<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
<p style="margin-top:0;margin-bottom:0"><br>
</p>
Hi Thierry,</div>
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
<br>
</div>
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
Thanks a lot for reviewing this. Your suggestions are very valuable.</div>
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
Please see my detailed answers inline.</div>
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
<br>
</div>
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
Best regards,</div>
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
Robert<br>
<br>
<div style="color: rgb(0, 0, 0);">
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Thierry Reding <thierry.reding@gmail.com><br>
<b>Sent:</b> Thursday, April 26, 2018 5:54 PM<br>
<b>To:</b> Robert Chiras<br>
<b>Cc:</b> dl-linux-imx; dri-devel@lists.freedesktop.org<br>
<b>Subject:</b> Re: [PATCH 1/2] drm/panel: Add Raydium RM67191 DSI Panel</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">On Tue, Apr 03, 2018 at 01:30:00PM +0300, Robert Chiras wrote:<br>
> Add support for the OLED display based on MIPI-DSI protocol from Raydium:<br>
> RM67191.<br>
> <br>
> Signed-off-by: Robert Chiras <robert.chiras@nxp.com><br>
> ---<br>
> .../bindings/display/panel/raydium,rm67191.txt | 55 ++<br>
> drivers/gpu/drm/panel/Kconfig | 9 +<br>
> drivers/gpu/drm/panel/Makefile | 1 +<br>
> drivers/gpu/drm/panel/panel-raydium-rm67191.c | 645 +++++++++++++++++++++<br>
> 4 files changed, 710 insertions(+)<br>
> create mode 100644 Documentation/devicetree/bindings/display/panel/raydium,rm67191.txt<br>
> create mode 100644 drivers/gpu/drm/panel/panel-raydium-rm67191.c<br>
> <br>
> diff --git a/Documentation/devicetree/bindings/display/panel/raydium,rm67191.txt b/Documentation/devicetree/bindings/display/panel/raydium,rm67191.txt<br>
> new file mode 100644<br>
> index 0000000..18a57de<br>
> --- /dev/null<br>
> +++ b/Documentation/devicetree/bindings/display/panel/raydium,rm67191.txt<br>
> @@ -0,0 +1,55 @@<br>
> +Raydium RM67171 OLED LCD panel with MIPI-DSI protocol<br>
> +<br>
> +Required properties:<br>
> +- compatible: "raydium,rm67191"<br>
> +- reg: virtual channel for MIPI-DSI protocol<br>
> + must be <0><br>
> +- dsi-lanes: number of DSI lanes to be used<br>
> + must be <3> or <4><br>
> +- port: input port node with endpoint definition as<br>
> + defined in Documentation/devicetree/bindings/graph.txt;<br>
> + the input port should be connected to a MIPI-DSI device<br>
> + driver<br>
> +<br>
> +Optional properties:<br>
> +- reset-gpio: a GPIO spec for the RST_B GPIO pin<br>
> +- display-timings: timings for the connected panel according to [1]<br>
> +- pinctrl-0 phandle to the pin settings for the reset pin<br>
> +- panel-width-mm: physical panel width [mm]<br>
> +- panel-height-mm: physical panel height [mm]<br>
> +<br>
> +[1]: Documentation/devicetree/bindings/display/display-timing.txt<br>
> +<br>
> +Example:<br>
> +<br>
> + panel@0 {<br>
> + compatible = "raydium,rm67191";<br>
> + reg = <0>;<br>
> + pinctrl-0 = <&pinctrl_mipi_dsi_0_1_en>;<br>
> + reset-gpio = <&gpio1 7 GPIO_ACTIVE_HIGH>;<br>
> + dsi-lanes = <4>;<br>
> + panel-width-mm = <68>;<br>
> + panel-height-mm = <121>;<br>
> + display-timings {<br>
> + timing {<br>
> + clock-frequency = <132000000>;<br>
> + hactive = <1080>;<br>
> + vactive = <1920>;<br>
> + hback-porch = <11>;<br>
> + hfront-porch = <4>;<br>
> + vback-porch = <48>;<br>
> + vfront-porch = <20>;<br>
> + hsync-len = <5>;<br>
> + vsync-len = <12>;<br>
> + hsync-active = <0>;<br>
> + vsync-active = <0>;<br>
> + de-active = <0>;<br>
> + pixelclk-active = <0>;<br>
> + };<br>
> + };<br>
<br>
This shouldn't be necessary. You already have the timings in your<br>
driver, why the extra work of getting it from DT?<br>
<br>
</div>
<div class="PlainText">[Robert] I added this as optional in the DT in case someone would like to use the panel with different timings than ones from driver. Anyway, after some tests I saw that the blanking timings are kind of fixed, so only the clock-frequency
could be changed. For example, if someone wants to use this panel at 30Hz (66MHz pixel clock) instead of the default one of 60Hz (132MHz pixel clock). But, I think you are right, I could get rid of the display-timings and just add an optional property for
changing the pixel clock in driver.<br>
<br>
> + port {<br>
> + panel1_in: endpoint {<br>
> + remote-endpoint = <&mipi1_out>;<br>
> + };<br>
> + };<br>
> + };<br>
<br>
Please split device tree bindings patches off into a separate patch and<br>
make sure you Cc the devicetree@vger.kernel.org mailing list so that<br>
they can be reviewed by the respective maintainers.<br>
<br>
Also make sure that you put maintainers on To: or at least Cc: so that<br>
they have a better chance of seeing your patch and don't have to go<br>
find them.</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">[Robert] Sure, will do that.</div>
<div class="PlainText"><br>
> diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig<br>
> index 6ba4031..769cba7 100644<br>
> --- a/drivers/gpu/drm/panel/Kconfig<br>
> +++ b/drivers/gpu/drm/panel/Kconfig<br>
> @@ -158,4 +158,13 @@ config DRM_PANEL_SITRONIX_ST7789V<br>
> Say Y here if you want to enable support for the Sitronix<br>
> ST7789V controller for 240x320 LCD panels<br>
> <br>
> +config DRM_PANEL_RAYDIUM_RM67191<br>
> + tristate "Raydium RM67191 FHD panel"<br>
> + depends on OF<br>
> + depends on DRM_MIPI_DSI<br>
> + depends on BACKLIGHT_CLASS_DEVICE<br>
> + help<br>
> + Say Y here if you want to enable support for Raydium RM67191 FHD<br>
> + (1080x1920) DSI panel.<br>
> +<br>
<br>
These should be sorted alphabetically.</div>
<div class="PlainText"><span style="font-size: 11pt;">[Robert] Will do.</span><br>
</div>
<div class="PlainText"><br>
> endmenu<br>
> diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile<br>
> index 6d251eb..838d5c6 100644<br>
> --- a/drivers/gpu/drm/panel/Makefile<br>
> +++ b/drivers/gpu/drm/panel/Makefile<br>
> @@ -16,3 +16,4 @@ obj-$(CONFIG_DRM_PANEL_SEIKO_43WVF1G) += panel-seiko-43wvf1g.o<br>
> obj-$(CONFIG_DRM_PANEL_SHARP_LQ101R1SX01) += panel-sharp-lq101r1sx01.o<br>
> obj-$(CONFIG_DRM_PANEL_SHARP_LS043T1LE01) += panel-sharp-ls043t1le01.o<br>
> obj-$(CONFIG_DRM_PANEL_SITRONIX_ST7789V) += panel-sitronix-st7789v.o<br>
> +obj-$(CONFIG_DRM_PANEL_RAYDIUM_RM67191) += panel-raydium-rm67191.o<br>
<br>
Same here.</div>
<div class="PlainText"><span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 14.6667px;">[Robert] Will do.</span><br>
<br>
> diff --git a/drivers/gpu/drm/panel/panel-raydium-rm67191.c b/drivers/gpu/drm/panel/panel-raydium-rm67191.c<br>
> new file mode 100644<br>
> index 0000000..07b0bd4<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/panel/panel-raydium-rm67191.c<br>
> @@ -0,0 +1,645 @@<br>
> +/*<br>
> + * i.MX drm driver - Raydium MIPI-DSI panel driver<br>
> + *<br>
> + * Copyright (C) 2017 NXP<br>
> + *<br>
> + * This program is free software; you can redistribute it and/or<br>
> + * modify it under the terms of the GNU General Public License<br>
> + * as published by the Free Software Foundation; either version 2<br>
> + * of the License, or (at your option) any later version.<br>
> + * This program is distributed in the hope that it will be useful,<br>
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
> + * GNU General Public License for more details.<br>
> + */<br>
> +<br>
> +#include <drm/drmP.h><br>
> +#include <drm/drm_crtc.h><br>
> +#include <drm/drm_mipi_dsi.h><br>
> +#include <drm/drm_panel.h><br>
> +#include <linux/gpio/consumer.h><br>
> +#include <linux/module.h><br>
> +#include <linux/of.h><br>
> +#include <linux/regulator/consumer.h><br>
> +#include <video/mipi_display.h><br>
> +#include <video/of_videomode.h><br>
> +#include <video/videomode.h><br>
> +<br>
> +#define CMD_TABLE_LEN 2<br>
> +typedef u8 cmd_set_table[CMD_TABLE_LEN];<br>
<br>
This is all very confusing. The "table" isn't in fact 2 entries long,<br>
but each entry contains two bytes.<br>
<br>
> +<br>
> +/* Write Manufacture Command Set Control */<br>
> +#define WRMAUCCTR 0xFE<br>
> +<br>
> +/* Manufacturer Command Set pages (CMD2) */<br>
> +static const cmd_set_table manufacturer_cmd_set[] = {<br>
<br>
There a lot of magic values in this table. Can you add a reference to<br>
where you got these from? Also, looking at these commands it seems<br>
like they are actually <command, parameter> pairs, so maybe a better<br>
representation would be something along the lines of:</div>
<div class="PlainText"><br>
struct cmd_set_entry {<br>
u8 command;<br>
u8 param;<br>
};<br>
<br>
static const struct cmd_set_entry manufacturer_cmd_set[] = {<br>
...<br>
};</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">[Robert] Your suggestion is good and I will change the code accordingly. <span style="font-size: 11pt;">Regarding the "magic values": I got them from a sample driver we received from the vendor. According to the Reference Manual, the
IC on this panel has two sets of registers: Manufacture Command Set (MCS = CMD2) and User Command Set (UCS = CMD1). In the RM, there is no detailed description of the MCS, only a reference to a command on how to switch between these command sets. Now, what
are those commands used in the MCS mode: we got no details for them (probably to protect their IP?)</span></div>
<div class="PlainText"><br>
> +struct rad_panel {<br>
> + struct drm_panel base;<br>
> + struct mipi_dsi_device *dsi;<br>
> +<br>
> + struct gpio_desc *reset;<br>
> + struct backlight_device *backlight;<br>
> +<br>
> + bool prepared;<br>
> + bool enabled;<br>
> +<br>
> + struct videomode vm;<br>
> + u32 width_mm;<br>
> + u32 height_mm;<br>
> +};<br>
> +<br>
> +static inline struct rad_panel *to_rad_panel(struct drm_panel *panel)<br>
> +{<br>
> + return container_of(panel, struct rad_panel, base);<br>
> +}<br>
> +<br>
> +static int rad_panel_push_cmd_list(struct mipi_dsi_device *dsi)<br>
> +{<br>
> + size_t i;<br>
> + const u8 *cmd;<br>
> + size_t count = sizeof(manufacturer_cmd_set) / CMD_TABLE_LEN;<br>
> + int ret = 0;<br>
> +<br>
> + for (i = 0; i < count ; i++) {<br>
> + cmd = manufacturer_cmd_set[i];<br>
> + ret = mipi_dsi_generic_write(dsi, cmd, CMD_TABLE_LEN);<br>
> + if (ret < 0)<br>
> + return ret;<br>
> + }<br>
> +<br>
> + return ret;<br>
> +};<br>
<br>
With the changes I suggested above, this simply becomes:<br>
<br>
for (i = 0; i < ARRAY_SIZE(manufacturer_cmd_set); i++) {<br>
const struct cmd_set_entry *entry = &manufacturer_cmd_set[i];<br>
u8 buffer[2] = { entry->cmd, entry->param };<br>
<br>
ret = mipi_dsi_generic_write(dsi, buffer, sizeof(buffer));<br>
if (ret < 0)<br>
return ret;<br>
}<br>
<br>
which is about the same length but a lot more idiomatic.</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">[Robert] Sure, will do this too. Thanks!<br>
<br>
> +static int rad_panel_prepare(struct drm_panel *panel)<br>
> +{<br>
> + struct rad_panel *rad = to_rad_panel(panel);<br>
> + struct mipi_dsi_device *dsi = rad->dsi;<br>
> + struct device *dev = &dsi->dev;<br>
> + int ret;<br>
> +<br>
> + if (rad->prepared)<br>
> + return 0;<br>
> +<br>
> + DRM_DEV_DEBUG_DRIVER(dev, "\n");<br>
> +<br>
> + if (rad->reset != NULL) {<br>
> + gpiod_set_value(rad->reset, 1);<br>
> + usleep_range(10000, 15000);<br>
> + gpiod_set_value(rad->reset, 0);<br>
> + usleep_range(5000, 10000);<br>
> + gpiod_set_value(rad->reset, 1);<br>
> + usleep_range(20000, 25000);<br>
> + }<br>
> +<br>
> + dsi->mode_flags |= MIPI_DSI_MODE_LPM;<br>
> +<br>
> + ret = rad_panel_push_cmd_list(dsi);<br>
> + if (ret < 0) {<br>
> + DRM_DEV_ERROR(dev, "Failed to send MCS (%d)\n", ret);<br>
> + goto fail;<br>
> + }<br>
> +<br>
> + /* Select User Command Set table (CMD1) */<br>
> + ret = mipi_dsi_generic_write(dsi, (u8[]){ WRMAUCCTR, 0x00 }, 2);<br>
> + if (ret < 0)<br>
> + goto fail;<br>
> +<br>
> + /* Software reset */<br>
> + ret = mipi_dsi_dcs_soft_reset(dsi);<br>
> + if (ret < 0) {<br>
> + DRM_DEV_ERROR(dev, "Failed to do Software Reset (%d)\n", ret);<br>
> + goto fail;<br>
> + }<br>
> +<br>
> + usleep_range(10000, 15000);<br>
> +<br>
> + /* Set DSI mode */<br>
> + ret = mipi_dsi_generic_write(dsi, (u8[]){ 0xC2, 0x0B }, 2);<br>
> + if (ret < 0) {<br>
> + DRM_DEV_ERROR(dev, "Failed to set DSI mode (%d)\n", ret);<br>
> + goto fail;<br>
> + }<br>
> + /* Set tear ON */<br>
> + ret = mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK);<br>
> + if (ret < 0) {<br>
> + DRM_DEV_ERROR(dev, "Failed to set tear ON (%d)\n", ret);<br>
> + goto fail;<br>
> + }<br>
> + /* Set tear scanline */<br>
> + ret = mipi_dsi_dcs_set_tear_scanline(dsi, 0x380);<br>
> + if (ret < 0) {<br>
> + DRM_DEV_ERROR(dev, "Failed to set tear scanline (%d)\n", ret);<br>
> + goto fail;<br>
> + }<br>
> + /* Set pixel format to RGB888 */<br>
> + ret = mipi_dsi_dcs_set_pixel_format(dsi, 0x77);<br>
> + if (ret < 0) {<br>
> + DRM_DEV_ERROR(dev, "Failed to set pixel format (%d)\n", ret);<br>
> + goto fail;<br>
> + }<br>
> + /* Set display brightness */<br>
> + ret = mipi_dsi_dcs_set_display_brightness(dsi, 0x20);<br>
> + if (ret < 0) {<br>
> + DRM_DEV_ERROR(dev, "Failed to set display brightness (%d)\n",<br>
> + ret);<br>
> + goto fail;<br>
> + }<br>
> + /* Exit sleep mode */<br>
> + ret = mipi_dsi_dcs_exit_sleep_mode(dsi);<br>
> + if (ret < 0) {<br>
> + DRM_DEV_ERROR(dev, "Failed to exit sleep mode (%d)\n", ret);<br>
> + goto fail;<br>
> + }<br>
> +<br>
> + usleep_range(5000, 10000);<br>
> +<br>
> + ret = mipi_dsi_dcs_set_display_on(dsi);<br>
> + if (ret < 0) {<br>
> + DRM_DEV_ERROR(dev, "Failed to set display ON (%d)\n", ret);<br>
> + goto fail;<br>
> + }<br>
> +<br>
> + rad->prepared = true;<br>
> +<br>
> + return 0;<br>
> +<br>
> +fail:<br>
> + if (rad->reset != NULL)<br>
> + gpiod_set_value(rad->reset, 0);<br>
> +<br>
> + return ret;<br>
> +}<br>
> +<br>
> +static int rad_panel_unprepare(struct drm_panel *panel)<br>
> +{<br>
> + struct rad_panel *rad = to_rad_panel(panel);<br>
> + struct mipi_dsi_device *dsi = rad->dsi;<br>
> + struct device *dev = &dsi->dev;<br>
> + int ret;<br>
> +<br>
> + if (!rad->prepared)<br>
> + return 0;<br>
> +<br>
> + DRM_DEV_DEBUG_DRIVER(dev, "\n");<br>
> +<br>
> + dsi->mode_flags |= MIPI_DSI_MODE_LPM;<br>
> +<br>
> + ret = mipi_dsi_dcs_set_display_off(dsi);<br>
> + if (ret < 0)<br>
> + DRM_DEV_ERROR(dev, "Failed to set display OFF (%d)\n", ret);<br>
> +<br>
> + usleep_range(5000, 10000);<br>
> +<br>
> + ret = mipi_dsi_dcs_enter_sleep_mode(dsi);<br>
> + if (ret < 0)<br>
> + DRM_DEV_ERROR(dev, "Failed to enter sleep mode (%d)\n", ret);<br>
> +<br>
> + usleep_range(10000, 15000);<br>
> +<br>
> + if (rad->reset != NULL) {<br>
> + gpiod_set_value(rad->reset, 0);<br>
> + usleep_range(10000, 15000);<br>
> + }<br>
> +<br>
> + rad->prepared = false;<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int rad_panel_enable(struct drm_panel *panel)<br>
> +{<br>
> + struct rad_panel *rad = to_rad_panel(panel);<br>
> + struct device *dev = &rad->dsi->dev;<br>
> +<br>
> + if (rad->enabled)<br>
> + return 0;<br>
> +<br>
> + DRM_DEV_DEBUG_DRIVER(dev, "\n");<br>
> +<br>
> + rad->backlight->props.power = FB_BLANK_UNBLANK;<br>
> + backlight_update_status(rad->backlight);<br>
<br>
Please use the new backlight_enable()...</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">[Robert] Will do.<br>
<br>
> +<br>
> + rad->enabled = true;<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int rad_panel_disable(struct drm_panel *panel)<br>
> +{<br>
> + struct rad_panel *rad = to_rad_panel(panel);<br>
> + struct device *dev = &rad->dsi->dev;<br>
> +<br>
> + if (!rad->enabled)<br>
> + return 0;<br>
> +<br>
> + DRM_DEV_DEBUG_DRIVER(dev, "\n");<br>
> +<br>
> + rad->backlight->props.power = FB_BLANK_POWERDOWN;<br>
> + backlight_update_status(rad->backlight);<br>
<br>
... and backlight_disable() functions.</div>
<div class="PlainText"><br>
</div>
<div class="PlainText"><span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 14.6667px;">[Robert] Same here.</span><br>
<br>
> +<br>
> + rad->enabled = false;<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int rad_panel_get_modes(struct drm_panel *panel)<br>
> +{<br>
> + struct rad_panel *rad = to_rad_panel(panel);<br>
> + struct device *dev = &rad->dsi->dev;<br>
> + struct drm_connector *connector = panel->connector;<br>
> + struct drm_display_mode *mode;<br>
> + u32 bus_format = MEDIA_BUS_FMT_RGB888_1X24;<br>
> + u32 *bus_flags = &connector->display_info.bus_flags;<br>
> + int ret;<br>
> +<br>
> + mode = drm_mode_create(connector->dev);<br>
> + if (!mode) {<br>
> + DRM_DEV_ERROR(dev, "Failed to create display mode!\n");<br>
> + return 0;<br>
> + }<br>
> +<br>
> + drm_display_mode_from_videomode(&rad->vm, mode);<br>
> + mode->width_mm = rad->width_mm;<br>
> + mode->height_mm = rad->height_mm;<br>
> + connector->display_info.width_mm = rad->width_mm;<br>
> + connector->display_info.height_mm = rad->height_mm;<br>
> + mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;<br>
> +<br>
> + if (rad->vm.flags & DISPLAY_FLAGS_DE_HIGH)<br>
> + *bus_flags |= DRM_BUS_FLAG_DE_HIGH;<br>
> + if (rad->vm.flags & DISPLAY_FLAGS_DE_LOW)<br>
> + *bus_flags |= DRM_BUS_FLAG_DE_LOW;<br>
> + if (rad->vm.flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE)<br>
> + *bus_flags |= DRM_BUS_FLAG_PIXDATA_NEGEDGE;<br>
> + if (rad->vm.flags & DISPLAY_FLAGS_PIXDATA_POSEDGE)<br>
> + *bus_flags |= DRM_BUS_FLAG_PIXDATA_POSEDGE;<br>
> +<br>
> + ret = drm_display_info_set_bus_formats(&connector->display_info,<br>
> + &bus_format, 1);<br>
> + if (ret)<br>
> + return ret;<br>
> +<br>
> + drm_mode_probed_add(panel->connector, mode);<br>
> +<br>
> + return 1;<br>
> +}<br>
> +<br>
> +static int rad_bl_get_brightness(struct backlight_device *bl)<br>
> +{<br>
> + struct mipi_dsi_device *dsi = bl_get_data(bl);<br>
> + struct rad_panel *rad = mipi_dsi_get_drvdata(dsi);<br>
> + struct device *dev = &dsi->dev;<br>
> + u16 brightness;<br>
> + int ret;<br>
> +<br>
> + if (!rad->prepared)<br>
> + return 0;<br>
> +<br>
> + DRM_DEV_DEBUG_DRIVER(dev, "\n");<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>
> + bl->props.brightness = brightness;<br>
> +<br>
> + return brightness & 0xff;<br>
> +}<br>
> +<br>
> +static int rad_bl_update_status(struct backlight_device *bl)<br>
> +{<br>
> + struct mipi_dsi_device *dsi = bl_get_data(bl);<br>
> + struct rad_panel *rad = mipi_dsi_get_drvdata(dsi);<br>
> + struct device *dev = &dsi->dev;<br>
> + int ret = 0;<br>
> +<br>
> + if (!rad->prepared)<br>
> + return 0;<br>
> +<br>
> + DRM_DEV_DEBUG_DRIVER(dev, "New brightness: %d\n", bl->props.brightness);<br>
> +<br>
> + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;<br>
> +<br>
> + ret = mipi_dsi_dcs_set_display_brightness(dsi, bl->props.brightness);<br>
> + if (ret < 0)<br>
> + return ret;<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static const struct backlight_ops rad_bl_ops = {<br>
> + .update_status = rad_bl_update_status,<br>
> + .get_brightness = rad_bl_get_brightness,<br>
> +};<br>
> +<br>
> +static const struct drm_panel_funcs rad_panel_funcs = {<br>
> + .prepare = rad_panel_prepare,<br>
> + .unprepare = rad_panel_unprepare,<br>
> + .enable = rad_panel_enable,<br>
> + .disable = rad_panel_disable,<br>
> + .get_modes = rad_panel_get_modes,<br>
> +};<br>
> +<br>
> +/*<br>
> + * The clock might range from 66MHz (30Hz refresh rate)<br>
> + * to 132MHz (60Hz refresh rate)<br>
> + */<br>
> +static const struct display_timing rad_default_timing = {<br>
> + .pixelclock = { 66000000, 120000000, 132000000 },<br>
> + .hactive = { 1080, 1080, 1080 },<br>
> + .hfront_porch = { 20, 20, 20 },<br>
> + .hsync_len = { 2, 2, 2 },<br>
> + .hback_porch = { 34, 34, 34 },<br>
> + .vactive = { 1920, 1920, 1920 },<br>
> + .vfront_porch = { 10, 10, 10 },<br>
> + .vsync_len = { 2, 2, 2 },<br>
> + .vback_porch = { 4, 4, 4 },<br>
> + .flags = DISPLAY_FLAGS_HSYNC_LOW |<br>
> + DISPLAY_FLAGS_VSYNC_LOW |<br>
> + DISPLAY_FLAGS_DE_LOW |<br>
> + DISPLAY_FLAGS_PIXDATA_NEGEDGE,<br>
> +};<br>
> +<br>
> +static int rad_panel_probe(struct mipi_dsi_device *dsi)<br>
> +{<br>
> + struct device *dev = &dsi->dev;<br>
> + struct device_node *np = dev->of_node;<br>
> + struct device_node *timings;<br>
> + struct rad_panel *panel;<br>
> + struct backlight_properties bl_props;<br>
> + int ret;<br>
> +<br>
> + panel = devm_kzalloc(&dsi->dev, sizeof(*panel), GFP_KERNEL);<br>
> + if (!panel)<br>
> + return -ENOMEM;<br>
> +<br>
> + mipi_dsi_set_drvdata(dsi, panel);<br>
> +<br>
> + panel->dsi = dsi;<br>
> +<br>
> + dsi->format = MIPI_DSI_FMT_RGB888;<br>
> + dsi->mode_flags = MIPI_DSI_MODE_VIDEO_HSE | MIPI_DSI_MODE_VIDEO |<br>
> + MIPI_DSI_CLOCK_NON_CONTINUOUS;<br>
> +<br>
> + ret = of_property_read_u32(np, "dsi-lanes", &dsi->lanes);<br>
> + if (ret < 0) {<br>
> + dev_err(dev, "Failed to get dsi-lanes property (%d)\n", ret);<br>
> + return ret;<br>
> + }<br>
> +<br>
> + /*<br>
> + * 'display-timings' is optional, so verify if the node is present<br>
> + * before calling of_get_videomode so we won't get console error<br>
> + * messages<br>
> + */<br>
> + timings = of_get_child_by_name(np, "display-timings");<br>
> + if (timings) {<br>
> + of_node_put(timings);<br>
> + ret = of_get_videomode(np, &panel->vm, 0);<br>
> + } else {<br>
> + videomode_from_timing(&rad_default_timing, &panel->vm);<br>
> + }<br>
> + if (ret < 0)<br>
> + return ret;<br>
> +<br>
> + of_property_read_u32(np, "panel-width-mm", &panel->width_mm);<br>
> + of_property_read_u32(np, "panel-height-mm", &panel->height_mm);<br>
> +<br>
> + panel->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);<br>
> +<br>
> + if (IS_ERR(panel->reset))<br>
> + panel->reset = NULL;<br>
> + else<br>
> + gpiod_set_value(panel->reset, 0);<br>
> +<br>
> +<br>
> + memset(&bl_props, 0, sizeof(bl_props));<br>
> + bl_props.type = BACKLIGHT_RAW;<br>
> + bl_props.brightness = 255;<br>
<br>
Maybe this should read the current brightness from the panel to make<br>
sure it's correct?</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">[Robert] In order to read the current brightness from the panel, we need to be able to send DSI commands. Since the DSI commands can be sent by means of the DSI host controller, at this moment is impossible to do this. Anyway, during
the panel_prepare, when the panel is initialized, the backlight value is defaulted there, so I can update the current brightness there.<br>
<br>
> + bl_props.max_brightness = 255;<br>
> +<br>
> + panel->backlight = devm_backlight_device_register(<br>
> + dev, dev_name(dev),<br>
> + dev, dsi,<br>
> + &rad_bl_ops, &bl_props);<br>
> + if (IS_ERR(panel->backlight)) {<br>
> + ret = PTR_ERR(panel->backlight);<br>
> + dev_err(dev, "Failed to register backlight (%d)\n", ret);<br>
> + return ret;<br>
> + }<br>
> +<br>
> + drm_panel_init(&panel->base);<br>
> + panel->base.funcs = &rad_panel_funcs;<br>
> + panel->base.dev = dev;<br>
> +<br>
> + ret = drm_panel_add(&panel->base);<br>
> +<br>
> + if (ret < 0)<br>
> + return ret;<br>
> +<br>
> + ret = mipi_dsi_attach(dsi);<br>
> + if (ret < 0)<br>
> + drm_panel_remove(&panel->base);<br>
> +<br>
> + return ret;<br>
> +}<br>
> +<br>
> +static int rad_panel_remove(struct mipi_dsi_device *dsi)<br>
> +{<br>
> + struct rad_panel *rad = mipi_dsi_get_drvdata(dsi);<br>
> + struct device *dev = &dsi->dev;<br>
> + int ret;<br>
> +<br>
> + ret = rad_panel_unprepare(&rad->base);<br>
> + ret |= rad_panel_disable(&rad->base);<br>
> + if (ret < 0)<br>
> + DRM_DEV_ERROR(dev, "Failed to disable panel (%d)\n", ret);<br>
<br>
This is the wrong way around. First disable, then unprepare. Also, this<br>
should not be necessary because the panel should've been disabled by the<br>
time you get here.</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">[Robert] Oh, you're right here. I will remove them.<br>
<br>
> +<br>
> + ret = mipi_dsi_detach(dsi);<br>
> + if (ret < 0)<br>
> + DRM_DEV_ERROR(dev, "Failed to detach from host (%d)\n",<br>
> + ret);<br>
> +<br>
> + drm_panel_detach(&rad->base);<br>
<br>
Please don't do that. I've just merged a set of patches which document<br>
this as being wrong and which remove similar calls from other panel<br>
drivers.</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">[Robert] I am sorry, but I don't understand here. Don't do what? <span>mipi_dsi_detach or <span>drm_panel_detach? Or are you referring to the fact that I'm still calling drm_panel_detach even though mipi_dsi_detach fails?</span></span><br>
<br>
> +<br>
> + if (rad->base.dev)<br>
> + drm_panel_remove(&rad->base);<br>
<br>
Why this check? Under what circumstances would this fail?</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">[Robert] Well, I thought that if probe fails, base will be NULL, but you are right about this. If probe fails there won't be any remove calls. Will fix this too.<br>
<br>
Thierry<br>
</div>
</span></font></div>
</div>
</div>
</div>
</body>
</html>