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