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