cx23885-video.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797
  1. /*
  2. * Driver for the Conexant CX23885 PCIe bridge
  3. *
  4. * Copyright (c) 2007 Steven Toth <stoth@linuxtv.org>
  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, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. *
  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <linux/init.h>
  22. #include <linux/list.h>
  23. #include <linux/module.h>
  24. #include <linux/moduleparam.h>
  25. #include <linux/kmod.h>
  26. #include <linux/kernel.h>
  27. #include <linux/slab.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/delay.h>
  30. #include <linux/kthread.h>
  31. #include <asm/div64.h>
  32. #include "cx23885.h"
  33. #include <media/v4l2-common.h>
  34. #include <media/v4l2-ioctl.h>
  35. #include "cx23885-ioctl.h"
  36. #include "tuner-xc2028.h"
  37. #include <media/cx25840.h>
  38. MODULE_DESCRIPTION("v4l2 driver module for cx23885 based TV cards");
  39. MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>");
  40. MODULE_LICENSE("GPL");
  41. /* ------------------------------------------------------------------ */
  42. static unsigned int video_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET };
  43. static unsigned int vbi_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET };
  44. static unsigned int radio_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET };
  45. module_param_array(video_nr, int, NULL, 0444);
  46. module_param_array(vbi_nr, int, NULL, 0444);
  47. module_param_array(radio_nr, int, NULL, 0444);
  48. MODULE_PARM_DESC(video_nr, "video device numbers");
  49. MODULE_PARM_DESC(vbi_nr, "vbi device numbers");
  50. MODULE_PARM_DESC(radio_nr, "radio device numbers");
  51. static unsigned int video_debug;
  52. module_param(video_debug, int, 0644);
  53. MODULE_PARM_DESC(video_debug, "enable debug messages [video]");
  54. static unsigned int irq_debug;
  55. module_param(irq_debug, int, 0644);
  56. MODULE_PARM_DESC(irq_debug, "enable debug messages [IRQ handler]");
  57. static unsigned int vid_limit = 16;
  58. module_param(vid_limit, int, 0644);
  59. MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
  60. #define dprintk(level, fmt, arg...)\
  61. do { if (video_debug >= level)\
  62. printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg);\
  63. } while (0)
  64. /* ------------------------------------------------------------------- */
  65. /* static data */
  66. #define FORMAT_FLAGS_PACKED 0x01
  67. #if 0
  68. static struct cx23885_fmt formats[] = {
  69. {
  70. .name = "8 bpp, gray",
  71. .fourcc = V4L2_PIX_FMT_GREY,
  72. .depth = 8,
  73. .flags = FORMAT_FLAGS_PACKED,
  74. }, {
  75. .name = "15 bpp RGB, le",
  76. .fourcc = V4L2_PIX_FMT_RGB555,
  77. .depth = 16,
  78. .flags = FORMAT_FLAGS_PACKED,
  79. }, {
  80. .name = "15 bpp RGB, be",
  81. .fourcc = V4L2_PIX_FMT_RGB555X,
  82. .depth = 16,
  83. .flags = FORMAT_FLAGS_PACKED,
  84. }, {
  85. .name = "16 bpp RGB, le",
  86. .fourcc = V4L2_PIX_FMT_RGB565,
  87. .depth = 16,
  88. .flags = FORMAT_FLAGS_PACKED,
  89. }, {
  90. .name = "16 bpp RGB, be",
  91. .fourcc = V4L2_PIX_FMT_RGB565X,
  92. .depth = 16,
  93. .flags = FORMAT_FLAGS_PACKED,
  94. }, {
  95. .name = "24 bpp RGB, le",
  96. .fourcc = V4L2_PIX_FMT_BGR24,
  97. .depth = 24,
  98. .flags = FORMAT_FLAGS_PACKED,
  99. }, {
  100. .name = "32 bpp RGB, le",
  101. .fourcc = V4L2_PIX_FMT_BGR32,
  102. .depth = 32,
  103. .flags = FORMAT_FLAGS_PACKED,
  104. }, {
  105. .name = "32 bpp RGB, be",
  106. .fourcc = V4L2_PIX_FMT_RGB32,
  107. .depth = 32,
  108. .flags = FORMAT_FLAGS_PACKED,
  109. }, {
  110. .name = "4:2:2, packed, YUYV",
  111. .fourcc = V4L2_PIX_FMT_YUYV,
  112. .depth = 16,
  113. .flags = FORMAT_FLAGS_PACKED,
  114. }, {
  115. .name = "4:2:2, packed, UYVY",
  116. .fourcc = V4L2_PIX_FMT_UYVY,
  117. .depth = 16,
  118. .flags = FORMAT_FLAGS_PACKED,
  119. },
  120. };
  121. #else
  122. static struct cx23885_fmt formats[] = {
  123. {
  124. #if 0
  125. .name = "4:2:2, packed, UYVY",
  126. .fourcc = V4L2_PIX_FMT_UYVY,
  127. .depth = 16,
  128. .flags = FORMAT_FLAGS_PACKED,
  129. }, {
  130. #endif
  131. .name = "4:2:2, packed, YUYV",
  132. .fourcc = V4L2_PIX_FMT_YUYV,
  133. .depth = 16,
  134. .flags = FORMAT_FLAGS_PACKED,
  135. }
  136. };
  137. #endif
  138. static struct cx23885_fmt *format_by_fourcc(unsigned int fourcc)
  139. {
  140. unsigned int i;
  141. for (i = 0; i < ARRAY_SIZE(formats); i++)
  142. if (formats[i].fourcc == fourcc)
  143. return formats+i;
  144. printk(KERN_ERR "%s(%c%c%c%c) NOT FOUND\n", __func__,
  145. (fourcc & 0xff),
  146. ((fourcc >> 8) & 0xff),
  147. ((fourcc >> 16) & 0xff),
  148. ((fourcc >> 24) & 0xff)
  149. );
  150. return NULL;
  151. }
  152. /* ------------------------------------------------------------------- */
  153. static const struct v4l2_queryctrl no_ctl = {
  154. .name = "42",
  155. .flags = V4L2_CTRL_FLAG_DISABLED,
  156. };
  157. static struct cx23885_ctrl cx23885_ctls[] = {
  158. /* --- video --- */
  159. {
  160. .v = {
  161. .id = V4L2_CID_BRIGHTNESS,
  162. .name = "Brightness",
  163. .minimum = 0x00,
  164. .maximum = 0xff,
  165. .step = 1,
  166. .default_value = 0x7f,
  167. .type = V4L2_CTRL_TYPE_INTEGER,
  168. },
  169. .off = 128,
  170. .reg = LUMA_CTRL,
  171. .mask = 0x00ff,
  172. .shift = 0,
  173. }, {
  174. .v = {
  175. .id = V4L2_CID_CONTRAST,
  176. .name = "Contrast",
  177. .minimum = 0,
  178. .maximum = 0x7f,
  179. .step = 1,
  180. .default_value = 0x3f,
  181. .type = V4L2_CTRL_TYPE_INTEGER,
  182. },
  183. .off = 0,
  184. .reg = LUMA_CTRL,
  185. .mask = 0xff00,
  186. .shift = 8,
  187. }, {
  188. .v = {
  189. .id = V4L2_CID_HUE,
  190. .name = "Hue",
  191. .minimum = -127,
  192. .maximum = 128,
  193. .step = 1,
  194. .default_value = 0x0,
  195. .type = V4L2_CTRL_TYPE_INTEGER,
  196. },
  197. .off = 128,
  198. .reg = CHROMA_CTRL,
  199. .mask = 0xff0000,
  200. .shift = 16,
  201. }, {
  202. /* strictly, this only describes only U saturation.
  203. * V saturation is handled specially through code.
  204. */
  205. .v = {
  206. .id = V4L2_CID_SATURATION,
  207. .name = "Saturation",
  208. .minimum = 0,
  209. .maximum = 0x7f,
  210. .step = 1,
  211. .default_value = 0x3f,
  212. .type = V4L2_CTRL_TYPE_INTEGER,
  213. },
  214. .off = 0,
  215. .reg = CHROMA_CTRL,
  216. .mask = 0x00ff,
  217. .shift = 0,
  218. }, {
  219. /* --- audio --- */
  220. .v = {
  221. .id = V4L2_CID_AUDIO_MUTE,
  222. .name = "Mute",
  223. .minimum = 0,
  224. .maximum = 1,
  225. .default_value = 1,
  226. .type = V4L2_CTRL_TYPE_BOOLEAN,
  227. },
  228. .reg = PATH1_CTL1,
  229. .mask = (0x1f << 24),
  230. .shift = 24,
  231. }, {
  232. .v = {
  233. .id = V4L2_CID_AUDIO_VOLUME,
  234. .name = "Volume",
  235. .minimum = 0,
  236. .maximum = 0x3f,
  237. .step = 1,
  238. .default_value = 0x3f,
  239. .type = V4L2_CTRL_TYPE_INTEGER,
  240. },
  241. .reg = PATH1_VOL_CTL,
  242. .mask = 0xff,
  243. .shift = 0,
  244. }
  245. };
  246. static const int CX23885_CTLS = ARRAY_SIZE(cx23885_ctls);
  247. /* Must be sorted from low to high control ID! */
  248. static const u32 cx23885_user_ctrls[] = {
  249. V4L2_CID_USER_CLASS,
  250. V4L2_CID_BRIGHTNESS,
  251. V4L2_CID_CONTRAST,
  252. V4L2_CID_SATURATION,
  253. V4L2_CID_HUE,
  254. V4L2_CID_AUDIO_VOLUME,
  255. V4L2_CID_AUDIO_MUTE,
  256. 0
  257. };
  258. static const u32 *ctrl_classes[] = {
  259. cx23885_user_ctrls,
  260. NULL
  261. };
  262. void cx23885_video_wakeup(struct cx23885_dev *dev,
  263. struct cx23885_dmaqueue *q, u32 count)
  264. {
  265. struct cx23885_buffer *buf;
  266. int bc;
  267. for (bc = 0;; bc++) {
  268. if (list_empty(&q->active))
  269. break;
  270. buf = list_entry(q->active.next,
  271. struct cx23885_buffer, vb.queue);
  272. /* count comes from the hw and is is 16bit wide --
  273. * this trick handles wrap-arounds correctly for
  274. * up to 32767 buffers in flight... */
  275. if ((s16) (count - buf->count) < 0)
  276. break;
  277. do_gettimeofday(&buf->vb.ts);
  278. dprintk(2, "[%p/%d] wakeup reg=%d buf=%d\n", buf, buf->vb.i,
  279. count, buf->count);
  280. buf->vb.state = VIDEOBUF_DONE;
  281. list_del(&buf->vb.queue);
  282. wake_up(&buf->vb.done);
  283. }
  284. if (list_empty(&q->active))
  285. del_timer(&q->timeout);
  286. else
  287. mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
  288. if (bc != 1)
  289. printk(KERN_ERR "%s: %d buffers handled (should be 1)\n",
  290. __func__, bc);
  291. }
  292. static int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm)
  293. {
  294. dprintk(1, "%s(norm = 0x%08x) name: [%s]\n",
  295. __func__,
  296. (unsigned int)norm,
  297. v4l2_norm_to_name(norm));
  298. dev->tvnorm = norm;
  299. call_all(dev, core, s_std, norm);
  300. return 0;
  301. }
  302. static struct video_device *cx23885_vdev_init(struct cx23885_dev *dev,
  303. struct pci_dev *pci,
  304. struct video_device *template,
  305. char *type)
  306. {
  307. struct video_device *vfd;
  308. dprintk(1, "%s()\n", __func__);
  309. vfd = video_device_alloc();
  310. if (NULL == vfd)
  311. return NULL;
  312. *vfd = *template;
  313. vfd->v4l2_dev = &dev->v4l2_dev;
  314. vfd->release = video_device_release;
  315. snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
  316. dev->name, type, cx23885_boards[dev->board].name);
  317. video_set_drvdata(vfd, dev);
  318. return vfd;
  319. }
  320. static int cx23885_ctrl_query(struct v4l2_queryctrl *qctrl)
  321. {
  322. int i;
  323. if (qctrl->id < V4L2_CID_BASE ||
  324. qctrl->id >= V4L2_CID_LASTP1)
  325. return -EINVAL;
  326. for (i = 0; i < CX23885_CTLS; i++)
  327. if (cx23885_ctls[i].v.id == qctrl->id)
  328. break;
  329. if (i == CX23885_CTLS) {
  330. *qctrl = no_ctl;
  331. return 0;
  332. }
  333. *qctrl = cx23885_ctls[i].v;
  334. return 0;
  335. }
  336. /* ------------------------------------------------------------------- */
  337. /* resource management */
  338. static int res_get(struct cx23885_dev *dev, struct cx23885_fh *fh,
  339. unsigned int bit)
  340. {
  341. dprintk(1, "%s()\n", __func__);
  342. if (fh->resources & bit)
  343. /* have it already allocated */
  344. return 1;
  345. /* is it free? */
  346. mutex_lock(&dev->lock);
  347. if (dev->resources & bit) {
  348. /* no, someone else uses it */
  349. mutex_unlock(&dev->lock);
  350. return 0;
  351. }
  352. /* it's free, grab it */
  353. fh->resources |= bit;
  354. dev->resources |= bit;
  355. dprintk(1, "res: get %d\n", bit);
  356. mutex_unlock(&dev->lock);
  357. return 1;
  358. }
  359. static int res_check(struct cx23885_fh *fh, unsigned int bit)
  360. {
  361. return fh->resources & bit;
  362. }
  363. static int res_locked(struct cx23885_dev *dev, unsigned int bit)
  364. {
  365. return dev->resources & bit;
  366. }
  367. static void res_free(struct cx23885_dev *dev, struct cx23885_fh *fh,
  368. unsigned int bits)
  369. {
  370. BUG_ON((fh->resources & bits) != bits);
  371. dprintk(1, "%s()\n", __func__);
  372. mutex_lock(&dev->lock);
  373. fh->resources &= ~bits;
  374. dev->resources &= ~bits;
  375. dprintk(1, "res: put %d\n", bits);
  376. mutex_unlock(&dev->lock);
  377. }
  378. static int cx23885_flatiron_write(struct cx23885_dev *dev, u8 reg, u8 data)
  379. {
  380. /* 8 bit registers, 8 bit values */
  381. u8 buf[] = { reg, data };
  382. struct i2c_msg msg = { .addr = 0x98 >> 1,
  383. .flags = 0, .buf = buf, .len = 2 };
  384. return i2c_transfer(&dev->i2c_bus[2].i2c_adap, &msg, 1);
  385. }
  386. static u8 cx23885_flatiron_read(struct cx23885_dev *dev, u8 reg)
  387. {
  388. /* 8 bit registers, 8 bit values */
  389. int ret;
  390. u8 b0[] = { reg };
  391. u8 b1[] = { 0 };
  392. struct i2c_msg msg[] = {
  393. { .addr = 0x98 >> 1, .flags = 0, .buf = b0, .len = 1 },
  394. { .addr = 0x98 >> 1, .flags = I2C_M_RD, .buf = b1, .len = 1 }
  395. };
  396. ret = i2c_transfer(&dev->i2c_bus[2].i2c_adap, &msg[0], 2);
  397. if (ret != 2)
  398. printk(KERN_ERR "%s() error\n", __func__);
  399. return b1[0];
  400. }
  401. static void cx23885_flatiron_dump(struct cx23885_dev *dev)
  402. {
  403. int i;
  404. dprintk(1, "Flatiron dump\n");
  405. for (i = 0; i < 0x24; i++) {
  406. dprintk(1, "FI[%02x] = %02x\n", i,
  407. cx23885_flatiron_read(dev, i));
  408. }
  409. }
  410. static int cx23885_flatiron_mux(struct cx23885_dev *dev, int input)
  411. {
  412. u8 val;
  413. dprintk(1, "%s(input = %d)\n", __func__, input);
  414. if (input == 1)
  415. val = cx23885_flatiron_read(dev, CH_PWR_CTRL1) & ~FLD_CH_SEL;
  416. else if (input == 2)
  417. val = cx23885_flatiron_read(dev, CH_PWR_CTRL1) | FLD_CH_SEL;
  418. else
  419. return -EINVAL;
  420. val |= 0x20; /* Enable clock to delta-sigma and dec filter */
  421. cx23885_flatiron_write(dev, CH_PWR_CTRL1, val);
  422. /* Wake up */
  423. cx23885_flatiron_write(dev, CH_PWR_CTRL2, 0);
  424. if (video_debug)
  425. cx23885_flatiron_dump(dev);
  426. return 0;
  427. }
  428. static int cx23885_video_mux(struct cx23885_dev *dev, unsigned int input)
  429. {
  430. dprintk(1, "%s() video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n",
  431. __func__,
  432. input, INPUT(input)->vmux,
  433. INPUT(input)->gpio0, INPUT(input)->gpio1,
  434. INPUT(input)->gpio2, INPUT(input)->gpio3);
  435. dev->input = input;
  436. if (dev->board == CX23885_BOARD_MYGICA_X8506 ||
  437. dev->board == CX23885_BOARD_MAGICPRO_PROHDTVE2) {
  438. /* Select Analog TV */
  439. if (INPUT(input)->type == CX23885_VMUX_TELEVISION)
  440. cx23885_gpio_clear(dev, GPIO_0);
  441. }
  442. /* Tell the internal A/V decoder */
  443. v4l2_subdev_call(dev->sd_cx25840, video, s_routing,
  444. INPUT(input)->vmux, 0, 0);
  445. if ((dev->board == CX23885_BOARD_HAUPPAUGE_HVR1800) ||
  446. (dev->board == CX23885_BOARD_MPX885)) {
  447. /* Configure audio routing */
  448. v4l2_subdev_call(dev->sd_cx25840, audio, s_routing,
  449. INPUT(input)->amux, 0, 0);
  450. if (INPUT(input)->amux == CX25840_AUDIO7)
  451. cx23885_flatiron_mux(dev, 1);
  452. else if (INPUT(input)->amux == CX25840_AUDIO6)
  453. cx23885_flatiron_mux(dev, 2);
  454. }
  455. return 0;
  456. }
  457. static int cx23885_audio_mux(struct cx23885_dev *dev, unsigned int input)
  458. {
  459. dprintk(1, "%s(input=%d)\n", __func__, input);
  460. /* The baseband video core of the cx23885 has two audio inputs.
  461. * LR1 and LR2. In almost every single case so far only HVR1xxx
  462. * cards we've only ever supported LR1. Time to support LR2,
  463. * which is available via the optional white breakout header on
  464. * the board.
  465. * We'll use a could of existing enums in the card struct to allow
  466. * devs to specify which baseband input they need, or just default
  467. * to what we've always used.
  468. */
  469. if (INPUT(input)->amux == CX25840_AUDIO7)
  470. cx23885_flatiron_mux(dev, 1);
  471. else if (INPUT(input)->amux == CX25840_AUDIO6)
  472. cx23885_flatiron_mux(dev, 2);
  473. else {
  474. /* Not specifically defined, assume the default. */
  475. cx23885_flatiron_mux(dev, 1);
  476. }
  477. return 0;
  478. }
  479. /* ------------------------------------------------------------------ */
  480. static int cx23885_start_video_dma(struct cx23885_dev *dev,
  481. struct cx23885_dmaqueue *q,
  482. struct cx23885_buffer *buf)
  483. {
  484. dprintk(1, "%s()\n", __func__);
  485. /* Stop the dma/fifo before we tamper with it's risc programs */
  486. cx_clear(VID_A_DMA_CTL, 0x11);
  487. /* setup fifo + format */
  488. cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH01],
  489. buf->bpl, buf->risc.dma);
  490. /* reset counter */
  491. cx_write(VID_A_GPCNT_CTL, 3);
  492. q->count = 1;
  493. /* enable irq */
  494. cx23885_irq_add_enable(dev, 0x01);
  495. cx_set(VID_A_INT_MSK, 0x000011);
  496. /* start dma */
  497. cx_set(DEV_CNTRL2, (1<<5));
  498. cx_set(VID_A_DMA_CTL, 0x11); /* FIFO and RISC enable */
  499. return 0;
  500. }
  501. static int cx23885_restart_video_queue(struct cx23885_dev *dev,
  502. struct cx23885_dmaqueue *q)
  503. {
  504. struct cx23885_buffer *buf, *prev;
  505. struct list_head *item;
  506. dprintk(1, "%s()\n", __func__);
  507. if (!list_empty(&q->active)) {
  508. buf = list_entry(q->active.next, struct cx23885_buffer,
  509. vb.queue);
  510. dprintk(2, "restart_queue [%p/%d]: restart dma\n",
  511. buf, buf->vb.i);
  512. cx23885_start_video_dma(dev, q, buf);
  513. list_for_each(item, &q->active) {
  514. buf = list_entry(item, struct cx23885_buffer,
  515. vb.queue);
  516. buf->count = q->count++;
  517. }
  518. mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
  519. return 0;
  520. }
  521. prev = NULL;
  522. for (;;) {
  523. if (list_empty(&q->queued))
  524. return 0;
  525. buf = list_entry(q->queued.next, struct cx23885_buffer,
  526. vb.queue);
  527. if (NULL == prev) {
  528. list_move_tail(&buf->vb.queue, &q->active);
  529. cx23885_start_video_dma(dev, q, buf);
  530. buf->vb.state = VIDEOBUF_ACTIVE;
  531. buf->count = q->count++;
  532. mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
  533. dprintk(2, "[%p/%d] restart_queue - first active\n",
  534. buf, buf->vb.i);
  535. } else if (prev->vb.width == buf->vb.width &&
  536. prev->vb.height == buf->vb.height &&
  537. prev->fmt == buf->fmt) {
  538. list_move_tail(&buf->vb.queue, &q->active);
  539. buf->vb.state = VIDEOBUF_ACTIVE;
  540. buf->count = q->count++;
  541. prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
  542. prev->risc.jmp[2] = cpu_to_le32(0); /* Bits 63 - 32 */
  543. dprintk(2, "[%p/%d] restart_queue - move to active\n",
  544. buf, buf->vb.i);
  545. } else {
  546. return 0;
  547. }
  548. prev = buf;
  549. }
  550. }
  551. static int buffer_setup(struct videobuf_queue *q, unsigned int *count,
  552. unsigned int *size)
  553. {
  554. struct cx23885_fh *fh = q->priv_data;
  555. *size = fh->fmt->depth*fh->width*fh->height >> 3;
  556. if (0 == *count)
  557. *count = 32;
  558. if (*size * *count > vid_limit * 1024 * 1024)
  559. *count = (vid_limit * 1024 * 1024) / *size;
  560. return 0;
  561. }
  562. static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
  563. enum v4l2_field field)
  564. {
  565. struct cx23885_fh *fh = q->priv_data;
  566. struct cx23885_dev *dev = fh->dev;
  567. struct cx23885_buffer *buf =
  568. container_of(vb, struct cx23885_buffer, vb);
  569. int rc, init_buffer = 0;
  570. u32 line0_offset, line1_offset;
  571. struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
  572. BUG_ON(NULL == fh->fmt);
  573. if (fh->width < 48 || fh->width > norm_maxw(dev->tvnorm) ||
  574. fh->height < 32 || fh->height > norm_maxh(dev->tvnorm))
  575. return -EINVAL;
  576. buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3;
  577. if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
  578. return -EINVAL;
  579. if (buf->fmt != fh->fmt ||
  580. buf->vb.width != fh->width ||
  581. buf->vb.height != fh->height ||
  582. buf->vb.field != field) {
  583. buf->fmt = fh->fmt;
  584. buf->vb.width = fh->width;
  585. buf->vb.height = fh->height;
  586. buf->vb.field = field;
  587. init_buffer = 1;
  588. }
  589. if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
  590. init_buffer = 1;
  591. rc = videobuf_iolock(q, &buf->vb, NULL);
  592. if (0 != rc)
  593. goto fail;
  594. }
  595. if (init_buffer) {
  596. buf->bpl = buf->vb.width * buf->fmt->depth >> 3;
  597. switch (buf->vb.field) {
  598. case V4L2_FIELD_TOP:
  599. cx23885_risc_buffer(dev->pci, &buf->risc,
  600. dma->sglist, 0, UNSET,
  601. buf->bpl, 0, buf->vb.height);
  602. break;
  603. case V4L2_FIELD_BOTTOM:
  604. cx23885_risc_buffer(dev->pci, &buf->risc,
  605. dma->sglist, UNSET, 0,
  606. buf->bpl, 0, buf->vb.height);
  607. break;
  608. case V4L2_FIELD_INTERLACED:
  609. if (dev->tvnorm & V4L2_STD_NTSC) {
  610. /* cx25840 transmits NTSC bottom field first */
  611. dprintk(1, "%s() Creating NTSC risc\n",
  612. __func__);
  613. line0_offset = buf->bpl;
  614. line1_offset = 0;
  615. } else {
  616. /* All other formats are top field first */
  617. dprintk(1, "%s() Creating PAL/SECAM risc\n",
  618. __func__);
  619. line0_offset = 0;
  620. line1_offset = buf->bpl;
  621. }
  622. cx23885_risc_buffer(dev->pci, &buf->risc,
  623. dma->sglist, line0_offset,
  624. line1_offset,
  625. buf->bpl, buf->bpl,
  626. buf->vb.height >> 1);
  627. break;
  628. case V4L2_FIELD_SEQ_TB:
  629. cx23885_risc_buffer(dev->pci, &buf->risc,
  630. dma->sglist,
  631. 0, buf->bpl * (buf->vb.height >> 1),
  632. buf->bpl, 0,
  633. buf->vb.height >> 1);
  634. break;
  635. case V4L2_FIELD_SEQ_BT:
  636. cx23885_risc_buffer(dev->pci, &buf->risc,
  637. dma->sglist,
  638. buf->bpl * (buf->vb.height >> 1), 0,
  639. buf->bpl, 0,
  640. buf->vb.height >> 1);
  641. break;
  642. default:
  643. BUG();
  644. }
  645. }
  646. dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
  647. buf, buf->vb.i,
  648. fh->width, fh->height, fh->fmt->depth, fh->fmt->name,
  649. (unsigned long)buf->risc.dma);
  650. buf->vb.state = VIDEOBUF_PREPARED;
  651. return 0;
  652. fail:
  653. cx23885_free_buffer(q, buf);
  654. return rc;
  655. }
  656. static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
  657. {
  658. struct cx23885_buffer *buf = container_of(vb,
  659. struct cx23885_buffer, vb);
  660. struct cx23885_buffer *prev;
  661. struct cx23885_fh *fh = vq->priv_data;
  662. struct cx23885_dev *dev = fh->dev;
  663. struct cx23885_dmaqueue *q = &dev->vidq;
  664. /* add jump to stopper */
  665. buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
  666. buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
  667. buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
  668. if (!list_empty(&q->queued)) {
  669. list_add_tail(&buf->vb.queue, &q->queued);
  670. buf->vb.state = VIDEOBUF_QUEUED;
  671. dprintk(2, "[%p/%d] buffer_queue - append to queued\n",
  672. buf, buf->vb.i);
  673. } else if (list_empty(&q->active)) {
  674. list_add_tail(&buf->vb.queue, &q->active);
  675. cx23885_start_video_dma(dev, q, buf);
  676. buf->vb.state = VIDEOBUF_ACTIVE;
  677. buf->count = q->count++;
  678. mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
  679. dprintk(2, "[%p/%d] buffer_queue - first active\n",
  680. buf, buf->vb.i);
  681. } else {
  682. prev = list_entry(q->active.prev, struct cx23885_buffer,
  683. vb.queue);
  684. if (prev->vb.width == buf->vb.width &&
  685. prev->vb.height == buf->vb.height &&
  686. prev->fmt == buf->fmt) {
  687. list_add_tail(&buf->vb.queue, &q->active);
  688. buf->vb.state = VIDEOBUF_ACTIVE;
  689. buf->count = q->count++;
  690. prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
  691. /* 64 bit bits 63-32 */
  692. prev->risc.jmp[2] = cpu_to_le32(0);
  693. dprintk(2, "[%p/%d] buffer_queue - append to active\n",
  694. buf, buf->vb.i);
  695. } else {
  696. list_add_tail(&buf->vb.queue, &q->queued);
  697. buf->vb.state = VIDEOBUF_QUEUED;
  698. dprintk(2, "[%p/%d] buffer_queue - first queued\n",
  699. buf, buf->vb.i);
  700. }
  701. }
  702. }
  703. static void buffer_release(struct videobuf_queue *q,
  704. struct videobuf_buffer *vb)
  705. {
  706. struct cx23885_buffer *buf = container_of(vb,
  707. struct cx23885_buffer, vb);
  708. cx23885_free_buffer(q, buf);
  709. }
  710. static struct videobuf_queue_ops cx23885_video_qops = {
  711. .buf_setup = buffer_setup,
  712. .buf_prepare = buffer_prepare,
  713. .buf_queue = buffer_queue,
  714. .buf_release = buffer_release,
  715. };
  716. static struct videobuf_queue *get_queue(struct cx23885_fh *fh)
  717. {
  718. switch (fh->type) {
  719. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  720. return &fh->vidq;
  721. case V4L2_BUF_TYPE_VBI_CAPTURE:
  722. return &fh->vbiq;
  723. default:
  724. BUG();
  725. return NULL;
  726. }
  727. }
  728. static int get_resource(struct cx23885_fh *fh)
  729. {
  730. switch (fh->type) {
  731. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  732. return RESOURCE_VIDEO;
  733. case V4L2_BUF_TYPE_VBI_CAPTURE:
  734. return RESOURCE_VBI;
  735. default:
  736. BUG();
  737. return 0;
  738. }
  739. }
  740. static int video_open(struct file *file)
  741. {
  742. struct video_device *vdev = video_devdata(file);
  743. struct cx23885_dev *dev = video_drvdata(file);
  744. struct cx23885_fh *fh;
  745. enum v4l2_buf_type type = 0;
  746. int radio = 0;
  747. switch (vdev->vfl_type) {
  748. case VFL_TYPE_GRABBER:
  749. type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  750. break;
  751. case VFL_TYPE_VBI:
  752. type = V4L2_BUF_TYPE_VBI_CAPTURE;
  753. break;
  754. case VFL_TYPE_RADIO:
  755. radio = 1;
  756. break;
  757. }
  758. dprintk(1, "open dev=%s radio=%d type=%s\n",
  759. video_device_node_name(vdev), radio, v4l2_type_names[type]);
  760. /* allocate + initialize per filehandle data */
  761. fh = kzalloc(sizeof(*fh), GFP_KERNEL);
  762. if (NULL == fh)
  763. return -ENOMEM;
  764. file->private_data = fh;
  765. fh->dev = dev;
  766. fh->radio = radio;
  767. fh->type = type;
  768. fh->width = 320;
  769. fh->height = 240;
  770. fh->fmt = format_by_fourcc(V4L2_PIX_FMT_YUYV);
  771. videobuf_queue_sg_init(&fh->vidq, &cx23885_video_qops,
  772. &dev->pci->dev, &dev->slock,
  773. V4L2_BUF_TYPE_VIDEO_CAPTURE,
  774. V4L2_FIELD_INTERLACED,
  775. sizeof(struct cx23885_buffer),
  776. fh, NULL);
  777. videobuf_queue_sg_init(&fh->vbiq, &cx23885_vbi_qops,
  778. &dev->pci->dev, &dev->slock,
  779. V4L2_BUF_TYPE_VBI_CAPTURE,
  780. V4L2_FIELD_SEQ_TB,
  781. sizeof(struct cx23885_buffer),
  782. fh, NULL);
  783. dprintk(1, "post videobuf_queue_init()\n");
  784. return 0;
  785. }
  786. static ssize_t video_read(struct file *file, char __user *data,
  787. size_t count, loff_t *ppos)
  788. {
  789. struct cx23885_fh *fh = file->private_data;
  790. switch (fh->type) {
  791. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  792. if (res_locked(fh->dev, RESOURCE_VIDEO))
  793. return -EBUSY;
  794. return videobuf_read_one(&fh->vidq, data, count, ppos,
  795. file->f_flags & O_NONBLOCK);
  796. case V4L2_BUF_TYPE_VBI_CAPTURE:
  797. if (!res_get(fh->dev, fh, RESOURCE_VBI))
  798. return -EBUSY;
  799. return videobuf_read_stream(&fh->vbiq, data, count, ppos, 1,
  800. file->f_flags & O_NONBLOCK);
  801. default:
  802. BUG();
  803. return 0;
  804. }
  805. }
  806. static unsigned int video_poll(struct file *file,
  807. struct poll_table_struct *wait)
  808. {
  809. struct cx23885_fh *fh = file->private_data;
  810. struct cx23885_buffer *buf;
  811. unsigned int rc = POLLERR;
  812. if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) {
  813. if (!res_get(fh->dev, fh, RESOURCE_VBI))
  814. return POLLERR;
  815. return videobuf_poll_stream(file, &fh->vbiq, wait);
  816. }
  817. mutex_lock(&fh->vidq.vb_lock);
  818. if (res_check(fh, RESOURCE_VIDEO)) {
  819. /* streaming capture */
  820. if (list_empty(&fh->vidq.stream))
  821. goto done;
  822. buf = list_entry(fh->vidq.stream.next,
  823. struct cx23885_buffer, vb.stream);
  824. } else {
  825. /* read() capture */
  826. buf = (struct cx23885_buffer *)fh->vidq.read_buf;
  827. if (NULL == buf)
  828. goto done;
  829. }
  830. poll_wait(file, &buf->vb.done, wait);
  831. if (buf->vb.state == VIDEOBUF_DONE ||
  832. buf->vb.state == VIDEOBUF_ERROR)
  833. rc = POLLIN|POLLRDNORM;
  834. else
  835. rc = 0;
  836. done:
  837. mutex_unlock(&fh->vidq.vb_lock);
  838. return rc;
  839. }
  840. static int video_release(struct file *file)
  841. {
  842. struct cx23885_fh *fh = file->private_data;
  843. struct cx23885_dev *dev = fh->dev;
  844. /* turn off overlay */
  845. if (res_check(fh, RESOURCE_OVERLAY)) {
  846. /* FIXME */
  847. res_free(dev, fh, RESOURCE_OVERLAY);
  848. }
  849. /* stop video capture */
  850. if (res_check(fh, RESOURCE_VIDEO)) {
  851. videobuf_queue_cancel(&fh->vidq);
  852. res_free(dev, fh, RESOURCE_VIDEO);
  853. }
  854. if (fh->vidq.read_buf) {
  855. buffer_release(&fh->vidq, fh->vidq.read_buf);
  856. kfree(fh->vidq.read_buf);
  857. }
  858. /* stop vbi capture */
  859. if (res_check(fh, RESOURCE_VBI)) {
  860. if (fh->vbiq.streaming)
  861. videobuf_streamoff(&fh->vbiq);
  862. if (fh->vbiq.reading)
  863. videobuf_read_stop(&fh->vbiq);
  864. res_free(dev, fh, RESOURCE_VBI);
  865. }
  866. videobuf_mmap_free(&fh->vidq);
  867. file->private_data = NULL;
  868. kfree(fh);
  869. /* We are not putting the tuner to sleep here on exit, because
  870. * we want to use the mpeg encoder in another session to capture
  871. * tuner video. Closing this will result in no video to the encoder.
  872. */
  873. return 0;
  874. }
  875. static int video_mmap(struct file *file, struct vm_area_struct *vma)
  876. {
  877. struct cx23885_fh *fh = file->private_data;
  878. return videobuf_mmap_mapper(get_queue(fh), vma);
  879. }
  880. /* ------------------------------------------------------------------ */
  881. /* VIDEO CTRL IOCTLS */
  882. static int cx23885_get_control(struct cx23885_dev *dev,
  883. struct v4l2_control *ctl)
  884. {
  885. dprintk(1, "%s() calling cx25840(VIDIOC_G_CTRL)\n", __func__);
  886. call_all(dev, core, g_ctrl, ctl);
  887. return 0;
  888. }
  889. static int cx23885_set_control(struct cx23885_dev *dev,
  890. struct v4l2_control *ctl)
  891. {
  892. dprintk(1, "%s() calling cx25840(VIDIOC_S_CTRL)\n", __func__);
  893. call_all(dev, core, s_ctrl, ctl);
  894. return 0;
  895. }
  896. static void init_controls(struct cx23885_dev *dev)
  897. {
  898. struct v4l2_control ctrl;
  899. int i;
  900. for (i = 0; i < CX23885_CTLS; i++) {
  901. ctrl.id = cx23885_ctls[i].v.id;
  902. ctrl.value = cx23885_ctls[i].v.default_value;
  903. cx23885_set_control(dev, &ctrl);
  904. }
  905. }
  906. /* ------------------------------------------------------------------ */
  907. /* VIDEO IOCTLS */
  908. static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
  909. struct v4l2_format *f)
  910. {
  911. struct cx23885_fh *fh = priv;
  912. f->fmt.pix.width = fh->width;
  913. f->fmt.pix.height = fh->height;
  914. f->fmt.pix.field = fh->vidq.field;
  915. f->fmt.pix.pixelformat = fh->fmt->fourcc;
  916. f->fmt.pix.bytesperline =
  917. (f->fmt.pix.width * fh->fmt->depth) >> 3;
  918. f->fmt.pix.sizeimage =
  919. f->fmt.pix.height * f->fmt.pix.bytesperline;
  920. return 0;
  921. }
  922. static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
  923. struct v4l2_format *f)
  924. {
  925. struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
  926. struct cx23885_fmt *fmt;
  927. enum v4l2_field field;
  928. unsigned int maxw, maxh;
  929. fmt = format_by_fourcc(f->fmt.pix.pixelformat);
  930. if (NULL == fmt)
  931. return -EINVAL;
  932. field = f->fmt.pix.field;
  933. maxw = norm_maxw(dev->tvnorm);
  934. maxh = norm_maxh(dev->tvnorm);
  935. if (V4L2_FIELD_ANY == field) {
  936. field = (f->fmt.pix.height > maxh/2)
  937. ? V4L2_FIELD_INTERLACED
  938. : V4L2_FIELD_BOTTOM;
  939. }
  940. switch (field) {
  941. case V4L2_FIELD_TOP:
  942. case V4L2_FIELD_BOTTOM:
  943. maxh = maxh / 2;
  944. break;
  945. case V4L2_FIELD_INTERLACED:
  946. break;
  947. default:
  948. return -EINVAL;
  949. }
  950. f->fmt.pix.field = field;
  951. v4l_bound_align_image(&f->fmt.pix.width, 48, maxw, 2,
  952. &f->fmt.pix.height, 32, maxh, 0, 0);
  953. f->fmt.pix.bytesperline =
  954. (f->fmt.pix.width * fmt->depth) >> 3;
  955. f->fmt.pix.sizeimage =
  956. f->fmt.pix.height * f->fmt.pix.bytesperline;
  957. return 0;
  958. }
  959. static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
  960. struct v4l2_format *f)
  961. {
  962. struct cx23885_fh *fh = priv;
  963. struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
  964. struct v4l2_mbus_framefmt mbus_fmt;
  965. int err;
  966. dprintk(2, "%s()\n", __func__);
  967. err = vidioc_try_fmt_vid_cap(file, priv, f);
  968. if (0 != err)
  969. return err;
  970. fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
  971. fh->width = f->fmt.pix.width;
  972. fh->height = f->fmt.pix.height;
  973. fh->vidq.field = f->fmt.pix.field;
  974. dprintk(2, "%s() width=%d height=%d field=%d\n", __func__,
  975. fh->width, fh->height, fh->vidq.field);
  976. v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED);
  977. call_all(dev, video, s_mbus_fmt, &mbus_fmt);
  978. v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt);
  979. return 0;
  980. }
  981. static int vidioc_querycap(struct file *file, void *priv,
  982. struct v4l2_capability *cap)
  983. {
  984. struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
  985. strcpy(cap->driver, "cx23885");
  986. strlcpy(cap->card, cx23885_boards[dev->board].name,
  987. sizeof(cap->card));
  988. sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci));
  989. cap->capabilities =
  990. V4L2_CAP_VIDEO_CAPTURE |
  991. V4L2_CAP_READWRITE |
  992. V4L2_CAP_STREAMING |
  993. V4L2_CAP_VBI_CAPTURE;
  994. if (UNSET != dev->tuner_type)
  995. cap->capabilities |= V4L2_CAP_TUNER;
  996. return 0;
  997. }
  998. static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
  999. struct v4l2_fmtdesc *f)
  1000. {
  1001. if (unlikely(f->index >= ARRAY_SIZE(formats)))
  1002. return -EINVAL;
  1003. strlcpy(f->description, formats[f->index].name,
  1004. sizeof(f->description));
  1005. f->pixelformat = formats[f->index].fourcc;
  1006. return 0;
  1007. }
  1008. static int vidioc_reqbufs(struct file *file, void *priv,
  1009. struct v4l2_requestbuffers *p)
  1010. {
  1011. struct cx23885_fh *fh = priv;
  1012. return videobuf_reqbufs(get_queue(fh), p);
  1013. }
  1014. static int vidioc_querybuf(struct file *file, void *priv,
  1015. struct v4l2_buffer *p)
  1016. {
  1017. struct cx23885_fh *fh = priv;
  1018. return videobuf_querybuf(get_queue(fh), p);
  1019. }
  1020. static int vidioc_qbuf(struct file *file, void *priv,
  1021. struct v4l2_buffer *p)
  1022. {
  1023. struct cx23885_fh *fh = priv;
  1024. return videobuf_qbuf(get_queue(fh), p);
  1025. }
  1026. static int vidioc_dqbuf(struct file *file, void *priv,
  1027. struct v4l2_buffer *p)
  1028. {
  1029. struct cx23885_fh *fh = priv;
  1030. return videobuf_dqbuf(get_queue(fh), p,
  1031. file->f_flags & O_NONBLOCK);
  1032. }
  1033. static int vidioc_streamon(struct file *file, void *priv,
  1034. enum v4l2_buf_type i)
  1035. {
  1036. struct cx23885_fh *fh = priv;
  1037. struct cx23885_dev *dev = fh->dev;
  1038. dprintk(1, "%s()\n", __func__);
  1039. if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
  1040. (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE))
  1041. return -EINVAL;
  1042. if (unlikely(i != fh->type))
  1043. return -EINVAL;
  1044. if (unlikely(!res_get(dev, fh, get_resource(fh))))
  1045. return -EBUSY;
  1046. /* Don't start VBI streaming unless vida streaming
  1047. * has already started.
  1048. */
  1049. if ((fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) &&
  1050. ((cx_read(VID_A_DMA_CTL) & 0x11) == 0))
  1051. return -EINVAL;
  1052. return videobuf_streamon(get_queue(fh));
  1053. }
  1054. static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
  1055. {
  1056. struct cx23885_fh *fh = priv;
  1057. struct cx23885_dev *dev = fh->dev;
  1058. int err, res;
  1059. dprintk(1, "%s()\n", __func__);
  1060. if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
  1061. (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE))
  1062. return -EINVAL;
  1063. if (i != fh->type)
  1064. return -EINVAL;
  1065. res = get_resource(fh);
  1066. err = videobuf_streamoff(get_queue(fh));
  1067. if (err < 0)
  1068. return err;
  1069. res_free(dev, fh, res);
  1070. return 0;
  1071. }
  1072. static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *tvnorms)
  1073. {
  1074. struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
  1075. dprintk(1, "%s()\n", __func__);
  1076. mutex_lock(&dev->lock);
  1077. cx23885_set_tvnorm(dev, *tvnorms);
  1078. mutex_unlock(&dev->lock);
  1079. return 0;
  1080. }
  1081. static int cx23885_enum_input(struct cx23885_dev *dev, struct v4l2_input *i)
  1082. {
  1083. static const char *iname[] = {
  1084. [CX23885_VMUX_COMPOSITE1] = "Composite1",
  1085. [CX23885_VMUX_COMPOSITE2] = "Composite2",
  1086. [CX23885_VMUX_COMPOSITE3] = "Composite3",
  1087. [CX23885_VMUX_COMPOSITE4] = "Composite4",
  1088. [CX23885_VMUX_SVIDEO] = "S-Video",
  1089. [CX23885_VMUX_COMPONENT] = "Component",
  1090. [CX23885_VMUX_TELEVISION] = "Television",
  1091. [CX23885_VMUX_CABLE] = "Cable TV",
  1092. [CX23885_VMUX_DVB] = "DVB",
  1093. [CX23885_VMUX_DEBUG] = "for debug only",
  1094. };
  1095. unsigned int n;
  1096. dprintk(1, "%s()\n", __func__);
  1097. n = i->index;
  1098. if (n >= MAX_CX23885_INPUT)
  1099. return -EINVAL;
  1100. if (0 == INPUT(n)->type)
  1101. return -EINVAL;
  1102. i->index = n;
  1103. i->type = V4L2_INPUT_TYPE_CAMERA;
  1104. strcpy(i->name, iname[INPUT(n)->type]);
  1105. if ((CX23885_VMUX_TELEVISION == INPUT(n)->type) ||
  1106. (CX23885_VMUX_CABLE == INPUT(n)->type)) {
  1107. i->type = V4L2_INPUT_TYPE_TUNER;
  1108. i->std = CX23885_NORMS;
  1109. }
  1110. /* Two selectable audio inputs for non-tv inputs */
  1111. if (INPUT(n)->type != CX23885_VMUX_TELEVISION)
  1112. i->audioset = 0x3;
  1113. return 0;
  1114. }
  1115. static int vidioc_enum_input(struct file *file, void *priv,
  1116. struct v4l2_input *i)
  1117. {
  1118. struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
  1119. dprintk(1, "%s()\n", __func__);
  1120. return cx23885_enum_input(dev, i);
  1121. }
  1122. static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  1123. {
  1124. struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
  1125. *i = dev->input;
  1126. dprintk(1, "%s() returns %d\n", __func__, *i);
  1127. return 0;
  1128. }
  1129. static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
  1130. {
  1131. struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
  1132. dprintk(1, "%s(%d)\n", __func__, i);
  1133. if (i >= MAX_CX23885_INPUT) {
  1134. dprintk(1, "%s() -EINVAL\n", __func__);
  1135. return -EINVAL;
  1136. }
  1137. if (INPUT(i)->type == 0)
  1138. return -EINVAL;
  1139. mutex_lock(&dev->lock);
  1140. cx23885_video_mux(dev, i);
  1141. /* By default establish the default audio input for the card also */
  1142. /* Caller is free to use VIDIOC_S_AUDIO to override afterwards */
  1143. cx23885_audio_mux(dev, i);
  1144. mutex_unlock(&dev->lock);
  1145. return 0;
  1146. }
  1147. static int vidioc_log_status(struct file *file, void *priv)
  1148. {
  1149. struct cx23885_fh *fh = priv;
  1150. struct cx23885_dev *dev = fh->dev;
  1151. printk(KERN_INFO
  1152. "%s/0: ============ START LOG STATUS ============\n",
  1153. dev->name);
  1154. call_all(dev, core, log_status);
  1155. printk(KERN_INFO
  1156. "%s/0: ============= END LOG STATUS =============\n",
  1157. dev->name);
  1158. return 0;
  1159. }
  1160. static int cx23885_query_audinput(struct file *file, void *priv,
  1161. struct v4l2_audio *i)
  1162. {
  1163. struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
  1164. static const char *iname[] = {
  1165. [0] = "Baseband L/R 1",
  1166. [1] = "Baseband L/R 2",
  1167. };
  1168. unsigned int n;
  1169. dprintk(1, "%s()\n", __func__);
  1170. n = i->index;
  1171. if (n >= 2)
  1172. return -EINVAL;
  1173. memset(i, 0, sizeof(*i));
  1174. i->index = n;
  1175. strcpy(i->name, iname[n]);
  1176. i->capability = V4L2_AUDCAP_STEREO;
  1177. i->mode = V4L2_AUDMODE_AVL;
  1178. return 0;
  1179. }
  1180. static int vidioc_enum_audinput(struct file *file, void *priv,
  1181. struct v4l2_audio *i)
  1182. {
  1183. return cx23885_query_audinput(file, priv, i);
  1184. }
  1185. static int vidioc_g_audinput(struct file *file, void *priv,
  1186. struct v4l2_audio *i)
  1187. {
  1188. struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
  1189. i->index = dev->audinput;
  1190. dprintk(1, "%s(input=%d)\n", __func__, i->index);
  1191. return cx23885_query_audinput(file, priv, i);
  1192. }
  1193. static int vidioc_s_audinput(struct file *file, void *priv,
  1194. struct v4l2_audio *i)
  1195. {
  1196. struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
  1197. if (i->index >= 2)
  1198. return -EINVAL;
  1199. dprintk(1, "%s(%d)\n", __func__, i->index);
  1200. dev->audinput = i->index;
  1201. /* Skip the audio defaults from the cards struct, caller wants
  1202. * directly touch the audio mux hardware. */
  1203. cx23885_flatiron_mux(dev, dev->audinput + 1);
  1204. return 0;
  1205. }
  1206. static int vidioc_queryctrl(struct file *file, void *priv,
  1207. struct v4l2_queryctrl *qctrl)
  1208. {
  1209. qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
  1210. if (unlikely(qctrl->id == 0))
  1211. return -EINVAL;
  1212. return cx23885_ctrl_query(qctrl);
  1213. }
  1214. static int vidioc_g_ctrl(struct file *file, void *priv,
  1215. struct v4l2_control *ctl)
  1216. {
  1217. struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
  1218. return cx23885_get_control(dev, ctl);
  1219. }
  1220. static int vidioc_s_ctrl(struct file *file, void *priv,
  1221. struct v4l2_control *ctl)
  1222. {
  1223. struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
  1224. return cx23885_set_control(dev, ctl);
  1225. }
  1226. static int vidioc_g_tuner(struct file *file, void *priv,
  1227. struct v4l2_tuner *t)
  1228. {
  1229. struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
  1230. if (unlikely(UNSET == dev->tuner_type))
  1231. return -EINVAL;
  1232. if (0 != t->index)
  1233. return -EINVAL;
  1234. strcpy(t->name, "Television");
  1235. call_all(dev, tuner, g_tuner, t);
  1236. return 0;
  1237. }
  1238. static int vidioc_s_tuner(struct file *file, void *priv,
  1239. struct v4l2_tuner *t)
  1240. {
  1241. struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
  1242. if (UNSET == dev->tuner_type)
  1243. return -EINVAL;
  1244. if (0 != t->index)
  1245. return -EINVAL;
  1246. /* Update the A/V core */
  1247. call_all(dev, tuner, s_tuner, t);
  1248. return 0;
  1249. }
  1250. static int vidioc_g_frequency(struct file *file, void *priv,
  1251. struct v4l2_frequency *f)
  1252. {
  1253. struct cx23885_fh *fh = priv;
  1254. struct cx23885_dev *dev = fh->dev;
  1255. if (unlikely(UNSET == dev->tuner_type))
  1256. return -EINVAL;
  1257. /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */
  1258. f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
  1259. f->frequency = dev->freq;
  1260. call_all(dev, tuner, g_frequency, f);
  1261. return 0;
  1262. }
  1263. static int cx23885_set_freq(struct cx23885_dev *dev, struct v4l2_frequency *f)
  1264. {
  1265. if (unlikely(UNSET == dev->tuner_type))
  1266. return -EINVAL;
  1267. if (unlikely(f->tuner != 0))
  1268. return -EINVAL;
  1269. mutex_lock(&dev->lock);
  1270. dev->freq = f->frequency;
  1271. call_all(dev, tuner, s_frequency, f);
  1272. /* When changing channels it is required to reset TVAUDIO */
  1273. msleep(10);
  1274. mutex_unlock(&dev->lock);
  1275. return 0;
  1276. }
  1277. static int vidioc_s_frequency(struct file *file, void *priv,
  1278. struct v4l2_frequency *f)
  1279. {
  1280. struct cx23885_fh *fh = priv;
  1281. struct cx23885_dev *dev = fh->dev;
  1282. if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV))
  1283. return -EINVAL;
  1284. if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO))
  1285. return -EINVAL;
  1286. return
  1287. cx23885_set_freq(dev, f);
  1288. }
  1289. /* ----------------------------------------------------------- */
  1290. static void cx23885_vid_timeout(unsigned long data)
  1291. {
  1292. struct cx23885_dev *dev = (struct cx23885_dev *)data;
  1293. struct cx23885_dmaqueue *q = &dev->vidq;
  1294. struct cx23885_buffer *buf;
  1295. unsigned long flags;
  1296. spin_lock_irqsave(&dev->slock, flags);
  1297. while (!list_empty(&q->active)) {
  1298. buf = list_entry(q->active.next,
  1299. struct cx23885_buffer, vb.queue);
  1300. list_del(&buf->vb.queue);
  1301. buf->vb.state = VIDEOBUF_ERROR;
  1302. wake_up(&buf->vb.done);
  1303. printk(KERN_ERR "%s: [%p/%d] timeout - dma=0x%08lx\n",
  1304. dev->name, buf, buf->vb.i,
  1305. (unsigned long)buf->risc.dma);
  1306. }
  1307. cx23885_restart_video_queue(dev, q);
  1308. spin_unlock_irqrestore(&dev->slock, flags);
  1309. }
  1310. int cx23885_video_irq(struct cx23885_dev *dev, u32 status)
  1311. {
  1312. u32 mask, count;
  1313. int handled = 0;
  1314. mask = cx_read(VID_A_INT_MSK);
  1315. if (0 == (status & mask))
  1316. return handled;
  1317. cx_write(VID_A_INT_STAT, status);
  1318. /* risc op code error, fifo overflow or line sync detection error */
  1319. if ((status & VID_BC_MSK_OPC_ERR) ||
  1320. (status & VID_BC_MSK_SYNC) ||
  1321. (status & VID_BC_MSK_OF)) {
  1322. if (status & VID_BC_MSK_OPC_ERR) {
  1323. dprintk(7, " (VID_BC_MSK_OPC_ERR 0x%08x)\n",
  1324. VID_BC_MSK_OPC_ERR);
  1325. printk(KERN_WARNING "%s: video risc op code error\n",
  1326. dev->name);
  1327. cx23885_sram_channel_dump(dev,
  1328. &dev->sram_channels[SRAM_CH01]);
  1329. }
  1330. if (status & VID_BC_MSK_SYNC)
  1331. dprintk(7, " (VID_BC_MSK_SYNC 0x%08x) "
  1332. "video lines miss-match\n",
  1333. VID_BC_MSK_SYNC);
  1334. if (status & VID_BC_MSK_OF)
  1335. dprintk(7, " (VID_BC_MSK_OF 0x%08x) fifo overflow\n",
  1336. VID_BC_MSK_OF);
  1337. }
  1338. /* Video */
  1339. if (status & VID_BC_MSK_RISCI1) {
  1340. spin_lock(&dev->slock);
  1341. count = cx_read(VID_A_GPCNT);
  1342. cx23885_video_wakeup(dev, &dev->vidq, count);
  1343. spin_unlock(&dev->slock);
  1344. handled++;
  1345. }
  1346. if (status & VID_BC_MSK_RISCI2) {
  1347. dprintk(2, "stopper video\n");
  1348. spin_lock(&dev->slock);
  1349. cx23885_restart_video_queue(dev, &dev->vidq);
  1350. spin_unlock(&dev->slock);
  1351. handled++;
  1352. }
  1353. /* Allow the VBI framework to process it's payload */
  1354. handled += cx23885_vbi_irq(dev, status);
  1355. return handled;
  1356. }
  1357. /* ----------------------------------------------------------- */
  1358. /* exported stuff */
  1359. static const struct v4l2_file_operations video_fops = {
  1360. .owner = THIS_MODULE,
  1361. .open = video_open,
  1362. .release = video_release,
  1363. .read = video_read,
  1364. .poll = video_poll,
  1365. .mmap = video_mmap,
  1366. .ioctl = video_ioctl2,
  1367. };
  1368. static const struct v4l2_ioctl_ops video_ioctl_ops = {
  1369. .vidioc_querycap = vidioc_querycap,
  1370. .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  1371. .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  1372. .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  1373. .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  1374. .vidioc_g_fmt_vbi_cap = cx23885_vbi_fmt,
  1375. .vidioc_try_fmt_vbi_cap = cx23885_vbi_fmt,
  1376. .vidioc_s_fmt_vbi_cap = cx23885_vbi_fmt,
  1377. .vidioc_reqbufs = vidioc_reqbufs,
  1378. .vidioc_querybuf = vidioc_querybuf,
  1379. .vidioc_qbuf = vidioc_qbuf,
  1380. .vidioc_dqbuf = vidioc_dqbuf,
  1381. .vidioc_s_std = vidioc_s_std,
  1382. .vidioc_enum_input = vidioc_enum_input,
  1383. .vidioc_g_input = vidioc_g_input,
  1384. .vidioc_s_input = vidioc_s_input,
  1385. .vidioc_log_status = vidioc_log_status,
  1386. .vidioc_queryctrl = vidioc_queryctrl,
  1387. .vidioc_g_ctrl = vidioc_g_ctrl,
  1388. .vidioc_s_ctrl = vidioc_s_ctrl,
  1389. .vidioc_streamon = vidioc_streamon,
  1390. .vidioc_streamoff = vidioc_streamoff,
  1391. .vidioc_g_tuner = vidioc_g_tuner,
  1392. .vidioc_s_tuner = vidioc_s_tuner,
  1393. .vidioc_g_frequency = vidioc_g_frequency,
  1394. .vidioc_s_frequency = vidioc_s_frequency,
  1395. .vidioc_g_chip_ident = cx23885_g_chip_ident,
  1396. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1397. .vidioc_g_register = cx23885_g_register,
  1398. .vidioc_s_register = cx23885_s_register,
  1399. #endif
  1400. .vidioc_enumaudio = vidioc_enum_audinput,
  1401. .vidioc_g_audio = vidioc_g_audinput,
  1402. .vidioc_s_audio = vidioc_s_audinput,
  1403. };
  1404. static struct video_device cx23885_vbi_template;
  1405. static struct video_device cx23885_video_template = {
  1406. .name = "cx23885-video",
  1407. .fops = &video_fops,
  1408. .ioctl_ops = &video_ioctl_ops,
  1409. .tvnorms = CX23885_NORMS,
  1410. .current_norm = V4L2_STD_NTSC_M,
  1411. };
  1412. static const struct v4l2_file_operations radio_fops = {
  1413. .owner = THIS_MODULE,
  1414. .open = video_open,
  1415. .release = video_release,
  1416. .ioctl = video_ioctl2,
  1417. };
  1418. void cx23885_video_unregister(struct cx23885_dev *dev)
  1419. {
  1420. dprintk(1, "%s()\n", __func__);
  1421. cx23885_irq_remove(dev, 0x01);
  1422. if (dev->vbi_dev) {
  1423. if (video_is_registered(dev->vbi_dev))
  1424. video_unregister_device(dev->vbi_dev);
  1425. else
  1426. video_device_release(dev->vbi_dev);
  1427. dev->vbi_dev = NULL;
  1428. btcx_riscmem_free(dev->pci, &dev->vbiq.stopper);
  1429. }
  1430. if (dev->video_dev) {
  1431. if (video_is_registered(dev->video_dev))
  1432. video_unregister_device(dev->video_dev);
  1433. else
  1434. video_device_release(dev->video_dev);
  1435. dev->video_dev = NULL;
  1436. btcx_riscmem_free(dev->pci, &dev->vidq.stopper);
  1437. }
  1438. if (dev->audio_dev)
  1439. cx23885_audio_unregister(dev);
  1440. }
  1441. int cx23885_video_register(struct cx23885_dev *dev)
  1442. {
  1443. int err;
  1444. dprintk(1, "%s()\n", __func__);
  1445. spin_lock_init(&dev->slock);
  1446. /* Initialize VBI template */
  1447. memcpy(&cx23885_vbi_template, &cx23885_video_template,
  1448. sizeof(cx23885_vbi_template));
  1449. strcpy(cx23885_vbi_template.name, "cx23885-vbi");
  1450. dev->tvnorm = cx23885_video_template.current_norm;
  1451. /* init video dma queues */
  1452. INIT_LIST_HEAD(&dev->vidq.active);
  1453. INIT_LIST_HEAD(&dev->vidq.queued);
  1454. dev->vidq.timeout.function = cx23885_vid_timeout;
  1455. dev->vidq.timeout.data = (unsigned long)dev;
  1456. init_timer(&dev->vidq.timeout);
  1457. cx23885_risc_stopper(dev->pci, &dev->vidq.stopper,
  1458. VID_A_DMA_CTL, 0x11, 0x00);
  1459. /* init vbi dma queues */
  1460. INIT_LIST_HEAD(&dev->vbiq.active);
  1461. INIT_LIST_HEAD(&dev->vbiq.queued);
  1462. dev->vbiq.timeout.function = cx23885_vbi_timeout;
  1463. dev->vbiq.timeout.data = (unsigned long)dev;
  1464. init_timer(&dev->vbiq.timeout);
  1465. cx23885_risc_stopper(dev->pci, &dev->vbiq.stopper,
  1466. VID_A_DMA_CTL, 0x22, 0x00);
  1467. cx23885_irq_add_enable(dev, 0x01);
  1468. if ((TUNER_ABSENT != dev->tuner_type) &&
  1469. ((dev->tuner_bus == 0) || (dev->tuner_bus == 1))) {
  1470. struct v4l2_subdev *sd = NULL;
  1471. if (dev->tuner_addr)
  1472. sd = v4l2_i2c_new_subdev(&dev->v4l2_dev,
  1473. &dev->i2c_bus[dev->tuner_bus].i2c_adap,
  1474. "tuner", dev->tuner_addr, NULL);
  1475. else
  1476. sd = v4l2_i2c_new_subdev(&dev->v4l2_dev,
  1477. &dev->i2c_bus[dev->tuner_bus].i2c_adap,
  1478. "tuner", 0, v4l2_i2c_tuner_addrs(ADDRS_TV));
  1479. if (sd) {
  1480. struct tuner_setup tun_setup;
  1481. memset(&tun_setup, 0, sizeof(tun_setup));
  1482. tun_setup.mode_mask = T_ANALOG_TV;
  1483. tun_setup.type = dev->tuner_type;
  1484. tun_setup.addr = v4l2_i2c_subdev_addr(sd);
  1485. tun_setup.tuner_callback = cx23885_tuner_callback;
  1486. v4l2_subdev_call(sd, tuner, s_type_addr, &tun_setup);
  1487. if (dev->board == CX23885_BOARD_LEADTEK_WINFAST_PXTV1200) {
  1488. struct xc2028_ctrl ctrl = {
  1489. .fname = XC2028_DEFAULT_FIRMWARE,
  1490. .max_len = 64
  1491. };
  1492. struct v4l2_priv_tun_config cfg = {
  1493. .tuner = dev->tuner_type,
  1494. .priv = &ctrl
  1495. };
  1496. v4l2_subdev_call(sd, tuner, s_config, &cfg);
  1497. }
  1498. }
  1499. }
  1500. /* register Video device */
  1501. dev->video_dev = cx23885_vdev_init(dev, dev->pci,
  1502. &cx23885_video_template, "video");
  1503. err = video_register_device(dev->video_dev, VFL_TYPE_GRABBER,
  1504. video_nr[dev->nr]);
  1505. if (err < 0) {
  1506. printk(KERN_INFO "%s: can't register video device\n",
  1507. dev->name);
  1508. goto fail_unreg;
  1509. }
  1510. printk(KERN_INFO "%s: registered device %s [v4l2]\n",
  1511. dev->name, video_device_node_name(dev->video_dev));
  1512. /* register VBI device */
  1513. dev->vbi_dev = cx23885_vdev_init(dev, dev->pci,
  1514. &cx23885_vbi_template, "vbi");
  1515. err = video_register_device(dev->vbi_dev, VFL_TYPE_VBI,
  1516. vbi_nr[dev->nr]);
  1517. if (err < 0) {
  1518. printk(KERN_INFO "%s: can't register vbi device\n",
  1519. dev->name);
  1520. goto fail_unreg;
  1521. }
  1522. printk(KERN_INFO "%s: registered device %s\n",
  1523. dev->name, video_device_node_name(dev->vbi_dev));
  1524. /* Register ALSA audio device */
  1525. dev->audio_dev = cx23885_audio_register(dev);
  1526. /* initial device configuration */
  1527. mutex_lock(&dev->lock);
  1528. cx23885_set_tvnorm(dev, dev->tvnorm);
  1529. init_controls(dev);
  1530. cx23885_video_mux(dev, 0);
  1531. cx23885_audio_mux(dev, 0);
  1532. mutex_unlock(&dev->lock);
  1533. return 0;
  1534. fail_unreg:
  1535. cx23885_video_unregister(dev);
  1536. return err;
  1537. }