venc_panel.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * Copyright (C) 2009 Nokia Corporation
  3. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  4. *
  5. * VENC panel driver
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/err.h>
  21. #include <linux/io.h>
  22. #include <linux/mutex.h>
  23. #include <linux/module.h>
  24. #include <video/omapdss.h>
  25. #include "dss.h"
  26. static struct {
  27. struct mutex lock;
  28. } venc_panel;
  29. static ssize_t display_output_type_show(struct device *dev,
  30. struct device_attribute *attr, char *buf)
  31. {
  32. struct omap_dss_device *dssdev = to_dss_device(dev);
  33. const char *ret;
  34. switch (dssdev->phy.venc.type) {
  35. case OMAP_DSS_VENC_TYPE_COMPOSITE:
  36. ret = "composite";
  37. break;
  38. case OMAP_DSS_VENC_TYPE_SVIDEO:
  39. ret = "svideo";
  40. break;
  41. default:
  42. return -EINVAL;
  43. }
  44. return snprintf(buf, PAGE_SIZE, "%s\n", ret);
  45. }
  46. static ssize_t display_output_type_store(struct device *dev,
  47. struct device_attribute *attr, const char *buf, size_t size)
  48. {
  49. struct omap_dss_device *dssdev = to_dss_device(dev);
  50. enum omap_dss_venc_type new_type;
  51. if (sysfs_streq("composite", buf))
  52. new_type = OMAP_DSS_VENC_TYPE_COMPOSITE;
  53. else if (sysfs_streq("svideo", buf))
  54. new_type = OMAP_DSS_VENC_TYPE_SVIDEO;
  55. else
  56. return -EINVAL;
  57. mutex_lock(&venc_panel.lock);
  58. if (dssdev->phy.venc.type != new_type) {
  59. dssdev->phy.venc.type = new_type;
  60. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
  61. omapdss_venc_display_disable(dssdev);
  62. omapdss_venc_display_enable(dssdev);
  63. }
  64. }
  65. mutex_unlock(&venc_panel.lock);
  66. return size;
  67. }
  68. static DEVICE_ATTR(output_type, S_IRUGO | S_IWUSR,
  69. display_output_type_show, display_output_type_store);
  70. static int venc_panel_probe(struct omap_dss_device *dssdev)
  71. {
  72. /* set default timings to PAL */
  73. const struct omap_video_timings default_timings = {
  74. .x_res = 720,
  75. .y_res = 574,
  76. .pixel_clock = 13500,
  77. .hsw = 64,
  78. .hfp = 12,
  79. .hbp = 68,
  80. .vsw = 5,
  81. .vfp = 5,
  82. .vbp = 41,
  83. .vsync_level = OMAPDSS_SIG_ACTIVE_HIGH,
  84. .hsync_level = OMAPDSS_SIG_ACTIVE_HIGH,
  85. .interlace = true,
  86. };
  87. mutex_init(&venc_panel.lock);
  88. dssdev->panel.timings = default_timings;
  89. return device_create_file(&dssdev->dev, &dev_attr_output_type);
  90. }
  91. static void venc_panel_remove(struct omap_dss_device *dssdev)
  92. {
  93. device_remove_file(&dssdev->dev, &dev_attr_output_type);
  94. }
  95. static int venc_panel_enable(struct omap_dss_device *dssdev)
  96. {
  97. int r;
  98. dev_dbg(&dssdev->dev, "venc_panel_enable\n");
  99. mutex_lock(&venc_panel.lock);
  100. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  101. r = -EINVAL;
  102. goto err;
  103. }
  104. omapdss_venc_set_timings(dssdev, &dssdev->panel.timings);
  105. r = omapdss_venc_display_enable(dssdev);
  106. if (r)
  107. goto err;
  108. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  109. mutex_unlock(&venc_panel.lock);
  110. return 0;
  111. err:
  112. mutex_unlock(&venc_panel.lock);
  113. return r;
  114. }
  115. static void venc_panel_disable(struct omap_dss_device *dssdev)
  116. {
  117. dev_dbg(&dssdev->dev, "venc_panel_disable\n");
  118. mutex_lock(&venc_panel.lock);
  119. if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED)
  120. goto end;
  121. if (dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED) {
  122. /* suspended is the same as disabled with venc */
  123. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  124. goto end;
  125. }
  126. omapdss_venc_display_disable(dssdev);
  127. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  128. end:
  129. mutex_unlock(&venc_panel.lock);
  130. }
  131. static int venc_panel_suspend(struct omap_dss_device *dssdev)
  132. {
  133. venc_panel_disable(dssdev);
  134. return 0;
  135. }
  136. static int venc_panel_resume(struct omap_dss_device *dssdev)
  137. {
  138. return venc_panel_enable(dssdev);
  139. }
  140. static void venc_panel_set_timings(struct omap_dss_device *dssdev,
  141. struct omap_video_timings *timings)
  142. {
  143. dev_dbg(&dssdev->dev, "venc_panel_set_timings\n");
  144. mutex_lock(&venc_panel.lock);
  145. omapdss_venc_set_timings(dssdev, timings);
  146. dssdev->panel.timings = *timings;
  147. mutex_unlock(&venc_panel.lock);
  148. }
  149. static int venc_panel_check_timings(struct omap_dss_device *dssdev,
  150. struct omap_video_timings *timings)
  151. {
  152. dev_dbg(&dssdev->dev, "venc_panel_check_timings\n");
  153. return omapdss_venc_check_timings(dssdev, timings);
  154. }
  155. static u32 venc_panel_get_wss(struct omap_dss_device *dssdev)
  156. {
  157. dev_dbg(&dssdev->dev, "venc_panel_get_wss\n");
  158. return omapdss_venc_get_wss(dssdev);
  159. }
  160. static int venc_panel_set_wss(struct omap_dss_device *dssdev, u32 wss)
  161. {
  162. dev_dbg(&dssdev->dev, "venc_panel_set_wss\n");
  163. return omapdss_venc_set_wss(dssdev, wss);
  164. }
  165. static struct omap_dss_driver venc_driver = {
  166. .probe = venc_panel_probe,
  167. .remove = venc_panel_remove,
  168. .enable = venc_panel_enable,
  169. .disable = venc_panel_disable,
  170. .suspend = venc_panel_suspend,
  171. .resume = venc_panel_resume,
  172. .get_resolution = omapdss_default_get_resolution,
  173. .get_recommended_bpp = omapdss_default_get_recommended_bpp,
  174. .set_timings = venc_panel_set_timings,
  175. .check_timings = venc_panel_check_timings,
  176. .get_wss = venc_panel_get_wss,
  177. .set_wss = venc_panel_set_wss,
  178. .driver = {
  179. .name = "venc",
  180. .owner = THIS_MODULE,
  181. },
  182. };
  183. int venc_panel_init(void)
  184. {
  185. return omap_dss_register_driver(&venc_driver);
  186. }
  187. void venc_panel_exit(void)
  188. {
  189. omap_dss_unregister_driver(&venc_driver);
  190. }