core.c 7.5 KB

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