Merge tag 'timer' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
[deliverable/linux.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>
736f29cd 35#include <linux/suspend.h>
559d6701 36
a0b38cc4 37#include <video/omapdss.h>
559d6701
TV
38
39#include "dss.h"
a0acb557 40#include "dss_features.h"
559d6701
TV
41
42static struct {
43 struct platform_device *pdev;
8a2cfea8
TV
44
45 struct regulator *vdds_dsi_reg;
46 struct regulator *vdds_sdi_reg;
c018c673
TV
47
48 const char *default_display_name;
559d6701
TV
49} core;
50
559d6701
TV
51static char *def_disp_name;
52module_param_named(def_disp, def_disp_name, charp, 0);
ac425ed5 53MODULE_PARM_DESC(def_disp, "default display name");
559d6701
TV
54
55#ifdef DEBUG
90ab5ee9 56bool dss_debug;
559d6701
TV
57module_param_named(debug, dss_debug, bool, 0644);
58#endif
59
8a2cfea8
TV
60/* REGULATORS */
61
62struct 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
76struct 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
00928eaf
TV
90int dss_get_ctx_loss_count(struct device *dev)
91{
92 struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
93 int cnt;
94
95 if (!board_data->get_context_loss_count)
96 return -ENOENT;
97
98 cnt = board_data->get_context_loss_count(dev);
99
100 WARN_ONCE(cnt < 0, "get_context_loss_count failed: %d\n", cnt);
101
102 return cnt;
103}
104
105int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask)
106{
107 struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
108
109 if (!board_data->dsi_enable_pads)
110 return -ENOENT;
111
112 return board_data->dsi_enable_pads(dsi_id, lane_mask);
113}
114
115void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask)
116{
117 struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
118
119 if (!board_data->dsi_enable_pads)
120 return;
121
122 return board_data->dsi_disable_pads(dsi_id, lane_mask);
123}
124
a8081d31
TV
125int dss_set_min_bus_tput(struct device *dev, unsigned long tput)
126{
127 struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
128
129 if (pdata->set_min_bus_tput)
130 return pdata->set_min_bus_tput(dev, tput);
131 else
132 return 0;
133}
134
559d6701 135#if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
559d6701
TV
136static int dss_debug_show(struct seq_file *s, void *unused)
137{
138 void (*func)(struct seq_file *) = s->private;
139 func(s);
140 return 0;
141}
142
143static int dss_debug_open(struct inode *inode, struct file *file)
144{
145 return single_open(file, dss_debug_show, inode->i_private);
146}
147
148static const struct file_operations dss_debug_fops = {
149 .open = dss_debug_open,
150 .read = seq_read,
151 .llseek = seq_lseek,
152 .release = single_release,
153};
154
155static struct dentry *dss_debugfs_dir;
156
157static int dss_initialize_debugfs(void)
158{
159 dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
160 if (IS_ERR(dss_debugfs_dir)) {
161 int err = PTR_ERR(dss_debugfs_dir);
162 dss_debugfs_dir = NULL;
163 return err;
164 }
165
166 debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
167 &dss_debug_dump_clocks, &dss_debug_fops);
168
559d6701
TV
169 return 0;
170}
171
172static void dss_uninitialize_debugfs(void)
173{
174 if (dss_debugfs_dir)
175 debugfs_remove_recursive(dss_debugfs_dir);
176}
e40402cf
TV
177
178int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
179{
180 struct dentry *d;
181
182 d = debugfs_create_file(name, S_IRUGO, dss_debugfs_dir,
183 write, &dss_debug_fops);
184
185 if (IS_ERR(d))
186 return PTR_ERR(d);
187
188 return 0;
189}
368a148e
JN
190#else /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
191static inline int dss_initialize_debugfs(void)
192{
193 return 0;
194}
195static inline void dss_uninitialize_debugfs(void)
196{
197}
0e9a126e 198int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
e40402cf
TV
199{
200 return 0;
201}
559d6701
TV
202#endif /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
203
204/* PLATFORM DEVICE */
736f29cd
TV
205static int omap_dss_pm_notif(struct notifier_block *b, unsigned long v, void *d)
206{
207 DSSDBG("pm notif %lu\n", v);
208
209 switch (v) {
210 case PM_SUSPEND_PREPARE:
211 DSSDBG("suspending displays\n");
212 return dss_suspend_all_devices();
213
214 case PM_POST_SUSPEND:
215 DSSDBG("resuming displays\n");
216 return dss_resume_all_devices();
217
218 default:
219 return 0;
220 }
221}
222
223static struct notifier_block omap_dss_pm_notif_block = {
224 .notifier_call = omap_dss_pm_notif,
225};
226
6e7e8f06 227static int __init omap_dss_probe(struct platform_device *pdev)
559d6701
TV
228{
229 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
559d6701 230 int r;
559d6701
TV
231
232 core.pdev = pdev;
233
a0acb557
AT
234 dss_features_init();
235
58f25548
TV
236 dss_apply_init();
237
559d6701
TV
238 dss_init_overlay_managers(pdev);
239 dss_init_overlays(pdev);
240
559d6701
TV
241 r = dss_initialize_debugfs();
242 if (r)
fce064cb 243 goto err_debugfs;
559d6701 244
c018c673
TV
245 if (def_disp_name)
246 core.default_display_name = def_disp_name;
247 else if (pdata->default_device)
248 core.default_display_name = pdata->default_device->name;
249
736f29cd
TV
250 register_pm_notifier(&omap_dss_pm_notif_block);
251
559d6701
TV
252 return 0;
253
fce064cb 254err_debugfs:
fce064cb 255
559d6701
TV
256 return r;
257}
258
259static int omap_dss_remove(struct platform_device *pdev)
260{
736f29cd
TV
261 unregister_pm_notifier(&omap_dss_pm_notif_block);
262
559d6701 263 dss_uninitialize_debugfs();
559d6701 264
559d6701
TV
265 dss_uninit_overlays(pdev);
266 dss_uninit_overlay_managers(pdev);
267
559d6701
TV
268 return 0;
269}
270
271static void omap_dss_shutdown(struct platform_device *pdev)
272{
273 DSSDBG("shutdown\n");
274 dss_disable_all_devices();
275}
276
559d6701 277static struct platform_driver omap_dss_driver = {
559d6701
TV
278 .remove = omap_dss_remove,
279 .shutdown = omap_dss_shutdown,
559d6701
TV
280 .driver = {
281 .name = "omapdss",
282 .owner = THIS_MODULE,
283 },
284};
285
286/* BUS */
287static int dss_bus_match(struct device *dev, struct device_driver *driver)
288{
289 struct omap_dss_device *dssdev = to_dss_device(dev);
290
291 DSSDBG("bus_match. dev %s/%s, drv %s\n",
292 dev_name(dev), dssdev->driver_name, driver->name);
293
294 return strcmp(dssdev->driver_name, driver->name) == 0;
295}
296
297static ssize_t device_name_show(struct device *dev,
298 struct device_attribute *attr, char *buf)
299{
300 struct omap_dss_device *dssdev = to_dss_device(dev);
301 return snprintf(buf, PAGE_SIZE, "%s\n",
302 dssdev->name ?
303 dssdev->name : "");
304}
305
306static struct device_attribute default_dev_attrs[] = {
307 __ATTR(name, S_IRUGO, device_name_show, NULL),
308 __ATTR_NULL,
309};
310
311static ssize_t driver_name_show(struct device_driver *drv, char *buf)
312{
313 struct omap_dss_driver *dssdrv = to_dss_driver(drv);
314 return snprintf(buf, PAGE_SIZE, "%s\n",
315 dssdrv->driver.name ?
316 dssdrv->driver.name : "");
317}
318static struct driver_attribute default_drv_attrs[] = {
319 __ATTR(name, S_IRUGO, driver_name_show, NULL),
320 __ATTR_NULL,
321};
322
323static struct bus_type dss_bus_type = {
324 .name = "omapdss",
325 .match = dss_bus_match,
326 .dev_attrs = default_dev_attrs,
327 .drv_attrs = default_drv_attrs,
328};
329
330static void dss_bus_release(struct device *dev)
331{
332 DSSDBG("bus_release\n");
333}
334
335static struct device dss_bus = {
336 .release = dss_bus_release,
337};
338
339struct bus_type *dss_get_bus(void)
340{
341 return &dss_bus_type;
342}
343
344/* DRIVER */
345static int dss_driver_probe(struct device *dev)
346{
347 int r;
348 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
349 struct omap_dss_device *dssdev = to_dss_device(dev);
559d6701
TV
350 bool force;
351
352 DSSDBG("driver_probe: dev %s/%s, drv %s\n",
353 dev_name(dev), dssdev->driver_name,
354 dssdrv->driver.name);
355
356 dss_init_device(core.pdev, dssdev);
357
c018c673
TV
358 force = core.default_display_name &&
359 strcmp(core.default_display_name, dssdev->name) == 0;
e020f9af 360 dss_recheck_connections(dssdev, force);
559d6701
TV
361
362 r = dssdrv->probe(dssdev);
363
364 if (r) {
365 DSSERR("driver probe failed: %d\n", r);
c121b152 366 dss_uninit_device(core.pdev, dssdev);
559d6701
TV
367 return r;
368 }
369
370 DSSDBG("probe done for device %s\n", dev_name(dev));
371
372 dssdev->driver = dssdrv;
373
374 return 0;
375}
376
377static int dss_driver_remove(struct device *dev)
378{
379 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
380 struct omap_dss_device *dssdev = to_dss_device(dev);
381
382 DSSDBG("driver_remove: dev %s/%s\n", dev_name(dev),
383 dssdev->driver_name);
384
385 dssdrv->remove(dssdev);
386
387 dss_uninit_device(core.pdev, dssdev);
388
389 dssdev->driver = NULL;
390
391 return 0;
392}
393
394int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
395{
396 dssdriver->driver.bus = &dss_bus_type;
397 dssdriver->driver.probe = dss_driver_probe;
398 dssdriver->driver.remove = dss_driver_remove;
96adcece
TV
399
400 if (dssdriver->get_resolution == NULL)
401 dssdriver->get_resolution = omapdss_default_get_resolution;
a2699504
TV
402 if (dssdriver->get_recommended_bpp == NULL)
403 dssdriver->get_recommended_bpp =
404 omapdss_default_get_recommended_bpp;
4b6430fc
GI
405 if (dssdriver->get_timings == NULL)
406 dssdriver->get_timings = omapdss_default_get_timings;
96adcece 407
559d6701
TV
408 return driver_register(&dssdriver->driver);
409}
410EXPORT_SYMBOL(omap_dss_register_driver);
411
412void omap_dss_unregister_driver(struct omap_dss_driver *dssdriver)
413{
414 driver_unregister(&dssdriver->driver);
415}
416EXPORT_SYMBOL(omap_dss_unregister_driver);
417
418/* DEVICE */
419static void reset_device(struct device *dev, int check)
420{
421 u8 *dev_p = (u8 *)dev;
422 u8 *dev_end = dev_p + sizeof(*dev);
423 void *saved_pdata;
424
425 saved_pdata = dev->platform_data;
426 if (check) {
427 /*
428 * Check if there is any other setting than platform_data
429 * in struct device; warn that these will be reset by our
430 * init.
431 */
432 dev->platform_data = NULL;
433 while (dev_p < dev_end) {
434 if (*dev_p) {
435 WARN("%s: struct device fields will be "
436 "discarded\n",
437 __func__);
438 break;
439 }
440 dev_p++;
441 }
442 }
443 memset(dev, 0, sizeof(*dev));
444 dev->platform_data = saved_pdata;
445}
446
447
448static void omap_dss_dev_release(struct device *dev)
449{
450 reset_device(dev, 0);
451}
452
35deca3d
TV
453int omap_dss_register_device(struct omap_dss_device *dssdev,
454 struct device *parent, int disp_num)
559d6701 455{
559d6701
TV
456 WARN_ON(!dssdev->driver_name);
457
458 reset_device(&dssdev->dev, 1);
459 dssdev->dev.bus = &dss_bus_type;
35deca3d 460 dssdev->dev.parent = parent;
559d6701 461 dssdev->dev.release = omap_dss_dev_release;
35deca3d 462 dev_set_name(&dssdev->dev, "display%d", disp_num);
e020f9af 463 return device_register(&dssdev->dev);
559d6701
TV
464}
465
35deca3d 466void omap_dss_unregister_device(struct omap_dss_device *dssdev)
559d6701
TV
467{
468 device_unregister(&dssdev->dev);
559d6701
TV
469}
470
35deca3d
TV
471static int dss_unregister_dss_dev(struct device *dev, void *data)
472{
473 struct omap_dss_device *dssdev = to_dss_device(dev);
474 omap_dss_unregister_device(dssdev);
475 return 0;
476}
477
478void omap_dss_unregister_child_devices(struct device *parent)
479{
480 device_for_each_child(parent, NULL, dss_unregister_dss_dev);
481}
482
559d6701 483/* BUS */
6e7e8f06 484static int __init omap_dss_bus_register(void)
559d6701
TV
485{
486 int r;
487
488 r = bus_register(&dss_bus_type);
489 if (r) {
490 DSSERR("bus register failed\n");
491 return r;
492 }
493
494 dev_set_name(&dss_bus, "omapdss");
495 r = device_register(&dss_bus);
496 if (r) {
497 DSSERR("bus driver register failed\n");
498 bus_unregister(&dss_bus_type);
499 return r;
500 }
501
502 return 0;
503}
504
505/* INIT */
461395c4
TV
506static int (*dss_output_drv_reg_funcs[])(void) __initdata = {
507#ifdef CONFIG_OMAP2_DSS_DPI
508 dpi_init_platform_driver,
509#endif
510#ifdef CONFIG_OMAP2_DSS_SDI
511 sdi_init_platform_driver,
512#endif
513#ifdef CONFIG_OMAP2_DSS_RFBI
514 rfbi_init_platform_driver,
515#endif
516#ifdef CONFIG_OMAP2_DSS_VENC
517 venc_init_platform_driver,
518#endif
519#ifdef CONFIG_OMAP2_DSS_DSI
520 dsi_init_platform_driver,
521#endif
522#ifdef CONFIG_OMAP4_DSS_HDMI
523 hdmi_init_platform_driver,
524#endif
525};
526
527static void (*dss_output_drv_unreg_funcs[])(void) __exitdata = {
528#ifdef CONFIG_OMAP2_DSS_DPI
529 dpi_uninit_platform_driver,
530#endif
531#ifdef CONFIG_OMAP2_DSS_SDI
532 sdi_uninit_platform_driver,
533#endif
534#ifdef CONFIG_OMAP2_DSS_RFBI
535 rfbi_uninit_platform_driver,
536#endif
537#ifdef CONFIG_OMAP2_DSS_VENC
538 venc_uninit_platform_driver,
539#endif
540#ifdef CONFIG_OMAP2_DSS_DSI
541 dsi_uninit_platform_driver,
542#endif
543#ifdef CONFIG_OMAP4_DSS_HDMI
544 hdmi_uninit_platform_driver,
545#endif
546};
547
548static bool dss_output_drv_loaded[ARRAY_SIZE(dss_output_drv_reg_funcs)];
559d6701 549
dc7e57fa
TV
550static int __init omap_dss_register_drivers(void)
551{
552 int r;
461395c4 553 int i;
dc7e57fa 554
11436e1d 555 r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
dc7e57fa
TV
556 if (r)
557 return r;
558
559 r = dss_init_platform_driver();
560 if (r) {
561 DSSERR("Failed to initialize DSS platform driver\n");
562 goto err_dss;
563 }
564
565 r = dispc_init_platform_driver();
566 if (r) {
567 DSSERR("Failed to initialize dispc platform driver\n");
568 goto err_dispc;
569 }
570
461395c4
TV
571 /*
572 * It's ok if the output-driver register fails. It happens, for example,
573 * when there is no output-device (e.g. SDI for OMAP4).
574 */
575 for (i = 0; i < ARRAY_SIZE(dss_output_drv_reg_funcs); ++i) {
576 r = dss_output_drv_reg_funcs[i]();
577 if (r == 0)
578 dss_output_drv_loaded[i] = true;
dc7e57fa
TV
579 }
580
581 return 0;
582
dc7e57fa
TV
583err_dispc:
584 dss_uninit_platform_driver();
585err_dss:
586 platform_driver_unregister(&omap_dss_driver);
587
588 return r;
589}
590
591static void __exit omap_dss_unregister_drivers(void)
592{
461395c4
TV
593 int i;
594
595 for (i = 0; i < ARRAY_SIZE(dss_output_drv_unreg_funcs); ++i) {
596 if (dss_output_drv_loaded[i])
597 dss_output_drv_unreg_funcs[i]();
598 }
599
dc7e57fa
TV
600 dispc_uninit_platform_driver();
601 dss_uninit_platform_driver();
602
603 platform_driver_unregister(&omap_dss_driver);
604}
605
559d6701
TV
606#ifdef CONFIG_OMAP2_DSS_MODULE
607static void omap_dss_bus_unregister(void)
608{
609 device_unregister(&dss_bus);
610
611 bus_unregister(&dss_bus_type);
612}
613
614static int __init omap_dss_init(void)
615{
616 int r;
617
618 r = omap_dss_bus_register();
619 if (r)
620 return r;
621
dc7e57fa 622 r = omap_dss_register_drivers();
559d6701
TV
623 if (r) {
624 omap_dss_bus_unregister();
625 return r;
626 }
627
628 return 0;
629}
630
631static void __exit omap_dss_exit(void)
632{
8a2cfea8
TV
633 if (core.vdds_dsi_reg != NULL) {
634 regulator_put(core.vdds_dsi_reg);
635 core.vdds_dsi_reg = NULL;
636 }
637
638 if (core.vdds_sdi_reg != NULL) {
639 regulator_put(core.vdds_sdi_reg);
640 core.vdds_sdi_reg = NULL;
641 }
642
dc7e57fa 643 omap_dss_unregister_drivers();
559d6701
TV
644
645 omap_dss_bus_unregister();
646}
647
648module_init(omap_dss_init);
649module_exit(omap_dss_exit);
650#else
651static int __init omap_dss_init(void)
652{
653 return omap_dss_bus_register();
654}
655
656static int __init omap_dss_init2(void)
657{
dc7e57fa 658 return omap_dss_register_drivers();
559d6701
TV
659}
660
661core_initcall(omap_dss_init);
662device_initcall(omap_dss_init2);
663#endif
664
665MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
666MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
667MODULE_LICENSE("GPL v2");
668
This page took 0.189225 seconds and 5 git commands to generate.