pvrusb2-i2c-cmd-v4l2.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. *
  3. * $Id$
  4. *
  5. * Copyright (C) 2005 Mike Isely <isely@pobox.com>
  6. * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. */
  22. #include "pvrusb2-i2c-cmd-v4l2.h"
  23. #include "pvrusb2-hdw-internal.h"
  24. #include "pvrusb2-debug.h"
  25. #include <linux/videodev2.h>
  26. static void set_standard(struct pvr2_hdw *hdw)
  27. {
  28. v4l2_std_id vs;
  29. vs = hdw->std_mask_cur;
  30. pvr2_trace(PVR2_TRACE_CHIPS,
  31. "i2c v4l2 set_standard(0x%llx)",(long long unsigned)vs);
  32. pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs);
  33. }
  34. static int check_standard(struct pvr2_hdw *hdw)
  35. {
  36. return hdw->std_dirty != 0;
  37. }
  38. const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard = {
  39. .check = check_standard,
  40. .update = set_standard,
  41. .name = "v4l2_standard",
  42. };
  43. static void set_bcsh(struct pvr2_hdw *hdw)
  44. {
  45. struct v4l2_control ctrl;
  46. pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_bcsh"
  47. " b=%d c=%d s=%d h=%d",
  48. hdw->brightness_val,hdw->contrast_val,
  49. hdw->saturation_val,hdw->hue_val);
  50. memset(&ctrl,0,sizeof(ctrl));
  51. ctrl.id = V4L2_CID_BRIGHTNESS;
  52. ctrl.value = hdw->brightness_val;
  53. pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
  54. ctrl.id = V4L2_CID_CONTRAST;
  55. ctrl.value = hdw->contrast_val;
  56. pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
  57. ctrl.id = V4L2_CID_SATURATION;
  58. ctrl.value = hdw->saturation_val;
  59. pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
  60. ctrl.id = V4L2_CID_HUE;
  61. ctrl.value = hdw->hue_val;
  62. pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
  63. }
  64. static int check_bcsh(struct pvr2_hdw *hdw)
  65. {
  66. return (hdw->brightness_dirty ||
  67. hdw->contrast_dirty ||
  68. hdw->saturation_dirty ||
  69. hdw->hue_dirty);
  70. }
  71. const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh = {
  72. .check = check_bcsh,
  73. .update = set_bcsh,
  74. .name = "v4l2_bcsh",
  75. };
  76. static void set_volume(struct pvr2_hdw *hdw)
  77. {
  78. struct v4l2_control ctrl;
  79. pvr2_trace(PVR2_TRACE_CHIPS,
  80. "i2c v4l2 set_volume"
  81. "(vol=%d bal=%d bas=%d treb=%d mute=%d)",
  82. hdw->volume_val,
  83. hdw->balance_val,
  84. hdw->bass_val,
  85. hdw->treble_val,
  86. hdw->mute_val);
  87. memset(&ctrl,0,sizeof(ctrl));
  88. ctrl.id = V4L2_CID_AUDIO_MUTE;
  89. ctrl.value = hdw->mute_val ? 1 : 0;
  90. pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
  91. ctrl.id = V4L2_CID_AUDIO_VOLUME;
  92. ctrl.value = hdw->volume_val;
  93. pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
  94. ctrl.id = V4L2_CID_AUDIO_BALANCE;
  95. ctrl.value = hdw->balance_val;
  96. pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
  97. ctrl.id = V4L2_CID_AUDIO_BASS;
  98. ctrl.value = hdw->bass_val;
  99. pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
  100. ctrl.id = V4L2_CID_AUDIO_TREBLE;
  101. ctrl.value = hdw->treble_val;
  102. pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
  103. }
  104. static int check_volume(struct pvr2_hdw *hdw)
  105. {
  106. return (hdw->volume_dirty ||
  107. hdw->balance_dirty ||
  108. hdw->bass_dirty ||
  109. hdw->treble_dirty ||
  110. hdw->mute_dirty);
  111. }
  112. const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume = {
  113. .check = check_volume,
  114. .update = set_volume,
  115. .name = "v4l2_volume",
  116. };
  117. static void set_frequency(struct pvr2_hdw *hdw)
  118. {
  119. unsigned long fv;
  120. struct v4l2_frequency freq;
  121. fv = hdw->freqVal;
  122. pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_freq(%lu)",fv);
  123. memset(&freq,0,sizeof(freq));
  124. freq.frequency = fv / 62500;
  125. freq.tuner = 0;
  126. freq.type = V4L2_TUNER_ANALOG_TV;
  127. pvr2_i2c_core_cmd(hdw,VIDIOC_S_FREQUENCY,&freq);
  128. }
  129. static int check_frequency(struct pvr2_hdw *hdw)
  130. {
  131. return hdw->freqDirty != 0;
  132. }
  133. const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency = {
  134. .check = check_frequency,
  135. .update = set_frequency,
  136. .name = "v4l2_freq",
  137. };
  138. static void set_size(struct pvr2_hdw *hdw)
  139. {
  140. struct v4l2_format fmt;
  141. memset(&fmt,0,sizeof(fmt));
  142. fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  143. fmt.fmt.pix.width = hdw->res_hor_val;
  144. fmt.fmt.pix.height = hdw->res_ver_val;
  145. pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_size(%dx%d)",
  146. fmt.fmt.pix.width,fmt.fmt.pix.height);
  147. pvr2_i2c_core_cmd(hdw,VIDIOC_S_FMT,&fmt);
  148. }
  149. static int check_size(struct pvr2_hdw *hdw)
  150. {
  151. return (hdw->res_hor_dirty || hdw->res_ver_dirty);
  152. }
  153. const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size = {
  154. .check = check_size,
  155. .update = set_size,
  156. .name = "v4l2_size",
  157. };
  158. static void do_log(struct pvr2_hdw *hdw)
  159. {
  160. pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 do_log()");
  161. pvr2_i2c_core_cmd(hdw,VIDIOC_LOG_STATUS,NULL);
  162. }
  163. static int check_log(struct pvr2_hdw *hdw)
  164. {
  165. return hdw->log_requested != 0;
  166. }
  167. const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log = {
  168. .check = check_log,
  169. .update = do_log,
  170. .name = "v4l2_log",
  171. };
  172. void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *cp,int fl)
  173. {
  174. pvr2_i2c_client_cmd(cp,
  175. (fl ? VIDIOC_STREAMON : VIDIOC_STREAMOFF),NULL);
  176. }
  177. /*
  178. Stuff for Emacs to see, in order to encourage consistent editing style:
  179. *** Local Variables: ***
  180. *** mode: c ***
  181. *** fill-column: 70 ***
  182. *** tab-width: 8 ***
  183. *** c-basic-offset: 8 ***
  184. *** End: ***
  185. */