video: bf54x-lq043fb: fix build error
[deliverable/linux.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 45
c018c673 46 const char *default_display_name;
559d6701
TV
47} core;
48
559d6701
TV
49static char *def_disp_name;
50module_param_named(def_disp, def_disp_name, charp, 0);
ac425ed5 51MODULE_PARM_DESC(def_disp, "default display name");
559d6701 52
591a0ac7
TV
53static bool dss_initialized;
54
2bbcce5e 55const char *omapdss_get_default_display_name(void)
6a03fca9
TV
56{
57 return core.default_display_name;
58}
2bbcce5e 59EXPORT_SYMBOL(omapdss_get_default_display_name);
6a03fca9 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
591a0ac7
TV
68bool omapdss_is_initialized(void)
69{
70 return dss_initialized;
71}
72EXPORT_SYMBOL(omapdss_is_initialized);
73
8f46efad
TV
74struct platform_device *dss_get_core_pdev(void)
75{
76 return core.pdev;
77}
78
00928eaf
TV
79int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask)
80{
81 struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
82
83 if (!board_data->dsi_enable_pads)
84 return -ENOENT;
85
86 return board_data->dsi_enable_pads(dsi_id, lane_mask);
87}
88
89void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask)
90{
91 struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
92
da6c5687 93 if (!board_data->dsi_disable_pads)
00928eaf
TV
94 return;
95
96 return board_data->dsi_disable_pads(dsi_id, lane_mask);
97}
98
a8081d31
TV
99int dss_set_min_bus_tput(struct device *dev, unsigned long tput)
100{
101 struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
102
103 if (pdata->set_min_bus_tput)
104 return pdata->set_min_bus_tput(dev, tput);
105 else
106 return 0;
107}
108
1b3bcb33 109#if defined(CONFIG_OMAP2_DSS_DEBUGFS)
559d6701
TV
110static int dss_debug_show(struct seq_file *s, void *unused)
111{
112 void (*func)(struct seq_file *) = s->private;
113 func(s);
114 return 0;
115}
116
117static int dss_debug_open(struct inode *inode, struct file *file)
118{
119 return single_open(file, dss_debug_show, inode->i_private);
120}
121
122static const struct file_operations dss_debug_fops = {
123 .open = dss_debug_open,
124 .read = seq_read,
125 .llseek = seq_lseek,
126 .release = single_release,
127};
128
129static struct dentry *dss_debugfs_dir;
130
131static int dss_initialize_debugfs(void)
132{
133 dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
134 if (IS_ERR(dss_debugfs_dir)) {
135 int err = PTR_ERR(dss_debugfs_dir);
136 dss_debugfs_dir = NULL;
137 return err;
138 }
139
140 debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
141 &dss_debug_dump_clocks, &dss_debug_fops);
142
559d6701
TV
143 return 0;
144}
145
146static void dss_uninitialize_debugfs(void)
147{
148 if (dss_debugfs_dir)
149 debugfs_remove_recursive(dss_debugfs_dir);
150}
e40402cf
TV
151
152int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
153{
154 struct dentry *d;
155
156 d = debugfs_create_file(name, S_IRUGO, dss_debugfs_dir,
157 write, &dss_debug_fops);
158
8c6ffba0 159 return PTR_ERR_OR_ZERO(d);
e40402cf 160}
1b3bcb33 161#else /* CONFIG_OMAP2_DSS_DEBUGFS */
368a148e
JN
162static inline int dss_initialize_debugfs(void)
163{
164 return 0;
165}
166static inline void dss_uninitialize_debugfs(void)
167{
168}
0e9a126e 169int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
e40402cf
TV
170{
171 return 0;
172}
1b3bcb33 173#endif /* CONFIG_OMAP2_DSS_DEBUGFS */
559d6701
TV
174
175/* PLATFORM DEVICE */
736f29cd
TV
176static int omap_dss_pm_notif(struct notifier_block *b, unsigned long v, void *d)
177{
178 DSSDBG("pm notif %lu\n", v);
179
180 switch (v) {
181 case PM_SUSPEND_PREPARE:
182 DSSDBG("suspending displays\n");
183 return dss_suspend_all_devices();
184
185 case PM_POST_SUSPEND:
186 DSSDBG("resuming displays\n");
187 return dss_resume_all_devices();
188
189 default:
190 return 0;
191 }
192}
193
194static struct notifier_block omap_dss_pm_notif_block = {
195 .notifier_call = omap_dss_pm_notif,
196};
197
6e7e8f06 198static int __init omap_dss_probe(struct platform_device *pdev)
559d6701
TV
199{
200 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
559d6701 201 int r;
559d6701
TV
202
203 core.pdev = pdev;
204
b2c7d54f 205 dss_features_init(omapdss_get_version());
a0acb557 206
559d6701
TV
207 r = dss_initialize_debugfs();
208 if (r)
fce064cb 209 goto err_debugfs;
559d6701 210
c018c673
TV
211 if (def_disp_name)
212 core.default_display_name = def_disp_name;
0a200126
TV
213 else if (pdata->default_display_name)
214 core.default_display_name = pdata->default_display_name;
c018c673
TV
215 else if (pdata->default_device)
216 core.default_display_name = pdata->default_device->name;
217
736f29cd
TV
218 register_pm_notifier(&omap_dss_pm_notif_block);
219
559d6701
TV
220 return 0;
221
fce064cb 222err_debugfs:
fce064cb 223
559d6701
TV
224 return r;
225}
226
227static int omap_dss_remove(struct platform_device *pdev)
228{
736f29cd
TV
229 unregister_pm_notifier(&omap_dss_pm_notif_block);
230
559d6701 231 dss_uninitialize_debugfs();
559d6701 232
559d6701
TV
233 return 0;
234}
235
236static void omap_dss_shutdown(struct platform_device *pdev)
237{
238 DSSDBG("shutdown\n");
239 dss_disable_all_devices();
240}
241
559d6701 242static struct platform_driver omap_dss_driver = {
559d6701
TV
243 .remove = omap_dss_remove,
244 .shutdown = omap_dss_shutdown,
559d6701
TV
245 .driver = {
246 .name = "omapdss",
247 .owner = THIS_MODULE,
248 },
249};
250
559d6701 251/* INIT */
461395c4 252static int (*dss_output_drv_reg_funcs[])(void) __initdata = {
046bc575
TV
253#ifdef CONFIG_OMAP2_DSS_DSI
254 dsi_init_platform_driver,
255#endif
461395c4
TV
256#ifdef CONFIG_OMAP2_DSS_DPI
257 dpi_init_platform_driver,
258#endif
259#ifdef CONFIG_OMAP2_DSS_SDI
260 sdi_init_platform_driver,
261#endif
262#ifdef CONFIG_OMAP2_DSS_RFBI
263 rfbi_init_platform_driver,
264#endif
265#ifdef CONFIG_OMAP2_DSS_VENC
266 venc_init_platform_driver,
267#endif
461395c4 268#ifdef CONFIG_OMAP4_DSS_HDMI
ef26958a 269 hdmi4_init_platform_driver,
461395c4
TV
270#endif
271};
272
273static void (*dss_output_drv_unreg_funcs[])(void) __exitdata = {
046bc575
TV
274#ifdef CONFIG_OMAP2_DSS_DSI
275 dsi_uninit_platform_driver,
276#endif
461395c4
TV
277#ifdef CONFIG_OMAP2_DSS_DPI
278 dpi_uninit_platform_driver,
279#endif
280#ifdef CONFIG_OMAP2_DSS_SDI
281 sdi_uninit_platform_driver,
282#endif
283#ifdef CONFIG_OMAP2_DSS_RFBI
284 rfbi_uninit_platform_driver,
285#endif
286#ifdef CONFIG_OMAP2_DSS_VENC
287 venc_uninit_platform_driver,
288#endif
461395c4 289#ifdef CONFIG_OMAP4_DSS_HDMI
ef26958a 290 hdmi4_uninit_platform_driver,
461395c4
TV
291#endif
292};
293
294static bool dss_output_drv_loaded[ARRAY_SIZE(dss_output_drv_reg_funcs)];
559d6701 295
b3864299 296static int __init omap_dss_init(void)
dc7e57fa
TV
297{
298 int r;
461395c4 299 int i;
dc7e57fa 300
11436e1d 301 r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
dc7e57fa
TV
302 if (r)
303 return r;
304
305 r = dss_init_platform_driver();
306 if (r) {
307 DSSERR("Failed to initialize DSS platform driver\n");
308 goto err_dss;
309 }
310
311 r = dispc_init_platform_driver();
312 if (r) {
313 DSSERR("Failed to initialize dispc platform driver\n");
314 goto err_dispc;
315 }
316
461395c4
TV
317 /*
318 * It's ok if the output-driver register fails. It happens, for example,
319 * when there is no output-device (e.g. SDI for OMAP4).
320 */
321 for (i = 0; i < ARRAY_SIZE(dss_output_drv_reg_funcs); ++i) {
322 r = dss_output_drv_reg_funcs[i]();
323 if (r == 0)
324 dss_output_drv_loaded[i] = true;
dc7e57fa
TV
325 }
326
b3864299
TV
327 dss_initialized = true;
328
dc7e57fa
TV
329 return 0;
330
dc7e57fa
TV
331err_dispc:
332 dss_uninit_platform_driver();
333err_dss:
334 platform_driver_unregister(&omap_dss_driver);
335
336 return r;
337}
338
b3864299 339static void __exit omap_dss_exit(void)
dc7e57fa 340{
461395c4
TV
341 int i;
342
343 for (i = 0; i < ARRAY_SIZE(dss_output_drv_unreg_funcs); ++i) {
344 if (dss_output_drv_loaded[i])
345 dss_output_drv_unreg_funcs[i]();
346 }
347
dc7e57fa
TV
348 dispc_uninit_platform_driver();
349 dss_uninit_platform_driver();
350
351 platform_driver_unregister(&omap_dss_driver);
352}
353
559d6701
TV
354module_init(omap_dss_init);
355module_exit(omap_dss_exit);
559d6701
TV
356
357MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
358MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
359MODULE_LICENSE("GPL v2");
360
This page took 0.257707 seconds and 5 git commands to generate.