pvrusb2-i2c-cmd-v4l2.c 6.4 KB

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