Re: [PATCH v17 09/10] drm/panel: Use of_find_backlight helper

2018-01-21 Thread Noralf Trønnes


Den 19.01.2018 11.47, skrev Meghana Madhyastha:

Replace of_find_backlight_by_node and of the code around it
with of_find_backlight helper to avoid repetition of code.

Signed-off-by: Meghana Madhyastha 
---
changes in v17:
-remove put_device() to avoid double put
  as we are using the devm version

  drivers/gpu/drm/panel/panel-innolux-p079zca.c   | 23 ---
  drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c | 25 -
  drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c | 25 -
  3 files changed, 12 insertions(+), 61 deletions(-)

diff --git a/drivers/gpu/drm/panel/panel-innolux-p079zca.c 
b/drivers/gpu/drm/panel/panel-innolux-p079zca.c
index 4c1b29eec..059f4af1a 100644
--- a/drivers/gpu/drm/panel/panel-innolux-p079zca.c
+++ b/drivers/gpu/drm/panel/panel-innolux-p079zca.c
@@ -230,37 +230,22 @@ static int innolux_panel_add(struct innolux_panel 
*innolux)
innolux->enable_gpio = NULL;
}
  
-	np = of_parse_phandle(dev->of_node, "backlight", 0);

-   if (np) {
-   innolux->backlight = of_find_backlight_by_node(np);
-   of_node_put(np);
+   innolux->backlight = devm_of_find_backlight(np);


There are several errors in these two last patches, like this one:

/home/pi/dim-build/workdirs/drm-misc/linux-linus/drivers/gpu/drm/panel/panel-innolux-p079zca.c: 
In function 'innolux_panel_add':
/home/pi/dim-build/workdirs/drm-misc/linux-linus/drivers/gpu/drm/panel/panel-innolux-p079zca.c:233:46: 
warning: passing argument 1 of 'devm_of_find_backlight' from 
incompatible pointer type

  innolux->backlight = devm_of_find_backlight(np);

Instead of tracking down the build dependencies to get this driver built,
you can instead use these defconfigs and all DRM drivers should be built:
https://cgit.freedesktop.org/drm/drm-tip/tree/?h=rerere-cache

But not all drivers are built on every architecture.

Noralf.

  
-		if (!innolux->backlight)

-   return -EPROBE_DEFER;
-   }
+   if (IS_ERR(innolux->backlight))
+   return PTR_ERR(innolux->backlight);
  
  	drm_panel_init(>base);

innolux->base.funcs = _panel_funcs;
innolux->base.dev = >link->dev;
  
-	err = drm_panel_add(>base);

-   if (err < 0)
-   goto put_backlight;
-
-   return 0;
-
-put_backlight:
-   put_device(>backlight->dev);
-
-   return err;
+   return drm_panel_add(>base);
  }
  
  static void innolux_panel_del(struct innolux_panel *innolux)

  {
if (innolux->base.dev)
drm_panel_remove(>base);
-
-   put_device(>backlight->dev);
  }
  
  static int innolux_panel_probe(struct mipi_dsi_device *dsi)

diff --git a/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c 
b/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
index 072c0fc79..85279d224 100644
--- a/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
+++ b/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
@@ -327,30 +327,16 @@ static int sharp_panel_add(struct sharp_panel *sharp)
if (IS_ERR(sharp->supply))
return PTR_ERR(sharp->supply);
  
-	np = of_parse_phandle(sharp->link1->dev.of_node, "backlight", 0);

-   if (np) {
-   sharp->backlight = of_find_backlight_by_node(np);
-   of_node_put(np);
+   sharp->backlight = devm_of_find_backlight(np);
  
-		if (!sharp->backlight)

-   return -EPROBE_DEFER;
-   }
+   if (IS_ERR(sharp->backlight))
+   return PTR_ERR(sharp->backlight);
  
  	drm_panel_init(>base);

sharp->base.funcs = _panel_funcs;
sharp->base.dev = >link1->dev;
  
-	err = drm_panel_add(>base);

-   if (err < 0)
-   goto put_backlight;
-
-   return 0;
-
-put_backlight:
-   if (sharp->backlight)
-   put_device(>backlight->dev);
-
-   return err;
+   return drm_panel_add(>base);
  }
  
  static void sharp_panel_del(struct sharp_panel *sharp)

@@ -358,9 +344,6 @@ static void sharp_panel_del(struct sharp_panel *sharp)
if (sharp->base.dev)
drm_panel_remove(>base);
  
-	if (sharp->backlight)

-   put_device(>backlight->dev);
-
if (sharp->link2)
put_device(>link2->dev);
  }
diff --git a/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c 
b/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
index 8a5137963..b634ec887 100644
--- a/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
+++ b/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
@@ -271,39 +271,22 @@ static int sharp_nt_panel_add(struct sharp_nt_panel 
*sharp_nt)
gpiod_set_value(sharp_nt->reset_gpio, 0);
}
  
-	np = of_parse_phandle(dev->of_node, "backlight", 0);

-   if (np) {
-   sharp_nt->backlight = of_find_backlight_by_node(np);
-   of_node_put(np);
+   sharp_nt->backlight = devm_of_find_backlight(np);
  
-		if (!sharp_nt->backlight)

-   

Re: [PATCH v17 09/10] drm/panel: Use of_find_backlight helper

2018-01-21 Thread Noralf Trønnes


Den 19.01.2018 11.47, skrev Meghana Madhyastha:

Replace of_find_backlight_by_node and of the code around it
with of_find_backlight helper to avoid repetition of code.

Signed-off-by: Meghana Madhyastha 
---
changes in v17:
-remove put_device() to avoid double put
  as we are using the devm version

  drivers/gpu/drm/panel/panel-innolux-p079zca.c   | 23 ---
  drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c | 25 -
  drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c | 25 -
  3 files changed, 12 insertions(+), 61 deletions(-)

diff --git a/drivers/gpu/drm/panel/panel-innolux-p079zca.c 
b/drivers/gpu/drm/panel/panel-innolux-p079zca.c
index 4c1b29eec..059f4af1a 100644
--- a/drivers/gpu/drm/panel/panel-innolux-p079zca.c
+++ b/drivers/gpu/drm/panel/panel-innolux-p079zca.c
@@ -230,37 +230,22 @@ static int innolux_panel_add(struct innolux_panel 
*innolux)
innolux->enable_gpio = NULL;
}
  
-	np = of_parse_phandle(dev->of_node, "backlight", 0);

-   if (np) {
-   innolux->backlight = of_find_backlight_by_node(np);
-   of_node_put(np);
+   innolux->backlight = devm_of_find_backlight(np);


There are several errors in these two last patches, like this one:

/home/pi/dim-build/workdirs/drm-misc/linux-linus/drivers/gpu/drm/panel/panel-innolux-p079zca.c: 
In function 'innolux_panel_add':
/home/pi/dim-build/workdirs/drm-misc/linux-linus/drivers/gpu/drm/panel/panel-innolux-p079zca.c:233:46: 
warning: passing argument 1 of 'devm_of_find_backlight' from 
incompatible pointer type

  innolux->backlight = devm_of_find_backlight(np);

Instead of tracking down the build dependencies to get this driver built,
you can instead use these defconfigs and all DRM drivers should be built:
https://cgit.freedesktop.org/drm/drm-tip/tree/?h=rerere-cache

But not all drivers are built on every architecture.

Noralf.

  
-		if (!innolux->backlight)

-   return -EPROBE_DEFER;
-   }
+   if (IS_ERR(innolux->backlight))
+   return PTR_ERR(innolux->backlight);
  
  	drm_panel_init(>base);

innolux->base.funcs = _panel_funcs;
innolux->base.dev = >link->dev;
  
-	err = drm_panel_add(>base);

-   if (err < 0)
-   goto put_backlight;
-
-   return 0;
-
-put_backlight:
-   put_device(>backlight->dev);
-
-   return err;
+   return drm_panel_add(>base);
  }
  
  static void innolux_panel_del(struct innolux_panel *innolux)

  {
if (innolux->base.dev)
drm_panel_remove(>base);
-
-   put_device(>backlight->dev);
  }
  
  static int innolux_panel_probe(struct mipi_dsi_device *dsi)

diff --git a/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c 
b/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
index 072c0fc79..85279d224 100644
--- a/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
+++ b/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
@@ -327,30 +327,16 @@ static int sharp_panel_add(struct sharp_panel *sharp)
if (IS_ERR(sharp->supply))
return PTR_ERR(sharp->supply);
  
-	np = of_parse_phandle(sharp->link1->dev.of_node, "backlight", 0);

-   if (np) {
-   sharp->backlight = of_find_backlight_by_node(np);
-   of_node_put(np);
+   sharp->backlight = devm_of_find_backlight(np);
  
-		if (!sharp->backlight)

-   return -EPROBE_DEFER;
-   }
+   if (IS_ERR(sharp->backlight))
+   return PTR_ERR(sharp->backlight);
  
  	drm_panel_init(>base);

sharp->base.funcs = _panel_funcs;
sharp->base.dev = >link1->dev;
  
-	err = drm_panel_add(>base);

-   if (err < 0)
-   goto put_backlight;
-
-   return 0;
-
-put_backlight:
-   if (sharp->backlight)
-   put_device(>backlight->dev);
-
-   return err;
+   return drm_panel_add(>base);
  }
  
  static void sharp_panel_del(struct sharp_panel *sharp)

@@ -358,9 +344,6 @@ static void sharp_panel_del(struct sharp_panel *sharp)
if (sharp->base.dev)
drm_panel_remove(>base);
  
-	if (sharp->backlight)

-   put_device(>backlight->dev);
-
if (sharp->link2)
put_device(>link2->dev);
  }
diff --git a/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c 
b/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
index 8a5137963..b634ec887 100644
--- a/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
+++ b/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
@@ -271,39 +271,22 @@ static int sharp_nt_panel_add(struct sharp_nt_panel 
*sharp_nt)
gpiod_set_value(sharp_nt->reset_gpio, 0);
}
  
-	np = of_parse_phandle(dev->of_node, "backlight", 0);

-   if (np) {
-   sharp_nt->backlight = of_find_backlight_by_node(np);
-   of_node_put(np);
+   sharp_nt->backlight = devm_of_find_backlight(np);
  
-		if (!sharp_nt->backlight)

-   return -EPROBE_DEFER;
-   

Re: [PATCH v17 03/10] video: backlight: Add of_find_backlight helper in backlight.c

2018-01-21 Thread Noralf Trønnes


Den 19.01.2018 12.05, skrev Daniel Thompson:

On Fri, Jan 19, 2018 at 10:42:15AM +, Meghana Madhyastha wrote:

Add of_find_backlight, a helper function which is a generic version
of tinydrm_of_find_backlight that can be used by other drivers to avoid
repetition of code and simplify things.

Signed-off-by: Meghana Madhyastha 

Didn't I already ack this one?


Meghana,

You are supposed to pick up the r-b/acks you get and add them when you send
a new version. This way the reviewer knows which patches still need 
attention.


Here's a good overview of the acks/r-b's you've received:
https://patchwork.freedesktop.org/project/dri-devel/patches/?submitter=17149

Beware that r-b/ack to the cover letter doesn't show up in patchwork, like
Sean did on the last version putting his r-b on the whole series.
The same goes for someone putting an r-b in one of the patches stating that
it applies to whole series, patchwork thinks it only applies to this one 
patch.


Noralf.




---
changes in v17:
-rebase with drm-misc-next
-convert st7735r callers from tinydrm specific helpers
  to new generic backlight helpers
-remove select BACKLIGHT_LCD_SUPPORT
  and select BACKLIGHT_CLASS_DEVICE from
  tinydrm/Kconfig

  drivers/video/backlight/backlight.c | 43 +
  include/linux/backlight.h   | 19 
  2 files changed, 62 insertions(+)

diff --git a/drivers/video/backlight/backlight.c 
b/drivers/video/backlight/backlight.c
index 8049e7656..553bf5c48 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -580,6 +580,49 @@ struct backlight_device *of_find_backlight_by_node(struct 
device_node *node)
  EXPORT_SYMBOL(of_find_backlight_by_node);
  #endif
  
+/**

+ * of_find_backlight - Get backlight device
+ * @dev: Device
+ *
+ * This function looks for a property named 'backlight' on the DT node
+ * connected to @dev and looks up the backlight device.
+ *
+ * Call backlight_put() to drop the reference on the backlight device.
+ *
+ * Returns:
+ * A pointer to the backlight device if found.
+ * Error pointer -EPROBE_DEFER if the DT property is set, but no backlight
+ * device is found.
+ * NULL if there's no backlight property.
+ */
+struct backlight_device *of_find_backlight(struct device *dev)
+{
+   struct backlight_device *bd = NULL;
+   struct device_node *np;
+
+   if (!dev)
+   return NULL;
+
+   if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
+   np = of_parse_phandle(dev->of_node, "backlight", 0);
+   if (np) {
+   bd = of_find_backlight_by_node(np);
+   of_node_put(np);
+   if (!bd)
+   return ERR_PTR(-EPROBE_DEFER);
+   /*
+* Note: gpio_backlight uses brightness as
+* power state during probe
+*/
+   if (!bd->props.brightness)
+   bd->props.brightness = bd->props.max_brightness;
+   }
+   }
+
+   return bd;
+}
+EXPORT_SYMBOL(of_find_backlight);
+
  static void __exit backlight_class_exit(void)
  {
class_destroy(backlight_class);
diff --git a/include/linux/backlight.h b/include/linux/backlight.h
index ace825e2c..ddc9bade4 100644
--- a/include/linux/backlight.h
+++ b/include/linux/backlight.h
@@ -162,6 +162,16 @@ static inline int backlight_disable(struct 
backlight_device *bd)
return backlight_update_status(bd);
  }
  
+/**

+ * backlight_put - Drop backlight reference
+ * @bd: the backlight device to put
+ */
+static inline void backlight_put(struct backlight_device *bd)
+{
+   if (bd)
+   put_device(>dev);
+}
+
  extern struct backlight_device *backlight_device_register(const char *name,
struct device *dev, void *devdata, const struct backlight_ops *ops,
const struct backlight_properties *props);
@@ -205,4 +215,13 @@ of_find_backlight_by_node(struct device_node *node)
  }
  #endif
  
+#if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)

+struct backlight_device *of_find_backlight(struct device *dev);
+#else
+static inline struct backlight_device *of_find_backlight(struct device *dev)
+{
+   return NULL;
+}
+#endif
+
  #endif
--
2.11.0





Re: [PATCH v17 03/10] video: backlight: Add of_find_backlight helper in backlight.c

2018-01-21 Thread Noralf Trønnes


Den 19.01.2018 12.05, skrev Daniel Thompson:

On Fri, Jan 19, 2018 at 10:42:15AM +, Meghana Madhyastha wrote:

Add of_find_backlight, a helper function which is a generic version
of tinydrm_of_find_backlight that can be used by other drivers to avoid
repetition of code and simplify things.

Signed-off-by: Meghana Madhyastha 

Didn't I already ack this one?


Meghana,

You are supposed to pick up the r-b/acks you get and add them when you send
a new version. This way the reviewer knows which patches still need 
attention.


Here's a good overview of the acks/r-b's you've received:
https://patchwork.freedesktop.org/project/dri-devel/patches/?submitter=17149

Beware that r-b/ack to the cover letter doesn't show up in patchwork, like
Sean did on the last version putting his r-b on the whole series.
The same goes for someone putting an r-b in one of the patches stating that
it applies to whole series, patchwork thinks it only applies to this one 
patch.


Noralf.




---
changes in v17:
-rebase with drm-misc-next
-convert st7735r callers from tinydrm specific helpers
  to new generic backlight helpers
-remove select BACKLIGHT_LCD_SUPPORT
  and select BACKLIGHT_CLASS_DEVICE from
  tinydrm/Kconfig

  drivers/video/backlight/backlight.c | 43 +
  include/linux/backlight.h   | 19 
  2 files changed, 62 insertions(+)

diff --git a/drivers/video/backlight/backlight.c 
b/drivers/video/backlight/backlight.c
index 8049e7656..553bf5c48 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -580,6 +580,49 @@ struct backlight_device *of_find_backlight_by_node(struct 
device_node *node)
  EXPORT_SYMBOL(of_find_backlight_by_node);
  #endif
  
+/**

+ * of_find_backlight - Get backlight device
+ * @dev: Device
+ *
+ * This function looks for a property named 'backlight' on the DT node
+ * connected to @dev and looks up the backlight device.
+ *
+ * Call backlight_put() to drop the reference on the backlight device.
+ *
+ * Returns:
+ * A pointer to the backlight device if found.
+ * Error pointer -EPROBE_DEFER if the DT property is set, but no backlight
+ * device is found.
+ * NULL if there's no backlight property.
+ */
+struct backlight_device *of_find_backlight(struct device *dev)
+{
+   struct backlight_device *bd = NULL;
+   struct device_node *np;
+
+   if (!dev)
+   return NULL;
+
+   if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
+   np = of_parse_phandle(dev->of_node, "backlight", 0);
+   if (np) {
+   bd = of_find_backlight_by_node(np);
+   of_node_put(np);
+   if (!bd)
+   return ERR_PTR(-EPROBE_DEFER);
+   /*
+* Note: gpio_backlight uses brightness as
+* power state during probe
+*/
+   if (!bd->props.brightness)
+   bd->props.brightness = bd->props.max_brightness;
+   }
+   }
+
+   return bd;
+}
+EXPORT_SYMBOL(of_find_backlight);
+
  static void __exit backlight_class_exit(void)
  {
class_destroy(backlight_class);
diff --git a/include/linux/backlight.h b/include/linux/backlight.h
index ace825e2c..ddc9bade4 100644
--- a/include/linux/backlight.h
+++ b/include/linux/backlight.h
@@ -162,6 +162,16 @@ static inline int backlight_disable(struct 
backlight_device *bd)
return backlight_update_status(bd);
  }
  
+/**

+ * backlight_put - Drop backlight reference
+ * @bd: the backlight device to put
+ */
+static inline void backlight_put(struct backlight_device *bd)
+{
+   if (bd)
+   put_device(>dev);
+}
+
  extern struct backlight_device *backlight_device_register(const char *name,
struct device *dev, void *devdata, const struct backlight_ops *ops,
const struct backlight_properties *props);
@@ -205,4 +215,13 @@ of_find_backlight_by_node(struct device_node *node)
  }
  #endif
  
+#if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)

+struct backlight_device *of_find_backlight(struct device *dev);
+#else
+static inline struct backlight_device *of_find_backlight(struct device *dev)
+{
+   return NULL;
+}
+#endif
+
  #endif
--
2.11.0





Re: [PATCH v16 09/10] drm/panel: Use of_find_backlight helper

2018-01-18 Thread Noralf Trønnes


Den 18.01.2018 13.07, skrev Meghana Madhyastha:

On Tue, Jan 16, 2018 at 06:08:53PM +0100, Noralf Trønnes wrote:

Den 16.01.2018 11.36, skrev Meghana Madhyastha:

Replace of_find_backlight_by_node and of the code around it
with of_find_backlight helper to avoid repetition of code.

Signed-off-by: Meghana Madhyastha <meghana.madhyas...@gmail.com>
---
  drivers/gpu/drm/panel/panel-innolux-p079zca.c   | 10 +++---
  drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c | 10 +++---
  drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c | 10 +++---
  3 files changed, 9 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/panel/panel-innolux-p079zca.c 
b/drivers/gpu/drm/panel/panel-innolux-p079zca.c
index 4c1b29eec..a69b0530f 100644
--- a/drivers/gpu/drm/panel/panel-innolux-p079zca.c
+++ b/drivers/gpu/drm/panel/panel-innolux-p079zca.c
@@ -230,14 +230,10 @@ static int innolux_panel_add(struct innolux_panel 
*innolux)
innolux->enable_gpio = NULL;
}
-   np = of_parse_phandle(dev->of_node, "backlight", 0);
-   if (np) {
-   innolux->backlight = of_find_backlight_by_node(np);
-   of_node_put(np);
+   innolux->backlight = devm_of_find_backlight(np);

This driver isn't broken like tinydrm was, so it does put the backlight
device on cleanup like it should. So when you're using the devm_ version,
the result is a double put. Just remove the put_device() in
innolux_panel_add/del() and you're good.

I have a quick question here. So devm_of_find_backlight automatically
does a put_device on detachment of the driver. However in this case,
put_device is called when panel_add is not successful (i.e when it
returns a negative value here). So is devm's release mechanism still
invoked here ?


As long as the error is propagated back up the chain, which it is in this
case, devres_release_all() is called and the resources are released.

Driver callchain passing up the error:
innolux_panel_driver.probe = innolux_panel_probe <- innolux_panel_add <- 
devm_of_find_backlight


This is mipi_dsi setting up the probe hook and calling into it's own 
version:


drivers/gpu/drm/drm_mipi_dsi.c:
int mipi_dsi_driver_register_full(struct mipi_dsi_driver *drv,
                  struct module *owner)
{
...
    if (drv->probe)
        drv->driver.probe = mipi_dsi_drv_probe;
...
}

static int mipi_dsi_drv_probe(struct device *dev)
{
    struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
    struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);

    return drv->probe(dsi);
}

This is the device-driver core that initiates the probing:

drivers/base/dd.c
static int really_probe(struct device *dev, struct device_driver *drv)
{
...
    } else if (drv->probe) {
        ret = drv->probe(dev);
        if (ret)
            goto probe_failed;
    }
...
probe_failed:
...
    devres_release_all(dev);
...
}


err = drm_panel_add(>base);
if (err < 0)
goto put_backlight;

return 0;

put_backlight:
put_device(>backlight->dev);
return err;

If so then I should change this to
err = drm_panel_add(>base)
return err;


Yes, and you can drop the variable:

    return drm_panel_add(>base);

Noralf.



Thanks and regards,
Meghana


I haven't checked the other drivers.

Noralf.

PS:
Give people a few days (one week?) to respond before respinning a new
version, so we avoid a fragmented discussion.


-   if (!innolux->backlight)
-   return -EPROBE_DEFER;
-   }
+   if (IS_ERR(innolux->backlight))
+   return PTR_ERR(innolux->backlight);
drm_panel_init(>base);
innolux->base.funcs = _panel_funcs;
diff --git a/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c 
b/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
index 1512ec4f3..d5450c9d9 100644
--- a/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
+++ b/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
@@ -329,14 +329,10 @@ static int sharp_panel_add(struct sharp_panel *sharp)
if (IS_ERR(sharp->supply))
return PTR_ERR(sharp->supply);
-   np = of_parse_phandle(sharp->link1->dev.of_node, "backlight", 0);
-   if (np) {
-   sharp->backlight = of_find_backlight_by_node(np);
-   of_node_put(np);
+   sharp->backlight = devm_of_find_backlight(np);
-   if (!sharp->backlight)
-   return -EPROBE_DEFER;
-   }
+   if (IS_ERR(sharp->backlight))
+   return PTR_ERR(sharp->backlight);
drm_panel_init(>base);
sharp->base.funcs = _panel_funcs;
diff --git a/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c 
b/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
index a6af3257f..db31d8268 100644
--- a/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
+++ b/driv

Re: [PATCH v16 09/10] drm/panel: Use of_find_backlight helper

2018-01-18 Thread Noralf Trønnes


Den 18.01.2018 13.07, skrev Meghana Madhyastha:

On Tue, Jan 16, 2018 at 06:08:53PM +0100, Noralf Trønnes wrote:

Den 16.01.2018 11.36, skrev Meghana Madhyastha:

Replace of_find_backlight_by_node and of the code around it
with of_find_backlight helper to avoid repetition of code.

Signed-off-by: Meghana Madhyastha 
---
  drivers/gpu/drm/panel/panel-innolux-p079zca.c   | 10 +++---
  drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c | 10 +++---
  drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c | 10 +++---
  3 files changed, 9 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/panel/panel-innolux-p079zca.c 
b/drivers/gpu/drm/panel/panel-innolux-p079zca.c
index 4c1b29eec..a69b0530f 100644
--- a/drivers/gpu/drm/panel/panel-innolux-p079zca.c
+++ b/drivers/gpu/drm/panel/panel-innolux-p079zca.c
@@ -230,14 +230,10 @@ static int innolux_panel_add(struct innolux_panel 
*innolux)
innolux->enable_gpio = NULL;
}
-   np = of_parse_phandle(dev->of_node, "backlight", 0);
-   if (np) {
-   innolux->backlight = of_find_backlight_by_node(np);
-   of_node_put(np);
+   innolux->backlight = devm_of_find_backlight(np);

This driver isn't broken like tinydrm was, so it does put the backlight
device on cleanup like it should. So when you're using the devm_ version,
the result is a double put. Just remove the put_device() in
innolux_panel_add/del() and you're good.

I have a quick question here. So devm_of_find_backlight automatically
does a put_device on detachment of the driver. However in this case,
put_device is called when panel_add is not successful (i.e when it
returns a negative value here). So is devm's release mechanism still
invoked here ?


As long as the error is propagated back up the chain, which it is in this
case, devres_release_all() is called and the resources are released.

Driver callchain passing up the error:
innolux_panel_driver.probe = innolux_panel_probe <- innolux_panel_add <- 
devm_of_find_backlight


This is mipi_dsi setting up the probe hook and calling into it's own 
version:


drivers/gpu/drm/drm_mipi_dsi.c:
int mipi_dsi_driver_register_full(struct mipi_dsi_driver *drv,
                  struct module *owner)
{
...
    if (drv->probe)
        drv->driver.probe = mipi_dsi_drv_probe;
...
}

static int mipi_dsi_drv_probe(struct device *dev)
{
    struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
    struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);

    return drv->probe(dsi);
}

This is the device-driver core that initiates the probing:

drivers/base/dd.c
static int really_probe(struct device *dev, struct device_driver *drv)
{
...
    } else if (drv->probe) {
        ret = drv->probe(dev);
        if (ret)
            goto probe_failed;
    }
...
probe_failed:
...
    devres_release_all(dev);
...
}


err = drm_panel_add(>base);
if (err < 0)
goto put_backlight;

return 0;

put_backlight:
put_device(>backlight->dev);
return err;

If so then I should change this to
err = drm_panel_add(>base)
return err;


Yes, and you can drop the variable:

    return drm_panel_add(>base);

Noralf.



Thanks and regards,
Meghana


I haven't checked the other drivers.

Noralf.

PS:
Give people a few days (one week?) to respond before respinning a new
version, so we avoid a fragmented discussion.


-   if (!innolux->backlight)
-   return -EPROBE_DEFER;
-   }
+   if (IS_ERR(innolux->backlight))
+   return PTR_ERR(innolux->backlight);
drm_panel_init(>base);
innolux->base.funcs = _panel_funcs;
diff --git a/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c 
b/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
index 1512ec4f3..d5450c9d9 100644
--- a/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
+++ b/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
@@ -329,14 +329,10 @@ static int sharp_panel_add(struct sharp_panel *sharp)
if (IS_ERR(sharp->supply))
return PTR_ERR(sharp->supply);
-   np = of_parse_phandle(sharp->link1->dev.of_node, "backlight", 0);
-   if (np) {
-   sharp->backlight = of_find_backlight_by_node(np);
-   of_node_put(np);
+   sharp->backlight = devm_of_find_backlight(np);
-   if (!sharp->backlight)
-   return -EPROBE_DEFER;
-   }
+   if (IS_ERR(sharp->backlight))
+   return PTR_ERR(sharp->backlight);
drm_panel_init(>base);
sharp->base.funcs = _panel_funcs;
diff --git a/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c 
b/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
index a6af3257f..db31d8268 100644
--- a/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
+++ b/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
@@ -

Re: [PATCH v16 01/10] video: backlight: Add helpers to enable and disable backlight

2018-01-17 Thread Noralf Trønnes


Den 17.01.2018 18.00, skrev Daniel Thompson:



On 16/01/18 10:31, Meghana Madhyastha wrote:

Add helper functions backlight_enable and backlight_disable to
enable/disable a backlight device. These helper functions can
then be used by different drm and tinydrm drivers to avoid
repetition of code and also to enforce a uniform and consistent
way to enable/disable a backlight device.

Signed-off-by: Meghana Madhyastha 


To be clear I don't disagree with anthing Daniel V. said about the 
horribly confused (and confusing) power states for backlight.


Nevertheless I don't recall seeing any response (positive or negative) 
to this post from v13:

https://www.spinics.net/lists/dri-devel/msg154459.html



I see that Daniel V has answered while I was chasing this down, but anyways:

A grep suggests that omap1_bl is the only driver that only checks fb_blank.
All the other drivers check both fb_blank and power, a few check state. The
backlight fbdev notifier callback doesn't set power, but sets fb_blank and
state.

fb_blank was marked 'Due to be removed' 9 years ago, so it hasn't been
high priority.

So for completeness I guess it makes sense to set fb_blank.

Noralf.

$ grep -r -C10 "props\.fb_blank" .
./drivers/video/backlight/corgi_lcd.c-  if (bd->props.power != 
FB_BLANK_UNBLANK)

./drivers/video/backlight/corgi_lcd.c-  intensity = 0;
./drivers/video/backlight/corgi_lcd.c-
./drivers/video/backlight/corgi_lcd.c:  if (bd->props.fb_blank != 
FB_BLANK_UNBLANK)

./drivers/video/backlight/corgi_lcd.c-  intensity = 0;
--
./drivers/video/backlight/adp8860_bl.c- if (bl->props.power != 
FB_BLANK_UNBLANK)

./drivers/video/backlight/adp8860_bl.c- brightness = 0;
./drivers/video/backlight/adp8860_bl.c-
./drivers/video/backlight/adp8860_bl.c: if (bl->props.fb_blank != 
FB_BLANK_UNBLANK)

./drivers/video/backlight/adp8860_bl.c- brightness = 0;
--
./drivers/video/backlight/hp680_bl.c-   if (bd->props.power != 
FB_BLANK_UNBLANK)

./drivers/video/backlight/hp680_bl.c-   intensity = 0;
./drivers/video/backlight/hp680_bl.c:   if (bd->props.fb_blank != 
FB_BLANK_UNBLANK)

./drivers/video/backlight/hp680_bl.c-   intensity = 0;
--
./drivers/video/backlight/cr_bllcd.c-static int 
cr_backlight_set_intensity(struct backlight_device *bd)

./drivers/video/backlight/cr_bllcd.c-{
./drivers/video/backlight/cr_bllcd.c-   int intensity = 
bd->props.brightness;
./drivers/video/backlight/cr_bllcd.c-   u32 addr = gpio_bar + 
CRVML_PANEL_PORT;

./drivers/video/backlight/cr_bllcd.c-   u32 cur = inl(addr);
./drivers/video/backlight/cr_bllcd.c-
./drivers/video/backlight/cr_bllcd.c-   if (bd->props.power == 
FB_BLANK_UNBLANK)
./drivers/video/backlight/cr_bllcd.c-   intensity = 
FB_BLANK_UNBLANK;
./drivers/video/backlight/cr_bllcd.c:   if (bd->props.fb_blank == 
FB_BLANK_UNBLANK)
./drivers/video/backlight/cr_bllcd.c-   intensity = 
FB_BLANK_UNBLANK;
./drivers/video/backlight/cr_bllcd.c-   if (bd->props.power == 
FB_BLANK_POWERDOWN)
./drivers/video/backlight/cr_bllcd.c-   intensity = 
FB_BLANK_POWERDOWN;
./drivers/video/backlight/cr_bllcd.c:   if (bd->props.fb_blank == 
FB_BLANK_POWERDOWN)
./drivers/video/backlight/cr_bllcd.c-   intensity = 
FB_BLANK_POWERDOWN;

--
./drivers/video/backlight/max8925_bl.c- if (bl->props.power != 
FB_BLANK_UNBLANK)

./drivers/video/backlight/max8925_bl.c- brightness = 0;
./drivers/video/backlight/max8925_bl.c-
./drivers/video/backlight/max8925_bl.c: if (bl->props.fb_blank != 
FB_BLANK_UNBLANK)

./drivers/video/backlight/max8925_bl.c- brightness = 0;
./drivers/video/backlight/max8925_bl.c-
./drivers/video/backlight/max8925_bl.c- if (bl->props.state & 
BL_CORE_SUSPENDED)

./drivers/video/backlight/max8925_bl.c- brightness = 0;
--
./drivers/video/backlight/lv5207lp.c-   if (backlight->props.power != 
FB_BLANK_UNBLANK ||
./drivers/video/backlight/lv5207lp.c: backlight->props.fb_blank != 
FB_BLANK_UNBLANK ||
./drivers/video/backlight/lv5207lp.c- backlight->props.state & 
(BL_CORE_SUSPENDED | BL_CORE_FBBLANK))

./drivers/video/backlight/lv5207lp.c-   brightness = 0;
--
./drivers/video/backlight/lm3533_bl.c-  if (bd->props.power != 
FB_BLANK_UNBLANK)

./drivers/video/backlight/lm3533_bl.c-  brightness = 0;
./drivers/video/backlight/lm3533_bl.c:  if (bd->props.fb_blank != 
FB_BLANK_UNBLANK)

./drivers/video/backlight/lm3533_bl.c-  brightness = 0;
--
./drivers/video/backlight/omap1_bl.c-static int 
omapbl_update_status(struct backlight_device *dev)

./drivers/video/backlight/omap1_bl.c-{
./drivers/video/backlight/omap1_bl.c-   struct omap_backlight *bl = 
bl_get_data(dev);

./drivers/video/backlight/omap1_bl.c-
./drivers/video/backlight/omap1_bl.c-   if (bl->current_intensity != 
dev->props.brightness) {
./drivers/video/backlight/omap1_bl.c-   if (bl->powermode == 
FB_BLANK_UNBLANK)
./drivers/video/backlight/omap1_bl.c- 
omapbl_send_intensity(dev->props.brightness);

Re: [PATCH v16 01/10] video: backlight: Add helpers to enable and disable backlight

2018-01-17 Thread Noralf Trønnes


Den 17.01.2018 18.00, skrev Daniel Thompson:



On 16/01/18 10:31, Meghana Madhyastha wrote:

Add helper functions backlight_enable and backlight_disable to
enable/disable a backlight device. These helper functions can
then be used by different drm and tinydrm drivers to avoid
repetition of code and also to enforce a uniform and consistent
way to enable/disable a backlight device.

Signed-off-by: Meghana Madhyastha 


To be clear I don't disagree with anthing Daniel V. said about the 
horribly confused (and confusing) power states for backlight.


Nevertheless I don't recall seeing any response (positive or negative) 
to this post from v13:

https://www.spinics.net/lists/dri-devel/msg154459.html



I see that Daniel V has answered while I was chasing this down, but anyways:

A grep suggests that omap1_bl is the only driver that only checks fb_blank.
All the other drivers check both fb_blank and power, a few check state. The
backlight fbdev notifier callback doesn't set power, but sets fb_blank and
state.

fb_blank was marked 'Due to be removed' 9 years ago, so it hasn't been
high priority.

So for completeness I guess it makes sense to set fb_blank.

Noralf.

$ grep -r -C10 "props\.fb_blank" .
./drivers/video/backlight/corgi_lcd.c-  if (bd->props.power != 
FB_BLANK_UNBLANK)

./drivers/video/backlight/corgi_lcd.c-  intensity = 0;
./drivers/video/backlight/corgi_lcd.c-
./drivers/video/backlight/corgi_lcd.c:  if (bd->props.fb_blank != 
FB_BLANK_UNBLANK)

./drivers/video/backlight/corgi_lcd.c-  intensity = 0;
--
./drivers/video/backlight/adp8860_bl.c- if (bl->props.power != 
FB_BLANK_UNBLANK)

./drivers/video/backlight/adp8860_bl.c- brightness = 0;
./drivers/video/backlight/adp8860_bl.c-
./drivers/video/backlight/adp8860_bl.c: if (bl->props.fb_blank != 
FB_BLANK_UNBLANK)

./drivers/video/backlight/adp8860_bl.c- brightness = 0;
--
./drivers/video/backlight/hp680_bl.c-   if (bd->props.power != 
FB_BLANK_UNBLANK)

./drivers/video/backlight/hp680_bl.c-   intensity = 0;
./drivers/video/backlight/hp680_bl.c:   if (bd->props.fb_blank != 
FB_BLANK_UNBLANK)

./drivers/video/backlight/hp680_bl.c-   intensity = 0;
--
./drivers/video/backlight/cr_bllcd.c-static int 
cr_backlight_set_intensity(struct backlight_device *bd)

./drivers/video/backlight/cr_bllcd.c-{
./drivers/video/backlight/cr_bllcd.c-   int intensity = 
bd->props.brightness;
./drivers/video/backlight/cr_bllcd.c-   u32 addr = gpio_bar + 
CRVML_PANEL_PORT;

./drivers/video/backlight/cr_bllcd.c-   u32 cur = inl(addr);
./drivers/video/backlight/cr_bllcd.c-
./drivers/video/backlight/cr_bllcd.c-   if (bd->props.power == 
FB_BLANK_UNBLANK)
./drivers/video/backlight/cr_bllcd.c-   intensity = 
FB_BLANK_UNBLANK;
./drivers/video/backlight/cr_bllcd.c:   if (bd->props.fb_blank == 
FB_BLANK_UNBLANK)
./drivers/video/backlight/cr_bllcd.c-   intensity = 
FB_BLANK_UNBLANK;
./drivers/video/backlight/cr_bllcd.c-   if (bd->props.power == 
FB_BLANK_POWERDOWN)
./drivers/video/backlight/cr_bllcd.c-   intensity = 
FB_BLANK_POWERDOWN;
./drivers/video/backlight/cr_bllcd.c:   if (bd->props.fb_blank == 
FB_BLANK_POWERDOWN)
./drivers/video/backlight/cr_bllcd.c-   intensity = 
FB_BLANK_POWERDOWN;

--
./drivers/video/backlight/max8925_bl.c- if (bl->props.power != 
FB_BLANK_UNBLANK)

./drivers/video/backlight/max8925_bl.c- brightness = 0;
./drivers/video/backlight/max8925_bl.c-
./drivers/video/backlight/max8925_bl.c: if (bl->props.fb_blank != 
FB_BLANK_UNBLANK)

./drivers/video/backlight/max8925_bl.c- brightness = 0;
./drivers/video/backlight/max8925_bl.c-
./drivers/video/backlight/max8925_bl.c- if (bl->props.state & 
BL_CORE_SUSPENDED)

./drivers/video/backlight/max8925_bl.c- brightness = 0;
--
./drivers/video/backlight/lv5207lp.c-   if (backlight->props.power != 
FB_BLANK_UNBLANK ||
./drivers/video/backlight/lv5207lp.c: backlight->props.fb_blank != 
FB_BLANK_UNBLANK ||
./drivers/video/backlight/lv5207lp.c- backlight->props.state & 
(BL_CORE_SUSPENDED | BL_CORE_FBBLANK))

./drivers/video/backlight/lv5207lp.c-   brightness = 0;
--
./drivers/video/backlight/lm3533_bl.c-  if (bd->props.power != 
FB_BLANK_UNBLANK)

./drivers/video/backlight/lm3533_bl.c-  brightness = 0;
./drivers/video/backlight/lm3533_bl.c:  if (bd->props.fb_blank != 
FB_BLANK_UNBLANK)

./drivers/video/backlight/lm3533_bl.c-  brightness = 0;
--
./drivers/video/backlight/omap1_bl.c-static int 
omapbl_update_status(struct backlight_device *dev)

./drivers/video/backlight/omap1_bl.c-{
./drivers/video/backlight/omap1_bl.c-   struct omap_backlight *bl = 
bl_get_data(dev);

./drivers/video/backlight/omap1_bl.c-
./drivers/video/backlight/omap1_bl.c-   if (bl->current_intensity != 
dev->props.brightness) {
./drivers/video/backlight/omap1_bl.c-   if (bl->powermode == 
FB_BLANK_UNBLANK)
./drivers/video/backlight/omap1_bl.c- 
omapbl_send_intensity(dev->props.brightness);

Re: [PATCH v16 07/10] drm/panel: Use backlight_enable/disable helpers

2018-01-16 Thread Noralf Trønnes


Den 16.01.2018 11.35, skrev Meghana Madhyastha:

Use backlight_enable/disable helpers instead of changing
the property and calling backlight_update_status for cleaner
and simpler code and also to avoid repetitions.

Signed-off-by: Meghana Madhyastha 
---
  drivers/gpu/drm/panel/panel-innolux-p079zca.c   |  6 ++
  drivers/gpu/drm/panel/panel-jdi-lt070me05000.c  |  6 ++
  drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c | 12 
  drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c | 12 
  4 files changed, 12 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/panel/panel-innolux-p079zca.c 
b/drivers/gpu/drm/panel/panel-innolux-p079zca.c
index 6ba93449f..4c1b29eec 100644
--- a/drivers/gpu/drm/panel/panel-innolux-p079zca.c
+++ b/drivers/gpu/drm/panel/panel-innolux-p079zca.c
@@ -45,8 +45,7 @@ static int innolux_panel_disable(struct drm_panel *panel)
if (!innolux->enabled)
return 0;
  
-	innolux->backlight->props.power = FB_BLANK_POWERDOWN;

-   backlight_update_status(innolux->backlight);
+   backlight_disable(innolux->backlight);
  
  	err = mipi_dsi_dcs_set_display_off(innolux->link);

if (err < 0)
@@ -151,8 +150,7 @@ static int innolux_panel_enable(struct drm_panel *panel)
if (innolux->enabled)
return 0;
  
-	innolux->backlight->props.power = FB_BLANK_UNBLANK;

-   ret = backlight_update_status(innolux->backlight);
+   ret = backlight_enable(innolux->backlight);
if (ret) {
DRM_DEV_ERROR(panel->drm->dev,
  "Failed to enable backlight %d\n", ret);
diff --git a/drivers/gpu/drm/panel/panel-jdi-lt070me05000.c 
b/drivers/gpu/drm/panel/panel-jdi-lt070me05000.c
index 5b2340ef7..0a94ab79a 100644
--- a/drivers/gpu/drm/panel/panel-jdi-lt070me05000.c
+++ b/drivers/gpu/drm/panel/panel-jdi-lt070me05000.c
@@ -192,8 +192,7 @@ static int jdi_panel_disable(struct drm_panel *panel)
if (!jdi->enabled)
return 0;
  
-	jdi->backlight->props.power = FB_BLANK_POWERDOWN;

-   backlight_update_status(jdi->backlight);
+   backlight_disable(jdi->backlight);
  
  	jdi->enabled = false;
  
@@ -289,8 +288,7 @@ static int jdi_panel_enable(struct drm_panel *panel)

if (jdi->enabled)
return 0;
  
-	jdi->backlight->props.power = FB_BLANK_UNBLANK;

-   backlight_update_status(jdi->backlight);
+   backlight_enable(jdi->backlight);
  
  	jdi->enabled = true;
  
diff --git a/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c b/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c

index 3cce3ca19..1512ec4f3 100644
--- a/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
+++ b/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
@@ -96,10 +96,8 @@ static int sharp_panel_disable(struct drm_panel *panel)
if (!sharp->enabled)
return 0;
  
-	if (sharp->backlight) {

-   sharp->backlight->props.power = FB_BLANK_POWERDOWN;
-   backlight_update_status(sharp->backlight);
-   }
+   if (sharp->backlight)


No need for a NULL check, backlight_enable/disable() already does that.
The same goes for the rest of the patch.

Noralf.


+   backlight_disable(sharp->backlight);
  
  	sharp->enabled = false;
  
@@ -263,10 +261,8 @@ static int sharp_panel_enable(struct drm_panel *panel)

if (sharp->enabled)
return 0;
  
-	if (sharp->backlight) {

-   sharp->backlight->props.power = FB_BLANK_UNBLANK;
-   backlight_update_status(sharp->backlight);
-   }
+   if (sharp->backlight)
+   backlight_enable(sharp->backlight);
  
  	sharp->enabled = true;
  
diff --git a/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c b/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c

index 3aeb0bda4..a6af3257f 100644
--- a/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
+++ b/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
@@ -117,10 +117,8 @@ static int sharp_nt_panel_disable(struct drm_panel *panel)
if (!sharp_nt->enabled)
return 0;
  
-	if (sharp_nt->backlight) {

-   sharp_nt->backlight->props.power = FB_BLANK_POWERDOWN;
-   backlight_update_status(sharp_nt->backlight);
-   }
+   if (sharp_nt->backlight)
+   backlight_disable(sharp_nt->backlight);
  
  	sharp_nt->enabled = false;
  
@@ -203,10 +201,8 @@ static int sharp_nt_panel_enable(struct drm_panel *panel)

if (sharp_nt->enabled)
return 0;
  
-	if (sharp_nt->backlight) {

-   sharp_nt->backlight->props.power = FB_BLANK_UNBLANK;
-   backlight_update_status(sharp_nt->backlight);
-   }
+   if (sharp_nt->backlight)
+   backlight_enable(sharp_nt->backlight);
  
  	sharp_nt->enabled = true;
  




Re: [PATCH v16 07/10] drm/panel: Use backlight_enable/disable helpers

2018-01-16 Thread Noralf Trønnes


Den 16.01.2018 11.35, skrev Meghana Madhyastha:

Use backlight_enable/disable helpers instead of changing
the property and calling backlight_update_status for cleaner
and simpler code and also to avoid repetitions.

Signed-off-by: Meghana Madhyastha 
---
  drivers/gpu/drm/panel/panel-innolux-p079zca.c   |  6 ++
  drivers/gpu/drm/panel/panel-jdi-lt070me05000.c  |  6 ++
  drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c | 12 
  drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c | 12 
  4 files changed, 12 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/panel/panel-innolux-p079zca.c 
b/drivers/gpu/drm/panel/panel-innolux-p079zca.c
index 6ba93449f..4c1b29eec 100644
--- a/drivers/gpu/drm/panel/panel-innolux-p079zca.c
+++ b/drivers/gpu/drm/panel/panel-innolux-p079zca.c
@@ -45,8 +45,7 @@ static int innolux_panel_disable(struct drm_panel *panel)
if (!innolux->enabled)
return 0;
  
-	innolux->backlight->props.power = FB_BLANK_POWERDOWN;

-   backlight_update_status(innolux->backlight);
+   backlight_disable(innolux->backlight);
  
  	err = mipi_dsi_dcs_set_display_off(innolux->link);

if (err < 0)
@@ -151,8 +150,7 @@ static int innolux_panel_enable(struct drm_panel *panel)
if (innolux->enabled)
return 0;
  
-	innolux->backlight->props.power = FB_BLANK_UNBLANK;

-   ret = backlight_update_status(innolux->backlight);
+   ret = backlight_enable(innolux->backlight);
if (ret) {
DRM_DEV_ERROR(panel->drm->dev,
  "Failed to enable backlight %d\n", ret);
diff --git a/drivers/gpu/drm/panel/panel-jdi-lt070me05000.c 
b/drivers/gpu/drm/panel/panel-jdi-lt070me05000.c
index 5b2340ef7..0a94ab79a 100644
--- a/drivers/gpu/drm/panel/panel-jdi-lt070me05000.c
+++ b/drivers/gpu/drm/panel/panel-jdi-lt070me05000.c
@@ -192,8 +192,7 @@ static int jdi_panel_disable(struct drm_panel *panel)
if (!jdi->enabled)
return 0;
  
-	jdi->backlight->props.power = FB_BLANK_POWERDOWN;

-   backlight_update_status(jdi->backlight);
+   backlight_disable(jdi->backlight);
  
  	jdi->enabled = false;
  
@@ -289,8 +288,7 @@ static int jdi_panel_enable(struct drm_panel *panel)

if (jdi->enabled)
return 0;
  
-	jdi->backlight->props.power = FB_BLANK_UNBLANK;

-   backlight_update_status(jdi->backlight);
+   backlight_enable(jdi->backlight);
  
  	jdi->enabled = true;
  
diff --git a/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c b/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c

index 3cce3ca19..1512ec4f3 100644
--- a/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
+++ b/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
@@ -96,10 +96,8 @@ static int sharp_panel_disable(struct drm_panel *panel)
if (!sharp->enabled)
return 0;
  
-	if (sharp->backlight) {

-   sharp->backlight->props.power = FB_BLANK_POWERDOWN;
-   backlight_update_status(sharp->backlight);
-   }
+   if (sharp->backlight)


No need for a NULL check, backlight_enable/disable() already does that.
The same goes for the rest of the patch.

Noralf.


+   backlight_disable(sharp->backlight);
  
  	sharp->enabled = false;
  
@@ -263,10 +261,8 @@ static int sharp_panel_enable(struct drm_panel *panel)

if (sharp->enabled)
return 0;
  
-	if (sharp->backlight) {

-   sharp->backlight->props.power = FB_BLANK_UNBLANK;
-   backlight_update_status(sharp->backlight);
-   }
+   if (sharp->backlight)
+   backlight_enable(sharp->backlight);
  
  	sharp->enabled = true;
  
diff --git a/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c b/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c

index 3aeb0bda4..a6af3257f 100644
--- a/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
+++ b/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
@@ -117,10 +117,8 @@ static int sharp_nt_panel_disable(struct drm_panel *panel)
if (!sharp_nt->enabled)
return 0;
  
-	if (sharp_nt->backlight) {

-   sharp_nt->backlight->props.power = FB_BLANK_POWERDOWN;
-   backlight_update_status(sharp_nt->backlight);
-   }
+   if (sharp_nt->backlight)
+   backlight_disable(sharp_nt->backlight);
  
  	sharp_nt->enabled = false;
  
@@ -203,10 +201,8 @@ static int sharp_nt_panel_enable(struct drm_panel *panel)

if (sharp_nt->enabled)
return 0;
  
-	if (sharp_nt->backlight) {

-   sharp_nt->backlight->props.power = FB_BLANK_UNBLANK;
-   backlight_update_status(sharp_nt->backlight);
-   }
+   if (sharp_nt->backlight)
+   backlight_enable(sharp_nt->backlight);
  
  	sharp_nt->enabled = true;
  




Re: [PATCH v16 09/10] drm/panel: Use of_find_backlight helper

2018-01-16 Thread Noralf Trønnes


Den 16.01.2018 11.36, skrev Meghana Madhyastha:

Replace of_find_backlight_by_node and of the code around it
with of_find_backlight helper to avoid repetition of code.

Signed-off-by: Meghana Madhyastha 
---
  drivers/gpu/drm/panel/panel-innolux-p079zca.c   | 10 +++---
  drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c | 10 +++---
  drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c | 10 +++---
  3 files changed, 9 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/panel/panel-innolux-p079zca.c 
b/drivers/gpu/drm/panel/panel-innolux-p079zca.c
index 4c1b29eec..a69b0530f 100644
--- a/drivers/gpu/drm/panel/panel-innolux-p079zca.c
+++ b/drivers/gpu/drm/panel/panel-innolux-p079zca.c
@@ -230,14 +230,10 @@ static int innolux_panel_add(struct innolux_panel 
*innolux)
innolux->enable_gpio = NULL;
}
  
-	np = of_parse_phandle(dev->of_node, "backlight", 0);

-   if (np) {
-   innolux->backlight = of_find_backlight_by_node(np);
-   of_node_put(np);
+   innolux->backlight = devm_of_find_backlight(np);


This driver isn't broken like tinydrm was, so it does put the backlight
device on cleanup like it should. So when you're using the devm_ version,
the result is a double put. Just remove the put_device() in
innolux_panel_add/del() and you're good.

I haven't checked the other drivers.

Noralf.

PS:
Give people a few days (one week?) to respond before respinning a new
version, so we avoid a fragmented discussion.

  
-		if (!innolux->backlight)

-   return -EPROBE_DEFER;
-   }
+   if (IS_ERR(innolux->backlight))
+   return PTR_ERR(innolux->backlight);
  
  	drm_panel_init(>base);

innolux->base.funcs = _panel_funcs;
diff --git a/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c 
b/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
index 1512ec4f3..d5450c9d9 100644
--- a/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
+++ b/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
@@ -329,14 +329,10 @@ static int sharp_panel_add(struct sharp_panel *sharp)
if (IS_ERR(sharp->supply))
return PTR_ERR(sharp->supply);
  
-	np = of_parse_phandle(sharp->link1->dev.of_node, "backlight", 0);

-   if (np) {
-   sharp->backlight = of_find_backlight_by_node(np);
-   of_node_put(np);
+   sharp->backlight = devm_of_find_backlight(np);
  
-		if (!sharp->backlight)

-   return -EPROBE_DEFER;
-   }
+   if (IS_ERR(sharp->backlight))
+   return PTR_ERR(sharp->backlight);
  
  	drm_panel_init(>base);

sharp->base.funcs = _panel_funcs;
diff --git a/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c 
b/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
index a6af3257f..db31d8268 100644
--- a/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
+++ b/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
@@ -273,14 +273,10 @@ static int sharp_nt_panel_add(struct sharp_nt_panel 
*sharp_nt)
gpiod_set_value(sharp_nt->reset_gpio, 0);
}
  
-	np = of_parse_phandle(dev->of_node, "backlight", 0);

-   if (np) {
-   sharp_nt->backlight = of_find_backlight_by_node(np);
-   of_node_put(np);
+   sharp_nt->backlight = devm_of_find_backlight(np);
  
-		if (!sharp_nt->backlight)

-   return -EPROBE_DEFER;
-   }
+   if (IS_ERR(sharp_nt->backlight))
+   return PTR_ERR(sharp_nt->backlight);
  
  	drm_panel_init(_nt->base);

sharp_nt->base.funcs = _nt_panel_funcs;




Re: [PATCH v16 09/10] drm/panel: Use of_find_backlight helper

2018-01-16 Thread Noralf Trønnes


Den 16.01.2018 11.36, skrev Meghana Madhyastha:

Replace of_find_backlight_by_node and of the code around it
with of_find_backlight helper to avoid repetition of code.

Signed-off-by: Meghana Madhyastha 
---
  drivers/gpu/drm/panel/panel-innolux-p079zca.c   | 10 +++---
  drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c | 10 +++---
  drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c | 10 +++---
  3 files changed, 9 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/panel/panel-innolux-p079zca.c 
b/drivers/gpu/drm/panel/panel-innolux-p079zca.c
index 4c1b29eec..a69b0530f 100644
--- a/drivers/gpu/drm/panel/panel-innolux-p079zca.c
+++ b/drivers/gpu/drm/panel/panel-innolux-p079zca.c
@@ -230,14 +230,10 @@ static int innolux_panel_add(struct innolux_panel 
*innolux)
innolux->enable_gpio = NULL;
}
  
-	np = of_parse_phandle(dev->of_node, "backlight", 0);

-   if (np) {
-   innolux->backlight = of_find_backlight_by_node(np);
-   of_node_put(np);
+   innolux->backlight = devm_of_find_backlight(np);


This driver isn't broken like tinydrm was, so it does put the backlight
device on cleanup like it should. So when you're using the devm_ version,
the result is a double put. Just remove the put_device() in
innolux_panel_add/del() and you're good.

I haven't checked the other drivers.

Noralf.

PS:
Give people a few days (one week?) to respond before respinning a new
version, so we avoid a fragmented discussion.

  
-		if (!innolux->backlight)

-   return -EPROBE_DEFER;
-   }
+   if (IS_ERR(innolux->backlight))
+   return PTR_ERR(innolux->backlight);
  
  	drm_panel_init(>base);

innolux->base.funcs = _panel_funcs;
diff --git a/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c 
b/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
index 1512ec4f3..d5450c9d9 100644
--- a/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
+++ b/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
@@ -329,14 +329,10 @@ static int sharp_panel_add(struct sharp_panel *sharp)
if (IS_ERR(sharp->supply))
return PTR_ERR(sharp->supply);
  
-	np = of_parse_phandle(sharp->link1->dev.of_node, "backlight", 0);

-   if (np) {
-   sharp->backlight = of_find_backlight_by_node(np);
-   of_node_put(np);
+   sharp->backlight = devm_of_find_backlight(np);
  
-		if (!sharp->backlight)

-   return -EPROBE_DEFER;
-   }
+   if (IS_ERR(sharp->backlight))
+   return PTR_ERR(sharp->backlight);
  
  	drm_panel_init(>base);

sharp->base.funcs = _panel_funcs;
diff --git a/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c 
b/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
index a6af3257f..db31d8268 100644
--- a/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
+++ b/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
@@ -273,14 +273,10 @@ static int sharp_nt_panel_add(struct sharp_nt_panel 
*sharp_nt)
gpiod_set_value(sharp_nt->reset_gpio, 0);
}
  
-	np = of_parse_phandle(dev->of_node, "backlight", 0);

-   if (np) {
-   sharp_nt->backlight = of_find_backlight_by_node(np);
-   of_node_put(np);
+   sharp_nt->backlight = devm_of_find_backlight(np);
  
-		if (!sharp_nt->backlight)

-   return -EPROBE_DEFER;
-   }
+   if (IS_ERR(sharp_nt->backlight))
+   return PTR_ERR(sharp_nt->backlight);
  
  	drm_panel_init(_nt->base);

sharp_nt->base.funcs = _nt_panel_funcs;




Re: [PATCH v16 06/10] drm/tinydrm: Call devres version of of_find_backlight

2018-01-16 Thread Noralf Trønnes


Den 16.01.2018 11.34, skrev Meghana Madhyastha:

Call devm_of_find_backlight (the devres version) instead of
of_find_backlight.

Signed-off-by: Meghana Madhyastha <meghana.madhyas...@gmail.com>
---
  drivers/gpu/drm/tinydrm/mi0283qt.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/tinydrm/mi0283qt.c 
b/drivers/gpu/drm/tinydrm/mi0283qt.c
index 3f9065fb5..4d8650bdc 100644
--- a/drivers/gpu/drm/tinydrm/mi0283qt.c
+++ b/drivers/gpu/drm/tinydrm/mi0283qt.c
@@ -191,7 +191,7 @@ static int mi0283qt_probe(struct spi_device *spi)
if (IS_ERR(mipi->regulator))
return PTR_ERR(mipi->regulator);
  
-	mipi->backlight = of_find_backlight(dev);

+   mipi->backlight = devm_of_find_backlight(dev);
if (IS_ERR(mipi->backlight))
return PTR_ERR(mipi->backlight);
  


You've missed st7735r.

With that fixed:
Reviewed-by: Noralf Trønnes <nor...@tronnes.org>



Re: [PATCH v16 06/10] drm/tinydrm: Call devres version of of_find_backlight

2018-01-16 Thread Noralf Trønnes


Den 16.01.2018 11.34, skrev Meghana Madhyastha:

Call devm_of_find_backlight (the devres version) instead of
of_find_backlight.

Signed-off-by: Meghana Madhyastha 
---
  drivers/gpu/drm/tinydrm/mi0283qt.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/tinydrm/mi0283qt.c 
b/drivers/gpu/drm/tinydrm/mi0283qt.c
index 3f9065fb5..4d8650bdc 100644
--- a/drivers/gpu/drm/tinydrm/mi0283qt.c
+++ b/drivers/gpu/drm/tinydrm/mi0283qt.c
@@ -191,7 +191,7 @@ static int mi0283qt_probe(struct spi_device *spi)
if (IS_ERR(mipi->regulator))
return PTR_ERR(mipi->regulator);
  
-	mipi->backlight = of_find_backlight(dev);

+   mipi->backlight = devm_of_find_backlight(dev);
if (IS_ERR(mipi->backlight))
return PTR_ERR(mipi->backlight);
  


You've missed st7735r.

With that fixed:
Reviewed-by: Noralf Trønnes 



Re: [PATCH v16 05/10] video: backlight: Add devres versions of of_find_backlight

2018-01-16 Thread Noralf Trønnes


Den 16.01.2018 11.34, skrev Meghana Madhyastha:

Add devm_of_find_backlight and the corresponding release
function because some drivers use devres versions of functions
for acquiring device resources.

Signed-off-by: Meghana Madhyastha <meghana.madhyas...@gmail.com>


checkpatch complains:
-:26: WARNING: Block comments should align the * on each line
This one is text so might as well fix it:
-:29: WARNING: line over 80 characters

With that fixed:
Reviewed-by: Noralf Trønnes <nor...@tronnes.org>


---
  drivers/video/backlight/backlight.c | 29 +
  include/linux/backlight.h   |  7 +++
  2 files changed, 36 insertions(+)

diff --git a/drivers/video/backlight/backlight.c 
b/drivers/video/backlight/backlight.c
index 7e4a5d77d..b3f76945f 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -620,6 +620,35 @@ struct backlight_device *of_find_backlight(struct device 
*dev)
  }
  EXPORT_SYMBOL(of_find_backlight);
  
+static void devm_backlight_put(void *data)

+{
+   backlight_put(data);
+}
+
+/**
+  * devm_of_find_backlight - Resource-managed of_find_backlight()
+  * @dev: Device
+  *
+  * Device managed version of of_find_backlight(). The reference on the 
backlight
+  * device is automatically dropped on driver detach.
+  */
+struct backlight_device *devm_of_find_backlight(struct device *dev)
+{
+   struct backlight_device *bd;
+   int ret;
+
+   bd = of_find_backlight(dev);
+   if (IS_ERR_OR_NULL(bd))
+   return bd;
+   ret = devm_add_action(dev, devm_backlight_put, bd);
+   if (ret) {
+   backlight_put(bd);
+   return ERR_PTR(ret);
+   }
+   return bd;
+}
+EXPORT_SYMBOL(devm_of_find_backlight);
+
  static void __exit backlight_class_exit(void)
  {
class_destroy(backlight_class);
diff --git a/include/linux/backlight.h b/include/linux/backlight.h
index 32ea510da..1d373f5a6 100644
--- a/include/linux/backlight.h
+++ b/include/linux/backlight.h
@@ -215,11 +215,18 @@ of_find_backlight_by_node(struct device_node *node)
  
  #if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)

  struct backlight_device *of_find_backlight(struct device *dev);
+struct backlight_device *devm_of_find_backlight(struct device *dev);
  #else
  static inline struct backlight_device *of_find_backlight(struct device *dev)
  {
return NULL;
  }
+
+static inline struct backlight_device *
+devm_of_find_backlight(struct device *dev)
+{
+   return NULL;
+}
  #endif
  
  #endif




Re: [PATCH v16 05/10] video: backlight: Add devres versions of of_find_backlight

2018-01-16 Thread Noralf Trønnes


Den 16.01.2018 11.34, skrev Meghana Madhyastha:

Add devm_of_find_backlight and the corresponding release
function because some drivers use devres versions of functions
for acquiring device resources.

Signed-off-by: Meghana Madhyastha 


checkpatch complains:
-:26: WARNING: Block comments should align the * on each line
This one is text so might as well fix it:
-:29: WARNING: line over 80 characters

With that fixed:
Reviewed-by: Noralf Trønnes 


---
  drivers/video/backlight/backlight.c | 29 +
  include/linux/backlight.h   |  7 +++
  2 files changed, 36 insertions(+)

diff --git a/drivers/video/backlight/backlight.c 
b/drivers/video/backlight/backlight.c
index 7e4a5d77d..b3f76945f 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -620,6 +620,35 @@ struct backlight_device *of_find_backlight(struct device 
*dev)
  }
  EXPORT_SYMBOL(of_find_backlight);
  
+static void devm_backlight_put(void *data)

+{
+   backlight_put(data);
+}
+
+/**
+  * devm_of_find_backlight - Resource-managed of_find_backlight()
+  * @dev: Device
+  *
+  * Device managed version of of_find_backlight(). The reference on the 
backlight
+  * device is automatically dropped on driver detach.
+  */
+struct backlight_device *devm_of_find_backlight(struct device *dev)
+{
+   struct backlight_device *bd;
+   int ret;
+
+   bd = of_find_backlight(dev);
+   if (IS_ERR_OR_NULL(bd))
+   return bd;
+   ret = devm_add_action(dev, devm_backlight_put, bd);
+   if (ret) {
+   backlight_put(bd);
+   return ERR_PTR(ret);
+   }
+   return bd;
+}
+EXPORT_SYMBOL(devm_of_find_backlight);
+
  static void __exit backlight_class_exit(void)
  {
class_destroy(backlight_class);
diff --git a/include/linux/backlight.h b/include/linux/backlight.h
index 32ea510da..1d373f5a6 100644
--- a/include/linux/backlight.h
+++ b/include/linux/backlight.h
@@ -215,11 +215,18 @@ of_find_backlight_by_node(struct device_node *node)
  
  #if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)

  struct backlight_device *of_find_backlight(struct device *dev);
+struct backlight_device *devm_of_find_backlight(struct device *dev);
  #else
  static inline struct backlight_device *of_find_backlight(struct device *dev)
  {
return NULL;
  }
+
+static inline struct backlight_device *
+devm_of_find_backlight(struct device *dev)
+{
+   return NULL;
+}
  #endif
  
  #endif




Re: [PATCH v16 04/10] drm/tinydrm: Replace tinydrm_of_find_backlight with of_find_backlight

2018-01-16 Thread Noralf Trønnes


Den 16.01.2018 11.34, skrev Meghana Madhyastha:

Remove tinydrm_of_find_backlight from tinydrm-helpers.c. We now have
a generic of_find_backlight defined in backlight.c. Let the callers
of tinydrm_of_find_backlight call of_find_backlight.

Signed-off-by: Meghana Madhyastha <meghana.madhyas...@gmail.com>


This patch needs rebasing, changes to mi0283qt.
You've missed st7735r.

I'd appreciate if you could also remove these from tinydrm/Kconfig:

    select BACKLIGHT_LCD_SUPPORT
    select BACKLIGHT_CLASS_DEVICE

It's an ugly hack that we don't need anymore thanks to your work!

With that fixed:
Reviewed-by: Noralf Trønnes <nor...@tronnes.org>


---
  drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 40 --
  drivers/gpu/drm/tinydrm/mi0283qt.c |  3 +-
  include/drm/tinydrm/tinydrm-helpers.h  |  2 --
  3 files changed, 2 insertions(+), 43 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c 
b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
index 7326e1758..d1c3ce9ab 100644
--- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
+++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
@@ -236,46 +236,6 @@ void tinydrm_xrgb_to_gray8(u8 *dst, void *vaddr, 
struct drm_framebuffer *fb,
  }
  EXPORT_SYMBOL(tinydrm_xrgb_to_gray8);
  
-/**

- * tinydrm_of_find_backlight - Find backlight device in device-tree
- * @dev: Device
- *
- * This function looks for a DT node pointed to by a property named 'backlight'
- * and uses of_find_backlight_by_node() to get the backlight device.
- * Additionally if the brightness property is zero, it is set to
- * max_brightness.
- *
- * Returns:
- * NULL if there's no backlight property.
- * Error pointer -EPROBE_DEFER if the DT node is found, but no backlight device
- * is found.
- * If the backlight device is found, a pointer to the structure is returned.
- */
-struct backlight_device *tinydrm_of_find_backlight(struct device *dev)
-{
-   struct backlight_device *backlight;
-   struct device_node *np;
-
-   np = of_parse_phandle(dev->of_node, "backlight", 0);
-   if (!np)
-   return NULL;
-
-   backlight = of_find_backlight_by_node(np);
-   of_node_put(np);
-
-   if (!backlight)
-   return ERR_PTR(-EPROBE_DEFER);
-
-   if (!backlight->props.brightness) {
-   backlight->props.brightness = backlight->props.max_brightness;
-   DRM_DEBUG_KMS("Backlight brightness set to %d\n",
- backlight->props.brightness);
-   }
-
-   return backlight;
-}
-EXPORT_SYMBOL(tinydrm_of_find_backlight);
-
  #if IS_ENABLED(CONFIG_SPI)
  
  /**

diff --git a/drivers/gpu/drm/tinydrm/mi0283qt.c 
b/drivers/gpu/drm/tinydrm/mi0283qt.c
index 674d40764..3f9065fb5 100644
--- a/drivers/gpu/drm/tinydrm/mi0283qt.c
+++ b/drivers/gpu/drm/tinydrm/mi0283qt.c
@@ -14,6 +14,7 @@
  #include 
  #include 
  #include 
+#include 
  #include 
  #include 
  #include 
@@ -190,7 +191,7 @@ static int mi0283qt_probe(struct spi_device *spi)
if (IS_ERR(mipi->regulator))
return PTR_ERR(mipi->regulator);
  
-	mipi->backlight = tinydrm_of_find_backlight(dev);

+   mipi->backlight = of_find_backlight(dev);
if (IS_ERR(mipi->backlight))
return PTR_ERR(mipi->backlight);
  
diff --git a/include/drm/tinydrm/tinydrm-helpers.h b/include/drm/tinydrm/tinydrm-helpers.h

index f54fae03e..0a4ddbc04 100644
--- a/include/drm/tinydrm/tinydrm-helpers.h
+++ b/include/drm/tinydrm/tinydrm-helpers.h
@@ -46,8 +46,6 @@ void tinydrm_xrgb_to_rgb565(u16 *dst, void *vaddr,
  void tinydrm_xrgb_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer 
*fb,
   struct drm_clip_rect *clip);
  
-struct backlight_device *tinydrm_of_find_backlight(struct device *dev);

-
  size_t tinydrm_spi_max_transfer_size(struct spi_device *spi, size_t max_len);
  bool tinydrm_spi_bpw_supported(struct spi_device *spi, u8 bpw);
  int tinydrm_spi_transfer(struct spi_device *spi, u32 speed_hz,




Re: [PATCH v16 04/10] drm/tinydrm: Replace tinydrm_of_find_backlight with of_find_backlight

2018-01-16 Thread Noralf Trønnes


Den 16.01.2018 11.34, skrev Meghana Madhyastha:

Remove tinydrm_of_find_backlight from tinydrm-helpers.c. We now have
a generic of_find_backlight defined in backlight.c. Let the callers
of tinydrm_of_find_backlight call of_find_backlight.

Signed-off-by: Meghana Madhyastha 


This patch needs rebasing, changes to mi0283qt.
You've missed st7735r.

I'd appreciate if you could also remove these from tinydrm/Kconfig:

    select BACKLIGHT_LCD_SUPPORT
    select BACKLIGHT_CLASS_DEVICE

It's an ugly hack that we don't need anymore thanks to your work!

With that fixed:
Reviewed-by: Noralf Trønnes 


---
  drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 40 --
  drivers/gpu/drm/tinydrm/mi0283qt.c |  3 +-
  include/drm/tinydrm/tinydrm-helpers.h  |  2 --
  3 files changed, 2 insertions(+), 43 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c 
b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
index 7326e1758..d1c3ce9ab 100644
--- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
+++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
@@ -236,46 +236,6 @@ void tinydrm_xrgb_to_gray8(u8 *dst, void *vaddr, 
struct drm_framebuffer *fb,
  }
  EXPORT_SYMBOL(tinydrm_xrgb_to_gray8);
  
-/**

- * tinydrm_of_find_backlight - Find backlight device in device-tree
- * @dev: Device
- *
- * This function looks for a DT node pointed to by a property named 'backlight'
- * and uses of_find_backlight_by_node() to get the backlight device.
- * Additionally if the brightness property is zero, it is set to
- * max_brightness.
- *
- * Returns:
- * NULL if there's no backlight property.
- * Error pointer -EPROBE_DEFER if the DT node is found, but no backlight device
- * is found.
- * If the backlight device is found, a pointer to the structure is returned.
- */
-struct backlight_device *tinydrm_of_find_backlight(struct device *dev)
-{
-   struct backlight_device *backlight;
-   struct device_node *np;
-
-   np = of_parse_phandle(dev->of_node, "backlight", 0);
-   if (!np)
-   return NULL;
-
-   backlight = of_find_backlight_by_node(np);
-   of_node_put(np);
-
-   if (!backlight)
-   return ERR_PTR(-EPROBE_DEFER);
-
-   if (!backlight->props.brightness) {
-   backlight->props.brightness = backlight->props.max_brightness;
-   DRM_DEBUG_KMS("Backlight brightness set to %d\n",
- backlight->props.brightness);
-   }
-
-   return backlight;
-}
-EXPORT_SYMBOL(tinydrm_of_find_backlight);
-
  #if IS_ENABLED(CONFIG_SPI)
  
  /**

diff --git a/drivers/gpu/drm/tinydrm/mi0283qt.c 
b/drivers/gpu/drm/tinydrm/mi0283qt.c
index 674d40764..3f9065fb5 100644
--- a/drivers/gpu/drm/tinydrm/mi0283qt.c
+++ b/drivers/gpu/drm/tinydrm/mi0283qt.c
@@ -14,6 +14,7 @@
  #include 
  #include 
  #include 
+#include 
  #include 
  #include 
  #include 
@@ -190,7 +191,7 @@ static int mi0283qt_probe(struct spi_device *spi)
if (IS_ERR(mipi->regulator))
return PTR_ERR(mipi->regulator);
  
-	mipi->backlight = tinydrm_of_find_backlight(dev);

+   mipi->backlight = of_find_backlight(dev);
if (IS_ERR(mipi->backlight))
return PTR_ERR(mipi->backlight);
  
diff --git a/include/drm/tinydrm/tinydrm-helpers.h b/include/drm/tinydrm/tinydrm-helpers.h

index f54fae03e..0a4ddbc04 100644
--- a/include/drm/tinydrm/tinydrm-helpers.h
+++ b/include/drm/tinydrm/tinydrm-helpers.h
@@ -46,8 +46,6 @@ void tinydrm_xrgb_to_rgb565(u16 *dst, void *vaddr,
  void tinydrm_xrgb_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer 
*fb,
   struct drm_clip_rect *clip);
  
-struct backlight_device *tinydrm_of_find_backlight(struct device *dev);

-
  size_t tinydrm_spi_max_transfer_size(struct spi_device *spi, size_t max_len);
  bool tinydrm_spi_bpw_supported(struct spi_device *spi, u8 bpw);
  int tinydrm_spi_transfer(struct spi_device *spi, u32 speed_hz,




Re: [PATCH v16 03/10] video: backlight: Add of_find_backlight helper in backlight.c

2018-01-16 Thread Noralf Trønnes


Den 16.01.2018 11.33, skrev Meghana Madhyastha:

Add of_find_backlight, a helper function which is a generic version
of tinydrm_of_find_backlight that can be used by other drivers to avoid
repetition of code and simplify things.

Signed-off-by: Meghana Madhyastha 
---
Changes in v16:
-Add comment about brightness in of_find_backlight

  drivers/video/backlight/backlight.c | 40 +
  include/linux/backlight.h   | 19 ++
  2 files changed, 59 insertions(+)

diff --git a/drivers/video/backlight/backlight.c 
b/drivers/video/backlight/backlight.c
index 8049e7656..7e4a5d77d 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -580,6 +580,46 @@ struct backlight_device *of_find_backlight_by_node(struct 
device_node *node)
  EXPORT_SYMBOL(of_find_backlight_by_node);
  #endif
  
+/**

+  * of_find_backlight - Get backlight device
+  * @dev: Device
+  *
+  * This function looks for a property named 'backlight' on the DT node
+  * connected to @dev and looks up the backlight device.
+  *
+  * Call backlight_put() to drop the reference on the backlight device.
+  * gpio_backlight uses brightness as power state during probe.


I was thinking the gpio_backlight issue to be a comment with the code, 
not the docs.

Isn't this sentence a bit confusing as part of the docs?

checkpatch complains:
-:21: WARNING: Block comments should align the * on each line
-:72: WARNING: Block comments should align the * on each line

Noralf.


+  *
+  * Returns:
+  * A pointer to the backlight device if found.
+  * Error pointer -EPROBE_DEFER if the DT property is set, but no backlight
+  * device is found.
+  * NULL if there's no backlight property.
+  */
+struct backlight_device *of_find_backlight(struct device *dev)
+{
+   struct backlight_device *bd = NULL;
+   struct device_node *np;
+
+   if (!dev)
+   return NULL;
+
+   if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
+   np = of_parse_phandle(dev->of_node, "backlight", 0);
+   if (np) {
+   bd = of_find_backlight_by_node(np);
+   of_node_put(np);
+   if (!bd)
+   return ERR_PTR(-EPROBE_DEFER);
+   if (!bd->props.brightness)
+   bd->props.brightness = bd->props.max_brightness;
+   }
+   }
+
+   return bd;
+}
+EXPORT_SYMBOL(of_find_backlight);
+
  static void __exit backlight_class_exit(void)
  {
class_destroy(backlight_class);
diff --git a/include/linux/backlight.h b/include/linux/backlight.h
index 7b6a9a2a3..32ea510da 100644
--- a/include/linux/backlight.h
+++ b/include/linux/backlight.h
@@ -160,6 +160,16 @@ static inline int backlight_disable(struct 
backlight_device *bd)
return backlight_update_status(bd);
  }
  
+/**

+  * backlight_put - Drop backlight reference
+  * @bd: the backlight device to put
+  */
+static inline void backlight_put(struct backlight_device *bd)
+{
+   if (bd)
+   put_device(>dev);
+}
+
  extern struct backlight_device *backlight_device_register(const char *name,
struct device *dev, void *devdata, const struct backlight_ops *ops,
const struct backlight_properties *props);
@@ -203,4 +213,13 @@ of_find_backlight_by_node(struct device_node *node)
  }
  #endif
  
+#if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)

+struct backlight_device *of_find_backlight(struct device *dev);
+#else
+static inline struct backlight_device *of_find_backlight(struct device *dev)
+{
+   return NULL;
+}
+#endif
+
  #endif




Re: [PATCH v16 03/10] video: backlight: Add of_find_backlight helper in backlight.c

2018-01-16 Thread Noralf Trønnes


Den 16.01.2018 11.33, skrev Meghana Madhyastha:

Add of_find_backlight, a helper function which is a generic version
of tinydrm_of_find_backlight that can be used by other drivers to avoid
repetition of code and simplify things.

Signed-off-by: Meghana Madhyastha 
---
Changes in v16:
-Add comment about brightness in of_find_backlight

  drivers/video/backlight/backlight.c | 40 +
  include/linux/backlight.h   | 19 ++
  2 files changed, 59 insertions(+)

diff --git a/drivers/video/backlight/backlight.c 
b/drivers/video/backlight/backlight.c
index 8049e7656..7e4a5d77d 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -580,6 +580,46 @@ struct backlight_device *of_find_backlight_by_node(struct 
device_node *node)
  EXPORT_SYMBOL(of_find_backlight_by_node);
  #endif
  
+/**

+  * of_find_backlight - Get backlight device
+  * @dev: Device
+  *
+  * This function looks for a property named 'backlight' on the DT node
+  * connected to @dev and looks up the backlight device.
+  *
+  * Call backlight_put() to drop the reference on the backlight device.
+  * gpio_backlight uses brightness as power state during probe.


I was thinking the gpio_backlight issue to be a comment with the code, 
not the docs.

Isn't this sentence a bit confusing as part of the docs?

checkpatch complains:
-:21: WARNING: Block comments should align the * on each line
-:72: WARNING: Block comments should align the * on each line

Noralf.


+  *
+  * Returns:
+  * A pointer to the backlight device if found.
+  * Error pointer -EPROBE_DEFER if the DT property is set, but no backlight
+  * device is found.
+  * NULL if there's no backlight property.
+  */
+struct backlight_device *of_find_backlight(struct device *dev)
+{
+   struct backlight_device *bd = NULL;
+   struct device_node *np;
+
+   if (!dev)
+   return NULL;
+
+   if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
+   np = of_parse_phandle(dev->of_node, "backlight", 0);
+   if (np) {
+   bd = of_find_backlight_by_node(np);
+   of_node_put(np);
+   if (!bd)
+   return ERR_PTR(-EPROBE_DEFER);
+   if (!bd->props.brightness)
+   bd->props.brightness = bd->props.max_brightness;
+   }
+   }
+
+   return bd;
+}
+EXPORT_SYMBOL(of_find_backlight);
+
  static void __exit backlight_class_exit(void)
  {
class_destroy(backlight_class);
diff --git a/include/linux/backlight.h b/include/linux/backlight.h
index 7b6a9a2a3..32ea510da 100644
--- a/include/linux/backlight.h
+++ b/include/linux/backlight.h
@@ -160,6 +160,16 @@ static inline int backlight_disable(struct 
backlight_device *bd)
return backlight_update_status(bd);
  }
  
+/**

+  * backlight_put - Drop backlight reference
+  * @bd: the backlight device to put
+  */
+static inline void backlight_put(struct backlight_device *bd)
+{
+   if (bd)
+   put_device(>dev);
+}
+
  extern struct backlight_device *backlight_device_register(const char *name,
struct device *dev, void *devdata, const struct backlight_ops *ops,
const struct backlight_properties *props);
@@ -203,4 +213,13 @@ of_find_backlight_by_node(struct device_node *node)
  }
  #endif
  
+#if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)

+struct backlight_device *of_find_backlight(struct device *dev);
+#else
+static inline struct backlight_device *of_find_backlight(struct device *dev)
+{
+   return NULL;
+}
+#endif
+
  #endif




Re: [PATCH v16 02/10] drm/tinydrm: Convert tinydrm_enable/disable_backlight to backlight_enable/disable

2018-01-16 Thread Noralf Trønnes


Den 16.01.2018 11.32, skrev Meghana Madhyastha:

Remove tinydrm_enable/disable_backlight and let the callers call the
more generic backlight_enable/disable helpers

Signed-off-by: Meghana Madhyastha <meghana.madhyas...@gmail.com>


This patch needs to be rebased on some recent changes to mipi-dbi.

Reviewed-by: Noralf Trønnes <nor...@tronnes.org>


---
  drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 55 --
  drivers/gpu/drm/tinydrm/mipi-dbi.c |  4 +-
  include/drm/tinydrm/tinydrm-helpers.h  |  2 -
  3 files changed, 2 insertions(+), 59 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c 
b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
index bf96072d1..7326e1758 100644
--- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
+++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
@@ -276,61 +276,6 @@ struct backlight_device *tinydrm_of_find_backlight(struct 
device *dev)
  }
  EXPORT_SYMBOL(tinydrm_of_find_backlight);
  
-/**

- * tinydrm_enable_backlight - Enable backlight helper
- * @backlight: Backlight device
- *
- * Returns:
- * Zero on success, negative error code on failure.
- */
-int tinydrm_enable_backlight(struct backlight_device *backlight)
-{
-   unsigned int old_state;
-   int ret;
-
-   if (!backlight)
-   return 0;
-
-   old_state = backlight->props.state;
-   backlight->props.state &= ~BL_CORE_FBBLANK;
-   DRM_DEBUG_KMS("Backlight state: 0x%x -> 0x%x\n", old_state,
- backlight->props.state);
-
-   ret = backlight_update_status(backlight);
-   if (ret)
-   DRM_ERROR("Failed to enable backlight %d\n", ret);
-
-   return ret;
-}
-EXPORT_SYMBOL(tinydrm_enable_backlight);
-
-/**
- * tinydrm_disable_backlight - Disable backlight helper
- * @backlight: Backlight device
- *
- * Returns:
- * Zero on success, negative error code on failure.
- */
-int tinydrm_disable_backlight(struct backlight_device *backlight)
-{
-   unsigned int old_state;
-   int ret;
-
-   if (!backlight)
-   return 0;
-
-   old_state = backlight->props.state;
-   backlight->props.state |= BL_CORE_FBBLANK;
-   DRM_DEBUG_KMS("Backlight state: 0x%x -> 0x%x\n", old_state,
- backlight->props.state);
-   ret = backlight_update_status(backlight);
-   if (ret)
-   DRM_ERROR("Failed to disable backlight %d\n", ret);
-
-   return ret;
-}
-EXPORT_SYMBOL(tinydrm_disable_backlight);
-
  #if IS_ENABLED(CONFIG_SPI)
  
  /**

diff --git a/drivers/gpu/drm/tinydrm/mipi-dbi.c 
b/drivers/gpu/drm/tinydrm/mipi-dbi.c
index aa6b6ce56..8c2cb1cf2 100644
--- a/drivers/gpu/drm/tinydrm/mipi-dbi.c
+++ b/drivers/gpu/drm/tinydrm/mipi-dbi.c
@@ -291,7 +291,7 @@ void mipi_dbi_pipe_enable(struct drm_simple_display_pipe 
*pipe,
if (fb)
fb->funcs->dirty(fb, NULL, 0, 0, NULL, 0);
  
-	tinydrm_enable_backlight(mipi->backlight);

+   backlight_enable(mipi->backlight);
  }
  EXPORT_SYMBOL(mipi_dbi_pipe_enable);
  
@@ -330,7 +330,7 @@ void mipi_dbi_pipe_disable(struct drm_simple_display_pipe *pipe)

mipi->enabled = false;
  
  	if (mipi->backlight)

-   tinydrm_disable_backlight(mipi->backlight);
+   backlight_disable(mipi->backlight);
else
mipi_dbi_blank(mipi);
  }
diff --git a/include/drm/tinydrm/tinydrm-helpers.h 
b/include/drm/tinydrm/tinydrm-helpers.h
index d554ded60..f54fae03e 100644
--- a/include/drm/tinydrm/tinydrm-helpers.h
+++ b/include/drm/tinydrm/tinydrm-helpers.h
@@ -47,8 +47,6 @@ void tinydrm_xrgb_to_gray8(u8 *dst, void *vaddr, struct 
drm_framebuffer *fb,
   struct drm_clip_rect *clip);
  
  struct backlight_device *tinydrm_of_find_backlight(struct device *dev);

-int tinydrm_enable_backlight(struct backlight_device *backlight);
-int tinydrm_disable_backlight(struct backlight_device *backlight);
  
  size_t tinydrm_spi_max_transfer_size(struct spi_device *spi, size_t max_len);

  bool tinydrm_spi_bpw_supported(struct spi_device *spi, u8 bpw);




Re: [PATCH v16 02/10] drm/tinydrm: Convert tinydrm_enable/disable_backlight to backlight_enable/disable

2018-01-16 Thread Noralf Trønnes


Den 16.01.2018 11.32, skrev Meghana Madhyastha:

Remove tinydrm_enable/disable_backlight and let the callers call the
more generic backlight_enable/disable helpers

Signed-off-by: Meghana Madhyastha 


This patch needs to be rebased on some recent changes to mipi-dbi.

Reviewed-by: Noralf Trønnes 


---
  drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 55 --
  drivers/gpu/drm/tinydrm/mipi-dbi.c |  4 +-
  include/drm/tinydrm/tinydrm-helpers.h  |  2 -
  3 files changed, 2 insertions(+), 59 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c 
b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
index bf96072d1..7326e1758 100644
--- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
+++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
@@ -276,61 +276,6 @@ struct backlight_device *tinydrm_of_find_backlight(struct 
device *dev)
  }
  EXPORT_SYMBOL(tinydrm_of_find_backlight);
  
-/**

- * tinydrm_enable_backlight - Enable backlight helper
- * @backlight: Backlight device
- *
- * Returns:
- * Zero on success, negative error code on failure.
- */
-int tinydrm_enable_backlight(struct backlight_device *backlight)
-{
-   unsigned int old_state;
-   int ret;
-
-   if (!backlight)
-   return 0;
-
-   old_state = backlight->props.state;
-   backlight->props.state &= ~BL_CORE_FBBLANK;
-   DRM_DEBUG_KMS("Backlight state: 0x%x -> 0x%x\n", old_state,
- backlight->props.state);
-
-   ret = backlight_update_status(backlight);
-   if (ret)
-   DRM_ERROR("Failed to enable backlight %d\n", ret);
-
-   return ret;
-}
-EXPORT_SYMBOL(tinydrm_enable_backlight);
-
-/**
- * tinydrm_disable_backlight - Disable backlight helper
- * @backlight: Backlight device
- *
- * Returns:
- * Zero on success, negative error code on failure.
- */
-int tinydrm_disable_backlight(struct backlight_device *backlight)
-{
-   unsigned int old_state;
-   int ret;
-
-   if (!backlight)
-   return 0;
-
-   old_state = backlight->props.state;
-   backlight->props.state |= BL_CORE_FBBLANK;
-   DRM_DEBUG_KMS("Backlight state: 0x%x -> 0x%x\n", old_state,
- backlight->props.state);
-   ret = backlight_update_status(backlight);
-   if (ret)
-   DRM_ERROR("Failed to disable backlight %d\n", ret);
-
-   return ret;
-}
-EXPORT_SYMBOL(tinydrm_disable_backlight);
-
  #if IS_ENABLED(CONFIG_SPI)
  
  /**

diff --git a/drivers/gpu/drm/tinydrm/mipi-dbi.c 
b/drivers/gpu/drm/tinydrm/mipi-dbi.c
index aa6b6ce56..8c2cb1cf2 100644
--- a/drivers/gpu/drm/tinydrm/mipi-dbi.c
+++ b/drivers/gpu/drm/tinydrm/mipi-dbi.c
@@ -291,7 +291,7 @@ void mipi_dbi_pipe_enable(struct drm_simple_display_pipe 
*pipe,
if (fb)
fb->funcs->dirty(fb, NULL, 0, 0, NULL, 0);
  
-	tinydrm_enable_backlight(mipi->backlight);

+   backlight_enable(mipi->backlight);
  }
  EXPORT_SYMBOL(mipi_dbi_pipe_enable);
  
@@ -330,7 +330,7 @@ void mipi_dbi_pipe_disable(struct drm_simple_display_pipe *pipe)

mipi->enabled = false;
  
  	if (mipi->backlight)

-   tinydrm_disable_backlight(mipi->backlight);
+   backlight_disable(mipi->backlight);
else
mipi_dbi_blank(mipi);
  }
diff --git a/include/drm/tinydrm/tinydrm-helpers.h 
b/include/drm/tinydrm/tinydrm-helpers.h
index d554ded60..f54fae03e 100644
--- a/include/drm/tinydrm/tinydrm-helpers.h
+++ b/include/drm/tinydrm/tinydrm-helpers.h
@@ -47,8 +47,6 @@ void tinydrm_xrgb_to_gray8(u8 *dst, void *vaddr, struct 
drm_framebuffer *fb,
   struct drm_clip_rect *clip);
  
  struct backlight_device *tinydrm_of_find_backlight(struct device *dev);

-int tinydrm_enable_backlight(struct backlight_device *backlight);
-int tinydrm_disable_backlight(struct backlight_device *backlight);
  
  size_t tinydrm_spi_max_transfer_size(struct spi_device *spi, size_t max_len);

  bool tinydrm_spi_bpw_supported(struct spi_device *spi, u8 bpw);




Re: [PATCH v16 01/10] video: backlight: Add helpers to enable and disable backlight

2018-01-16 Thread Noralf Trønnes


Den 16.01.2018 11.31, skrev Meghana Madhyastha:

Add helper functions backlight_enable and backlight_disable to
enable/disable a backlight device. These helper functions can
then be used by different drm and tinydrm drivers to avoid
repetition of code and also to enforce a uniform and consistent
way to enable/disable a backlight device.

Signed-off-by: Meghana Madhyastha <meghana.madhyas...@gmail.com>


checkpatch complains:
-:23: WARNING: Block comments should align the * on each line
-:45: ERROR: trailing whitespace

With that fixed:
Reviewed-by: Noralf Trønnes <nor...@tronnes.org>


---
  include/linux/backlight.h | 30 ++
  1 file changed, 30 insertions(+)

diff --git a/include/linux/backlight.h b/include/linux/backlight.h
index af7003548..7b6a9a2a3 100644
--- a/include/linux/backlight.h
+++ b/include/linux/backlight.h
@@ -130,6 +130,36 @@ static inline int backlight_update_status(struct 
backlight_device *bd)
return ret;
  }
  
+/**

+  * backlight_enable - Enable backlight
+  * @bd: the backlight device to enable
+  */
+static inline int backlight_enable(struct backlight_device *bd)
+{
+   if (!bd)
+   return 0;
+
+   bd->props.power = FB_BLANK_UNBLANK;
+   bd->props.state &= ~BL_CORE_FBBLANK;
+
+   return backlight_update_status(bd);
+}
+
+/**
+  * backlight_disable - Disable backlight
+  * @bd: the backlight device to disable
+  */
+static inline int backlight_disable(struct backlight_device *bd)
+{
+   if (!bd)
+   return 0;
+   
+   bd->props.power = FB_BLANK_POWERDOWN;
+   bd->props.state |= BL_CORE_FBBLANK;
+
+   return backlight_update_status(bd);
+}
+
  extern struct backlight_device *backlight_device_register(const char *name,
struct device *dev, void *devdata, const struct backlight_ops *ops,
const struct backlight_properties *props);




Re: [PATCH v16 01/10] video: backlight: Add helpers to enable and disable backlight

2018-01-16 Thread Noralf Trønnes


Den 16.01.2018 11.31, skrev Meghana Madhyastha:

Add helper functions backlight_enable and backlight_disable to
enable/disable a backlight device. These helper functions can
then be used by different drm and tinydrm drivers to avoid
repetition of code and also to enforce a uniform and consistent
way to enable/disable a backlight device.

Signed-off-by: Meghana Madhyastha 


checkpatch complains:
-:23: WARNING: Block comments should align the * on each line
-:45: ERROR: trailing whitespace

With that fixed:
Reviewed-by: Noralf Trønnes 


---
  include/linux/backlight.h | 30 ++
  1 file changed, 30 insertions(+)

diff --git a/include/linux/backlight.h b/include/linux/backlight.h
index af7003548..7b6a9a2a3 100644
--- a/include/linux/backlight.h
+++ b/include/linux/backlight.h
@@ -130,6 +130,36 @@ static inline int backlight_update_status(struct 
backlight_device *bd)
return ret;
  }
  
+/**

+  * backlight_enable - Enable backlight
+  * @bd: the backlight device to enable
+  */
+static inline int backlight_enable(struct backlight_device *bd)
+{
+   if (!bd)
+   return 0;
+
+   bd->props.power = FB_BLANK_UNBLANK;
+   bd->props.state &= ~BL_CORE_FBBLANK;
+
+   return backlight_update_status(bd);
+}
+
+/**
+  * backlight_disable - Disable backlight
+  * @bd: the backlight device to disable
+  */
+static inline int backlight_disable(struct backlight_device *bd)
+{
+   if (!bd)
+   return 0;
+   
+   bd->props.power = FB_BLANK_POWERDOWN;
+   bd->props.state |= BL_CORE_FBBLANK;
+
+   return backlight_update_status(bd);
+}
+
  extern struct backlight_device *backlight_device_register(const char *name,
struct device *dev, void *devdata, const struct backlight_ops *ops,
const struct backlight_properties *props);




Re: [PATCH v4 3/3] drm/tinydrm: add driver for ST7735R panels

2018-01-03 Thread Noralf Trønnes


Den 02.01.2018 10.42, skrev Linus Walleij:

On Mon, Jan 1, 2018 at 8:02 PM, David Lechner <da...@lechnology.com> wrote:


This adds a new driver for Sitronix ST7735R display panels.

This has been tested using an Adafruit 1.8" TFT.

Signed-off-by: David Lechner <da...@lechnology.com>
Reviewed-by: Noralf Trønnes <nor...@tronnes.org>

Reviewed-by: Linus Walleij <linus.wall...@linaro.org>


Thanks, series applied to drm-misc.

Noralf.



Re: [PATCH v4 3/3] drm/tinydrm: add driver for ST7735R panels

2018-01-03 Thread Noralf Trønnes


Den 02.01.2018 10.42, skrev Linus Walleij:

On Mon, Jan 1, 2018 at 8:02 PM, David Lechner  wrote:


This adds a new driver for Sitronix ST7735R display panels.

This has been tested using an Adafruit 1.8" TFT.

Signed-off-by: David Lechner 
Reviewed-by: Noralf Trønnes 

Reviewed-by: Linus Walleij 


Thanks, series applied to drm-misc.

Noralf.



Re: [PATCH 0/3] update compatible string for ILI9225

2018-01-03 Thread Noralf Trønnes


Den 21.12.2017 19.33, skrev David Lechner:

This updates the device tree compatible string for an ILI9225 display.
Detailed explanation is in the patches.

David Lechner (3):
   dt-bindings: Add "vot" vendor prefix
   dt-bindings: update compatible string for ILI9225
   drm/tinydrm: Update ILI9225 compatible string


Series applied to drm-misc.

Noralf.


  Documentation/devicetree/bindings/display/ilitek,ili9225.txt | 4 ++--
  Documentation/devicetree/bindings/vendor-prefixes.txt| 1 +
  drivers/gpu/drm/tinydrm/ili9225.c| 4 ++--
  3 files changed, 5 insertions(+), 4 deletions(-)





Re: [PATCH 0/3] update compatible string for ILI9225

2018-01-03 Thread Noralf Trønnes


Den 21.12.2017 19.33, skrev David Lechner:

This updates the device tree compatible string for an ILI9225 display.
Detailed explanation is in the patches.

David Lechner (3):
   dt-bindings: Add "vot" vendor prefix
   dt-bindings: update compatible string for ILI9225
   drm/tinydrm: Update ILI9225 compatible string


Series applied to drm-misc.

Noralf.


  Documentation/devicetree/bindings/display/ilitek,ili9225.txt | 4 ++--
  Documentation/devicetree/bindings/vendor-prefixes.txt| 1 +
  drivers/gpu/drm/tinydrm/ili9225.c| 4 ++--
  3 files changed, 5 insertions(+), 4 deletions(-)





Re: [PATCH v3 3/3] drm/tinydrm: add driver for ST7735R panels

2017-12-31 Thread Noralf Trønnes


Den 21.12.2017 20.35, skrev David Lechner:

On 12/21/2017 01:23 PM, David Lechner wrote:

This adds a new driver for Sitronix ST7735R display panels.

This has been tested using an Adafruit 1.8" TFT.

Signed-off-by: David Lechner 
---




+    mipi_dbi_command(mipi, ST7735R_GAMCTRP1, 0x0f, 0x1a, 0x0f, 0x18, 
0x2f,

+ 0x28, 0x20, 0x22, 0x1f, 0x1b, 0x23, 0x37, 0x00, 0x07,
+ 0x02, 0x10);
+    mipi_dbi_command(mipi, ST7735R_GAMCTRN1, 0x0f, 0x1b, 0x0f, 0x17, 
0x33,

+ 0x2c, 0x29, 0x2e, 0x30, 0x30, 0x39, 0x3f, 0x00, 0x07,
+ 0x03, 0x10);
By the way, how do you know what is the "right" gamma curve? I think I 
copied this from the generic st7735r driver in fbtft, but I noticed 
that there is also a different curve for the Adafruit 1.8" display in 
fbtft. I'm wondering if I should have used that one instead. I can't 
really tell a difference looking at the display.


From what I can tell this is the curve used by the Arduino library:

https://github.com/adafruit/Adafruit-ST7735-Library/blob/master/Adafruit_ST7735.cpp

static const uint8_t PROGMEM
  Rcmd3[] = { // Init for 7735R, part 3 (red or green tab)
    4,    //  4 commands in list:
    ST7735_GMCTRP1, 16  , //  1: Magical unicorn dust, 16 args, no 
delay:

  0x02, 0x1c, 0x07, 0x12,
  0x37, 0x32, 0x29, 0x2d,
  0x29, 0x25, 0x2B, 0x39,
  0x00, 0x01, 0x03, 0x10,
    ST7735_GMCTRN1, 16  , //  2: Sparkles and rainbows, 16 args, no 
delay:

  0x03, 0x1d, 0x07, 0x06,
  0x2E, 0x2C, 0x29, 0x2D,
  0x2E, 0x2E, 0x37, 0x3F,
  0x00, 0x00, 0x02, 0x10,

void Adafruit_ST7735::initR(uint8_t options) {
  commonInit(Rcmd1);
...
  commandList(Rcmd3);


Noralf.



Re: [PATCH v3 3/3] drm/tinydrm: add driver for ST7735R panels

2017-12-31 Thread Noralf Trønnes


Den 21.12.2017 20.35, skrev David Lechner:

On 12/21/2017 01:23 PM, David Lechner wrote:

This adds a new driver for Sitronix ST7735R display panels.

This has been tested using an Adafruit 1.8" TFT.

Signed-off-by: David Lechner 
---




+    mipi_dbi_command(mipi, ST7735R_GAMCTRP1, 0x0f, 0x1a, 0x0f, 0x18, 
0x2f,

+ 0x28, 0x20, 0x22, 0x1f, 0x1b, 0x23, 0x37, 0x00, 0x07,
+ 0x02, 0x10);
+    mipi_dbi_command(mipi, ST7735R_GAMCTRN1, 0x0f, 0x1b, 0x0f, 0x17, 
0x33,

+ 0x2c, 0x29, 0x2e, 0x30, 0x30, 0x39, 0x3f, 0x00, 0x07,
+ 0x03, 0x10);
By the way, how do you know what is the "right" gamma curve? I think I 
copied this from the generic st7735r driver in fbtft, but I noticed 
that there is also a different curve for the Adafruit 1.8" display in 
fbtft. I'm wondering if I should have used that one instead. I can't 
really tell a difference looking at the display.


From what I can tell this is the curve used by the Arduino library:

https://github.com/adafruit/Adafruit-ST7735-Library/blob/master/Adafruit_ST7735.cpp

static const uint8_t PROGMEM
  Rcmd3[] = { // Init for 7735R, part 3 (red or green tab)
    4,    //  4 commands in list:
    ST7735_GMCTRP1, 16  , //  1: Magical unicorn dust, 16 args, no 
delay:

  0x02, 0x1c, 0x07, 0x12,
  0x37, 0x32, 0x29, 0x2d,
  0x29, 0x25, 0x2B, 0x39,
  0x00, 0x01, 0x03, 0x10,
    ST7735_GMCTRN1, 16  , //  2: Sparkles and rainbows, 16 args, no 
delay:

  0x03, 0x1d, 0x07, 0x06,
  0x2E, 0x2C, 0x29, 0x2D,
  0x2E, 0x2E, 0x37, 0x3F,
  0x00, 0x00, 0x02, 0x10,

void Adafruit_ST7735::initR(uint8_t options) {
  commonInit(Rcmd1);
...
  commandList(Rcmd3);


Noralf.



Re: [PATCH v3 3/3] drm/tinydrm: add driver for ST7735R panels

2017-12-31 Thread Noralf Trønnes


Den 21.12.2017 20.23, skrev David Lechner:

This adds a new driver for Sitronix ST7735R display panels.

This has been tested using an Adafruit 1.8" TFT.

Signed-off-by: David Lechner <da...@lechnology.com>
---

v3 changes:
* Changed compatible string
* use SPDX license header
* Renamed mode struct to use panel name instead of controller name

v2 changes:
* Change delay from 10ms to 20ms to avoid checkpatch warning
* Use mipi_dbi_pipe_enable()/mipi_dbi_pipe_disable() to reduce duplicated code
* Rebase on drm-misc-next (tinydrm_lastclose => drm_fb_helper_lastclose)
* Use mipi_dbi_debugfs_init
* Add mipi->read_commands = NULL; since this display is write-only



diff --git a/drivers/gpu/drm/tinydrm/st7735r.c 
b/drivers/gpu/drm/tinydrm/st7735r.c
new file mode 100644
index 000..0b05b2c
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/st7735r.c
@@ -0,0 +1,215 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * DRM driver for Sitronix ST7735R panels
+ *
+ * Copyright 2017 David Lechner <da...@lechnology.com>
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#define ST7735R_FRMCTR10xb1
+#define ST7735R_FRMCTR20xb2
+#define ST7735R_FRMCTR30xb3
+#define ST7735R_INVCTR 0xb4
+#define ST7735R_PWCTR1 0xc0
+#define ST7735R_PWCTR2 0xc1
+#define ST7735R_PWCTR3 0xc2
+#define ST7735R_PWCTR4 0xc3
+#define ST7735R_PWCTR5 0xc4
+#define ST7735R_VMCTR1 0xc5
+#define ST7735R_GAMCTRP1   0xe0
+#define ST7735R_GAMCTRN1   0xe1
+
+#define ST7735R_MY BIT(7)
+#define ST7735R_MX BIT(6)
+#define ST7735R_MV BIT(5)
+
+static void st7735r_pipe_enable(struct drm_simple_display_pipe *pipe,
+   struct drm_crtc_state *crtc_state)


This is confusing, you name the mode after the panel, but not the enable
function which has an initialization sequence that is also panel specific.

With .enable function named after the panel (and *_pipe_funcs):

Reviewed-by: Noralf Trønnes <nor...@tronnes.org>


+{
+   struct tinydrm_device *tdev = pipe_to_tinydrm(pipe);
+   struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev);
+   struct device *dev = tdev->drm->dev;
+   int ret;
+   u8 addr_mode;
+
+   DRM_DEBUG_KMS("\n");
+
+   mipi_dbi_hw_reset(mipi);
+
+   ret = mipi_dbi_command(mipi, MIPI_DCS_SOFT_RESET);
+   if (ret) {
+   DRM_DEV_ERROR(dev, "Error sending command %d\n", ret);
+   return;
+   }
+
+   msleep(150);
+
+   mipi_dbi_command(mipi, MIPI_DCS_EXIT_SLEEP_MODE);
+   msleep(500);
+
+   mipi_dbi_command(mipi, ST7735R_FRMCTR1, 0x01, 0x2c, 0x2d);
+   mipi_dbi_command(mipi, ST7735R_FRMCTR2, 0x01, 0x2c, 0x2d);
+   mipi_dbi_command(mipi, ST7735R_FRMCTR3, 0x01, 0x2c, 0x2d, 0x01, 0x2c,
+0x2d);
+   mipi_dbi_command(mipi, ST7735R_INVCTR, 0x07);
+   mipi_dbi_command(mipi, ST7735R_PWCTR1, 0xa2, 0x02, 0x84);
+   mipi_dbi_command(mipi, ST7735R_PWCTR2, 0xc5);
+   mipi_dbi_command(mipi, ST7735R_PWCTR3, 0x0a, 0x00);
+   mipi_dbi_command(mipi, ST7735R_PWCTR4, 0x8a, 0x2a);
+   mipi_dbi_command(mipi, ST7735R_PWCTR5, 0x8a, 0xee);
+   mipi_dbi_command(mipi, ST7735R_VMCTR1, 0x0e);
+   mipi_dbi_command(mipi, MIPI_DCS_EXIT_INVERT_MODE);
+   switch (mipi->rotation) {
+   default:
+   addr_mode = ST7735R_MX | ST7735R_MY;
+   break;
+   case 90:
+   addr_mode = ST7735R_MX | ST7735R_MV;
+   break;
+   case 180:
+   addr_mode = 0;
+   break;
+   case 270:
+   addr_mode = ST7735R_MY | ST7735R_MV;
+   break;
+   }
+   mipi_dbi_command(mipi, MIPI_DCS_SET_ADDRESS_MODE, addr_mode);
+   mipi_dbi_command(mipi, MIPI_DCS_SET_PIXEL_FORMAT,
+MIPI_DCS_PIXEL_FMT_16BIT);
+   mipi_dbi_command(mipi, ST7735R_GAMCTRP1, 0x0f, 0x1a, 0x0f, 0x18, 0x2f,
+0x28, 0x20, 0x22, 0x1f, 0x1b, 0x23, 0x37, 0x00, 0x07,
+0x02, 0x10);
+   mipi_dbi_command(mipi, ST7735R_GAMCTRN1, 0x0f, 0x1b, 0x0f, 0x17, 0x33,
+0x2c, 0x29, 0x2e, 0x30, 0x30, 0x39, 0x3f, 0x00, 0x07,
+0x03, 0x10);
+   mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_ON);
+
+   msleep(100);
+
+   mipi_dbi_command(mipi, MIPI_DCS_ENTER_NORMAL_MODE);
+
+   msleep(20);
+
+   mipi_dbi_pipe_enable(pipe, crtc_state);
+}
+
+static const struct drm_simple_display_pipe_funcs st7735r_pipe_funcs = {
+   .enable = st7735r_pipe_enable,
+   .disable= mipi_dbi_pipe_disable,
+   .update = tinydrm_display_pipe_update,
+   .prepare_fb = tinydrm_display_pipe_prepare_fb,
+};
+
+static const struct drm_display_mode jd

Re: [PATCH v3 3/3] drm/tinydrm: add driver for ST7735R panels

2017-12-31 Thread Noralf Trønnes


Den 21.12.2017 20.23, skrev David Lechner:

This adds a new driver for Sitronix ST7735R display panels.

This has been tested using an Adafruit 1.8" TFT.

Signed-off-by: David Lechner 
---

v3 changes:
* Changed compatible string
* use SPDX license header
* Renamed mode struct to use panel name instead of controller name

v2 changes:
* Change delay from 10ms to 20ms to avoid checkpatch warning
* Use mipi_dbi_pipe_enable()/mipi_dbi_pipe_disable() to reduce duplicated code
* Rebase on drm-misc-next (tinydrm_lastclose => drm_fb_helper_lastclose)
* Use mipi_dbi_debugfs_init
* Add mipi->read_commands = NULL; since this display is write-only



diff --git a/drivers/gpu/drm/tinydrm/st7735r.c 
b/drivers/gpu/drm/tinydrm/st7735r.c
new file mode 100644
index 000..0b05b2c
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/st7735r.c
@@ -0,0 +1,215 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * DRM driver for Sitronix ST7735R panels
+ *
+ * Copyright 2017 David Lechner 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#define ST7735R_FRMCTR10xb1
+#define ST7735R_FRMCTR20xb2
+#define ST7735R_FRMCTR30xb3
+#define ST7735R_INVCTR 0xb4
+#define ST7735R_PWCTR1 0xc0
+#define ST7735R_PWCTR2 0xc1
+#define ST7735R_PWCTR3 0xc2
+#define ST7735R_PWCTR4 0xc3
+#define ST7735R_PWCTR5 0xc4
+#define ST7735R_VMCTR1 0xc5
+#define ST7735R_GAMCTRP1   0xe0
+#define ST7735R_GAMCTRN1   0xe1
+
+#define ST7735R_MY BIT(7)
+#define ST7735R_MX BIT(6)
+#define ST7735R_MV BIT(5)
+
+static void st7735r_pipe_enable(struct drm_simple_display_pipe *pipe,
+   struct drm_crtc_state *crtc_state)


This is confusing, you name the mode after the panel, but not the enable
function which has an initialization sequence that is also panel specific.

With .enable function named after the panel (and *_pipe_funcs):

Reviewed-by: Noralf Trønnes 


+{
+   struct tinydrm_device *tdev = pipe_to_tinydrm(pipe);
+   struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev);
+   struct device *dev = tdev->drm->dev;
+   int ret;
+   u8 addr_mode;
+
+   DRM_DEBUG_KMS("\n");
+
+   mipi_dbi_hw_reset(mipi);
+
+   ret = mipi_dbi_command(mipi, MIPI_DCS_SOFT_RESET);
+   if (ret) {
+   DRM_DEV_ERROR(dev, "Error sending command %d\n", ret);
+   return;
+   }
+
+   msleep(150);
+
+   mipi_dbi_command(mipi, MIPI_DCS_EXIT_SLEEP_MODE);
+   msleep(500);
+
+   mipi_dbi_command(mipi, ST7735R_FRMCTR1, 0x01, 0x2c, 0x2d);
+   mipi_dbi_command(mipi, ST7735R_FRMCTR2, 0x01, 0x2c, 0x2d);
+   mipi_dbi_command(mipi, ST7735R_FRMCTR3, 0x01, 0x2c, 0x2d, 0x01, 0x2c,
+0x2d);
+   mipi_dbi_command(mipi, ST7735R_INVCTR, 0x07);
+   mipi_dbi_command(mipi, ST7735R_PWCTR1, 0xa2, 0x02, 0x84);
+   mipi_dbi_command(mipi, ST7735R_PWCTR2, 0xc5);
+   mipi_dbi_command(mipi, ST7735R_PWCTR3, 0x0a, 0x00);
+   mipi_dbi_command(mipi, ST7735R_PWCTR4, 0x8a, 0x2a);
+   mipi_dbi_command(mipi, ST7735R_PWCTR5, 0x8a, 0xee);
+   mipi_dbi_command(mipi, ST7735R_VMCTR1, 0x0e);
+   mipi_dbi_command(mipi, MIPI_DCS_EXIT_INVERT_MODE);
+   switch (mipi->rotation) {
+   default:
+   addr_mode = ST7735R_MX | ST7735R_MY;
+   break;
+   case 90:
+   addr_mode = ST7735R_MX | ST7735R_MV;
+   break;
+   case 180:
+   addr_mode = 0;
+   break;
+   case 270:
+   addr_mode = ST7735R_MY | ST7735R_MV;
+   break;
+   }
+   mipi_dbi_command(mipi, MIPI_DCS_SET_ADDRESS_MODE, addr_mode);
+   mipi_dbi_command(mipi, MIPI_DCS_SET_PIXEL_FORMAT,
+MIPI_DCS_PIXEL_FMT_16BIT);
+   mipi_dbi_command(mipi, ST7735R_GAMCTRP1, 0x0f, 0x1a, 0x0f, 0x18, 0x2f,
+0x28, 0x20, 0x22, 0x1f, 0x1b, 0x23, 0x37, 0x00, 0x07,
+0x02, 0x10);
+   mipi_dbi_command(mipi, ST7735R_GAMCTRN1, 0x0f, 0x1b, 0x0f, 0x17, 0x33,
+0x2c, 0x29, 0x2e, 0x30, 0x30, 0x39, 0x3f, 0x00, 0x07,
+0x03, 0x10);
+   mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_ON);
+
+   msleep(100);
+
+   mipi_dbi_command(mipi, MIPI_DCS_ENTER_NORMAL_MODE);
+
+   msleep(20);
+
+   mipi_dbi_pipe_enable(pipe, crtc_state);
+}
+
+static const struct drm_simple_display_pipe_funcs st7735r_pipe_funcs = {
+   .enable = st7735r_pipe_enable,
+   .disable= mipi_dbi_pipe_disable,
+   .update = tinydrm_display_pipe_update,
+   .prepare_fb = tinydrm_display_pipe_prepare_fb,
+};
+
+static const struct drm_display_mode jd_t18003_t01_mode = {
+   TINYDRM_MODE(128, 160, 28, 35),
+};
+
+DEFINE_DRM_GEM_CMA_FOPS(st7735r_fops);
+

Re: UDL's fbdev doesn't work for user-space apps

2017-12-12 Thread Noralf Trønnes


Den 04.12.2017 12.32, skrev Alexey Brodkin:

Hello,

I'm trying to use DisplayLink USB2.0-to-HDMI adapter as the one and only
video output and I want to get Xserver working on top of that.

I'm not very familiar with all the parts of Linux GPU/video stack
(especially its user-space counterpart) so my assumptions might be wrong
in that case please correct me.

My first [probably incorrect] assumption is Xserver requires fbdev (/dev/fbX)
and it cannot use DRI video card natively. Is that correct?

So to get /ded/fb0 with UDL I just enabled CONFIG_DRM_UDL & 
CONFIG_DRM_FBDEV_EMULATION.
That gave me boot console on HDMI screen and I was full of expectations.
But when I tried to use /dev/fb0 from whatever user-space app nothing got
displayed on the screen... as well as no error messages appeared.

After eyeballing at UDL code (especially in comparison with QXC which uses 
deferredio
as well) I noticed that in UDL fb_deferred_io_init() is called from 
udl_fb_open(),
i.e. .fb_open call-back (in other words every time user-space app opens 
/dev/fb0)
while in QXC this is done only once and much earlier in qxlfb_create(), which is
called with .fb_probe call-back. So moved fb_deferred_io_init() in UDL driver 
from
udl_fb_open() to udlfb_create() which is also called from .fb_probe.

With that change I finally got video output via fbdev from user-space app,
but only on the first run. The next attempt to run inevitably ends with
kernel crash showing the following stack-trace (having half of the new screen
rendered on display):
>8-
Stack Trace:
   udl_handle_damage+0x48/0x210
   udl_crtc_mode_set+0x6ee/0x754
   drm_crtc_helper_set_mode+0x25e/0x438
   drm_crtc_helper_set_config+0x6d6/0x814
   __drm_mode_set_config_internal+0x48/0xc8
   drm_mode_setcrtc+0x320/0x478
   drm_ioctl+0x22c/0x3e4
   SyS_ioctl+0xa4/0x8cc
   EV_Trap+0x108/0x10c
random: crng init done
>8-

I'm wondering if UDL driver (its DRM flavor) was ever tested for
fbdev in user-space? If so and it really works for somebody
maybe I'm doing something terribly wrong - in that case any comments
are very welcome.


udl uses shmem buffers which doesn't work with fbdev deferred io.
They fight over page->lru and page->mapping. See this commit:
drm/udl: disable fb_defio by default
677d23b70bf949f75746c80cbae92c233c6b5e2a

Noralf.


One interesting note: it seems like pure DRI stuff works like a charm.
I may run kmscube perfectly fine without any changes whatsoever and do it
many times in a row.

Thanks in advance,
Alexey
___
dri-devel mailing list
dri-de...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel





Re: UDL's fbdev doesn't work for user-space apps

2017-12-12 Thread Noralf Trønnes


Den 04.12.2017 12.32, skrev Alexey Brodkin:

Hello,

I'm trying to use DisplayLink USB2.0-to-HDMI adapter as the one and only
video output and I want to get Xserver working on top of that.

I'm not very familiar with all the parts of Linux GPU/video stack
(especially its user-space counterpart) so my assumptions might be wrong
in that case please correct me.

My first [probably incorrect] assumption is Xserver requires fbdev (/dev/fbX)
and it cannot use DRI video card natively. Is that correct?

So to get /ded/fb0 with UDL I just enabled CONFIG_DRM_UDL & 
CONFIG_DRM_FBDEV_EMULATION.
That gave me boot console on HDMI screen and I was full of expectations.
But when I tried to use /dev/fb0 from whatever user-space app nothing got
displayed on the screen... as well as no error messages appeared.

After eyeballing at UDL code (especially in comparison with QXC which uses 
deferredio
as well) I noticed that in UDL fb_deferred_io_init() is called from 
udl_fb_open(),
i.e. .fb_open call-back (in other words every time user-space app opens 
/dev/fb0)
while in QXC this is done only once and much earlier in qxlfb_create(), which is
called with .fb_probe call-back. So moved fb_deferred_io_init() in UDL driver 
from
udl_fb_open() to udlfb_create() which is also called from .fb_probe.

With that change I finally got video output via fbdev from user-space app,
but only on the first run. The next attempt to run inevitably ends with
kernel crash showing the following stack-trace (having half of the new screen
rendered on display):
>8-
Stack Trace:
   udl_handle_damage+0x48/0x210
   udl_crtc_mode_set+0x6ee/0x754
   drm_crtc_helper_set_mode+0x25e/0x438
   drm_crtc_helper_set_config+0x6d6/0x814
   __drm_mode_set_config_internal+0x48/0xc8
   drm_mode_setcrtc+0x320/0x478
   drm_ioctl+0x22c/0x3e4
   SyS_ioctl+0xa4/0x8cc
   EV_Trap+0x108/0x10c
random: crng init done
>8-

I'm wondering if UDL driver (its DRM flavor) was ever tested for
fbdev in user-space? If so and it really works for somebody
maybe I'm doing something terribly wrong - in that case any comments
are very welcome.


udl uses shmem buffers which doesn't work with fbdev deferred io.
They fight over page->lru and page->mapping. See this commit:
drm/udl: disable fb_defio by default
677d23b70bf949f75746c80cbae92c233c6b5e2a

Noralf.


One interesting note: it seems like pure DRI stuff works like a charm.
I may run kmscube perfectly fine without any changes whatsoever and do it
many times in a row.

Thanks in advance,
Alexey
___
dri-devel mailing list
dri-de...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel





Re: [PATCH v2 2/2] drm/tinydrm: add driver for ST7735R panels

2017-12-11 Thread Noralf Trønnes


Den 10.12.2017 23.10, skrev David Lechner:

This adds a new driver for Sitronix ST7735R display panels.

This has been tested using an Adafruit 1.8" TFT.

Signed-off-by: David Lechner 
---



+static void st7735r_pipe_enable(struct drm_simple_display_pipe *pipe,
+   struct drm_crtc_state *crtc_state)
+{
+   struct tinydrm_device *tdev = pipe_to_tinydrm(pipe);
+   struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev);
+   struct device *dev = tdev->drm->dev;
+   int ret;
+   u8 addr_mode;
+
+   DRM_DEBUG_KMS("\n");
+
+   mipi_dbi_hw_reset(mipi);
+
+   ret = mipi_dbi_command(mipi, MIPI_DCS_SOFT_RESET);
+   if (ret) {
+   DRM_DEV_ERROR(dev, "Error sending command %d\n", ret);
+   return;
+   }
+
+   msleep(150);
+
+   mipi_dbi_command(mipi, MIPI_DCS_EXIT_SLEEP_MODE);
+   msleep(500);
+
+   mipi_dbi_command(mipi, ST7735R_FRMCTR1, 0x01, 0x2c, 0x2d);
+   mipi_dbi_command(mipi, ST7735R_FRMCTR2, 0x01, 0x2c, 0x2d);
+   mipi_dbi_command(mipi, ST7735R_FRMCTR3, 0x01, 0x2c, 0x2d, 0x01, 0x2c,
+0x2d);
+   mipi_dbi_command(mipi, ST7735R_INVCTR, 0x07);
+   mipi_dbi_command(mipi, ST7735R_PWCTR1, 0xa2, 0x02, 0x84);
+   mipi_dbi_command(mipi, ST7735R_PWCTR2, 0xc5);
+   mipi_dbi_command(mipi, ST7735R_PWCTR3, 0x0a, 0x00);
+   mipi_dbi_command(mipi, ST7735R_PWCTR4, 0x8a, 0x2a);
+   mipi_dbi_command(mipi, ST7735R_PWCTR5, 0x8a, 0xee);
+   mipi_dbi_command(mipi, ST7735R_VMCTR1, 0x0e);
+   mipi_dbi_command(mipi, MIPI_DCS_EXIT_INVERT_MODE);
+   switch (mipi->rotation) {
+   default:
+   addr_mode = ST7735R_MX | ST7735R_MY;
+   break;
+   case 90:
+   addr_mode = ST7735R_MX | ST7735R_MV;
+   break;
+   case 180:
+   addr_mode = 0;
+   break;
+   case 270:
+   addr_mode = ST7735R_MY | ST7735R_MV;
+   break;
+   }
+   mipi_dbi_command(mipi, MIPI_DCS_SET_ADDRESS_MODE, addr_mode);
+   mipi_dbi_command(mipi, MIPI_DCS_SET_PIXEL_FORMAT,
+MIPI_DCS_PIXEL_FMT_16BIT);
+   mipi_dbi_command(mipi, ST7735R_GAMCTRP1, 0x0f, 0x1a, 0x0f, 0x18, 0x2f,
+0x28, 0x20, 0x22, 0x1f, 0x1b, 0x23, 0x37, 0x00, 0x07,
+0x02, 0x10);
+   mipi_dbi_command(mipi, ST7735R_GAMCTRN1, 0x0f, 0x1b, 0x0f, 0x17, 0x33,
+0x2c, 0x29, 0x2e, 0x30, 0x30, 0x39, 0x3f, 0x00, 0x07,
+0x03, 0x10);
+   mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_ON);
+
+   msleep(100);
+
+   mipi_dbi_command(mipi, MIPI_DCS_ENTER_NORMAL_MODE);
+
+   msleep(20);
+
+   mipi_dbi_pipe_enable(pipe, crtc_state);
+}
+
+static const struct drm_simple_display_pipe_funcs st7735r_pipe_funcs = {
+   .enable = st7735r_pipe_enable,
+   .disable= mipi_dbi_pipe_disable,
+   .update = tinydrm_display_pipe_update,
+   .prepare_fb = tinydrm_display_pipe_prepare_fb,
+};
+
+static const struct drm_display_mode st7735r_mode = {
+   TINYDRM_MODE(128, 160, 28, 35),
+};


This naming talk has made me realise that these should be named after
the panel since they're not generic controller functions.
Maybe the mode can be generic, not sure if the physical size can/will
differ, the resolution is very likely to be the same for all.

What's your view on my descision to split the MIPI DBI compatible
controllers into per controller drivers instead of having one driver
that supports them all?
I've been afraid that it will be a very big file with macro definitions
per controller and enable functions per panel.

This driver has 15 macros and ~80 panel specific lines.
With one panel supported, half the driver is boilerplate.
The mi0283qt panel (MIPI DBI compatible) is in the same ballpark.

Adding helpers for panel reset/exit_sleep, for MIPI_DCS_SET_ADDRESS_MODE
and for display_on/enter_normal/flush could cut it down some more if we
made one driver to rule them all. Maybe the enable function per panel
could be cut in half that way.

I'm starting to wonder if one driver isn't such a bad solution after all...

Noralf.



Re: [PATCH v2 2/2] drm/tinydrm: add driver for ST7735R panels

2017-12-11 Thread Noralf Trønnes


Den 10.12.2017 23.10, skrev David Lechner:

This adds a new driver for Sitronix ST7735R display panels.

This has been tested using an Adafruit 1.8" TFT.

Signed-off-by: David Lechner 
---



+static void st7735r_pipe_enable(struct drm_simple_display_pipe *pipe,
+   struct drm_crtc_state *crtc_state)
+{
+   struct tinydrm_device *tdev = pipe_to_tinydrm(pipe);
+   struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev);
+   struct device *dev = tdev->drm->dev;
+   int ret;
+   u8 addr_mode;
+
+   DRM_DEBUG_KMS("\n");
+
+   mipi_dbi_hw_reset(mipi);
+
+   ret = mipi_dbi_command(mipi, MIPI_DCS_SOFT_RESET);
+   if (ret) {
+   DRM_DEV_ERROR(dev, "Error sending command %d\n", ret);
+   return;
+   }
+
+   msleep(150);
+
+   mipi_dbi_command(mipi, MIPI_DCS_EXIT_SLEEP_MODE);
+   msleep(500);
+
+   mipi_dbi_command(mipi, ST7735R_FRMCTR1, 0x01, 0x2c, 0x2d);
+   mipi_dbi_command(mipi, ST7735R_FRMCTR2, 0x01, 0x2c, 0x2d);
+   mipi_dbi_command(mipi, ST7735R_FRMCTR3, 0x01, 0x2c, 0x2d, 0x01, 0x2c,
+0x2d);
+   mipi_dbi_command(mipi, ST7735R_INVCTR, 0x07);
+   mipi_dbi_command(mipi, ST7735R_PWCTR1, 0xa2, 0x02, 0x84);
+   mipi_dbi_command(mipi, ST7735R_PWCTR2, 0xc5);
+   mipi_dbi_command(mipi, ST7735R_PWCTR3, 0x0a, 0x00);
+   mipi_dbi_command(mipi, ST7735R_PWCTR4, 0x8a, 0x2a);
+   mipi_dbi_command(mipi, ST7735R_PWCTR5, 0x8a, 0xee);
+   mipi_dbi_command(mipi, ST7735R_VMCTR1, 0x0e);
+   mipi_dbi_command(mipi, MIPI_DCS_EXIT_INVERT_MODE);
+   switch (mipi->rotation) {
+   default:
+   addr_mode = ST7735R_MX | ST7735R_MY;
+   break;
+   case 90:
+   addr_mode = ST7735R_MX | ST7735R_MV;
+   break;
+   case 180:
+   addr_mode = 0;
+   break;
+   case 270:
+   addr_mode = ST7735R_MY | ST7735R_MV;
+   break;
+   }
+   mipi_dbi_command(mipi, MIPI_DCS_SET_ADDRESS_MODE, addr_mode);
+   mipi_dbi_command(mipi, MIPI_DCS_SET_PIXEL_FORMAT,
+MIPI_DCS_PIXEL_FMT_16BIT);
+   mipi_dbi_command(mipi, ST7735R_GAMCTRP1, 0x0f, 0x1a, 0x0f, 0x18, 0x2f,
+0x28, 0x20, 0x22, 0x1f, 0x1b, 0x23, 0x37, 0x00, 0x07,
+0x02, 0x10);
+   mipi_dbi_command(mipi, ST7735R_GAMCTRN1, 0x0f, 0x1b, 0x0f, 0x17, 0x33,
+0x2c, 0x29, 0x2e, 0x30, 0x30, 0x39, 0x3f, 0x00, 0x07,
+0x03, 0x10);
+   mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_ON);
+
+   msleep(100);
+
+   mipi_dbi_command(mipi, MIPI_DCS_ENTER_NORMAL_MODE);
+
+   msleep(20);
+
+   mipi_dbi_pipe_enable(pipe, crtc_state);
+}
+
+static const struct drm_simple_display_pipe_funcs st7735r_pipe_funcs = {
+   .enable = st7735r_pipe_enable,
+   .disable= mipi_dbi_pipe_disable,
+   .update = tinydrm_display_pipe_update,
+   .prepare_fb = tinydrm_display_pipe_prepare_fb,
+};
+
+static const struct drm_display_mode st7735r_mode = {
+   TINYDRM_MODE(128, 160, 28, 35),
+};


This naming talk has made me realise that these should be named after
the panel since they're not generic controller functions.
Maybe the mode can be generic, not sure if the physical size can/will
differ, the resolution is very likely to be the same for all.

What's your view on my descision to split the MIPI DBI compatible
controllers into per controller drivers instead of having one driver
that supports them all?
I've been afraid that it will be a very big file with macro definitions
per controller and enable functions per panel.

This driver has 15 macros and ~80 panel specific lines.
With one panel supported, half the driver is boilerplate.
The mi0283qt panel (MIPI DBI compatible) is in the same ballpark.

Adding helpers for panel reset/exit_sleep, for MIPI_DCS_SET_ADDRESS_MODE
and for display_on/enter_normal/flush could cut it down some more if we
made one driver to rule them all. Maybe the enable function per panel
could be cut in half that way.

I'm starting to wonder if one driver isn't such a bad solution after all...

Noralf.



Re: [PATCH v2 1/2] dt-bindings: Add binding for Sitronix ST7735R display panels

2017-12-11 Thread Noralf Trønnes


Den 10.12.2017 23.10, skrev David Lechner:

This adds a new device tree binding for Sitronix ST7735R display panels,
such as the Adafruit 1.8" TFT.

Signed-off-by: David Lechner 
Acked-by: Rob Herring 
---

v2: changes:
* None, but...

I'm wondering about my choice of compatible here. I chose the name
"sitronix,st7735r-jd-t18003-t01" to mean a Sitronix ST7735R controller
connected to a JD-T18003-T01 LCD screen.

What I am actually using, though, is an Adafruit 1.8" TFT breakout [1]. It
has some additional electronics which just pass through signals to the
controller. The bare display is also available from Adafruit [2].

Limor brought up an interesting point in an off-list discussion. The
same controller can be wired to the same LCD in different ways. This is
evident in the fbftf drivers in staging. There is an "adafruit18" and an
"adafruit18_green" in fbftf_devices.c where apparently, two otherwise
identical displays were wired slightly differently at the factory so that
on one, the on-board GRAM word 0 does not correspond to pixel 0,0 on the
LCD. It requires a special offset to the GRAM starting address in order to
have the image displayed correctly.

Additionally, fbtft supports a SainSmart 1.8" TFT [3] that uses the same
controller, but it appears that these have different gamma curves (perhaps
they use different LCDs?). The available pins are exactly the same as the
Adafruit display though.

As I am writing this, I am looking at the JD-1800 datasheet [4] again for
the Adafruit display and I see that in addition to specifying the size of
the display it says "IC: ST7735B". So, I am starting to think that "jianda,
jd-t18003-t01" would be a better compatible string since it tells you
everything you need to know about this display. Just using the controller
name by itself ("sitronix,st7735r") is not enough because it does not tell
you things like the number of pixels or the physical size of the LCD.

What I am not sure about, though, is how to represent the Adafruit display
that requires the offset in the device tree. Would it be a different
compatible string or should we add an extra property to indicate this
quirk?

On a related note, I recently submitted device tree bindings for a similar
SPI display breakout board [5][6]. After more digging though, I found a
datasheet for that display [7], so I'm thinking a compatible string of
"vot,v220hf01a-t" would be better by the same reasoning above.

And, I know this is getting long, but one more thing...

There was a binding acked recently for the LCD on a D-Link DIR-685 Wireless
N Storage Router [8]. This uses the compound compatible string of "dlink,
dir-685-panel", "ilitek,ili9322". If we want to try to keep things
consistent, perhaps I should be adopting this pattern as well? And perhaps
it would be better to use the better known vendor name instead of the
obscure vendors from the datasheets that I have found? For example,
"adafruit,618" "sitronix,st7735r" instead of "jianda,jd-t18003-t01"?


I vote for this:
"jianda,jd-t18003-t01"

The display controller is part of the panel so you can't have this
panel with another controller. If the Adafruit #358 panel with
breakout board did something that made it incompatible with a bare
jianda panel, then it would make sense to call it "adafruit,something".

I don't know the full story about the green tab version of the display
with the offset problem, but it's a long time ago and I don't think
it's worth it to support it. It would require a custom dirtyfb callback.

There's also a black tab version of this Adafruit display with the
colors reversed BGR/RGB, but that also is some time back now.

I guess they all had different panels with their own names which would
result in different compatible strings. This means that the end user
would have to know excatly which version of the Adafruit display they're
using to know which compatible string to use. If the SPI MISO signal
had been routed out from the panel, it would have been possible to make
a driver just with a "adafruit,tft18" comaptible and let the driver ask
the controller which version it is. Assuming that info is available in
the controller. Not all panel vendors bother to do that.

The "mi,mi0283qt" panel for instance is used on the Adafruit PiTFT 28
and the Watterott rpi-display, making it possible to use the same
compatible for both displays and also for anyone buying that panel from
some other source.

One last thing, if the panel is made specifically for Adafruit and not
available from any other source, then it makes sense to call it
something "adafruit".

Noralf.


[1]: https://www.adafruit.com/product/358
[2]: https://www.adafruit.com/product/618
[3]: 
https://www.sainsmart.com/products/1-8-tft-spi-lcd-screen-with-microsd-socket
[4]: http://www.adafruit.com/datasheets/JD-T1800.pdf
[5]: https://patchwork.freedesktop.org/patch/187038/
[6]: https://patchwork.freedesktop.org/patch/189233/
[7]: 

Re: [PATCH v2 1/2] dt-bindings: Add binding for Sitronix ST7735R display panels

2017-12-11 Thread Noralf Trønnes


Den 10.12.2017 23.10, skrev David Lechner:

This adds a new device tree binding for Sitronix ST7735R display panels,
such as the Adafruit 1.8" TFT.

Signed-off-by: David Lechner 
Acked-by: Rob Herring 
---

v2: changes:
* None, but...

I'm wondering about my choice of compatible here. I chose the name
"sitronix,st7735r-jd-t18003-t01" to mean a Sitronix ST7735R controller
connected to a JD-T18003-T01 LCD screen.

What I am actually using, though, is an Adafruit 1.8" TFT breakout [1]. It
has some additional electronics which just pass through signals to the
controller. The bare display is also available from Adafruit [2].

Limor brought up an interesting point in an off-list discussion. The
same controller can be wired to the same LCD in different ways. This is
evident in the fbftf drivers in staging. There is an "adafruit18" and an
"adafruit18_green" in fbftf_devices.c where apparently, two otherwise
identical displays were wired slightly differently at the factory so that
on one, the on-board GRAM word 0 does not correspond to pixel 0,0 on the
LCD. It requires a special offset to the GRAM starting address in order to
have the image displayed correctly.

Additionally, fbtft supports a SainSmart 1.8" TFT [3] that uses the same
controller, but it appears that these have different gamma curves (perhaps
they use different LCDs?). The available pins are exactly the same as the
Adafruit display though.

As I am writing this, I am looking at the JD-1800 datasheet [4] again for
the Adafruit display and I see that in addition to specifying the size of
the display it says "IC: ST7735B". So, I am starting to think that "jianda,
jd-t18003-t01" would be a better compatible string since it tells you
everything you need to know about this display. Just using the controller
name by itself ("sitronix,st7735r") is not enough because it does not tell
you things like the number of pixels or the physical size of the LCD.

What I am not sure about, though, is how to represent the Adafruit display
that requires the offset in the device tree. Would it be a different
compatible string or should we add an extra property to indicate this
quirk?

On a related note, I recently submitted device tree bindings for a similar
SPI display breakout board [5][6]. After more digging though, I found a
datasheet for that display [7], so I'm thinking a compatible string of
"vot,v220hf01a-t" would be better by the same reasoning above.

And, I know this is getting long, but one more thing...

There was a binding acked recently for the LCD on a D-Link DIR-685 Wireless
N Storage Router [8]. This uses the compound compatible string of "dlink,
dir-685-panel", "ilitek,ili9322". If we want to try to keep things
consistent, perhaps I should be adopting this pattern as well? And perhaps
it would be better to use the better known vendor name instead of the
obscure vendors from the datasheets that I have found? For example,
"adafruit,618" "sitronix,st7735r" instead of "jianda,jd-t18003-t01"?


I vote for this:
"jianda,jd-t18003-t01"

The display controller is part of the panel so you can't have this
panel with another controller. If the Adafruit #358 panel with
breakout board did something that made it incompatible with a bare
jianda panel, then it would make sense to call it "adafruit,something".

I don't know the full story about the green tab version of the display
with the offset problem, but it's a long time ago and I don't think
it's worth it to support it. It would require a custom dirtyfb callback.

There's also a black tab version of this Adafruit display with the
colors reversed BGR/RGB, but that also is some time back now.

I guess they all had different panels with their own names which would
result in different compatible strings. This means that the end user
would have to know excatly which version of the Adafruit display they're
using to know which compatible string to use. If the SPI MISO signal
had been routed out from the panel, it would have been possible to make
a driver just with a "adafruit,tft18" comaptible and let the driver ask
the controller which version it is. Assuming that info is available in
the controller. Not all panel vendors bother to do that.

The "mi,mi0283qt" panel for instance is used on the Adafruit PiTFT 28
and the Watterott rpi-display, making it possible to use the same
compatible for both displays and also for anyone buying that panel from
some other source.

One last thing, if the panel is made specifically for Adafruit and not
available from any other source, then it makes sense to call it
something "adafruit".

Noralf.


[1]: https://www.adafruit.com/product/358
[2]: https://www.adafruit.com/product/618
[3]: 
https://www.sainsmart.com/products/1-8-tft-spi-lcd-screen-with-microsd-socket
[4]: http://www.adafruit.com/datasheets/JD-T1800.pdf
[5]: https://patchwork.freedesktop.org/patch/187038/
[6]: https://patchwork.freedesktop.org/patch/189233/
[7]: 

Re: [PATCH v1 2/2] drm/tinydrm: add driver for ST7735R panels

2017-12-09 Thread Noralf Trønnes


Den 29.11.2017 04.01, skrev David Lechner:

This adds a new driver for Sitronix ST7735R display panels.

This has been tested using an Adafruit 1.8" TFT.

Signed-off-by: David Lechner 
---



diff --git a/drivers/gpu/drm/tinydrm/st7735r.c 
b/drivers/gpu/drm/tinydrm/st7735r.c



+static struct drm_driver st7735r_driver = {
+   .driver_features= DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME |
+ DRIVER_ATOMIC,
+   .fops   = _fops,
+   TINYDRM_GEM_DRIVER_OPS,
+   .lastclose  = tinydrm_lastclose,


I was reminded of this since it would have made it easy to turn off the
panel and see if it turned white. Adding this makes it possible to send
commands from userspace for testing:

    .debugfs_init        = mipi_dbi_debugfs_init,

If you do that you have to set this to NULL since it's not possible to
read from the controller in this panel:

    mipi->read_commands = NULL;

Noralf.



Re: [PATCH v1 2/2] drm/tinydrm: add driver for ST7735R panels

2017-12-09 Thread Noralf Trønnes


Den 29.11.2017 04.01, skrev David Lechner:

This adds a new driver for Sitronix ST7735R display panels.

This has been tested using an Adafruit 1.8" TFT.

Signed-off-by: David Lechner 
---



diff --git a/drivers/gpu/drm/tinydrm/st7735r.c 
b/drivers/gpu/drm/tinydrm/st7735r.c



+static struct drm_driver st7735r_driver = {
+   .driver_features= DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME |
+ DRIVER_ATOMIC,
+   .fops   = _fops,
+   TINYDRM_GEM_DRIVER_OPS,
+   .lastclose  = tinydrm_lastclose,


I was reminded of this since it would have made it easy to turn off the
panel and see if it turned white. Adding this makes it possible to send
commands from userspace for testing:

    .debugfs_init        = mipi_dbi_debugfs_init,

If you do that you have to set this to NULL since it's not possible to
read from the controller in this panel:

    mipi->read_commands = NULL;

Noralf.



Re: [PATCH v1 1/2] dt-bindings: Add binding for Sitronix ST7735R display panels

2017-12-08 Thread Noralf Trønnes


Den 29.11.2017 04.01, skrev David Lechner:

This adds a new device tree binding for Sitronix ST7735R display panels,
such as the Adafruit 1.8" TFT.

Signed-off-by: David Lechner 
---
  .../bindings/display/sitronix,st7735r.txt  | 35 ++
  1 file changed, 35 insertions(+)
  create mode 100644 
Documentation/devicetree/bindings/display/sitronix,st7735r.txt

diff --git a/Documentation/devicetree/bindings/display/sitronix,st7735r.txt 
b/Documentation/devicetree/bindings/display/sitronix,st7735r.txt
new file mode 100644
index 000..bbb8ba6
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/sitronix,st7735r.txt
@@ -0,0 +1,35 @@
+Sitronix ST7735R display panels
+
+This binding is for display panels using a Sitronix ST7735R controller in SPI
+mode.
+
+Required properties:
+- compatible:  "sitronix,st7735r-jd-t18003-t01"
+- dc-gpios:Display data/command selection (D/CX)
+- reset-gpios: Reset signal (RSTX)


I'm wondering if this should be optional.

Even though the display needs the reset line to be driven, it doesn't
have to be so by a gpio, I believe you can even get away with just
using a resistor as a reset circuit.

Not terribly important, it's up to you.

Noralf.



+
+The node for this driver must be a child node of a SPI controller, hence
+all mandatory properties described in ../spi/spi-bus.txt must be specified.
+
+Optional properties:
+- rotation:panel rotation in degrees counter clockwise (0,90,180,270)
+- backlight:   phandle of the backlight device attached to the panel
+
+Example:
+
+   backlight: backlight {
+   compatible = "gpio-backlight";
+   gpios = < 44 GPIO_ACTIVE_HIGH>;
+   }
+
+   ...
+
+   display@0{
+   compatible = "sitronix,st7735r-jd-t18003-t01";
+   reg = <0>;
+   spi-max-frequency = <3200>;
+   dc-gpios = < 43 GPIO_ACTIVE_HIGH>;
+   reset-gpios = < 80 GPIO_ACTIVE_HIGH>;
+   rotation = <270>;
+   backlight = 
+   };




Re: [PATCH v1 1/2] dt-bindings: Add binding for Sitronix ST7735R display panels

2017-12-08 Thread Noralf Trønnes


Den 29.11.2017 04.01, skrev David Lechner:

This adds a new device tree binding for Sitronix ST7735R display panels,
such as the Adafruit 1.8" TFT.

Signed-off-by: David Lechner 
---
  .../bindings/display/sitronix,st7735r.txt  | 35 ++
  1 file changed, 35 insertions(+)
  create mode 100644 
Documentation/devicetree/bindings/display/sitronix,st7735r.txt

diff --git a/Documentation/devicetree/bindings/display/sitronix,st7735r.txt 
b/Documentation/devicetree/bindings/display/sitronix,st7735r.txt
new file mode 100644
index 000..bbb8ba6
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/sitronix,st7735r.txt
@@ -0,0 +1,35 @@
+Sitronix ST7735R display panels
+
+This binding is for display panels using a Sitronix ST7735R controller in SPI
+mode.
+
+Required properties:
+- compatible:  "sitronix,st7735r-jd-t18003-t01"
+- dc-gpios:Display data/command selection (D/CX)
+- reset-gpios: Reset signal (RSTX)


I'm wondering if this should be optional.

Even though the display needs the reset line to be driven, it doesn't
have to be so by a gpio, I believe you can even get away with just
using a resistor as a reset circuit.

Not terribly important, it's up to you.

Noralf.



+
+The node for this driver must be a child node of a SPI controller, hence
+all mandatory properties described in ../spi/spi-bus.txt must be specified.
+
+Optional properties:
+- rotation:panel rotation in degrees counter clockwise (0,90,180,270)
+- backlight:   phandle of the backlight device attached to the panel
+
+Example:
+
+   backlight: backlight {
+   compatible = "gpio-backlight";
+   gpios = < 44 GPIO_ACTIVE_HIGH>;
+   }
+
+   ...
+
+   display@0{
+   compatible = "sitronix,st7735r-jd-t18003-t01";
+   reg = <0>;
+   spi-max-frequency = <3200>;
+   dc-gpios = < 43 GPIO_ACTIVE_HIGH>;
+   reset-gpios = < 80 GPIO_ACTIVE_HIGH>;
+   rotation = <270>;
+   backlight = 
+   };




Re: [PATCH v1 2/2] drm/tinydrm: add driver for ST7735R panels

2017-12-08 Thread Noralf Trønnes


Den 06.12.2017 19.27, skrev Noralf Trønnes:


Den 29.11.2017 04.01, skrev David Lechner:

This adds a new driver for Sitronix ST7735R display panels.

This has been tested using an Adafruit 1.8" TFT.

Signed-off-by: David Lechner <da...@lechnology.com>
---




diff --git a/drivers/gpu/drm/tinydrm/st7735r.c 
b/drivers/gpu/drm/tinydrm/st7735r.c





+static struct drm_driver st7735r_driver = {
+    .driver_features    = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME |
+  DRIVER_ATOMIC,
+    .fops    = _fops,
+    TINYDRM_GEM_DRIVER_OPS,
+    .lastclose    = tinydrm_lastclose,


tinydrm_lastclose() is going away, please use:

    .lastclose        = drm_fb_helper_lastclose,

Noralf.


+    .name    = "st7735r",
+    .desc    = "Sitronix ST7735R",
+    .date    = "20171128",
+    .major    = 1,
+    .minor    = 0,
+};
+
+static const struct of_device_id st7735r_of_match[] = {
+    { .compatible = "sitronix,st7735r-jd-t18003-t01" },
+    {},
+};
+MODULE_DEVICE_TABLE(of, st7735r_of_match);
+
+static const struct spi_device_id st7735r_id[] = {
+    { "st7735r-jd-t18003-t01", 0 },
+    { },
+};
+MODULE_DEVICE_TABLE(spi, st7735r_id);
+
+static int st7735r_probe(struct spi_device *spi)
+{
+    struct device *dev = >dev;
+    struct mipi_dbi *mipi;
+    struct gpio_desc *dc;
+    u32 rotation = 0;
+    int ret;
+
+    mipi = devm_kzalloc(dev, sizeof(*mipi), GFP_KERNEL);
+    if (!mipi)
+    return -ENOMEM;
+
+    mipi->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+    if (IS_ERR(mipi->reset)) {
+    DRM_DEV_ERROR(dev, "Failed to get gpio 'reset'\n");
+    return PTR_ERR(mipi->reset);
+    }
+
+    dc = devm_gpiod_get(dev, "dc", GPIOD_OUT_LOW);
+    if (IS_ERR(dc)) {
+    DRM_DEV_ERROR(dev, "Failed to get gpio 'dc'\n");
+    return PTR_ERR(dc);
+    }
+
+    mipi->backlight = tinydrm_of_find_backlight(dev);
+    if (IS_ERR(mipi->backlight))
+    return PTR_ERR(mipi->backlight);
+
+    device_property_read_u32(dev, "rotation", );
+
+    ret = mipi_dbi_spi_init(spi, mipi, dc);
+    if (ret)
+    return ret;
+
+    ret = mipi_dbi_init(>dev, mipi, _pipe_funcs,
+    _driver, _mode, rotation);
+    if (ret)
+    return ret;
+
+    spi_set_drvdata(spi, mipi);
+
+    return devm_tinydrm_register(>tinydrm);
+}
+
+static void st7735r_shutdown(struct spi_device *spi)
+{
+    struct mipi_dbi *mipi = spi_get_drvdata(spi);
+
+    tinydrm_shutdown(>tinydrm);
+}
+
+static struct spi_driver st7735r_spi_driver = {
+    .driver = {
+    .name = "st7735r",
+    .owner = THIS_MODULE,
+    .of_match_table = st7735r_of_match,
+    },
+    .id_table = st7735r_id,
+    .probe = st7735r_probe,
+    .shutdown = st7735r_shutdown,
+};
+module_spi_driver(st7735r_spi_driver);
+
+MODULE_DESCRIPTION("Sitronix ST7735R DRM driver");
+MODULE_AUTHOR("David Lechner <da...@lechnology.com>");
+MODULE_LICENSE("GPL");


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





Re: [PATCH v1 2/2] drm/tinydrm: add driver for ST7735R panels

2017-12-08 Thread Noralf Trønnes


Den 06.12.2017 19.27, skrev Noralf Trønnes:


Den 29.11.2017 04.01, skrev David Lechner:

This adds a new driver for Sitronix ST7735R display panels.

This has been tested using an Adafruit 1.8" TFT.

Signed-off-by: David Lechner 
---




diff --git a/drivers/gpu/drm/tinydrm/st7735r.c 
b/drivers/gpu/drm/tinydrm/st7735r.c





+static struct drm_driver st7735r_driver = {
+    .driver_features    = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME |
+  DRIVER_ATOMIC,
+    .fops    = _fops,
+    TINYDRM_GEM_DRIVER_OPS,
+    .lastclose    = tinydrm_lastclose,


tinydrm_lastclose() is going away, please use:

    .lastclose        = drm_fb_helper_lastclose,

Noralf.


+    .name    = "st7735r",
+    .desc    = "Sitronix ST7735R",
+    .date    = "20171128",
+    .major    = 1,
+    .minor    = 0,
+};
+
+static const struct of_device_id st7735r_of_match[] = {
+    { .compatible = "sitronix,st7735r-jd-t18003-t01" },
+    {},
+};
+MODULE_DEVICE_TABLE(of, st7735r_of_match);
+
+static const struct spi_device_id st7735r_id[] = {
+    { "st7735r-jd-t18003-t01", 0 },
+    { },
+};
+MODULE_DEVICE_TABLE(spi, st7735r_id);
+
+static int st7735r_probe(struct spi_device *spi)
+{
+    struct device *dev = >dev;
+    struct mipi_dbi *mipi;
+    struct gpio_desc *dc;
+    u32 rotation = 0;
+    int ret;
+
+    mipi = devm_kzalloc(dev, sizeof(*mipi), GFP_KERNEL);
+    if (!mipi)
+    return -ENOMEM;
+
+    mipi->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+    if (IS_ERR(mipi->reset)) {
+    DRM_DEV_ERROR(dev, "Failed to get gpio 'reset'\n");
+    return PTR_ERR(mipi->reset);
+    }
+
+    dc = devm_gpiod_get(dev, "dc", GPIOD_OUT_LOW);
+    if (IS_ERR(dc)) {
+    DRM_DEV_ERROR(dev, "Failed to get gpio 'dc'\n");
+    return PTR_ERR(dc);
+    }
+
+    mipi->backlight = tinydrm_of_find_backlight(dev);
+    if (IS_ERR(mipi->backlight))
+    return PTR_ERR(mipi->backlight);
+
+    device_property_read_u32(dev, "rotation", );
+
+    ret = mipi_dbi_spi_init(spi, mipi, dc);
+    if (ret)
+    return ret;
+
+    ret = mipi_dbi_init(>dev, mipi, _pipe_funcs,
+    _driver, _mode, rotation);
+    if (ret)
+    return ret;
+
+    spi_set_drvdata(spi, mipi);
+
+    return devm_tinydrm_register(>tinydrm);
+}
+
+static void st7735r_shutdown(struct spi_device *spi)
+{
+    struct mipi_dbi *mipi = spi_get_drvdata(spi);
+
+    tinydrm_shutdown(>tinydrm);
+}
+
+static struct spi_driver st7735r_spi_driver = {
+    .driver = {
+    .name = "st7735r",
+    .owner = THIS_MODULE,
+    .of_match_table = st7735r_of_match,
+    },
+    .id_table = st7735r_id,
+    .probe = st7735r_probe,
+    .shutdown = st7735r_shutdown,
+};
+module_spi_driver(st7735r_spi_driver);
+
+MODULE_DESCRIPTION("Sitronix ST7735R DRM driver");
+MODULE_AUTHOR("David Lechner ");
+MODULE_LICENSE("GPL");


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





Re: [PATCH v1 2/2] drm/tinydrm: add driver for ST7735R panels

2017-12-06 Thread Noralf Trønnes


Den 29.11.2017 04.01, skrev David Lechner:

This adds a new driver for Sitronix ST7735R display panels.

This has been tested using an Adafruit 1.8" TFT.

Signed-off-by: David Lechner 
---
  MAINTAINERS   |   6 +
  drivers/gpu/drm/tinydrm/Kconfig   |  10 ++
  drivers/gpu/drm/tinydrm/Makefile  |   1 +
  drivers/gpu/drm/tinydrm/st7735r.c | 237 ++
  4 files changed, 254 insertions(+)
  create mode 100644 drivers/gpu/drm/tinydrm/st7735r.c

diff --git a/MAINTAINERS b/MAINTAINERS
index a174632..9c7707e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4462,6 +4462,12 @@ S:   Maintained
  F:drivers/gpu/drm/tinydrm/st7586.c
  F:Documentation/devicetree/bindings/display/st7586.txt
  
+DRM DRIVER FOR SITRONIX ST7735R PANELS

+M: David Lechner 


I know we haven't done this in the other tinydrm drivers, but I think
we should start adding which tree the development is happening in:

T:    git git://anongit.freedesktop.org/drm/drm-misc


+S: Maintained
+F: drivers/gpu/drm/tinydrm/st7735r.c
+F: Documentation/devicetree/bindings/display/st7735r.txt
+
  DRM DRIVER FOR TDFX VIDEO CARDS
  S:Orphan / Obsolete
  F:drivers/gpu/drm/tdfx/
diff --git a/drivers/gpu/drm/tinydrm/Kconfig b/drivers/gpu/drm/tinydrm/Kconfig
index 90c5bd5..b0e567d 100644
--- a/drivers/gpu/drm/tinydrm/Kconfig
+++ b/drivers/gpu/drm/tinydrm/Kconfig
@@ -52,3 +52,13 @@ config TINYDRM_ST7586
  * LEGO MINDSTORMS EV3
  
  	  If M is selected the module will be called st7586.

+
+config TINYDRM_ST7735R
+   tristate "DRM support for Sitronix ST7735R display panels"
+   depends on DRM_TINYDRM && SPI
+   select TINYDRM_MIPI_DBI
+   help
+ DRM driver Sitronix ST7735R with one of the following LCDs:
+ * JD-T18003-T01 1.8" 128x160 TFT
+
+ If M is selected the module will be called st7735r.
diff --git a/drivers/gpu/drm/tinydrm/Makefile b/drivers/gpu/drm/tinydrm/Makefile
index 8aeee53..49a1119 100644
--- a/drivers/gpu/drm/tinydrm/Makefile
+++ b/drivers/gpu/drm/tinydrm/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_TINYDRM_ILI9225)   += ili9225.o
  obj-$(CONFIG_TINYDRM_MI0283QT)+= mi0283qt.o
  obj-$(CONFIG_TINYDRM_REPAPER) += repaper.o
  obj-$(CONFIG_TINYDRM_ST7586)  += st7586.o
+obj-$(CONFIG_TINYDRM_ST7735R)  += st7735r.o
diff --git a/drivers/gpu/drm/tinydrm/st7735r.c 
b/drivers/gpu/drm/tinydrm/st7735r.c
new file mode 100644
index 000..6435b00
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/st7735r.c
@@ -0,0 +1,237 @@
+/*
+ * DRM driver for Sitronix ST7735R panels
+ *
+ * Copyright 2017 David Lechner 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#define ST7735R_FRMCTR10xb1
+#define ST7735R_FRMCTR20xb2
+#define ST7735R_FRMCTR30xb3
+#define ST7735R_INVCTR 0xb4
+#define ST7735R_PWCTR1 0xc0
+#define ST7735R_PWCTR2 0xc1
+#define ST7735R_PWCTR3 0xc2
+#define ST7735R_PWCTR4 0xc3
+#define ST7735R_PWCTR5 0xc4
+#define ST7735R_VMCTR1 0xc5
+#define ST7735R_GAMCTRP1   0xe0
+#define ST7735R_GAMCTRN1   0xe1
+
+#define ST7735R_MY BIT(7)
+#define ST7735R_MX BIT(6)
+#define ST7735R_MV BIT(5)
+
+static void st7735r_pipe_enable(struct drm_simple_display_pipe *pipe,
+   struct drm_crtc_state *crtc_state)
+{
+   struct tinydrm_device *tdev = pipe_to_tinydrm(pipe);
+   struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev);
+   struct drm_framebuffer *fb = pipe->plane.fb;
+   struct device *dev = tdev->drm->dev;
+   int ret;
+   u8 addr_mode;
+
+   DRM_DEBUG_KMS("\n");
+
+   mipi_dbi_hw_reset(mipi);
+
+   ret = mipi_dbi_command(mipi, MIPI_DCS_SOFT_RESET);
+   if (ret) {
+   DRM_DEV_ERROR(dev, "Error sending command %d\n", ret);
+   return;
+   }
+
+   msleep(150);
+
+   mipi_dbi_command(mipi, MIPI_DCS_EXIT_SLEEP_MODE);
+   msleep(500);
+
+   mipi_dbi_command(mipi, ST7735R_FRMCTR1, 0x01, 0x2c, 0x2d);
+   mipi_dbi_command(mipi, ST7735R_FRMCTR2, 0x01, 0x2c, 0x2d);
+   mipi_dbi_command(mipi, ST7735R_FRMCTR3, 0x01, 0x2c, 0x2d, 0x01, 0x2c,
+0x2d);
+   mipi_dbi_command(mipi, ST7735R_INVCTR, 0x07);
+   mipi_dbi_command(mipi, ST7735R_PWCTR1, 0xa2, 0x02, 0x84);
+   mipi_dbi_command(mipi, ST7735R_PWCTR2, 0xc5);
+   mipi_dbi_command(mipi, ST7735R_PWCTR3, 0x0a, 0x00);
+   mipi_dbi_command(mipi, ST7735R_PWCTR4, 0x8a, 0x2a);
+   mipi_dbi_command(mipi, 

Re: [PATCH v1 2/2] drm/tinydrm: add driver for ST7735R panels

2017-12-06 Thread Noralf Trønnes


Den 29.11.2017 04.01, skrev David Lechner:

This adds a new driver for Sitronix ST7735R display panels.

This has been tested using an Adafruit 1.8" TFT.

Signed-off-by: David Lechner 
---
  MAINTAINERS   |   6 +
  drivers/gpu/drm/tinydrm/Kconfig   |  10 ++
  drivers/gpu/drm/tinydrm/Makefile  |   1 +
  drivers/gpu/drm/tinydrm/st7735r.c | 237 ++
  4 files changed, 254 insertions(+)
  create mode 100644 drivers/gpu/drm/tinydrm/st7735r.c

diff --git a/MAINTAINERS b/MAINTAINERS
index a174632..9c7707e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4462,6 +4462,12 @@ S:   Maintained
  F:drivers/gpu/drm/tinydrm/st7586.c
  F:Documentation/devicetree/bindings/display/st7586.txt
  
+DRM DRIVER FOR SITRONIX ST7735R PANELS

+M: David Lechner 


I know we haven't done this in the other tinydrm drivers, but I think
we should start adding which tree the development is happening in:

T:    git git://anongit.freedesktop.org/drm/drm-misc


+S: Maintained
+F: drivers/gpu/drm/tinydrm/st7735r.c
+F: Documentation/devicetree/bindings/display/st7735r.txt
+
  DRM DRIVER FOR TDFX VIDEO CARDS
  S:Orphan / Obsolete
  F:drivers/gpu/drm/tdfx/
diff --git a/drivers/gpu/drm/tinydrm/Kconfig b/drivers/gpu/drm/tinydrm/Kconfig
index 90c5bd5..b0e567d 100644
--- a/drivers/gpu/drm/tinydrm/Kconfig
+++ b/drivers/gpu/drm/tinydrm/Kconfig
@@ -52,3 +52,13 @@ config TINYDRM_ST7586
  * LEGO MINDSTORMS EV3
  
  	  If M is selected the module will be called st7586.

+
+config TINYDRM_ST7735R
+   tristate "DRM support for Sitronix ST7735R display panels"
+   depends on DRM_TINYDRM && SPI
+   select TINYDRM_MIPI_DBI
+   help
+ DRM driver Sitronix ST7735R with one of the following LCDs:
+ * JD-T18003-T01 1.8" 128x160 TFT
+
+ If M is selected the module will be called st7735r.
diff --git a/drivers/gpu/drm/tinydrm/Makefile b/drivers/gpu/drm/tinydrm/Makefile
index 8aeee53..49a1119 100644
--- a/drivers/gpu/drm/tinydrm/Makefile
+++ b/drivers/gpu/drm/tinydrm/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_TINYDRM_ILI9225)   += ili9225.o
  obj-$(CONFIG_TINYDRM_MI0283QT)+= mi0283qt.o
  obj-$(CONFIG_TINYDRM_REPAPER) += repaper.o
  obj-$(CONFIG_TINYDRM_ST7586)  += st7586.o
+obj-$(CONFIG_TINYDRM_ST7735R)  += st7735r.o
diff --git a/drivers/gpu/drm/tinydrm/st7735r.c 
b/drivers/gpu/drm/tinydrm/st7735r.c
new file mode 100644
index 000..6435b00
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/st7735r.c
@@ -0,0 +1,237 @@
+/*
+ * DRM driver for Sitronix ST7735R panels
+ *
+ * Copyright 2017 David Lechner 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#define ST7735R_FRMCTR10xb1
+#define ST7735R_FRMCTR20xb2
+#define ST7735R_FRMCTR30xb3
+#define ST7735R_INVCTR 0xb4
+#define ST7735R_PWCTR1 0xc0
+#define ST7735R_PWCTR2 0xc1
+#define ST7735R_PWCTR3 0xc2
+#define ST7735R_PWCTR4 0xc3
+#define ST7735R_PWCTR5 0xc4
+#define ST7735R_VMCTR1 0xc5
+#define ST7735R_GAMCTRP1   0xe0
+#define ST7735R_GAMCTRN1   0xe1
+
+#define ST7735R_MY BIT(7)
+#define ST7735R_MX BIT(6)
+#define ST7735R_MV BIT(5)
+
+static void st7735r_pipe_enable(struct drm_simple_display_pipe *pipe,
+   struct drm_crtc_state *crtc_state)
+{
+   struct tinydrm_device *tdev = pipe_to_tinydrm(pipe);
+   struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev);
+   struct drm_framebuffer *fb = pipe->plane.fb;
+   struct device *dev = tdev->drm->dev;
+   int ret;
+   u8 addr_mode;
+
+   DRM_DEBUG_KMS("\n");
+
+   mipi_dbi_hw_reset(mipi);
+
+   ret = mipi_dbi_command(mipi, MIPI_DCS_SOFT_RESET);
+   if (ret) {
+   DRM_DEV_ERROR(dev, "Error sending command %d\n", ret);
+   return;
+   }
+
+   msleep(150);
+
+   mipi_dbi_command(mipi, MIPI_DCS_EXIT_SLEEP_MODE);
+   msleep(500);
+
+   mipi_dbi_command(mipi, ST7735R_FRMCTR1, 0x01, 0x2c, 0x2d);
+   mipi_dbi_command(mipi, ST7735R_FRMCTR2, 0x01, 0x2c, 0x2d);
+   mipi_dbi_command(mipi, ST7735R_FRMCTR3, 0x01, 0x2c, 0x2d, 0x01, 0x2c,
+0x2d);
+   mipi_dbi_command(mipi, ST7735R_INVCTR, 0x07);
+   mipi_dbi_command(mipi, ST7735R_PWCTR1, 0xa2, 0x02, 0x84);
+   mipi_dbi_command(mipi, ST7735R_PWCTR2, 0xc5);
+   mipi_dbi_command(mipi, ST7735R_PWCTR3, 0x0a, 0x00);
+   mipi_dbi_command(mipi, ST7735R_PWCTR4, 0x8a, 0x2a);
+   mipi_dbi_command(mipi, ST7735R_PWCTR5, 0x8a, 0xee);
+   mipi_dbi_command(mipi, 

Re: [PATCH v1 2/2] drm/tinydrm: add driver for ILI9225 panels

2017-12-01 Thread Noralf Trønnes

(cc: Thierry)

Den 01.12.2017 15.03, skrev Linus Walleij:

On Wed, Nov 8, 2017 at 4:52 AM, David Lechner  wrote:


This adds a new driver for display panels based on the Ilitek ILI9225
controller.

This was developed for a no-name panel with a red PCB that is commonly
marketed for Arduino. See .

I really did try very hard to find a make and model for this panel, but
there doesn't seem to be one, so the best I can do is offer the picture
in the link above for identification.

Signed-off-by: David Lechner 

Can you explain why tinydrm is not putting its panel drivers in
drivers/gpu/drm/panel?


The short answer is that tinydrm sends pixel data over the panel
controller's control interface whereas drm/panel leaves that to a
dedicated pixel interface fed by another driver.

tinydrm is used with controllers that have onboard GRAM which is
scanned out by the panel controller itself. Many of these controllers
support multiple interfaces, like MIPI DSI/DPI/DBI. A MIPI DPI
compatible controller has a control bus, usually SPI, to operate the
panel. This same control bus can be used in MIPI DBI mode on some
controllers to push pixels.

The MIPI standard documents isn't open, but some are available if you
do a search. We also have MIPI DCS which is the command set shared by
the MIPI compatible controllers.

So how do we deal with controllers that can operate in many modes?
I raised the question when a panel driver was reviewed earlier this
year, but nothing really came out of it.

I suppose that displays that are used with DSI/DPI doesn't have a
controller with onboard GRAM, since that would just increase the price.
The MIPI standard defines different controller types which has no,
partial or full framebuffer. So in reality it's not that likely that
we will see the same controller used both in tinydrm and drm/panel.

But I'm hardly an expert on these matters, I've only used the DBI mode.
I've cc'ed the drm/panel maintainer, maybe he can shed some more light.

Noralf.


I guess everybody knows except me, it's usually like that :(

I am anyways working on a driver for Ilitek 9322 that I want
to land in drivers/gpu/drm/panel. Here is the last iteration:
https://lists.freedesktop.org/archives/dri-devel/2017-August/150205.html
Yeah I got sidetracked. OK I will get to it now.

There are some similarities with the code I'm seeing here
but I believe they are essentially different. But it will be hard
to share code if you put the driver in the tinydrm framework.

I guess you have also seen:
drivers/video/backlight/ili922x.c
?

Stefano Babic who wrote the backlight driver is available for
reviewing, so includ him in follow-ups (added to To: line).

I'm putting you on CC as I'm rewriting it a bit after the DT
maintainers review, will try to repost ASAP.

Yours,
Linus Walleij
___
dri-devel mailing list
dri-de...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel





Re: [PATCH v1 2/2] drm/tinydrm: add driver for ILI9225 panels

2017-12-01 Thread Noralf Trønnes

(cc: Thierry)

Den 01.12.2017 15.03, skrev Linus Walleij:

On Wed, Nov 8, 2017 at 4:52 AM, David Lechner  wrote:


This adds a new driver for display panels based on the Ilitek ILI9225
controller.

This was developed for a no-name panel with a red PCB that is commonly
marketed for Arduino. See .

I really did try very hard to find a make and model for this panel, but
there doesn't seem to be one, so the best I can do is offer the picture
in the link above for identification.

Signed-off-by: David Lechner 

Can you explain why tinydrm is not putting its panel drivers in
drivers/gpu/drm/panel?


The short answer is that tinydrm sends pixel data over the panel
controller's control interface whereas drm/panel leaves that to a
dedicated pixel interface fed by another driver.

tinydrm is used with controllers that have onboard GRAM which is
scanned out by the panel controller itself. Many of these controllers
support multiple interfaces, like MIPI DSI/DPI/DBI. A MIPI DPI
compatible controller has a control bus, usually SPI, to operate the
panel. This same control bus can be used in MIPI DBI mode on some
controllers to push pixels.

The MIPI standard documents isn't open, but some are available if you
do a search. We also have MIPI DCS which is the command set shared by
the MIPI compatible controllers.

So how do we deal with controllers that can operate in many modes?
I raised the question when a panel driver was reviewed earlier this
year, but nothing really came out of it.

I suppose that displays that are used with DSI/DPI doesn't have a
controller with onboard GRAM, since that would just increase the price.
The MIPI standard defines different controller types which has no,
partial or full framebuffer. So in reality it's not that likely that
we will see the same controller used both in tinydrm and drm/panel.

But I'm hardly an expert on these matters, I've only used the DBI mode.
I've cc'ed the drm/panel maintainer, maybe he can shed some more light.

Noralf.


I guess everybody knows except me, it's usually like that :(

I am anyways working on a driver for Ilitek 9322 that I want
to land in drivers/gpu/drm/panel. Here is the last iteration:
https://lists.freedesktop.org/archives/dri-devel/2017-August/150205.html
Yeah I got sidetracked. OK I will get to it now.

There are some similarities with the code I'm seeing here
but I believe they are essentially different. But it will be hard
to share code if you put the driver in the tinydrm framework.

I guess you have also seen:
drivers/video/backlight/ili922x.c
?

Stefano Babic who wrote the backlight driver is available for
reviewing, so includ him in follow-ups (added to To: line).

I'm putting you on CC as I'm rewriting it a bit after the DT
maintainers review, will try to repost ASAP.

Yours,
Linus Walleij
___
dri-devel mailing list
dri-de...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel





Re: [PATCH v2 0/4] DRM driver for ILI9225 display panels

2017-12-01 Thread Noralf Trønnes


Den 19.11.2017 21.12, skrev David Lechner:

This is a new driver for ILI9225 based display panels.


Thanks, applied to drm-misc.

Noralf.


v2 changes:
* New patch for ilitek vendor prefix.
* Use "ilitek" instead of "generic" in dt-bindings
* New patch to export 2 mipi_dbi_* functions
* Clean up ILI9225 driver based on feedback

David Lechner (4):
   dt-bindings: Add vendor prefix for ilitek
   dt-bindings: Add binding for Ilitek ILI9225 display panels
   drm/tinydrm: export mipi_dbi_buf_copy and mipi_dbi_spi_cmd_max_speed
   drm/tinydrm: add driver for ILI9225 panels

  .../devicetree/bindings/display/ilitek,ili9225.txt |  25 ++
  .../devicetree/bindings/vendor-prefixes.txt|   1 +
  MAINTAINERS|   6 +
  drivers/gpu/drm/tinydrm/Kconfig|  10 +
  drivers/gpu/drm/tinydrm/Makefile   |   1 +
  drivers/gpu/drm/tinydrm/ili9225.c  | 468 +
  drivers/gpu/drm/tinydrm/mipi-dbi.c |  24 +-
  include/drm/tinydrm/mipi-dbi.h |   4 +-
  8 files changed, 534 insertions(+), 5 deletions(-)
  create mode 100644 
Documentation/devicetree/bindings/display/ilitek,ili9225.txt
  create mode 100644 drivers/gpu/drm/tinydrm/ili9225.c





Re: [PATCH v2 0/4] DRM driver for ILI9225 display panels

2017-12-01 Thread Noralf Trønnes


Den 19.11.2017 21.12, skrev David Lechner:

This is a new driver for ILI9225 based display panels.


Thanks, applied to drm-misc.

Noralf.


v2 changes:
* New patch for ilitek vendor prefix.
* Use "ilitek" instead of "generic" in dt-bindings
* New patch to export 2 mipi_dbi_* functions
* Clean up ILI9225 driver based on feedback

David Lechner (4):
   dt-bindings: Add vendor prefix for ilitek
   dt-bindings: Add binding for Ilitek ILI9225 display panels
   drm/tinydrm: export mipi_dbi_buf_copy and mipi_dbi_spi_cmd_max_speed
   drm/tinydrm: add driver for ILI9225 panels

  .../devicetree/bindings/display/ilitek,ili9225.txt |  25 ++
  .../devicetree/bindings/vendor-prefixes.txt|   1 +
  MAINTAINERS|   6 +
  drivers/gpu/drm/tinydrm/Kconfig|  10 +
  drivers/gpu/drm/tinydrm/Makefile   |   1 +
  drivers/gpu/drm/tinydrm/ili9225.c  | 468 +
  drivers/gpu/drm/tinydrm/mipi-dbi.c |  24 +-
  include/drm/tinydrm/mipi-dbi.h |   4 +-
  8 files changed, 534 insertions(+), 5 deletions(-)
  create mode 100644 
Documentation/devicetree/bindings/display/ilitek,ili9225.txt
  create mode 100644 drivers/gpu/drm/tinydrm/ili9225.c





Re: [PATCH v2 4/4] drm/tinydrm: add driver for ILI9225 panels

2017-11-22 Thread Noralf Trønnes


Den 19.11.2017 21.12, skrev David Lechner:

This adds a new driver for display panels based on the Ilitek ILI9225
controller.

This was developed for a no-name panel with a red PCB that is commonly
marketed for Arduino. See <https://github.com/Nkawu/TFT_22_ILI9225>.

Signed-off-by: David Lechner <da...@lechnology.com>
---


Reviewed-by: Noralf Trønnes <nor...@tronnes.org>


v2 changes:
* use exported mipi_dbi_* functions from patch 3/4
* new ili9225_command function

  MAINTAINERS   |   6 +
  drivers/gpu/drm/tinydrm/Kconfig   |  10 +
  drivers/gpu/drm/tinydrm/Makefile  |   1 +
  drivers/gpu/drm/tinydrm/ili9225.c | 468 ++
  4 files changed, 485 insertions(+)
  create mode 100644 drivers/gpu/drm/tinydrm/ili9225.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 0d77f22..72404f3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4372,6 +4372,12 @@ T:   git git://anongit.freedesktop.org/drm/drm-misc
  S:Maintained
  F:drivers/gpu/drm/tve200/
  
+DRM DRIVER FOR ILITEK ILI9225 PANELS

+M: David Lechner <da...@lechnology.com>
+S: Maintained
+F: drivers/gpu/drm/tinydrm/ili9225.c
+F: Documentation/devicetree/bindings/display/ili9225.txt
+
  DRM DRIVER FOR INTEL I810 VIDEO CARDS
  S:Orphan / Obsolete
  F:drivers/gpu/drm/i810/
diff --git a/drivers/gpu/drm/tinydrm/Kconfig b/drivers/gpu/drm/tinydrm/Kconfig
index 2e790e7..90c5bd5 100644
--- a/drivers/gpu/drm/tinydrm/Kconfig
+++ b/drivers/gpu/drm/tinydrm/Kconfig
@@ -12,6 +12,16 @@ menuconfig DRM_TINYDRM
  config TINYDRM_MIPI_DBI
tristate
  
+config TINYDRM_ILI9225

+   tristate "DRM support for ILI9225 display panels"
+   depends on DRM_TINYDRM && SPI
+   select TINYDRM_MIPI_DBI
+   help
+ DRM driver for the following Ilitek ILI9225 panels:
+ * No-name 2.2" color screen module
+
+ If M is selected the module will be called ili9225.
+
  config TINYDRM_MI0283QT
tristate "DRM support for MI0283QT"
depends on DRM_TINYDRM && SPI
diff --git a/drivers/gpu/drm/tinydrm/Makefile b/drivers/gpu/drm/tinydrm/Makefile
index 0c184bd..8aeee53 100644
--- a/drivers/gpu/drm/tinydrm/Makefile
+++ b/drivers/gpu/drm/tinydrm/Makefile
@@ -4,6 +4,7 @@ obj-$(CONFIG_DRM_TINYDRM)   += core/
  obj-$(CONFIG_TINYDRM_MIPI_DBI)+= mipi-dbi.o
  
  # Displays

+obj-$(CONFIG_TINYDRM_ILI9225)  += ili9225.o
  obj-$(CONFIG_TINYDRM_MI0283QT)+= mi0283qt.o
  obj-$(CONFIG_TINYDRM_REPAPER) += repaper.o
  obj-$(CONFIG_TINYDRM_ST7586)  += st7586.o
diff --git a/drivers/gpu/drm/tinydrm/ili9225.c 
b/drivers/gpu/drm/tinydrm/ili9225.c
new file mode 100644
index 000..3b766a2
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/ili9225.c
@@ -0,0 +1,468 @@
+/*
+ * DRM driver for Ilitek ILI9225 panels
+ *
+ * Copyright 2017 David Lechner <da...@lechnology.com>
+ *
+ * Some code copied from mipi-dbi.c
+ * Copyright 2016 Noralf Trønnes
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#define ILI9225_DRIVER_READ_CODE   0x00
+#define ILI9225_DRIVER_OUTPUT_CONTROL  0x01
+#define ILI9225_LCD_AC_DRIVING_CONTROL 0x02
+#define ILI9225_ENTRY_MODE 0x03
+#define ILI9225_DISPLAY_CONTROL_1  0x07
+#define ILI9225_BLANK_PERIOD_CONTROL_1 0x08
+#define ILI9225_FRAME_CYCLE_CONTROL0x0b
+#define ILI9225_INTERFACE_CONTROL  0x0c
+#define ILI9225_OSCILLATION_CONTROL0x0f
+#define ILI9225_POWER_CONTROL_10x10
+#define ILI9225_POWER_CONTROL_20x11
+#define ILI9225_POWER_CONTROL_30x12
+#define ILI9225_POWER_CONTROL_40x13
+#define ILI9225_POWER_CONTROL_50x14
+#define ILI9225_VCI_RECYCLING  0x15
+#define ILI9225_RAM_ADDRESS_SET_1  0x20
+#define ILI9225_RAM_ADDRESS_SET_2  0x21
+#define ILI9225_WRITE_DATA_TO_GRAM 0x22
+#define ILI9225_SOFTWARE_RESET 0x28
+#define ILI9225_GATE_SCAN_CONTROL  0x30
+#define ILI9225_VERTICAL_SCROLL_1  0x31
+#define ILI9225_VERTICAL_SCROLL_2  0x32
+#define ILI9225_VERTICAL_SCROLL_3  0x33
+#define ILI9225_PARTIAL_DRIVING_POS_1  0x34
+#define ILI9225_PARTIAL_DRIVING_POS_2  0x35
+#define ILI9225_HORIZ_WINDOW_ADDR_10x36
+#define ILI9225_HORIZ_WINDOW_ADDR_20x37
+#define ILI9225_VERT_WINDOW_ADDR_1 0x38
+#define ILI9225_VERT_WINDOW_ADDR_2 0x39
+#define ILI9225_GAMMA_CONTROL_10x50
+#define ILI9225_GAMMA_CONTROL_20x51
+#define ILI9225_GAMMA_CONTROL_30x52
+#define ILI9225_GAMMA_CONTROL_4   

Re: [PATCH v2 4/4] drm/tinydrm: add driver for ILI9225 panels

2017-11-22 Thread Noralf Trønnes


Den 19.11.2017 21.12, skrev David Lechner:

This adds a new driver for display panels based on the Ilitek ILI9225
controller.

This was developed for a no-name panel with a red PCB that is commonly
marketed for Arduino. See <https://github.com/Nkawu/TFT_22_ILI9225>.

Signed-off-by: David Lechner 
---


Reviewed-by: Noralf Trønnes 


v2 changes:
* use exported mipi_dbi_* functions from patch 3/4
* new ili9225_command function

  MAINTAINERS   |   6 +
  drivers/gpu/drm/tinydrm/Kconfig   |  10 +
  drivers/gpu/drm/tinydrm/Makefile  |   1 +
  drivers/gpu/drm/tinydrm/ili9225.c | 468 ++
  4 files changed, 485 insertions(+)
  create mode 100644 drivers/gpu/drm/tinydrm/ili9225.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 0d77f22..72404f3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4372,6 +4372,12 @@ T:   git git://anongit.freedesktop.org/drm/drm-misc
  S:Maintained
  F:drivers/gpu/drm/tve200/
  
+DRM DRIVER FOR ILITEK ILI9225 PANELS

+M: David Lechner 
+S: Maintained
+F: drivers/gpu/drm/tinydrm/ili9225.c
+F: Documentation/devicetree/bindings/display/ili9225.txt
+
  DRM DRIVER FOR INTEL I810 VIDEO CARDS
  S:Orphan / Obsolete
  F:drivers/gpu/drm/i810/
diff --git a/drivers/gpu/drm/tinydrm/Kconfig b/drivers/gpu/drm/tinydrm/Kconfig
index 2e790e7..90c5bd5 100644
--- a/drivers/gpu/drm/tinydrm/Kconfig
+++ b/drivers/gpu/drm/tinydrm/Kconfig
@@ -12,6 +12,16 @@ menuconfig DRM_TINYDRM
  config TINYDRM_MIPI_DBI
tristate
  
+config TINYDRM_ILI9225

+   tristate "DRM support for ILI9225 display panels"
+   depends on DRM_TINYDRM && SPI
+   select TINYDRM_MIPI_DBI
+   help
+ DRM driver for the following Ilitek ILI9225 panels:
+ * No-name 2.2" color screen module
+
+ If M is selected the module will be called ili9225.
+
  config TINYDRM_MI0283QT
tristate "DRM support for MI0283QT"
depends on DRM_TINYDRM && SPI
diff --git a/drivers/gpu/drm/tinydrm/Makefile b/drivers/gpu/drm/tinydrm/Makefile
index 0c184bd..8aeee53 100644
--- a/drivers/gpu/drm/tinydrm/Makefile
+++ b/drivers/gpu/drm/tinydrm/Makefile
@@ -4,6 +4,7 @@ obj-$(CONFIG_DRM_TINYDRM)   += core/
  obj-$(CONFIG_TINYDRM_MIPI_DBI)+= mipi-dbi.o
  
  # Displays

+obj-$(CONFIG_TINYDRM_ILI9225)  += ili9225.o
  obj-$(CONFIG_TINYDRM_MI0283QT)+= mi0283qt.o
  obj-$(CONFIG_TINYDRM_REPAPER) += repaper.o
  obj-$(CONFIG_TINYDRM_ST7586)  += st7586.o
diff --git a/drivers/gpu/drm/tinydrm/ili9225.c 
b/drivers/gpu/drm/tinydrm/ili9225.c
new file mode 100644
index 000..3b766a2
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/ili9225.c
@@ -0,0 +1,468 @@
+/*
+ * DRM driver for Ilitek ILI9225 panels
+ *
+ * Copyright 2017 David Lechner 
+ *
+ * Some code copied from mipi-dbi.c
+ * Copyright 2016 Noralf Trønnes
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#define ILI9225_DRIVER_READ_CODE   0x00
+#define ILI9225_DRIVER_OUTPUT_CONTROL  0x01
+#define ILI9225_LCD_AC_DRIVING_CONTROL 0x02
+#define ILI9225_ENTRY_MODE 0x03
+#define ILI9225_DISPLAY_CONTROL_1  0x07
+#define ILI9225_BLANK_PERIOD_CONTROL_1 0x08
+#define ILI9225_FRAME_CYCLE_CONTROL0x0b
+#define ILI9225_INTERFACE_CONTROL  0x0c
+#define ILI9225_OSCILLATION_CONTROL0x0f
+#define ILI9225_POWER_CONTROL_10x10
+#define ILI9225_POWER_CONTROL_20x11
+#define ILI9225_POWER_CONTROL_30x12
+#define ILI9225_POWER_CONTROL_40x13
+#define ILI9225_POWER_CONTROL_50x14
+#define ILI9225_VCI_RECYCLING  0x15
+#define ILI9225_RAM_ADDRESS_SET_1  0x20
+#define ILI9225_RAM_ADDRESS_SET_2  0x21
+#define ILI9225_WRITE_DATA_TO_GRAM 0x22
+#define ILI9225_SOFTWARE_RESET 0x28
+#define ILI9225_GATE_SCAN_CONTROL  0x30
+#define ILI9225_VERTICAL_SCROLL_1  0x31
+#define ILI9225_VERTICAL_SCROLL_2  0x32
+#define ILI9225_VERTICAL_SCROLL_3  0x33
+#define ILI9225_PARTIAL_DRIVING_POS_1  0x34
+#define ILI9225_PARTIAL_DRIVING_POS_2  0x35
+#define ILI9225_HORIZ_WINDOW_ADDR_10x36
+#define ILI9225_HORIZ_WINDOW_ADDR_20x37
+#define ILI9225_VERT_WINDOW_ADDR_1 0x38
+#define ILI9225_VERT_WINDOW_ADDR_2 0x39
+#define ILI9225_GAMMA_CONTROL_10x50
+#define ILI9225_GAMMA_CONTROL_20x51
+#define ILI9225_GAMMA_CONTROL_30x52
+#define ILI9225_GAMMA_CONTROL_40x53
+#define ILI9225_GAMMA_CONTROL_50x54
+#define ILI9225_GAMMA_CONTROL_60x55
+#define ILI92

Re: [PATCH v2 3/4] drm/tinydrm: export mipi_dbi_buf_copy and mipi_dbi_spi_cmd_max_speed

2017-11-22 Thread Noralf Trønnes


Den 19.11.2017 21.12, skrev David Lechner:

This exports the mipi_dbi_buf_copy() and mipi_dbi_spi_cmd_max_speed()
functions so that they can be shared with other drivers.

Signed-off-by: David Lechner <da...@lechnology.com>
---


Reviewed-by: Noralf Trønnes <nor...@tronnes.org>


v2 changes:
* new patch in v2

  drivers/gpu/drm/tinydrm/mipi-dbi.c | 24 
  include/drm/tinydrm/mipi-dbi.h |  4 +++-
  2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/mipi-dbi.c 
b/drivers/gpu/drm/tinydrm/mipi-dbi.c
index 347f9b2..aa6b6ce 100644
--- a/drivers/gpu/drm/tinydrm/mipi-dbi.c
+++ b/drivers/gpu/drm/tinydrm/mipi-dbi.c
@@ -154,8 +154,18 @@ int mipi_dbi_command_buf(struct mipi_dbi *mipi, u8 cmd, u8 
*data, size_t len)
  }
  EXPORT_SYMBOL(mipi_dbi_command_buf);
  
-static int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,

-   struct drm_clip_rect *clip, bool swap)
+/**
+ * mipi_dbi_buf_copy - Copy a framebuffer, transforming it if necessary
+ * @dst: The destination buffer
+ * @fb: The source framebuffer
+ * @clip: Clipping rectangle of the area to be copied
+ * @swap: When true, swap MSB/LSB of 16-bit values
+ *
+ * Returns:
+ * Zero on success, negative error code on failure.
+ */
+int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
+ struct drm_clip_rect *clip, bool swap)
  {
struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
struct dma_buf_attachment *import_attach = cma_obj->base.import_attach;
@@ -192,6 +202,7 @@ static int mipi_dbi_buf_copy(void *dst, struct 
drm_framebuffer *fb,
 DMA_FROM_DEVICE);
return ret;
  }
+EXPORT_SYMBOL(mipi_dbi_buf_copy);
  
  static int mipi_dbi_fb_dirty(struct drm_framebuffer *fb,

 struct drm_file *file_priv,
@@ -444,18 +455,23 @@ EXPORT_SYMBOL(mipi_dbi_display_is_on);
  
  #if IS_ENABLED(CONFIG_SPI)
  
-/*

+/**
+ * mipi_dbi_spi_cmd_max_speed - get the maximum SPI bus speed
+ * @spi: SPI device
+ * @len: The transfer buffer length.
+ *
   * Many controllers have a max speed of 10MHz, but can be pushed way beyond
   * that. Increase reliability by running pixel data at max speed and the rest
   * at 10MHz, preventing transfer glitches from messing up the init settings.
   */
-static u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len)
+u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len)
  {
if (len > 64)
return 0; /* use default */
  
  	return min_t(u32, 1000, spi->max_speed_hz);

  }
+EXPORT_SYMBOL(mipi_dbi_spi_cmd_max_speed);
  
  /*

   * MIPI DBI Type C Option 1
diff --git a/include/drm/tinydrm/mipi-dbi.h b/include/drm/tinydrm/mipi-dbi.h
index 83346dd..5d0e82b 100644
--- a/include/drm/tinydrm/mipi-dbi.h
+++ b/include/drm/tinydrm/mipi-dbi.h
@@ -72,10 +72,12 @@ void mipi_dbi_pipe_enable(struct drm_simple_display_pipe 
*pipe,
  void mipi_dbi_pipe_disable(struct drm_simple_display_pipe *pipe);
  void mipi_dbi_hw_reset(struct mipi_dbi *mipi);
  bool mipi_dbi_display_is_on(struct mipi_dbi *mipi);
+u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len);
  
  int mipi_dbi_command_read(struct mipi_dbi *mipi, u8 cmd, u8 *val);

  int mipi_dbi_command_buf(struct mipi_dbi *mipi, u8 cmd, u8 *data, size_t len);
-
+int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
+ struct drm_clip_rect *clip, bool swap);
  /**
   * mipi_dbi_command - MIPI DCS command with optional parameter(s)
   * @mipi: MIPI structure




Re: [PATCH v2 3/4] drm/tinydrm: export mipi_dbi_buf_copy and mipi_dbi_spi_cmd_max_speed

2017-11-22 Thread Noralf Trønnes


Den 19.11.2017 21.12, skrev David Lechner:

This exports the mipi_dbi_buf_copy() and mipi_dbi_spi_cmd_max_speed()
functions so that they can be shared with other drivers.

Signed-off-by: David Lechner 
---


Reviewed-by: Noralf Trønnes 


v2 changes:
* new patch in v2

  drivers/gpu/drm/tinydrm/mipi-dbi.c | 24 
  include/drm/tinydrm/mipi-dbi.h |  4 +++-
  2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/mipi-dbi.c 
b/drivers/gpu/drm/tinydrm/mipi-dbi.c
index 347f9b2..aa6b6ce 100644
--- a/drivers/gpu/drm/tinydrm/mipi-dbi.c
+++ b/drivers/gpu/drm/tinydrm/mipi-dbi.c
@@ -154,8 +154,18 @@ int mipi_dbi_command_buf(struct mipi_dbi *mipi, u8 cmd, u8 
*data, size_t len)
  }
  EXPORT_SYMBOL(mipi_dbi_command_buf);
  
-static int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,

-   struct drm_clip_rect *clip, bool swap)
+/**
+ * mipi_dbi_buf_copy - Copy a framebuffer, transforming it if necessary
+ * @dst: The destination buffer
+ * @fb: The source framebuffer
+ * @clip: Clipping rectangle of the area to be copied
+ * @swap: When true, swap MSB/LSB of 16-bit values
+ *
+ * Returns:
+ * Zero on success, negative error code on failure.
+ */
+int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
+ struct drm_clip_rect *clip, bool swap)
  {
struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
struct dma_buf_attachment *import_attach = cma_obj->base.import_attach;
@@ -192,6 +202,7 @@ static int mipi_dbi_buf_copy(void *dst, struct 
drm_framebuffer *fb,
 DMA_FROM_DEVICE);
return ret;
  }
+EXPORT_SYMBOL(mipi_dbi_buf_copy);
  
  static int mipi_dbi_fb_dirty(struct drm_framebuffer *fb,

 struct drm_file *file_priv,
@@ -444,18 +455,23 @@ EXPORT_SYMBOL(mipi_dbi_display_is_on);
  
  #if IS_ENABLED(CONFIG_SPI)
  
-/*

+/**
+ * mipi_dbi_spi_cmd_max_speed - get the maximum SPI bus speed
+ * @spi: SPI device
+ * @len: The transfer buffer length.
+ *
   * Many controllers have a max speed of 10MHz, but can be pushed way beyond
   * that. Increase reliability by running pixel data at max speed and the rest
   * at 10MHz, preventing transfer glitches from messing up the init settings.
   */
-static u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len)
+u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len)
  {
if (len > 64)
return 0; /* use default */
  
  	return min_t(u32, 1000, spi->max_speed_hz);

  }
+EXPORT_SYMBOL(mipi_dbi_spi_cmd_max_speed);
  
  /*

   * MIPI DBI Type C Option 1
diff --git a/include/drm/tinydrm/mipi-dbi.h b/include/drm/tinydrm/mipi-dbi.h
index 83346dd..5d0e82b 100644
--- a/include/drm/tinydrm/mipi-dbi.h
+++ b/include/drm/tinydrm/mipi-dbi.h
@@ -72,10 +72,12 @@ void mipi_dbi_pipe_enable(struct drm_simple_display_pipe 
*pipe,
  void mipi_dbi_pipe_disable(struct drm_simple_display_pipe *pipe);
  void mipi_dbi_hw_reset(struct mipi_dbi *mipi);
  bool mipi_dbi_display_is_on(struct mipi_dbi *mipi);
+u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len);
  
  int mipi_dbi_command_read(struct mipi_dbi *mipi, u8 cmd, u8 *val);

  int mipi_dbi_command_buf(struct mipi_dbi *mipi, u8 cmd, u8 *data, size_t len);
-
+int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
+ struct drm_clip_rect *clip, bool swap);
  /**
   * mipi_dbi_command - MIPI DCS command with optional parameter(s)
   * @mipi: MIPI structure




Re: [PATCH v2] drm: gem_cma_helper.c: Allow importing of contiguous scatterlists with nents > 1

2017-11-15 Thread Noralf Trønnes


Den 15.11.2017 14.04, skrev Liviu Dudau:

Hi,

On Sat, Nov 11, 2017 at 02:47:35PM +0200, Laurent Pinchart wrote:

Hi Liviu,

Thank you for the patch.

On Friday, 10 November 2017 15:33:10 EET Liviu Dudau wrote:

drm_gem_cma_prime_import_sg_table() will fail if the number of entries
in the sg_table > 1. However, you can have a device that uses an IOMMU
engine and can map a discontiguous buffer with multiple entries that
have consecutive sg_dma_addresses, effectively making it contiguous.
Allow for that scenario by testing the entries in the sg_table for
contiguous coverage.

Reviewed-by: Laurent Pinchart 
Signed-off-by: Liviu Dudau 
---

Laurent,

Thanks for the review! I would like to ask for one more favour: if you
are OK with this version, can you pull this patch through the drm-misc tree?

I could, but I'd first need to set dim up, and I'm currently abroad with a bad
internet connection and a big deadline for the middle of next week (I know,
lots of excuses), so it's not very convenient for me at this time.

Any other drm-misc maintainers feeling helpful and willing to take this
patch in?


Sure, I can do it this evening.

Noralf.


  Otherwise I can send it through the mali-dp tree if no one
objects.

Best regards,
Liviu


  drivers/gpu/drm/drm_gem_cma_helper.c | 22 --
  include/drm/drm_gem_cma_helper.h |  4 +++-
  2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c
b/drivers/gpu/drm/drm_gem_cma_helper.c index 020e7668dfaba..43b179212052d
100644
--- a/drivers/gpu/drm/drm_gem_cma_helper.c
+++ b/drivers/gpu/drm/drm_gem_cma_helper.c
@@ -482,8 +482,26 @@ drm_gem_cma_prime_import_sg_table(struct drm_device
*dev, {
struct drm_gem_cma_object *cma_obj;

-   if (sgt->nents != 1)
-   return ERR_PTR(-EINVAL);
+   if (sgt->nents != 1) {
+   /* check if the entries in the sg_table are contiguous */
+   dma_addr_t next_addr = sg_dma_address(sgt->sgl);
+   struct scatterlist *s;
+   unsigned int i;
+
+   for_each_sg(sgt->sgl, s, sgt->nents, i) {
+   /*
+* sg_dma_address(s) is only valid for entries
+* that have sg_dma_len(s) != 0
+*/
+   if (!sg_dma_len(s))
+   continue;
+
+   if (sg_dma_address(s) != next_addr)
+   return ERR_PTR(-EINVAL);
+
+   next_addr = sg_dma_address(s) + sg_dma_len(s);
+   }
+   }

/* Create a CMA GEM buffer. */
cma_obj = __drm_gem_cma_create(dev, attach->dmabuf->size);
diff --git a/include/drm/drm_gem_cma_helper.h
b/include/drm/drm_gem_cma_helper.h index 58a739bf15f1f..214aa85adc8d5
100644
--- a/include/drm/drm_gem_cma_helper.h
+++ b/include/drm/drm_gem_cma_helper.h
@@ -8,7 +8,9 @@
   * struct drm_gem_cma_object - GEM object backed by CMA memory allocations
   * @base: base GEM object
   * @paddr: physical address of the backing memory
- * @sgt: scatter/gather table for imported PRIME buffers
+ * @sgt: scatter/gather table for imported PRIME buffers. The table can
have + *   more than one entry but they are guaranteed to have
contiguous + *   DMA addresses.
   * @vaddr: kernel virtual address of the backing memory
   */
  struct drm_gem_cma_object {

--
Regards,

Laurent Pinchart





Re: [PATCH v2] drm: gem_cma_helper.c: Allow importing of contiguous scatterlists with nents > 1

2017-11-15 Thread Noralf Trønnes


Den 15.11.2017 14.04, skrev Liviu Dudau:

Hi,

On Sat, Nov 11, 2017 at 02:47:35PM +0200, Laurent Pinchart wrote:

Hi Liviu,

Thank you for the patch.

On Friday, 10 November 2017 15:33:10 EET Liviu Dudau wrote:

drm_gem_cma_prime_import_sg_table() will fail if the number of entries
in the sg_table > 1. However, you can have a device that uses an IOMMU
engine and can map a discontiguous buffer with multiple entries that
have consecutive sg_dma_addresses, effectively making it contiguous.
Allow for that scenario by testing the entries in the sg_table for
contiguous coverage.

Reviewed-by: Laurent Pinchart 
Signed-off-by: Liviu Dudau 
---

Laurent,

Thanks for the review! I would like to ask for one more favour: if you
are OK with this version, can you pull this patch through the drm-misc tree?

I could, but I'd first need to set dim up, and I'm currently abroad with a bad
internet connection and a big deadline for the middle of next week (I know,
lots of excuses), so it's not very convenient for me at this time.

Any other drm-misc maintainers feeling helpful and willing to take this
patch in?


Sure, I can do it this evening.

Noralf.


  Otherwise I can send it through the mali-dp tree if no one
objects.

Best regards,
Liviu


  drivers/gpu/drm/drm_gem_cma_helper.c | 22 --
  include/drm/drm_gem_cma_helper.h |  4 +++-
  2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c
b/drivers/gpu/drm/drm_gem_cma_helper.c index 020e7668dfaba..43b179212052d
100644
--- a/drivers/gpu/drm/drm_gem_cma_helper.c
+++ b/drivers/gpu/drm/drm_gem_cma_helper.c
@@ -482,8 +482,26 @@ drm_gem_cma_prime_import_sg_table(struct drm_device
*dev, {
struct drm_gem_cma_object *cma_obj;

-   if (sgt->nents != 1)
-   return ERR_PTR(-EINVAL);
+   if (sgt->nents != 1) {
+   /* check if the entries in the sg_table are contiguous */
+   dma_addr_t next_addr = sg_dma_address(sgt->sgl);
+   struct scatterlist *s;
+   unsigned int i;
+
+   for_each_sg(sgt->sgl, s, sgt->nents, i) {
+   /*
+* sg_dma_address(s) is only valid for entries
+* that have sg_dma_len(s) != 0
+*/
+   if (!sg_dma_len(s))
+   continue;
+
+   if (sg_dma_address(s) != next_addr)
+   return ERR_PTR(-EINVAL);
+
+   next_addr = sg_dma_address(s) + sg_dma_len(s);
+   }
+   }

/* Create a CMA GEM buffer. */
cma_obj = __drm_gem_cma_create(dev, attach->dmabuf->size);
diff --git a/include/drm/drm_gem_cma_helper.h
b/include/drm/drm_gem_cma_helper.h index 58a739bf15f1f..214aa85adc8d5
100644
--- a/include/drm/drm_gem_cma_helper.h
+++ b/include/drm/drm_gem_cma_helper.h
@@ -8,7 +8,9 @@
   * struct drm_gem_cma_object - GEM object backed by CMA memory allocations
   * @base: base GEM object
   * @paddr: physical address of the backing memory
- * @sgt: scatter/gather table for imported PRIME buffers
+ * @sgt: scatter/gather table for imported PRIME buffers. The table can
have + *   more than one entry but they are guaranteed to have
contiguous + *   DMA addresses.
   * @vaddr: kernel virtual address of the backing memory
   */
  struct drm_gem_cma_object {

--
Regards,

Laurent Pinchart





Re: [PATCH v1 2/2] drm/tinydrm: add driver for ILI9225 panels

2017-11-10 Thread Noralf Trønnes


Den 08.11.2017 04.52, skrev David Lechner:

This adds a new driver for display panels based on the Ilitek ILI9225
controller.

This was developed for a no-name panel with a red PCB that is commonly
marketed for Arduino. See <https://github.com/Nkawu/TFT_22_ILI9225>.

I really did try very hard to find a make and model for this panel, but
there doesn't seem to be one, so the best I can do is offer the picture
in the link above for identification.

Signed-off-by: David Lechner <da...@lechnology.com>
---
  MAINTAINERS   |   6 +
  drivers/gpu/drm/tinydrm/Kconfig   |  10 +
  drivers/gpu/drm/tinydrm/Makefile  |   1 +
  drivers/gpu/drm/tinydrm/ili9225.c | 547 ++
  4 files changed, 564 insertions(+)
  create mode 100644 drivers/gpu/drm/tinydrm/ili9225.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 0d77f22..72404f3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4372,6 +4372,12 @@ T:   git git://anongit.freedesktop.org/drm/drm-misc
  S:Maintained
  F:drivers/gpu/drm/tve200/
  
+DRM DRIVER FOR ILITEK ILI9225 PANELS

+M: David Lechner <da...@lechnology.com>
+S: Maintained
+F: drivers/gpu/drm/tinydrm/ili9225.c
+F: Documentation/devicetree/bindings/display/ili9225.txt
+
  DRM DRIVER FOR INTEL I810 VIDEO CARDS
  S:Orphan / Obsolete
  F:drivers/gpu/drm/i810/
diff --git a/drivers/gpu/drm/tinydrm/Kconfig b/drivers/gpu/drm/tinydrm/Kconfig
index 2e790e7..90c5bd5 100644
--- a/drivers/gpu/drm/tinydrm/Kconfig
+++ b/drivers/gpu/drm/tinydrm/Kconfig
@@ -12,6 +12,16 @@ menuconfig DRM_TINYDRM
  config TINYDRM_MIPI_DBI
tristate
  
+config TINYDRM_ILI9225

+   tristate "DRM support for ILI9225 display panels"
+   depends on DRM_TINYDRM && SPI
+   select TINYDRM_MIPI_DBI
+   help
+ DRM driver for the following Ilitek ILI9225 panels:
+ * No-name 2.2" color screen module
+
+ If M is selected the module will be called ili9225.
+
  config TINYDRM_MI0283QT
tristate "DRM support for MI0283QT"
depends on DRM_TINYDRM && SPI
diff --git a/drivers/gpu/drm/tinydrm/Makefile b/drivers/gpu/drm/tinydrm/Makefile
index 0c184bd..8aeee53 100644
--- a/drivers/gpu/drm/tinydrm/Makefile
+++ b/drivers/gpu/drm/tinydrm/Makefile
@@ -4,6 +4,7 @@ obj-$(CONFIG_DRM_TINYDRM)   += core/
  obj-$(CONFIG_TINYDRM_MIPI_DBI)+= mipi-dbi.o
  
  # Displays

+obj-$(CONFIG_TINYDRM_ILI9225)  += ili9225.o
  obj-$(CONFIG_TINYDRM_MI0283QT)+= mi0283qt.o
  obj-$(CONFIG_TINYDRM_REPAPER) += repaper.o
  obj-$(CONFIG_TINYDRM_ST7586)  += st7586.o
diff --git a/drivers/gpu/drm/tinydrm/ili9225.c 
b/drivers/gpu/drm/tinydrm/ili9225.c
new file mode 100644
index 000..07e1b8b
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/ili9225.c
@@ -0,0 +1,547 @@
+/*
+ * DRM driver for Ilitek ILI9225 panels
+ *
+ * Copyright 2017 David Lechner <da...@lechnology.com>
+ *
+ * Lots of code copied from mipi-dbi.c
+ * Copyright 2016 Noralf Trønnes
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#define ILI9225_DRIVER_READ_CODE   0x00
+#define ILI9225_DRIVER_OUTPUT_CONTROL  0x01
+#define ILI9225_LCD_AC_DRIVING_CONTROL 0x02
+#define ILI9225_ENTRY_MODE 0x03
+#define ILI9225_DISPLAY_CONTROL_1  0x07
+#define ILI9225_BLANK_PERIOD_CONTROL_1 0x08
+#define ILI9225_FRAME_CYCLE_CONTROL0x0b
+#define ILI9225_INTERFACE_CONTROL  0x0c
+#define ILI9225_OSCILLATION_CONTROL0x0f
+#define ILI9225_POWER_CONTROL_10x10
+#define ILI9225_POWER_CONTROL_20x11
+#define ILI9225_POWER_CONTROL_30x12
+#define ILI9225_POWER_CONTROL_40x13
+#define ILI9225_POWER_CONTROL_50x14
+#define ILI9225_VCI_RECYCLING  0x15
+#define ILI9225_RAM_ADDRESS_SET_1  0x20
+#define ILI9225_RAM_ADDRESS_SET_2  0x21
+#define ILI9225_WRITE_DATA_TO_GRAM 0x22
+#define ILI9225_SOFTWARE_RESET 0x28
+#define ILI9225_GATE_SCAN_CONTROL  0x30
+#define ILI9225_VERTICAL_SCROLL_1  0x31
+#define ILI9225_VERTICAL_SCROLL_2  0x32
+#define ILI9225_VERTICAL_SCROLL_3  0x33
+#define ILI9225_PARTIAL_DRIVING_POS_1  0x34
+#define ILI9225_PARTIAL_DRIVING_POS_2  0x35
+#define ILI9225_HORIZ_WINDOW_ADDR_10x36
+#define ILI9225_HORIZ_WINDOW_ADDR_20x37
+#define ILI9225_VERT_WINDOW_ADDR_1 0x38
+#define ILI9225_VERT_WINDOW_ADDR_2 0x39
+#define ILI9225_GAMMA_CONTROL_10x50
+#define ILI9225_GAMMA_CONTROL_20x51
+#define ILI9225_GAMMA_CONTROL_30x52
+#define ILI9225_GAM

Re: [PATCH v1 2/2] drm/tinydrm: add driver for ILI9225 panels

2017-11-10 Thread Noralf Trønnes


Den 08.11.2017 04.52, skrev David Lechner:

This adds a new driver for display panels based on the Ilitek ILI9225
controller.

This was developed for a no-name panel with a red PCB that is commonly
marketed for Arduino. See <https://github.com/Nkawu/TFT_22_ILI9225>.

I really did try very hard to find a make and model for this panel, but
there doesn't seem to be one, so the best I can do is offer the picture
in the link above for identification.

Signed-off-by: David Lechner 
---
  MAINTAINERS   |   6 +
  drivers/gpu/drm/tinydrm/Kconfig   |  10 +
  drivers/gpu/drm/tinydrm/Makefile  |   1 +
  drivers/gpu/drm/tinydrm/ili9225.c | 547 ++
  4 files changed, 564 insertions(+)
  create mode 100644 drivers/gpu/drm/tinydrm/ili9225.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 0d77f22..72404f3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4372,6 +4372,12 @@ T:   git git://anongit.freedesktop.org/drm/drm-misc
  S:Maintained
  F:drivers/gpu/drm/tve200/
  
+DRM DRIVER FOR ILITEK ILI9225 PANELS

+M: David Lechner 
+S: Maintained
+F: drivers/gpu/drm/tinydrm/ili9225.c
+F: Documentation/devicetree/bindings/display/ili9225.txt
+
  DRM DRIVER FOR INTEL I810 VIDEO CARDS
  S:Orphan / Obsolete
  F:drivers/gpu/drm/i810/
diff --git a/drivers/gpu/drm/tinydrm/Kconfig b/drivers/gpu/drm/tinydrm/Kconfig
index 2e790e7..90c5bd5 100644
--- a/drivers/gpu/drm/tinydrm/Kconfig
+++ b/drivers/gpu/drm/tinydrm/Kconfig
@@ -12,6 +12,16 @@ menuconfig DRM_TINYDRM
  config TINYDRM_MIPI_DBI
tristate
  
+config TINYDRM_ILI9225

+   tristate "DRM support for ILI9225 display panels"
+   depends on DRM_TINYDRM && SPI
+   select TINYDRM_MIPI_DBI
+   help
+ DRM driver for the following Ilitek ILI9225 panels:
+ * No-name 2.2" color screen module
+
+ If M is selected the module will be called ili9225.
+
  config TINYDRM_MI0283QT
tristate "DRM support for MI0283QT"
depends on DRM_TINYDRM && SPI
diff --git a/drivers/gpu/drm/tinydrm/Makefile b/drivers/gpu/drm/tinydrm/Makefile
index 0c184bd..8aeee53 100644
--- a/drivers/gpu/drm/tinydrm/Makefile
+++ b/drivers/gpu/drm/tinydrm/Makefile
@@ -4,6 +4,7 @@ obj-$(CONFIG_DRM_TINYDRM)   += core/
  obj-$(CONFIG_TINYDRM_MIPI_DBI)+= mipi-dbi.o
  
  # Displays

+obj-$(CONFIG_TINYDRM_ILI9225)  += ili9225.o
  obj-$(CONFIG_TINYDRM_MI0283QT)+= mi0283qt.o
  obj-$(CONFIG_TINYDRM_REPAPER) += repaper.o
  obj-$(CONFIG_TINYDRM_ST7586)  += st7586.o
diff --git a/drivers/gpu/drm/tinydrm/ili9225.c 
b/drivers/gpu/drm/tinydrm/ili9225.c
new file mode 100644
index 000..07e1b8b
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/ili9225.c
@@ -0,0 +1,547 @@
+/*
+ * DRM driver for Ilitek ILI9225 panels
+ *
+ * Copyright 2017 David Lechner 
+ *
+ * Lots of code copied from mipi-dbi.c
+ * Copyright 2016 Noralf Trønnes
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#define ILI9225_DRIVER_READ_CODE   0x00
+#define ILI9225_DRIVER_OUTPUT_CONTROL  0x01
+#define ILI9225_LCD_AC_DRIVING_CONTROL 0x02
+#define ILI9225_ENTRY_MODE 0x03
+#define ILI9225_DISPLAY_CONTROL_1  0x07
+#define ILI9225_BLANK_PERIOD_CONTROL_1 0x08
+#define ILI9225_FRAME_CYCLE_CONTROL0x0b
+#define ILI9225_INTERFACE_CONTROL  0x0c
+#define ILI9225_OSCILLATION_CONTROL0x0f
+#define ILI9225_POWER_CONTROL_10x10
+#define ILI9225_POWER_CONTROL_20x11
+#define ILI9225_POWER_CONTROL_30x12
+#define ILI9225_POWER_CONTROL_40x13
+#define ILI9225_POWER_CONTROL_50x14
+#define ILI9225_VCI_RECYCLING  0x15
+#define ILI9225_RAM_ADDRESS_SET_1  0x20
+#define ILI9225_RAM_ADDRESS_SET_2  0x21
+#define ILI9225_WRITE_DATA_TO_GRAM 0x22
+#define ILI9225_SOFTWARE_RESET 0x28
+#define ILI9225_GATE_SCAN_CONTROL  0x30
+#define ILI9225_VERTICAL_SCROLL_1  0x31
+#define ILI9225_VERTICAL_SCROLL_2  0x32
+#define ILI9225_VERTICAL_SCROLL_3  0x33
+#define ILI9225_PARTIAL_DRIVING_POS_1  0x34
+#define ILI9225_PARTIAL_DRIVING_POS_2  0x35
+#define ILI9225_HORIZ_WINDOW_ADDR_10x36
+#define ILI9225_HORIZ_WINDOW_ADDR_20x37
+#define ILI9225_VERT_WINDOW_ADDR_1 0x38
+#define ILI9225_VERT_WINDOW_ADDR_2 0x39
+#define ILI9225_GAMMA_CONTROL_10x50
+#define ILI9225_GAMMA_CONTROL_20x51
+#define ILI9225_GAMMA_CONTROL_30x52
+#define ILI9225_GAMMA_CONTROL_40x53
+#define ILI9225_GAMMA_CONTROL_50x54
+#def

Re: [PATCH v1 0/2] DRM driver for ILI9225 display panels

2017-11-10 Thread Noralf Trønnes

Hi David, nice to see a new driver.

Den 08.11.2017 04.52, skrev David Lechner:

This is a new driver for ILI9225 based display panels.

There are a couple of things that stand out:

1.  Despite my best efforts, I could not find a name for this display[1], so I
 have made up a generic name for it. If someone recognizes this and has a
 name for it, please speak up. The best documentation I could find was
 here[2].

2.  There is quite a bit of one-off code copied from mipi-dbi.c. Based on the
 feedback from a previous patch series, I'm guessing that we don't want to
 modify mipi-dbi.c to accommodate the ILI9225 controller because the ILI9225
 controller does not use standard MIPI commands. ILI9225 has it's own
 non-standard command set, but other than that, it pretty much matches the
 generic mipi-dbi driver in all regards.


Yes you're right, I don't want non MIPI code in mipi-dbi, but we can
try and make it flexible for usage with DBI like interfaces.


 Code that could be easily shared:

 a.  ili9225_buf_copy() is exactly the same as mipi_dbi_buf_copy()
 - ili9225_buf_copy() is used in ili9225_fb_dirty()
 - mipi_dbi_buf_copy() is static in mipi-dbi.c


You can export mipi_dbi_buf_copy().


 b.  ili9225_spi_cmd_max_speed() is exactly the same as
 mipi_dbi_spi_cmd_max_speed()
 - ili9225_spi_cmd_max_speed() is used in ili9225_command() below, so
   would not need to be copied if mipi_dbi_typec3_command() could be
   shared
 - mipi_dbi_spi_cmd_max_speed() is static in mipi-dbi.c


Same here, you can export the function.


 c.  ili9225_command() is nearly the same as mipi_dbi_typec3_command()
 - a few unused lines were removed so I didn't have to copy even more
   code, but these would not be an issue if code was shared
 - cmd == ILI9225_WRITE_DATA_TO_GRAM instead of
   cmd == MIPI_DCS_WRITE_MEMORY_START

 d.  ili9225_spi_init() is nearly the same as mipi_dbi_spi_init()
 - a few unused lines were removed so I didn't have to copy even more
   code, but these would not be an issue if code was shared
 - mipi->command = ili9225_command instead of
   mipi->command = mipi_dbi_typec3_command
 - this function would not need to be copied if 
mipi_dbi_typec3_command()
   was modified to work with the ILI9225 command set too


Looks like you can use mipi_dbi_spi_init() and reassign afterwards:
    mipi_dbi_spi_init();
    mipi->command = ili9225_command;


 e.  ili9225_init() is nearly the same as mipi_dbi_init()
 - only difference is ili9225_fb_funcs instead of mipi_dbi_fb_funcs


When we get framebuffer flushing trough atomic modeset, we'll use a generic
fb_dirty and at that point it will be possible to use mipi_dbi_init().
The actual flushing will happen in the update callback I guess.


3.  I haven't tried it, but I believe that it is possible to implement
 DRM_FORMAT_RGB888 directly instead of simulating DRM_FORMAT_XRGB.
 I don't know if there would be any real benefit to doing this. I am not
 familiar enough with userspace programs/libraries to know if this mode is
 universally used. And, it will only physically be 18-bit color instead of
 24-bit but will increase the amount of data transferred by 50% (3 bytes per
 pixel instead of 2). Implementing this would have a side effect of making
 the one-off shared code (described above) more than one-off though.


I have tried it on a display and I couldn't really tell the difference
between 16-bit and 18-bit colors, with X windows at least. And as you
say it's terrible for the framerate.

I'll look closer through the driver later today and see if I have more
comments.

Side note:
This controller can also do something called 24-bit 4 wire SPI. It uses a
Start byte the same way that the (only) SPI mode on ILI9320 and ILI9325 do.
I did a test implementation for ILI9325 where I used regmap as the register
abstraction: https://github.com/notro/tinydrm/blob/master/tinydrm-ili9325.c

Noralf.


[1]: https://github.com/Nkawu/TFT_22_ILI9225
[2]: http://www.hotmcu.com/22-176x220-tft-lcd-with-spi-interface-p-316.html

David Lechner (2):
   dt-bindings: Add binding for Ilitek ILI9225 display panels
   drm/tinydrm: add driver for ILI9225 panels

  .../devicetree/bindings/display/ilitek,ili9225.txt |  25 +
  MAINTAINERS|   6 +
  drivers/gpu/drm/tinydrm/Kconfig|  10 +
  drivers/gpu/drm/tinydrm/Makefile   |   1 +
  drivers/gpu/drm/tinydrm/ili9225.c  | 547 +
  5 files changed, 589 insertions(+)
  create mode 100644 
Documentation/devicetree/bindings/display/ilitek,ili9225.txt
  create mode 100644 drivers/gpu/drm/tinydrm/ili9225.c

--
2.7.4





Re: [PATCH v1 0/2] DRM driver for ILI9225 display panels

2017-11-10 Thread Noralf Trønnes

Hi David, nice to see a new driver.

Den 08.11.2017 04.52, skrev David Lechner:

This is a new driver for ILI9225 based display panels.

There are a couple of things that stand out:

1.  Despite my best efforts, I could not find a name for this display[1], so I
 have made up a generic name for it. If someone recognizes this and has a
 name for it, please speak up. The best documentation I could find was
 here[2].

2.  There is quite a bit of one-off code copied from mipi-dbi.c. Based on the
 feedback from a previous patch series, I'm guessing that we don't want to
 modify mipi-dbi.c to accommodate the ILI9225 controller because the ILI9225
 controller does not use standard MIPI commands. ILI9225 has it's own
 non-standard command set, but other than that, it pretty much matches the
 generic mipi-dbi driver in all regards.


Yes you're right, I don't want non MIPI code in mipi-dbi, but we can
try and make it flexible for usage with DBI like interfaces.


 Code that could be easily shared:

 a.  ili9225_buf_copy() is exactly the same as mipi_dbi_buf_copy()
 - ili9225_buf_copy() is used in ili9225_fb_dirty()
 - mipi_dbi_buf_copy() is static in mipi-dbi.c


You can export mipi_dbi_buf_copy().


 b.  ili9225_spi_cmd_max_speed() is exactly the same as
 mipi_dbi_spi_cmd_max_speed()
 - ili9225_spi_cmd_max_speed() is used in ili9225_command() below, so
   would not need to be copied if mipi_dbi_typec3_command() could be
   shared
 - mipi_dbi_spi_cmd_max_speed() is static in mipi-dbi.c


Same here, you can export the function.


 c.  ili9225_command() is nearly the same as mipi_dbi_typec3_command()
 - a few unused lines were removed so I didn't have to copy even more
   code, but these would not be an issue if code was shared
 - cmd == ILI9225_WRITE_DATA_TO_GRAM instead of
   cmd == MIPI_DCS_WRITE_MEMORY_START

 d.  ili9225_spi_init() is nearly the same as mipi_dbi_spi_init()
 - a few unused lines were removed so I didn't have to copy even more
   code, but these would not be an issue if code was shared
 - mipi->command = ili9225_command instead of
   mipi->command = mipi_dbi_typec3_command
 - this function would not need to be copied if 
mipi_dbi_typec3_command()
   was modified to work with the ILI9225 command set too


Looks like you can use mipi_dbi_spi_init() and reassign afterwards:
    mipi_dbi_spi_init();
    mipi->command = ili9225_command;


 e.  ili9225_init() is nearly the same as mipi_dbi_init()
 - only difference is ili9225_fb_funcs instead of mipi_dbi_fb_funcs


When we get framebuffer flushing trough atomic modeset, we'll use a generic
fb_dirty and at that point it will be possible to use mipi_dbi_init().
The actual flushing will happen in the update callback I guess.


3.  I haven't tried it, but I believe that it is possible to implement
 DRM_FORMAT_RGB888 directly instead of simulating DRM_FORMAT_XRGB.
 I don't know if there would be any real benefit to doing this. I am not
 familiar enough with userspace programs/libraries to know if this mode is
 universally used. And, it will only physically be 18-bit color instead of
 24-bit but will increase the amount of data transferred by 50% (3 bytes per
 pixel instead of 2). Implementing this would have a side effect of making
 the one-off shared code (described above) more than one-off though.


I have tried it on a display and I couldn't really tell the difference
between 16-bit and 18-bit colors, with X windows at least. And as you
say it's terrible for the framerate.

I'll look closer through the driver later today and see if I have more
comments.

Side note:
This controller can also do something called 24-bit 4 wire SPI. It uses a
Start byte the same way that the (only) SPI mode on ILI9320 and ILI9325 do.
I did a test implementation for ILI9325 where I used regmap as the register
abstraction: https://github.com/notro/tinydrm/blob/master/tinydrm-ili9325.c

Noralf.


[1]: https://github.com/Nkawu/TFT_22_ILI9225
[2]: http://www.hotmcu.com/22-176x220-tft-lcd-with-spi-interface-p-316.html

David Lechner (2):
   dt-bindings: Add binding for Ilitek ILI9225 display panels
   drm/tinydrm: add driver for ILI9225 panels

  .../devicetree/bindings/display/ilitek,ili9225.txt |  25 +
  MAINTAINERS|   6 +
  drivers/gpu/drm/tinydrm/Kconfig|  10 +
  drivers/gpu/drm/tinydrm/Makefile   |   1 +
  drivers/gpu/drm/tinydrm/ili9225.c  | 547 +
  5 files changed, 589 insertions(+)
  create mode 100644 
Documentation/devicetree/bindings/display/ilitek,ili9225.txt
  create mode 100644 drivers/gpu/drm/tinydrm/ili9225.c

--
2.7.4





Re: [Outreachy kernel] [PATCH] drm/tinydrm: Replace list_for_each with list_for_each_entry

2017-10-21 Thread Noralf Trønnes


Den 16.10.2017 21.19, skrev Sean Paul:

On Sun, Oct 15, 2017 at 01:58:23AM +0530, Harsha Sharma wrote:

Replace use of list_for_each with list_for_each_entry to simplify the
code and remove variables that are used only in list_for_each.
Done with following coccinelle patch:

@r@
identifier fn,i,f,p;
expression e;
iterator name list_for_each, list_for_each_entry;
type T;
@@

fn(...) {
++ T *i;
   <+...
- list_for_each(p,e)
+ list_for_each_entry(i,e,f)
   {
   ...
-   T *i = list_entry(p,T,f);
   ...
}
...+>
}

@@
identifier r.fn,r.p;
@@

fn(...) {
   ...
- struct list_head *p;
   ... when != p
}

@@
identifier r.fn,r.i,r.f;
expression r.e;
statement S;
@@

fn(...) {
   <...
   list_for_each_entry(i,e,f)
- {
   S
- }
   ...>
}

@s@
identifier i,f,p;
expression e;
type T;
@@

- list_for_each(p,e)
+ list_for_each_entry(i,e,f)
   {
 ... when != T *i;
-   i = list_entry(p,T,f);
 ...
   }

@@
identifier s.p;
@@

- struct list_head *p;
   ... when != p

@@
identifier s.i,s.f;
expression s.e;
statement S;
@@

   list_for_each_entry(i,e,f)
- {
   S
- }

Signed-off-by: Harsha Sharma 

Reviewed-by: Sean Paul 


Thanks, applied to drm-misc.

Noralf.


---
  drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c 
b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
index bd6cce093a85..bf96072d1b97 100644
--- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
+++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
@@ -414,11 +414,9 @@ tinydrm_dbg_spi_print(struct spi_device *spi, struct 
spi_transfer *tr,
  void _tinydrm_dbg_spi_message(struct spi_device *spi, struct spi_message *m)
  {
struct spi_transfer *tmp;
-   struct list_head *pos;
int i = 0;
  
-	list_for_each(pos, >transfers) {

-   tmp = list_entry(pos, struct spi_transfer, transfer_list);
+   list_for_each_entry(tmp, >transfers, transfer_list) {
  
  		if (tmp->tx_buf)

tinydrm_dbg_spi_print(spi, tmp, tmp->tx_buf, i, true);
--
2.11.0

--
You received this message because you are subscribed to the Google Groups 
"outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to outreachy-kernel+unsubscr...@googlegroups.com.
To post to this group, send email to outreachy-ker...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/outreachy-kernel/20171014202823.29230-1-harshasharmaiitr%40gmail.com.
For more options, visit https://groups.google.com/d/optout.




Re: [Outreachy kernel] [PATCH] drm/tinydrm: Replace list_for_each with list_for_each_entry

2017-10-21 Thread Noralf Trønnes


Den 16.10.2017 21.19, skrev Sean Paul:

On Sun, Oct 15, 2017 at 01:58:23AM +0530, Harsha Sharma wrote:

Replace use of list_for_each with list_for_each_entry to simplify the
code and remove variables that are used only in list_for_each.
Done with following coccinelle patch:

@r@
identifier fn,i,f,p;
expression e;
iterator name list_for_each, list_for_each_entry;
type T;
@@

fn(...) {
++ T *i;
   <+...
- list_for_each(p,e)
+ list_for_each_entry(i,e,f)
   {
   ...
-   T *i = list_entry(p,T,f);
   ...
}
...+>
}

@@
identifier r.fn,r.p;
@@

fn(...) {
   ...
- struct list_head *p;
   ... when != p
}

@@
identifier r.fn,r.i,r.f;
expression r.e;
statement S;
@@

fn(...) {
   <...
   list_for_each_entry(i,e,f)
- {
   S
- }
   ...>
}

@s@
identifier i,f,p;
expression e;
type T;
@@

- list_for_each(p,e)
+ list_for_each_entry(i,e,f)
   {
 ... when != T *i;
-   i = list_entry(p,T,f);
 ...
   }

@@
identifier s.p;
@@

- struct list_head *p;
   ... when != p

@@
identifier s.i,s.f;
expression s.e;
statement S;
@@

   list_for_each_entry(i,e,f)
- {
   S
- }

Signed-off-by: Harsha Sharma 

Reviewed-by: Sean Paul 


Thanks, applied to drm-misc.

Noralf.


---
  drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c 
b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
index bd6cce093a85..bf96072d1b97 100644
--- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
+++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
@@ -414,11 +414,9 @@ tinydrm_dbg_spi_print(struct spi_device *spi, struct 
spi_transfer *tr,
  void _tinydrm_dbg_spi_message(struct spi_device *spi, struct spi_message *m)
  {
struct spi_transfer *tmp;
-   struct list_head *pos;
int i = 0;
  
-	list_for_each(pos, >transfers) {

-   tmp = list_entry(pos, struct spi_transfer, transfer_list);
+   list_for_each_entry(tmp, >transfers, transfer_list) {
  
  		if (tmp->tx_buf)

tinydrm_dbg_spi_print(spi, tmp, tmp->tx_buf, i, true);
--
2.11.0

--
You received this message because you are subscribed to the Google Groups 
"outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to outreachy-kernel+unsubscr...@googlegroups.com.
To post to this group, send email to outreachy-ker...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/outreachy-kernel/20171014202823.29230-1-harshasharmaiitr%40gmail.com.
For more options, visit https://groups.google.com/d/optout.




Re: [PATCH v3] drm/tinydrm: Replace dev_error with DRM_DEV_ERROR

2017-10-13 Thread Noralf Trønnes


Den 07.10.2017 00.17, skrev Harsha Sharma:

Convert instances of dev_error to DRM_DEV_ERROR as we have
DRM_DEV_ERROR variants of drm print macros.

Signed-off-by: Harsha Sharma 
---


Thanks, applied to drm-misc.

Noralf.


Changes in v3:
  -Solve merge conflicts
Changes in v2:
  -Fix alignment issues
  drivers/gpu/drm/tinydrm/mi0283qt.c |  8 
  drivers/gpu/drm/tinydrm/repaper.c  | 28 +---
  drivers/gpu/drm/tinydrm/st7586.c   |  6 +++---
  3 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/mi0283qt.c 
b/drivers/gpu/drm/tinydrm/mi0283qt.c
index 7e5bb7d6f655..7dded506ba8c 100644
--- a/drivers/gpu/drm/tinydrm/mi0283qt.c
+++ b/drivers/gpu/drm/tinydrm/mi0283qt.c
@@ -31,7 +31,7 @@ static int mi0283qt_init(struct mipi_dbi *mipi)
  
  	ret = regulator_enable(mipi->regulator);

if (ret) {
-   dev_err(dev, "Failed to enable regulator %d\n", ret);
+   DRM_DEV_ERROR(dev, "Failed to enable regulator %d\n", ret);
return ret;
}
  
@@ -42,7 +42,7 @@ static int mi0283qt_init(struct mipi_dbi *mipi)

mipi_dbi_hw_reset(mipi);
ret = mipi_dbi_command(mipi, MIPI_DCS_SOFT_RESET);
if (ret) {
-   dev_err(dev, "Error sending command %d\n", ret);
+   DRM_DEV_ERROR(dev, "Error sending command %d\n", ret);
regulator_disable(mipi->regulator);
return ret;
}
@@ -175,13 +175,13 @@ static int mi0283qt_probe(struct spi_device *spi)
  
  	mipi->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);

if (IS_ERR(mipi->reset)) {
-   dev_err(dev, "Failed to get gpio 'reset'\n");
+   DRM_DEV_ERROR(dev, "Failed to get gpio 'reset'\n");
return PTR_ERR(mipi->reset);
}
  
  	dc = devm_gpiod_get_optional(dev, "dc", GPIOD_OUT_LOW);

if (IS_ERR(dc)) {
-   dev_err(dev, "Failed to get gpio 'dc'\n");
+   DRM_DEV_ERROR(dev, "Failed to get gpio 'dc'\n");
return PTR_ERR(dc);
}
  
diff --git a/drivers/gpu/drm/tinydrm/repaper.c b/drivers/gpu/drm/tinydrm/repaper.c

index 30dc97b3ff21..028d428d4ab9 100644
--- a/drivers/gpu/drm/tinydrm/repaper.c
+++ b/drivers/gpu/drm/tinydrm/repaper.c
@@ -473,8 +473,7 @@ static void repaper_get_temperature(struct repaper_epd *epd)
  
  	ret = thermal_zone_get_temp(epd->thermal, );

if (ret) {
-   dev_err(>spi->dev, "Failed to get temperature (%d)\n",
-   ret);
+   DRM_DEV_ERROR(>spi->dev, "Failed to get temperature 
(%d)\n", ret);
return;
}
  
@@ -629,7 +628,7 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb,

mutex_unlock(>dirty_lock);
  
  	if (ret)

-   dev_err(fb->dev->dev, "Failed to update display (%d)\n", ret);
+   DRM_DEV_ERROR(fb->dev->dev, "Failed to update display (%d)\n", 
ret);
kfree(buf);
  
  	return ret;

@@ -703,7 +702,7 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
}
  
  	if (!i) {

-   dev_err(dev, "timeout waiting for panel to become ready.\n");
+   DRM_DEV_ERROR(dev, "timeout waiting for panel to become 
ready.\n");
power_off(epd);
return;
}
@@ -725,9 +724,9 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
ret = repaper_read_val(spi, 0x0f);
if (ret < 0 || !(ret & 0x80)) {
if (ret < 0)
-   dev_err(dev, "failed to read chip (%d)\n", ret);
+   DRM_DEV_ERROR(dev, "failed to read chip (%d)\n", ret);
else
-   dev_err(dev, "panel is reported broken\n");
+   DRM_DEV_ERROR(dev, "panel is reported broken\n");
power_off(epd);
return;
}
@@ -767,7 +766,7 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
/* check DC/DC */
ret = repaper_read_val(spi, 0x0f);
if (ret < 0) {
-   dev_err(dev, "failed to read chip (%d)\n", ret);
+   DRM_DEV_ERROR(dev, "failed to read chip (%d)\n", ret);
power_off(epd);
return;
}
@@ -779,7 +778,7 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
}
  
  	if (!dc_ok) {

-   dev_err(dev, "dc/dc failed\n");
+   DRM_DEV_ERROR(dev, "dc/dc failed\n");
power_off(epd);
return;
}
@@ -959,7 +958,7 @@ static int repaper_probe(struct spi_device *spi)
if (IS_ERR(epd->panel_on)) {
ret = PTR_ERR(epd->panel_on);
if (ret != -EPROBE_DEFER)
-   dev_err(dev, "Failed to get gpio 'panel-on'\n");
+   

Re: [PATCH v3] drm/tinydrm: Replace dev_error with DRM_DEV_ERROR

2017-10-13 Thread Noralf Trønnes


Den 07.10.2017 00.17, skrev Harsha Sharma:

Convert instances of dev_error to DRM_DEV_ERROR as we have
DRM_DEV_ERROR variants of drm print macros.

Signed-off-by: Harsha Sharma 
---


Thanks, applied to drm-misc.

Noralf.


Changes in v3:
  -Solve merge conflicts
Changes in v2:
  -Fix alignment issues
  drivers/gpu/drm/tinydrm/mi0283qt.c |  8 
  drivers/gpu/drm/tinydrm/repaper.c  | 28 +---
  drivers/gpu/drm/tinydrm/st7586.c   |  6 +++---
  3 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/mi0283qt.c 
b/drivers/gpu/drm/tinydrm/mi0283qt.c
index 7e5bb7d6f655..7dded506ba8c 100644
--- a/drivers/gpu/drm/tinydrm/mi0283qt.c
+++ b/drivers/gpu/drm/tinydrm/mi0283qt.c
@@ -31,7 +31,7 @@ static int mi0283qt_init(struct mipi_dbi *mipi)
  
  	ret = regulator_enable(mipi->regulator);

if (ret) {
-   dev_err(dev, "Failed to enable regulator %d\n", ret);
+   DRM_DEV_ERROR(dev, "Failed to enable regulator %d\n", ret);
return ret;
}
  
@@ -42,7 +42,7 @@ static int mi0283qt_init(struct mipi_dbi *mipi)

mipi_dbi_hw_reset(mipi);
ret = mipi_dbi_command(mipi, MIPI_DCS_SOFT_RESET);
if (ret) {
-   dev_err(dev, "Error sending command %d\n", ret);
+   DRM_DEV_ERROR(dev, "Error sending command %d\n", ret);
regulator_disable(mipi->regulator);
return ret;
}
@@ -175,13 +175,13 @@ static int mi0283qt_probe(struct spi_device *spi)
  
  	mipi->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);

if (IS_ERR(mipi->reset)) {
-   dev_err(dev, "Failed to get gpio 'reset'\n");
+   DRM_DEV_ERROR(dev, "Failed to get gpio 'reset'\n");
return PTR_ERR(mipi->reset);
}
  
  	dc = devm_gpiod_get_optional(dev, "dc", GPIOD_OUT_LOW);

if (IS_ERR(dc)) {
-   dev_err(dev, "Failed to get gpio 'dc'\n");
+   DRM_DEV_ERROR(dev, "Failed to get gpio 'dc'\n");
return PTR_ERR(dc);
}
  
diff --git a/drivers/gpu/drm/tinydrm/repaper.c b/drivers/gpu/drm/tinydrm/repaper.c

index 30dc97b3ff21..028d428d4ab9 100644
--- a/drivers/gpu/drm/tinydrm/repaper.c
+++ b/drivers/gpu/drm/tinydrm/repaper.c
@@ -473,8 +473,7 @@ static void repaper_get_temperature(struct repaper_epd *epd)
  
  	ret = thermal_zone_get_temp(epd->thermal, );

if (ret) {
-   dev_err(>spi->dev, "Failed to get temperature (%d)\n",
-   ret);
+   DRM_DEV_ERROR(>spi->dev, "Failed to get temperature 
(%d)\n", ret);
return;
}
  
@@ -629,7 +628,7 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb,

mutex_unlock(>dirty_lock);
  
  	if (ret)

-   dev_err(fb->dev->dev, "Failed to update display (%d)\n", ret);
+   DRM_DEV_ERROR(fb->dev->dev, "Failed to update display (%d)\n", 
ret);
kfree(buf);
  
  	return ret;

@@ -703,7 +702,7 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
}
  
  	if (!i) {

-   dev_err(dev, "timeout waiting for panel to become ready.\n");
+   DRM_DEV_ERROR(dev, "timeout waiting for panel to become 
ready.\n");
power_off(epd);
return;
}
@@ -725,9 +724,9 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
ret = repaper_read_val(spi, 0x0f);
if (ret < 0 || !(ret & 0x80)) {
if (ret < 0)
-   dev_err(dev, "failed to read chip (%d)\n", ret);
+   DRM_DEV_ERROR(dev, "failed to read chip (%d)\n", ret);
else
-   dev_err(dev, "panel is reported broken\n");
+   DRM_DEV_ERROR(dev, "panel is reported broken\n");
power_off(epd);
return;
}
@@ -767,7 +766,7 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
/* check DC/DC */
ret = repaper_read_val(spi, 0x0f);
if (ret < 0) {
-   dev_err(dev, "failed to read chip (%d)\n", ret);
+   DRM_DEV_ERROR(dev, "failed to read chip (%d)\n", ret);
power_off(epd);
return;
}
@@ -779,7 +778,7 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
}
  
  	if (!dc_ok) {

-   dev_err(dev, "dc/dc failed\n");
+   DRM_DEV_ERROR(dev, "dc/dc failed\n");
power_off(epd);
return;
}
@@ -959,7 +958,7 @@ static int repaper_probe(struct spi_device *spi)
if (IS_ERR(epd->panel_on)) {
ret = PTR_ERR(epd->panel_on);
if (ret != -EPROBE_DEFER)
-   dev_err(dev, "Failed to get gpio 'panel-on'\n");
+   DRM_DEV_ERROR(dev, "Failed to get 

Re: [PATCH v2] drm/tinydrm: Replace dev_error with DRM_DEV_ERROR

2017-10-04 Thread Noralf Trønnes


Den 29.09.2017 09.48, skrev Harsha Sharma:

Convert instances of dev_error to DRM_DEV_ERROR as we have
DRM_DEV_ERROR variants of drm print macros.

Signed-off-by: Harsha Sharma 
---
Changes in v2:
  -Fix alignment issues


This patchfile is corrupt.
Looks like you have manually edited the file.
Please don't do that, generate a new one.

Noralf.


  drivers/gpu/drm/tinydrm/mi0283qt.c |  8 
  drivers/gpu/drm/tinydrm/repaper.c  | 26 +-
  drivers/gpu/drm/tinydrm/st7586.c   |  6 +++---
  3 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/mi0283qt.c 
b/drivers/gpu/drm/tinydrm/mi0283qt.c
index 7e5bb7d..7dded50 100644
--- a/drivers/gpu/drm/tinydrm/mi0283qt.c
+++ b/drivers/gpu/drm/tinydrm/mi0283qt.c
@@ -31,7 +31,7 @@ static int mi0283qt_init(struct mipi_dbi *mipi)
  
  	ret = regulator_enable(mipi->regulator);

if (ret) {
-   dev_err(dev, "Failed to enable regulator %d\n", ret);
+   DRM_DEV_ERROR(dev, "Failed to enable regulator %d\n", ret);
return ret;
}
  
@@ -42,7 +42,7 @@ static int mi0283qt_init(struct mipi_dbi *mipi)

mipi_dbi_hw_reset(mipi);
ret = mipi_dbi_command(mipi, MIPI_DCS_SOFT_RESET);
if (ret) {
-   dev_err(dev, "Error sending command %d\n", ret);
+   DRM_DEV_ERROR(dev, "Error sending command %d\n", ret);
regulator_disable(mipi->regulator);
return ret;
}
@@ -175,13 +175,13 @@ static int mi0283qt_probe(struct spi_device *spi)
  
  	mipi->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);

if (IS_ERR(mipi->reset)) {
-   dev_err(dev, "Failed to get gpio 'reset'\n");
+   DRM_DEV_ERROR(dev, "Failed to get gpio 'reset'\n");
return PTR_ERR(mipi->reset);
}
  
  	dc = devm_gpiod_get_optional(dev, "dc", GPIOD_OUT_LOW);

if (IS_ERR(dc)) {
-   dev_err(dev, "Failed to get gpio 'dc'\n");
+   DRM_DEV_ERROR(dev, "Failed to get gpio 'dc'\n");
return PTR_ERR(dc);
}
  
diff --git a/drivers/gpu/drm/tinydrm/repaper.c b/drivers/gpu/drm/tinydrm/repaper.c

index 30dc97b..bd152bb 100644
--- a/drivers/gpu/drm/tinydrm/repaper.c
+++ b/drivers/gpu/drm/tinydrm/repaper.c
@@ -473,7 +473,7 @@ static void repaper_get_temperature(struct repaper_epd *epd)
  
  	ret = thermal_zone_get_temp(epd->thermal, );

if (ret) {
-   dev_err(>spi->dev, "Failed to get temperature (%d)\n",
+   DRM_DEV_ERROR(>spi->dev, "Failed to get temperature 
(%d)\n", ret);
return;
}
@@ -629,7 +629,7 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb,
mutex_unlock(>dirty_lock);
  
  	if (ret)

-   dev_err(fb->dev->dev, "Failed to update display (%d)\n", ret);
+   DRM_DEV_ERROR(fb->dev->dev, "Failed to update display (%d)\n", 
ret);
kfree(buf);
  
  	return ret;

@@ -703,7 +703,7 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
}
  
  	if (!i) {

-   dev_err(dev, "timeout waiting for panel to become ready.\n");
+   DRM_DEV_ERROR(dev, "timeout waiting for panel to become 
ready.\n");
power_off(epd);
return;
}
@@ -725,9 +725,9 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
ret = repaper_read_val(spi, 0x0f);
if (ret < 0 || !(ret & 0x80)) {
if (ret < 0)
-   dev_err(dev, "failed to read chip (%d)\n", ret);
+   DRM_DEV_ERROR(dev, "failed to read chip (%d)\n", ret);
else
-   dev_err(dev, "panel is reported broken\n");
+   DRM_DEV_ERROR(dev, "panel is reported broken\n");
power_off(epd);
return;
}
@@ -767,7 +767,7 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
/* check DC/DC */
ret = repaper_read_val(spi, 0x0f);
if (ret < 0) {
-   dev_err(dev, "failed to read chip (%d)\n", ret);
+   DRM_DEV_ERROR(dev, "failed to read chip (%d)\n", ret);
power_off(epd);
return;
}
@@ -779,7 +779,7 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
}
  
  	if (!dc_ok) {

-   dev_err(dev, "dc/dc failed\n");
+   DRM_DEV_ERROR(dev, "dc/dc failed\n");
power_off(epd);
return;
}
@@ -959,7 +959,7 @@ static int repaper_probe(struct spi_device *spi)
if (IS_ERR(epd->panel_on)) {
ret = PTR_ERR(epd->panel_on);
if (ret != -EPROBE_DEFER)
-   dev_err(dev, "Failed to get gpio 'panel-on'\n");
+   

Re: [PATCH v2] drm/tinydrm: Replace dev_error with DRM_DEV_ERROR

2017-10-04 Thread Noralf Trønnes


Den 29.09.2017 09.48, skrev Harsha Sharma:

Convert instances of dev_error to DRM_DEV_ERROR as we have
DRM_DEV_ERROR variants of drm print macros.

Signed-off-by: Harsha Sharma 
---
Changes in v2:
  -Fix alignment issues


This patchfile is corrupt.
Looks like you have manually edited the file.
Please don't do that, generate a new one.

Noralf.


  drivers/gpu/drm/tinydrm/mi0283qt.c |  8 
  drivers/gpu/drm/tinydrm/repaper.c  | 26 +-
  drivers/gpu/drm/tinydrm/st7586.c   |  6 +++---
  3 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/mi0283qt.c 
b/drivers/gpu/drm/tinydrm/mi0283qt.c
index 7e5bb7d..7dded50 100644
--- a/drivers/gpu/drm/tinydrm/mi0283qt.c
+++ b/drivers/gpu/drm/tinydrm/mi0283qt.c
@@ -31,7 +31,7 @@ static int mi0283qt_init(struct mipi_dbi *mipi)
  
  	ret = regulator_enable(mipi->regulator);

if (ret) {
-   dev_err(dev, "Failed to enable regulator %d\n", ret);
+   DRM_DEV_ERROR(dev, "Failed to enable regulator %d\n", ret);
return ret;
}
  
@@ -42,7 +42,7 @@ static int mi0283qt_init(struct mipi_dbi *mipi)

mipi_dbi_hw_reset(mipi);
ret = mipi_dbi_command(mipi, MIPI_DCS_SOFT_RESET);
if (ret) {
-   dev_err(dev, "Error sending command %d\n", ret);
+   DRM_DEV_ERROR(dev, "Error sending command %d\n", ret);
regulator_disable(mipi->regulator);
return ret;
}
@@ -175,13 +175,13 @@ static int mi0283qt_probe(struct spi_device *spi)
  
  	mipi->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);

if (IS_ERR(mipi->reset)) {
-   dev_err(dev, "Failed to get gpio 'reset'\n");
+   DRM_DEV_ERROR(dev, "Failed to get gpio 'reset'\n");
return PTR_ERR(mipi->reset);
}
  
  	dc = devm_gpiod_get_optional(dev, "dc", GPIOD_OUT_LOW);

if (IS_ERR(dc)) {
-   dev_err(dev, "Failed to get gpio 'dc'\n");
+   DRM_DEV_ERROR(dev, "Failed to get gpio 'dc'\n");
return PTR_ERR(dc);
}
  
diff --git a/drivers/gpu/drm/tinydrm/repaper.c b/drivers/gpu/drm/tinydrm/repaper.c

index 30dc97b..bd152bb 100644
--- a/drivers/gpu/drm/tinydrm/repaper.c
+++ b/drivers/gpu/drm/tinydrm/repaper.c
@@ -473,7 +473,7 @@ static void repaper_get_temperature(struct repaper_epd *epd)
  
  	ret = thermal_zone_get_temp(epd->thermal, );

if (ret) {
-   dev_err(>spi->dev, "Failed to get temperature (%d)\n",
+   DRM_DEV_ERROR(>spi->dev, "Failed to get temperature 
(%d)\n", ret);
return;
}
@@ -629,7 +629,7 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb,
mutex_unlock(>dirty_lock);
  
  	if (ret)

-   dev_err(fb->dev->dev, "Failed to update display (%d)\n", ret);
+   DRM_DEV_ERROR(fb->dev->dev, "Failed to update display (%d)\n", 
ret);
kfree(buf);
  
  	return ret;

@@ -703,7 +703,7 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
}
  
  	if (!i) {

-   dev_err(dev, "timeout waiting for panel to become ready.\n");
+   DRM_DEV_ERROR(dev, "timeout waiting for panel to become 
ready.\n");
power_off(epd);
return;
}
@@ -725,9 +725,9 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
ret = repaper_read_val(spi, 0x0f);
if (ret < 0 || !(ret & 0x80)) {
if (ret < 0)
-   dev_err(dev, "failed to read chip (%d)\n", ret);
+   DRM_DEV_ERROR(dev, "failed to read chip (%d)\n", ret);
else
-   dev_err(dev, "panel is reported broken\n");
+   DRM_DEV_ERROR(dev, "panel is reported broken\n");
power_off(epd);
return;
}
@@ -767,7 +767,7 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
/* check DC/DC */
ret = repaper_read_val(spi, 0x0f);
if (ret < 0) {
-   dev_err(dev, "failed to read chip (%d)\n", ret);
+   DRM_DEV_ERROR(dev, "failed to read chip (%d)\n", ret);
power_off(epd);
return;
}
@@ -779,7 +779,7 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
}
  
  	if (!dc_ok) {

-   dev_err(dev, "dc/dc failed\n");
+   DRM_DEV_ERROR(dev, "dc/dc failed\n");
power_off(epd);
return;
}
@@ -959,7 +959,7 @@ static int repaper_probe(struct spi_device *spi)
if (IS_ERR(epd->panel_on)) {
ret = PTR_ERR(epd->panel_on);
if (ret != -EPROBE_DEFER)
-   dev_err(dev, "Failed to get gpio 'panel-on'\n");
+   DRM_DEV_ERROR(dev, "Failed to get gpio 

Re: [PATCH] drm/tinydrm: Replace dev_error with DRM_DEV_ERROR

2017-09-25 Thread Noralf Trønnes


Den 23.09.2017 11.10, skrev Harsha Sharma:

Convert instances of dev_error to DRM_DEV_ERROR as we have
DRM_DEV_ERROR variants of drm print macros.

Signed-off-by: Harsha Sharma <harshasharmai...@gmail.com>
---
  drivers/gpu/drm/tinydrm/mi0283qt.c |  8 
  drivers/gpu/drm/tinydrm/repaper.c  | 26 +-
  drivers/gpu/drm/tinydrm/st7586.c   |  6 +++---
  3 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/mi0283qt.c 
b/drivers/gpu/drm/tinydrm/mi0283qt.c
index 7e5bb7d..7dded50 100644
--- a/drivers/gpu/drm/tinydrm/mi0283qt.c
+++ b/drivers/gpu/drm/tinydrm/mi0283qt.c
@@ -31,7 +31,7 @@ static int mi0283qt_init(struct mipi_dbi *mipi)
  
  	ret = regulator_enable(mipi->regulator);

if (ret) {
-   dev_err(dev, "Failed to enable regulator %d\n", ret);
+   DRM_DEV_ERROR(dev, "Failed to enable regulator %d\n", ret);
return ret;
}
  
@@ -42,7 +42,7 @@ static int mi0283qt_init(struct mipi_dbi *mipi)

mipi_dbi_hw_reset(mipi);
ret = mipi_dbi_command(mipi, MIPI_DCS_SOFT_RESET);
if (ret) {
-   dev_err(dev, "Error sending command %d\n", ret);
+   DRM_DEV_ERROR(dev, "Error sending command %d\n", ret);
regulator_disable(mipi->regulator);
return ret;
}
@@ -175,13 +175,13 @@ static int mi0283qt_probe(struct spi_device *spi)
  
  	mipi->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);

if (IS_ERR(mipi->reset)) {
-   dev_err(dev, "Failed to get gpio 'reset'\n");
+   DRM_DEV_ERROR(dev, "Failed to get gpio 'reset'\n");
return PTR_ERR(mipi->reset);
}
  
  	dc = devm_gpiod_get_optional(dev, "dc", GPIOD_OUT_LOW);

if (IS_ERR(dc)) {
-   dev_err(dev, "Failed to get gpio 'dc'\n");
+   DRM_DEV_ERROR(dev, "Failed to get gpio 'dc'\n");
return PTR_ERR(dc);
}
  
diff --git a/drivers/gpu/drm/tinydrm/repaper.c b/drivers/gpu/drm/tinydrm/repaper.c

index 30dc97b..bd152bb 100644
--- a/drivers/gpu/drm/tinydrm/repaper.c
+++ b/drivers/gpu/drm/tinydrm/repaper.c
@@ -473,7 +473,7 @@ static void repaper_get_temperature(struct repaper_epd *epd)
  
  	ret = thermal_zone_get_temp(epd->thermal, );

if (ret) {
-   dev_err(>spi->dev, "Failed to get temperature (%d)\n",
+   DRM_DEV_ERROR(>spi->dev, "Failed to get temperature 
(%d)\n",
ret);


Please fix these alignment issues, or maybe just put it all on one line:

CHECK: Alignment should match open parenthesis
#59: FILE: drivers/gpu/drm/tinydrm/repaper.c:477:
+   DRM_DEV_ERROR(>spi->dev, "Failed to get temperature 
(%d)\n",

    ret);

CHECK: Alignment should match open parenthesis
#152: FILE: drivers/gpu/drm/tinydrm/repaper.c:995:
+   DRM_DEV_ERROR(dev, "Failed to get thermal zone: 
%s\n",

    thermal_zone);

With that changed you can add to your next version:
Reviewed-by: Noralf Trønnes <nor...@tronnes.org>


return;
}
@@ -629,7 +629,7 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb,
mutex_unlock(>dirty_lock);
  
  	if (ret)

-   dev_err(fb->dev->dev, "Failed to update display (%d)\n", ret);
+   DRM_DEV_ERROR(fb->dev->dev, "Failed to update display (%d)\n", 
ret);
kfree(buf);
  
  	return ret;

@@ -703,7 +703,7 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
}
  
  	if (!i) {

-   dev_err(dev, "timeout waiting for panel to become ready.\n");
+   DRM_DEV_ERROR(dev, "timeout waiting for panel to become 
ready.\n");
power_off(epd);
return;
}
@@ -725,9 +725,9 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
ret = repaper_read_val(spi, 0x0f);
if (ret < 0 || !(ret & 0x80)) {
if (ret < 0)
-   dev_err(dev, "failed to read chip (%d)\n", ret);
+   DRM_DEV_ERROR(dev, "failed to read chip (%d)\n", ret);
else
-   dev_err(dev, "panel is reported broken\n");
+   DRM_DEV_ERROR(dev, "panel is reported broken\n");
power_off(epd);
return;
}
@@ -767,7 +767,7 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
/* check DC/DC */
ret = repaper_read_val(spi, 0x0f);
if (ret < 0) {
-   dev_err(dev, "failed to read chip 

Re: [PATCH] drm/tinydrm: Replace dev_error with DRM_DEV_ERROR

2017-09-25 Thread Noralf Trønnes


Den 23.09.2017 11.10, skrev Harsha Sharma:

Convert instances of dev_error to DRM_DEV_ERROR as we have
DRM_DEV_ERROR variants of drm print macros.

Signed-off-by: Harsha Sharma 
---
  drivers/gpu/drm/tinydrm/mi0283qt.c |  8 
  drivers/gpu/drm/tinydrm/repaper.c  | 26 +-
  drivers/gpu/drm/tinydrm/st7586.c   |  6 +++---
  3 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/mi0283qt.c 
b/drivers/gpu/drm/tinydrm/mi0283qt.c
index 7e5bb7d..7dded50 100644
--- a/drivers/gpu/drm/tinydrm/mi0283qt.c
+++ b/drivers/gpu/drm/tinydrm/mi0283qt.c
@@ -31,7 +31,7 @@ static int mi0283qt_init(struct mipi_dbi *mipi)
  
  	ret = regulator_enable(mipi->regulator);

if (ret) {
-   dev_err(dev, "Failed to enable regulator %d\n", ret);
+   DRM_DEV_ERROR(dev, "Failed to enable regulator %d\n", ret);
return ret;
}
  
@@ -42,7 +42,7 @@ static int mi0283qt_init(struct mipi_dbi *mipi)

mipi_dbi_hw_reset(mipi);
ret = mipi_dbi_command(mipi, MIPI_DCS_SOFT_RESET);
if (ret) {
-   dev_err(dev, "Error sending command %d\n", ret);
+   DRM_DEV_ERROR(dev, "Error sending command %d\n", ret);
regulator_disable(mipi->regulator);
return ret;
}
@@ -175,13 +175,13 @@ static int mi0283qt_probe(struct spi_device *spi)
  
  	mipi->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);

if (IS_ERR(mipi->reset)) {
-   dev_err(dev, "Failed to get gpio 'reset'\n");
+   DRM_DEV_ERROR(dev, "Failed to get gpio 'reset'\n");
return PTR_ERR(mipi->reset);
}
  
  	dc = devm_gpiod_get_optional(dev, "dc", GPIOD_OUT_LOW);

if (IS_ERR(dc)) {
-   dev_err(dev, "Failed to get gpio 'dc'\n");
+   DRM_DEV_ERROR(dev, "Failed to get gpio 'dc'\n");
return PTR_ERR(dc);
}
  
diff --git a/drivers/gpu/drm/tinydrm/repaper.c b/drivers/gpu/drm/tinydrm/repaper.c

index 30dc97b..bd152bb 100644
--- a/drivers/gpu/drm/tinydrm/repaper.c
+++ b/drivers/gpu/drm/tinydrm/repaper.c
@@ -473,7 +473,7 @@ static void repaper_get_temperature(struct repaper_epd *epd)
  
  	ret = thermal_zone_get_temp(epd->thermal, );

if (ret) {
-   dev_err(>spi->dev, "Failed to get temperature (%d)\n",
+   DRM_DEV_ERROR(>spi->dev, "Failed to get temperature 
(%d)\n",
ret);


Please fix these alignment issues, or maybe just put it all on one line:

CHECK: Alignment should match open parenthesis
#59: FILE: drivers/gpu/drm/tinydrm/repaper.c:477:
+   DRM_DEV_ERROR(>spi->dev, "Failed to get temperature 
(%d)\n",

    ret);

CHECK: Alignment should match open parenthesis
#152: FILE: drivers/gpu/drm/tinydrm/repaper.c:995:
+   DRM_DEV_ERROR(dev, "Failed to get thermal zone: 
%s\n",

    thermal_zone);

With that changed you can add to your next version:
Reviewed-by: Noralf Trønnes 


return;
}
@@ -629,7 +629,7 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb,
mutex_unlock(>dirty_lock);
  
  	if (ret)

-   dev_err(fb->dev->dev, "Failed to update display (%d)\n", ret);
+   DRM_DEV_ERROR(fb->dev->dev, "Failed to update display (%d)\n", 
ret);
kfree(buf);
  
  	return ret;

@@ -703,7 +703,7 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
}
  
  	if (!i) {

-   dev_err(dev, "timeout waiting for panel to become ready.\n");
+   DRM_DEV_ERROR(dev, "timeout waiting for panel to become 
ready.\n");
power_off(epd);
return;
}
@@ -725,9 +725,9 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
ret = repaper_read_val(spi, 0x0f);
if (ret < 0 || !(ret & 0x80)) {
if (ret < 0)
-   dev_err(dev, "failed to read chip (%d)\n", ret);
+   DRM_DEV_ERROR(dev, "failed to read chip (%d)\n", ret);
else
-   dev_err(dev, "panel is reported broken\n");
+   DRM_DEV_ERROR(dev, "panel is reported broken\n");
power_off(epd);
return;
}
@@ -767,7 +767,7 @@ static void repaper_pipe_enable(struct 
drm_simple_display_pipe *pipe,
/* check DC/DC */
ret = repaper_read_val(spi, 0x0f);
if (ret < 0) {
-   dev_err(dev, "failed to read chip (%d)\n", ret);
+   DRM_DEV_ERROR(dev

Re: [PATCH][drm-next] drm/tinydrm: make function st7586_pipe_enable static

2017-08-16 Thread Noralf Trønnes


Den 16.08.2017 17.46, skrev David Lechner:

On 08/16/2017 04:23 AM, Colin King wrote:

From: Colin Ian King 

The function st7586_pipe_enable  is local to the source
and does not need to be in global scope, so make it static.

Cleans up sparse warning:
symbol 'st7586_pipe_enable' was not declared. Should it be static?

Signed-off-by: Colin Ian King 
---


Acked-By: David Lechner 


Thanks, applied to drm-misc.

Noralf.



Re: [PATCH][drm-next] drm/tinydrm: make function st7586_pipe_enable static

2017-08-16 Thread Noralf Trønnes


Den 16.08.2017 17.46, skrev David Lechner:

On 08/16/2017 04:23 AM, Colin King wrote:

From: Colin Ian King 

The function st7586_pipe_enable  is local to the source
and does not need to be in global scope, so make it static.

Cleans up sparse warning:
symbol 'st7586_pipe_enable' was not declared. Should it be static?

Signed-off-by: Colin Ian King 
---


Acked-By: David Lechner 


Thanks, applied to drm-misc.

Noralf.



Re: [PATCH v4 3/5] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-11 Thread Noralf Trønnes


Den 09.08.2017 19.59, skrev Noralf Trønnes:


Den 07.08.2017 19.39, skrev David Lechner:

LEGO MINDSTORMS EV3 has an LCD with a ST7586 controller. This adds a new
module for the ST7586 controller with parameters for the LEGO MINDSTORMS
EV3 LCD display.

Signed-off-by: David Lechner <da...@lechnology.com>
---


This looks good, even I understand the pixel packing now :-)
Now we wait for the DT maintainers to have their say.

Reviewed-by: Noralf Trønnes <nor...@tronnes.org>



Thanks, applied to drm-misc together with dt binding.

Noralf.


v4 changes:
* correct order for MAINTAINERS entry
* Drop code not used by LEGO EV3 (regulator, backlight, suspend/resume)
* Make gpios required
* Use lookup table for pixel packing algorithm
* Don't modify clip when used as function parameter
* Use roundup/rounddown macros


  MAINTAINERS  |   6 +
  drivers/gpu/drm/tinydrm/Kconfig  |  10 +
  drivers/gpu/drm/tinydrm/Makefile |   1 +
  drivers/gpu/drm/tinydrm/st7586.c | 428 
+++

  4 files changed, 445 insertions(+)
  create mode 100644 drivers/gpu/drm/tinydrm/st7586.c

diff --git a/MAINTAINERS b/MAINTAINERS
index a1e772e..19ca3e6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4380,6 +4380,12 @@ S:Orphan / Obsolete
  F:drivers/gpu/drm/sis/
  F:include/uapi/drm/sis_drm.h
  +DRM DRIVER FOR SITRONIX ST7586 PANELS
+M:David Lechner <da...@lechnology.com>
+S:Maintained
+F:drivers/gpu/drm/tinydrm/st7586.c
+F:Documentation/devicetree/bindings/display/st7586.txt
+
  DRM DRIVER FOR TDFX VIDEO CARDS
  S:Orphan / Obsolete
  F:drivers/gpu/drm/tdfx/
diff --git a/drivers/gpu/drm/tinydrm/Kconfig 
b/drivers/gpu/drm/tinydrm/Kconfig

index f17c3ca..2e790e7 100644
--- a/drivers/gpu/drm/tinydrm/Kconfig
+++ b/drivers/gpu/drm/tinydrm/Kconfig
@@ -32,3 +32,13 @@ config TINYDRM_REPAPER
2.71" TFT EPD Panel (E2271CS021)
  If M is selected the module will be called repaper.
+
+config TINYDRM_ST7586
+tristate "DRM support for Sitronix ST7586 display panels"
+depends on DRM_TINYDRM && SPI
+select TINYDRM_MIPI_DBI
+help
+  DRM driver for the following Sitronix ST7586 panels:
+  * LEGO MINDSTORMS EV3
+
+  If M is selected the module will be called st7586.
diff --git a/drivers/gpu/drm/tinydrm/Makefile 
b/drivers/gpu/drm/tinydrm/Makefile

index 95bb4d4..0c184bd 100644
--- a/drivers/gpu/drm/tinydrm/Makefile
+++ b/drivers/gpu/drm/tinydrm/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_TINYDRM_MIPI_DBI)+= mipi-dbi.o
  # Displays
  obj-$(CONFIG_TINYDRM_MI0283QT)+= mi0283qt.o
  obj-$(CONFIG_TINYDRM_REPAPER)+= repaper.o
+obj-$(CONFIG_TINYDRM_ST7586)+= st7586.o
diff --git a/drivers/gpu/drm/tinydrm/st7586.c 
b/drivers/gpu/drm/tinydrm/st7586.c

new file mode 100644
index 000..1b39d3f
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/st7586.c
@@ -0,0 +1,428 @@
+/*
+ * DRM driver for Sitronix ST7586 panels
+ *
+ * Copyright 2017 David Lechner <da...@lechnology.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+/* controller-specific commands */
+#define ST7586_DISP_MODE_GRAY0x38
+#define ST7586_DISP_MODE_MONO0x39
+#define ST7586_ENABLE_DDRAM0x3a
+#define ST7586_SET_DISP_DUTY0xb0
+#define ST7586_SET_PART_DISP0xb4
+#define ST7586_SET_NLINE_INV0xb5
+#define ST7586_SET_VOP0xc0
+#define ST7586_SET_BIAS_SYSTEM0xc3
+#define ST7586_SET_BOOST_LEVEL0xc4
+#define ST7586_SET_VOP_OFFSET0xc7
+#define ST7586_ENABLE_ANALOG0xd0
+#define ST7586_AUTO_READ_CTRL0xd7
+#define ST7586_OTP_RW_CTRL0xe0
+#define ST7586_OTP_CTRL_OUT0xe1
+#define ST7586_OTP_READ0xe3
+
+#define ST7586_DISP_CTRL_MXBIT(6)
+#define ST7586_DISP_CTRL_MYBIT(7)
+
+/*
+ * The ST7586 controller has an unusual pixel format where 2bpp 
grayscale is
+ * packed 3 pixels per byte with the first two pixels using 3 bits 
and the 3rd

+ * pixel using only 2 bits.
+ *
+ * |  D7  |  D6  |  D5  ||  |  || 2bpp |
+ * | (D4) | (D3) | (D2) ||  D1  |  D0  || GRAY |
+ * +--+--+--++--+--++--+
+ * |  1   |  1   |  1   ||  1   |  1   || 0  0 | black
+ * |  1   |  0   |  0   ||  1   |  0   || 0  1 | dark gray
+ * |  0   |  1   |  0   ||  0   |  1   || 1  0 | light gray
+ * |  0   |  0   |  0   ||  0   |  0   || 1  1 | white
+ */
+
+static const u8 st7586_lookup[] = { 0x7, 0x4, 0x2, 0x0 };
+
+static void st7586_xrgb_to_gray332(u8 *dst, void *vaddr,
+   struct drm_framebuffer *fb,
+   struct drm_clip_rect *clip)
+{
+size_t len = (clip->x2 - clip->x1) * (clip->y2

Re: [PATCH v4 3/5] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-11 Thread Noralf Trønnes


Den 09.08.2017 19.59, skrev Noralf Trønnes:


Den 07.08.2017 19.39, skrev David Lechner:

LEGO MINDSTORMS EV3 has an LCD with a ST7586 controller. This adds a new
module for the ST7586 controller with parameters for the LEGO MINDSTORMS
EV3 LCD display.

Signed-off-by: David Lechner 
---


This looks good, even I understand the pixel packing now :-)
Now we wait for the DT maintainers to have their say.

Reviewed-by: Noralf Trønnes 



Thanks, applied to drm-misc together with dt binding.

Noralf.


v4 changes:
* correct order for MAINTAINERS entry
* Drop code not used by LEGO EV3 (regulator, backlight, suspend/resume)
* Make gpios required
* Use lookup table for pixel packing algorithm
* Don't modify clip when used as function parameter
* Use roundup/rounddown macros


  MAINTAINERS  |   6 +
  drivers/gpu/drm/tinydrm/Kconfig  |  10 +
  drivers/gpu/drm/tinydrm/Makefile |   1 +
  drivers/gpu/drm/tinydrm/st7586.c | 428 
+++

  4 files changed, 445 insertions(+)
  create mode 100644 drivers/gpu/drm/tinydrm/st7586.c

diff --git a/MAINTAINERS b/MAINTAINERS
index a1e772e..19ca3e6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4380,6 +4380,12 @@ S:Orphan / Obsolete
  F:drivers/gpu/drm/sis/
  F:include/uapi/drm/sis_drm.h
  +DRM DRIVER FOR SITRONIX ST7586 PANELS
+M:David Lechner 
+S:Maintained
+F:drivers/gpu/drm/tinydrm/st7586.c
+F:Documentation/devicetree/bindings/display/st7586.txt
+
  DRM DRIVER FOR TDFX VIDEO CARDS
  S:Orphan / Obsolete
  F:drivers/gpu/drm/tdfx/
diff --git a/drivers/gpu/drm/tinydrm/Kconfig 
b/drivers/gpu/drm/tinydrm/Kconfig

index f17c3ca..2e790e7 100644
--- a/drivers/gpu/drm/tinydrm/Kconfig
+++ b/drivers/gpu/drm/tinydrm/Kconfig
@@ -32,3 +32,13 @@ config TINYDRM_REPAPER
2.71" TFT EPD Panel (E2271CS021)
  If M is selected the module will be called repaper.
+
+config TINYDRM_ST7586
+tristate "DRM support for Sitronix ST7586 display panels"
+depends on DRM_TINYDRM && SPI
+select TINYDRM_MIPI_DBI
+help
+  DRM driver for the following Sitronix ST7586 panels:
+  * LEGO MINDSTORMS EV3
+
+  If M is selected the module will be called st7586.
diff --git a/drivers/gpu/drm/tinydrm/Makefile 
b/drivers/gpu/drm/tinydrm/Makefile

index 95bb4d4..0c184bd 100644
--- a/drivers/gpu/drm/tinydrm/Makefile
+++ b/drivers/gpu/drm/tinydrm/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_TINYDRM_MIPI_DBI)+= mipi-dbi.o
  # Displays
  obj-$(CONFIG_TINYDRM_MI0283QT)+= mi0283qt.o
  obj-$(CONFIG_TINYDRM_REPAPER)+= repaper.o
+obj-$(CONFIG_TINYDRM_ST7586)+= st7586.o
diff --git a/drivers/gpu/drm/tinydrm/st7586.c 
b/drivers/gpu/drm/tinydrm/st7586.c

new file mode 100644
index 000..1b39d3f
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/st7586.c
@@ -0,0 +1,428 @@
+/*
+ * DRM driver for Sitronix ST7586 panels
+ *
+ * Copyright 2017 David Lechner 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+/* controller-specific commands */
+#define ST7586_DISP_MODE_GRAY0x38
+#define ST7586_DISP_MODE_MONO0x39
+#define ST7586_ENABLE_DDRAM0x3a
+#define ST7586_SET_DISP_DUTY0xb0
+#define ST7586_SET_PART_DISP0xb4
+#define ST7586_SET_NLINE_INV0xb5
+#define ST7586_SET_VOP0xc0
+#define ST7586_SET_BIAS_SYSTEM0xc3
+#define ST7586_SET_BOOST_LEVEL0xc4
+#define ST7586_SET_VOP_OFFSET0xc7
+#define ST7586_ENABLE_ANALOG0xd0
+#define ST7586_AUTO_READ_CTRL0xd7
+#define ST7586_OTP_RW_CTRL0xe0
+#define ST7586_OTP_CTRL_OUT0xe1
+#define ST7586_OTP_READ0xe3
+
+#define ST7586_DISP_CTRL_MXBIT(6)
+#define ST7586_DISP_CTRL_MYBIT(7)
+
+/*
+ * The ST7586 controller has an unusual pixel format where 2bpp 
grayscale is
+ * packed 3 pixels per byte with the first two pixels using 3 bits 
and the 3rd

+ * pixel using only 2 bits.
+ *
+ * |  D7  |  D6  |  D5  ||  |  || 2bpp |
+ * | (D4) | (D3) | (D2) ||  D1  |  D0  || GRAY |
+ * +--+--+--++--+--++--+
+ * |  1   |  1   |  1   ||  1   |  1   || 0  0 | black
+ * |  1   |  0   |  0   ||  1   |  0   || 0  1 | dark gray
+ * |  0   |  1   |  0   ||  0   |  1   || 1  0 | light gray
+ * |  0   |  0   |  0   ||  0   |  0   || 1  1 | white
+ */
+
+static const u8 st7586_lookup[] = { 0x7, 0x4, 0x2, 0x0 };
+
+static void st7586_xrgb_to_gray332(u8 *dst, void *vaddr,
+   struct drm_framebuffer *fb,
+   struct drm_clip_rect *clip)
+{
+size_t len = (clip->x2 - clip->x1) * (clip->y2 - clip->y1);
+unsigned int x, y;
+u8 *src, *buf, val;
+
+buf = kmalloc(len, GFP_KERN

Re: [PATCH libdrm] drm: Remove create_handle() drm_framebuffer "virtual".

2017-08-09 Thread Noralf Trønnes


Den 09.08.2017 01.42, skrev Joe Kniss:

Because all drivers currently use gem objects for framebuffer planes,
the virtual create_handle() is not required.  This change adds a
struct drm_gem_object *gems[4] field to drm_framebuffer and removes
create_handle() function pointer from drm_framebuffer_funcs.  The
corresponding *_create_handle() function is removed from each driver.

In many cases this change eliminates a struct *_framebuffer object,
as the only need for the derived struct is the addition of the gem
object pointer.

TESTED: compiled: allyesconfig ARCH=x86,arm platforms:i915, rockchip

Signed-off-by: Joe Kniss 
---


Hi Joe,

I'm also looking into adding gem objs to drm_framebuffer in this patch:
[PATCH v2 01/22] drm: Add GEM backed framebuffer library
https://lists.freedesktop.org/archives/dri-devel/2017-August/149782.html

[...]


diff --git a/drivers/gpu/drm/drm_fb_cma_helper.c 
b/drivers/gpu/drm/drm_fb_cma_helper.c
index ade319d10e70..f5f011b910b1 100644
--- a/drivers/gpu/drm/drm_fb_cma_helper.c
+++ b/drivers/gpu/drm/drm_fb_cma_helper.c
@@ -31,14 +31,9 @@
  
  #define DEFAULT_FBDEFIO_DELAY_MS 50
  
-struct drm_fb_cma {

-   struct drm_framebuffer  fb;
-   struct drm_gem_cma_object   *obj[4];
-};
-
  struct drm_fbdev_cma {
struct drm_fb_helperfb_helper;
-   struct drm_fb_cma   *fb;
+   struct drm_framebuffer  *fb;


This fb pointer isn't necessary, since fb_helper already has one.

Noralf.


const struct drm_framebuffer_funcs *fb_funcs;
  };
  
@@ -72,7 +67,6 @@ struct drm_fbdev_cma {

   *
   * static struct drm_framebuffer_funcs driver_fb_funcs = {
   * .destroy   = drm_fb_cma_destroy,
- * .create_handle = drm_fb_cma_create_handle,
   * .dirty = driver_fb_dirty,
   * };
   *
@@ -90,67 +84,50 @@ static inline struct drm_fbdev_cma *to_fbdev_cma(struct 
drm_fb_helper *helper)
return container_of(helper, struct drm_fbdev_cma, fb_helper);
  }
  
-static inline struct drm_fb_cma *to_fb_cma(struct drm_framebuffer *fb)

-{
-   return container_of(fb, struct drm_fb_cma, fb);
-}
-
  void drm_fb_cma_destroy(struct drm_framebuffer *fb)
  {
-   struct drm_fb_cma *fb_cma = to_fb_cma(fb);
int i;
  
  	for (i = 0; i < 4; i++) {

-   if (fb_cma->obj[i])
-   drm_gem_object_put_unlocked(_cma->obj[i]->base);
+   if (fb->gem_objs[i])
+   drm_gem_object_put_unlocked(fb->gem_objs[i]);
}
  
  	drm_framebuffer_cleanup(fb);

-   kfree(fb_cma);
+   kfree(fb);
  }
  EXPORT_SYMBOL(drm_fb_cma_destroy);
  
-int drm_fb_cma_create_handle(struct drm_framebuffer *fb,

-   struct drm_file *file_priv, unsigned int *handle)
-{
-   struct drm_fb_cma *fb_cma = to_fb_cma(fb);
-
-   return drm_gem_handle_create(file_priv,
-   _cma->obj[0]->base, handle);
-}
-EXPORT_SYMBOL(drm_fb_cma_create_handle);
-
  static struct drm_framebuffer_funcs drm_fb_cma_funcs = {
.destroy= drm_fb_cma_destroy,
-   .create_handle  = drm_fb_cma_create_handle,
  };
  
-static struct drm_fb_cma *drm_fb_cma_alloc(struct drm_device *dev,

+static struct drm_framebuffer *drm_fb_cma_alloc(struct drm_device *dev,
const struct drm_mode_fb_cmd2 *mode_cmd,
struct drm_gem_cma_object **obj,
unsigned int num_planes, const struct drm_framebuffer_funcs *funcs)
  {
-   struct drm_fb_cma *fb_cma;
+   struct drm_framebuffer *fb;
int ret;
int i;
  
-	fb_cma = kzalloc(sizeof(*fb_cma), GFP_KERNEL);

-   if (!fb_cma)
+   fb = kzalloc(sizeof(*fb), GFP_KERNEL);
+   if (!fb)
return ERR_PTR(-ENOMEM);
  
-	drm_helper_mode_fill_fb_struct(dev, _cma->fb, mode_cmd);

+   drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
  
  	for (i = 0; i < num_planes; i++)

-   fb_cma->obj[i] = obj[i];
+   fb->gem_objs[i] = [i]->base;
  
-	ret = drm_framebuffer_init(dev, _cma->fb, funcs);

+   ret = drm_framebuffer_init(dev, fb, funcs);
if (ret) {
dev_err(dev->dev, "Failed to initialize framebuffer: %d\n", 
ret);
-   kfree(fb_cma);
+   kfree(fb);
return ERR_PTR(ret);
}
  
-	return fb_cma;

+   return fb;
  }
  
  /**

@@ -171,7 +148,7 @@ struct drm_framebuffer *drm_fb_cma_create_with_funcs(struct 
drm_device *dev,
const struct drm_framebuffer_funcs *funcs)
  {
const struct drm_format_info *info;
-   struct drm_fb_cma *fb_cma;
+   struct drm_framebuffer *fb;
struct drm_gem_cma_object *objs[4];
struct drm_gem_object *obj;
int ret;
@@ -205,13 +182,13 @@ struct drm_framebuffer 
*drm_fb_cma_create_with_funcs(struct drm_device *dev,
objs[i] = to_drm_gem_cma_obj(obj);
}
  
-	fb_cma = drm_fb_cma_alloc(dev, mode_cmd, objs, i, funcs);

-   if (IS_ERR(fb_cma)) {
-   ret = 

Re: [PATCH libdrm] drm: Remove create_handle() drm_framebuffer "virtual".

2017-08-09 Thread Noralf Trønnes


Den 09.08.2017 01.42, skrev Joe Kniss:

Because all drivers currently use gem objects for framebuffer planes,
the virtual create_handle() is not required.  This change adds a
struct drm_gem_object *gems[4] field to drm_framebuffer and removes
create_handle() function pointer from drm_framebuffer_funcs.  The
corresponding *_create_handle() function is removed from each driver.

In many cases this change eliminates a struct *_framebuffer object,
as the only need for the derived struct is the addition of the gem
object pointer.

TESTED: compiled: allyesconfig ARCH=x86,arm platforms:i915, rockchip

Signed-off-by: Joe Kniss 
---


Hi Joe,

I'm also looking into adding gem objs to drm_framebuffer in this patch:
[PATCH v2 01/22] drm: Add GEM backed framebuffer library
https://lists.freedesktop.org/archives/dri-devel/2017-August/149782.html

[...]


diff --git a/drivers/gpu/drm/drm_fb_cma_helper.c 
b/drivers/gpu/drm/drm_fb_cma_helper.c
index ade319d10e70..f5f011b910b1 100644
--- a/drivers/gpu/drm/drm_fb_cma_helper.c
+++ b/drivers/gpu/drm/drm_fb_cma_helper.c
@@ -31,14 +31,9 @@
  
  #define DEFAULT_FBDEFIO_DELAY_MS 50
  
-struct drm_fb_cma {

-   struct drm_framebuffer  fb;
-   struct drm_gem_cma_object   *obj[4];
-};
-
  struct drm_fbdev_cma {
struct drm_fb_helperfb_helper;
-   struct drm_fb_cma   *fb;
+   struct drm_framebuffer  *fb;


This fb pointer isn't necessary, since fb_helper already has one.

Noralf.


const struct drm_framebuffer_funcs *fb_funcs;
  };
  
@@ -72,7 +67,6 @@ struct drm_fbdev_cma {

   *
   * static struct drm_framebuffer_funcs driver_fb_funcs = {
   * .destroy   = drm_fb_cma_destroy,
- * .create_handle = drm_fb_cma_create_handle,
   * .dirty = driver_fb_dirty,
   * };
   *
@@ -90,67 +84,50 @@ static inline struct drm_fbdev_cma *to_fbdev_cma(struct 
drm_fb_helper *helper)
return container_of(helper, struct drm_fbdev_cma, fb_helper);
  }
  
-static inline struct drm_fb_cma *to_fb_cma(struct drm_framebuffer *fb)

-{
-   return container_of(fb, struct drm_fb_cma, fb);
-}
-
  void drm_fb_cma_destroy(struct drm_framebuffer *fb)
  {
-   struct drm_fb_cma *fb_cma = to_fb_cma(fb);
int i;
  
  	for (i = 0; i < 4; i++) {

-   if (fb_cma->obj[i])
-   drm_gem_object_put_unlocked(_cma->obj[i]->base);
+   if (fb->gem_objs[i])
+   drm_gem_object_put_unlocked(fb->gem_objs[i]);
}
  
  	drm_framebuffer_cleanup(fb);

-   kfree(fb_cma);
+   kfree(fb);
  }
  EXPORT_SYMBOL(drm_fb_cma_destroy);
  
-int drm_fb_cma_create_handle(struct drm_framebuffer *fb,

-   struct drm_file *file_priv, unsigned int *handle)
-{
-   struct drm_fb_cma *fb_cma = to_fb_cma(fb);
-
-   return drm_gem_handle_create(file_priv,
-   _cma->obj[0]->base, handle);
-}
-EXPORT_SYMBOL(drm_fb_cma_create_handle);
-
  static struct drm_framebuffer_funcs drm_fb_cma_funcs = {
.destroy= drm_fb_cma_destroy,
-   .create_handle  = drm_fb_cma_create_handle,
  };
  
-static struct drm_fb_cma *drm_fb_cma_alloc(struct drm_device *dev,

+static struct drm_framebuffer *drm_fb_cma_alloc(struct drm_device *dev,
const struct drm_mode_fb_cmd2 *mode_cmd,
struct drm_gem_cma_object **obj,
unsigned int num_planes, const struct drm_framebuffer_funcs *funcs)
  {
-   struct drm_fb_cma *fb_cma;
+   struct drm_framebuffer *fb;
int ret;
int i;
  
-	fb_cma = kzalloc(sizeof(*fb_cma), GFP_KERNEL);

-   if (!fb_cma)
+   fb = kzalloc(sizeof(*fb), GFP_KERNEL);
+   if (!fb)
return ERR_PTR(-ENOMEM);
  
-	drm_helper_mode_fill_fb_struct(dev, _cma->fb, mode_cmd);

+   drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
  
  	for (i = 0; i < num_planes; i++)

-   fb_cma->obj[i] = obj[i];
+   fb->gem_objs[i] = [i]->base;
  
-	ret = drm_framebuffer_init(dev, _cma->fb, funcs);

+   ret = drm_framebuffer_init(dev, fb, funcs);
if (ret) {
dev_err(dev->dev, "Failed to initialize framebuffer: %d\n", 
ret);
-   kfree(fb_cma);
+   kfree(fb);
return ERR_PTR(ret);
}
  
-	return fb_cma;

+   return fb;
  }
  
  /**

@@ -171,7 +148,7 @@ struct drm_framebuffer *drm_fb_cma_create_with_funcs(struct 
drm_device *dev,
const struct drm_framebuffer_funcs *funcs)
  {
const struct drm_format_info *info;
-   struct drm_fb_cma *fb_cma;
+   struct drm_framebuffer *fb;
struct drm_gem_cma_object *objs[4];
struct drm_gem_object *obj;
int ret;
@@ -205,13 +182,13 @@ struct drm_framebuffer 
*drm_fb_cma_create_with_funcs(struct drm_device *dev,
objs[i] = to_drm_gem_cma_obj(obj);
}
  
-	fb_cma = drm_fb_cma_alloc(dev, mode_cmd, objs, i, funcs);

-   if (IS_ERR(fb_cma)) {
-   ret = PTR_ERR(fb_cma);
+   

Re: [PATCH v4 3/5] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-09 Thread Noralf Trønnes


Den 07.08.2017 19.39, skrev David Lechner:

LEGO MINDSTORMS EV3 has an LCD with a ST7586 controller. This adds a new
module for the ST7586 controller with parameters for the LEGO MINDSTORMS
EV3 LCD display.

Signed-off-by: David Lechner <da...@lechnology.com>
---


This looks good, even I understand the pixel packing now :-)
Now we wait for the DT maintainers to have their say.

Reviewed-by: Noralf Trønnes <nor...@tronnes.org>


v4 changes:
* correct order for MAINTAINERS entry
* Drop code not used by LEGO EV3 (regulator, backlight, suspend/resume)
* Make gpios required
* Use lookup table for pixel packing algorithm
* Don't modify clip when used as function parameter
* Use roundup/rounddown macros


  MAINTAINERS  |   6 +
  drivers/gpu/drm/tinydrm/Kconfig  |  10 +
  drivers/gpu/drm/tinydrm/Makefile |   1 +
  drivers/gpu/drm/tinydrm/st7586.c | 428 +++
  4 files changed, 445 insertions(+)
  create mode 100644 drivers/gpu/drm/tinydrm/st7586.c

diff --git a/MAINTAINERS b/MAINTAINERS
index a1e772e..19ca3e6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4380,6 +4380,12 @@ S:   Orphan / Obsolete
  F:drivers/gpu/drm/sis/
  F:include/uapi/drm/sis_drm.h
  
+DRM DRIVER FOR SITRONIX ST7586 PANELS

+M: David Lechner <da...@lechnology.com>
+S: Maintained
+F: drivers/gpu/drm/tinydrm/st7586.c
+F: Documentation/devicetree/bindings/display/st7586.txt
+
  DRM DRIVER FOR TDFX VIDEO CARDS
  S:Orphan / Obsolete
  F:drivers/gpu/drm/tdfx/
diff --git a/drivers/gpu/drm/tinydrm/Kconfig b/drivers/gpu/drm/tinydrm/Kconfig
index f17c3ca..2e790e7 100644
--- a/drivers/gpu/drm/tinydrm/Kconfig
+++ b/drivers/gpu/drm/tinydrm/Kconfig
@@ -32,3 +32,13 @@ config TINYDRM_REPAPER
  2.71" TFT EPD Panel (E2271CS021)
  
  	  If M is selected the module will be called repaper.

+
+config TINYDRM_ST7586
+   tristate "DRM support for Sitronix ST7586 display panels"
+   depends on DRM_TINYDRM && SPI
+   select TINYDRM_MIPI_DBI
+   help
+ DRM driver for the following Sitronix ST7586 panels:
+ * LEGO MINDSTORMS EV3
+
+ If M is selected the module will be called st7586.
diff --git a/drivers/gpu/drm/tinydrm/Makefile b/drivers/gpu/drm/tinydrm/Makefile
index 95bb4d4..0c184bd 100644
--- a/drivers/gpu/drm/tinydrm/Makefile
+++ b/drivers/gpu/drm/tinydrm/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_TINYDRM_MIPI_DBI)  += mipi-dbi.o
  # Displays
  obj-$(CONFIG_TINYDRM_MI0283QT)+= mi0283qt.o
  obj-$(CONFIG_TINYDRM_REPAPER) += repaper.o
+obj-$(CONFIG_TINYDRM_ST7586)   += st7586.o
diff --git a/drivers/gpu/drm/tinydrm/st7586.c b/drivers/gpu/drm/tinydrm/st7586.c
new file mode 100644
index 000..1b39d3f
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/st7586.c
@@ -0,0 +1,428 @@
+/*
+ * DRM driver for Sitronix ST7586 panels
+ *
+ * Copyright 2017 David Lechner <da...@lechnology.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+/* controller-specific commands */
+#define ST7586_DISP_MODE_GRAY  0x38
+#define ST7586_DISP_MODE_MONO  0x39
+#define ST7586_ENABLE_DDRAM0x3a
+#define ST7586_SET_DISP_DUTY   0xb0
+#define ST7586_SET_PART_DISP   0xb4
+#define ST7586_SET_NLINE_INV   0xb5
+#define ST7586_SET_VOP 0xc0
+#define ST7586_SET_BIAS_SYSTEM 0xc3
+#define ST7586_SET_BOOST_LEVEL 0xc4
+#define ST7586_SET_VOP_OFFSET  0xc7
+#define ST7586_ENABLE_ANALOG   0xd0
+#define ST7586_AUTO_READ_CTRL  0xd7
+#define ST7586_OTP_RW_CTRL 0xe0
+#define ST7586_OTP_CTRL_OUT0xe1
+#define ST7586_OTP_READ0xe3
+
+#define ST7586_DISP_CTRL_MXBIT(6)
+#define ST7586_DISP_CTRL_MYBIT(7)
+
+/*
+ * The ST7586 controller has an unusual pixel format where 2bpp grayscale is
+ * packed 3 pixels per byte with the first two pixels using 3 bits and the 3rd
+ * pixel using only 2 bits.
+ *
+ * |  D7  |  D6  |  D5  ||  |  || 2bpp |
+ * | (D4) | (D3) | (D2) ||  D1  |  D0  || GRAY |
+ * +--+--+--++--+--++--+
+ * |  1   |  1   |  1   ||  1   |  1   || 0  0 | black
+ * |  1   |  0   |  0   ||  1   |  0   || 0  1 | dark gray
+ * |  0   |  1   |  0   ||  0   |  1   || 1  0 | light gray
+ * |  0   |  0   |  0   ||  0   |  0   || 1  1 | white
+ */
+
+static const u8 st7586_lookup[] = { 0x7, 0x4, 0x2, 0x0 };
+
+static void st7586_xrgb_to_gray332(u8 *dst, void *vaddr,
+  struct drm_framebuffer *fb,
+  struct drm_clip_rect *clip)
+{
+   size_t len = (clip->x2 - clip->x1) * (clip->y2 - clip->y1);
+   unsigned int x, y;
+   

Re: [PATCH v4 3/5] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-09 Thread Noralf Trønnes


Den 07.08.2017 19.39, skrev David Lechner:

LEGO MINDSTORMS EV3 has an LCD with a ST7586 controller. This adds a new
module for the ST7586 controller with parameters for the LEGO MINDSTORMS
EV3 LCD display.

Signed-off-by: David Lechner 
---


This looks good, even I understand the pixel packing now :-)
Now we wait for the DT maintainers to have their say.

Reviewed-by: Noralf Trønnes 


v4 changes:
* correct order for MAINTAINERS entry
* Drop code not used by LEGO EV3 (regulator, backlight, suspend/resume)
* Make gpios required
* Use lookup table for pixel packing algorithm
* Don't modify clip when used as function parameter
* Use roundup/rounddown macros


  MAINTAINERS  |   6 +
  drivers/gpu/drm/tinydrm/Kconfig  |  10 +
  drivers/gpu/drm/tinydrm/Makefile |   1 +
  drivers/gpu/drm/tinydrm/st7586.c | 428 +++
  4 files changed, 445 insertions(+)
  create mode 100644 drivers/gpu/drm/tinydrm/st7586.c

diff --git a/MAINTAINERS b/MAINTAINERS
index a1e772e..19ca3e6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4380,6 +4380,12 @@ S:   Orphan / Obsolete
  F:drivers/gpu/drm/sis/
  F:include/uapi/drm/sis_drm.h
  
+DRM DRIVER FOR SITRONIX ST7586 PANELS

+M: David Lechner 
+S: Maintained
+F: drivers/gpu/drm/tinydrm/st7586.c
+F: Documentation/devicetree/bindings/display/st7586.txt
+
  DRM DRIVER FOR TDFX VIDEO CARDS
  S:Orphan / Obsolete
  F:drivers/gpu/drm/tdfx/
diff --git a/drivers/gpu/drm/tinydrm/Kconfig b/drivers/gpu/drm/tinydrm/Kconfig
index f17c3ca..2e790e7 100644
--- a/drivers/gpu/drm/tinydrm/Kconfig
+++ b/drivers/gpu/drm/tinydrm/Kconfig
@@ -32,3 +32,13 @@ config TINYDRM_REPAPER
  2.71" TFT EPD Panel (E2271CS021)
  
  	  If M is selected the module will be called repaper.

+
+config TINYDRM_ST7586
+   tristate "DRM support for Sitronix ST7586 display panels"
+   depends on DRM_TINYDRM && SPI
+   select TINYDRM_MIPI_DBI
+   help
+ DRM driver for the following Sitronix ST7586 panels:
+ * LEGO MINDSTORMS EV3
+
+ If M is selected the module will be called st7586.
diff --git a/drivers/gpu/drm/tinydrm/Makefile b/drivers/gpu/drm/tinydrm/Makefile
index 95bb4d4..0c184bd 100644
--- a/drivers/gpu/drm/tinydrm/Makefile
+++ b/drivers/gpu/drm/tinydrm/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_TINYDRM_MIPI_DBI)  += mipi-dbi.o
  # Displays
  obj-$(CONFIG_TINYDRM_MI0283QT)+= mi0283qt.o
  obj-$(CONFIG_TINYDRM_REPAPER) += repaper.o
+obj-$(CONFIG_TINYDRM_ST7586)   += st7586.o
diff --git a/drivers/gpu/drm/tinydrm/st7586.c b/drivers/gpu/drm/tinydrm/st7586.c
new file mode 100644
index 000..1b39d3f
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/st7586.c
@@ -0,0 +1,428 @@
+/*
+ * DRM driver for Sitronix ST7586 panels
+ *
+ * Copyright 2017 David Lechner 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+/* controller-specific commands */
+#define ST7586_DISP_MODE_GRAY  0x38
+#define ST7586_DISP_MODE_MONO  0x39
+#define ST7586_ENABLE_DDRAM0x3a
+#define ST7586_SET_DISP_DUTY   0xb0
+#define ST7586_SET_PART_DISP   0xb4
+#define ST7586_SET_NLINE_INV   0xb5
+#define ST7586_SET_VOP 0xc0
+#define ST7586_SET_BIAS_SYSTEM 0xc3
+#define ST7586_SET_BOOST_LEVEL 0xc4
+#define ST7586_SET_VOP_OFFSET  0xc7
+#define ST7586_ENABLE_ANALOG   0xd0
+#define ST7586_AUTO_READ_CTRL  0xd7
+#define ST7586_OTP_RW_CTRL 0xe0
+#define ST7586_OTP_CTRL_OUT0xe1
+#define ST7586_OTP_READ0xe3
+
+#define ST7586_DISP_CTRL_MXBIT(6)
+#define ST7586_DISP_CTRL_MYBIT(7)
+
+/*
+ * The ST7586 controller has an unusual pixel format where 2bpp grayscale is
+ * packed 3 pixels per byte with the first two pixels using 3 bits and the 3rd
+ * pixel using only 2 bits.
+ *
+ * |  D7  |  D6  |  D5  ||  |  || 2bpp |
+ * | (D4) | (D3) | (D2) ||  D1  |  D0  || GRAY |
+ * +--+--+--++--+--++--+
+ * |  1   |  1   |  1   ||  1   |  1   || 0  0 | black
+ * |  1   |  0   |  0   ||  1   |  0   || 0  1 | dark gray
+ * |  0   |  1   |  0   ||  0   |  1   || 1  0 | light gray
+ * |  0   |  0   |  0   ||  0   |  0   || 1  1 | white
+ */
+
+static const u8 st7586_lookup[] = { 0x7, 0x4, 0x2, 0x0 };
+
+static void st7586_xrgb_to_gray332(u8 *dst, void *vaddr,
+  struct drm_framebuffer *fb,
+  struct drm_clip_rect *clip)
+{
+   size_t len = (clip->x2 - clip->x1) * (clip->y2 - clip->y1);
+   unsigned int x, y;
+   u8 *src, *buf, val;
+
+   buf = kmalloc(len, GFP_KERNEL);
+   if (!buf)
+   return;
+
+ 

Re: [PATCH v4 1/5] drm/tinydrm: Generalize tinydrm_xrgb8888_to_gray8()

2017-08-09 Thread Noralf Trønnes


Den 07.08.2017 19.39, skrev David Lechner:

This adds parameters for vaddr and clip to tinydrm_xrgb_to_gray8() to
make it more generic.

dma_buf_{begin,end}_cpu_access() are moved out to the repaper driver.

Return type is change to void to simplify error handling by callers.

Signed-off-by: David Lechner 
---


Thanks for doing this, applied to drm-misc.

Noralf.


v4 changes:
* Change return type to void.


  drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 42 +-
  drivers/gpu/drm/tinydrm/repaper.c  | 28 +++--
  include/drm/tinydrm/tinydrm-helpers.h  |  3 +-
  3 files changed, 41 insertions(+), 32 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c 
b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
index 75808bb..bd6cce0 100644
--- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
+++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
@@ -185,7 +185,9 @@ EXPORT_SYMBOL(tinydrm_xrgb_to_rgb565);
  /**
   * tinydrm_xrgb_to_gray8 - Convert XRGB to grayscale
   * @dst: 8-bit grayscale destination buffer
+ * @vaddr: XRGB source buffer
   * @fb: DRM framebuffer
+ * @clip: Clip rectangle area to copy
   *
   * Drm doesn't have native monochrome or grayscale support.
   * Such drivers can announce the commonly supported XR24 format to userspace
@@ -195,41 +197,31 @@ EXPORT_SYMBOL(tinydrm_xrgb_to_rgb565);
   * where 1 means foreground color and 0 background color.
   *
   * ITU BT.601 is used for the RGB -> luma (brightness) conversion.
- *
- * Returns:
- * Zero on success, negative error code on failure.
   */
-int tinydrm_xrgb_to_gray8(u8 *dst, struct drm_framebuffer *fb)
+void tinydrm_xrgb_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer 
*fb,
+  struct drm_clip_rect *clip)
  {
-   struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
-   struct dma_buf_attachment *import_attach = cma_obj->base.import_attach;
-   unsigned int x, y, pitch = fb->pitches[0];
-   int ret = 0;
+   unsigned int len = (clip->x2 - clip->x1) * sizeof(u32);
+   unsigned int x, y;
void *buf;
u32 *src;
  
  	if (WARN_ON(fb->format->format != DRM_FORMAT_XRGB))

-   return -EINVAL;
+   return;
/*
 * The cma memory is write-combined so reads are uncached.
 * Speed up by fetching one line at a time.
 */
-   buf = kmalloc(pitch, GFP_KERNEL);
+   buf = kmalloc(len, GFP_KERNEL);
if (!buf)
-   return -ENOMEM;
-
-   if (import_attach) {
-   ret = dma_buf_begin_cpu_access(import_attach->dmabuf,
-  DMA_FROM_DEVICE);
-   if (ret)
-   goto err_free;
-   }
+   return;
  
-	for (y = 0; y < fb->height; y++) {

-   src = cma_obj->vaddr + (y * pitch);
-   memcpy(buf, src, pitch);
+   for (y = clip->y1; y < clip->y2; y++) {
+   src = vaddr + (y * fb->pitches[0]);
+   src += clip->x1;
+   memcpy(buf, src, len);
src = buf;
-   for (x = 0; x < fb->width; x++) {
+   for (x = clip->x1; x < clip->x2; x++) {
u8 r = (*src & 0x00ff) >> 16;
u8 g = (*src & 0xff00) >> 8;
u8 b =  *src & 0x00ff;
@@ -240,13 +232,7 @@ int tinydrm_xrgb_to_gray8(u8 *dst, struct 
drm_framebuffer *fb)
}
}
  
-	if (import_attach)

-   ret = dma_buf_end_cpu_access(import_attach->dmabuf,
-DMA_FROM_DEVICE);
-err_free:
kfree(buf);
-
-   return ret;
  }
  EXPORT_SYMBOL(tinydrm_xrgb_to_gray8);
  
diff --git a/drivers/gpu/drm/tinydrm/repaper.c b/drivers/gpu/drm/tinydrm/repaper.c

index 3343d3f..30dc97b 100644
--- a/drivers/gpu/drm/tinydrm/repaper.c
+++ b/drivers/gpu/drm/tinydrm/repaper.c
@@ -18,6 +18,7 @@
   */
  
  #include 

+#include 
  #include 
  #include 
  #include 
@@ -525,11 +526,20 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb,
struct drm_clip_rect *clips,
unsigned int num_clips)
  {
+   struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
+   struct dma_buf_attachment *import_attach = cma_obj->base.import_attach;
struct tinydrm_device *tdev = fb->dev->dev_private;
struct repaper_epd *epd = epd_from_tinydrm(tdev);
+   struct drm_clip_rect clip;
u8 *buf = NULL;
int ret = 0;
  
+	/* repaper can't do partial updates */

+   clip.x1 = 0;
+   clip.x2 = fb->width;
+   clip.y1 = 0;
+   clip.y2 = fb->height;
+
mutex_lock(>dirty_lock);
  
  	if (!epd->enabled)

@@ -550,9 +560,21 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb,
goto 

Re: [PATCH v4 1/5] drm/tinydrm: Generalize tinydrm_xrgb8888_to_gray8()

2017-08-09 Thread Noralf Trønnes


Den 07.08.2017 19.39, skrev David Lechner:

This adds parameters for vaddr and clip to tinydrm_xrgb_to_gray8() to
make it more generic.

dma_buf_{begin,end}_cpu_access() are moved out to the repaper driver.

Return type is change to void to simplify error handling by callers.

Signed-off-by: David Lechner 
---


Thanks for doing this, applied to drm-misc.

Noralf.


v4 changes:
* Change return type to void.


  drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 42 +-
  drivers/gpu/drm/tinydrm/repaper.c  | 28 +++--
  include/drm/tinydrm/tinydrm-helpers.h  |  3 +-
  3 files changed, 41 insertions(+), 32 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c 
b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
index 75808bb..bd6cce0 100644
--- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
+++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
@@ -185,7 +185,9 @@ EXPORT_SYMBOL(tinydrm_xrgb_to_rgb565);
  /**
   * tinydrm_xrgb_to_gray8 - Convert XRGB to grayscale
   * @dst: 8-bit grayscale destination buffer
+ * @vaddr: XRGB source buffer
   * @fb: DRM framebuffer
+ * @clip: Clip rectangle area to copy
   *
   * Drm doesn't have native monochrome or grayscale support.
   * Such drivers can announce the commonly supported XR24 format to userspace
@@ -195,41 +197,31 @@ EXPORT_SYMBOL(tinydrm_xrgb_to_rgb565);
   * where 1 means foreground color and 0 background color.
   *
   * ITU BT.601 is used for the RGB -> luma (brightness) conversion.
- *
- * Returns:
- * Zero on success, negative error code on failure.
   */
-int tinydrm_xrgb_to_gray8(u8 *dst, struct drm_framebuffer *fb)
+void tinydrm_xrgb_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer 
*fb,
+  struct drm_clip_rect *clip)
  {
-   struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
-   struct dma_buf_attachment *import_attach = cma_obj->base.import_attach;
-   unsigned int x, y, pitch = fb->pitches[0];
-   int ret = 0;
+   unsigned int len = (clip->x2 - clip->x1) * sizeof(u32);
+   unsigned int x, y;
void *buf;
u32 *src;
  
  	if (WARN_ON(fb->format->format != DRM_FORMAT_XRGB))

-   return -EINVAL;
+   return;
/*
 * The cma memory is write-combined so reads are uncached.
 * Speed up by fetching one line at a time.
 */
-   buf = kmalloc(pitch, GFP_KERNEL);
+   buf = kmalloc(len, GFP_KERNEL);
if (!buf)
-   return -ENOMEM;
-
-   if (import_attach) {
-   ret = dma_buf_begin_cpu_access(import_attach->dmabuf,
-  DMA_FROM_DEVICE);
-   if (ret)
-   goto err_free;
-   }
+   return;
  
-	for (y = 0; y < fb->height; y++) {

-   src = cma_obj->vaddr + (y * pitch);
-   memcpy(buf, src, pitch);
+   for (y = clip->y1; y < clip->y2; y++) {
+   src = vaddr + (y * fb->pitches[0]);
+   src += clip->x1;
+   memcpy(buf, src, len);
src = buf;
-   for (x = 0; x < fb->width; x++) {
+   for (x = clip->x1; x < clip->x2; x++) {
u8 r = (*src & 0x00ff) >> 16;
u8 g = (*src & 0xff00) >> 8;
u8 b =  *src & 0x00ff;
@@ -240,13 +232,7 @@ int tinydrm_xrgb_to_gray8(u8 *dst, struct 
drm_framebuffer *fb)
}
}
  
-	if (import_attach)

-   ret = dma_buf_end_cpu_access(import_attach->dmabuf,
-DMA_FROM_DEVICE);
-err_free:
kfree(buf);
-
-   return ret;
  }
  EXPORT_SYMBOL(tinydrm_xrgb_to_gray8);
  
diff --git a/drivers/gpu/drm/tinydrm/repaper.c b/drivers/gpu/drm/tinydrm/repaper.c

index 3343d3f..30dc97b 100644
--- a/drivers/gpu/drm/tinydrm/repaper.c
+++ b/drivers/gpu/drm/tinydrm/repaper.c
@@ -18,6 +18,7 @@
   */
  
  #include 

+#include 
  #include 
  #include 
  #include 
@@ -525,11 +526,20 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb,
struct drm_clip_rect *clips,
unsigned int num_clips)
  {
+   struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
+   struct dma_buf_attachment *import_attach = cma_obj->base.import_attach;
struct tinydrm_device *tdev = fb->dev->dev_private;
struct repaper_epd *epd = epd_from_tinydrm(tdev);
+   struct drm_clip_rect clip;
u8 *buf = NULL;
int ret = 0;
  
+	/* repaper can't do partial updates */

+   clip.x1 = 0;
+   clip.x2 = fb->width;
+   clip.y1 = 0;
+   clip.y2 = fb->height;
+
mutex_lock(>dirty_lock);
  
  	if (!epd->enabled)

@@ -550,9 +560,21 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb,
goto out_unlock;
}
  
-	ret 

Re: [PATCH v5 2/6] drm/bridge: Add a devm_ allocator for panel bridge.

2017-08-07 Thread Noralf Trønnes


Den 07.08.2017 12.22, skrev Laurent Pinchart:

Hi Daniel,

On Monday 07 Aug 2017 11:25:07 Daniel Vetter wrote:

On Sat, Aug 05, 2017 at 12:59:07PM +0200, Noralf Trønnes wrote:

Den 05.08.2017 00.19, skrev Ilia Mirkin:

On Fri, Aug 4, 2017 at 4:43 PM, Eric Anholt <e...@anholt.net> wrote:

Laurent Pinchart <laurent.pinch...@ideasonboard.com> writes:

On Tuesday 18 Jul 2017 14:05:06 Eric Anholt wrote:

This will let drivers reduce the error cleanup they need, in
particular the "is_panel_bridge" flag.

v2: Slight cleanup of remove function by Andrzej

I just want to point out that, in the context of Daniel's work on
hot-unplug, 90% of the devm_* allocations are wrong and will get in
the way. All DRM core objects that are accessible one way or
another from userspace will need to be properly reference-counted
and freed only when the last reference disappears, which could be
well after the corresponding device is removed. I believe this
could be one such objects :-/

Sure, if you're hotplugging, your life is pain.  For non-hotpluggable
devices, like our SOC platform devices (current panel-bridge
consumers), this still seems like an excellent simplification of
memory management.

At that point you may as well make your module non-unloadable, and
return failure when trying to remove a device from management by the
driver (whatever the opposite of "probe" is, I forget). Hotplugging
doesn't only happen when physically removing, it can happen for all
kinds of reasons... and userspace may still hold references in some of
those cases.

If drm_open() gets a ref on dev->dev and puts it in drm_release(),
won't that delay devm_* cleanup until userspace is done?

No. drm_device is the thing that is refcounted for userspace references
like open FD (we're not perfect about it, e.g. sysfs and dma-buf/fence
don't).

devm_ otoh is tied to the lifetime of the underlying device, and that one
can get outlived by drm_device. Or at least afaiui, devm_ stuff is nuked
on unplug, and not when the final sw reference of the struct device
disappears.

Not sure tough, it's complicated.

It's complicated when you have to understand the behaviour by reading the
code, but the behaviour isn't that complex. devm resources are released both

1. right after the driver's .remove() operation returns
2. when the device is deleted (last reference released)

It's the first one that makes devm_* allocation unsuitable for any structure
that is accessible from userspace (such as in file operation handlers).



I see, when the device is removed, the driver is released. No help
holding a ref on struct device.
I did a test and this is the stack trace in devm_tinydrm_release():

[  129.433179] [] (unwind_backtrace) from [] 
(show_stack+0x20/0x24)
[  129.433213] [] (show_stack) from [] 
(dump_stack+0x20/0x28)
[  129.433242] [] (dump_stack) from [] 
(__warn+0xe4/0x10c)
[  129.433264] [] (__warn) from [] 
(warn_slowpath_null+0x30/0x38)
[  129.433324] [] (warn_slowpath_null) from [] 
(devm_tinydrm_release+0x24/0x48 [tinydrm])
[  129.433389] [] (devm_tinydrm_release [tinydrm]) from 
[] (devm_action_release+0x1c/0x20)
[  129.433414] [] (devm_action_release) from [] 
(release_nodes+0x188/0x21c)
[  129.433437] [] (release_nodes) from [] 
(devres_release_all+0x44/0x64)
[  129.433461] [] (devres_release_all) from [] 
(__device_release_driver+0x9c/0x118)
[  129.433480] [] (__device_release_driver) from [] 
(device_release_driver+0x2c/0x38)
[  129.433499] [] (device_release_driver) from [] 
(bus_remove_device+0xe4/0x114)
[  129.433532] [] (bus_remove_device) from [] 
(device_del+0x118/0x22c)
[  129.433554] [] (device_del) from [] 
(device_unregister+0x1c/0x30)
[  129.433592] [] (device_unregister) from [] 
(spi_unregister_device+0x60/0x64)
[  129.433617] [] (spi_unregister_device) from [] 
(of_spi_notify+0x70/0x164)
[  129.433642] [] (of_spi_notify) from [] 
(notifier_call_chain+0x54/0x94)
[  129.433664] [] (notifier_call_chain) from [] 
(__blocking_notifier_call_chain+0x58/0x70)
[  129.433683] [] (__blocking_notifier_call_chain) from 
[] (blocking_notifier_call_chain+0x28/0x30)
[  129.433721] [] (blocking_notifier_call_chain) from 
[] (__of_changeset_entry_notify+0x90/0xe0)
[  129.433748] [] (__of_changeset_entry_notify) from 
[] (__of_changeset_revert+0x70/0xcc)
[  129.433774] [] (__of_changeset_revert) from [] 
(of_overlay_destroy+0x10c/0x1bc)
[  129.433795] [] (of_overlay_destroy) from [] 
(cfs_overlay_release+0x2c/0x50)
[  129.433832] [] (cfs_overlay_release) from [] 
(config_item_release+0x68/0x8c)
[  129.433859] [] (config_item_release) from [] 
(config_item_put+0x44/0x48)
[  129.433879] [] (config_item_put) from [] 
(configfs_rmdir+0x190/0x220)
[  129.433902] [] (configfs_rmdir) from [] 
(vfs_rmdir+0x80/0x118)
[  129.433922] [] (vfs_rmdir) from [] 
(do_rmdir+0x144/0x1a0)
[  129.433941] [] (do_rmdir) from [] 
(SyS_rmdir+0x20/0x24)
[  129.433966] [] (SyS_rmdir) from [] 
(ret_fast_syscall+0x0/0x1c)


This means that tinydrm 

Re: [PATCH v5 2/6] drm/bridge: Add a devm_ allocator for panel bridge.

2017-08-07 Thread Noralf Trønnes


Den 07.08.2017 12.22, skrev Laurent Pinchart:

Hi Daniel,

On Monday 07 Aug 2017 11:25:07 Daniel Vetter wrote:

On Sat, Aug 05, 2017 at 12:59:07PM +0200, Noralf Trønnes wrote:

Den 05.08.2017 00.19, skrev Ilia Mirkin:

On Fri, Aug 4, 2017 at 4:43 PM, Eric Anholt  wrote:

Laurent Pinchart  writes:

On Tuesday 18 Jul 2017 14:05:06 Eric Anholt wrote:

This will let drivers reduce the error cleanup they need, in
particular the "is_panel_bridge" flag.

v2: Slight cleanup of remove function by Andrzej

I just want to point out that, in the context of Daniel's work on
hot-unplug, 90% of the devm_* allocations are wrong and will get in
the way. All DRM core objects that are accessible one way or
another from userspace will need to be properly reference-counted
and freed only when the last reference disappears, which could be
well after the corresponding device is removed. I believe this
could be one such objects :-/

Sure, if you're hotplugging, your life is pain.  For non-hotpluggable
devices, like our SOC platform devices (current panel-bridge
consumers), this still seems like an excellent simplification of
memory management.

At that point you may as well make your module non-unloadable, and
return failure when trying to remove a device from management by the
driver (whatever the opposite of "probe" is, I forget). Hotplugging
doesn't only happen when physically removing, it can happen for all
kinds of reasons... and userspace may still hold references in some of
those cases.

If drm_open() gets a ref on dev->dev and puts it in drm_release(),
won't that delay devm_* cleanup until userspace is done?

No. drm_device is the thing that is refcounted for userspace references
like open FD (we're not perfect about it, e.g. sysfs and dma-buf/fence
don't).

devm_ otoh is tied to the lifetime of the underlying device, and that one
can get outlived by drm_device. Or at least afaiui, devm_ stuff is nuked
on unplug, and not when the final sw reference of the struct device
disappears.

Not sure tough, it's complicated.

It's complicated when you have to understand the behaviour by reading the
code, but the behaviour isn't that complex. devm resources are released both

1. right after the driver's .remove() operation returns
2. when the device is deleted (last reference released)

It's the first one that makes devm_* allocation unsuitable for any structure
that is accessible from userspace (such as in file operation handlers).



I see, when the device is removed, the driver is released. No help
holding a ref on struct device.
I did a test and this is the stack trace in devm_tinydrm_release():

[  129.433179] [] (unwind_backtrace) from [] 
(show_stack+0x20/0x24)
[  129.433213] [] (show_stack) from [] 
(dump_stack+0x20/0x28)
[  129.433242] [] (dump_stack) from [] 
(__warn+0xe4/0x10c)
[  129.433264] [] (__warn) from [] 
(warn_slowpath_null+0x30/0x38)
[  129.433324] [] (warn_slowpath_null) from [] 
(devm_tinydrm_release+0x24/0x48 [tinydrm])
[  129.433389] [] (devm_tinydrm_release [tinydrm]) from 
[] (devm_action_release+0x1c/0x20)
[  129.433414] [] (devm_action_release) from [] 
(release_nodes+0x188/0x21c)
[  129.433437] [] (release_nodes) from [] 
(devres_release_all+0x44/0x64)
[  129.433461] [] (devres_release_all) from [] 
(__device_release_driver+0x9c/0x118)
[  129.433480] [] (__device_release_driver) from [] 
(device_release_driver+0x2c/0x38)
[  129.433499] [] (device_release_driver) from [] 
(bus_remove_device+0xe4/0x114)
[  129.433532] [] (bus_remove_device) from [] 
(device_del+0x118/0x22c)
[  129.433554] [] (device_del) from [] 
(device_unregister+0x1c/0x30)
[  129.433592] [] (device_unregister) from [] 
(spi_unregister_device+0x60/0x64)
[  129.433617] [] (spi_unregister_device) from [] 
(of_spi_notify+0x70/0x164)
[  129.433642] [] (of_spi_notify) from [] 
(notifier_call_chain+0x54/0x94)
[  129.433664] [] (notifier_call_chain) from [] 
(__blocking_notifier_call_chain+0x58/0x70)
[  129.433683] [] (__blocking_notifier_call_chain) from 
[] (blocking_notifier_call_chain+0x28/0x30)
[  129.433721] [] (blocking_notifier_call_chain) from 
[] (__of_changeset_entry_notify+0x90/0xe0)
[  129.433748] [] (__of_changeset_entry_notify) from 
[] (__of_changeset_revert+0x70/0xcc)
[  129.433774] [] (__of_changeset_revert) from [] 
(of_overlay_destroy+0x10c/0x1bc)
[  129.433795] [] (of_overlay_destroy) from [] 
(cfs_overlay_release+0x2c/0x50)
[  129.433832] [] (cfs_overlay_release) from [] 
(config_item_release+0x68/0x8c)
[  129.433859] [] (config_item_release) from [] 
(config_item_put+0x44/0x48)
[  129.433879] [] (config_item_put) from [] 
(configfs_rmdir+0x190/0x220)
[  129.433902] [] (configfs_rmdir) from [] 
(vfs_rmdir+0x80/0x118)
[  129.433922] [] (vfs_rmdir) from [] 
(do_rmdir+0x144/0x1a0)
[  129.433941] [] (do_rmdir) from [] 
(SyS_rmdir+0x20/0x24)
[  129.433966] [] (SyS_rmdir) from [] 
(ret_fast_syscall+0x0/0x1c)


This means that tinydrm won't work with usb devices.
I need to look into moving cleanup

Re: [PATCH v3 4/6] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-05 Thread Noralf Trønnes


Den 05.08.2017 20.19, skrev Noralf Trønnes:


Den 04.08.2017 00.33, skrev David Lechner:

LEGO MINDSTORMS EV3 has an LCD with a ST7586 controller. This adds a new
module for the ST7586 controller with parameters for the LEGO MINDSTORMS
EV3 LCD display.

Signed-off-by: David Lechner <da...@lechnology.com>
---


[...]

diff --git a/drivers/gpu/drm/tinydrm/st7586.c 
b/drivers/gpu/drm/tinydrm/st7586.c


[...]


+static void st7586_xrgb_to_gray332(u8 *dst, void *vaddr,


Could you put a comment somewhere explaining what grey332 means, that 
it's not
a 332 pixel format that I first thought, but that you store 3x 2-bit 
pixles in one byte.



+   struct drm_framebuffer *fb,
+   struct drm_clip_rect *clip)
+{
+size_t len = (clip->x2 - clip->x1) * (clip->y2 - clip->y1);
+unsigned int x, y;
+u8 *src, *buf, val;
+
+/* 3 pixels per byte, so grow clip to nearest multiple of 3 */
+clip->x1 = clip->x1 / 3 * 3;


Something wrong here: 3 * 3.


+clip->x2 = (clip->x2 + 2) / 3 * 3;


You can use DIV_ROUND_UP().



Now I see what you're doing, can you use roundup() and rounddown()?


+
+buf = kmalloc(len, GFP_KERNEL);
+if (!buf)
+return;
+
+tinydrm_xrgb_to_gray8(buf, vaddr, fb, clip);
+src = buf;
+
+for (y = clip->y1; y < clip->y2; y++) {
+for (x = clip->x1; x < clip->x2; x += 3) {
+val = *src++ & 0xc0;
+if (val & 0xc0)
+val |= 0x20;
+val |= (*src++ & 0xc0) >> 3;
+if (val & 0x18)
+val |= 0x04;
+val |= *src++ >> 6;
+*dst++ = ~val;


I don't understand how this pixel packing matches the one described in
the datasheet. Why do you flip the bits at the end?


+}
+}
+
+/* now adjust the clip so it applies to dst */
+clip->x1 /= 3;
+clip->x2 /= 3;


I don't like this, you are changing the clip into a buffer length.
Better do the calculation before you call mipi_dbi_command_buf().


+
+kfree(buf);
+}
+
+static int st7586_buf_copy(void *dst, struct drm_framebuffer *fb,
+   struct drm_clip_rect *clip)
+{
+struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
+struct dma_buf_attachment *import_attach = 
cma_obj->base.import_attach;

+struct drm_format_name_buf format_name;
+void *src = cma_obj->vaddr;
+int ret = 0;
+
+if (import_attach) {
+ret = dma_buf_begin_cpu_access(import_attach->dmabuf,
+   DMA_FROM_DEVICE);
+if (ret)
+return ret;
+}
+
+switch (fb->format->format) {
+case DRM_FORMAT_XRGB:
+st7586_xrgb_to_gray332(dst, src, fb, clip);
+break;


I assume you will be adding monochrome and greyscale formats here soon.
Maybe you should have a function st7586_grey8_pack() or something, and do:

switch (fb->format->format) {
case DRM_FORMAT_XRGB:
buf = kmalloc();
tinydrm_xrgb_to_gray8(buf, src, fb, clip);
st7586_grey8_to_packed8(dst, buf, clip);
kfree();
break;

And then later add:

case DRM_FORMAT_Y8:
st7586_grey8_to_packed8(dst, src,...);
break;
case DRM_FORMAT_Y1:
st7586_mono_to_packed8(dst, src,...);
break;

Just a suggestion, feel free to do what you want.

A patch adding greyscale came today:
https://lists.freedesktop.org/archives/dri-devel/2017-August/149445.html


+default:
+dev_err_once(fb->dev->dev, "Format is not supported: %s\n",
+ drm_get_format_name(fb->format->format,
+ _name));
+ret = -EINVAL;
+break;


You don't need this default, because you can only get the ones in 
st7586_formats.



+}
+
+if (import_attach)
+dma_buf_end_cpu_access(import_attach->dmabuf, DMA_FROM_DEVICE);


ret = dma_buf_end_cpu_access(...)


+
+return ret;
+}
+
+static int st7586_fb_dirty(struct drm_framebuffer *fb,
+   struct drm_file *file_priv, unsigned int flags,
+   unsigned int color, struct drm_clip_rect *clips,
+   unsigned int num_clips)
+{
+struct tinydrm_device *tdev = fb->dev->dev_private;
+struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev);
+struct drm_clip_rect clip;
+int ret = 0;
+
+mutex_lock(>dirty_lock);
+
+if (!mipi->enabled)
+goto out_unlock;
+
+/* fbdev can flush even when we're not interested */
+if (tdev->pipe.plane.fb != fb)
+goto out_unlock;
+
+tinydrm_merge_clips(, clips, num_clips, flags, fb->width,
+fb->height);
+


I suggest you adjust the clip here since it applies to all formats:

/* pixels are packed in threes */

Re: [PATCH v3 4/6] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-05 Thread Noralf Trønnes


Den 05.08.2017 20.19, skrev Noralf Trønnes:


Den 04.08.2017 00.33, skrev David Lechner:

LEGO MINDSTORMS EV3 has an LCD with a ST7586 controller. This adds a new
module for the ST7586 controller with parameters for the LEGO MINDSTORMS
EV3 LCD display.

Signed-off-by: David Lechner 
---


[...]

diff --git a/drivers/gpu/drm/tinydrm/st7586.c 
b/drivers/gpu/drm/tinydrm/st7586.c


[...]


+static void st7586_xrgb_to_gray332(u8 *dst, void *vaddr,


Could you put a comment somewhere explaining what grey332 means, that 
it's not
a 332 pixel format that I first thought, but that you store 3x 2-bit 
pixles in one byte.



+   struct drm_framebuffer *fb,
+   struct drm_clip_rect *clip)
+{
+size_t len = (clip->x2 - clip->x1) * (clip->y2 - clip->y1);
+unsigned int x, y;
+u8 *src, *buf, val;
+
+/* 3 pixels per byte, so grow clip to nearest multiple of 3 */
+clip->x1 = clip->x1 / 3 * 3;


Something wrong here: 3 * 3.


+clip->x2 = (clip->x2 + 2) / 3 * 3;


You can use DIV_ROUND_UP().



Now I see what you're doing, can you use roundup() and rounddown()?


+
+buf = kmalloc(len, GFP_KERNEL);
+if (!buf)
+return;
+
+tinydrm_xrgb_to_gray8(buf, vaddr, fb, clip);
+src = buf;
+
+for (y = clip->y1; y < clip->y2; y++) {
+for (x = clip->x1; x < clip->x2; x += 3) {
+val = *src++ & 0xc0;
+if (val & 0xc0)
+val |= 0x20;
+val |= (*src++ & 0xc0) >> 3;
+if (val & 0x18)
+val |= 0x04;
+val |= *src++ >> 6;
+*dst++ = ~val;


I don't understand how this pixel packing matches the one described in
the datasheet. Why do you flip the bits at the end?


+}
+}
+
+/* now adjust the clip so it applies to dst */
+clip->x1 /= 3;
+clip->x2 /= 3;


I don't like this, you are changing the clip into a buffer length.
Better do the calculation before you call mipi_dbi_command_buf().


+
+kfree(buf);
+}
+
+static int st7586_buf_copy(void *dst, struct drm_framebuffer *fb,
+   struct drm_clip_rect *clip)
+{
+struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
+struct dma_buf_attachment *import_attach = 
cma_obj->base.import_attach;

+struct drm_format_name_buf format_name;
+void *src = cma_obj->vaddr;
+int ret = 0;
+
+if (import_attach) {
+ret = dma_buf_begin_cpu_access(import_attach->dmabuf,
+   DMA_FROM_DEVICE);
+if (ret)
+return ret;
+}
+
+switch (fb->format->format) {
+case DRM_FORMAT_XRGB:
+st7586_xrgb_to_gray332(dst, src, fb, clip);
+break;


I assume you will be adding monochrome and greyscale formats here soon.
Maybe you should have a function st7586_grey8_pack() or something, and do:

switch (fb->format->format) {
case DRM_FORMAT_XRGB:
buf = kmalloc();
tinydrm_xrgb_to_gray8(buf, src, fb, clip);
st7586_grey8_to_packed8(dst, buf, clip);
kfree();
break;

And then later add:

case DRM_FORMAT_Y8:
st7586_grey8_to_packed8(dst, src,...);
break;
case DRM_FORMAT_Y1:
st7586_mono_to_packed8(dst, src,...);
break;

Just a suggestion, feel free to do what you want.

A patch adding greyscale came today:
https://lists.freedesktop.org/archives/dri-devel/2017-August/149445.html


+default:
+dev_err_once(fb->dev->dev, "Format is not supported: %s\n",
+ drm_get_format_name(fb->format->format,
+ _name));
+ret = -EINVAL;
+break;


You don't need this default, because you can only get the ones in 
st7586_formats.



+}
+
+if (import_attach)
+dma_buf_end_cpu_access(import_attach->dmabuf, DMA_FROM_DEVICE);


ret = dma_buf_end_cpu_access(...)


+
+return ret;
+}
+
+static int st7586_fb_dirty(struct drm_framebuffer *fb,
+   struct drm_file *file_priv, unsigned int flags,
+   unsigned int color, struct drm_clip_rect *clips,
+   unsigned int num_clips)
+{
+struct tinydrm_device *tdev = fb->dev->dev_private;
+struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev);
+struct drm_clip_rect clip;
+int ret = 0;
+
+mutex_lock(>dirty_lock);
+
+if (!mipi->enabled)
+goto out_unlock;
+
+/* fbdev can flush even when we're not interested */
+if (tdev->pipe.plane.fb != fb)
+goto out_unlock;
+
+tinydrm_merge_clips(, clips, num_clips, flags, fb->width,
+fb->height);
+


I suggest you adjust the clip here since it applies to all formats:

/* pixels are packed in threes */
clip->x1 = rounddown(clip->x1, 3);

Re: [PATCH v3 4/6] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-05 Thread Noralf Trønnes


Den 04.08.2017 00.33, skrev David Lechner:

LEGO MINDSTORMS EV3 has an LCD with a ST7586 controller. This adds a new
module for the ST7586 controller with parameters for the LEGO MINDSTORMS
EV3 LCD display.

Signed-off-by: David Lechner 
---
  MAINTAINERS  |   6 +
  drivers/gpu/drm/tinydrm/Kconfig  |  10 +
  drivers/gpu/drm/tinydrm/Makefile |   1 +
  drivers/gpu/drm/tinydrm/st7586.c | 466 +++
  4 files changed, 483 insertions(+)
  create mode 100644 drivers/gpu/drm/tinydrm/st7586.c

diff --git a/MAINTAINERS b/MAINTAINERS
index a1e772e..9643f95 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4365,6 +4365,12 @@ S:   Maintained
  F:drivers/gpu/drm/tinydrm/repaper.c
  F:Documentation/devicetree/bindings/display/repaper.txt
  
+DRM DRIVER FOR SITRONIX ST7586 PANELS

+M: David Lechner 
+S: Maintained
+F: drivers/gpu/drm/tinydrm/st7586.c
+F: Documentation/devicetree/bindings/display/st7586.txt
+


This file is sorted alphabetically, so it should go after SIS.
It seems REPAPER ended up in the wrong place after the conflict
resolution following Linus's cleanup.


  DRM DRIVER FOR RAGE 128 VIDEO CARDS
  S:Orphan / Obsolete
  F:drivers/gpu/drm/r128/
diff --git a/drivers/gpu/drm/tinydrm/Kconfig b/drivers/gpu/drm/tinydrm/Kconfig
index f17c3ca..2e790e7 100644
--- a/drivers/gpu/drm/tinydrm/Kconfig
+++ b/drivers/gpu/drm/tinydrm/Kconfig
@@ -32,3 +32,13 @@ config TINYDRM_REPAPER
  2.71" TFT EPD Panel (E2271CS021)
  
  	  If M is selected the module will be called repaper.

+
+config TINYDRM_ST7586
+   tristate "DRM support for Sitronix ST7586 display panels"
+   depends on DRM_TINYDRM && SPI
+   select TINYDRM_MIPI_DBI
+   help
+ DRM driver for the following Sitronix ST7586 panels:
+ * LEGO MINDSTORMS EV3
+
+ If M is selected the module will be called st7586.
diff --git a/drivers/gpu/drm/tinydrm/Makefile b/drivers/gpu/drm/tinydrm/Makefile
index 95bb4d4..0c184bd 100644
--- a/drivers/gpu/drm/tinydrm/Makefile
+++ b/drivers/gpu/drm/tinydrm/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_TINYDRM_MIPI_DBI)  += mipi-dbi.o
  # Displays
  obj-$(CONFIG_TINYDRM_MI0283QT)+= mi0283qt.o
  obj-$(CONFIG_TINYDRM_REPAPER) += repaper.o
+obj-$(CONFIG_TINYDRM_ST7586)   += st7586.o
diff --git a/drivers/gpu/drm/tinydrm/st7586.c b/drivers/gpu/drm/tinydrm/st7586.c
new file mode 100644
index 000..11e226d
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/st7586.c
@@ -0,0 +1,466 @@
+/*
+ * DRM driver for Sitronix ST7586 panels
+ *
+ * Copyright 2017 David Lechner 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+/* controller-specific commands */
+#define ST7586_DISP_MODE_GRAY  0x38
+#define ST7586_DISP_MODE_MONO  0x39
+#define ST7586_ENABLE_DDRAM0x3a
+#define ST7586_SET_DISP_DUTY   0xb0
+#define ST7586_SET_PART_DISP   0xb4
+#define ST7586_SET_NLINE_INV   0xb5
+#define ST7586_SET_VOP 0xc0
+#define ST7586_SET_BIAS_SYSTEM 0xc3
+#define ST7586_SET_BOOST_LEVEL 0xc4
+#define ST7586_SET_VOP_OFFSET  0xc7
+#define ST7586_ENABLE_ANALOG   0xd0
+#define ST7586_AUTO_READ_CTRL  0xd7
+#define ST7586_OTP_RW_CTRL 0xe0
+#define ST7586_OTP_CTRL_OUT0xe1
+#define ST7586_OTP_READ0xe3
+
+#define ST7586_DISP_CTRL_MXBIT(6)
+#define ST7586_DISP_CTRL_MYBIT(7)
+
+static void st7586_xrgb_to_gray332(u8 *dst, void *vaddr,


Could you put a comment somewhere explaining what grey332 means, that 
it's not
a 332 pixel format that I first thought, but that you store 3x 2-bit 
pixles in one byte.



+  struct drm_framebuffer *fb,
+  struct drm_clip_rect *clip)
+{
+   size_t len = (clip->x2 - clip->x1) * (clip->y2 - clip->y1);
+   unsigned int x, y;
+   u8 *src, *buf, val;
+
+   /* 3 pixels per byte, so grow clip to nearest multiple of 3 */
+   clip->x1 = clip->x1 / 3 * 3;


Something wrong here: 3 * 3.


+   clip->x2 = (clip->x2 + 2) / 3 * 3;


You can use DIV_ROUND_UP().


+
+   buf = kmalloc(len, GFP_KERNEL);
+   if (!buf)
+   return;
+
+   tinydrm_xrgb_to_gray8(buf, vaddr, fb, clip);
+   src = buf;
+
+   for (y = clip->y1; y < clip->y2; y++) {
+   for (x = clip->x1; x < clip->x2; x += 3) {
+   val = *src++ & 0xc0;
+   if (val & 0xc0)
+   val |= 0x20;
+   val |= (*src++ & 0xc0) >> 3;
+   if (val & 0x18)
+ 

Re: [PATCH v3 4/6] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD

2017-08-05 Thread Noralf Trønnes


Den 04.08.2017 00.33, skrev David Lechner:

LEGO MINDSTORMS EV3 has an LCD with a ST7586 controller. This adds a new
module for the ST7586 controller with parameters for the LEGO MINDSTORMS
EV3 LCD display.

Signed-off-by: David Lechner 
---
  MAINTAINERS  |   6 +
  drivers/gpu/drm/tinydrm/Kconfig  |  10 +
  drivers/gpu/drm/tinydrm/Makefile |   1 +
  drivers/gpu/drm/tinydrm/st7586.c | 466 +++
  4 files changed, 483 insertions(+)
  create mode 100644 drivers/gpu/drm/tinydrm/st7586.c

diff --git a/MAINTAINERS b/MAINTAINERS
index a1e772e..9643f95 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4365,6 +4365,12 @@ S:   Maintained
  F:drivers/gpu/drm/tinydrm/repaper.c
  F:Documentation/devicetree/bindings/display/repaper.txt
  
+DRM DRIVER FOR SITRONIX ST7586 PANELS

+M: David Lechner 
+S: Maintained
+F: drivers/gpu/drm/tinydrm/st7586.c
+F: Documentation/devicetree/bindings/display/st7586.txt
+


This file is sorted alphabetically, so it should go after SIS.
It seems REPAPER ended up in the wrong place after the conflict
resolution following Linus's cleanup.


  DRM DRIVER FOR RAGE 128 VIDEO CARDS
  S:Orphan / Obsolete
  F:drivers/gpu/drm/r128/
diff --git a/drivers/gpu/drm/tinydrm/Kconfig b/drivers/gpu/drm/tinydrm/Kconfig
index f17c3ca..2e790e7 100644
--- a/drivers/gpu/drm/tinydrm/Kconfig
+++ b/drivers/gpu/drm/tinydrm/Kconfig
@@ -32,3 +32,13 @@ config TINYDRM_REPAPER
  2.71" TFT EPD Panel (E2271CS021)
  
  	  If M is selected the module will be called repaper.

+
+config TINYDRM_ST7586
+   tristate "DRM support for Sitronix ST7586 display panels"
+   depends on DRM_TINYDRM && SPI
+   select TINYDRM_MIPI_DBI
+   help
+ DRM driver for the following Sitronix ST7586 panels:
+ * LEGO MINDSTORMS EV3
+
+ If M is selected the module will be called st7586.
diff --git a/drivers/gpu/drm/tinydrm/Makefile b/drivers/gpu/drm/tinydrm/Makefile
index 95bb4d4..0c184bd 100644
--- a/drivers/gpu/drm/tinydrm/Makefile
+++ b/drivers/gpu/drm/tinydrm/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_TINYDRM_MIPI_DBI)  += mipi-dbi.o
  # Displays
  obj-$(CONFIG_TINYDRM_MI0283QT)+= mi0283qt.o
  obj-$(CONFIG_TINYDRM_REPAPER) += repaper.o
+obj-$(CONFIG_TINYDRM_ST7586)   += st7586.o
diff --git a/drivers/gpu/drm/tinydrm/st7586.c b/drivers/gpu/drm/tinydrm/st7586.c
new file mode 100644
index 000..11e226d
--- /dev/null
+++ b/drivers/gpu/drm/tinydrm/st7586.c
@@ -0,0 +1,466 @@
+/*
+ * DRM driver for Sitronix ST7586 panels
+ *
+ * Copyright 2017 David Lechner 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+/* controller-specific commands */
+#define ST7586_DISP_MODE_GRAY  0x38
+#define ST7586_DISP_MODE_MONO  0x39
+#define ST7586_ENABLE_DDRAM0x3a
+#define ST7586_SET_DISP_DUTY   0xb0
+#define ST7586_SET_PART_DISP   0xb4
+#define ST7586_SET_NLINE_INV   0xb5
+#define ST7586_SET_VOP 0xc0
+#define ST7586_SET_BIAS_SYSTEM 0xc3
+#define ST7586_SET_BOOST_LEVEL 0xc4
+#define ST7586_SET_VOP_OFFSET  0xc7
+#define ST7586_ENABLE_ANALOG   0xd0
+#define ST7586_AUTO_READ_CTRL  0xd7
+#define ST7586_OTP_RW_CTRL 0xe0
+#define ST7586_OTP_CTRL_OUT0xe1
+#define ST7586_OTP_READ0xe3
+
+#define ST7586_DISP_CTRL_MXBIT(6)
+#define ST7586_DISP_CTRL_MYBIT(7)
+
+static void st7586_xrgb_to_gray332(u8 *dst, void *vaddr,


Could you put a comment somewhere explaining what grey332 means, that 
it's not
a 332 pixel format that I first thought, but that you store 3x 2-bit 
pixles in one byte.



+  struct drm_framebuffer *fb,
+  struct drm_clip_rect *clip)
+{
+   size_t len = (clip->x2 - clip->x1) * (clip->y2 - clip->y1);
+   unsigned int x, y;
+   u8 *src, *buf, val;
+
+   /* 3 pixels per byte, so grow clip to nearest multiple of 3 */
+   clip->x1 = clip->x1 / 3 * 3;


Something wrong here: 3 * 3.


+   clip->x2 = (clip->x2 + 2) / 3 * 3;


You can use DIV_ROUND_UP().


+
+   buf = kmalloc(len, GFP_KERNEL);
+   if (!buf)
+   return;
+
+   tinydrm_xrgb_to_gray8(buf, vaddr, fb, clip);
+   src = buf;
+
+   for (y = clip->y1; y < clip->y2; y++) {
+   for (x = clip->x1; x < clip->x2; x += 3) {
+   val = *src++ & 0xc0;
+   if (val & 0xc0)
+   val |= 0x20;
+   val |= (*src++ & 0xc0) >> 3;
+   if (val & 0x18)
+   val |= 0x04;
+   val |= *src++ >> 6;
+  

Re: [PATCH v5 2/6] drm/bridge: Add a devm_ allocator for panel bridge.

2017-08-05 Thread Noralf Trønnes


Den 05.08.2017 12.59, skrev Noralf Trønnes:

(I had to switch to Daniel's Intel address to get this sent)

Den 05.08.2017 00.19, skrev Ilia Mirkin:

On Fri, Aug 4, 2017 at 4:43 PM, Eric Anholt <e...@anholt.net> wrote:

Laurent Pinchart <laurent.pinch...@ideasonboard.com> writes:


Hi Eric,

(CC'ing Daniel)

Thank you for the patch.

On Tuesday 18 Jul 2017 14:05:06 Eric Anholt wrote:

This will let drivers reduce the error cleanup they need, in
particular the "is_panel_bridge" flag.

v2: Slight cleanup of remove function by Andrzej
I just want to point out that, in the context of Daniel's work on 
hot-unplug,
90% of the devm_* allocations are wrong and will get in the way. 
All DRM core
objects that are accessible one way or another from userspace will 
need to be
properly reference-counted and freed only when the last reference 
disappears,
which could be well after the corresponding device is removed. I 
believe this

could be one such objects :-/

Sure, if you're hotplugging, your life is pain.  For non-hotpluggable
devices, like our SOC platform devices (current panel-bridge 
consumers),

this still seems like an excellent simplification of memory management.

At that point you may as well make your module non-unloadable, and
return failure when trying to remove a device from management by the
driver (whatever the opposite of "probe" is, I forget). Hotplugging
doesn't only happen when physically removing, it can happen for all
kinds of reasons... and userspace may still hold references in some of
those cases.


If drm_open() gets a ref on dev->dev and puts it in drm_release(),
won't that delay devm_* cleanup until userspace is done?



It seems plausible looking at the code:

void device_initialize(struct device *dev)
{
[...]
kobject_init(>kobj, _ktype);
[...]
}

static struct kobj_type device_ktype = {
.release= device_release,
};

/**
 * device_release - free device structure.
 * @kobj: device's kobject.
 *
 * This is called once the reference count for the object
 * reaches 0. We forward the call to the device's release
 * method, which should handle actually freeing the structure.
 */
static void device_release(struct kobject *kobj)
{
[...]
devres_release_all(dev);
[...]
}

Last put call chain:
put_device() -> kobject_put() -> kref_put() -> kobject_release() ->
kobject_cleanup() -> device_release() -> devres_release_all()

But I haven't actually tried it, so I might be mistaken.



Re: [PATCH v5 2/6] drm/bridge: Add a devm_ allocator for panel bridge.

2017-08-05 Thread Noralf Trønnes


Den 05.08.2017 12.59, skrev Noralf Trønnes:

(I had to switch to Daniel's Intel address to get this sent)

Den 05.08.2017 00.19, skrev Ilia Mirkin:

On Fri, Aug 4, 2017 at 4:43 PM, Eric Anholt  wrote:

Laurent Pinchart  writes:


Hi Eric,

(CC'ing Daniel)

Thank you for the patch.

On Tuesday 18 Jul 2017 14:05:06 Eric Anholt wrote:

This will let drivers reduce the error cleanup they need, in
particular the "is_panel_bridge" flag.

v2: Slight cleanup of remove function by Andrzej
I just want to point out that, in the context of Daniel's work on 
hot-unplug,
90% of the devm_* allocations are wrong and will get in the way. 
All DRM core
objects that are accessible one way or another from userspace will 
need to be
properly reference-counted and freed only when the last reference 
disappears,
which could be well after the corresponding device is removed. I 
believe this

could be one such objects :-/

Sure, if you're hotplugging, your life is pain.  For non-hotpluggable
devices, like our SOC platform devices (current panel-bridge 
consumers),

this still seems like an excellent simplification of memory management.

At that point you may as well make your module non-unloadable, and
return failure when trying to remove a device from management by the
driver (whatever the opposite of "probe" is, I forget). Hotplugging
doesn't only happen when physically removing, it can happen for all
kinds of reasons... and userspace may still hold references in some of
those cases.


If drm_open() gets a ref on dev->dev and puts it in drm_release(),
won't that delay devm_* cleanup until userspace is done?



It seems plausible looking at the code:

void device_initialize(struct device *dev)
{
[...]
kobject_init(>kobj, _ktype);
[...]
}

static struct kobj_type device_ktype = {
.release= device_release,
};

/**
 * device_release - free device structure.
 * @kobj: device's kobject.
 *
 * This is called once the reference count for the object
 * reaches 0. We forward the call to the device's release
 * method, which should handle actually freeing the structure.
 */
static void device_release(struct kobject *kobj)
{
[...]
devres_release_all(dev);
[...]
}

Last put call chain:
put_device() -> kobject_put() -> kref_put() -> kobject_release() ->
kobject_cleanup() -> device_release() -> devres_release_all()

But I haven't actually tried it, so I might be mistaken.



Re: [PATCH v5 2/6] drm/bridge: Add a devm_ allocator for panel bridge.

2017-08-05 Thread Noralf Trønnes

(I had to switch to Daniel's Intel address to get this sent)

Den 05.08.2017 00.19, skrev Ilia Mirkin:

On Fri, Aug 4, 2017 at 4:43 PM, Eric Anholt  wrote:

Laurent Pinchart  writes:


Hi Eric,

(CC'ing Daniel)

Thank you for the patch.

On Tuesday 18 Jul 2017 14:05:06 Eric Anholt wrote:

This will let drivers reduce the error cleanup they need, in
particular the "is_panel_bridge" flag.

v2: Slight cleanup of remove function by Andrzej

I just want to point out that, in the context of Daniel's work on hot-unplug,
90% of the devm_* allocations are wrong and will get in the way. All DRM core
objects that are accessible one way or another from userspace will need to be
properly reference-counted and freed only when the last reference disappears,
which could be well after the corresponding device is removed. I believe this
could be one such objects :-/

Sure, if you're hotplugging, your life is pain.  For non-hotpluggable
devices, like our SOC platform devices (current panel-bridge consumers),
this still seems like an excellent simplification of memory management.

At that point you may as well make your module non-unloadable, and
return failure when trying to remove a device from management by the
driver (whatever the opposite of "probe" is, I forget). Hotplugging
doesn't only happen when physically removing, it can happen for all
kinds of reasons... and userspace may still hold references in some of
those cases.


If drm_open() gets a ref on dev->dev and puts it in drm_release(),
won't that delay devm_* cleanup until userspace is done?



Re: [PATCH v5 2/6] drm/bridge: Add a devm_ allocator for panel bridge.

2017-08-05 Thread Noralf Trønnes

(I had to switch to Daniel's Intel address to get this sent)

Den 05.08.2017 00.19, skrev Ilia Mirkin:

On Fri, Aug 4, 2017 at 4:43 PM, Eric Anholt  wrote:

Laurent Pinchart  writes:


Hi Eric,

(CC'ing Daniel)

Thank you for the patch.

On Tuesday 18 Jul 2017 14:05:06 Eric Anholt wrote:

This will let drivers reduce the error cleanup they need, in
particular the "is_panel_bridge" flag.

v2: Slight cleanup of remove function by Andrzej

I just want to point out that, in the context of Daniel's work on hot-unplug,
90% of the devm_* allocations are wrong and will get in the way. All DRM core
objects that are accessible one way or another from userspace will need to be
properly reference-counted and freed only when the last reference disappears,
which could be well after the corresponding device is removed. I believe this
could be one such objects :-/

Sure, if you're hotplugging, your life is pain.  For non-hotpluggable
devices, like our SOC platform devices (current panel-bridge consumers),
this still seems like an excellent simplification of memory management.

At that point you may as well make your module non-unloadable, and
return failure when trying to remove a device from management by the
driver (whatever the opposite of "probe" is, I forget). Hotplugging
doesn't only happen when physically removing, it can happen for all
kinds of reasons... and userspace may still hold references in some of
those cases.


If drm_open() gets a ref on dev->dev and puts it in drm_release(),
won't that delay devm_* cleanup until userspace is done?



Re: [PATCH v3 3/6] dt-bindings: add binding for Sitronix ST7586 display panels

2017-08-04 Thread Noralf Trønnes


Den 04.08.2017 18.51, skrev David Lechner:

On 08/04/2017 04:48 AM, Noralf Trønnes wrote:


Den 04.08.2017 00.33, skrev David Lechner:

This adds a new binding for Sitronix ST7586 display panels.

Using lego as the vendor prefix in the compatible string because the 
display

panel I am working with is an integral part of the LEGO MINDSTORMS EV3.


Is this display available outside of this Lego part?

No, it is not.


If not you can remove the properties you don't need for this particular
display setup. Another st7586 display with a different panel would need
a different initialization sequence and compatible string, so we can
add properties when/if that happens.


OK. so I will drop power-supply and backlight.



And the dc/reset gpios should be required properties since your display
won't work without them (or rather they're hardwired that way).

Should I remove these from the driver as well? There are some panels 
out there that could use them.[1]


[1]: 
http://www.buydisplay.com/download/manual/ERC240160-1_Series_Datasheet.pdf




Yes, because that display won't work with the driver as-is, so it's
really dead code. If someone wants to add support for that display,
they'll add the necessary code. When maintaining code for 10-20 years,
it's important to not add code that 'might' be used in the future.
Let the future take care of itself and keep the codebase slim :-)

Noralf.



Noralf.


Signed-off-by: David Lechner <da...@lechnology.com>
---
  .../bindings/display/sitronix,st7586.txt   | 26 
++

  1 file changed, 26 insertions(+)
  create mode 100644 
Documentation/devicetree/bindings/display/sitronix,st7586.txt


diff --git 
a/Documentation/devicetree/bindings/display/sitronix,st7586.txt 
b/Documentation/devicetree/bindings/display/sitronix,st7586.txt

new file mode 100644
index 000..dfb0b7b
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/sitronix,st7586.txt
@@ -0,0 +1,26 @@
+Sitronix ST7586 display panel
+
+Required properties:
+- compatible:"lego,ev3-lcd".
+
+The node for this driver must be a child node of a SPI controller, 
hence
+all mandatory properties described in ../spi/spi-bus.txt must be 
specified.

+
+Optional properties:
+- dc-gpios:D/C pin. The presence/absence of this GPIO determines
+the panel interface operation mode (IF[3:1] pins):
+- present: IF=011 4-wire 8-bit data serial interface
+- absent:  IF=010 3-wire 9-bit data serial interface
+- reset-gpios:Reset pin
+- power-supply:A regulator node for the supply voltage.
+- backlight:phandle of the backlight device attached to the panel
+- rotation:panel rotation in degrees counter clockwise 
(0,90,180,270)

+
+Example:
+display@0{
+compatible = "lego,ev3-lcd";
+reg = <0>;
+spi-max-frequency = <1000>;
+dc-gpios = < 43 GPIO_ACTIVE_HIGH>;
+reset-gpios = < 80 GPIO_ACTIVE_HIGH>;
+};








Re: [PATCH v3 3/6] dt-bindings: add binding for Sitronix ST7586 display panels

2017-08-04 Thread Noralf Trønnes


Den 04.08.2017 18.51, skrev David Lechner:

On 08/04/2017 04:48 AM, Noralf Trønnes wrote:


Den 04.08.2017 00.33, skrev David Lechner:

This adds a new binding for Sitronix ST7586 display panels.

Using lego as the vendor prefix in the compatible string because the 
display

panel I am working with is an integral part of the LEGO MINDSTORMS EV3.


Is this display available outside of this Lego part?

No, it is not.


If not you can remove the properties you don't need for this particular
display setup. Another st7586 display with a different panel would need
a different initialization sequence and compatible string, so we can
add properties when/if that happens.


OK. so I will drop power-supply and backlight.



And the dc/reset gpios should be required properties since your display
won't work without them (or rather they're hardwired that way).

Should I remove these from the driver as well? There are some panels 
out there that could use them.[1]


[1]: 
http://www.buydisplay.com/download/manual/ERC240160-1_Series_Datasheet.pdf




Yes, because that display won't work with the driver as-is, so it's
really dead code. If someone wants to add support for that display,
they'll add the necessary code. When maintaining code for 10-20 years,
it's important to not add code that 'might' be used in the future.
Let the future take care of itself and keep the codebase slim :-)

Noralf.



Noralf.


Signed-off-by: David Lechner 
---
  .../bindings/display/sitronix,st7586.txt   | 26 
++

  1 file changed, 26 insertions(+)
  create mode 100644 
Documentation/devicetree/bindings/display/sitronix,st7586.txt


diff --git 
a/Documentation/devicetree/bindings/display/sitronix,st7586.txt 
b/Documentation/devicetree/bindings/display/sitronix,st7586.txt

new file mode 100644
index 000..dfb0b7b
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/sitronix,st7586.txt
@@ -0,0 +1,26 @@
+Sitronix ST7586 display panel
+
+Required properties:
+- compatible:"lego,ev3-lcd".
+
+The node for this driver must be a child node of a SPI controller, 
hence
+all mandatory properties described in ../spi/spi-bus.txt must be 
specified.

+
+Optional properties:
+- dc-gpios:D/C pin. The presence/absence of this GPIO determines
+the panel interface operation mode (IF[3:1] pins):
+- present: IF=011 4-wire 8-bit data serial interface
+- absent:  IF=010 3-wire 9-bit data serial interface
+- reset-gpios:Reset pin
+- power-supply:A regulator node for the supply voltage.
+- backlight:phandle of the backlight device attached to the panel
+- rotation:panel rotation in degrees counter clockwise 
(0,90,180,270)

+
+Example:
+display@0{
+compatible = "lego,ev3-lcd";
+reg = <0>;
+spi-max-frequency = <1000>;
+dc-gpios = < 43 GPIO_ACTIVE_HIGH>;
+reset-gpios = < 80 GPIO_ACTIVE_HIGH>;
+};








Re: [PATCH v3 3/6] dt-bindings: add binding for Sitronix ST7586 display panels

2017-08-04 Thread Noralf Trønnes

Hi Laurent,


Den 04.08.2017 16.54, skrev Laurent Pinchart:

Hi David,

Thank you for the patch.

On Thursday 03 Aug 2017 17:33:47 David Lechner wrote:

This adds a new binding for Sitronix ST7586 display panels.

Using lego as the vendor prefix in the compatible string because the display
panel I am working with is an integral part of the LEGO MINDSTORMS EV3.

Signed-off-by: David Lechner 
---
  .../bindings/display/sitronix,st7586.txt   | 26 +++
  1 file changed, 26 insertions(+)
  create mode 100644
Documentation/devicetree/bindings/display/sitronix,st7586.txt

diff --git a/Documentation/devicetree/bindings/display/sitronix,st7586.txt
b/Documentation/devicetree/bindings/display/sitronix,st7586.txt new file
mode 100644
index 000..dfb0b7b
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/sitronix,st7586.txt
@@ -0,0 +1,26 @@
+Sitronix ST7586 display panel
+
+Required properties:
+- compatible:  "lego,ev3-lcd".
+
+The node for this driver must be a child node of a SPI controller, hence
+all mandatory properties described in ../spi/spi-bus.txt must be specified.
+
+Optional properties:
+- dc-gpios:D/C pin. The presence/absence of this GPIO determines
+   the panel interface operation mode (IF[3:1] pins):
+   - present: IF=011 4-wire 8-bit data serial interface
+   - absent:  IF=010 3-wire 9-bit data serial interface

How does this work ? Do you have a single GPIO on your system connected to
IF[1], with IF[3:2] hardwired to 01 ?


+- reset-gpios: Reset pin
+- power-supply:A regulator node for the supply voltage.
+- backlight:   phandle of the backlight device attached to the panel
+- rotation:panel rotation in degrees counter clockwise (0,90,180,270)

Please use the OF graph DT bindings (a.k.a. ports) to describe the connection
between the panel and its source.


This display has a controller with onboard memory that is scanned out
to the panel. The controller is connected, in this instance, through SPI.
Both initialization and pixel data is transferred over SPI. It resembles
the MIPI DCS/DBI standard except that it misses some of the commands and
has non standard formats: 2-bit greyscale and monochrome. MIPI DBI only
supports rgb formats (3, 8, 12, 16 and 18-bits). So it isn't a drm panel
in the sense as one connected through MIPI DSI or MIPI DPI.

MIPI DBI has 3 interface types:
- 8/9/16/18 bit parallel bus + Data/Command signal (8080 or motorola bus)
- 8/16 bit SPI + D/C signal
- 9 bit SPI (D/C as first bit)

Noralf.


+Example:
+   display@0{
+   compatible = "lego,ev3-lcd";
+   reg = <0>;
+   spi-max-frequency = <1000>;
+   dc-gpios = < 43 GPIO_ACTIVE_HIGH>;
+   reset-gpios = < 80 GPIO_ACTIVE_HIGH>;
+   };




Re: [PATCH v3 3/6] dt-bindings: add binding for Sitronix ST7586 display panels

2017-08-04 Thread Noralf Trønnes

Hi Laurent,


Den 04.08.2017 16.54, skrev Laurent Pinchart:

Hi David,

Thank you for the patch.

On Thursday 03 Aug 2017 17:33:47 David Lechner wrote:

This adds a new binding for Sitronix ST7586 display panels.

Using lego as the vendor prefix in the compatible string because the display
panel I am working with is an integral part of the LEGO MINDSTORMS EV3.

Signed-off-by: David Lechner 
---
  .../bindings/display/sitronix,st7586.txt   | 26 +++
  1 file changed, 26 insertions(+)
  create mode 100644
Documentation/devicetree/bindings/display/sitronix,st7586.txt

diff --git a/Documentation/devicetree/bindings/display/sitronix,st7586.txt
b/Documentation/devicetree/bindings/display/sitronix,st7586.txt new file
mode 100644
index 000..dfb0b7b
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/sitronix,st7586.txt
@@ -0,0 +1,26 @@
+Sitronix ST7586 display panel
+
+Required properties:
+- compatible:  "lego,ev3-lcd".
+
+The node for this driver must be a child node of a SPI controller, hence
+all mandatory properties described in ../spi/spi-bus.txt must be specified.
+
+Optional properties:
+- dc-gpios:D/C pin. The presence/absence of this GPIO determines
+   the panel interface operation mode (IF[3:1] pins):
+   - present: IF=011 4-wire 8-bit data serial interface
+   - absent:  IF=010 3-wire 9-bit data serial interface

How does this work ? Do you have a single GPIO on your system connected to
IF[1], with IF[3:2] hardwired to 01 ?


+- reset-gpios: Reset pin
+- power-supply:A regulator node for the supply voltage.
+- backlight:   phandle of the backlight device attached to the panel
+- rotation:panel rotation in degrees counter clockwise (0,90,180,270)

Please use the OF graph DT bindings (a.k.a. ports) to describe the connection
between the panel and its source.


This display has a controller with onboard memory that is scanned out
to the panel. The controller is connected, in this instance, through SPI.
Both initialization and pixel data is transferred over SPI. It resembles
the MIPI DCS/DBI standard except that it misses some of the commands and
has non standard formats: 2-bit greyscale and monochrome. MIPI DBI only
supports rgb formats (3, 8, 12, 16 and 18-bits). So it isn't a drm panel
in the sense as one connected through MIPI DSI or MIPI DPI.

MIPI DBI has 3 interface types:
- 8/9/16/18 bit parallel bus + Data/Command signal (8080 or motorola bus)
- 8/16 bit SPI + D/C signal
- 9 bit SPI (D/C as first bit)

Noralf.


+Example:
+   display@0{
+   compatible = "lego,ev3-lcd";
+   reg = <0>;
+   spi-max-frequency = <1000>;
+   dc-gpios = < 43 GPIO_ACTIVE_HIGH>;
+   reset-gpios = < 80 GPIO_ACTIVE_HIGH>;
+   };




Re: [PATCH v3 2/6] drm/tinydrm: generalize tinydrm_xrgb8888_to_gray8()

2017-08-04 Thread Noralf Trønnes


Den 04.08.2017 09.27, skrev Noralf Trønnes:


Den 04.08.2017 00.33, skrev David Lechner:
This adds parameters for vaddr and clip to 
tinydrm_xrgb_to_gray8() to

make it more generic.

dma_buf_{begin,end}_cpu_access() are moved out to the repaper driver.

Signed-off-by: David Lechner <da...@lechnology.com>
---
  drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 35 
++

  drivers/gpu/drm/tinydrm/repaper.c  | 21 +++-
  include/drm/tinydrm/tinydrm-helpers.h  |  3 ++-
  3 files changed, 35 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c 
b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c

index 75808bb..5915ba8 100644
--- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
+++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
@@ -185,7 +185,9 @@ EXPORT_SYMBOL(tinydrm_xrgb_to_rgb565);
  /**
   * tinydrm_xrgb_to_gray8 - Convert XRGB to grayscale
   * @dst: 8-bit grayscale destination buffer
+ * @vaddr: XRGB source buffer
   * @fb: DRM framebuffer
+ * @clip: Clip rectangle area to copy
   *
   * Drm doesn't have native monochrome or grayscale support.
   * Such drivers can announce the commonly supported XR24 format to 
userspace

@@ -199,12 +201,11 @@ EXPORT_SYMBOL(tinydrm_xrgb_to_rgb565);
   * Returns:
   * Zero on success, negative error code on failure.
   */
-int tinydrm_xrgb_to_gray8(u8 *dst, struct drm_framebuffer *fb)
+int tinydrm_xrgb_to_gray8(u8 *dst, void *vaddr, struct 
drm_framebuffer *fb,

+  struct drm_clip_rect *clip)
  {
-struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
-struct dma_buf_attachment *import_attach = 
cma_obj->base.import_attach;

-unsigned int x, y, pitch = fb->pitches[0];
-int ret = 0;
+unsigned int len = (clip->x2 - clip->x1) * sizeof(u32);
+unsigned int x, y;
  void *buf;
  u32 *src;
  @@ -214,22 +215,16 @@ int tinydrm_xrgb_to_gray8(u8 *dst, struct 
drm_framebuffer *fb)

   * The cma memory is write-combined so reads are uncached.
   * Speed up by fetching one line at a time.
   */
-buf = kmalloc(pitch, GFP_KERNEL);
+buf = kmalloc(len, GFP_KERNEL);
  if (!buf)
  return -ENOMEM;
  -if (import_attach) {
-ret = dma_buf_begin_cpu_access(import_attach->dmabuf,
-   DMA_FROM_DEVICE);
-if (ret)
-goto err_free;
-}
-
-for (y = 0; y < fb->height; y++) {
-src = cma_obj->vaddr + (y * pitch);
-memcpy(buf, src, pitch);
+for (y = clip->y1; y < clip->y2; y++) {
+src = vaddr + (y * fb->pitches[0]);
+src += clip->x1;
+memcpy(buf, src, len);
  src = buf;
-for (x = 0; x < fb->width; x++) {
+for (x = clip->x1; x < clip->x2; x++) {
  u8 r = (*src & 0x00ff) >> 16;
  u8 g = (*src & 0xff00) >> 8;
  u8 b =  *src & 0x00ff;
@@ -240,13 +235,9 @@ int tinydrm_xrgb_to_gray8(u8 *dst, struct 
drm_framebuffer *fb)

  }
  }
  -if (import_attach)
-ret = dma_buf_end_cpu_access(import_attach->dmabuf,
- DMA_FROM_DEVICE);
-err_free:
  kfree(buf);
  -return ret;
+return 0;
  }
  EXPORT_SYMBOL(tinydrm_xrgb_to_gray8);
  diff --git a/drivers/gpu/drm/tinydrm/repaper.c 
b/drivers/gpu/drm/tinydrm/repaper.c

index 3343d3f..d34cd9b 100644
--- a/drivers/gpu/drm/tinydrm/repaper.c
+++ b/drivers/gpu/drm/tinydrm/repaper.c
@@ -18,6 +18,7 @@
   */
#include 
+#include 
  #include 
  #include 
  #include 
@@ -525,11 +526,20 @@ static int repaper_fb_dirty(struct 
drm_framebuffer *fb,

  struct drm_clip_rect *clips,
  unsigned int num_clips)
  {
+struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
+struct dma_buf_attachment *import_attach = 
cma_obj->base.import_attach;

  struct tinydrm_device *tdev = fb->dev->dev_private;
  struct repaper_epd *epd = epd_from_tinydrm(tdev);
+struct drm_clip_rect clip;
  u8 *buf = NULL;
  int ret = 0;
  +/* repaper can't do partial updates */
+clip.x1 = 0;
+clip.x2 = fb->width;
+clip.y1 = 0;
+clip.y2 = fb->height;
+
  mutex_lock(>dirty_lock);
if (!epd->enabled)
@@ -550,7 +560,16 @@ static int repaper_fb_dirty(struct 
drm_framebuffer *fb,

  goto out_unlock;
  }
  -ret = tinydrm_xrgb_to_gray8(buf, fb);
+if (import_attach) {
+ret = dma_buf_begin_cpu_access(import_attach->dmabuf,
+   DMA_FROM_DEVICE);
+if (ret)
+goto out_unlock;
+}
+
+ret = tinydrm_xrgb_to_gray8(buf, cma_obj->vaddr, fb, );
+if (import_attach)
+dma_buf_end_cpu_access(import_attach->dmabuf, DMA_FROM_DEVICE);


I think we can make tinydrm_xrgb_to_gr

Re: [PATCH v3 2/6] drm/tinydrm: generalize tinydrm_xrgb8888_to_gray8()

2017-08-04 Thread Noralf Trønnes


Den 04.08.2017 09.27, skrev Noralf Trønnes:


Den 04.08.2017 00.33, skrev David Lechner:
This adds parameters for vaddr and clip to 
tinydrm_xrgb_to_gray8() to

make it more generic.

dma_buf_{begin,end}_cpu_access() are moved out to the repaper driver.

Signed-off-by: David Lechner 
---
  drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 35 
++

  drivers/gpu/drm/tinydrm/repaper.c  | 21 +++-
  include/drm/tinydrm/tinydrm-helpers.h  |  3 ++-
  3 files changed, 35 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c 
b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c

index 75808bb..5915ba8 100644
--- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
+++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
@@ -185,7 +185,9 @@ EXPORT_SYMBOL(tinydrm_xrgb_to_rgb565);
  /**
   * tinydrm_xrgb_to_gray8 - Convert XRGB to grayscale
   * @dst: 8-bit grayscale destination buffer
+ * @vaddr: XRGB source buffer
   * @fb: DRM framebuffer
+ * @clip: Clip rectangle area to copy
   *
   * Drm doesn't have native monochrome or grayscale support.
   * Such drivers can announce the commonly supported XR24 format to 
userspace

@@ -199,12 +201,11 @@ EXPORT_SYMBOL(tinydrm_xrgb_to_rgb565);
   * Returns:
   * Zero on success, negative error code on failure.
   */
-int tinydrm_xrgb_to_gray8(u8 *dst, struct drm_framebuffer *fb)
+int tinydrm_xrgb_to_gray8(u8 *dst, void *vaddr, struct 
drm_framebuffer *fb,

+  struct drm_clip_rect *clip)
  {
-struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
-struct dma_buf_attachment *import_attach = 
cma_obj->base.import_attach;

-unsigned int x, y, pitch = fb->pitches[0];
-int ret = 0;
+unsigned int len = (clip->x2 - clip->x1) * sizeof(u32);
+unsigned int x, y;
  void *buf;
  u32 *src;
  @@ -214,22 +215,16 @@ int tinydrm_xrgb_to_gray8(u8 *dst, struct 
drm_framebuffer *fb)

   * The cma memory is write-combined so reads are uncached.
   * Speed up by fetching one line at a time.
   */
-buf = kmalloc(pitch, GFP_KERNEL);
+buf = kmalloc(len, GFP_KERNEL);
  if (!buf)
  return -ENOMEM;
  -if (import_attach) {
-ret = dma_buf_begin_cpu_access(import_attach->dmabuf,
-   DMA_FROM_DEVICE);
-if (ret)
-goto err_free;
-}
-
-for (y = 0; y < fb->height; y++) {
-src = cma_obj->vaddr + (y * pitch);
-memcpy(buf, src, pitch);
+for (y = clip->y1; y < clip->y2; y++) {
+src = vaddr + (y * fb->pitches[0]);
+src += clip->x1;
+memcpy(buf, src, len);
  src = buf;
-for (x = 0; x < fb->width; x++) {
+for (x = clip->x1; x < clip->x2; x++) {
  u8 r = (*src & 0x00ff) >> 16;
  u8 g = (*src & 0xff00) >> 8;
  u8 b =  *src & 0x00ff;
@@ -240,13 +235,9 @@ int tinydrm_xrgb_to_gray8(u8 *dst, struct 
drm_framebuffer *fb)

  }
  }
  -if (import_attach)
-ret = dma_buf_end_cpu_access(import_attach->dmabuf,
- DMA_FROM_DEVICE);
-err_free:
  kfree(buf);
  -return ret;
+return 0;
  }
  EXPORT_SYMBOL(tinydrm_xrgb_to_gray8);
  diff --git a/drivers/gpu/drm/tinydrm/repaper.c 
b/drivers/gpu/drm/tinydrm/repaper.c

index 3343d3f..d34cd9b 100644
--- a/drivers/gpu/drm/tinydrm/repaper.c
+++ b/drivers/gpu/drm/tinydrm/repaper.c
@@ -18,6 +18,7 @@
   */
#include 
+#include 
  #include 
  #include 
  #include 
@@ -525,11 +526,20 @@ static int repaper_fb_dirty(struct 
drm_framebuffer *fb,

  struct drm_clip_rect *clips,
  unsigned int num_clips)
  {
+struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
+struct dma_buf_attachment *import_attach = 
cma_obj->base.import_attach;

  struct tinydrm_device *tdev = fb->dev->dev_private;
  struct repaper_epd *epd = epd_from_tinydrm(tdev);
+struct drm_clip_rect clip;
  u8 *buf = NULL;
  int ret = 0;
  +/* repaper can't do partial updates */
+clip.x1 = 0;
+clip.x2 = fb->width;
+clip.y1 = 0;
+clip.y2 = fb->height;
+
  mutex_lock(>dirty_lock);
if (!epd->enabled)
@@ -550,7 +560,16 @@ static int repaper_fb_dirty(struct 
drm_framebuffer *fb,

  goto out_unlock;
  }
  -ret = tinydrm_xrgb_to_gray8(buf, fb);
+if (import_attach) {
+ret = dma_buf_begin_cpu_access(import_attach->dmabuf,
+   DMA_FROM_DEVICE);
+if (ret)
+goto out_unlock;
+}
+
+ret = tinydrm_xrgb_to_gray8(buf, cma_obj->vaddr, fb, );
+if (import_attach)
+dma_buf_end_cpu_access(import_attach->dmabuf, DMA_FROM_DEVICE);


I think we can make tinydrm_xrgb_to_gray8() return void like th

Re: [PATCH v3 1/6] drm/tinydrm: remove call to mipi_dbi_init() from mipi_dbi_spi_init()

2017-08-04 Thread Noralf Trønnes


Den 04.08.2017 00.33, skrev David Lechner:

This removes the call to mipi_dbi_init() from mipi_dbi_spi_init() so that
drivers can have a driver-specific implementation if needed.

Suggested-by: Noralf Trønnes <nor...@tronnes.org>
Signed-off-by: David Lechner <da...@lechnology.com>
Reviewed-by: Noralf Trønnes <nor...@tronnes.org>
---


Thanks, applied to drm-misc.

Noralf.


  drivers/gpu/drm/tinydrm/mi0283qt.c |  8 ++--
  drivers/gpu/drm/tinydrm/mipi-dbi.c | 17 +
  include/drm/tinydrm/mipi-dbi.h |  6 +-
  3 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/mi0283qt.c 
b/drivers/gpu/drm/tinydrm/mi0283qt.c
index 482ff1c3..7e5bb7d 100644
--- a/drivers/gpu/drm/tinydrm/mi0283qt.c
+++ b/drivers/gpu/drm/tinydrm/mi0283qt.c
@@ -195,8 +195,12 @@ static int mi0283qt_probe(struct spi_device *spi)
  
  	device_property_read_u32(dev, "rotation", );
  
-	ret = mipi_dbi_spi_init(spi, mipi, dc, _pipe_funcs,

-   _driver, _mode, rotation);
+   ret = mipi_dbi_spi_init(spi, mipi, dc);
+   if (ret)
+   return ret;
+
+   ret = mipi_dbi_init(>dev, mipi, _pipe_funcs,
+   _driver, _mode, rotation);
if (ret)
return ret;
  
diff --git a/drivers/gpu/drm/tinydrm/mipi-dbi.c b/drivers/gpu/drm/tinydrm/mipi-dbi.c

index e10fa4b..cba9784 100644
--- a/drivers/gpu/drm/tinydrm/mipi-dbi.c
+++ b/drivers/gpu/drm/tinydrm/mipi-dbi.c
@@ -777,15 +777,12 @@ static int mipi_dbi_typec3_command(struct mipi_dbi *mipi, 
u8 cmd,
  /**
   * mipi_dbi_spi_init - Initialize MIPI DBI SPI interfaced controller
   * @spi: SPI device
- * @dc: D/C gpio (optional)
   * @mipi: _dbi structure to initialize
- * @pipe_funcs: Display pipe functions
- * @driver: DRM driver
- * @mode: Display mode
- * @rotation: Initial rotation in degrees Counter Clock Wise
+ * @dc: D/C gpio (optional)
   *
   * This function sets _dbi->command, enables >read_commands for the
- * usual read commands and initializes @mipi using mipi_dbi_init().
+ * usual read commands. It should be followed by a call to mipi_dbi_init() or
+ * a driver-specific init.
   *
   * If @dc is set, a Type C Option 3 interface is assumed, if not
   * Type C Option 1.
@@ -800,11 +797,7 @@ static int mipi_dbi_typec3_command(struct mipi_dbi *mipi, 
u8 cmd,
   * Zero on success, negative error code on failure.
   */
  int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *mipi,
- struct gpio_desc *dc,
- const struct drm_simple_display_pipe_funcs *pipe_funcs,
- struct drm_driver *driver,
- const struct drm_display_mode *mode,
- unsigned int rotation)
+ struct gpio_desc *dc)
  {
size_t tx_size = tinydrm_spi_max_transfer_size(spi, 0);
struct device *dev = >dev;
@@ -850,7 +843,7 @@ int mipi_dbi_spi_init(struct spi_device *spi, struct 
mipi_dbi *mipi,
return -ENOMEM;
}
  
-	return mipi_dbi_init(dev, mipi, pipe_funcs, driver, mode, rotation);

+   return 0;
  }
  EXPORT_SYMBOL(mipi_dbi_spi_init);
  
diff --git a/include/drm/tinydrm/mipi-dbi.h b/include/drm/tinydrm/mipi-dbi.h

index d137b16..83346dd 100644
--- a/include/drm/tinydrm/mipi-dbi.h
+++ b/include/drm/tinydrm/mipi-dbi.h
@@ -62,11 +62,7 @@ mipi_dbi_from_tinydrm(struct tinydrm_device *tdev)
  }
  
  int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *mipi,

- struct gpio_desc *dc,
- const struct drm_simple_display_pipe_funcs *pipe_funcs,
- struct drm_driver *driver,
- const struct drm_display_mode *mode,
- unsigned int rotation);
+ struct gpio_desc *dc);
  int mipi_dbi_init(struct device *dev, struct mipi_dbi *mipi,
  const struct drm_simple_display_pipe_funcs *pipe_funcs,
  struct drm_driver *driver,




Re: [PATCH v3 1/6] drm/tinydrm: remove call to mipi_dbi_init() from mipi_dbi_spi_init()

2017-08-04 Thread Noralf Trønnes


Den 04.08.2017 00.33, skrev David Lechner:

This removes the call to mipi_dbi_init() from mipi_dbi_spi_init() so that
drivers can have a driver-specific implementation if needed.

Suggested-by: Noralf Trønnes 
Signed-off-by: David Lechner 
Reviewed-by: Noralf Trønnes 
---


Thanks, applied to drm-misc.

Noralf.


  drivers/gpu/drm/tinydrm/mi0283qt.c |  8 ++--
  drivers/gpu/drm/tinydrm/mipi-dbi.c | 17 +
  include/drm/tinydrm/mipi-dbi.h |  6 +-
  3 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/mi0283qt.c 
b/drivers/gpu/drm/tinydrm/mi0283qt.c
index 482ff1c3..7e5bb7d 100644
--- a/drivers/gpu/drm/tinydrm/mi0283qt.c
+++ b/drivers/gpu/drm/tinydrm/mi0283qt.c
@@ -195,8 +195,12 @@ static int mi0283qt_probe(struct spi_device *spi)
  
  	device_property_read_u32(dev, "rotation", );
  
-	ret = mipi_dbi_spi_init(spi, mipi, dc, _pipe_funcs,

-   _driver, _mode, rotation);
+   ret = mipi_dbi_spi_init(spi, mipi, dc);
+   if (ret)
+   return ret;
+
+   ret = mipi_dbi_init(>dev, mipi, _pipe_funcs,
+   _driver, _mode, rotation);
if (ret)
return ret;
  
diff --git a/drivers/gpu/drm/tinydrm/mipi-dbi.c b/drivers/gpu/drm/tinydrm/mipi-dbi.c

index e10fa4b..cba9784 100644
--- a/drivers/gpu/drm/tinydrm/mipi-dbi.c
+++ b/drivers/gpu/drm/tinydrm/mipi-dbi.c
@@ -777,15 +777,12 @@ static int mipi_dbi_typec3_command(struct mipi_dbi *mipi, 
u8 cmd,
  /**
   * mipi_dbi_spi_init - Initialize MIPI DBI SPI interfaced controller
   * @spi: SPI device
- * @dc: D/C gpio (optional)
   * @mipi: _dbi structure to initialize
- * @pipe_funcs: Display pipe functions
- * @driver: DRM driver
- * @mode: Display mode
- * @rotation: Initial rotation in degrees Counter Clock Wise
+ * @dc: D/C gpio (optional)
   *
   * This function sets _dbi->command, enables >read_commands for the
- * usual read commands and initializes @mipi using mipi_dbi_init().
+ * usual read commands. It should be followed by a call to mipi_dbi_init() or
+ * a driver-specific init.
   *
   * If @dc is set, a Type C Option 3 interface is assumed, if not
   * Type C Option 1.
@@ -800,11 +797,7 @@ static int mipi_dbi_typec3_command(struct mipi_dbi *mipi, 
u8 cmd,
   * Zero on success, negative error code on failure.
   */
  int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *mipi,
- struct gpio_desc *dc,
- const struct drm_simple_display_pipe_funcs *pipe_funcs,
- struct drm_driver *driver,
- const struct drm_display_mode *mode,
- unsigned int rotation)
+ struct gpio_desc *dc)
  {
size_t tx_size = tinydrm_spi_max_transfer_size(spi, 0);
struct device *dev = >dev;
@@ -850,7 +843,7 @@ int mipi_dbi_spi_init(struct spi_device *spi, struct 
mipi_dbi *mipi,
return -ENOMEM;
}
  
-	return mipi_dbi_init(dev, mipi, pipe_funcs, driver, mode, rotation);

+   return 0;
  }
  EXPORT_SYMBOL(mipi_dbi_spi_init);
  
diff --git a/include/drm/tinydrm/mipi-dbi.h b/include/drm/tinydrm/mipi-dbi.h

index d137b16..83346dd 100644
--- a/include/drm/tinydrm/mipi-dbi.h
+++ b/include/drm/tinydrm/mipi-dbi.h
@@ -62,11 +62,7 @@ mipi_dbi_from_tinydrm(struct tinydrm_device *tdev)
  }
  
  int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *mipi,

- struct gpio_desc *dc,
- const struct drm_simple_display_pipe_funcs *pipe_funcs,
- struct drm_driver *driver,
- const struct drm_display_mode *mode,
- unsigned int rotation);
+ struct gpio_desc *dc);
  int mipi_dbi_init(struct device *dev, struct mipi_dbi *mipi,
  const struct drm_simple_display_pipe_funcs *pipe_funcs,
  struct drm_driver *driver,




Re: [PATCH v3 3/6] dt-bindings: add binding for Sitronix ST7586 display panels

2017-08-04 Thread Noralf Trønnes


Den 04.08.2017 00.33, skrev David Lechner:

This adds a new binding for Sitronix ST7586 display panels.

Using lego as the vendor prefix in the compatible string because the display
panel I am working with is an integral part of the LEGO MINDSTORMS EV3.


Is this display available outside of this Lego part?
If not you can remove the properties you don't need for this particular
display setup. Another st7586 display with a different panel would need
a different initialization sequence and compatible string, so we can
add properties when/if that happens.

Noralf.


Signed-off-by: David Lechner 
---
  .../bindings/display/sitronix,st7586.txt   | 26 ++
  1 file changed, 26 insertions(+)
  create mode 100644 
Documentation/devicetree/bindings/display/sitronix,st7586.txt

diff --git a/Documentation/devicetree/bindings/display/sitronix,st7586.txt 
b/Documentation/devicetree/bindings/display/sitronix,st7586.txt
new file mode 100644
index 000..dfb0b7b
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/sitronix,st7586.txt
@@ -0,0 +1,26 @@
+Sitronix ST7586 display panel
+
+Required properties:
+- compatible:  "lego,ev3-lcd".
+
+The node for this driver must be a child node of a SPI controller, hence
+all mandatory properties described in ../spi/spi-bus.txt must be specified.
+
+Optional properties:
+- dc-gpios:D/C pin. The presence/absence of this GPIO determines
+   the panel interface operation mode (IF[3:1] pins):
+   - present: IF=011 4-wire 8-bit data serial interface
+   - absent:  IF=010 3-wire 9-bit data serial interface
+- reset-gpios: Reset pin
+- power-supply:A regulator node for the supply voltage.
+- backlight:   phandle of the backlight device attached to the panel
+- rotation:panel rotation in degrees counter clockwise (0,90,180,270)
+
+Example:
+   display@0{
+   compatible = "lego,ev3-lcd";
+   reg = <0>;
+   spi-max-frequency = <1000>;
+   dc-gpios = < 43 GPIO_ACTIVE_HIGH>;
+   reset-gpios = < 80 GPIO_ACTIVE_HIGH>;
+   };




Re: [PATCH v3 3/6] dt-bindings: add binding for Sitronix ST7586 display panels

2017-08-04 Thread Noralf Trønnes


Den 04.08.2017 00.33, skrev David Lechner:

This adds a new binding for Sitronix ST7586 display panels.

Using lego as the vendor prefix in the compatible string because the display
panel I am working with is an integral part of the LEGO MINDSTORMS EV3.


Is this display available outside of this Lego part?
If not you can remove the properties you don't need for this particular
display setup. Another st7586 display with a different panel would need
a different initialization sequence and compatible string, so we can
add properties when/if that happens.

Noralf.


Signed-off-by: David Lechner 
---
  .../bindings/display/sitronix,st7586.txt   | 26 ++
  1 file changed, 26 insertions(+)
  create mode 100644 
Documentation/devicetree/bindings/display/sitronix,st7586.txt

diff --git a/Documentation/devicetree/bindings/display/sitronix,st7586.txt 
b/Documentation/devicetree/bindings/display/sitronix,st7586.txt
new file mode 100644
index 000..dfb0b7b
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/sitronix,st7586.txt
@@ -0,0 +1,26 @@
+Sitronix ST7586 display panel
+
+Required properties:
+- compatible:  "lego,ev3-lcd".
+
+The node for this driver must be a child node of a SPI controller, hence
+all mandatory properties described in ../spi/spi-bus.txt must be specified.
+
+Optional properties:
+- dc-gpios:D/C pin. The presence/absence of this GPIO determines
+   the panel interface operation mode (IF[3:1] pins):
+   - present: IF=011 4-wire 8-bit data serial interface
+   - absent:  IF=010 3-wire 9-bit data serial interface
+- reset-gpios: Reset pin
+- power-supply:A regulator node for the supply voltage.
+- backlight:   phandle of the backlight device attached to the panel
+- rotation:panel rotation in degrees counter clockwise (0,90,180,270)
+
+Example:
+   display@0{
+   compatible = "lego,ev3-lcd";
+   reg = <0>;
+   spi-max-frequency = <1000>;
+   dc-gpios = < 43 GPIO_ACTIVE_HIGH>;
+   reset-gpios = < 80 GPIO_ACTIVE_HIGH>;
+   };




Re: [PATCH v3 2/6] drm/tinydrm: generalize tinydrm_xrgb8888_to_gray8()

2017-08-04 Thread Noralf Trønnes


Den 04.08.2017 00.33, skrev David Lechner:

This adds parameters for vaddr and clip to tinydrm_xrgb_to_gray8() to
make it more generic.

dma_buf_{begin,end}_cpu_access() are moved out to the repaper driver.

Signed-off-by: David Lechner 
---
  drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 35 ++
  drivers/gpu/drm/tinydrm/repaper.c  | 21 +++-
  include/drm/tinydrm/tinydrm-helpers.h  |  3 ++-
  3 files changed, 35 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c 
b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
index 75808bb..5915ba8 100644
--- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
+++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
@@ -185,7 +185,9 @@ EXPORT_SYMBOL(tinydrm_xrgb_to_rgb565);
  /**
   * tinydrm_xrgb_to_gray8 - Convert XRGB to grayscale
   * @dst: 8-bit grayscale destination buffer
+ * @vaddr: XRGB source buffer
   * @fb: DRM framebuffer
+ * @clip: Clip rectangle area to copy
   *
   * Drm doesn't have native monochrome or grayscale support.
   * Such drivers can announce the commonly supported XR24 format to userspace
@@ -199,12 +201,11 @@ EXPORT_SYMBOL(tinydrm_xrgb_to_rgb565);
   * Returns:
   * Zero on success, negative error code on failure.
   */
-int tinydrm_xrgb_to_gray8(u8 *dst, struct drm_framebuffer *fb)
+int tinydrm_xrgb_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb,
+ struct drm_clip_rect *clip)
  {
-   struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
-   struct dma_buf_attachment *import_attach = cma_obj->base.import_attach;
-   unsigned int x, y, pitch = fb->pitches[0];
-   int ret = 0;
+   unsigned int len = (clip->x2 - clip->x1) * sizeof(u32);
+   unsigned int x, y;
void *buf;
u32 *src;
  
@@ -214,22 +215,16 @@ int tinydrm_xrgb_to_gray8(u8 *dst, struct drm_framebuffer *fb)

 * The cma memory is write-combined so reads are uncached.
 * Speed up by fetching one line at a time.
 */
-   buf = kmalloc(pitch, GFP_KERNEL);
+   buf = kmalloc(len, GFP_KERNEL);
if (!buf)
return -ENOMEM;
  
-	if (import_attach) {

-   ret = dma_buf_begin_cpu_access(import_attach->dmabuf,
-  DMA_FROM_DEVICE);
-   if (ret)
-   goto err_free;
-   }
-
-   for (y = 0; y < fb->height; y++) {
-   src = cma_obj->vaddr + (y * pitch);
-   memcpy(buf, src, pitch);
+   for (y = clip->y1; y < clip->y2; y++) {
+   src = vaddr + (y * fb->pitches[0]);
+   src += clip->x1;
+   memcpy(buf, src, len);
src = buf;
-   for (x = 0; x < fb->width; x++) {
+   for (x = clip->x1; x < clip->x2; x++) {
u8 r = (*src & 0x00ff) >> 16;
u8 g = (*src & 0xff00) >> 8;
u8 b =  *src & 0x00ff;
@@ -240,13 +235,9 @@ int tinydrm_xrgb_to_gray8(u8 *dst, struct 
drm_framebuffer *fb)
}
}
  
-	if (import_attach)

-   ret = dma_buf_end_cpu_access(import_attach->dmabuf,
-DMA_FROM_DEVICE);
-err_free:
kfree(buf);
  
-	return ret;

+   return 0;
  }
  EXPORT_SYMBOL(tinydrm_xrgb_to_gray8);
  
diff --git a/drivers/gpu/drm/tinydrm/repaper.c b/drivers/gpu/drm/tinydrm/repaper.c

index 3343d3f..d34cd9b 100644
--- a/drivers/gpu/drm/tinydrm/repaper.c
+++ b/drivers/gpu/drm/tinydrm/repaper.c
@@ -18,6 +18,7 @@
   */
  
  #include 

+#include 
  #include 
  #include 
  #include 
@@ -525,11 +526,20 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb,
struct drm_clip_rect *clips,
unsigned int num_clips)
  {
+   struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
+   struct dma_buf_attachment *import_attach = cma_obj->base.import_attach;
struct tinydrm_device *tdev = fb->dev->dev_private;
struct repaper_epd *epd = epd_from_tinydrm(tdev);
+   struct drm_clip_rect clip;
u8 *buf = NULL;
int ret = 0;
  
+	/* repaper can't do partial updates */

+   clip.x1 = 0;
+   clip.x2 = fb->width;
+   clip.y1 = 0;
+   clip.y2 = fb->height;
+
mutex_lock(>dirty_lock);
  
  	if (!epd->enabled)

@@ -550,7 +560,16 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb,
goto out_unlock;
}
  
-	ret = tinydrm_xrgb_to_gray8(buf, fb);

+   if (import_attach) {
+   ret = dma_buf_begin_cpu_access(import_attach->dmabuf,
+  DMA_FROM_DEVICE);
+   if (ret)
+   goto out_unlock;
+   }
+
+   ret = tinydrm_xrgb_to_gray8(buf, 

Re: [PATCH v3 2/6] drm/tinydrm: generalize tinydrm_xrgb8888_to_gray8()

2017-08-04 Thread Noralf Trønnes


Den 04.08.2017 00.33, skrev David Lechner:

This adds parameters for vaddr and clip to tinydrm_xrgb_to_gray8() to
make it more generic.

dma_buf_{begin,end}_cpu_access() are moved out to the repaper driver.

Signed-off-by: David Lechner 
---
  drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 35 ++
  drivers/gpu/drm/tinydrm/repaper.c  | 21 +++-
  include/drm/tinydrm/tinydrm-helpers.h  |  3 ++-
  3 files changed, 35 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c 
b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
index 75808bb..5915ba8 100644
--- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
+++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
@@ -185,7 +185,9 @@ EXPORT_SYMBOL(tinydrm_xrgb_to_rgb565);
  /**
   * tinydrm_xrgb_to_gray8 - Convert XRGB to grayscale
   * @dst: 8-bit grayscale destination buffer
+ * @vaddr: XRGB source buffer
   * @fb: DRM framebuffer
+ * @clip: Clip rectangle area to copy
   *
   * Drm doesn't have native monochrome or grayscale support.
   * Such drivers can announce the commonly supported XR24 format to userspace
@@ -199,12 +201,11 @@ EXPORT_SYMBOL(tinydrm_xrgb_to_rgb565);
   * Returns:
   * Zero on success, negative error code on failure.
   */
-int tinydrm_xrgb_to_gray8(u8 *dst, struct drm_framebuffer *fb)
+int tinydrm_xrgb_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb,
+ struct drm_clip_rect *clip)
  {
-   struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
-   struct dma_buf_attachment *import_attach = cma_obj->base.import_attach;
-   unsigned int x, y, pitch = fb->pitches[0];
-   int ret = 0;
+   unsigned int len = (clip->x2 - clip->x1) * sizeof(u32);
+   unsigned int x, y;
void *buf;
u32 *src;
  
@@ -214,22 +215,16 @@ int tinydrm_xrgb_to_gray8(u8 *dst, struct drm_framebuffer *fb)

 * The cma memory is write-combined so reads are uncached.
 * Speed up by fetching one line at a time.
 */
-   buf = kmalloc(pitch, GFP_KERNEL);
+   buf = kmalloc(len, GFP_KERNEL);
if (!buf)
return -ENOMEM;
  
-	if (import_attach) {

-   ret = dma_buf_begin_cpu_access(import_attach->dmabuf,
-  DMA_FROM_DEVICE);
-   if (ret)
-   goto err_free;
-   }
-
-   for (y = 0; y < fb->height; y++) {
-   src = cma_obj->vaddr + (y * pitch);
-   memcpy(buf, src, pitch);
+   for (y = clip->y1; y < clip->y2; y++) {
+   src = vaddr + (y * fb->pitches[0]);
+   src += clip->x1;
+   memcpy(buf, src, len);
src = buf;
-   for (x = 0; x < fb->width; x++) {
+   for (x = clip->x1; x < clip->x2; x++) {
u8 r = (*src & 0x00ff) >> 16;
u8 g = (*src & 0xff00) >> 8;
u8 b =  *src & 0x00ff;
@@ -240,13 +235,9 @@ int tinydrm_xrgb_to_gray8(u8 *dst, struct 
drm_framebuffer *fb)
}
}
  
-	if (import_attach)

-   ret = dma_buf_end_cpu_access(import_attach->dmabuf,
-DMA_FROM_DEVICE);
-err_free:
kfree(buf);
  
-	return ret;

+   return 0;
  }
  EXPORT_SYMBOL(tinydrm_xrgb_to_gray8);
  
diff --git a/drivers/gpu/drm/tinydrm/repaper.c b/drivers/gpu/drm/tinydrm/repaper.c

index 3343d3f..d34cd9b 100644
--- a/drivers/gpu/drm/tinydrm/repaper.c
+++ b/drivers/gpu/drm/tinydrm/repaper.c
@@ -18,6 +18,7 @@
   */
  
  #include 

+#include 
  #include 
  #include 
  #include 
@@ -525,11 +526,20 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb,
struct drm_clip_rect *clips,
unsigned int num_clips)
  {
+   struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
+   struct dma_buf_attachment *import_attach = cma_obj->base.import_attach;
struct tinydrm_device *tdev = fb->dev->dev_private;
struct repaper_epd *epd = epd_from_tinydrm(tdev);
+   struct drm_clip_rect clip;
u8 *buf = NULL;
int ret = 0;
  
+	/* repaper can't do partial updates */

+   clip.x1 = 0;
+   clip.x2 = fb->width;
+   clip.y1 = 0;
+   clip.y2 = fb->height;
+
mutex_lock(>dirty_lock);
  
  	if (!epd->enabled)

@@ -550,7 +560,16 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb,
goto out_unlock;
}
  
-	ret = tinydrm_xrgb_to_gray8(buf, fb);

+   if (import_attach) {
+   ret = dma_buf_begin_cpu_access(import_attach->dmabuf,
+  DMA_FROM_DEVICE);
+   if (ret)
+   goto out_unlock;
+   }
+
+   ret = tinydrm_xrgb_to_gray8(buf, cma_obj->vaddr, fb, );
+   

<    1   2   3   4   5   6   7   8   9   >