core.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. #define DSS_SUBSYS_NAME "CORE"
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/clk.h>
  26. #include <linux/err.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/seq_file.h>
  29. #include <linux/debugfs.h>
  30. #include <linux/io.h>
  31. #include <linux/device.h>
  32. #include <linux/regulator/consumer.h>
  33. #include <linux/suspend.h>
  34. #include <linux/slab.h>
  35. #include <video/omapdss.h>
  36. #include "dss.h"
  37. #include "dss_features.h"
  38. static struct {
  39. struct platform_device *pdev;
  40. const char *default_display_name;
  41. } core;
  42. static char *def_disp_name;
  43. module_param_named(def_disp, def_disp_name, charp, 0);
  44. MODULE_PARM_DESC(def_disp, "default display name");
  45. static bool dss_initialized;
  46. const char *omapdss_get_default_display_name(void)
  47. {
  48. return core.default_display_name;
  49. }
  50. EXPORT_SYMBOL(omapdss_get_default_display_name);
  51. enum omapdss_version omapdss_get_version(void)
  52. {
  53. struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
  54. return pdata->version;
  55. }
  56. EXPORT_SYMBOL(omapdss_get_version);
  57. bool omapdss_is_initialized(void)
  58. {
  59. return dss_initialized;
  60. }
  61. EXPORT_SYMBOL(omapdss_is_initialized);
  62. struct platform_device *dss_get_core_pdev(void)
  63. {
  64. return core.pdev;
  65. }
  66. int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask)
  67. {
  68. struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
  69. if (!board_data->dsi_enable_pads)
  70. return -ENOENT;
  71. return board_data->dsi_enable_pads(dsi_id, lane_mask);
  72. }
  73. void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask)
  74. {
  75. struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
  76. if (!board_data->dsi_disable_pads)
  77. return;
  78. return board_data->dsi_disable_pads(dsi_id, lane_mask);
  79. }
  80. int dss_set_min_bus_tput(struct device *dev, unsigned long tput)
  81. {
  82. struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
  83. if (pdata->set_min_bus_tput)
  84. return pdata->set_min_bus_tput(dev, tput);
  85. else
  86. return 0;
  87. }
  88. #if defined(CONFIG_OMAP2_DSS_DEBUGFS)
  89. static int dss_debug_show(struct seq_file *s, void *unused)
  90. {
  91. void (*func)(struct seq_file *) = s->private;
  92. func(s);
  93. return 0;
  94. }
  95. static int dss_debug_open(struct inode *inode, struct file *file)
  96. {
  97. return single_open(file, dss_debug_show, inode->i_private);
  98. }
  99. static const struct file_operations dss_debug_fops = {
  100. .open = dss_debug_open,
  101. .read = seq_read,
  102. .llseek = seq_lseek,
  103. .release = single_release,
  104. };
  105. static struct dentry *dss_debugfs_dir;
  106. static int dss_initialize_debugfs(void)
  107. {
  108. dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
  109. if (IS_ERR(dss_debugfs_dir)) {
  110. int err = PTR_ERR(dss_debugfs_dir);
  111. dss_debugfs_dir = NULL;
  112. return err;
  113. }
  114. debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
  115. &dss_debug_dump_clocks, &dss_debug_fops);
  116. return 0;
  117. }
  118. static void dss_uninitialize_debugfs(void)
  119. {
  120. if (dss_debugfs_dir)
  121. debugfs_remove_recursive(dss_debugfs_dir);
  122. }
  123. int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
  124. {
  125. struct dentry *d;
  126. d = debugfs_create_file(name, S_IRUGO, dss_debugfs_dir,
  127. write, &dss_debug_fops);
  128. return PTR_ERR_OR_ZERO(d);
  129. }
  130. #else /* CONFIG_OMAP2_DSS_DEBUGFS */
  131. static inline int dss_initialize_debugfs(void)
  132. {
  133. return 0;
  134. }
  135. static inline void dss_uninitialize_debugfs(void)
  136. {
  137. }
  138. int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
  139. {
  140. return 0;
  141. }
  142. #endif /* CONFIG_OMAP2_DSS_DEBUGFS */
  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. switch (v) {
  148. case PM_SUSPEND_PREPARE:
  149. DSSDBG("suspending displays\n");
  150. return dss_suspend_all_devices();
  151. case PM_POST_SUSPEND:
  152. DSSDBG("resuming displays\n");
  153. return dss_resume_all_devices();
  154. default:
  155. return 0;
  156. }
  157. }
  158. static struct notifier_block omap_dss_pm_notif_block = {
  159. .notifier_call = omap_dss_pm_notif,
  160. };
  161. static int __init omap_dss_probe(struct platform_device *pdev)
  162. {
  163. struct omap_dss_board_info *pdata = pdev->dev.platform_data;
  164. int r;
  165. core.pdev = pdev;
  166. dss_features_init(omapdss_get_version());
  167. r = dss_initialize_debugfs();
  168. if (r)
  169. goto err_debugfs;
  170. if (def_disp_name)
  171. core.default_display_name = def_disp_name;
  172. else if (pdata->default_display_name)
  173. core.default_display_name = pdata->default_display_name;
  174. else if (pdata->default_device)
  175. core.default_display_name = pdata->default_device->name;
  176. register_pm_notifier(&omap_dss_pm_notif_block);
  177. return 0;
  178. err_debugfs:
  179. return r;
  180. }
  181. static int omap_dss_remove(struct platform_device *pdev)
  182. {
  183. unregister_pm_notifier(&omap_dss_pm_notif_block);
  184. dss_uninitialize_debugfs();
  185. return 0;
  186. }
  187. static void omap_dss_shutdown(struct platform_device *pdev)
  188. {
  189. DSSDBG("shutdown\n");
  190. dss_disable_all_devices();
  191. }
  192. static struct platform_driver omap_dss_driver = {
  193. .remove = omap_dss_remove,
  194. .shutdown = omap_dss_shutdown,
  195. .driver = {
  196. .name = "omapdss",
  197. .owner = THIS_MODULE,
  198. },
  199. };
  200. /* INIT */
  201. static int (*dss_output_drv_reg_funcs[])(void) __initdata = {
  202. #ifdef CONFIG_OMAP2_DSS_DSI
  203. dsi_init_platform_driver,
  204. #endif
  205. #ifdef CONFIG_OMAP2_DSS_DPI
  206. dpi_init_platform_driver,
  207. #endif
  208. #ifdef CONFIG_OMAP2_DSS_SDI
  209. sdi_init_platform_driver,
  210. #endif
  211. #ifdef CONFIG_OMAP2_DSS_RFBI
  212. rfbi_init_platform_driver,
  213. #endif
  214. #ifdef CONFIG_OMAP2_DSS_VENC
  215. venc_init_platform_driver,
  216. #endif
  217. #ifdef CONFIG_OMAP4_DSS_HDMI
  218. hdmi_init_platform_driver,
  219. #endif
  220. };
  221. static void (*dss_output_drv_unreg_funcs[])(void) __exitdata = {
  222. #ifdef CONFIG_OMAP2_DSS_DSI
  223. dsi_uninit_platform_driver,
  224. #endif
  225. #ifdef CONFIG_OMAP2_DSS_DPI
  226. dpi_uninit_platform_driver,
  227. #endif
  228. #ifdef CONFIG_OMAP2_DSS_SDI
  229. sdi_uninit_platform_driver,
  230. #endif
  231. #ifdef CONFIG_OMAP2_DSS_RFBI
  232. rfbi_uninit_platform_driver,
  233. #endif
  234. #ifdef CONFIG_OMAP2_DSS_VENC
  235. venc_uninit_platform_driver,
  236. #endif
  237. #ifdef CONFIG_OMAP4_DSS_HDMI
  238. hdmi_uninit_platform_driver,
  239. #endif
  240. };
  241. static bool dss_output_drv_loaded[ARRAY_SIZE(dss_output_drv_reg_funcs)];
  242. static int __init omap_dss_init(void)
  243. {
  244. int r;
  245. int i;
  246. r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
  247. if (r)
  248. return r;
  249. r = dss_init_platform_driver();
  250. if (r) {
  251. DSSERR("Failed to initialize DSS platform driver\n");
  252. goto err_dss;
  253. }
  254. r = dispc_init_platform_driver();
  255. if (r) {
  256. DSSERR("Failed to initialize dispc platform driver\n");
  257. goto err_dispc;
  258. }
  259. /*
  260. * It's ok if the output-driver register fails. It happens, for example,
  261. * when there is no output-device (e.g. SDI for OMAP4).
  262. */
  263. for (i = 0; i < ARRAY_SIZE(dss_output_drv_reg_funcs); ++i) {
  264. r = dss_output_drv_reg_funcs[i]();
  265. if (r == 0)
  266. dss_output_drv_loaded[i] = true;
  267. }
  268. dss_initialized = true;
  269. return 0;
  270. err_dispc:
  271. dss_uninit_platform_driver();
  272. err_dss:
  273. platform_driver_unregister(&omap_dss_driver);
  274. return r;
  275. }
  276. static void __exit omap_dss_exit(void)
  277. {
  278. int i;
  279. for (i = 0; i < ARRAY_SIZE(dss_output_drv_unreg_funcs); ++i) {
  280. if (dss_output_drv_loaded[i])
  281. dss_output_drv_unreg_funcs[i]();
  282. }
  283. dispc_uninit_platform_driver();
  284. dss_uninit_platform_driver();
  285. platform_driver_unregister(&omap_dss_driver);
  286. }
  287. module_init(omap_dss_init);
  288. module_exit(omap_dss_exit);
  289. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  290. MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
  291. MODULE_LICENSE("GPL v2");