OMAPDSS: add omapdss_compat_init()
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / video / omap2 / dss / core.c
1 /*
2 * linux/drivers/video/omap2/dss/core.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 "CORE"
24
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/clk.h>
28 #include <linux/err.h>
29 #include <linux/platform_device.h>
30 #include <linux/seq_file.h>
31 #include <linux/debugfs.h>
32 #include <linux/io.h>
33 #include <linux/device.h>
34 #include <linux/regulator/consumer.h>
35 #include <linux/suspend.h>
36 #include <linux/slab.h>
37
38 #include <video/omapdss.h>
39
40 #include "dss.h"
41 #include "dss_features.h"
42
43 static struct {
44 struct platform_device *pdev;
45
46 struct regulator *vdds_dsi_reg;
47 struct regulator *vdds_sdi_reg;
48
49 const char *default_display_name;
50 } core;
51
52 static char *def_disp_name;
53 module_param_named(def_disp, def_disp_name, charp, 0);
54 MODULE_PARM_DESC(def_disp, "default display name");
55
56 const char *omapdss_get_default_display_name(void)
57 {
58 return core.default_display_name;
59 }
60 EXPORT_SYMBOL(omapdss_get_default_display_name);
61
62 enum omapdss_version omapdss_get_version(void)
63 {
64 struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
65 return pdata->version;
66 }
67 EXPORT_SYMBOL(omapdss_get_version);
68
69 struct platform_device *dss_get_core_pdev(void)
70 {
71 return core.pdev;
72 }
73
74 /* REGULATORS */
75
76 struct regulator *dss_get_vdds_dsi(void)
77 {
78 struct regulator *reg;
79
80 if (core.vdds_dsi_reg != NULL)
81 return core.vdds_dsi_reg;
82
83 reg = regulator_get(&core.pdev->dev, "vdds_dsi");
84 if (!IS_ERR(reg))
85 core.vdds_dsi_reg = reg;
86
87 return reg;
88 }
89
90 struct regulator *dss_get_vdds_sdi(void)
91 {
92 struct regulator *reg;
93
94 if (core.vdds_sdi_reg != NULL)
95 return core.vdds_sdi_reg;
96
97 reg = regulator_get(&core.pdev->dev, "vdds_sdi");
98 if (!IS_ERR(reg))
99 core.vdds_sdi_reg = reg;
100
101 return reg;
102 }
103
104 int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask)
105 {
106 struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
107
108 if (!board_data->dsi_enable_pads)
109 return -ENOENT;
110
111 return board_data->dsi_enable_pads(dsi_id, lane_mask);
112 }
113
114 void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask)
115 {
116 struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
117
118 if (!board_data->dsi_disable_pads)
119 return;
120
121 return board_data->dsi_disable_pads(dsi_id, lane_mask);
122 }
123
124 int dss_set_min_bus_tput(struct device *dev, unsigned long tput)
125 {
126 struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
127
128 if (pdata->set_min_bus_tput)
129 return pdata->set_min_bus_tput(dev, tput);
130 else
131 return 0;
132 }
133
134 #if defined(CONFIG_OMAP2_DSS_DEBUGFS)
135 static int dss_debug_show(struct seq_file *s, void *unused)
136 {
137 void (*func)(struct seq_file *) = s->private;
138 func(s);
139 return 0;
140 }
141
142 static int dss_debug_open(struct inode *inode, struct file *file)
143 {
144 return single_open(file, dss_debug_show, inode->i_private);
145 }
146
147 static const struct file_operations dss_debug_fops = {
148 .open = dss_debug_open,
149 .read = seq_read,
150 .llseek = seq_lseek,
151 .release = single_release,
152 };
153
154 static struct dentry *dss_debugfs_dir;
155
156 static int dss_initialize_debugfs(void)
157 {
158 dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
159 if (IS_ERR(dss_debugfs_dir)) {
160 int err = PTR_ERR(dss_debugfs_dir);
161 dss_debugfs_dir = NULL;
162 return err;
163 }
164
165 debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
166 &dss_debug_dump_clocks, &dss_debug_fops);
167
168 return 0;
169 }
170
171 static void dss_uninitialize_debugfs(void)
172 {
173 if (dss_debugfs_dir)
174 debugfs_remove_recursive(dss_debugfs_dir);
175 }
176
177 int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
178 {
179 struct dentry *d;
180
181 d = debugfs_create_file(name, S_IRUGO, dss_debugfs_dir,
182 write, &dss_debug_fops);
183
184 if (IS_ERR(d))
185 return PTR_ERR(d);
186
187 return 0;
188 }
189 #else /* CONFIG_OMAP2_DSS_DEBUGFS */
190 static inline int dss_initialize_debugfs(void)
191 {
192 return 0;
193 }
194 static inline void dss_uninitialize_debugfs(void)
195 {
196 }
197 int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
198 {
199 return 0;
200 }
201 #endif /* CONFIG_OMAP2_DSS_DEBUGFS */
202
203 /* PLATFORM DEVICE */
204 static int omap_dss_pm_notif(struct notifier_block *b, unsigned long v, void *d)
205 {
206 DSSDBG("pm notif %lu\n", v);
207
208 switch (v) {
209 case PM_SUSPEND_PREPARE:
210 DSSDBG("suspending displays\n");
211 return dss_suspend_all_devices();
212
213 case PM_POST_SUSPEND:
214 DSSDBG("resuming displays\n");
215 return dss_resume_all_devices();
216
217 default:
218 return 0;
219 }
220 }
221
222 static struct notifier_block omap_dss_pm_notif_block = {
223 .notifier_call = omap_dss_pm_notif,
224 };
225
226 static int __init omap_dss_probe(struct platform_device *pdev)
227 {
228 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
229 int r;
230
231 core.pdev = pdev;
232
233 dss_features_init(omapdss_get_version());
234
235 omapdss_compat_init();
236
237 dss_init_overlay_managers(pdev);
238 dss_init_overlays(pdev);
239
240 r = dss_initialize_debugfs();
241 if (r)
242 goto err_debugfs;
243
244 if (def_disp_name)
245 core.default_display_name = def_disp_name;
246 else if (pdata->default_device)
247 core.default_display_name = pdata->default_device->name;
248
249 register_pm_notifier(&omap_dss_pm_notif_block);
250
251 return 0;
252
253 err_debugfs:
254
255 return r;
256 }
257
258 static int omap_dss_remove(struct platform_device *pdev)
259 {
260 unregister_pm_notifier(&omap_dss_pm_notif_block);
261
262 dss_uninitialize_debugfs();
263
264 dss_uninit_overlays(pdev);
265 dss_uninit_overlay_managers(pdev);
266
267 omapdss_compat_uninit();
268
269 return 0;
270 }
271
272 static void omap_dss_shutdown(struct platform_device *pdev)
273 {
274 DSSDBG("shutdown\n");
275 dss_disable_all_devices();
276 }
277
278 static struct platform_driver omap_dss_driver = {
279 .remove = omap_dss_remove,
280 .shutdown = omap_dss_shutdown,
281 .driver = {
282 .name = "omapdss",
283 .owner = THIS_MODULE,
284 },
285 };
286
287 /* BUS */
288 static int dss_bus_match(struct device *dev, struct device_driver *driver)
289 {
290 struct omap_dss_device *dssdev = to_dss_device(dev);
291
292 DSSDBG("bus_match. dev %s/%s, drv %s\n",
293 dev_name(dev), dssdev->driver_name, driver->name);
294
295 return strcmp(dssdev->driver_name, driver->name) == 0;
296 }
297
298 static ssize_t device_name_show(struct device *dev,
299 struct device_attribute *attr, char *buf)
300 {
301 struct omap_dss_device *dssdev = to_dss_device(dev);
302 return snprintf(buf, PAGE_SIZE, "%s\n",
303 dssdev->name ?
304 dssdev->name : "");
305 }
306
307 static struct device_attribute default_dev_attrs[] = {
308 __ATTR(name, S_IRUGO, device_name_show, NULL),
309 __ATTR_NULL,
310 };
311
312 static ssize_t driver_name_show(struct device_driver *drv, char *buf)
313 {
314 struct omap_dss_driver *dssdrv = to_dss_driver(drv);
315 return snprintf(buf, PAGE_SIZE, "%s\n",
316 dssdrv->driver.name ?
317 dssdrv->driver.name : "");
318 }
319 static struct driver_attribute default_drv_attrs[] = {
320 __ATTR(name, S_IRUGO, driver_name_show, NULL),
321 __ATTR_NULL,
322 };
323
324 static struct bus_type dss_bus_type = {
325 .name = "omapdss",
326 .match = dss_bus_match,
327 .dev_attrs = default_dev_attrs,
328 .drv_attrs = default_drv_attrs,
329 };
330
331 static void dss_bus_release(struct device *dev)
332 {
333 DSSDBG("bus_release\n");
334 }
335
336 static struct device dss_bus = {
337 .release = dss_bus_release,
338 };
339
340 struct bus_type *dss_get_bus(void)
341 {
342 return &dss_bus_type;
343 }
344
345 /* DRIVER */
346 static int dss_driver_probe(struct device *dev)
347 {
348 int r;
349 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
350 struct omap_dss_device *dssdev = to_dss_device(dev);
351
352 DSSDBG("driver_probe: dev %s/%s, drv %s\n",
353 dev_name(dev), dssdev->driver_name,
354 dssdrv->driver.name);
355
356 r = dss_init_device(core.pdev, dssdev);
357 if (r)
358 return r;
359
360 r = dssdrv->probe(dssdev);
361
362 if (r) {
363 DSSERR("driver probe failed: %d\n", r);
364 dss_uninit_device(core.pdev, dssdev);
365 return r;
366 }
367
368 DSSDBG("probe done for device %s\n", dev_name(dev));
369
370 dssdev->driver = dssdrv;
371
372 return 0;
373 }
374
375 static int dss_driver_remove(struct device *dev)
376 {
377 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
378 struct omap_dss_device *dssdev = to_dss_device(dev);
379
380 DSSDBG("driver_remove: dev %s/%s\n", dev_name(dev),
381 dssdev->driver_name);
382
383 dssdrv->remove(dssdev);
384
385 dss_uninit_device(core.pdev, dssdev);
386
387 dssdev->driver = NULL;
388
389 return 0;
390 }
391
392 int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
393 {
394 dssdriver->driver.bus = &dss_bus_type;
395 dssdriver->driver.probe = dss_driver_probe;
396 dssdriver->driver.remove = dss_driver_remove;
397
398 if (dssdriver->get_resolution == NULL)
399 dssdriver->get_resolution = omapdss_default_get_resolution;
400 if (dssdriver->get_recommended_bpp == NULL)
401 dssdriver->get_recommended_bpp =
402 omapdss_default_get_recommended_bpp;
403 if (dssdriver->get_timings == NULL)
404 dssdriver->get_timings = omapdss_default_get_timings;
405
406 return driver_register(&dssdriver->driver);
407 }
408 EXPORT_SYMBOL(omap_dss_register_driver);
409
410 void omap_dss_unregister_driver(struct omap_dss_driver *dssdriver)
411 {
412 driver_unregister(&dssdriver->driver);
413 }
414 EXPORT_SYMBOL(omap_dss_unregister_driver);
415
416 /* DEVICE */
417
418 static void omap_dss_dev_release(struct device *dev)
419 {
420 struct omap_dss_device *dssdev = to_dss_device(dev);
421 kfree(dssdev);
422 }
423
424 static int disp_num_counter;
425
426 struct omap_dss_device *dss_alloc_and_init_device(struct device *parent)
427 {
428 struct omap_dss_device *dssdev;
429
430 dssdev = kzalloc(sizeof(*dssdev), GFP_KERNEL);
431 if (!dssdev)
432 return NULL;
433
434 dssdev->dev.bus = &dss_bus_type;
435 dssdev->dev.parent = parent;
436 dssdev->dev.release = omap_dss_dev_release;
437 dev_set_name(&dssdev->dev, "display%d", disp_num_counter++);
438
439 device_initialize(&dssdev->dev);
440
441 return dssdev;
442 }
443
444 int dss_add_device(struct omap_dss_device *dssdev)
445 {
446 return device_add(&dssdev->dev);
447 }
448
449 void dss_put_device(struct omap_dss_device *dssdev)
450 {
451 put_device(&dssdev->dev);
452 }
453
454 void dss_unregister_device(struct omap_dss_device *dssdev)
455 {
456 device_unregister(&dssdev->dev);
457 }
458
459 static int dss_unregister_dss_dev(struct device *dev, void *data)
460 {
461 struct omap_dss_device *dssdev = to_dss_device(dev);
462 dss_unregister_device(dssdev);
463 return 0;
464 }
465
466 void dss_unregister_child_devices(struct device *parent)
467 {
468 device_for_each_child(parent, NULL, dss_unregister_dss_dev);
469 }
470
471 void dss_copy_device_pdata(struct omap_dss_device *dst,
472 const struct omap_dss_device *src)
473 {
474 u8 *d = (u8 *)dst;
475 u8 *s = (u8 *)src;
476 size_t dsize = sizeof(struct device);
477
478 memcpy(d + dsize, s + dsize, sizeof(struct omap_dss_device) - dsize);
479 }
480
481 /* BUS */
482 static int __init omap_dss_bus_register(void)
483 {
484 int r;
485
486 r = bus_register(&dss_bus_type);
487 if (r) {
488 DSSERR("bus register failed\n");
489 return r;
490 }
491
492 dev_set_name(&dss_bus, "omapdss");
493 r = device_register(&dss_bus);
494 if (r) {
495 DSSERR("bus driver register failed\n");
496 bus_unregister(&dss_bus_type);
497 return r;
498 }
499
500 return 0;
501 }
502
503 /* INIT */
504 static int (*dss_output_drv_reg_funcs[])(void) __initdata = {
505 #ifdef CONFIG_OMAP2_DSS_DSI
506 dsi_init_platform_driver,
507 #endif
508 #ifdef CONFIG_OMAP2_DSS_DPI
509 dpi_init_platform_driver,
510 #endif
511 #ifdef CONFIG_OMAP2_DSS_SDI
512 sdi_init_platform_driver,
513 #endif
514 #ifdef CONFIG_OMAP2_DSS_RFBI
515 rfbi_init_platform_driver,
516 #endif
517 #ifdef CONFIG_OMAP2_DSS_VENC
518 venc_init_platform_driver,
519 #endif
520 #ifdef CONFIG_OMAP4_DSS_HDMI
521 hdmi_init_platform_driver,
522 #endif
523 };
524
525 static void (*dss_output_drv_unreg_funcs[])(void) __exitdata = {
526 #ifdef CONFIG_OMAP2_DSS_DSI
527 dsi_uninit_platform_driver,
528 #endif
529 #ifdef CONFIG_OMAP2_DSS_DPI
530 dpi_uninit_platform_driver,
531 #endif
532 #ifdef CONFIG_OMAP2_DSS_SDI
533 sdi_uninit_platform_driver,
534 #endif
535 #ifdef CONFIG_OMAP2_DSS_RFBI
536 rfbi_uninit_platform_driver,
537 #endif
538 #ifdef CONFIG_OMAP2_DSS_VENC
539 venc_uninit_platform_driver,
540 #endif
541 #ifdef CONFIG_OMAP4_DSS_HDMI
542 hdmi_uninit_platform_driver,
543 #endif
544 };
545
546 static bool dss_output_drv_loaded[ARRAY_SIZE(dss_output_drv_reg_funcs)];
547
548 static int __init omap_dss_register_drivers(void)
549 {
550 int r;
551 int i;
552
553 r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
554 if (r)
555 return r;
556
557 r = dss_init_platform_driver();
558 if (r) {
559 DSSERR("Failed to initialize DSS platform driver\n");
560 goto err_dss;
561 }
562
563 r = dispc_init_platform_driver();
564 if (r) {
565 DSSERR("Failed to initialize dispc platform driver\n");
566 goto err_dispc;
567 }
568
569 /*
570 * It's ok if the output-driver register fails. It happens, for example,
571 * when there is no output-device (e.g. SDI for OMAP4).
572 */
573 for (i = 0; i < ARRAY_SIZE(dss_output_drv_reg_funcs); ++i) {
574 r = dss_output_drv_reg_funcs[i]();
575 if (r == 0)
576 dss_output_drv_loaded[i] = true;
577 }
578
579 return 0;
580
581 err_dispc:
582 dss_uninit_platform_driver();
583 err_dss:
584 platform_driver_unregister(&omap_dss_driver);
585
586 return r;
587 }
588
589 static void __exit omap_dss_unregister_drivers(void)
590 {
591 int i;
592
593 for (i = 0; i < ARRAY_SIZE(dss_output_drv_unreg_funcs); ++i) {
594 if (dss_output_drv_loaded[i])
595 dss_output_drv_unreg_funcs[i]();
596 }
597
598 dispc_uninit_platform_driver();
599 dss_uninit_platform_driver();
600
601 platform_driver_unregister(&omap_dss_driver);
602 }
603
604 #ifdef CONFIG_OMAP2_DSS_MODULE
605 static void omap_dss_bus_unregister(void)
606 {
607 device_unregister(&dss_bus);
608
609 bus_unregister(&dss_bus_type);
610 }
611
612 static int __init omap_dss_init(void)
613 {
614 int r;
615
616 r = omap_dss_bus_register();
617 if (r)
618 return r;
619
620 r = omap_dss_register_drivers();
621 if (r) {
622 omap_dss_bus_unregister();
623 return r;
624 }
625
626 return 0;
627 }
628
629 static void __exit omap_dss_exit(void)
630 {
631 if (core.vdds_dsi_reg != NULL) {
632 regulator_put(core.vdds_dsi_reg);
633 core.vdds_dsi_reg = NULL;
634 }
635
636 if (core.vdds_sdi_reg != NULL) {
637 regulator_put(core.vdds_sdi_reg);
638 core.vdds_sdi_reg = NULL;
639 }
640
641 omap_dss_unregister_drivers();
642
643 omap_dss_bus_unregister();
644 }
645
646 module_init(omap_dss_init);
647 module_exit(omap_dss_exit);
648 #else
649 static int __init omap_dss_init(void)
650 {
651 return omap_dss_bus_register();
652 }
653
654 static int __init omap_dss_init2(void)
655 {
656 return omap_dss_register_drivers();
657 }
658
659 core_initcall(omap_dss_init);
660 device_initcall(omap_dss_init2);
661 #endif
662
663 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
664 MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
665 MODULE_LICENSE("GPL v2");
666