cx23885-417.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570
  1. /*
  2. *
  3. * Support for a cx23417 mpeg encoder via cx23885 host port.
  4. *
  5. * (c) 2004 Jelle Foks <jelle@foks.us>
  6. * (c) 2004 Gerd Knorr <kraxel@bytesex.org>
  7. * (c) 2008 Steven Toth <stoth@linuxtv.org>
  8. * - CX23885/7/8 support
  9. *
  10. * Includes parts from the ivtv driver <http://sourceforge.net/projects/ivtv/>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. */
  22. #include "cx23885.h"
  23. #include "cx23885-ioctl.h"
  24. #include <linux/module.h>
  25. #include <linux/moduleparam.h>
  26. #include <linux/init.h>
  27. #include <linux/fs.h>
  28. #include <linux/delay.h>
  29. #include <linux/device.h>
  30. #include <linux/firmware.h>
  31. #include <linux/slab.h>
  32. #include <media/v4l2-common.h>
  33. #include <media/v4l2-ioctl.h>
  34. #include <media/drv-intf/cx2341x.h>
  35. #define CX23885_FIRM_IMAGE_SIZE 376836
  36. #define CX23885_FIRM_IMAGE_NAME "v4l-cx23885-enc.fw"
  37. static unsigned int mpegbufs = 32;
  38. module_param(mpegbufs, int, 0644);
  39. MODULE_PARM_DESC(mpegbufs, "number of mpeg buffers, range 2-32");
  40. static unsigned int mpeglines = 32;
  41. module_param(mpeglines, int, 0644);
  42. MODULE_PARM_DESC(mpeglines, "number of lines in an MPEG buffer, range 2-32");
  43. static unsigned int mpeglinesize = 512;
  44. module_param(mpeglinesize, int, 0644);
  45. MODULE_PARM_DESC(mpeglinesize,
  46. "number of bytes in each line of an MPEG buffer, range 512-1024");
  47. static unsigned int v4l_debug;
  48. module_param(v4l_debug, int, 0644);
  49. MODULE_PARM_DESC(v4l_debug, "enable V4L debug messages");
  50. #define dprintk(level, fmt, arg...)\
  51. do { if (v4l_debug >= level) \
  52. printk(KERN_DEBUG pr_fmt("%s: 417:" fmt), \
  53. __func__, ##arg); \
  54. } while (0)
  55. static struct cx23885_tvnorm cx23885_tvnorms[] = {
  56. {
  57. .name = "NTSC-M",
  58. .id = V4L2_STD_NTSC_M,
  59. }, {
  60. .name = "NTSC-JP",
  61. .id = V4L2_STD_NTSC_M_JP,
  62. }, {
  63. .name = "PAL-BG",
  64. .id = V4L2_STD_PAL_BG,
  65. }, {
  66. .name = "PAL-DK",
  67. .id = V4L2_STD_PAL_DK,
  68. }, {
  69. .name = "PAL-I",
  70. .id = V4L2_STD_PAL_I,
  71. }, {
  72. .name = "PAL-M",
  73. .id = V4L2_STD_PAL_M,
  74. }, {
  75. .name = "PAL-N",
  76. .id = V4L2_STD_PAL_N,
  77. }, {
  78. .name = "PAL-Nc",
  79. .id = V4L2_STD_PAL_Nc,
  80. }, {
  81. .name = "PAL-60",
  82. .id = V4L2_STD_PAL_60,
  83. }, {
  84. .name = "SECAM-L",
  85. .id = V4L2_STD_SECAM_L,
  86. }, {
  87. .name = "SECAM-DK",
  88. .id = V4L2_STD_SECAM_DK,
  89. }
  90. };
  91. /* ------------------------------------------------------------------ */
  92. enum cx23885_capture_type {
  93. CX23885_MPEG_CAPTURE,
  94. CX23885_RAW_CAPTURE,
  95. CX23885_RAW_PASSTHRU_CAPTURE
  96. };
  97. enum cx23885_capture_bits {
  98. CX23885_RAW_BITS_NONE = 0x00,
  99. CX23885_RAW_BITS_YUV_CAPTURE = 0x01,
  100. CX23885_RAW_BITS_PCM_CAPTURE = 0x02,
  101. CX23885_RAW_BITS_VBI_CAPTURE = 0x04,
  102. CX23885_RAW_BITS_PASSTHRU_CAPTURE = 0x08,
  103. CX23885_RAW_BITS_TO_HOST_CAPTURE = 0x10
  104. };
  105. enum cx23885_capture_end {
  106. CX23885_END_AT_GOP, /* stop at the end of gop, generate irq */
  107. CX23885_END_NOW, /* stop immediately, no irq */
  108. };
  109. enum cx23885_framerate {
  110. CX23885_FRAMERATE_NTSC_30, /* NTSC: 30fps */
  111. CX23885_FRAMERATE_PAL_25 /* PAL: 25fps */
  112. };
  113. enum cx23885_stream_port {
  114. CX23885_OUTPUT_PORT_MEMORY,
  115. CX23885_OUTPUT_PORT_STREAMING,
  116. CX23885_OUTPUT_PORT_SERIAL
  117. };
  118. enum cx23885_data_xfer_status {
  119. CX23885_MORE_BUFFERS_FOLLOW,
  120. CX23885_LAST_BUFFER,
  121. };
  122. enum cx23885_picture_mask {
  123. CX23885_PICTURE_MASK_NONE,
  124. CX23885_PICTURE_MASK_I_FRAMES,
  125. CX23885_PICTURE_MASK_I_P_FRAMES = 0x3,
  126. CX23885_PICTURE_MASK_ALL_FRAMES = 0x7,
  127. };
  128. enum cx23885_vbi_mode_bits {
  129. CX23885_VBI_BITS_SLICED,
  130. CX23885_VBI_BITS_RAW,
  131. };
  132. enum cx23885_vbi_insertion_bits {
  133. CX23885_VBI_BITS_INSERT_IN_XTENSION_USR_DATA,
  134. CX23885_VBI_BITS_INSERT_IN_PRIVATE_PACKETS = 0x1 << 1,
  135. CX23885_VBI_BITS_SEPARATE_STREAM = 0x2 << 1,
  136. CX23885_VBI_BITS_SEPARATE_STREAM_USR_DATA = 0x4 << 1,
  137. CX23885_VBI_BITS_SEPARATE_STREAM_PRV_DATA = 0x5 << 1,
  138. };
  139. enum cx23885_dma_unit {
  140. CX23885_DMA_BYTES,
  141. CX23885_DMA_FRAMES,
  142. };
  143. enum cx23885_dma_transfer_status_bits {
  144. CX23885_DMA_TRANSFER_BITS_DONE = 0x01,
  145. CX23885_DMA_TRANSFER_BITS_ERROR = 0x04,
  146. CX23885_DMA_TRANSFER_BITS_LL_ERROR = 0x10,
  147. };
  148. enum cx23885_pause {
  149. CX23885_PAUSE_ENCODING,
  150. CX23885_RESUME_ENCODING,
  151. };
  152. enum cx23885_copyright {
  153. CX23885_COPYRIGHT_OFF,
  154. CX23885_COPYRIGHT_ON,
  155. };
  156. enum cx23885_notification_type {
  157. CX23885_NOTIFICATION_REFRESH,
  158. };
  159. enum cx23885_notification_status {
  160. CX23885_NOTIFICATION_OFF,
  161. CX23885_NOTIFICATION_ON,
  162. };
  163. enum cx23885_notification_mailbox {
  164. CX23885_NOTIFICATION_NO_MAILBOX = -1,
  165. };
  166. enum cx23885_field1_lines {
  167. CX23885_FIELD1_SAA7114 = 0x00EF, /* 239 */
  168. CX23885_FIELD1_SAA7115 = 0x00F0, /* 240 */
  169. CX23885_FIELD1_MICRONAS = 0x0105, /* 261 */
  170. };
  171. enum cx23885_field2_lines {
  172. CX23885_FIELD2_SAA7114 = 0x00EF, /* 239 */
  173. CX23885_FIELD2_SAA7115 = 0x00F0, /* 240 */
  174. CX23885_FIELD2_MICRONAS = 0x0106, /* 262 */
  175. };
  176. enum cx23885_custom_data_type {
  177. CX23885_CUSTOM_EXTENSION_USR_DATA,
  178. CX23885_CUSTOM_PRIVATE_PACKET,
  179. };
  180. enum cx23885_mute {
  181. CX23885_UNMUTE,
  182. CX23885_MUTE,
  183. };
  184. enum cx23885_mute_video_mask {
  185. CX23885_MUTE_VIDEO_V_MASK = 0x0000FF00,
  186. CX23885_MUTE_VIDEO_U_MASK = 0x00FF0000,
  187. CX23885_MUTE_VIDEO_Y_MASK = 0xFF000000,
  188. };
  189. enum cx23885_mute_video_shift {
  190. CX23885_MUTE_VIDEO_V_SHIFT = 8,
  191. CX23885_MUTE_VIDEO_U_SHIFT = 16,
  192. CX23885_MUTE_VIDEO_Y_SHIFT = 24,
  193. };
  194. /* defines below are from ivtv-driver.h */
  195. #define IVTV_CMD_HW_BLOCKS_RST 0xFFFFFFFF
  196. /* Firmware API commands */
  197. #define IVTV_API_STD_TIMEOUT 500
  198. /* Registers */
  199. /* IVTV_REG_OFFSET */
  200. #define IVTV_REG_ENC_SDRAM_REFRESH (0x07F8)
  201. #define IVTV_REG_ENC_SDRAM_PRECHARGE (0x07FC)
  202. #define IVTV_REG_SPU (0x9050)
  203. #define IVTV_REG_HW_BLOCKS (0x9054)
  204. #define IVTV_REG_VPU (0x9058)
  205. #define IVTV_REG_APU (0xA064)
  206. /**** Bit definitions for MC417_RWD and MC417_OEN registers ***
  207. bits 31-16
  208. +-----------+
  209. | Reserved |
  210. +-----------+
  211. bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8
  212. +-------+-------+-------+-------+-------+-------+-------+-------+
  213. | MIWR# | MIRD# | MICS# |MIRDY# |MIADDR3|MIADDR2|MIADDR1|MIADDR0|
  214. +-------+-------+-------+-------+-------+-------+-------+-------+
  215. bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0
  216. +-------+-------+-------+-------+-------+-------+-------+-------+
  217. |MIDATA7|MIDATA6|MIDATA5|MIDATA4|MIDATA3|MIDATA2|MIDATA1|MIDATA0|
  218. +-------+-------+-------+-------+-------+-------+-------+-------+
  219. ***/
  220. #define MC417_MIWR 0x8000
  221. #define MC417_MIRD 0x4000
  222. #define MC417_MICS 0x2000
  223. #define MC417_MIRDY 0x1000
  224. #define MC417_MIADDR 0x0F00
  225. #define MC417_MIDATA 0x00FF
  226. /* MIADDR* nibble definitions */
  227. #define MCI_MEMORY_DATA_BYTE0 0x000
  228. #define MCI_MEMORY_DATA_BYTE1 0x100
  229. #define MCI_MEMORY_DATA_BYTE2 0x200
  230. #define MCI_MEMORY_DATA_BYTE3 0x300
  231. #define MCI_MEMORY_ADDRESS_BYTE2 0x400
  232. #define MCI_MEMORY_ADDRESS_BYTE1 0x500
  233. #define MCI_MEMORY_ADDRESS_BYTE0 0x600
  234. #define MCI_REGISTER_DATA_BYTE0 0x800
  235. #define MCI_REGISTER_DATA_BYTE1 0x900
  236. #define MCI_REGISTER_DATA_BYTE2 0xA00
  237. #define MCI_REGISTER_DATA_BYTE3 0xB00
  238. #define MCI_REGISTER_ADDRESS_BYTE0 0xC00
  239. #define MCI_REGISTER_ADDRESS_BYTE1 0xD00
  240. #define MCI_REGISTER_MODE 0xE00
  241. /* Read and write modes */
  242. #define MCI_MODE_REGISTER_READ 0
  243. #define MCI_MODE_REGISTER_WRITE 1
  244. #define MCI_MODE_MEMORY_READ 0
  245. #define MCI_MODE_MEMORY_WRITE 0x40
  246. /*** Bit definitions for MC417_CTL register ****
  247. bits 31-6 bits 5-4 bit 3 bits 2-1 Bit 0
  248. +--------+-------------+--------+--------------+------------+
  249. |Reserved|MC417_SPD_CTL|Reserved|MC417_GPIO_SEL|UART_GPIO_EN|
  250. +--------+-------------+--------+--------------+------------+
  251. ***/
  252. #define MC417_SPD_CTL(x) (((x) << 4) & 0x00000030)
  253. #define MC417_GPIO_SEL(x) (((x) << 1) & 0x00000006)
  254. #define MC417_UART_GPIO_EN 0x00000001
  255. /* Values for speed control */
  256. #define MC417_SPD_CTL_SLOW 0x1
  257. #define MC417_SPD_CTL_MEDIUM 0x0
  258. #define MC417_SPD_CTL_FAST 0x3 /* b'1x, but we use b'11 */
  259. /* Values for GPIO select */
  260. #define MC417_GPIO_SEL_GPIO3 0x3
  261. #define MC417_GPIO_SEL_GPIO2 0x2
  262. #define MC417_GPIO_SEL_GPIO1 0x1
  263. #define MC417_GPIO_SEL_GPIO0 0x0
  264. void cx23885_mc417_init(struct cx23885_dev *dev)
  265. {
  266. u32 regval;
  267. dprintk(2, "%s()\n", __func__);
  268. /* Configure MC417_CTL register to defaults. */
  269. regval = MC417_SPD_CTL(MC417_SPD_CTL_FAST) |
  270. MC417_GPIO_SEL(MC417_GPIO_SEL_GPIO3) |
  271. MC417_UART_GPIO_EN;
  272. cx_write(MC417_CTL, regval);
  273. /* Configure MC417_OEN to defaults. */
  274. regval = MC417_MIRDY;
  275. cx_write(MC417_OEN, regval);
  276. /* Configure MC417_RWD to defaults. */
  277. regval = MC417_MIWR | MC417_MIRD | MC417_MICS;
  278. cx_write(MC417_RWD, regval);
  279. }
  280. static int mc417_wait_ready(struct cx23885_dev *dev)
  281. {
  282. u32 mi_ready;
  283. unsigned long timeout = jiffies + msecs_to_jiffies(1);
  284. for (;;) {
  285. mi_ready = cx_read(MC417_RWD) & MC417_MIRDY;
  286. if (mi_ready != 0)
  287. return 0;
  288. if (time_after(jiffies, timeout))
  289. return -1;
  290. udelay(1);
  291. }
  292. }
  293. int mc417_register_write(struct cx23885_dev *dev, u16 address, u32 value)
  294. {
  295. u32 regval;
  296. /* Enable MC417 GPIO outputs except for MC417_MIRDY,
  297. * which is an input.
  298. */
  299. cx_write(MC417_OEN, MC417_MIRDY);
  300. /* Write data byte 0 */
  301. regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_DATA_BYTE0 |
  302. (value & 0x000000FF);
  303. cx_write(MC417_RWD, regval);
  304. /* Transition CS/WR to effect write transaction across bus. */
  305. regval |= MC417_MICS | MC417_MIWR;
  306. cx_write(MC417_RWD, regval);
  307. /* Write data byte 1 */
  308. regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_DATA_BYTE1 |
  309. ((value >> 8) & 0x000000FF);
  310. cx_write(MC417_RWD, regval);
  311. regval |= MC417_MICS | MC417_MIWR;
  312. cx_write(MC417_RWD, regval);
  313. /* Write data byte 2 */
  314. regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_DATA_BYTE2 |
  315. ((value >> 16) & 0x000000FF);
  316. cx_write(MC417_RWD, regval);
  317. regval |= MC417_MICS | MC417_MIWR;
  318. cx_write(MC417_RWD, regval);
  319. /* Write data byte 3 */
  320. regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_DATA_BYTE3 |
  321. ((value >> 24) & 0x000000FF);
  322. cx_write(MC417_RWD, regval);
  323. regval |= MC417_MICS | MC417_MIWR;
  324. cx_write(MC417_RWD, regval);
  325. /* Write address byte 0 */
  326. regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_ADDRESS_BYTE0 |
  327. (address & 0xFF);
  328. cx_write(MC417_RWD, regval);
  329. regval |= MC417_MICS | MC417_MIWR;
  330. cx_write(MC417_RWD, regval);
  331. /* Write address byte 1 */
  332. regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_ADDRESS_BYTE1 |
  333. ((address >> 8) & 0xFF);
  334. cx_write(MC417_RWD, regval);
  335. regval |= MC417_MICS | MC417_MIWR;
  336. cx_write(MC417_RWD, regval);
  337. /* Indicate that this is a write. */
  338. regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_MODE |
  339. MCI_MODE_REGISTER_WRITE;
  340. cx_write(MC417_RWD, regval);
  341. regval |= MC417_MICS | MC417_MIWR;
  342. cx_write(MC417_RWD, regval);
  343. /* Wait for the trans to complete (MC417_MIRDY asserted). */
  344. return mc417_wait_ready(dev);
  345. }
  346. int mc417_register_read(struct cx23885_dev *dev, u16 address, u32 *value)
  347. {
  348. int retval;
  349. u32 regval;
  350. u32 tempval;
  351. u32 dataval;
  352. /* Enable MC417 GPIO outputs except for MC417_MIRDY,
  353. * which is an input.
  354. */
  355. cx_write(MC417_OEN, MC417_MIRDY);
  356. /* Write address byte 0 */
  357. regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_ADDRESS_BYTE0 |
  358. ((address & 0x00FF));
  359. cx_write(MC417_RWD, regval);
  360. regval |= MC417_MICS | MC417_MIWR;
  361. cx_write(MC417_RWD, regval);
  362. /* Write address byte 1 */
  363. regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_ADDRESS_BYTE1 |
  364. ((address >> 8) & 0xFF);
  365. cx_write(MC417_RWD, regval);
  366. regval |= MC417_MICS | MC417_MIWR;
  367. cx_write(MC417_RWD, regval);
  368. /* Indicate that this is a register read. */
  369. regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_MODE |
  370. MCI_MODE_REGISTER_READ;
  371. cx_write(MC417_RWD, regval);
  372. regval |= MC417_MICS | MC417_MIWR;
  373. cx_write(MC417_RWD, regval);
  374. /* Wait for the trans to complete (MC417_MIRDY asserted). */
  375. retval = mc417_wait_ready(dev);
  376. /* switch the DAT0-7 GPIO[10:3] to input mode */
  377. cx_write(MC417_OEN, MC417_MIRDY | MC417_MIDATA);
  378. /* Read data byte 0 */
  379. regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_DATA_BYTE0;
  380. cx_write(MC417_RWD, regval);
  381. /* Transition RD to effect read transaction across bus.
  382. * Transition 0x5000 -> 0x9000 correct (RD/RDY -> WR/RDY)?
  383. * Should it be 0x9000 -> 0xF000 (also why is RDY being set, its
  384. * input only...)
  385. */
  386. regval = MC417_MIWR | MC417_MIRDY | MCI_REGISTER_DATA_BYTE0;
  387. cx_write(MC417_RWD, regval);
  388. /* Collect byte */
  389. tempval = cx_read(MC417_RWD);
  390. dataval = tempval & 0x000000FF;
  391. /* Bring CS and RD high. */
  392. regval = MC417_MIWR | MC417_MIRD | MC417_MICS | MC417_MIRDY;
  393. cx_write(MC417_RWD, regval);
  394. /* Read data byte 1 */
  395. regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_DATA_BYTE1;
  396. cx_write(MC417_RWD, regval);
  397. regval = MC417_MIWR | MC417_MIRDY | MCI_REGISTER_DATA_BYTE1;
  398. cx_write(MC417_RWD, regval);
  399. tempval = cx_read(MC417_RWD);
  400. dataval |= ((tempval & 0x000000FF) << 8);
  401. regval = MC417_MIWR | MC417_MIRD | MC417_MICS | MC417_MIRDY;
  402. cx_write(MC417_RWD, regval);
  403. /* Read data byte 2 */
  404. regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_DATA_BYTE2;
  405. cx_write(MC417_RWD, regval);
  406. regval = MC417_MIWR | MC417_MIRDY | MCI_REGISTER_DATA_BYTE2;
  407. cx_write(MC417_RWD, regval);
  408. tempval = cx_read(MC417_RWD);
  409. dataval |= ((tempval & 0x000000FF) << 16);
  410. regval = MC417_MIWR | MC417_MIRD | MC417_MICS | MC417_MIRDY;
  411. cx_write(MC417_RWD, regval);
  412. /* Read data byte 3 */
  413. regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_DATA_BYTE3;
  414. cx_write(MC417_RWD, regval);
  415. regval = MC417_MIWR | MC417_MIRDY | MCI_REGISTER_DATA_BYTE3;
  416. cx_write(MC417_RWD, regval);
  417. tempval = cx_read(MC417_RWD);
  418. dataval |= ((tempval & 0x000000FF) << 24);
  419. regval = MC417_MIWR | MC417_MIRD | MC417_MICS | MC417_MIRDY;
  420. cx_write(MC417_RWD, regval);
  421. *value = dataval;
  422. return retval;
  423. }
  424. int mc417_memory_write(struct cx23885_dev *dev, u32 address, u32 value)
  425. {
  426. u32 regval;
  427. /* Enable MC417 GPIO outputs except for MC417_MIRDY,
  428. * which is an input.
  429. */
  430. cx_write(MC417_OEN, MC417_MIRDY);
  431. /* Write data byte 0 */
  432. regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_DATA_BYTE0 |
  433. (value & 0x000000FF);
  434. cx_write(MC417_RWD, regval);
  435. /* Transition CS/WR to effect write transaction across bus. */
  436. regval |= MC417_MICS | MC417_MIWR;
  437. cx_write(MC417_RWD, regval);
  438. /* Write data byte 1 */
  439. regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_DATA_BYTE1 |
  440. ((value >> 8) & 0x000000FF);
  441. cx_write(MC417_RWD, regval);
  442. regval |= MC417_MICS | MC417_MIWR;
  443. cx_write(MC417_RWD, regval);
  444. /* Write data byte 2 */
  445. regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_DATA_BYTE2 |
  446. ((value >> 16) & 0x000000FF);
  447. cx_write(MC417_RWD, regval);
  448. regval |= MC417_MICS | MC417_MIWR;
  449. cx_write(MC417_RWD, regval);
  450. /* Write data byte 3 */
  451. regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_DATA_BYTE3 |
  452. ((value >> 24) & 0x000000FF);
  453. cx_write(MC417_RWD, regval);
  454. regval |= MC417_MICS | MC417_MIWR;
  455. cx_write(MC417_RWD, regval);
  456. /* Write address byte 2 */
  457. regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_ADDRESS_BYTE2 |
  458. MCI_MODE_MEMORY_WRITE | ((address >> 16) & 0x3F);
  459. cx_write(MC417_RWD, regval);
  460. regval |= MC417_MICS | MC417_MIWR;
  461. cx_write(MC417_RWD, regval);
  462. /* Write address byte 1 */
  463. regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_ADDRESS_BYTE1 |
  464. ((address >> 8) & 0xFF);
  465. cx_write(MC417_RWD, regval);
  466. regval |= MC417_MICS | MC417_MIWR;
  467. cx_write(MC417_RWD, regval);
  468. /* Write address byte 0 */
  469. regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_ADDRESS_BYTE0 |
  470. (address & 0xFF);
  471. cx_write(MC417_RWD, regval);
  472. regval |= MC417_MICS | MC417_MIWR;
  473. cx_write(MC417_RWD, regval);
  474. /* Wait for the trans to complete (MC417_MIRDY asserted). */
  475. return mc417_wait_ready(dev);
  476. }
  477. int mc417_memory_read(struct cx23885_dev *dev, u32 address, u32 *value)
  478. {
  479. int retval;
  480. u32 regval;
  481. u32 tempval;
  482. u32 dataval;
  483. /* Enable MC417 GPIO outputs except for MC417_MIRDY,
  484. * which is an input.
  485. */
  486. cx_write(MC417_OEN, MC417_MIRDY);
  487. /* Write address byte 2 */
  488. regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_ADDRESS_BYTE2 |
  489. MCI_MODE_MEMORY_READ | ((address >> 16) & 0x3F);
  490. cx_write(MC417_RWD, regval);
  491. regval |= MC417_MICS | MC417_MIWR;
  492. cx_write(MC417_RWD, regval);
  493. /* Write address byte 1 */
  494. regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_ADDRESS_BYTE1 |
  495. ((address >> 8) & 0xFF);
  496. cx_write(MC417_RWD, regval);
  497. regval |= MC417_MICS | MC417_MIWR;
  498. cx_write(MC417_RWD, regval);
  499. /* Write address byte 0 */
  500. regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_ADDRESS_BYTE0 |
  501. (address & 0xFF);
  502. cx_write(MC417_RWD, regval);
  503. regval |= MC417_MICS | MC417_MIWR;
  504. cx_write(MC417_RWD, regval);
  505. /* Wait for the trans to complete (MC417_MIRDY asserted). */
  506. retval = mc417_wait_ready(dev);
  507. /* switch the DAT0-7 GPIO[10:3] to input mode */
  508. cx_write(MC417_OEN, MC417_MIRDY | MC417_MIDATA);
  509. /* Read data byte 3 */
  510. regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_DATA_BYTE3;
  511. cx_write(MC417_RWD, regval);
  512. /* Transition RD to effect read transaction across bus. */
  513. regval = MC417_MIWR | MC417_MIRDY | MCI_MEMORY_DATA_BYTE3;
  514. cx_write(MC417_RWD, regval);
  515. /* Collect byte */
  516. tempval = cx_read(MC417_RWD);
  517. dataval = ((tempval & 0x000000FF) << 24);
  518. /* Bring CS and RD high. */
  519. regval = MC417_MIWR | MC417_MIRD | MC417_MICS | MC417_MIRDY;
  520. cx_write(MC417_RWD, regval);
  521. /* Read data byte 2 */
  522. regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_DATA_BYTE2;
  523. cx_write(MC417_RWD, regval);
  524. regval = MC417_MIWR | MC417_MIRDY | MCI_MEMORY_DATA_BYTE2;
  525. cx_write(MC417_RWD, regval);
  526. tempval = cx_read(MC417_RWD);
  527. dataval |= ((tempval & 0x000000FF) << 16);
  528. regval = MC417_MIWR | MC417_MIRD | MC417_MICS | MC417_MIRDY;
  529. cx_write(MC417_RWD, regval);
  530. /* Read data byte 1 */
  531. regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_DATA_BYTE1;
  532. cx_write(MC417_RWD, regval);
  533. regval = MC417_MIWR | MC417_MIRDY | MCI_MEMORY_DATA_BYTE1;
  534. cx_write(MC417_RWD, regval);
  535. tempval = cx_read(MC417_RWD);
  536. dataval |= ((tempval & 0x000000FF) << 8);
  537. regval = MC417_MIWR | MC417_MIRD | MC417_MICS | MC417_MIRDY;
  538. cx_write(MC417_RWD, regval);
  539. /* Read data byte 0 */
  540. regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_DATA_BYTE0;
  541. cx_write(MC417_RWD, regval);
  542. regval = MC417_MIWR | MC417_MIRDY | MCI_MEMORY_DATA_BYTE0;
  543. cx_write(MC417_RWD, regval);
  544. tempval = cx_read(MC417_RWD);
  545. dataval |= (tempval & 0x000000FF);
  546. regval = MC417_MIWR | MC417_MIRD | MC417_MICS | MC417_MIRDY;
  547. cx_write(MC417_RWD, regval);
  548. *value = dataval;
  549. return retval;
  550. }
  551. void mc417_gpio_set(struct cx23885_dev *dev, u32 mask)
  552. {
  553. u32 val;
  554. /* Set the gpio value */
  555. mc417_register_read(dev, 0x900C, &val);
  556. val |= (mask & 0x000ffff);
  557. mc417_register_write(dev, 0x900C, val);
  558. }
  559. void mc417_gpio_clear(struct cx23885_dev *dev, u32 mask)
  560. {
  561. u32 val;
  562. /* Clear the gpio value */
  563. mc417_register_read(dev, 0x900C, &val);
  564. val &= ~(mask & 0x0000ffff);
  565. mc417_register_write(dev, 0x900C, val);
  566. }
  567. void mc417_gpio_enable(struct cx23885_dev *dev, u32 mask, int asoutput)
  568. {
  569. u32 val;
  570. /* Enable GPIO direction bits */
  571. mc417_register_read(dev, 0x9020, &val);
  572. if (asoutput)
  573. val |= (mask & 0x0000ffff);
  574. else
  575. val &= ~(mask & 0x0000ffff);
  576. mc417_register_write(dev, 0x9020, val);
  577. }
  578. /* ------------------------------------------------------------------ */
  579. /* MPEG encoder API */
  580. static char *cmd_to_str(int cmd)
  581. {
  582. switch (cmd) {
  583. case CX2341X_ENC_PING_FW:
  584. return "PING_FW";
  585. case CX2341X_ENC_START_CAPTURE:
  586. return "START_CAPTURE";
  587. case CX2341X_ENC_STOP_CAPTURE:
  588. return "STOP_CAPTURE";
  589. case CX2341X_ENC_SET_AUDIO_ID:
  590. return "SET_AUDIO_ID";
  591. case CX2341X_ENC_SET_VIDEO_ID:
  592. return "SET_VIDEO_ID";
  593. case CX2341X_ENC_SET_PCR_ID:
  594. return "SET_PCR_ID";
  595. case CX2341X_ENC_SET_FRAME_RATE:
  596. return "SET_FRAME_RATE";
  597. case CX2341X_ENC_SET_FRAME_SIZE:
  598. return "SET_FRAME_SIZE";
  599. case CX2341X_ENC_SET_BIT_RATE:
  600. return "SET_BIT_RATE";
  601. case CX2341X_ENC_SET_GOP_PROPERTIES:
  602. return "SET_GOP_PROPERTIES";
  603. case CX2341X_ENC_SET_ASPECT_RATIO:
  604. return "SET_ASPECT_RATIO";
  605. case CX2341X_ENC_SET_DNR_FILTER_MODE:
  606. return "SET_DNR_FILTER_MODE";
  607. case CX2341X_ENC_SET_DNR_FILTER_PROPS:
  608. return "SET_DNR_FILTER_PROPS";
  609. case CX2341X_ENC_SET_CORING_LEVELS:
  610. return "SET_CORING_LEVELS";
  611. case CX2341X_ENC_SET_SPATIAL_FILTER_TYPE:
  612. return "SET_SPATIAL_FILTER_TYPE";
  613. case CX2341X_ENC_SET_VBI_LINE:
  614. return "SET_VBI_LINE";
  615. case CX2341X_ENC_SET_STREAM_TYPE:
  616. return "SET_STREAM_TYPE";
  617. case CX2341X_ENC_SET_OUTPUT_PORT:
  618. return "SET_OUTPUT_PORT";
  619. case CX2341X_ENC_SET_AUDIO_PROPERTIES:
  620. return "SET_AUDIO_PROPERTIES";
  621. case CX2341X_ENC_HALT_FW:
  622. return "HALT_FW";
  623. case CX2341X_ENC_GET_VERSION:
  624. return "GET_VERSION";
  625. case CX2341X_ENC_SET_GOP_CLOSURE:
  626. return "SET_GOP_CLOSURE";
  627. case CX2341X_ENC_GET_SEQ_END:
  628. return "GET_SEQ_END";
  629. case CX2341X_ENC_SET_PGM_INDEX_INFO:
  630. return "SET_PGM_INDEX_INFO";
  631. case CX2341X_ENC_SET_VBI_CONFIG:
  632. return "SET_VBI_CONFIG";
  633. case CX2341X_ENC_SET_DMA_BLOCK_SIZE:
  634. return "SET_DMA_BLOCK_SIZE";
  635. case CX2341X_ENC_GET_PREV_DMA_INFO_MB_10:
  636. return "GET_PREV_DMA_INFO_MB_10";
  637. case CX2341X_ENC_GET_PREV_DMA_INFO_MB_9:
  638. return "GET_PREV_DMA_INFO_MB_9";
  639. case CX2341X_ENC_SCHED_DMA_TO_HOST:
  640. return "SCHED_DMA_TO_HOST";
  641. case CX2341X_ENC_INITIALIZE_INPUT:
  642. return "INITIALIZE_INPUT";
  643. case CX2341X_ENC_SET_FRAME_DROP_RATE:
  644. return "SET_FRAME_DROP_RATE";
  645. case CX2341X_ENC_PAUSE_ENCODER:
  646. return "PAUSE_ENCODER";
  647. case CX2341X_ENC_REFRESH_INPUT:
  648. return "REFRESH_INPUT";
  649. case CX2341X_ENC_SET_COPYRIGHT:
  650. return "SET_COPYRIGHT";
  651. case CX2341X_ENC_SET_EVENT_NOTIFICATION:
  652. return "SET_EVENT_NOTIFICATION";
  653. case CX2341X_ENC_SET_NUM_VSYNC_LINES:
  654. return "SET_NUM_VSYNC_LINES";
  655. case CX2341X_ENC_SET_PLACEHOLDER:
  656. return "SET_PLACEHOLDER";
  657. case CX2341X_ENC_MUTE_VIDEO:
  658. return "MUTE_VIDEO";
  659. case CX2341X_ENC_MUTE_AUDIO:
  660. return "MUTE_AUDIO";
  661. case CX2341X_ENC_MISC:
  662. return "MISC";
  663. default:
  664. return "UNKNOWN";
  665. }
  666. }
  667. static int cx23885_mbox_func(void *priv,
  668. u32 command,
  669. int in,
  670. int out,
  671. u32 data[CX2341X_MBOX_MAX_DATA])
  672. {
  673. struct cx23885_dev *dev = priv;
  674. unsigned long timeout;
  675. u32 value, flag, retval = 0;
  676. int i;
  677. dprintk(3, "%s: command(0x%X) = %s\n", __func__, command,
  678. cmd_to_str(command));
  679. /* this may not be 100% safe if we can't read any memory location
  680. without side effects */
  681. mc417_memory_read(dev, dev->cx23417_mailbox - 4, &value);
  682. if (value != 0x12345678) {
  683. pr_err("Firmware and/or mailbox pointer not initialized or corrupted, signature = 0x%x, cmd = %s\n",
  684. value, cmd_to_str(command));
  685. return -1;
  686. }
  687. /* This read looks at 32 bits, but flag is only 8 bits.
  688. * Seems we also bail if CMD or TIMEOUT bytes are set???
  689. */
  690. mc417_memory_read(dev, dev->cx23417_mailbox, &flag);
  691. if (flag) {
  692. pr_err("ERROR: Mailbox appears to be in use (%x), cmd = %s\n",
  693. flag, cmd_to_str(command));
  694. return -1;
  695. }
  696. flag |= 1; /* tell 'em we're working on it */
  697. mc417_memory_write(dev, dev->cx23417_mailbox, flag);
  698. /* write command + args + fill remaining with zeros */
  699. /* command code */
  700. mc417_memory_write(dev, dev->cx23417_mailbox + 1, command);
  701. mc417_memory_write(dev, dev->cx23417_mailbox + 3,
  702. IVTV_API_STD_TIMEOUT); /* timeout */
  703. for (i = 0; i < in; i++) {
  704. mc417_memory_write(dev, dev->cx23417_mailbox + 4 + i, data[i]);
  705. dprintk(3, "API Input %d = %d\n", i, data[i]);
  706. }
  707. for (; i < CX2341X_MBOX_MAX_DATA; i++)
  708. mc417_memory_write(dev, dev->cx23417_mailbox + 4 + i, 0);
  709. flag |= 3; /* tell 'em we're done writing */
  710. mc417_memory_write(dev, dev->cx23417_mailbox, flag);
  711. /* wait for firmware to handle the API command */
  712. timeout = jiffies + msecs_to_jiffies(10);
  713. for (;;) {
  714. mc417_memory_read(dev, dev->cx23417_mailbox, &flag);
  715. if (0 != (flag & 4))
  716. break;
  717. if (time_after(jiffies, timeout)) {
  718. pr_err("ERROR: API Mailbox timeout\n");
  719. return -1;
  720. }
  721. udelay(10);
  722. }
  723. /* read output values */
  724. for (i = 0; i < out; i++) {
  725. mc417_memory_read(dev, dev->cx23417_mailbox + 4 + i, data + i);
  726. dprintk(3, "API Output %d = %d\n", i, data[i]);
  727. }
  728. mc417_memory_read(dev, dev->cx23417_mailbox + 2, &retval);
  729. dprintk(3, "API result = %d\n", retval);
  730. flag = 0;
  731. mc417_memory_write(dev, dev->cx23417_mailbox, flag);
  732. return retval;
  733. }
  734. /* We don't need to call the API often, so using just one
  735. * mailbox will probably suffice
  736. */
  737. static int cx23885_api_cmd(struct cx23885_dev *dev,
  738. u32 command,
  739. u32 inputcnt,
  740. u32 outputcnt,
  741. ...)
  742. {
  743. u32 data[CX2341X_MBOX_MAX_DATA];
  744. va_list vargs;
  745. int i, err;
  746. dprintk(3, "%s() cmds = 0x%08x\n", __func__, command);
  747. va_start(vargs, outputcnt);
  748. for (i = 0; i < inputcnt; i++)
  749. data[i] = va_arg(vargs, int);
  750. err = cx23885_mbox_func(dev, command, inputcnt, outputcnt, data);
  751. for (i = 0; i < outputcnt; i++) {
  752. int *vptr = va_arg(vargs, int *);
  753. *vptr = data[i];
  754. }
  755. va_end(vargs);
  756. return err;
  757. }
  758. static int cx23885_api_func(void *priv, u32 cmd, int in, int out, u32 data[CX2341X_MBOX_MAX_DATA])
  759. {
  760. return cx23885_mbox_func(priv, cmd, in, out, data);
  761. }
  762. static int cx23885_find_mailbox(struct cx23885_dev *dev)
  763. {
  764. u32 signature[4] = {
  765. 0x12345678, 0x34567812, 0x56781234, 0x78123456
  766. };
  767. int signaturecnt = 0;
  768. u32 value;
  769. int i;
  770. dprintk(2, "%s()\n", __func__);
  771. for (i = 0; i < CX23885_FIRM_IMAGE_SIZE; i++) {
  772. mc417_memory_read(dev, i, &value);
  773. if (value == signature[signaturecnt])
  774. signaturecnt++;
  775. else
  776. signaturecnt = 0;
  777. if (4 == signaturecnt) {
  778. dprintk(1, "Mailbox signature found at 0x%x\n", i+1);
  779. return i+1;
  780. }
  781. }
  782. pr_err("Mailbox signature values not found!\n");
  783. return -1;
  784. }
  785. static int cx23885_load_firmware(struct cx23885_dev *dev)
  786. {
  787. static const unsigned char magic[8] = {
  788. 0xa7, 0x0d, 0x00, 0x00, 0x66, 0xbb, 0x55, 0xaa
  789. };
  790. const struct firmware *firmware;
  791. int i, retval = 0;
  792. u32 value = 0;
  793. u32 gpio_output = 0;
  794. u32 gpio_value;
  795. u32 checksum = 0;
  796. u32 *dataptr;
  797. dprintk(2, "%s()\n", __func__);
  798. /* Save GPIO settings before reset of APU */
  799. retval |= mc417_memory_read(dev, 0x9020, &gpio_output);
  800. retval |= mc417_memory_read(dev, 0x900C, &gpio_value);
  801. retval = mc417_register_write(dev,
  802. IVTV_REG_VPU, 0xFFFFFFED);
  803. retval |= mc417_register_write(dev,
  804. IVTV_REG_HW_BLOCKS, IVTV_CMD_HW_BLOCKS_RST);
  805. retval |= mc417_register_write(dev,
  806. IVTV_REG_ENC_SDRAM_REFRESH, 0x80000800);
  807. retval |= mc417_register_write(dev,
  808. IVTV_REG_ENC_SDRAM_PRECHARGE, 0x1A);
  809. retval |= mc417_register_write(dev,
  810. IVTV_REG_APU, 0);
  811. if (retval != 0) {
  812. pr_err("%s: Error with mc417_register_write\n",
  813. __func__);
  814. return -1;
  815. }
  816. retval = request_firmware(&firmware, CX23885_FIRM_IMAGE_NAME,
  817. &dev->pci->dev);
  818. if (retval != 0)
  819. return -1;
  820. if (firmware->size != CX23885_FIRM_IMAGE_SIZE) {
  821. pr_err("ERROR: Firmware size mismatch (have %zu, expected %d)\n",
  822. firmware->size, CX23885_FIRM_IMAGE_SIZE);
  823. release_firmware(firmware);
  824. return -1;
  825. }
  826. if (0 != memcmp(firmware->data, magic, 8)) {
  827. pr_err("ERROR: Firmware magic mismatch, wrong file?\n");
  828. release_firmware(firmware);
  829. return -1;
  830. }
  831. /* transfer to the chip */
  832. dprintk(2, "Loading firmware ...\n");
  833. dataptr = (u32 *)firmware->data;
  834. for (i = 0; i < (firmware->size >> 2); i++) {
  835. value = *dataptr;
  836. checksum += ~value;
  837. if (mc417_memory_write(dev, i, value) != 0) {
  838. pr_err("ERROR: Loading firmware failed!\n");
  839. release_firmware(firmware);
  840. return -1;
  841. }
  842. dataptr++;
  843. }
  844. /* read back to verify with the checksum */
  845. dprintk(1, "Verifying firmware ...\n");
  846. for (i--; i >= 0; i--) {
  847. if (mc417_memory_read(dev, i, &value) != 0) {
  848. pr_err("ERROR: Reading firmware failed!\n");
  849. release_firmware(firmware);
  850. return -1;
  851. }
  852. checksum -= ~value;
  853. }
  854. if (checksum) {
  855. pr_err("ERROR: Firmware load failed (checksum mismatch).\n");
  856. release_firmware(firmware);
  857. return -1;
  858. }
  859. release_firmware(firmware);
  860. dprintk(1, "Firmware upload successful.\n");
  861. retval |= mc417_register_write(dev, IVTV_REG_HW_BLOCKS,
  862. IVTV_CMD_HW_BLOCKS_RST);
  863. /* F/W power up disturbs the GPIOs, restore state */
  864. retval |= mc417_register_write(dev, 0x9020, gpio_output);
  865. retval |= mc417_register_write(dev, 0x900C, gpio_value);
  866. retval |= mc417_register_read(dev, IVTV_REG_VPU, &value);
  867. retval |= mc417_register_write(dev, IVTV_REG_VPU, value & 0xFFFFFFE8);
  868. /* Hardcoded GPIO's here */
  869. retval |= mc417_register_write(dev, 0x9020, 0x4000);
  870. retval |= mc417_register_write(dev, 0x900C, 0x4000);
  871. mc417_register_read(dev, 0x9020, &gpio_output);
  872. mc417_register_read(dev, 0x900C, &gpio_value);
  873. if (retval < 0)
  874. pr_err("%s: Error with mc417_register_write\n",
  875. __func__);
  876. return 0;
  877. }
  878. void cx23885_417_check_encoder(struct cx23885_dev *dev)
  879. {
  880. u32 status, seq;
  881. status = seq = 0;
  882. cx23885_api_cmd(dev, CX2341X_ENC_GET_SEQ_END, 0, 2, &status, &seq);
  883. dprintk(1, "%s() status = %d, seq = %d\n", __func__, status, seq);
  884. }
  885. static void cx23885_codec_settings(struct cx23885_dev *dev)
  886. {
  887. dprintk(1, "%s()\n", __func__);
  888. /* Dynamically change the height based on video standard */
  889. if (dev->encodernorm.id & V4L2_STD_525_60)
  890. dev->ts1.height = 480;
  891. else
  892. dev->ts1.height = 576;
  893. /* assign frame size */
  894. cx23885_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0,
  895. dev->ts1.height, dev->ts1.width);
  896. dev->cxhdl.width = dev->ts1.width;
  897. dev->cxhdl.height = dev->ts1.height;
  898. dev->cxhdl.is_50hz =
  899. (dev->encodernorm.id & V4L2_STD_625_50) != 0;
  900. cx2341x_handler_setup(&dev->cxhdl);
  901. cx23885_api_cmd(dev, CX2341X_ENC_MISC, 2, 0, 3, 1);
  902. cx23885_api_cmd(dev, CX2341X_ENC_MISC, 2, 0, 4, 1);
  903. }
  904. static int cx23885_initialize_codec(struct cx23885_dev *dev, int startencoder)
  905. {
  906. int version;
  907. int retval;
  908. u32 i, data[7];
  909. dprintk(1, "%s()\n", __func__);
  910. retval = cx23885_api_cmd(dev, CX2341X_ENC_PING_FW, 0, 0); /* ping */
  911. if (retval < 0) {
  912. dprintk(2, "%s() PING OK\n", __func__);
  913. retval = cx23885_load_firmware(dev);
  914. if (retval < 0) {
  915. pr_err("%s() f/w load failed\n", __func__);
  916. return retval;
  917. }
  918. retval = cx23885_find_mailbox(dev);
  919. if (retval < 0) {
  920. pr_err("%s() mailbox < 0, error\n",
  921. __func__);
  922. return -1;
  923. }
  924. dev->cx23417_mailbox = retval;
  925. retval = cx23885_api_cmd(dev, CX2341X_ENC_PING_FW, 0, 0);
  926. if (retval < 0) {
  927. pr_err("ERROR: cx23417 firmware ping failed!\n");
  928. return -1;
  929. }
  930. retval = cx23885_api_cmd(dev, CX2341X_ENC_GET_VERSION, 0, 1,
  931. &version);
  932. if (retval < 0) {
  933. pr_err("ERROR: cx23417 firmware get encoder :version failed!\n");
  934. return -1;
  935. }
  936. dprintk(1, "cx23417 firmware version is 0x%08x\n", version);
  937. msleep(200);
  938. }
  939. cx23885_codec_settings(dev);
  940. msleep(60);
  941. cx23885_api_cmd(dev, CX2341X_ENC_SET_NUM_VSYNC_LINES, 2, 0,
  942. CX23885_FIELD1_SAA7115, CX23885_FIELD2_SAA7115);
  943. cx23885_api_cmd(dev, CX2341X_ENC_SET_PLACEHOLDER, 12, 0,
  944. CX23885_CUSTOM_EXTENSION_USR_DATA, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  945. 0, 0);
  946. /* Setup to capture VBI */
  947. data[0] = 0x0001BD00;
  948. data[1] = 1; /* frames per interrupt */
  949. data[2] = 4; /* total bufs */
  950. data[3] = 0x91559155; /* start codes */
  951. data[4] = 0x206080C0; /* stop codes */
  952. data[5] = 6; /* lines */
  953. data[6] = 64; /* BPL */
  954. cx23885_api_cmd(dev, CX2341X_ENC_SET_VBI_CONFIG, 7, 0, data[0], data[1],
  955. data[2], data[3], data[4], data[5], data[6]);
  956. for (i = 2; i <= 24; i++) {
  957. int valid;
  958. valid = ((i >= 19) && (i <= 21));
  959. cx23885_api_cmd(dev, CX2341X_ENC_SET_VBI_LINE, 5, 0, i,
  960. valid, 0 , 0, 0);
  961. cx23885_api_cmd(dev, CX2341X_ENC_SET_VBI_LINE, 5, 0,
  962. i | 0x80000000, valid, 0, 0, 0);
  963. }
  964. cx23885_api_cmd(dev, CX2341X_ENC_MUTE_AUDIO, 1, 0, CX23885_UNMUTE);
  965. msleep(60);
  966. /* initialize the video input */
  967. cx23885_api_cmd(dev, CX2341X_ENC_INITIALIZE_INPUT, 0, 0);
  968. msleep(60);
  969. /* Enable VIP style pixel invalidation so we work with scaled mode */
  970. mc417_memory_write(dev, 2120, 0x00000080);
  971. /* start capturing to the host interface */
  972. if (startencoder) {
  973. cx23885_api_cmd(dev, CX2341X_ENC_START_CAPTURE, 2, 0,
  974. CX23885_MPEG_CAPTURE, CX23885_RAW_BITS_NONE);
  975. msleep(10);
  976. }
  977. return 0;
  978. }
  979. /* ------------------------------------------------------------------ */
  980. static int queue_setup(struct vb2_queue *q,
  981. unsigned int *num_buffers, unsigned int *num_planes,
  982. unsigned int sizes[], struct device *alloc_devs[])
  983. {
  984. struct cx23885_dev *dev = q->drv_priv;
  985. dev->ts1.ts_packet_size = mpeglinesize;
  986. dev->ts1.ts_packet_count = mpeglines;
  987. *num_planes = 1;
  988. sizes[0] = mpeglinesize * mpeglines;
  989. *num_buffers = mpegbufs;
  990. return 0;
  991. }
  992. static int buffer_prepare(struct vb2_buffer *vb)
  993. {
  994. struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
  995. struct cx23885_dev *dev = vb->vb2_queue->drv_priv;
  996. struct cx23885_buffer *buf =
  997. container_of(vbuf, struct cx23885_buffer, vb);
  998. return cx23885_buf_prepare(buf, &dev->ts1);
  999. }
  1000. static void buffer_finish(struct vb2_buffer *vb)
  1001. {
  1002. struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
  1003. struct cx23885_dev *dev = vb->vb2_queue->drv_priv;
  1004. struct cx23885_buffer *buf = container_of(vbuf,
  1005. struct cx23885_buffer, vb);
  1006. cx23885_free_buffer(dev, buf);
  1007. }
  1008. static void buffer_queue(struct vb2_buffer *vb)
  1009. {
  1010. struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
  1011. struct cx23885_dev *dev = vb->vb2_queue->drv_priv;
  1012. struct cx23885_buffer *buf = container_of(vbuf,
  1013. struct cx23885_buffer, vb);
  1014. cx23885_buf_queue(&dev->ts1, buf);
  1015. }
  1016. static int cx23885_start_streaming(struct vb2_queue *q, unsigned int count)
  1017. {
  1018. struct cx23885_dev *dev = q->drv_priv;
  1019. struct cx23885_dmaqueue *dmaq = &dev->ts1.mpegq;
  1020. unsigned long flags;
  1021. int ret;
  1022. ret = cx23885_initialize_codec(dev, 1);
  1023. if (ret == 0) {
  1024. struct cx23885_buffer *buf = list_entry(dmaq->active.next,
  1025. struct cx23885_buffer, queue);
  1026. cx23885_start_dma(&dev->ts1, dmaq, buf);
  1027. return 0;
  1028. }
  1029. spin_lock_irqsave(&dev->slock, flags);
  1030. while (!list_empty(&dmaq->active)) {
  1031. struct cx23885_buffer *buf = list_entry(dmaq->active.next,
  1032. struct cx23885_buffer, queue);
  1033. list_del(&buf->queue);
  1034. vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_QUEUED);
  1035. }
  1036. spin_unlock_irqrestore(&dev->slock, flags);
  1037. return ret;
  1038. }
  1039. static void cx23885_stop_streaming(struct vb2_queue *q)
  1040. {
  1041. struct cx23885_dev *dev = q->drv_priv;
  1042. /* stop mpeg capture */
  1043. cx23885_api_cmd(dev, CX2341X_ENC_STOP_CAPTURE, 3, 0,
  1044. CX23885_END_NOW, CX23885_MPEG_CAPTURE,
  1045. CX23885_RAW_BITS_NONE);
  1046. msleep(500);
  1047. cx23885_417_check_encoder(dev);
  1048. cx23885_cancel_buffers(&dev->ts1);
  1049. }
  1050. static const struct vb2_ops cx23885_qops = {
  1051. .queue_setup = queue_setup,
  1052. .buf_prepare = buffer_prepare,
  1053. .buf_finish = buffer_finish,
  1054. .buf_queue = buffer_queue,
  1055. .wait_prepare = vb2_ops_wait_prepare,
  1056. .wait_finish = vb2_ops_wait_finish,
  1057. .start_streaming = cx23885_start_streaming,
  1058. .stop_streaming = cx23885_stop_streaming,
  1059. };
  1060. /* ------------------------------------------------------------------ */
  1061. static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id)
  1062. {
  1063. struct cx23885_dev *dev = video_drvdata(file);
  1064. *id = dev->tvnorm;
  1065. return 0;
  1066. }
  1067. static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id)
  1068. {
  1069. struct cx23885_dev *dev = video_drvdata(file);
  1070. unsigned int i;
  1071. int ret;
  1072. for (i = 0; i < ARRAY_SIZE(cx23885_tvnorms); i++)
  1073. if (id & cx23885_tvnorms[i].id)
  1074. break;
  1075. if (i == ARRAY_SIZE(cx23885_tvnorms))
  1076. return -EINVAL;
  1077. ret = cx23885_set_tvnorm(dev, id);
  1078. if (!ret)
  1079. dev->encodernorm = cx23885_tvnorms[i];
  1080. return ret;
  1081. }
  1082. static int vidioc_enum_input(struct file *file, void *priv,
  1083. struct v4l2_input *i)
  1084. {
  1085. struct cx23885_dev *dev = video_drvdata(file);
  1086. dprintk(1, "%s()\n", __func__);
  1087. return cx23885_enum_input(dev, i);
  1088. }
  1089. static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  1090. {
  1091. return cx23885_get_input(file, priv, i);
  1092. }
  1093. static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
  1094. {
  1095. return cx23885_set_input(file, priv, i);
  1096. }
  1097. static int vidioc_g_tuner(struct file *file, void *priv,
  1098. struct v4l2_tuner *t)
  1099. {
  1100. struct cx23885_dev *dev = video_drvdata(file);
  1101. if (dev->tuner_type == TUNER_ABSENT)
  1102. return -EINVAL;
  1103. if (0 != t->index)
  1104. return -EINVAL;
  1105. strcpy(t->name, "Television");
  1106. call_all(dev, tuner, g_tuner, t);
  1107. dprintk(1, "VIDIOC_G_TUNER: tuner type %d\n", t->type);
  1108. return 0;
  1109. }
  1110. static int vidioc_s_tuner(struct file *file, void *priv,
  1111. const struct v4l2_tuner *t)
  1112. {
  1113. struct cx23885_dev *dev = video_drvdata(file);
  1114. if (dev->tuner_type == TUNER_ABSENT)
  1115. return -EINVAL;
  1116. /* Update the A/V core */
  1117. call_all(dev, tuner, s_tuner, t);
  1118. return 0;
  1119. }
  1120. static int vidioc_g_frequency(struct file *file, void *priv,
  1121. struct v4l2_frequency *f)
  1122. {
  1123. struct cx23885_dev *dev = video_drvdata(file);
  1124. if (dev->tuner_type == TUNER_ABSENT)
  1125. return -EINVAL;
  1126. f->type = V4L2_TUNER_ANALOG_TV;
  1127. f->frequency = dev->freq;
  1128. call_all(dev, tuner, g_frequency, f);
  1129. return 0;
  1130. }
  1131. static int vidioc_s_frequency(struct file *file, void *priv,
  1132. const struct v4l2_frequency *f)
  1133. {
  1134. return cx23885_set_frequency(file, priv, f);
  1135. }
  1136. static int vidioc_querycap(struct file *file, void *priv,
  1137. struct v4l2_capability *cap)
  1138. {
  1139. struct cx23885_dev *dev = video_drvdata(file);
  1140. struct cx23885_tsport *tsport = &dev->ts1;
  1141. strlcpy(cap->driver, dev->name, sizeof(cap->driver));
  1142. strlcpy(cap->card, cx23885_boards[tsport->dev->board].name,
  1143. sizeof(cap->card));
  1144. sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci));
  1145. cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
  1146. V4L2_CAP_STREAMING;
  1147. if (dev->tuner_type != TUNER_ABSENT)
  1148. cap->device_caps |= V4L2_CAP_TUNER;
  1149. cap->capabilities = cap->device_caps | V4L2_CAP_VBI_CAPTURE |
  1150. V4L2_CAP_AUDIO | V4L2_CAP_DEVICE_CAPS;
  1151. return 0;
  1152. }
  1153. static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
  1154. struct v4l2_fmtdesc *f)
  1155. {
  1156. if (f->index != 0)
  1157. return -EINVAL;
  1158. strlcpy(f->description, "MPEG", sizeof(f->description));
  1159. f->pixelformat = V4L2_PIX_FMT_MPEG;
  1160. return 0;
  1161. }
  1162. static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
  1163. struct v4l2_format *f)
  1164. {
  1165. struct cx23885_dev *dev = video_drvdata(file);
  1166. f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
  1167. f->fmt.pix.bytesperline = 0;
  1168. f->fmt.pix.sizeimage =
  1169. dev->ts1.ts_packet_size * dev->ts1.ts_packet_count;
  1170. f->fmt.pix.colorspace = 0;
  1171. f->fmt.pix.width = dev->ts1.width;
  1172. f->fmt.pix.height = dev->ts1.height;
  1173. f->fmt.pix.field = V4L2_FIELD_INTERLACED;
  1174. dprintk(1, "VIDIOC_G_FMT: w: %d, h: %d\n",
  1175. dev->ts1.width, dev->ts1.height);
  1176. return 0;
  1177. }
  1178. static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
  1179. struct v4l2_format *f)
  1180. {
  1181. struct cx23885_dev *dev = video_drvdata(file);
  1182. f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
  1183. f->fmt.pix.bytesperline = 0;
  1184. f->fmt.pix.sizeimage =
  1185. dev->ts1.ts_packet_size * dev->ts1.ts_packet_count;
  1186. f->fmt.pix.colorspace = 0;
  1187. f->fmt.pix.field = V4L2_FIELD_INTERLACED;
  1188. dprintk(1, "VIDIOC_TRY_FMT: w: %d, h: %d\n",
  1189. dev->ts1.width, dev->ts1.height);
  1190. return 0;
  1191. }
  1192. static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
  1193. struct v4l2_format *f)
  1194. {
  1195. struct cx23885_dev *dev = video_drvdata(file);
  1196. f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
  1197. f->fmt.pix.bytesperline = 0;
  1198. f->fmt.pix.sizeimage =
  1199. dev->ts1.ts_packet_size * dev->ts1.ts_packet_count;
  1200. f->fmt.pix.colorspace = 0;
  1201. f->fmt.pix.field = V4L2_FIELD_INTERLACED;
  1202. dprintk(1, "VIDIOC_S_FMT: w: %d, h: %d, f: %d\n",
  1203. f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.field);
  1204. return 0;
  1205. }
  1206. static int vidioc_log_status(struct file *file, void *priv)
  1207. {
  1208. struct cx23885_dev *dev = video_drvdata(file);
  1209. char name[32 + 2];
  1210. snprintf(name, sizeof(name), "%s/2", dev->name);
  1211. call_all(dev, core, log_status);
  1212. v4l2_ctrl_handler_log_status(&dev->cxhdl.hdl, name);
  1213. return 0;
  1214. }
  1215. static const struct v4l2_file_operations mpeg_fops = {
  1216. .owner = THIS_MODULE,
  1217. .open = v4l2_fh_open,
  1218. .release = vb2_fop_release,
  1219. .read = vb2_fop_read,
  1220. .poll = vb2_fop_poll,
  1221. .unlocked_ioctl = video_ioctl2,
  1222. .mmap = vb2_fop_mmap,
  1223. };
  1224. static const struct v4l2_ioctl_ops mpeg_ioctl_ops = {
  1225. .vidioc_g_std = vidioc_g_std,
  1226. .vidioc_s_std = vidioc_s_std,
  1227. .vidioc_enum_input = vidioc_enum_input,
  1228. .vidioc_g_input = vidioc_g_input,
  1229. .vidioc_s_input = vidioc_s_input,
  1230. .vidioc_g_tuner = vidioc_g_tuner,
  1231. .vidioc_s_tuner = vidioc_s_tuner,
  1232. .vidioc_g_frequency = vidioc_g_frequency,
  1233. .vidioc_s_frequency = vidioc_s_frequency,
  1234. .vidioc_querycap = vidioc_querycap,
  1235. .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  1236. .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  1237. .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  1238. .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  1239. .vidioc_reqbufs = vb2_ioctl_reqbufs,
  1240. .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  1241. .vidioc_querybuf = vb2_ioctl_querybuf,
  1242. .vidioc_qbuf = vb2_ioctl_qbuf,
  1243. .vidioc_dqbuf = vb2_ioctl_dqbuf,
  1244. .vidioc_streamon = vb2_ioctl_streamon,
  1245. .vidioc_streamoff = vb2_ioctl_streamoff,
  1246. .vidioc_log_status = vidioc_log_status,
  1247. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1248. .vidioc_g_chip_info = cx23885_g_chip_info,
  1249. .vidioc_g_register = cx23885_g_register,
  1250. .vidioc_s_register = cx23885_s_register,
  1251. #endif
  1252. };
  1253. static struct video_device cx23885_mpeg_template = {
  1254. .name = "cx23885",
  1255. .fops = &mpeg_fops,
  1256. .ioctl_ops = &mpeg_ioctl_ops,
  1257. .tvnorms = CX23885_NORMS,
  1258. };
  1259. void cx23885_417_unregister(struct cx23885_dev *dev)
  1260. {
  1261. dprintk(1, "%s()\n", __func__);
  1262. if (dev->v4l_device) {
  1263. if (video_is_registered(dev->v4l_device))
  1264. video_unregister_device(dev->v4l_device);
  1265. else
  1266. video_device_release(dev->v4l_device);
  1267. v4l2_ctrl_handler_free(&dev->cxhdl.hdl);
  1268. dev->v4l_device = NULL;
  1269. }
  1270. }
  1271. static struct video_device *cx23885_video_dev_alloc(
  1272. struct cx23885_tsport *tsport,
  1273. struct pci_dev *pci,
  1274. struct video_device *template,
  1275. char *type)
  1276. {
  1277. struct video_device *vfd;
  1278. struct cx23885_dev *dev = tsport->dev;
  1279. dprintk(1, "%s()\n", __func__);
  1280. vfd = video_device_alloc();
  1281. if (NULL == vfd)
  1282. return NULL;
  1283. *vfd = *template;
  1284. snprintf(vfd->name, sizeof(vfd->name), "%s (%s)",
  1285. cx23885_boards[tsport->dev->board].name, type);
  1286. vfd->v4l2_dev = &dev->v4l2_dev;
  1287. vfd->release = video_device_release;
  1288. return vfd;
  1289. }
  1290. int cx23885_417_register(struct cx23885_dev *dev)
  1291. {
  1292. /* FIXME: Port1 hardcoded here */
  1293. int err = -ENODEV;
  1294. struct cx23885_tsport *tsport = &dev->ts1;
  1295. struct vb2_queue *q;
  1296. dprintk(1, "%s()\n", __func__);
  1297. if (cx23885_boards[dev->board].portb != CX23885_MPEG_ENCODER)
  1298. return err;
  1299. /* Set default TV standard */
  1300. dev->encodernorm = cx23885_tvnorms[0];
  1301. if (dev->encodernorm.id & V4L2_STD_525_60)
  1302. tsport->height = 480;
  1303. else
  1304. tsport->height = 576;
  1305. tsport->width = 720;
  1306. dev->cxhdl.port = CX2341X_PORT_SERIAL;
  1307. err = cx2341x_handler_init(&dev->cxhdl, 50);
  1308. if (err)
  1309. return err;
  1310. dev->cxhdl.priv = dev;
  1311. dev->cxhdl.func = cx23885_api_func;
  1312. cx2341x_handler_set_50hz(&dev->cxhdl, tsport->height == 576);
  1313. v4l2_ctrl_add_handler(&dev->ctrl_handler, &dev->cxhdl.hdl, NULL);
  1314. /* Allocate and initialize V4L video device */
  1315. dev->v4l_device = cx23885_video_dev_alloc(tsport,
  1316. dev->pci, &cx23885_mpeg_template, "mpeg");
  1317. q = &dev->vb2_mpegq;
  1318. q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1319. q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ;
  1320. q->gfp_flags = GFP_DMA32;
  1321. q->min_buffers_needed = 2;
  1322. q->drv_priv = dev;
  1323. q->buf_struct_size = sizeof(struct cx23885_buffer);
  1324. q->ops = &cx23885_qops;
  1325. q->mem_ops = &vb2_dma_sg_memops;
  1326. q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  1327. q->lock = &dev->lock;
  1328. q->dev = &dev->pci->dev;
  1329. err = vb2_queue_init(q);
  1330. if (err < 0)
  1331. return err;
  1332. video_set_drvdata(dev->v4l_device, dev);
  1333. dev->v4l_device->lock = &dev->lock;
  1334. dev->v4l_device->queue = q;
  1335. err = video_register_device(dev->v4l_device,
  1336. VFL_TYPE_GRABBER, -1);
  1337. if (err < 0) {
  1338. pr_info("%s: can't register mpeg device\n", dev->name);
  1339. return err;
  1340. }
  1341. pr_info("%s: registered device %s [mpeg]\n",
  1342. dev->name, video_device_node_name(dev->v4l_device));
  1343. /* ST: Configure the encoder paramaters, but don't begin
  1344. * encoding, this resolves an issue where the first time the
  1345. * encoder is started video can be choppy.
  1346. */
  1347. cx23885_initialize_codec(dev, 0);
  1348. return 0;
  1349. }
  1350. MODULE_FIRMWARE(CX23885_FIRM_IMAGE_NAME);