pvrusb2-i2c-cmd-v4l2.c 6.4 KB

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