From patchwork Mon Feb 1 10:37:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iskren Chernev X-Patchwork-Id: 374348 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 E209DC433E6 for ; Mon, 1 Feb 2021 10:39:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF4EB64E98 for ; Mon, 1 Feb 2021 10:39:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233289AbhBAKjl (ORCPT ); Mon, 1 Feb 2021 05:39:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233281AbhBAKjF (ORCPT ); Mon, 1 Feb 2021 05:39:05 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A36F9C0617A7; Mon, 1 Feb 2021 02:37:49 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id f16so12169817wmq.5; Mon, 01 Feb 2021 02:37:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Y4HDfAIXn4csaJdLWtNsEmq7IQCGJl8To6HPJWasocw=; b=KDyMx9ldojQIM8AwkDVYF8F1ETlxUKunw92WGM4JluCVPQT9YLW+qKb3DCCNyzOIEw NP4PtcLXRr3lHSJyC1yTWAfnHvtTD4Ap/wDHG6AdbHLck8aVffJXZlWGdeKoOq1aPjjm d5YIQa99intc7jlL6wVD4JMbtMmRYvYSl47idsrQEFyuIhjgewEewXTLXYIBcQVAkVI4 0Nx0wYogCKbwJzV0llHwUADc9lRSDCmM0cDD4i3/1sQ5Y1KPaKmvzpC0/TDtwYzoip+M sXRexM2tIl1DLv3NpYQcfeQ/Q0R5RPGe51z6W+/6ThTyRf3Zxff+5AeviBAEyHHMO/K1 QZlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Y4HDfAIXn4csaJdLWtNsEmq7IQCGJl8To6HPJWasocw=; b=RXcIsz/vxiJOOBNsXRDtVLMRAtrdeS4D06+OFCsVn8J0h2i/+zDUvY0jveYdEZ+6tA m0FRIjO9TEzIySzBSyIf7q5yH+Y40Eg7S/5+4FjUKWfTMjEAdTaVSB/pAJnWglQLG5OK ILiR7NSThfxhye/ZoMvcavPOEtGATt/WeTnExuex3oWxLgjfglm8EhrS9jFmBKXQ5+wg 4v8mHPuUjiMQrgyM+qOieicRC905JtodcK/9klyDsM994LOtcRIzla6h3VavcNZw87IE 8pMDNxJhujSs4X+gB6eiMjaVHM4W0EG6fmHkV/+QnJ/m1W7fqfB40DjWb0e8jJBRWjfR bBzQ== X-Gm-Message-State: AOAM533xbFXyoECD6GIreUhvPHQPQTVgK5/Al6aBU6biPRH+/EC7WpFo JWMNkqT0Lztlw4DMFs1xcVL9j3KsHTg= X-Google-Smtp-Source: ABdhPJwnmYdI8hHeNi9Yhcx2VLE+xn7/xCz3CN08L3cPwx5ZZ0HUnj7/Ym4SfDktzPrKQoBLNeqXzQ== X-Received: by 2002:a7b:c76e:: with SMTP id x14mr1297910wmk.17.1612175868447; Mon, 01 Feb 2021 02:37:48 -0800 (PST) Received: from localhost (178-169-161-196.razgrad.ddns.bulsat.com. [178.169.161.196]) by smtp.gmail.com with ESMTPSA id m18sm2243760wmq.1.2021.02.01.02.37.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 01 Feb 2021 02:37:47 -0800 (PST) From: Iskren Chernev To: Rob Herring , Sam Ravnborg , Thierry Reding Cc: Daniel Vetter , David Airlie , devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, phone-devel@vger.kernel.org, Iskren Chernev Subject: [PATCH v2 1/2] dt-bindings: panel: Add Samsung S6E3FA2 panel Date: Mon, 1 Feb 2021 12:37:10 +0200 Message-Id: <20210201103712.1619585-1-iskren.chernev@gmail.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The Samsung S6E3FA2 AMOLED cmd LCD panel is used on the Samsung Galaxy S5 (klte). Signed-off-by: Iskren Chernev --- OK, miraculously the panel turns on and off now, so the simple-panel can graduate into its own driver. v1: https://lkml.org/lkml/2020/12/30/293 Changes in v2: - move bindings to separate file, add 2 regulators - add standalone panel driver .../display/panel/samsung,s6e3fa2.yaml | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Documentation/devicetree/bindings/display/panel/samsung,s6e3fa2.yaml base-commit: fd821bf0ed9a7db09d2e007df697f4d9ecfda99a -- 2.30.0 diff --git a/Documentation/devicetree/bindings/display/panel/samsung,s6e3fa2.yaml b/Documentation/devicetree/bindings/display/panel/samsung,s6e3fa2.yaml new file mode 100644 index 000000000000..a759150bd539 --- /dev/null +++ b/Documentation/devicetree/bindings/display/panel/samsung,s6e3fa2.yaml @@ -0,0 +1,62 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/display/panel/samsung,s6e3fa2.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Samsung s6e3fa2 AMOLED CMD LCD panel + +maintainers: + - Iskren Chernev + +allOf: + - $ref: panel-common.yaml# + +properties: + compatible: + const: samsung,s6e3fa2 + + reg: true + reset-gpios: true + port: true + + iovdd-supply: + description: IOVDD regulator + + vddr-supply: + description: VDDR regulator + +required: + - compatible + - reset-gpios + - iovdd-supply + - vddr-supply + - port + +unevaluatedProperties: false + +examples: + - | + /* from Samsung Galaxy S5 klte */ + dsi@fd922800 { + #address-cells = <1>; + #size-cells = <0>; + + panel@0 { + compatible = "samsung,s6e3fa2"; + reg = <0>; + + reset-gpios = <&pma8084_gpios 17 GPIO_ACTIVE_LOW>; + + iovdd-supply = <&pma8084_lvs4>; + vddr-supply = <&vreg_panel>; + + port { + panel_in: endpoint { + remote-endpoint = <&dsi0_out>; + }; + }; + }; + }; + +... From patchwork Mon Feb 1 10:37:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iskren Chernev X-Patchwork-Id: 374346 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=-17.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=ham 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 1A975C43381 for ; Mon, 1 Feb 2021 10:40:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E23B564EC2 for ; Mon, 1 Feb 2021 10:40:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233316AbhBAKkM (ORCPT ); Mon, 1 Feb 2021 05:40:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233089AbhBAKjq (ORCPT ); Mon, 1 Feb 2021 05:39:46 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01F6FC0617AB; Mon, 1 Feb 2021 02:37:53 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id l12so16015373wry.2; Mon, 01 Feb 2021 02:37:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OmPc4zcSXEy2/eeYGH36lorcsfTfPG91Lw81KNJajcA=; b=C4mXFPf39ImTCBnzfOjZNH5r4HKYJOKaxfdo1bNjV1To+sSEF91Ahx8y95w6cdNTEf gSQUlc2wKWVduhCQ3QdJoiHM4GrPXX/TXLHpnqCRTcwOL+IMAQ0NVk2Rjxln6DshiuhI AITf59XzBQNiojkNJIJjUGPjzb1sbAWZtMenvhtacJMtFGx7trpG42E6vFaCgXOE7nf+ eaKBtcTUSoRs3tM5sE6yMD/bbGAnT7o/2w8C5r05UrCGr+p3USnDbNUd8Zjk2CEfvzE5 azZ+noK2BUqIe8v52k1aapgrU6MG9KIi0Cwio+jrscpNvvjU6ApZIzqhSGOxgLfx6G3w vfbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OmPc4zcSXEy2/eeYGH36lorcsfTfPG91Lw81KNJajcA=; b=rY6CeVXyPetFaRdTI0TNjiFaZnK/I5rV7CfreLUDdMUs2KaIwdJivFh2M1DpbdyLbK ip9QyMwax3KWaScjuLCxvE5DKpy8cPrOoGWmirq5+b1XZk7sU9whqmVTA7JxQnEQdbTo u5a/gfnNKVjGd3C2cROMD7WnayYP7u44z8yCvkUbPorIrN9yh2AAu4yXtP/A44GptF8T 3/rLwSKJffYGFgh4eNZk67777mFgWHpV/Vwk3d/azvYITcdXsQ+AQxsTubOaaNRDouy+ Tv4FZJhNWEqergHUNMsFMcbgeOgLqu7oDDnxBrOND20adhXBbOqowSqaOG7LllPuCSyW KljA== X-Gm-Message-State: AOAM531kwy7IwmBalkIwntIW0OKM5ftmY5WFEhzwr4QwwMPuRDs68j83 fbMjWAMzPqhrJnJI+/pUryKh8SrgWXqTdw== X-Google-Smtp-Source: ABdhPJxiFGNpPtafIwIOGhVl9svv3Qp1sSvVIc9JNGaYoZe/GEEXz6VugVcBfE4hV2CuH5JWMU9QFA== X-Received: by 2002:adf:f4c1:: with SMTP id h1mr17506522wrp.102.1612175871760; Mon, 01 Feb 2021 02:37:51 -0800 (PST) Received: from localhost (178-169-161-196.razgrad.ddns.bulsat.com. [178.169.161.196]) by smtp.gmail.com with ESMTPSA id i6sm27066021wrs.71.2021.02.01.02.37.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 01 Feb 2021 02:37:50 -0800 (PST) From: Iskren Chernev To: Rob Herring , Sam Ravnborg , Thierry Reding Cc: Daniel Vetter , David Airlie , devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, phone-devel@vger.kernel.org, Iskren Chernev Subject: [PATCH v2 2/2] drm/panel: Add panel for Samsung Galaxy S5 Date: Mon, 1 Feb 2021 12:37:11 +0200 Message-Id: <20210201103712.1619585-2-iskren.chernev@gmail.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210201103712.1619585-1-iskren.chernev@gmail.com> References: <20210201103712.1619585-1-iskren.chernev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The Samsung Galaxy S5 uses the samsung s6e3fa2 AMOLED cmd LCD panel. This driver was generated with [1], with the addition of mipi_dsi_dcs_set_display_on at the end of the on method. [1] https://github.com/msm8916-mainline/linux-mdss-dsi-panel-driver-generator Signed-off-by: Iskren Chernev --- drivers/gpu/drm/panel/Kconfig | 6 + drivers/gpu/drm/panel/Makefile | 1 + drivers/gpu/drm/panel/panel-samsung-s6e3fa2.c | 299 ++++++++++++++++++ 3 files changed, 306 insertions(+) create mode 100644 drivers/gpu/drm/panel/panel-samsung-s6e3fa2.c diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig index 4894913936e9..82dff2afd5f1 100644 --- a/drivers/gpu/drm/panel/Kconfig +++ b/drivers/gpu/drm/panel/Kconfig @@ -348,6 +348,12 @@ config DRM_PANEL_SAMSUNG_S6D16D0 depends on DRM_MIPI_DSI select VIDEOMODE_HELPERS +config DRM_PANEL_SAMSUNG_S6E3FA2 + tristate "Samsung S6E3FA2 DSI video mode panel" + depends on OF + depends on DRM_MIPI_DSI + select VIDEOMODE_HELPERS + config DRM_PANEL_SAMSUNG_S6E3HA2 tristate "Samsung S6E3HA2 DSI video mode panel" depends on OF diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile index cae4d976c069..87d3f76f050e 100644 --- a/drivers/gpu/drm/panel/Makefile +++ b/drivers/gpu/drm/panel/Makefile @@ -35,6 +35,7 @@ obj-$(CONFIG_DRM_PANEL_RAYDIUM_RM68200) += panel-raydium-rm68200.o obj-$(CONFIG_DRM_PANEL_RONBO_RB070D30) += panel-ronbo-rb070d30.o obj-$(CONFIG_DRM_PANEL_SAMSUNG_LD9040) += panel-samsung-ld9040.o obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6D16D0) += panel-samsung-s6d16d0.o +obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E3FA2) += panel-samsung-s6e3fa2.o obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E3HA2) += panel-samsung-s6e3ha2.o obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E63J0X03) += panel-samsung-s6e63j0x03.o obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E63M0) += panel-samsung-s6e63m0.o diff --git a/drivers/gpu/drm/panel/panel-samsung-s6e3fa2.c b/drivers/gpu/drm/panel/panel-samsung-s6e3fa2.c new file mode 100644 index 000000000000..8985fccf9792 --- /dev/null +++ b/drivers/gpu/drm/panel/panel-samsung-s6e3fa2.c @@ -0,0 +1,299 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// Copyright (c) 2021 Iskren Chernev +// Generated with linux-mdss-dsi-panel-driver-generator from vendor device tree: +// Copyright (c) 2021, The Linux Foundation. All rights reserved. + +#include +#include +#include +#include +#include + +#include +#include +#include + +struct samsung_s6e3fa2 { + struct drm_panel panel; + struct mipi_dsi_device *dsi; + struct regulator_bulk_data supplies[2]; + struct gpio_desc *reset_gpio; + bool prepared; +}; + +static inline +struct samsung_s6e3fa2 *to_samsung_s6e3fa2(struct drm_panel *panel) +{ + return container_of(panel, struct samsung_s6e3fa2, panel); +} + +#define dsi_generic_write_seq(dsi, seq...) do { \ + static const u8 d[] = { seq }; \ + int ret; \ + ret = mipi_dsi_generic_write(dsi, d, ARRAY_SIZE(d)); \ + if (ret < 0) \ + return ret; \ + } while (0) + +#define dsi_dcs_write_seq(dsi, seq...) do { \ + static const u8 d[] = { seq }; \ + int ret; \ + ret = mipi_dsi_dcs_write_buffer(dsi, d, ARRAY_SIZE(d)); \ + if (ret < 0) \ + return ret; \ + } while (0) + +static void samsung_s6e3fa2_reset(struct samsung_s6e3fa2 *ctx) +{ + gpiod_set_value_cansleep(ctx->reset_gpio, 0); + usleep_range(5000, 6000); + gpiod_set_value_cansleep(ctx->reset_gpio, 1); + usleep_range(5000, 6000); + gpiod_set_value_cansleep(ctx->reset_gpio, 0); + usleep_range(7000, 8000); +} + +static int samsung_s6e3fa2_on(struct samsung_s6e3fa2 *ctx) +{ + struct mipi_dsi_device *dsi = ctx->dsi; + struct device *dev = &dsi->dev; + int ret; + + dsi->mode_flags |= MIPI_DSI_MODE_LPM; + + dsi_generic_write_seq(dsi, 0xf0, 0x5a, 0x5a); + dsi_generic_write_seq(dsi, 0xfc, 0x5a, 0x5a); + dsi_dcs_write_seq(dsi, 0xf2); + dsi_dcs_write_seq(dsi, 0xf9); + usleep_range(5000, 6000); + + ret = mipi_dsi_dcs_exit_sleep_mode(dsi); + if (ret < 0) { + dev_err(dev, "Failed to exit sleep mode: %d\n", ret); + return ret; + } + msleep(20); + + dsi_generic_write_seq(dsi, 0xca, + 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, + 0x00); + dsi_generic_write_seq(dsi, 0xb2, 0x00, 0x0e, 0x00, 0x0e); + dsi_generic_write_seq(dsi, 0xb6, + 0x98, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, + 0x55, 0x54, 0x20, 0x00, 0x0a, 0xaa, 0xaf, 0x0f, + 0x02, 0x22, 0x22, 0x10); + dsi_generic_write_seq(dsi, 0xb5, 0x41); + dsi_generic_write_seq(dsi, 0xf7, 0x03); + dsi_generic_write_seq(dsi, 0xf7, 0x00); + dsi_generic_write_seq(dsi, 0xb0, 0x02); + dsi_generic_write_seq(dsi, 0xfd, 0x0a); + dsi_generic_write_seq(dsi, 0xfe, 0x80); + dsi_generic_write_seq(dsi, 0xfe, 0x00); + dsi_generic_write_seq(dsi, 0x35, 0x00); + dsi_generic_write_seq(dsi, 0xbd, 0x05, 0x02, 0x02); + dsi_generic_write_seq(dsi, 0xf0, 0xa5, 0xa5); + dsi_generic_write_seq(dsi, 0xfc, 0xa5, 0xa5); + + ret = mipi_dsi_dcs_set_display_on(dsi); + if (ret < 0) { + dev_err(dev, "Failed to set display on: %d\n", ret); + return ret; + } + + return 0; +} + +static int samsung_s6e3fa2_off(struct samsung_s6e3fa2 *ctx) +{ + struct mipi_dsi_device *dsi = ctx->dsi; + struct device *dev = &dsi->dev; + int ret; + + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; + + ret = mipi_dsi_dcs_set_display_off(dsi); + if (ret < 0) { + dev_err(dev, "Failed to set display off: %d\n", ret); + return ret; + } + usleep_range(10000, 11000); + + ret = mipi_dsi_dcs_enter_sleep_mode(dsi); + if (ret < 0) { + dev_err(dev, "Failed to enter sleep mode: %d\n", ret); + return ret; + } + msleep(120); + + return 0; +} + +static int samsung_s6e3fa2_prepare(struct drm_panel *panel) +{ + struct samsung_s6e3fa2 *ctx = to_samsung_s6e3fa2(panel); + struct device *dev = &ctx->dsi->dev; + int ret; + + if (ctx->prepared) + return 0; + + ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies); + if (ret < 0) { + dev_err(dev, "Failed to enable regulators: %d\n", ret); + return ret; + } + + samsung_s6e3fa2_reset(ctx); + + ret = samsung_s6e3fa2_on(ctx); + if (ret < 0) { + dev_err(dev, "Failed to initialize panel: %d\n", ret); + gpiod_set_value_cansleep(ctx->reset_gpio, 1); + regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies); + return ret; + } + + ctx->prepared = true; + return 0; +} + +static int samsung_s6e3fa2_unprepare(struct drm_panel *panel) +{ + struct samsung_s6e3fa2 *ctx = to_samsung_s6e3fa2(panel); + struct device *dev = &ctx->dsi->dev; + int ret; + + if (!ctx->prepared) + return 0; + + ret = samsung_s6e3fa2_off(ctx); + if (ret < 0) + dev_err(dev, "Failed to un-initialize panel: %d\n", ret); + + gpiod_set_value_cansleep(ctx->reset_gpio, 1); + regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies); + + ctx->prepared = false; + return 0; +} + +static const struct drm_display_mode samsung_s6e3fa2_mode = { + .clock = (1080 + 162 + 10 + 36) * (1920 + 13 + 2 + 3) * 60 / 1000, + .hdisplay = 1080, + .hsync_start = 1080 + 162, + .hsync_end = 1080 + 162 + 10, + .htotal = 1080 + 162 + 10 + 36, + .vdisplay = 1920, + .vsync_start = 1920 + 13, + .vsync_end = 1920 + 13 + 2, + .vtotal = 1920 + 13 + 2 + 3, + .width_mm = 65, + .height_mm = 115, +}; + +static int samsung_s6e3fa2_get_modes(struct drm_panel *panel, + struct drm_connector *connector) +{ + struct drm_display_mode *mode; + + mode = drm_mode_duplicate(connector->dev, &samsung_s6e3fa2_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 samsung_s6e3fa2_panel_funcs = { + .prepare = samsung_s6e3fa2_prepare, + .unprepare = samsung_s6e3fa2_unprepare, + .get_modes = samsung_s6e3fa2_get_modes, +}; + +static int samsung_s6e3fa2_probe(struct mipi_dsi_device *dsi) +{ + struct device *dev = &dsi->dev; + struct samsung_s6e3fa2 *ctx; + int ret; + + ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + ctx->supplies[0].supply = "iovdd"; + ctx->supplies[1].supply = "vddr"; + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ctx->supplies), + ctx->supplies); + if (ret < 0) + return dev_err_probe(dev, ret, "Failed to get regulators\n"); + + ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(ctx->reset_gpio)) + return dev_err_probe(dev, PTR_ERR(ctx->reset_gpio), + "Failed to get reset-gpios\n"); + + ctx->dsi = dsi; + mipi_dsi_set_drvdata(dsi, ctx); + + dsi->lanes = 4; + dsi->format = MIPI_DSI_FMT_RGB888; + dsi->mode_flags = MIPI_DSI_MODE_VIDEO_BURST | + MIPI_DSI_CLOCK_NON_CONTINUOUS; + + drm_panel_init(&ctx->panel, dev, &samsung_s6e3fa2_panel_funcs, + DRM_MODE_CONNECTOR_DSI); + + drm_panel_add(&ctx->panel); + + ret = mipi_dsi_attach(dsi); + if (ret < 0) { + dev_err(dev, "Failed to attach to DSI host: %d\n", ret); + drm_panel_remove(&ctx->panel); + return ret; + } + + return 0; +} + +static int samsung_s6e3fa2_remove(struct mipi_dsi_device *dsi) +{ + struct samsung_s6e3fa2 *ctx = mipi_dsi_get_drvdata(dsi); + int ret; + + ret = mipi_dsi_detach(dsi); + if (ret < 0) + dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n", ret); + + drm_panel_remove(&ctx->panel); + + return 0; +} + +static const struct of_device_id samsung_s6e3fa2_of_match[] = { + { .compatible = "samsung,s6e3fa2" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, samsung_s6e3fa2_of_match); + +static struct mipi_dsi_driver samsung_s6e3fa2_driver = { + .probe = samsung_s6e3fa2_probe, + .remove = samsung_s6e3fa2_remove, + .driver = { + .name = "panel-samsung-s6e3fa2", + .of_match_table = samsung_s6e3fa2_of_match, + }, +}; +module_mipi_dsi_driver(samsung_s6e3fa2_driver); + +MODULE_AUTHOR("Iskren Chernev "); +MODULE_DESCRIPTION("DRM driver for samsung,s6e3fa2 panel"); +MODULE_LICENSE("GPL v2");