drm/dsi: Resolve MIPI DSI device from phandle
authorThierry Reding <treding@nvidia.com>
Wed, 6 Aug 2014 06:53:39 +0000 (08:53 +0200)
committerThierry Reding <treding@nvidia.com>
Thu, 13 Nov 2014 12:56:14 +0000 (13:56 +0100)
Add a function, of_find_mipi_dsi_device_by_node(), that can be used to
resolve a phandle to a MIPI DSI device.

Acked-by: Andrzej Hajda <a.hajda@samsung.com>
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Signed-off-by: Thierry Reding <treding@nvidia.com>
drivers/gpu/drm/drm_mipi_dsi.c
include/drm/drm_mipi_dsi.h

index 2f39372e58b61cb737e87ac0cc32f9adf986a8e9..3850b352960174b257c0aa7304d74464d638feba 100644 (file)
@@ -67,6 +67,29 @@ static struct bus_type mipi_dsi_bus_type = {
        .pm = &mipi_dsi_device_pm_ops,
 };
 
+static int of_device_match(struct device *dev, void *data)
+{
+       return dev->of_node == data;
+}
+
+/**
+ * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a
+ *    device tree node
+ * @np: device tree node
+ *
+ * Return: A pointer to the MIPI DSI device corresponding to @np or NULL if no
+ *    such device exists (or has not been registered yet).
+ */
+struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np)
+{
+       struct device *dev;
+
+       dev = bus_find_device(&mipi_dsi_bus_type, NULL, np, of_device_match);
+
+       return dev ? to_mipi_dsi_device(dev) : NULL;
+}
+EXPORT_SYMBOL(of_find_mipi_dsi_device_by_node);
+
 static void mipi_dsi_dev_release(struct device *dev)
 {
        struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
index 061a792daf7d1ddee5266577dadc2668badea6a7..ea0d982058c3ea4fc313e0724c825e32aa8a0466 100644 (file)
@@ -163,6 +163,7 @@ static inline struct mipi_dsi_device *to_mipi_dsi_device(struct device *dev)
        return container_of(dev, struct mipi_dsi_device, dev);
 }
 
+struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np);
 int mipi_dsi_attach(struct mipi_dsi_device *dsi);
 int mipi_dsi_detach(struct mipi_dsi_device *dsi);
 int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,