cx88-blackbird.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155
  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 int mpeg_do_ioctl(struct inode *inode, struct file *file,
  596. unsigned int cmd, void *arg)
  597. {
  598. struct cx8802_fh *fh = file->private_data;
  599. struct cx8802_dev *dev = fh->dev;
  600. struct cx88_core *core = dev->core;
  601. if (debug > 1)
  602. v4l_print_ioctl(core->name,cmd);
  603. switch (cmd) {
  604. /* --- capabilities ------------------------------------------ */
  605. case VIDIOC_QUERYCAP:
  606. {
  607. struct v4l2_capability *cap = arg;
  608. memset(cap,0,sizeof(*cap));
  609. strcpy(cap->driver, "cx88_blackbird");
  610. strlcpy(cap->card, cx88_boards[core->board].name,sizeof(cap->card));
  611. sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
  612. cap->version = CX88_VERSION_CODE;
  613. cap->capabilities =
  614. V4L2_CAP_VIDEO_CAPTURE |
  615. V4L2_CAP_READWRITE |
  616. V4L2_CAP_STREAMING |
  617. 0;
  618. if (UNSET != core->tuner_type)
  619. cap->capabilities |= V4L2_CAP_TUNER;
  620. return 0;
  621. }
  622. /* --- capture ioctls ---------------------------------------- */
  623. case VIDIOC_ENUM_FMT:
  624. {
  625. struct v4l2_fmtdesc *f = arg;
  626. int index;
  627. index = f->index;
  628. if (index != 0)
  629. return -EINVAL;
  630. memset(f,0,sizeof(*f));
  631. f->index = index;
  632. strlcpy(f->description, "MPEG", sizeof(f->description));
  633. f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  634. f->pixelformat = V4L2_PIX_FMT_MPEG;
  635. return 0;
  636. }
  637. case VIDIOC_G_FMT:
  638. {
  639. struct v4l2_format *f = arg;
  640. memset(f,0,sizeof(*f));
  641. f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  642. f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
  643. f->fmt.pix.bytesperline = 0;
  644. f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */
  645. f->fmt.pix.colorspace = 0;
  646. f->fmt.pix.width = dev->width;
  647. f->fmt.pix.height = dev->height;
  648. f->fmt.pix.field = fh->mpegq.field;
  649. dprintk(0,"VIDIOC_G_FMT: w: %d, h: %d, f: %d\n",
  650. dev->width, dev->height, fh->mpegq.field );
  651. return 0;
  652. }
  653. case VIDIOC_TRY_FMT:
  654. {
  655. struct v4l2_format *f = arg;
  656. f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  657. f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
  658. f->fmt.pix.bytesperline = 0;
  659. f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */;
  660. f->fmt.pix.colorspace = 0;
  661. dprintk(0,"VIDIOC_TRY_FMT: w: %d, h: %d, f: %d\n",
  662. dev->width, dev->height, fh->mpegq.field );
  663. return 0;
  664. }
  665. case VIDIOC_S_FMT:
  666. {
  667. struct v4l2_format *f = arg;
  668. f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  669. f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
  670. f->fmt.pix.bytesperline = 0;
  671. f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */;
  672. f->fmt.pix.colorspace = 0;
  673. dprintk(0,"VIDIOC_S_FMT: w: %d, h: %d, f: %d\n",
  674. f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.field );
  675. return 0;
  676. }
  677. /* --- streaming capture ------------------------------------- */
  678. case VIDIOC_REQBUFS:
  679. return videobuf_reqbufs(&fh->mpegq, arg);
  680. case VIDIOC_QUERYBUF:
  681. return videobuf_querybuf(&fh->mpegq, arg);
  682. case VIDIOC_QBUF:
  683. return videobuf_qbuf(&fh->mpegq, arg);
  684. case VIDIOC_DQBUF:
  685. return videobuf_dqbuf(&fh->mpegq, arg,
  686. file->f_flags & O_NONBLOCK);
  687. case VIDIOC_STREAMON:
  688. return videobuf_streamon(&fh->mpegq);
  689. case VIDIOC_STREAMOFF:
  690. return videobuf_streamoff(&fh->mpegq);
  691. /* --- mpeg compression -------------------------------------- */
  692. case VIDIOC_G_MPEGCOMP:
  693. {
  694. struct v4l2_mpeg_compression *f = arg;
  695. printk(KERN_WARNING "VIDIOC_G_MPEGCOMP is obsolete. "
  696. "Replace with VIDIOC_G_EXT_CTRLS!");
  697. memcpy(f,&default_mpeg_params,sizeof(*f));
  698. return 0;
  699. }
  700. case VIDIOC_S_MPEGCOMP:
  701. printk(KERN_WARNING "VIDIOC_S_MPEGCOMP is obsolete. "
  702. "Replace with VIDIOC_S_EXT_CTRLS!");
  703. return 0;
  704. case VIDIOC_G_EXT_CTRLS:
  705. {
  706. struct v4l2_ext_controls *f = arg;
  707. if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
  708. return -EINVAL;
  709. return cx2341x_ext_ctrls(&dev->params, f, cmd);
  710. }
  711. case VIDIOC_S_EXT_CTRLS:
  712. case VIDIOC_TRY_EXT_CTRLS:
  713. {
  714. struct v4l2_ext_controls *f = arg;
  715. struct cx2341x_mpeg_params p;
  716. int err;
  717. if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
  718. return -EINVAL;
  719. p = dev->params;
  720. err = cx2341x_ext_ctrls(&p, f, cmd);
  721. if (err == 0 && cmd == VIDIOC_S_EXT_CTRLS) {
  722. err = cx2341x_update(dev, blackbird_mbox_func, &dev->params, &p);
  723. dev->params = p;
  724. }
  725. return err;
  726. }
  727. case VIDIOC_S_FREQUENCY:
  728. {
  729. blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0,
  730. BLACKBIRD_END_NOW,
  731. BLACKBIRD_MPEG_CAPTURE,
  732. BLACKBIRD_RAW_BITS_NONE);
  733. cx88_do_ioctl( inode, file, 0, dev->core, cmd, arg, cx88_ioctl_hook );
  734. blackbird_initialize_codec(dev);
  735. cx88_set_scale(dev->core, dev->width, dev->height,
  736. fh->mpegq.field);
  737. return 0;
  738. }
  739. default:
  740. return cx88_do_ioctl( inode, file, 0, dev->core, cmd, arg, cx88_ioctl_hook );
  741. }
  742. return 0;
  743. }
  744. int (*cx88_ioctl_hook)(struct inode *inode, struct file *file,
  745. unsigned int cmd, void *arg);
  746. unsigned int (*cx88_ioctl_translator)(unsigned int cmd);
  747. static unsigned int mpeg_translate_ioctl(unsigned int cmd)
  748. {
  749. return cmd;
  750. }
  751. static int mpeg_ioctl(struct inode *inode, struct file *file,
  752. unsigned int cmd, unsigned long arg)
  753. {
  754. cmd = cx88_ioctl_translator( cmd );
  755. return video_usercopy(inode, file, cmd, arg, cx88_ioctl_hook);
  756. }
  757. static int mpeg_open(struct inode *inode, struct file *file)
  758. {
  759. int minor = iminor(inode);
  760. struct cx8802_dev *h,*dev = NULL;
  761. struct cx8802_fh *fh;
  762. struct list_head *list;
  763. list_for_each(list,&cx8802_devlist) {
  764. h = list_entry(list, struct cx8802_dev, devlist);
  765. if (h->mpeg_dev->minor == minor)
  766. dev = h;
  767. }
  768. if (NULL == dev)
  769. return -ENODEV;
  770. if (blackbird_initialize_codec(dev) < 0)
  771. return -EINVAL;
  772. dprintk(1,"open minor=%d\n",minor);
  773. /* allocate + initialize per filehandle data */
  774. fh = kzalloc(sizeof(*fh),GFP_KERNEL);
  775. if (NULL == fh)
  776. return -ENOMEM;
  777. file->private_data = fh;
  778. fh->dev = dev;
  779. videobuf_queue_init(&fh->mpegq, &blackbird_qops,
  780. dev->pci, &dev->slock,
  781. V4L2_BUF_TYPE_VIDEO_CAPTURE,
  782. V4L2_FIELD_INTERLACED,
  783. sizeof(struct cx88_buffer),
  784. fh);
  785. /* FIXME: locking against other video device */
  786. cx88_set_scale(dev->core, dev->width, dev->height,
  787. fh->mpegq.field);
  788. return 0;
  789. }
  790. static int mpeg_release(struct inode *inode, struct file *file)
  791. {
  792. struct cx8802_fh *fh = file->private_data;
  793. /* blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0, BLACKBIRD_END_NOW, 0, 0x13); */
  794. blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0,
  795. BLACKBIRD_END_NOW,
  796. BLACKBIRD_MPEG_CAPTURE,
  797. BLACKBIRD_RAW_BITS_NONE
  798. );
  799. cx8802_cancel_buffers(fh->dev);
  800. /* stop mpeg capture */
  801. if (fh->mpegq.streaming)
  802. videobuf_streamoff(&fh->mpegq);
  803. if (fh->mpegq.reading)
  804. videobuf_read_stop(&fh->mpegq);
  805. videobuf_mmap_free(&fh->mpegq);
  806. file->private_data = NULL;
  807. kfree(fh);
  808. return 0;
  809. }
  810. static ssize_t
  811. mpeg_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
  812. {
  813. struct cx8802_fh *fh = file->private_data;
  814. return videobuf_read_stream(&fh->mpegq, data, count, ppos, 0,
  815. file->f_flags & O_NONBLOCK);
  816. }
  817. static unsigned int
  818. mpeg_poll(struct file *file, struct poll_table_struct *wait)
  819. {
  820. struct cx8802_fh *fh = file->private_data;
  821. return videobuf_poll_stream(file, &fh->mpegq, wait);
  822. }
  823. static int
  824. mpeg_mmap(struct file *file, struct vm_area_struct * vma)
  825. {
  826. struct cx8802_fh *fh = file->private_data;
  827. return videobuf_mmap_mapper(&fh->mpegq, vma);
  828. }
  829. static struct file_operations mpeg_fops =
  830. {
  831. .owner = THIS_MODULE,
  832. .open = mpeg_open,
  833. .release = mpeg_release,
  834. .read = mpeg_read,
  835. .poll = mpeg_poll,
  836. .mmap = mpeg_mmap,
  837. .ioctl = mpeg_ioctl,
  838. .llseek = no_llseek,
  839. };
  840. static struct video_device cx8802_mpeg_template =
  841. {
  842. .name = "cx8802",
  843. .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_SCALES|VID_TYPE_MPEG_ENCODER,
  844. .hardware = 0,
  845. .fops = &mpeg_fops,
  846. .minor = -1,
  847. };
  848. /* ------------------------------------------------------------------ */
  849. static void blackbird_unregister_video(struct cx8802_dev *dev)
  850. {
  851. if (dev->mpeg_dev) {
  852. if (-1 != dev->mpeg_dev->minor)
  853. video_unregister_device(dev->mpeg_dev);
  854. else
  855. video_device_release(dev->mpeg_dev);
  856. dev->mpeg_dev = NULL;
  857. }
  858. }
  859. static int blackbird_register_video(struct cx8802_dev *dev)
  860. {
  861. int err;
  862. dev->mpeg_dev = cx88_vdev_init(dev->core,dev->pci,
  863. &cx8802_mpeg_template,"mpeg");
  864. err = video_register_device(dev->mpeg_dev,VFL_TYPE_GRABBER, -1);
  865. if (err < 0) {
  866. printk(KERN_INFO "%s/2: can't register mpeg device\n",
  867. dev->core->name);
  868. return err;
  869. }
  870. printk(KERN_INFO "%s/2: registered device video%d [mpeg]\n",
  871. dev->core->name,dev->mpeg_dev->minor & 0x1f);
  872. return 0;
  873. }
  874. /* ----------------------------------------------------------- */
  875. static int __devinit blackbird_probe(struct pci_dev *pci_dev,
  876. const struct pci_device_id *pci_id)
  877. {
  878. struct cx8802_dev *dev;
  879. struct cx88_core *core;
  880. int err;
  881. /* general setup */
  882. core = cx88_core_get(pci_dev);
  883. if (NULL == core)
  884. return -EINVAL;
  885. err = -ENODEV;
  886. if (!cx88_boards[core->board].blackbird)
  887. goto fail_core;
  888. err = -ENOMEM;
  889. dev = kzalloc(sizeof(*dev),GFP_KERNEL);
  890. if (NULL == dev)
  891. goto fail_core;
  892. dev->pci = pci_dev;
  893. dev->core = core;
  894. dev->width = 720;
  895. dev->height = 576;
  896. cx2341x_fill_defaults(&dev->params);
  897. dev->params.port = CX2341X_PORT_STREAMING;
  898. switch (core->board) {
  899. case CX88_BOARD_HAUPPAUGE_ROSLYN:
  900. if (core->tuner_formats & V4L2_STD_525_60) {
  901. dev->height = 480;
  902. } else {
  903. dev->height = 576;
  904. }
  905. break;
  906. case CX88_BOARD_KWORLD_HARDWARE_MPEG_TV_XPERT:
  907. if (core->tvnorm->id & V4L2_STD_525_60) {
  908. dev->height = 480;
  909. } else {
  910. dev->height = 576;
  911. }
  912. break;
  913. }
  914. err = cx8802_init_common(dev);
  915. if (0 != err)
  916. goto fail_free;
  917. /* blackbird stuff */
  918. printk("%s/2: cx23416 based mpeg encoder (blackbird reference design)\n",
  919. core->name);
  920. host_setup(dev->core);
  921. list_add_tail(&dev->devlist,&cx8802_devlist);
  922. blackbird_register_video(dev);
  923. /* initial device configuration: needed ? */
  924. return 0;
  925. fail_free:
  926. kfree(dev);
  927. fail_core:
  928. cx88_core_put(core,pci_dev);
  929. return err;
  930. }
  931. static void __devexit blackbird_remove(struct pci_dev *pci_dev)
  932. {
  933. struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
  934. /* blackbird */
  935. blackbird_unregister_video(dev);
  936. list_del(&dev->devlist);
  937. /* common */
  938. cx8802_fini_common(dev);
  939. cx88_core_put(dev->core,dev->pci);
  940. kfree(dev);
  941. }
  942. static struct pci_device_id cx8802_pci_tbl[] = {
  943. {
  944. .vendor = 0x14f1,
  945. .device = 0x8802,
  946. .subvendor = PCI_ANY_ID,
  947. .subdevice = PCI_ANY_ID,
  948. },{
  949. /* --- end of list --- */
  950. }
  951. };
  952. MODULE_DEVICE_TABLE(pci, cx8802_pci_tbl);
  953. static struct pci_driver blackbird_pci_driver = {
  954. .name = "cx88-blackbird",
  955. .id_table = cx8802_pci_tbl,
  956. .probe = blackbird_probe,
  957. .remove = __devexit_p(blackbird_remove),
  958. .suspend = cx8802_suspend_common,
  959. .resume = cx8802_resume_common,
  960. };
  961. static int blackbird_init(void)
  962. {
  963. printk(KERN_INFO "cx2388x blackbird driver version %d.%d.%d loaded\n",
  964. (CX88_VERSION_CODE >> 16) & 0xff,
  965. (CX88_VERSION_CODE >> 8) & 0xff,
  966. CX88_VERSION_CODE & 0xff);
  967. #ifdef SNAPSHOT
  968. printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
  969. SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
  970. #endif
  971. cx88_ioctl_hook = mpeg_do_ioctl;
  972. cx88_ioctl_translator = mpeg_translate_ioctl;
  973. return pci_register_driver(&blackbird_pci_driver);
  974. }
  975. static void blackbird_fini(void)
  976. {
  977. pci_unregister_driver(&blackbird_pci_driver);
  978. }
  979. module_init(blackbird_init);
  980. module_exit(blackbird_fini);
  981. EXPORT_SYMBOL(cx88_ioctl_hook);
  982. EXPORT_SYMBOL(cx88_ioctl_translator);
  983. /* ----------------------------------------------------------- */
  984. /*
  985. * Local variables:
  986. * c-basic-offset: 8
  987. * End:
  988. * 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
  989. */