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