Message ID | 20230521-drm-panels-sony-v1-8-541c341d6bee@somainline.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1059238vqo; Sun, 21 May 2023 14:24:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5VjEch+s8cv2gxlS4tjJfi+GSdd3+dE/zqHg+AJpZw3SvXDXqTEHdTO9ORqlVB3AQC8zjm X-Received: by 2002:a05:6a00:1995:b0:64d:277c:4ab2 with SMTP id d21-20020a056a00199500b0064d277c4ab2mr13171145pfl.24.1684704279387; Sun, 21 May 2023 14:24:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684704279; cv=none; d=google.com; s=arc-20160816; b=I49tigBAALwGPkdFqPqPcXDpH46bmUTdKNXMNTHiavskTg6uhhhL4cAKj0X9M7kgGb mBcl55JQwkz1qu1mK5nwhCPM/NdetbTNafxP7FpeEvtCem24TojJnZYx3Hc9Y9p7he2C 1dJAzucOgKQjqvDvuF0l0B2zGAhGB2DR+sImCUurfrpFpXGKnxc7G5/ArW0sYsY+sZpC zmkABh/tXcygPxl3BWXAvxvisRWpVNJYwCyaxJIBCgVJpo8MaYBDzANYs5Tn3zuikP4K vHZprjUZBTGUq76z9dcExBtuV9lOHwFWI1BDY/aNOEQGQ2CO0d6vmt/xX1pd5+Nd8mgk OUMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from; bh=eiy1LL4UNmeOCH2pL3jb5thZbB2eWIGJthLi1vguzV0=; b=Xc1CoxobkhqthKjzjSpJ6PPBqrHFcW8vd2XRUxK+KHTX7ufUC9dLdt8+jSCI0HsQh/ MaGaBwmEdK8asWlTF/pTxZfikI1/SOwmHVSeK9v+92ZS22z+9EAjGEXJQ8jd+XN9omOb Lv23xjzYvQ2cCp6qhVGMUyz1GK6ogkqttnLh4rcSv/3JLQuRDaF1+OocAFd4Qxd+PvS2 4no+Zw7mLFvYl0eMmOOHLXsXbtIz0U2KKGR32YNYcBIqQFf/pkKN3pjNd71299PsNWyE qBokBLSqGgLjTfr+wxZO2ns55BsG7CHoJigwUwYefhy0L4WTJbZUUJtaDribgttB1CXK Ox4w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p186-20020a6229c3000000b0063b82909b1esi1970115pfp.0.2023.05.21.14.24.27; Sun, 21 May 2023 14:24:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229999AbjEUVXp (ORCPT <rfc822;cscallsign@gmail.com> + 99 others); Sun, 21 May 2023 17:23:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231150AbjEUVXV (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 21 May 2023 17:23:21 -0400 Received: from relay05.th.seeweb.it (relay05.th.seeweb.it [5.144.164.166]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A3DA10E for <linux-kernel@vger.kernel.org>; Sun, 21 May 2023 14:23:18 -0700 (PDT) Received: from Marijn-Arch-PC.localdomain (94-211-6-86.cable.dynamic.v4.ziggo.nl [94.211.6.86]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by m-r2.th.seeweb.it (Postfix) with ESMTPSA id 000A83F360; Sun, 21 May 2023 23:23:15 +0200 (CEST) From: Marijn Suijten <marijn.suijten@somainline.org> Date: Sun, 21 May 2023 23:23:10 +0200 Subject: [PATCH RFC 08/10] drm/panel/samsung-sofef03: Add panel driver for Sony Xperia 5 II MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230521-drm-panels-sony-v1-8-541c341d6bee@somainline.org> References: <20230521-drm-panels-sony-v1-0-541c341d6bee@somainline.org> In-Reply-To: <20230521-drm-panels-sony-v1-0-541c341d6bee@somainline.org> To: Neil Armstrong <neil.armstrong@linaro.org>, Sam Ravnborg <sam@ravnborg.org>, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>, Caleb Connolly <caleb@connolly.tech>, Rob Herring <robh+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Conor Dooley <conor+dt@kernel.org>, Andy Gross <agross@kernel.org>, Bjorn Andersson <andersson@kernel.org> Cc: ~postmarketos/upstreaming@lists.sr.ht, AngeloGioacchino Del Regno <angelogioacchino.delregno@somainline.org>, Konrad Dybcio <konrad.dybcio@linaro.org>, Martin Botka <martin.botka@somainline.org>, Jami Kettunen <jami.kettunen@somainline.org>, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, Dmitry Baryshkov <dmitry.baryshkov@linaro.org>, Abhinav Kumar <quic_abhinavk@quicinc.com>, Kuogee Hsieh <quic_khsieh@quicinc.com>, Jessica Zhang <quic_jesszhan@quicinc.com>, Marijn Suijten <marijn.suijten@somainline.org>, Konrad Dybcio <konrad.dybcio@somainline.org> X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766540474402159977?= X-GMAIL-MSGID: =?utf-8?q?1766540474402159977?= |
Series |
drm/panel: Drivers for four Sony CMD-mode (and DSC) panels
|
|
Commit Message
Marijn Suijten
May 21, 2023, 9:23 p.m. UTC
The SOFEF03-M Display-IC paired with an unknown panel in the Sony Xperia
5 II always uses Display Stream Compression 1.1 and features a 60hz and
120hz refresh-rate mode.
Co-developed-by: Konrad Dybcio <konrad.dybcio@somainline.org>
Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org>
---
drivers/gpu/drm/panel/Kconfig | 14 +
drivers/gpu/drm/panel/Makefile | 1 +
drivers/gpu/drm/panel/panel-samsung-sofef03.c | 423 ++++++++++++++++++++++++++
3 files changed, 438 insertions(+)
Comments
On 22/05/2023 00:23, Marijn Suijten wrote: > The SOFEF03-M Display-IC paired with an unknown panel in the Sony Xperia > 5 II always uses Display Stream Compression 1.1 and features a 60hz and > 120hz refresh-rate mode. > > Co-developed-by: Konrad Dybcio <konrad.dybcio@somainline.org> Konrad's S-o-b is also required then > Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org> > --- > drivers/gpu/drm/panel/Kconfig | 14 + > drivers/gpu/drm/panel/Makefile | 1 + > drivers/gpu/drm/panel/panel-samsung-sofef03.c | 423 ++++++++++++++++++++++++++ > 3 files changed, 438 insertions(+) > > diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig > index 3f11e9906f2cb..8e2668153bce2 100644 > --- a/drivers/gpu/drm/panel/Kconfig > +++ b/drivers/gpu/drm/panel/Kconfig > @@ -630,6 +630,20 @@ config DRM_PANEL_SAMSUNG_SOFEF01 > > This panel features a fixed mode of 1080x2520@60. > > +config DRM_PANEL_SAMSUNG_SOFEF03 > + tristate "Samsung sofef03 Sony Xperia 5 II DSI cmd mode panel" > + depends on GPIOLIB > + depends on OF > + depends on DRM_MIPI_DSI > + depends on BACKLIGHT_CLASS_DEVICE > + help > + Say Y or M here if you want to enable support for the Samsung AMOLED > + command mode panel found in the Sony Xperia 5 II smartphone. > + > + This panel uses Display Stream Compression 1.1. > + > + The panel features a 1080x2520@60 and 1080x2520@120 mode. > + > config DRM_PANEL_SEIKO_43WVF1G > tristate "Seiko 43WVF1G panel" > depends on OF > diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile > index a4039d0fc9cfb..52dcd82e33120 100644 > --- a/drivers/gpu/drm/panel/Makefile > +++ b/drivers/gpu/drm/panel/Makefile > @@ -63,6 +63,7 @@ obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E88A0_AMS452EF01) += panel-samsung-s6e88a0-ams4 > obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E8AA0) += panel-samsung-s6e8aa0.o > obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF00) += panel-samsung-sofef00.o > obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF01) += panel-samsung-sofef01.o > +obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF03) += panel-samsung-sofef03.o > obj-$(CONFIG_DRM_PANEL_SEIKO_43WVF1G) += panel-seiko-43wvf1g.o > obj-$(CONFIG_DRM_PANEL_SHARP_LQ101R1SX01) += panel-sharp-lq101r1sx01.o > obj-$(CONFIG_DRM_PANEL_SHARP_LS037V7DW01) += panel-sharp-ls037v7dw01.o > diff --git a/drivers/gpu/drm/panel/panel-samsung-sofef03.c b/drivers/gpu/drm/panel/panel-samsung-sofef03.c > new file mode 100644 > index 0000000000000..2763e1c56b37b > --- /dev/null > +++ b/drivers/gpu/drm/panel/panel-samsung-sofef03.c > @@ -0,0 +1,423 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright (c) 2022 Konrad Dybcio <konrad.dybcio@linaro.org> > + * Copyright (c) 2023 Marijn Suijten <marijn.suijten@somainline.org> > + */ > + > +#include <linux/backlight.h> > +#include <linux/delay.h> > +#include <linux/gpio/consumer.h> > +#include <linux/module.h> > +#include <linux/of.h> > +#include <linux/regulator/consumer.h> > + > +#include <video/mipi_display.h> > + > +#include <drm/drm_mipi_dsi.h> > +#include <drm/drm_modes.h> > +#include <drm/drm_panel.h> > +#include <drm/drm_probe_helper.h> > +#include <drm/display/drm_dsc.h> > +#include <drm/display/drm_dsc_helper.h> > + > +static const bool enable_120hz = true; > + > +struct samsung_sofef03_m { > + struct drm_panel panel; > + struct mipi_dsi_device *dsi; > + struct regulator *vddio, *vci; > + struct gpio_desc *reset_gpio; > + bool prepared; > +}; > + > +static inline struct samsung_sofef03_m *to_samsung_sofef03_m(struct drm_panel *panel) > +{ > + return container_of(panel, struct samsung_sofef03_m, panel); > +} > + > +static void samsung_sofef03_m_reset(struct samsung_sofef03_m *ctx) > +{ > + gpiod_set_value_cansleep(ctx->reset_gpio, 0); > + usleep_range(10000, 11000); > +} > + > +static int samsung_sofef03_m_on(struct samsung_sofef03_m *ctx) > +{ > + struct mipi_dsi_device *dsi = ctx->dsi; > + struct device *dev = &dsi->dev; > + int ret; > + > + dsi->mode_flags |= MIPI_DSI_MODE_LPM; > + > + mipi_dsi_dcs_write_seq(dsi, 0x9d, 0x01); > + > + ret = mipi_dsi_dcs_exit_sleep_mode(dsi); > + if (ret < 0) { > + dev_err(dev, "Failed to exit sleep mode: %d\n", ret); > + return ret; > + } > + usleep_range(10000, 11000); > + > + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); > + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x09); > + mipi_dsi_dcs_write_seq(dsi, 0xd5, 0x00, 0x00, 0x00); > + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x08); > + mipi_dsi_dcs_write_seq(dsi, 0xee, 0x00, 0x00); > + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); > + > + ret = mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK); > + if (ret < 0) { > + dev_err(dev, "Failed to set tear on: %d\n", ret); > + return ret; > + } > + > + ret = mipi_dsi_dcs_set_column_address(dsi, 0, 1080 - 1); > + if (ret < 0) { > + dev_err(dev, "Failed to set column address: %d\n", ret); > + return ret; > + } > + > + ret = mipi_dsi_dcs_set_page_address(dsi, 0, 2520 - 1); > + if (ret < 0) { > + dev_err(dev, "Failed to set page address: %d\n", ret); > + return ret; > + } > + > + ret = mipi_dsi_dcs_set_display_brightness_large(dsi, 100); > + if (ret < 0) { > + dev_err(dev, "Failed to set display brightness: %d\n", ret); > + return ret; > + } > + > + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); > + mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x83); > + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x01); > + mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x01); > + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x02); > + mipi_dsi_dcs_write_seq(dsi, 0xec, 0x02, 0x00, 0x1c, 0x1c); > + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x0c); > + mipi_dsi_dcs_write_seq(dsi, 0xec, 0x01, 0x19); > + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); > + mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_WRITE_CONTROL_DISPLAY, BIT(5)); > + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); > + mipi_dsi_dcs_write_seq(dsi, 0xc2, 0x2d, 0x27); > + mipi_dsi_dcs_write_seq(dsi, 0x60, enable_120hz ? 0x10 : 0x00); > + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); > + msleep(110); > + > + ret = mipi_dsi_dcs_set_display_on(dsi); > + if (ret < 0) { > + dev_err(dev, "Failed to turn display on: %d\n", ret); > + return ret; > + } > + > + return 0; > +} > + > +static int samsung_sofef03_m_off(struct samsung_sofef03_m *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 turn display off: %d\n", ret); > + return ret; > + } > + msleep(20); > + > + 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(100); > + > + return 0; > +} > + > +static int samsung_sofef03_m_prepare(struct drm_panel *panel) > +{ > + struct samsung_sofef03_m *ctx = to_samsung_sofef03_m(panel); > + struct drm_dsc_picture_parameter_set pps; > + struct device *dev = &ctx->dsi->dev; > + int ret; > + > + if (ctx->prepared) > + return 0; > + > + ret = regulator_enable(ctx->vddio); > + if (ret < 0) { > + dev_err(dev, "Failed to enable vddio regulator: %d\n", ret); > + return ret; > + } > + > + ret = regulator_enable(ctx->vci); > + if (ret < 0) { > + dev_err(dev, "Failed to enable vci regulator: %d\n", ret); > + regulator_disable(ctx->vddio); > + return ret; > + } > + > + samsung_sofef03_m_reset(ctx); > + > + ret = samsung_sofef03_m_on(ctx); > + if (ret < 0) { > + dev_err(dev, "Failed to initialize panel: %d\n", ret); > + goto fail; > + } > + > + if (ctx->dsi->dsc) { Always true > + drm_dsc_pps_payload_pack(&pps, ctx->dsi->dsc); > + > + ret = mipi_dsi_picture_parameter_set(ctx->dsi, &pps); > + if (ret < 0) { > + dev_err(dev, "failed to transmit PPS: %d\n", ret); > + goto fail; > + } > + > + ret = mipi_dsi_compression_mode(ctx->dsi, true); > + if (ret < 0) { > + dev_err(dev, "Failed to enable compression mode: %d\n", ret); > + goto fail; > + } > + > + msleep(28); > + } > + > + ctx->prepared = true; > + return 0; > + > +fail: > + gpiod_set_value_cansleep(ctx->reset_gpio, 1); > + regulator_disable(ctx->vci); > + regulator_disable(ctx->vddio); > + return ret; > +} > + > +static int samsung_sofef03_m_unprepare(struct drm_panel *panel) > +{ > + struct samsung_sofef03_m *ctx = to_samsung_sofef03_m(panel); > + struct device *dev = &ctx->dsi->dev; > + int ret; > + > + if (!ctx->prepared) > + return 0; > + > + ret = samsung_sofef03_m_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_disable(ctx->vci); > + regulator_disable(ctx->vddio); > + > + ctx->prepared = false; > + return 0; > +} > + > +static const struct drm_display_mode samsung_sofef03_m_60hz_mode = { > + .clock = (1080 + 156 + 8 + 8) * (2520 + 2393 + 8 + 8) * 60 / 1000, > + .hdisplay = 1080, > + .hsync_start = 1080 + 156, > + .hsync_end = 1080 + 156 + 8, > + .htotal = 1080 + 156 + 8 + 8, > + .vdisplay = 2520, > + .vsync_start = 2520 + 2393, > + .vsync_end = 2520 + 2393 + 8, > + .vtotal = 2520 + 2393 + 8 + 8, > + .width_mm = 61, > + .height_mm = 142, > +}; > + > +static const struct drm_display_mode samsung_sofef03_m_120hz_mode = { > + .clock = (1080 + 56 + 8 + 8) * (2520 + 499 + 8 + 8) * 120 / 1000, > + .hdisplay = 1080, > + .hsync_start = 1080 + 56, > + .hsync_end = 1080 + 56 + 8, > + .htotal = 1080 + 56 + 8 + 8, > + .vdisplay = 2520, > + .vsync_start = 2520 + 499, > + .vsync_end = 2520 + 499 + 8, > + .vtotal = 2520 + 499 + 8 + 8, > + .width_mm = 61, > + .height_mm = 142, > +}; > + > +static int samsung_sofef03_m_get_modes(struct drm_panel *panel, > + struct drm_connector *connector) > +{ > + if (enable_120hz) Is it possible to switch between these modes at runtime? It might be logical to define 60 Hz mode as preferred, while allowing users to switch to 120 Hz when required for some reason. > + return drm_connector_helper_get_modes_fixed(connector, > + &samsung_sofef03_m_120hz_mode); > + else > + return drm_connector_helper_get_modes_fixed(connector, > + &samsung_sofef03_m_60hz_mode); > +} > + > +static const struct drm_panel_funcs samsung_sofef03_m_panel_funcs = { > + .prepare = samsung_sofef03_m_prepare, > + .unprepare = samsung_sofef03_m_unprepare, > + .get_modes = samsung_sofef03_m_get_modes, > +}; > + > +static int samsung_sofef03_m_bl_update_status(struct backlight_device *bl) > +{ > + struct mipi_dsi_device *dsi = bl_get_data(bl); > + u16 brightness = backlight_get_brightness(bl); > + int ret; > + > + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; > + > + pr_err("Writing %#x\n", brightness); > + > + ret = mipi_dsi_dcs_set_display_brightness_large(dsi, brightness); > + if (ret < 0) > + return ret; > + > + dsi->mode_flags |= MIPI_DSI_MODE_LPM; > + > + return 0; > +} > + > +static int samsung_sofef03_m_bl_get_brightness(struct backlight_device *bl) > +{ > + struct mipi_dsi_device *dsi = bl_get_data(bl); > + u16 brightness; > + int ret; > + > + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; > + > + ret = mipi_dsi_dcs_get_display_brightness_large(dsi, &brightness); > + if (ret < 0) > + return ret; > + > + dsi->mode_flags |= MIPI_DSI_MODE_LPM; > + > + pr_err("Read display brightness %#x\n", brightness); > + > + return brightness; > +} > + > +static const struct backlight_ops samsung_sofef03_m_bl_ops = { > + .update_status = samsung_sofef03_m_bl_update_status, > + .get_brightness = samsung_sofef03_m_bl_get_brightness, > +}; > + > +static struct backlight_device * > +samsung_sofef03_m_create_backlight(struct mipi_dsi_device *dsi) > +{ > + struct device *dev = &dsi->dev; > + const struct backlight_properties props = { > + .type = BACKLIGHT_RAW, > + .brightness = 100, > + .max_brightness = 1023, > + }; > + > + return devm_backlight_device_register(dev, dev_name(dev), dev, dsi, > + &samsung_sofef03_m_bl_ops, &props); > +} > + > +static int samsung_sofef03_m_probe(struct mipi_dsi_device *dsi) > +{ > + struct device *dev = &dsi->dev; > + struct drm_dsc_config *dsc; > + struct samsung_sofef03_m *ctx; > + int ret; > + > + ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); > + if (!ctx) > + return -ENOMEM; > + > + ctx->vddio = devm_regulator_get(dev, "vddio"); > + if (IS_ERR(ctx->vddio)) > + return dev_err_probe(dev, PTR_ERR(ctx->vddio), > + "Failed to get vddio regulator\n"); > + > + ctx->vci = devm_regulator_get(dev, "vci"); > + if (IS_ERR(ctx->vci)) > + return dev_err_probe(dev, PTR_ERR(ctx->vci), > + "Failed to get vci regulator\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_CLOCK_NON_CONTINUOUS; > + > + drm_panel_init(&ctx->panel, dev, &samsung_sofef03_m_panel_funcs, > + DRM_MODE_CONNECTOR_DSI); > + > + ctx->panel.backlight = samsung_sofef03_m_create_backlight(dsi); > + if (IS_ERR(ctx->panel.backlight)) > + return dev_err_probe(dev, PTR_ERR(ctx->panel.backlight), > + "Failed to create backlight\n"); > + > + drm_panel_add(&ctx->panel); > + > + /* This panel only supports DSC; unconditionally enable it */ > + dsi->dsc = dsc = devm_kzalloc(&dsi->dev, sizeof(*dsc), GFP_KERNEL); Double assignment > + if (!dsc) > + return -ENOMEM; > + > + dsc->dsc_version_major = 1; > + dsc->dsc_version_minor = 1; > + > + dsc->slice_height = 30; > + dsc->slice_width = 540; > + dsc->slice_count = 2; > + dsc->bits_per_component = 8; > + dsc->bits_per_pixel = 8 << 4; /* 4 fractional bits */ > + dsc->block_pred_enable = true; > + > + 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 void samsung_sofef03_m_remove(struct mipi_dsi_device *dsi) > +{ > + struct samsung_sofef03_m *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); > +} > + > +static const struct of_device_id samsung_sofef03_m_of_match[] = { > + { .compatible = "samsung,sofef03-m" }, > + { /* sentinel */ } > +}; > +MODULE_DEVICE_TABLE(of, samsung_sofef03_m_of_match); > + > +static struct mipi_dsi_driver samsung_sofef03_m_driver = { > + .probe = samsung_sofef03_m_probe, > + .remove = samsung_sofef03_m_remove, > + .driver = { > + .name = "panel-samsung-sofef03-m", > + .of_match_table = samsung_sofef03_m_of_match, > + }, > +}; > +module_mipi_dsi_driver(samsung_sofef03_m_driver); > + > +MODULE_AUTHOR("Konrad Dybcio <konrad.dybcio@linaro.org>"); > +MODULE_AUTHOR("Marijn Suijten <marijn.suijten@somainline.org>"); > +MODULE_DESCRIPTION("DRM panel driver for Samsung SOFEF03-M Display-IC panels"); > +MODULE_LICENSE("GPL"); >
On 22/05/2023 03:23, Dmitry Baryshkov wrote: > On 22/05/2023 00:23, Marijn Suijten wrote: >> The SOFEF03-M Display-IC paired with an unknown panel in the Sony Xperia >> 5 II always uses Display Stream Compression 1.1 and features a 60hz and >> 120hz refresh-rate mode. >> >> Co-developed-by: Konrad Dybcio <konrad.dybcio@somainline.org> > > Konrad's S-o-b is also required then > >> Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org> >> --- >> drivers/gpu/drm/panel/Kconfig | 14 + >> drivers/gpu/drm/panel/Makefile | 1 + >> drivers/gpu/drm/panel/panel-samsung-sofef03.c | 423 ++++++++++++++++++++++++++ >> 3 files changed, 438 insertions(+) >> >> diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig >> index 3f11e9906f2cb..8e2668153bce2 100644 >> --- a/drivers/gpu/drm/panel/Kconfig >> +++ b/drivers/gpu/drm/panel/Kconfig >> @@ -630,6 +630,20 @@ config DRM_PANEL_SAMSUNG_SOFEF01 >> This panel features a fixed mode of 1080x2520@60. >> +config DRM_PANEL_SAMSUNG_SOFEF03 >> + tristate "Samsung sofef03 Sony Xperia 5 II DSI cmd mode panel" >> + depends on GPIOLIB >> + depends on OF >> + depends on DRM_MIPI_DSI >> + depends on BACKLIGHT_CLASS_DEVICE >> + help >> + Say Y or M here if you want to enable support for the Samsung AMOLED >> + command mode panel found in the Sony Xperia 5 II smartphone. >> + >> + This panel uses Display Stream Compression 1.1. >> + >> + The panel features a 1080x2520@60 and 1080x2520@120 mode. >> + >> config DRM_PANEL_SEIKO_43WVF1G >> tristate "Seiko 43WVF1G panel" >> depends on OF >> diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile >> index a4039d0fc9cfb..52dcd82e33120 100644 >> --- a/drivers/gpu/drm/panel/Makefile >> +++ b/drivers/gpu/drm/panel/Makefile >> @@ -63,6 +63,7 @@ obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E88A0_AMS452EF01) += panel-samsung-s6e88a0-ams4 >> obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E8AA0) += panel-samsung-s6e8aa0.o >> obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF00) += panel-samsung-sofef00.o >> obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF01) += panel-samsung-sofef01.o >> +obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF03) += panel-samsung-sofef03.o >> obj-$(CONFIG_DRM_PANEL_SEIKO_43WVF1G) += panel-seiko-43wvf1g.o >> obj-$(CONFIG_DRM_PANEL_SHARP_LQ101R1SX01) += panel-sharp-lq101r1sx01.o >> obj-$(CONFIG_DRM_PANEL_SHARP_LS037V7DW01) += panel-sharp-ls037v7dw01.o >> diff --git a/drivers/gpu/drm/panel/panel-samsung-sofef03.c b/drivers/gpu/drm/panel/panel-samsung-sofef03.c >> new file mode 100644 >> index 0000000000000..2763e1c56b37b >> --- /dev/null >> +++ b/drivers/gpu/drm/panel/panel-samsung-sofef03.c >> @@ -0,0 +1,423 @@ >> +// SPDX-License-Identifier: GPL-2.0-only >> +/* >> + * Copyright (c) 2022 Konrad Dybcio <konrad.dybcio@linaro.org> >> + * Copyright (c) 2023 Marijn Suijten <marijn.suijten@somainline.org> >> + */ >> + >> +#include <linux/backlight.h> >> +#include <linux/delay.h> >> +#include <linux/gpio/consumer.h> >> +#include <linux/module.h> >> +#include <linux/of.h> >> +#include <linux/regulator/consumer.h> >> + >> +#include <video/mipi_display.h> >> + >> +#include <drm/drm_mipi_dsi.h> >> +#include <drm/drm_modes.h> >> +#include <drm/drm_panel.h> >> +#include <drm/drm_probe_helper.h> >> +#include <drm/display/drm_dsc.h> >> +#include <drm/display/drm_dsc_helper.h> >> + >> +static const bool enable_120hz = true; Maybe this can be a module parameter ? Can you explain why this can't be dynamically changed by a modeset ? >> + >> +struct samsung_sofef03_m { >> + struct drm_panel panel; >> + struct mipi_dsi_device *dsi; >> + struct regulator *vddio, *vci; >> + struct gpio_desc *reset_gpio; >> + bool prepared; >> +}; >> + >> +static inline struct samsung_sofef03_m *to_samsung_sofef03_m(struct drm_panel *panel) >> +{ >> + return container_of(panel, struct samsung_sofef03_m, panel); >> +} >> + >> +static void samsung_sofef03_m_reset(struct samsung_sofef03_m *ctx) >> +{ >> + gpiod_set_value_cansleep(ctx->reset_gpio, 0); >> + usleep_range(10000, 11000); >> +} >> + >> +static int samsung_sofef03_m_on(struct samsung_sofef03_m *ctx) >> +{ >> + struct mipi_dsi_device *dsi = ctx->dsi; >> + struct device *dev = &dsi->dev; >> + int ret; >> + >> + dsi->mode_flags |= MIPI_DSI_MODE_LPM; >> + >> + mipi_dsi_dcs_write_seq(dsi, 0x9d, 0x01); >> + >> + ret = mipi_dsi_dcs_exit_sleep_mode(dsi); >> + if (ret < 0) { >> + dev_err(dev, "Failed to exit sleep mode: %d\n", ret); >> + return ret; >> + } >> + usleep_range(10000, 11000); >> + >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); >> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x09); >> + mipi_dsi_dcs_write_seq(dsi, 0xd5, 0x00, 0x00, 0x00); >> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x08); >> + mipi_dsi_dcs_write_seq(dsi, 0xee, 0x00, 0x00); >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); >> + >> + ret = mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK); >> + if (ret < 0) { >> + dev_err(dev, "Failed to set tear on: %d\n", ret); >> + return ret; >> + } >> + >> + ret = mipi_dsi_dcs_set_column_address(dsi, 0, 1080 - 1); >> + if (ret < 0) { >> + dev_err(dev, "Failed to set column address: %d\n", ret); >> + return ret; >> + } >> + >> + ret = mipi_dsi_dcs_set_page_address(dsi, 0, 2520 - 1); >> + if (ret < 0) { >> + dev_err(dev, "Failed to set page address: %d\n", ret); >> + return ret; >> + } >> + >> + ret = mipi_dsi_dcs_set_display_brightness_large(dsi, 100); >> + if (ret < 0) { >> + dev_err(dev, "Failed to set display brightness: %d\n", ret); >> + return ret; >> + } >> + >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); >> + mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x83); >> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x01); >> + mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x01); >> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x02); >> + mipi_dsi_dcs_write_seq(dsi, 0xec, 0x02, 0x00, 0x1c, 0x1c); >> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x0c); >> + mipi_dsi_dcs_write_seq(dsi, 0xec, 0x01, 0x19); >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); >> + mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_WRITE_CONTROL_DISPLAY, BIT(5)); >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); >> + mipi_dsi_dcs_write_seq(dsi, 0xc2, 0x2d, 0x27); >> + mipi_dsi_dcs_write_seq(dsi, 0x60, enable_120hz ? 0x10 : 0x00); >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); >> + msleep(110); >> + >> + ret = mipi_dsi_dcs_set_display_on(dsi); >> + if (ret < 0) { >> + dev_err(dev, "Failed to turn display on: %d\n", ret); >> + return ret; >> + } >> + >> + return 0; >> +} >> + >> +static int samsung_sofef03_m_off(struct samsung_sofef03_m *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 turn display off: %d\n", ret); >> + return ret; >> + } >> + msleep(20); >> + >> + 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(100); >> + >> + return 0; >> +} >> + >> +static int samsung_sofef03_m_prepare(struct drm_panel *panel) >> +{ >> + struct samsung_sofef03_m *ctx = to_samsung_sofef03_m(panel); >> + struct drm_dsc_picture_parameter_set pps; >> + struct device *dev = &ctx->dsi->dev; >> + int ret; >> + >> + if (ctx->prepared) >> + return 0; >> + >> + ret = regulator_enable(ctx->vddio); >> + if (ret < 0) { >> + dev_err(dev, "Failed to enable vddio regulator: %d\n", ret); >> + return ret; >> + } >> + >> + ret = regulator_enable(ctx->vci); >> + if (ret < 0) { >> + dev_err(dev, "Failed to enable vci regulator: %d\n", ret); >> + regulator_disable(ctx->vddio); >> + return ret; >> + } >> + >> + samsung_sofef03_m_reset(ctx); >> + >> + ret = samsung_sofef03_m_on(ctx); >> + if (ret < 0) { >> + dev_err(dev, "Failed to initialize panel: %d\n", ret); >> + goto fail; >> + } >> + >> + if (ctx->dsi->dsc) { > > Always true > >> + drm_dsc_pps_payload_pack(&pps, ctx->dsi->dsc); >> + >> + ret = mipi_dsi_picture_parameter_set(ctx->dsi, &pps); >> + if (ret < 0) { >> + dev_err(dev, "failed to transmit PPS: %d\n", ret); >> + goto fail; >> + } >> + >> + ret = mipi_dsi_compression_mode(ctx->dsi, true); >> + if (ret < 0) { >> + dev_err(dev, "Failed to enable compression mode: %d\n", ret); >> + goto fail; >> + } >> + >> + msleep(28); >> + } >> + >> + ctx->prepared = true; >> + return 0; >> + >> +fail: >> + gpiod_set_value_cansleep(ctx->reset_gpio, 1); >> + regulator_disable(ctx->vci); >> + regulator_disable(ctx->vddio); >> + return ret; >> +} >> + >> +static int samsung_sofef03_m_unprepare(struct drm_panel *panel) >> +{ >> + struct samsung_sofef03_m *ctx = to_samsung_sofef03_m(panel); >> + struct device *dev = &ctx->dsi->dev; >> + int ret; >> + >> + if (!ctx->prepared) >> + return 0; >> + >> + ret = samsung_sofef03_m_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_disable(ctx->vci); >> + regulator_disable(ctx->vddio); >> + >> + ctx->prepared = false; >> + return 0; >> +} >> + >> +static const struct drm_display_mode samsung_sofef03_m_60hz_mode = { >> + .clock = (1080 + 156 + 8 + 8) * (2520 + 2393 + 8 + 8) * 60 / 1000, >> + .hdisplay = 1080, >> + .hsync_start = 1080 + 156, >> + .hsync_end = 1080 + 156 + 8, >> + .htotal = 1080 + 156 + 8 + 8, >> + .vdisplay = 2520, >> + .vsync_start = 2520 + 2393, >> + .vsync_end = 2520 + 2393 + 8, >> + .vtotal = 2520 + 2393 + 8 + 8, >> + .width_mm = 61, >> + .height_mm = 142, >> +}; >> + >> +static const struct drm_display_mode samsung_sofef03_m_120hz_mode = { >> + .clock = (1080 + 56 + 8 + 8) * (2520 + 499 + 8 + 8) * 120 / 1000, >> + .hdisplay = 1080, >> + .hsync_start = 1080 + 56, >> + .hsync_end = 1080 + 56 + 8, >> + .htotal = 1080 + 56 + 8 + 8, >> + .vdisplay = 2520, >> + .vsync_start = 2520 + 499, >> + .vsync_end = 2520 + 499 + 8, >> + .vtotal = 2520 + 499 + 8 + 8, >> + .width_mm = 61, >> + .height_mm = 142, >> +}; >> + >> +static int samsung_sofef03_m_get_modes(struct drm_panel *panel, >> + struct drm_connector *connector) >> +{ >> + if (enable_120hz) > > Is it possible to switch between these modes at runtime? It might be logical to define 60 Hz mode as preferred, while allowing users to switch to 120 Hz when required for some reason. > >> + return drm_connector_helper_get_modes_fixed(connector, >> + &samsung_sofef03_m_120hz_mode); >> + else >> + return drm_connector_helper_get_modes_fixed(connector, >> + &samsung_sofef03_m_60hz_mode); >> +} >> + >> +static const struct drm_panel_funcs samsung_sofef03_m_panel_funcs = { >> + .prepare = samsung_sofef03_m_prepare, >> + .unprepare = samsung_sofef03_m_unprepare, >> + .get_modes = samsung_sofef03_m_get_modes, >> +}; >> + >> +static int samsung_sofef03_m_bl_update_status(struct backlight_device *bl) >> +{ >> + struct mipi_dsi_device *dsi = bl_get_data(bl); >> + u16 brightness = backlight_get_brightness(bl); >> + int ret; >> + >> + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; >> + >> + pr_err("Writing %#x\n", brightness); You forgot to remove those desbug prints :-p >> + >> + ret = mipi_dsi_dcs_set_display_brightness_large(dsi, brightness); >> + if (ret < 0) >> + return ret; >> + >> + dsi->mode_flags |= MIPI_DSI_MODE_LPM; >> + >> + return 0; >> +} >> + >> +static int samsung_sofef03_m_bl_get_brightness(struct backlight_device *bl) >> +{ >> + struct mipi_dsi_device *dsi = bl_get_data(bl); >> + u16 brightness; >> + int ret; >> + >> + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; >> + >> + ret = mipi_dsi_dcs_get_display_brightness_large(dsi, &brightness); >> + if (ret < 0) >> + return ret; >> + >> + dsi->mode_flags |= MIPI_DSI_MODE_LPM; >> + >> + pr_err("Read display brightness %#x\n", brightness); Ditto >> + >> + return brightness; >> +} >> + >> +static const struct backlight_ops samsung_sofef03_m_bl_ops = { >> + .update_status = samsung_sofef03_m_bl_update_status, >> + .get_brightness = samsung_sofef03_m_bl_get_brightness, >> +}; >> + >> +static struct backlight_device * >> +samsung_sofef03_m_create_backlight(struct mipi_dsi_device *dsi) >> +{ >> + struct device *dev = &dsi->dev; >> + const struct backlight_properties props = { >> + .type = BACKLIGHT_RAW, >> + .brightness = 100, >> + .max_brightness = 1023, >> + }; >> + >> + return devm_backlight_device_register(dev, dev_name(dev), dev, dsi, >> + &samsung_sofef03_m_bl_ops, &props); >> +} >> + >> +static int samsung_sofef03_m_probe(struct mipi_dsi_device *dsi) >> +{ >> + struct device *dev = &dsi->dev; >> + struct drm_dsc_config *dsc; >> + struct samsung_sofef03_m *ctx; >> + int ret; >> + >> + ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); >> + if (!ctx) >> + return -ENOMEM; >> + >> + ctx->vddio = devm_regulator_get(dev, "vddio"); >> + if (IS_ERR(ctx->vddio)) >> + return dev_err_probe(dev, PTR_ERR(ctx->vddio), >> + "Failed to get vddio regulator\n"); >> + >> + ctx->vci = devm_regulator_get(dev, "vci"); >> + if (IS_ERR(ctx->vci)) >> + return dev_err_probe(dev, PTR_ERR(ctx->vci), >> + "Failed to get vci regulator\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_CLOCK_NON_CONTINUOUS; >> + >> + drm_panel_init(&ctx->panel, dev, &samsung_sofef03_m_panel_funcs, >> + DRM_MODE_CONNECTOR_DSI); >> + >> + ctx->panel.backlight = samsung_sofef03_m_create_backlight(dsi); >> + if (IS_ERR(ctx->panel.backlight)) >> + return dev_err_probe(dev, PTR_ERR(ctx->panel.backlight), >> + "Failed to create backlight\n"); >> + >> + drm_panel_add(&ctx->panel); >> + >> + /* This panel only supports DSC; unconditionally enable it */ >> + dsi->dsc = dsc = devm_kzalloc(&dsi->dev, sizeof(*dsc), GFP_KERNEL); > > Double assignment > >> + if (!dsc) >> + return -ENOMEM; >> + >> + dsc->dsc_version_major = 1; >> + dsc->dsc_version_minor = 1; >> + >> + dsc->slice_height = 30; >> + dsc->slice_width = 540; >> + dsc->slice_count = 2; >> + dsc->bits_per_component = 8; >> + dsc->bits_per_pixel = 8 << 4; /* 4 fractional bits */ >> + dsc->block_pred_enable = true; >> + >> + 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 void samsung_sofef03_m_remove(struct mipi_dsi_device *dsi) >> +{ >> + struct samsung_sofef03_m *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); >> +} >> + >> +static const struct of_device_id samsung_sofef03_m_of_match[] = { >> + { .compatible = "samsung,sofef03-m" }, >> + { /* sentinel */ } >> +}; >> +MODULE_DEVICE_TABLE(of, samsung_sofef03_m_of_match); >> + >> +static struct mipi_dsi_driver samsung_sofef03_m_driver = { >> + .probe = samsung_sofef03_m_probe, >> + .remove = samsung_sofef03_m_remove, >> + .driver = { >> + .name = "panel-samsung-sofef03-m", >> + .of_match_table = samsung_sofef03_m_of_match, >> + }, >> +}; >> +module_mipi_dsi_driver(samsung_sofef03_m_driver); >> + >> +MODULE_AUTHOR("Konrad Dybcio <konrad.dybcio@linaro.org>"); >> +MODULE_AUTHOR("Marijn Suijten <marijn.suijten@somainline.org>"); >> +MODULE_DESCRIPTION("DRM panel driver for Samsung SOFEF03-M Display-IC panels"); >> +MODULE_LICENSE("GPL"); >> >
On Mon, 22 May 2023 at 12:08, Neil Armstrong <neil.armstrong@linaro.org> wrote: > > On 22/05/2023 03:23, Dmitry Baryshkov wrote: > > On 22/05/2023 00:23, Marijn Suijten wrote: > >> The SOFEF03-M Display-IC paired with an unknown panel in the Sony Xperia > >> 5 II always uses Display Stream Compression 1.1 and features a 60hz and > >> 120hz refresh-rate mode. > >> > >> Co-developed-by: Konrad Dybcio <konrad.dybcio@somainline.org> > > > > Konrad's S-o-b is also required then > > > >> Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org> > >> --- > >> drivers/gpu/drm/panel/Kconfig | 14 + > >> drivers/gpu/drm/panel/Makefile | 1 + > >> drivers/gpu/drm/panel/panel-samsung-sofef03.c | 423 ++++++++++++++++++++++++++ > >> 3 files changed, 438 insertions(+) > >> > >> diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig > >> index 3f11e9906f2cb..8e2668153bce2 100644 > >> --- a/drivers/gpu/drm/panel/Kconfig > >> +++ b/drivers/gpu/drm/panel/Kconfig > >> @@ -630,6 +630,20 @@ config DRM_PANEL_SAMSUNG_SOFEF01 > >> This panel features a fixed mode of 1080x2520@60. > >> +config DRM_PANEL_SAMSUNG_SOFEF03 > >> + tristate "Samsung sofef03 Sony Xperia 5 II DSI cmd mode panel" > >> + depends on GPIOLIB > >> + depends on OF > >> + depends on DRM_MIPI_DSI > >> + depends on BACKLIGHT_CLASS_DEVICE > >> + help > >> + Say Y or M here if you want to enable support for the Samsung AMOLED > >> + command mode panel found in the Sony Xperia 5 II smartphone. > >> + > >> + This panel uses Display Stream Compression 1.1. > >> + > >> + The panel features a 1080x2520@60 and 1080x2520@120 mode. > >> + > >> config DRM_PANEL_SEIKO_43WVF1G > >> tristate "Seiko 43WVF1G panel" > >> depends on OF > >> diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile > >> index a4039d0fc9cfb..52dcd82e33120 100644 > >> --- a/drivers/gpu/drm/panel/Makefile > >> +++ b/drivers/gpu/drm/panel/Makefile > >> @@ -63,6 +63,7 @@ obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E88A0_AMS452EF01) += panel-samsung-s6e88a0-ams4 > >> obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E8AA0) += panel-samsung-s6e8aa0.o > >> obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF00) += panel-samsung-sofef00.o > >> obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF01) += panel-samsung-sofef01.o > >> +obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF03) += panel-samsung-sofef03.o > >> obj-$(CONFIG_DRM_PANEL_SEIKO_43WVF1G) += panel-seiko-43wvf1g.o > >> obj-$(CONFIG_DRM_PANEL_SHARP_LQ101R1SX01) += panel-sharp-lq101r1sx01.o > >> obj-$(CONFIG_DRM_PANEL_SHARP_LS037V7DW01) += panel-sharp-ls037v7dw01.o > >> diff --git a/drivers/gpu/drm/panel/panel-samsung-sofef03.c b/drivers/gpu/drm/panel/panel-samsung-sofef03.c > >> new file mode 100644 > >> index 0000000000000..2763e1c56b37b > >> --- /dev/null > >> +++ b/drivers/gpu/drm/panel/panel-samsung-sofef03.c > >> @@ -0,0 +1,423 @@ > >> +// SPDX-License-Identifier: GPL-2.0-only > >> +/* > >> + * Copyright (c) 2022 Konrad Dybcio <konrad.dybcio@linaro.org> > >> + * Copyright (c) 2023 Marijn Suijten <marijn.suijten@somainline.org> > >> + */ > >> + > >> +#include <linux/backlight.h> > >> +#include <linux/delay.h> > >> +#include <linux/gpio/consumer.h> > >> +#include <linux/module.h> > >> +#include <linux/of.h> > >> +#include <linux/regulator/consumer.h> > >> + > >> +#include <video/mipi_display.h> > >> + > >> +#include <drm/drm_mipi_dsi.h> > >> +#include <drm/drm_modes.h> > >> +#include <drm/drm_panel.h> > >> +#include <drm/drm_probe_helper.h> > >> +#include <drm/display/drm_dsc.h> > >> +#include <drm/display/drm_dsc_helper.h> > >> + > >> +static const bool enable_120hz = true; > > Maybe this can be a module parameter ? Can you explain why this can't be dynamically changed by a modeset ? > > >> + > >> +struct samsung_sofef03_m { > >> + struct drm_panel panel; > >> + struct mipi_dsi_device *dsi; > >> + struct regulator *vddio, *vci; > >> + struct gpio_desc *reset_gpio; > >> + bool prepared; > >> +}; > >> + > >> +static inline struct samsung_sofef03_m *to_samsung_sofef03_m(struct drm_panel *panel) > >> +{ > >> + return container_of(panel, struct samsung_sofef03_m, panel); > >> +} > >> + > >> +static void samsung_sofef03_m_reset(struct samsung_sofef03_m *ctx) > >> +{ > >> + gpiod_set_value_cansleep(ctx->reset_gpio, 0); > >> + usleep_range(10000, 11000); > >> +} > >> + > >> +static int samsung_sofef03_m_on(struct samsung_sofef03_m *ctx) > >> +{ > >> + struct mipi_dsi_device *dsi = ctx->dsi; > >> + struct device *dev = &dsi->dev; > >> + int ret; > >> + > >> + dsi->mode_flags |= MIPI_DSI_MODE_LPM; > >> + > >> + mipi_dsi_dcs_write_seq(dsi, 0x9d, 0x01); > >> + > >> + ret = mipi_dsi_dcs_exit_sleep_mode(dsi); > >> + if (ret < 0) { > >> + dev_err(dev, "Failed to exit sleep mode: %d\n", ret); > >> + return ret; > >> + } > >> + usleep_range(10000, 11000); > >> + > >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); > >> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x09); > >> + mipi_dsi_dcs_write_seq(dsi, 0xd5, 0x00, 0x00, 0x00); > >> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x08); > >> + mipi_dsi_dcs_write_seq(dsi, 0xee, 0x00, 0x00); > >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); > >> + > >> + ret = mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK); > >> + if (ret < 0) { > >> + dev_err(dev, "Failed to set tear on: %d\n", ret); > >> + return ret; > >> + } > >> + > >> + ret = mipi_dsi_dcs_set_column_address(dsi, 0, 1080 - 1); > >> + if (ret < 0) { > >> + dev_err(dev, "Failed to set column address: %d\n", ret); > >> + return ret; > >> + } > >> + > >> + ret = mipi_dsi_dcs_set_page_address(dsi, 0, 2520 - 1); > >> + if (ret < 0) { > >> + dev_err(dev, "Failed to set page address: %d\n", ret); > >> + return ret; > >> + } > >> + > >> + ret = mipi_dsi_dcs_set_display_brightness_large(dsi, 100); > >> + if (ret < 0) { > >> + dev_err(dev, "Failed to set display brightness: %d\n", ret); > >> + return ret; > >> + } > >> + > >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); > >> + mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x83); > >> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x01); > >> + mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x01); > >> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x02); > >> + mipi_dsi_dcs_write_seq(dsi, 0xec, 0x02, 0x00, 0x1c, 0x1c); > >> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x0c); > >> + mipi_dsi_dcs_write_seq(dsi, 0xec, 0x01, 0x19); > >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); > >> + mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_WRITE_CONTROL_DISPLAY, BIT(5)); > >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); > >> + mipi_dsi_dcs_write_seq(dsi, 0xc2, 0x2d, 0x27); > >> + mipi_dsi_dcs_write_seq(dsi, 0x60, enable_120hz ? 0x10 : 0x00); > >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); > >> + msleep(110); > >> + > >> + ret = mipi_dsi_dcs_set_display_on(dsi); > >> + if (ret < 0) { > >> + dev_err(dev, "Failed to turn display on: %d\n", ret); > >> + return ret; > >> + } > >> + > >> + return 0; > >> +} > >> + > >> +static int samsung_sofef03_m_off(struct samsung_sofef03_m *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 turn display off: %d\n", ret); > >> + return ret; > >> + } > >> + msleep(20); > >> + > >> + 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(100); > >> + > >> + return 0; > >> +} > >> + > >> +static int samsung_sofef03_m_prepare(struct drm_panel *panel) > >> +{ > >> + struct samsung_sofef03_m *ctx = to_samsung_sofef03_m(panel); > >> + struct drm_dsc_picture_parameter_set pps; > >> + struct device *dev = &ctx->dsi->dev; > >> + int ret; > >> + > >> + if (ctx->prepared) > >> + return 0; > >> + > >> + ret = regulator_enable(ctx->vddio); > >> + if (ret < 0) { > >> + dev_err(dev, "Failed to enable vddio regulator: %d\n", ret); > >> + return ret; > >> + } > >> + > >> + ret = regulator_enable(ctx->vci); > >> + if (ret < 0) { > >> + dev_err(dev, "Failed to enable vci regulator: %d\n", ret); > >> + regulator_disable(ctx->vddio); > >> + return ret; > >> + } > >> + > >> + samsung_sofef03_m_reset(ctx); > >> + > >> + ret = samsung_sofef03_m_on(ctx); > >> + if (ret < 0) { > >> + dev_err(dev, "Failed to initialize panel: %d\n", ret); > >> + goto fail; > >> + } > >> + > >> + if (ctx->dsi->dsc) { > > > > Always true > > > >> + drm_dsc_pps_payload_pack(&pps, ctx->dsi->dsc); > >> + > >> + ret = mipi_dsi_picture_parameter_set(ctx->dsi, &pps); > >> + if (ret < 0) { > >> + dev_err(dev, "failed to transmit PPS: %d\n", ret); > >> + goto fail; > >> + } > >> + > >> + ret = mipi_dsi_compression_mode(ctx->dsi, true); > >> + if (ret < 0) { > >> + dev_err(dev, "Failed to enable compression mode: %d\n", ret); > >> + goto fail; > >> + } > >> + > >> + msleep(28); > >> + } > >> + > >> + ctx->prepared = true; > >> + return 0; > >> + > >> +fail: > >> + gpiod_set_value_cansleep(ctx->reset_gpio, 1); > >> + regulator_disable(ctx->vci); > >> + regulator_disable(ctx->vddio); > >> + return ret; > >> +} > >> + > >> +static int samsung_sofef03_m_unprepare(struct drm_panel *panel) > >> +{ > >> + struct samsung_sofef03_m *ctx = to_samsung_sofef03_m(panel); > >> + struct device *dev = &ctx->dsi->dev; > >> + int ret; > >> + > >> + if (!ctx->prepared) > >> + return 0; > >> + > >> + ret = samsung_sofef03_m_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_disable(ctx->vci); > >> + regulator_disable(ctx->vddio); > >> + > >> + ctx->prepared = false; > >> + return 0; > >> +} > >> + > >> +static const struct drm_display_mode samsung_sofef03_m_60hz_mode = { > >> + .clock = (1080 + 156 + 8 + 8) * (2520 + 2393 + 8 + 8) * 60 / 1000, > >> + .hdisplay = 1080, > >> + .hsync_start = 1080 + 156, > >> + .hsync_end = 1080 + 156 + 8, > >> + .htotal = 1080 + 156 + 8 + 8, > >> + .vdisplay = 2520, > >> + .vsync_start = 2520 + 2393, > >> + .vsync_end = 2520 + 2393 + 8, > >> + .vtotal = 2520 + 2393 + 8 + 8, > >> + .width_mm = 61, > >> + .height_mm = 142, > >> +}; > >> + > >> +static const struct drm_display_mode samsung_sofef03_m_120hz_mode = { > >> + .clock = (1080 + 56 + 8 + 8) * (2520 + 499 + 8 + 8) * 120 / 1000, > >> + .hdisplay = 1080, > >> + .hsync_start = 1080 + 56, > >> + .hsync_end = 1080 + 56 + 8, > >> + .htotal = 1080 + 56 + 8 + 8, > >> + .vdisplay = 2520, > >> + .vsync_start = 2520 + 499, > >> + .vsync_end = 2520 + 499 + 8, > >> + .vtotal = 2520 + 499 + 8 + 8, > >> + .width_mm = 61, > >> + .height_mm = 142, > >> +}; > >> + > >> +static int samsung_sofef03_m_get_modes(struct drm_panel *panel, > >> + struct drm_connector *connector) > >> +{ > >> + if (enable_120hz) > > > > Is it possible to switch between these modes at runtime? It might be logical to define 60 Hz mode as preferred, while allowing users to switch to 120 Hz when required for some reason. Current panel API does not have a way to handle modesetting. All callbacks only get the panel as an input, state is left aside. Probably it's time to add atomic_*() versions of these callbacks, so that one can pass the state and maybe a connector? Or maybe the panel should get lightweight state too, like bridges do. > > > >> + return drm_connector_helper_get_modes_fixed(connector, > >> + &samsung_sofef03_m_120hz_mode); > >> + else > >> + return drm_connector_helper_get_modes_fixed(connector, > >> + &samsung_sofef03_m_60hz_mode); > >> +}
On 22.05.2023 03:23, Dmitry Baryshkov wrote: > On 22/05/2023 00:23, Marijn Suijten wrote: >> The SOFEF03-M Display-IC paired with an unknown panel in the Sony Xperia >> 5 II always uses Display Stream Compression 1.1 and features a 60hz and >> 120hz refresh-rate mode. >> >> Co-developed-by: Konrad Dybcio <konrad.dybcio@somainline.org> > > Konrad's S-o-b is also required then I guess I should use the matching email, so: Signed-off-by: Konrad Dybcio <konrad.dybcio@somainline.org> Konrad > >> Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org> >> --- >> drivers/gpu/drm/panel/Kconfig | 14 + >> drivers/gpu/drm/panel/Makefile | 1 + >> drivers/gpu/drm/panel/panel-samsung-sofef03.c | 423 ++++++++++++++++++++++++++ >> 3 files changed, 438 insertions(+) >> >> diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig >> index 3f11e9906f2cb..8e2668153bce2 100644 >> --- a/drivers/gpu/drm/panel/Kconfig >> +++ b/drivers/gpu/drm/panel/Kconfig >> @@ -630,6 +630,20 @@ config DRM_PANEL_SAMSUNG_SOFEF01 >> This panel features a fixed mode of 1080x2520@60. >> +config DRM_PANEL_SAMSUNG_SOFEF03 >> + tristate "Samsung sofef03 Sony Xperia 5 II DSI cmd mode panel" >> + depends on GPIOLIB >> + depends on OF >> + depends on DRM_MIPI_DSI >> + depends on BACKLIGHT_CLASS_DEVICE >> + help >> + Say Y or M here if you want to enable support for the Samsung AMOLED >> + command mode panel found in the Sony Xperia 5 II smartphone. >> + >> + This panel uses Display Stream Compression 1.1. >> + >> + The panel features a 1080x2520@60 and 1080x2520@120 mode. >> + >> config DRM_PANEL_SEIKO_43WVF1G >> tristate "Seiko 43WVF1G panel" >> depends on OF >> diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile >> index a4039d0fc9cfb..52dcd82e33120 100644 >> --- a/drivers/gpu/drm/panel/Makefile >> +++ b/drivers/gpu/drm/panel/Makefile >> @@ -63,6 +63,7 @@ obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E88A0_AMS452EF01) += panel-samsung-s6e88a0-ams4 >> obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E8AA0) += panel-samsung-s6e8aa0.o >> obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF00) += panel-samsung-sofef00.o >> obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF01) += panel-samsung-sofef01.o >> +obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF03) += panel-samsung-sofef03.o >> obj-$(CONFIG_DRM_PANEL_SEIKO_43WVF1G) += panel-seiko-43wvf1g.o >> obj-$(CONFIG_DRM_PANEL_SHARP_LQ101R1SX01) += panel-sharp-lq101r1sx01.o >> obj-$(CONFIG_DRM_PANEL_SHARP_LS037V7DW01) += panel-sharp-ls037v7dw01.o >> diff --git a/drivers/gpu/drm/panel/panel-samsung-sofef03.c b/drivers/gpu/drm/panel/panel-samsung-sofef03.c >> new file mode 100644 >> index 0000000000000..2763e1c56b37b >> --- /dev/null >> +++ b/drivers/gpu/drm/panel/panel-samsung-sofef03.c >> @@ -0,0 +1,423 @@ >> +// SPDX-License-Identifier: GPL-2.0-only >> +/* >> + * Copyright (c) 2022 Konrad Dybcio <konrad.dybcio@linaro.org> >> + * Copyright (c) 2023 Marijn Suijten <marijn.suijten@somainline.org> >> + */ >> + >> +#include <linux/backlight.h> >> +#include <linux/delay.h> >> +#include <linux/gpio/consumer.h> >> +#include <linux/module.h> >> +#include <linux/of.h> >> +#include <linux/regulator/consumer.h> >> + >> +#include <video/mipi_display.h> >> + >> +#include <drm/drm_mipi_dsi.h> >> +#include <drm/drm_modes.h> >> +#include <drm/drm_panel.h> >> +#include <drm/drm_probe_helper.h> >> +#include <drm/display/drm_dsc.h> >> +#include <drm/display/drm_dsc_helper.h> >> + >> +static const bool enable_120hz = true; >> + >> +struct samsung_sofef03_m { >> + struct drm_panel panel; >> + struct mipi_dsi_device *dsi; >> + struct regulator *vddio, *vci; >> + struct gpio_desc *reset_gpio; >> + bool prepared; >> +}; >> + >> +static inline struct samsung_sofef03_m *to_samsung_sofef03_m(struct drm_panel *panel) >> +{ >> + return container_of(panel, struct samsung_sofef03_m, panel); >> +} >> + >> +static void samsung_sofef03_m_reset(struct samsung_sofef03_m *ctx) >> +{ >> + gpiod_set_value_cansleep(ctx->reset_gpio, 0); >> + usleep_range(10000, 11000); >> +} >> + >> +static int samsung_sofef03_m_on(struct samsung_sofef03_m *ctx) >> +{ >> + struct mipi_dsi_device *dsi = ctx->dsi; >> + struct device *dev = &dsi->dev; >> + int ret; >> + >> + dsi->mode_flags |= MIPI_DSI_MODE_LPM; >> + >> + mipi_dsi_dcs_write_seq(dsi, 0x9d, 0x01); >> + >> + ret = mipi_dsi_dcs_exit_sleep_mode(dsi); >> + if (ret < 0) { >> + dev_err(dev, "Failed to exit sleep mode: %d\n", ret); >> + return ret; >> + } >> + usleep_range(10000, 11000); >> + >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); >> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x09); >> + mipi_dsi_dcs_write_seq(dsi, 0xd5, 0x00, 0x00, 0x00); >> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x08); >> + mipi_dsi_dcs_write_seq(dsi, 0xee, 0x00, 0x00); >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); >> + >> + ret = mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK); >> + if (ret < 0) { >> + dev_err(dev, "Failed to set tear on: %d\n", ret); >> + return ret; >> + } >> + >> + ret = mipi_dsi_dcs_set_column_address(dsi, 0, 1080 - 1); >> + if (ret < 0) { >> + dev_err(dev, "Failed to set column address: %d\n", ret); >> + return ret; >> + } >> + >> + ret = mipi_dsi_dcs_set_page_address(dsi, 0, 2520 - 1); >> + if (ret < 0) { >> + dev_err(dev, "Failed to set page address: %d\n", ret); >> + return ret; >> + } >> + >> + ret = mipi_dsi_dcs_set_display_brightness_large(dsi, 100); >> + if (ret < 0) { >> + dev_err(dev, "Failed to set display brightness: %d\n", ret); >> + return ret; >> + } >> + >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); >> + mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x83); >> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x01); >> + mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x01); >> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x02); >> + mipi_dsi_dcs_write_seq(dsi, 0xec, 0x02, 0x00, 0x1c, 0x1c); >> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x0c); >> + mipi_dsi_dcs_write_seq(dsi, 0xec, 0x01, 0x19); >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); >> + mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_WRITE_CONTROL_DISPLAY, BIT(5)); >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); >> + mipi_dsi_dcs_write_seq(dsi, 0xc2, 0x2d, 0x27); >> + mipi_dsi_dcs_write_seq(dsi, 0x60, enable_120hz ? 0x10 : 0x00); >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); >> + msleep(110); >> + >> + ret = mipi_dsi_dcs_set_display_on(dsi); >> + if (ret < 0) { >> + dev_err(dev, "Failed to turn display on: %d\n", ret); >> + return ret; >> + } >> + >> + return 0; >> +} >> + >> +static int samsung_sofef03_m_off(struct samsung_sofef03_m *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 turn display off: %d\n", ret); >> + return ret; >> + } >> + msleep(20); >> + >> + 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(100); >> + >> + return 0; >> +} >> + >> +static int samsung_sofef03_m_prepare(struct drm_panel *panel) >> +{ >> + struct samsung_sofef03_m *ctx = to_samsung_sofef03_m(panel); >> + struct drm_dsc_picture_parameter_set pps; >> + struct device *dev = &ctx->dsi->dev; >> + int ret; >> + >> + if (ctx->prepared) >> + return 0; >> + >> + ret = regulator_enable(ctx->vddio); >> + if (ret < 0) { >> + dev_err(dev, "Failed to enable vddio regulator: %d\n", ret); >> + return ret; >> + } >> + >> + ret = regulator_enable(ctx->vci); >> + if (ret < 0) { >> + dev_err(dev, "Failed to enable vci regulator: %d\n", ret); >> + regulator_disable(ctx->vddio); >> + return ret; >> + } >> + >> + samsung_sofef03_m_reset(ctx); >> + >> + ret = samsung_sofef03_m_on(ctx); >> + if (ret < 0) { >> + dev_err(dev, "Failed to initialize panel: %d\n", ret); >> + goto fail; >> + } >> + >> + if (ctx->dsi->dsc) { > > Always true > >> + drm_dsc_pps_payload_pack(&pps, ctx->dsi->dsc); >> + >> + ret = mipi_dsi_picture_parameter_set(ctx->dsi, &pps); >> + if (ret < 0) { >> + dev_err(dev, "failed to transmit PPS: %d\n", ret); >> + goto fail; >> + } >> + >> + ret = mipi_dsi_compression_mode(ctx->dsi, true); >> + if (ret < 0) { >> + dev_err(dev, "Failed to enable compression mode: %d\n", ret); >> + goto fail; >> + } >> + >> + msleep(28); >> + } >> + >> + ctx->prepared = true; >> + return 0; >> + >> +fail: >> + gpiod_set_value_cansleep(ctx->reset_gpio, 1); >> + regulator_disable(ctx->vci); >> + regulator_disable(ctx->vddio); >> + return ret; >> +} >> + >> +static int samsung_sofef03_m_unprepare(struct drm_panel *panel) >> +{ >> + struct samsung_sofef03_m *ctx = to_samsung_sofef03_m(panel); >> + struct device *dev = &ctx->dsi->dev; >> + int ret; >> + >> + if (!ctx->prepared) >> + return 0; >> + >> + ret = samsung_sofef03_m_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_disable(ctx->vci); >> + regulator_disable(ctx->vddio); >> + >> + ctx->prepared = false; >> + return 0; >> +} >> + >> +static const struct drm_display_mode samsung_sofef03_m_60hz_mode = { >> + .clock = (1080 + 156 + 8 + 8) * (2520 + 2393 + 8 + 8) * 60 / 1000, >> + .hdisplay = 1080, >> + .hsync_start = 1080 + 156, >> + .hsync_end = 1080 + 156 + 8, >> + .htotal = 1080 + 156 + 8 + 8, >> + .vdisplay = 2520, >> + .vsync_start = 2520 + 2393, >> + .vsync_end = 2520 + 2393 + 8, >> + .vtotal = 2520 + 2393 + 8 + 8, >> + .width_mm = 61, >> + .height_mm = 142, >> +}; >> + >> +static const struct drm_display_mode samsung_sofef03_m_120hz_mode = { >> + .clock = (1080 + 56 + 8 + 8) * (2520 + 499 + 8 + 8) * 120 / 1000, >> + .hdisplay = 1080, >> + .hsync_start = 1080 + 56, >> + .hsync_end = 1080 + 56 + 8, >> + .htotal = 1080 + 56 + 8 + 8, >> + .vdisplay = 2520, >> + .vsync_start = 2520 + 499, >> + .vsync_end = 2520 + 499 + 8, >> + .vtotal = 2520 + 499 + 8 + 8, >> + .width_mm = 61, >> + .height_mm = 142, >> +}; >> + >> +static int samsung_sofef03_m_get_modes(struct drm_panel *panel, >> + struct drm_connector *connector) >> +{ >> + if (enable_120hz) > > Is it possible to switch between these modes at runtime? It might be logical to define 60 Hz mode as preferred, while allowing users to switch to 120 Hz when required for some reason. > >> + return drm_connector_helper_get_modes_fixed(connector, >> + &samsung_sofef03_m_120hz_mode); >> + else >> + return drm_connector_helper_get_modes_fixed(connector, >> + &samsung_sofef03_m_60hz_mode); >> +} >> + >> +static const struct drm_panel_funcs samsung_sofef03_m_panel_funcs = { >> + .prepare = samsung_sofef03_m_prepare, >> + .unprepare = samsung_sofef03_m_unprepare, >> + .get_modes = samsung_sofef03_m_get_modes, >> +}; >> + >> +static int samsung_sofef03_m_bl_update_status(struct backlight_device *bl) >> +{ >> + struct mipi_dsi_device *dsi = bl_get_data(bl); >> + u16 brightness = backlight_get_brightness(bl); >> + int ret; >> + >> + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; >> + >> + pr_err("Writing %#x\n", brightness); >> + >> + ret = mipi_dsi_dcs_set_display_brightness_large(dsi, brightness); >> + if (ret < 0) >> + return ret; >> + >> + dsi->mode_flags |= MIPI_DSI_MODE_LPM; >> + >> + return 0; >> +} >> + >> +static int samsung_sofef03_m_bl_get_brightness(struct backlight_device *bl) >> +{ >> + struct mipi_dsi_device *dsi = bl_get_data(bl); >> + u16 brightness; >> + int ret; >> + >> + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; >> + >> + ret = mipi_dsi_dcs_get_display_brightness_large(dsi, &brightness); >> + if (ret < 0) >> + return ret; >> + >> + dsi->mode_flags |= MIPI_DSI_MODE_LPM; >> + >> + pr_err("Read display brightness %#x\n", brightness); >> + >> + return brightness; >> +} >> + >> +static const struct backlight_ops samsung_sofef03_m_bl_ops = { >> + .update_status = samsung_sofef03_m_bl_update_status, >> + .get_brightness = samsung_sofef03_m_bl_get_brightness, >> +}; >> + >> +static struct backlight_device * >> +samsung_sofef03_m_create_backlight(struct mipi_dsi_device *dsi) >> +{ >> + struct device *dev = &dsi->dev; >> + const struct backlight_properties props = { >> + .type = BACKLIGHT_RAW, >> + .brightness = 100, >> + .max_brightness = 1023, >> + }; >> + >> + return devm_backlight_device_register(dev, dev_name(dev), dev, dsi, >> + &samsung_sofef03_m_bl_ops, &props); >> +} >> + >> +static int samsung_sofef03_m_probe(struct mipi_dsi_device *dsi) >> +{ >> + struct device *dev = &dsi->dev; >> + struct drm_dsc_config *dsc; >> + struct samsung_sofef03_m *ctx; >> + int ret; >> + >> + ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); >> + if (!ctx) >> + return -ENOMEM; >> + >> + ctx->vddio = devm_regulator_get(dev, "vddio"); >> + if (IS_ERR(ctx->vddio)) >> + return dev_err_probe(dev, PTR_ERR(ctx->vddio), >> + "Failed to get vddio regulator\n"); >> + >> + ctx->vci = devm_regulator_get(dev, "vci"); >> + if (IS_ERR(ctx->vci)) >> + return dev_err_probe(dev, PTR_ERR(ctx->vci), >> + "Failed to get vci regulator\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_CLOCK_NON_CONTINUOUS; >> + >> + drm_panel_init(&ctx->panel, dev, &samsung_sofef03_m_panel_funcs, >> + DRM_MODE_CONNECTOR_DSI); >> + >> + ctx->panel.backlight = samsung_sofef03_m_create_backlight(dsi); >> + if (IS_ERR(ctx->panel.backlight)) >> + return dev_err_probe(dev, PTR_ERR(ctx->panel.backlight), >> + "Failed to create backlight\n"); >> + >> + drm_panel_add(&ctx->panel); >> + >> + /* This panel only supports DSC; unconditionally enable it */ >> + dsi->dsc = dsc = devm_kzalloc(&dsi->dev, sizeof(*dsc), GFP_KERNEL); > > Double assignment > >> + if (!dsc) >> + return -ENOMEM; >> + >> + dsc->dsc_version_major = 1; >> + dsc->dsc_version_minor = 1; >> + >> + dsc->slice_height = 30; >> + dsc->slice_width = 540; >> + dsc->slice_count = 2; >> + dsc->bits_per_component = 8; >> + dsc->bits_per_pixel = 8 << 4; /* 4 fractional bits */ >> + dsc->block_pred_enable = true; >> + >> + 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 void samsung_sofef03_m_remove(struct mipi_dsi_device *dsi) >> +{ >> + struct samsung_sofef03_m *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); >> +} >> + >> +static const struct of_device_id samsung_sofef03_m_of_match[] = { >> + { .compatible = "samsung,sofef03-m" }, >> + { /* sentinel */ } >> +}; >> +MODULE_DEVICE_TABLE(of, samsung_sofef03_m_of_match); >> + >> +static struct mipi_dsi_driver samsung_sofef03_m_driver = { >> + .probe = samsung_sofef03_m_probe, >> + .remove = samsung_sofef03_m_remove, >> + .driver = { >> + .name = "panel-samsung-sofef03-m", >> + .of_match_table = samsung_sofef03_m_of_match, >> + }, >> +}; >> +module_mipi_dsi_driver(samsung_sofef03_m_driver); >> + >> +MODULE_AUTHOR("Konrad Dybcio <konrad.dybcio@linaro.org>"); >> +MODULE_AUTHOR("Marijn Suijten <marijn.suijten@somainline.org>"); >> +MODULE_DESCRIPTION("DRM panel driver for Samsung SOFEF03-M Display-IC panels"); >> +MODULE_LICENSE("GPL"); >> >
On 2023-05-22 11:08:12, Neil Armstrong wrote: > On 22/05/2023 03:23, Dmitry Baryshkov wrote: > > On 22/05/2023 00:23, Marijn Suijten wrote: > >> The SOFEF03-M Display-IC paired with an unknown panel in the Sony Xperia > >> 5 II always uses Display Stream Compression 1.1 and features a 60hz and > >> 120hz refresh-rate mode. > >> > >> Co-developed-by: Konrad Dybcio <konrad.dybcio@somainline.org> > > > > Konrad's S-o-b is also required then I am unsure what to include here, since Konrad originally "authored" the commit but I believe it was nothing more than a completely broken and unusable driver spit out by "The mdss panel generator". This needed enough rewriting that I don't feel like giving it much credit ;) > > > >> Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org> > >> --- > >> drivers/gpu/drm/panel/Kconfig | 14 + > >> drivers/gpu/drm/panel/Makefile | 1 + > >> drivers/gpu/drm/panel/panel-samsung-sofef03.c | 423 ++++++++++++++++++++++++++ > >> 3 files changed, 438 insertions(+) > >> > >> diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig > >> index 3f11e9906f2cb..8e2668153bce2 100644 > >> --- a/drivers/gpu/drm/panel/Kconfig > >> +++ b/drivers/gpu/drm/panel/Kconfig > >> @@ -630,6 +630,20 @@ config DRM_PANEL_SAMSUNG_SOFEF01 > >> This panel features a fixed mode of 1080x2520@60. > >> +config DRM_PANEL_SAMSUNG_SOFEF03 > >> + tristate "Samsung sofef03 Sony Xperia 5 II DSI cmd mode panel" > >> + depends on GPIOLIB > >> + depends on OF > >> + depends on DRM_MIPI_DSI > >> + depends on BACKLIGHT_CLASS_DEVICE > >> + help > >> + Say Y or M here if you want to enable support for the Samsung AMOLED > >> + command mode panel found in the Sony Xperia 5 II smartphone. > >> + > >> + This panel uses Display Stream Compression 1.1. > >> + > >> + The panel features a 1080x2520@60 and 1080x2520@120 mode. > >> + > >> config DRM_PANEL_SEIKO_43WVF1G > >> tristate "Seiko 43WVF1G panel" > >> depends on OF > >> diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile > >> index a4039d0fc9cfb..52dcd82e33120 100644 > >> --- a/drivers/gpu/drm/panel/Makefile > >> +++ b/drivers/gpu/drm/panel/Makefile > >> @@ -63,6 +63,7 @@ obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E88A0_AMS452EF01) += panel-samsung-s6e88a0-ams4 > >> obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E8AA0) += panel-samsung-s6e8aa0.o > >> obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF00) += panel-samsung-sofef00.o > >> obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF01) += panel-samsung-sofef01.o > >> +obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF03) += panel-samsung-sofef03.o > >> obj-$(CONFIG_DRM_PANEL_SEIKO_43WVF1G) += panel-seiko-43wvf1g.o > >> obj-$(CONFIG_DRM_PANEL_SHARP_LQ101R1SX01) += panel-sharp-lq101r1sx01.o > >> obj-$(CONFIG_DRM_PANEL_SHARP_LS037V7DW01) += panel-sharp-ls037v7dw01.o > >> diff --git a/drivers/gpu/drm/panel/panel-samsung-sofef03.c b/drivers/gpu/drm/panel/panel-samsung-sofef03.c > >> new file mode 100644 > >> index 0000000000000..2763e1c56b37b > >> --- /dev/null > >> +++ b/drivers/gpu/drm/panel/panel-samsung-sofef03.c > >> @@ -0,0 +1,423 @@ > >> +// SPDX-License-Identifier: GPL-2.0-only > >> +/* > >> + * Copyright (c) 2022 Konrad Dybcio <konrad.dybcio@linaro.org> > >> + * Copyright (c) 2023 Marijn Suijten <marijn.suijten@somainline.org> > >> + */ > >> + > >> +#include <linux/backlight.h> > >> +#include <linux/delay.h> > >> +#include <linux/gpio/consumer.h> > >> +#include <linux/module.h> > >> +#include <linux/of.h> > >> +#include <linux/regulator/consumer.h> > >> + > >> +#include <video/mipi_display.h> > >> + > >> +#include <drm/drm_mipi_dsi.h> > >> +#include <drm/drm_modes.h> > >> +#include <drm/drm_panel.h> > >> +#include <drm/drm_probe_helper.h> > >> +#include <drm/display/drm_dsc.h> > >> +#include <drm/display/drm_dsc_helper.h> > >> + > >> +static const bool enable_120hz = true; > > Maybe this can be a module parameter ? Can you explain why this can't be dynamically changed by a modeset ? > > >> + > >> +struct samsung_sofef03_m { > >> + struct drm_panel panel; > >> + struct mipi_dsi_device *dsi; > >> + struct regulator *vddio, *vci; > >> + struct gpio_desc *reset_gpio; > >> + bool prepared; > >> +}; > >> + > >> +static inline struct samsung_sofef03_m *to_samsung_sofef03_m(struct drm_panel *panel) > >> +{ > >> + return container_of(panel, struct samsung_sofef03_m, panel); > >> +} > >> + > >> +static void samsung_sofef03_m_reset(struct samsung_sofef03_m *ctx) > >> +{ > >> + gpiod_set_value_cansleep(ctx->reset_gpio, 0); > >> + usleep_range(10000, 11000); > >> +} > >> + > >> +static int samsung_sofef03_m_on(struct samsung_sofef03_m *ctx) > >> +{ > >> + struct mipi_dsi_device *dsi = ctx->dsi; > >> + struct device *dev = &dsi->dev; > >> + int ret; > >> + > >> + dsi->mode_flags |= MIPI_DSI_MODE_LPM; > >> + > >> + mipi_dsi_dcs_write_seq(dsi, 0x9d, 0x01); > >> + > >> + ret = mipi_dsi_dcs_exit_sleep_mode(dsi); > >> + if (ret < 0) { > >> + dev_err(dev, "Failed to exit sleep mode: %d\n", ret); > >> + return ret; > >> + } > >> + usleep_range(10000, 11000); > >> + > >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); > >> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x09); > >> + mipi_dsi_dcs_write_seq(dsi, 0xd5, 0x00, 0x00, 0x00); > >> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x08); > >> + mipi_dsi_dcs_write_seq(dsi, 0xee, 0x00, 0x00); > >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); > >> + > >> + ret = mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK); > >> + if (ret < 0) { > >> + dev_err(dev, "Failed to set tear on: %d\n", ret); > >> + return ret; > >> + } > >> + > >> + ret = mipi_dsi_dcs_set_column_address(dsi, 0, 1080 - 1); > >> + if (ret < 0) { > >> + dev_err(dev, "Failed to set column address: %d\n", ret); > >> + return ret; > >> + } > >> + > >> + ret = mipi_dsi_dcs_set_page_address(dsi, 0, 2520 - 1); > >> + if (ret < 0) { > >> + dev_err(dev, "Failed to set page address: %d\n", ret); > >> + return ret; > >> + } > >> + > >> + ret = mipi_dsi_dcs_set_display_brightness_large(dsi, 100); > >> + if (ret < 0) { > >> + dev_err(dev, "Failed to set display brightness: %d\n", ret); > >> + return ret; > >> + } > >> + > >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); > >> + mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x83); > >> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x01); > >> + mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x01); > >> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x02); > >> + mipi_dsi_dcs_write_seq(dsi, 0xec, 0x02, 0x00, 0x1c, 0x1c); > >> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x0c); > >> + mipi_dsi_dcs_write_seq(dsi, 0xec, 0x01, 0x19); > >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); > >> + mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_WRITE_CONTROL_DISPLAY, BIT(5)); > >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); > >> + mipi_dsi_dcs_write_seq(dsi, 0xc2, 0x2d, 0x27); > >> + mipi_dsi_dcs_write_seq(dsi, 0x60, enable_120hz ? 0x10 : 0x00); > >> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); > >> + msleep(110); > >> + > >> + ret = mipi_dsi_dcs_set_display_on(dsi); > >> + if (ret < 0) { > >> + dev_err(dev, "Failed to turn display on: %d\n", ret); > >> + return ret; > >> + } > >> + > >> + return 0; > >> +} > >> + > >> +static int samsung_sofef03_m_off(struct samsung_sofef03_m *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 turn display off: %d\n", ret); > >> + return ret; > >> + } > >> + msleep(20); > >> + > >> + 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(100); > >> + > >> + return 0; > >> +} > >> + > >> +static int samsung_sofef03_m_prepare(struct drm_panel *panel) > >> +{ > >> + struct samsung_sofef03_m *ctx = to_samsung_sofef03_m(panel); > >> + struct drm_dsc_picture_parameter_set pps; > >> + struct device *dev = &ctx->dsi->dev; > >> + int ret; > >> + > >> + if (ctx->prepared) > >> + return 0; > >> + > >> + ret = regulator_enable(ctx->vddio); > >> + if (ret < 0) { > >> + dev_err(dev, "Failed to enable vddio regulator: %d\n", ret); > >> + return ret; > >> + } > >> + > >> + ret = regulator_enable(ctx->vci); > >> + if (ret < 0) { > >> + dev_err(dev, "Failed to enable vci regulator: %d\n", ret); > >> + regulator_disable(ctx->vddio); > >> + return ret; > >> + } > >> + > >> + samsung_sofef03_m_reset(ctx); > >> + > >> + ret = samsung_sofef03_m_on(ctx); > >> + if (ret < 0) { > >> + dev_err(dev, "Failed to initialize panel: %d\n", ret); > >> + goto fail; > >> + } > >> + > >> + if (ctx->dsi->dsc) { > > > > Always true Would like to keep this as described in the Xperia XZ3 panel driver review. > >> + drm_dsc_pps_payload_pack(&pps, ctx->dsi->dsc); > >> + > >> + ret = mipi_dsi_picture_parameter_set(ctx->dsi, &pps); > >> + if (ret < 0) { > >> + dev_err(dev, "failed to transmit PPS: %d\n", ret); > >> + goto fail; > >> + } > >> + > >> + ret = mipi_dsi_compression_mode(ctx->dsi, true); > >> + if (ret < 0) { > >> + dev_err(dev, "Failed to enable compression mode: %d\n", ret); > >> + goto fail; > >> + } > >> + > >> + msleep(28); > >> + } > >> + > >> + ctx->prepared = true; > >> + return 0; > >> + > >> +fail: > >> + gpiod_set_value_cansleep(ctx->reset_gpio, 1); > >> + regulator_disable(ctx->vci); > >> + regulator_disable(ctx->vddio); > >> + return ret; > >> +} > >> + > >> +static int samsung_sofef03_m_unprepare(struct drm_panel *panel) > >> +{ > >> + struct samsung_sofef03_m *ctx = to_samsung_sofef03_m(panel); > >> + struct device *dev = &ctx->dsi->dev; > >> + int ret; > >> + > >> + if (!ctx->prepared) > >> + return 0; > >> + > >> + ret = samsung_sofef03_m_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_disable(ctx->vci); > >> + regulator_disable(ctx->vddio); > >> + > >> + ctx->prepared = false; > >> + return 0; > >> +} > >> + > >> +static const struct drm_display_mode samsung_sofef03_m_60hz_mode = { > >> + .clock = (1080 + 156 + 8 + 8) * (2520 + 2393 + 8 + 8) * 60 / 1000, > >> + .hdisplay = 1080, > >> + .hsync_start = 1080 + 156, > >> + .hsync_end = 1080 + 156 + 8, > >> + .htotal = 1080 + 156 + 8 + 8, > >> + .vdisplay = 2520, > >> + .vsync_start = 2520 + 2393, > >> + .vsync_end = 2520 + 2393 + 8, > >> + .vtotal = 2520 + 2393 + 8 + 8, > >> + .width_mm = 61, > >> + .height_mm = 142, > >> +}; > >> + > >> +static const struct drm_display_mode samsung_sofef03_m_120hz_mode = { > >> + .clock = (1080 + 56 + 8 + 8) * (2520 + 499 + 8 + 8) * 120 / 1000, > >> + .hdisplay = 1080, > >> + .hsync_start = 1080 + 56, > >> + .hsync_end = 1080 + 56 + 8, > >> + .htotal = 1080 + 56 + 8 + 8, > >> + .vdisplay = 2520, > >> + .vsync_start = 2520 + 499, > >> + .vsync_end = 2520 + 499 + 8, > >> + .vtotal = 2520 + 499 + 8 + 8, > >> + .width_mm = 61, > >> + .height_mm = 142, > >> +}; > >> + > >> +static int samsung_sofef03_m_get_modes(struct drm_panel *panel, > >> + struct drm_connector *connector) > >> +{ > >> + if (enable_120hz) > > > > Is it possible to switch between these modes at runtime? It might be logical to define 60 Hz mode as preferred, while allowing users to switch to 120 Hz when required for some reason. I'd love to define two modes but as described in the cover letter - and the reason to send this as RFC - drm_panel currently does not expose the mode back to the driver in e.g. _prepare, so I cannot update or resend the necessary dcs commands to set **or change** the current mode (downstream defines commands to change the rate without fully resetting the panel). I can either convert this to drm_bridge (is that easy / worth it?) or hack it in with a global as done here so that we can tackle that endeavour separately, while at least having the drivers upstream (or on the lists) as requested by quic for DSC development. > >> + return drm_connector_helper_get_modes_fixed(connector, > >> + &samsung_sofef03_m_120hz_mode); > >> + else > >> + return drm_connector_helper_get_modes_fixed(connector, > >> + &samsung_sofef03_m_60hz_mode); > >> +} > >> + > >> +static const struct drm_panel_funcs samsung_sofef03_m_panel_funcs = { > >> + .prepare = samsung_sofef03_m_prepare, > >> + .unprepare = samsung_sofef03_m_unprepare, > >> + .get_modes = samsung_sofef03_m_get_modes, > >> +}; > >> + > >> +static int samsung_sofef03_m_bl_update_status(struct backlight_device *bl) > >> +{ > >> + struct mipi_dsi_device *dsi = bl_get_data(bl); > >> + u16 brightness = backlight_get_brightness(bl); > >> + int ret; > >> + > >> + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; > >> + > >> + pr_err("Writing %#x\n", brightness); > > You forgot to remove those desbug prints :-p RFC: I indeed forgot to mention this in the cover letter but this driver is still mostly broken beyond displaying an image. Setting brightness here does nothing (except after sending the command many times in quick succession by e.g. a brightness slider in UI, the panel gets stuck on a broken image) and the panel remained black if it wasn't for the random set_brightness_large(100) in _prepare. I will remove these in a followup once figuring out how to make and keep it working. - Marijn
On 29.05.2023 23:21, Marijn Suijten wrote: > On 2023-05-22 11:08:12, Neil Armstrong wrote: >> On 22/05/2023 03:23, Dmitry Baryshkov wrote: >>> On 22/05/2023 00:23, Marijn Suijten wrote: >>>> The SOFEF03-M Display-IC paired with an unknown panel in the Sony Xperia >>>> 5 II always uses Display Stream Compression 1.1 and features a 60hz and >>>> 120hz refresh-rate mode. >>>> >>>> Co-developed-by: Konrad Dybcio <konrad.dybcio@somainline.org> >>> >>> Konrad's S-o-b is also required then > > I am unsure what to include here, since Konrad originally "authored" the > commit but I believe it was nothing more than a completely broken and > unusable driver spit out by "The mdss panel generator". This needed > enough rewriting that I don't feel like giving it much credit ;) Might have been. I won't be mad if you drop this! Konrad > >>> >>>> Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org> >>>> --- >>>> drivers/gpu/drm/panel/Kconfig | 14 + >>>> drivers/gpu/drm/panel/Makefile | 1 + >>>> drivers/gpu/drm/panel/panel-samsung-sofef03.c | 423 ++++++++++++++++++++++++++ >>>> 3 files changed, 438 insertions(+) >>>> >>>> diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig >>>> index 3f11e9906f2cb..8e2668153bce2 100644 >>>> --- a/drivers/gpu/drm/panel/Kconfig >>>> +++ b/drivers/gpu/drm/panel/Kconfig >>>> @@ -630,6 +630,20 @@ config DRM_PANEL_SAMSUNG_SOFEF01 >>>> This panel features a fixed mode of 1080x2520@60. >>>> +config DRM_PANEL_SAMSUNG_SOFEF03 >>>> + tristate "Samsung sofef03 Sony Xperia 5 II DSI cmd mode panel" >>>> + depends on GPIOLIB >>>> + depends on OF >>>> + depends on DRM_MIPI_DSI >>>> + depends on BACKLIGHT_CLASS_DEVICE >>>> + help >>>> + Say Y or M here if you want to enable support for the Samsung AMOLED >>>> + command mode panel found in the Sony Xperia 5 II smartphone. >>>> + >>>> + This panel uses Display Stream Compression 1.1. >>>> + >>>> + The panel features a 1080x2520@60 and 1080x2520@120 mode. >>>> + >>>> config DRM_PANEL_SEIKO_43WVF1G >>>> tristate "Seiko 43WVF1G panel" >>>> depends on OF >>>> diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile >>>> index a4039d0fc9cfb..52dcd82e33120 100644 >>>> --- a/drivers/gpu/drm/panel/Makefile >>>> +++ b/drivers/gpu/drm/panel/Makefile >>>> @@ -63,6 +63,7 @@ obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E88A0_AMS452EF01) += panel-samsung-s6e88a0-ams4 >>>> obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E8AA0) += panel-samsung-s6e8aa0.o >>>> obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF00) += panel-samsung-sofef00.o >>>> obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF01) += panel-samsung-sofef01.o >>>> +obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF03) += panel-samsung-sofef03.o >>>> obj-$(CONFIG_DRM_PANEL_SEIKO_43WVF1G) += panel-seiko-43wvf1g.o >>>> obj-$(CONFIG_DRM_PANEL_SHARP_LQ101R1SX01) += panel-sharp-lq101r1sx01.o >>>> obj-$(CONFIG_DRM_PANEL_SHARP_LS037V7DW01) += panel-sharp-ls037v7dw01.o >>>> diff --git a/drivers/gpu/drm/panel/panel-samsung-sofef03.c b/drivers/gpu/drm/panel/panel-samsung-sofef03.c >>>> new file mode 100644 >>>> index 0000000000000..2763e1c56b37b >>>> --- /dev/null >>>> +++ b/drivers/gpu/drm/panel/panel-samsung-sofef03.c >>>> @@ -0,0 +1,423 @@ >>>> +// SPDX-License-Identifier: GPL-2.0-only >>>> +/* >>>> + * Copyright (c) 2022 Konrad Dybcio <konrad.dybcio@linaro.org> >>>> + * Copyright (c) 2023 Marijn Suijten <marijn.suijten@somainline.org> >>>> + */ >>>> + >>>> +#include <linux/backlight.h> >>>> +#include <linux/delay.h> >>>> +#include <linux/gpio/consumer.h> >>>> +#include <linux/module.h> >>>> +#include <linux/of.h> >>>> +#include <linux/regulator/consumer.h> >>>> + >>>> +#include <video/mipi_display.h> >>>> + >>>> +#include <drm/drm_mipi_dsi.h> >>>> +#include <drm/drm_modes.h> >>>> +#include <drm/drm_panel.h> >>>> +#include <drm/drm_probe_helper.h> >>>> +#include <drm/display/drm_dsc.h> >>>> +#include <drm/display/drm_dsc_helper.h> >>>> + >>>> +static const bool enable_120hz = true; >> >> Maybe this can be a module parameter ? Can you explain why this can't be dynamically changed by a modeset ? >> >>>> + >>>> +struct samsung_sofef03_m { >>>> + struct drm_panel panel; >>>> + struct mipi_dsi_device *dsi; >>>> + struct regulator *vddio, *vci; >>>> + struct gpio_desc *reset_gpio; >>>> + bool prepared; >>>> +}; >>>> + >>>> +static inline struct samsung_sofef03_m *to_samsung_sofef03_m(struct drm_panel *panel) >>>> +{ >>>> + return container_of(panel, struct samsung_sofef03_m, panel); >>>> +} >>>> + >>>> +static void samsung_sofef03_m_reset(struct samsung_sofef03_m *ctx) >>>> +{ >>>> + gpiod_set_value_cansleep(ctx->reset_gpio, 0); >>>> + usleep_range(10000, 11000); >>>> +} >>>> + >>>> +static int samsung_sofef03_m_on(struct samsung_sofef03_m *ctx) >>>> +{ >>>> + struct mipi_dsi_device *dsi = ctx->dsi; >>>> + struct device *dev = &dsi->dev; >>>> + int ret; >>>> + >>>> + dsi->mode_flags |= MIPI_DSI_MODE_LPM; >>>> + >>>> + mipi_dsi_dcs_write_seq(dsi, 0x9d, 0x01); >>>> + >>>> + ret = mipi_dsi_dcs_exit_sleep_mode(dsi); >>>> + if (ret < 0) { >>>> + dev_err(dev, "Failed to exit sleep mode: %d\n", ret); >>>> + return ret; >>>> + } >>>> + usleep_range(10000, 11000); >>>> + >>>> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); >>>> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x09); >>>> + mipi_dsi_dcs_write_seq(dsi, 0xd5, 0x00, 0x00, 0x00); >>>> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x08); >>>> + mipi_dsi_dcs_write_seq(dsi, 0xee, 0x00, 0x00); >>>> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); >>>> + >>>> + ret = mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK); >>>> + if (ret < 0) { >>>> + dev_err(dev, "Failed to set tear on: %d\n", ret); >>>> + return ret; >>>> + } >>>> + >>>> + ret = mipi_dsi_dcs_set_column_address(dsi, 0, 1080 - 1); >>>> + if (ret < 0) { >>>> + dev_err(dev, "Failed to set column address: %d\n", ret); >>>> + return ret; >>>> + } >>>> + >>>> + ret = mipi_dsi_dcs_set_page_address(dsi, 0, 2520 - 1); >>>> + if (ret < 0) { >>>> + dev_err(dev, "Failed to set page address: %d\n", ret); >>>> + return ret; >>>> + } >>>> + >>>> + ret = mipi_dsi_dcs_set_display_brightness_large(dsi, 100); >>>> + if (ret < 0) { >>>> + dev_err(dev, "Failed to set display brightness: %d\n", ret); >>>> + return ret; >>>> + } >>>> + >>>> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); >>>> + mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x83); >>>> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x01); >>>> + mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x01); >>>> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x02); >>>> + mipi_dsi_dcs_write_seq(dsi, 0xec, 0x02, 0x00, 0x1c, 0x1c); >>>> + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x0c); >>>> + mipi_dsi_dcs_write_seq(dsi, 0xec, 0x01, 0x19); >>>> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); >>>> + mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_WRITE_CONTROL_DISPLAY, BIT(5)); >>>> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); >>>> + mipi_dsi_dcs_write_seq(dsi, 0xc2, 0x2d, 0x27); >>>> + mipi_dsi_dcs_write_seq(dsi, 0x60, enable_120hz ? 0x10 : 0x00); >>>> + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); >>>> + msleep(110); >>>> + >>>> + ret = mipi_dsi_dcs_set_display_on(dsi); >>>> + if (ret < 0) { >>>> + dev_err(dev, "Failed to turn display on: %d\n", ret); >>>> + return ret; >>>> + } >>>> + >>>> + return 0; >>>> +} >>>> + >>>> +static int samsung_sofef03_m_off(struct samsung_sofef03_m *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 turn display off: %d\n", ret); >>>> + return ret; >>>> + } >>>> + msleep(20); >>>> + >>>> + 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(100); >>>> + >>>> + return 0; >>>> +} >>>> + >>>> +static int samsung_sofef03_m_prepare(struct drm_panel *panel) >>>> +{ >>>> + struct samsung_sofef03_m *ctx = to_samsung_sofef03_m(panel); >>>> + struct drm_dsc_picture_parameter_set pps; >>>> + struct device *dev = &ctx->dsi->dev; >>>> + int ret; >>>> + >>>> + if (ctx->prepared) >>>> + return 0; >>>> + >>>> + ret = regulator_enable(ctx->vddio); >>>> + if (ret < 0) { >>>> + dev_err(dev, "Failed to enable vddio regulator: %d\n", ret); >>>> + return ret; >>>> + } >>>> + >>>> + ret = regulator_enable(ctx->vci); >>>> + if (ret < 0) { >>>> + dev_err(dev, "Failed to enable vci regulator: %d\n", ret); >>>> + regulator_disable(ctx->vddio); >>>> + return ret; >>>> + } >>>> + >>>> + samsung_sofef03_m_reset(ctx); >>>> + >>>> + ret = samsung_sofef03_m_on(ctx); >>>> + if (ret < 0) { >>>> + dev_err(dev, "Failed to initialize panel: %d\n", ret); >>>> + goto fail; >>>> + } >>>> + >>>> + if (ctx->dsi->dsc) { >>> >>> Always true > > Would like to keep this as described in the Xperia XZ3 panel driver > review. > >>>> + drm_dsc_pps_payload_pack(&pps, ctx->dsi->dsc); >>>> + >>>> + ret = mipi_dsi_picture_parameter_set(ctx->dsi, &pps); >>>> + if (ret < 0) { >>>> + dev_err(dev, "failed to transmit PPS: %d\n", ret); >>>> + goto fail; >>>> + } >>>> + >>>> + ret = mipi_dsi_compression_mode(ctx->dsi, true); >>>> + if (ret < 0) { >>>> + dev_err(dev, "Failed to enable compression mode: %d\n", ret); >>>> + goto fail; >>>> + } >>>> + >>>> + msleep(28); >>>> + } >>>> + >>>> + ctx->prepared = true; >>>> + return 0; >>>> + >>>> +fail: >>>> + gpiod_set_value_cansleep(ctx->reset_gpio, 1); >>>> + regulator_disable(ctx->vci); >>>> + regulator_disable(ctx->vddio); >>>> + return ret; >>>> +} >>>> + >>>> +static int samsung_sofef03_m_unprepare(struct drm_panel *panel) >>>> +{ >>>> + struct samsung_sofef03_m *ctx = to_samsung_sofef03_m(panel); >>>> + struct device *dev = &ctx->dsi->dev; >>>> + int ret; >>>> + >>>> + if (!ctx->prepared) >>>> + return 0; >>>> + >>>> + ret = samsung_sofef03_m_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_disable(ctx->vci); >>>> + regulator_disable(ctx->vddio); >>>> + >>>> + ctx->prepared = false; >>>> + return 0; >>>> +} >>>> + >>>> +static const struct drm_display_mode samsung_sofef03_m_60hz_mode = { >>>> + .clock = (1080 + 156 + 8 + 8) * (2520 + 2393 + 8 + 8) * 60 / 1000, >>>> + .hdisplay = 1080, >>>> + .hsync_start = 1080 + 156, >>>> + .hsync_end = 1080 + 156 + 8, >>>> + .htotal = 1080 + 156 + 8 + 8, >>>> + .vdisplay = 2520, >>>> + .vsync_start = 2520 + 2393, >>>> + .vsync_end = 2520 + 2393 + 8, >>>> + .vtotal = 2520 + 2393 + 8 + 8, >>>> + .width_mm = 61, >>>> + .height_mm = 142, >>>> +}; >>>> + >>>> +static const struct drm_display_mode samsung_sofef03_m_120hz_mode = { >>>> + .clock = (1080 + 56 + 8 + 8) * (2520 + 499 + 8 + 8) * 120 / 1000, >>>> + .hdisplay = 1080, >>>> + .hsync_start = 1080 + 56, >>>> + .hsync_end = 1080 + 56 + 8, >>>> + .htotal = 1080 + 56 + 8 + 8, >>>> + .vdisplay = 2520, >>>> + .vsync_start = 2520 + 499, >>>> + .vsync_end = 2520 + 499 + 8, >>>> + .vtotal = 2520 + 499 + 8 + 8, >>>> + .width_mm = 61, >>>> + .height_mm = 142, >>>> +}; >>>> + >>>> +static int samsung_sofef03_m_get_modes(struct drm_panel *panel, >>>> + struct drm_connector *connector) >>>> +{ >>>> + if (enable_120hz) >>> >>> Is it possible to switch between these modes at runtime? It might be logical to define 60 Hz mode as preferred, while allowing users to switch to 120 Hz when required for some reason. > > I'd love to define two modes but as described in the cover letter - and > the reason to send this as RFC - drm_panel currently does not expose the > mode back to the driver in e.g. _prepare, so I cannot update or resend > the necessary dcs commands to set **or change** the current mode > (downstream defines commands to change the rate without fully resetting > the panel). > > I can either convert this to drm_bridge (is that easy / worth it?) or > hack it in with a global as done here so that we can tackle that > endeavour separately, while at least having the drivers upstream (or on > the lists) as requested by quic for DSC development. > >>>> + return drm_connector_helper_get_modes_fixed(connector, >>>> + &samsung_sofef03_m_120hz_mode); >>>> + else >>>> + return drm_connector_helper_get_modes_fixed(connector, >>>> + &samsung_sofef03_m_60hz_mode); >>>> +} >>>> + >>>> +static const struct drm_panel_funcs samsung_sofef03_m_panel_funcs = { >>>> + .prepare = samsung_sofef03_m_prepare, >>>> + .unprepare = samsung_sofef03_m_unprepare, >>>> + .get_modes = samsung_sofef03_m_get_modes, >>>> +}; >>>> + >>>> +static int samsung_sofef03_m_bl_update_status(struct backlight_device *bl) >>>> +{ >>>> + struct mipi_dsi_device *dsi = bl_get_data(bl); >>>> + u16 brightness = backlight_get_brightness(bl); >>>> + int ret; >>>> + >>>> + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; >>>> + >>>> + pr_err("Writing %#x\n", brightness); >> >> You forgot to remove those desbug prints :-p > > RFC: I indeed forgot to mention this in the cover letter but this driver > is still mostly broken beyond displaying an image. Setting brightness > here does nothing (except after sending the command many times in quick > succession by e.g. a brightness slider in UI, the panel gets stuck on a > broken image) and the panel remained black if it wasn't for the random > set_brightness_large(100) in _prepare. > > I will remove these in a followup once figuring out how to make and keep > it working. > > - Marijn
On 30/05/2023 00:29, Konrad Dybcio wrote: > > > On 29.05.2023 23:21, Marijn Suijten wrote: >> On 2023-05-22 11:08:12, Neil Armstrong wrote: >>> On 22/05/2023 03:23, Dmitry Baryshkov wrote: >>>> On 22/05/2023 00:23, Marijn Suijten wrote: >>>>> The SOFEF03-M Display-IC paired with an unknown panel in the Sony Xperia >>>>> 5 II always uses Display Stream Compression 1.1 and features a 60hz and >>>>> 120hz refresh-rate mode. >>>>> >>>>> Co-developed-by: Konrad Dybcio <konrad.dybcio@somainline.org> >>>> >>>> Konrad's S-o-b is also required then >> >> I am unsure what to include here, since Konrad originally "authored" the >> commit but I believe it was nothing more than a completely broken and >> unusable driver spit out by "The mdss panel generator". This needed >> enough rewriting that I don't feel like giving it much credit ;) > Might have been. I won't be mad if you drop this! I'd say, either add S-o-B, or drop C-D-B. The Co-developed-by should always come with the Signed-of-by, otherwise one can not be sure that the co-developer didn't copy-paste some super-proprietary stolen code. > > Konrad >> >>>> >>>>> Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org>
On 2023-05-30 01:22:54, Dmitry Baryshkov wrote: > On 30/05/2023 00:29, Konrad Dybcio wrote: > > > > > > On 29.05.2023 23:21, Marijn Suijten wrote: > >> On 2023-05-22 11:08:12, Neil Armstrong wrote: > >>> On 22/05/2023 03:23, Dmitry Baryshkov wrote: > >>>> On 22/05/2023 00:23, Marijn Suijten wrote: > >>>>> The SOFEF03-M Display-IC paired with an unknown panel in the Sony Xperia > >>>>> 5 II always uses Display Stream Compression 1.1 and features a 60hz and > >>>>> 120hz refresh-rate mode. > >>>>> > >>>>> Co-developed-by: Konrad Dybcio <konrad.dybcio@somainline.org> > >>>> > >>>> Konrad's S-o-b is also required then > >> > >> I am unsure what to include here, since Konrad originally "authored" the > >> commit but I believe it was nothing more than a completely broken and > >> unusable driver spit out by "The mdss panel generator". This needed > >> enough rewriting that I don't feel like giving it much credit ;) > > Might have been. I won't be mad if you drop this! > > I'd say, either add S-o-B, or drop C-D-B. The Co-developed-by should > always come with the Signed-of-by, otherwise one can not be sure that > the co-developer didn't copy-paste some super-proprietary stolen code. That is effectively what the downstream command sequences are, with their meaning removed :P I'll drop it then, that makes most sense I think. - Marijn
diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig index 3f11e9906f2cb..8e2668153bce2 100644 --- a/drivers/gpu/drm/panel/Kconfig +++ b/drivers/gpu/drm/panel/Kconfig @@ -630,6 +630,20 @@ config DRM_PANEL_SAMSUNG_SOFEF01 This panel features a fixed mode of 1080x2520@60. +config DRM_PANEL_SAMSUNG_SOFEF03 + tristate "Samsung sofef03 Sony Xperia 5 II DSI cmd mode panel" + depends on GPIOLIB + depends on OF + depends on DRM_MIPI_DSI + depends on BACKLIGHT_CLASS_DEVICE + help + Say Y or M here if you want to enable support for the Samsung AMOLED + command mode panel found in the Sony Xperia 5 II smartphone. + + This panel uses Display Stream Compression 1.1. + + The panel features a 1080x2520@60 and 1080x2520@120 mode. + config DRM_PANEL_SEIKO_43WVF1G tristate "Seiko 43WVF1G panel" depends on OF diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile index a4039d0fc9cfb..52dcd82e33120 100644 --- a/drivers/gpu/drm/panel/Makefile +++ b/drivers/gpu/drm/panel/Makefile @@ -63,6 +63,7 @@ obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E88A0_AMS452EF01) += panel-samsung-s6e88a0-ams4 obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E8AA0) += panel-samsung-s6e8aa0.o obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF00) += panel-samsung-sofef00.o obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF01) += panel-samsung-sofef01.o +obj-$(CONFIG_DRM_PANEL_SAMSUNG_SOFEF03) += panel-samsung-sofef03.o obj-$(CONFIG_DRM_PANEL_SEIKO_43WVF1G) += panel-seiko-43wvf1g.o obj-$(CONFIG_DRM_PANEL_SHARP_LQ101R1SX01) += panel-sharp-lq101r1sx01.o obj-$(CONFIG_DRM_PANEL_SHARP_LS037V7DW01) += panel-sharp-ls037v7dw01.o diff --git a/drivers/gpu/drm/panel/panel-samsung-sofef03.c b/drivers/gpu/drm/panel/panel-samsung-sofef03.c new file mode 100644 index 0000000000000..2763e1c56b37b --- /dev/null +++ b/drivers/gpu/drm/panel/panel-samsung-sofef03.c @@ -0,0 +1,423 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022 Konrad Dybcio <konrad.dybcio@linaro.org> + * Copyright (c) 2023 Marijn Suijten <marijn.suijten@somainline.org> + */ + +#include <linux/backlight.h> +#include <linux/delay.h> +#include <linux/gpio/consumer.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/regulator/consumer.h> + +#include <video/mipi_display.h> + +#include <drm/drm_mipi_dsi.h> +#include <drm/drm_modes.h> +#include <drm/drm_panel.h> +#include <drm/drm_probe_helper.h> +#include <drm/display/drm_dsc.h> +#include <drm/display/drm_dsc_helper.h> + +static const bool enable_120hz = true; + +struct samsung_sofef03_m { + struct drm_panel panel; + struct mipi_dsi_device *dsi; + struct regulator *vddio, *vci; + struct gpio_desc *reset_gpio; + bool prepared; +}; + +static inline struct samsung_sofef03_m *to_samsung_sofef03_m(struct drm_panel *panel) +{ + return container_of(panel, struct samsung_sofef03_m, panel); +} + +static void samsung_sofef03_m_reset(struct samsung_sofef03_m *ctx) +{ + gpiod_set_value_cansleep(ctx->reset_gpio, 0); + usleep_range(10000, 11000); +} + +static int samsung_sofef03_m_on(struct samsung_sofef03_m *ctx) +{ + struct mipi_dsi_device *dsi = ctx->dsi; + struct device *dev = &dsi->dev; + int ret; + + dsi->mode_flags |= MIPI_DSI_MODE_LPM; + + mipi_dsi_dcs_write_seq(dsi, 0x9d, 0x01); + + ret = mipi_dsi_dcs_exit_sleep_mode(dsi); + if (ret < 0) { + dev_err(dev, "Failed to exit sleep mode: %d\n", ret); + return ret; + } + usleep_range(10000, 11000); + + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x09); + mipi_dsi_dcs_write_seq(dsi, 0xd5, 0x00, 0x00, 0x00); + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x08); + mipi_dsi_dcs_write_seq(dsi, 0xee, 0x00, 0x00); + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); + + ret = mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK); + if (ret < 0) { + dev_err(dev, "Failed to set tear on: %d\n", ret); + return ret; + } + + ret = mipi_dsi_dcs_set_column_address(dsi, 0, 1080 - 1); + if (ret < 0) { + dev_err(dev, "Failed to set column address: %d\n", ret); + return ret; + } + + ret = mipi_dsi_dcs_set_page_address(dsi, 0, 2520 - 1); + if (ret < 0) { + dev_err(dev, "Failed to set page address: %d\n", ret); + return ret; + } + + ret = mipi_dsi_dcs_set_display_brightness_large(dsi, 100); + if (ret < 0) { + dev_err(dev, "Failed to set display brightness: %d\n", ret); + return ret; + } + + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); + mipi_dsi_dcs_write_seq(dsi, 0xdf, 0x83); + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x01); + mipi_dsi_dcs_write_seq(dsi, 0xe6, 0x01); + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x02); + mipi_dsi_dcs_write_seq(dsi, 0xec, 0x02, 0x00, 0x1c, 0x1c); + mipi_dsi_dcs_write_seq(dsi, 0xb0, 0x0c); + mipi_dsi_dcs_write_seq(dsi, 0xec, 0x01, 0x19); + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); + mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_WRITE_CONTROL_DISPLAY, BIT(5)); + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a); + mipi_dsi_dcs_write_seq(dsi, 0xc2, 0x2d, 0x27); + mipi_dsi_dcs_write_seq(dsi, 0x60, enable_120hz ? 0x10 : 0x00); + mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5); + msleep(110); + + ret = mipi_dsi_dcs_set_display_on(dsi); + if (ret < 0) { + dev_err(dev, "Failed to turn display on: %d\n", ret); + return ret; + } + + return 0; +} + +static int samsung_sofef03_m_off(struct samsung_sofef03_m *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 turn display off: %d\n", ret); + return ret; + } + msleep(20); + + 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(100); + + return 0; +} + +static int samsung_sofef03_m_prepare(struct drm_panel *panel) +{ + struct samsung_sofef03_m *ctx = to_samsung_sofef03_m(panel); + struct drm_dsc_picture_parameter_set pps; + struct device *dev = &ctx->dsi->dev; + int ret; + + if (ctx->prepared) + return 0; + + ret = regulator_enable(ctx->vddio); + if (ret < 0) { + dev_err(dev, "Failed to enable vddio regulator: %d\n", ret); + return ret; + } + + ret = regulator_enable(ctx->vci); + if (ret < 0) { + dev_err(dev, "Failed to enable vci regulator: %d\n", ret); + regulator_disable(ctx->vddio); + return ret; + } + + samsung_sofef03_m_reset(ctx); + + ret = samsung_sofef03_m_on(ctx); + if (ret < 0) { + dev_err(dev, "Failed to initialize panel: %d\n", ret); + goto fail; + } + + if (ctx->dsi->dsc) { + drm_dsc_pps_payload_pack(&pps, ctx->dsi->dsc); + + ret = mipi_dsi_picture_parameter_set(ctx->dsi, &pps); + if (ret < 0) { + dev_err(dev, "failed to transmit PPS: %d\n", ret); + goto fail; + } + + ret = mipi_dsi_compression_mode(ctx->dsi, true); + if (ret < 0) { + dev_err(dev, "Failed to enable compression mode: %d\n", ret); + goto fail; + } + + msleep(28); + } + + ctx->prepared = true; + return 0; + +fail: + gpiod_set_value_cansleep(ctx->reset_gpio, 1); + regulator_disable(ctx->vci); + regulator_disable(ctx->vddio); + return ret; +} + +static int samsung_sofef03_m_unprepare(struct drm_panel *panel) +{ + struct samsung_sofef03_m *ctx = to_samsung_sofef03_m(panel); + struct device *dev = &ctx->dsi->dev; + int ret; + + if (!ctx->prepared) + return 0; + + ret = samsung_sofef03_m_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_disable(ctx->vci); + regulator_disable(ctx->vddio); + + ctx->prepared = false; + return 0; +} + +static const struct drm_display_mode samsung_sofef03_m_60hz_mode = { + .clock = (1080 + 156 + 8 + 8) * (2520 + 2393 + 8 + 8) * 60 / 1000, + .hdisplay = 1080, + .hsync_start = 1080 + 156, + .hsync_end = 1080 + 156 + 8, + .htotal = 1080 + 156 + 8 + 8, + .vdisplay = 2520, + .vsync_start = 2520 + 2393, + .vsync_end = 2520 + 2393 + 8, + .vtotal = 2520 + 2393 + 8 + 8, + .width_mm = 61, + .height_mm = 142, +}; + +static const struct drm_display_mode samsung_sofef03_m_120hz_mode = { + .clock = (1080 + 56 + 8 + 8) * (2520 + 499 + 8 + 8) * 120 / 1000, + .hdisplay = 1080, + .hsync_start = 1080 + 56, + .hsync_end = 1080 + 56 + 8, + .htotal = 1080 + 56 + 8 + 8, + .vdisplay = 2520, + .vsync_start = 2520 + 499, + .vsync_end = 2520 + 499 + 8, + .vtotal = 2520 + 499 + 8 + 8, + .width_mm = 61, + .height_mm = 142, +}; + +static int samsung_sofef03_m_get_modes(struct drm_panel *panel, + struct drm_connector *connector) +{ + if (enable_120hz) + return drm_connector_helper_get_modes_fixed(connector, + &samsung_sofef03_m_120hz_mode); + else + return drm_connector_helper_get_modes_fixed(connector, + &samsung_sofef03_m_60hz_mode); +} + +static const struct drm_panel_funcs samsung_sofef03_m_panel_funcs = { + .prepare = samsung_sofef03_m_prepare, + .unprepare = samsung_sofef03_m_unprepare, + .get_modes = samsung_sofef03_m_get_modes, +}; + +static int samsung_sofef03_m_bl_update_status(struct backlight_device *bl) +{ + struct mipi_dsi_device *dsi = bl_get_data(bl); + u16 brightness = backlight_get_brightness(bl); + int ret; + + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; + + pr_err("Writing %#x\n", brightness); + + ret = mipi_dsi_dcs_set_display_brightness_large(dsi, brightness); + if (ret < 0) + return ret; + + dsi->mode_flags |= MIPI_DSI_MODE_LPM; + + return 0; +} + +static int samsung_sofef03_m_bl_get_brightness(struct backlight_device *bl) +{ + struct mipi_dsi_device *dsi = bl_get_data(bl); + u16 brightness; + int ret; + + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; + + ret = mipi_dsi_dcs_get_display_brightness_large(dsi, &brightness); + if (ret < 0) + return ret; + + dsi->mode_flags |= MIPI_DSI_MODE_LPM; + + pr_err("Read display brightness %#x\n", brightness); + + return brightness; +} + +static const struct backlight_ops samsung_sofef03_m_bl_ops = { + .update_status = samsung_sofef03_m_bl_update_status, + .get_brightness = samsung_sofef03_m_bl_get_brightness, +}; + +static struct backlight_device * +samsung_sofef03_m_create_backlight(struct mipi_dsi_device *dsi) +{ + struct device *dev = &dsi->dev; + const struct backlight_properties props = { + .type = BACKLIGHT_RAW, + .brightness = 100, + .max_brightness = 1023, + }; + + return devm_backlight_device_register(dev, dev_name(dev), dev, dsi, + &samsung_sofef03_m_bl_ops, &props); +} + +static int samsung_sofef03_m_probe(struct mipi_dsi_device *dsi) +{ + struct device *dev = &dsi->dev; + struct drm_dsc_config *dsc; + struct samsung_sofef03_m *ctx; + int ret; + + ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + ctx->vddio = devm_regulator_get(dev, "vddio"); + if (IS_ERR(ctx->vddio)) + return dev_err_probe(dev, PTR_ERR(ctx->vddio), + "Failed to get vddio regulator\n"); + + ctx->vci = devm_regulator_get(dev, "vci"); + if (IS_ERR(ctx->vci)) + return dev_err_probe(dev, PTR_ERR(ctx->vci), + "Failed to get vci regulator\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_CLOCK_NON_CONTINUOUS; + + drm_panel_init(&ctx->panel, dev, &samsung_sofef03_m_panel_funcs, + DRM_MODE_CONNECTOR_DSI); + + ctx->panel.backlight = samsung_sofef03_m_create_backlight(dsi); + if (IS_ERR(ctx->panel.backlight)) + return dev_err_probe(dev, PTR_ERR(ctx->panel.backlight), + "Failed to create backlight\n"); + + drm_panel_add(&ctx->panel); + + /* This panel only supports DSC; unconditionally enable it */ + dsi->dsc = dsc = devm_kzalloc(&dsi->dev, sizeof(*dsc), GFP_KERNEL); + if (!dsc) + return -ENOMEM; + + dsc->dsc_version_major = 1; + dsc->dsc_version_minor = 1; + + dsc->slice_height = 30; + dsc->slice_width = 540; + dsc->slice_count = 2; + dsc->bits_per_component = 8; + dsc->bits_per_pixel = 8 << 4; /* 4 fractional bits */ + dsc->block_pred_enable = true; + + 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 void samsung_sofef03_m_remove(struct mipi_dsi_device *dsi) +{ + struct samsung_sofef03_m *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); +} + +static const struct of_device_id samsung_sofef03_m_of_match[] = { + { .compatible = "samsung,sofef03-m" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, samsung_sofef03_m_of_match); + +static struct mipi_dsi_driver samsung_sofef03_m_driver = { + .probe = samsung_sofef03_m_probe, + .remove = samsung_sofef03_m_remove, + .driver = { + .name = "panel-samsung-sofef03-m", + .of_match_table = samsung_sofef03_m_of_match, + }, +}; +module_mipi_dsi_driver(samsung_sofef03_m_driver); + +MODULE_AUTHOR("Konrad Dybcio <konrad.dybcio@linaro.org>"); +MODULE_AUTHOR("Marijn Suijten <marijn.suijten@somainline.org>"); +MODULE_DESCRIPTION("DRM panel driver for Samsung SOFEF03-M Display-IC panels"); +MODULE_LICENSE("GPL");