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