venc_panel.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. omapdss_venc_set_type(dssdev, new_type);
  61. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
  62. omapdss_venc_display_disable(dssdev);
  63. omapdss_venc_display_enable(dssdev);
  64. }
  65. }
  66. mutex_unlock(&venc_panel.lock);
  67. return size;
  68. }
  69. static DEVICE_ATTR(output_type, S_IRUGO | S_IWUSR,
  70. display_output_type_show, display_output_type_store);
  71. static int venc_panel_probe(struct omap_dss_device *dssdev)
  72. {
  73. /* set default timings to PAL */
  74. const struct omap_video_timings default_timings = {
  75. .x_res = 720,
  76. .y_res = 574,
  77. .pixel_clock = 13500,
  78. .hsw = 64,
  79. .hfp = 12,
  80. .hbp = 68,
  81. .vsw = 5,
  82. .vfp = 5,
  83. .vbp = 41,
  84. .vsync_level = OMAPDSS_SIG_ACTIVE_HIGH,
  85. .hsync_level = OMAPDSS_SIG_ACTIVE_HIGH,
  86. .interlace = true,
  87. };
  88. mutex_init(&venc_panel.lock);
  89. dssdev->panel.timings = default_timings;
  90. return device_create_file(&dssdev->dev, &dev_attr_output_type);
  91. }
  92. static void venc_panel_remove(struct omap_dss_device *dssdev)
  93. {
  94. device_remove_file(&dssdev->dev, &dev_attr_output_type);
  95. }
  96. static int venc_panel_enable(struct omap_dss_device *dssdev)
  97. {
  98. int r;
  99. dev_dbg(&dssdev->dev, "venc_panel_enable\n");
  100. mutex_lock(&venc_panel.lock);
  101. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
  102. r = -EINVAL;
  103. goto err;
  104. }
  105. omapdss_venc_set_timings(dssdev, &dssdev->panel.timings);
  106. omapdss_venc_set_type(dssdev, dssdev->phy.venc.type);
  107. omapdss_venc_invert_vid_out_polarity(dssdev,
  108. dssdev->phy.venc.invert_polarity);
  109. r = omapdss_venc_display_enable(dssdev);
  110. if (r)
  111. goto err;
  112. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  113. mutex_unlock(&venc_panel.lock);
  114. return 0;
  115. err:
  116. mutex_unlock(&venc_panel.lock);
  117. return r;
  118. }
  119. static void venc_panel_disable(struct omap_dss_device *dssdev)
  120. {
  121. dev_dbg(&dssdev->dev, "venc_panel_disable\n");
  122. mutex_lock(&venc_panel.lock);
  123. if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED)
  124. goto end;
  125. omapdss_venc_display_disable(dssdev);
  126. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  127. end:
  128. mutex_unlock(&venc_panel.lock);
  129. }
  130. static void venc_panel_set_timings(struct omap_dss_device *dssdev,
  131. struct omap_video_timings *timings)
  132. {
  133. dev_dbg(&dssdev->dev, "venc_panel_set_timings\n");
  134. mutex_lock(&venc_panel.lock);
  135. omapdss_venc_set_timings(dssdev, timings);
  136. dssdev->panel.timings = *timings;
  137. mutex_unlock(&venc_panel.lock);
  138. }
  139. static int venc_panel_check_timings(struct omap_dss_device *dssdev,
  140. struct omap_video_timings *timings)
  141. {
  142. dev_dbg(&dssdev->dev, "venc_panel_check_timings\n");
  143. return omapdss_venc_check_timings(dssdev, timings);
  144. }
  145. static u32 venc_panel_get_wss(struct omap_dss_device *dssdev)
  146. {
  147. dev_dbg(&dssdev->dev, "venc_panel_get_wss\n");
  148. return omapdss_venc_get_wss(dssdev);
  149. }
  150. static int venc_panel_set_wss(struct omap_dss_device *dssdev, u32 wss)
  151. {
  152. dev_dbg(&dssdev->dev, "venc_panel_set_wss\n");
  153. return omapdss_venc_set_wss(dssdev, wss);
  154. }
  155. static struct omap_dss_driver venc_driver = {
  156. .probe = venc_panel_probe,
  157. .remove = venc_panel_remove,
  158. .enable = venc_panel_enable,
  159. .disable = venc_panel_disable,
  160. .get_resolution = omapdss_default_get_resolution,
  161. .get_recommended_bpp = omapdss_default_get_recommended_bpp,
  162. .set_timings = venc_panel_set_timings,
  163. .check_timings = venc_panel_check_timings,
  164. .get_wss = venc_panel_get_wss,
  165. .set_wss = venc_panel_set_wss,
  166. .driver = {
  167. .name = "venc",
  168. .owner = THIS_MODULE,
  169. },
  170. };
  171. int venc_panel_init(void)
  172. {
  173. return omap_dss_register_driver(&venc_driver);
  174. }
  175. void venc_panel_exit(void)
  176. {
  177. omap_dss_unregister_driver(&venc_driver);
  178. }