pvrusb2-i2c-cmd-v4l2.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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 execute_init(struct pvr2_hdw *hdw)
  27. {
  28. u32 dummy = 0;
  29. pvr2_trace(PVR2_TRACE_CHIPS, "i2c v4l2 init");
  30. pvr2_i2c_core_cmd(hdw, VIDIOC_INT_INIT, &dummy);
  31. }
  32. const struct pvr2_i2c_op pvr2_i2c_op_v4l2_init = {
  33. .update = execute_init,
  34. .name = "v4l2_init",
  35. };
  36. static void set_standard(struct pvr2_hdw *hdw)
  37. {
  38. pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_standard");
  39. if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
  40. pvr2_i2c_core_cmd(hdw,AUDC_SET_RADIO,NULL);
  41. } else {
  42. v4l2_std_id vs;
  43. vs = hdw->std_mask_cur;
  44. pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs);
  45. }
  46. hdw->tuner_signal_stale = !0;
  47. hdw->cropcap_stale = !0;
  48. }
  49. static int check_standard(struct pvr2_hdw *hdw)
  50. {
  51. return (hdw->input_dirty != 0) || (hdw->std_dirty != 0);
  52. }
  53. const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard = {
  54. .check = check_standard,
  55. .update = set_standard,
  56. .name = "v4l2_standard",
  57. };
  58. static void set_bcsh(struct pvr2_hdw *hdw)
  59. {
  60. struct v4l2_control ctrl;
  61. pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_bcsh"
  62. " b=%d c=%d s=%d h=%d",
  63. hdw->brightness_val,hdw->contrast_val,
  64. hdw->saturation_val,hdw->hue_val);
  65. memset(&ctrl,0,sizeof(ctrl));
  66. ctrl.id = V4L2_CID_BRIGHTNESS;
  67. ctrl.value = hdw->brightness_val;
  68. pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
  69. ctrl.id = V4L2_CID_CONTRAST;
  70. ctrl.value = hdw->contrast_val;
  71. pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
  72. ctrl.id = V4L2_CID_SATURATION;
  73. ctrl.value = hdw->saturation_val;
  74. pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
  75. ctrl.id = V4L2_CID_HUE;
  76. ctrl.value = hdw->hue_val;
  77. pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
  78. }
  79. static int check_bcsh(struct pvr2_hdw *hdw)
  80. {
  81. return (hdw->brightness_dirty ||
  82. hdw->contrast_dirty ||
  83. hdw->saturation_dirty ||
  84. hdw->hue_dirty);
  85. }
  86. const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh = {
  87. .check = check_bcsh,
  88. .update = set_bcsh,
  89. .name = "v4l2_bcsh",
  90. };
  91. static void set_volume(struct pvr2_hdw *hdw)
  92. {
  93. struct v4l2_control ctrl;
  94. pvr2_trace(PVR2_TRACE_CHIPS,
  95. "i2c v4l2 set_volume"
  96. "(vol=%d bal=%d bas=%d treb=%d mute=%d)",
  97. hdw->volume_val,
  98. hdw->balance_val,
  99. hdw->bass_val,
  100. hdw->treble_val,
  101. hdw->mute_val);
  102. memset(&ctrl,0,sizeof(ctrl));
  103. ctrl.id = V4L2_CID_AUDIO_MUTE;
  104. ctrl.value = hdw->mute_val ? 1 : 0;
  105. pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
  106. ctrl.id = V4L2_CID_AUDIO_VOLUME;
  107. ctrl.value = hdw->volume_val;
  108. pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
  109. ctrl.id = V4L2_CID_AUDIO_BALANCE;
  110. ctrl.value = hdw->balance_val;
  111. pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
  112. ctrl.id = V4L2_CID_AUDIO_BASS;
  113. ctrl.value = hdw->bass_val;
  114. pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
  115. ctrl.id = V4L2_CID_AUDIO_TREBLE;
  116. ctrl.value = hdw->treble_val;
  117. pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
  118. }
  119. static int check_volume(struct pvr2_hdw *hdw)
  120. {
  121. return (hdw->volume_dirty ||
  122. hdw->balance_dirty ||
  123. hdw->bass_dirty ||
  124. hdw->treble_dirty ||
  125. hdw->mute_dirty);
  126. }
  127. const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume = {
  128. .check = check_volume,
  129. .update = set_volume,
  130. .name = "v4l2_volume",
  131. };
  132. static void set_audiomode(struct pvr2_hdw *hdw)
  133. {
  134. struct v4l2_tuner vt;
  135. memset(&vt,0,sizeof(vt));
  136. vt.audmode = hdw->audiomode_val;
  137. pvr2_i2c_core_cmd(hdw,VIDIOC_S_TUNER,&vt);
  138. }
  139. static int check_audiomode(struct pvr2_hdw *hdw)
  140. {
  141. return (hdw->input_dirty ||
  142. hdw->audiomode_dirty);
  143. }
  144. const struct pvr2_i2c_op pvr2_i2c_op_v4l2_audiomode = {
  145. .check = check_audiomode,
  146. .update = set_audiomode,
  147. .name = "v4l2_audiomode",
  148. };
  149. static void set_frequency(struct pvr2_hdw *hdw)
  150. {
  151. unsigned long fv;
  152. struct v4l2_frequency freq;
  153. fv = pvr2_hdw_get_cur_freq(hdw);
  154. pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_freq(%lu)",fv);
  155. if (hdw->tuner_signal_stale) {
  156. pvr2_i2c_core_status_poll(hdw);
  157. }
  158. memset(&freq,0,sizeof(freq));
  159. if (hdw->tuner_signal_info.capability & V4L2_TUNER_CAP_LOW) {
  160. // ((fv * 1000) / 62500)
  161. freq.frequency = (fv * 2) / 125;
  162. } else {
  163. freq.frequency = fv / 62500;
  164. }
  165. /* tuner-core currently doesn't seem to care about this, but
  166. let's set it anyway for completeness. */
  167. if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
  168. freq.type = V4L2_TUNER_RADIO;
  169. } else {
  170. freq.type = V4L2_TUNER_ANALOG_TV;
  171. }
  172. freq.tuner = 0;
  173. pvr2_i2c_core_cmd(hdw,VIDIOC_S_FREQUENCY,&freq);
  174. }
  175. static int check_frequency(struct pvr2_hdw *hdw)
  176. {
  177. return hdw->freqDirty != 0;
  178. }
  179. const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency = {
  180. .check = check_frequency,
  181. .update = set_frequency,
  182. .name = "v4l2_freq",
  183. };
  184. static void set_size(struct pvr2_hdw *hdw)
  185. {
  186. struct v4l2_format fmt;
  187. memset(&fmt,0,sizeof(fmt));
  188. fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  189. fmt.fmt.pix.width = hdw->res_hor_val;
  190. fmt.fmt.pix.height = hdw->res_ver_val;
  191. pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_size(%dx%d)",
  192. fmt.fmt.pix.width,fmt.fmt.pix.height);
  193. pvr2_i2c_core_cmd(hdw,VIDIOC_S_FMT,&fmt);
  194. }
  195. static int check_size(struct pvr2_hdw *hdw)
  196. {
  197. return (hdw->res_hor_dirty || hdw->res_ver_dirty);
  198. }
  199. const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size = {
  200. .check = check_size,
  201. .update = set_size,
  202. .name = "v4l2_size",
  203. };
  204. static void set_crop(struct pvr2_hdw *hdw)
  205. {
  206. struct v4l2_crop crop;
  207. memset(&crop, 0, sizeof crop);
  208. crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  209. crop.c.left = hdw->cropl_val;
  210. crop.c.top = hdw->cropt_val;
  211. crop.c.height = hdw->croph_val;
  212. crop.c.width = hdw->cropw_val;
  213. pvr2_trace(PVR2_TRACE_CHIPS,
  214. "i2c v4l2 set_crop crop=%d:%d:%d:%d",
  215. crop.c.width, crop.c.height, crop.c.left, crop.c.top);
  216. pvr2_i2c_core_cmd(hdw, VIDIOC_S_CROP, &crop);
  217. }
  218. static int check_crop(struct pvr2_hdw *hdw)
  219. {
  220. return (hdw->cropl_dirty || hdw->cropt_dirty ||
  221. hdw->cropw_dirty || hdw->croph_dirty);
  222. }
  223. const struct pvr2_i2c_op pvr2_i2c_op_v4l2_crop = {
  224. .check = check_crop,
  225. .update = set_crop,
  226. .name = "v4l2_crop",
  227. };
  228. static void do_log(struct pvr2_hdw *hdw)
  229. {
  230. pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 do_log()");
  231. pvr2_i2c_core_cmd(hdw,VIDIOC_LOG_STATUS,NULL);
  232. }
  233. static int check_log(struct pvr2_hdw *hdw)
  234. {
  235. return hdw->log_requested != 0;
  236. }
  237. const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log = {
  238. .check = check_log,
  239. .update = do_log,
  240. .name = "v4l2_log",
  241. };
  242. void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *cp,int fl)
  243. {
  244. pvr2_i2c_client_cmd(cp,
  245. (fl ? VIDIOC_STREAMON : VIDIOC_STREAMOFF),NULL);
  246. }
  247. void pvr2_v4l2_cmd_status_poll(struct pvr2_i2c_client *cp)
  248. {
  249. int stat;
  250. struct pvr2_hdw *hdw = cp->hdw;
  251. if (hdw->cropcap_stale) {
  252. hdw->cropcap_info.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  253. stat = pvr2_i2c_client_cmd(cp, VIDIOC_CROPCAP,
  254. &hdw->cropcap_info);
  255. if (stat == 0) {
  256. /* Check was successful, so the data is no
  257. longer considered stale. */
  258. hdw->cropcap_stale = 0;
  259. }
  260. }
  261. pvr2_i2c_client_cmd(cp, VIDIOC_G_TUNER, &hdw->tuner_signal_info);
  262. }
  263. /*
  264. Stuff for Emacs to see, in order to encourage consistent editing style:
  265. *** Local Variables: ***
  266. *** mode: c ***
  267. *** fill-column: 70 ***
  268. *** tab-width: 8 ***
  269. *** c-basic-offset: 8 ***
  270. *** End: ***
  271. */