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>
34 #include <linux/regulator/consumer.h>
35 #include <linux/suspend.h>
36 #include <linux/slab.h>
37 
38 #include <video/omapfb_dss.h>
39 
40 #include "dss.h"
41 #include "dss_features.h"
42 
43 static struct {
44 	struct platform_device *pdev;
45 
46 	const char *default_display_name;
47 } core;
48 
49 static char *def_disp_name;
50 module_param_named(def_disp, def_disp_name, charp, 0);
51 MODULE_PARM_DESC(def_disp, "default display name");
52 
omapdss_get_default_display_name(void)53 const char *omapdss_get_default_display_name(void)
54 {
55 	return core.default_display_name;
56 }
57 EXPORT_SYMBOL(omapdss_get_default_display_name);
58 
omapdss_get_version(void)59 enum omapdss_version omapdss_get_version(void)
60 {
61 	struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
62 	return pdata->version;
63 }
64 EXPORT_SYMBOL(omapdss_get_version);
65 
dss_get_core_pdev(void)66 struct platform_device *dss_get_core_pdev(void)
67 {
68 	return core.pdev;
69 }
70 
dss_dsi_enable_pads(int dsi_id,unsigned lane_mask)71 int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask)
72 {
73 	struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
74 
75 	if (!board_data->dsi_enable_pads)
76 		return -ENOENT;
77 
78 	return board_data->dsi_enable_pads(dsi_id, lane_mask);
79 }
80 
dss_dsi_disable_pads(int dsi_id,unsigned lane_mask)81 void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask)
82 {
83 	struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
84 
85 	if (!board_data->dsi_disable_pads)
86 		return;
87 
88 	return board_data->dsi_disable_pads(dsi_id, lane_mask);
89 }
90 
dss_set_min_bus_tput(struct device * dev,unsigned long tput)91 int dss_set_min_bus_tput(struct device *dev, unsigned long tput)
92 {
93 	struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
94 
95 	if (pdata->set_min_bus_tput)
96 		return pdata->set_min_bus_tput(dev, tput);
97 	else
98 		return 0;
99 }
100 
101 #if defined(CONFIG_FB_OMAP2_DSS_DEBUGFS)
dss_debug_show(struct seq_file * s,void * unused)102 static int dss_debug_show(struct seq_file *s, void *unused)
103 {
104 	void (*func)(struct seq_file *) = s->private;
105 	func(s);
106 	return 0;
107 }
108 
dss_debug_open(struct inode * inode,struct file * file)109 static int dss_debug_open(struct inode *inode, struct file *file)
110 {
111 	return single_open(file, dss_debug_show, inode->i_private);
112 }
113 
114 static const struct file_operations dss_debug_fops = {
115 	.open           = dss_debug_open,
116 	.read           = seq_read,
117 	.llseek         = seq_lseek,
118 	.release        = single_release,
119 };
120 
121 static struct dentry *dss_debugfs_dir;
122 
dss_initialize_debugfs(void)123 static int dss_initialize_debugfs(void)
124 {
125 	dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
126 	if (IS_ERR(dss_debugfs_dir)) {
127 		int err = PTR_ERR(dss_debugfs_dir);
128 		dss_debugfs_dir = NULL;
129 		return err;
130 	}
131 
132 	debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
133 			&dss_debug_dump_clocks, &dss_debug_fops);
134 
135 	return 0;
136 }
137 
dss_uninitialize_debugfs(void)138 static void dss_uninitialize_debugfs(void)
139 {
140 	debugfs_remove_recursive(dss_debugfs_dir);
141 }
142 
dss_debugfs_create_file(const char * name,void (* write)(struct seq_file *))143 int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
144 {
145 	struct dentry *d;
146 
147 	d = debugfs_create_file(name, S_IRUGO, dss_debugfs_dir,
148 			write, &dss_debug_fops);
149 
150 	return PTR_ERR_OR_ZERO(d);
151 }
152 #else /* CONFIG_FB_OMAP2_DSS_DEBUGFS */
dss_initialize_debugfs(void)153 static inline int dss_initialize_debugfs(void)
154 {
155 	return 0;
156 }
dss_uninitialize_debugfs(void)157 static inline void dss_uninitialize_debugfs(void)
158 {
159 }
dss_debugfs_create_file(const char * name,void (* write)(struct seq_file *))160 int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
161 {
162 	return 0;
163 }
164 #endif /* CONFIG_FB_OMAP2_DSS_DEBUGFS */
165 
166 /* PLATFORM DEVICE */
omap_dss_pm_notif(struct notifier_block * b,unsigned long v,void * d)167 static int omap_dss_pm_notif(struct notifier_block *b, unsigned long v, void *d)
168 {
169 	DSSDBG("pm notif %lu\n", v);
170 
171 	switch (v) {
172 	case PM_SUSPEND_PREPARE:
173 	case PM_HIBERNATION_PREPARE:
174 	case PM_RESTORE_PREPARE:
175 		DSSDBG("suspending displays\n");
176 		return dss_suspend_all_devices();
177 
178 	case PM_POST_SUSPEND:
179 	case PM_POST_HIBERNATION:
180 	case PM_POST_RESTORE:
181 		DSSDBG("resuming displays\n");
182 		return dss_resume_all_devices();
183 
184 	default:
185 		return 0;
186 	}
187 }
188 
189 static struct notifier_block omap_dss_pm_notif_block = {
190 	.notifier_call = omap_dss_pm_notif,
191 };
192 
omap_dss_probe(struct platform_device * pdev)193 static int __init omap_dss_probe(struct platform_device *pdev)
194 {
195 	int r;
196 
197 	core.pdev = pdev;
198 
199 	dss_features_init(omapdss_get_version());
200 
201 	r = dss_initialize_debugfs();
202 	if (r)
203 		goto err_debugfs;
204 
205 	if (def_disp_name)
206 		core.default_display_name = def_disp_name;
207 
208 	register_pm_notifier(&omap_dss_pm_notif_block);
209 
210 	return 0;
211 
212 err_debugfs:
213 
214 	return r;
215 }
216 
omap_dss_remove(struct platform_device * pdev)217 static int omap_dss_remove(struct platform_device *pdev)
218 {
219 	unregister_pm_notifier(&omap_dss_pm_notif_block);
220 
221 	dss_uninitialize_debugfs();
222 
223 	return 0;
224 }
225 
omap_dss_shutdown(struct platform_device * pdev)226 static void omap_dss_shutdown(struct platform_device *pdev)
227 {
228 	DSSDBG("shutdown\n");
229 	dss_disable_all_devices();
230 }
231 
232 static struct platform_driver omap_dss_driver = {
233 	.remove         = omap_dss_remove,
234 	.shutdown	= omap_dss_shutdown,
235 	.driver         = {
236 		.name   = "omapdss",
237 	},
238 };
239 
240 /* INIT */
241 static int (*dss_output_drv_reg_funcs[])(void) __initdata = {
242 	dss_init_platform_driver,
243 	dispc_init_platform_driver,
244 #ifdef CONFIG_FB_OMAP2_DSS_DSI
245 	dsi_init_platform_driver,
246 #endif
247 #ifdef CONFIG_FB_OMAP2_DSS_DPI
248 	dpi_init_platform_driver,
249 #endif
250 #ifdef CONFIG_FB_OMAP2_DSS_SDI
251 	sdi_init_platform_driver,
252 #endif
253 #ifdef CONFIG_FB_OMAP2_DSS_RFBI
254 	rfbi_init_platform_driver,
255 #endif
256 #ifdef CONFIG_FB_OMAP2_DSS_VENC
257 	venc_init_platform_driver,
258 #endif
259 #ifdef CONFIG_FB_OMAP4_DSS_HDMI
260 	hdmi4_init_platform_driver,
261 #endif
262 #ifdef CONFIG_FB_OMAP5_DSS_HDMI
263 	hdmi5_init_platform_driver,
264 #endif
265 };
266 
267 static void (*dss_output_drv_unreg_funcs[])(void) = {
268 #ifdef CONFIG_FB_OMAP5_DSS_HDMI
269 	hdmi5_uninit_platform_driver,
270 #endif
271 #ifdef CONFIG_FB_OMAP4_DSS_HDMI
272 	hdmi4_uninit_platform_driver,
273 #endif
274 #ifdef CONFIG_FB_OMAP2_DSS_VENC
275 	venc_uninit_platform_driver,
276 #endif
277 #ifdef CONFIG_FB_OMAP2_DSS_RFBI
278 	rfbi_uninit_platform_driver,
279 #endif
280 #ifdef CONFIG_FB_OMAP2_DSS_SDI
281 	sdi_uninit_platform_driver,
282 #endif
283 #ifdef CONFIG_FB_OMAP2_DSS_DPI
284 	dpi_uninit_platform_driver,
285 #endif
286 #ifdef CONFIG_FB_OMAP2_DSS_DSI
287 	dsi_uninit_platform_driver,
288 #endif
289 	dispc_uninit_platform_driver,
290 	dss_uninit_platform_driver,
291 };
292 
omap_dss_init(void)293 static int __init omap_dss_init(void)
294 {
295 	int r;
296 	int i;
297 
298 	r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
299 	if (r)
300 		return r;
301 
302 	for (i = 0; i < ARRAY_SIZE(dss_output_drv_reg_funcs); ++i) {
303 		r = dss_output_drv_reg_funcs[i]();
304 		if (r)
305 			goto err_reg;
306 	}
307 
308 	return 0;
309 
310 err_reg:
311 	for (i = ARRAY_SIZE(dss_output_drv_reg_funcs) - i;
312 			i < ARRAY_SIZE(dss_output_drv_reg_funcs);
313 			++i)
314 		dss_output_drv_unreg_funcs[i]();
315 
316 	platform_driver_unregister(&omap_dss_driver);
317 
318 	return r;
319 }
320 
omap_dss_exit(void)321 static void __exit omap_dss_exit(void)
322 {
323 	int i;
324 
325 	for (i = 0; i < ARRAY_SIZE(dss_output_drv_unreg_funcs); ++i)
326 		dss_output_drv_unreg_funcs[i]();
327 
328 	platform_driver_unregister(&omap_dss_driver);
329 }
330 
331 module_init(omap_dss_init);
332 module_exit(omap_dss_exit);
333 
334 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
335 MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
336 MODULE_LICENSE("GPL v2");
337 
338