pvrusb2-i2c-cmd-v4l2.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. 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. }
  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_frequency(struct pvr2_hdw *hdw)
  122. {
  123. unsigned long fv;
  124. struct v4l2_frequency freq;
  125. fv = hdw->freqVal;
  126. pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_freq(%lu)",fv);
  127. memset(&freq,0,sizeof(freq));
  128. if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
  129. // ((fv * 1000) / 62500)
  130. freq.frequency = (fv * 2) / 125;
  131. freq.type = V4L2_TUNER_RADIO;
  132. } else {
  133. freq.frequency = fv / 62500;
  134. freq.type = V4L2_TUNER_ANALOG_TV;
  135. }
  136. freq.tuner = 0;
  137. pvr2_i2c_core_cmd(hdw,VIDIOC_S_FREQUENCY,&freq);
  138. }
  139. static int check_frequency(struct pvr2_hdw *hdw)
  140. {
  141. return hdw->freqDirty != 0;
  142. }
  143. const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency = {
  144. .check = check_frequency,
  145. .update = set_frequency,
  146. .name = "v4l2_freq",
  147. };
  148. static void set_size(struct pvr2_hdw *hdw)
  149. {
  150. struct v4l2_format fmt;
  151. memset(&fmt,0,sizeof(fmt));
  152. fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  153. fmt.fmt.pix.width = hdw->res_hor_val;
  154. fmt.fmt.pix.height = hdw->res_ver_val;
  155. pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_size(%dx%d)",
  156. fmt.fmt.pix.width,fmt.fmt.pix.height);
  157. pvr2_i2c_core_cmd(hdw,VIDIOC_S_FMT,&fmt);
  158. }
  159. static int check_size(struct pvr2_hdw *hdw)
  160. {
  161. return (hdw->res_hor_dirty || hdw->res_ver_dirty);
  162. }
  163. const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size = {
  164. .check = check_size,
  165. .update = set_size,
  166. .name = "v4l2_size",
  167. };
  168. static void do_log(struct pvr2_hdw *hdw)
  169. {
  170. pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 do_log()");
  171. pvr2_i2c_core_cmd(hdw,VIDIOC_LOG_STATUS,NULL);
  172. }
  173. static int check_log(struct pvr2_hdw *hdw)
  174. {
  175. return hdw->log_requested != 0;
  176. }
  177. const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log = {
  178. .check = check_log,
  179. .update = do_log,
  180. .name = "v4l2_log",
  181. };
  182. void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *cp,int fl)
  183. {
  184. pvr2_i2c_client_cmd(cp,
  185. (fl ? VIDIOC_STREAMON : VIDIOC_STREAMOFF),NULL);
  186. }
  187. /*
  188. Stuff for Emacs to see, in order to encourage consistent editing style:
  189. *** Local Variables: ***
  190. *** mode: c ***
  191. *** fill-column: 70 ***
  192. *** tab-width: 8 ***
  193. *** c-basic-offset: 8 ***
  194. *** End: ***
  195. */