]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/gpu/drm/omapdrm/dss/display.c
e567ff68b216f0795c271a6adca248eac8b82c94
[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 struct omap_dss_device *omap_dss_get_device(struct omap_dss_device *dssdev)
136 {
137 if (!try_module_get(dssdev->owner))
138 return NULL;
139
140 if (get_device(dssdev->dev) == NULL) {
141 module_put(dssdev->owner);
142 return NULL;
143 }
144
145 return dssdev;
146 }
147 EXPORT_SYMBOL(omap_dss_get_device);
148
149 void omap_dss_put_device(struct omap_dss_device *dssdev)
150 {
151 put_device(dssdev->dev);
152 module_put(dssdev->owner);
153 }
154 EXPORT_SYMBOL(omap_dss_put_device);
155
156 /*
157 * ref count of the found device is incremented.
158 * ref count of from-device is decremented.
159 */
160 struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
161 {
162 struct list_head *l;
163 struct omap_dss_device *dssdev;
164
165 mutex_lock(&panel_list_mutex);
166
167 if (list_empty(&panel_list)) {
168 dssdev = NULL;
169 goto out;
170 }
171
172 if (from == NULL) {
173 dssdev = list_first_entry(&panel_list, struct omap_dss_device,
174 panel_list);
175 omap_dss_get_device(dssdev);
176 goto out;
177 }
178
179 omap_dss_put_device(from);
180
181 list_for_each(l, &panel_list) {
182 dssdev = list_entry(l, struct omap_dss_device, panel_list);
183 if (dssdev == from) {
184 if (list_is_last(l, &panel_list)) {
185 dssdev = NULL;
186 goto out;
187 }
188
189 dssdev = list_entry(l->next, struct omap_dss_device,
190 panel_list);
191 omap_dss_get_device(dssdev);
192 goto out;
193 }
194 }
195
196 WARN(1, "'from' dssdev not found\n");
197
198 dssdev = NULL;
199 out:
200 mutex_unlock(&panel_list_mutex);
201 return dssdev;
202 }
203 EXPORT_SYMBOL(omap_dss_get_next_device);
204
205 struct omap_dss_device *omap_dss_find_device(void *data,
206 int (*match)(struct omap_dss_device *dssdev, void *data))
207 {
208 struct omap_dss_device *dssdev = NULL;
209
210 while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
211 if (match(dssdev, data))
212 return dssdev;
213 }
214
215 return NULL;
216 }
217 EXPORT_SYMBOL(omap_dss_find_device);