From a86d73c20cf219f344513f58d538d4620d68b577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20S=C5=82abo=C5=84?= Date: Thu, 9 Nov 2023 18:23:21 +0100 Subject: [PATCH] Add panel driver --- .../boot/dts/qcom/msm8937-lenovo-l38011.dts | 40 ++ .../gpu/drm/panel/msm8916-generated/Kconfig | 4 + .../gpu/drm/panel/msm8916-generated/Makefile | 1 + .../panel-lenovo-novatek-nt36525.c | 342 ++++++++++++++++++ 4 files changed, 387 insertions(+) create mode 100644 drivers/gpu/drm/panel/msm8916-generated/panel-lenovo-novatek-nt36525.c diff --git a/arch/arm64/boot/dts/qcom/msm8937-lenovo-l38011.dts b/arch/arm64/boot/dts/qcom/msm8937-lenovo-l38011.dts index e8a24847657a18..b7885e2c37f294 100644 --- a/arch/arm64/boot/dts/qcom/msm8937-lenovo-l38011.dts +++ b/arch/arm64/boot/dts/qcom/msm8937-lenovo-l38011.dts @@ -120,6 +120,46 @@ status = "disabled"; }; +&gpu { + status = "okay"; +}; + +&mdss { + status = "okay"; +}; + +&dsi0 { + status = "okay"; + vdda-supply = <&pm8937_l2>; + vddio-supply = <&pm8937_l6>; + + panel@0 { + compatible = "lenovo,l38011-panel"; + reg = <0>; + + reset-gpios = <&tlmm 98 GPIO_ACTIVE_LOW>; + + port { + panel_in: endpoint { + remote-endpoint = <&dsi0_out>; + }; + }; + }; +}; + +&dsi0_out { + data-lanes = <0 1 2 3>; + remote-endpoint = <&panel_in>; +}; + + +&dsi_phy0 { + vddio-supply = <&pm8937_l6>; + vcca-supply = <&pm8937_s3>; + qcom,dsi-phy-regulator-ldo-mode; + status = "okay"; +}; + &wcnss { status = "okay"; }; diff --git a/drivers/gpu/drm/panel/msm8916-generated/Kconfig b/drivers/gpu/drm/panel/msm8916-generated/Kconfig index 9d07cc04390052..ee43d6ae3a8943 100644 --- a/drivers/gpu/drm/panel/msm8916-generated/Kconfig +++ b/drivers/gpu/drm/panel/msm8916-generated/Kconfig @@ -45,6 +45,10 @@ config DRM_PANEL_HUAWEI_TIANMA_NT35521 tristate "Huawei TIANMA NT35521" default DRM_PANEL_MSM8916_GENERATED +config DRM_PANEL_LENOVO_NOVATEK_NT36525 + tristate "Lenovo Novatek NT36525" + default DRM_PANEL_MSM8916_GENERATED + config DRM_PANEL_LONGCHEER_BOOYI_OTM1287 tristate "Longcheer BOOYI OTM1287" default DRM_PANEL_MSM8916_GENERATED diff --git a/drivers/gpu/drm/panel/msm8916-generated/Makefile b/drivers/gpu/drm/panel/msm8916-generated/Makefile index 9c271a696e3723..b747aa08d03ae3 100644 --- a/drivers/gpu/drm/panel/msm8916-generated/Makefile +++ b/drivers/gpu/drm/panel/msm8916-generated/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_DRM_PANEL_HUAWEI_BOE_OTM8019A) += panel-huawei-boe-otm8019a.o obj-$(CONFIG_DRM_PANEL_HUAWEI_KIWI_CMI_NT35532) += panel-huawei-kiwi-cmi-nt35532.o obj-$(CONFIG_DRM_PANEL_HUAWEI_KIWI_TIANMA_NT35596) += panel-huawei-kiwi-tianma-nt35596.o obj-$(CONFIG_DRM_PANEL_HUAWEI_TIANMA_NT35521) += panel-huawei-tianma-nt35521.o +obj-$(CONFIG_DRM_PANEL_WINGTECH_YASSY_ILI9881) += panel-lenovo-novatek-nt36525.o obj-$(CONFIG_DRM_PANEL_LONGCHEER_BOOYI_OTM1287) += panel-longcheer-booyi-otm1287.o obj-$(CONFIG_DRM_PANEL_LONGCHEER_DIJING_ILI9881C) += panel-longcheer-dijing-ili9881c.o obj-$(CONFIG_DRM_PANEL_LONGCHEER_TRULY_NT35695) += panel-longcheer-truly-nt35695.o diff --git a/drivers/gpu/drm/panel/msm8916-generated/panel-lenovo-novatek-nt36525.c b/drivers/gpu/drm/panel/msm8916-generated/panel-lenovo-novatek-nt36525.c new file mode 100644 index 00000000000000..3bfe54ac17e02b --- /dev/null +++ b/drivers/gpu/drm/panel/msm8916-generated/panel-lenovo-novatek-nt36525.c @@ -0,0 +1,342 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (c) 2023 FIXME +// Generated with linux-mdss-dsi-panel-driver-generator from vendor device tree: +// Copyright (c) 2013, The Linux Foundation. All rights reserved. (FIXME) + +#include +#include +#include +#include + +#include +#include +#include + +struct nt36525_innolux { + struct drm_panel panel; + struct mipi_dsi_device *dsi; + struct gpio_desc *reset_gpio; + bool prepared; +}; + +static inline +struct nt36525_innolux *to_nt36525_innolux(struct drm_panel *panel) +{ + return container_of(panel, struct nt36525_innolux, panel); +} + +#define dsi_generic_write_seq(dsi, seq...) do { \ + static const u8 d[] = { seq }; \ + int ret; \ + ret = mipi_dsi_generic_write(dsi, d, ARRAY_SIZE(d)); \ + if (ret < 0) \ + return ret; \ + } while (0) + +static void nt36525_innolux_reset(struct nt36525_innolux *ctx) +{ + gpiod_set_value_cansleep(ctx->reset_gpio, 0); + usleep_range(1000, 2000); + gpiod_set_value_cansleep(ctx->reset_gpio, 1); + usleep_range(5000, 6000); + gpiod_set_value_cansleep(ctx->reset_gpio, 0); + usleep_range(10000, 11000); +} + +static int nt36525_innolux_on(struct nt36525_innolux *ctx) +{ + struct mipi_dsi_device *dsi = ctx->dsi; + struct device *dev = &dsi->dev; + int ret; + + dsi_generic_write_seq(dsi, 0xff, 0x22); + dsi_generic_write_seq(dsi, 0xfb, 0x01); + dsi_generic_write_seq(dsi, 0x00, 0x00); + dsi_generic_write_seq(dsi, 0x01, 0x00); + dsi_generic_write_seq(dsi, 0x02, 0x00); + dsi_generic_write_seq(dsi, 0x03, 0x00); + dsi_generic_write_seq(dsi, 0x04, 0x00); + dsi_generic_write_seq(dsi, 0x05, 0x00); + dsi_generic_write_seq(dsi, 0x06, 0x00); + dsi_generic_write_seq(dsi, 0x07, 0x00); + dsi_generic_write_seq(dsi, 0x08, 0x00); + dsi_generic_write_seq(dsi, 0x09, 0x00); + dsi_generic_write_seq(dsi, 0x0a, 0x00); + dsi_generic_write_seq(dsi, 0x0b, 0x00); + dsi_generic_write_seq(dsi, 0x0c, 0x00); + dsi_generic_write_seq(dsi, 0x0d, 0x00); + dsi_generic_write_seq(dsi, 0x0e, 0x00); + dsi_generic_write_seq(dsi, 0x0f, 0x00); + dsi_generic_write_seq(dsi, 0x10, 0x00); + dsi_generic_write_seq(dsi, 0x11, 0x00); + dsi_generic_write_seq(dsi, 0x12, 0x00); + dsi_generic_write_seq(dsi, 0x13, 0x00); + dsi_generic_write_seq(dsi, 0x1a, 0x00); + dsi_generic_write_seq(dsi, 0x1b, 0x30); + dsi_generic_write_seq(dsi, 0x1c, 0x30); + dsi_generic_write_seq(dsi, 0x1d, 0x30); + dsi_generic_write_seq(dsi, 0x1e, 0x30); + dsi_generic_write_seq(dsi, 0x1f, 0x30); + dsi_generic_write_seq(dsi, 0x20, 0x30); + dsi_generic_write_seq(dsi, 0x21, 0x30); + dsi_generic_write_seq(dsi, 0x22, 0x30); + dsi_generic_write_seq(dsi, 0x23, 0x30); + dsi_generic_write_seq(dsi, 0x24, 0x30); + dsi_generic_write_seq(dsi, 0x25, 0x30); + dsi_generic_write_seq(dsi, 0x26, 0x30); + dsi_generic_write_seq(dsi, 0x27, 0x30); + dsi_generic_write_seq(dsi, 0x28, 0x30); + dsi_generic_write_seq(dsi, 0x29, 0x30); + dsi_generic_write_seq(dsi, 0x2a, 0x30); + dsi_generic_write_seq(dsi, 0x2b, 0x30); + dsi_generic_write_seq(dsi, 0x2f, 0x30); + dsi_generic_write_seq(dsi, 0x30, 0x30); + dsi_generic_write_seq(dsi, 0x31, 0x30); + dsi_generic_write_seq(dsi, 0x32, 0x12); + dsi_generic_write_seq(dsi, 0x33, 0x16); + dsi_generic_write_seq(dsi, 0x34, 0x15); + dsi_generic_write_seq(dsi, 0x35, 0x13); + dsi_generic_write_seq(dsi, 0x36, 0x0a); + dsi_generic_write_seq(dsi, 0x37, 0x06); + dsi_generic_write_seq(dsi, 0x38, 0x02); + dsi_generic_write_seq(dsi, 0x39, 0x02); + dsi_generic_write_seq(dsi, 0x3a, 0x06); + dsi_generic_write_seq(dsi, 0x3b, 0x0f); + dsi_generic_write_seq(dsi, 0x3f, 0x1a); + dsi_generic_write_seq(dsi, 0x40, 0x18); + dsi_generic_write_seq(dsi, 0x41, 0x15); + dsi_generic_write_seq(dsi, 0x42, 0x13); + dsi_generic_write_seq(dsi, 0x43, 0x10); + dsi_generic_write_seq(dsi, 0x44, 0x0e); + dsi_generic_write_seq(dsi, 0x45, 0x0e); + dsi_generic_write_seq(dsi, 0x46, 0x10); + dsi_generic_write_seq(dsi, 0x47, 0x12); + dsi_generic_write_seq(dsi, 0x48, 0x13); + dsi_generic_write_seq(dsi, 0x49, 0x13); + dsi_generic_write_seq(dsi, 0x4a, 0x13); + dsi_generic_write_seq(dsi, 0x4b, 0x12); + dsi_generic_write_seq(dsi, 0x4c, 0x11); + dsi_generic_write_seq(dsi, 0x4d, 0x20); + dsi_generic_write_seq(dsi, 0x4e, 0x00); + dsi_generic_write_seq(dsi, 0x4f, 0x00); + dsi_generic_write_seq(dsi, 0x50, 0x00); + dsi_generic_write_seq(dsi, 0x51, 0x00); + dsi_generic_write_seq(dsi, 0x52, 0x00); + dsi_generic_write_seq(dsi, 0x53, 0x01); + dsi_generic_write_seq(dsi, 0x54, 0x01); + dsi_generic_write_seq(dsi, 0x55, 0x01); + dsi_generic_write_seq(dsi, 0x56, 0x00); + dsi_generic_write_seq(dsi, 0x58, 0x12); + dsi_generic_write_seq(dsi, 0x59, 0x0e); + dsi_generic_write_seq(dsi, 0x68, 0x00); + dsi_generic_write_seq(dsi, 0x84, 0x00); + dsi_generic_write_seq(dsi, 0x85, 0x00); + dsi_generic_write_seq(dsi, 0x86, 0x00); + dsi_generic_write_seq(dsi, 0x87, 0x00); + dsi_generic_write_seq(dsi, 0x88, 0x00); + dsi_generic_write_seq(dsi, 0xa2, 0x20); + dsi_generic_write_seq(dsi, 0xff, 0x27); + dsi_generic_write_seq(dsi, 0xfb, 0x01); + dsi_generic_write_seq(dsi, 0xad, 0x25); + dsi_generic_write_seq(dsi, 0xae, 0x55); + dsi_generic_write_seq(dsi, 0xaf, 0x05); + dsi_generic_write_seq(dsi, 0xff, 0x26); + dsi_generic_write_seq(dsi, 0xfb, 0x01); + dsi_generic_write_seq(dsi, 0x19, 0x12); + dsi_generic_write_seq(dsi, 0xff, 0x10); + dsi_generic_write_seq(dsi, 0x55, 0x80); + + ret = mipi_dsi_dcs_exit_sleep_mode(dsi); + if (ret < 0) { + dev_err(dev, "Failed to exit sleep mode: %d\n", ret); + return ret; + } + msleep(100); + + ret = mipi_dsi_dcs_set_display_on(dsi); + if (ret < 0) { + dev_err(dev, "Failed to set display on: %d\n", ret); + return ret; + } + msleep(20); + + return 0; +} + +static int nt36525_innolux_off(struct nt36525_innolux *ctx) +{ + struct mipi_dsi_device *dsi = ctx->dsi; + struct device *dev = &dsi->dev; + int ret; + + ret = mipi_dsi_dcs_set_display_off(dsi); + if (ret < 0) { + dev_err(dev, "Failed to set 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(120); + + return 0; +} + +static int nt36525_innolux_prepare(struct drm_panel *panel) +{ + struct nt36525_innolux *ctx = to_nt36525_innolux(panel); + struct device *dev = &ctx->dsi->dev; + int ret; + + if (ctx->prepared) + return 0; + + nt36525_innolux_reset(ctx); + + ret = nt36525_innolux_on(ctx); + if (ret < 0) { + dev_err(dev, "Failed to initialize panel: %d\n", ret); + gpiod_set_value_cansleep(ctx->reset_gpio, 1); + return ret; + } + + ctx->prepared = true; + return 0; +} + +static int nt36525_innolux_unprepare(struct drm_panel *panel) +{ + struct nt36525_innolux *ctx = to_nt36525_innolux(panel); + struct device *dev = &ctx->dsi->dev; + int ret; + + if (!ctx->prepared) + return 0; + + ret = nt36525_innolux_off(ctx); + if (ret < 0) + dev_err(dev, "Failed to un-initialize panel: %d\n", ret); + + gpiod_set_value_cansleep(ctx->reset_gpio, 1); + + ctx->prepared = false; + return 0; +} + +static const struct drm_display_mode nt36525_innolux_mode = { + .clock = (720 + 72 + 8 + 152) * (1440 + 10 + 2 + 8) * 60 / 1000, + .hdisplay = 720, + .hsync_start = 720 + 72, + .hsync_end = 720 + 72 + 8, + .htotal = 720 + 72 + 8 + 152, + .vdisplay = 1440, + .vsync_start = 1440 + 10, + .vsync_end = 1440 + 10 + 2, + .vtotal = 1440 + 10 + 2 + 8, + .width_mm = 68, + .height_mm = 129, +}; + +static int nt36525_innolux_get_modes(struct drm_panel *panel, + struct drm_connector *connector) +{ + struct drm_display_mode *mode; + + mode = drm_mode_duplicate(connector->dev, &nt36525_innolux_mode); + if (!mode) + return -ENOMEM; + + drm_mode_set_name(mode); + + mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED; + connector->display_info.width_mm = mode->width_mm; + connector->display_info.height_mm = mode->height_mm; + drm_mode_probed_add(connector, mode); + + return 1; +} + +static const struct drm_panel_funcs nt36525_innolux_panel_funcs = { + .prepare = nt36525_innolux_prepare, + .unprepare = nt36525_innolux_unprepare, + .get_modes = nt36525_innolux_get_modes, +}; + +static int nt36525_innolux_probe(struct mipi_dsi_device *dsi) +{ + struct device *dev = &dsi->dev; + struct nt36525_innolux *ctx; + int ret; + + ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(ctx->reset_gpio)) + return dev_err_probe(dev, PTR_ERR(ctx->reset_gpio), + "Failed to get reset-gpios\n"); + + ctx->dsi = dsi; + mipi_dsi_set_drvdata(dsi, ctx); + + dsi->lanes = 4; + dsi->format = MIPI_DSI_FMT_RGB888; + dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST | + MIPI_DSI_MODE_NO_EOT_PACKET | + MIPI_DSI_CLOCK_NON_CONTINUOUS | MIPI_DSI_MODE_LPM; + + drm_panel_init(&ctx->panel, dev, &nt36525_innolux_panel_funcs, + DRM_MODE_CONNECTOR_DSI); + + ret = drm_panel_of_backlight(&ctx->panel); + if (ret) + return dev_err_probe(dev, ret, "Failed to get backlight\n"); + + drm_panel_add(&ctx->panel); + + ret = mipi_dsi_attach(dsi); + if (ret < 0) { + dev_err(dev, "Failed to attach to DSI host: %d\n", ret); + drm_panel_remove(&ctx->panel); + return ret; + } + + return 0; +} + +static void nt36525_innolux_remove(struct mipi_dsi_device *dsi) +{ + struct nt36525_innolux *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 nt36525_innolux_of_match[] = { + { .compatible = "lenovo,innolux-nt36525" }, // FIXME + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, nt36525_innolux_of_match); + +static struct mipi_dsi_driver nt36525_innolux_driver = { + .probe = nt36525_innolux_probe, + .remove = nt36525_innolux_remove, + .driver = { + .name = "panel-novatek-nt36523", + .of_match_table = nt36525_innolux_of_match, + }, +}; +module_mipi_dsi_driver(nt36525_innolux_driver); + +MODULE_AUTHOR("linux-mdss-dsi-panel-driver-generator "); // FIXME +MODULE_DESCRIPTION("DRM driver for nt36525 innolux video mode dsi panel"); +MODULE_LICENSE("GPL");