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