From nobody Thu Nov 28 00:41:50 2024 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6ECA1849C; Mon, 7 Oct 2024 01:31:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728264680; cv=none; b=ckj4Jm/fKu8LqIChL53kFw5H5v8v/5zW25WTDjFakyANmW7PNxnJmPpuR+xH129sJBzBLbdZ5GDZTkCH/vu38gMUKgubPXVNPhT1TmAoNYT+OuVGPN4s3foZqlgnsvC+7yqCMEpAi6GNfmZ0MA3aRmaRINv+ofME/M37+1GQaog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728264680; c=relaxed/simple; bh=7v8EkhMDv+Jx4uOPQGK7HMrlgEz0giZggGqCi8QC6H0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tWUCcWuWkKrUvM3o0aQm872LWIUtaBxRKzuHt8urak9zRh0CZdx5r8iPXnQGadujcdoxtC3wbIVnvF1VVrukMNlEfowryw4uPxxElEE4aCn8zhbOTTnPOIgiweRcAzsXIiVRb+YBmczWDUJg9LL16SvYfsNyisOoYgonXRgXU2Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=K/Zf9t1i; arc=none smtp.client-ip=209.85.222.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="K/Zf9t1i" Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-7ae3d9a93c0so415933185a.3; Sun, 06 Oct 2024 18:31:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728264678; x=1728869478; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=j3ksh4XUKkffbY/duSvAxp7lxaY240eNih1Cc+96aTE=; b=K/Zf9t1iMLOKWH790Tapxl2gs3Uk7yHFHCt+EfH/uAR4rdVFTw4Os4FDGlEZ2n4sMB +rW3V7nqz/8jSi6GNy7B08aHNe5V/MPa7LSj4qgBqcpb5J9i0ExR+d7XeP9kdLdMC/fN fAp13M7wbJGP14fKj/TCSSxZBtSYeHK7lTjJI13Iu/5RKKNdKb+ep8PcRxM8bo/nmzoS a9oSewL2psZC5mLg4gb1gw04wPAiNdkt8pf4BaDkXcTl5+SLD8TfMY6GJXlWIWv6Y8Hv M+THXVK5LDh6z3sDLYB0KhTxrxYA2Uffw9VW/Ynrm68mlPNeiJWh6GDWTo/bzm7eoYAS +Mbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728264678; x=1728869478; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j3ksh4XUKkffbY/duSvAxp7lxaY240eNih1Cc+96aTE=; b=DFK55UYSyImx5RXPtv7AI0HAVeOriWvJbBFNXJbsarRR3R7ls4S8is/B2VTfLz++bK IuLghmn792DyBi3oKr4N2qYGDZkrrWGHhc7IXzYm3o3R6flOd7on+TvG2Ynhl8k6VMIa Fpt46I3Z1e3XjpUN5w/7iOWrQVxmSmYZts8YiKGUGUKKulSK9rfCbUjH5FfA4QTR6U1l 3ERhw2eA0d0Uuul7OixPVGNj6fy0nOIkaBW6RERQBH/SdPyiGpDsiE9BrBz6B+GQ4Q1O VPSkyBseNpG6mK/iIuCRv3rMT0A2Qt2MYSvoel9pGLXL1RzGLREEGLOxFUAV5kq4mz0L QOGg== X-Forwarded-Encrypted: i=1; AJvYcCU7ZPm0B3iyr3nSUo4ub+d9DigAzD0PNBPAhdWUNLaz37xQcnbymfTM4fc0Fwir3fn4Df6evw1YHqgUMu8v@vger.kernel.org, AJvYcCV9bMa36pDZh9MhsvNruppErzBP+GMGpDfOAL3pJRUdJwcv8+dYsmf+y5AMFG3r1I6w4otsVhtAnNKx@vger.kernel.org, AJvYcCWmkQ4+DybdmApn740pF0CuzIiUIwCTuK1oXsDQue1/oy0DhvBZqQI7enG7vUB5boZ83OLaAP2yL4gb@vger.kernel.org X-Gm-Message-State: AOJu0Yz4Gz9urSk5oAoM2S5bKAXSh8/i2XNLXB05unPH4Vdpm/6fUagW nQbx3n4NrixbZ7FsHMTgUQV30UR+hswELU2PMsIeRf8SsbmN11LG X-Google-Smtp-Source: AGHT+IHfkg0cGT4jshIHtr7s47CTUFILrvkTDKQ6NMGzBzbAdTlKcS6WdQJISVBiQ/o7R1qiaHbtgQ== X-Received: by 2002:a05:620a:2413:b0:7a9:b605:f823 with SMTP id af79cd13be357-7ae6f4547b9mr1781299685a.37.1728264678271; Sun, 06 Oct 2024 18:31:18 -0700 (PDT) Received: from localhost.localdomain (ool-1826d901.dyn.optonline.net. [24.38.217.1]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7ae757627fdsm207326985a.100.2024.10.06.18.31.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Oct 2024 18:31:17 -0700 (PDT) From: Alex Lanzano To: u.kleine-koenig@baylibre.com, Alex Lanzano , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Rob Herring , Krzysztof Kozlowski , Conor Dooley , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Mehdi Djait , Dmitry Baryshkov Cc: skhan@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, Krzysztof Kozlowski , dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v9 1/2] dt-bindings: display: Add Sharp Memory LCD bindings Date: Sun, 6 Oct 2024 21:30:05 -0400 Message-ID: <20241007013036.3104877-2-lanzano.alex@gmail.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241007013036.3104877-1-lanzano.alex@gmail.com> References: <20241007013036.3104877-1-lanzano.alex@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add device tree bindings for the monochrome Sharp Memory LCD Co-developed-by: Mehdi Djait Signed-off-by: Mehdi Djait Signed-off-by: Alex Lanzano Reviewed-by: Krzysztof Kozlowski --- .../bindings/display/sharp,ls010b7dh04.yaml | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 Documentation/devicetree/bindings/display/sharp,ls010b7= dh04.yaml diff --git a/Documentation/devicetree/bindings/display/sharp,ls010b7dh04.ya= ml b/Documentation/devicetree/bindings/display/sharp,ls010b7dh04.yaml new file mode 100644 index 000000000000..8097f091c2a5 --- /dev/null +++ b/Documentation/devicetree/bindings/display/sharp,ls010b7dh04.yaml @@ -0,0 +1,92 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/display/sharp,ls010b7dh04.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sharp Memory LCD panels + +maintainers: + - Alex Lanzano + +description: + Sharp Memory LCDs are a series of monochrome displays that operate over + a SPI bus. The displays require a signal (VCOM) to be generated to preve= nt + DC bias build up resulting in pixels being unable to change. Three modes + can be used to provide the VCOM signal ("software", "external", "pwm"). + +properties: + compatible: + enum: + - sharp,ls010b7dh04 + - sharp,ls011b7dh03 + - sharp,ls012b7dd01 + - sharp,ls013b7dh03 + - sharp,ls013b7dh05 + - sharp,ls018b7dh02 + - sharp,ls027b7dh01 + - sharp,ls027b7dh01a + - sharp,ls032b7dd02 + - sharp,ls044q7dh01 + + reg: + maxItems: 1 + + spi-max-frequency: + maximum: 2000000 + + sharp,vcom-mode: + $ref: /schemas/types.yaml#/definitions/string + description: | + software - This mode relies on a software operation to send a + "maintain display" message to the display, toggling the vcom + bit on and off with each message + + external - This mode relies on an external clock to generate + the signal on the EXTCOMM pin + + pwm - This mode relies on a pwm device to generate the signal + on the EXTCOMM pin + + enum: [software, external, pwm] + + enable-gpios: true + + pwms: + maxItems: 1 + description: External VCOM signal + +required: + - compatible + - reg + - sharp,vcom-mode + +allOf: + - $ref: panel/panel-common.yaml# + - $ref: /schemas/spi/spi-peripheral-props.yaml# + + - if: + properties: + sharp,vcom-mode: + const: pwm + then: + required: + - pwms + +unevaluatedProperties: false + +examples: + - | + spi { + #address-cells =3D <1>; + #size-cells =3D <0>; + + display@0 { + compatible =3D "sharp,ls013b7dh03"; + reg =3D <0>; + spi-cs-high; + spi-max-frequency =3D <1000000>; + sharp,vcom-mode =3D "software"; + }; + }; +... --=20 2.46.2 From nobody Thu Nov 28 00:41:50 2024 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DE521755C; Mon, 7 Oct 2024 01:31:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728264694; cv=none; b=UbdWvpkjJaILKvJqb2MoOvA4PLR7LX53ahSeDQKdDmbAoAga74SVHGwPtLV62sNsYnh0ger+3shgBuOYhjMauZiZ5oxQ0zGxbOVhtEPMpGnOL0Fb2FGZTHpT0QdVjtKzr7DgpksZ5fbPeHc/Mx/VPZ5t7sCvO9XV1Vfn0/Z2ZDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728264694; c=relaxed/simple; bh=uJ2/CeiWtbzAejVoaZITFfCSsTcmohhfIBx5LPADxLw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q3QuXs3GV/4W6jagxStSq8Na2ABRfnyrUtL1no6rsCyDuibnVO1SF7S6b3S46JGgZx6Yo3MHgRdgBCoJSjRnZ3C3/+5+dC9H65StO1OUO0zA5BKwiuNVCRdXces5ez34N/774JX5xruS+oNY2Z4VwtttDF1l8jqeiiPsf18tcto= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AHtU8Siz; arc=none smtp.client-ip=209.85.222.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AHtU8Siz" Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-7a9ad8a7c63so400057285a.3; Sun, 06 Oct 2024 18:31:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728264691; x=1728869491; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9UIIIw7ZoF0g2WSi2tWUhStN6bMGyenGLPc2hDmXddY=; b=AHtU8Siz2EVMetKWrndnTiQx4QDP++bj7nOYfJPYWvuNQGGgD3J/uZRstBfEluMWrf v/118raZYPiL+gcI6oc4M0oR76qoUjTC7jUoas3fZ2vBRUVBPz/CrsuLaR9t68rpLK4L CsysFT0lhTqGgbRPC79WzWgd7IglMvjx/wkpjgDkykKVJjLt+B8aY9heR/O2/c/+1crm rZPy6r9LN+aSwmiCZPpejfF/+YyIexPxXGaSD8GcUs/C8/1/I5GlXaVnbYLWB5a9dqKQ ZB30gnS9DgaAaCy6H/RmAJGlT6mLEnKzEUCdI/UUodoqsHO/vjmHvKkHILB9gQaAVIZO W9PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728264691; x=1728869491; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9UIIIw7ZoF0g2WSi2tWUhStN6bMGyenGLPc2hDmXddY=; b=qTigIZu75oN4NQSDbDbWadKD4tESK6GUYWtxDdJILuGX/xcMlKC1NteFNOmNfuzG1G bSObef5jLJkzeiq6Mg7Kj2O95M3HUkEHahr8SoXpdoN7ftg4he7f59z76WPKqKR9kbQq 5/iCcABG8OsPMuyjIqVHB5Lw356QB0FJiN/bEHu5pTMl1Ax9aZyioQ1Oe4/0UKLzuxrU Eg57Rk7BhBE4Z6H+fZiv1KwVKSxn46+B+LbW6CfsiJ8NOTZsQ3B0pfat/5O1mf7gGWki pFvmc0iiXmQfo8tjIt4XWnIDJ2hgJA3tWdSfKFxx3N+7aOLsBt7oIZYdSTGDPtMg7fcl CiSA== X-Forwarded-Encrypted: i=1; AJvYcCUDpvBmeGzNQfK+Ko9H/c59RtgrE0Zf6qxXRpD9zNEE8BRPkYDuZ2PoDIEIvJWU8B++s5wdeYsvu82w@vger.kernel.org, AJvYcCUFfDFL7HP0v1KZOBiPr1hYttHagC1XmRqQbA/OsPHZSVlolughPe8Ckf7G17aAuLoTraDX+UNPEV7X@vger.kernel.org, AJvYcCWznV1tQStVVcJYOaJPdt8XLbjZEGLi8NawMwVz814orEuKPxPXzUwvbLAmTeonT/CESJf96YUxCGP8EjLI@vger.kernel.org X-Gm-Message-State: AOJu0YwUeBxcNufhSI7Z5U7FnTpft6dxxAixryPpv82QcPQiriegQUG5 lcqdAtPyTFsk/F4NRfrftL6UkOzhlB84NwcpQJLw7vuWdejzfk1e X-Google-Smtp-Source: AGHT+IFQ7rKIHni3pmUrJHCZ2brj9Mg+69MJ8kWkCsAQhM/+mHE2WMG1IQzIPsi8kC6OE9aBU2AP9Q== X-Received: by 2002:a05:620a:2483:b0:7ab:4042:6d7 with SMTP id af79cd13be357-7ae6f421cb5mr1621726485a.5.1728264691076; Sun, 06 Oct 2024 18:31:31 -0700 (PDT) Received: from localhost.localdomain (ool-1826d901.dyn.optonline.net. [24.38.217.1]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7ae757627fdsm207326985a.100.2024.10.06.18.31.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Oct 2024 18:31:30 -0700 (PDT) From: Alex Lanzano To: u.kleine-koenig@baylibre.com, Alex Lanzano , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Rob Herring , Krzysztof Kozlowski , Conor Dooley , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Mehdi Djait , Dmitry Baryshkov Cc: skhan@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v9 2/2] drm/tiny: Add driver for Sharp Memory LCD Date: Sun, 6 Oct 2024 21:30:06 -0400 Message-ID: <20241007013036.3104877-3-lanzano.alex@gmail.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241007013036.3104877-1-lanzano.alex@gmail.com> References: <20241007013036.3104877-1-lanzano.alex@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for the monochrome Sharp Memory LCDs. Co-developed-by: Mehdi Djait Signed-off-by: Mehdi Djait Signed-off-by: Alex Lanzano Reviewed-by: Dmitry Baryshkov --- MAINTAINERS | 6 + drivers/gpu/drm/tiny/Kconfig | 20 + drivers/gpu/drm/tiny/Makefile | 1 + drivers/gpu/drm/tiny/sharp-memory.c | 666 ++++++++++++++++++++++++++++ 4 files changed, 693 insertions(+) create mode 100644 drivers/gpu/drm/tiny/sharp-memory.c diff --git a/MAINTAINERS b/MAINTAINERS index 5432239f3c5d..f3b1a6115711 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7289,6 +7289,12 @@ S: Maintained F: Documentation/devicetree/bindings/display/panel/samsung,s6d7aa0.yaml F: drivers/gpu/drm/panel/panel-samsung-s6d7aa0.c =20 +DRM DRIVER FOR SHARP MEMORY LCD +M: Alex Lanzano +S: Maintained +F: Documentation/devicetree/bindings/display/sharp,ls010b7dh04.yaml +F: drivers/gpu/drm/tiny/sharp-memory.c + DRM DRIVER FOR SITRONIX ST7586 PANELS M: David Lechner S: Maintained diff --git a/drivers/gpu/drm/tiny/Kconfig b/drivers/gpu/drm/tiny/Kconfig index f6889f649bc1..bc386954faa2 100644 --- a/drivers/gpu/drm/tiny/Kconfig +++ b/drivers/gpu/drm/tiny/Kconfig @@ -186,6 +186,26 @@ config TINYDRM_REPAPER =20 If M is selected the module will be called repaper. =20 +config TINYDRM_SHARP_MEMORY + tristate "DRM support for Sharp Memory LCD panels" + depends on DRM && SPI + select DRM_GEM_DMA_HELPER + select DRM_KMS_HELPER + help + DRM Driver for the following Sharp Memory Panels: + * 1.00" Sharp Memory LCD (LS010B7DH04) + * 1.10" Sharp Memory LCD (LS011B7DH03) + * 1.20" Sharp Memory LCD (LS012B7DD01) + * 1.28" Sharp Memory LCD (LS013B7DH03) + * 1.26" Sharp Memory LCD (LS013B7DH05) + * 1.80" Sharp Memory LCD (LS018B7DH02) + * 2.70" Sharp Memory LCD (LS027B7DH01) + * 2.70" Sharp Memory LCD (LS027B7DH01A) + * 3.20" Sharp Memory LCD (LS032B7DD02) + * 4.40" Sharp Memory LCD (LS044Q7DH01) + + If M is selected the module will be called sharp_memory. + config TINYDRM_ST7586 tristate "DRM support for Sitronix ST7586 display panels" depends on DRM && SPI diff --git a/drivers/gpu/drm/tiny/Makefile b/drivers/gpu/drm/tiny/Makefile index 76dde89a044b..4aaf56f8707d 100644 --- a/drivers/gpu/drm/tiny/Makefile +++ b/drivers/gpu/drm/tiny/Makefile @@ -14,5 +14,6 @@ obj-$(CONFIG_TINYDRM_ILI9341) +=3D ili9341.o obj-$(CONFIG_TINYDRM_ILI9486) +=3D ili9486.o obj-$(CONFIG_TINYDRM_MI0283QT) +=3D mi0283qt.o obj-$(CONFIG_TINYDRM_REPAPER) +=3D repaper.o +obj-$(CONFIG_TINYDRM_SHARP_MEMORY) +=3D sharp-memory.o obj-$(CONFIG_TINYDRM_ST7586) +=3D st7586.o obj-$(CONFIG_TINYDRM_ST7735R) +=3D st7735r.o diff --git a/drivers/gpu/drm/tiny/sharp-memory.c b/drivers/gpu/drm/tiny/sha= rp-memory.c new file mode 100644 index 000000000000..397b305cce38 --- /dev/null +++ b/drivers/gpu/drm/tiny/sharp-memory.c @@ -0,0 +1,666 @@ +// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SHARP_MODE_PERIOD 8 +#define SHARP_ADDR_PERIOD 8 +#define SHARP_DUMMY_PERIOD 8 + +#define SHARP_MEMORY_DISPLAY_MAINTAIN_MODE 0 +#define SHARP_MEMORY_DISPLAY_UPDATE_MODE 1 +#define SHARP_MEMORY_DISPLAY_CLEAR_MODE 4 + +enum sharp_memory_model { + LS010B7DH04, + LS011B7DH03, + LS012B7DD01, + LS013B7DH03, + LS013B7DH05, + LS018B7DH02, + LS027B7DH01, + LS027B7DH01A, + LS032B7DD02, + LS044Q7DH01, +}; + +enum sharp_memory_vcom_mode { + SHARP_MEMORY_SOFTWARE_VCOM, + SHARP_MEMORY_EXTERNAL_VCOM, + SHARP_MEMORY_PWM_VCOM +}; + +struct sharp_memory_device { + struct drm_device drm; + struct spi_device *spi; + + const struct drm_display_mode *mode; + + struct drm_crtc crtc; + struct drm_plane plane; + struct drm_encoder encoder; + struct drm_connector connector; + + struct gpio_desc *enable_gpio; + + struct task_struct *sw_vcom_signal; + struct pwm_device *pwm_vcom_signal; + + enum sharp_memory_vcom_mode vcom_mode; + u8 vcom; + + u32 pitch; + u32 tx_buffer_size; + u8 *tx_buffer; + + /* When vcom_mode =3D=3D "software" a kthread is used to periodically sen= d a + * 'maintain display' message over spi. This mutex ensures tx_buffer acce= ss + * and spi bus usage is synchronized in this case. + */ + struct mutex tx_mutex; +}; + +static inline int sharp_memory_spi_write(struct spi_device *spi, void *buf= , size_t len) +{ + /* Reverse the bit order */ + for (u8 *b =3D buf; b < ((u8 *)buf) + len; ++b) + *b =3D bitrev8(*b); + + return spi_write(spi, buf, len); +} + +static inline struct sharp_memory_device *drm_to_sharp_memory_device(struc= t drm_device *drm) +{ + return container_of(drm, struct sharp_memory_device, drm); +} + +DEFINE_DRM_GEM_DMA_FOPS(sharp_memory_fops); + +static const struct drm_driver sharp_memory_drm_driver =3D { + .driver_features =3D DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC, + .fops =3D &sharp_memory_fops, + DRM_GEM_DMA_DRIVER_OPS_VMAP, + .name =3D "sharp_memory_display", + .desc =3D "Sharp Display Memory LCD", + .date =3D "20231129", + .major =3D 1, + .minor =3D 0, +}; + +static inline void sharp_memory_set_tx_buffer_mode(u8 *buffer, u8 mode, u8= vcom) +{ + *buffer =3D mode | (vcom << 1); +} + +static inline void sharp_memory_set_tx_buffer_addresses(u8 *buffer, + struct drm_rect clip, + u32 pitch) +{ + for (u32 line =3D 0; line < clip.y2; ++line) + buffer[line * pitch] =3D line + 1; +} + +static void sharp_memory_set_tx_buffer_data(u8 *buffer, + struct drm_framebuffer *fb, + struct drm_rect clip, + u32 pitch, + struct drm_format_conv_state *fmtcnv_state) +{ + int ret; + struct iosys_map dst, vmap; + struct drm_gem_dma_object *dma_obj =3D drm_fb_dma_get_gem_obj(fb, 0); + + ret =3D drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE); + if (ret) + return; + + iosys_map_set_vaddr(&dst, buffer); + iosys_map_set_vaddr(&vmap, dma_obj->vaddr); + + drm_fb_xrgb8888_to_mono(&dst, &pitch, &vmap, fb, &clip, fmtcnv_state); + + drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE); +} + +static int sharp_memory_update_display(struct sharp_memory_device *smd, + struct drm_framebuffer *fb, + struct drm_rect clip, + struct drm_format_conv_state *fmtcnv_state) +{ + int ret; + u32 pitch =3D smd->pitch; + u8 vcom =3D smd->vcom; + u8 *tx_buffer =3D smd->tx_buffer; + u32 tx_buffer_size =3D smd->tx_buffer_size; + + mutex_lock(&smd->tx_mutex); + + /* Populate the transmit buffer with frame data */ + sharp_memory_set_tx_buffer_mode(&tx_buffer[0], + SHARP_MEMORY_DISPLAY_UPDATE_MODE, vcom); + sharp_memory_set_tx_buffer_addresses(&tx_buffer[1], clip, pitch); + sharp_memory_set_tx_buffer_data(&tx_buffer[2], fb, clip, pitch, fmtcnv_st= ate); + + ret =3D sharp_memory_spi_write(smd->spi, tx_buffer, tx_buffer_size); + + mutex_unlock(&smd->tx_mutex); + + return ret; +} + +static int sharp_memory_maintain_display(struct sharp_memory_device *smd) +{ + int ret; + u8 vcom =3D smd->vcom; + u8 *tx_buffer =3D smd->tx_buffer; + + mutex_lock(&smd->tx_mutex); + + sharp_memory_set_tx_buffer_mode(&tx_buffer[0], SHARP_MEMORY_DISPLAY_MAINT= AIN_MODE, vcom); + tx_buffer[1] =3D 0; /* Write dummy data */ + ret =3D sharp_memory_spi_write(smd->spi, tx_buffer, 2); + + mutex_unlock(&smd->tx_mutex); + + return ret; +} + +static int sharp_memory_clear_display(struct sharp_memory_device *smd) +{ + int ret; + u8 vcom =3D smd->vcom; + u8 *tx_buffer =3D smd->tx_buffer; + + mutex_lock(&smd->tx_mutex); + + sharp_memory_set_tx_buffer_mode(&tx_buffer[0], SHARP_MEMORY_DISPLAY_CLEAR= _MODE, vcom); + tx_buffer[1] =3D 0; /* write dummy data */ + ret =3D sharp_memory_spi_write(smd->spi, tx_buffer, 2); + + mutex_unlock(&smd->tx_mutex); + + return ret; +} + +static void sharp_memory_fb_dirty(struct drm_framebuffer *fb, struct drm_r= ect *rect, + struct drm_format_conv_state *fmtconv_state) +{ + struct drm_rect clip; + struct sharp_memory_device *smd =3D drm_to_sharp_memory_device(fb->dev); + + /* Always update a full line regardless of what is dirty */ + clip.x1 =3D 0; + clip.x2 =3D fb->width; + clip.y1 =3D rect->y1; + clip.y2 =3D rect->y2; + + sharp_memory_update_display(smd, fb, clip, fmtconv_state); +} + +static int sharp_memory_plane_atomic_check(struct drm_plane *plane, + struct drm_atomic_state *state) +{ + struct drm_plane_state *plane_state =3D drm_atomic_get_new_plane_state(st= ate, plane); + struct sharp_memory_device *smd; + struct drm_crtc_state *crtc_state; + + smd =3D container_of(plane, struct sharp_memory_device, plane); + crtc_state =3D drm_atomic_get_new_crtc_state(state, &smd->crtc); + + return drm_atomic_helper_check_plane_state(plane_state, crtc_state, + DRM_PLANE_NO_SCALING, + DRM_PLANE_NO_SCALING, + false, false); +} + +static void sharp_memory_plane_atomic_update(struct drm_plane *plane, + struct drm_atomic_state *state) +{ + struct drm_plane_state *old_state =3D drm_atomic_get_old_plane_state(stat= e, plane); + struct drm_plane_state *plane_state =3D plane->state; + struct drm_format_conv_state fmtcnv_state =3D DRM_FORMAT_CONV_STATE_INIT; + struct sharp_memory_device *smd; + struct drm_rect rect; + + smd =3D container_of(plane, struct sharp_memory_device, plane); + if (!smd->crtc.state->active) + return; + + if (drm_atomic_helper_damage_merged(old_state, plane_state, &rect)) + sharp_memory_fb_dirty(plane_state->fb, &rect, &fmtcnv_state); + + drm_format_conv_state_release(&fmtcnv_state); +} + +static const struct drm_plane_helper_funcs sharp_memory_plane_helper_funcs= =3D { + .prepare_fb =3D drm_gem_plane_helper_prepare_fb, + .atomic_check =3D sharp_memory_plane_atomic_check, + .atomic_update =3D sharp_memory_plane_atomic_update, +}; + +static bool sharp_memory_format_mod_supported(struct drm_plane *plane, + u32 format, + u64 modifier) +{ + return modifier =3D=3D DRM_FORMAT_MOD_LINEAR; +} + +static const struct drm_plane_funcs sharp_memory_plane_funcs =3D { + .update_plane =3D drm_atomic_helper_update_plane, + .disable_plane =3D drm_atomic_helper_disable_plane, + .destroy =3D drm_plane_cleanup, + .reset =3D drm_atomic_helper_plane_reset, + .atomic_duplicate_state =3D drm_atomic_helper_plane_duplicate_state, + .atomic_destroy_state =3D drm_atomic_helper_plane_destroy_state, + .format_mod_supported =3D sharp_memory_format_mod_supported, +}; + +static enum drm_mode_status sharp_memory_crtc_mode_valid(struct drm_crtc *= crtc, + const struct drm_display_mode *mode) +{ + struct sharp_memory_device *smd =3D drm_to_sharp_memory_device(crtc->dev); + + return drm_crtc_helper_mode_valid_fixed(crtc, mode, smd->mode); +} + +static int sharp_memory_crtc_check(struct drm_crtc *crtc, + struct drm_atomic_state *state) +{ + struct drm_crtc_state *crtc_state =3D drm_atomic_get_new_crtc_state(state= , crtc); + int ret; + + if (!crtc_state->enable) + goto out; + + ret =3D drm_atomic_helper_check_crtc_primary_plane(crtc_state); + if (ret) + return ret; + +out: + return drm_atomic_add_affected_planes(state, crtc); +} + +static int sharp_memory_sw_vcom_signal_thread(void *data) +{ + struct sharp_memory_device *smd =3D data; + + while (!kthread_should_stop()) { + smd->vcom ^=3D 1; /* Toggle vcom */ + sharp_memory_maintain_display(smd); + msleep(1000); + } + + return 0; +} + +static void sharp_memory_crtc_enable(struct drm_crtc *crtc, + struct drm_atomic_state *state) +{ + struct sharp_memory_device *smd =3D drm_to_sharp_memory_device(crtc->dev); + + sharp_memory_clear_display(smd); + + if (smd->enable_gpio) + gpiod_set_value(smd->enable_gpio, 1); +} + +static void sharp_memory_crtc_disable(struct drm_crtc *crtc, + struct drm_atomic_state *state) +{ + struct sharp_memory_device *smd =3D drm_to_sharp_memory_device(crtc->dev); + + sharp_memory_clear_display(smd); + + if (smd->enable_gpio) + gpiod_set_value(smd->enable_gpio, 0); +} + +static const struct drm_crtc_helper_funcs sharp_memory_crtc_helper_funcs = =3D { + .mode_valid =3D sharp_memory_crtc_mode_valid, + .atomic_check =3D sharp_memory_crtc_check, + .atomic_enable =3D sharp_memory_crtc_enable, + .atomic_disable =3D sharp_memory_crtc_disable, +}; + +static const struct drm_crtc_funcs sharp_memory_crtc_funcs =3D { + .reset =3D drm_atomic_helper_crtc_reset, + .destroy =3D drm_crtc_cleanup, + .set_config =3D drm_atomic_helper_set_config, + .page_flip =3D drm_atomic_helper_page_flip, + .atomic_duplicate_state =3D drm_atomic_helper_crtc_duplicate_state, + .atomic_destroy_state =3D drm_atomic_helper_crtc_destroy_state, +}; + +static const struct drm_encoder_funcs sharp_memory_encoder_funcs =3D { + .destroy =3D drm_encoder_cleanup, +}; + +static int sharp_memory_connector_get_modes(struct drm_connector *connecto= r) +{ + struct sharp_memory_device *smd =3D drm_to_sharp_memory_device(connector-= >dev); + + return drm_connector_helper_get_modes_fixed(connector, smd->mode); +} + +static const struct drm_connector_helper_funcs sharp_memory_connector_hfun= cs =3D { + .get_modes =3D sharp_memory_connector_get_modes, +}; + +static const struct drm_connector_funcs sharp_memory_connector_funcs =3D { + .reset =3D drm_atomic_helper_connector_reset, + .fill_modes =3D drm_helper_probe_single_connector_modes, + .destroy =3D drm_connector_cleanup, + .atomic_duplicate_state =3D drm_atomic_helper_connector_duplicate_state, + .atomic_destroy_state =3D drm_atomic_helper_connector_destroy_state, + +}; + +static const struct drm_mode_config_funcs sharp_memory_mode_config_funcs = =3D { + .fb_create =3D drm_gem_fb_create_with_dirty, + .atomic_check =3D drm_atomic_helper_check, + .atomic_commit =3D drm_atomic_helper_commit, +}; + +static const struct drm_display_mode sharp_memory_ls010b7dh04_mode =3D { + DRM_SIMPLE_MODE(128, 128, 18, 18), +}; + +static const struct drm_display_mode sharp_memory_ls011b7dh03_mode =3D { + DRM_SIMPLE_MODE(160, 68, 25, 10), +}; + +static const struct drm_display_mode sharp_memory_ls012b7dd01_mode =3D { + DRM_SIMPLE_MODE(184, 38, 29, 6), +}; + +static const struct drm_display_mode sharp_memory_ls013b7dh03_mode =3D { + DRM_SIMPLE_MODE(128, 128, 23, 23), +}; + +static const struct drm_display_mode sharp_memory_ls013b7dh05_mode =3D { + DRM_SIMPLE_MODE(144, 168, 20, 24), +}; + +static const struct drm_display_mode sharp_memory_ls018b7dh02_mode =3D { + DRM_SIMPLE_MODE(230, 303, 27, 36), +}; + +static const struct drm_display_mode sharp_memory_ls027b7dh01_mode =3D { + DRM_SIMPLE_MODE(400, 240, 58, 35), +}; + +static const struct drm_display_mode sharp_memory_ls032b7dd02_mode =3D { + DRM_SIMPLE_MODE(336, 536, 42, 68), +}; + +static const struct drm_display_mode sharp_memory_ls044q7dh01_mode =3D { + DRM_SIMPLE_MODE(320, 240, 89, 67), +}; + +static const struct spi_device_id sharp_memory_ids[] =3D { + {"ls010b7dh04", (kernel_ulong_t)&sharp_memory_ls010b7dh04_mode}, + {"ls011b7dh03", (kernel_ulong_t)&sharp_memory_ls011b7dh03_mode}, + {"ls012b7dd01", (kernel_ulong_t)&sharp_memory_ls012b7dd01_mode}, + {"ls013b7dh03", (kernel_ulong_t)&sharp_memory_ls013b7dh03_mode}, + {"ls013b7dh05", (kernel_ulong_t)&sharp_memory_ls013b7dh05_mode}, + {"ls018b7dh02", (kernel_ulong_t)&sharp_memory_ls018b7dh02_mode}, + {"ls027b7dh01", (kernel_ulong_t)&sharp_memory_ls027b7dh01_mode}, + {"ls027b7dh01a", (kernel_ulong_t)&sharp_memory_ls027b7dh01_mode}, + {"ls032b7dd02", (kernel_ulong_t)&sharp_memory_ls032b7dd02_mode}, + {"ls044q7dh01", (kernel_ulong_t)&sharp_memory_ls044q7dh01_mode}, + {}, +}; +MODULE_DEVICE_TABLE(spi, sharp_memory_ids); + +static const struct of_device_id sharp_memory_of_match[] =3D { + {.compatible =3D "sharp,ls010b7dh04", &sharp_memory_ls010b7dh04_mode}, + {.compatible =3D "sharp,ls011b7dh03", &sharp_memory_ls011b7dh03_mode}, + {.compatible =3D "sharp,ls012b7dd01", &sharp_memory_ls012b7dd01_mode}, + {.compatible =3D "sharp,ls013b7dh03", &sharp_memory_ls013b7dh03_mode}, + {.compatible =3D "sharp,ls013b7dh05", &sharp_memory_ls013b7dh05_mode}, + {.compatible =3D "sharp,ls018b7dh02", &sharp_memory_ls018b7dh02_mode}, + {.compatible =3D "sharp,ls027b7dh01", &sharp_memory_ls027b7dh01_mode}, + {.compatible =3D "sharp,ls027b7dh01a", &sharp_memory_ls027b7dh01_mode}, + {.compatible =3D "sharp,ls032b7dd02", &sharp_memory_ls032b7dd02_mode}, + {.compatible =3D "sharp,ls044q7dh01", &sharp_memory_ls044q7dh01_mode}, + {}, +}; +MODULE_DEVICE_TABLE(of, sharp_memory_of_match); + +static const u32 sharp_memory_formats[] =3D { + DRM_FORMAT_XRGB8888, +}; + +static int sharp_memory_pipe_init(struct drm_device *dev, + struct sharp_memory_device *smd, + const u32 *formats, unsigned int format_count, + const u64 *format_modifiers) +{ + int ret; + struct drm_encoder *encoder =3D &smd->encoder; + struct drm_plane *plane =3D &smd->plane; + struct drm_crtc *crtc =3D &smd->crtc; + struct drm_connector *connector =3D &smd->connector; + + drm_plane_helper_add(plane, &sharp_memory_plane_helper_funcs); + ret =3D drm_universal_plane_init(dev, plane, 0, + &sharp_memory_plane_funcs, + formats, format_count, + format_modifiers, + DRM_PLANE_TYPE_PRIMARY, NULL); + if (ret) + return ret; + + drm_crtc_helper_add(crtc, &sharp_memory_crtc_helper_funcs); + ret =3D drm_crtc_init_with_planes(dev, crtc, plane, NULL, + &sharp_memory_crtc_funcs, NULL); + if (ret) + return ret; + + encoder->possible_crtcs =3D drm_crtc_mask(crtc); + ret =3D drm_encoder_init(dev, encoder, &sharp_memory_encoder_funcs, + DRM_MODE_ENCODER_NONE, NULL); + if (ret) + return ret; + + ret =3D drm_connector_init(&smd->drm, &smd->connector, + &sharp_memory_connector_funcs, + DRM_MODE_CONNECTOR_SPI); + if (ret) + return ret; + + drm_connector_helper_add(&smd->connector, + &sharp_memory_connector_hfuncs); + + return drm_connector_attach_encoder(connector, encoder); +} + +static int sharp_memory_init_pwm_vcom_signal(struct sharp_memory_device *s= md) +{ + struct pwm_state pwm_state; + struct device *dev =3D &smd->spi->dev; + + smd->pwm_vcom_signal =3D devm_pwm_get(dev, NULL); + if (IS_ERR(smd->pwm_vcom_signal)) + return dev_err_probe(dev, -EINVAL, "Could not get pwm device\n"); + + pwm_init_state(smd->pwm_vcom_signal, &pwm_state); + pwm_set_relative_duty_cycle(&pwm_state, 1, 10); + pwm_state.enabled =3D true; + pwm_apply_might_sleep(smd->pwm_vcom_signal, &pwm_state); + + return 0; +} + +static int sharp_memory_probe(struct spi_device *spi) +{ + int ret; + struct device *dev; + struct sharp_memory_device *smd; + struct drm_device *drm; + const char *vcom_mode_str; + + dev =3D &spi->dev; + + ret =3D spi_setup(spi); + if (ret < 0) + return dev_err_probe(dev, ret, "Failed to setup spi device\n"); + + if (!dev->coherent_dma_mask) { + ret =3D dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32)); + if (ret) + return dev_err_probe(dev, ret, "Failed to set dma mask\n"); + } + + smd =3D devm_drm_dev_alloc(dev, &sharp_memory_drm_driver, + struct sharp_memory_device, drm); + if (!smd) + return -ENOMEM; + + spi_set_drvdata(spi, smd); + + smd->spi =3D spi; + drm =3D &smd->drm; + ret =3D drmm_mode_config_init(drm); + if (ret) + return dev_err_probe(dev, ret, "Failed to initialize drm config\n"); + + smd->enable_gpio =3D devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_HIG= H); + if (!smd->enable_gpio) + dev_warn(dev, "Enable gpio not defined\n"); + + drm->mode_config.funcs =3D &sharp_memory_mode_config_funcs; + smd->mode =3D spi_get_device_match_data(spi); + + smd->pitch =3D (SHARP_ADDR_PERIOD + smd->mode->hdisplay + SHARP_DUMMY_PER= IOD) / 8; + smd->tx_buffer_size =3D (SHARP_MODE_PERIOD + + (SHARP_ADDR_PERIOD + (smd->mode->hdisplay) + SHARP_DUMMY_PERIOD)= * + smd->mode->vdisplay) / 8; + + smd->tx_buffer =3D devm_kzalloc(dev, smd->tx_buffer_size, GFP_KERNEL); + if (!smd->tx_buffer) + return -ENOMEM; + + mutex_init(&smd->tx_mutex); + + /* + * VCOM is a signal that prevents DC bias from being built up in + * the panel resulting in pixels being forever stuck in one state. + * + * This driver supports three different methods to generate this + * signal depending on EXTMODE pin: + * + * software (EXTMODE =3D L) - This mode uses a kthread to + * periodically send a "maintain display" message to the display, + * toggling the vcom bit on and off with each message + * + * external (EXTMODE =3D H) - This mode relies on an external + * clock to generate the signal on the EXTCOMM pin + * + * pwm (EXTMODE =3D H) - This mode uses a pwm device to generate + * the signal on the EXTCOMM pin + * + */ + if (device_property_read_string(dev, "sharp,vcom-mode", &vcom_mode_str)) + return dev_err_probe(dev, -EINVAL, + "Unable to find sharp,vcom-mode node in device tree\n"); + + if (!strcmp("software", vcom_mode_str)) { + smd->vcom_mode =3D SHARP_MEMORY_SOFTWARE_VCOM; + smd->sw_vcom_signal =3D kthread_run(sharp_memory_sw_vcom_signal_thread, + smd, "sw_vcom_signal"); + + } else if (!strcmp("external", vcom_mode_str)) { + smd->vcom_mode =3D SHARP_MEMORY_EXTERNAL_VCOM; + + } else if (!strcmp("pwm", vcom_mode_str)) { + smd->vcom_mode =3D SHARP_MEMORY_PWM_VCOM; + ret =3D sharp_memory_init_pwm_vcom_signal(smd); + if (ret) + return dev_err_probe(dev, ret, + "Failed to initialize external COM signal\n"); + } else { + return dev_err_probe(dev, -EINVAL, "Invalid value set for vcom-mode\n"); + } + + drm->mode_config.min_width =3D smd->mode->hdisplay; + drm->mode_config.max_width =3D smd->mode->hdisplay; + drm->mode_config.min_height =3D smd->mode->vdisplay; + drm->mode_config.max_height =3D smd->mode->vdisplay; + + ret =3D sharp_memory_pipe_init(drm, smd, sharp_memory_formats, + ARRAY_SIZE(sharp_memory_formats), + NULL); + if (ret) + return dev_err_probe(dev, ret, "Failed to initialize display pipeline.\n= "); + + drm_plane_enable_fb_damage_clips(&smd->plane); + drm_mode_config_reset(drm); + + ret =3D drm_dev_register(drm, 0); + if (ret) + return dev_err_probe(dev, ret, "Failed to register drm device.\n"); + + drm_fbdev_dma_setup(drm, 0); + + return 0; +} + +static void sharp_memory_remove(struct spi_device *spi) +{ + struct sharp_memory_device *smd =3D spi_get_drvdata(spi); + + drm_dev_unplug(&smd->drm); + drm_atomic_helper_shutdown(&smd->drm); + + switch (smd->vcom_mode) { + case SHARP_MEMORY_SOFTWARE_VCOM: + kthread_stop(smd->sw_vcom_signal); + break; + + case SHARP_MEMORY_EXTERNAL_VCOM: + break; + + case SHARP_MEMORY_PWM_VCOM: + pwm_disable(smd->pwm_vcom_signal); + break; + } +} + +static struct spi_driver sharp_memory_spi_driver =3D { + .driver =3D { + .name =3D "sharp_memory", + .of_match_table =3D sharp_memory_of_match, + }, + .probe =3D sharp_memory_probe, + .remove =3D sharp_memory_remove, + .id_table =3D sharp_memory_ids, +}; +module_spi_driver(sharp_memory_spi_driver); + +MODULE_AUTHOR("Alex Lanzano "); +MODULE_DESCRIPTION("SPI Protocol driver for the sharp_memory display"); +MODULE_LICENSE("GPL"); --=20 2.46.2