OMAP: DSS2: Remove FB_OMAP_BOOTLOADER_INIT support
[pandora-kernel.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
36 #include <plat/display.h>
37
38 #include "dss.h"
39 #include "dss_features.h"
40
41 static struct {
42         struct platform_device *pdev;
43
44         struct regulator *vdds_dsi_reg;
45         struct regulator *vdds_sdi_reg;
46 } core;
47
48 static char *def_disp_name;
49 module_param_named(def_disp, def_disp_name, charp, 0);
50 MODULE_PARM_DESC(def_disp, "default display name");
51
52 #ifdef DEBUG
53 unsigned int dss_debug;
54 module_param_named(debug, dss_debug, bool, 0644);
55 #endif
56
57 /* REGULATORS */
58
59 struct regulator *dss_get_vdds_dsi(void)
60 {
61         struct regulator *reg;
62
63         if (core.vdds_dsi_reg != NULL)
64                 return core.vdds_dsi_reg;
65
66         reg = regulator_get(&core.pdev->dev, "vdds_dsi");
67         if (!IS_ERR(reg))
68                 core.vdds_dsi_reg = reg;
69
70         return reg;
71 }
72
73 struct regulator *dss_get_vdds_sdi(void)
74 {
75         struct regulator *reg;
76
77         if (core.vdds_sdi_reg != NULL)
78                 return core.vdds_sdi_reg;
79
80         reg = regulator_get(&core.pdev->dev, "vdds_sdi");
81         if (!IS_ERR(reg))
82                 core.vdds_sdi_reg = reg;
83
84         return reg;
85 }
86
87 #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
88 static int dss_debug_show(struct seq_file *s, void *unused)
89 {
90         void (*func)(struct seq_file *) = s->private;
91         func(s);
92         return 0;
93 }
94
95 static int dss_debug_open(struct inode *inode, struct file *file)
96 {
97         return single_open(file, dss_debug_show, inode->i_private);
98 }
99
100 static const struct file_operations dss_debug_fops = {
101         .open           = dss_debug_open,
102         .read           = seq_read,
103         .llseek         = seq_lseek,
104         .release        = single_release,
105 };
106
107 static struct dentry *dss_debugfs_dir;
108
109 static int dss_initialize_debugfs(void)
110 {
111         dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
112         if (IS_ERR(dss_debugfs_dir)) {
113                 int err = PTR_ERR(dss_debugfs_dir);
114                 dss_debugfs_dir = NULL;
115                 return err;
116         }
117
118         debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
119                         &dss_debug_dump_clocks, &dss_debug_fops);
120
121 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
122         debugfs_create_file("dispc_irq", S_IRUGO, dss_debugfs_dir,
123                         &dispc_dump_irqs, &dss_debug_fops);
124 #endif
125
126 #if defined(CONFIG_OMAP2_DSS_DSI) && defined(CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS)
127         debugfs_create_file("dsi_irq", S_IRUGO, dss_debugfs_dir,
128                         &dsi_dump_irqs, &dss_debug_fops);
129 #endif
130
131         debugfs_create_file("dss", S_IRUGO, dss_debugfs_dir,
132                         &dss_dump_regs, &dss_debug_fops);
133         debugfs_create_file("dispc", S_IRUGO, dss_debugfs_dir,
134                         &dispc_dump_regs, &dss_debug_fops);
135 #ifdef CONFIG_OMAP2_DSS_RFBI
136         debugfs_create_file("rfbi", S_IRUGO, dss_debugfs_dir,
137                         &rfbi_dump_regs, &dss_debug_fops);
138 #endif
139 #ifdef CONFIG_OMAP2_DSS_DSI
140         debugfs_create_file("dsi", S_IRUGO, dss_debugfs_dir,
141                         &dsi_dump_regs, &dss_debug_fops);
142 #endif
143 #ifdef CONFIG_OMAP2_DSS_VENC
144         debugfs_create_file("venc", S_IRUGO, dss_debugfs_dir,
145                         &venc_dump_regs, &dss_debug_fops);
146 #endif
147         return 0;
148 }
149
150 static void dss_uninitialize_debugfs(void)
151 {
152         if (dss_debugfs_dir)
153                 debugfs_remove_recursive(dss_debugfs_dir);
154 }
155 #else /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
156 static inline int dss_initialize_debugfs(void)
157 {
158         return 0;
159 }
160 static inline void dss_uninitialize_debugfs(void)
161 {
162 }
163 #endif /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
164
165 /* PLATFORM DEVICE */
166 static int omap_dss_probe(struct platform_device *pdev)
167 {
168         struct omap_dss_board_info *pdata = pdev->dev.platform_data;
169         int r;
170         int i;
171
172         core.pdev = pdev;
173
174         dss_features_init();
175
176         dss_init_overlay_managers(pdev);
177         dss_init_overlays(pdev);
178
179         r = dss_init_platform_driver();
180         if (r) {
181                 DSSERR("Failed to initialize DSS platform driver\n");
182                 goto err_dss;
183         }
184
185         /* keep clocks enabled to prevent context saves/restores during init */
186         dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
187
188         r = rfbi_init_platform_driver();
189         if (r) {
190                 DSSERR("Failed to initialize rfbi platform driver\n");
191                 goto err_rfbi;
192         }
193
194         r = dpi_init(pdev);
195         if (r) {
196                 DSSERR("Failed to initialize dpi\n");
197                 goto err_dpi;
198         }
199
200         r = dispc_init_platform_driver();
201         if (r) {
202                 DSSERR("Failed to initialize dispc platform driver\n");
203                 goto err_dispc;
204         }
205
206         r = venc_init_platform_driver();
207         if (r) {
208                 DSSERR("Failed to initialize venc platform driver\n");
209                 goto err_venc;
210         }
211
212         if (cpu_is_omap34xx()) {
213                 r = sdi_init();
214                 if (r) {
215                         DSSERR("Failed to initialize SDI\n");
216                         goto err_sdi;
217                 }
218
219                 r = dsi_init_platform_driver();
220                 if (r) {
221                         DSSERR("Failed to initialize DSI platform driver\n");
222                         goto err_dsi;
223                 }
224         }
225
226         r = dss_initialize_debugfs();
227         if (r)
228                 goto err_debugfs;
229
230         for (i = 0; i < pdata->num_devices; ++i) {
231                 struct omap_dss_device *dssdev = pdata->devices[i];
232
233                 r = omap_dss_register_device(dssdev);
234                 if (r) {
235                         DSSERR("device %d %s register failed %d\n", i,
236                                 dssdev->name ?: "unnamed", r);
237
238                         while (--i >= 0)
239                                 omap_dss_unregister_device(pdata->devices[i]);
240
241                         goto err_register;
242                 }
243
244                 if (def_disp_name && strcmp(def_disp_name, dssdev->name) == 0)
245                         pdata->default_device = dssdev;
246         }
247
248         dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
249
250         return 0;
251
252 err_register:
253         dss_uninitialize_debugfs();
254 err_debugfs:
255         if (cpu_is_omap34xx())
256                 dsi_uninit_platform_driver();
257 err_dsi:
258         if (cpu_is_omap34xx())
259                 sdi_exit();
260 err_sdi:
261         venc_uninit_platform_driver();
262 err_venc:
263         dispc_uninit_platform_driver();
264 err_dispc:
265         dpi_exit();
266 err_dpi:
267         rfbi_uninit_platform_driver();
268 err_rfbi:
269         dss_uninit_platform_driver();
270 err_dss:
271
272         return r;
273 }
274
275 static int omap_dss_remove(struct platform_device *pdev)
276 {
277         struct omap_dss_board_info *pdata = pdev->dev.platform_data;
278         int i;
279
280         dss_uninitialize_debugfs();
281
282         venc_uninit_platform_driver();
283         dispc_uninit_platform_driver();
284         dpi_exit();
285         rfbi_uninit_platform_driver();
286         if (cpu_is_omap34xx()) {
287                 dsi_uninit_platform_driver();
288                 sdi_exit();
289         }
290
291         dss_uninit_platform_driver();
292
293         dss_uninit_overlays(pdev);
294         dss_uninit_overlay_managers(pdev);
295
296         for (i = 0; i < pdata->num_devices; ++i)
297                 omap_dss_unregister_device(pdata->devices[i]);
298
299         return 0;
300 }
301
302 static void omap_dss_shutdown(struct platform_device *pdev)
303 {
304         DSSDBG("shutdown\n");
305         dss_disable_all_devices();
306 }
307
308 static int omap_dss_suspend(struct platform_device *pdev, pm_message_t state)
309 {
310         DSSDBG("suspend %d\n", state.event);
311
312         return dss_suspend_all_devices();
313 }
314
315 static int omap_dss_resume(struct platform_device *pdev)
316 {
317         DSSDBG("resume\n");
318
319         return dss_resume_all_devices();
320 }
321
322 static struct platform_driver omap_dss_driver = {
323         .probe          = omap_dss_probe,
324         .remove         = omap_dss_remove,
325         .shutdown       = omap_dss_shutdown,
326         .suspend        = omap_dss_suspend,
327         .resume         = omap_dss_resume,
328         .driver         = {
329                 .name   = "omapdss",
330                 .owner  = THIS_MODULE,
331         },
332 };
333
334 /* BUS */
335 static int dss_bus_match(struct device *dev, struct device_driver *driver)
336 {
337         struct omap_dss_device *dssdev = to_dss_device(dev);
338
339         DSSDBG("bus_match. dev %s/%s, drv %s\n",
340                         dev_name(dev), dssdev->driver_name, driver->name);
341
342         return strcmp(dssdev->driver_name, driver->name) == 0;
343 }
344
345 static ssize_t device_name_show(struct device *dev,
346                 struct device_attribute *attr, char *buf)
347 {
348         struct omap_dss_device *dssdev = to_dss_device(dev);
349         return snprintf(buf, PAGE_SIZE, "%s\n",
350                         dssdev->name ?
351                         dssdev->name : "");
352 }
353
354 static struct device_attribute default_dev_attrs[] = {
355         __ATTR(name, S_IRUGO, device_name_show, NULL),
356         __ATTR_NULL,
357 };
358
359 static ssize_t driver_name_show(struct device_driver *drv, char *buf)
360 {
361         struct omap_dss_driver *dssdrv = to_dss_driver(drv);
362         return snprintf(buf, PAGE_SIZE, "%s\n",
363                         dssdrv->driver.name ?
364                         dssdrv->driver.name : "");
365 }
366 static struct driver_attribute default_drv_attrs[] = {
367         __ATTR(name, S_IRUGO, driver_name_show, NULL),
368         __ATTR_NULL,
369 };
370
371 static struct bus_type dss_bus_type = {
372         .name = "omapdss",
373         .match = dss_bus_match,
374         .dev_attrs = default_dev_attrs,
375         .drv_attrs = default_drv_attrs,
376 };
377
378 static void dss_bus_release(struct device *dev)
379 {
380         DSSDBG("bus_release\n");
381 }
382
383 static struct device dss_bus = {
384         .release = dss_bus_release,
385 };
386
387 struct bus_type *dss_get_bus(void)
388 {
389         return &dss_bus_type;
390 }
391
392 /* DRIVER */
393 static int dss_driver_probe(struct device *dev)
394 {
395         int r;
396         struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
397         struct omap_dss_device *dssdev = to_dss_device(dev);
398         struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
399         bool force;
400
401         DSSDBG("driver_probe: dev %s/%s, drv %s\n",
402                                 dev_name(dev), dssdev->driver_name,
403                                 dssdrv->driver.name);
404
405         dss_init_device(core.pdev, dssdev);
406
407         force = pdata->default_device == dssdev;
408         dss_recheck_connections(dssdev, force);
409
410         r = dssdrv->probe(dssdev);
411
412         if (r) {
413                 DSSERR("driver probe failed: %d\n", r);
414                 dss_uninit_device(core.pdev, dssdev);
415                 return r;
416         }
417
418         DSSDBG("probe done for device %s\n", dev_name(dev));
419
420         dssdev->driver = dssdrv;
421
422         return 0;
423 }
424
425 static int dss_driver_remove(struct device *dev)
426 {
427         struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
428         struct omap_dss_device *dssdev = to_dss_device(dev);
429
430         DSSDBG("driver_remove: dev %s/%s\n", dev_name(dev),
431                         dssdev->driver_name);
432
433         dssdrv->remove(dssdev);
434
435         dss_uninit_device(core.pdev, dssdev);
436
437         dssdev->driver = NULL;
438
439         return 0;
440 }
441
442 int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
443 {
444         dssdriver->driver.bus = &dss_bus_type;
445         dssdriver->driver.probe = dss_driver_probe;
446         dssdriver->driver.remove = dss_driver_remove;
447
448         if (dssdriver->get_resolution == NULL)
449                 dssdriver->get_resolution = omapdss_default_get_resolution;
450         if (dssdriver->get_recommended_bpp == NULL)
451                 dssdriver->get_recommended_bpp =
452                         omapdss_default_get_recommended_bpp;
453
454         return driver_register(&dssdriver->driver);
455 }
456 EXPORT_SYMBOL(omap_dss_register_driver);
457
458 void omap_dss_unregister_driver(struct omap_dss_driver *dssdriver)
459 {
460         driver_unregister(&dssdriver->driver);
461 }
462 EXPORT_SYMBOL(omap_dss_unregister_driver);
463
464 /* DEVICE */
465 static void reset_device(struct device *dev, int check)
466 {
467         u8 *dev_p = (u8 *)dev;
468         u8 *dev_end = dev_p + sizeof(*dev);
469         void *saved_pdata;
470
471         saved_pdata = dev->platform_data;
472         if (check) {
473                 /*
474                  * Check if there is any other setting than platform_data
475                  * in struct device; warn that these will be reset by our
476                  * init.
477                  */
478                 dev->platform_data = NULL;
479                 while (dev_p < dev_end) {
480                         if (*dev_p) {
481                                 WARN("%s: struct device fields will be "
482                                                 "discarded\n",
483                                      __func__);
484                                 break;
485                         }
486                         dev_p++;
487                 }
488         }
489         memset(dev, 0, sizeof(*dev));
490         dev->platform_data = saved_pdata;
491 }
492
493
494 static void omap_dss_dev_release(struct device *dev)
495 {
496         reset_device(dev, 0);
497 }
498
499 int omap_dss_register_device(struct omap_dss_device *dssdev)
500 {
501         static int dev_num;
502
503         WARN_ON(!dssdev->driver_name);
504
505         reset_device(&dssdev->dev, 1);
506         dssdev->dev.bus = &dss_bus_type;
507         dssdev->dev.parent = &dss_bus;
508         dssdev->dev.release = omap_dss_dev_release;
509         dev_set_name(&dssdev->dev, "display%d", dev_num++);
510         return device_register(&dssdev->dev);
511 }
512
513 void omap_dss_unregister_device(struct omap_dss_device *dssdev)
514 {
515         device_unregister(&dssdev->dev);
516 }
517
518 /* BUS */
519 static int omap_dss_bus_register(void)
520 {
521         int r;
522
523         r = bus_register(&dss_bus_type);
524         if (r) {
525                 DSSERR("bus register failed\n");
526                 return r;
527         }
528
529         dev_set_name(&dss_bus, "omapdss");
530         r = device_register(&dss_bus);
531         if (r) {
532                 DSSERR("bus driver register failed\n");
533                 bus_unregister(&dss_bus_type);
534                 return r;
535         }
536
537         return 0;
538 }
539
540 /* INIT */
541
542 #ifdef CONFIG_OMAP2_DSS_MODULE
543 static void omap_dss_bus_unregister(void)
544 {
545         device_unregister(&dss_bus);
546
547         bus_unregister(&dss_bus_type);
548 }
549
550 static int __init omap_dss_init(void)
551 {
552         int r;
553
554         r = omap_dss_bus_register();
555         if (r)
556                 return r;
557
558         r = platform_driver_register(&omap_dss_driver);
559         if (r) {
560                 omap_dss_bus_unregister();
561                 return r;
562         }
563
564         return 0;
565 }
566
567 static void __exit omap_dss_exit(void)
568 {
569         if (core.vdds_dsi_reg != NULL) {
570                 regulator_put(core.vdds_dsi_reg);
571                 core.vdds_dsi_reg = NULL;
572         }
573
574         if (core.vdds_sdi_reg != NULL) {
575                 regulator_put(core.vdds_sdi_reg);
576                 core.vdds_sdi_reg = NULL;
577         }
578
579         platform_driver_unregister(&omap_dss_driver);
580
581         omap_dss_bus_unregister();
582 }
583
584 module_init(omap_dss_init);
585 module_exit(omap_dss_exit);
586 #else
587 static int __init omap_dss_init(void)
588 {
589         return omap_dss_bus_register();
590 }
591
592 static int __init omap_dss_init2(void)
593 {
594         return platform_driver_register(&omap_dss_driver);
595 }
596
597 core_initcall(omap_dss_init);
598 device_initcall(omap_dss_init2);
599 #endif
600
601 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
602 MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
603 MODULE_LICENSE("GPL v2");
604