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