Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/dsi: Get DSI host by DT device node

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 DSI hosts that are currently registered. This
list will be used to find the struct mipi_dsi_host corresponding to the
device tree node passed to of_find_mipi_dsi_host_by_node().

Reviewed-by: Andrzej Hajda <a.hajda@samsung.com>
Signed-off-by: Archit Taneja <architt@codeaurora.org>
Signed-off-by: Thierry Reding <treding@nvidia.com>

authored by

Archit Taneja and committed by
Thierry Reding
97b6ae50 509e42ce

+42
+39
drivers/gpu/drm/drm_mipi_dsi.c
··· 235 235 } 236 236 EXPORT_SYMBOL(mipi_dsi_device_unregister); 237 237 238 + static DEFINE_MUTEX(host_lock); 239 + static LIST_HEAD(host_list); 240 + 241 + /** 242 + * of_find_mipi_dsi_host_by_node() - find the MIPI DSI host matching a 243 + * device tree node 244 + * @node: device tree node 245 + * 246 + * Returns: 247 + * A pointer to the MIPI DSI host corresponding to @node or NULL if no 248 + * such device exists (or has not been registered yet). 249 + */ 250 + struct mipi_dsi_host *of_find_mipi_dsi_host_by_node(struct device_node *node) 251 + { 252 + struct mipi_dsi_host *host; 253 + 254 + mutex_lock(&host_lock); 255 + 256 + list_for_each_entry(host, &host_list, list) { 257 + if (host->dev->of_node == node) { 258 + mutex_unlock(&host_lock); 259 + return host; 260 + } 261 + } 262 + 263 + mutex_unlock(&host_lock); 264 + 265 + return NULL; 266 + } 267 + EXPORT_SYMBOL(of_find_mipi_dsi_host_by_node); 268 + 238 269 int mipi_dsi_host_register(struct mipi_dsi_host *host) 239 270 { 240 271 struct device_node *node; ··· 276 245 continue; 277 246 of_mipi_dsi_device_add(host, node); 278 247 } 248 + 249 + mutex_lock(&host_lock); 250 + list_add_tail(&host->list, &host_list); 251 + mutex_unlock(&host_lock); 279 252 280 253 return 0; 281 254 } ··· 297 262 void mipi_dsi_host_unregister(struct mipi_dsi_host *host) 298 263 { 299 264 device_for_each_child(host->dev, NULL, mipi_dsi_remove_device_fn); 265 + 266 + mutex_lock(&host_lock); 267 + list_del_init(&host->list); 268 + mutex_unlock(&host_lock); 300 269 } 301 270 EXPORT_SYMBOL(mipi_dsi_host_unregister); 302 271
+3
include/drm/drm_mipi_dsi.h
··· 96 96 * struct mipi_dsi_host - DSI host device 97 97 * @dev: driver model device node for this DSI host 98 98 * @ops: DSI host operations 99 + * @list: list management 99 100 */ 100 101 struct mipi_dsi_host { 101 102 struct device *dev; 102 103 const struct mipi_dsi_host_ops *ops; 104 + struct list_head list; 103 105 }; 104 106 105 107 int mipi_dsi_host_register(struct mipi_dsi_host *host); 106 108 void mipi_dsi_host_unregister(struct mipi_dsi_host *host); 109 + struct mipi_dsi_host *of_find_mipi_dsi_host_by_node(struct device_node *node); 107 110 108 111 /* DSI mode flags */ 109 112