]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/gpu/drm/omapdrm/dss/display.c
drm/omap: dss: Functions to check components in the display/output list
[mirror_ubuntu-bionic-kernel.git] / drivers / gpu / drm / omapdrm / dss / display.c
1 /*
2 * linux/drivers/video/omap2/dss/display.c
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * Some code and ideas taken from drivers/video/omap/ driver
8 * by Imre Deak.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #define DSS_SUBSYS_NAME "DISPLAY"
24
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/jiffies.h>
28 #include <linux/platform_device.h>
29 #include <linux/of.h>
30
31 #include "omapdss.h"
32
33 void omapdss_default_get_resolution(struct omap_dss_device *dssdev,
34 u16 *xres, u16 *yres)
35 {
36 *xres = dssdev->panel.vm.hactive;
37 *yres = dssdev->panel.vm.vactive;
38 }
39 EXPORT_SYMBOL(omapdss_default_get_resolution);
40
41 int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev)
42 {
43 switch (dssdev->type) {
44 case OMAP_DISPLAY_TYPE_DPI:
45 if (dssdev->phy.dpi.data_lines == 24)
46 return 24;
47 else
48 return 16;
49
50 case OMAP_DISPLAY_TYPE_DBI:
51 if (dssdev->ctrl.pixel_size == 24)
52 return 24;
53 else
54 return 16;
55 case OMAP_DISPLAY_TYPE_DSI:
56 if (dssdev->panel.dsi_pix_fmt == OMAP_DSS_DSI_FMT_RGB565)
57 return 16;
58 else
59 return 24;
60 case OMAP_DISPLAY_TYPE_VENC:
61 case OMAP_DISPLAY_TYPE_SDI:
62 case OMAP_DISPLAY_TYPE_HDMI:
63 case OMAP_DISPLAY_TYPE_DVI:
64 return 24;
65 default:
66 BUG();
67 return 0;
68 }
69 }
70 EXPORT_SYMBOL(omapdss_default_get_recommended_bpp);
71
72 void omapdss_default_get_timings(struct omap_dss_device *dssdev,
73 struct videomode *vm)
74 {
75 *vm = dssdev->panel.vm;
76 }
77 EXPORT_SYMBOL(omapdss_default_get_timings);
78
79 static LIST_HEAD(panel_list);
80 static DEFINE_MUTEX(panel_list_mutex);
81 static int disp_num_counter;
82
83 int omapdss_register_display(struct omap_dss_device *dssdev)
84 {
85 struct omap_dss_driver *drv = dssdev->driver;
86 int id;
87
88 /*
89 * Note: this presumes all the displays are either using DT or non-DT,
90 * which normally should be the case. This also presumes that all
91 * displays either have an DT alias, or none has.
92 */
93
94 if (dssdev->dev->of_node) {
95 id = of_alias_get_id(dssdev->dev->of_node, "display");
96
97 if (id < 0)
98 id = disp_num_counter++;
99 } else {
100 id = disp_num_counter++;
101 }
102
103 snprintf(dssdev->alias, sizeof(dssdev->alias), "display%d", id);
104
105 /* Use 'label' property for name, if it exists */
106 if (dssdev->dev->of_node)
107 of_property_read_string(dssdev->dev->of_node, "label",
108 &dssdev->name);
109
110 if (dssdev->name == NULL)
111 dssdev->name = dssdev->alias;
112
113 if (drv && drv->get_resolution == NULL)
114 drv->get_resolution = omapdss_default_get_resolution;
115 if (drv && drv->get_recommended_bpp == NULL)
116 drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
117 if (drv && drv->get_timings == NULL)
118 drv->get_timings = omapdss_default_get_timings;
119
120 mutex_lock(&panel_list_mutex);
121 list_add_tail(&dssdev->panel_list, &panel_list);
122 mutex_unlock(&panel_list_mutex);
123 return 0;
124 }
125 EXPORT_SYMBOL(omapdss_register_display);
126
127 void omapdss_unregister_display(struct omap_dss_device *dssdev)
128 {
129 mutex_lock(&panel_list_mutex);
130 list_del(&dssdev->panel_list);
131 mutex_unlock(&panel_list_mutex);
132 }
133 EXPORT_SYMBOL(omapdss_unregister_display);
134
135 bool omapdss_component_is_display(struct device_node *node)
136 {
137 struct omap_dss_device *dssdev;
138 bool found = false;
139
140 mutex_lock(&panel_list_mutex);
141 list_for_each_entry(dssdev, &panel_list, panel_list) {
142 if (dssdev->dev->of_node == node) {
143 found = true;
144 goto out;
145 }
146 }
147 out:
148 mutex_unlock(&panel_list_mutex);
149 return found;
150 }
151 EXPORT_SYMBOL(omapdss_component_is_display);
152
153 struct omap_dss_device *omap_dss_get_device(struct omap_dss_device *dssdev)
154 {
155 if (!try_module_get(dssdev->owner))
156 return NULL;
157
158 if (get_device(dssdev->dev) == NULL) {
159 module_put(dssdev->owner);
160 return NULL;
161 }
162
163 return dssdev;
164 }
165 EXPORT_SYMBOL(omap_dss_get_device);
166
167 void omap_dss_put_device(struct omap_dss_device *dssdev)
168 {
169 put_device(dssdev->dev);
170 module_put(dssdev->owner);
171 }
172 EXPORT_SYMBOL(omap_dss_put_device);
173
174 /*
175 * ref count of the found device is incremented.
176 * ref count of from-device is decremented.
177 */
178 struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
179 {
180 struct list_head *l;
181 struct omap_dss_device *dssdev;
182
183 mutex_lock(&panel_list_mutex);
184
185 if (list_empty(&panel_list)) {
186 dssdev = NULL;
187 goto out;
188 }
189
190 if (from == NULL) {
191 dssdev = list_first_entry(&panel_list, struct omap_dss_device,
192 panel_list);
193 omap_dss_get_device(dssdev);
194 goto out;
195 }
196
197 omap_dss_put_device(from);
198
199 list_for_each(l, &panel_list) {
200 dssdev = list_entry(l, struct omap_dss_device, panel_list);
201 if (dssdev == from) {
202 if (list_is_last(l, &panel_list)) {
203 dssdev = NULL;
204 goto out;
205 }
206
207 dssdev = list_entry(l->next, struct omap_dss_device,
208 panel_list);
209 omap_dss_get_device(dssdev);
210 goto out;
211 }
212 }
213
214 WARN(1, "'from' dssdev not found\n");
215
216 dssdev = NULL;
217 out:
218 mutex_unlock(&panel_list_mutex);
219 return dssdev;
220 }
221 EXPORT_SYMBOL(omap_dss_get_next_device);
222
223 struct omap_dss_device *omap_dss_find_device(void *data,
224 int (*match)(struct omap_dss_device *dssdev, void *data))
225 {
226 struct omap_dss_device *dssdev = NULL;
227
228 while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
229 if (match(dssdev, data))
230 return dssdev;
231 }
232
233 return NULL;
234 }
235 EXPORT_SYMBOL(omap_dss_find_device);