[PATCH v6 2/2] drm/tinydrm: Add devres versions of drm_of_find_backlight
Meghana Madhyastha
meghana.madhyastha at gmail.com
Sat Sep 30 17:14:18 UTC 2017
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.
Signed-off-by: Meghana Madhyastha <meghana.madhyastha at gmail.com>
---
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(-)
diff --git a/drivers/gpu/drm/drm_of.c b/drivers/gpu/drm/drm_of.c
index d878d3a..6fb3fe5 100644
--- a/drivers/gpu/drm/drm_of.c
+++ b/drivers/gpu/drm/drm_of.c
@@ -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);
diff --git a/drivers/gpu/drm/tinydrm/mi0283qt.c b/drivers/gpu/drm/tinydrm/mi0283qt.c
index 682b4db..6724e5e 100644
--- a/drivers/gpu/drm/tinydrm/mi0283qt.c
+++ b/drivers/gpu/drm/tinydrm/mi0283qt.c
@@ -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);
diff --git a/include/linux/backlight.h b/include/linux/backlight.h
index 47a095e..f601f15 100644
--- a/include/linux/backlight.h
+++ b/include/linux/backlight.h
@@ -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
--
2.7.4
More information about the dri-devel
mailing list