Skip to contentSkip to conversation

drm/tinydrm: drm_of_find_backlight helper

PATCH Superseded Meghana Madhyastha 3 participants 11 messages Sep 30, 2017 – Oct 2, 2017

Subsystems (3)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 cover drm/tinydrm: drm_of_find_backlight helper

Move tinydrm_of_find_backlight to drm_of.c and rename it to drm_of_find_backlight for better organizational structure.

Changes in v6:
-Move function declarations to linux/backlight.h to prevent
build errors for the dependencies issue.
-Remove docs for devm_drm_of_find_backlight_release as it is
an internal function.

Meghana Madhyastha (2):
drm/tinydrm: Move tinydrm_of_find_backlight into drm_of.c drm/tinydrm: Add devres versions of drm_of_find_backlight

 drivers/gpu/drm/drm_of.c                       | 84 ++++++++++++++++++++++++++
 drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 40 ------------
 drivers/gpu/drm/tinydrm/mi0283qt.c             |  2 +-
 include/drm/tinydrm/tinydrm-helpers.h          |  1 -
 include/linux/backlight.h                      | 18 ++++++
 5 files changed, 103 insertions(+), 42 deletions(-)
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH v6 1/2 drm/tinydrm: Move tinydrm_of_find_backlight into drm_of.c

Rename tinydrm_of_find_backlight to drm_of_find_backlight and move it into drm_of.c from tinydrm-helpers.c. This is because other drivers in the drm subsystem might need to call this function. In that case and otherwise, it is better from an organizational point of view to move it into drm_of.c along with the other _of.c functions.

---
Changes in v6:
-Move function declarations to linux/backlight.h to resolve
module dependency issues.

 drivers/gpu/drm/drm_of.c                       | 44 ++++++++++++++++++++++++++
 drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 40 -----------------------
 drivers/gpu/drm/tinydrm/mi0283qt.c             |  2 +-
 include/drm/tinydrm/tinydrm-helpers.h          |  1 -
 include/linux/backlight.h                      | 11 +++++++
 5 files changed, 56 insertions(+), 42 deletions(-)
drivers/gpu/drm/drm_of.c +44 -0
index 8dafbdf..d878d3a 100644
@@ -1,6 +1,7 @@
 #include <linux/component.h>
 #include <linux/export.h>
 #include <linux/list.h>
+#include <linux/backlight.h>
 #include <linux/of_graph.h>
 #include <drm/drmP.h>
 #include <drm/drm_bridge.h>
@@ -260,3 +261,46 @@ int drm_of_find_panel_or_bridge(const struct device_node *np,
 	return ret;
 }
 EXPORT_SYMBOL_GPL(drm_of_find_panel_or_bridge);
+
+/**
+ * drm_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.
+ *
+ * Note: It is the responsibility of the caller to call put_device() when
+ * releasing the resource.
+ *
+ * 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 *drm_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(drm_of_find_backlight);
drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +0 -40
index bd6cce0..cd4c6a5 100644
@@ -237,46 +237,6 @@ void tinydrm_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb,
 EXPORT_SYMBOL(tinydrm_xrgb8888_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);
-
-/**
  * tinydrm_enable_backlight - Enable backlight helper
  * @backlight: Backlight device
  *
drivers/gpu/drm/tinydrm/mi0283qt.c +1 -1
index 7e5bb7d..682b4db 100644
@@ -189,7 +189,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 = drm_of_find_backlight(dev);
 	if (IS_ERR(mipi->backlight))
 		return PTR_ERR(mipi->backlight);
 
include/drm/tinydrm/tinydrm-helpers.h +0 -1
index d554ded..e40ef2d 100644
@@ -46,7 +46,6 @@ void tinydrm_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
 void tinydrm_xrgb8888_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);
 
include/linux/backlight.h +11 -0
index 5f2fd61..47a095e 100644
@@ -172,4 +172,15 @@ of_find_backlight_by_node(struct device_node *node)
 }
 #endif
 
+#if defined(CONFIG_OF) && IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
+struct backlight_device *
+drm_of_find_backlight(struct device *dev);
+#else
+static inline struct backlight_device *
+drm_of_find_backlight(struct device *dev)
+{
+	return NULL;
+}
+#endif
+
 #endif
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

Re: [PATCH v6 1/2] drm/tinydrm: Move tinydrm_of_find_backlight into drm_of.c

Den 30.09.2017 19.12, skrev Meghana Madhyastha:

Quoted 165 lines

Rename tinydrm_of_find_backlight to drm_of_find_backlight and move it into drm_of.c from tinydrm-helpers.c. This is because other drivers in the drm subsystem might need to call this function. In that case and otherwise, it is better from an organizational point of view to move it into drm_of.c along with the other _of.c functions.

---
Changes in v6:

(quoted diff) +0 -1
-Move function declarations to linux/backlight.h to resolve
  module dependency issues.
 
  drivers/gpu/drm/drm_of.c                       | 44 ++++++++++++++++++++++++++
  drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 40 -----------------------
  drivers/gpu/drm/tinydrm/mi0283qt.c             |  2 +-
  include/drm/tinydrm/tinydrm-helpers.h          |  1 -
  include/linux/backlight.h                      | 11 +++++++
  5 files changed, 56 insertions(+), 42 deletions(-)
drivers/gpu/drm/drm_of.c +44 -0
index 8dafbdf..d878d3a 100644
@@ -1,6 +1,7 @@
  #include <linux/component.h>
  #include <linux/export.h>
  #include <linux/list.h>
+#include <linux/backlight.h>
  #include <linux/of_graph.h>
  #include <drm/drmP.h>
  #include <drm/drm_bridge.h>
@@ -260,3 +261,46 @@ int drm_of_find_panel_or_bridge(const struct device_node *np,
  	return ret;
  }
  EXPORT_SYMBOL_GPL(drm_of_find_panel_or_bridge);
+
+/**
+ * drm_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.
+ *
+ * Note: It is the responsibility of the caller to call put_device() when
+ * releasing the resource.
+ *
+ * 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 *drm_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(drm_of_find_backlight);
drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +0 -40
index bd6cce0..cd4c6a5 100644
@@ -237,46 +237,6 @@ void tinydrm_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb,
  EXPORT_SYMBOL(tinydrm_xrgb8888_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);
-
-/**
   * tinydrm_enable_backlight - Enable backlight helper
   * @backlight: Backlight device
   *
drivers/gpu/drm/tinydrm/mi0283qt.c +1 -1
index 7e5bb7d..682b4db 100644
@@ -189,7 +189,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 = drm_of_find_backlight(dev);
  	if (IS_ERR(mipi->backlight))
  		return PTR_ERR(mipi->backlight);
 
include/drm/tinydrm/tinydrm-helpers.h +0 -1
index d554ded..e40ef2d 100644
@@ -46,7 +46,6 @@ void tinydrm_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
  void tinydrm_xrgb8888_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);
 
include/linux/backlight.h +2 -0
index 5f2fd61..47a095e 100644
@@ -172,4 +172,15 @@ of_find_backlight_by_node(struct device_node *node)
  }
  #endif
 
+#if defined(CONFIG_OF) && IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
+struct backlight_device *

include/linux/backlight.h of_find_backlight_by_node(struct device_node *node) · line 186

Quoted 10 lines
include/linux/backlight.h +9 -0
+drm_of_find_backlight(struct device *dev);
+#else
+static inline struct backlight_device *
+drm_of_find_backlight(struct device *dev)
+{
+	return NULL;
+}
+#endif
+
  #endif

This isn't what I meant, you only change the of_find_backlight_by_node() declaration/definition. It should be like this:

#if defined(CONFIG_OF) && IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE) struct backlight_device *of_find_backlight_by_node(struct device_node *node); #else
static inline struct backlight_device * of_find_backlight_by_node(struct device_node *node)
{
    return NULL;
}
#endif

And this change needs to be a patch on it's own. The backlight subsystem has it's own maintainer that will review this change.
It's best to send him/them the whole patchset so they see the context.

Noralf.

#3 lore raw

Re: [PATCH v6 1/2] drm/tinydrm: Move tinydrm_of_find_backlight into drm_of.c

Quoted 175 lines · Noralf Trønnes

Den 30.09.2017 19.12, skrev Meghana Madhyastha:

Quoted 159 lines

Rename tinydrm_of_find_backlight to drm_of_find_backlight and move it into drm_of.c from tinydrm-helpers.c. This is because other drivers in the drm subsystem might need to call this function. In that case and otherwise, it is better from an organizational point of view to move it into drm_of.c along with the other _of.c functions.

---
Changes in v6:

(quoted diff) +0 -1
-Move function declarations to linux/backlight.h to resolve
 module dependency issues.
 
 drivers/gpu/drm/drm_of.c                       | 44 ++++++++++++++++++++++++++
 drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 40 -----------------------
 drivers/gpu/drm/tinydrm/mi0283qt.c             |  2 +-
 include/drm/tinydrm/tinydrm-helpers.h          |  1 -
 include/linux/backlight.h                      | 11 +++++++
 5 files changed, 56 insertions(+), 42 deletions(-)
drivers/gpu/drm/drm_of.c +44 -0
index 8dafbdf..d878d3a 100644
@@ -1,6 +1,7 @@
 #include <linux/component.h>
 #include <linux/export.h>
 #include <linux/list.h>
+#include <linux/backlight.h>
 #include <linux/of_graph.h>
 #include <drm/drmP.h>
 #include <drm/drm_bridge.h>
@@ -260,3 +261,46 @@ int drm_of_find_panel_or_bridge(const struct device_node *np,
 	return ret;
 }
 EXPORT_SYMBOL_GPL(drm_of_find_panel_or_bridge);
+
+/**
+ * drm_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.
+ *
+ * Note: It is the responsibility of the caller to call put_device() when
+ * releasing the resource.
+ *
+ * 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 *drm_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(drm_of_find_backlight);
drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +0 -40
index bd6cce0..cd4c6a5 100644
@@ -237,46 +237,6 @@ void tinydrm_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb,
 EXPORT_SYMBOL(tinydrm_xrgb8888_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);
-
-/**
  * tinydrm_enable_backlight - Enable backlight helper
  * @backlight: Backlight device
  *
drivers/gpu/drm/tinydrm/mi0283qt.c +1 -1
index 7e5bb7d..682b4db 100644
@@ -189,7 +189,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 = drm_of_find_backlight(dev);
 	if (IS_ERR(mipi->backlight))
 		return PTR_ERR(mipi->backlight);
include/drm/tinydrm/tinydrm-helpers.h +0 -1
index d554ded..e40ef2d 100644
@@ -46,7 +46,6 @@ void tinydrm_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
 void tinydrm_xrgb8888_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);
include/linux/backlight.h +2 -0
index 5f2fd61..47a095e 100644
@@ -172,4 +172,15 @@ of_find_backlight_by_node(struct device_node *node)
 }
 #endif
+#if defined(CONFIG_OF) && IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
+struct backlight_device *

include/linux/backlight.h of_find_backlight_by_node(struct device_node *node) · line 185

Quoted 10 lines
include/linux/backlight.h +9 -0
+drm_of_find_backlight(struct device *dev);
+#else
+static inline struct backlight_device *
+drm_of_find_backlight(struct device *dev)
+{
+	return NULL;
+}
+#endif
+
 #endif

This isn't what I meant, you only change the of_find_backlight_by_node() declaration/definition. It should be like this:

Quoted 10 lines

#if defined(CONFIG_OF) && IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE) struct backlight_device *of_find_backlight_by_node(struct device_node *node);
#else
static inline struct backlight_device * of_find_backlight_by_node(struct device_node *node)
{
    return NULL;
}
#endif

I see. So basically add the function declaration of drm_of_find_backlight and devm_drm_of_find_backlight in drm_of.h and this function declaration need not be inside the #ifdef CONFIG / #else part?
So there need not be a dummy version of drm_of_find_backlight here because we are anyway taking care of that in of_find_backliht by node? Sorry for the many versions and thank you for the clarifications.

Regards,
Meghana

Quoted 6 lines

And this change needs to be a patch on it's own. The backlight subsystem has it's own maintainer that will review this change.
It's best to send him/them the whole patchset so they see the context.

Noralf.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw

Re: [PATCH v6 1/2] drm/tinydrm: Move tinydrm_of_find_backlight into drm_of.c

Den 01.10.2017 06.14, skrev Meghana Madhyastha:

Quoted 184 lines · Noralf Trønnes
Quoted 173 lines

Den 30.09.2017 19.12, skrev Meghana Madhyastha:

Quoted 159 lines

Rename tinydrm_of_find_backlight to drm_of_find_backlight and move it into drm_of.c from tinydrm-helpers.c. This is because other drivers in the drm subsystem might need to call this function. In that case and otherwise, it is better from an organizational point of view to move it into drm_of.c along with the other _of.c functions.

---
Changes in v6:

(quoted diff) +0 -1
-Move function declarations to linux/backlight.h to resolve
  module dependency issues.
 
  drivers/gpu/drm/drm_of.c                       | 44 ++++++++++++++++++++++++++
  drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 40 -----------------------
  drivers/gpu/drm/tinydrm/mi0283qt.c             |  2 +-
  include/drm/tinydrm/tinydrm-helpers.h          |  1 -
  include/linux/backlight.h                      | 11 +++++++
  5 files changed, 56 insertions(+), 42 deletions(-)
drivers/gpu/drm/drm_of.c +44 -0
index 8dafbdf..d878d3a 100644
@@ -1,6 +1,7 @@
  #include <linux/component.h>
  #include <linux/export.h>
  #include <linux/list.h>
+#include <linux/backlight.h>
  #include <linux/of_graph.h>
  #include <drm/drmP.h>
  #include <drm/drm_bridge.h>
@@ -260,3 +261,46 @@ int drm_of_find_panel_or_bridge(const struct device_node *np,
  	return ret;
  }
  EXPORT_SYMBOL_GPL(drm_of_find_panel_or_bridge);
+
+/**
+ * drm_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.
+ *
+ * Note: It is the responsibility of the caller to call put_device() when
+ * releasing the resource.
+ *
+ * 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 *drm_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(drm_of_find_backlight);
drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +0 -40
index bd6cce0..cd4c6a5 100644
@@ -237,46 +237,6 @@ void tinydrm_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb,
  EXPORT_SYMBOL(tinydrm_xrgb8888_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);
-
-/**
   * tinydrm_enable_backlight - Enable backlight helper
   * @backlight: Backlight device
   *
drivers/gpu/drm/tinydrm/mi0283qt.c +1 -1
index 7e5bb7d..682b4db 100644
@@ -189,7 +189,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 = drm_of_find_backlight(dev);
  	if (IS_ERR(mipi->backlight))
  		return PTR_ERR(mipi->backlight);
include/drm/tinydrm/tinydrm-helpers.h +0 -1
index d554ded..e40ef2d 100644
@@ -46,7 +46,6 @@ void tinydrm_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
  void tinydrm_xrgb8888_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);
include/linux/backlight.h +2 -0
index 5f2fd61..47a095e 100644
@@ -172,4 +172,15 @@ of_find_backlight_by_node(struct device_node *node)
  }
  #endif
+#if defined(CONFIG_OF) && IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
+struct backlight_device *

include/linux/backlight.h of_find_backlight_by_node(struct device_node *node) · line 185

Quoted 10 lines
include/linux/backlight.h +9 -0
+drm_of_find_backlight(struct device *dev);
+#else
+static inline struct backlight_device *
+drm_of_find_backlight(struct device *dev)
+{
+	return NULL;
+}
+#endif
+
  #endif

This isn't what I meant, you only change the of_find_backlight_by_node() declaration/definition. It should be like this:

Quoted 10 lines

#if defined(CONFIG_OF) && IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE) struct backlight_device *of_find_backlight_by_node(struct device_node *node);
#else
static inline struct backlight_device * of_find_backlight_by_node(struct device_node *node)
{
    return NULL;
}
#endif

Quoted 6 lines

I see. So basically add the function declaration of drm_of_find_backlight and devm_drm_of_find_backlight in drm_of.h and this function declaration need not be inside the #ifdef CONFIG / #else part?
So there need not be a dummy version of drm_of_find_backlight here because we are anyway taking care of that in of_find_backliht by node? Sorry for the many versions and thank you for the clarifications.

You need the dummy part in drm_of.h because you need to handle the CONFIG_OF option here as well.

If drm_of_find_backlight() was only 2-3 lines of code, you could have made a static inline function in drm_of.h outside the #if/#else/#endif, but since it's longer than that it should be in drm_of.c.

CONFIG_OF decides if drm_of.c is built (as part of drm.o) or not:

drivers/gpu/drm/Makefile:
drm-$(CONFIG_OF) += drm_of.o

This means we need a function prototype declaration for the CONFIG_OF=y case, and an inline function definition for the CONFIG_OF=n case.

Noralf.

Quoted 8 lines

Regards,
Meghana

Quoted 6 lines

And this change needs to be a patch on it's own. The backlight subsystem has it's own maintainer that will review this change.
It's best to send him/them the whole patchset so they see the context.

Noralf.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw

Re: [PATCH v6 1/2] drm/tinydrm: Move tinydrm_of_find_backlight into drm_of.c

Quoted 202 lines · Noralf Trønnes

Den 01.10.2017 06.14, skrev Meghana Madhyastha:

Quoted 184 lines · Noralf Trønnes
Quoted 173 lines

Den 30.09.2017 19.12, skrev Meghana Madhyastha:

Quoted 159 lines

Rename tinydrm_of_find_backlight to drm_of_find_backlight and move it into drm_of.c from tinydrm-helpers.c. This is because other drivers in the drm subsystem might need to call this function. In that case and otherwise, it is better from an organizational point of view to move it into drm_of.c along with the other _of.c functions.

---
Changes in v6:

(quoted diff) +0 -1
-Move function declarations to linux/backlight.h to resolve
 module dependency issues.
 
 drivers/gpu/drm/drm_of.c                       | 44 ++++++++++++++++++++++++++
 drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 40 -----------------------
 drivers/gpu/drm/tinydrm/mi0283qt.c             |  2 +-
 include/drm/tinydrm/tinydrm-helpers.h          |  1 -
 include/linux/backlight.h                      | 11 +++++++
 5 files changed, 56 insertions(+), 42 deletions(-)
drivers/gpu/drm/drm_of.c +44 -0
index 8dafbdf..d878d3a 100644
@@ -1,6 +1,7 @@
 #include <linux/component.h>
 #include <linux/export.h>
 #include <linux/list.h>
+#include <linux/backlight.h>
 #include <linux/of_graph.h>
 #include <drm/drmP.h>
 #include <drm/drm_bridge.h>
@@ -260,3 +261,46 @@ int drm_of_find_panel_or_bridge(const struct device_node *np,
 	return ret;
 }
 EXPORT_SYMBOL_GPL(drm_of_find_panel_or_bridge);
+
+/**
+ * drm_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.
+ *
+ * Note: It is the responsibility of the caller to call put_device() when
+ * releasing the resource.
+ *
+ * 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 *drm_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(drm_of_find_backlight);
drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +0 -40
index bd6cce0..cd4c6a5 100644
@@ -237,46 +237,6 @@ void tinydrm_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb,
 EXPORT_SYMBOL(tinydrm_xrgb8888_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);
-
-/**
  * tinydrm_enable_backlight - Enable backlight helper
  * @backlight: Backlight device
  *
drivers/gpu/drm/tinydrm/mi0283qt.c +1 -1
index 7e5bb7d..682b4db 100644
@@ -189,7 +189,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 = drm_of_find_backlight(dev);
 	if (IS_ERR(mipi->backlight))
 		return PTR_ERR(mipi->backlight);
include/drm/tinydrm/tinydrm-helpers.h +0 -1
index d554ded..e40ef2d 100644
@@ -46,7 +46,6 @@ void tinydrm_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
 void tinydrm_xrgb8888_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);
include/linux/backlight.h +2 -0
index 5f2fd61..47a095e 100644
@@ -172,4 +172,15 @@ of_find_backlight_by_node(struct device_node *node)
 }
 #endif
+#if defined(CONFIG_OF) && IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
+struct backlight_device *

include/linux/backlight.h of_find_backlight_by_node(struct device_node *node) · line 185

Quoted 10 lines
include/linux/backlight.h +9 -0
+drm_of_find_backlight(struct device *dev);
+#else
+static inline struct backlight_device *
+drm_of_find_backlight(struct device *dev)
+{
+	return NULL;
+}
+#endif
+
 #endif

This isn't what I meant, you only change the of_find_backlight_by_node() declaration/definition. It should be like this:

Quoted 10 lines

#if defined(CONFIG_OF) && IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE) struct backlight_device *of_find_backlight_by_node(struct device_node *node);
#else
static inline struct backlight_device * of_find_backlight_by_node(struct device_node *node)
{
    return NULL;
}
#endif

Quoted 6 lines

I see. So basically add the function declaration of drm_of_find_backlight and devm_drm_of_find_backlight in drm_of.h and this function declaration need not be inside the #ifdef CONFIG / #else part?
So there need not be a dummy version of drm_of_find_backlight here because we are anyway taking care of that in of_find_backliht by node? Sorry for the many versions and thank you for the clarifications.

You need the dummy part in drm_of.h because you need to handle the CONFIG_OF option here as well.

If drm_of_find_backlight() was only 2-3 lines of code, you could have made a static inline function in drm_of.h outside the #if/#else/#endif, but since it's longer than that it should be in drm_of.c.

CONFIG_OF decides if drm_of.c is built (as part of drm.o) or not:

Quoted 7 lines

drivers/gpu/drm/Makefile:
drm-$(CONFIG_OF) += drm_of.o

This means we need a function prototype declaration for the CONFIG_OF=y case, and an inline function definition for the CONFIG_OF=n case.

Noralf.

I have one more question. In that case, why wouldn't my previous patch work ? (i.e definition and declaration of drm_of_find_backlight in linux/backlight.h with if/else directives)

Regards,
Meghana

Quoted 9 lines
Quoted 8 lines

Regards,
Meghana

Quoted 6 lines

And this change needs to be a patch on it's own. The backlight subsystem has it's own maintainer that will review this change.
It's best to send him/them the whole patchset so they see the context.

Noralf.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw

Re: [PATCH v6 1/2] drm/tinydrm: Move tinydrm_of_find_backlight into drm_of.c

Den 01.10.2017 15.34, skrev Meghana Madhyastha:

Quoted 204 lines · Noralf Trønnes
Quoted 203 lines

Den 01.10.2017 06.14, skrev Meghana Madhyastha:

Quoted 184 lines · Noralf Trønnes
Quoted 173 lines

Den 30.09.2017 19.12, skrev Meghana Madhyastha:

Quoted 159 lines

Rename tinydrm_of_find_backlight to drm_of_find_backlight and move it into drm_of.c from tinydrm-helpers.c. This is because other drivers in the drm subsystem might need to call this function. In that case and otherwise, it is better from an organizational point of view to move it into drm_of.c along with the other _of.c functions.

---
Changes in v6:

(quoted diff) +0 -1
-Move function declarations to linux/backlight.h to resolve
  module dependency issues.
 
  drivers/gpu/drm/drm_of.c                       | 44 ++++++++++++++++++++++++++
  drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 40 -----------------------
  drivers/gpu/drm/tinydrm/mi0283qt.c             |  2 +-
  include/drm/tinydrm/tinydrm-helpers.h          |  1 -
  include/linux/backlight.h                      | 11 +++++++
  5 files changed, 56 insertions(+), 42 deletions(-)
drivers/gpu/drm/drm_of.c +44 -0
index 8dafbdf..d878d3a 100644
@@ -1,6 +1,7 @@
  #include <linux/component.h>
  #include <linux/export.h>
  #include <linux/list.h>
+#include <linux/backlight.h>
  #include <linux/of_graph.h>
  #include <drm/drmP.h>
  #include <drm/drm_bridge.h>
@@ -260,3 +261,46 @@ int drm_of_find_panel_or_bridge(const struct device_node *np,
  	return ret;
  }
  EXPORT_SYMBOL_GPL(drm_of_find_panel_or_bridge);
+
+/**
+ * drm_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.
+ *
+ * Note: It is the responsibility of the caller to call put_device() when
+ * releasing the resource.
+ *
+ * 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 *drm_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(drm_of_find_backlight);
drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +0 -40
index bd6cce0..cd4c6a5 100644
@@ -237,46 +237,6 @@ void tinydrm_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb,
  EXPORT_SYMBOL(tinydrm_xrgb8888_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);
-
-/**
   * tinydrm_enable_backlight - Enable backlight helper
   * @backlight: Backlight device
   *
drivers/gpu/drm/tinydrm/mi0283qt.c +1 -1
index 7e5bb7d..682b4db 100644
@@ -189,7 +189,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 = drm_of_find_backlight(dev);
  	if (IS_ERR(mipi->backlight))
  		return PTR_ERR(mipi->backlight);
include/drm/tinydrm/tinydrm-helpers.h +0 -1
index d554ded..e40ef2d 100644
@@ -46,7 +46,6 @@ void tinydrm_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
  void tinydrm_xrgb8888_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);
include/linux/backlight.h +2 -0
index 5f2fd61..47a095e 100644
@@ -172,4 +172,15 @@ of_find_backlight_by_node(struct device_node *node)
  }
  #endif
+#if defined(CONFIG_OF) && IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
+struct backlight_device *

include/linux/backlight.h of_find_backlight_by_node(struct device_node *node) · line 185

Quoted 10 lines
include/linux/backlight.h +9 -0
+drm_of_find_backlight(struct device *dev);
+#else
+static inline struct backlight_device *
+drm_of_find_backlight(struct device *dev)
+{
+	return NULL;
+}
+#endif
+
  #endif

This isn't what I meant, you only change the of_find_backlight_by_node() declaration/definition. It should be like this:

Quoted 10 lines

#if defined(CONFIG_OF) && IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE) struct backlight_device *of_find_backlight_by_node(struct device_node *node);
#else
static inline struct backlight_device * of_find_backlight_by_node(struct device_node *node)
{
    return NULL;
}
#endif

Quoted 6 lines

I see. So basically add the function declaration of drm_of_find_backlight and devm_drm_of_find_backlight in drm_of.h and this function declaration need not be inside the #ifdef CONFIG / #else part?
So there need not be a dummy version of drm_of_find_backlight here because we are anyway taking care of that in of_find_backliht by node? Sorry for the many versions and thank you for the clarifications.

You need the dummy part in drm_of.h because you need to handle the CONFIG_OF option here as well.

If drm_of_find_backlight() was only 2-3 lines of code, you could have made a static inline function in drm_of.h outside the #if/#else/#endif, but since it's longer than that it should be in drm_of.c.

CONFIG_OF decides if drm_of.c is built (as part of drm.o) or not:

drivers/gpu/drm/Makefile:
drm-$(CONFIG_OF) += drm_of.o

Quoted 7 lines
Quoted 4 lines

This means we need a function prototype declaration for the CONFIG_OF=y case, and an inline function definition for the CONFIG_OF=n case.

Noralf.

I have one more question. In that case, why wouldn't my previous patch work ? (i.e definition and declaration of drm_of_find_backlight in linux/backlight.h with if/else directives)

It will work, the compiler doesn't complain as long as you include backlight.h and make sure drm_of.c is built. But that would result in a complexity that humans would struggle to get right. And in this case it's even 2 different subsystems with different maintainers...

So in order to succeed with complex projects, humans need some more rules than what the compiler requires. And one of those are:
  A header file is usually connected to a source file.

backlight.h contains prototypes and definitions for backlight.c drm_of.h contains prototypes and definitions for drm_of.c

Quoted 11 lines

Regards,
Meghana

Quoted 8 lines
Quoted 8 lines

Regards,
Meghana

Quoted 6 lines

And this change needs to be a patch on it's own. The backlight subsystem has it's own maintainer that will review this change.
It's best to send him/them the whole patchset so they see the context.

Noralf.

#7 lore raw

Re: [PATCH v6 1/2] drm/tinydrm: Move tinydrm_of_find_backlight into drm_of.c

Quoted 219 lines · Noralf Trønnes

Den 01.10.2017 15.34, skrev Meghana Madhyastha:

Quoted 204 lines · Noralf Trønnes
Quoted 203 lines

Den 01.10.2017 06.14, skrev Meghana Madhyastha:

Quoted 184 lines · Noralf Trønnes
Quoted 173 lines

Den 30.09.2017 19.12, skrev Meghana Madhyastha:

Quoted 159 lines

Rename tinydrm_of_find_backlight to drm_of_find_backlight and move it into drm_of.c from tinydrm-helpers.c. This is because other drivers in the drm subsystem might need to call this function. In that case and otherwise, it is better from an organizational point of view to move it into drm_of.c along with the other _of.c functions.

---
Changes in v6:

(quoted diff) +0 -1
-Move function declarations to linux/backlight.h to resolve
 module dependency issues.
 
 drivers/gpu/drm/drm_of.c                       | 44 ++++++++++++++++++++++++++
 drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 40 -----------------------
 drivers/gpu/drm/tinydrm/mi0283qt.c             |  2 +-
 include/drm/tinydrm/tinydrm-helpers.h          |  1 -
 include/linux/backlight.h                      | 11 +++++++
 5 files changed, 56 insertions(+), 42 deletions(-)
drivers/gpu/drm/drm_of.c +44 -0
index 8dafbdf..d878d3a 100644
@@ -1,6 +1,7 @@
 #include <linux/component.h>
 #include <linux/export.h>
 #include <linux/list.h>
+#include <linux/backlight.h>
 #include <linux/of_graph.h>
 #include <drm/drmP.h>
 #include <drm/drm_bridge.h>
@@ -260,3 +261,46 @@ int drm_of_find_panel_or_bridge(const struct device_node *np,
 	return ret;
 }
 EXPORT_SYMBOL_GPL(drm_of_find_panel_or_bridge);
+
+/**
+ * drm_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.
+ *
+ * Note: It is the responsibility of the caller to call put_device() when
+ * releasing the resource.
+ *
+ * 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 *drm_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(drm_of_find_backlight);
drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +0 -40
index bd6cce0..cd4c6a5 100644
@@ -237,46 +237,6 @@ void tinydrm_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb,
 EXPORT_SYMBOL(tinydrm_xrgb8888_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);
-
-/**
  * tinydrm_enable_backlight - Enable backlight helper
  * @backlight: Backlight device
  *
drivers/gpu/drm/tinydrm/mi0283qt.c +1 -1
index 7e5bb7d..682b4db 100644
@@ -189,7 +189,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 = drm_of_find_backlight(dev);
 	if (IS_ERR(mipi->backlight))
 		return PTR_ERR(mipi->backlight);
include/drm/tinydrm/tinydrm-helpers.h +0 -1
index d554ded..e40ef2d 100644
@@ -46,7 +46,6 @@ void tinydrm_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
 void tinydrm_xrgb8888_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);
include/linux/backlight.h +2 -0
index 5f2fd61..47a095e 100644
@@ -172,4 +172,15 @@ of_find_backlight_by_node(struct device_node *node)
 }
 #endif
+#if defined(CONFIG_OF) && IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
+struct backlight_device *

include/linux/backlight.h of_find_backlight_by_node(struct device_node *node) · line 185

Quoted 10 lines
include/linux/backlight.h +9 -0
+drm_of_find_backlight(struct device *dev);
+#else
+static inline struct backlight_device *
+drm_of_find_backlight(struct device *dev)
+{
+	return NULL;
+}
+#endif
+
 #endif

This isn't what I meant, you only change the of_find_backlight_by_node() declaration/definition. It should be like this:

Quoted 10 lines

#if defined(CONFIG_OF) && IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE) struct backlight_device *of_find_backlight_by_node(struct device_node *node);
#else
static inline struct backlight_device * of_find_backlight_by_node(struct device_node *node)
{
    return NULL;
}
#endif

Quoted 6 lines

I see. So basically add the function declaration of drm_of_find_backlight and devm_drm_of_find_backlight in drm_of.h and this function declaration need not be inside the #ifdef CONFIG / #else part?
So there need not be a dummy version of drm_of_find_backlight here because we are anyway taking care of that in of_find_backliht by node? Sorry for the many versions and thank you for the clarifications.

You need the dummy part in drm_of.h because you need to handle the CONFIG_OF option here as well.

If drm_of_find_backlight() was only 2-3 lines of code, you could have made a static inline function in drm_of.h outside the #if/#else/#endif, but since it's longer than that it should be in drm_of.c.

CONFIG_OF decides if drm_of.c is built (as part of drm.o) or not:

drivers/gpu/drm/Makefile:
drm-$(CONFIG_OF) += drm_of.o

Quoted 7 lines
Quoted 4 lines

This means we need a function prototype declaration for the CONFIG_OF=y case, and an inline function definition for the CONFIG_OF=n case.

Noralf.

I have one more question. In that case, why wouldn't my previous patch work ? (i.e definition and declaration of drm_of_find_backlight in linux/backlight.h with if/else directives)

It will work, the compiler doesn't complain as long as you include backlight.h and make sure drm_of.c is built. But that would result in a complexity that humans would struggle to get right. And in this case it's even 2 different subsystems with different maintainers...

Quoted 6 lines

So in order to succeed with complex projects, humans need some more rules than what the compiler requires. And one of those are:
  A header file is usually connected to a source file.

backlight.h contains prototypes and definitions for backlight.c drm_of.h contains prototypes and definitions for drm_of.c

Okay that makes sense. Initially, I thought that we could add the declarations/definitions along with of_find_backlight_by_node in linux/backlight.h as I hadn't realized that each .c file should strictly have a one to one correspondence with the .h file of the same name but as you mentioned, it is necessary in a large/complex project like this.

Thank you for the clarifications !

Regards,
Meghana

Quoted 4 lines
Quoted 4 lines

Regards,
Meghana

Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Regards,
Meghana

Quoted 6 lines

And this change needs to be a patch on it's own. The backlight subsystem has it's own maintainer that will review this change.
It's best to send him/them the whole patchset so they see the context.

Noralf.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#8 lore raw

Re: [PATCH v6 1/2] drm/tinydrm: Move tinydrm_of_find_backlight into drm_of.c

In reply to Meghana Madhyastha
reproduce: wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross…

Hi Meghana,

[auto build test ERROR on drm/drm-next]
[also build test ERROR on v4.14-rc3 next-20170929]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Meghana-Madhyastha/drm-tinydrm-drm_of_find_backlight-helper/20171003-011920
base:   git://people.freedesktop.org/~airlied/linux.git drm-next
config: arm-sunxi_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 6.1.1-9) 6.1.1 20160705

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm

All errors (new ones prefixed by >>):

>> drivers/gpu/drm/drm_of.c:283:26: error: redefinition of 'drm_of_find_backlight'

struct backlight_device *drm_of_find_backlight(struct device *dev)
^~~~~~~~~~~~~~~~~~~~~
In file included from drivers/gpu/drm/drm_of.c:4:0:
include/linux/backlight.h:180:1: note: previous definition of 'drm_of_find_backlight' was here
drm_of_find_backlight(struct device *dev)
^~~~~~~~~~~~~~~~~~~~~

vim +/drm_of_find_backlight +283 drivers/gpu/drm/drm_of.c

264
265 /**
266 * drm_of_find_backlight - Find backlight device in device-tree
267 * @dev: Device
268 *
269 * This function looks for a DT node pointed to by a property named 'backlight'
270 * and uses of_find_backlight_by_node() to get the backlight device.
271 * Additionally if the brightness property is zero, it is set to
272 * max_brightness.
273 *
274 * Note: It is the responsibility of the caller to call put_device() when
275 * releasing the resource.
276 *
277 * Returns:
278 * NULL if there's no backlight property.
279 * Error pointer -EPROBE_DEFER if the DT node is found, but no backlight device
280 * is found.
281 * If the backlight device is found, a pointer to the structure is returned.
282 */

 > 283	struct backlight_device *drm_of_find_backlight(struct device *dev)

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#9 lore raw

PATCH v6 2/2 drm/tinydrm: Add devres versions of drm_of_find_backlight

In reply to Meghana Madhyastha

Add devm_drm_of_find_backlight and the corresponding release function because some drivers such as tinydrm use devres versions of functions for requiring device resources.

---
Changes in v6:
- Remove docstring for devm_drm_of_backlight_release because it is and internal function.

 drivers/gpu/drm/drm_of.c           | 40 ++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/tinydrm/mi0283qt.c |  2 +-
 include/linux/backlight.h          |  7 +++++++
 3 files changed, 48 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_of.c +40 -0
index d878d3a..6fb3fe5 100644
@@ -304,3 +304,43 @@ struct backlight_device *drm_of_find_backlight(struct device *dev)
 	return backlight;
 }
 EXPORT_SYMBOL(drm_of_find_backlight);
+
+static void devm_drm_of_find_backlight_release(void *data)
+{
+	put_device(data);
+}
+
+/**
+ * devm_drm_of_find_backlight - Find backlight device in device-tree
+ * devres version of the function
+ * @dev: Device
+ *
+ * This is the devres version of the function drm_of_find_backlight.
+ * Some drivers use devres versions of functions for
+ * requiring device resources.
+ *
+ * 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 *devm_drm_of_find_backlight(struct device *dev)
+{
+	struct backlight_device *backlight;
+	int ret;
+
+	backlight = drm_of_find_backlight(dev);
+	if (IS_ERR_OR_NULL(backlight))
+		return backlight;
+
+	ret = devm_add_action(dev, devm_drm_of_find_backlight_release,
+			      &backlight->dev);
+	if (ret) {
+		put_device(&backlight->dev);
+		return ERR_PTR(ret);
+	}
+
+	return backlight;
+}
+EXPORT_SYMBOL(devm_drm_of_find_backlight);
drivers/gpu/drm/tinydrm/mi0283qt.c +1 -1
index 682b4db..6724e5e 100644
@@ -189,7 +189,7 @@ static int mi0283qt_probe(struct spi_device *spi)
 	if (IS_ERR(mipi->regulator))
 		return PTR_ERR(mipi->regulator);
 
-	mipi->backlight = drm_of_find_backlight(dev);
+	mipi->backlight = devm_drm_of_find_backlight(dev);
 	if (IS_ERR(mipi->backlight))
 		return PTR_ERR(mipi->backlight);
 
include/linux/backlight.h +7 -0
index 47a095e..f601f15 100644
@@ -175,12 +175,19 @@ of_find_backlight_by_node(struct device_node *node)
 #if defined(CONFIG_OF) && IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
 struct backlight_device *
 drm_of_find_backlight(struct device *dev);
+devm_drm_of_find_backlight(struct device *dev);
 #else
 static inline struct backlight_device *
 drm_of_find_backlight(struct device *dev)
 {
 	return NULL;
 }
+
+static inline struct backlight_device *
+devm_drm_of_find_backlight(struct device *dev)
+{
+	return NULL;
+}
 #endif
 
 #endif
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#10 lore raw

Re: [PATCH v6 2/2] drm/tinydrm: Add devres versions of drm_of_find_backlight

reproduce: wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross…

Hi Meghana,

[auto build test ERROR on drm/drm-next]
[also build test ERROR on v4.14-rc3 next-20170929]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Meghana-Madhyastha/drm-tinydrm-drm_of_find_backlight-helper/20171003-011920
base:   git://people.freedesktop.org/~airlied/linux.git drm-next
config: arm-sunxi_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 6.1.1-9) 6.1.1 20160705

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm

All errors (new ones prefixed by >>):

drivers/gpu/drm/drm_of.c:283:26: error: redefinition of 'drm_of_find_backlight'
struct backlight_device *drm_of_find_backlight(struct device *dev)
^~~~~~~~~~~~~~~~~~~~~
In file included from drivers/gpu/drm/drm_of.c:4:0:
include/linux/backlight.h:181:1: note: previous definition of 'drm_of_find_backlight' was here
drm_of_find_backlight(struct device *dev)
^~~~~~~~~~~~~~~~~~~~~

>> drivers/gpu/drm/drm_of.c:328:26: error: redefinition of 'devm_drm_of_find_backlight'

struct backlight_device *devm_drm_of_find_backlight(struct device *dev)
^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from drivers/gpu/drm/drm_of.c:4:0:
include/linux/backlight.h:187:1: note: previous definition of 'devm_drm_of_find_backlight' was here
devm_drm_of_find_backlight(struct device *dev)
^~~~~~~~~~~~~~~~~~~~~~~~~~

vim +/devm_drm_of_find_backlight +328 drivers/gpu/drm/drm_of.c

264
265 /**
266 * drm_of_find_backlight - Find backlight device in device-tree
267 * @dev: Device
268 *
269 * This function looks for a DT node pointed to by a property named 'backlight'
270 * and uses of_find_backlight_by_node() to get the backlight device.
271 * Additionally if the brightness property is zero, it is set to
272 * max_brightness.
273 *
274 * Note: It is the responsibility of the caller to call put_device() when
275 * releasing the resource.
276 *
277 * Returns:
278 * NULL if there's no backlight property.
279 * Error pointer -EPROBE_DEFER if the DT node is found, but no backlight device
280 * is found.
281 * If the backlight device is found, a pointer to the structure is returned.
282 */

 > 283	struct backlight_device *drm_of_find_backlight(struct device *dev)
   284	{
   285		struct backlight_device *backlight;
   286		struct device_node *np;
   287	
   288		np = of_parse_phandle(dev->of_node, "backlight", 0);
   289		if (!np)
   290			return NULL;
   291	
   292		backlight = of_find_backlight_by_node(np);
   293		of_node_put(np);
   294	
   295		if (!backlight)
   296			return ERR_PTR(-EPROBE_DEFER);
   297	
   298		if (!backlight->props.brightness) {
   299			backlight->props.brightness = backlight->props.max_brightness;
   300			DRM_DEBUG_KMS("Backlight brightness set to %d\n",
   301				      backlight->props.brightness);
   302		}
   303	
   304		return backlight;
   305	}
   306	EXPORT_SYMBOL(drm_of_find_backlight);
   307	
   308	static void devm_drm_of_find_backlight_release(void *data)
   309	{
   310		put_device(data);
   311	}
   312	
   313	/**
   314	 * devm_drm_of_find_backlight - Find backlight device in device-tree
   315	 * devres version of the function
   316	 * @dev: Device
   317	 *
   318	 * This is the devres version of the function drm_of_find_backlight.
   319	 * Some drivers use devres versions of functions for
   320	 * requiring device resources.
   321	 *
   322	 * Returns:
   323	 * NULL if there's no backlight property.
   324	 * Error pointer -EPROBE_DEFER if the DT node is found, but no backlight device
   325	 * is found.
   326	 * If the backlight device is found, a pointer to the structure is returned.
   327	 */
 > 328	struct backlight_device *devm_drm_of_find_backlight(struct device *dev)

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation