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