/drivers/media/video/pvrusb2/pvrusb2-hdw.c

https://bitbucket.org/wisechild/galaxy-nexus · C · 5322 lines · 4253 code · 603 blank · 466 comment · 714 complexity · 7c94954335ac73ba1975e7d8876f4c34 MD5 · raw file

Large files are truncated click here to view the full file

  1. /*
  2. *
  3. *
  4. * Copyright (C) 2005 Mike Isely <isely@pobox.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. */
  20. #include <linux/errno.h>
  21. #include <linux/string.h>
  22. #include <linux/slab.h>
  23. #include <linux/firmware.h>
  24. #include <linux/videodev2.h>
  25. #include <media/v4l2-common.h>
  26. #include <media/tuner.h>
  27. #include "pvrusb2.h"
  28. #include "pvrusb2-std.h"
  29. #include "pvrusb2-util.h"
  30. #include "pvrusb2-hdw.h"
  31. #include "pvrusb2-i2c-core.h"
  32. #include "pvrusb2-eeprom.h"
  33. #include "pvrusb2-hdw-internal.h"
  34. #include "pvrusb2-encoder.h"
  35. #include "pvrusb2-debug.h"
  36. #include "pvrusb2-fx2-cmd.h"
  37. #include "pvrusb2-wm8775.h"
  38. #include "pvrusb2-video-v4l.h"
  39. #include "pvrusb2-cx2584x-v4l.h"
  40. #include "pvrusb2-cs53l32a.h"
  41. #include "pvrusb2-audio.h"
  42. #define TV_MIN_FREQ 55250000L
  43. #define TV_MAX_FREQ 850000000L
  44. /* This defines a minimum interval that the decoder must remain quiet
  45. before we are allowed to start it running. */
  46. #define TIME_MSEC_DECODER_WAIT 50
  47. /* This defines a minimum interval that the decoder must be allowed to run
  48. before we can safely begin using its streaming output. */
  49. #define TIME_MSEC_DECODER_STABILIZATION_WAIT 300
  50. /* This defines a minimum interval that the encoder must remain quiet
  51. before we are allowed to configure it. */
  52. #define TIME_MSEC_ENCODER_WAIT 50
  53. /* This defines the minimum interval that the encoder must successfully run
  54. before we consider that the encoder has run at least once since its
  55. firmware has been loaded. This measurement is in important for cases
  56. where we can't do something until we know that the encoder has been run
  57. at least once. */
  58. #define TIME_MSEC_ENCODER_OK 250
  59. static struct pvr2_hdw *unit_pointers[PVR_NUM] = {[ 0 ... PVR_NUM-1 ] = NULL};
  60. static DEFINE_MUTEX(pvr2_unit_mtx);
  61. static int ctlchg;
  62. static int procreload;
  63. static int tuner[PVR_NUM] = { [0 ... PVR_NUM-1] = -1 };
  64. static int tolerance[PVR_NUM] = { [0 ... PVR_NUM-1] = 0 };
  65. static int video_std[PVR_NUM] = { [0 ... PVR_NUM-1] = 0 };
  66. static int init_pause_msec;
  67. module_param(ctlchg, int, S_IRUGO|S_IWUSR);
  68. MODULE_PARM_DESC(ctlchg, "0=optimize ctl change 1=always accept new ctl value");
  69. module_param(init_pause_msec, int, S_IRUGO|S_IWUSR);
  70. MODULE_PARM_DESC(init_pause_msec, "hardware initialization settling delay");
  71. module_param(procreload, int, S_IRUGO|S_IWUSR);
  72. MODULE_PARM_DESC(procreload,
  73. "Attempt init failure recovery with firmware reload");
  74. module_param_array(tuner, int, NULL, 0444);
  75. MODULE_PARM_DESC(tuner,"specify installed tuner type");
  76. module_param_array(video_std, int, NULL, 0444);
  77. MODULE_PARM_DESC(video_std,"specify initial video standard");
  78. module_param_array(tolerance, int, NULL, 0444);
  79. MODULE_PARM_DESC(tolerance,"specify stream error tolerance");
  80. /* US Broadcast channel 3 (61.25 MHz), to help with testing */
  81. static int default_tv_freq = 61250000L;
  82. /* 104.3 MHz, a usable FM station for my area */
  83. static int default_radio_freq = 104300000L;
  84. module_param_named(tv_freq, default_tv_freq, int, 0444);
  85. MODULE_PARM_DESC(tv_freq, "specify initial television frequency");
  86. module_param_named(radio_freq, default_radio_freq, int, 0444);
  87. MODULE_PARM_DESC(radio_freq, "specify initial radio frequency");
  88. #define PVR2_CTL_WRITE_ENDPOINT 0x01
  89. #define PVR2_CTL_READ_ENDPOINT 0x81
  90. #define PVR2_GPIO_IN 0x9008
  91. #define PVR2_GPIO_OUT 0x900c
  92. #define PVR2_GPIO_DIR 0x9020
  93. #define trace_firmware(...) pvr2_trace(PVR2_TRACE_FIRMWARE,__VA_ARGS__)
  94. #define PVR2_FIRMWARE_ENDPOINT 0x02
  95. /* size of a firmware chunk */
  96. #define FIRMWARE_CHUNK_SIZE 0x2000
  97. typedef void (*pvr2_subdev_update_func)(struct pvr2_hdw *,
  98. struct v4l2_subdev *);
  99. static const pvr2_subdev_update_func pvr2_module_update_functions[] = {
  100. [PVR2_CLIENT_ID_WM8775] = pvr2_wm8775_subdev_update,
  101. [PVR2_CLIENT_ID_SAA7115] = pvr2_saa7115_subdev_update,
  102. [PVR2_CLIENT_ID_MSP3400] = pvr2_msp3400_subdev_update,
  103. [PVR2_CLIENT_ID_CX25840] = pvr2_cx25840_subdev_update,
  104. [PVR2_CLIENT_ID_CS53L32A] = pvr2_cs53l32a_subdev_update,
  105. };
  106. static const char *module_names[] = {
  107. [PVR2_CLIENT_ID_MSP3400] = "msp3400",
  108. [PVR2_CLIENT_ID_CX25840] = "cx25840",
  109. [PVR2_CLIENT_ID_SAA7115] = "saa7115",
  110. [PVR2_CLIENT_ID_TUNER] = "tuner",
  111. [PVR2_CLIENT_ID_DEMOD] = "tuner",
  112. [PVR2_CLIENT_ID_CS53L32A] = "cs53l32a",
  113. [PVR2_CLIENT_ID_WM8775] = "wm8775",
  114. };
  115. static const unsigned char *module_i2c_addresses[] = {
  116. [PVR2_CLIENT_ID_TUNER] = "\x60\x61\x62\x63",
  117. [PVR2_CLIENT_ID_DEMOD] = "\x43",
  118. [PVR2_CLIENT_ID_MSP3400] = "\x40",
  119. [PVR2_CLIENT_ID_SAA7115] = "\x21",
  120. [PVR2_CLIENT_ID_WM8775] = "\x1b",
  121. [PVR2_CLIENT_ID_CX25840] = "\x44",
  122. [PVR2_CLIENT_ID_CS53L32A] = "\x11",
  123. };
  124. static const char *ir_scheme_names[] = {
  125. [PVR2_IR_SCHEME_NONE] = "none",
  126. [PVR2_IR_SCHEME_29XXX] = "29xxx",
  127. [PVR2_IR_SCHEME_24XXX] = "24xxx (29xxx emulation)",
  128. [PVR2_IR_SCHEME_24XXX_MCE] = "24xxx (MCE device)",
  129. [PVR2_IR_SCHEME_ZILOG] = "Zilog",
  130. };
  131. /* Define the list of additional controls we'll dynamically construct based
  132. on query of the cx2341x module. */
  133. struct pvr2_mpeg_ids {
  134. const char *strid;
  135. int id;
  136. };
  137. static const struct pvr2_mpeg_ids mpeg_ids[] = {
  138. {
  139. .strid = "audio_layer",
  140. .id = V4L2_CID_MPEG_AUDIO_ENCODING,
  141. },{
  142. .strid = "audio_bitrate",
  143. .id = V4L2_CID_MPEG_AUDIO_L2_BITRATE,
  144. },{
  145. /* Already using audio_mode elsewhere :-( */
  146. .strid = "mpeg_audio_mode",
  147. .id = V4L2_CID_MPEG_AUDIO_MODE,
  148. },{
  149. .strid = "mpeg_audio_mode_extension",
  150. .id = V4L2_CID_MPEG_AUDIO_MODE_EXTENSION,
  151. },{
  152. .strid = "audio_emphasis",
  153. .id = V4L2_CID_MPEG_AUDIO_EMPHASIS,
  154. },{
  155. .strid = "audio_crc",
  156. .id = V4L2_CID_MPEG_AUDIO_CRC,
  157. },{
  158. .strid = "video_aspect",
  159. .id = V4L2_CID_MPEG_VIDEO_ASPECT,
  160. },{
  161. .strid = "video_b_frames",
  162. .id = V4L2_CID_MPEG_VIDEO_B_FRAMES,
  163. },{
  164. .strid = "video_gop_size",
  165. .id = V4L2_CID_MPEG_VIDEO_GOP_SIZE,
  166. },{
  167. .strid = "video_gop_closure",
  168. .id = V4L2_CID_MPEG_VIDEO_GOP_CLOSURE,
  169. },{
  170. .strid = "video_bitrate_mode",
  171. .id = V4L2_CID_MPEG_VIDEO_BITRATE_MODE,
  172. },{
  173. .strid = "video_bitrate",
  174. .id = V4L2_CID_MPEG_VIDEO_BITRATE,
  175. },{
  176. .strid = "video_bitrate_peak",
  177. .id = V4L2_CID_MPEG_VIDEO_BITRATE_PEAK,
  178. },{
  179. .strid = "video_temporal_decimation",
  180. .id = V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION,
  181. },{
  182. .strid = "stream_type",
  183. .id = V4L2_CID_MPEG_STREAM_TYPE,
  184. },{
  185. .strid = "video_spatial_filter_mode",
  186. .id = V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE,
  187. },{
  188. .strid = "video_spatial_filter",
  189. .id = V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER,
  190. },{
  191. .strid = "video_luma_spatial_filter_type",
  192. .id = V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE,
  193. },{
  194. .strid = "video_chroma_spatial_filter_type",
  195. .id = V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE,
  196. },{
  197. .strid = "video_temporal_filter_mode",
  198. .id = V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE,
  199. },{
  200. .strid = "video_temporal_filter",
  201. .id = V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER,
  202. },{
  203. .strid = "video_median_filter_type",
  204. .id = V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE,
  205. },{
  206. .strid = "video_luma_median_filter_top",
  207. .id = V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP,
  208. },{
  209. .strid = "video_luma_median_filter_bottom",
  210. .id = V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM,
  211. },{
  212. .strid = "video_chroma_median_filter_top",
  213. .id = V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP,
  214. },{
  215. .strid = "video_chroma_median_filter_bottom",
  216. .id = V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM,
  217. }
  218. };
  219. #define MPEGDEF_COUNT ARRAY_SIZE(mpeg_ids)
  220. static const char *control_values_srate[] = {
  221. [V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100] = "44.1 kHz",
  222. [V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000] = "48 kHz",
  223. [V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000] = "32 kHz",
  224. };
  225. static const char *control_values_input[] = {
  226. [PVR2_CVAL_INPUT_TV] = "television", /*xawtv needs this name*/
  227. [PVR2_CVAL_INPUT_DTV] = "dtv",
  228. [PVR2_CVAL_INPUT_RADIO] = "radio",
  229. [PVR2_CVAL_INPUT_SVIDEO] = "s-video",
  230. [PVR2_CVAL_INPUT_COMPOSITE] = "composite",
  231. };
  232. static const char *control_values_audiomode[] = {
  233. [V4L2_TUNER_MODE_MONO] = "Mono",
  234. [V4L2_TUNER_MODE_STEREO] = "Stereo",
  235. [V4L2_TUNER_MODE_LANG1] = "Lang1",
  236. [V4L2_TUNER_MODE_LANG2] = "Lang2",
  237. [V4L2_TUNER_MODE_LANG1_LANG2] = "Lang1+Lang2",
  238. };
  239. static const char *control_values_hsm[] = {
  240. [PVR2_CVAL_HSM_FAIL] = "Fail",
  241. [PVR2_CVAL_HSM_HIGH] = "High",
  242. [PVR2_CVAL_HSM_FULL] = "Full",
  243. };
  244. static const char *pvr2_state_names[] = {
  245. [PVR2_STATE_NONE] = "none",
  246. [PVR2_STATE_DEAD] = "dead",
  247. [PVR2_STATE_COLD] = "cold",
  248. [PVR2_STATE_WARM] = "warm",
  249. [PVR2_STATE_ERROR] = "error",
  250. [PVR2_STATE_READY] = "ready",
  251. [PVR2_STATE_RUN] = "run",
  252. };
  253. struct pvr2_fx2cmd_descdef {
  254. unsigned char id;
  255. unsigned char *desc;
  256. };
  257. static const struct pvr2_fx2cmd_descdef pvr2_fx2cmd_desc[] = {
  258. {FX2CMD_MEM_WRITE_DWORD, "write encoder dword"},
  259. {FX2CMD_MEM_READ_DWORD, "read encoder dword"},
  260. {FX2CMD_HCW_ZILOG_RESET, "zilog IR reset control"},
  261. {FX2CMD_MEM_READ_64BYTES, "read encoder 64bytes"},
  262. {FX2CMD_REG_WRITE, "write encoder register"},
  263. {FX2CMD_REG_READ, "read encoder register"},
  264. {FX2CMD_MEMSEL, "encoder memsel"},
  265. {FX2CMD_I2C_WRITE, "i2c write"},
  266. {FX2CMD_I2C_READ, "i2c read"},
  267. {FX2CMD_GET_USB_SPEED, "get USB speed"},
  268. {FX2CMD_STREAMING_ON, "stream on"},
  269. {FX2CMD_STREAMING_OFF, "stream off"},
  270. {FX2CMD_FWPOST1, "fwpost1"},
  271. {FX2CMD_POWER_OFF, "power off"},
  272. {FX2CMD_POWER_ON, "power on"},
  273. {FX2CMD_DEEP_RESET, "deep reset"},
  274. {FX2CMD_GET_EEPROM_ADDR, "get rom addr"},
  275. {FX2CMD_GET_IR_CODE, "get IR code"},
  276. {FX2CMD_HCW_DEMOD_RESETIN, "hcw demod resetin"},
  277. {FX2CMD_HCW_DTV_STREAMING_ON, "hcw dtv stream on"},
  278. {FX2CMD_HCW_DTV_STREAMING_OFF, "hcw dtv stream off"},
  279. {FX2CMD_ONAIR_DTV_STREAMING_ON, "onair dtv stream on"},
  280. {FX2CMD_ONAIR_DTV_STREAMING_OFF, "onair dtv stream off"},
  281. {FX2CMD_ONAIR_DTV_POWER_ON, "onair dtv power on"},
  282. {FX2CMD_ONAIR_DTV_POWER_OFF, "onair dtv power off"},
  283. };
  284. static int pvr2_hdw_set_input(struct pvr2_hdw *hdw,int v);
  285. static void pvr2_hdw_state_sched(struct pvr2_hdw *);
  286. static int pvr2_hdw_state_eval(struct pvr2_hdw *);
  287. static void pvr2_hdw_set_cur_freq(struct pvr2_hdw *,unsigned long);
  288. static void pvr2_hdw_worker_poll(struct work_struct *work);
  289. static int pvr2_hdw_wait(struct pvr2_hdw *,int state);
  290. static int pvr2_hdw_untrip_unlocked(struct pvr2_hdw *);
  291. static void pvr2_hdw_state_log_state(struct pvr2_hdw *);
  292. static int pvr2_hdw_cmd_usbstream(struct pvr2_hdw *hdw,int runFl);
  293. static int pvr2_hdw_commit_setup(struct pvr2_hdw *hdw);
  294. static int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *hdw);
  295. static void pvr2_hdw_internal_find_stdenum(struct pvr2_hdw *hdw);
  296. static void pvr2_hdw_internal_set_std_avail(struct pvr2_hdw *hdw);
  297. static void pvr2_hdw_quiescent_timeout(unsigned long);
  298. static void pvr2_hdw_decoder_stabilization_timeout(unsigned long);
  299. static void pvr2_hdw_encoder_wait_timeout(unsigned long);
  300. static void pvr2_hdw_encoder_run_timeout(unsigned long);
  301. static int pvr2_issue_simple_cmd(struct pvr2_hdw *,u32);
  302. static int pvr2_send_request_ex(struct pvr2_hdw *hdw,
  303. unsigned int timeout,int probe_fl,
  304. void *write_data,unsigned int write_len,
  305. void *read_data,unsigned int read_len);
  306. static int pvr2_hdw_check_cropcap(struct pvr2_hdw *hdw);
  307. static void trace_stbit(const char *name,int val)
  308. {
  309. pvr2_trace(PVR2_TRACE_STBITS,
  310. "State bit %s <-- %s",
  311. name,(val ? "true" : "false"));
  312. }
  313. static int ctrl_channelfreq_get(struct pvr2_ctrl *cptr,int *vp)
  314. {
  315. struct pvr2_hdw *hdw = cptr->hdw;
  316. if ((hdw->freqProgSlot > 0) && (hdw->freqProgSlot <= FREQTABLE_SIZE)) {
  317. *vp = hdw->freqTable[hdw->freqProgSlot-1];
  318. } else {
  319. *vp = 0;
  320. }
  321. return 0;
  322. }
  323. static int ctrl_channelfreq_set(struct pvr2_ctrl *cptr,int m,int v)
  324. {
  325. struct pvr2_hdw *hdw = cptr->hdw;
  326. unsigned int slotId = hdw->freqProgSlot;
  327. if ((slotId > 0) && (slotId <= FREQTABLE_SIZE)) {
  328. hdw->freqTable[slotId-1] = v;
  329. /* Handle side effects correctly - if we're tuned to this
  330. slot, then forgot the slot id relation since the stored
  331. frequency has been changed. */
  332. if (hdw->freqSelector) {
  333. if (hdw->freqSlotRadio == slotId) {
  334. hdw->freqSlotRadio = 0;
  335. }
  336. } else {
  337. if (hdw->freqSlotTelevision == slotId) {
  338. hdw->freqSlotTelevision = 0;
  339. }
  340. }
  341. }
  342. return 0;
  343. }
  344. static int ctrl_channelprog_get(struct pvr2_ctrl *cptr,int *vp)
  345. {
  346. *vp = cptr->hdw->freqProgSlot;
  347. return 0;
  348. }
  349. static int ctrl_channelprog_set(struct pvr2_ctrl *cptr,int m,int v)
  350. {
  351. struct pvr2_hdw *hdw = cptr->hdw;
  352. if ((v >= 0) && (v <= FREQTABLE_SIZE)) {
  353. hdw->freqProgSlot = v;
  354. }
  355. return 0;
  356. }
  357. static int ctrl_channel_get(struct pvr2_ctrl *cptr,int *vp)
  358. {
  359. struct pvr2_hdw *hdw = cptr->hdw;
  360. *vp = hdw->freqSelector ? hdw->freqSlotRadio : hdw->freqSlotTelevision;
  361. return 0;
  362. }
  363. static int ctrl_channel_set(struct pvr2_ctrl *cptr,int m,int slotId)
  364. {
  365. unsigned freq = 0;
  366. struct pvr2_hdw *hdw = cptr->hdw;
  367. if ((slotId < 0) || (slotId > FREQTABLE_SIZE)) return 0;
  368. if (slotId > 0) {
  369. freq = hdw->freqTable[slotId-1];
  370. if (!freq) return 0;
  371. pvr2_hdw_set_cur_freq(hdw,freq);
  372. }
  373. if (hdw->freqSelector) {
  374. hdw->freqSlotRadio = slotId;
  375. } else {
  376. hdw->freqSlotTelevision = slotId;
  377. }
  378. return 0;
  379. }
  380. static int ctrl_freq_get(struct pvr2_ctrl *cptr,int *vp)
  381. {
  382. *vp = pvr2_hdw_get_cur_freq(cptr->hdw);
  383. return 0;
  384. }
  385. static int ctrl_freq_is_dirty(struct pvr2_ctrl *cptr)
  386. {
  387. return cptr->hdw->freqDirty != 0;
  388. }
  389. static void ctrl_freq_clear_dirty(struct pvr2_ctrl *cptr)
  390. {
  391. cptr->hdw->freqDirty = 0;
  392. }
  393. static int ctrl_freq_set(struct pvr2_ctrl *cptr,int m,int v)
  394. {
  395. pvr2_hdw_set_cur_freq(cptr->hdw,v);
  396. return 0;
  397. }
  398. static int ctrl_cropl_min_get(struct pvr2_ctrl *cptr, int *left)
  399. {
  400. struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
  401. int stat = pvr2_hdw_check_cropcap(cptr->hdw);
  402. if (stat != 0) {
  403. return stat;
  404. }
  405. *left = cap->bounds.left;
  406. return 0;
  407. }
  408. static int ctrl_cropl_max_get(struct pvr2_ctrl *cptr, int *left)
  409. {
  410. struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
  411. int stat = pvr2_hdw_check_cropcap(cptr->hdw);
  412. if (stat != 0) {
  413. return stat;
  414. }
  415. *left = cap->bounds.left;
  416. if (cap->bounds.width > cptr->hdw->cropw_val) {
  417. *left += cap->bounds.width - cptr->hdw->cropw_val;
  418. }
  419. return 0;
  420. }
  421. static int ctrl_cropt_min_get(struct pvr2_ctrl *cptr, int *top)
  422. {
  423. struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
  424. int stat = pvr2_hdw_check_cropcap(cptr->hdw);
  425. if (stat != 0) {
  426. return stat;
  427. }
  428. *top = cap->bounds.top;
  429. return 0;
  430. }
  431. static int ctrl_cropt_max_get(struct pvr2_ctrl *cptr, int *top)
  432. {
  433. struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
  434. int stat = pvr2_hdw_check_cropcap(cptr->hdw);
  435. if (stat != 0) {
  436. return stat;
  437. }
  438. *top = cap->bounds.top;
  439. if (cap->bounds.height > cptr->hdw->croph_val) {
  440. *top += cap->bounds.height - cptr->hdw->croph_val;
  441. }
  442. return 0;
  443. }
  444. static int ctrl_cropw_max_get(struct pvr2_ctrl *cptr, int *width)
  445. {
  446. struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
  447. int stat, bleftend, cleft;
  448. stat = pvr2_hdw_check_cropcap(cptr->hdw);
  449. if (stat != 0) {
  450. return stat;
  451. }
  452. bleftend = cap->bounds.left+cap->bounds.width;
  453. cleft = cptr->hdw->cropl_val;
  454. *width = cleft < bleftend ? bleftend-cleft : 0;
  455. return 0;
  456. }
  457. static int ctrl_croph_max_get(struct pvr2_ctrl *cptr, int *height)
  458. {
  459. struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
  460. int stat, btopend, ctop;
  461. stat = pvr2_hdw_check_cropcap(cptr->hdw);
  462. if (stat != 0) {
  463. return stat;
  464. }
  465. btopend = cap->bounds.top+cap->bounds.height;
  466. ctop = cptr->hdw->cropt_val;
  467. *height = ctop < btopend ? btopend-ctop : 0;
  468. return 0;
  469. }
  470. static int ctrl_get_cropcapbl(struct pvr2_ctrl *cptr, int *val)
  471. {
  472. struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
  473. int stat = pvr2_hdw_check_cropcap(cptr->hdw);
  474. if (stat != 0) {
  475. return stat;
  476. }
  477. *val = cap->bounds.left;
  478. return 0;
  479. }
  480. static int ctrl_get_cropcapbt(struct pvr2_ctrl *cptr, int *val)
  481. {
  482. struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
  483. int stat = pvr2_hdw_check_cropcap(cptr->hdw);
  484. if (stat != 0) {
  485. return stat;
  486. }
  487. *val = cap->bounds.top;
  488. return 0;
  489. }
  490. static int ctrl_get_cropcapbw(struct pvr2_ctrl *cptr, int *val)
  491. {
  492. struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
  493. int stat = pvr2_hdw_check_cropcap(cptr->hdw);
  494. if (stat != 0) {
  495. return stat;
  496. }
  497. *val = cap->bounds.width;
  498. return 0;
  499. }
  500. static int ctrl_get_cropcapbh(struct pvr2_ctrl *cptr, int *val)
  501. {
  502. struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
  503. int stat = pvr2_hdw_check_cropcap(cptr->hdw);
  504. if (stat != 0) {
  505. return stat;
  506. }
  507. *val = cap->bounds.height;
  508. return 0;
  509. }
  510. static int ctrl_get_cropcapdl(struct pvr2_ctrl *cptr, int *val)
  511. {
  512. struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
  513. int stat = pvr2_hdw_check_cropcap(cptr->hdw);
  514. if (stat != 0) {
  515. return stat;
  516. }
  517. *val = cap->defrect.left;
  518. return 0;
  519. }
  520. static int ctrl_get_cropcapdt(struct pvr2_ctrl *cptr, int *val)
  521. {
  522. struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
  523. int stat = pvr2_hdw_check_cropcap(cptr->hdw);
  524. if (stat != 0) {
  525. return stat;
  526. }
  527. *val = cap->defrect.top;
  528. return 0;
  529. }
  530. static int ctrl_get_cropcapdw(struct pvr2_ctrl *cptr, int *val)
  531. {
  532. struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
  533. int stat = pvr2_hdw_check_cropcap(cptr->hdw);
  534. if (stat != 0) {
  535. return stat;
  536. }
  537. *val = cap->defrect.width;
  538. return 0;
  539. }
  540. static int ctrl_get_cropcapdh(struct pvr2_ctrl *cptr, int *val)
  541. {
  542. struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
  543. int stat = pvr2_hdw_check_cropcap(cptr->hdw);
  544. if (stat != 0) {
  545. return stat;
  546. }
  547. *val = cap->defrect.height;
  548. return 0;
  549. }
  550. static int ctrl_get_cropcappan(struct pvr2_ctrl *cptr, int *val)
  551. {
  552. struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
  553. int stat = pvr2_hdw_check_cropcap(cptr->hdw);
  554. if (stat != 0) {
  555. return stat;
  556. }
  557. *val = cap->pixelaspect.numerator;
  558. return 0;
  559. }
  560. static int ctrl_get_cropcappad(struct pvr2_ctrl *cptr, int *val)
  561. {
  562. struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
  563. int stat = pvr2_hdw_check_cropcap(cptr->hdw);
  564. if (stat != 0) {
  565. return stat;
  566. }
  567. *val = cap->pixelaspect.denominator;
  568. return 0;
  569. }
  570. static int ctrl_vres_max_get(struct pvr2_ctrl *cptr,int *vp)
  571. {
  572. /* Actual maximum depends on the video standard in effect. */
  573. if (cptr->hdw->std_mask_cur & V4L2_STD_525_60) {
  574. *vp = 480;
  575. } else {
  576. *vp = 576;
  577. }
  578. return 0;
  579. }
  580. static int ctrl_vres_min_get(struct pvr2_ctrl *cptr,int *vp)
  581. {
  582. /* Actual minimum depends on device digitizer type. */
  583. if (cptr->hdw->hdw_desc->flag_has_cx25840) {
  584. *vp = 75;
  585. } else {
  586. *vp = 17;
  587. }
  588. return 0;
  589. }
  590. static int ctrl_get_input(struct pvr2_ctrl *cptr,int *vp)
  591. {
  592. *vp = cptr->hdw->input_val;
  593. return 0;
  594. }
  595. static int ctrl_check_input(struct pvr2_ctrl *cptr,int v)
  596. {
  597. return ((1 << v) & cptr->hdw->input_allowed_mask) != 0;
  598. }
  599. static int ctrl_set_input(struct pvr2_ctrl *cptr,int m,int v)
  600. {
  601. return pvr2_hdw_set_input(cptr->hdw,v);
  602. }
  603. static int ctrl_isdirty_input(struct pvr2_ctrl *cptr)
  604. {
  605. return cptr->hdw->input_dirty != 0;
  606. }
  607. static void ctrl_cleardirty_input(struct pvr2_ctrl *cptr)
  608. {
  609. cptr->hdw->input_dirty = 0;
  610. }
  611. static int ctrl_freq_max_get(struct pvr2_ctrl *cptr, int *vp)
  612. {
  613. unsigned long fv;
  614. struct pvr2_hdw *hdw = cptr->hdw;
  615. if (hdw->tuner_signal_stale) {
  616. pvr2_hdw_status_poll(hdw);
  617. }
  618. fv = hdw->tuner_signal_info.rangehigh;
  619. if (!fv) {
  620. /* Safety fallback */
  621. *vp = TV_MAX_FREQ;
  622. return 0;
  623. }
  624. if (hdw->tuner_signal_info.capability & V4L2_TUNER_CAP_LOW) {
  625. fv = (fv * 125) / 2;
  626. } else {
  627. fv = fv * 62500;
  628. }
  629. *vp = fv;
  630. return 0;
  631. }
  632. static int ctrl_freq_min_get(struct pvr2_ctrl *cptr, int *vp)
  633. {
  634. unsigned long fv;
  635. struct pvr2_hdw *hdw = cptr->hdw;
  636. if (hdw->tuner_signal_stale) {
  637. pvr2_hdw_status_poll(hdw);
  638. }
  639. fv = hdw->tuner_signal_info.rangelow;
  640. if (!fv) {
  641. /* Safety fallback */
  642. *vp = TV_MIN_FREQ;
  643. return 0;
  644. }
  645. if (hdw->tuner_signal_info.capability & V4L2_TUNER_CAP_LOW) {
  646. fv = (fv * 125) / 2;
  647. } else {
  648. fv = fv * 62500;
  649. }
  650. *vp = fv;
  651. return 0;
  652. }
  653. static int ctrl_cx2341x_is_dirty(struct pvr2_ctrl *cptr)
  654. {
  655. return cptr->hdw->enc_stale != 0;
  656. }
  657. static void ctrl_cx2341x_clear_dirty(struct pvr2_ctrl *cptr)
  658. {
  659. cptr->hdw->enc_stale = 0;
  660. cptr->hdw->enc_unsafe_stale = 0;
  661. }
  662. static int ctrl_cx2341x_get(struct pvr2_ctrl *cptr,int *vp)
  663. {
  664. int ret;
  665. struct v4l2_ext_controls cs;
  666. struct v4l2_ext_control c1;
  667. memset(&cs,0,sizeof(cs));
  668. memset(&c1,0,sizeof(c1));
  669. cs.controls = &c1;
  670. cs.count = 1;
  671. c1.id = cptr->info->v4l_id;
  672. ret = cx2341x_ext_ctrls(&cptr->hdw->enc_ctl_state, 0, &cs,
  673. VIDIOC_G_EXT_CTRLS);
  674. if (ret) return ret;
  675. *vp = c1.value;
  676. return 0;
  677. }
  678. static int ctrl_cx2341x_set(struct pvr2_ctrl *cptr,int m,int v)
  679. {
  680. int ret;
  681. struct pvr2_hdw *hdw = cptr->hdw;
  682. struct v4l2_ext_controls cs;
  683. struct v4l2_ext_control c1;
  684. memset(&cs,0,sizeof(cs));
  685. memset(&c1,0,sizeof(c1));
  686. cs.controls = &c1;
  687. cs.count = 1;
  688. c1.id = cptr->info->v4l_id;
  689. c1.value = v;
  690. ret = cx2341x_ext_ctrls(&hdw->enc_ctl_state,
  691. hdw->state_encoder_run, &cs,
  692. VIDIOC_S_EXT_CTRLS);
  693. if (ret == -EBUSY) {
  694. /* Oops. cx2341x is telling us it's not safe to change
  695. this control while we're capturing. Make a note of this
  696. fact so that the pipeline will be stopped the next time
  697. controls are committed. Then go on ahead and store this
  698. change anyway. */
  699. ret = cx2341x_ext_ctrls(&hdw->enc_ctl_state,
  700. 0, &cs,
  701. VIDIOC_S_EXT_CTRLS);
  702. if (!ret) hdw->enc_unsafe_stale = !0;
  703. }
  704. if (ret) return ret;
  705. hdw->enc_stale = !0;
  706. return 0;
  707. }
  708. static unsigned int ctrl_cx2341x_getv4lflags(struct pvr2_ctrl *cptr)
  709. {
  710. struct v4l2_queryctrl qctrl;
  711. struct pvr2_ctl_info *info;
  712. qctrl.id = cptr->info->v4l_id;
  713. cx2341x_ctrl_query(&cptr->hdw->enc_ctl_state,&qctrl);
  714. /* Strip out the const so we can adjust a function pointer. It's
  715. OK to do this here because we know this is a dynamically created
  716. control, so the underlying storage for the info pointer is (a)
  717. private to us, and (b) not in read-only storage. Either we do
  718. this or we significantly complicate the underlying control
  719. implementation. */
  720. info = (struct pvr2_ctl_info *)(cptr->info);
  721. if (qctrl.flags & V4L2_CTRL_FLAG_READ_ONLY) {
  722. if (info->set_value) {
  723. info->set_value = NULL;
  724. }
  725. } else {
  726. if (!(info->set_value)) {
  727. info->set_value = ctrl_cx2341x_set;
  728. }
  729. }
  730. return qctrl.flags;
  731. }
  732. static int ctrl_streamingenabled_get(struct pvr2_ctrl *cptr,int *vp)
  733. {
  734. *vp = cptr->hdw->state_pipeline_req;
  735. return 0;
  736. }
  737. static int ctrl_masterstate_get(struct pvr2_ctrl *cptr,int *vp)
  738. {
  739. *vp = cptr->hdw->master_state;
  740. return 0;
  741. }
  742. static int ctrl_hsm_get(struct pvr2_ctrl *cptr,int *vp)
  743. {
  744. int result = pvr2_hdw_is_hsm(cptr->hdw);
  745. *vp = PVR2_CVAL_HSM_FULL;
  746. if (result < 0) *vp = PVR2_CVAL_HSM_FAIL;
  747. if (result) *vp = PVR2_CVAL_HSM_HIGH;
  748. return 0;
  749. }
  750. static int ctrl_stdavail_get(struct pvr2_ctrl *cptr,int *vp)
  751. {
  752. *vp = cptr->hdw->std_mask_avail;
  753. return 0;
  754. }
  755. static int ctrl_stdavail_set(struct pvr2_ctrl *cptr,int m,int v)
  756. {
  757. struct pvr2_hdw *hdw = cptr->hdw;
  758. v4l2_std_id ns;
  759. ns = hdw->std_mask_avail;
  760. ns = (ns & ~m) | (v & m);
  761. if (ns == hdw->std_mask_avail) return 0;
  762. hdw->std_mask_avail = ns;
  763. pvr2_hdw_internal_set_std_avail(hdw);
  764. pvr2_hdw_internal_find_stdenum(hdw);
  765. return 0;
  766. }
  767. static int ctrl_std_val_to_sym(struct pvr2_ctrl *cptr,int msk,int val,
  768. char *bufPtr,unsigned int bufSize,
  769. unsigned int *len)
  770. {
  771. *len = pvr2_std_id_to_str(bufPtr,bufSize,msk & val);
  772. return 0;
  773. }
  774. static int ctrl_std_sym_to_val(struct pvr2_ctrl *cptr,
  775. const char *bufPtr,unsigned int bufSize,
  776. int *mskp,int *valp)
  777. {
  778. int ret;
  779. v4l2_std_id id;
  780. ret = pvr2_std_str_to_id(&id,bufPtr,bufSize);
  781. if (ret < 0) return ret;
  782. if (mskp) *mskp = id;
  783. if (valp) *valp = id;
  784. return 0;
  785. }
  786. static int ctrl_stdcur_get(struct pvr2_ctrl *cptr,int *vp)
  787. {
  788. *vp = cptr->hdw->std_mask_cur;
  789. return 0;
  790. }
  791. static int ctrl_stdcur_set(struct pvr2_ctrl *cptr,int m,int v)
  792. {
  793. struct pvr2_hdw *hdw = cptr->hdw;
  794. v4l2_std_id ns;
  795. ns = hdw->std_mask_cur;
  796. ns = (ns & ~m) | (v & m);
  797. if (ns == hdw->std_mask_cur) return 0;
  798. hdw->std_mask_cur = ns;
  799. hdw->std_dirty = !0;
  800. pvr2_hdw_internal_find_stdenum(hdw);
  801. return 0;
  802. }
  803. static int ctrl_stdcur_is_dirty(struct pvr2_ctrl *cptr)
  804. {
  805. return cptr->hdw->std_dirty != 0;
  806. }
  807. static void ctrl_stdcur_clear_dirty(struct pvr2_ctrl *cptr)
  808. {
  809. cptr->hdw->std_dirty = 0;
  810. }
  811. static int ctrl_signal_get(struct pvr2_ctrl *cptr,int *vp)
  812. {
  813. struct pvr2_hdw *hdw = cptr->hdw;
  814. pvr2_hdw_status_poll(hdw);
  815. *vp = hdw->tuner_signal_info.signal;
  816. return 0;
  817. }
  818. static int ctrl_audio_modes_present_get(struct pvr2_ctrl *cptr,int *vp)
  819. {
  820. int val = 0;
  821. unsigned int subchan;
  822. struct pvr2_hdw *hdw = cptr->hdw;
  823. pvr2_hdw_status_poll(hdw);
  824. subchan = hdw->tuner_signal_info.rxsubchans;
  825. if (subchan & V4L2_TUNER_SUB_MONO) {
  826. val |= (1 << V4L2_TUNER_MODE_MONO);
  827. }
  828. if (subchan & V4L2_TUNER_SUB_STEREO) {
  829. val |= (1 << V4L2_TUNER_MODE_STEREO);
  830. }
  831. if (subchan & V4L2_TUNER_SUB_LANG1) {
  832. val |= (1 << V4L2_TUNER_MODE_LANG1);
  833. }
  834. if (subchan & V4L2_TUNER_SUB_LANG2) {
  835. val |= (1 << V4L2_TUNER_MODE_LANG2);
  836. }
  837. *vp = val;
  838. return 0;
  839. }
  840. static int ctrl_stdenumcur_set(struct pvr2_ctrl *cptr,int m,int v)
  841. {
  842. struct pvr2_hdw *hdw = cptr->hdw;
  843. if (v < 0) return -EINVAL;
  844. if (v > hdw->std_enum_cnt) return -EINVAL;
  845. hdw->std_enum_cur = v;
  846. if (!v) return 0;
  847. v--;
  848. if (hdw->std_mask_cur == hdw->std_defs[v].id) return 0;
  849. hdw->std_mask_cur = hdw->std_defs[v].id;
  850. hdw->std_dirty = !0;
  851. return 0;
  852. }
  853. static int ctrl_stdenumcur_get(struct pvr2_ctrl *cptr,int *vp)
  854. {
  855. *vp = cptr->hdw->std_enum_cur;
  856. return 0;
  857. }
  858. static int ctrl_stdenumcur_is_dirty(struct pvr2_ctrl *cptr)
  859. {
  860. return cptr->hdw->std_dirty != 0;
  861. }
  862. static void ctrl_stdenumcur_clear_dirty(struct pvr2_ctrl *cptr)
  863. {
  864. cptr->hdw->std_dirty = 0;
  865. }
  866. #define DEFINT(vmin,vmax) \
  867. .type = pvr2_ctl_int, \
  868. .def.type_int.min_value = vmin, \
  869. .def.type_int.max_value = vmax
  870. #define DEFENUM(tab) \
  871. .type = pvr2_ctl_enum, \
  872. .def.type_enum.count = ARRAY_SIZE(tab), \
  873. .def.type_enum.value_names = tab
  874. #define DEFBOOL \
  875. .type = pvr2_ctl_bool
  876. #define DEFMASK(msk,tab) \
  877. .type = pvr2_ctl_bitmask, \
  878. .def.type_bitmask.valid_bits = msk, \
  879. .def.type_bitmask.bit_names = tab
  880. #define DEFREF(vname) \
  881. .set_value = ctrl_set_##vname, \
  882. .get_value = ctrl_get_##vname, \
  883. .is_dirty = ctrl_isdirty_##vname, \
  884. .clear_dirty = ctrl_cleardirty_##vname
  885. #define VCREATE_FUNCS(vname) \
  886. static int ctrl_get_##vname(struct pvr2_ctrl *cptr,int *vp) \
  887. {*vp = cptr->hdw->vname##_val; return 0;} \
  888. static int ctrl_set_##vname(struct pvr2_ctrl *cptr,int m,int v) \
  889. {cptr->hdw->vname##_val = v; cptr->hdw->vname##_dirty = !0; return 0;} \
  890. static int ctrl_isdirty_##vname(struct pvr2_ctrl *cptr) \
  891. {return cptr->hdw->vname##_dirty != 0;} \
  892. static void ctrl_cleardirty_##vname(struct pvr2_ctrl *cptr) \
  893. {cptr->hdw->vname##_dirty = 0;}
  894. VCREATE_FUNCS(brightness)
  895. VCREATE_FUNCS(contrast)
  896. VCREATE_FUNCS(saturation)
  897. VCREATE_FUNCS(hue)
  898. VCREATE_FUNCS(volume)
  899. VCREATE_FUNCS(balance)
  900. VCREATE_FUNCS(bass)
  901. VCREATE_FUNCS(treble)
  902. VCREATE_FUNCS(mute)
  903. VCREATE_FUNCS(cropl)
  904. VCREATE_FUNCS(cropt)
  905. VCREATE_FUNCS(cropw)
  906. VCREATE_FUNCS(croph)
  907. VCREATE_FUNCS(audiomode)
  908. VCREATE_FUNCS(res_hor)
  909. VCREATE_FUNCS(res_ver)
  910. VCREATE_FUNCS(srate)
  911. /* Table definition of all controls which can be manipulated */
  912. static const struct pvr2_ctl_info control_defs[] = {
  913. {
  914. .v4l_id = V4L2_CID_BRIGHTNESS,
  915. .desc = "Brightness",
  916. .name = "brightness",
  917. .default_value = 128,
  918. DEFREF(brightness),
  919. DEFINT(0,255),
  920. },{
  921. .v4l_id = V4L2_CID_CONTRAST,
  922. .desc = "Contrast",
  923. .name = "contrast",
  924. .default_value = 68,
  925. DEFREF(contrast),
  926. DEFINT(0,127),
  927. },{
  928. .v4l_id = V4L2_CID_SATURATION,
  929. .desc = "Saturation",
  930. .name = "saturation",
  931. .default_value = 64,
  932. DEFREF(saturation),
  933. DEFINT(0,127),
  934. },{
  935. .v4l_id = V4L2_CID_HUE,
  936. .desc = "Hue",
  937. .name = "hue",
  938. .default_value = 0,
  939. DEFREF(hue),
  940. DEFINT(-128,127),
  941. },{
  942. .v4l_id = V4L2_CID_AUDIO_VOLUME,
  943. .desc = "Volume",
  944. .name = "volume",
  945. .default_value = 62000,
  946. DEFREF(volume),
  947. DEFINT(0,65535),
  948. },{
  949. .v4l_id = V4L2_CID_AUDIO_BALANCE,
  950. .desc = "Balance",
  951. .name = "balance",
  952. .default_value = 0,
  953. DEFREF(balance),
  954. DEFINT(-32768,32767),
  955. },{
  956. .v4l_id = V4L2_CID_AUDIO_BASS,
  957. .desc = "Bass",
  958. .name = "bass",
  959. .default_value = 0,
  960. DEFREF(bass),
  961. DEFINT(-32768,32767),
  962. },{
  963. .v4l_id = V4L2_CID_AUDIO_TREBLE,
  964. .desc = "Treble",
  965. .name = "treble",
  966. .default_value = 0,
  967. DEFREF(treble),
  968. DEFINT(-32768,32767),
  969. },{
  970. .v4l_id = V4L2_CID_AUDIO_MUTE,
  971. .desc = "Mute",
  972. .name = "mute",
  973. .default_value = 0,
  974. DEFREF(mute),
  975. DEFBOOL,
  976. }, {
  977. .desc = "Capture crop left margin",
  978. .name = "crop_left",
  979. .internal_id = PVR2_CID_CROPL,
  980. .default_value = 0,
  981. DEFREF(cropl),
  982. DEFINT(-129, 340),
  983. .get_min_value = ctrl_cropl_min_get,
  984. .get_max_value = ctrl_cropl_max_get,
  985. .get_def_value = ctrl_get_cropcapdl,
  986. }, {
  987. .desc = "Capture crop top margin",
  988. .name = "crop_top",
  989. .internal_id = PVR2_CID_CROPT,
  990. .default_value = 0,
  991. DEFREF(cropt),
  992. DEFINT(-35, 544),
  993. .get_min_value = ctrl_cropt_min_get,
  994. .get_max_value = ctrl_cropt_max_get,
  995. .get_def_value = ctrl_get_cropcapdt,
  996. }, {
  997. .desc = "Capture crop width",
  998. .name = "crop_width",
  999. .internal_id = PVR2_CID_CROPW,
  1000. .default_value = 720,
  1001. DEFREF(cropw),
  1002. DEFINT(0, 864),
  1003. .get_max_value = ctrl_cropw_max_get,
  1004. .get_def_value = ctrl_get_cropcapdw,
  1005. }, {
  1006. .desc = "Capture crop height",
  1007. .name = "crop_height",
  1008. .internal_id = PVR2_CID_CROPH,
  1009. .default_value = 480,
  1010. DEFREF(croph),
  1011. DEFINT(0, 576),
  1012. .get_max_value = ctrl_croph_max_get,
  1013. .get_def_value = ctrl_get_cropcapdh,
  1014. }, {
  1015. .desc = "Capture capability pixel aspect numerator",
  1016. .name = "cropcap_pixel_numerator",
  1017. .internal_id = PVR2_CID_CROPCAPPAN,
  1018. .get_value = ctrl_get_cropcappan,
  1019. }, {
  1020. .desc = "Capture capability pixel aspect denominator",
  1021. .name = "cropcap_pixel_denominator",
  1022. .internal_id = PVR2_CID_CROPCAPPAD,
  1023. .get_value = ctrl_get_cropcappad,
  1024. }, {
  1025. .desc = "Capture capability bounds top",
  1026. .name = "cropcap_bounds_top",
  1027. .internal_id = PVR2_CID_CROPCAPBT,
  1028. .get_value = ctrl_get_cropcapbt,
  1029. }, {
  1030. .desc = "Capture capability bounds left",
  1031. .name = "cropcap_bounds_left",
  1032. .internal_id = PVR2_CID_CROPCAPBL,
  1033. .get_value = ctrl_get_cropcapbl,
  1034. }, {
  1035. .desc = "Capture capability bounds width",
  1036. .name = "cropcap_bounds_width",
  1037. .internal_id = PVR2_CID_CROPCAPBW,
  1038. .get_value = ctrl_get_cropcapbw,
  1039. }, {
  1040. .desc = "Capture capability bounds height",
  1041. .name = "cropcap_bounds_height",
  1042. .internal_id = PVR2_CID_CROPCAPBH,
  1043. .get_value = ctrl_get_cropcapbh,
  1044. },{
  1045. .desc = "Video Source",
  1046. .name = "input",
  1047. .internal_id = PVR2_CID_INPUT,
  1048. .default_value = PVR2_CVAL_INPUT_TV,
  1049. .check_value = ctrl_check_input,
  1050. DEFREF(input),
  1051. DEFENUM(control_values_input),
  1052. },{
  1053. .desc = "Audio Mode",
  1054. .name = "audio_mode",
  1055. .internal_id = PVR2_CID_AUDIOMODE,
  1056. .default_value = V4L2_TUNER_MODE_STEREO,
  1057. DEFREF(audiomode),
  1058. DEFENUM(control_values_audiomode),
  1059. },{
  1060. .desc = "Horizontal capture resolution",
  1061. .name = "resolution_hor",
  1062. .internal_id = PVR2_CID_HRES,
  1063. .default_value = 720,
  1064. DEFREF(res_hor),
  1065. DEFINT(19,720),
  1066. },{
  1067. .desc = "Vertical capture resolution",
  1068. .name = "resolution_ver",
  1069. .internal_id = PVR2_CID_VRES,
  1070. .default_value = 480,
  1071. DEFREF(res_ver),
  1072. DEFINT(17,576),
  1073. /* Hook in check for video standard and adjust maximum
  1074. depending on the standard. */
  1075. .get_max_value = ctrl_vres_max_get,
  1076. .get_min_value = ctrl_vres_min_get,
  1077. },{
  1078. .v4l_id = V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ,
  1079. .default_value = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000,
  1080. .desc = "Audio Sampling Frequency",
  1081. .name = "srate",
  1082. DEFREF(srate),
  1083. DEFENUM(control_values_srate),
  1084. },{
  1085. .desc = "Tuner Frequency (Hz)",
  1086. .name = "frequency",
  1087. .internal_id = PVR2_CID_FREQUENCY,
  1088. .default_value = 0,
  1089. .set_value = ctrl_freq_set,
  1090. .get_value = ctrl_freq_get,
  1091. .is_dirty = ctrl_freq_is_dirty,
  1092. .clear_dirty = ctrl_freq_clear_dirty,
  1093. DEFINT(0,0),
  1094. /* Hook in check for input value (tv/radio) and adjust
  1095. max/min values accordingly */
  1096. .get_max_value = ctrl_freq_max_get,
  1097. .get_min_value = ctrl_freq_min_get,
  1098. },{
  1099. .desc = "Channel",
  1100. .name = "channel",
  1101. .set_value = ctrl_channel_set,
  1102. .get_value = ctrl_channel_get,
  1103. DEFINT(0,FREQTABLE_SIZE),
  1104. },{
  1105. .desc = "Channel Program Frequency",
  1106. .name = "freq_table_value",
  1107. .set_value = ctrl_channelfreq_set,
  1108. .get_value = ctrl_channelfreq_get,
  1109. DEFINT(0,0),
  1110. /* Hook in check for input value (tv/radio) and adjust
  1111. max/min values accordingly */
  1112. .get_max_value = ctrl_freq_max_get,
  1113. .get_min_value = ctrl_freq_min_get,
  1114. },{
  1115. .desc = "Channel Program ID",
  1116. .name = "freq_table_channel",
  1117. .set_value = ctrl_channelprog_set,
  1118. .get_value = ctrl_channelprog_get,
  1119. DEFINT(0,FREQTABLE_SIZE),
  1120. },{
  1121. .desc = "Streaming Enabled",
  1122. .name = "streaming_enabled",
  1123. .get_value = ctrl_streamingenabled_get,
  1124. DEFBOOL,
  1125. },{
  1126. .desc = "USB Speed",
  1127. .name = "usb_speed",
  1128. .get_value = ctrl_hsm_get,
  1129. DEFENUM(control_values_hsm),
  1130. },{
  1131. .desc = "Master State",
  1132. .name = "master_state",
  1133. .get_value = ctrl_masterstate_get,
  1134. DEFENUM(pvr2_state_names),
  1135. },{
  1136. .desc = "Signal Present",
  1137. .name = "signal_present",
  1138. .get_value = ctrl_signal_get,
  1139. DEFINT(0,65535),
  1140. },{
  1141. .desc = "Audio Modes Present",
  1142. .name = "audio_modes_present",
  1143. .get_value = ctrl_audio_modes_present_get,
  1144. /* For this type we "borrow" the V4L2_TUNER_MODE enum from
  1145. v4l. Nothing outside of this module cares about this,
  1146. but I reuse it in order to also reuse the
  1147. control_values_audiomode string table. */
  1148. DEFMASK(((1 << V4L2_TUNER_MODE_MONO)|
  1149. (1 << V4L2_TUNER_MODE_STEREO)|
  1150. (1 << V4L2_TUNER_MODE_LANG1)|
  1151. (1 << V4L2_TUNER_MODE_LANG2)),
  1152. control_values_audiomode),
  1153. },{
  1154. .desc = "Video Standards Available Mask",
  1155. .name = "video_standard_mask_available",
  1156. .internal_id = PVR2_CID_STDAVAIL,
  1157. .skip_init = !0,
  1158. .get_value = ctrl_stdavail_get,
  1159. .set_value = ctrl_stdavail_set,
  1160. .val_to_sym = ctrl_std_val_to_sym,
  1161. .sym_to_val = ctrl_std_sym_to_val,
  1162. .type = pvr2_ctl_bitmask,
  1163. },{
  1164. .desc = "Video Standards In Use Mask",
  1165. .name = "video_standard_mask_active",
  1166. .internal_id = PVR2_CID_STDCUR,
  1167. .skip_init = !0,
  1168. .get_value = ctrl_stdcur_get,
  1169. .set_value = ctrl_stdcur_set,
  1170. .is_dirty = ctrl_stdcur_is_dirty,
  1171. .clear_dirty = ctrl_stdcur_clear_dirty,
  1172. .val_to_sym = ctrl_std_val_to_sym,
  1173. .sym_to_val = ctrl_std_sym_to_val,
  1174. .type = pvr2_ctl_bitmask,
  1175. },{
  1176. .desc = "Video Standard Name",
  1177. .name = "video_standard",
  1178. .internal_id = PVR2_CID_STDENUM,
  1179. .skip_init = !0,
  1180. .get_value = ctrl_stdenumcur_get,
  1181. .set_value = ctrl_stdenumcur_set,
  1182. .is_dirty = ctrl_stdenumcur_is_dirty,
  1183. .clear_dirty = ctrl_stdenumcur_clear_dirty,
  1184. .type = pvr2_ctl_enum,
  1185. }
  1186. };
  1187. #define CTRLDEF_COUNT ARRAY_SIZE(control_defs)
  1188. const char *pvr2_config_get_name(enum pvr2_config cfg)
  1189. {
  1190. switch (cfg) {
  1191. case pvr2_config_empty: return "empty";
  1192. case pvr2_config_mpeg: return "mpeg";
  1193. case pvr2_config_vbi: return "vbi";
  1194. case pvr2_config_pcm: return "pcm";
  1195. case pvr2_config_rawvideo: return "raw video";
  1196. }
  1197. return "<unknown>";
  1198. }
  1199. struct usb_device *pvr2_hdw_get_dev(struct pvr2_hdw *hdw)
  1200. {
  1201. return hdw->usb_dev;
  1202. }
  1203. unsigned long pvr2_hdw_get_sn(struct pvr2_hdw *hdw)
  1204. {
  1205. return hdw->serial_number;
  1206. }
  1207. const char *pvr2_hdw_get_bus_info(struct pvr2_hdw *hdw)
  1208. {
  1209. return hdw->bus_info;
  1210. }
  1211. const char *pvr2_hdw_get_device_identifier(struct pvr2_hdw *hdw)
  1212. {
  1213. return hdw->identifier;
  1214. }
  1215. unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *hdw)
  1216. {
  1217. return hdw->freqSelector ? hdw->freqValTelevision : hdw->freqValRadio;
  1218. }
  1219. /* Set the currently tuned frequency and account for all possible
  1220. driver-core side effects of this action. */
  1221. static void pvr2_hdw_set_cur_freq(struct pvr2_hdw *hdw,unsigned long val)
  1222. {
  1223. if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
  1224. if (hdw->freqSelector) {
  1225. /* Swing over to radio frequency selection */
  1226. hdw->freqSelector = 0;
  1227. hdw->freqDirty = !0;
  1228. }
  1229. if (hdw->freqValRadio != val) {
  1230. hdw->freqValRadio = val;
  1231. hdw->freqSlotRadio = 0;
  1232. hdw->freqDirty = !0;
  1233. }
  1234. } else {
  1235. if (!(hdw->freqSelector)) {
  1236. /* Swing over to television frequency selection */
  1237. hdw->freqSelector = 1;
  1238. hdw->freqDirty = !0;
  1239. }
  1240. if (hdw->freqValTelevision != val) {
  1241. hdw->freqValTelevision = val;
  1242. hdw->freqSlotTelevision = 0;
  1243. hdw->freqDirty = !0;
  1244. }
  1245. }
  1246. }
  1247. int pvr2_hdw_get_unit_number(struct pvr2_hdw *hdw)
  1248. {
  1249. return hdw->unit_number;
  1250. }
  1251. /* Attempt to locate one of the given set of files. Messages are logged
  1252. appropriate to what has been found. The return value will be 0 or
  1253. greater on success (it will be the index of the file name found) and
  1254. fw_entry will be filled in. Otherwise a negative error is returned on
  1255. failure. If the return value is -ENOENT then no viable firmware file
  1256. could be located. */
  1257. static int pvr2_locate_firmware(struct pvr2_hdw *hdw,
  1258. const struct firmware **fw_entry,
  1259. const char *fwtypename,
  1260. unsigned int fwcount,
  1261. const char *fwnames[])
  1262. {
  1263. unsigned int idx;
  1264. int ret = -EINVAL;
  1265. for (idx = 0; idx < fwcount; idx++) {
  1266. ret = request_firmware(fw_entry,
  1267. fwnames[idx],
  1268. &hdw->usb_dev->dev);
  1269. if (!ret) {
  1270. trace_firmware("Located %s firmware: %s;"
  1271. " uploading...",
  1272. fwtypename,
  1273. fwnames[idx]);
  1274. return idx;
  1275. }
  1276. if (ret == -ENOENT) continue;
  1277. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  1278. "request_firmware fatal error with code=%d",ret);
  1279. return ret;
  1280. }
  1281. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  1282. "***WARNING***"
  1283. " Device %s firmware"
  1284. " seems to be missing.",
  1285. fwtypename);
  1286. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  1287. "Did you install the pvrusb2 firmware files"
  1288. " in their proper location?");
  1289. if (fwcount == 1) {
  1290. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  1291. "request_firmware unable to locate %s file %s",
  1292. fwtypename,fwnames[0]);
  1293. } else {
  1294. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  1295. "request_firmware unable to locate"
  1296. " one of the following %s files:",
  1297. fwtypename);
  1298. for (idx = 0; idx < fwcount; idx++) {
  1299. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  1300. "request_firmware: Failed to find %s",
  1301. fwnames[idx]);
  1302. }
  1303. }
  1304. return ret;
  1305. }
  1306. /*
  1307. * pvr2_upload_firmware1().
  1308. *
  1309. * Send the 8051 firmware to the device. After the upload, arrange for
  1310. * device to re-enumerate.
  1311. *
  1312. * NOTE : the pointer to the firmware data given by request_firmware()
  1313. * is not suitable for an usb transaction.
  1314. *
  1315. */
  1316. static int pvr2_upload_firmware1(struct pvr2_hdw *hdw)
  1317. {
  1318. const struct firmware *fw_entry = NULL;
  1319. void *fw_ptr;
  1320. unsigned int pipe;
  1321. unsigned int fwsize;
  1322. int ret;
  1323. u16 address;
  1324. if (!hdw->hdw_desc->fx2_firmware.cnt) {
  1325. hdw->fw1_state = FW1_STATE_OK;
  1326. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  1327. "Connected device type defines"
  1328. " no firmware to upload; ignoring firmware");
  1329. return -ENOTTY;
  1330. }
  1331. hdw->fw1_state = FW1_STATE_FAILED; // default result
  1332. trace_firmware("pvr2_upload_firmware1");
  1333. ret = pvr2_locate_firmware(hdw,&fw_entry,"fx2 controller",
  1334. hdw->hdw_desc->fx2_firmware.cnt,
  1335. hdw->hdw_desc->fx2_firmware.lst);
  1336. if (ret < 0) {
  1337. if (ret == -ENOENT) hdw->fw1_state = FW1_STATE_MISSING;
  1338. return ret;
  1339. }
  1340. usb_clear_halt(hdw->usb_dev, usb_sndbulkpipe(hdw->usb_dev, 0 & 0x7f));
  1341. pipe = usb_sndctrlpipe(hdw->usb_dev, 0);
  1342. fwsize = fw_entry->size;
  1343. if ((fwsize != 0x2000) &&
  1344. (!(hdw->hdw_desc->flag_fx2_16kb && (fwsize == 0x4000)))) {
  1345. if (hdw->hdw_desc->flag_fx2_16kb) {
  1346. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  1347. "Wrong fx2 firmware size"
  1348. " (expected 8192 or 16384, got %u)",
  1349. fwsize);
  1350. } else {
  1351. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  1352. "Wrong fx2 firmware size"
  1353. " (expected 8192, got %u)",
  1354. fwsize);
  1355. }
  1356. release_firmware(fw_entry);
  1357. return -ENOMEM;
  1358. }
  1359. fw_ptr = kmalloc(0x800, GFP_KERNEL);
  1360. if (fw_ptr == NULL){
  1361. release_firmware(fw_entry);
  1362. return -ENOMEM;
  1363. }
  1364. /* We have to hold the CPU during firmware upload. */
  1365. pvr2_hdw_cpureset_assert(hdw,1);
  1366. /* upload the firmware to address 0000-1fff in 2048 (=0x800) bytes
  1367. chunk. */
  1368. ret = 0;
  1369. for (address = 0; address < fwsize; address += 0x800) {
  1370. memcpy(fw_ptr, fw_entry->data + address, 0x800);
  1371. ret += usb_control_msg(hdw->usb_dev, pipe, 0xa0, 0x40, address,
  1372. 0, fw_ptr, 0x800, HZ);
  1373. }
  1374. trace_firmware("Upload done, releasing device's CPU");
  1375. /* Now release the CPU. It will disconnect and reconnect later. */
  1376. pvr2_hdw_cpureset_assert(hdw,0);
  1377. kfree(fw_ptr);
  1378. release_firmware(fw_entry);
  1379. trace_firmware("Upload done (%d bytes sent)",ret);
  1380. /* We should have written fwsize bytes */
  1381. if (ret == fwsize) {
  1382. hdw->fw1_state = FW1_STATE_RELOAD;
  1383. return 0;
  1384. }
  1385. return -EIO;
  1386. }
  1387. /*
  1388. * pvr2_upload_firmware2()
  1389. *
  1390. * This uploads encoder firmware on endpoint 2.
  1391. *
  1392. */
  1393. int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
  1394. {
  1395. const struct firmware *fw_entry = NULL;
  1396. void *fw_ptr;
  1397. unsigned int pipe, fw_len, fw_done, bcnt, icnt;
  1398. int actual_length;
  1399. int ret = 0;
  1400. int fwidx;
  1401. static const char *fw_files[] = {
  1402. CX2341X_FIRM_ENC_FILENAME,
  1403. };
  1404. if (hdw->hdw_desc->flag_skip_cx23416_firmware) {
  1405. return 0;
  1406. }
  1407. trace_firmware("pvr2_upload_firmware2");
  1408. ret = pvr2_locate_firmware(hdw,&fw_entry,"encoder",
  1409. ARRAY_SIZE(fw_files), fw_files);
  1410. if (ret < 0) return ret;
  1411. fwidx = ret;
  1412. ret = 0;
  1413. /* Since we're about to completely reinitialize the encoder,
  1414. invalidate our cached copy of its configuration state. Next
  1415. time we configure the encoder, then we'll fully configure it. */
  1416. hdw->enc_cur_valid = 0;
  1417. /* Encoder is about to be reset so note that as far as we're
  1418. concerned now, the encoder has never been run. */
  1419. del_timer_sync(&hdw->encoder_run_timer);
  1420. if (hdw->state_encoder_runok) {
  1421. hdw->state_encoder_runok = 0;
  1422. trace_stbit("state_encoder_runok",hdw->state_encoder_runok);
  1423. }
  1424. /* First prepare firmware loading */
  1425. ret |= pvr2_write_register(hdw, 0x0048, 0xffffffff); /*interrupt mask*/
  1426. ret |= pvr2_hdw_gpio_chg_dir(hdw,0xffffffff,0x00000088); /*gpio dir*/
  1427. ret |= pvr2_hdw_gpio_chg_out(hdw,0xffffffff,0x00000008); /*gpio output state*/
  1428. ret |= pvr2_hdw_cmd_deep_reset(hdw);
  1429. ret |= pvr2_write_register(hdw, 0xa064, 0x00000000); /*APU command*/
  1430. ret |= pvr2_hdw_gpio_chg_dir(hdw,0xffffffff,0x00000408); /*gpio dir*/
  1431. ret |= pvr2_hdw_gpio_chg_out(hdw,0xffffffff,0x00000008); /*gpio output state*/
  1432. ret |= pvr2_write_register(hdw, 0x9058, 0xffffffed); /*VPU ctrl*/
  1433. ret |= pvr2_write_register(hdw, 0x9054, 0xfffffffd); /*reset hw blocks*/
  1434. ret |= pvr2_write_register(hdw, 0x07f8, 0x80000800); /*encoder SDRAM refresh*/
  1435. ret |= pvr2_write_register(hdw, 0x07fc, 0x0000001a); /*encoder SDRAM pre-charge*/
  1436. ret |= pvr2_write_register(hdw, 0x0700, 0x00000000); /*I2C clock*/
  1437. ret |= pvr2_write_register(hdw, 0xaa00, 0x00000000); /*unknown*/
  1438. ret |= pvr2_write_register(hdw, 0xaa04, 0x00057810); /*unknown*/
  1439. ret |= pvr2_write_register(hdw, 0xaa10, 0x00148500); /*unknown*/
  1440. ret |= pvr2_write_register(hdw, 0xaa18, 0x00840000); /*unknown*/
  1441. ret |= pvr2_issue_simple_cmd(hdw,FX2CMD_FWPOST1);
  1442. ret |= pvr2_issue_simple_cmd(hdw,FX2CMD_MEMSEL | (1 << 8) | (0 << 16));
  1443. if (ret) {
  1444. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  1445. "firmware2 upload prep failed, ret=%d",ret);
  1446. release_firmware(fw_entry);
  1447. goto done;
  1448. }
  1449. /* Now send firmware */
  1450. fw_len = fw_entry->size;
  1451. if (fw_len % sizeof(u32)) {
  1452. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  1453. "size of %s firmware"
  1454. " must be a multiple of %zu bytes",
  1455. fw_files[fwidx],sizeof(u32));
  1456. release_firmware(fw_entry);
  1457. ret = -EINVAL;
  1458. goto done;
  1459. }
  1460. fw_ptr = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL);
  1461. if (fw_ptr == NULL){
  1462. release_firmware(fw_entry);
  1463. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  1464. "failed to allocate memory for firmware2 upload");
  1465. ret = -ENOMEM;
  1466. goto done;
  1467. }
  1468. pipe = usb_sndbulkpipe(hdw->usb_dev, PVR2_FIRMWARE_ENDPOINT);
  1469. fw_done = 0;
  1470. for (fw_done = 0; fw_done < fw_len;) {
  1471. bcnt = fw_len - fw_done;
  1472. if (bcnt > FIRMWARE_CHUNK_SIZE) bcnt = FIRMWARE_CHUNK_SIZE;
  1473. memcpy(fw_ptr, fw_entry->data + fw_done, bcnt);
  1474. /* Usbsnoop log shows that we must swap bytes... */
  1475. /* Some background info: The data being swapped here is a
  1476. firmware image destined for the mpeg encoder chip that
  1477. lives at the other end of a USB endpoint. The encoder
  1478. chip always talks in 32 bit chunks and its storage is
  1479. organized into 32 bit words. However from the file
  1480. system to the encoder chip everything is purely a byte
  1481. stream. The firmware file's contents are always 32 bit
  1482. swapped from what the encoder expects. Thus the need
  1483. always exists to swap the bytes regardless of the endian
  1484. type of the host processor and therefore swab32() makes
  1485. the most sense. */
  1486. for (icnt = 0; icnt < bcnt/4 ; icnt++)
  1487. ((u32 *)fw_ptr)[icnt] = swab32(((u32 *)fw_ptr)[icnt]);
  1488. ret |= usb_bulk_msg(hdw->usb_dev, pipe, fw_ptr,bcnt,
  1489. &actual_length, HZ);
  1490. ret |= (actual_length != bcnt);
  1491. if (ret) break;
  1492. fw_done += bcnt;
  1493. }
  1494. trace_firmware("upload of %s : %i / %i ",
  1495. fw_files[fwidx],fw_done,fw_len);
  1496. kfree(fw_ptr);
  1497. release_firmware(fw_entry);
  1498. if (ret) {
  1499. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  1500. "firmware2 upload transfer failure");
  1501. goto done;
  1502. }
  1503. /* Finish upload */
  1504. ret |= pvr2_write_register(hdw, 0x9054, 0xffffffff); /*reset hw blocks*/
  1505. ret |= pvr2_write_register(hdw, 0x9058, 0xffffffe8); /*VPU ctrl*/
  1506. ret |= pvr2_issue_simple_cmd(hdw,FX2CMD_MEMSEL | (1 << 8) | (0 << 16));
  1507. if (ret) {
  1508. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  1509. "firmware2 upload post-proc failure");
  1510. }
  1511. done:
  1512. if (hdw->hdw_desc->signal_routing_scheme ==
  1513. PVR2_ROUTING_SCHEME_GOTVIEW) {
  1514. /* Ensure that GPIO 11 is set to output for GOTVIEW
  1515. hardware. */
  1516. pvr2_hdw_gpio_chg_dir(hdw,(1 << 11),~0);
  1517. }
  1518. return ret;
  1519. }
  1520. static const char *pvr2_get_state_name(unsigned int st)
  1521. {
  1522. if (st < ARRAY_SIZE(pvr2_state_names)) {
  1523. return pvr2_state_names[st];
  1524. }
  1525. return "???";
  1526. }
  1527. static int pvr2_decoder_enable(struct pvr2_hdw *hdw,int enablefl)
  1528. {
  1529. /* Even though we really only care about the video decoder chip at
  1530. this point, we'll broadcast stream on/off to all sub-devices
  1531. anyway, just in case somebody else wants to hear the
  1532. command... */
  1533. pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 stream=%s",
  1534. (enablefl ? "on" : "off"));
  1535. v4l2_device_call_all(&hdw->v4l2_dev, 0, video, s_stream, enablefl);
  1536. v4l2_device_call_all(&hdw->v4l2_dev, 0, audio, s_stream, enablefl);
  1537. if (hdw->decoder_client_id) {
  1538. /* We get here if the encoder has been noticed. Otherwise
  1539. we'll issue a warning to the user (which should
  1540. normally never happen). */
  1541. return 0;
  1542. }
  1543. if (!hdw->flag_decoder_missed) {
  1544. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  1545. "WARNING: No decoder present");
  1546. hdw->flag_decoder_missed = !0;
  1547. trace_stbit("flag_decoder_missed",
  1548. hdw->flag_decoder_missed);
  1549. }
  1550. return -EIO;
  1551. }
  1552. int pvr2_hdw_get_state(struct pvr2_hdw *hdw)
  1553. {
  1554. return hdw->master_state;
  1555. }
  1556. static int pvr2_hdw_untrip_unlocked(struct pvr2_hdw *hdw)
  1557. {
  1558. if (!hdw->flag_tripped) return 0;
  1559. hdw->flag_tripped = 0;
  1560. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  1561. "Clearing driver error statuss");
  1562. return !0;
  1563. }
  1564. int pvr2_hdw_untrip(struct pvr2_hdw *hdw)
  1565. {
  1566. int fl;
  1567. LOCK_TAKE(hdw->big_lock); do {
  1568. fl = pvr2_hdw_untrip_unlocked(hdw);
  1569. } while (0); LOCK_GIVE(hdw->big_lock);
  1570. if (fl) pvr2_hdw_state_sched(hdw);
  1571. return 0;
  1572. }
  1573. int pvr2_hdw_get_streaming(struct pvr2_hdw *hdw)
  1574. {
  1575. return hdw->state_pipeline_req != 0;
  1576. }
  1577. int pvr2_hdw_set_streaming(struct pvr2_hdw *hdw,int enable_flag)
  1578. {
  1579. int ret,st;
  1580. LOCK_TAKE(hdw->big_lock); do {
  1581. pvr2_hdw_untrip_unlocked(hdw);
  1582. if ((!enable_flag) != !(hdw->state_pipeline_req)) {
  1583. hdw->state_pipeline_req = enable_flag != 0;
  1584. pvr2_trace(PVR2_TRACE_START_STOP,
  1585. "/*--TRACE_STREAM--*/ %s",
  1586. enable_flag ? "enable" : "disable");
  1587. }
  1588. pvr2_hdw_state_sched(hdw);
  1589. } while (0); LOCK_GIVE(hdw->big_lock);
  1590. if ((ret = pvr2_hdw_wait(hdw,0)) < 0) return ret;
  1591. if (enable_flag) {
  1592. while ((st = hdw->master_state) != PVR2_STATE_RUN) {
  1593. if (st != PVR2_STATE_READY) return -EIO;
  1594. if ((ret = pvr2_hdw_wait(hdw,st)) < 0) return ret;
  1595. }
  1596. }
  1597. return 0;
  1598. }
  1599. int pvr2_hdw_set_stream_type(struct pvr2_hdw *hdw,enum pvr2_config config)
  1600. {
  1601. int fl;
  1602. LOCK_TAKE(hdw->big_lock);
  1603. if ((fl = (hdw->desired_stream_type != config)) != 0) {
  1604. hdw->desired_stream_type = config;
  1605. hdw->state_pipeline_config = 0;
  1606. trace_stbit("state_pipeline_config",
  1607. hdw->state_pipeline_config);
  1608. pvr2_hdw_state_sched(hdw);
  1609. }
  1610. LOCK_GIVE(hdw->big_lock);
  1611. if (fl) return 0;
  1612. return pvr2_hdw_wait(hdw,0);
  1613. }
  1614. static int get_default_tuner_type(struct pvr2_hdw *hdw)
  1615. {
  1616. int unit_number = hdw->unit_number;
  1617. int tp = -1;
  1618. if ((unit_number >= 0) && (unit_number < PVR_NUM)) {
  1619. tp = tuner[unit_number];
  1620. }
  1621. if (tp < 0) return -EINVAL;
  1622. hdw->tuner_type = tp;
  1623. hdw->tuner_updated = !0;
  1624. return 0;
  1625. }
  1626. static v4l2_std_id get_default_standard(struct pvr2_hdw *hdw)
  1627. {
  1628. int unit_number = hdw->unit_number;
  1629. int tp = 0;
  1630. if ((unit_number >= 0) && (unit_number < PVR_NUM)) {
  1631. tp = video_std[unit_number];
  1632. if (tp) return tp;
  1633. }
  1634. return 0;
  1635. }
  1636. static unsigned int get_default_error_tolerance(struct pvr2_hdw *hdw)
  1637. {
  1638. int unit_number = hdw->unit_number;
  1639. int tp = 0;
  1640. if ((unit_number >= 0) && (unit_number < PVR_NUM)) {
  1641. tp = tolerance[unit_number];
  1642. }
  1643. return tp;
  1644. }
  1645. static int pvr2_hdw_check_firmware(struct pvr2_hdw *hdw)
  1646. {
  1647. /* Try a harmless request to fetch the eeprom's address over
  1648. endpoint 1. See what happens. Only the full FX2 image can
  1649. respond to this. If this probe fails then likely the FX2
  1650. firmware needs be loaded. */
  1651. int result;
  1652. LOCK_TAKE(hdw->ctl_lock); do {
  1653. hdw->cmd_buffer[0] = FX2CMD_GET_EEPROM_ADDR;
  1654. result = pvr2_send_request_e