core.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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 void dss_disable_all_devices(void)
  139. {
  140. struct omap_dss_device *dssdev = NULL;
  141. for_each_dss_dev(dssdev) {
  142. if (!dssdev->driver)
  143. continue;
  144. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  145. dssdev->driver->disable(dssdev);
  146. }
  147. }
  148. static int __init omap_dss_probe(struct platform_device *pdev)
  149. {
  150. struct omap_dss_board_info *pdata = pdev->dev.platform_data;
  151. int r;
  152. core.pdev = pdev;
  153. dss_features_init(omapdss_get_version());
  154. r = dss_initialize_debugfs();
  155. if (r)
  156. goto err_debugfs;
  157. if (def_disp_name)
  158. core.default_display_name = def_disp_name;
  159. else if (pdata->default_display_name)
  160. core.default_display_name = pdata->default_display_name;
  161. else if (pdata->default_device)
  162. core.default_display_name = pdata->default_device->name;
  163. return 0;
  164. err_debugfs:
  165. return r;
  166. }
  167. static int omap_dss_remove(struct platform_device *pdev)
  168. {
  169. dss_uninitialize_debugfs();
  170. return 0;
  171. }
  172. static void omap_dss_shutdown(struct platform_device *pdev)
  173. {
  174. DSSDBG("shutdown\n");
  175. dss_disable_all_devices();
  176. }
  177. static struct platform_driver omap_dss_driver = {
  178. .remove = omap_dss_remove,
  179. .shutdown = omap_dss_shutdown,
  180. .driver = {
  181. .name = "omapdss",
  182. },
  183. };
  184. /* INIT */
  185. static int (*dss_output_drv_reg_funcs[])(void) __initdata = {
  186. dss_init_platform_driver,
  187. dispc_init_platform_driver,
  188. #ifdef CONFIG_OMAP2_DSS_DSI
  189. dsi_init_platform_driver,
  190. #endif
  191. #ifdef CONFIG_OMAP2_DSS_DPI
  192. dpi_init_platform_driver,
  193. #endif
  194. #ifdef CONFIG_OMAP2_DSS_SDI
  195. sdi_init_platform_driver,
  196. #endif
  197. #ifdef CONFIG_OMAP2_DSS_RFBI
  198. rfbi_init_platform_driver,
  199. #endif
  200. #ifdef CONFIG_OMAP2_DSS_VENC
  201. venc_init_platform_driver,
  202. #endif
  203. #ifdef CONFIG_OMAP4_DSS_HDMI
  204. hdmi4_init_platform_driver,
  205. #endif
  206. #ifdef CONFIG_OMAP5_DSS_HDMI
  207. hdmi5_init_platform_driver,
  208. #endif
  209. };
  210. static void (*dss_output_drv_unreg_funcs[])(void) = {
  211. #ifdef CONFIG_OMAP5_DSS_HDMI
  212. hdmi5_uninit_platform_driver,
  213. #endif
  214. #ifdef CONFIG_OMAP4_DSS_HDMI
  215. hdmi4_uninit_platform_driver,
  216. #endif
  217. #ifdef CONFIG_OMAP2_DSS_VENC
  218. venc_uninit_platform_driver,
  219. #endif
  220. #ifdef CONFIG_OMAP2_DSS_RFBI
  221. rfbi_uninit_platform_driver,
  222. #endif
  223. #ifdef CONFIG_OMAP2_DSS_SDI
  224. sdi_uninit_platform_driver,
  225. #endif
  226. #ifdef CONFIG_OMAP2_DSS_DPI
  227. dpi_uninit_platform_driver,
  228. #endif
  229. #ifdef CONFIG_OMAP2_DSS_DSI
  230. dsi_uninit_platform_driver,
  231. #endif
  232. dispc_uninit_platform_driver,
  233. dss_uninit_platform_driver,
  234. };
  235. static int __init omap_dss_init(void)
  236. {
  237. int r;
  238. int i;
  239. r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
  240. if (r)
  241. return r;
  242. for (i = 0; i < ARRAY_SIZE(dss_output_drv_reg_funcs); ++i) {
  243. r = dss_output_drv_reg_funcs[i]();
  244. if (r)
  245. goto err_reg;
  246. }
  247. return 0;
  248. err_reg:
  249. for (i = ARRAY_SIZE(dss_output_drv_reg_funcs) - i;
  250. i < ARRAY_SIZE(dss_output_drv_reg_funcs);
  251. ++i)
  252. dss_output_drv_unreg_funcs[i]();
  253. platform_driver_unregister(&omap_dss_driver);
  254. return r;
  255. }
  256. static void __exit omap_dss_exit(void)
  257. {
  258. int i;
  259. for (i = 0; i < ARRAY_SIZE(dss_output_drv_unreg_funcs); ++i)
  260. dss_output_drv_unreg_funcs[i]();
  261. platform_driver_unregister(&omap_dss_driver);
  262. }
  263. module_init(omap_dss_init);
  264. module_exit(omap_dss_exit);
  265. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  266. MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
  267. MODULE_LICENSE("GPL v2");