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