xref: /linux/drivers/video/fbdev/omap2/omapfb/dss/core.c (revision 260f6f4fda93c8485c8037865c941b42b9cba5d2)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * linux/drivers/video/omap2/dss/core.c
4  *
5  * Copyright (C) 2009 Nokia Corporation
6  * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
7  *
8  * Some code and ideas taken from drivers/video/omap/ driver
9  * by Imre Deak.
10  */
11 
12 #define DSS_SUBSYS_NAME "CORE"
13 
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/clk.h>
17 #include <linux/err.h>
18 #include <linux/export.h>
19 #include <linux/platform_device.h>
20 #include <linux/seq_file.h>
21 #include <linux/debugfs.h>
22 #include <linux/io.h>
23 #include <linux/device.h>
24 #include <linux/regulator/consumer.h>
25 #include <linux/suspend.h>
26 #include <linux/slab.h>
27 
28 #include <video/omapfb_dss.h>
29 
30 #include "dss.h"
31 #include "dss_features.h"
32 
33 static struct {
34 	struct platform_device *pdev;
35 
36 	const char *default_display_name;
37 } core;
38 
39 static char *def_disp_name;
40 module_param_named(def_disp, def_disp_name, charp, 0);
41 MODULE_PARM_DESC(def_disp, "default display name");
42 
omapdss_get_default_display_name(void)43 const char *omapdss_get_default_display_name(void)
44 {
45 	return core.default_display_name;
46 }
47 EXPORT_SYMBOL(omapdss_get_default_display_name);
48 
omapdss_get_version(void)49 enum omapdss_version omapdss_get_version(void)
50 {
51 	struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
52 	return pdata->version;
53 }
54 EXPORT_SYMBOL(omapdss_get_version);
55 
dss_get_core_pdev(void)56 struct platform_device *dss_get_core_pdev(void)
57 {
58 	return core.pdev;
59 }
60 
dss_dsi_enable_pads(int dsi_id,unsigned lane_mask)61 int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask)
62 {
63 	struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
64 
65 	if (!board_data->dsi_enable_pads)
66 		return -ENOENT;
67 
68 	return board_data->dsi_enable_pads(dsi_id, lane_mask);
69 }
70 
dss_dsi_disable_pads(int dsi_id,unsigned lane_mask)71 void dss_dsi_disable_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_disable_pads)
76 		return;
77 
78 	return board_data->dsi_disable_pads(dsi_id, lane_mask);
79 }
80 
dss_set_min_bus_tput(struct device * dev,unsigned long tput)81 int dss_set_min_bus_tput(struct device *dev, unsigned long tput)
82 {
83 	struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
84 
85 	if (pdata->set_min_bus_tput)
86 		return pdata->set_min_bus_tput(dev, tput);
87 	else
88 		return 0;
89 }
90 
91 #if defined(CONFIG_FB_OMAP2_DSS_DEBUGFS)
dss_show(struct seq_file * s,void * unused)92 static int dss_show(struct seq_file *s, void *unused)
93 {
94 	void (*func)(struct seq_file *) = s->private;
95 	func(s);
96 	return 0;
97 }
98 
99 DEFINE_SHOW_ATTRIBUTE(dss);
100 
101 static struct dentry *dss_debugfs_dir;
102 
dss_initialize_debugfs(void)103 static void dss_initialize_debugfs(void)
104 {
105 	dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
106 
107 	debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
108 			&dss_debug_dump_clocks, &dss_fops);
109 }
110 
dss_uninitialize_debugfs(void)111 static void dss_uninitialize_debugfs(void)
112 {
113 	debugfs_remove_recursive(dss_debugfs_dir);
114 }
115 
dss_debugfs_create_file(const char * name,void (* write)(struct seq_file *))116 void dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
117 {
118 	debugfs_create_file(name, S_IRUGO, dss_debugfs_dir, write, &dss_fops);
119 }
120 #else /* CONFIG_FB_OMAP2_DSS_DEBUGFS */
dss_initialize_debugfs(void)121 static inline void dss_initialize_debugfs(void)
122 {
123 }
dss_uninitialize_debugfs(void)124 static inline void dss_uninitialize_debugfs(void)
125 {
126 }
dss_debugfs_create_file(const char * name,void (* write)(struct seq_file *))127 void dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
128 {
129 }
130 #endif /* CONFIG_FB_OMAP2_DSS_DEBUGFS */
131 
132 /* PLATFORM DEVICE */
omap_dss_pm_notif(struct notifier_block * b,unsigned long v,void * d)133 static int omap_dss_pm_notif(struct notifier_block *b, unsigned long v, void *d)
134 {
135 	DSSDBG("pm notif %lu\n", v);
136 
137 	switch (v) {
138 	case PM_SUSPEND_PREPARE:
139 	case PM_HIBERNATION_PREPARE:
140 	case PM_RESTORE_PREPARE:
141 		DSSDBG("suspending displays\n");
142 		return dss_suspend_all_devices();
143 
144 	case PM_POST_SUSPEND:
145 	case PM_POST_HIBERNATION:
146 	case PM_POST_RESTORE:
147 		DSSDBG("resuming displays\n");
148 		return dss_resume_all_devices();
149 
150 	default:
151 		return 0;
152 	}
153 }
154 
155 static struct notifier_block omap_dss_pm_notif_block = {
156 	.notifier_call = omap_dss_pm_notif,
157 };
158 
omap_dss_probe(struct platform_device * pdev)159 static int __init omap_dss_probe(struct platform_device *pdev)
160 {
161 	core.pdev = pdev;
162 
163 	dss_features_init(omapdss_get_version());
164 
165 	dss_initialize_debugfs();
166 
167 	if (def_disp_name)
168 		core.default_display_name = def_disp_name;
169 
170 	register_pm_notifier(&omap_dss_pm_notif_block);
171 
172 	return 0;
173 }
174 
omap_dss_remove(struct platform_device * pdev)175 static void omap_dss_remove(struct platform_device *pdev)
176 {
177 	unregister_pm_notifier(&omap_dss_pm_notif_block);
178 
179 	dss_uninitialize_debugfs();
180 }
181 
omap_dss_shutdown(struct platform_device * pdev)182 static void omap_dss_shutdown(struct platform_device *pdev)
183 {
184 	DSSDBG("shutdown\n");
185 	dss_disable_all_devices();
186 }
187 
188 static struct platform_driver omap_dss_driver = {
189 	.remove		= omap_dss_remove,
190 	.shutdown	= omap_dss_shutdown,
191 	.driver		= {
192 		.name	= "omapdss",
193 	},
194 };
195 
196 /* INIT */
197 static int (*dss_output_drv_reg_funcs[])(void) __initdata = {
198 	dss_init_platform_driver,
199 	dispc_init_platform_driver,
200 #ifdef CONFIG_FB_OMAP2_DSS_DSI
201 	dsi_init_platform_driver,
202 #endif
203 #ifdef CONFIG_FB_OMAP2_DSS_DPI
204 	dpi_init_platform_driver,
205 #endif
206 #ifdef CONFIG_FB_OMAP2_DSS_SDI
207 	sdi_init_platform_driver,
208 #endif
209 #ifdef CONFIG_FB_OMAP2_DSS_VENC
210 	venc_init_platform_driver,
211 #endif
212 #ifdef CONFIG_FB_OMAP4_DSS_HDMI
213 	hdmi4_init_platform_driver,
214 #endif
215 #ifdef CONFIG_FB_OMAP5_DSS_HDMI
216 	hdmi5_init_platform_driver,
217 #endif
218 };
219 
220 static void (*dss_output_drv_unreg_funcs[])(void) = {
221 #ifdef CONFIG_FB_OMAP5_DSS_HDMI
222 	hdmi5_uninit_platform_driver,
223 #endif
224 #ifdef CONFIG_FB_OMAP4_DSS_HDMI
225 	hdmi4_uninit_platform_driver,
226 #endif
227 #ifdef CONFIG_FB_OMAP2_DSS_VENC
228 	venc_uninit_platform_driver,
229 #endif
230 #ifdef CONFIG_FB_OMAP2_DSS_SDI
231 	sdi_uninit_platform_driver,
232 #endif
233 #ifdef CONFIG_FB_OMAP2_DSS_DPI
234 	dpi_uninit_platform_driver,
235 #endif
236 #ifdef CONFIG_FB_OMAP2_DSS_DSI
237 	dsi_uninit_platform_driver,
238 #endif
239 	dispc_uninit_platform_driver,
240 	dss_uninit_platform_driver,
241 };
242 
omap_dss_init(void)243 static int __init omap_dss_init(void)
244 {
245 	int r;
246 	int i;
247 
248 	r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
249 	if (r)
250 		return r;
251 
252 	for (i = 0; i < ARRAY_SIZE(dss_output_drv_reg_funcs); ++i) {
253 		r = dss_output_drv_reg_funcs[i]();
254 		if (r)
255 			goto err_reg;
256 	}
257 
258 	return 0;
259 
260 err_reg:
261 	for (i = ARRAY_SIZE(dss_output_drv_reg_funcs) - i;
262 			i < ARRAY_SIZE(dss_output_drv_reg_funcs);
263 			++i)
264 		dss_output_drv_unreg_funcs[i]();
265 
266 	platform_driver_unregister(&omap_dss_driver);
267 
268 	return r;
269 }
270 
omap_dss_exit(void)271 static void __exit omap_dss_exit(void)
272 {
273 	int i;
274 
275 	for (i = 0; i < ARRAY_SIZE(dss_output_drv_unreg_funcs); ++i)
276 		dss_output_drv_unreg_funcs[i]();
277 
278 	platform_driver_unregister(&omap_dss_driver);
279 }
280 
281 module_init(omap_dss_init);
282 module_exit(omap_dss_exit);
283 
284 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
285 MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
286 MODULE_LICENSE("GPL v2");
287 
288