<div dir="auto">Hi,<div dir="auto"><br></div><div dir="auto">Thanks for your review. I'll send a v2 soon, however we need to solve the compat string issue first.</div><div dir="auto"><br></div><div dir="auto">How should I document tm5p5? I think it's rather some kind of a model no. along with the nt35596 IC than a vendor name.. Or should we call it something like "unknown,tm5p5-nt35596", perhaps "asus,z00t-tm5p5-n35596" [1]?</div><div dir="auto"><br></div><div dir="auto">[1] Z<span style="font-family:sans-serif">00T is the model number of the smartphone that uses this panel</span></div><div dir="auto"><br></div><div dir="auto">Konrad</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, May 2, 2020, 09:05 Sam Ravnborg <<a href="mailto:sam@ravnborg.org">sam@ravnborg.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Konrad.<br>
<br>
On Fri, May 01, 2020 at 10:48:22PM +0200, Konrad Dybcio wrote:<br>
> This adds support for TMP5P5 NT35596 1080x1920 video<br>
> mode panel that can be found on some Asus Zenfone 2<br>
> Laser (Z00T) devices.<br>
<br>
Very well-writen driver. Only a few small things in the following.<br>
<br>
Sam<br>
<br>
> <br>
> Signed-off-by: Konrad Dybcio <<a href="mailto:konradybcio@gmail.com" target="_blank" rel="noreferrer">konradybcio@gmail.com</a>><br>
> ---<br>
> drivers/gpu/drm/panel/Kconfig | 9 +<br>
> drivers/gpu/drm/panel/Makefile | 1 +<br>
> drivers/gpu/drm/panel/panel-tm5p5-nt35596.c | 366 ++++++++++++++++++++<br>
> 3 files changed, 376 insertions(+)<br>
> create mode 100644 drivers/gpu/drm/panel/panel-tm5p5-nt35596.c<br>
> <br>
> diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig<br>
> index a1723c1b5fbf8..6ff892334ac4b 100644<br>
> --- a/drivers/gpu/drm/panel/Kconfig<br>
> +++ b/drivers/gpu/drm/panel/Kconfig<br>
> @@ -401,6 +401,15 @@ config DRM_PANEL_SONY_ACX565AKM<br>
> Say Y here if you want to enable support for the Sony ACX565AKM<br>
> 800x600 3.5" panel (found on the Nokia N900).<br>
> <br>
> +config DRM_PANEL_TM5P5_NT35596<br>
> + tristate "TM5P5 NT35596 panel"<br>
> + depends on GPIOLIB && OF<br>
> + depends on DRM_MIPI_DSI<br>
> + help<br>
> + Say Y here if you want to enable support for the TMP5P5<br>
> + NT35596 1080x1920 video mode panel as found in some Asus<br>
> + Zenfone 2 Laser Z00T devices.<br>
> +<br>
> config DRM_PANEL_TPO_TD028TTEC1<br>
> tristate "Toppoly (TPO) TD028TTEC1 panel driver"<br>
> depends on OF && SPI<br>
> diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile<br>
> index 96a883cd66305..4fc7e00b18502 100644<br>
> --- a/drivers/gpu/drm/panel/Makefile<br>
> +++ b/drivers/gpu/drm/panel/Makefile<br>
> @@ -42,6 +42,7 @@ obj-$(CONFIG_DRM_PANEL_SITRONIX_ST7701) += panel-sitronix-st7701.o<br>
> obj-$(CONFIG_DRM_PANEL_SITRONIX_ST7789V) += panel-sitronix-st7789v.o<br>
> obj-$(CONFIG_DRM_PANEL_SONY_ACX424AKP) += panel-sony-acx424akp.o<br>
> obj-$(CONFIG_DRM_PANEL_SONY_ACX565AKM) += panel-sony-acx565akm.o<br>
> +obj-$(CONFIG_DRM_PANEL_TM5P5_NT35596) += panel-tm5p5-nt35596.o<br>
> obj-$(CONFIG_DRM_PANEL_TPO_TD028TTEC1) += panel-tpo-td028ttec1.o<br>
> obj-$(CONFIG_DRM_PANEL_TPO_TD043MTEA1) += panel-tpo-td043mtea1.o<br>
> obj-$(CONFIG_DRM_PANEL_TPO_TPG110) += panel-tpo-tpg110.o<br>
> diff --git a/drivers/gpu/drm/panel/panel-tm5p5-nt35596.c b/drivers/gpu/drm/panel/panel-tm5p5-nt35596.c<br>
> new file mode 100644<br>
> index 0000000000000..c361ab76812b8<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/panel/panel-tm5p5-nt35596.c<br>
> @@ -0,0 +1,366 @@<br>
> +// SPDX-License-Identifier: GPL-2.0-only<br>
> +<br>
> +#include <linux/backlight.h><br>
> +#include <linux/delay.h><br>
> +#include <linux/gpio/consumer.h><br>
> +#include <linux/module.h><br>
> +#include <linux/of.h><br>
> +#include <linux/regulator/consumer.h><br>
> +<br>
> +#include <drm/drm_mipi_dsi.h><br>
> +#include <drm/drm_modes.h><br>
> +#include <drm/drm_panel.h><br>
> +<br>
> +struct tm5p5_nt35596 {<br>
> + struct drm_panel panel;<br>
> + struct mipi_dsi_device *dsi;<br>
> + struct regulator_bulk_data supplies[2];<br>
> + struct gpio_desc *reset_gpio;<br>
> + bool prepared;<br>
> +};<br>
> +<br>
> +static inline struct tm5p5_nt35596 *to_tm5p5_nt35596(struct drm_panel *panel)<br>
> +{<br>
> + return container_of(panel, struct tm5p5_nt35596, panel);<br>
> +}<br>
> +<br>
> +#define dsi_generic_write_seq(dsi, seq...) do { \<br>
> + static const u8 d[] = { seq }; \<br>
> + int ret; \<br>
> + ret = mipi_dsi_generic_write(dsi, d, ARRAY_SIZE(d)); \<br>
> + if (ret < 0) \<br>
> + return ret; \<br>
> + } while (0)<br>
> +<br>
> +#define dsi_dcs_write_seq(dsi, seq...) do { \<br>
> + static const u8 d[] = { seq }; \<br>
> + int ret; \<br>
> + ret = mipi_dsi_dcs_write_buffer(dsi, d, ARRAY_SIZE(d)); \<br>
> + if (ret < 0) \<br>
> + return ret; \<br>
> + } while (0)<br>
> +<br>
> +static void tm5p5_nt35596_reset(struct tm5p5_nt35596 *ctx)<br>
> +{<br>
> + gpiod_set_value_cansleep(ctx->reset_gpio, 1);<br>
> + usleep_range(1000, 2000);<br>
> + gpiod_set_value_cansleep(ctx->reset_gpio, 0);<br>
> + usleep_range(1000, 2000);<br>
> + gpiod_set_value_cansleep(ctx->reset_gpio, 1);<br>
> + usleep_range(15000, 16000);<br>
> +}<br>
> +<br>
> +static int tm5p5_nt35596_on(struct tm5p5_nt35596 *ctx)<br>
> +{<br>
> + struct mipi_dsi_device *dsi = ctx->dsi;<br>
<br>
Do you have any idea of what happens in the following?<br>
I recall 0xff is explained in a few other drivers for example.<br>
<br>
If you get an idea it would be nice with a few headlines.<br>
> +<br>
> + dsi_generic_write_seq(dsi, 0xff, 0x05);<br>
> + dsi_generic_write_seq(dsi, 0xfb, 0x01);<br>
> + dsi_generic_write_seq(dsi, 0xc5, 0x31);<br>
> + dsi_generic_write_seq(dsi, 0xff, 0x04);<br>
> + dsi_generic_write_seq(dsi, 0x01, 0x84);<br>
> + dsi_generic_write_seq(dsi, 0x05, 0x25);<br>
> + dsi_generic_write_seq(dsi, 0x06, 0x01);<br>
> + dsi_generic_write_seq(dsi, 0x07, 0x20);<br>
> + dsi_generic_write_seq(dsi, 0x08, 0x06);<br>
> + dsi_generic_write_seq(dsi, 0x09, 0x08);<br>
> + dsi_generic_write_seq(dsi, 0x0a, 0x10);<br>
> + dsi_generic_write_seq(dsi, 0x0b, 0x10);<br>
> + dsi_generic_write_seq(dsi, 0x0c, 0x10);<br>
> + dsi_generic_write_seq(dsi, 0x0d, 0x14);<br>
> + dsi_generic_write_seq(dsi, 0x0e, 0x14);<br>
> + dsi_generic_write_seq(dsi, 0x0f, 0x14);<br>
> + dsi_generic_write_seq(dsi, 0x10, 0x14);<br>
> + dsi_generic_write_seq(dsi, 0x11, 0x14);<br>
> + dsi_generic_write_seq(dsi, 0x12, 0x14);<br>
> + dsi_generic_write_seq(dsi, 0x17, 0xf3);<br>
> + dsi_generic_write_seq(dsi, 0x18, 0xc0);<br>
> + dsi_generic_write_seq(dsi, 0x19, 0xc0);<br>
> + dsi_generic_write_seq(dsi, 0x1a, 0xc0);<br>
> + dsi_generic_write_seq(dsi, 0x1b, 0xb3);<br>
> + dsi_generic_write_seq(dsi, 0x1c, 0xb3);<br>
> + dsi_generic_write_seq(dsi, 0x1d, 0xb3);<br>
> + dsi_generic_write_seq(dsi, 0x1e, 0xb3);<br>
> + dsi_generic_write_seq(dsi, 0x1f, 0xb3);<br>
> + dsi_generic_write_seq(dsi, 0x20, 0xb3);<br>
> + dsi_generic_write_seq(dsi, 0xfb, 0x01);<br>
> + dsi_generic_write_seq(dsi, 0xff, 0x00);<br>
> + dsi_generic_write_seq(dsi, 0xfb, 0x01);<br>
> + dsi_generic_write_seq(dsi, 0x35, 0x01);<br>
> + dsi_generic_write_seq(dsi, 0xd3, 0x06);<br>
> + dsi_generic_write_seq(dsi, 0xd4, 0x04);<br>
> + dsi_generic_write_seq(dsi, 0x5e, 0x0d);<br>
> + dsi_generic_write_seq(dsi, 0x11, 0x00);<br>
> + msleep(100);<br>
> + dsi_generic_write_seq(dsi, 0x29, 0x00);<br>
> + dsi_generic_write_seq(dsi, 0x53, 0x24);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int tm5p5_nt35596_off(struct tm5p5_nt35596 *ctx)<br>
> +{<br>
> + struct mipi_dsi_device *dsi = ctx->dsi;<br>
> + struct device *dev = &dsi->dev;<br>
> + int ret;<br>
> +<br>
> + ret = mipi_dsi_dcs_set_display_off(dsi);<br>
> + if (ret < 0) {<br>
> + dev_err(dev, "Failed to set display off: %d\n", ret);<br>
> + return ret;<br>
> + }<br>
> + msleep(60);<br>
> +<br>
> + ret = mipi_dsi_dcs_enter_sleep_mode(dsi);<br>
> + if (ret < 0) {<br>
> + dev_err(dev, "Failed to enter sleep mode: %d\n", ret);<br>
> + return ret;<br>
> + }<br>
<br>
I wonder why the panel do not need a:<br>
mipi_dsi_dcs_exit_sleep_mode()<br>
and<br>
mipi_dsi_dcs_set_display_on()<br>
<br>
in the tm5p5_nt35596_on() function.<br>
<br>
Usually the prepare and unprepare steps are<br>
somehow symmetrical.<br>
<br>
> +<br>
> + dsi_dcs_write_seq(dsi, 0x4f, 0x01);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int tm5p5_nt35596_prepare(struct drm_panel *panel)<br>
> +{<br>
> + struct tm5p5_nt35596 *ctx = to_tm5p5_nt35596(panel);<br>
> + struct device *dev = &ctx->dsi->dev;<br>
> + int ret;<br>
> +<br>
> + if (ctx->prepared)<br>
> + return 0;<br>
> +<br>
> + ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies);<br>
> + if (ret < 0) {<br>
> + dev_err(dev, "Failed to enable regulators: %d\n", ret);<br>
> + return ret;<br>
> + }<br>
> +<br>
> + tm5p5_nt35596_reset(ctx);<br>
> +<br>
> + ret = tm5p5_nt35596_on(ctx);<br>
> + if (ret < 0) {<br>
> + dev_err(dev, "Failed to initialize panel: %d\n", ret);<br>
> + gpiod_set_value_cansleep(ctx->reset_gpio, 0);<br>
> + regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);<br>
Line too long.<br>
<br>
> + return ret;<br>
> + }<br>
> +<br>
> + ctx->prepared = true;<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int tm5p5_nt35596_unprepare(struct drm_panel *panel)<br>
> +{<br>
> + struct tm5p5_nt35596 *ctx = to_tm5p5_nt35596(panel);<br>
> + struct device *dev = &ctx->dsi->dev;<br>
> + int ret;<br>
> +<br>
> + if (!ctx->prepared)<br>
> + return 0;<br>
> +<br>
> + ret = tm5p5_nt35596_off(ctx);<br>
> + if (ret < 0)<br>
> + dev_err(dev, "Failed to un-initialize panel: %d\n", ret);<br>
> +<br>
> + gpiod_set_value_cansleep(ctx->reset_gpio, 0);<br>
> + regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);<br>
> +<br>
> + ctx->prepared = false;<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static const struct drm_display_mode tm5p5_nt35596_mode = {<br>
> + .clock = (1080 + 100 + 8 + 16) * (1920 + 4 + 2 + 4) * 60 / 1000,<br>
> + .hdisplay = 1080,<br>
> + .hsync_start = 1080 + 100,<br>
> + .hsync_end = 1080 + 100 + 8,<br>
> + .htotal = 1080 + 100 + 8 + 16,<br>
> + .vdisplay = 1920,<br>
> + .vsync_start = 1920 + 4,<br>
> + .vsync_end = 1920 + 4 + 2,<br>
> + .vtotal = 1920 + 4 + 2 + 4,<br>
> + .vrefresh = 60,<br>
> + .width_mm = 68,<br>
> + .height_mm = 121,<br>
> +};<br>
We have patches pending to remove vrefresh, which I thought<br>
was already applied. Anyway, keep it here.<br>
We will eaither remove it later or if the patches crosses<br>
I will do it when applying this patch.<br>
<br>
> +<br>
> +static int tm5p5_nt35596_get_modes(struct drm_panel *panel,<br>
> + struct drm_connector *connector)<br>
> +{<br>
> + struct drm_display_mode *mode;<br>
> +<br>
> + mode = drm_mode_duplicate(connector->dev, &tm5p5_nt35596_mode);<br>
> + if (!mode)<br>
> + return -ENOMEM;<br>
> +<br>
> + drm_mode_set_name(mode);<br>
> +<br>
> + mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;<br>
> + connector->display_info.width_mm = mode->width_mm;<br>
> + connector->display_info.height_mm = mode->height_mm;<br>
> + drm_mode_probed_add(connector, mode);<br>
> +<br>
> + return 1;<br>
> +}<br>
> +<br>
> +static const struct drm_panel_funcs tm5p5_nt35596_panel_funcs = {<br>
> + .prepare = tm5p5_nt35596_prepare,<br>
> + .unprepare = tm5p5_nt35596_unprepare,<br>
> + .get_modes = tm5p5_nt35596_get_modes,<br>
> +};<br>
> +<br>
> +static int tm5p5_nt35596_bl_update_status(struct backlight_device *bl)<br>
> +{<br>
> + struct mipi_dsi_device *dsi = bl_get_data(bl);<br>
> + u16 brightness = bl->props.brightness;<br>
> + int ret;<br>
> +<br>
> + if (bl->props.power != FB_BLANK_UNBLANK ||<br>
> + bl->props.fb_blank != FB_BLANK_UNBLANK ||<br>
> + bl->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK))<br>
> + brightness = 0;<br>
> +<br>
> + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;<br>
> +<br>
> + ret = mipi_dsi_dcs_set_display_brightness(dsi, brightness);<br>
> + if (ret < 0)<br>
> + return ret;<br>
> +<br>
> + dsi->mode_flags |= MIPI_DSI_MODE_LPM;<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +// TODO: Check if /sys/class/backlight/.../actual_brightness actually returns<br>
> +// correct values. If not, remove this function.<br>
Please resolve this TODO<br>
<br>
> +static int tm5p5_nt35596_bl_get_brightness(struct backlight_device *bl)<br>
> +{<br>
> + struct mipi_dsi_device *dsi = bl_get_data(bl);<br>
> + u16 brightness = bl->props.brightness;<br>
> + int ret;<br>
> +<br>
> + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;<br>
> +<br>
> + ret = mipi_dsi_dcs_get_display_brightness(dsi, &brightness);<br>
> + if (ret < 0)<br>
> + return ret;<br>
> +<br>
> + dsi->mode_flags |= MIPI_DSI_MODE_LPM;<br>
> +<br>
> + return brightness & 0xff;<br>
> +}<br>
> +<br>
> +static const struct backlight_ops tm5p5_nt35596_bl_ops = {<br>
> + .update_status = tm5p5_nt35596_bl_update_status,<br>
> + .get_brightness = tm5p5_nt35596_bl_get_brightness,<br>
> +};<br>
> +<br>
> +static struct backlight_device *<br>
> +tm5p5_nt35596_create_backlight(struct mipi_dsi_device *dsi)<br>
> +{<br>
> + struct device *dev = &dsi->dev;<br>
> + struct backlight_properties props = {<br>
> + .type = BACKLIGHT_RAW,<br>
> + .brightness = 255,<br>
> + .max_brightness = 255,<br>
> + };<br>
Make props const.<br>
<br>
> +<br>
> + return devm_backlight_device_register(dev, dev_name(dev), dev, dsi,<br>
> + &tm5p5_nt35596_bl_ops, &props);<br>
> +}<br>
> +<br>
> +static int tm5p5_nt35596_probe(struct mipi_dsi_device *dsi)<br>
> +{<br>
> + struct device *dev = &dsi->dev;<br>
> + struct tm5p5_nt35596 *ctx;<br>
> + int ret;<br>
> +<br>
> + ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);<br>
> + if (!ctx)<br>
> + return -ENOMEM;<br>
> +<br>
> + ctx->supplies[0].supply = "vdd";<br>
> + ctx->supplies[1].supply = "vddio";<br>
> + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ctx->supplies),<br>
> + ctx->supplies);<br>
> + if (ret < 0) {<br>
> + dev_err(dev, "Failed to get regulators: %d\n", ret);<br>
> + return ret;<br>
> + }<br>
> +<br>
> + ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);<br>
> + if (IS_ERR(ctx->reset_gpio)) {<br>
> + ret = PTR_ERR(ctx->reset_gpio);<br>
> + dev_err(dev, "Failed to get reset-gpios: %d\n", ret);<br>
> + return ret;<br>
> + }<br>
> +<br>
> + ctx->dsi = dsi;<br>
> + mipi_dsi_set_drvdata(dsi, ctx);<br>
> +<br>
> + dsi->lanes = 4;<br>
> + dsi->format = MIPI_DSI_FMT_RGB888;<br>
> + dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST |<br>
> + MIPI_DSI_MODE_VIDEO_HSE | MIPI_DSI_MODE_EOT_PACKET |<br>
> + MIPI_DSI_CLOCK_NON_CONTINUOUS | MIPI_DSI_MODE_LPM;<br>
> +<br>
> + drm_panel_init(&ctx->panel, dev, &tm5p5_nt35596_panel_funcs,<br>
> + DRM_MODE_CONNECTOR_DSI);<br>
> +<br>
> + ctx->panel.backlight = tm5p5_nt35596_create_backlight(dsi);<br>
> + if (IS_ERR(ctx->panel.backlight)) {<br>
> + ret = PTR_ERR(ctx->panel.backlight);<br>
> + dev_err(dev, "Failed to create backlight: %d\n", ret);<br>
> + return ret;<br>
> + }<br>
> +<br>
> + ret = drm_panel_add(&ctx->panel);<br>
> + if (ret < 0) {<br>
> + dev_err(dev, "Failed to add panel: %d\n", ret);<br>
> + return ret;<br>
> + }<br>
> +<br>
> + ret = mipi_dsi_attach(dsi);<br>
> + if (ret < 0) {<br>
> + dev_err(dev, "Failed to attach to DSI host: %d\n", ret);<br>
> + return ret;<br>
> + }<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int tm5p5_nt35596_remove(struct mipi_dsi_device *dsi)<br>
> +{<br>
> + struct tm5p5_nt35596 *ctx = mipi_dsi_get_drvdata(dsi);<br>
> + int ret;<br>
> +<br>
> + ret = mipi_dsi_detach(dsi);<br>
> + if (ret < 0)<br>
> + dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n", ret);<br>
Line too long I think<br>
<br>
> +<br>
> + drm_panel_remove(&ctx->panel);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static const struct of_device_id tm5p5_nt35596_of_match[] = {<br>
> + { .compatible = "tm5p5,nt35596" },<br>
vendor tm5p5 is not documented.<br>
<br>
> + { /* sentinel */ }<br>
> +};<br>
> +MODULE_DEVICE_TABLE(of, tm5p5_nt35596_of_match);<br>
> +<br>
> +static struct mipi_dsi_driver tm5p5_nt35596_driver = {<br>
> + .probe = tm5p5_nt35596_probe,<br>
> + .remove = tm5p5_nt35596_remove,<br>
> + .driver = {<br>
> + .name = "panel-tm5p5-nt35596",<br>
> + .of_match_table = tm5p5_nt35596_of_match,<br>
> + },<br>
> +};<br>
> +module_mipi_dsi_driver(tm5p5_nt35596_driver);<br>
> +<br>
> +MODULE_AUTHOR("Konrad Dybcio <<a href="mailto:konradybcio@gmail.com" target="_blank" rel="noreferrer">konradybcio@gmail.com</a>>");<br>
> +MODULE_DESCRIPTION("DRM driver for tm5p5 nt35596 1080p video mode dsi panel");<br>
> +MODULE_LICENSE("GPL v2");<br>
> -- <br>
> 2.26.1<br>
</blockquote></div>