diff mbox

[v4,6/6] drm/dsi: Get DSI host by DT device node

Message ID 1449751300-2841-7-git-send-email-architt@codeaurora.org (mailing list archive)
State New, archived
Headers show

Commit Message

Archit Taneja Dec. 10, 2015, 12:41 p.m. UTC
mipi_dsi_devices are inherently aware of their host because they
share a parent-child hierarchy in the device tree.

non-dsi drivers that create dsi device don't have this data. In order to
get this information, they require to a phandle to the dsi host in the
device tree.

Maintain a list of all the hosts DSI that are currently registered.

This list will be used to find the mipi_dsi_host corresponding to the
device_node passed in of_find_mipi_dsi_host_by_node.

Reviewed-by: Andrzej Hajda <a.hajda@samsung.com>
Signed-off-by: Archit Taneja <architt@codeaurora.org>
---
 drivers/gpu/drm/drm_mipi_dsi.c | 38 ++++++++++++++++++++++++++++++++++++++
 include/drm/drm_mipi_dsi.h     |  3 +++
 2 files changed, 41 insertions(+)

Comments

Thierry Reding Jan. 21, 2016, 4:16 p.m. UTC | #1
On Thu, Dec 10, 2015 at 06:11:40PM +0530, Archit Taneja wrote:
> mipi_dsi_devices are inherently aware of their host because they
> share a parent-child hierarchy in the device tree.
> 
> non-dsi drivers that create dsi device don't have this data. In order to
> get this information, they require to a phandle to the dsi host in the
> device tree.
> 
> Maintain a list of all the hosts DSI that are currently registered.
> 
> This list will be used to find the mipi_dsi_host corresponding to the
> device_node passed in of_find_mipi_dsi_host_by_node.
> 
> Reviewed-by: Andrzej Hajda <a.hajda@samsung.com>
> Signed-off-by: Archit Taneja <architt@codeaurora.org>
> ---
>  drivers/gpu/drm/drm_mipi_dsi.c | 38 ++++++++++++++++++++++++++++++++++++++
>  include/drm/drm_mipi_dsi.h     |  3 +++
>  2 files changed, 41 insertions(+)

Please be more consistent with the spelling. Abbreviations should be all
capitals. Also s/mipi_dsi_devices/MIPI DSI devices/, and so on.

Otherwise I guess this makes sense.

Thierry
Archit Taneja Jan. 27, 2016, 5:21 a.m. UTC | #2
On 01/21/2016 09:46 PM, Thierry Reding wrote:
> On Thu, Dec 10, 2015 at 06:11:40PM +0530, Archit Taneja wrote:
>> mipi_dsi_devices are inherently aware of their host because they
>> share a parent-child hierarchy in the device tree.
>>
>> non-dsi drivers that create dsi device don't have this data. In order to
>> get this information, they require to a phandle to the dsi host in the
>> device tree.
>>
>> Maintain a list of all the hosts DSI that are currently registered.
>>
>> This list will be used to find the mipi_dsi_host corresponding to the
>> device_node passed in of_find_mipi_dsi_host_by_node.
>>
>> Reviewed-by: Andrzej Hajda <a.hajda@samsung.com>
>> Signed-off-by: Archit Taneja <architt@codeaurora.org>
>> ---
>>   drivers/gpu/drm/drm_mipi_dsi.c | 38 ++++++++++++++++++++++++++++++++++++++
>>   include/drm/drm_mipi_dsi.h     |  3 +++
>>   2 files changed, 41 insertions(+)
>
> Please be more consistent with the spelling. Abbreviations should be all
> capitals. Also s/mipi_dsi_devices/MIPI DSI devices/, and so on.

I'll ensure the abbreviations are consistent in the next revision.

>
> Otherwise I guess this makes sense.

Thanks for the review.

Thanks,
Archit
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
index 7a81171..e40a665 100644
--- a/drivers/gpu/drm/drm_mipi_dsi.c
+++ b/drivers/gpu/drm/drm_mipi_dsi.c
@@ -213,6 +213,36 @@  of_mipi_dsi_device_add(struct mipi_dsi_host *host, struct device_node *node)
 }
 #endif
 
+static DEFINE_MUTEX(host_lock);
+static LIST_HEAD(host_list);
+
+/**
+ * of_find_mipi_dsi_host_by_node() - find the MIPI DSI host matching a
+ *    device tree node
+ * @node: device tree node
+ *
+ * Return: A pointer to the MIPI DSI host corresponding to @np or NULL if no
+ *    such device exists (or has not been registered yet).
+ */
+struct mipi_dsi_host *of_find_mipi_dsi_host_by_node(struct device_node *node)
+{
+	struct mipi_dsi_host *host;
+
+	mutex_lock(&host_lock);
+
+	list_for_each_entry(host, &host_list, list) {
+		if (host->dev->of_node == node) {
+			mutex_unlock(&host_lock);
+			return host;
+		}
+	}
+
+	mutex_unlock(&host_lock);
+
+	return NULL;
+}
+EXPORT_SYMBOL(of_find_mipi_dsi_host_by_node);
+
 int mipi_dsi_host_register(struct mipi_dsi_host *host)
 {
 	struct device_node *node;
@@ -224,6 +254,10 @@  int mipi_dsi_host_register(struct mipi_dsi_host *host)
 		of_mipi_dsi_device_add(host, node);
 	}
 
+	mutex_lock(&host_lock);
+	list_add_tail(&host->list, &host_list);
+	mutex_unlock(&host_lock);
+
 	return 0;
 }
 EXPORT_SYMBOL(mipi_dsi_host_register);
@@ -240,6 +274,10 @@  static int mipi_dsi_remove_device_fn(struct device *dev, void *priv)
 void mipi_dsi_host_unregister(struct mipi_dsi_host *host)
 {
 	device_for_each_child(host->dev, NULL, mipi_dsi_remove_device_fn);
+
+	mutex_lock(&host_lock);
+	list_del_init(&host->list);
+	mutex_unlock(&host_lock);
 }
 EXPORT_SYMBOL(mipi_dsi_host_unregister);
 
diff --git a/include/drm/drm_mipi_dsi.h b/include/drm/drm_mipi_dsi.h
index 410d8b5..e5c1df9 100644
--- a/include/drm/drm_mipi_dsi.h
+++ b/include/drm/drm_mipi_dsi.h
@@ -96,14 +96,17 @@  struct mipi_dsi_host_ops {
  * struct mipi_dsi_host - DSI host device
  * @dev: driver model device node for this DSI host
  * @ops: DSI host operations
+ * @list: list management
  */
 struct mipi_dsi_host {
 	struct device *dev;
 	const struct mipi_dsi_host_ops *ops;
+	struct list_head list;
 };
 
 int mipi_dsi_host_register(struct mipi_dsi_host *host);
 void mipi_dsi_host_unregister(struct mipi_dsi_host *host);
+struct mipi_dsi_host *of_find_mipi_dsi_host_by_node(struct device_node *node);
 
 /* DSI mode flags */