aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSumit Semwal <sumit.semwal@linaro.org>2019-06-19 12:06:21 +0530
committerSumit Semwal <sumit.semwal@linaro.org>2019-06-24 16:11:11 +0530
commit90d8b89de9e2f7e616776adb2c4b7bef8927c0f9 (patch)
tree5127a313e38436fd00a8b91f563af4ecf14599de
parent2e2544287eb4eadbd7e3a5d4bcba31362ec6386c (diff)
wip: add lg sw43408 panel
Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
-rw-r--r--MAINTAINERS7
-rw-r--r--drivers/gpu/drm/panel/Kconfig11
-rw-r--r--drivers/gpu/drm/panel/Makefile1
-rw-r--r--drivers/gpu/drm/panel/panel-lg-sw43408.c559
4 files changed, 578 insertions, 0 deletions
diff --git a/MAINTAINERS b/MAINTAINERS
index 57f496cff999..f9f53dce0649 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5033,6 +5033,13 @@ S: Orphan / Obsolete
F: drivers/gpu/drm/i810/
F: include/uapi/drm/i810_drm.h
+DRM DRIVER FOR LG SW43408 PANELS
+M: Sumit Semwal <sumit.semwal@linaro.org>
+T: git git://anongit.freedesktop.org/drm/drm-misc
+S: Maintained
+F: drivers/gpu/drm/panel/panel-lg-sw43408.c
+F: Documentation/devicetree/bindings/display/panel/lg,sw43408-panel.txt
+
DRM DRIVER FOR MATROX G200/G400 GRAPHICS CARDS
S: Orphan / Obsolete
F: drivers/gpu/drm/mga/
diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
index e281fc544742..24c762e1e203 100644
--- a/drivers/gpu/drm/panel/Kconfig
+++ b/drivers/gpu/drm/panel/Kconfig
@@ -98,6 +98,17 @@ config DRM_PANEL_KINGDISPLAY_KD097D04
24 bit RGB per pixel. It provides a MIPI DSI interface to
the host and has a built-in LED backlight.
+config DRM_PANEL_LG_SW43408
+ tristate "LG SW43408 panel"
+ depends on OF
+ depends on DRM_MIPI_DSI
+ depends on BACKLIGHT_CLASS_DEVICE
+ help
+ Say Y here if you want to enable support for LG sw43408 panel.
+ The panel has a 1080x2160 resolution and uses
+ 24 bit RGB per pixel. It provides a MIPI DSI interface to
+ the host and has a built-in LED backlight.
+
config DRM_PANEL_SAMSUNG_LD9040
tristate "Samsung LD9040 RGB/SPI panel"
depends on OF && SPI
diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile
index 78e3dc376bdd..61169b3ea684 100644
--- a/drivers/gpu/drm/panel/Makefile
+++ b/drivers/gpu/drm/panel/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_DRM_PANEL_INNOLUX_P079ZCA) += panel-innolux-p079zca.o
obj-$(CONFIG_DRM_PANEL_JDI_LT070ME05000) += panel-jdi-lt070me05000.o
obj-$(CONFIG_DRM_PANEL_KINGDISPLAY_KD097D04) += panel-kingdisplay-kd097d04.o
obj-$(CONFIG_DRM_PANEL_LG_LG4573) += panel-lg-lg4573.o
+obj-$(CONFIG_DRM_PANEL_LG_SW43408) += panel-lg-sw43408.o
obj-$(CONFIG_DRM_PANEL_OLIMEX_LCD_OLINUXINO) += panel-olimex-lcd-olinuxino.o
obj-$(CONFIG_DRM_PANEL_ORISETECH_OTM8009A) += panel-orisetech-otm8009a.o
obj-$(CONFIG_DRM_PANEL_PANASONIC_VVX10F034N00) += panel-panasonic-vvx10f034n00.o
diff --git a/drivers/gpu/drm/panel/panel-lg-sw43408.c b/drivers/gpu/drm/panel/panel-lg-sw43408.c
new file mode 100644
index 000000000000..6f1857de0904
--- /dev/null
+++ b/drivers/gpu/drm/panel/panel-lg-sw43408.c
@@ -0,0 +1,559 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019 Linaro Ltd
+ * Author: Sumit Semwal <sumit.semwal@linaro.org>
+ */
+
+#include <linux/backlight.h>
+#include <linux/delay.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+
+#include <linux/gpio/consumer.h>
+#include <linux/regulator/consumer.h>
+
+#include <drm/drm_device.h>
+#include <drm/drm_mipi_dsi.h>
+#include <drm/drm_modes.h>
+#include <drm/drm_panel.h>
+#include <drm/drm_print.h>
+
+#include <video/mipi_display.h>
+
+/*
+to figure out:
+ - reset_gpio - is ACTIVE_HIGH
+ - does the panel need to set lab-supply?
+ - looks like clocks are taken care of in drivers/gpu/drm/msm/dsi/dsi_host,
+ - do we need pinctrl for panel, or does the dsi_host one suffice?
+
+dsi_sw43408_cmd_display: qcom,dsi-display@51 {
+ compatible = "qcom,dsi-display";
+ label = "dsi_sw43408_cmd_display";
+ qcom,display-type = "primary";
+
+ qcom,dsi-ctrl = <&mdss_dsi0>;
+ qcom,dsi-phy = <&mdss_dsi_phy0>;
+ clocks = <&mdss_dsi0_pll BYTECLK_MUX_0_CLK>,
+ <&mdss_dsi0_pll PCLK_MUX_0_CLK>;
+ clock-names = "src_byte_clk", "src_pixel_clk";
+
+ pinctrl-names = "panel_active", "panel_suspend";
+ pinctrl-0 = <&sde_dsi_active &sde_te_active>;
+ pinctrl-1 = <&sde_dsi_suspend &sde_te_suspend>;
+
+ qcom,dsi-panel = <&dsi_sw43408_dsc_fhd_cmd>;
+
+ vddi-supply = <&pm8998_l14>;
+ vpnl-supply = <&pm8998_l28>;
+ lab-supply = <&lab_regulator>;
+};
+
+&dsi_sw43408_dsc_fhd_cmd {
+ qcom,panel-supply-entries = <&dsi_panel_pwr_supply_sw43408>;
+ qcom,mdss-dsi-t-clk-post = <0x09>;
+ qcom,mdss-dsi-t-clk-pre = <0x1A>;
+
+ qcom,platform-reset-gpio = <&tlmm 6 0>;
+ qcom,mdss-dsi-display-timings {
+ timing@0 {
+ qcom,mdss-dsi-panel-phy-timings =
+ [00 0E 03 03 1E 1D 04 04 02 03 04 00];
+ };
+ };
+};
+
+*/
+
+struct panel_cmd {
+ size_t len;
+ const char *data;
+};
+
+#define _INIT_CMD(...) { \
+ .len = sizeof((char[]){__VA_ARGS__}), \
+ .data = (char[]){__VA_ARGS__} }
+
+static const char * const regulator_names[] = {
+ "vddi",
+ "vpnl",
+// "lab", // Validate the name
+};
+
+static unsigned long const regulator_enable_loads[] = {
+ 62000,
+ 857000,
+// 0, // Confirm this value
+};
+
+static unsigned long const regulator_disable_loads[] = {
+ 80,
+ 0,
+// 0, // confirm this value
+};
+
+struct panel_desc {
+ const struct drm_display_mode *display_mode;
+ const char *panel_name;
+
+ unsigned int width_mm;
+ unsigned int height_mm;
+
+ unsigned long mode_flags;
+ enum mipi_dsi_pixel_format format;
+ unsigned int lanes;
+
+ const struct panel_cmd *on_cmds;
+};
+
+struct panel_info {
+ struct drm_panel base;
+ struct mipi_dsi_device *link;
+ const struct panel_desc *desc;
+
+ struct backlight_device *backlight;
+
+ struct regulator_bulk_data supplies[ARRAY_SIZE(regulator_names)];
+
+ struct gpio_desc *reset_gpio;
+
+ bool prepared;
+ bool enabled;
+};
+
+static inline struct panel_info *to_panel_info(struct drm_panel *panel)
+{
+ return container_of(panel, struct panel_info, base);
+}
+
+static int send_mipi_cmds(struct drm_panel *panel, const struct panel_cmd *cmds)
+{
+ struct panel_info *pinfo = to_panel_info(panel);
+ unsigned int i = 0;
+ int err;
+
+ if (!cmds)
+ return -EFAULT;
+
+ for (i = 0; cmds[i].len != 0; i++) {
+ const struct panel_cmd *cmd = &cmds[i];
+
+ if (cmd->len == 2)
+ err = mipi_dsi_dcs_write(pinfo->link,
+ cmd->data[1], NULL, 0);
+ else
+ err = mipi_dsi_dcs_write(pinfo->link,
+ cmd->data[1], cmd->data + 2,
+ cmd->len - 2);
+
+ if (err < 0)
+ return err;
+
+ usleep_range((cmd->data[0]) * 1000,
+ (1 + cmd->data[0]) * 1000);
+ }
+
+ return 0;
+}
+
+static int lg_panel_disable(struct drm_panel *panel)
+{
+ struct panel_info *pinfo = to_panel_info(panel);
+
+ backlight_disable(pinfo->backlight);
+
+ pinfo->enabled = false;
+
+ return 0;
+}
+
+static int lg_panel_power_off(struct drm_panel *panel)
+{
+ struct panel_info *pinfo = to_panel_info(panel);
+ int i, ret = 0;
+
+ gpiod_set_value(pinfo->reset_gpio, 0);
+
+ for (i = 0; i < ARRAY_SIZE(pinfo->supplies); i++) {
+ ret = regulator_set_load(pinfo->supplies[i].consumer,
+ regulator_disable_loads[i]);
+ if (ret) {
+ DRM_DEV_ERROR(panel->dev,
+ "regulator_set_load failed %d\n", ret);
+ return ret;
+ }
+ }
+
+ ret = regulator_bulk_disable(ARRAY_SIZE(pinfo->supplies), pinfo->supplies);
+ if (ret) {
+ DRM_DEV_ERROR(panel->dev,
+ "regulator_bulk_disable failed %d\n", ret);
+ }
+ return ret;
+}
+
+static int lg_panel_unprepare(struct drm_panel *panel)
+{
+ struct panel_info *pinfo = to_panel_info(panel);
+ int ret;
+
+ if (!pinfo->prepared)
+ return 0;
+
+ ret = mipi_dsi_dcs_write(pinfo->link, MIPI_DCS_SET_DISPLAY_OFF, NULL, 0);
+ if (ret < 0) {
+ DRM_DEV_ERROR(panel->dev,
+ "set_display_off cmd failed ret = %d\n",
+ ret);
+ }
+
+ /* 120ms delay required here as per DCS spec */
+ msleep(120);
+
+ ret = mipi_dsi_dcs_write(pinfo->link, MIPI_DCS_ENTER_SLEEP_MODE, NULL, 0);
+ if (ret < 0) {
+ DRM_DEV_ERROR(panel->dev,
+ "enter_sleep cmd failed ret = %d\n", ret);
+ }
+
+ ret = lg_panel_power_off(panel);
+ if (ret < 0)
+ DRM_DEV_ERROR(panel->dev, "power_off failed ret = %d\n", ret);
+
+ pinfo->prepared = false;
+
+ return ret;
+
+}
+
+static int lg_panel_power_on(struct panel_info *pinfo)
+{
+ int ret, i;
+
+ for (i = 0; i < ARRAY_SIZE(pinfo->supplies); i++) {
+ ret = regulator_set_load(pinfo->supplies[i].consumer,
+ regulator_enable_loads[i]);
+ if (ret)
+ return ret;
+ }
+
+ ret = regulator_bulk_enable(ARRAY_SIZE(pinfo->supplies), pinfo->supplies);
+ if (ret < 0)
+ return ret;
+
+ /*
+ * Reset sequence of LG sw43408 panel requires the panel to be
+ * out of reset for 9ms, followed by being held in reset
+ * for 1ms and then out again
+ * Check: value to set - 0 or 1?
+ */
+ gpiod_set_value(pinfo->reset_gpio, 1);
+ usleep_range(9000, 10000);
+ gpiod_set_value(pinfo->reset_gpio, 0);
+ usleep_range(1000, 2000);
+ gpiod_set_value(pinfo->reset_gpio, 1);
+ usleep_range(9000, 10000);
+
+ return 0;
+}
+
+static int lg_panel_prepare(struct drm_panel *panel)
+{
+ struct panel_info *pinfo = to_panel_info(panel);
+ int err;
+
+ if (pinfo->prepared)
+ return 0;
+
+ err = lg_panel_power_on(pinfo);
+ if (err < 0)
+ goto poweroff;
+
+ /* send init code */
+ err = send_mipi_cmds(panel, pinfo->desc->on_cmds);
+ if (err < 0) {
+ DRM_DEV_ERROR(panel->dev,
+ "failed to send DCS Init Code: %d\n", err);
+ goto poweroff;
+ }
+
+ pinfo->prepared = true;
+
+ return 0;
+
+poweroff:
+ gpiod_set_value(pinfo->reset_gpio, 1);
+ return err;
+}
+
+static int lg_panel_enable(struct drm_panel *panel)
+{
+ struct panel_info *pinfo = to_panel_info(panel);
+ int ret;
+
+ if (pinfo->enabled)
+ return 0;
+
+ ret = backlight_enable(pinfo->backlight);
+ if (ret) {
+ DRM_DEV_ERROR(panel->drm->dev,
+ "Failed to enable backlight %d\n", ret);
+ return ret;
+ }
+
+ pinfo->enabled = true;
+
+ return 0;
+}
+
+static int lg_panel_get_modes(struct drm_panel *panel)
+{
+ struct panel_info *pinfo = to_panel_info(panel);
+ const struct drm_display_mode *m = pinfo->desc->display_mode;
+ struct drm_display_mode *mode;
+
+ mode = drm_mode_duplicate(panel->drm, m);
+ if (!mode) {
+ DRM_DEV_ERROR(panel->drm->dev, "failed to add mode %ux%u@%u\n",
+ m->hdisplay, m->vdisplay, m->vrefresh);
+ return -ENOMEM;
+ }
+
+ panel->connector->display_info.width_mm = pinfo->desc->width_mm;
+ panel->connector->display_info.height_mm = pinfo->desc->height_mm;
+
+ drm_mode_set_name(mode);
+ drm_mode_probed_add(panel->connector, mode);
+
+ return 1;
+}
+
+static const struct drm_panel_funcs panel_funcs = {
+ .disable = lg_panel_disable,
+ .unprepare = lg_panel_unprepare,
+ .prepare = lg_panel_prepare,
+ .enable = lg_panel_enable,
+ .get_modes = lg_panel_get_modes,
+};
+
+/* The on_cmds sequence is translated from the below table, taken from
+ pixel3 panel driver dts:
+qcom,mdss-dsi-on-command = [
+ 15 01 00 00 00 00 02 26 02 => MIPI_DSI_SET_GAMMA_CURVE, 0x02
+ 15 01 00 00 00 00 02 35 00 => MIPI_DSI_SET_TEAR_ON
+ 39 01 00 00 00 00 03 53 0C 30 => as-is;
+ 39 01 00 00 00 00 07 55 00 70 DF 00 70 DF => as-is;
+ 39 01 00 00 00 00 04 F7 01 49 0C => as-is
+ 05 01 00 00 87 00 01 11 => MIPI_DCS_EXIT_SLEEP_MODE
+ 07 01 00 00 00 00 01 11 =??
+ 15 01 00 00 00 00 02 B0 AC
+ 39 01 00 00 00 00 13 CD
+ 00 00 00 19 19 19 19 19
+ 19 19 19 19 19 19 19 19
+ 16 16
+ 39 01 00 00 00 00 06 CB 80 5C 07 03 28
+ 39 01 00 00 00 00 04 C0 02 02 0F
+ 39 01 00 00 00 00 08 E5
+ 00 3A 00 3A 00 0E 10
+ 39 01 00 00 00 00 2A B5
+ 75 60 2D 5D 80 00 0A 0B
+ 00 05 0B 00 80 0D 0E 40
+ 00 0C 00 16 00 B8 00 80
+ 0D 0E 40 00 0C 00 16 00
+ B8 00 81 00 03 03 03 01
+ 01
+ 39 01 00 00 00 00 07 55 04 61 DB 04 70 DB
+ 15 01 00 00 00 00 02 B0 CA
+ 05 01 00 00 32 00 01 29 => MIPI_DCS_SET_DISPLAY_ON
+];
+*/
+
+static const struct panel_cmd lg_sw43408_on_cmds[] = {
+ _INIT_CMD(0x00, 0x26, 0x02), // MIPI_DCS_SET_GAMMA_CURVE, 0x02
+ _INIT_CMD(0x00, 0x35, 0x00), // MIPI_DCS_SET_TEAR_ON
+ _INIT_CMD(0x00, 0x53, 0x0C, 0x30),
+ _INIT_CMD(0x00, 0x55, 0x00, 0x70, 0xDF, 0x00, 0x70, 0xDF),
+ _INIT_CMD(0x00, 0xF7, 0x01, 0x49, 0x0C),
+ _INIT_CMD(0x00, 0x11), // MIPI_DCS_EXIT_SLEEP_MODE
+ _INIT_CMD(0x00, 0x11), // repetition, but what does a 07 DTYPE mean?
+ _INIT_CMD(0x00, 0xB0, 0xAC),
+ _INIT_CMD(0x00, 0xCD,
+ 0x00, 0x00, 0x00, 0x19, 0x19, 0x19, 0x19, 0x19,
+ 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19,
+ 0x16, 0x16),
+ _INIT_CMD(0x00, 0xCB, 0x80, 0x5C, 0x07, 0x03, 0x28),
+ _INIT_CMD(0x00, 0xC0, 0x02, 0x02, 0x0F),
+ _INIT_CMD(0x00, 0xE5, 0x00, 0x3A, 0x00, 0x3A, 0x00, 0x0E, 0x10),
+ _INIT_CMD(0x00, 0xB5,
+ 0x75, 0x60, 0x2D, 0x5D, 0x80, 0x00, 0x0A, 0x0B,
+ 0x00, 0x05, 0x0B, 0x00, 0x80, 0x0D, 0x0E, 0x40,
+ 0x00, 0x0C, 0x00, 0x16, 0x00, 0xB8, 0x00, 0x80,
+ 0x0D, 0x0E, 0x40, 0x00, 0x0C, 0x00, 0x16, 0x00,
+ 0xB8, 0x00, 0x81, 0x00, 0x03, 0x03, 0x03, 0x01,
+ 0x01),
+ _INIT_CMD(0x00, 0x55, 0x04, 0x61, 0xDB, 0x04, 0x70, 0xDB),
+ _INIT_CMD(0x00, 0xB0, 0xCA),
+ _INIT_CMD(0x00, 0x29),
+
+ {},
+};
+
+
+
+
+static const struct drm_display_mode lg_panel_default_mode = {
+ .clock = 152340,
+
+ .hdisplay = 1080,
+ .hsync_start = 1080 + 20,
+ .hsync_end = 1080 + 20 + 32,
+ .htotal = 1080 + 20 + 32 + 20,
+
+ .vdisplay = 2160,
+ .vsync_start = 2160 + 20,
+ .vsync_end = 2160 + 20 + 4,
+ .vtotal = 2160 + 20 + 4 + 20,
+ .vrefresh = 60,
+
+ .type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,
+};
+
+static const struct panel_desc lg_panel_desc = {
+ .display_mode = &lg_panel_default_mode,
+
+ .width_mm = 62,
+ .height_mm = 124,
+
+ .mode_flags = MIPI_DSI_MODE_LPM,
+ .format = MIPI_DSI_FMT_RGB888,
+ .lanes = 4,
+ .on_cmds = lg_sw43408_on_cmds,
+};
+
+
+static const struct of_device_id panel_of_match[] = {
+ { .compatible = "lg,sw43408",
+ .data = &lg_panel_desc
+ },
+ {
+ /* sentinel */
+ }
+};
+MODULE_DEVICE_TABLE(of, panel_of_match);
+
+static int panel_add(struct panel_info *pinfo)
+{
+ struct device *dev = &pinfo->link->dev;
+ int i, ret;
+
+ for (i = 0; i < ARRAY_SIZE(pinfo->supplies); i++)
+ pinfo->supplies[i].supply = regulator_names[i];
+
+ ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(pinfo->supplies),
+ pinfo->supplies);
+ if (ret < 0)
+ return ret;
+
+ pinfo->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+ if (IS_ERR(pinfo->reset_gpio)) {
+ DRM_DEV_ERROR(dev, "cannot get reset gpio %ld\n",
+ PTR_ERR(pinfo->reset_gpio));
+ return PTR_ERR(pinfo->reset_gpio);
+ }
+
+ pinfo->backlight = devm_of_find_backlight(dev);
+ if (IS_ERR(pinfo->backlight))
+ return PTR_ERR(pinfo->backlight);
+
+ drm_panel_init(&pinfo->base);
+ pinfo->base.funcs = &panel_funcs;
+ pinfo->base.dev = &pinfo->link->dev;
+
+ ret = drm_panel_add(&pinfo->base);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+static void panel_del(struct panel_info *pinfo)
+{
+ if (pinfo->base.dev)
+ drm_panel_remove(&pinfo->base);
+}
+
+static int panel_probe(struct mipi_dsi_device *dsi)
+{
+ struct panel_info *pinfo;
+ const struct panel_desc *desc;
+ int err;
+
+ pinfo = devm_kzalloc(&dsi->dev, sizeof(*pinfo), GFP_KERNEL);
+ if (!pinfo)
+ return -ENOMEM;
+
+ desc = of_device_get_match_data(&dsi->dev);
+ dsi->mode_flags = desc->mode_flags;
+ dsi->format = desc->format;
+ dsi->lanes = desc->lanes;
+ pinfo->desc = desc;
+
+ pinfo->link = dsi;
+ mipi_dsi_set_drvdata(dsi, pinfo);
+
+ err = panel_add(pinfo);
+ if (err < 0)
+ return err;
+
+ return mipi_dsi_attach(dsi);
+}
+
+static int panel_remove(struct mipi_dsi_device *dsi)
+{
+ struct panel_info *pinfo = mipi_dsi_get_drvdata(dsi);
+ int err;
+
+ err = lg_panel_unprepare(&pinfo->base);
+ if (err < 0)
+ DRM_DEV_ERROR(&dsi->dev, "failed to unprepare panel: %d\n",
+ err);
+
+ err = lg_panel_disable(&pinfo->base);
+ if (err < 0)
+ DRM_DEV_ERROR(&dsi->dev, "failed to disable panel: %d\n", err);
+
+ err = mipi_dsi_detach(dsi);
+ if (err < 0)
+ DRM_DEV_ERROR(&dsi->dev, "failed to detach from DSI host: %d\n",
+ err);
+
+ drm_panel_detach(&pinfo->base);
+ panel_del(pinfo);
+
+ return 0;
+}
+
+static void panel_shutdown(struct mipi_dsi_device *dsi)
+{
+ struct panel_info *pinfo = mipi_dsi_get_drvdata(dsi);
+
+ lg_panel_disable(&pinfo->base);
+ lg_panel_unprepare(&pinfo->base);
+}
+
+static struct mipi_dsi_driver panel_driver = {
+ .driver = {
+ .name = "panel-lg-sw43408",
+ .of_match_table = panel_of_match,
+ },
+ .probe = panel_probe,
+ .remove = panel_remove,
+ .shutdown = panel_shutdown,
+};
+module_mipi_dsi_driver(panel_driver);
+
+MODULE_AUTHOR("Sumit Semwal <sumit.semwal@linaro.org>");
+MODULE_DESCRIPTION("LG SW436408 MIPI-DSI LCD panel");
+MODULE_LICENSE("GPL");