cx88-blackbird.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196
  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. release_firmware(firmware);
  398. return -1;
  399. }
  400. if (0 != memcmp(firmware->data, magic, 8)) {
  401. dprintk(0, "ERROR: Firmware magic mismatch, wrong file?\n");
  402. release_firmware(firmware);
  403. return -1;
  404. }
  405. /* transfer to the chip */
  406. dprintk(1,"Loading firmware ...\n");
  407. dataptr = (u32*)firmware->data;
  408. for (i = 0; i < (firmware->size >> 2); i++) {
  409. value = *dataptr;
  410. checksum += ~value;
  411. memory_write(dev->core, i, value);
  412. dataptr++;
  413. }
  414. /* read back to verify with the checksum */
  415. for (i--; i >= 0; i--) {
  416. memory_read(dev->core, i, &value);
  417. checksum -= ~value;
  418. }
  419. if (checksum) {
  420. dprintk(0, "ERROR: Firmware load failed (checksum mismatch).\n");
  421. release_firmware(firmware);
  422. return -1;
  423. }
  424. release_firmware(firmware);
  425. dprintk(0, "Firmware upload successful.\n");
  426. retval |= register_write(dev->core, IVTV_REG_HW_BLOCKS, IVTV_CMD_HW_BLOCKS_RST);
  427. retval |= register_read(dev->core, IVTV_REG_SPU, &value);
  428. retval |= register_write(dev->core, IVTV_REG_SPU, value & 0xFFFFFFFE);
  429. msleep(1);
  430. retval |= register_read(dev->core, IVTV_REG_VPU, &value);
  431. retval |= register_write(dev->core, IVTV_REG_VPU, value & 0xFFFFFFE8);
  432. if (retval < 0)
  433. dprintk(0, "Error with register_write\n");
  434. return 0;
  435. }
  436. /**
  437. Settings used by the windows tv app for PVR2000:
  438. =================================================================================================================
  439. Profile | Codec | Resolution | CBR/VBR | Video Qlty | V. Bitrate | Frmrate | Audio Codec | A. Bitrate | A. Mode
  440. -----------------------------------------------------------------------------------------------------------------
  441. MPEG-1 | MPEG1 | 352x288PAL | (CBR) | 1000:Optimal | 2000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
  442. MPEG-2 | MPEG2 | 720x576PAL | VBR | 600 :Good | 4000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
  443. VCD | MPEG1 | 352x288PAL | (CBR) | 1000:Optimal | 1150 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
  444. DVD | MPEG2 | 720x576PAL | VBR | 600 :Good | 6000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
  445. DB* DVD | MPEG2 | 720x576PAL | CBR | 600 :Good | 6000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
  446. =================================================================================================================
  447. *DB: "DirectBurn"
  448. */
  449. static void blackbird_codec_settings(struct cx8802_dev *dev)
  450. {
  451. /* assign frame size */
  452. blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0,
  453. dev->height, dev->width);
  454. dev->params.width = dev->width;
  455. dev->params.height = dev->height;
  456. dev->params.is_50hz = (dev->core->tvnorm->id & V4L2_STD_625_50) != 0;
  457. cx2341x_update(dev, blackbird_mbox_func, NULL, &dev->params);
  458. }
  459. static struct v4l2_mpeg_compression default_mpeg_params = {
  460. .st_type = V4L2_MPEG_PS_2,
  461. .st_bitrate = {
  462. .mode = V4L2_BITRATE_CBR,
  463. .min = 0,
  464. .target = 0,
  465. .max = 0
  466. },
  467. .ts_pid_pmt = 16,
  468. .ts_pid_audio = 260,
  469. .ts_pid_video = 256,
  470. .ts_pid_pcr = 259,
  471. .ps_size = 0,
  472. .au_type = V4L2_MPEG_AU_2_II,
  473. .au_bitrate = {
  474. .mode = V4L2_BITRATE_CBR,
  475. .min = 224,
  476. .target = 224,
  477. .max = 224
  478. },
  479. .au_sample_rate = 48000,
  480. .au_pesid = 0,
  481. .vi_type = V4L2_MPEG_VI_2,
  482. .vi_aspect_ratio = V4L2_MPEG_ASPECT_4_3,
  483. .vi_bitrate = {
  484. .mode = V4L2_BITRATE_CBR,
  485. .min = 4000,
  486. .target = 4500,
  487. .max = 6000
  488. },
  489. .vi_frame_rate = 25,
  490. .vi_frames_per_gop = 12,
  491. .vi_bframes_count = 2,
  492. .vi_pesid = 0,
  493. .closed_gops = 1,
  494. .pulldown = 0
  495. };
  496. static int blackbird_initialize_codec(struct cx8802_dev *dev)
  497. {
  498. struct cx88_core *core = dev->core;
  499. int version;
  500. int retval;
  501. dprintk(1,"Initialize codec\n");
  502. retval = blackbird_api_cmd(dev, CX2341X_ENC_PING_FW, 0, 0); /* ping */
  503. if (retval < 0) {
  504. /* ping was not successful, reset and upload firmware */
  505. cx_write(MO_SRST_IO, 0); /* SYS_RSTO=0 */
  506. msleep(1);
  507. cx_write(MO_SRST_IO, 1); /* SYS_RSTO=1 */
  508. msleep(1);
  509. retval = blackbird_load_firmware(dev);
  510. if (retval < 0)
  511. return retval;
  512. dev->mailbox = blackbird_find_mailbox(dev);
  513. if (dev->mailbox < 0)
  514. return -1;
  515. retval = blackbird_api_cmd(dev, CX2341X_ENC_PING_FW, 0, 0); /* ping */
  516. if (retval < 0) {
  517. dprintk(0, "ERROR: Firmware ping failed!\n");
  518. return -1;
  519. }
  520. retval = blackbird_api_cmd(dev, CX2341X_ENC_GET_VERSION, 0, 1, &version);
  521. if (retval < 0) {
  522. dprintk(0, "ERROR: Firmware get encoder version failed!\n");
  523. return -1;
  524. }
  525. dprintk(0, "Firmware version is 0x%08x\n", version);
  526. }
  527. msleep(1);
  528. cx_write(MO_PINMUX_IO, 0x88); /* 656-8bit IO and enable MPEG parallel IO */
  529. cx_clear(MO_INPUT_FORMAT, 0x100); /* chroma subcarrier lock to normal? */
  530. cx_write(MO_VBOS_CONTROL, 0x84A00); /* no 656 mode, 8-bit pixels, disable VBI */
  531. cx_clear(MO_OUTPUT_FORMAT, 0x0008); /* Normal Y-limits to let the mpeg encoder sync */
  532. blackbird_codec_settings(dev);
  533. msleep(1);
  534. /* blackbird_api_cmd(dev, IVTV_API_ASSIGN_NUM_VSYNC_LINES, 4, 0, 0xef, 0xef);
  535. blackbird_api_cmd(dev, IVTV_API_ASSIGN_NUM_VSYNC_LINES, 4, 0, 0xf0, 0xf0);
  536. blackbird_api_cmd(dev, IVTV_API_ASSIGN_NUM_VSYNC_LINES, 4, 0, 0x180, 0x180); */
  537. blackbird_api_cmd(dev, CX2341X_ENC_SET_NUM_VSYNC_LINES, 2, 0,
  538. BLACKBIRD_FIELD1_SAA7115,
  539. BLACKBIRD_FIELD2_SAA7115
  540. );
  541. /* blackbird_api_cmd(dev, IVTV_API_ASSIGN_PLACEHOLDER, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); */
  542. blackbird_api_cmd(dev, CX2341X_ENC_SET_PLACEHOLDER, 12, 0,
  543. BLACKBIRD_CUSTOM_EXTENSION_USR_DATA,
  544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  545. /* initialize the video input */
  546. blackbird_api_cmd(dev, CX2341X_ENC_INITIALIZE_INPUT, 0, 0);
  547. msleep(1);
  548. blackbird_api_cmd(dev, CX2341X_ENC_MUTE_VIDEO, 1, 0, BLACKBIRD_UNMUTE);
  549. msleep(1);
  550. blackbird_api_cmd(dev, CX2341X_ENC_MUTE_AUDIO, 1, 0, BLACKBIRD_UNMUTE);
  551. msleep(1);
  552. /* start capturing to the host interface */
  553. /* blackbird_api_cmd(dev, CX2341X_ENC_START_CAPTURE, 2, 0, 0, 0x13); */
  554. blackbird_api_cmd(dev, CX2341X_ENC_START_CAPTURE, 2, 0,
  555. BLACKBIRD_MPEG_CAPTURE,
  556. BLACKBIRD_RAW_BITS_NONE
  557. );
  558. msleep(10);
  559. blackbird_api_cmd(dev, CX2341X_ENC_REFRESH_INPUT, 0,0);
  560. return 0;
  561. }
  562. /* ------------------------------------------------------------------ */
  563. static int bb_buf_setup(struct videobuf_queue *q,
  564. unsigned int *count, unsigned int *size)
  565. {
  566. struct cx8802_fh *fh = q->priv_data;
  567. fh->dev->ts_packet_size = 188 * 4; /* was: 512 */
  568. fh->dev->ts_packet_count = mpegbufs; /* was: 100 */
  569. *size = fh->dev->ts_packet_size * fh->dev->ts_packet_count;
  570. *count = fh->dev->ts_packet_count;
  571. return 0;
  572. }
  573. static int
  574. bb_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
  575. enum v4l2_field field)
  576. {
  577. struct cx8802_fh *fh = q->priv_data;
  578. return cx8802_buf_prepare(q, fh->dev, (struct cx88_buffer*)vb, field);
  579. }
  580. static void
  581. bb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
  582. {
  583. struct cx8802_fh *fh = q->priv_data;
  584. cx8802_buf_queue(fh->dev, (struct cx88_buffer*)vb);
  585. }
  586. static void
  587. bb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
  588. {
  589. cx88_free_buffer(q, (struct cx88_buffer*)vb);
  590. }
  591. static struct videobuf_queue_ops blackbird_qops = {
  592. .buf_setup = bb_buf_setup,
  593. .buf_prepare = bb_buf_prepare,
  594. .buf_queue = bb_buf_queue,
  595. .buf_release = bb_buf_release,
  596. };
  597. /* ------------------------------------------------------------------ */
  598. static const u32 *ctrl_classes[] = {
  599. cx88_user_ctrls,
  600. cx2341x_mpeg_ctrls,
  601. NULL
  602. };
  603. static int blackbird_queryctrl(struct cx8802_dev *dev, struct v4l2_queryctrl *qctrl)
  604. {
  605. qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
  606. if (qctrl->id == 0)
  607. return -EINVAL;
  608. /* Standard V4L2 controls */
  609. if (cx8800_ctrl_query(qctrl) == 0)
  610. return 0;
  611. /* MPEG V4L2 controls */
  612. if (cx2341x_ctrl_query(&dev->params, qctrl))
  613. qctrl->flags |= V4L2_CTRL_FLAG_DISABLED;
  614. return 0;
  615. }
  616. static int blackbird_querymenu(struct cx8802_dev *dev, struct v4l2_querymenu *qmenu)
  617. {
  618. struct v4l2_queryctrl qctrl;
  619. qctrl.id = qmenu->id;
  620. blackbird_queryctrl(dev, &qctrl);
  621. return v4l2_ctrl_query_menu(qmenu, &qctrl, cx2341x_ctrl_get_menu(qmenu->id));
  622. }
  623. /* ------------------------------------------------------------------ */
  624. static int mpeg_do_ioctl(struct inode *inode, struct file *file,
  625. unsigned int cmd, void *arg)
  626. {
  627. struct cx8802_fh *fh = file->private_data;
  628. struct cx8802_dev *dev = fh->dev;
  629. struct cx88_core *core = dev->core;
  630. if (debug > 1)
  631. v4l_print_ioctl(core->name,cmd);
  632. switch (cmd) {
  633. /* --- capabilities ------------------------------------------ */
  634. case VIDIOC_QUERYCAP:
  635. {
  636. struct v4l2_capability *cap = arg;
  637. memset(cap,0,sizeof(*cap));
  638. strcpy(cap->driver, "cx88_blackbird");
  639. strlcpy(cap->card, cx88_boards[core->board].name,sizeof(cap->card));
  640. sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
  641. cap->version = CX88_VERSION_CODE;
  642. cap->capabilities =
  643. V4L2_CAP_VIDEO_CAPTURE |
  644. V4L2_CAP_READWRITE |
  645. V4L2_CAP_STREAMING |
  646. 0;
  647. if (UNSET != core->tuner_type)
  648. cap->capabilities |= V4L2_CAP_TUNER;
  649. return 0;
  650. }
  651. /* --- capture ioctls ---------------------------------------- */
  652. case VIDIOC_ENUM_FMT:
  653. {
  654. struct v4l2_fmtdesc *f = arg;
  655. int index;
  656. index = f->index;
  657. if (index != 0)
  658. return -EINVAL;
  659. memset(f,0,sizeof(*f));
  660. f->index = index;
  661. strlcpy(f->description, "MPEG", sizeof(f->description));
  662. f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  663. f->pixelformat = V4L2_PIX_FMT_MPEG;
  664. return 0;
  665. }
  666. case VIDIOC_G_FMT:
  667. {
  668. struct v4l2_format *f = arg;
  669. memset(f,0,sizeof(*f));
  670. f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  671. f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
  672. f->fmt.pix.bytesperline = 0;
  673. f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */
  674. f->fmt.pix.colorspace = 0;
  675. f->fmt.pix.width = dev->width;
  676. f->fmt.pix.height = dev->height;
  677. f->fmt.pix.field = fh->mpegq.field;
  678. dprintk(0,"VIDIOC_G_FMT: w: %d, h: %d, f: %d\n",
  679. dev->width, dev->height, fh->mpegq.field );
  680. return 0;
  681. }
  682. case VIDIOC_TRY_FMT:
  683. {
  684. struct v4l2_format *f = arg;
  685. f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  686. f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
  687. f->fmt.pix.bytesperline = 0;
  688. f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */;
  689. f->fmt.pix.colorspace = 0;
  690. dprintk(0,"VIDIOC_TRY_FMT: w: %d, h: %d, f: %d\n",
  691. dev->width, dev->height, fh->mpegq.field );
  692. return 0;
  693. }
  694. case VIDIOC_S_FMT:
  695. {
  696. struct v4l2_format *f = arg;
  697. f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  698. f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
  699. f->fmt.pix.bytesperline = 0;
  700. f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */;
  701. f->fmt.pix.colorspace = 0;
  702. dprintk(0,"VIDIOC_S_FMT: w: %d, h: %d, f: %d\n",
  703. f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.field );
  704. return 0;
  705. }
  706. /* --- streaming capture ------------------------------------- */
  707. case VIDIOC_REQBUFS:
  708. return videobuf_reqbufs(&fh->mpegq, arg);
  709. case VIDIOC_QUERYBUF:
  710. return videobuf_querybuf(&fh->mpegq, arg);
  711. case VIDIOC_QBUF:
  712. return videobuf_qbuf(&fh->mpegq, arg);
  713. case VIDIOC_DQBUF:
  714. return videobuf_dqbuf(&fh->mpegq, arg,
  715. file->f_flags & O_NONBLOCK);
  716. case VIDIOC_STREAMON:
  717. return videobuf_streamon(&fh->mpegq);
  718. case VIDIOC_STREAMOFF:
  719. return videobuf_streamoff(&fh->mpegq);
  720. /* --- mpeg compression -------------------------------------- */
  721. case VIDIOC_G_MPEGCOMP:
  722. {
  723. struct v4l2_mpeg_compression *f = arg;
  724. printk(KERN_WARNING "VIDIOC_G_MPEGCOMP is obsolete. "
  725. "Replace with VIDIOC_G_EXT_CTRLS!");
  726. memcpy(f,&default_mpeg_params,sizeof(*f));
  727. return 0;
  728. }
  729. case VIDIOC_S_MPEGCOMP:
  730. printk(KERN_WARNING "VIDIOC_S_MPEGCOMP is obsolete. "
  731. "Replace with VIDIOC_S_EXT_CTRLS!");
  732. return 0;
  733. case VIDIOC_G_EXT_CTRLS:
  734. {
  735. struct v4l2_ext_controls *f = arg;
  736. if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
  737. return -EINVAL;
  738. return cx2341x_ext_ctrls(&dev->params, f, cmd);
  739. }
  740. case VIDIOC_S_EXT_CTRLS:
  741. case VIDIOC_TRY_EXT_CTRLS:
  742. {
  743. struct v4l2_ext_controls *f = arg;
  744. struct cx2341x_mpeg_params p;
  745. int err;
  746. if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
  747. return -EINVAL;
  748. p = dev->params;
  749. err = cx2341x_ext_ctrls(&p, f, cmd);
  750. if (err == 0 && cmd == VIDIOC_S_EXT_CTRLS) {
  751. err = cx2341x_update(dev, blackbird_mbox_func, &dev->params, &p);
  752. dev->params = p;
  753. }
  754. return err;
  755. }
  756. case VIDIOC_S_FREQUENCY:
  757. {
  758. blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0,
  759. BLACKBIRD_END_NOW,
  760. BLACKBIRD_MPEG_CAPTURE,
  761. BLACKBIRD_RAW_BITS_NONE);
  762. cx88_do_ioctl(inode, file, 0, dev->core, cmd, arg, mpeg_do_ioctl);
  763. blackbird_initialize_codec(dev);
  764. cx88_set_scale(dev->core, dev->width, dev->height,
  765. fh->mpegq.field);
  766. return 0;
  767. }
  768. case VIDIOC_LOG_STATUS:
  769. {
  770. char name[32 + 2];
  771. snprintf(name, sizeof(name), "%s/2", core->name);
  772. printk("%s/2: ============ START LOG STATUS ============\n",
  773. core->name);
  774. cx88_call_i2c_clients(core, VIDIOC_LOG_STATUS, 0);
  775. cx2341x_log_status(&dev->params, name);
  776. printk("%s/2: ============= END LOG STATUS =============\n",
  777. core->name);
  778. return 0;
  779. }
  780. case VIDIOC_QUERYMENU:
  781. return blackbird_querymenu(dev, arg);
  782. case VIDIOC_QUERYCTRL:
  783. {
  784. struct v4l2_queryctrl *c = arg;
  785. if (blackbird_queryctrl(dev, c) == 0)
  786. return 0;
  787. return cx88_do_ioctl(inode, file, 0, dev->core, cmd, arg, mpeg_do_ioctl);
  788. }
  789. default:
  790. return cx88_do_ioctl(inode, file, 0, dev->core, cmd, arg, mpeg_do_ioctl);
  791. }
  792. return 0;
  793. }
  794. static unsigned int mpeg_translate_ioctl(unsigned int cmd)
  795. {
  796. return cmd;
  797. }
  798. static int mpeg_ioctl(struct inode *inode, struct file *file,
  799. unsigned int cmd, unsigned long arg)
  800. {
  801. cmd = mpeg_translate_ioctl( cmd );
  802. return video_usercopy(inode, file, cmd, arg, mpeg_do_ioctl);
  803. }
  804. static int mpeg_open(struct inode *inode, struct file *file)
  805. {
  806. int minor = iminor(inode);
  807. struct cx8802_dev *h,*dev = NULL;
  808. struct cx8802_fh *fh;
  809. struct list_head *list;
  810. list_for_each(list,&cx8802_devlist) {
  811. h = list_entry(list, struct cx8802_dev, devlist);
  812. if (h->mpeg_dev->minor == minor)
  813. dev = h;
  814. }
  815. if (NULL == dev)
  816. return -ENODEV;
  817. if (blackbird_initialize_codec(dev) < 0)
  818. return -EINVAL;
  819. dprintk(1,"open minor=%d\n",minor);
  820. /* allocate + initialize per filehandle data */
  821. fh = kzalloc(sizeof(*fh),GFP_KERNEL);
  822. if (NULL == fh)
  823. return -ENOMEM;
  824. file->private_data = fh;
  825. fh->dev = dev;
  826. videobuf_queue_init(&fh->mpegq, &blackbird_qops,
  827. dev->pci, &dev->slock,
  828. V4L2_BUF_TYPE_VIDEO_CAPTURE,
  829. V4L2_FIELD_INTERLACED,
  830. sizeof(struct cx88_buffer),
  831. fh);
  832. /* FIXME: locking against other video device */
  833. cx88_set_scale(dev->core, dev->width, dev->height,
  834. fh->mpegq.field);
  835. return 0;
  836. }
  837. static int mpeg_release(struct inode *inode, struct file *file)
  838. {
  839. struct cx8802_fh *fh = file->private_data;
  840. /* blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0, BLACKBIRD_END_NOW, 0, 0x13); */
  841. blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0,
  842. BLACKBIRD_END_NOW,
  843. BLACKBIRD_MPEG_CAPTURE,
  844. BLACKBIRD_RAW_BITS_NONE
  845. );
  846. cx8802_cancel_buffers(fh->dev);
  847. /* stop mpeg capture */
  848. if (fh->mpegq.streaming)
  849. videobuf_streamoff(&fh->mpegq);
  850. if (fh->mpegq.reading)
  851. videobuf_read_stop(&fh->mpegq);
  852. videobuf_mmap_free(&fh->mpegq);
  853. file->private_data = NULL;
  854. kfree(fh);
  855. return 0;
  856. }
  857. static ssize_t
  858. mpeg_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
  859. {
  860. struct cx8802_fh *fh = file->private_data;
  861. return videobuf_read_stream(&fh->mpegq, data, count, ppos, 0,
  862. file->f_flags & O_NONBLOCK);
  863. }
  864. static unsigned int
  865. mpeg_poll(struct file *file, struct poll_table_struct *wait)
  866. {
  867. struct cx8802_fh *fh = file->private_data;
  868. return videobuf_poll_stream(file, &fh->mpegq, wait);
  869. }
  870. static int
  871. mpeg_mmap(struct file *file, struct vm_area_struct * vma)
  872. {
  873. struct cx8802_fh *fh = file->private_data;
  874. return videobuf_mmap_mapper(&fh->mpegq, vma);
  875. }
  876. static struct file_operations mpeg_fops =
  877. {
  878. .owner = THIS_MODULE,
  879. .open = mpeg_open,
  880. .release = mpeg_release,
  881. .read = mpeg_read,
  882. .poll = mpeg_poll,
  883. .mmap = mpeg_mmap,
  884. .ioctl = mpeg_ioctl,
  885. .llseek = no_llseek,
  886. };
  887. static struct video_device cx8802_mpeg_template =
  888. {
  889. .name = "cx8802",
  890. .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_SCALES|VID_TYPE_MPEG_ENCODER,
  891. .hardware = 0,
  892. .fops = &mpeg_fops,
  893. .minor = -1,
  894. };
  895. /* ------------------------------------------------------------------ */
  896. static void blackbird_unregister_video(struct cx8802_dev *dev)
  897. {
  898. if (dev->mpeg_dev) {
  899. if (-1 != dev->mpeg_dev->minor)
  900. video_unregister_device(dev->mpeg_dev);
  901. else
  902. video_device_release(dev->mpeg_dev);
  903. dev->mpeg_dev = NULL;
  904. }
  905. }
  906. static int blackbird_register_video(struct cx8802_dev *dev)
  907. {
  908. int err;
  909. dev->mpeg_dev = cx88_vdev_init(dev->core,dev->pci,
  910. &cx8802_mpeg_template,"mpeg");
  911. err = video_register_device(dev->mpeg_dev,VFL_TYPE_GRABBER, -1);
  912. if (err < 0) {
  913. printk(KERN_INFO "%s/2: can't register mpeg device\n",
  914. dev->core->name);
  915. return err;
  916. }
  917. printk(KERN_INFO "%s/2: registered device video%d [mpeg]\n",
  918. dev->core->name,dev->mpeg_dev->minor & 0x1f);
  919. return 0;
  920. }
  921. /* ----------------------------------------------------------- */
  922. static int __devinit blackbird_probe(struct pci_dev *pci_dev,
  923. const struct pci_device_id *pci_id)
  924. {
  925. struct cx8802_dev *dev;
  926. struct cx88_core *core;
  927. int err;
  928. /* general setup */
  929. core = cx88_core_get(pci_dev);
  930. if (NULL == core)
  931. return -EINVAL;
  932. err = -ENODEV;
  933. if (!cx88_boards[core->board].blackbird)
  934. goto fail_core;
  935. err = -ENOMEM;
  936. dev = kzalloc(sizeof(*dev),GFP_KERNEL);
  937. if (NULL == dev)
  938. goto fail_core;
  939. dev->pci = pci_dev;
  940. dev->core = core;
  941. dev->width = 720;
  942. dev->height = 576;
  943. cx2341x_fill_defaults(&dev->params);
  944. dev->params.port = CX2341X_PORT_STREAMING;
  945. if (core->tvnorm->id & V4L2_STD_525_60) {
  946. dev->height = 480;
  947. } else {
  948. dev->height = 576;
  949. }
  950. err = cx8802_init_common(dev);
  951. if (0 != err)
  952. goto fail_free;
  953. /* blackbird stuff */
  954. printk("%s/2: cx23416 based mpeg encoder (blackbird reference design)\n",
  955. core->name);
  956. host_setup(dev->core);
  957. list_add_tail(&dev->devlist,&cx8802_devlist);
  958. blackbird_register_video(dev);
  959. /* initial device configuration: needed ? */
  960. return 0;
  961. fail_free:
  962. kfree(dev);
  963. fail_core:
  964. cx88_core_put(core,pci_dev);
  965. return err;
  966. }
  967. static void __devexit blackbird_remove(struct pci_dev *pci_dev)
  968. {
  969. struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
  970. /* blackbird */
  971. blackbird_unregister_video(dev);
  972. list_del(&dev->devlist);
  973. /* common */
  974. cx8802_fini_common(dev);
  975. cx88_core_put(dev->core,dev->pci);
  976. kfree(dev);
  977. }
  978. static struct pci_device_id cx8802_pci_tbl[] = {
  979. {
  980. .vendor = 0x14f1,
  981. .device = 0x8802,
  982. .subvendor = PCI_ANY_ID,
  983. .subdevice = PCI_ANY_ID,
  984. },{
  985. /* --- end of list --- */
  986. }
  987. };
  988. MODULE_DEVICE_TABLE(pci, cx8802_pci_tbl);
  989. static struct pci_driver blackbird_pci_driver = {
  990. .name = "cx88-blackbird",
  991. .id_table = cx8802_pci_tbl,
  992. .probe = blackbird_probe,
  993. .remove = __devexit_p(blackbird_remove),
  994. #ifdef CONFIG_PM
  995. .suspend = cx8802_suspend_common,
  996. .resume = cx8802_resume_common,
  997. #endif
  998. };
  999. static int blackbird_init(void)
  1000. {
  1001. printk(KERN_INFO "cx2388x blackbird driver version %d.%d.%d loaded\n",
  1002. (CX88_VERSION_CODE >> 16) & 0xff,
  1003. (CX88_VERSION_CODE >> 8) & 0xff,
  1004. CX88_VERSION_CODE & 0xff);
  1005. #ifdef SNAPSHOT
  1006. printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
  1007. SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
  1008. #endif
  1009. return pci_register_driver(&blackbird_pci_driver);
  1010. }
  1011. static void blackbird_fini(void)
  1012. {
  1013. pci_unregister_driver(&blackbird_pci_driver);
  1014. }
  1015. module_init(blackbird_init);
  1016. module_exit(blackbird_fini);
  1017. /* ----------------------------------------------------------- */
  1018. /*
  1019. * Local variables:
  1020. * c-basic-offset: 8
  1021. * End:
  1022. * 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
  1023. */