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. struct mutex hdmi_lock;
  31. } hdmi;
  32. static int hdmi_panel_probe(struct omap_dss_device *dssdev)
  33. {
  34. DSSDBG("ENTER hdmi_panel_probe\n");
  35. dssdev->panel.config = OMAP_DSS_LCD_TFT |
  36. OMAP_DSS_LCD_IVS | OMAP_DSS_LCD_IHS;
  37. dssdev->panel.timings = (struct omap_video_timings){640, 480, 25175, 96, 16, 48, 2 , 11, 31};
  38. DSSDBG("hdmi_panel_probe x_res= %d y_res = %d\n",
  39. dssdev->panel.timings.x_res,
  40. dssdev->panel.timings.y_res);
  41. return 0;
  42. }
  43. static void hdmi_panel_remove(struct omap_dss_device *dssdev)
  44. {
  45. }
  46. static int hdmi_panel_enable(struct omap_dss_device *dssdev)
  47. {
  48. int r = 0;
  49. DSSDBG("ENTER hdmi_panel_enable\n");
  50. mutex_lock(&hdmi.hdmi_lock);
  51. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  52. r = -EINVAL;
  53. goto err;
  54. }
  55. r = omapdss_hdmi_display_enable(dssdev);
  56. if (r) {
  57. DSSERR("failed to power on\n");
  58. goto err;
  59. }
  60. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  61. err:
  62. mutex_unlock(&hdmi.hdmi_lock);
  63. return r;
  64. }
  65. static void hdmi_panel_disable(struct omap_dss_device *dssdev)
  66. {
  67. mutex_lock(&hdmi.hdmi_lock);
  68. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  69. omapdss_hdmi_display_disable(dssdev);
  70. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  71. mutex_unlock(&hdmi.hdmi_lock);
  72. }
  73. static int hdmi_panel_suspend(struct omap_dss_device *dssdev)
  74. {
  75. int r = 0;
  76. mutex_lock(&hdmi.hdmi_lock);
  77. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  78. r = -EINVAL;
  79. goto err;
  80. }
  81. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  82. omapdss_hdmi_display_disable(dssdev);
  83. err:
  84. mutex_unlock(&hdmi.hdmi_lock);
  85. return r;
  86. }
  87. static int hdmi_panel_resume(struct omap_dss_device *dssdev)
  88. {
  89. int r = 0;
  90. mutex_lock(&hdmi.hdmi_lock);
  91. if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
  92. r = -EINVAL;
  93. goto err;
  94. }
  95. r = omapdss_hdmi_display_enable(dssdev);
  96. if (r) {
  97. DSSERR("failed to power on\n");
  98. goto err;
  99. }
  100. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  101. err:
  102. mutex_unlock(&hdmi.hdmi_lock);
  103. return r;
  104. }
  105. static void hdmi_get_timings(struct omap_dss_device *dssdev,
  106. struct omap_video_timings *timings)
  107. {
  108. mutex_lock(&hdmi.hdmi_lock);
  109. *timings = dssdev->panel.timings;
  110. mutex_unlock(&hdmi.hdmi_lock);
  111. }
  112. static void hdmi_set_timings(struct omap_dss_device *dssdev,
  113. struct omap_video_timings *timings)
  114. {
  115. DSSDBG("hdmi_set_timings\n");
  116. mutex_lock(&hdmi.hdmi_lock);
  117. dssdev->panel.timings = *timings;
  118. omapdss_hdmi_display_set_timing(dssdev);
  119. mutex_unlock(&hdmi.hdmi_lock);
  120. }
  121. static int hdmi_check_timings(struct omap_dss_device *dssdev,
  122. struct omap_video_timings *timings)
  123. {
  124. int r = 0;
  125. DSSDBG("hdmi_check_timings\n");
  126. mutex_lock(&hdmi.hdmi_lock);
  127. r = omapdss_hdmi_display_check_timing(dssdev, timings);
  128. mutex_unlock(&hdmi.hdmi_lock);
  129. return r;
  130. }
  131. static int hdmi_read_edid(struct omap_dss_device *dssdev, u8 *buf, int len)
  132. {
  133. int r;
  134. mutex_lock(&hdmi.hdmi_lock);
  135. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  136. r = omapdss_hdmi_display_enable(dssdev);
  137. if (r)
  138. goto err;
  139. }
  140. r = omapdss_hdmi_read_edid(buf, len);
  141. if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED ||
  142. dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
  143. omapdss_hdmi_display_disable(dssdev);
  144. err:
  145. mutex_unlock(&hdmi.hdmi_lock);
  146. return r;
  147. }
  148. static bool hdmi_detect(struct omap_dss_device *dssdev)
  149. {
  150. int r;
  151. mutex_lock(&hdmi.hdmi_lock);
  152. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  153. r = omapdss_hdmi_display_enable(dssdev);
  154. if (r)
  155. goto err;
  156. }
  157. r = omapdss_hdmi_detect();
  158. if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED ||
  159. dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
  160. omapdss_hdmi_display_disable(dssdev);
  161. err:
  162. mutex_unlock(&hdmi.hdmi_lock);
  163. return r;
  164. }
  165. static struct omap_dss_driver hdmi_driver = {
  166. .probe = hdmi_panel_probe,
  167. .remove = hdmi_panel_remove,
  168. .enable = hdmi_panel_enable,
  169. .disable = hdmi_panel_disable,
  170. .suspend = hdmi_panel_suspend,
  171. .resume = hdmi_panel_resume,
  172. .get_timings = hdmi_get_timings,
  173. .set_timings = hdmi_set_timings,
  174. .check_timings = hdmi_check_timings,
  175. .read_edid = hdmi_read_edid,
  176. .detect = hdmi_detect,
  177. .driver = {
  178. .name = "hdmi_panel",
  179. .owner = THIS_MODULE,
  180. },
  181. };
  182. int hdmi_panel_init(void)
  183. {
  184. mutex_init(&hdmi.hdmi_lock);
  185. omap_dss_register_driver(&hdmi_driver);
  186. return 0;
  187. }
  188. void hdmi_panel_exit(void)
  189. {
  190. omap_dss_unregister_driver(&hdmi_driver);
  191. }