Re: [RESEND PATCH v5 2/2] drm/bridge: hx8837: add a Himax HX8837 display controller driver

2020-10-26 Thread Lubomir Rintel
Hello Sam,

On Fri, Oct 16, 2020 at 10:07:34PM +0200, Sam Ravnborg wrote:
> Hi Lubomir.
> 
> On Sat, Sep 26, 2020 at 02:07:19AM +0200, Lubomir Rintel wrote:
> > Himax HX8837 is used to drive the LCD panel on OLPC platforms.
> > 
> > It controls the panel backlight and is able to refresh it when the LCD
> > controller (and the rest of the plaform) is powered off.
> > 
> > It also converts regular RGB color data from the LCDC so that it looks
> > reasonable on the OLPC LCD panel with a monochromatic layer on top of a
> > layer that can either reflect light (b/w sunlight readable mode) or light
> > pattern of red, green and blue pixels.
> > 
> > At this point, the driver is rather basic. The self-refresh mode is not
> > supported. There's no way of independently controlling the color swizzling,
> > antialiasing or b/w conversion, but it probably isn't too useful either.
> > 
> > There's another driver for the same hardware on OLPC XO-1.5 and XO-1.75
> > in drivers/staging/olpc_dcon. The display on that hardware doesn't utilize
> > DRM, so this driver doesn't replace the other one yet.
> > 
> > Signed-off-by: Lubomir Rintel 
> 
> A little feedback follows.
> 
>   Sam
> 
> > 
> > ---
> > Changes since v3:
> > - Added this patch, in place of a driver derived from
> >   drivers/staging/olpc_dcon. Compared to the previous one this
> >   implements the bare minimum, without the fancy stuff such as
> >   self-refresh that need more work/thinking.
> > 
> >  drivers/gpu/drm/bridge/Kconfig|  13 ++
> >  drivers/gpu/drm/bridge/Makefile   |   1 +
> >  drivers/gpu/drm/bridge/himax-hx8837.c | 325 ++
> >  3 files changed, 339 insertions(+)
> >  create mode 100644 drivers/gpu/drm/bridge/himax-hx8837.c
> > 
> > diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
> > index ef91646441b16..6a923dd56c1d5 100644
> > --- a/drivers/gpu/drm/bridge/Kconfig
> > +++ b/drivers/gpu/drm/bridge/Kconfig
> > @@ -48,6 +48,19 @@ config DRM_DISPLAY_CONNECTOR
> >   on ARM-based platforms. Saying Y here when this driver is not needed
> >   will not cause any issue.
> >  
> > +config DRM_HIMAX_HX8837
> > +tristate "HiMax HX8837 OLPC Display Controller"
> > +   depends on OF
> > +   depends on OLPC || ARCH_MMP || COMPILE_TEST
> > +   select DRM_KMS_HELPER
> > +select BACKLIGHT_LCD_SUPPORT
> > +select BACKLIGHT_CLASS_DEVICE
> > +help
> > +  Enable support for HiMax HX8837 Display Controller as found in 
> > the
> > +  OLPC XO laptops.
> > +
> > +  If your laptop doesn't have green ears, say "N"
> 
> There is a mixture of tabs and spaces for indent - use tabs only (and
> tabs + 2 spaces for the help text).
> 
> 
> > +
> >  config DRM_LONTIUM_LT9611
> > tristate "Lontium LT9611 DSI/HDMI bridge"
> > select SND_SOC_HDMI_CODEC if SND_SOC
> > diff --git a/drivers/gpu/drm/bridge/Makefile 
> > b/drivers/gpu/drm/bridge/Makefile
> > index 2b3aff104e466..21f72df3260db 100644
> > --- a/drivers/gpu/drm/bridge/Makefile
> > +++ b/drivers/gpu/drm/bridge/Makefile
> > @@ -2,6 +2,7 @@
> >  obj-$(CONFIG_DRM_CDNS_DSI) += cdns-dsi.o
> >  obj-$(CONFIG_DRM_CHRONTEL_CH7033) += chrontel-ch7033.o
> >  obj-$(CONFIG_DRM_DISPLAY_CONNECTOR) += display-connector.o
> > +obj-$(CONFIG_DRM_HIMAX_HX8837) += himax-hx8837.o
> Please add in alphabetical order.
> 
> >  obj-$(CONFIG_DRM_LONTIUM_LT9611) += lontium-lt9611.o
> >  obj-$(CONFIG_DRM_LVDS_CODEC) += lvds-codec.o
> >  obj-$(CONFIG_DRM_MEGACHIPS_STDP_GE_B850V3_FW) += 
> > megachips-stdp-ge-b850v3-fw.o
> > diff --git a/drivers/gpu/drm/bridge/himax-hx8837.c 
> > b/drivers/gpu/drm/bridge/himax-hx8837.c
> > new file mode 100644
> > index 0..1e97fcb8ce505
> > --- /dev/null
> > +++ b/drivers/gpu/drm/bridge/himax-hx8837.c
> > @@ -0,0 +1,325 @@
> > +// SPDX-License-Identifier: GPL-2.0-or-later
> > +/*
> > + * HiMax HX8837 Display Controller Driver
> > + *
> > + * Datasheet: 
> > http://wiki.laptop.org/images/0/09/DCON_datasheet_HX8837-A.pdf
> > + *
> > + * Copyright (C) 2020 Lubomir Rintel
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> In blocks are good but please add them in alphabetical order.
> 
> > +
> > +#define bridge_to_hx8837_priv(x) \
> > +   container_of(x, struct hx8837_priv, bridge)
> > +
> > +/* DCON registers */
> > +enum {
> > +   DCON_REG_ID = 0x00,
> > +   DCON_REG_MODE   = 0x01,
> > +   DCON_REG_HRES   = 0x02,
> > +   DCON_REG_HTOTAL = 0x03,
> > +   DCON_REG_HSYNC_WIDTH= 0x04,
> > +   DCON_REG_VRES   = 0x05,
> > +   DCON_REG_VTOTAL = 0x06,
> > +   DCON_REG_VSYNC_WIDTH= 0x07,
> > +   DCON_REG_TIMEOUT= 0x08,
> > +   DCON_REG_SCAN_INT   = 0x09,
> > +   DCON_REG_BRIGHT = 0x0a,
> > +   DCON_REG_MEM_OPT_A  = 0x41,
> > +   DCON_REG_MEM_OPT_B  = 0x42,
> > +};
> > +
> > +/* 

Re: [RESEND PATCH v5 2/2] drm/bridge: hx8837: add a Himax HX8837 display controller driver

2020-10-25 Thread Sam Ravnborg
Hi Lubomir.

> > > +static int hx8837_bl_update_status(struct backlight_device *bl)
> > > +{
> > > + struct hx8837_priv *priv = bl_get_data(bl);
> > > + unsigned int val;
> > > + int ret;
> > > +
> > > + ret = regmap_update_bits(priv->regmap, DCON_REG_BRIGHT,
> > > +0x000f,
> > > +bl->props.brightness);
> > 
> > Use backlight_get_brightness() to get the brightness.
> > This will also make sure 0 is returned when backlight is off so the
> > logic a few lines down is correct.
> 
> I'm not sure I understand this one. I'm wondering if you could help me out
> with it before I follow up with v4.
> 
> Currently I read in the current brightness level in probe() (which
> prevents struct backlight_properties, below, from being const) and the
> nthe brightness is entirely in control of the driver via
> update_status().
> 
> What would I need get_brightness() for? We know that whatever the driver
> set is the current level. It doesn't seem to be called on backlight
> device registration so it doesn't make the readin in probe()
> unnecessary either.

The request here is to replace the direct access to backlight properties
"bl->props.brightness" with the helper backlight_get_brightness(bl).

Sam
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [RESEND PATCH v5 2/2] drm/bridge: hx8837: add a Himax HX8837 display controller driver

2020-10-16 Thread Sam Ravnborg
Hi Lubomir.

On Sat, Sep 26, 2020 at 02:07:19AM +0200, Lubomir Rintel wrote:
> Himax HX8837 is used to drive the LCD panel on OLPC platforms.
> 
> It controls the panel backlight and is able to refresh it when the LCD
> controller (and the rest of the plaform) is powered off.
> 
> It also converts regular RGB color data from the LCDC so that it looks
> reasonable on the OLPC LCD panel with a monochromatic layer on top of a
> layer that can either reflect light (b/w sunlight readable mode) or light
> pattern of red, green and blue pixels.
> 
> At this point, the driver is rather basic. The self-refresh mode is not
> supported. There's no way of independently controlling the color swizzling,
> antialiasing or b/w conversion, but it probably isn't too useful either.
> 
> There's another driver for the same hardware on OLPC XO-1.5 and XO-1.75
> in drivers/staging/olpc_dcon. The display on that hardware doesn't utilize
> DRM, so this driver doesn't replace the other one yet.
> 
> Signed-off-by: Lubomir Rintel 

A little feedback follows.

Sam

> 
> ---
> Changes since v3:
> - Added this patch, in place of a driver derived from
>   drivers/staging/olpc_dcon. Compared to the previous one this
>   implements the bare minimum, without the fancy stuff such as
>   self-refresh that need more work/thinking.
> 
>  drivers/gpu/drm/bridge/Kconfig|  13 ++
>  drivers/gpu/drm/bridge/Makefile   |   1 +
>  drivers/gpu/drm/bridge/himax-hx8837.c | 325 ++
>  3 files changed, 339 insertions(+)
>  create mode 100644 drivers/gpu/drm/bridge/himax-hx8837.c
> 
> diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
> index ef91646441b16..6a923dd56c1d5 100644
> --- a/drivers/gpu/drm/bridge/Kconfig
> +++ b/drivers/gpu/drm/bridge/Kconfig
> @@ -48,6 +48,19 @@ config DRM_DISPLAY_CONNECTOR
> on ARM-based platforms. Saying Y here when this driver is not needed
> will not cause any issue.
>  
> +config DRM_HIMAX_HX8837
> +tristate "HiMax HX8837 OLPC Display Controller"
> + depends on OF
> + depends on OLPC || ARCH_MMP || COMPILE_TEST
> + select DRM_KMS_HELPER
> +select BACKLIGHT_LCD_SUPPORT
> +select BACKLIGHT_CLASS_DEVICE
> +help
> +  Enable support for HiMax HX8837 Display Controller as found in the
> +  OLPC XO laptops.
> +
> +  If your laptop doesn't have green ears, say "N"

There is a mixture of tabs and spaces for indent - use tabs only (and
tabs + 2 spaces for the help text).


> +
>  config DRM_LONTIUM_LT9611
>   tristate "Lontium LT9611 DSI/HDMI bridge"
>   select SND_SOC_HDMI_CODEC if SND_SOC
> diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
> index 2b3aff104e466..21f72df3260db 100644
> --- a/drivers/gpu/drm/bridge/Makefile
> +++ b/drivers/gpu/drm/bridge/Makefile
> @@ -2,6 +2,7 @@
>  obj-$(CONFIG_DRM_CDNS_DSI) += cdns-dsi.o
>  obj-$(CONFIG_DRM_CHRONTEL_CH7033) += chrontel-ch7033.o
>  obj-$(CONFIG_DRM_DISPLAY_CONNECTOR) += display-connector.o
> +obj-$(CONFIG_DRM_HIMAX_HX8837) += himax-hx8837.o
Please add in alphabetical order.

>  obj-$(CONFIG_DRM_LONTIUM_LT9611) += lontium-lt9611.o
>  obj-$(CONFIG_DRM_LVDS_CODEC) += lvds-codec.o
>  obj-$(CONFIG_DRM_MEGACHIPS_STDP_GE_B850V3_FW) += 
> megachips-stdp-ge-b850v3-fw.o
> diff --git a/drivers/gpu/drm/bridge/himax-hx8837.c 
> b/drivers/gpu/drm/bridge/himax-hx8837.c
> new file mode 100644
> index 0..1e97fcb8ce505
> --- /dev/null
> +++ b/drivers/gpu/drm/bridge/himax-hx8837.c
> @@ -0,0 +1,325 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * HiMax HX8837 Display Controller Driver
> + *
> + * Datasheet: http://wiki.laptop.org/images/0/09/DCON_datasheet_HX8837-A.pdf
> + *
> + * Copyright (C) 2020 Lubomir Rintel
> + */
> +
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
In blocks are good but please add them in alphabetical order.

> +
> +#define bridge_to_hx8837_priv(x) \
> + container_of(x, struct hx8837_priv, bridge)
> +
> +/* DCON registers */
> +enum {
> + DCON_REG_ID = 0x00,
> + DCON_REG_MODE   = 0x01,
> + DCON_REG_HRES   = 0x02,
> + DCON_REG_HTOTAL = 0x03,
> + DCON_REG_HSYNC_WIDTH= 0x04,
> + DCON_REG_VRES   = 0x05,
> + DCON_REG_VTOTAL = 0x06,
> + DCON_REG_VSYNC_WIDTH= 0x07,
> + DCON_REG_TIMEOUT= 0x08,
> + DCON_REG_SCAN_INT   = 0x09,
> + DCON_REG_BRIGHT = 0x0a,
> + DCON_REG_MEM_OPT_A  = 0x41,
> + DCON_REG_MEM_OPT_B  = 0x42,
> +};
> +
> +/* DCON_REG_MODE */
> +enum {
> + MODE_PASSTHRU   = BIT(0),
> + MODE_SLEEP  = BIT(1),
> + MODE_SLEEP_AUTO = BIT(2),
> + MODE_BL_ENABLE  = BIT(3),
> + MODE_BLANK  = BIT(4),
> + MODE_CSWIZZLE   = BIT(5),
> + MODE_COL_AA = BIT(6),
> + 

[RESEND PATCH v5 2/2] drm/bridge: hx8837: add a Himax HX8837 display controller driver

2020-09-28 Thread Lubomir Rintel
Himax HX8837 is used to drive the LCD panel on OLPC platforms.

It controls the panel backlight and is able to refresh it when the LCD
controller (and the rest of the plaform) is powered off.

It also converts regular RGB color data from the LCDC so that it looks
reasonable on the OLPC LCD panel with a monochromatic layer on top of a
layer that can either reflect light (b/w sunlight readable mode) or light
pattern of red, green and blue pixels.

At this point, the driver is rather basic. The self-refresh mode is not
supported. There's no way of independently controlling the color swizzling,
antialiasing or b/w conversion, but it probably isn't too useful either.

There's another driver for the same hardware on OLPC XO-1.5 and XO-1.75
in drivers/staging/olpc_dcon. The display on that hardware doesn't utilize
DRM, so this driver doesn't replace the other one yet.

Signed-off-by: Lubomir Rintel 

---
Changes since v3:
- Added this patch, in place of a driver derived from
  drivers/staging/olpc_dcon. Compared to the previous one this
  implements the bare minimum, without the fancy stuff such as
  self-refresh that need more work/thinking.

 drivers/gpu/drm/bridge/Kconfig|  13 ++
 drivers/gpu/drm/bridge/Makefile   |   1 +
 drivers/gpu/drm/bridge/himax-hx8837.c | 325 ++
 3 files changed, 339 insertions(+)
 create mode 100644 drivers/gpu/drm/bridge/himax-hx8837.c

diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
index ef91646441b16..6a923dd56c1d5 100644
--- a/drivers/gpu/drm/bridge/Kconfig
+++ b/drivers/gpu/drm/bridge/Kconfig
@@ -48,6 +48,19 @@ config DRM_DISPLAY_CONNECTOR
  on ARM-based platforms. Saying Y here when this driver is not needed
  will not cause any issue.
 
+config DRM_HIMAX_HX8837
+tristate "HiMax HX8837 OLPC Display Controller"
+   depends on OF
+   depends on OLPC || ARCH_MMP || COMPILE_TEST
+   select DRM_KMS_HELPER
+select BACKLIGHT_LCD_SUPPORT
+select BACKLIGHT_CLASS_DEVICE
+help
+  Enable support for HiMax HX8837 Display Controller as found in the
+  OLPC XO laptops.
+
+  If your laptop doesn't have green ears, say "N"
+
 config DRM_LONTIUM_LT9611
tristate "Lontium LT9611 DSI/HDMI bridge"
select SND_SOC_HDMI_CODEC if SND_SOC
diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
index 2b3aff104e466..21f72df3260db 100644
--- a/drivers/gpu/drm/bridge/Makefile
+++ b/drivers/gpu/drm/bridge/Makefile
@@ -2,6 +2,7 @@
 obj-$(CONFIG_DRM_CDNS_DSI) += cdns-dsi.o
 obj-$(CONFIG_DRM_CHRONTEL_CH7033) += chrontel-ch7033.o
 obj-$(CONFIG_DRM_DISPLAY_CONNECTOR) += display-connector.o
+obj-$(CONFIG_DRM_HIMAX_HX8837) += himax-hx8837.o
 obj-$(CONFIG_DRM_LONTIUM_LT9611) += lontium-lt9611.o
 obj-$(CONFIG_DRM_LVDS_CODEC) += lvds-codec.o
 obj-$(CONFIG_DRM_MEGACHIPS_STDP_GE_B850V3_FW) += 
megachips-stdp-ge-b850v3-fw.o
diff --git a/drivers/gpu/drm/bridge/himax-hx8837.c 
b/drivers/gpu/drm/bridge/himax-hx8837.c
new file mode 100644
index 0..1e97fcb8ce505
--- /dev/null
+++ b/drivers/gpu/drm/bridge/himax-hx8837.c
@@ -0,0 +1,325 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * HiMax HX8837 Display Controller Driver
+ *
+ * Datasheet: http://wiki.laptop.org/images/0/09/DCON_datasheet_HX8837-A.pdf
+ *
+ * Copyright (C) 2020 Lubomir Rintel
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define bridge_to_hx8837_priv(x) \
+   container_of(x, struct hx8837_priv, bridge)
+
+/* DCON registers */
+enum {
+   DCON_REG_ID = 0x00,
+   DCON_REG_MODE   = 0x01,
+   DCON_REG_HRES   = 0x02,
+   DCON_REG_HTOTAL = 0x03,
+   DCON_REG_HSYNC_WIDTH= 0x04,
+   DCON_REG_VRES   = 0x05,
+   DCON_REG_VTOTAL = 0x06,
+   DCON_REG_VSYNC_WIDTH= 0x07,
+   DCON_REG_TIMEOUT= 0x08,
+   DCON_REG_SCAN_INT   = 0x09,
+   DCON_REG_BRIGHT = 0x0a,
+   DCON_REG_MEM_OPT_A  = 0x41,
+   DCON_REG_MEM_OPT_B  = 0x42,
+};
+
+/* DCON_REG_MODE */
+enum {
+   MODE_PASSTHRU   = BIT(0),
+   MODE_SLEEP  = BIT(1),
+   MODE_SLEEP_AUTO = BIT(2),
+   MODE_BL_ENABLE  = BIT(3),
+   MODE_BLANK  = BIT(4),
+   MODE_CSWIZZLE   = BIT(5),
+   MODE_COL_AA = BIT(6),
+   MODE_MONO_LUMA  = BIT(7),
+   MODE_SCAN_INT   = BIT(8),
+   MODE_CLOCKDIV   = BIT(9),
+   MODE_DEBUG  = BIT(14),
+   MODE_SELFTEST   = BIT(15),
+};
+
+struct hx8837_priv {
+   struct regmap *regmap;
+   struct gpio_desc *load_gpio;
+
+   struct drm_bridge *panel_bridge;
+   struct drm_panel *panel;
+   struct drm_bridge bridge;
+};
+
+static int hx8837_bridge_attach(struct drm_bridge *bridge,
+   enum