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