cx88-blackbird.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  1. /*
  2. *
  3. * Support for a cx23416 mpeg encoder via cx2388x host port.
  4. * "blackbird" reference design.
  5. *
  6. * (c) 2004 Jelle Foks <jelle@foks.8m.com>
  7. * (c) 2004 Gerd Knorr <kraxel@bytesex.org>
  8. *
  9. * Includes parts from the ivtv driver( http://ivtv.sourceforge.net/),
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. #include <linux/module.h>
  26. #include <linux/moduleparam.h>
  27. #include <linux/init.h>
  28. #include <linux/fs.h>
  29. #include <linux/delay.h>
  30. #include <linux/device.h>
  31. #include <linux/firmware.h>
  32. #include <media/v4l2-common.h>
  33. #include <media/cx2341x.h>
  34. #include "cx88.h"
  35. MODULE_DESCRIPTION("driver for cx2388x/cx23416 based mpeg encoder cards");
  36. MODULE_AUTHOR("Jelle Foks <jelle@foks.8m.com>, Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
  37. MODULE_LICENSE("GPL");
  38. static unsigned int mpegbufs = 32;
  39. module_param(mpegbufs,int,0644);
  40. MODULE_PARM_DESC(mpegbufs,"number of mpeg buffers, range 2-32");
  41. static unsigned int debug = 0;
  42. module_param(debug,int,0644);
  43. MODULE_PARM_DESC(debug,"enable debug messages [blackbird]");
  44. #define dprintk(level,fmt, arg...) if (debug >= level) \
  45. printk(KERN_DEBUG "%s/2-bb: " fmt, dev->core->name , ## arg)
  46. static LIST_HEAD(cx8802_devlist);
  47. /* ------------------------------------------------------------------ */
  48. #define BLACKBIRD_FIRM_IMAGE_SIZE 256*1024
  49. /* defines below are from ivtv-driver.h */
  50. #define IVTV_CMD_HW_BLOCKS_RST 0xFFFFFFFF
  51. /* Firmware API commands */
  52. #define IVTV_API_STD_TIMEOUT 500
  53. enum blackbird_capture_type {
  54. BLACKBIRD_MPEG_CAPTURE,
  55. BLACKBIRD_RAW_CAPTURE,
  56. BLACKBIRD_RAW_PASSTHRU_CAPTURE
  57. };
  58. enum blackbird_capture_bits {
  59. BLACKBIRD_RAW_BITS_NONE = 0x00,
  60. BLACKBIRD_RAW_BITS_YUV_CAPTURE = 0x01,
  61. BLACKBIRD_RAW_BITS_PCM_CAPTURE = 0x02,
  62. BLACKBIRD_RAW_BITS_VBI_CAPTURE = 0x04,
  63. BLACKBIRD_RAW_BITS_PASSTHRU_CAPTURE = 0x08,
  64. BLACKBIRD_RAW_BITS_TO_HOST_CAPTURE = 0x10
  65. };
  66. enum blackbird_capture_end {
  67. BLACKBIRD_END_AT_GOP, /* stop at the end of gop, generate irq */
  68. BLACKBIRD_END_NOW, /* stop immediately, no irq */
  69. };
  70. enum blackbird_framerate {
  71. BLACKBIRD_FRAMERATE_NTSC_30, /* NTSC: 30fps */
  72. BLACKBIRD_FRAMERATE_PAL_25 /* PAL: 25fps */
  73. };
  74. enum blackbird_stream_port {
  75. BLACKBIRD_OUTPUT_PORT_MEMORY,
  76. BLACKBIRD_OUTPUT_PORT_STREAMING,
  77. BLACKBIRD_OUTPUT_PORT_SERIAL
  78. };
  79. enum blackbird_data_xfer_status {
  80. BLACKBIRD_MORE_BUFFERS_FOLLOW,
  81. BLACKBIRD_LAST_BUFFER,
  82. };
  83. enum blackbird_picture_mask {
  84. BLACKBIRD_PICTURE_MASK_NONE,
  85. BLACKBIRD_PICTURE_MASK_I_FRAMES,
  86. BLACKBIRD_PICTURE_MASK_I_P_FRAMES = 0x3,
  87. BLACKBIRD_PICTURE_MASK_ALL_FRAMES = 0x7,
  88. };
  89. enum blackbird_vbi_mode_bits {
  90. BLACKBIRD_VBI_BITS_SLICED,
  91. BLACKBIRD_VBI_BITS_RAW,
  92. };
  93. enum blackbird_vbi_insertion_bits {
  94. BLACKBIRD_VBI_BITS_INSERT_IN_XTENSION_USR_DATA,
  95. BLACKBIRD_VBI_BITS_INSERT_IN_PRIVATE_PACKETS = 0x1 << 1,
  96. BLACKBIRD_VBI_BITS_SEPARATE_STREAM = 0x2 << 1,
  97. BLACKBIRD_VBI_BITS_SEPARATE_STREAM_USR_DATA = 0x4 << 1,
  98. BLACKBIRD_VBI_BITS_SEPARATE_STREAM_PRV_DATA = 0x5 << 1,
  99. };
  100. enum blackbird_dma_unit {
  101. BLACKBIRD_DMA_BYTES,
  102. BLACKBIRD_DMA_FRAMES,
  103. };
  104. enum blackbird_dma_transfer_status_bits {
  105. BLACKBIRD_DMA_TRANSFER_BITS_DONE = 0x01,
  106. BLACKBIRD_DMA_TRANSFER_BITS_ERROR = 0x04,
  107. BLACKBIRD_DMA_TRANSFER_BITS_LL_ERROR = 0x10,
  108. };
  109. enum blackbird_pause {
  110. BLACKBIRD_PAUSE_ENCODING,
  111. BLACKBIRD_RESUME_ENCODING,
  112. };
  113. enum blackbird_copyright {
  114. BLACKBIRD_COPYRIGHT_OFF,
  115. BLACKBIRD_COPYRIGHT_ON,
  116. };
  117. enum blackbird_notification_type {
  118. BLACKBIRD_NOTIFICATION_REFRESH,
  119. };
  120. enum blackbird_notification_status {
  121. BLACKBIRD_NOTIFICATION_OFF,
  122. BLACKBIRD_NOTIFICATION_ON,
  123. };
  124. enum blackbird_notification_mailbox {
  125. BLACKBIRD_NOTIFICATION_NO_MAILBOX = -1,
  126. };
  127. enum blackbird_field1_lines {
  128. BLACKBIRD_FIELD1_SAA7114 = 0x00EF, /* 239 */
  129. BLACKBIRD_FIELD1_SAA7115 = 0x00F0, /* 240 */
  130. BLACKBIRD_FIELD1_MICRONAS = 0x0105, /* 261 */
  131. };
  132. enum blackbird_field2_lines {
  133. BLACKBIRD_FIELD2_SAA7114 = 0x00EF, /* 239 */
  134. BLACKBIRD_FIELD2_SAA7115 = 0x00F0, /* 240 */
  135. BLACKBIRD_FIELD2_MICRONAS = 0x0106, /* 262 */
  136. };
  137. enum blackbird_custom_data_type {
  138. BLACKBIRD_CUSTOM_EXTENSION_USR_DATA,
  139. BLACKBIRD_CUSTOM_PRIVATE_PACKET,
  140. };
  141. enum blackbird_mute {
  142. BLACKBIRD_UNMUTE,
  143. BLACKBIRD_MUTE,
  144. };
  145. enum blackbird_mute_video_mask {
  146. BLACKBIRD_MUTE_VIDEO_V_MASK = 0x0000FF00,
  147. BLACKBIRD_MUTE_VIDEO_U_MASK = 0x00FF0000,
  148. BLACKBIRD_MUTE_VIDEO_Y_MASK = 0xFF000000,
  149. };
  150. enum blackbird_mute_video_shift {
  151. BLACKBIRD_MUTE_VIDEO_V_SHIFT = 8,
  152. BLACKBIRD_MUTE_VIDEO_U_SHIFT = 16,
  153. BLACKBIRD_MUTE_VIDEO_Y_SHIFT = 24,
  154. };
  155. /* Registers */
  156. #define IVTV_REG_ENC_SDRAM_REFRESH (0x07F8 /*| IVTV_REG_OFFSET*/)
  157. #define IVTV_REG_ENC_SDRAM_PRECHARGE (0x07FC /*| IVTV_REG_OFFSET*/)
  158. #define IVTV_REG_SPU (0x9050 /*| IVTV_REG_OFFSET*/)
  159. #define IVTV_REG_HW_BLOCKS (0x9054 /*| IVTV_REG_OFFSET*/)
  160. #define IVTV_REG_VPU (0x9058 /*| IVTV_REG_OFFSET*/)
  161. #define IVTV_REG_APU (0xA064 /*| IVTV_REG_OFFSET*/)
  162. /* ------------------------------------------------------------------ */
  163. static void host_setup(struct cx88_core *core)
  164. {
  165. /* toggle reset of the host */
  166. cx_write(MO_GPHST_SOFT_RST, 1);
  167. udelay(100);
  168. cx_write(MO_GPHST_SOFT_RST, 0);
  169. udelay(100);
  170. /* host port setup */
  171. cx_write(MO_GPHST_WSC, 0x44444444U);
  172. cx_write(MO_GPHST_XFR, 0);
  173. cx_write(MO_GPHST_WDTH, 15);
  174. cx_write(MO_GPHST_HDSHK, 0);
  175. cx_write(MO_GPHST_MUX16, 0x44448888U);
  176. cx_write(MO_GPHST_MODE, 0);
  177. }
  178. /* ------------------------------------------------------------------ */
  179. #define P1_MDATA0 0x390000
  180. #define P1_MDATA1 0x390001
  181. #define P1_MDATA2 0x390002
  182. #define P1_MDATA3 0x390003
  183. #define P1_MADDR2 0x390004
  184. #define P1_MADDR1 0x390005
  185. #define P1_MADDR0 0x390006
  186. #define P1_RDATA0 0x390008
  187. #define P1_RDATA1 0x390009
  188. #define P1_RDATA2 0x39000A
  189. #define P1_RDATA3 0x39000B
  190. #define P1_RADDR0 0x39000C
  191. #define P1_RADDR1 0x39000D
  192. #define P1_RRDWR 0x39000E
  193. static int wait_ready_gpio0_bit1(struct cx88_core *core, u32 state)
  194. {
  195. unsigned long timeout = jiffies + msecs_to_jiffies(1);
  196. u32 gpio0,need;
  197. need = state ? 2 : 0;
  198. for (;;) {
  199. gpio0 = cx_read(MO_GP0_IO) & 2;
  200. if (need == gpio0)
  201. return 0;
  202. if (time_after(jiffies,timeout))
  203. return -1;
  204. udelay(1);
  205. }
  206. }
  207. static int memory_write(struct cx88_core *core, u32 address, u32 value)
  208. {
  209. /* Warning: address is dword address (4 bytes) */
  210. cx_writeb(P1_MDATA0, (unsigned int)value);
  211. cx_writeb(P1_MDATA1, (unsigned int)(value >> 8));
  212. cx_writeb(P1_MDATA2, (unsigned int)(value >> 16));
  213. cx_writeb(P1_MDATA3, (unsigned int)(value >> 24));
  214. cx_writeb(P1_MADDR2, (unsigned int)(address >> 16) | 0x40);
  215. cx_writeb(P1_MADDR1, (unsigned int)(address >> 8));
  216. cx_writeb(P1_MADDR0, (unsigned int)address);
  217. cx_read(P1_MDATA0);
  218. cx_read(P1_MADDR0);
  219. return wait_ready_gpio0_bit1(core,1);
  220. }
  221. static int memory_read(struct cx88_core *core, u32 address, u32 *value)
  222. {
  223. int retval;
  224. u32 val;
  225. /* Warning: address is dword address (4 bytes) */
  226. cx_writeb(P1_MADDR2, (unsigned int)(address >> 16) & ~0xC0);
  227. cx_writeb(P1_MADDR1, (unsigned int)(address >> 8));
  228. cx_writeb(P1_MADDR0, (unsigned int)address);
  229. cx_read(P1_MADDR0);
  230. retval = wait_ready_gpio0_bit1(core,1);
  231. cx_writeb(P1_MDATA3, 0);
  232. val = (unsigned char)cx_read(P1_MDATA3) << 24;
  233. cx_writeb(P1_MDATA2, 0);
  234. val |= (unsigned char)cx_read(P1_MDATA2) << 16;
  235. cx_writeb(P1_MDATA1, 0);
  236. val |= (unsigned char)cx_read(P1_MDATA1) << 8;
  237. cx_writeb(P1_MDATA0, 0);
  238. val |= (unsigned char)cx_read(P1_MDATA0);
  239. *value = val;
  240. return retval;
  241. }
  242. static int register_write(struct cx88_core *core, u32 address, u32 value)
  243. {
  244. cx_writeb(P1_RDATA0, (unsigned int)value);
  245. cx_writeb(P1_RDATA1, (unsigned int)(value >> 8));
  246. cx_writeb(P1_RDATA2, (unsigned int)(value >> 16));
  247. cx_writeb(P1_RDATA3, (unsigned int)(value >> 24));
  248. cx_writeb(P1_RADDR0, (unsigned int)address);
  249. cx_writeb(P1_RADDR1, (unsigned int)(address >> 8));
  250. cx_writeb(P1_RRDWR, 1);
  251. cx_read(P1_RDATA0);
  252. cx_read(P1_RADDR0);
  253. return wait_ready_gpio0_bit1(core,1);
  254. }
  255. static int register_read(struct cx88_core *core, u32 address, u32 *value)
  256. {
  257. int retval;
  258. u32 val;
  259. cx_writeb(P1_RADDR0, (unsigned int)address);
  260. cx_writeb(P1_RADDR1, (unsigned int)(address >> 8));
  261. cx_writeb(P1_RRDWR, 0);
  262. cx_read(P1_RADDR0);
  263. retval = wait_ready_gpio0_bit1(core,1);
  264. val = (unsigned char)cx_read(P1_RDATA0);
  265. val |= (unsigned char)cx_read(P1_RDATA1) << 8;
  266. val |= (unsigned char)cx_read(P1_RDATA2) << 16;
  267. val |= (unsigned char)cx_read(P1_RDATA3) << 24;
  268. *value = val;
  269. return retval;
  270. }
  271. /* ------------------------------------------------------------------ */
  272. static int blackbird_mbox_func(void *priv, int command, int in, int out, u32 data[CX2341X_MBOX_MAX_DATA])
  273. {
  274. struct cx8802_dev *dev = priv;
  275. unsigned long timeout;
  276. u32 value, flag, retval;
  277. int i;
  278. dprintk(1,"%s: 0x%X\n", __FUNCTION__, command);
  279. /* this may not be 100% safe if we can't read any memory location
  280. without side effects */
  281. memory_read(dev->core, dev->mailbox - 4, &value);
  282. if (value != 0x12345678) {
  283. dprintk(0, "Firmware and/or mailbox pointer not initialized or corrupted\n");
  284. return -1;
  285. }
  286. memory_read(dev->core, dev->mailbox, &flag);
  287. if (flag) {
  288. dprintk(0, "ERROR: Mailbox appears to be in use (%x)\n", flag);
  289. return -1;
  290. }
  291. flag |= 1; /* tell 'em we're working on it */
  292. memory_write(dev->core, dev->mailbox, flag);
  293. /* write command + args + fill remaining with zeros */
  294. memory_write(dev->core, dev->mailbox + 1, command); /* command code */
  295. memory_write(dev->core, dev->mailbox + 3, IVTV_API_STD_TIMEOUT); /* timeout */
  296. for (i = 0; i < in; i++) {
  297. memory_write(dev->core, dev->mailbox + 4 + i, data[i]);
  298. dprintk(1, "API Input %d = %d\n", i, data[i]);
  299. }
  300. for (; i < CX2341X_MBOX_MAX_DATA; i++)
  301. memory_write(dev->core, dev->mailbox + 4 + i, 0);
  302. flag |= 3; /* tell 'em we're done writing */
  303. memory_write(dev->core, dev->mailbox, flag);
  304. /* wait for firmware to handle the API command */
  305. timeout = jiffies + msecs_to_jiffies(10);
  306. for (;;) {
  307. memory_read(dev->core, dev->mailbox, &flag);
  308. if (0 != (flag & 4))
  309. break;
  310. if (time_after(jiffies,timeout)) {
  311. dprintk(0, "ERROR: API Mailbox timeout\n");
  312. return -1;
  313. }
  314. udelay(10);
  315. }
  316. /* read output values */
  317. for (i = 0; i < out; i++) {
  318. memory_read(dev->core, dev->mailbox + 4 + i, data + i);
  319. dprintk(1, "API Output %d = %d\n", i, data[i]);
  320. }
  321. memory_read(dev->core, dev->mailbox + 2, &retval);
  322. dprintk(1, "API result = %d\n",retval);
  323. flag = 0;
  324. memory_write(dev->core, dev->mailbox, flag);
  325. return retval;
  326. }
  327. /* ------------------------------------------------------------------ */
  328. /* We don't need to call the API often, so using just one mailbox will probably suffice */
  329. static int blackbird_api_cmd(struct cx8802_dev *dev, u32 command,
  330. u32 inputcnt, u32 outputcnt, ...)
  331. {
  332. u32 data[CX2341X_MBOX_MAX_DATA];
  333. va_list vargs;
  334. int i, err;
  335. va_start(vargs, outputcnt);
  336. for (i = 0; i < inputcnt; i++) {
  337. data[i] = va_arg(vargs, int);
  338. }
  339. err = blackbird_mbox_func(dev, command, inputcnt, outputcnt, data);
  340. for (i = 0; i < outputcnt; i++) {
  341. int *vptr = va_arg(vargs, int *);
  342. *vptr = data[i];
  343. }
  344. va_end(vargs);
  345. return err;
  346. }
  347. static int blackbird_find_mailbox(struct cx8802_dev *dev)
  348. {
  349. u32 signature[4]={0x12345678, 0x34567812, 0x56781234, 0x78123456};
  350. int signaturecnt=0;
  351. u32 value;
  352. int i;
  353. for (i = 0; i < BLACKBIRD_FIRM_IMAGE_SIZE; i++) {
  354. memory_read(dev->core, i, &value);
  355. if (value == signature[signaturecnt])
  356. signaturecnt++;
  357. else
  358. signaturecnt = 0;
  359. if (4 == signaturecnt) {
  360. dprintk(1, "Mailbox signature found\n");
  361. return i+1;
  362. }
  363. }
  364. dprintk(0, "Mailbox signature values not found!\n");
  365. return -1;
  366. }
  367. static int blackbird_load_firmware(struct cx8802_dev *dev)
  368. {
  369. static const unsigned char magic[8] = {
  370. 0xa7, 0x0d, 0x00, 0x00, 0x66, 0xbb, 0x55, 0xaa
  371. };
  372. const struct firmware *firmware;
  373. int i, retval = 0;
  374. u32 value = 0;
  375. u32 checksum = 0;
  376. u32 *dataptr;
  377. retval = register_write(dev->core, IVTV_REG_VPU, 0xFFFFFFED);
  378. retval |= register_write(dev->core, IVTV_REG_HW_BLOCKS, IVTV_CMD_HW_BLOCKS_RST);
  379. retval |= register_write(dev->core, IVTV_REG_ENC_SDRAM_REFRESH, 0x80000640);
  380. retval |= register_write(dev->core, IVTV_REG_ENC_SDRAM_PRECHARGE, 0x1A);
  381. msleep(1);
  382. retval |= register_write(dev->core, IVTV_REG_APU, 0);
  383. if (retval < 0)
  384. dprintk(0, "Error with register_write\n");
  385. retval = request_firmware(&firmware, CX2341X_FIRM_ENC_FILENAME,
  386. &dev->pci->dev);
  387. if (retval != 0) {
  388. dprintk(0, "ERROR: Hotplug firmware request failed (%s).\n",
  389. CX2341X_FIRM_ENC_FILENAME);
  390. dprintk(0, "Please fix your hotplug setup, the board will "
  391. "not work without firmware loaded!\n");
  392. return -1;
  393. }
  394. if (firmware->size != BLACKBIRD_FIRM_IMAGE_SIZE) {
  395. dprintk(0, "ERROR: Firmware size mismatch (have %zd, expected %d)\n",
  396. firmware->size, BLACKBIRD_FIRM_IMAGE_SIZE);
  397. return -1;
  398. }
  399. if (0 != memcmp(firmware->data, magic, 8)) {
  400. dprintk(0, "ERROR: Firmware magic mismatch, wrong file?\n");
  401. return -1;
  402. }
  403. /* transfer to the chip */
  404. dprintk(1,"Loading firmware ...\n");
  405. dataptr = (u32*)firmware->data;
  406. for (i = 0; i < (firmware->size >> 2); i++) {
  407. value = *dataptr;
  408. checksum += ~value;
  409. memory_write(dev->core, i, value);
  410. dataptr++;
  411. }
  412. /* read back to verify with the checksum */
  413. for (i--; i >= 0; i--) {
  414. memory_read(dev->core, i, &value);
  415. checksum -= ~value;
  416. }
  417. if (checksum) {
  418. dprintk(0, "ERROR: Firmware load failed (checksum mismatch).\n");
  419. return -1;
  420. }
  421. release_firmware(firmware);
  422. dprintk(0, "Firmware upload successful.\n");
  423. retval |= register_write(dev->core, IVTV_REG_HW_BLOCKS, IVTV_CMD_HW_BLOCKS_RST);
  424. retval |= register_read(dev->core, IVTV_REG_SPU, &value);
  425. retval |= register_write(dev->core, IVTV_REG_SPU, value & 0xFFFFFFFE);
  426. msleep(1);
  427. retval |= register_read(dev->core, IVTV_REG_VPU, &value);
  428. retval |= register_write(dev->core, IVTV_REG_VPU, value & 0xFFFFFFE8);
  429. if (retval < 0)
  430. dprintk(0, "Error with register_write\n");
  431. return 0;
  432. }
  433. /**
  434. Settings used by the windows tv app for PVR2000:
  435. =================================================================================================================
  436. Profile | Codec | Resolution | CBR/VBR | Video Qlty | V. Bitrate | Frmrate | Audio Codec | A. Bitrate | A. Mode
  437. -----------------------------------------------------------------------------------------------------------------
  438. MPEG-1 | MPEG1 | 352x288PAL | (CBR) | 1000:Optimal | 2000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
  439. MPEG-2 | MPEG2 | 720x576PAL | VBR | 600 :Good | 4000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
  440. VCD | MPEG1 | 352x288PAL | (CBR) | 1000:Optimal | 1150 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
  441. DVD | MPEG2 | 720x576PAL | VBR | 600 :Good | 6000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
  442. DB* DVD | MPEG2 | 720x576PAL | CBR | 600 :Good | 6000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
  443. =================================================================================================================
  444. *DB: "DirectBurn"
  445. */
  446. static void blackbird_codec_settings(struct cx8802_dev *dev)
  447. {
  448. /* assign frame size */
  449. blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0,
  450. dev->height, dev->width);
  451. dev->params.width = dev->width;
  452. dev->params.height = dev->height;
  453. dev->params.is_50hz = (dev->core->tvnorm->id & V4L2_STD_625_50) != 0;
  454. cx2341x_update(dev, blackbird_mbox_func, NULL, &dev->params);
  455. }
  456. static struct v4l2_mpeg_compression default_mpeg_params = {
  457. .st_type = V4L2_MPEG_PS_2,
  458. .st_bitrate = {
  459. .mode = V4L2_BITRATE_CBR,
  460. .min = 0,
  461. .target = 0,
  462. .max = 0
  463. },
  464. .ts_pid_pmt = 16,
  465. .ts_pid_audio = 260,
  466. .ts_pid_video = 256,
  467. .ts_pid_pcr = 259,
  468. .ps_size = 0,
  469. .au_type = V4L2_MPEG_AU_2_II,
  470. .au_bitrate = {
  471. .mode = V4L2_BITRATE_CBR,
  472. .min = 224,
  473. .target = 224,
  474. .max = 224
  475. },
  476. .au_sample_rate = 48000,
  477. .au_pesid = 0,
  478. .vi_type = V4L2_MPEG_VI_2,
  479. .vi_aspect_ratio = V4L2_MPEG_ASPECT_4_3,
  480. .vi_bitrate = {
  481. .mode = V4L2_BITRATE_CBR,
  482. .min = 4000,
  483. .target = 4500,
  484. .max = 6000
  485. },
  486. .vi_frame_rate = 25,
  487. .vi_frames_per_gop = 12,
  488. .vi_bframes_count = 2,
  489. .vi_pesid = 0,
  490. .closed_gops = 1,
  491. .pulldown = 0
  492. };
  493. static int blackbird_initialize_codec(struct cx8802_dev *dev)
  494. {
  495. struct cx88_core *core = dev->core;
  496. int version;
  497. int retval;
  498. dprintk(1,"Initialize codec\n");
  499. retval = blackbird_api_cmd(dev, CX2341X_ENC_PING_FW, 0, 0); /* ping */
  500. if (retval < 0) {
  501. /* ping was not successful, reset and upload firmware */
  502. cx_write(MO_SRST_IO, 0); /* SYS_RSTO=0 */
  503. msleep(1);
  504. cx_write(MO_SRST_IO, 1); /* SYS_RSTO=1 */
  505. msleep(1);
  506. retval = blackbird_load_firmware(dev);
  507. if (retval < 0)
  508. return retval;
  509. dev->mailbox = blackbird_find_mailbox(dev);
  510. if (dev->mailbox < 0)
  511. return -1;
  512. retval = blackbird_api_cmd(dev, CX2341X_ENC_PING_FW, 0, 0); /* ping */
  513. if (retval < 0) {
  514. dprintk(0, "ERROR: Firmware ping failed!\n");
  515. return -1;
  516. }
  517. retval = blackbird_api_cmd(dev, CX2341X_ENC_GET_VERSION, 0, 1, &version);
  518. if (retval < 0) {
  519. dprintk(0, "ERROR: Firmware get encoder version failed!\n");
  520. return -1;
  521. }
  522. dprintk(0, "Firmware version is 0x%08x\n", version);
  523. }
  524. msleep(1);
  525. cx_write(MO_PINMUX_IO, 0x88); /* 656-8bit IO and enable MPEG parallel IO */
  526. cx_clear(MO_INPUT_FORMAT, 0x100); /* chroma subcarrier lock to normal? */
  527. cx_write(MO_VBOS_CONTROL, 0x84A00); /* no 656 mode, 8-bit pixels, disable VBI */
  528. cx_clear(MO_OUTPUT_FORMAT, 0x0008); /* Normal Y-limits to let the mpeg encoder sync */
  529. blackbird_codec_settings(dev);
  530. msleep(1);
  531. /* blackbird_api_cmd(dev, IVTV_API_ASSIGN_NUM_VSYNC_LINES, 4, 0, 0xef, 0xef);
  532. blackbird_api_cmd(dev, IVTV_API_ASSIGN_NUM_VSYNC_LINES, 4, 0, 0xf0, 0xf0);
  533. blackbird_api_cmd(dev, IVTV_API_ASSIGN_NUM_VSYNC_LINES, 4, 0, 0x180, 0x180); */
  534. blackbird_api_cmd(dev, CX2341X_ENC_SET_NUM_VSYNC_LINES, 2, 0,
  535. BLACKBIRD_FIELD1_SAA7115,
  536. BLACKBIRD_FIELD2_SAA7115
  537. );
  538. /* blackbird_api_cmd(dev, IVTV_API_ASSIGN_PLACEHOLDER, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); */
  539. blackbird_api_cmd(dev, CX2341X_ENC_SET_PLACEHOLDER, 12, 0,
  540. BLACKBIRD_CUSTOM_EXTENSION_USR_DATA,
  541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  542. /* initialize the video input */
  543. blackbird_api_cmd(dev, CX2341X_ENC_INITIALIZE_INPUT, 0, 0);
  544. msleep(1);
  545. blackbird_api_cmd(dev, CX2341X_ENC_MUTE_VIDEO, 1, 0, BLACKBIRD_UNMUTE);
  546. msleep(1);
  547. blackbird_api_cmd(dev, CX2341X_ENC_MUTE_AUDIO, 1, 0, BLACKBIRD_UNMUTE);
  548. msleep(1);
  549. /* start capturing to the host interface */
  550. /* blackbird_api_cmd(dev, CX2341X_ENC_START_CAPTURE, 2, 0, 0, 0x13); */
  551. blackbird_api_cmd(dev, CX2341X_ENC_START_CAPTURE, 2, 0,
  552. BLACKBIRD_MPEG_CAPTURE,
  553. BLACKBIRD_RAW_BITS_NONE
  554. );
  555. msleep(10);
  556. blackbird_api_cmd(dev, CX2341X_ENC_REFRESH_INPUT, 0,0);
  557. return 0;
  558. }
  559. /* ------------------------------------------------------------------ */
  560. static int bb_buf_setup(struct videobuf_queue *q,
  561. unsigned int *count, unsigned int *size)
  562. {
  563. struct cx8802_fh *fh = q->priv_data;
  564. fh->dev->ts_packet_size = 188 * 4; /* was: 512 */
  565. fh->dev->ts_packet_count = mpegbufs; /* was: 100 */
  566. *size = fh->dev->ts_packet_size * fh->dev->ts_packet_count;
  567. *count = fh->dev->ts_packet_count;
  568. return 0;
  569. }
  570. static int
  571. bb_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
  572. enum v4l2_field field)
  573. {
  574. struct cx8802_fh *fh = q->priv_data;
  575. return cx8802_buf_prepare(q, fh->dev, (struct cx88_buffer*)vb, field);
  576. }
  577. static void
  578. bb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
  579. {
  580. struct cx8802_fh *fh = q->priv_data;
  581. cx8802_buf_queue(fh->dev, (struct cx88_buffer*)vb);
  582. }
  583. static void
  584. bb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
  585. {
  586. cx88_free_buffer(q, (struct cx88_buffer*)vb);
  587. }
  588. static struct videobuf_queue_ops blackbird_qops = {
  589. .buf_setup = bb_buf_setup,
  590. .buf_prepare = bb_buf_prepare,
  591. .buf_queue = bb_buf_queue,
  592. .buf_release = bb_buf_release,
  593. };
  594. /* ------------------------------------------------------------------ */
  595. static const u32 *ctrl_classes[] = {
  596. cx88_user_ctrls,
  597. cx2341x_mpeg_ctrls,
  598. NULL
  599. };
  600. static int blackbird_queryctrl(struct cx8802_dev *dev, struct v4l2_queryctrl *qctrl)
  601. {
  602. qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
  603. if (qctrl->id == 0)
  604. return -EINVAL;
  605. /* Standard V4L2 controls */
  606. if (cx8800_ctrl_query(qctrl) == 0)
  607. return 0;
  608. /* MPEG V4L2 controls */
  609. if (cx2341x_ctrl_query(&dev->params, qctrl))
  610. qctrl->flags |= V4L2_CTRL_FLAG_DISABLED;
  611. return 0;
  612. }
  613. static int blackbird_querymenu(struct cx8802_dev *dev, struct v4l2_querymenu *qmenu)
  614. {
  615. struct v4l2_queryctrl qctrl;
  616. qctrl.id = qmenu->id;
  617. blackbird_queryctrl(dev, &qctrl);
  618. return v4l2_ctrl_query_menu(qmenu, &qctrl, cx2341x_ctrl_get_menu(qmenu->id));
  619. }
  620. /* ------------------------------------------------------------------ */
  621. static int mpeg_do_ioctl(struct inode *inode, struct file *file,
  622. unsigned int cmd, void *arg)
  623. {
  624. struct cx8802_fh *fh = file->private_data;
  625. struct cx8802_dev *dev = fh->dev;
  626. struct cx88_core *core = dev->core;
  627. if (debug > 1)
  628. v4l_print_ioctl(core->name,cmd);
  629. switch (cmd) {
  630. /* --- capabilities ------------------------------------------ */
  631. case VIDIOC_QUERYCAP:
  632. {
  633. struct v4l2_capability *cap = arg;
  634. memset(cap,0,sizeof(*cap));
  635. strcpy(cap->driver, "cx88_blackbird");
  636. strlcpy(cap->card, cx88_boards[core->board].name,sizeof(cap->card));
  637. sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
  638. cap->version = CX88_VERSION_CODE;
  639. cap->capabilities =
  640. V4L2_CAP_VIDEO_CAPTURE |
  641. V4L2_CAP_READWRITE |
  642. V4L2_CAP_STREAMING |
  643. 0;
  644. if (UNSET != core->tuner_type)
  645. cap->capabilities |= V4L2_CAP_TUNER;
  646. return 0;
  647. }
  648. /* --- capture ioctls ---------------------------------------- */
  649. case VIDIOC_ENUM_FMT:
  650. {
  651. struct v4l2_fmtdesc *f = arg;
  652. int index;
  653. index = f->index;
  654. if (index != 0)
  655. return -EINVAL;
  656. memset(f,0,sizeof(*f));
  657. f->index = index;
  658. strlcpy(f->description, "MPEG", sizeof(f->description));
  659. f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  660. f->pixelformat = V4L2_PIX_FMT_MPEG;
  661. return 0;
  662. }
  663. case VIDIOC_G_FMT:
  664. {
  665. struct v4l2_format *f = arg;
  666. memset(f,0,sizeof(*f));
  667. f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  668. f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
  669. f->fmt.pix.bytesperline = 0;
  670. f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */
  671. f->fmt.pix.colorspace = 0;
  672. f->fmt.pix.width = dev->width;
  673. f->fmt.pix.height = dev->height;
  674. f->fmt.pix.field = fh->mpegq.field;
  675. dprintk(0,"VIDIOC_G_FMT: w: %d, h: %d, f: %d\n",
  676. dev->width, dev->height, fh->mpegq.field );
  677. return 0;
  678. }
  679. case VIDIOC_TRY_FMT:
  680. {
  681. struct v4l2_format *f = arg;
  682. f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  683. f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
  684. f->fmt.pix.bytesperline = 0;
  685. f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */;
  686. f->fmt.pix.colorspace = 0;
  687. dprintk(0,"VIDIOC_TRY_FMT: w: %d, h: %d, f: %d\n",
  688. dev->width, dev->height, fh->mpegq.field );
  689. return 0;
  690. }
  691. case VIDIOC_S_FMT:
  692. {
  693. struct v4l2_format *f = arg;
  694. f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  695. f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
  696. f->fmt.pix.bytesperline = 0;
  697. f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */;
  698. f->fmt.pix.colorspace = 0;
  699. dprintk(0,"VIDIOC_S_FMT: w: %d, h: %d, f: %d\n",
  700. f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.field );
  701. return 0;
  702. }
  703. /* --- streaming capture ------------------------------------- */
  704. case VIDIOC_REQBUFS:
  705. return videobuf_reqbufs(&fh->mpegq, arg);
  706. case VIDIOC_QUERYBUF:
  707. return videobuf_querybuf(&fh->mpegq, arg);
  708. case VIDIOC_QBUF:
  709. return videobuf_qbuf(&fh->mpegq, arg);
  710. case VIDIOC_DQBUF:
  711. return videobuf_dqbuf(&fh->mpegq, arg,
  712. file->f_flags & O_NONBLOCK);
  713. case VIDIOC_STREAMON:
  714. return videobuf_streamon(&fh->mpegq);
  715. case VIDIOC_STREAMOFF:
  716. return videobuf_streamoff(&fh->mpegq);
  717. /* --- mpeg compression -------------------------------------- */
  718. case VIDIOC_G_MPEGCOMP:
  719. {
  720. struct v4l2_mpeg_compression *f = arg;
  721. printk(KERN_WARNING "VIDIOC_G_MPEGCOMP is obsolete. "
  722. "Replace with VIDIOC_G_EXT_CTRLS!");
  723. memcpy(f,&default_mpeg_params,sizeof(*f));
  724. return 0;
  725. }
  726. case VIDIOC_S_MPEGCOMP:
  727. printk(KERN_WARNING "VIDIOC_S_MPEGCOMP is obsolete. "
  728. "Replace with VIDIOC_S_EXT_CTRLS!");
  729. return 0;
  730. case VIDIOC_G_EXT_CTRLS:
  731. {
  732. struct v4l2_ext_controls *f = arg;
  733. if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
  734. return -EINVAL;
  735. return cx2341x_ext_ctrls(&dev->params, f, cmd);
  736. }
  737. case VIDIOC_S_EXT_CTRLS:
  738. case VIDIOC_TRY_EXT_CTRLS:
  739. {
  740. struct v4l2_ext_controls *f = arg;
  741. struct cx2341x_mpeg_params p;
  742. int err;
  743. if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
  744. return -EINVAL;
  745. p = dev->params;
  746. err = cx2341x_ext_ctrls(&p, f, cmd);
  747. if (err == 0 && cmd == VIDIOC_S_EXT_CTRLS) {
  748. err = cx2341x_update(dev, blackbird_mbox_func, &dev->params, &p);
  749. dev->params = p;
  750. }
  751. return err;
  752. }
  753. case VIDIOC_S_FREQUENCY:
  754. {
  755. blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0,
  756. BLACKBIRD_END_NOW,
  757. BLACKBIRD_MPEG_CAPTURE,
  758. BLACKBIRD_RAW_BITS_NONE);
  759. cx88_do_ioctl(inode, file, 0, dev->core, cmd, arg, mpeg_do_ioctl);
  760. blackbird_initialize_codec(dev);
  761. cx88_set_scale(dev->core, dev->width, dev->height,
  762. fh->mpegq.field);
  763. return 0;
  764. }
  765. case VIDIOC_LOG_STATUS:
  766. {
  767. char name[32 + 2];
  768. snprintf(name, sizeof(name), "%s/2", core->name);
  769. printk("%s/2: ============ START LOG STATUS ============\n",
  770. core->name);
  771. cx88_call_i2c_clients(core, VIDIOC_LOG_STATUS, 0);
  772. cx2341x_log_status(&dev->params, name);
  773. printk("%s/2: ============= END LOG STATUS =============\n",
  774. core->name);
  775. return 0;
  776. }
  777. case VIDIOC_QUERYMENU:
  778. return blackbird_querymenu(dev, arg);
  779. case VIDIOC_QUERYCTRL:
  780. {
  781. struct v4l2_queryctrl *c = arg;
  782. if (blackbird_queryctrl(dev, c) == 0)
  783. return 0;
  784. return cx88_do_ioctl(inode, file, 0, dev->core, cmd, arg, mpeg_do_ioctl);
  785. }
  786. default:
  787. return cx88_do_ioctl(inode, file, 0, dev->core, cmd, arg, mpeg_do_ioctl);
  788. }
  789. return 0;
  790. }
  791. static unsigned int mpeg_translate_ioctl(unsigned int cmd)
  792. {
  793. return cmd;
  794. }
  795. static int mpeg_ioctl(struct inode *inode, struct file *file,
  796. unsigned int cmd, unsigned long arg)
  797. {
  798. cmd = mpeg_translate_ioctl( cmd );
  799. return video_usercopy(inode, file, cmd, arg, mpeg_do_ioctl);
  800. }
  801. static int mpeg_open(struct inode *inode, struct file *file)
  802. {
  803. int minor = iminor(inode);
  804. struct cx8802_dev *h,*dev = NULL;
  805. struct cx8802_fh *fh;
  806. struct list_head *list;
  807. list_for_each(list,&cx8802_devlist) {
  808. h = list_entry(list, struct cx8802_dev, devlist);
  809. if (h->mpeg_dev->minor == minor)
  810. dev = h;
  811. }
  812. if (NULL == dev)
  813. return -ENODEV;
  814. if (blackbird_initialize_codec(dev) < 0)
  815. return -EINVAL;
  816. dprintk(1,"open minor=%d\n",minor);
  817. /* allocate + initialize per filehandle data */
  818. fh = kzalloc(sizeof(*fh),GFP_KERNEL);
  819. if (NULL == fh)
  820. return -ENOMEM;
  821. file->private_data = fh;
  822. fh->dev = dev;
  823. videobuf_queue_init(&fh->mpegq, &blackbird_qops,
  824. dev->pci, &dev->slock,
  825. V4L2_BUF_TYPE_VIDEO_CAPTURE,
  826. V4L2_FIELD_INTERLACED,
  827. sizeof(struct cx88_buffer),
  828. fh);
  829. /* FIXME: locking against other video device */
  830. cx88_set_scale(dev->core, dev->width, dev->height,
  831. fh->mpegq.field);
  832. return 0;
  833. }
  834. static int mpeg_release(struct inode *inode, struct file *file)
  835. {
  836. struct cx8802_fh *fh = file->private_data;
  837. /* blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0, BLACKBIRD_END_NOW, 0, 0x13); */
  838. blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0,
  839. BLACKBIRD_END_NOW,
  840. BLACKBIRD_MPEG_CAPTURE,
  841. BLACKBIRD_RAW_BITS_NONE
  842. );
  843. cx8802_cancel_buffers(fh->dev);
  844. /* stop mpeg capture */
  845. if (fh->mpegq.streaming)
  846. videobuf_streamoff(&fh->mpegq);
  847. if (fh->mpegq.reading)
  848. videobuf_read_stop(&fh->mpegq);
  849. videobuf_mmap_free(&fh->mpegq);
  850. file->private_data = NULL;
  851. kfree(fh);
  852. return 0;
  853. }
  854. static ssize_t
  855. mpeg_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
  856. {
  857. struct cx8802_fh *fh = file->private_data;
  858. return videobuf_read_stream(&fh->mpegq, data, count, ppos, 0,
  859. file->f_flags & O_NONBLOCK);
  860. }
  861. static unsigned int
  862. mpeg_poll(struct file *file, struct poll_table_struct *wait)
  863. {
  864. struct cx8802_fh *fh = file->private_data;
  865. return videobuf_poll_stream(file, &fh->mpegq, wait);
  866. }
  867. static int
  868. mpeg_mmap(struct file *file, struct vm_area_struct * vma)
  869. {
  870. struct cx8802_fh *fh = file->private_data;
  871. return videobuf_mmap_mapper(&fh->mpegq, vma);
  872. }
  873. static struct file_operations mpeg_fops =
  874. {
  875. .owner = THIS_MODULE,
  876. .open = mpeg_open,
  877. .release = mpeg_release,
  878. .read = mpeg_read,
  879. .poll = mpeg_poll,
  880. .mmap = mpeg_mmap,
  881. .ioctl = mpeg_ioctl,
  882. .llseek = no_llseek,
  883. };
  884. static struct video_device cx8802_mpeg_template =
  885. {
  886. .name = "cx8802",
  887. .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_SCALES|VID_TYPE_MPEG_ENCODER,
  888. .hardware = 0,
  889. .fops = &mpeg_fops,
  890. .minor = -1,
  891. };
  892. /* ------------------------------------------------------------------ */
  893. static void blackbird_unregister_video(struct cx8802_dev *dev)
  894. {
  895. if (dev->mpeg_dev) {
  896. if (-1 != dev->mpeg_dev->minor)
  897. video_unregister_device(dev->mpeg_dev);
  898. else
  899. video_device_release(dev->mpeg_dev);
  900. dev->mpeg_dev = NULL;
  901. }
  902. }
  903. static int blackbird_register_video(struct cx8802_dev *dev)
  904. {
  905. int err;
  906. dev->mpeg_dev = cx88_vdev_init(dev->core,dev->pci,
  907. &cx8802_mpeg_template,"mpeg");
  908. err = video_register_device(dev->mpeg_dev,VFL_TYPE_GRABBER, -1);
  909. if (err < 0) {
  910. printk(KERN_INFO "%s/2: can't register mpeg device\n",
  911. dev->core->name);
  912. return err;
  913. }
  914. printk(KERN_INFO "%s/2: registered device video%d [mpeg]\n",
  915. dev->core->name,dev->mpeg_dev->minor & 0x1f);
  916. return 0;
  917. }
  918. /* ----------------------------------------------------------- */
  919. static int __devinit blackbird_probe(struct pci_dev *pci_dev,
  920. const struct pci_device_id *pci_id)
  921. {
  922. struct cx8802_dev *dev;
  923. struct cx88_core *core;
  924. int err;
  925. /* general setup */
  926. core = cx88_core_get(pci_dev);
  927. if (NULL == core)
  928. return -EINVAL;
  929. err = -ENODEV;
  930. if (!cx88_boards[core->board].blackbird)
  931. goto fail_core;
  932. err = -ENOMEM;
  933. dev = kzalloc(sizeof(*dev),GFP_KERNEL);
  934. if (NULL == dev)
  935. goto fail_core;
  936. dev->pci = pci_dev;
  937. dev->core = core;
  938. dev->width = 720;
  939. dev->height = 576;
  940. cx2341x_fill_defaults(&dev->params);
  941. dev->params.port = CX2341X_PORT_STREAMING;
  942. if (core->tvnorm->id & V4L2_STD_525_60) {
  943. dev->height = 480;
  944. } else {
  945. dev->height = 576;
  946. }
  947. err = cx8802_init_common(dev);
  948. if (0 != err)
  949. goto fail_free;
  950. /* blackbird stuff */
  951. printk("%s/2: cx23416 based mpeg encoder (blackbird reference design)\n",
  952. core->name);
  953. host_setup(dev->core);
  954. list_add_tail(&dev->devlist,&cx8802_devlist);
  955. blackbird_register_video(dev);
  956. /* initial device configuration: needed ? */
  957. return 0;
  958. fail_free:
  959. kfree(dev);
  960. fail_core:
  961. cx88_core_put(core,pci_dev);
  962. return err;
  963. }
  964. static void __devexit blackbird_remove(struct pci_dev *pci_dev)
  965. {
  966. struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
  967. /* blackbird */
  968. blackbird_unregister_video(dev);
  969. list_del(&dev->devlist);
  970. /* common */
  971. cx8802_fini_common(dev);
  972. cx88_core_put(dev->core,dev->pci);
  973. kfree(dev);
  974. }
  975. static struct pci_device_id cx8802_pci_tbl[] = {
  976. {
  977. .vendor = 0x14f1,
  978. .device = 0x8802,
  979. .subvendor = PCI_ANY_ID,
  980. .subdevice = PCI_ANY_ID,
  981. },{
  982. /* --- end of list --- */
  983. }
  984. };
  985. MODULE_DEVICE_TABLE(pci, cx8802_pci_tbl);
  986. static struct pci_driver blackbird_pci_driver = {
  987. .name = "cx88-blackbird",
  988. .id_table = cx8802_pci_tbl,
  989. .probe = blackbird_probe,
  990. .remove = __devexit_p(blackbird_remove),
  991. .suspend = cx8802_suspend_common,
  992. .resume = cx8802_resume_common,
  993. };
  994. static int blackbird_init(void)
  995. {
  996. printk(KERN_INFO "cx2388x blackbird driver version %d.%d.%d loaded\n",
  997. (CX88_VERSION_CODE >> 16) & 0xff,
  998. (CX88_VERSION_CODE >> 8) & 0xff,
  999. CX88_VERSION_CODE & 0xff);
  1000. #ifdef SNAPSHOT
  1001. printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
  1002. SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
  1003. #endif
  1004. return pci_register_driver(&blackbird_pci_driver);
  1005. }
  1006. static void blackbird_fini(void)
  1007. {
  1008. pci_unregister_driver(&blackbird_pci_driver);
  1009. }
  1010. module_init(blackbird_init);
  1011. module_exit(blackbird_fini);
  1012. /* ----------------------------------------------------------- */
  1013. /*
  1014. * Local variables:
  1015. * c-basic-offset: 8
  1016. * End:
  1017. * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
  1018. */