cx88-blackbird.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  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, mpeg_do_ioctl);
  734. blackbird_initialize_codec(dev);
  735. cx88_set_scale(dev->core, dev->width, dev->height,
  736. fh->mpegq.field);
  737. return 0;
  738. }
  739. case VIDIOC_LOG_STATUS:
  740. {
  741. char name[32 + 2];
  742. snprintf(name, sizeof(name), "%s/2", core->name);
  743. printk("%s/2: ============ START LOG STATUS ============\n",
  744. core->name);
  745. cx88_call_i2c_clients(core, VIDIOC_LOG_STATUS, 0);
  746. cx2341x_log_status(&dev->params, name);
  747. printk("%s/2: ============= END LOG STATUS =============\n",
  748. core->name);
  749. return 0;
  750. }
  751. default:
  752. return cx88_do_ioctl(inode, file, 0, dev->core, cmd, arg, mpeg_do_ioctl);
  753. }
  754. return 0;
  755. }
  756. static unsigned int mpeg_translate_ioctl(unsigned int cmd)
  757. {
  758. return cmd;
  759. }
  760. static int mpeg_ioctl(struct inode *inode, struct file *file,
  761. unsigned int cmd, unsigned long arg)
  762. {
  763. cmd = mpeg_translate_ioctl( cmd );
  764. return video_usercopy(inode, file, cmd, arg, mpeg_do_ioctl);
  765. }
  766. static int mpeg_open(struct inode *inode, struct file *file)
  767. {
  768. int minor = iminor(inode);
  769. struct cx8802_dev *h,*dev = NULL;
  770. struct cx8802_fh *fh;
  771. struct list_head *list;
  772. list_for_each(list,&cx8802_devlist) {
  773. h = list_entry(list, struct cx8802_dev, devlist);
  774. if (h->mpeg_dev->minor == minor)
  775. dev = h;
  776. }
  777. if (NULL == dev)
  778. return -ENODEV;
  779. if (blackbird_initialize_codec(dev) < 0)
  780. return -EINVAL;
  781. dprintk(1,"open minor=%d\n",minor);
  782. /* allocate + initialize per filehandle data */
  783. fh = kzalloc(sizeof(*fh),GFP_KERNEL);
  784. if (NULL == fh)
  785. return -ENOMEM;
  786. file->private_data = fh;
  787. fh->dev = dev;
  788. videobuf_queue_init(&fh->mpegq, &blackbird_qops,
  789. dev->pci, &dev->slock,
  790. V4L2_BUF_TYPE_VIDEO_CAPTURE,
  791. V4L2_FIELD_INTERLACED,
  792. sizeof(struct cx88_buffer),
  793. fh);
  794. /* FIXME: locking against other video device */
  795. cx88_set_scale(dev->core, dev->width, dev->height,
  796. fh->mpegq.field);
  797. return 0;
  798. }
  799. static int mpeg_release(struct inode *inode, struct file *file)
  800. {
  801. struct cx8802_fh *fh = file->private_data;
  802. /* blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0, BLACKBIRD_END_NOW, 0, 0x13); */
  803. blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0,
  804. BLACKBIRD_END_NOW,
  805. BLACKBIRD_MPEG_CAPTURE,
  806. BLACKBIRD_RAW_BITS_NONE
  807. );
  808. cx8802_cancel_buffers(fh->dev);
  809. /* stop mpeg capture */
  810. if (fh->mpegq.streaming)
  811. videobuf_streamoff(&fh->mpegq);
  812. if (fh->mpegq.reading)
  813. videobuf_read_stop(&fh->mpegq);
  814. videobuf_mmap_free(&fh->mpegq);
  815. file->private_data = NULL;
  816. kfree(fh);
  817. return 0;
  818. }
  819. static ssize_t
  820. mpeg_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
  821. {
  822. struct cx8802_fh *fh = file->private_data;
  823. return videobuf_read_stream(&fh->mpegq, data, count, ppos, 0,
  824. file->f_flags & O_NONBLOCK);
  825. }
  826. static unsigned int
  827. mpeg_poll(struct file *file, struct poll_table_struct *wait)
  828. {
  829. struct cx8802_fh *fh = file->private_data;
  830. return videobuf_poll_stream(file, &fh->mpegq, wait);
  831. }
  832. static int
  833. mpeg_mmap(struct file *file, struct vm_area_struct * vma)
  834. {
  835. struct cx8802_fh *fh = file->private_data;
  836. return videobuf_mmap_mapper(&fh->mpegq, vma);
  837. }
  838. static struct file_operations mpeg_fops =
  839. {
  840. .owner = THIS_MODULE,
  841. .open = mpeg_open,
  842. .release = mpeg_release,
  843. .read = mpeg_read,
  844. .poll = mpeg_poll,
  845. .mmap = mpeg_mmap,
  846. .ioctl = mpeg_ioctl,
  847. .llseek = no_llseek,
  848. };
  849. static struct video_device cx8802_mpeg_template =
  850. {
  851. .name = "cx8802",
  852. .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_SCALES|VID_TYPE_MPEG_ENCODER,
  853. .hardware = 0,
  854. .fops = &mpeg_fops,
  855. .minor = -1,
  856. };
  857. /* ------------------------------------------------------------------ */
  858. static void blackbird_unregister_video(struct cx8802_dev *dev)
  859. {
  860. if (dev->mpeg_dev) {
  861. if (-1 != dev->mpeg_dev->minor)
  862. video_unregister_device(dev->mpeg_dev);
  863. else
  864. video_device_release(dev->mpeg_dev);
  865. dev->mpeg_dev = NULL;
  866. }
  867. }
  868. static int blackbird_register_video(struct cx8802_dev *dev)
  869. {
  870. int err;
  871. dev->mpeg_dev = cx88_vdev_init(dev->core,dev->pci,
  872. &cx8802_mpeg_template,"mpeg");
  873. err = video_register_device(dev->mpeg_dev,VFL_TYPE_GRABBER, -1);
  874. if (err < 0) {
  875. printk(KERN_INFO "%s/2: can't register mpeg device\n",
  876. dev->core->name);
  877. return err;
  878. }
  879. printk(KERN_INFO "%s/2: registered device video%d [mpeg]\n",
  880. dev->core->name,dev->mpeg_dev->minor & 0x1f);
  881. return 0;
  882. }
  883. /* ----------------------------------------------------------- */
  884. static int __devinit blackbird_probe(struct pci_dev *pci_dev,
  885. const struct pci_device_id *pci_id)
  886. {
  887. struct cx8802_dev *dev;
  888. struct cx88_core *core;
  889. int err;
  890. /* general setup */
  891. core = cx88_core_get(pci_dev);
  892. if (NULL == core)
  893. return -EINVAL;
  894. err = -ENODEV;
  895. if (!cx88_boards[core->board].blackbird)
  896. goto fail_core;
  897. err = -ENOMEM;
  898. dev = kzalloc(sizeof(*dev),GFP_KERNEL);
  899. if (NULL == dev)
  900. goto fail_core;
  901. dev->pci = pci_dev;
  902. dev->core = core;
  903. dev->width = 720;
  904. dev->height = 576;
  905. cx2341x_fill_defaults(&dev->params);
  906. dev->params.port = CX2341X_PORT_STREAMING;
  907. if (core->tvnorm->id & V4L2_STD_525_60) {
  908. dev->height = 480;
  909. } else {
  910. dev->height = 576;
  911. }
  912. err = cx8802_init_common(dev);
  913. if (0 != err)
  914. goto fail_free;
  915. /* blackbird stuff */
  916. printk("%s/2: cx23416 based mpeg encoder (blackbird reference design)\n",
  917. core->name);
  918. host_setup(dev->core);
  919. list_add_tail(&dev->devlist,&cx8802_devlist);
  920. blackbird_register_video(dev);
  921. /* initial device configuration: needed ? */
  922. return 0;
  923. fail_free:
  924. kfree(dev);
  925. fail_core:
  926. cx88_core_put(core,pci_dev);
  927. return err;
  928. }
  929. static void __devexit blackbird_remove(struct pci_dev *pci_dev)
  930. {
  931. struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
  932. /* blackbird */
  933. blackbird_unregister_video(dev);
  934. list_del(&dev->devlist);
  935. /* common */
  936. cx8802_fini_common(dev);
  937. cx88_core_put(dev->core,dev->pci);
  938. kfree(dev);
  939. }
  940. static struct pci_device_id cx8802_pci_tbl[] = {
  941. {
  942. .vendor = 0x14f1,
  943. .device = 0x8802,
  944. .subvendor = PCI_ANY_ID,
  945. .subdevice = PCI_ANY_ID,
  946. },{
  947. /* --- end of list --- */
  948. }
  949. };
  950. MODULE_DEVICE_TABLE(pci, cx8802_pci_tbl);
  951. static struct pci_driver blackbird_pci_driver = {
  952. .name = "cx88-blackbird",
  953. .id_table = cx8802_pci_tbl,
  954. .probe = blackbird_probe,
  955. .remove = __devexit_p(blackbird_remove),
  956. .suspend = cx8802_suspend_common,
  957. .resume = cx8802_resume_common,
  958. };
  959. static int blackbird_init(void)
  960. {
  961. printk(KERN_INFO "cx2388x blackbird driver version %d.%d.%d loaded\n",
  962. (CX88_VERSION_CODE >> 16) & 0xff,
  963. (CX88_VERSION_CODE >> 8) & 0xff,
  964. CX88_VERSION_CODE & 0xff);
  965. #ifdef SNAPSHOT
  966. printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
  967. SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
  968. #endif
  969. return pci_register_driver(&blackbird_pci_driver);
  970. }
  971. static void blackbird_fini(void)
  972. {
  973. pci_unregister_driver(&blackbird_pci_driver);
  974. }
  975. module_init(blackbird_init);
  976. module_exit(blackbird_fini);
  977. /* ----------------------------------------------------------- */
  978. /*
  979. * Local variables:
  980. * c-basic-offset: 8
  981. * End:
  982. * 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
  983. */