hdmi_panel.c 4.7 KB

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