cx88-blackbird.c 34 KB

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