drm_panel.c revision 1.3 1 /* $NetBSD: drm_panel.c,v 1.3 2019/12/09 15:36:16 jakllsch 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.3 2019/12/09 15:36:16 jakllsch 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 #ifdef __NetBSD__
36 static struct mutex panel_lock;
37 static struct list_head panel_list = LIST_HEAD_INIT(panel_list);
38 #else
39 static DEFINE_MUTEX(panel_lock);
40 static LIST_HEAD(panel_list);
41 #endif
42
43 void drm_panel_init(struct drm_panel *panel)
44 {
45 INIT_LIST_HEAD(&panel->list);
46 }
47 EXPORT_SYMBOL(drm_panel_init);
48
49 int drm_panel_add(struct drm_panel *panel)
50 {
51 mutex_lock(&panel_lock);
52 list_add_tail(&panel->list, &panel_list);
53 mutex_unlock(&panel_lock);
54
55 return 0;
56 }
57 EXPORT_SYMBOL(drm_panel_add);
58
59 void drm_panel_remove(struct drm_panel *panel)
60 {
61 mutex_lock(&panel_lock);
62 list_del_init(&panel->list);
63 mutex_unlock(&panel_lock);
64 }
65 EXPORT_SYMBOL(drm_panel_remove);
66
67 int drm_panel_attach(struct drm_panel *panel, struct drm_connector *connector)
68 {
69 if (panel->connector)
70 return -EBUSY;
71
72 panel->connector = connector;
73 panel->drm = connector->dev;
74
75 return 0;
76 }
77 EXPORT_SYMBOL(drm_panel_attach);
78
79 int drm_panel_detach(struct drm_panel *panel)
80 {
81 panel->connector = NULL;
82 panel->drm = NULL;
83
84 return 0;
85 }
86 EXPORT_SYMBOL(drm_panel_detach);
87
88 #ifdef CONFIG_OF
89 struct drm_panel *of_drm_find_panel(struct device_node *np)
90 {
91 struct drm_panel *panel;
92
93 mutex_lock(&panel_lock);
94
95 list_for_each_entry(panel, &panel_list, list) {
96 if (panel->dev->of_node == np) {
97 mutex_unlock(&panel_lock);
98 return panel;
99 }
100 }
101
102 mutex_unlock(&panel_lock);
103 return NULL;
104 }
105 EXPORT_SYMBOL(of_drm_find_panel);
106 #endif
107
108 MODULE_AUTHOR("Thierry Reding <treding (at) nvidia.com>");
109 MODULE_DESCRIPTION("DRM panel infrastructure");
110 MODULE_LICENSE("GPL and additional rights");
111