From patchwork Tue May 25 11:31:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 12278561 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 197C0C2B9F8 for ; Tue, 25 May 2021 11:39:07 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8BA8D6128D for ; Tue, 25 May 2021 11:39:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8BA8D6128D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=somainline.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B06936E9F6; Tue, 25 May 2021 11:39:05 +0000 (UTC) Received: from relay04.th.seeweb.it (relay04.th.seeweb.it [IPv6:2001:4b7a:2000:18::165]) by gabe.freedesktop.org (Postfix) with ESMTPS id 541F96E9FA for ; Tue, 25 May 2021 11:39:00 +0000 (UTC) Received: from localhost.localdomain (83.6.168.54.neoplus.adsl.tpnet.pl [83.6.168.54]) by m-r1.th.seeweb.it (Postfix) with ESMTPA id EBE2520425; Tue, 25 May 2021 13:31:12 +0200 (CEST) From: Konrad Dybcio To: ~postmarketos/upstreaming@lists.sr.ht Subject: [PATCH 1/2] dt-bindings: Add SONY Synaptics JDI panel Date: Tue, 25 May 2021 13:31:02 +0200 Message-Id: <20210525113105.52990-1-konrad.dybcio@somainline.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, David Airlie , Konrad Dybcio , linux-kernel@vger.kernel.org, jamipkettunen@somainline.org, Rob Herring , Thierry Reding , martin.botka@somainline.org, dri-devel@lists.freedesktop.org, angelogioacchino.delregno@somainline.org, marijn.suijten@somainline.org, Sam Ravnborg Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add bindings for the SONY Synaptics JDI panel used in Xperia X, X Performance, X Compact, XZ and XZs smartphones. Due to the nature of phone manufacturing and lack of any docs whatsoever, replacement names have been used to indicate the devices that this panel is used on. Signed-off-by: Konrad Dybcio --- .../display/panel/sony,synaptics-jdi.yaml | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 Documentation/devicetree/bindings/display/panel/sony,synaptics-jdi.yaml diff --git a/Documentation/devicetree/bindings/display/panel/sony,synaptics-jdi.yaml b/Documentation/devicetree/bindings/display/panel/sony,synaptics-jdi.yaml new file mode 100644 index 000000000000..81d841c049e8 --- /dev/null +++ b/Documentation/devicetree/bindings/display/panel/sony,synaptics-jdi.yaml @@ -0,0 +1,100 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/display/panel/sony,synaptics-jdi.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: SONY Synaptics JDI panel + +maintainers: + - Konrad Dybcio + +description: |+ + This panel seems to only be found in SONY Xperia + X, X Performance, X Compact, XZ and XZs + smartphones and we have no straightforward way of + actually getting the correct model number, + as no schematics are released publicly. + +allOf: + - $ref: panel-common.yaml# + +properties: + compatible: + items: + - enum: + - sony,synaptics-jdi-dora + - sony,synaptics-jdi-kagura + - sony,synaptics-jdi-keyaki + - sony,synaptics-jdi-kugo + - sony,synaptics-jdi-suzu + + reg: true + + reset-gpios: true + + avdd-supply: + description: avdd supply + + vddio-supply: + description: vddio supply + + vsn-supply: + description: voltage negative supply + + vsp-supply: + description: voltage positive supply + + tvdd-supply: + description: tvdd supply + + preset-gpio: + description: panel reset pin + + pvddio-gpio: + description: panel vddio pin + + treset-gpio: + description: touch reset pin + +required: + - compatible + - reg + - preset-gpio + - pvddio-gpio + - treset-gpio + - avdd-supply + - vddio-supply + - vsn-supply + - vsp-supply + - tvdd-supply + +additionalProperties: false + +examples: + - | + #include + + dsi { + #address-cells = <1>; + #size-cells = <0>; + panel: panel@0 { + reg = <0>; + + pvddio-gpio = <&tlmm 51 GPIO_ACTIVE_HIGH>; + preset-gpio = <&tlmm 8 GPIO_ACTIVE_HIGH>; + treset-gpio = <&tlmm 89 GPIO_ACTIVE_HIGH>; + + vddio-supply = <&pm8994_s4>; + avdd-supply = <&pm8994_l2>; + tvdd-supply = <&panel_tvdd>; + + backlight = <&pmi8994_wled>; + + port { + panel_in: endpoint { + remote-endpoint = <&dsi0_out>; + }; + }; + }; + }; From patchwork Tue May 25 11:31:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 12278563 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABE90C2B9F8 for ; Tue, 25 May 2021 11:39:09 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7706C6128D for ; Tue, 25 May 2021 11:39:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7706C6128D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=somainline.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E9E1D6E9FA; Tue, 25 May 2021 11:39:05 +0000 (UTC) X-Greylist: delayed 461 seconds by postgrey-1.36 at gabe; Tue, 25 May 2021 11:39:04 UTC Received: from m-r1.th.seeweb.it (m-r1.th.seeweb.it [IPv6:2001:4b7a:2000:18::170]) by gabe.freedesktop.org (Postfix) with ESMTPS id 52EC56E9F6 for ; Tue, 25 May 2021 11:39:00 +0000 (UTC) Received: from localhost.localdomain (83.6.168.54.neoplus.adsl.tpnet.pl [83.6.168.54]) by m-r1.th.seeweb.it (Postfix) with ESMTPA id 8402A2042B; Tue, 25 May 2021 13:31:17 +0200 (CEST) From: Konrad Dybcio To: ~postmarketos/upstreaming@lists.sr.ht Subject: [PATCH 2/2] drm/panel: Add support for SONY JDI Synaptics panel Date: Tue, 25 May 2021 13:31:03 +0200 Message-Id: <20210525113105.52990-2-konrad.dybcio@somainline.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210525113105.52990-1-konrad.dybcio@somainline.org> References: <20210525113105.52990-1-konrad.dybcio@somainline.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, David Airlie , Konrad Dybcio , linux-kernel@vger.kernel.org, jamipkettunen@somainline.org, Rob Herring , Thierry Reding , martin.botka@somainline.org, dri-devel@lists.freedesktop.org, angelogioacchino.delregno@somainline.org, marijn.suijten@somainline.org, Sam Ravnborg Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: AngeloGioacchino Del Regno This commit adds support for Synaptics+JDI display panels used in SONY Xperia X, X Compact, X Performance, XZ and XZs smartphones. Due to the nature of phone manufacturing, it is impossible to retrieve the actual panel names, hence the replacement ones, detailing the devices they are used on. Co-developed-by: Konrad Dybcio Signed-off-by: AngeloGioacchino Del Regno Signed-off-by: Konrad Dybcio --- drivers/gpu/drm/panel/Kconfig | 10 + drivers/gpu/drm/panel/Makefile | 1 + .../gpu/drm/panel/panel-sony-synaptics-jdi.c | 511 ++++++++++++++++++ 3 files changed, 522 insertions(+) create mode 100644 drivers/gpu/drm/panel/panel-sony-synaptics-jdi.c diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig index 47a3348acfc6..ac76cca2947e 100644 --- a/drivers/gpu/drm/panel/Kconfig +++ b/drivers/gpu/drm/panel/Kconfig @@ -514,6 +514,16 @@ config DRM_PANEL_SONY_ACX565AKM Say Y here if you want to enable support for the Sony ACX565AKM 800x600 3.5" panel (found on the Nokia N900). +config DRM_PANEL_SONY_SYNAPTICS_JDI + tristate "SONY Synaptics JDI panel" + depends on OF + depends on DRM_MIPI_DSI + depends on BACKLIGHT_CLASS_DEVICE + help + Say Y here if you want to enable support for Synaptics+JDI hybrid + in-cell 720x1280/1080x1920 up-to 120Hz panels found in some SONY + Xperia X, X Performance, X Compact, XZ and XZs devices. + config DRM_PANEL_TDO_TL070WSH30 tristate "TDO TL070WSH30 DSI panel" depends on OF diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile index 2fca73ba06cb..70ad719ec712 100644 --- a/drivers/gpu/drm/panel/Makefile +++ b/drivers/gpu/drm/panel/Makefile @@ -53,6 +53,7 @@ obj-$(CONFIG_DRM_PANEL_SITRONIX_ST7703) += panel-sitronix-st7703.o obj-$(CONFIG_DRM_PANEL_SITRONIX_ST7789V) += panel-sitronix-st7789v.o obj-$(CONFIG_DRM_PANEL_SONY_ACX424AKP) += panel-sony-acx424akp.o obj-$(CONFIG_DRM_PANEL_SONY_ACX565AKM) += panel-sony-acx565akm.o +obj-$(CONFIG_DRM_PANEL_SONY_SYNAPTICS_JDI) += panel-sony-synaptics-jdi.o obj-$(CONFIG_DRM_PANEL_TDO_TL070WSH30) += panel-tdo-tl070wsh30.o obj-$(CONFIG_DRM_PANEL_TPO_TD028TTEC1) += panel-tpo-td028ttec1.o obj-$(CONFIG_DRM_PANEL_TPO_TD043MTEA1) += panel-tpo-td043mtea1.o diff --git a/drivers/gpu/drm/panel/panel-sony-synaptics-jdi.c b/drivers/gpu/drm/panel/panel-sony-synaptics-jdi.c new file mode 100644 index 000000000000..2b1972dea58a --- /dev/null +++ b/drivers/gpu/drm/panel/panel-sony-synaptics-jdi.c @@ -0,0 +1,511 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2021 AngeloGioacchino Del Regno + * Copyright (C) 2021 Konrad Dybcio + * + * Parameters from dsi-panel-somc-synaptics-jdi-1080p-cmd.dtsi + * and dsi-panel-somc-synaptics-jdi-720p-cmd.dtsi from SONY stock kernel. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +enum synaptics_jdi_type { + TYPE_FHD60HZ_SONY_KAGURA, + TYPE_FHD60HZ_SONY_SUZU, + TYPE_HD60HZ_SONY_KUGO, +}; + +struct synaptics_jdi_panel_desc { + const struct drm_display_mode *mode; + enum synaptics_jdi_type type; +}; + +struct synaptics_jdi_panel { + struct drm_panel base; + struct mipi_dsi_device *dsi; + + struct backlight_device *backlight; + + struct regulator_bulk_data supplies[5]; + + struct gpio_desc *pan_reset_gpio; + struct gpio_desc *ts_reset_gpio; + + bool prepared; + bool enabled; + + const struct synaptics_jdi_panel_desc *desc; +}; + +/* FHD panel initialization sequences */ +static const u8 cmd_on1[2] = {0xB0, 0x00}; +static const u8 cmd_on2[2] = {0xD6, 0x01}; +static const u8 cmd_on3[3] = {0xC4, 0x70, 0x03}; +static const u8 cmd_on4[27] = { + 0xED, 0x27, 0x31, 0x2F, 0x13, 0x00, 0x6A, 0x99, + 0x03, 0x17, 0x91, 0xF2, 0x00, 0x00, 0x03, 0x14, + 0x17, 0x3F, 0x14, 0x12, 0x26, 0x23, 0x00, 0x20, + 0x00, 0x00, 0x57 +}; +static const u8 cmd_on5[27] = { + 0xEE, 0x13, 0x61, 0x5F, 0x09, 0x00, 0x6A, 0x99, + 0x03, 0x00, 0x01, 0xB2, 0x00, 0x00, 0x03, 0x00, + 0x00, 0x33, 0x14, 0x12, 0x00, 0x21, 0x00, 0x20, + 0x00, 0x00, 0x57 +}; +static const u8 cmd_on6[27] = { + 0xEF, 0x27, 0x31, 0x2F, 0x13, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x14, + 0x17, 0x0F, 0x14, 0x00, 0x00, 0x20, 0x00, 0x00, + 0x00, 0x00, 0xA6 +}; +static const u8 cmd_on7[27] = { + 0xF0, 0xE3, 0x07, 0x73, 0xDF, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE3, 0x00, + 0x00, 0x03, 0x14, 0x00, 0x00, 0x20, 0x00, 0x00, + 0x00, 0x00, 0xA7 +}; +static const u8 cmd_on8[2] = {0x35, 0x00}; +static const u8 cmd_on9[2] = {0x36, 0x00}; +static const u8 cmd_on10[2] = {0x3A, 0x77}; +static const u8 cmd_on11[5] = {0x2A, 0x00, 0x00, 0x04, 0x37}; +static const u8 cmd_on12[5] = {0x2B, 0x00, 0x00, 0x07, 0x7F}; +static const u8 cmd_on13[3] = {0x44, 0x00, 0x00}; +static const u8 cmd_off_unk4[14] = { + 0xEC, 0x64, 0xDC, 0x7A, 0x7A, 0x3D, 0x00, 0x0B, + 0x0B, 0x13, 0x15, 0x68, 0x0B, 0x95, +}; + +/* HD panel initialization sequences */ +static const u8 cmd_on4_hd[14] = { + 0xEC, 0x64, 0xDC, 0x7A, 0x7A, 0x3D, 0x00, 0x0B, + 0x0B, 0x13, 0x15, 0x68, 0x0B, 0xB5, +}; +static const u8 cmd_on5_hd[2] = {0xB0, 0x03}; +static const u8 cmd_on6_hd[2] = {0x35, 0x00}; +static const u8 cmd_on7_hd[2] = {0x36, 0x00}; +static const u8 cmd_on8_hd[2] = {0x3A, 0x77}; +static const u8 cmd_on9_hd[5] = {0x2A, 0x00, 0x00, 0x02, 0xCF}; +static const u8 cmd_on10_hd[5] = {0x2B, 0x00, 0x00, 0x04, 0xFF}; +static const u8 cmd_on11_hd[3] = {0x44, 0x00, 0x00}; + +static inline struct synaptics_jdi_panel *to_synaptics_jdi_panel(struct drm_panel *panel) +{ + return container_of(panel, struct synaptics_jdi_panel, base); +} + +static int synaptics_jdi_panel_enable(struct drm_panel *panel) +{ + struct synaptics_jdi_panel *synaptics_jdi_panel = to_synaptics_jdi_panel(panel); + + if (synaptics_jdi_panel->enabled) + return 0; + + synaptics_jdi_panel->enabled = true; + + return 0; +} + +static int synaptics_jdi_panel_init(struct synaptics_jdi_panel *synaptics_jdi_panel) +{ + synaptics_jdi_panel->dsi->mode_flags |= MIPI_DSI_MODE_LPM; + + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on1, sizeof(cmd_on1)); + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on2, sizeof(cmd_on2)); + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on3, sizeof(cmd_on3)); + + if (synaptics_jdi_panel->desc->type == TYPE_HD60HZ_SONY_KUGO) { + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on4_hd, sizeof(cmd_on4_hd)); + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on5_hd, sizeof(cmd_on5_hd)); + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on6_hd, sizeof(cmd_on6_hd)); + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on7_hd, sizeof(cmd_on7_hd)); + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on8_hd, sizeof(cmd_on8_hd)); + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on9_hd, sizeof(cmd_on9_hd)); + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on10_hd, sizeof(cmd_on10_hd)); + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on11_hd, sizeof(cmd_on11_hd)); + } else { + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on4, sizeof(cmd_on4)); + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on5, sizeof(cmd_on5)); + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on6, sizeof(cmd_on6)); + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on7, sizeof(cmd_on7)); + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on8, sizeof(cmd_on8)); + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on9, sizeof(cmd_on9)); + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on10, sizeof(cmd_on10)); + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on11, sizeof(cmd_on11)); + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on12, sizeof(cmd_on12)); + mipi_dsi_generic_write(synaptics_jdi_panel->dsi, cmd_on13, sizeof(cmd_on13)); + } + + mipi_dsi_dcs_exit_sleep_mode(synaptics_jdi_panel->dsi); + + msleep(120); + + return 0; +} + +static int synaptics_jdi_panel_on(struct synaptics_jdi_panel *synaptics_jdi_panel) +{ + struct device *dev = &synaptics_jdi_panel->dsi->dev; + int ret = 0; + + ret = mipi_dsi_dcs_set_display_on(synaptics_jdi_panel->dsi); + if (ret < 0) { + dev_err(dev, "Cannot send disp on cmd: %d\n", ret); + return ret; + } + + msleep(120); + + return ret; +} + +static int synaptics_jdi_panel_disable(struct drm_panel *panel) +{ + struct synaptics_jdi_panel *synaptics_jdi_panel = to_synaptics_jdi_panel(panel); + + if (!synaptics_jdi_panel->enabled) + return 0; + + synaptics_jdi_panel->enabled = false; + + return 0; +} + +static int synaptics_jdi_panel_off(struct synaptics_jdi_panel *synaptics_jdi_panel) +{ + struct device *dev = &synaptics_jdi_panel->dsi->dev; + int ret = 0; + + synaptics_jdi_panel->dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; + + ret = mipi_dsi_dcs_set_display_off(synaptics_jdi_panel->dsi); + if (ret < 0) + dev_err(dev, "Cannot set display off: %d\n", ret); + + ret = mipi_dsi_dcs_enter_sleep_mode(synaptics_jdi_panel->dsi); + if (ret < 0) + dev_err(dev, "Cannot enter sleep mode: %d\n", ret); + + msleep(100); + + return ret; +} + +static int synaptics_jdi_panel_unprepare(struct drm_panel *panel) +{ + struct synaptics_jdi_panel *synaptics_jdi_panel = to_synaptics_jdi_panel(panel); + + if (!synaptics_jdi_panel->prepared) + return 0; + + if (synaptics_jdi_panel->ts_reset_gpio) { + gpiod_set_value(synaptics_jdi_panel->ts_reset_gpio, 0); + usleep_range(10000, 11000); + } + + synaptics_jdi_panel_off(synaptics_jdi_panel); + + regulator_bulk_disable(ARRAY_SIZE(synaptics_jdi_panel->supplies), + synaptics_jdi_panel->supplies); + + if (synaptics_jdi_panel->pan_reset_gpio) { + gpiod_set_value(synaptics_jdi_panel->pan_reset_gpio, 0); + usleep_range(10000, 11000); + } + + synaptics_jdi_panel->prepared = false; + + return 0; +} + +static int synaptics_jdi_panel_prepare(struct drm_panel *panel) +{ + struct synaptics_jdi_panel *synaptics_jdi_panel = to_synaptics_jdi_panel(panel); + struct device *dev = &synaptics_jdi_panel->dsi->dev; + int ret = 0; + + if (synaptics_jdi_panel->prepared) + return 0; + + /* Power rail VDDIO -> in-cell panel main */ + ret = regulator_enable(synaptics_jdi_panel->supplies[0].consumer); + if (ret < 0) + return ret; + + msleep(80); + + /* Power rail AVDD -> in-cell touch-controller main */ + ret = regulator_enable(synaptics_jdi_panel->supplies[1].consumer); + if (ret < 0) + dev_err(dev, "Cannot enable AVDD: %d\n", ret); + else + usleep_range(1000, 1100); + + ret = regulator_enable(synaptics_jdi_panel->supplies[3].consumer); + if (ret < 0) { + dev_err(dev, "Cannot enable VSP: %d\n", ret); + goto poweroff_s1; + } + + ret = regulator_enable(synaptics_jdi_panel->supplies[4].consumer); + if (ret < 0) { + dev_err(dev, "Cannot enable VSN: %d\n", ret); + goto poweroff_s1; + } + + /* Enable the in-cell supply to panel */ + ret = regulator_enable(synaptics_jdi_panel->supplies[2].consumer); + if (ret < 0) { + dev_err(dev, "Cannot enable TVDD: %d\n", ret); + goto poweroff_s1; + } else { + usleep_range(1000, 1100); + } + + if (synaptics_jdi_panel->ts_reset_gpio) + gpiod_set_value(synaptics_jdi_panel->ts_reset_gpio, 1); + + if (synaptics_jdi_panel->pan_reset_gpio) { + gpiod_set_value(synaptics_jdi_panel->pan_reset_gpio, 0); + usleep_range(10000, 11000); + gpiod_set_value(synaptics_jdi_panel->pan_reset_gpio, 1); + usleep_range(10000, 11000); + }; + + ret = synaptics_jdi_panel_init(synaptics_jdi_panel); + if (ret < 0) { + dev_err(dev, "Cannot initialize panel: %d\n", ret); + goto poweroff_s2; + } + + ret = synaptics_jdi_panel_on(synaptics_jdi_panel); + if (ret < 0) { + dev_err(dev, "Cannot poweron panel: %d\n", ret); + goto poweroff_s2; + } + + synaptics_jdi_panel->prepared = true; + + return 0; + +poweroff_s2: + /* Disable tvdd to avoid current/voltage spikes in the enable path */ + regulator_disable(synaptics_jdi_panel->supplies[2].consumer); +poweroff_s1: + regulator_disable(synaptics_jdi_panel->supplies[1].consumer); + regulator_disable(synaptics_jdi_panel->supplies[0].consumer); + + return ret; +} + +static const struct drm_display_mode fhd60hz_suzu_mode = { + .clock = 149506, + .hdisplay = 1080, + .hsync_start = 1080 + 56, + .hsync_end = 1080 + 56 + 8, + .htotal = 1080 + 56 + 8 + 8, + .vdisplay = 1920, + .vsync_start = 1920 + 227, + .vsync_end = 1920 + 227 + 8, + .vtotal = 1920 + 227 + 8 + 8, + .width_mm = 61, + .height_mm = 110, +}; + +static const struct synaptics_jdi_panel_desc fhd60hz_suzu = { + .mode = &fhd60hz_suzu_mode, + .type = TYPE_FHD60HZ_SONY_SUZU, +}; + +static const struct drm_display_mode fhd60hz_kagura_mode = { + .clock = 149506, + .hdisplay = 1080, + .hsync_start = 1080 + 56, + .hsync_end = 1080 + 56 + 8, + .htotal = 1080 + 56 + 8 + 8, + .vdisplay = 1920, + .vsync_start = 1920 + 227, + .vsync_end = 1920 + 227 + 8, + .vtotal = 1920 + 227 + 8 + 8, + .width_mm = 64, + .height_mm = 114, +}; + +static const struct synaptics_jdi_panel_desc fhd60hz_kagura = { + .mode = &fhd60hz_kagura_mode, + .type = TYPE_FHD60HZ_SONY_KAGURA, +}; + +static const struct drm_display_mode hd60hz_kugo_mode = { + .clock = 149506, + .hdisplay = 720, + .hsync_start = 720 + 20, + .hsync_end = 720 + 20 + 8, + .htotal = 720 + 20 + 8 + 8, + .vdisplay = 1280, + .vsync_start = 1280 + 2000, + .vsync_end = 1280 + 2000 + 8, + .vtotal = 1280 + 2000 + 8 + 8, + .width_mm = 56, + .height_mm = 100, +}; + +static const struct synaptics_jdi_panel_desc hd60hz_kugo = { + .mode = &hd60hz_kugo_mode, + .type = TYPE_HD60HZ_SONY_KUGO, +}; + +static int synaptics_jdi_panel_get_modes(struct drm_panel *panel, + struct drm_connector *connector) +{ + struct synaptics_jdi_panel *ctx = container_of(panel, struct synaptics_jdi_panel, base); + struct drm_display_mode *mode; + + mode = drm_mode_duplicate(connector->dev, ctx->desc->mode); + if (!mode) + return -ENOMEM; + + drm_mode_set_name(mode); + + mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED; + connector->display_info.width_mm = mode->width_mm; + connector->display_info.height_mm = mode->height_mm; + drm_mode_probed_add(connector, mode); + + return 1; +} + +static const struct drm_panel_funcs synaptics_jdi_panel_funcs = { + .disable = synaptics_jdi_panel_disable, + .unprepare = synaptics_jdi_panel_unprepare, + .prepare = synaptics_jdi_panel_prepare, + .enable = synaptics_jdi_panel_enable, + .get_modes = synaptics_jdi_panel_get_modes, +}; + +static const struct of_device_id synaptics_jdi_of_match[] = { + { .compatible = "sony,synaptics-jdi-dora", .data = &fhd60hz_suzu }, + { .compatible = "sony,synaptics-jdi-kagura", .data = &fhd60hz_kagura }, + { .compatible = "sony,synaptics-jdi-keyaki", .data = &fhd60hz_kagura }, + { .compatible = "sony,synaptics-jdi-kugo", .data = &hd60hz_kugo }, + { .compatible = "sony,synaptics-jdi-suzu", .data = &fhd60hz_suzu }, + { } +}; +MODULE_DEVICE_TABLE(of, synaptics_jdi_of_match); + +static int synaptics_jdi_panel_add(struct synaptics_jdi_panel *synaptics_jdi_panel) +{ + struct device *dev = &synaptics_jdi_panel->dsi->dev; + int ret = 0; + + synaptics_jdi_panel->supplies[0].supply = "vddio"; + synaptics_jdi_panel->supplies[1].supply = "avdd"; + synaptics_jdi_panel->supplies[2].supply = "tvdd"; + synaptics_jdi_panel->supplies[3].supply = "vsp"; + synaptics_jdi_panel->supplies[4].supply = "vsn"; + + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(synaptics_jdi_panel->supplies), + synaptics_jdi_panel->supplies); + + synaptics_jdi_panel->pan_reset_gpio = devm_gpiod_get(dev, "preset", GPIOD_ASIS); + if (IS_ERR(synaptics_jdi_panel->pan_reset_gpio)) { + dev_err(dev, "cannot get preset-gpio: %ld\n", + PTR_ERR(synaptics_jdi_panel->pan_reset_gpio)); + synaptics_jdi_panel->pan_reset_gpio = NULL; + } + + synaptics_jdi_panel->ts_reset_gpio = devm_gpiod_get(dev, "treset", GPIOD_ASIS); + if (IS_ERR(synaptics_jdi_panel->ts_reset_gpio)) { + dev_err(dev, "cannot get treset-gpio: %ld\n", + PTR_ERR(synaptics_jdi_panel->ts_reset_gpio)); + synaptics_jdi_panel->ts_reset_gpio = NULL; + } + + drm_panel_init(&synaptics_jdi_panel->base, &synaptics_jdi_panel->dsi->dev, + &synaptics_jdi_panel_funcs, DRM_MODE_CONNECTOR_DSI); + + drm_panel_add(&synaptics_jdi_panel->base); + + return ret; +} + +static void synaptics_jdi_panel_del(struct synaptics_jdi_panel *synaptics_jdi_panel) +{ + if (synaptics_jdi_panel->base.dev) + drm_panel_remove(&synaptics_jdi_panel->base); +} + +static int synaptics_jdi_panel_probe(struct mipi_dsi_device *dsi) +{ + struct synaptics_jdi_panel *synaptics_jdi_panel; + int ret; + + dsi->lanes = 4; + dsi->format = MIPI_DSI_FMT_RGB888; + dsi->mode_flags = MIPI_DSI_CLOCK_NON_CONTINUOUS; + + synaptics_jdi_panel = devm_kzalloc(&dsi->dev, sizeof(*synaptics_jdi_panel), GFP_KERNEL); + if (!synaptics_jdi_panel) + return -ENOMEM; + + mipi_dsi_set_drvdata(dsi, synaptics_jdi_panel); + synaptics_jdi_panel->dsi = dsi; + synaptics_jdi_panel->desc = of_device_get_match_data(&dsi->dev); + + ret = synaptics_jdi_panel_add(synaptics_jdi_panel); + if (ret < 0) + return ret; + + return mipi_dsi_attach(dsi); +} + +static int synaptics_jdi_panel_remove(struct mipi_dsi_device *dsi) +{ + struct synaptics_jdi_panel *synaptics_jdi_panel = mipi_dsi_get_drvdata(dsi); + struct device *dev = &synaptics_jdi_panel->dsi->dev; + int ret; + + ret = synaptics_jdi_panel_disable(&synaptics_jdi_panel->base); + if (ret < 0) + dev_err(dev, "failed to disable panel: %d\n", ret); + + ret = mipi_dsi_detach(dsi); + if (ret < 0) + dev_err(dev, "Cannot detach from DSI host: %d\n", ret); + + synaptics_jdi_panel_del(synaptics_jdi_panel); + + return 0; +} + +static void synaptics_jdi_panel_shutdown(struct mipi_dsi_device *dsi) +{ + struct synaptics_jdi_panel *synaptics_jdi_panel = mipi_dsi_get_drvdata(dsi); + + synaptics_jdi_panel_disable(&synaptics_jdi_panel->base); +} + +static struct mipi_dsi_driver synaptics_jdi_panel_driver = { + .driver = { + .name = "panel-sony-synaptics-jdi", + .of_match_table = synaptics_jdi_of_match, + }, + .probe = synaptics_jdi_panel_probe, + .remove = synaptics_jdi_panel_remove, + .shutdown = synaptics_jdi_panel_shutdown, +}; +module_mipi_dsi_driver(synaptics_jdi_panel_driver); + +MODULE_AUTHOR("AngeloGioacchino Del Regno "); +MODULE_AUTHOR("Konrad Dybcio "); +MODULE_DESCRIPTION("SONY Synaptics JDI panel driver"); +MODULE_LICENSE("GPL v2");