fbdev: omap2: no need to check return value of debugfs_create functions
[linux-2.6-microblaze.git] / drivers / video / fbdev / omap2 / omapfb / dss / core.c
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
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
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
66 struct platform_device *dss_get_core_pdev(void)
67 {
68         return core.pdev;
69 }
70
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
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
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)
102 static int dss_show(struct seq_file *s, void *unused)
103 {
104         void (*func)(struct seq_file *) = s->private;
105         func(s);
106         return 0;
107 }
108
109 DEFINE_SHOW_ATTRIBUTE(dss);
110
111 static struct dentry *dss_debugfs_dir;
112
113 static void dss_initialize_debugfs(void)
114 {
115         dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
116
117         debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
118                         &dss_debug_dump_clocks, &dss_fops);
119 }
120
121 static void dss_uninitialize_debugfs(void)
122 {
123         debugfs_remove_recursive(dss_debugfs_dir);
124 }
125
126 void dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
127 {
128         debugfs_create_file(name, S_IRUGO, dss_debugfs_dir, write, &dss_fops);
129 }
130 #else /* CONFIG_FB_OMAP2_DSS_DEBUGFS */
131 static inline void dss_initialize_debugfs(void)
132 {
133 }
134 static inline void dss_uninitialize_debugfs(void)
135 {
136 }
137 void dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
138 {
139         return 0;
140 }
141 #endif /* CONFIG_FB_OMAP2_DSS_DEBUGFS */
142
143 /* PLATFORM DEVICE */
144 static int omap_dss_pm_notif(struct notifier_block *b, unsigned long v, void *d)
145 {
146         DSSDBG("pm notif %lu\n", v);
147
148         switch (v) {
149         case PM_SUSPEND_PREPARE:
150         case PM_HIBERNATION_PREPARE:
151         case PM_RESTORE_PREPARE:
152                 DSSDBG("suspending displays\n");
153                 return dss_suspend_all_devices();
154
155         case PM_POST_SUSPEND:
156         case PM_POST_HIBERNATION:
157         case PM_POST_RESTORE:
158                 DSSDBG("resuming displays\n");
159                 return dss_resume_all_devices();
160
161         default:
162                 return 0;
163         }
164 }
165
166 static struct notifier_block omap_dss_pm_notif_block = {
167         .notifier_call = omap_dss_pm_notif,
168 };
169
170 static int __init omap_dss_probe(struct platform_device *pdev)
171 {
172         int r;
173
174         core.pdev = pdev;
175
176         dss_features_init(omapdss_get_version());
177
178         dss_initialize_debugfs();
179
180         if (def_disp_name)
181                 core.default_display_name = def_disp_name;
182
183         register_pm_notifier(&omap_dss_pm_notif_block);
184
185         return 0;
186 }
187
188 static int omap_dss_remove(struct platform_device *pdev)
189 {
190         unregister_pm_notifier(&omap_dss_pm_notif_block);
191
192         dss_uninitialize_debugfs();
193
194         return 0;
195 }
196
197 static void omap_dss_shutdown(struct platform_device *pdev)
198 {
199         DSSDBG("shutdown\n");
200         dss_disable_all_devices();
201 }
202
203 static struct platform_driver omap_dss_driver = {
204         .remove         = omap_dss_remove,
205         .shutdown       = omap_dss_shutdown,
206         .driver         = {
207                 .name   = "omapdss",
208         },
209 };
210
211 /* INIT */
212 static int (*dss_output_drv_reg_funcs[])(void) __initdata = {
213         dss_init_platform_driver,
214         dispc_init_platform_driver,
215 #ifdef CONFIG_FB_OMAP2_DSS_DSI
216         dsi_init_platform_driver,
217 #endif
218 #ifdef CONFIG_FB_OMAP2_DSS_DPI
219         dpi_init_platform_driver,
220 #endif
221 #ifdef CONFIG_FB_OMAP2_DSS_SDI
222         sdi_init_platform_driver,
223 #endif
224 #ifdef CONFIG_FB_OMAP2_DSS_RFBI
225         rfbi_init_platform_driver,
226 #endif
227 #ifdef CONFIG_FB_OMAP2_DSS_VENC
228         venc_init_platform_driver,
229 #endif
230 #ifdef CONFIG_FB_OMAP4_DSS_HDMI
231         hdmi4_init_platform_driver,
232 #endif
233 #ifdef CONFIG_FB_OMAP5_DSS_HDMI
234         hdmi5_init_platform_driver,
235 #endif
236 };
237
238 static void (*dss_output_drv_unreg_funcs[])(void) = {
239 #ifdef CONFIG_FB_OMAP5_DSS_HDMI
240         hdmi5_uninit_platform_driver,
241 #endif
242 #ifdef CONFIG_FB_OMAP4_DSS_HDMI
243         hdmi4_uninit_platform_driver,
244 #endif
245 #ifdef CONFIG_FB_OMAP2_DSS_VENC
246         venc_uninit_platform_driver,
247 #endif
248 #ifdef CONFIG_FB_OMAP2_DSS_RFBI
249         rfbi_uninit_platform_driver,
250 #endif
251 #ifdef CONFIG_FB_OMAP2_DSS_SDI
252         sdi_uninit_platform_driver,
253 #endif
254 #ifdef CONFIG_FB_OMAP2_DSS_DPI
255         dpi_uninit_platform_driver,
256 #endif
257 #ifdef CONFIG_FB_OMAP2_DSS_DSI
258         dsi_uninit_platform_driver,
259 #endif
260         dispc_uninit_platform_driver,
261         dss_uninit_platform_driver,
262 };
263
264 static int __init omap_dss_init(void)
265 {
266         int r;
267         int i;
268
269         r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
270         if (r)
271                 return r;
272
273         for (i = 0; i < ARRAY_SIZE(dss_output_drv_reg_funcs); ++i) {
274                 r = dss_output_drv_reg_funcs[i]();
275                 if (r)
276                         goto err_reg;
277         }
278
279         return 0;
280
281 err_reg:
282         for (i = ARRAY_SIZE(dss_output_drv_reg_funcs) - i;
283                         i < ARRAY_SIZE(dss_output_drv_reg_funcs);
284                         ++i)
285                 dss_output_drv_unreg_funcs[i]();
286
287         platform_driver_unregister(&omap_dss_driver);
288
289         return r;
290 }
291
292 static void __exit omap_dss_exit(void)
293 {
294         int i;
295
296         for (i = 0; i < ARRAY_SIZE(dss_output_drv_unreg_funcs); ++i)
297                 dss_output_drv_unreg_funcs[i]();
298
299         platform_driver_unregister(&omap_dss_driver);
300 }
301
302 module_init(omap_dss_init);
303 module_exit(omap_dss_exit);
304
305 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
306 MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
307 MODULE_LICENSE("GPL v2");
308