core.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. } core;
  41. enum omapdss_version omapdss_get_version(void)
  42. {
  43. struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
  44. return pdata->version;
  45. }
  46. EXPORT_SYMBOL(omapdss_get_version);
  47. int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask)
  48. {
  49. struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
  50. if (!board_data->dsi_enable_pads)
  51. return -ENOENT;
  52. return board_data->dsi_enable_pads(dsi_id, lane_mask);
  53. }
  54. void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask)
  55. {
  56. struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
  57. if (!board_data->dsi_disable_pads)
  58. return;
  59. return board_data->dsi_disable_pads(dsi_id, lane_mask);
  60. }
  61. int dss_set_min_bus_tput(struct device *dev, unsigned long tput)
  62. {
  63. struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
  64. if (pdata->set_min_bus_tput)
  65. return pdata->set_min_bus_tput(dev, tput);
  66. else
  67. return 0;
  68. }
  69. #if defined(CONFIG_OMAP2_DSS_DEBUGFS)
  70. static int dss_debug_show(struct seq_file *s, void *unused)
  71. {
  72. void (*func)(struct seq_file *) = s->private;
  73. func(s);
  74. return 0;
  75. }
  76. static int dss_debug_open(struct inode *inode, struct file *file)
  77. {
  78. return single_open(file, dss_debug_show, inode->i_private);
  79. }
  80. static const struct file_operations dss_debug_fops = {
  81. .open = dss_debug_open,
  82. .read = seq_read,
  83. .llseek = seq_lseek,
  84. .release = single_release,
  85. };
  86. static struct dentry *dss_debugfs_dir;
  87. static int dss_initialize_debugfs(void)
  88. {
  89. dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
  90. if (IS_ERR(dss_debugfs_dir)) {
  91. int err = PTR_ERR(dss_debugfs_dir);
  92. dss_debugfs_dir = NULL;
  93. return err;
  94. }
  95. debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
  96. &dss_debug_dump_clocks, &dss_debug_fops);
  97. return 0;
  98. }
  99. static void dss_uninitialize_debugfs(void)
  100. {
  101. if (dss_debugfs_dir)
  102. debugfs_remove_recursive(dss_debugfs_dir);
  103. }
  104. int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
  105. {
  106. struct dentry *d;
  107. d = debugfs_create_file(name, S_IRUGO, dss_debugfs_dir,
  108. write, &dss_debug_fops);
  109. return PTR_ERR_OR_ZERO(d);
  110. }
  111. #else /* CONFIG_OMAP2_DSS_DEBUGFS */
  112. static inline int dss_initialize_debugfs(void)
  113. {
  114. return 0;
  115. }
  116. static inline void dss_uninitialize_debugfs(void)
  117. {
  118. }
  119. int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
  120. {
  121. return 0;
  122. }
  123. #endif /* CONFIG_OMAP2_DSS_DEBUGFS */
  124. /* PLATFORM DEVICE */
  125. static void dss_disable_all_devices(void)
  126. {
  127. struct omap_dss_device *dssdev = NULL;
  128. for_each_dss_dev(dssdev) {
  129. if (!dssdev->driver)
  130. continue;
  131. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  132. dssdev->driver->disable(dssdev);
  133. }
  134. }
  135. static int __init omap_dss_probe(struct platform_device *pdev)
  136. {
  137. int r;
  138. core.pdev = pdev;
  139. dss_features_init(omapdss_get_version());
  140. r = dss_initialize_debugfs();
  141. if (r)
  142. goto err_debugfs;
  143. return 0;
  144. err_debugfs:
  145. return r;
  146. }
  147. static int omap_dss_remove(struct platform_device *pdev)
  148. {
  149. dss_uninitialize_debugfs();
  150. return 0;
  151. }
  152. static void omap_dss_shutdown(struct platform_device *pdev)
  153. {
  154. DSSDBG("shutdown\n");
  155. dss_disable_all_devices();
  156. }
  157. static struct platform_driver omap_dss_driver = {
  158. .remove = omap_dss_remove,
  159. .shutdown = omap_dss_shutdown,
  160. .driver = {
  161. .name = "omapdss",
  162. },
  163. };
  164. /* INIT */
  165. static int (*dss_output_drv_reg_funcs[])(void) __initdata = {
  166. dss_init_platform_driver,
  167. dispc_init_platform_driver,
  168. #ifdef CONFIG_OMAP2_DSS_DSI
  169. dsi_init_platform_driver,
  170. #endif
  171. #ifdef CONFIG_OMAP2_DSS_VENC
  172. venc_init_platform_driver,
  173. #endif
  174. #ifdef CONFIG_OMAP4_DSS_HDMI
  175. hdmi4_init_platform_driver,
  176. #endif
  177. #ifdef CONFIG_OMAP5_DSS_HDMI
  178. hdmi5_init_platform_driver,
  179. #endif
  180. };
  181. static void (*dss_output_drv_unreg_funcs[])(void) = {
  182. #ifdef CONFIG_OMAP5_DSS_HDMI
  183. hdmi5_uninit_platform_driver,
  184. #endif
  185. #ifdef CONFIG_OMAP4_DSS_HDMI
  186. hdmi4_uninit_platform_driver,
  187. #endif
  188. #ifdef CONFIG_OMAP2_DSS_VENC
  189. venc_uninit_platform_driver,
  190. #endif
  191. #ifdef CONFIG_OMAP2_DSS_DSI
  192. dsi_uninit_platform_driver,
  193. #endif
  194. dispc_uninit_platform_driver,
  195. dss_uninit_platform_driver,
  196. };
  197. static int __init omap_dss_init(void)
  198. {
  199. int r;
  200. int i;
  201. r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
  202. if (r)
  203. return r;
  204. for (i = 0; i < ARRAY_SIZE(dss_output_drv_reg_funcs); ++i) {
  205. r = dss_output_drv_reg_funcs[i]();
  206. if (r)
  207. goto err_reg;
  208. }
  209. return 0;
  210. err_reg:
  211. for (i = ARRAY_SIZE(dss_output_drv_reg_funcs) - i;
  212. i < ARRAY_SIZE(dss_output_drv_reg_funcs);
  213. ++i)
  214. dss_output_drv_unreg_funcs[i]();
  215. platform_driver_unregister(&omap_dss_driver);
  216. return r;
  217. }
  218. static void __exit omap_dss_exit(void)
  219. {
  220. int i;
  221. for (i = 0; i < ARRAY_SIZE(dss_output_drv_unreg_funcs); ++i)
  222. dss_output_drv_unreg_funcs[i]();
  223. platform_driver_unregister(&omap_dss_driver);
  224. }
  225. module_init(omap_dss_init);
  226. module_exit(omap_dss_exit);
  227. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  228. MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
  229. MODULE_LICENSE("GPL v2");