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