display.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * OMAP2plus display device setup / initialization.
  3. *
  4. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  5. * Senthilvadivu Guruswamy
  6. * Sumit Semwal
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  13. * kind, whether express or implied; without even the implied warranty
  14. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/string.h>
  18. #include <linux/kernel.h>
  19. #include <linux/init.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/io.h>
  22. #include <linux/clk.h>
  23. #include <linux/err.h>
  24. #include <video/omapdss.h>
  25. #include <plat/omap_hwmod.h>
  26. #include <plat/omap_device.h>
  27. #include <plat/omap-pm.h>
  28. #include "control.h"
  29. static struct platform_device omap_display_device = {
  30. .name = "omapdss",
  31. .id = -1,
  32. .dev = {
  33. .platform_data = NULL,
  34. },
  35. };
  36. static struct omap_device_pm_latency omap_dss_latency[] = {
  37. [0] = {
  38. .deactivate_func = omap_device_idle_hwmods,
  39. .activate_func = omap_device_enable_hwmods,
  40. .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
  41. },
  42. };
  43. struct omap_dss_hwmod_data {
  44. const char *oh_name;
  45. const char *dev_name;
  46. const int id;
  47. };
  48. static const struct omap_dss_hwmod_data omap2_dss_hwmod_data[] __initdata = {
  49. { "dss_core", "omapdss_dss", -1 },
  50. { "dss_dispc", "omapdss_dispc", -1 },
  51. { "dss_rfbi", "omapdss_rfbi", -1 },
  52. { "dss_venc", "omapdss_venc", -1 },
  53. };
  54. static const struct omap_dss_hwmod_data omap3_dss_hwmod_data[] __initdata = {
  55. { "dss_core", "omapdss_dss", -1 },
  56. { "dss_dispc", "omapdss_dispc", -1 },
  57. { "dss_rfbi", "omapdss_rfbi", -1 },
  58. { "dss_venc", "omapdss_venc", -1 },
  59. { "dss_dsi1", "omapdss_dsi", 0 },
  60. };
  61. static const struct omap_dss_hwmod_data omap4_dss_hwmod_data[] __initdata = {
  62. { "dss_core", "omapdss_dss", -1 },
  63. { "dss_dispc", "omapdss_dispc", -1 },
  64. { "dss_rfbi", "omapdss_rfbi", -1 },
  65. { "dss_venc", "omapdss_venc", -1 },
  66. { "dss_dsi1", "omapdss_dsi", 0 },
  67. { "dss_dsi2", "omapdss_dsi", 1 },
  68. { "dss_hdmi", "omapdss_hdmi", -1 },
  69. };
  70. static int omap4_dsi_mux_pads(int dsi_id, unsigned lanes)
  71. {
  72. u32 enable_mask, enable_shift;
  73. u32 pipd_mask, pipd_shift;
  74. u32 reg;
  75. if (dsi_id == 0) {
  76. enable_mask = OMAP4_DSI1_LANEENABLE_MASK;
  77. enable_shift = OMAP4_DSI1_LANEENABLE_SHIFT;
  78. pipd_mask = OMAP4_DSI1_PIPD_MASK;
  79. pipd_shift = OMAP4_DSI1_PIPD_SHIFT;
  80. } else if (dsi_id == 1) {
  81. enable_mask = OMAP4_DSI2_LANEENABLE_MASK;
  82. enable_shift = OMAP4_DSI2_LANEENABLE_SHIFT;
  83. pipd_mask = OMAP4_DSI2_PIPD_MASK;
  84. pipd_shift = OMAP4_DSI2_PIPD_SHIFT;
  85. } else {
  86. return -ENODEV;
  87. }
  88. reg = omap4_ctrl_pad_readl(OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_DSIPHY);
  89. reg &= ~enable_mask;
  90. reg &= ~pipd_mask;
  91. reg |= (lanes << enable_shift) & enable_mask;
  92. reg |= (lanes << pipd_shift) & pipd_mask;
  93. omap4_ctrl_pad_writel(reg, OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_DSIPHY);
  94. return 0;
  95. }
  96. static int omap_dsi_enable_pads(int dsi_id, unsigned lane_mask)
  97. {
  98. if (cpu_is_omap44xx())
  99. return omap4_dsi_mux_pads(dsi_id, lane_mask);
  100. return 0;
  101. }
  102. static void omap_dsi_disable_pads(int dsi_id, unsigned lane_mask)
  103. {
  104. if (cpu_is_omap44xx())
  105. omap4_dsi_mux_pads(dsi_id, 0);
  106. }
  107. int __init omap_display_init(struct omap_dss_board_info *board_data)
  108. {
  109. int r = 0;
  110. struct omap_hwmod *oh;
  111. struct omap_device *od;
  112. int i, oh_count;
  113. struct omap_display_platform_data pdata;
  114. const struct omap_dss_hwmod_data *curr_dss_hwmod;
  115. memset(&pdata, 0, sizeof(pdata));
  116. if (cpu_is_omap24xx()) {
  117. curr_dss_hwmod = omap2_dss_hwmod_data;
  118. oh_count = ARRAY_SIZE(omap2_dss_hwmod_data);
  119. } else if (cpu_is_omap34xx()) {
  120. curr_dss_hwmod = omap3_dss_hwmod_data;
  121. oh_count = ARRAY_SIZE(omap3_dss_hwmod_data);
  122. } else {
  123. curr_dss_hwmod = omap4_dss_hwmod_data;
  124. oh_count = ARRAY_SIZE(omap4_dss_hwmod_data);
  125. }
  126. if (board_data->dsi_enable_pads == NULL)
  127. board_data->dsi_enable_pads = omap_dsi_enable_pads;
  128. if (board_data->dsi_disable_pads == NULL)
  129. board_data->dsi_disable_pads = omap_dsi_disable_pads;
  130. pdata.board_data = board_data;
  131. pdata.board_data->get_context_loss_count =
  132. omap_pm_get_dev_context_loss_count;
  133. for (i = 0; i < oh_count; i++) {
  134. oh = omap_hwmod_lookup(curr_dss_hwmod[i].oh_name);
  135. if (!oh) {
  136. pr_err("Could not look up %s\n",
  137. curr_dss_hwmod[i].oh_name);
  138. return -ENODEV;
  139. }
  140. od = omap_device_build(curr_dss_hwmod[i].dev_name,
  141. curr_dss_hwmod[i].id, oh, &pdata,
  142. sizeof(struct omap_display_platform_data),
  143. omap_dss_latency,
  144. ARRAY_SIZE(omap_dss_latency), 0);
  145. if (WARN((IS_ERR(od)), "Could not build omap_device for %s\n",
  146. curr_dss_hwmod[i].oh_name))
  147. return -ENODEV;
  148. }
  149. omap_display_device.dev.platform_data = board_data;
  150. r = platform_device_register(&omap_display_device);
  151. if (r < 0)
  152. printk(KERN_ERR "Unable to register OMAP-Display device\n");
  153. return r;
  154. }