core.c 7.0 KB

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