hdmi_panel.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * hdmi_panel.c
  3. *
  4. * HDMI library support functions for TI OMAP4 processors.
  5. *
  6. * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
  7. * Authors: Mythri P k <mythripk@ti.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as published by
  11. * the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/err.h>
  23. #include <linux/io.h>
  24. #include <linux/mutex.h>
  25. #include <linux/module.h>
  26. #include <video/omapdss.h>
  27. #include <linux/slab.h>
  28. #include "dss.h"
  29. static struct {
  30. /* This protects the panel ops, mainly when accessing the HDMI IP. */
  31. struct mutex lock;
  32. } hdmi;
  33. static int hdmi_panel_probe(struct omap_dss_device *dssdev)
  34. {
  35. DSSDBG("ENTER hdmi_panel_probe\n");
  36. dssdev->panel.config = OMAP_DSS_LCD_TFT |
  37. OMAP_DSS_LCD_IVS | OMAP_DSS_LCD_IHS;
  38. dssdev->panel.timings = (struct omap_video_timings){640, 480, 25175, 96, 16, 48, 2 , 11, 31};
  39. DSSDBG("hdmi_panel_probe x_res= %d y_res = %d\n",
  40. dssdev->panel.timings.x_res,
  41. dssdev->panel.timings.y_res);
  42. return 0;
  43. }
  44. static void hdmi_panel_remove(struct omap_dss_device *dssdev)
  45. {
  46. }
  47. static int hdmi_panel_enable(struct omap_dss_device *dssdev)
  48. {
  49. int r = 0;
  50. DSSDBG("ENTER hdmi_panel_enable\n");
  51. mutex_lock(&hdmi.lock);
  52. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  53. r = -EINVAL;
  54. goto err;
  55. }
  56. r = omapdss_hdmi_display_enable(dssdev);
  57. if (r) {
  58. DSSERR("failed to power on\n");
  59. goto err;
  60. }
  61. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  62. err:
  63. mutex_unlock(&hdmi.lock);
  64. return r;
  65. }
  66. static void hdmi_panel_disable(struct omap_dss_device *dssdev)
  67. {
  68. mutex_lock(&hdmi.lock);
  69. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  70. omapdss_hdmi_display_disable(dssdev);
  71. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  72. mutex_unlock(&hdmi.lock);
  73. }
  74. static int hdmi_panel_suspend(struct omap_dss_device *dssdev)
  75. {
  76. int r = 0;
  77. mutex_lock(&hdmi.lock);
  78. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  79. r = -EINVAL;
  80. goto err;
  81. }
  82. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  83. omapdss_hdmi_display_disable(dssdev);
  84. err:
  85. mutex_unlock(&hdmi.lock);
  86. return r;
  87. }
  88. static int hdmi_panel_resume(struct omap_dss_device *dssdev)
  89. {
  90. int r = 0;
  91. mutex_lock(&hdmi.lock);
  92. if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
  93. r = -EINVAL;
  94. goto err;
  95. }
  96. r = omapdss_hdmi_display_enable(dssdev);
  97. if (r) {
  98. DSSERR("failed to power on\n");
  99. goto err;
  100. }
  101. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  102. err:
  103. mutex_unlock(&hdmi.lock);
  104. return r;
  105. }
  106. static void hdmi_get_timings(struct omap_dss_device *dssdev,
  107. struct omap_video_timings *timings)
  108. {
  109. mutex_lock(&hdmi.lock);
  110. *timings = dssdev->panel.timings;
  111. mutex_unlock(&hdmi.lock);
  112. }
  113. static void hdmi_set_timings(struct omap_dss_device *dssdev,
  114. struct omap_video_timings *timings)
  115. {
  116. DSSDBG("hdmi_set_timings\n");
  117. mutex_lock(&hdmi.lock);
  118. dssdev->panel.timings = *timings;
  119. omapdss_hdmi_display_set_timing(dssdev);
  120. mutex_unlock(&hdmi.lock);
  121. }
  122. static int hdmi_check_timings(struct omap_dss_device *dssdev,
  123. struct omap_video_timings *timings)
  124. {
  125. int r = 0;
  126. DSSDBG("hdmi_check_timings\n");
  127. mutex_lock(&hdmi.lock);
  128. r = omapdss_hdmi_display_check_timing(dssdev, timings);
  129. mutex_unlock(&hdmi.lock);
  130. return r;
  131. }
  132. static int hdmi_read_edid(struct omap_dss_device *dssdev, u8 *buf, int len)
  133. {
  134. int r;
  135. mutex_lock(&hdmi.lock);
  136. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  137. r = omapdss_hdmi_display_enable(dssdev);
  138. if (r)
  139. goto err;
  140. }
  141. r = omapdss_hdmi_read_edid(buf, len);
  142. if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED ||
  143. dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
  144. omapdss_hdmi_display_disable(dssdev);
  145. err:
  146. mutex_unlock(&hdmi.lock);
  147. return r;
  148. }
  149. static bool hdmi_detect(struct omap_dss_device *dssdev)
  150. {
  151. int r;
  152. mutex_lock(&hdmi.lock);
  153. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  154. r = omapdss_hdmi_display_enable(dssdev);
  155. if (r)
  156. goto err;
  157. }
  158. r = omapdss_hdmi_detect();
  159. if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED ||
  160. dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
  161. omapdss_hdmi_display_disable(dssdev);
  162. err:
  163. mutex_unlock(&hdmi.lock);
  164. return r;
  165. }
  166. static struct omap_dss_driver hdmi_driver = {
  167. .probe = hdmi_panel_probe,
  168. .remove = hdmi_panel_remove,
  169. .enable = hdmi_panel_enable,
  170. .disable = hdmi_panel_disable,
  171. .suspend = hdmi_panel_suspend,
  172. .resume = hdmi_panel_resume,
  173. .get_timings = hdmi_get_timings,
  174. .set_timings = hdmi_set_timings,
  175. .check_timings = hdmi_check_timings,
  176. .read_edid = hdmi_read_edid,
  177. .detect = hdmi_detect,
  178. .driver = {
  179. .name = "hdmi_panel",
  180. .owner = THIS_MODULE,
  181. },
  182. };
  183. int hdmi_panel_init(void)
  184. {
  185. mutex_init(&hdmi.lock);
  186. omap_dss_register_driver(&hdmi_driver);
  187. return 0;
  188. }
  189. void hdmi_panel_exit(void)
  190. {
  191. omap_dss_unregister_driver(&hdmi_driver);
  192. }