blob: 1c175a4e7f6bf2846d1bc0cb9a1d8ee783648e1a [file] [log] [blame]
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001/*
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>
Tomi Valkeineneed07e02009-08-07 13:43:20 +030028#include <linux/platform_device.h>
29
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030030#include <video/omapdss.h>
Tomi Valkeineneed07e02009-08-07 13:43:20 +030031#include "dss.h"
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +030032#include "dss_features.h"
Tomi Valkeineneed07e02009-08-07 13:43:20 +030033
Tomi Valkeinen96adcec2010-01-11 13:54:33 +020034void omapdss_default_get_resolution(struct omap_dss_device *dssdev,
Tomi Valkeineneed07e02009-08-07 13:43:20 +030035 u16 *xres, u16 *yres)
36{
37 *xres = dssdev->panel.timings.x_res;
38 *yres = dssdev->panel.timings.y_res;
39}
Tomi Valkeinen96adcec2010-01-11 13:54:33 +020040EXPORT_SYMBOL(omapdss_default_get_resolution);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030041
Tomi Valkeinena2699502010-01-11 14:33:40 +020042int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev)
Tomi Valkeineneed07e02009-08-07 13:43:20 +030043{
Tomi Valkeineneed07e02009-08-07 13:43:20 +030044 switch (dssdev->type) {
45 case OMAP_DISPLAY_TYPE_DPI:
46 if (dssdev->phy.dpi.data_lines == 24)
47 return 24;
48 else
49 return 16;
50
51 case OMAP_DISPLAY_TYPE_DBI:
Tomi Valkeineneed07e02009-08-07 13:43:20 +030052 if (dssdev->ctrl.pixel_size == 24)
53 return 24;
54 else
55 return 16;
Archit Tanejaa3b3cc22011-09-08 18:42:16 +053056 case OMAP_DISPLAY_TYPE_DSI:
57 if (dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt) > 16)
58 return 24;
59 else
60 return 16;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030061 case OMAP_DISPLAY_TYPE_VENC:
62 case OMAP_DISPLAY_TYPE_SDI:
Mythri P Kb1196012011-03-08 17:15:54 +053063 case OMAP_DISPLAY_TYPE_HDMI:
Tomi Valkeineneed07e02009-08-07 13:43:20 +030064 return 24;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030065 default:
66 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +030067 return 0;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030068 }
69}
Tomi Valkeinena2699502010-01-11 14:33:40 +020070EXPORT_SYMBOL(omapdss_default_get_recommended_bpp);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030071
Grazvydas Ignotas4b6430f2012-03-15 20:00:23 +020072void omapdss_default_get_timings(struct omap_dss_device *dssdev,
73 struct omap_video_timings *timings)
74{
75 *timings = dssdev->panel.timings;
76}
77EXPORT_SYMBOL(omapdss_default_get_timings);
78
Tomi Valkeineneed07e02009-08-07 13:43:20 +030079static int dss_suspend_device(struct device *dev, void *data)
80{
Tomi Valkeineneed07e02009-08-07 13:43:20 +030081 struct omap_dss_device *dssdev = to_dss_device(dev);
82
83 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
84 dssdev->activate_after_resume = false;
85 return 0;
86 }
87
Tomi Valkeinen998c3362012-05-30 13:26:00 +030088 dssdev->driver->disable(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030089
90 dssdev->activate_after_resume = true;
91
92 return 0;
93}
94
95int dss_suspend_all_devices(void)
96{
97 int r;
98 struct bus_type *bus = dss_get_bus();
99
100 r = bus_for_each_dev(bus, NULL, NULL, dss_suspend_device);
101 if (r) {
102 /* resume all displays that were suspended */
103 dss_resume_all_devices();
104 return r;
105 }
106
107 return 0;
108}
109
110static int dss_resume_device(struct device *dev, void *data)
111{
112 int r;
113 struct omap_dss_device *dssdev = to_dss_device(dev);
114
Tomi Valkeinen998c3362012-05-30 13:26:00 +0300115 if (dssdev->activate_after_resume) {
116 r = dssdev->driver->enable(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300117 if (r)
118 return r;
119 }
120
121 dssdev->activate_after_resume = false;
122
123 return 0;
124}
125
126int dss_resume_all_devices(void)
127{
128 struct bus_type *bus = dss_get_bus();
129
130 return bus_for_each_dev(bus, NULL, NULL, dss_resume_device);
131}
132
133static int dss_disable_device(struct device *dev, void *data)
134{
135 struct omap_dss_device *dssdev = to_dss_device(dev);
Jani Nikula279fcd42010-03-24 11:59:38 +0100136
137 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
138 dssdev->driver->disable(dssdev);
139
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300140 return 0;
141}
142
143void dss_disable_all_devices(void)
144{
145 struct bus_type *bus = dss_get_bus();
146 bus_for_each_dev(bus, NULL, NULL, dss_disable_device);
147}
148
Tomi Valkeinen2e7e3dc2012-11-16 15:45:26 +0200149static LIST_HEAD(panel_list);
150static DEFINE_MUTEX(panel_list_mutex);
151static int disp_num_counter;
152
153int omapdss_register_display(struct omap_dss_device *dssdev)
154{
155 struct omap_dss_driver *drv = dssdev->driver;
156
157 snprintf(dssdev->alias, sizeof(dssdev->alias),
158 "display%d", disp_num_counter++);
159
160 if (drv && drv->get_resolution == NULL)
161 drv->get_resolution = omapdss_default_get_resolution;
162 if (drv && drv->get_recommended_bpp == NULL)
163 drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
164 if (drv && drv->get_timings == NULL)
165 drv->get_timings = omapdss_default_get_timings;
166
167 mutex_lock(&panel_list_mutex);
168 list_add_tail(&dssdev->panel_list, &panel_list);
169 mutex_unlock(&panel_list_mutex);
170 return 0;
171}
172EXPORT_SYMBOL(omapdss_register_display);
173
174void omapdss_unregister_display(struct omap_dss_device *dssdev)
175{
176 mutex_lock(&panel_list_mutex);
177 list_del(&dssdev->panel_list);
178 mutex_unlock(&panel_list_mutex);
179}
180EXPORT_SYMBOL(omapdss_unregister_display);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300181
182void omap_dss_get_device(struct omap_dss_device *dssdev)
183{
184 get_device(&dssdev->dev);
185}
186EXPORT_SYMBOL(omap_dss_get_device);
187
188void omap_dss_put_device(struct omap_dss_device *dssdev)
189{
190 put_device(&dssdev->dev);
191}
192EXPORT_SYMBOL(omap_dss_put_device);
193
194/* ref count of the found device is incremented. ref count
195 * of from-device is decremented. */
196struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
197{
198 struct device *dev;
199 struct device *dev_start = NULL;
200 struct omap_dss_device *dssdev = NULL;
201
202 int match(struct device *dev, void *data)
203 {
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300204 return 1;
205 }
206
207 if (from)
208 dev_start = &from->dev;
209 dev = bus_find_device(dss_get_bus(), dev_start, NULL, match);
210 if (dev)
211 dssdev = to_dss_device(dev);
212 if (from)
213 put_device(&from->dev);
214
215 return dssdev;
216}
217EXPORT_SYMBOL(omap_dss_get_next_device);
218
219struct omap_dss_device *omap_dss_find_device(void *data,
220 int (*match)(struct omap_dss_device *dssdev, void *data))
221{
222 struct omap_dss_device *dssdev = NULL;
223
224 while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
225 if (match(dssdev, data))
226 return dssdev;
227 }
228
229 return NULL;
230}
231EXPORT_SYMBOL(omap_dss_find_device);
232
233int omap_dss_start_device(struct omap_dss_device *dssdev)
234{
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300235 if (!dssdev->driver) {
236 DSSDBG("no driver\n");
Tomi Valkeinene020f9a2010-02-17 13:36:48 +0200237 return -ENODEV;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300238 }
239
240 if (!try_module_get(dssdev->dev.driver->owner)) {
Tomi Valkeinene020f9a2010-02-17 13:36:48 +0200241 return -ENODEV;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300242 }
243
244 return 0;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300245}
246EXPORT_SYMBOL(omap_dss_start_device);
247
248void omap_dss_stop_device(struct omap_dss_device *dssdev)
249{
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300250 module_put(dssdev->dev.driver->owner);
251}
252EXPORT_SYMBOL(omap_dss_stop_device);
253
Tomi Valkeinen6fcd4852013-05-10 13:02:32 +0300254void videomode_to_omap_video_timings(const struct videomode *vm,
255 struct omap_video_timings *ovt)
256{
257 memset(ovt, 0, sizeof(*ovt));
258
259 ovt->pixel_clock = vm->pixelclock / 1000;
260 ovt->x_res = vm->hactive;
261 ovt->hbp = vm->hback_porch;
262 ovt->hfp = vm->hfront_porch;
263 ovt->hsw = vm->hsync_len;
264 ovt->y_res = vm->vactive;
265 ovt->vbp = vm->vback_porch;
266 ovt->vfp = vm->vfront_porch;
267 ovt->vsw = vm->vsync_len;
268
269 ovt->vsync_level = vm->flags & DISPLAY_FLAGS_VSYNC_HIGH ?
270 OMAPDSS_SIG_ACTIVE_HIGH :
271 OMAPDSS_SIG_ACTIVE_LOW;
272 ovt->hsync_level = vm->flags & DISPLAY_FLAGS_HSYNC_HIGH ?
273 OMAPDSS_SIG_ACTIVE_HIGH :
274 OMAPDSS_SIG_ACTIVE_LOW;
275 ovt->de_level = vm->flags & DISPLAY_FLAGS_DE_HIGH ?
276 OMAPDSS_SIG_ACTIVE_HIGH :
277 OMAPDSS_SIG_ACTIVE_HIGH;
278 ovt->data_pclk_edge = vm->flags & DISPLAY_FLAGS_PIXDATA_POSEDGE ?
279 OMAPDSS_DRIVE_SIG_RISING_EDGE :
280 OMAPDSS_DRIVE_SIG_FALLING_EDGE;
281
282 ovt->sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES;
283}
284EXPORT_SYMBOL(videomode_to_omap_video_timings);
285
286void omap_video_timings_to_videomode(const struct omap_video_timings *ovt,
287 struct videomode *vm)
288{
289 memset(vm, 0, sizeof(*vm));
290
291 vm->pixelclock = ovt->pixel_clock * 1000;
292
293 vm->hactive = ovt->x_res;
294 vm->hback_porch = ovt->hbp;
295 vm->hfront_porch = ovt->hfp;
296 vm->hsync_len = ovt->hsw;
297 vm->vactive = ovt->y_res;
298 vm->vback_porch = ovt->vbp;
299 vm->vfront_porch = ovt->vfp;
300 vm->vsync_len = ovt->vsw;
301
302 if (ovt->hsync_level == OMAPDSS_SIG_ACTIVE_HIGH)
303 vm->flags |= DISPLAY_FLAGS_HSYNC_HIGH;
304 else
305 vm->flags |= DISPLAY_FLAGS_HSYNC_LOW;
306
307 if (ovt->vsync_level == OMAPDSS_SIG_ACTIVE_HIGH)
308 vm->flags |= DISPLAY_FLAGS_VSYNC_HIGH;
309 else
310 vm->flags |= DISPLAY_FLAGS_VSYNC_LOW;
311
312 if (ovt->de_level == OMAPDSS_SIG_ACTIVE_HIGH)
313 vm->flags |= DISPLAY_FLAGS_DE_HIGH;
314 else
315 vm->flags |= DISPLAY_FLAGS_DE_LOW;
316
317 if (ovt->data_pclk_edge == OMAPDSS_DRIVE_SIG_RISING_EDGE)
318 vm->flags |= DISPLAY_FLAGS_PIXDATA_POSEDGE;
319 else
320 vm->flags |= DISPLAY_FLAGS_PIXDATA_NEGEDGE;
321}
322EXPORT_SYMBOL(omap_video_timings_to_videomode);