]> git.karo-electronics.de Git - mv-sheeva.git/blob - drivers/video/omap2/dss/display.c
OMAP: DSS2: remove update_mode from omapdss
[mv-sheeva.git] / drivers / video / omap2 / 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
30 #include <video/omapdss.h>
31 #include "dss.h"
32
33 static ssize_t display_enabled_show(struct device *dev,
34                 struct device_attribute *attr, char *buf)
35 {
36         struct omap_dss_device *dssdev = to_dss_device(dev);
37         bool enabled = dssdev->state != OMAP_DSS_DISPLAY_DISABLED;
38
39         return snprintf(buf, PAGE_SIZE, "%d\n", enabled);
40 }
41
42 static ssize_t display_enabled_store(struct device *dev,
43                 struct device_attribute *attr,
44                 const char *buf, size_t size)
45 {
46         struct omap_dss_device *dssdev = to_dss_device(dev);
47         int r, enabled;
48
49         r = kstrtoint(buf, 0, &enabled);
50         if (r)
51                 return r;
52
53         enabled = !!enabled;
54
55         if (enabled != (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)) {
56                 if (enabled) {
57                         r = dssdev->driver->enable(dssdev);
58                         if (r)
59                                 return r;
60                 } else {
61                         dssdev->driver->disable(dssdev);
62                 }
63         }
64
65         return size;
66 }
67
68 static ssize_t display_tear_show(struct device *dev,
69                 struct device_attribute *attr, char *buf)
70 {
71         struct omap_dss_device *dssdev = to_dss_device(dev);
72         return snprintf(buf, PAGE_SIZE, "%d\n",
73                         dssdev->driver->get_te ?
74                         dssdev->driver->get_te(dssdev) : 0);
75 }
76
77 static ssize_t display_tear_store(struct device *dev,
78                 struct device_attribute *attr, const char *buf, size_t size)
79 {
80         struct omap_dss_device *dssdev = to_dss_device(dev);
81         int te, r;
82
83         if (!dssdev->driver->enable_te || !dssdev->driver->get_te)
84                 return -ENOENT;
85
86         r = kstrtoint(buf, 0, &te);
87         if (r)
88                 return r;
89
90         te = !!te;
91
92         r = dssdev->driver->enable_te(dssdev, te);
93         if (r)
94                 return r;
95
96         return size;
97 }
98
99 static ssize_t display_timings_show(struct device *dev,
100                 struct device_attribute *attr, char *buf)
101 {
102         struct omap_dss_device *dssdev = to_dss_device(dev);
103         struct omap_video_timings t;
104
105         if (!dssdev->driver->get_timings)
106                 return -ENOENT;
107
108         dssdev->driver->get_timings(dssdev, &t);
109
110         return snprintf(buf, PAGE_SIZE, "%u,%u/%u/%u/%u,%u/%u/%u/%u\n",
111                         t.pixel_clock,
112                         t.x_res, t.hfp, t.hbp, t.hsw,
113                         t.y_res, t.vfp, t.vbp, t.vsw);
114 }
115
116 static ssize_t display_timings_store(struct device *dev,
117                 struct device_attribute *attr, const char *buf, size_t size)
118 {
119         struct omap_dss_device *dssdev = to_dss_device(dev);
120         struct omap_video_timings t;
121         int r, found;
122
123         if (!dssdev->driver->set_timings || !dssdev->driver->check_timings)
124                 return -ENOENT;
125
126         found = 0;
127 #ifdef CONFIG_OMAP2_DSS_VENC
128         if (strncmp("pal", buf, 3) == 0) {
129                 t = omap_dss_pal_timings;
130                 found = 1;
131         } else if (strncmp("ntsc", buf, 4) == 0) {
132                 t = omap_dss_ntsc_timings;
133                 found = 1;
134         }
135 #endif
136         if (!found && sscanf(buf, "%u,%hu/%hu/%hu/%hu,%hu/%hu/%hu/%hu",
137                                 &t.pixel_clock,
138                                 &t.x_res, &t.hfp, &t.hbp, &t.hsw,
139                                 &t.y_res, &t.vfp, &t.vbp, &t.vsw) != 9)
140                 return -EINVAL;
141
142         r = dssdev->driver->check_timings(dssdev, &t);
143         if (r)
144                 return r;
145
146         dssdev->driver->set_timings(dssdev, &t);
147
148         return size;
149 }
150
151 static ssize_t display_rotate_show(struct device *dev,
152                 struct device_attribute *attr, char *buf)
153 {
154         struct omap_dss_device *dssdev = to_dss_device(dev);
155         int rotate;
156         if (!dssdev->driver->get_rotate)
157                 return -ENOENT;
158         rotate = dssdev->driver->get_rotate(dssdev);
159         return snprintf(buf, PAGE_SIZE, "%u\n", rotate);
160 }
161
162 static ssize_t display_rotate_store(struct device *dev,
163                 struct device_attribute *attr, const char *buf, size_t size)
164 {
165         struct omap_dss_device *dssdev = to_dss_device(dev);
166         int rot, r;
167
168         if (!dssdev->driver->set_rotate || !dssdev->driver->get_rotate)
169                 return -ENOENT;
170
171         r = kstrtoint(buf, 0, &rot);
172         if (r)
173                 return r;
174
175         r = dssdev->driver->set_rotate(dssdev, rot);
176         if (r)
177                 return r;
178
179         return size;
180 }
181
182 static ssize_t display_mirror_show(struct device *dev,
183                 struct device_attribute *attr, char *buf)
184 {
185         struct omap_dss_device *dssdev = to_dss_device(dev);
186         int mirror;
187         if (!dssdev->driver->get_mirror)
188                 return -ENOENT;
189         mirror = dssdev->driver->get_mirror(dssdev);
190         return snprintf(buf, PAGE_SIZE, "%u\n", mirror);
191 }
192
193 static ssize_t display_mirror_store(struct device *dev,
194                 struct device_attribute *attr, const char *buf, size_t size)
195 {
196         struct omap_dss_device *dssdev = to_dss_device(dev);
197         int mirror, r;
198
199         if (!dssdev->driver->set_mirror || !dssdev->driver->get_mirror)
200                 return -ENOENT;
201
202         r = kstrtoint(buf, 0, &mirror);
203         if (r)
204                 return r;
205
206         mirror = !!mirror;
207
208         r = dssdev->driver->set_mirror(dssdev, mirror);
209         if (r)
210                 return r;
211
212         return size;
213 }
214
215 static ssize_t display_wss_show(struct device *dev,
216                 struct device_attribute *attr, char *buf)
217 {
218         struct omap_dss_device *dssdev = to_dss_device(dev);
219         unsigned int wss;
220
221         if (!dssdev->driver->get_wss)
222                 return -ENOENT;
223
224         wss = dssdev->driver->get_wss(dssdev);
225
226         return snprintf(buf, PAGE_SIZE, "0x%05x\n", wss);
227 }
228
229 static ssize_t display_wss_store(struct device *dev,
230                 struct device_attribute *attr, const char *buf, size_t size)
231 {
232         struct omap_dss_device *dssdev = to_dss_device(dev);
233         u32 wss;
234         int r;
235
236         if (!dssdev->driver->get_wss || !dssdev->driver->set_wss)
237                 return -ENOENT;
238
239         r = kstrtou32(buf, 0, &wss);
240         if (r)
241                 return r;
242
243         if (wss > 0xfffff)
244                 return -EINVAL;
245
246         r = dssdev->driver->set_wss(dssdev, wss);
247         if (r)
248                 return r;
249
250         return size;
251 }
252
253 static DEVICE_ATTR(enabled, S_IRUGO|S_IWUSR,
254                 display_enabled_show, display_enabled_store);
255 static DEVICE_ATTR(tear_elim, S_IRUGO|S_IWUSR,
256                 display_tear_show, display_tear_store);
257 static DEVICE_ATTR(timings, S_IRUGO|S_IWUSR,
258                 display_timings_show, display_timings_store);
259 static DEVICE_ATTR(rotate, S_IRUGO|S_IWUSR,
260                 display_rotate_show, display_rotate_store);
261 static DEVICE_ATTR(mirror, S_IRUGO|S_IWUSR,
262                 display_mirror_show, display_mirror_store);
263 static DEVICE_ATTR(wss, S_IRUGO|S_IWUSR,
264                 display_wss_show, display_wss_store);
265
266 static struct device_attribute *display_sysfs_attrs[] = {
267         &dev_attr_enabled,
268         &dev_attr_tear_elim,
269         &dev_attr_timings,
270         &dev_attr_rotate,
271         &dev_attr_mirror,
272         &dev_attr_wss,
273         NULL
274 };
275
276 void omapdss_default_get_resolution(struct omap_dss_device *dssdev,
277                         u16 *xres, u16 *yres)
278 {
279         *xres = dssdev->panel.timings.x_res;
280         *yres = dssdev->panel.timings.y_res;
281 }
282 EXPORT_SYMBOL(omapdss_default_get_resolution);
283
284 void default_get_overlay_fifo_thresholds(enum omap_plane plane,
285                 u32 fifo_size, enum omap_burst_size *burst_size,
286                 u32 *fifo_low, u32 *fifo_high)
287 {
288         unsigned burst_size_bytes;
289
290         *burst_size = OMAP_DSS_BURST_16x32;
291         burst_size_bytes = 16 * 32 / 8;
292
293         *fifo_high = fifo_size - 1;
294         *fifo_low = fifo_size - burst_size_bytes;
295 }
296
297 int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev)
298 {
299         switch (dssdev->type) {
300         case OMAP_DISPLAY_TYPE_DPI:
301                 if (dssdev->phy.dpi.data_lines == 24)
302                         return 24;
303                 else
304                         return 16;
305
306         case OMAP_DISPLAY_TYPE_DBI:
307         case OMAP_DISPLAY_TYPE_DSI:
308                 if (dssdev->ctrl.pixel_size == 24)
309                         return 24;
310                 else
311                         return 16;
312         case OMAP_DISPLAY_TYPE_VENC:
313         case OMAP_DISPLAY_TYPE_SDI:
314         case OMAP_DISPLAY_TYPE_HDMI:
315                 return 24;
316         default:
317                 BUG();
318         }
319 }
320 EXPORT_SYMBOL(omapdss_default_get_recommended_bpp);
321
322 /* Checks if replication logic should be used. Only use for active matrix,
323  * when overlay is in RGB12U or RGB16 mode, and LCD interface is
324  * 18bpp or 24bpp */
325 bool dss_use_replication(struct omap_dss_device *dssdev,
326                 enum omap_color_mode mode)
327 {
328         int bpp;
329
330         if (mode != OMAP_DSS_COLOR_RGB12U && mode != OMAP_DSS_COLOR_RGB16)
331                 return false;
332
333         if (dssdev->type == OMAP_DISPLAY_TYPE_DPI &&
334                         (dssdev->panel.config & OMAP_DSS_LCD_TFT) == 0)
335                 return false;
336
337         switch (dssdev->type) {
338         case OMAP_DISPLAY_TYPE_DPI:
339                 bpp = dssdev->phy.dpi.data_lines;
340                 break;
341         case OMAP_DISPLAY_TYPE_HDMI:
342         case OMAP_DISPLAY_TYPE_VENC:
343         case OMAP_DISPLAY_TYPE_SDI:
344                 bpp = 24;
345                 break;
346         case OMAP_DISPLAY_TYPE_DBI:
347         case OMAP_DISPLAY_TYPE_DSI:
348                 bpp = dssdev->ctrl.pixel_size;
349                 break;
350         default:
351                 BUG();
352         }
353
354         return bpp > 16;
355 }
356
357 void dss_init_device(struct platform_device *pdev,
358                 struct omap_dss_device *dssdev)
359 {
360         struct device_attribute *attr;
361         int i;
362         int r;
363
364         switch (dssdev->type) {
365 #ifdef CONFIG_OMAP2_DSS_DPI
366         case OMAP_DISPLAY_TYPE_DPI:
367                 r = dpi_init_display(dssdev);
368                 break;
369 #endif
370 #ifdef CONFIG_OMAP2_DSS_RFBI
371         case OMAP_DISPLAY_TYPE_DBI:
372                 r = rfbi_init_display(dssdev);
373                 break;
374 #endif
375 #ifdef CONFIG_OMAP2_DSS_VENC
376         case OMAP_DISPLAY_TYPE_VENC:
377                 r = venc_init_display(dssdev);
378                 break;
379 #endif
380 #ifdef CONFIG_OMAP2_DSS_SDI
381         case OMAP_DISPLAY_TYPE_SDI:
382                 r = sdi_init_display(dssdev);
383                 break;
384 #endif
385 #ifdef CONFIG_OMAP2_DSS_DSI
386         case OMAP_DISPLAY_TYPE_DSI:
387                 r = dsi_init_display(dssdev);
388                 break;
389 #endif
390         case OMAP_DISPLAY_TYPE_HDMI:
391                 r = hdmi_init_display(dssdev);
392                 break;
393         default:
394                 DSSERR("Support for display '%s' not compiled in.\n",
395                                 dssdev->name);
396                 return;
397         }
398
399         if (r) {
400                 DSSERR("failed to init display %s\n", dssdev->name);
401                 return;
402         }
403
404         /* create device sysfs files */
405         i = 0;
406         while ((attr = display_sysfs_attrs[i++]) != NULL) {
407                 r = device_create_file(&dssdev->dev, attr);
408                 if (r)
409                         DSSERR("failed to create sysfs file\n");
410         }
411
412         /* create display? sysfs links */
413         r = sysfs_create_link(&pdev->dev.kobj, &dssdev->dev.kobj,
414                         dev_name(&dssdev->dev));
415         if (r)
416                 DSSERR("failed to create sysfs display link\n");
417 }
418
419 void dss_uninit_device(struct platform_device *pdev,
420                 struct omap_dss_device *dssdev)
421 {
422         struct device_attribute *attr;
423         int i = 0;
424
425         sysfs_remove_link(&pdev->dev.kobj, dev_name(&dssdev->dev));
426
427         while ((attr = display_sysfs_attrs[i++]) != NULL)
428                 device_remove_file(&dssdev->dev, attr);
429
430         if (dssdev->manager)
431                 dssdev->manager->unset_device(dssdev->manager);
432 }
433
434 static int dss_suspend_device(struct device *dev, void *data)
435 {
436         int r;
437         struct omap_dss_device *dssdev = to_dss_device(dev);
438
439         if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
440                 dssdev->activate_after_resume = false;
441                 return 0;
442         }
443
444         if (!dssdev->driver->suspend) {
445                 DSSERR("display '%s' doesn't implement suspend\n",
446                                 dssdev->name);
447                 return -ENOSYS;
448         }
449
450         r = dssdev->driver->suspend(dssdev);
451         if (r)
452                 return r;
453
454         dssdev->activate_after_resume = true;
455
456         return 0;
457 }
458
459 int dss_suspend_all_devices(void)
460 {
461         int r;
462         struct bus_type *bus = dss_get_bus();
463
464         r = bus_for_each_dev(bus, NULL, NULL, dss_suspend_device);
465         if (r) {
466                 /* resume all displays that were suspended */
467                 dss_resume_all_devices();
468                 return r;
469         }
470
471         return 0;
472 }
473
474 static int dss_resume_device(struct device *dev, void *data)
475 {
476         int r;
477         struct omap_dss_device *dssdev = to_dss_device(dev);
478
479         if (dssdev->activate_after_resume && dssdev->driver->resume) {
480                 r = dssdev->driver->resume(dssdev);
481                 if (r)
482                         return r;
483         }
484
485         dssdev->activate_after_resume = false;
486
487         return 0;
488 }
489
490 int dss_resume_all_devices(void)
491 {
492         struct bus_type *bus = dss_get_bus();
493
494         return bus_for_each_dev(bus, NULL, NULL, dss_resume_device);
495 }
496
497 static int dss_disable_device(struct device *dev, void *data)
498 {
499         struct omap_dss_device *dssdev = to_dss_device(dev);
500
501         if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
502                 dssdev->driver->disable(dssdev);
503
504         return 0;
505 }
506
507 void dss_disable_all_devices(void)
508 {
509         struct bus_type *bus = dss_get_bus();
510         bus_for_each_dev(bus, NULL, NULL, dss_disable_device);
511 }
512
513
514 void omap_dss_get_device(struct omap_dss_device *dssdev)
515 {
516         get_device(&dssdev->dev);
517 }
518 EXPORT_SYMBOL(omap_dss_get_device);
519
520 void omap_dss_put_device(struct omap_dss_device *dssdev)
521 {
522         put_device(&dssdev->dev);
523 }
524 EXPORT_SYMBOL(omap_dss_put_device);
525
526 /* ref count of the found device is incremented. ref count
527  * of from-device is decremented. */
528 struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
529 {
530         struct device *dev;
531         struct device *dev_start = NULL;
532         struct omap_dss_device *dssdev = NULL;
533
534         int match(struct device *dev, void *data)
535         {
536                 return 1;
537         }
538
539         if (from)
540                 dev_start = &from->dev;
541         dev = bus_find_device(dss_get_bus(), dev_start, NULL, match);
542         if (dev)
543                 dssdev = to_dss_device(dev);
544         if (from)
545                 put_device(&from->dev);
546
547         return dssdev;
548 }
549 EXPORT_SYMBOL(omap_dss_get_next_device);
550
551 struct omap_dss_device *omap_dss_find_device(void *data,
552                 int (*match)(struct omap_dss_device *dssdev, void *data))
553 {
554         struct omap_dss_device *dssdev = NULL;
555
556         while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
557                 if (match(dssdev, data))
558                         return dssdev;
559         }
560
561         return NULL;
562 }
563 EXPORT_SYMBOL(omap_dss_find_device);
564
565 int omap_dss_start_device(struct omap_dss_device *dssdev)
566 {
567         if (!dssdev->driver) {
568                 DSSDBG("no driver\n");
569                 return -ENODEV;
570         }
571
572         if (!try_module_get(dssdev->dev.driver->owner)) {
573                 return -ENODEV;
574         }
575
576         return 0;
577 }
578 EXPORT_SYMBOL(omap_dss_start_device);
579
580 void omap_dss_stop_device(struct omap_dss_device *dssdev)
581 {
582         module_put(dssdev->dev.driver->owner);
583 }
584 EXPORT_SYMBOL(omap_dss_stop_device);
585