pvrusb2-i2c-cmd-v4l2.c 5.9 KB

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