xref: /linux/drivers/gpu/drm/drm_bridge.c (revision e0bf6c5ca2d3281f231c5f0c9bf145e9513644de)
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sub license,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the
12  * next paragraph) shall be included in all copies or substantial portions
13  * of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #include <linux/err.h>
25 #include <linux/module.h>
26 
27 #include <drm/drm_crtc.h>
28 
29 #include "drm/drmP.h"
30 
31 static DEFINE_MUTEX(bridge_lock);
32 static LIST_HEAD(bridge_list);
33 
34 int drm_bridge_add(struct drm_bridge *bridge)
35 {
36 	mutex_lock(&bridge_lock);
37 	list_add_tail(&bridge->list, &bridge_list);
38 	mutex_unlock(&bridge_lock);
39 
40 	return 0;
41 }
42 EXPORT_SYMBOL(drm_bridge_add);
43 
44 void drm_bridge_remove(struct drm_bridge *bridge)
45 {
46 	mutex_lock(&bridge_lock);
47 	list_del_init(&bridge->list);
48 	mutex_unlock(&bridge_lock);
49 }
50 EXPORT_SYMBOL(drm_bridge_remove);
51 
52 extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge)
53 {
54 	if (!dev || !bridge)
55 		return -EINVAL;
56 
57 	if (bridge->dev)
58 		return -EBUSY;
59 
60 	bridge->dev = dev;
61 
62 	if (bridge->funcs->attach)
63 		return bridge->funcs->attach(bridge);
64 
65 	return 0;
66 }
67 EXPORT_SYMBOL(drm_bridge_attach);
68 
69 #ifdef CONFIG_OF
70 struct drm_bridge *of_drm_find_bridge(struct device_node *np)
71 {
72 	struct drm_bridge *bridge;
73 
74 	mutex_lock(&bridge_lock);
75 
76 	list_for_each_entry(bridge, &bridge_list, list) {
77 		if (bridge->of_node == np) {
78 			mutex_unlock(&bridge_lock);
79 			return bridge;
80 		}
81 	}
82 
83 	mutex_unlock(&bridge_lock);
84 	return NULL;
85 }
86 EXPORT_SYMBOL(of_drm_find_bridge);
87 #endif
88 
89 MODULE_AUTHOR("Ajay Kumar <ajaykumar.rs@samsung.com>");
90 MODULE_DESCRIPTION("DRM bridge infrastructure");
91 MODULE_LICENSE("GPL and additional rights");
92