pvrusb2-v4l2.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  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 <linux/kernel.h>
  23. #include <linux/version.h>
  24. #include "pvrusb2-context.h"
  25. #include "pvrusb2-hdw.h"
  26. #include "pvrusb2.h"
  27. #include "pvrusb2-debug.h"
  28. #include "pvrusb2-v4l2.h"
  29. #include "pvrusb2-ioread.h"
  30. #include <linux/videodev2.h>
  31. #include <media/v4l2-dev.h>
  32. #include <media/v4l2-common.h>
  33. struct pvr2_v4l2_dev;
  34. struct pvr2_v4l2_fh;
  35. struct pvr2_v4l2;
  36. struct pvr2_v4l2_dev {
  37. struct video_device devbase; /* MUST be first! */
  38. struct pvr2_v4l2 *v4lp;
  39. struct pvr2_context_stream *stream;
  40. enum pvr2_config config;
  41. };
  42. struct pvr2_v4l2_fh {
  43. struct pvr2_channel channel;
  44. struct pvr2_v4l2_dev *dev_info;
  45. enum v4l2_priority prio;
  46. struct pvr2_ioread *rhp;
  47. struct file *file;
  48. struct pvr2_v4l2 *vhead;
  49. struct pvr2_v4l2_fh *vnext;
  50. struct pvr2_v4l2_fh *vprev;
  51. wait_queue_head_t wait_data;
  52. int fw_mode_flag;
  53. };
  54. struct pvr2_v4l2 {
  55. struct pvr2_channel channel;
  56. struct pvr2_v4l2_fh *vfirst;
  57. struct pvr2_v4l2_fh *vlast;
  58. struct v4l2_prio_state prio;
  59. /* streams - Note that these must be separately, individually,
  60. * allocated pointers. This is because the v4l core is going to
  61. * manage their deletion - separately, individually... */
  62. struct pvr2_v4l2_dev *dev_video;
  63. struct pvr2_v4l2_dev *dev_radio;
  64. };
  65. static int video_nr[PVR_NUM] = {[0 ... PVR_NUM-1] = -1};
  66. module_param_array(video_nr, int, NULL, 0444);
  67. MODULE_PARM_DESC(video_nr, "Offset for device's video dev minor");
  68. static int radio_nr[PVR_NUM] = {[0 ... PVR_NUM-1] = -1};
  69. module_param_array(radio_nr, int, NULL, 0444);
  70. MODULE_PARM_DESC(radio_nr, "Offset for device's radio dev minor");
  71. static int vbi_nr[PVR_NUM] = {[0 ... PVR_NUM-1] = -1};
  72. module_param_array(vbi_nr, int, NULL, 0444);
  73. MODULE_PARM_DESC(vbi_nr, "Offset for device's vbi dev minor");
  74. static struct v4l2_capability pvr_capability ={
  75. .driver = "pvrusb2",
  76. .card = "Hauppauge WinTV pvr-usb2",
  77. .bus_info = "usb",
  78. .version = KERNEL_VERSION(0,8,0),
  79. .capabilities = (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VBI_CAPTURE |
  80. V4L2_CAP_TUNER | V4L2_CAP_AUDIO | V4L2_CAP_RADIO |
  81. V4L2_CAP_READWRITE),
  82. .reserved = {0,0,0,0}
  83. };
  84. static struct v4l2_tuner pvr_v4l2_tuners[]= {
  85. {
  86. .index = 0,
  87. .name = "TV Tuner",
  88. .type = V4L2_TUNER_ANALOG_TV,
  89. .capability = (V4L2_TUNER_CAP_NORM |
  90. V4L2_TUNER_CAP_STEREO |
  91. V4L2_TUNER_CAP_LANG1 |
  92. V4L2_TUNER_CAP_LANG2),
  93. .rangelow = 0,
  94. .rangehigh = 0,
  95. .rxsubchans = V4L2_TUNER_SUB_STEREO,
  96. .audmode = V4L2_TUNER_MODE_STEREO,
  97. .signal = 0,
  98. .afc = 0,
  99. .reserved = {0,0,0,0}
  100. }
  101. };
  102. static struct v4l2_fmtdesc pvr_fmtdesc [] = {
  103. {
  104. .index = 0,
  105. .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
  106. .flags = V4L2_FMT_FLAG_COMPRESSED,
  107. .description = "MPEG1/2",
  108. // This should really be V4L2_PIX_FMT_MPEG, but xawtv
  109. // breaks when I do that.
  110. .pixelformat = 0, // V4L2_PIX_FMT_MPEG,
  111. .reserved = { 0, 0, 0, 0 }
  112. }
  113. };
  114. #define PVR_FORMAT_PIX 0
  115. #define PVR_FORMAT_VBI 1
  116. static struct v4l2_format pvr_format [] = {
  117. [PVR_FORMAT_PIX] = {
  118. .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
  119. .fmt = {
  120. .pix = {
  121. .width = 720,
  122. .height = 576,
  123. // This should really be V4L2_PIX_FMT_MPEG,
  124. // but xawtv breaks when I do that.
  125. .pixelformat = 0, // V4L2_PIX_FMT_MPEG,
  126. .field = V4L2_FIELD_INTERLACED,
  127. .bytesperline = 0, // doesn't make sense
  128. // here
  129. //FIXME : Don't know what to put here...
  130. .sizeimage = (32*1024),
  131. .colorspace = 0, // doesn't make sense here
  132. .priv = 0
  133. }
  134. }
  135. },
  136. [PVR_FORMAT_VBI] = {
  137. .type = V4L2_BUF_TYPE_VBI_CAPTURE,
  138. .fmt = {
  139. .vbi = {
  140. .sampling_rate = 27000000,
  141. .offset = 248,
  142. .samples_per_line = 1443,
  143. .sample_format = V4L2_PIX_FMT_GREY,
  144. .start = { 0, 0 },
  145. .count = { 0, 0 },
  146. .flags = 0,
  147. .reserved = { 0, 0 }
  148. }
  149. }
  150. }
  151. };
  152. /*
  153. * pvr_ioctl()
  154. *
  155. * This is part of Video 4 Linux API. The procedure handles ioctl() calls.
  156. *
  157. */
  158. static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
  159. unsigned int cmd, void *arg)
  160. {
  161. struct pvr2_v4l2_fh *fh = file->private_data;
  162. struct pvr2_v4l2 *vp = fh->vhead;
  163. struct pvr2_v4l2_dev *dev_info = fh->dev_info;
  164. struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
  165. int ret = -EINVAL;
  166. if (pvrusb2_debug & PVR2_TRACE_V4LIOCTL) {
  167. v4l_print_ioctl(pvr2_hdw_get_driver_name(hdw),cmd);
  168. }
  169. if (!pvr2_hdw_dev_ok(hdw)) {
  170. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  171. "ioctl failed - bad or no context");
  172. return -EFAULT;
  173. }
  174. /* check priority */
  175. switch (cmd) {
  176. case VIDIOC_S_CTRL:
  177. case VIDIOC_S_STD:
  178. case VIDIOC_S_INPUT:
  179. case VIDIOC_S_TUNER:
  180. case VIDIOC_S_FREQUENCY:
  181. ret = v4l2_prio_check(&vp->prio, &fh->prio);
  182. if (ret)
  183. return ret;
  184. }
  185. switch (cmd) {
  186. case VIDIOC_QUERYCAP:
  187. {
  188. struct v4l2_capability *cap = arg;
  189. memcpy(cap, &pvr_capability, sizeof(struct v4l2_capability));
  190. ret = 0;
  191. break;
  192. }
  193. case VIDIOC_G_PRIORITY:
  194. {
  195. enum v4l2_priority *p = arg;
  196. *p = v4l2_prio_max(&vp->prio);
  197. ret = 0;
  198. break;
  199. }
  200. case VIDIOC_S_PRIORITY:
  201. {
  202. enum v4l2_priority *prio = arg;
  203. ret = v4l2_prio_change(&vp->prio, &fh->prio, *prio);
  204. break;
  205. }
  206. case VIDIOC_ENUMSTD:
  207. {
  208. struct v4l2_standard *vs = (struct v4l2_standard *)arg;
  209. int idx = vs->index;
  210. ret = pvr2_hdw_get_stdenum_value(hdw,vs,idx+1);
  211. break;
  212. }
  213. case VIDIOC_G_STD:
  214. {
  215. int val = 0;
  216. ret = pvr2_ctrl_get_value(
  217. pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_STDCUR),&val);
  218. *(v4l2_std_id *)arg = val;
  219. break;
  220. }
  221. case VIDIOC_S_STD:
  222. {
  223. ret = pvr2_ctrl_set_value(
  224. pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_STDCUR),
  225. *(v4l2_std_id *)arg);
  226. break;
  227. }
  228. case VIDIOC_ENUMINPUT:
  229. {
  230. struct pvr2_ctrl *cptr;
  231. struct v4l2_input *vi = (struct v4l2_input *)arg;
  232. struct v4l2_input tmp;
  233. unsigned int cnt;
  234. cptr = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT);
  235. memset(&tmp,0,sizeof(tmp));
  236. tmp.index = vi->index;
  237. ret = 0;
  238. switch (vi->index) {
  239. case PVR2_CVAL_INPUT_TV:
  240. case PVR2_CVAL_INPUT_RADIO:
  241. tmp.type = V4L2_INPUT_TYPE_TUNER;
  242. break;
  243. case PVR2_CVAL_INPUT_SVIDEO:
  244. case PVR2_CVAL_INPUT_COMPOSITE:
  245. tmp.type = V4L2_INPUT_TYPE_CAMERA;
  246. break;
  247. default:
  248. ret = -EINVAL;
  249. break;
  250. }
  251. if (ret < 0) break;
  252. cnt = 0;
  253. pvr2_ctrl_get_valname(cptr,vi->index,
  254. tmp.name,sizeof(tmp.name)-1,&cnt);
  255. tmp.name[cnt] = 0;
  256. /* Don't bother with audioset, since this driver currently
  257. always switches the audio whenever the video is
  258. switched. */
  259. /* Handling std is a tougher problem. It doesn't make
  260. sense in cases where a device might be multi-standard.
  261. We could just copy out the current value for the
  262. standard, but it can change over time. For now just
  263. leave it zero. */
  264. memcpy(vi, &tmp, sizeof(tmp));
  265. ret = 0;
  266. break;
  267. }
  268. case VIDIOC_G_INPUT:
  269. {
  270. struct pvr2_ctrl *cptr;
  271. struct v4l2_input *vi = (struct v4l2_input *)arg;
  272. int val;
  273. cptr = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT);
  274. val = 0;
  275. ret = pvr2_ctrl_get_value(cptr,&val);
  276. vi->index = val;
  277. break;
  278. }
  279. case VIDIOC_S_INPUT:
  280. {
  281. struct v4l2_input *vi = (struct v4l2_input *)arg;
  282. ret = pvr2_ctrl_set_value(
  283. pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT),
  284. vi->index);
  285. break;
  286. }
  287. case VIDIOC_ENUMAUDIO:
  288. {
  289. ret = -EINVAL;
  290. break;
  291. }
  292. case VIDIOC_G_AUDIO:
  293. {
  294. ret = -EINVAL;
  295. break;
  296. }
  297. case VIDIOC_S_AUDIO:
  298. {
  299. ret = -EINVAL;
  300. break;
  301. }
  302. case VIDIOC_G_TUNER:
  303. {
  304. struct v4l2_tuner *vt = (struct v4l2_tuner *)arg;
  305. unsigned int status_mask;
  306. int val;
  307. if (vt->index !=0) break;
  308. status_mask = pvr2_hdw_get_signal_status(hdw);
  309. memcpy(vt, &pvr_v4l2_tuners[vt->index],
  310. sizeof(struct v4l2_tuner));
  311. vt->signal = 0;
  312. if (status_mask & PVR2_SIGNAL_OK) {
  313. if (status_mask & PVR2_SIGNAL_STEREO) {
  314. vt->rxsubchans = V4L2_TUNER_SUB_STEREO;
  315. } else {
  316. vt->rxsubchans = V4L2_TUNER_SUB_MONO;
  317. }
  318. if (status_mask & PVR2_SIGNAL_SAP) {
  319. vt->rxsubchans |= (V4L2_TUNER_SUB_LANG1 |
  320. V4L2_TUNER_SUB_LANG2);
  321. }
  322. vt->signal = 65535;
  323. }
  324. val = 0;
  325. ret = pvr2_ctrl_get_value(
  326. pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_AUDIOMODE),
  327. &val);
  328. vt->audmode = val;
  329. break;
  330. }
  331. case VIDIOC_S_TUNER:
  332. {
  333. struct v4l2_tuner *vt=(struct v4l2_tuner *)arg;
  334. if (vt->index != 0)
  335. break;
  336. ret = pvr2_ctrl_set_value(
  337. pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_AUDIOMODE),
  338. vt->audmode);
  339. }
  340. case VIDIOC_S_FREQUENCY:
  341. {
  342. const struct v4l2_frequency *vf = (struct v4l2_frequency *)arg;
  343. unsigned long fv;
  344. fv = vf->frequency;
  345. if (vf->type == V4L2_TUNER_RADIO) {
  346. fv = (fv * 125) / 2;
  347. } else {
  348. fv = fv * 62500;
  349. }
  350. ret = pvr2_ctrl_set_value(
  351. pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_FREQUENCY),fv);
  352. break;
  353. }
  354. case VIDIOC_G_FREQUENCY:
  355. {
  356. struct v4l2_frequency *vf = (struct v4l2_frequency *)arg;
  357. int val = 0;
  358. int cur_input = PVR2_CVAL_INPUT_TV;
  359. ret = pvr2_ctrl_get_value(
  360. pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_FREQUENCY),
  361. &val);
  362. if (ret != 0) break;
  363. pvr2_ctrl_get_value(
  364. pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT),
  365. &cur_input);
  366. if (cur_input == PVR2_CVAL_INPUT_RADIO) {
  367. val = (val * 2) / 125;
  368. vf->frequency = val;
  369. vf->type = V4L2_TUNER_RADIO;
  370. } else {
  371. val /= 62500;
  372. vf->frequency = val;
  373. vf->type = V4L2_TUNER_ANALOG_TV;
  374. }
  375. break;
  376. }
  377. case VIDIOC_ENUM_FMT:
  378. {
  379. struct v4l2_fmtdesc *fd = (struct v4l2_fmtdesc *)arg;
  380. /* Only one format is supported : mpeg.*/
  381. if (fd->index != 0)
  382. break;
  383. memcpy(fd, pvr_fmtdesc, sizeof(struct v4l2_fmtdesc));
  384. ret = 0;
  385. break;
  386. }
  387. case VIDIOC_G_FMT:
  388. {
  389. struct v4l2_format *vf = (struct v4l2_format *)arg;
  390. int val;
  391. switch(vf->type) {
  392. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  393. memcpy(vf, &pvr_format[PVR_FORMAT_PIX],
  394. sizeof(struct v4l2_format));
  395. val = 0;
  396. pvr2_ctrl_get_value(
  397. pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_HRES),
  398. &val);
  399. vf->fmt.pix.width = val;
  400. val = 0;
  401. pvr2_ctrl_get_value(
  402. pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_VRES),
  403. &val);
  404. vf->fmt.pix.height = val;
  405. ret = 0;
  406. break;
  407. case V4L2_BUF_TYPE_VBI_CAPTURE:
  408. // ????? Still need to figure out to do VBI correctly
  409. ret = -EINVAL;
  410. break;
  411. default:
  412. ret = -EINVAL;
  413. break;
  414. }
  415. break;
  416. }
  417. case VIDIOC_TRY_FMT:
  418. case VIDIOC_S_FMT:
  419. {
  420. struct v4l2_format *vf = (struct v4l2_format *)arg;
  421. ret = 0;
  422. switch(vf->type) {
  423. case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
  424. int lmin,lmax;
  425. struct pvr2_ctrl *hcp,*vcp;
  426. int h = vf->fmt.pix.height;
  427. int w = vf->fmt.pix.width;
  428. hcp = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_HRES);
  429. vcp = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_VRES);
  430. lmin = pvr2_ctrl_get_min(hcp);
  431. lmax = pvr2_ctrl_get_max(hcp);
  432. if (w < lmin) {
  433. w = lmin;
  434. } else if (w > lmax) {
  435. w = lmax;
  436. }
  437. lmin = pvr2_ctrl_get_min(vcp);
  438. lmax = pvr2_ctrl_get_max(vcp);
  439. if (h < lmin) {
  440. h = lmin;
  441. } else if (h > lmax) {
  442. h = lmax;
  443. }
  444. memcpy(vf, &pvr_format[PVR_FORMAT_PIX],
  445. sizeof(struct v4l2_format));
  446. vf->fmt.pix.width = w;
  447. vf->fmt.pix.height = h;
  448. if (cmd == VIDIOC_S_FMT) {
  449. pvr2_ctrl_set_value(hcp,vf->fmt.pix.width);
  450. pvr2_ctrl_set_value(vcp,vf->fmt.pix.height);
  451. }
  452. } break;
  453. case V4L2_BUF_TYPE_VBI_CAPTURE:
  454. // ????? Still need to figure out to do VBI correctly
  455. ret = -EINVAL;
  456. break;
  457. default:
  458. ret = -EINVAL;
  459. break;
  460. }
  461. break;
  462. }
  463. case VIDIOC_STREAMON:
  464. {
  465. ret = pvr2_hdw_set_stream_type(hdw,dev_info->config);
  466. if (ret < 0) return ret;
  467. ret = pvr2_hdw_set_streaming(hdw,!0);
  468. break;
  469. }
  470. case VIDIOC_STREAMOFF:
  471. {
  472. ret = pvr2_hdw_set_streaming(hdw,0);
  473. break;
  474. }
  475. case VIDIOC_QUERYCTRL:
  476. {
  477. struct pvr2_ctrl *cptr;
  478. struct v4l2_queryctrl *vc = (struct v4l2_queryctrl *)arg;
  479. ret = 0;
  480. if (vc->id & V4L2_CTRL_FLAG_NEXT_CTRL) {
  481. cptr = pvr2_hdw_get_ctrl_nextv4l(
  482. hdw,(vc->id & ~V4L2_CTRL_FLAG_NEXT_CTRL));
  483. if (cptr) vc->id = pvr2_ctrl_get_v4lid(cptr);
  484. } else {
  485. cptr = pvr2_hdw_get_ctrl_v4l(hdw,vc->id);
  486. }
  487. if (!cptr) {
  488. pvr2_trace(PVR2_TRACE_V4LIOCTL,
  489. "QUERYCTRL id=0x%x not implemented here",
  490. vc->id);
  491. ret = -EINVAL;
  492. break;
  493. }
  494. pvr2_trace(PVR2_TRACE_V4LIOCTL,
  495. "QUERYCTRL id=0x%x mapping name=%s (%s)",
  496. vc->id,pvr2_ctrl_get_name(cptr),
  497. pvr2_ctrl_get_desc(cptr));
  498. strlcpy(vc->name,pvr2_ctrl_get_desc(cptr),sizeof(vc->name));
  499. vc->flags = pvr2_ctrl_get_v4lflags(cptr);
  500. vc->default_value = pvr2_ctrl_get_def(cptr);
  501. switch (pvr2_ctrl_get_type(cptr)) {
  502. case pvr2_ctl_enum:
  503. vc->type = V4L2_CTRL_TYPE_MENU;
  504. vc->minimum = 0;
  505. vc->maximum = pvr2_ctrl_get_cnt(cptr) - 1;
  506. vc->step = 1;
  507. break;
  508. case pvr2_ctl_bool:
  509. vc->type = V4L2_CTRL_TYPE_BOOLEAN;
  510. vc->minimum = 0;
  511. vc->maximum = 1;
  512. vc->step = 1;
  513. break;
  514. case pvr2_ctl_int:
  515. vc->type = V4L2_CTRL_TYPE_INTEGER;
  516. vc->minimum = pvr2_ctrl_get_min(cptr);
  517. vc->maximum = pvr2_ctrl_get_max(cptr);
  518. vc->step = 1;
  519. break;
  520. default:
  521. pvr2_trace(PVR2_TRACE_V4LIOCTL,
  522. "QUERYCTRL id=0x%x name=%s not mappable",
  523. vc->id,pvr2_ctrl_get_name(cptr));
  524. ret = -EINVAL;
  525. break;
  526. }
  527. break;
  528. }
  529. case VIDIOC_QUERYMENU:
  530. {
  531. struct v4l2_querymenu *vm = (struct v4l2_querymenu *)arg;
  532. unsigned int cnt = 0;
  533. ret = pvr2_ctrl_get_valname(pvr2_hdw_get_ctrl_v4l(hdw,vm->id),
  534. vm->index,
  535. vm->name,sizeof(vm->name)-1,
  536. &cnt);
  537. vm->name[cnt] = 0;
  538. break;
  539. }
  540. case VIDIOC_G_CTRL:
  541. {
  542. struct v4l2_control *vc = (struct v4l2_control *)arg;
  543. int val = 0;
  544. ret = pvr2_ctrl_get_value(pvr2_hdw_get_ctrl_v4l(hdw,vc->id),
  545. &val);
  546. vc->value = val;
  547. break;
  548. }
  549. case VIDIOC_S_CTRL:
  550. {
  551. struct v4l2_control *vc = (struct v4l2_control *)arg;
  552. ret = pvr2_ctrl_set_value(pvr2_hdw_get_ctrl_v4l(hdw,vc->id),
  553. vc->value);
  554. break;
  555. }
  556. case VIDIOC_G_EXT_CTRLS:
  557. {
  558. struct v4l2_ext_controls *ctls =
  559. (struct v4l2_ext_controls *)arg;
  560. struct v4l2_ext_control *ctrl;
  561. unsigned int idx;
  562. int val;
  563. for (idx = 0; idx < ctls->count; idx++) {
  564. ctrl = ctls->controls + idx;
  565. ret = pvr2_ctrl_get_value(
  566. pvr2_hdw_get_ctrl_v4l(hdw,ctrl->id),&val);
  567. if (ret) {
  568. ctls->error_idx = idx;
  569. break;
  570. }
  571. /* Ensure that if read as a 64 bit value, the user
  572. will still get a hopefully sane value */
  573. ctrl->value64 = 0;
  574. ctrl->value = val;
  575. }
  576. break;
  577. }
  578. case VIDIOC_S_EXT_CTRLS:
  579. {
  580. struct v4l2_ext_controls *ctls =
  581. (struct v4l2_ext_controls *)arg;
  582. struct v4l2_ext_control *ctrl;
  583. unsigned int idx;
  584. for (idx = 0; idx < ctls->count; idx++) {
  585. ctrl = ctls->controls + idx;
  586. ret = pvr2_ctrl_set_value(
  587. pvr2_hdw_get_ctrl_v4l(hdw,ctrl->id),
  588. ctrl->value);
  589. if (ret) {
  590. ctls->error_idx = idx;
  591. break;
  592. }
  593. }
  594. break;
  595. }
  596. case VIDIOC_TRY_EXT_CTRLS:
  597. {
  598. struct v4l2_ext_controls *ctls =
  599. (struct v4l2_ext_controls *)arg;
  600. struct v4l2_ext_control *ctrl;
  601. struct pvr2_ctrl *pctl;
  602. unsigned int idx;
  603. /* For the moment just validate that the requested control
  604. actually exists. */
  605. for (idx = 0; idx < ctls->count; idx++) {
  606. ctrl = ctls->controls + idx;
  607. pctl = pvr2_hdw_get_ctrl_v4l(hdw,ctrl->id);
  608. if (!pctl) {
  609. ret = -EINVAL;
  610. ctls->error_idx = idx;
  611. break;
  612. }
  613. }
  614. break;
  615. }
  616. case VIDIOC_LOG_STATUS:
  617. {
  618. pvr2_hdw_trigger_module_log(hdw);
  619. ret = 0;
  620. break;
  621. }
  622. #ifdef CONFIG_VIDEO_ADV_DEBUG
  623. case VIDIOC_INT_G_REGISTER:
  624. case VIDIOC_INT_S_REGISTER:
  625. {
  626. u32 val;
  627. struct v4l2_register *req = (struct v4l2_register *)arg;
  628. if (cmd == VIDIOC_INT_S_REGISTER) val = req->val;
  629. ret = pvr2_hdw_register_access(
  630. hdw,req->i2c_id,req->reg,
  631. cmd == VIDIOC_INT_S_REGISTER,&val);
  632. if (cmd == VIDIOC_INT_G_REGISTER) req->val = val;
  633. break;
  634. }
  635. #endif
  636. default :
  637. ret = v4l_compat_translate_ioctl(inode,file,cmd,
  638. arg,pvr2_v4l2_do_ioctl);
  639. }
  640. pvr2_hdw_commit_ctl(hdw);
  641. if (ret < 0) {
  642. if (pvrusb2_debug & PVR2_TRACE_V4LIOCTL) {
  643. pvr2_trace(PVR2_TRACE_V4LIOCTL,
  644. "pvr2_v4l2_do_ioctl failure, ret=%d",ret);
  645. } else {
  646. if (pvrusb2_debug & PVR2_TRACE_V4LIOCTL) {
  647. pvr2_trace(PVR2_TRACE_V4LIOCTL,
  648. "pvr2_v4l2_do_ioctl failure, ret=%d"
  649. " command was:",ret);
  650. v4l_print_ioctl(pvr2_hdw_get_driver_name(hdw),
  651. cmd);
  652. }
  653. }
  654. } else {
  655. pvr2_trace(PVR2_TRACE_V4LIOCTL,
  656. "pvr2_v4l2_do_ioctl complete, ret=%d (0x%x)",
  657. ret,ret);
  658. }
  659. return ret;
  660. }
  661. static void pvr2_v4l2_dev_destroy(struct pvr2_v4l2_dev *dip)
  662. {
  663. enum pvr2_config cfg = dip->config;
  664. int minor_id = dip->devbase.minor;
  665. enum pvr2_v4l_type pvt;
  666. struct pvr2_hdw *hdw = dip->v4lp->channel.mc_head->hdw;
  667. switch (cfg) {
  668. case pvr2_config_mpeg:
  669. pvt = pvr2_v4l_type_video;
  670. break;
  671. case pvr2_config_vbi:
  672. pvt = pvr2_v4l_type_vbi;
  673. break;
  674. case pvr2_config_radio:
  675. pvt = pvr2_v4l_type_radio;
  676. break;
  677. default: /* paranoia */
  678. pvt = pvr2_v4l_type_video;
  679. break;
  680. }
  681. pvr2_hdw_v4l_store_minor_number(hdw,pvt,-1);
  682. /* Paranoia */
  683. dip->v4lp = NULL;
  684. dip->stream = NULL;
  685. /* Actual deallocation happens later when all internal references
  686. are gone. */
  687. video_unregister_device(&dip->devbase);
  688. switch (cfg) {
  689. case pvr2_config_mpeg:
  690. printk(KERN_INFO "pvrusb2: unregistered device video%d [%s]\n",
  691. minor_id & 0x1f,
  692. pvr2_config_get_name(cfg));
  693. break;
  694. case pvr2_config_radio:
  695. printk(KERN_INFO "pvrusb2: unregistered device radio%d [%s]\n",
  696. minor_id & 0x1f,
  697. pvr2_config_get_name(cfg));
  698. break;
  699. case pvr2_config_vbi:
  700. printk(KERN_INFO "pvrusb2: unregistered device vbi%d [%s]\n",
  701. minor_id & 0x1f,
  702. pvr2_config_get_name(cfg));
  703. break;
  704. default:
  705. break;
  706. }
  707. }
  708. static void pvr2_v4l2_destroy_no_lock(struct pvr2_v4l2 *vp)
  709. {
  710. if (vp->dev_video) {
  711. pvr2_v4l2_dev_destroy(vp->dev_video);
  712. vp->dev_video = 0;
  713. }
  714. if (vp->dev_radio) {
  715. pvr2_v4l2_dev_destroy(vp->dev_radio);
  716. vp->dev_radio = 0;
  717. }
  718. pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr2_v4l2 id=%p",vp);
  719. pvr2_channel_done(&vp->channel);
  720. kfree(vp);
  721. }
  722. static void pvr2_video_device_release(struct video_device *vdev)
  723. {
  724. struct pvr2_v4l2_dev *dev;
  725. dev = container_of(vdev,struct pvr2_v4l2_dev,devbase);
  726. kfree(dev);
  727. }
  728. static void pvr2_v4l2_internal_check(struct pvr2_channel *chp)
  729. {
  730. struct pvr2_v4l2 *vp;
  731. vp = container_of(chp,struct pvr2_v4l2,channel);
  732. if (!vp->channel.mc_head->disconnect_flag) return;
  733. if (vp->vfirst) return;
  734. pvr2_v4l2_destroy_no_lock(vp);
  735. }
  736. static int pvr2_v4l2_ioctl(struct inode *inode, struct file *file,
  737. unsigned int cmd, unsigned long arg)
  738. {
  739. /* Temporary hack : use ivtv api until a v4l2 one is available. */
  740. #define IVTV_IOC_G_CODEC 0xFFEE7703
  741. #define IVTV_IOC_S_CODEC 0xFFEE7704
  742. if (cmd == IVTV_IOC_G_CODEC || cmd == IVTV_IOC_S_CODEC) return 0;
  743. return video_usercopy(inode, file, cmd, arg, pvr2_v4l2_do_ioctl);
  744. }
  745. static int pvr2_v4l2_release(struct inode *inode, struct file *file)
  746. {
  747. struct pvr2_v4l2_fh *fhp = file->private_data;
  748. struct pvr2_v4l2 *vp = fhp->vhead;
  749. struct pvr2_context *mp = fhp->vhead->channel.mc_head;
  750. pvr2_trace(PVR2_TRACE_OPEN_CLOSE,"pvr2_v4l2_release");
  751. if (fhp->rhp) {
  752. struct pvr2_stream *sp;
  753. struct pvr2_hdw *hdw;
  754. hdw = fhp->channel.mc_head->hdw;
  755. pvr2_hdw_set_streaming(hdw,0);
  756. sp = pvr2_ioread_get_stream(fhp->rhp);
  757. if (sp) pvr2_stream_set_callback(sp,NULL,NULL);
  758. pvr2_ioread_destroy(fhp->rhp);
  759. fhp->rhp = NULL;
  760. }
  761. if (fhp->dev_info->config == pvr2_config_radio) {
  762. int ret;
  763. struct pvr2_hdw *hdw;
  764. hdw = fhp->channel.mc_head->hdw;
  765. if ((ret = pvr2_ctrl_set_value(
  766. pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT),
  767. PVR2_CVAL_INPUT_TV))) {
  768. return ret;
  769. }
  770. }
  771. v4l2_prio_close(&vp->prio, &fhp->prio);
  772. file->private_data = NULL;
  773. pvr2_context_enter(mp); do {
  774. if (fhp->vnext) {
  775. fhp->vnext->vprev = fhp->vprev;
  776. } else {
  777. vp->vlast = fhp->vprev;
  778. }
  779. if (fhp->vprev) {
  780. fhp->vprev->vnext = fhp->vnext;
  781. } else {
  782. vp->vfirst = fhp->vnext;
  783. }
  784. fhp->vnext = NULL;
  785. fhp->vprev = NULL;
  786. fhp->vhead = NULL;
  787. pvr2_channel_done(&fhp->channel);
  788. pvr2_trace(PVR2_TRACE_STRUCT,
  789. "Destroying pvr_v4l2_fh id=%p",fhp);
  790. kfree(fhp);
  791. if (vp->channel.mc_head->disconnect_flag && !vp->vfirst) {
  792. pvr2_v4l2_destroy_no_lock(vp);
  793. }
  794. } while (0); pvr2_context_exit(mp);
  795. return 0;
  796. }
  797. static int pvr2_v4l2_open(struct inode *inode, struct file *file)
  798. {
  799. struct pvr2_v4l2_dev *dip; /* Our own context pointer */
  800. struct pvr2_v4l2_fh *fhp;
  801. struct pvr2_v4l2 *vp;
  802. struct pvr2_hdw *hdw;
  803. dip = container_of(video_devdata(file),struct pvr2_v4l2_dev,devbase);
  804. vp = dip->v4lp;
  805. hdw = vp->channel.hdw;
  806. pvr2_trace(PVR2_TRACE_OPEN_CLOSE,"pvr2_v4l2_open");
  807. if (!pvr2_hdw_dev_ok(hdw)) {
  808. pvr2_trace(PVR2_TRACE_OPEN_CLOSE,
  809. "pvr2_v4l2_open: hardware not ready");
  810. return -EIO;
  811. }
  812. fhp = kmalloc(sizeof(*fhp),GFP_KERNEL);
  813. if (!fhp) {
  814. return -ENOMEM;
  815. }
  816. memset(fhp,0,sizeof(*fhp));
  817. init_waitqueue_head(&fhp->wait_data);
  818. fhp->dev_info = dip;
  819. pvr2_context_enter(vp->channel.mc_head); do {
  820. pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr_v4l2_fh id=%p",fhp);
  821. pvr2_channel_init(&fhp->channel,vp->channel.mc_head);
  822. /* pk: warning, severe ugliness follows. 18+ only.
  823. please blaim V4L(ivtv) for braindamaged interfaces,
  824. not the implementor. This is probably flawed, but
  825. suggestions on how to do this "right" are welcome! */
  826. if (dip->config == pvr2_config_radio) {
  827. int ret;
  828. if ((pvr2_channel_check_stream_no_lock(&fhp->channel,
  829. fhp->dev_info->stream)) != 0) {
  830. /* We can 't switch modes while streaming */
  831. pvr2_channel_done(&fhp->channel);
  832. kfree(fhp);
  833. pvr2_context_exit(vp->channel.mc_head);
  834. return -EBUSY;
  835. }
  836. if ((ret = pvr2_ctrl_set_value(
  837. pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT),
  838. PVR2_CVAL_INPUT_RADIO))) {
  839. pvr2_channel_done(&fhp->channel);
  840. kfree(fhp);
  841. pvr2_context_exit(vp->channel.mc_head);
  842. return ret;
  843. }
  844. }
  845. fhp->vnext = NULL;
  846. fhp->vprev = vp->vlast;
  847. if (vp->vlast) {
  848. vp->vlast->vnext = fhp;
  849. } else {
  850. vp->vfirst = fhp;
  851. }
  852. vp->vlast = fhp;
  853. fhp->vhead = vp;
  854. } while (0); pvr2_context_exit(vp->channel.mc_head);
  855. fhp->file = file;
  856. file->private_data = fhp;
  857. v4l2_prio_open(&vp->prio,&fhp->prio);
  858. fhp->fw_mode_flag = pvr2_hdw_cpufw_get_enabled(hdw);
  859. return 0;
  860. }
  861. static void pvr2_v4l2_notify(struct pvr2_v4l2_fh *fhp)
  862. {
  863. wake_up(&fhp->wait_data);
  864. }
  865. static int pvr2_v4l2_iosetup(struct pvr2_v4l2_fh *fh)
  866. {
  867. int ret;
  868. struct pvr2_stream *sp;
  869. struct pvr2_hdw *hdw;
  870. if (fh->rhp) return 0;
  871. /* First read() attempt. Try to claim the stream and start
  872. it... */
  873. if ((ret = pvr2_channel_claim_stream(&fh->channel,
  874. fh->dev_info->stream)) != 0) {
  875. /* Someone else must already have it */
  876. return ret;
  877. }
  878. fh->rhp = pvr2_channel_create_mpeg_stream(fh->dev_info->stream);
  879. if (!fh->rhp) {
  880. pvr2_channel_claim_stream(&fh->channel,NULL);
  881. return -ENOMEM;
  882. }
  883. hdw = fh->channel.mc_head->hdw;
  884. sp = fh->dev_info->stream->stream;
  885. pvr2_stream_set_callback(sp,(pvr2_stream_callback)pvr2_v4l2_notify,fh);
  886. pvr2_hdw_set_stream_type(hdw,fh->dev_info->config);
  887. pvr2_hdw_set_streaming(hdw,!0);
  888. ret = pvr2_ioread_set_enabled(fh->rhp,!0);
  889. return ret;
  890. }
  891. static ssize_t pvr2_v4l2_read(struct file *file,
  892. char __user *buff, size_t count, loff_t *ppos)
  893. {
  894. struct pvr2_v4l2_fh *fh = file->private_data;
  895. int ret;
  896. if (fh->fw_mode_flag) {
  897. struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
  898. char *tbuf;
  899. int c1,c2;
  900. int tcnt = 0;
  901. unsigned int offs = *ppos;
  902. tbuf = kmalloc(PAGE_SIZE,GFP_KERNEL);
  903. if (!tbuf) return -ENOMEM;
  904. while (count) {
  905. c1 = count;
  906. if (c1 > PAGE_SIZE) c1 = PAGE_SIZE;
  907. c2 = pvr2_hdw_cpufw_get(hdw,offs,tbuf,c1);
  908. if (c2 < 0) {
  909. tcnt = c2;
  910. break;
  911. }
  912. if (!c2) break;
  913. if (copy_to_user(buff,tbuf,c2)) {
  914. tcnt = -EFAULT;
  915. break;
  916. }
  917. offs += c2;
  918. tcnt += c2;
  919. buff += c2;
  920. count -= c2;
  921. *ppos += c2;
  922. }
  923. kfree(tbuf);
  924. return tcnt;
  925. }
  926. if (fh->dev_info->config == pvr2_config_radio) {
  927. /* Radio device nodes on this device
  928. cannot be read or written. */
  929. return -EPERM;
  930. }
  931. if (!fh->rhp) {
  932. ret = pvr2_v4l2_iosetup(fh);
  933. if (ret) {
  934. return ret;
  935. }
  936. }
  937. for (;;) {
  938. ret = pvr2_ioread_read(fh->rhp,buff,count);
  939. if (ret >= 0) break;
  940. if (ret != -EAGAIN) break;
  941. if (file->f_flags & O_NONBLOCK) break;
  942. /* Doing blocking I/O. Wait here. */
  943. ret = wait_event_interruptible(
  944. fh->wait_data,
  945. pvr2_ioread_avail(fh->rhp) >= 0);
  946. if (ret < 0) break;
  947. }
  948. return ret;
  949. }
  950. static unsigned int pvr2_v4l2_poll(struct file *file, poll_table *wait)
  951. {
  952. unsigned int mask = 0;
  953. struct pvr2_v4l2_fh *fh = file->private_data;
  954. int ret;
  955. if (fh->fw_mode_flag) {
  956. mask |= POLLIN | POLLRDNORM;
  957. return mask;
  958. }
  959. if (fh->dev_info->config == pvr2_config_radio) {
  960. /* Radio device nodes on this device
  961. cannot be read or written. */
  962. return -EPERM;
  963. }
  964. if (!fh->rhp) {
  965. ret = pvr2_v4l2_iosetup(fh);
  966. if (ret) return POLLERR;
  967. }
  968. poll_wait(file,&fh->wait_data,wait);
  969. if (pvr2_ioread_avail(fh->rhp) >= 0) {
  970. mask |= POLLIN | POLLRDNORM;
  971. }
  972. return mask;
  973. }
  974. static const struct file_operations vdev_fops = {
  975. .owner = THIS_MODULE,
  976. .open = pvr2_v4l2_open,
  977. .release = pvr2_v4l2_release,
  978. .read = pvr2_v4l2_read,
  979. .ioctl = pvr2_v4l2_ioctl,
  980. .llseek = no_llseek,
  981. .poll = pvr2_v4l2_poll,
  982. };
  983. #define VID_HARDWARE_PVRUSB2 38 /* FIXME : need a good value */
  984. static struct video_device vdev_template = {
  985. .owner = THIS_MODULE,
  986. .type = VID_TYPE_CAPTURE | VID_TYPE_TUNER,
  987. .type2 = (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VBI_CAPTURE
  988. | V4L2_CAP_TUNER | V4L2_CAP_AUDIO
  989. | V4L2_CAP_READWRITE),
  990. .hardware = VID_HARDWARE_PVRUSB2,
  991. .fops = &vdev_fops,
  992. };
  993. static void pvr2_v4l2_dev_init(struct pvr2_v4l2_dev *dip,
  994. struct pvr2_v4l2 *vp,
  995. enum pvr2_config cfg)
  996. {
  997. int mindevnum;
  998. int unit_number;
  999. int v4l_type;
  1000. enum pvr2_v4l_type pvt;
  1001. dip->v4lp = vp;
  1002. dip->config = cfg;
  1003. switch (dip->config) {
  1004. case pvr2_config_mpeg:
  1005. v4l_type = VFL_TYPE_GRABBER;
  1006. pvt = pvr2_v4l_type_video;
  1007. dip->stream = &vp->channel.mc_head->video_stream;
  1008. break;
  1009. case pvr2_config_vbi:
  1010. v4l_type = VFL_TYPE_VBI;
  1011. pvt = pvr2_v4l_type_vbi;
  1012. break;
  1013. case pvr2_config_radio:
  1014. v4l_type = VFL_TYPE_RADIO;
  1015. pvt = pvr2_v4l_type_radio;
  1016. break;
  1017. default:
  1018. /* Bail out (this should be impossible) */
  1019. err("Failed to set up pvrusb2 v4l dev"
  1020. " due to unrecognized config");
  1021. return;
  1022. }
  1023. /* radio device doesn 't need its own stream */
  1024. if (!dip->stream && dip->config != pvr2_config_radio) {
  1025. err("Failed to set up pvrusb2 v4l dev"
  1026. " due to missing stream instance");
  1027. return;
  1028. }
  1029. memcpy(&dip->devbase,&vdev_template,sizeof(vdev_template));
  1030. dip->devbase.release = pvr2_video_device_release;
  1031. mindevnum = -1;
  1032. unit_number = pvr2_hdw_get_unit_number(vp->channel.mc_head->hdw);
  1033. if ((unit_number >= 0) && (unit_number < PVR_NUM)) {
  1034. switch (v4l_type) {
  1035. case VFL_TYPE_VBI:
  1036. mindevnum = vbi_nr[unit_number];
  1037. break;
  1038. case VFL_TYPE_RADIO:
  1039. mindevnum = radio_nr[unit_number];
  1040. break;
  1041. case VFL_TYPE_GRABBER:
  1042. default:
  1043. mindevnum = video_nr[unit_number];
  1044. break;
  1045. }
  1046. }
  1047. if ((video_register_device(&dip->devbase, v4l_type, mindevnum) < 0) &&
  1048. (video_register_device(&dip->devbase, v4l_type, -1) < 0)) {
  1049. err("Failed to register pvrusb2 v4l device");
  1050. }
  1051. switch (dip->config) {
  1052. case pvr2_config_mpeg:
  1053. printk(KERN_INFO "pvrusb2: registered device video%d [%s]\n",
  1054. dip->devbase.minor & 0x1f,
  1055. pvr2_config_get_name(dip->config));
  1056. break;
  1057. case pvr2_config_radio:
  1058. printk(KERN_INFO "pvrusb2: registered device radio%d [%s]\n",
  1059. dip->devbase.minor & 0x1f,
  1060. pvr2_config_get_name(dip->config));
  1061. break;
  1062. case pvr2_config_vbi:
  1063. printk(KERN_INFO "pvrusb2: registered device vbi%d [%s]\n",
  1064. dip->devbase.minor & 0x1f,
  1065. pvr2_config_get_name(dip->config));
  1066. break;
  1067. default:
  1068. break;
  1069. }
  1070. pvr2_hdw_v4l_store_minor_number(vp->channel.mc_head->hdw,
  1071. pvt,dip->devbase.minor);
  1072. }
  1073. struct pvr2_v4l2 *pvr2_v4l2_create(struct pvr2_context *mnp)
  1074. {
  1075. struct pvr2_v4l2 *vp;
  1076. vp = kmalloc(sizeof(*vp),GFP_KERNEL);
  1077. if (!vp) return vp;
  1078. memset(vp,0,sizeof(*vp));
  1079. vp->dev_video = kmalloc(sizeof(*vp->dev_video),GFP_KERNEL);
  1080. vp->dev_radio = kmalloc(sizeof(*vp->dev_radio),GFP_KERNEL);
  1081. if (!(vp->dev_video && vp->dev_radio)) {
  1082. if (vp->dev_video) kfree(vp->dev_video);
  1083. if (vp->dev_radio) kfree(vp->dev_radio);
  1084. kfree(vp);
  1085. return NULL;
  1086. }
  1087. memset(vp->dev_video,0,sizeof(*vp->dev_video));
  1088. memset(vp->dev_radio,0,sizeof(*vp->dev_radio));
  1089. pvr2_channel_init(&vp->channel,mnp);
  1090. pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_v4l2 id=%p",vp);
  1091. vp->channel.check_func = pvr2_v4l2_internal_check;
  1092. /* register streams */
  1093. pvr2_v4l2_dev_init(vp->dev_video,vp,pvr2_config_mpeg);
  1094. pvr2_v4l2_dev_init(vp->dev_radio,vp,pvr2_config_radio);
  1095. return vp;
  1096. }
  1097. /*
  1098. Stuff for Emacs to see, in order to encourage consistent editing style:
  1099. *** Local Variables: ***
  1100. *** mode: c ***
  1101. *** fill-column: 75 ***
  1102. *** tab-width: 8 ***
  1103. *** c-basic-offset: 8 ***
  1104. *** End: ***
  1105. */