drm_panel.c revision 1.2 1 /* $NetBSD: drm_panel.c,v 1.2 2018/08/27 04:58:19 riastradh Exp $ */
2
3 /*
4 * Copyright (C) 2013, NVIDIA Corporation. All rights reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sub license,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25
26 #include <sys/cdefs.h>
27 __KERNEL_RCSID(0, "$NetBSD: drm_panel.c,v 1.2 2018/08/27 04:58:19 riastradh Exp $");
28
29 #include <linux/err.h>
30 #include <linux/module.h>
31
32 #include <drm/drm_crtc.h>
33 #include <drm/drm_panel.h>
34
35 static DEFINE_MUTEX(panel_lock);
36 static LIST_HEAD(panel_list);
37
38 void drm_panel_init(struct drm_panel *panel)
39 {
40 INIT_LIST_HEAD(&panel->list);
41 }
42 EXPORT_SYMBOL(drm_panel_init);
43
44 int drm_panel_add(struct drm_panel *panel)
45 {
46 mutex_lock(&panel_lock);
47 list_add_tail(&panel->list, &panel_list);
48 mutex_unlock(&panel_lock);
49
50 return 0;
51 }
52 EXPORT_SYMBOL(drm_panel_add);
53
54 void drm_panel_remove(struct drm_panel *panel)
55 {
56 mutex_lock(&panel_lock);
57 list_del_init(&panel->list);
58 mutex_unlock(&panel_lock);
59 }
60 EXPORT_SYMBOL(drm_panel_remove);
61
62 int drm_panel_attach(struct drm_panel *panel, struct drm_connector *connector)
63 {
64 if (panel->connector)
65 return -EBUSY;
66
67 panel->connector = connector;
68 panel->drm = connector->dev;
69
70 return 0;
71 }
72 EXPORT_SYMBOL(drm_panel_attach);
73
74 int drm_panel_detach(struct drm_panel *panel)
75 {
76 panel->connector = NULL;
77 panel->drm = NULL;
78
79 return 0;
80 }
81 EXPORT_SYMBOL(drm_panel_detach);
82
83 #ifdef CONFIG_OF
84 struct drm_panel *of_drm_find_panel(struct device_node *np)
85 {
86 struct drm_panel *panel;
87
88 mutex_lock(&panel_lock);
89
90 list_for_each_entry(panel, &panel_list, list) {
91 if (panel->dev->of_node == np) {
92 mutex_unlock(&panel_lock);
93 return panel;
94 }
95 }
96
97 mutex_unlock(&panel_lock);
98 return NULL;
99 }
100 EXPORT_SYMBOL(of_drm_find_panel);
101 #endif
102
103 MODULE_AUTHOR("Thierry Reding <treding (at) nvidia.com>");
104 MODULE_DESCRIPTION("DRM panel infrastructure");
105 MODULE_LICENSE("GPL and additional rights");
106