cx88-blackbird.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  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. dprintk( 1, "%s\n", __FUNCTION__);
  814. dev = cx8802_get_device(inode);
  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 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. */