cx231xx-cards.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477
  1. /*
  2. cx231xx-cards.c - driver for Conexant Cx23100/101/102
  3. USB video capture devices
  4. Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
  5. Based on em28xx driver
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <linux/init.h>
  19. #include <linux/module.h>
  20. #include <linux/slab.h>
  21. #include <linux/delay.h>
  22. #include <linux/i2c.h>
  23. #include <linux/usb.h>
  24. #include <media/tuner.h>
  25. #include <media/tveeprom.h>
  26. #include <media/v4l2-common.h>
  27. #include <media/cx25840.h>
  28. #include "dvb-usb-ids.h"
  29. #include "xc5000.h"
  30. #include "tda18271.h"
  31. #include "cx231xx.h"
  32. static int tuner = -1;
  33. module_param(tuner, int, 0444);
  34. MODULE_PARM_DESC(tuner, "tuner type");
  35. static int transfer_mode = 1;
  36. module_param(transfer_mode, int, 0444);
  37. MODULE_PARM_DESC(transfer_mode, "transfer mode (1-ISO or 0-BULK)");
  38. static unsigned int disable_ir;
  39. module_param(disable_ir, int, 0444);
  40. MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
  41. /* Bitmask marking allocated devices from 0 to CX231XX_MAXBOARDS */
  42. static unsigned long cx231xx_devused;
  43. /*
  44. * Reset sequences for analog/digital modes
  45. */
  46. static struct cx231xx_reg_seq RDE250_XCV_TUNER[] = {
  47. {0x03, 0x01, 10},
  48. {0x03, 0x00, 30},
  49. {0x03, 0x01, 10},
  50. {-1, -1, -1},
  51. };
  52. /*
  53. * Board definitions
  54. */
  55. struct cx231xx_board cx231xx_boards[] = {
  56. [CX231XX_BOARD_UNKNOWN] = {
  57. .name = "Unknown CX231xx video grabber",
  58. .tuner_type = TUNER_ABSENT,
  59. .input = {{
  60. .type = CX231XX_VMUX_TELEVISION,
  61. .vmux = CX231XX_VIN_3_1,
  62. .amux = CX231XX_AMUX_VIDEO,
  63. .gpio = NULL,
  64. }, {
  65. .type = CX231XX_VMUX_COMPOSITE1,
  66. .vmux = CX231XX_VIN_2_1,
  67. .amux = CX231XX_AMUX_LINE_IN,
  68. .gpio = NULL,
  69. }, {
  70. .type = CX231XX_VMUX_SVIDEO,
  71. .vmux = CX231XX_VIN_1_1 |
  72. (CX231XX_VIN_1_2 << 8) |
  73. CX25840_SVIDEO_ON,
  74. .amux = CX231XX_AMUX_LINE_IN,
  75. .gpio = NULL,
  76. }
  77. },
  78. },
  79. [CX231XX_BOARD_CNXT_CARRAERA] = {
  80. .name = "Conexant Hybrid TV - CARRAERA",
  81. .tuner_type = TUNER_XC5000,
  82. .tuner_addr = 0x61,
  83. .tuner_gpio = RDE250_XCV_TUNER,
  84. .tuner_sif_gpio = 0x05,
  85. .tuner_scl_gpio = 0x1a,
  86. .tuner_sda_gpio = 0x1b,
  87. .decoder = CX231XX_AVDECODER,
  88. .output_mode = OUT_MODE_VIP11,
  89. .demod_xfer_mode = 0,
  90. .ctl_pin_status_mask = 0xFFFFFFC4,
  91. .agc_analog_digital_select_gpio = 0x0c,
  92. .gpio_pin_status_mask = 0x4001000,
  93. .tuner_i2c_master = 1,
  94. .demod_i2c_master = 2,
  95. .has_dvb = 1,
  96. .demod_addr = 0x02,
  97. .norm = V4L2_STD_PAL,
  98. .input = {{
  99. .type = CX231XX_VMUX_TELEVISION,
  100. .vmux = CX231XX_VIN_3_1,
  101. .amux = CX231XX_AMUX_VIDEO,
  102. .gpio = NULL,
  103. }, {
  104. .type = CX231XX_VMUX_COMPOSITE1,
  105. .vmux = CX231XX_VIN_2_1,
  106. .amux = CX231XX_AMUX_LINE_IN,
  107. .gpio = NULL,
  108. }, {
  109. .type = CX231XX_VMUX_SVIDEO,
  110. .vmux = CX231XX_VIN_1_1 |
  111. (CX231XX_VIN_1_2 << 8) |
  112. CX25840_SVIDEO_ON,
  113. .amux = CX231XX_AMUX_LINE_IN,
  114. .gpio = NULL,
  115. }
  116. },
  117. },
  118. [CX231XX_BOARD_CNXT_SHELBY] = {
  119. .name = "Conexant Hybrid TV - SHELBY",
  120. .tuner_type = TUNER_XC5000,
  121. .tuner_addr = 0x61,
  122. .tuner_gpio = RDE250_XCV_TUNER,
  123. .tuner_sif_gpio = 0x05,
  124. .tuner_scl_gpio = 0x1a,
  125. .tuner_sda_gpio = 0x1b,
  126. .decoder = CX231XX_AVDECODER,
  127. .output_mode = OUT_MODE_VIP11,
  128. .demod_xfer_mode = 0,
  129. .ctl_pin_status_mask = 0xFFFFFFC4,
  130. .agc_analog_digital_select_gpio = 0x0c,
  131. .gpio_pin_status_mask = 0x4001000,
  132. .tuner_i2c_master = 1,
  133. .demod_i2c_master = 2,
  134. .has_dvb = 1,
  135. .demod_addr = 0x32,
  136. .norm = V4L2_STD_NTSC,
  137. .input = {{
  138. .type = CX231XX_VMUX_TELEVISION,
  139. .vmux = CX231XX_VIN_3_1,
  140. .amux = CX231XX_AMUX_VIDEO,
  141. .gpio = NULL,
  142. }, {
  143. .type = CX231XX_VMUX_COMPOSITE1,
  144. .vmux = CX231XX_VIN_2_1,
  145. .amux = CX231XX_AMUX_LINE_IN,
  146. .gpio = NULL,
  147. }, {
  148. .type = CX231XX_VMUX_SVIDEO,
  149. .vmux = CX231XX_VIN_1_1 |
  150. (CX231XX_VIN_1_2 << 8) |
  151. CX25840_SVIDEO_ON,
  152. .amux = CX231XX_AMUX_LINE_IN,
  153. .gpio = NULL,
  154. }
  155. },
  156. },
  157. [CX231XX_BOARD_CNXT_RDE_253S] = {
  158. .name = "Conexant Hybrid TV - RDE253S",
  159. .tuner_type = TUNER_NXP_TDA18271,
  160. .tuner_addr = 0x60,
  161. .tuner_gpio = RDE250_XCV_TUNER,
  162. .tuner_sif_gpio = 0x05,
  163. .tuner_scl_gpio = 0x1a,
  164. .tuner_sda_gpio = 0x1b,
  165. .decoder = CX231XX_AVDECODER,
  166. .output_mode = OUT_MODE_VIP11,
  167. .demod_xfer_mode = 0,
  168. .ctl_pin_status_mask = 0xFFFFFFC4,
  169. .agc_analog_digital_select_gpio = 0x1c,
  170. .gpio_pin_status_mask = 0x4001000,
  171. .tuner_i2c_master = 1,
  172. .demod_i2c_master = 2,
  173. .has_dvb = 1,
  174. .demod_addr = 0x02,
  175. .norm = V4L2_STD_PAL,
  176. .input = {{
  177. .type = CX231XX_VMUX_TELEVISION,
  178. .vmux = CX231XX_VIN_3_1,
  179. .amux = CX231XX_AMUX_VIDEO,
  180. .gpio = NULL,
  181. }, {
  182. .type = CX231XX_VMUX_COMPOSITE1,
  183. .vmux = CX231XX_VIN_2_1,
  184. .amux = CX231XX_AMUX_LINE_IN,
  185. .gpio = NULL,
  186. }, {
  187. .type = CX231XX_VMUX_SVIDEO,
  188. .vmux = CX231XX_VIN_1_1 |
  189. (CX231XX_VIN_1_2 << 8) |
  190. CX25840_SVIDEO_ON,
  191. .amux = CX231XX_AMUX_LINE_IN,
  192. .gpio = NULL,
  193. }
  194. },
  195. },
  196. [CX231XX_BOARD_CNXT_RDU_253S] = {
  197. .name = "Conexant Hybrid TV - RDU253S",
  198. .tuner_type = TUNER_NXP_TDA18271,
  199. .tuner_addr = 0x60,
  200. .tuner_gpio = RDE250_XCV_TUNER,
  201. .tuner_sif_gpio = 0x05,
  202. .tuner_scl_gpio = 0x1a,
  203. .tuner_sda_gpio = 0x1b,
  204. .decoder = CX231XX_AVDECODER,
  205. .output_mode = OUT_MODE_VIP11,
  206. .demod_xfer_mode = 0,
  207. .ctl_pin_status_mask = 0xFFFFFFC4,
  208. .agc_analog_digital_select_gpio = 0x1c,
  209. .gpio_pin_status_mask = 0x4001000,
  210. .tuner_i2c_master = 1,
  211. .demod_i2c_master = 2,
  212. .has_dvb = 1,
  213. .demod_addr = 0x02,
  214. .norm = V4L2_STD_PAL,
  215. .input = {{
  216. .type = CX231XX_VMUX_TELEVISION,
  217. .vmux = CX231XX_VIN_3_1,
  218. .amux = CX231XX_AMUX_VIDEO,
  219. .gpio = NULL,
  220. }, {
  221. .type = CX231XX_VMUX_COMPOSITE1,
  222. .vmux = CX231XX_VIN_2_1,
  223. .amux = CX231XX_AMUX_LINE_IN,
  224. .gpio = NULL,
  225. }, {
  226. .type = CX231XX_VMUX_SVIDEO,
  227. .vmux = CX231XX_VIN_1_1 |
  228. (CX231XX_VIN_1_2 << 8) |
  229. CX25840_SVIDEO_ON,
  230. .amux = CX231XX_AMUX_LINE_IN,
  231. .gpio = NULL,
  232. }
  233. },
  234. },
  235. [CX231XX_BOARD_CNXT_VIDEO_GRABBER] = {
  236. .name = "Conexant VIDEO GRABBER",
  237. .tuner_type = TUNER_ABSENT,
  238. .decoder = CX231XX_AVDECODER,
  239. .output_mode = OUT_MODE_VIP11,
  240. .ctl_pin_status_mask = 0xFFFFFFC4,
  241. .agc_analog_digital_select_gpio = 0x1c,
  242. .gpio_pin_status_mask = 0x4001000,
  243. .norm = V4L2_STD_PAL,
  244. .no_alt_vanc = 1,
  245. .external_av = 1,
  246. .dont_use_port_3 = 1,
  247. /* Actually, it has a 417, but it isn't working correctly.
  248. * So set to 0 for now until someone can manage to get this
  249. * to work reliably. */
  250. .has_417 = 0,
  251. .input = {{
  252. .type = CX231XX_VMUX_COMPOSITE1,
  253. .vmux = CX231XX_VIN_2_1,
  254. .amux = CX231XX_AMUX_LINE_IN,
  255. .gpio = NULL,
  256. }, {
  257. .type = CX231XX_VMUX_SVIDEO,
  258. .vmux = CX231XX_VIN_1_1 |
  259. (CX231XX_VIN_1_2 << 8) |
  260. CX25840_SVIDEO_ON,
  261. .amux = CX231XX_AMUX_LINE_IN,
  262. .gpio = NULL,
  263. }
  264. },
  265. },
  266. [CX231XX_BOARD_CNXT_RDE_250] = {
  267. .name = "Conexant Hybrid TV - rde 250",
  268. .tuner_type = TUNER_XC5000,
  269. .tuner_addr = 0x61,
  270. .tuner_gpio = RDE250_XCV_TUNER,
  271. .tuner_sif_gpio = 0x05,
  272. .tuner_scl_gpio = 0x1a,
  273. .tuner_sda_gpio = 0x1b,
  274. .decoder = CX231XX_AVDECODER,
  275. .output_mode = OUT_MODE_VIP11,
  276. .demod_xfer_mode = 0,
  277. .ctl_pin_status_mask = 0xFFFFFFC4,
  278. .agc_analog_digital_select_gpio = 0x0c,
  279. .gpio_pin_status_mask = 0x4001000,
  280. .tuner_i2c_master = 1,
  281. .demod_i2c_master = 2,
  282. .has_dvb = 1,
  283. .demod_addr = 0x02,
  284. .norm = V4L2_STD_PAL,
  285. .input = {{
  286. .type = CX231XX_VMUX_TELEVISION,
  287. .vmux = CX231XX_VIN_2_1,
  288. .amux = CX231XX_AMUX_VIDEO,
  289. .gpio = NULL,
  290. }
  291. },
  292. },
  293. [CX231XX_BOARD_CNXT_RDU_250] = {
  294. .name = "Conexant Hybrid TV - RDU 250",
  295. .tuner_type = TUNER_XC5000,
  296. .tuner_addr = 0x61,
  297. .tuner_gpio = RDE250_XCV_TUNER,
  298. .tuner_sif_gpio = 0x05,
  299. .tuner_scl_gpio = 0x1a,
  300. .tuner_sda_gpio = 0x1b,
  301. .decoder = CX231XX_AVDECODER,
  302. .output_mode = OUT_MODE_VIP11,
  303. .demod_xfer_mode = 0,
  304. .ctl_pin_status_mask = 0xFFFFFFC4,
  305. .agc_analog_digital_select_gpio = 0x0c,
  306. .gpio_pin_status_mask = 0x4001000,
  307. .tuner_i2c_master = 1,
  308. .demod_i2c_master = 2,
  309. .has_dvb = 1,
  310. .demod_addr = 0x32,
  311. .norm = V4L2_STD_NTSC,
  312. .input = {{
  313. .type = CX231XX_VMUX_TELEVISION,
  314. .vmux = CX231XX_VIN_2_1,
  315. .amux = CX231XX_AMUX_VIDEO,
  316. .gpio = NULL,
  317. }
  318. },
  319. },
  320. [CX231XX_BOARD_HAUPPAUGE_EXETER] = {
  321. .name = "Hauppauge EXETER",
  322. .tuner_type = TUNER_NXP_TDA18271,
  323. .tuner_addr = 0x60,
  324. .tuner_gpio = RDE250_XCV_TUNER,
  325. .tuner_sif_gpio = 0x05,
  326. .tuner_scl_gpio = 0x1a,
  327. .tuner_sda_gpio = 0x1b,
  328. .decoder = CX231XX_AVDECODER,
  329. .output_mode = OUT_MODE_VIP11,
  330. .demod_xfer_mode = 0,
  331. .ctl_pin_status_mask = 0xFFFFFFC4,
  332. .agc_analog_digital_select_gpio = 0x0c,
  333. .gpio_pin_status_mask = 0x4001000,
  334. .tuner_i2c_master = 1,
  335. .demod_i2c_master = 2,
  336. .has_dvb = 1,
  337. .demod_addr = 0x0e,
  338. .norm = V4L2_STD_NTSC,
  339. .input = {{
  340. .type = CX231XX_VMUX_TELEVISION,
  341. .vmux = CX231XX_VIN_3_1,
  342. .amux = CX231XX_AMUX_VIDEO,
  343. .gpio = NULL,
  344. }, {
  345. .type = CX231XX_VMUX_COMPOSITE1,
  346. .vmux = CX231XX_VIN_2_1,
  347. .amux = CX231XX_AMUX_LINE_IN,
  348. .gpio = NULL,
  349. }, {
  350. .type = CX231XX_VMUX_SVIDEO,
  351. .vmux = CX231XX_VIN_1_1 |
  352. (CX231XX_VIN_1_2 << 8) |
  353. CX25840_SVIDEO_ON,
  354. .amux = CX231XX_AMUX_LINE_IN,
  355. .gpio = NULL,
  356. } },
  357. },
  358. [CX231XX_BOARD_HAUPPAUGE_USBLIVE2] = {
  359. .name = "Hauppauge USB Live 2",
  360. .tuner_type = TUNER_ABSENT,
  361. .decoder = CX231XX_AVDECODER,
  362. .output_mode = OUT_MODE_VIP11,
  363. .demod_xfer_mode = 0,
  364. .ctl_pin_status_mask = 0xFFFFFFC4,
  365. .agc_analog_digital_select_gpio = 0x0c,
  366. .gpio_pin_status_mask = 0x4001000,
  367. .norm = V4L2_STD_NTSC,
  368. .no_alt_vanc = 1,
  369. .external_av = 1,
  370. .dont_use_port_3 = 1,
  371. .input = {{
  372. .type = CX231XX_VMUX_COMPOSITE1,
  373. .vmux = CX231XX_VIN_2_1,
  374. .amux = CX231XX_AMUX_LINE_IN,
  375. .gpio = NULL,
  376. }, {
  377. .type = CX231XX_VMUX_SVIDEO,
  378. .vmux = CX231XX_VIN_1_1 |
  379. (CX231XX_VIN_1_2 << 8) |
  380. CX25840_SVIDEO_ON,
  381. .amux = CX231XX_AMUX_LINE_IN,
  382. .gpio = NULL,
  383. } },
  384. },
  385. [CX231XX_BOARD_KWORLD_UB430_USB_HYBRID] = {
  386. .name = "Kworld UB430 USB Hybrid",
  387. .tuner_type = TUNER_NXP_TDA18271,
  388. .tuner_addr = 0x60,
  389. .decoder = CX231XX_AVDECODER,
  390. .output_mode = OUT_MODE_VIP11,
  391. .demod_xfer_mode = 0,
  392. .ctl_pin_status_mask = 0xFFFFFFC4,
  393. .agc_analog_digital_select_gpio = 0x11, /* According with PV cxPolaris.inf file */
  394. .tuner_sif_gpio = -1,
  395. .tuner_scl_gpio = -1,
  396. .tuner_sda_gpio = -1,
  397. .gpio_pin_status_mask = 0x4001000,
  398. .tuner_i2c_master = 2,
  399. .demod_i2c_master = 1,
  400. .ir_i2c_master = 2,
  401. .has_dvb = 1,
  402. .demod_addr = 0x10,
  403. .norm = V4L2_STD_PAL_M,
  404. .input = {{
  405. .type = CX231XX_VMUX_TELEVISION,
  406. .vmux = CX231XX_VIN_3_1,
  407. .amux = CX231XX_AMUX_VIDEO,
  408. .gpio = NULL,
  409. }, {
  410. .type = CX231XX_VMUX_COMPOSITE1,
  411. .vmux = CX231XX_VIN_2_1,
  412. .amux = CX231XX_AMUX_LINE_IN,
  413. .gpio = NULL,
  414. }, {
  415. .type = CX231XX_VMUX_SVIDEO,
  416. .vmux = CX231XX_VIN_1_1 |
  417. (CX231XX_VIN_1_2 << 8) |
  418. CX25840_SVIDEO_ON,
  419. .amux = CX231XX_AMUX_LINE_IN,
  420. .gpio = NULL,
  421. } },
  422. },
  423. [CX231XX_BOARD_KWORLD_UB445_USB_HYBRID] = {
  424. .name = "Kworld UB445 USB Hybrid",
  425. .tuner_type = TUNER_NXP_TDA18271,
  426. .tuner_addr = 0x60,
  427. .decoder = CX231XX_AVDECODER,
  428. .output_mode = OUT_MODE_VIP11,
  429. .demod_xfer_mode = 0,
  430. .ctl_pin_status_mask = 0xFFFFFFC4,
  431. .agc_analog_digital_select_gpio = 0x11, /* According with PV cxPolaris.inf file */
  432. .tuner_sif_gpio = -1,
  433. .tuner_scl_gpio = -1,
  434. .tuner_sda_gpio = -1,
  435. .gpio_pin_status_mask = 0x4001000,
  436. .tuner_i2c_master = 2,
  437. .demod_i2c_master = 1,
  438. .ir_i2c_master = 2,
  439. .has_dvb = 1,
  440. .demod_addr = 0x10,
  441. .norm = V4L2_STD_NTSC_M,
  442. .input = {{
  443. .type = CX231XX_VMUX_TELEVISION,
  444. .vmux = CX231XX_VIN_3_1,
  445. .amux = CX231XX_AMUX_VIDEO,
  446. .gpio = NULL,
  447. }, {
  448. .type = CX231XX_VMUX_COMPOSITE1,
  449. .vmux = CX231XX_VIN_2_1,
  450. .amux = CX231XX_AMUX_LINE_IN,
  451. .gpio = NULL,
  452. }, {
  453. .type = CX231XX_VMUX_SVIDEO,
  454. .vmux = CX231XX_VIN_1_1 |
  455. (CX231XX_VIN_1_2 << 8) |
  456. CX25840_SVIDEO_ON,
  457. .amux = CX231XX_AMUX_LINE_IN,
  458. .gpio = NULL,
  459. } },
  460. },
  461. [CX231XX_BOARD_PV_PLAYTV_USB_HYBRID] = {
  462. .name = "Pixelview PlayTV USB Hybrid",
  463. .tuner_type = TUNER_NXP_TDA18271,
  464. .tuner_addr = 0x60,
  465. .decoder = CX231XX_AVDECODER,
  466. .output_mode = OUT_MODE_VIP11,
  467. .demod_xfer_mode = 0,
  468. .ctl_pin_status_mask = 0xFFFFFFC4,
  469. .agc_analog_digital_select_gpio = 0x00, /* According with PV cxPolaris.inf file */
  470. .tuner_sif_gpio = -1,
  471. .tuner_scl_gpio = -1,
  472. .tuner_sda_gpio = -1,
  473. .gpio_pin_status_mask = 0x4001000,
  474. .tuner_i2c_master = 2,
  475. .demod_i2c_master = 1,
  476. .ir_i2c_master = 2,
  477. .rc_map_name = RC_MAP_PIXELVIEW_002T,
  478. .has_dvb = 1,
  479. .demod_addr = 0x10,
  480. .norm = V4L2_STD_PAL_M,
  481. .input = {{
  482. .type = CX231XX_VMUX_TELEVISION,
  483. .vmux = CX231XX_VIN_3_1,
  484. .amux = CX231XX_AMUX_VIDEO,
  485. .gpio = NULL,
  486. }, {
  487. .type = CX231XX_VMUX_COMPOSITE1,
  488. .vmux = CX231XX_VIN_2_1,
  489. .amux = CX231XX_AMUX_LINE_IN,
  490. .gpio = NULL,
  491. }, {
  492. .type = CX231XX_VMUX_SVIDEO,
  493. .vmux = CX231XX_VIN_1_1 |
  494. (CX231XX_VIN_1_2 << 8) |
  495. CX25840_SVIDEO_ON,
  496. .amux = CX231XX_AMUX_LINE_IN,
  497. .gpio = NULL,
  498. } },
  499. },
  500. [CX231XX_BOARD_PV_XCAPTURE_USB] = {
  501. .name = "Pixelview Xcapture USB",
  502. .tuner_type = TUNER_ABSENT,
  503. .decoder = CX231XX_AVDECODER,
  504. .output_mode = OUT_MODE_VIP11,
  505. .demod_xfer_mode = 0,
  506. .ctl_pin_status_mask = 0xFFFFFFC4,
  507. .agc_analog_digital_select_gpio = 0x0c,
  508. .gpio_pin_status_mask = 0x4001000,
  509. .norm = V4L2_STD_NTSC,
  510. .no_alt_vanc = 1,
  511. .external_av = 1,
  512. .dont_use_port_3 = 1,
  513. .input = {{
  514. .type = CX231XX_VMUX_COMPOSITE1,
  515. .vmux = CX231XX_VIN_2_1,
  516. .amux = CX231XX_AMUX_LINE_IN,
  517. .gpio = NULL,
  518. }, {
  519. .type = CX231XX_VMUX_SVIDEO,
  520. .vmux = CX231XX_VIN_1_1 |
  521. (CX231XX_VIN_1_2 << 8) |
  522. CX25840_SVIDEO_ON,
  523. .amux = CX231XX_AMUX_LINE_IN,
  524. .gpio = NULL,
  525. }
  526. },
  527. },
  528. [CX231XX_BOARD_ICONBIT_U100] = {
  529. .name = "Iconbit Analog Stick U100 FM",
  530. .tuner_type = TUNER_ABSENT,
  531. .decoder = CX231XX_AVDECODER,
  532. .output_mode = OUT_MODE_VIP11,
  533. .demod_xfer_mode = 0,
  534. .ctl_pin_status_mask = 0xFFFFFFC4,
  535. .agc_analog_digital_select_gpio = 0x1C,
  536. .gpio_pin_status_mask = 0x4001000,
  537. .input = {{
  538. .type = CX231XX_VMUX_COMPOSITE1,
  539. .vmux = CX231XX_VIN_2_1,
  540. .amux = CX231XX_AMUX_LINE_IN,
  541. .gpio = NULL,
  542. }, {
  543. .type = CX231XX_VMUX_SVIDEO,
  544. .vmux = CX231XX_VIN_1_1 |
  545. (CX231XX_VIN_1_2 << 8) |
  546. CX25840_SVIDEO_ON,
  547. .amux = CX231XX_AMUX_LINE_IN,
  548. .gpio = NULL,
  549. } },
  550. },
  551. [CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL] = {
  552. .name = "Hauppauge WinTV USB2 FM (PAL)",
  553. .tuner_type = TUNER_NXP_TDA18271,
  554. .tuner_addr = 0x60,
  555. .tuner_gpio = RDE250_XCV_TUNER,
  556. .tuner_sif_gpio = 0x05,
  557. .tuner_scl_gpio = 0x1a,
  558. .tuner_sda_gpio = 0x1b,
  559. .decoder = CX231XX_AVDECODER,
  560. .output_mode = OUT_MODE_VIP11,
  561. .ctl_pin_status_mask = 0xFFFFFFC4,
  562. .agc_analog_digital_select_gpio = 0x0c,
  563. .gpio_pin_status_mask = 0x4001000,
  564. .tuner_i2c_master = 1,
  565. .norm = V4L2_STD_PAL,
  566. .input = {{
  567. .type = CX231XX_VMUX_TELEVISION,
  568. .vmux = CX231XX_VIN_3_1,
  569. .amux = CX231XX_AMUX_VIDEO,
  570. .gpio = NULL,
  571. }, {
  572. .type = CX231XX_VMUX_COMPOSITE1,
  573. .vmux = CX231XX_VIN_2_1,
  574. .amux = CX231XX_AMUX_LINE_IN,
  575. .gpio = NULL,
  576. }, {
  577. .type = CX231XX_VMUX_SVIDEO,
  578. .vmux = CX231XX_VIN_1_1 |
  579. (CX231XX_VIN_1_2 << 8) |
  580. CX25840_SVIDEO_ON,
  581. .amux = CX231XX_AMUX_LINE_IN,
  582. .gpio = NULL,
  583. } },
  584. },
  585. [CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC] = {
  586. .name = "Hauppauge WinTV USB2 FM (NTSC)",
  587. .tuner_type = TUNER_NXP_TDA18271,
  588. .tuner_addr = 0x60,
  589. .tuner_gpio = RDE250_XCV_TUNER,
  590. .tuner_sif_gpio = 0x05,
  591. .tuner_scl_gpio = 0x1a,
  592. .tuner_sda_gpio = 0x1b,
  593. .decoder = CX231XX_AVDECODER,
  594. .output_mode = OUT_MODE_VIP11,
  595. .ctl_pin_status_mask = 0xFFFFFFC4,
  596. .agc_analog_digital_select_gpio = 0x0c,
  597. .gpio_pin_status_mask = 0x4001000,
  598. .tuner_i2c_master = 1,
  599. .norm = V4L2_STD_NTSC,
  600. .input = {{
  601. .type = CX231XX_VMUX_TELEVISION,
  602. .vmux = CX231XX_VIN_3_1,
  603. .amux = CX231XX_AMUX_VIDEO,
  604. .gpio = NULL,
  605. }, {
  606. .type = CX231XX_VMUX_COMPOSITE1,
  607. .vmux = CX231XX_VIN_2_1,
  608. .amux = CX231XX_AMUX_LINE_IN,
  609. .gpio = NULL,
  610. }, {
  611. .type = CX231XX_VMUX_SVIDEO,
  612. .vmux = CX231XX_VIN_1_1 |
  613. (CX231XX_VIN_1_2 << 8) |
  614. CX25840_SVIDEO_ON,
  615. .amux = CX231XX_AMUX_LINE_IN,
  616. .gpio = NULL,
  617. } },
  618. },
  619. [CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2] = {
  620. .name = "Elgato Video Capture V2",
  621. .tuner_type = TUNER_ABSENT,
  622. .decoder = CX231XX_AVDECODER,
  623. .output_mode = OUT_MODE_VIP11,
  624. .demod_xfer_mode = 0,
  625. .ctl_pin_status_mask = 0xFFFFFFC4,
  626. .agc_analog_digital_select_gpio = 0x0c,
  627. .gpio_pin_status_mask = 0x4001000,
  628. .norm = V4L2_STD_NTSC,
  629. .no_alt_vanc = 1,
  630. .external_av = 1,
  631. .dont_use_port_3 = 1,
  632. .input = {{
  633. .type = CX231XX_VMUX_COMPOSITE1,
  634. .vmux = CX231XX_VIN_2_1,
  635. .amux = CX231XX_AMUX_LINE_IN,
  636. .gpio = NULL,
  637. }, {
  638. .type = CX231XX_VMUX_SVIDEO,
  639. .vmux = CX231XX_VIN_1_1 |
  640. (CX231XX_VIN_1_2 << 8) |
  641. CX25840_SVIDEO_ON,
  642. .amux = CX231XX_AMUX_LINE_IN,
  643. .gpio = NULL,
  644. } },
  645. },
  646. [CX231XX_BOARD_OTG102] = {
  647. .name = "Geniatech OTG102",
  648. .tuner_type = TUNER_ABSENT,
  649. .decoder = CX231XX_AVDECODER,
  650. .output_mode = OUT_MODE_VIP11,
  651. .ctl_pin_status_mask = 0xFFFFFFC4,
  652. .agc_analog_digital_select_gpio = 0x0c,
  653. /* According with PV CxPlrCAP.inf file */
  654. .gpio_pin_status_mask = 0x4001000,
  655. .norm = V4L2_STD_NTSC,
  656. .no_alt_vanc = 1,
  657. .external_av = 1,
  658. .dont_use_port_3 = 1,
  659. /*.has_417 = 1, */
  660. /* This board is believed to have a hardware encoding chip
  661. * supporting mpeg1/2/4, but as the 417 is apparently not
  662. * working for the reference board it is not here either. */
  663. .input = {{
  664. .type = CX231XX_VMUX_COMPOSITE1,
  665. .vmux = CX231XX_VIN_2_1,
  666. .amux = CX231XX_AMUX_LINE_IN,
  667. .gpio = NULL,
  668. }, {
  669. .type = CX231XX_VMUX_SVIDEO,
  670. .vmux = CX231XX_VIN_1_1 |
  671. (CX231XX_VIN_1_2 << 8) |
  672. CX25840_SVIDEO_ON,
  673. .amux = CX231XX_AMUX_LINE_IN,
  674. .gpio = NULL,
  675. }
  676. },
  677. },
  678. };
  679. const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
  680. /* table of devices that work with this driver */
  681. struct usb_device_id cx231xx_id_table[] = {
  682. {USB_DEVICE(0x0572, 0x5A3C),
  683. .driver_info = CX231XX_BOARD_UNKNOWN},
  684. {USB_DEVICE(0x0572, 0x58A2),
  685. .driver_info = CX231XX_BOARD_CNXT_CARRAERA},
  686. {USB_DEVICE(0x0572, 0x58A1),
  687. .driver_info = CX231XX_BOARD_CNXT_SHELBY},
  688. {USB_DEVICE(0x0572, 0x58A4),
  689. .driver_info = CX231XX_BOARD_CNXT_RDE_253S},
  690. {USB_DEVICE(0x0572, 0x58A5),
  691. .driver_info = CX231XX_BOARD_CNXT_RDU_253S},
  692. {USB_DEVICE(0x0572, 0x58A6),
  693. .driver_info = CX231XX_BOARD_CNXT_VIDEO_GRABBER},
  694. {USB_DEVICE(0x0572, 0x589E),
  695. .driver_info = CX231XX_BOARD_CNXT_RDE_250},
  696. {USB_DEVICE(0x0572, 0x58A0),
  697. .driver_info = CX231XX_BOARD_CNXT_RDU_250},
  698. {USB_DEVICE(0x2040, 0xb110),
  699. .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL},
  700. {USB_DEVICE(0x2040, 0xb111),
  701. .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC},
  702. {USB_DEVICE(0x2040, 0xb120),
  703. .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
  704. {USB_DEVICE(0x2040, 0xb140),
  705. .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
  706. {USB_DEVICE(0x2040, 0xc200),
  707. .driver_info = CX231XX_BOARD_HAUPPAUGE_USBLIVE2},
  708. {USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x4000, 0x4001),
  709. .driver_info = CX231XX_BOARD_PV_PLAYTV_USB_HYBRID},
  710. {USB_DEVICE(USB_VID_PIXELVIEW, 0x5014),
  711. .driver_info = CX231XX_BOARD_PV_XCAPTURE_USB},
  712. {USB_DEVICE(0x1b80, 0xe424),
  713. .driver_info = CX231XX_BOARD_KWORLD_UB430_USB_HYBRID},
  714. {USB_DEVICE(0x1b80, 0xe421),
  715. .driver_info = CX231XX_BOARD_KWORLD_UB445_USB_HYBRID},
  716. {USB_DEVICE(0x1f4d, 0x0237),
  717. .driver_info = CX231XX_BOARD_ICONBIT_U100},
  718. {USB_DEVICE(0x0fd9, 0x0037),
  719. .driver_info = CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2},
  720. {USB_DEVICE(0x1f4d, 0x0102),
  721. .driver_info = CX231XX_BOARD_OTG102},
  722. {},
  723. };
  724. MODULE_DEVICE_TABLE(usb, cx231xx_id_table);
  725. /* cx231xx_tuner_callback
  726. * will be used to reset XC5000 tuner using GPIO pin
  727. */
  728. int cx231xx_tuner_callback(void *ptr, int component, int command, int arg)
  729. {
  730. int rc = 0;
  731. struct cx231xx *dev = ptr;
  732. if (dev->tuner_type == TUNER_XC5000) {
  733. if (command == XC5000_TUNER_RESET) {
  734. cx231xx_info
  735. ("Tuner CB: RESET: cmd %d : tuner type %d \n",
  736. command, dev->tuner_type);
  737. cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
  738. 1);
  739. msleep(10);
  740. cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
  741. 0);
  742. msleep(330);
  743. cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
  744. 1);
  745. msleep(10);
  746. }
  747. } else if (dev->tuner_type == TUNER_NXP_TDA18271) {
  748. switch (command) {
  749. case TDA18271_CALLBACK_CMD_AGC_ENABLE:
  750. if (dev->model == CX231XX_BOARD_PV_PLAYTV_USB_HYBRID)
  751. rc = cx231xx_set_agc_analog_digital_mux_select(dev, arg);
  752. break;
  753. default:
  754. rc = -EINVAL;
  755. break;
  756. }
  757. }
  758. return rc;
  759. }
  760. EXPORT_SYMBOL_GPL(cx231xx_tuner_callback);
  761. static void cx231xx_reset_out(struct cx231xx *dev)
  762. {
  763. cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
  764. msleep(200);
  765. cx231xx_set_gpio_value(dev, CX23417_RESET, 0);
  766. msleep(200);
  767. cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
  768. }
  769. static void cx231xx_enable_OSC(struct cx231xx *dev)
  770. {
  771. cx231xx_set_gpio_value(dev, CX23417_OSC_EN, 1);
  772. }
  773. static void cx231xx_sleep_s5h1432(struct cx231xx *dev)
  774. {
  775. cx231xx_set_gpio_value(dev, SLEEP_S5H1432, 0);
  776. }
  777. static inline void cx231xx_set_model(struct cx231xx *dev)
  778. {
  779. dev->board = cx231xx_boards[dev->model];
  780. }
  781. /* Since cx231xx_pre_card_setup() requires a proper dev->model,
  782. * this won't work for boards with generic PCI IDs
  783. */
  784. void cx231xx_pre_card_setup(struct cx231xx *dev)
  785. {
  786. cx231xx_set_model(dev);
  787. cx231xx_info("Identified as %s (card=%d)\n",
  788. dev->board.name, dev->model);
  789. /* set the direction for GPIO pins */
  790. if (dev->board.tuner_gpio) {
  791. cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
  792. cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
  793. }
  794. if (dev->board.tuner_sif_gpio >= 0)
  795. cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
  796. /* request some modules if any required */
  797. /* set the mode to Analog mode initially */
  798. cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
  799. /* Unlock device */
  800. /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */
  801. }
  802. static void cx231xx_config_tuner(struct cx231xx *dev)
  803. {
  804. struct tuner_setup tun_setup;
  805. struct v4l2_frequency f;
  806. if (dev->tuner_type == TUNER_ABSENT)
  807. return;
  808. tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
  809. tun_setup.type = dev->tuner_type;
  810. tun_setup.addr = dev->tuner_addr;
  811. tun_setup.tuner_callback = cx231xx_tuner_callback;
  812. tuner_call(dev, tuner, s_type_addr, &tun_setup);
  813. #if 0
  814. if (tun_setup.type == TUNER_XC5000) {
  815. static struct xc2028_ctrl ctrl = {
  816. .fname = XC5000_DEFAULT_FIRMWARE,
  817. .max_len = 64,
  818. .demod = 0;
  819. };
  820. struct v4l2_priv_tun_config cfg = {
  821. .tuner = dev->tuner_type,
  822. .priv = &ctrl,
  823. };
  824. tuner_call(dev, tuner, s_config, &cfg);
  825. }
  826. #endif
  827. /* configure tuner */
  828. f.tuner = 0;
  829. f.type = V4L2_TUNER_ANALOG_TV;
  830. f.frequency = 9076; /* just a magic number */
  831. dev->ctl_freq = f.frequency;
  832. call_all(dev, tuner, s_frequency, &f);
  833. }
  834. void cx231xx_card_setup(struct cx231xx *dev)
  835. {
  836. cx231xx_set_model(dev);
  837. dev->tuner_type = cx231xx_boards[dev->model].tuner_type;
  838. if (cx231xx_boards[dev->model].tuner_addr)
  839. dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr;
  840. /* request some modules */
  841. if (dev->board.decoder == CX231XX_AVDECODER) {
  842. dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
  843. &dev->i2c_bus[0].i2c_adap,
  844. "cx25840", 0x88 >> 1, NULL);
  845. if (dev->sd_cx25840 == NULL)
  846. cx231xx_info("cx25840 subdev registration failure\n");
  847. cx25840_call(dev, core, load_fw);
  848. }
  849. /* Initialize the tuner */
  850. if (dev->board.tuner_type != TUNER_ABSENT) {
  851. dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev,
  852. &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
  853. "tuner",
  854. dev->tuner_addr, NULL);
  855. if (dev->sd_tuner == NULL)
  856. cx231xx_info("tuner subdev registration failure\n");
  857. else
  858. cx231xx_config_tuner(dev);
  859. }
  860. }
  861. /*
  862. * cx231xx_config()
  863. * inits registers with sane defaults
  864. */
  865. int cx231xx_config(struct cx231xx *dev)
  866. {
  867. /* TBD need to add cx231xx specific code */
  868. return 0;
  869. }
  870. /*
  871. * cx231xx_config_i2c()
  872. * configure i2c attached devices
  873. */
  874. void cx231xx_config_i2c(struct cx231xx *dev)
  875. {
  876. /* u32 input = INPUT(dev->video_input)->vmux; */
  877. call_all(dev, video, s_stream, 1);
  878. }
  879. /*
  880. * cx231xx_realease_resources()
  881. * unregisters the v4l2,i2c and usb devices
  882. * called when the device gets disconected or at module unload
  883. */
  884. void cx231xx_release_resources(struct cx231xx *dev)
  885. {
  886. cx231xx_release_analog_resources(dev);
  887. cx231xx_remove_from_devlist(dev);
  888. cx231xx_ir_exit(dev);
  889. /* Release I2C buses */
  890. cx231xx_dev_uninit(dev);
  891. /* delete v4l2 device */
  892. v4l2_device_unregister(&dev->v4l2_dev);
  893. usb_put_dev(dev->udev);
  894. /* Mark device as unused */
  895. clear_bit(dev->devno, &cx231xx_devused);
  896. kfree(dev->video_mode.alt_max_pkt_size);
  897. kfree(dev->vbi_mode.alt_max_pkt_size);
  898. kfree(dev->sliced_cc_mode.alt_max_pkt_size);
  899. kfree(dev->ts1_mode.alt_max_pkt_size);
  900. kfree(dev);
  901. }
  902. /*
  903. * cx231xx_init_dev()
  904. * allocates and inits the device structs, registers i2c bus and v4l device
  905. */
  906. static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
  907. int minor)
  908. {
  909. int retval = -ENOMEM;
  910. int errCode;
  911. unsigned int maxh, maxw;
  912. dev->udev = udev;
  913. mutex_init(&dev->lock);
  914. mutex_init(&dev->ctrl_urb_lock);
  915. mutex_init(&dev->gpio_i2c_lock);
  916. mutex_init(&dev->i2c_lock);
  917. spin_lock_init(&dev->video_mode.slock);
  918. spin_lock_init(&dev->vbi_mode.slock);
  919. spin_lock_init(&dev->sliced_cc_mode.slock);
  920. init_waitqueue_head(&dev->open);
  921. init_waitqueue_head(&dev->wait_frame);
  922. init_waitqueue_head(&dev->wait_stream);
  923. dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg;
  924. dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg;
  925. dev->cx231xx_send_usb_command = cx231xx_send_usb_command;
  926. dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read;
  927. dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write;
  928. /* Query cx231xx to find what pcb config it is related to */
  929. initialize_cx231xx(dev);
  930. /*To workaround error number=-71 on EP0 for VideoGrabber,
  931. need set alt here.*/
  932. if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER ||
  933. dev->model == CX231XX_BOARD_HAUPPAUGE_USBLIVE2) {
  934. cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
  935. cx231xx_set_alt_setting(dev, INDEX_VANC, 1);
  936. }
  937. /* Cx231xx pre card setup */
  938. cx231xx_pre_card_setup(dev);
  939. errCode = cx231xx_config(dev);
  940. if (errCode) {
  941. cx231xx_errdev("error configuring device\n");
  942. return -ENOMEM;
  943. }
  944. /* set default norm */
  945. dev->norm = dev->board.norm;
  946. /* register i2c bus */
  947. errCode = cx231xx_dev_init(dev);
  948. if (errCode < 0) {
  949. cx231xx_dev_uninit(dev);
  950. cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
  951. __func__, errCode);
  952. return errCode;
  953. }
  954. /* Do board specific init */
  955. cx231xx_card_setup(dev);
  956. /* configure the device */
  957. cx231xx_config_i2c(dev);
  958. maxw = norm_maxw(dev);
  959. maxh = norm_maxh(dev);
  960. /* set default image size */
  961. dev->width = maxw;
  962. dev->height = maxh;
  963. dev->interlaced = 0;
  964. dev->video_input = 0;
  965. errCode = cx231xx_config(dev);
  966. if (errCode < 0) {
  967. cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
  968. __func__, errCode);
  969. return errCode;
  970. }
  971. /* init video dma queues */
  972. INIT_LIST_HEAD(&dev->video_mode.vidq.active);
  973. INIT_LIST_HEAD(&dev->video_mode.vidq.queued);
  974. /* init vbi dma queues */
  975. INIT_LIST_HEAD(&dev->vbi_mode.vidq.active);
  976. INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued);
  977. /* Reset other chips required if they are tied up with GPIO pins */
  978. cx231xx_add_into_devlist(dev);
  979. if (dev->board.has_417) {
  980. printk(KERN_INFO "attach 417 %d\n", dev->model);
  981. if (cx231xx_417_register(dev) < 0) {
  982. printk(KERN_ERR
  983. "%s() Failed to register 417 on VID_B\n",
  984. __func__);
  985. }
  986. }
  987. retval = cx231xx_register_analog_devices(dev);
  988. if (retval < 0) {
  989. cx231xx_release_resources(dev);
  990. return retval;
  991. }
  992. cx231xx_ir_init(dev);
  993. cx231xx_init_extension(dev);
  994. return 0;
  995. }
  996. #if defined(CONFIG_MODULES) && defined(MODULE)
  997. static void request_module_async(struct work_struct *work)
  998. {
  999. struct cx231xx *dev = container_of(work,
  1000. struct cx231xx, request_module_wk);
  1001. if (dev->has_alsa_audio)
  1002. request_module("cx231xx-alsa");
  1003. if (dev->board.has_dvb)
  1004. request_module("cx231xx-dvb");
  1005. }
  1006. static void request_modules(struct cx231xx *dev)
  1007. {
  1008. INIT_WORK(&dev->request_module_wk, request_module_async);
  1009. schedule_work(&dev->request_module_wk);
  1010. }
  1011. static void flush_request_modules(struct cx231xx *dev)
  1012. {
  1013. flush_work(&dev->request_module_wk);
  1014. }
  1015. #else
  1016. #define request_modules(dev)
  1017. #define flush_request_modules(dev)
  1018. #endif /* CONFIG_MODULES */
  1019. /*
  1020. * cx231xx_usb_probe()
  1021. * checks for supported devices
  1022. */
  1023. static int cx231xx_usb_probe(struct usb_interface *interface,
  1024. const struct usb_device_id *id)
  1025. {
  1026. struct usb_device *udev;
  1027. struct usb_interface *uif;
  1028. struct cx231xx *dev = NULL;
  1029. int retval = -ENODEV;
  1030. int nr = 0, ifnum;
  1031. int i, isoc_pipe = 0;
  1032. char *speed;
  1033. struct usb_interface_assoc_descriptor *assoc_desc;
  1034. udev = usb_get_dev(interface_to_usbdev(interface));
  1035. ifnum = interface->altsetting[0].desc.bInterfaceNumber;
  1036. /*
  1037. * Interface number 0 - IR interface (handled by mceusb driver)
  1038. * Interface number 1 - AV interface (handled by this driver)
  1039. */
  1040. if (ifnum != 1)
  1041. return -ENODEV;
  1042. /* Check to see next free device and mark as used */
  1043. do {
  1044. nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
  1045. if (nr >= CX231XX_MAXBOARDS) {
  1046. /* No free device slots */
  1047. cx231xx_err(DRIVER_NAME ": Supports only %i devices.\n",
  1048. CX231XX_MAXBOARDS);
  1049. return -ENOMEM;
  1050. }
  1051. } while (test_and_set_bit(nr, &cx231xx_devused));
  1052. /* allocate memory for our device state and initialize it */
  1053. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  1054. if (dev == NULL) {
  1055. cx231xx_err(DRIVER_NAME ": out of memory!\n");
  1056. clear_bit(nr, &cx231xx_devused);
  1057. return -ENOMEM;
  1058. }
  1059. snprintf(dev->name, 29, "cx231xx #%d", nr);
  1060. dev->devno = nr;
  1061. dev->model = id->driver_info;
  1062. dev->video_mode.alt = -1;
  1063. dev->interface_count++;
  1064. /* reset gpio dir and value */
  1065. dev->gpio_dir = 0;
  1066. dev->gpio_val = 0;
  1067. dev->xc_fw_load_done = 0;
  1068. dev->has_alsa_audio = 1;
  1069. dev->power_mode = -1;
  1070. atomic_set(&dev->devlist_count, 0);
  1071. /* 0 - vbi ; 1 -sliced cc mode */
  1072. dev->vbi_or_sliced_cc_mode = 0;
  1073. /* get maximum no.of IAD interfaces */
  1074. assoc_desc = udev->actconfig->intf_assoc[0];
  1075. dev->max_iad_interface_count = assoc_desc->bInterfaceCount;
  1076. /* init CIR module TBD */
  1077. /*mode_tv: digital=1 or analog=0*/
  1078. dev->mode_tv = 0;
  1079. dev->USE_ISO = transfer_mode;
  1080. switch (udev->speed) {
  1081. case USB_SPEED_LOW:
  1082. speed = "1.5";
  1083. break;
  1084. case USB_SPEED_UNKNOWN:
  1085. case USB_SPEED_FULL:
  1086. speed = "12";
  1087. break;
  1088. case USB_SPEED_HIGH:
  1089. speed = "480";
  1090. break;
  1091. default:
  1092. speed = "unknown";
  1093. }
  1094. cx231xx_info("New device %s %s @ %s Mbps "
  1095. "(%04x:%04x) with %d interfaces\n",
  1096. udev->manufacturer ? udev->manufacturer : "",
  1097. udev->product ? udev->product : "",
  1098. speed,
  1099. le16_to_cpu(udev->descriptor.idVendor),
  1100. le16_to_cpu(udev->descriptor.idProduct),
  1101. dev->max_iad_interface_count);
  1102. /* increment interface count */
  1103. dev->interface_count++;
  1104. /* get device number */
  1105. nr = dev->devno;
  1106. assoc_desc = udev->actconfig->intf_assoc[0];
  1107. if (assoc_desc->bFirstInterface != ifnum) {
  1108. cx231xx_err(DRIVER_NAME ": Not found "
  1109. "matching IAD interface\n");
  1110. clear_bit(dev->devno, &cx231xx_devused);
  1111. kfree(dev);
  1112. dev = NULL;
  1113. return -ENODEV;
  1114. }
  1115. cx231xx_info("registering interface %d\n", ifnum);
  1116. /* save our data pointer in this interface device */
  1117. usb_set_intfdata(interface, dev);
  1118. /*
  1119. * AV device initialization - only done at the last interface
  1120. */
  1121. /* Create v4l2 device */
  1122. retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
  1123. if (retval) {
  1124. cx231xx_errdev("v4l2_device_register failed\n");
  1125. clear_bit(dev->devno, &cx231xx_devused);
  1126. kfree(dev);
  1127. dev = NULL;
  1128. return -EIO;
  1129. }
  1130. /* allocate device struct */
  1131. retval = cx231xx_init_dev(dev, udev, nr);
  1132. if (retval) {
  1133. clear_bit(dev->devno, &cx231xx_devused);
  1134. v4l2_device_unregister(&dev->v4l2_dev);
  1135. kfree(dev);
  1136. dev = NULL;
  1137. usb_set_intfdata(interface, NULL);
  1138. return retval;
  1139. }
  1140. /* compute alternate max packet sizes for video */
  1141. uif = udev->actconfig->interface[dev->current_pcb_config.
  1142. hs_config_info[0].interface_info.video_index + 1];
  1143. dev->video_mode.end_point_addr = uif->altsetting[0].
  1144. endpoint[isoc_pipe].desc.bEndpointAddress;
  1145. dev->video_mode.num_alt = uif->num_altsetting;
  1146. cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
  1147. dev->video_mode.end_point_addr,
  1148. dev->video_mode.num_alt);
  1149. dev->video_mode.alt_max_pkt_size =
  1150. kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL);
  1151. if (dev->video_mode.alt_max_pkt_size == NULL) {
  1152. cx231xx_errdev("out of memory!\n");
  1153. clear_bit(dev->devno, &cx231xx_devused);
  1154. v4l2_device_unregister(&dev->v4l2_dev);
  1155. kfree(dev);
  1156. dev = NULL;
  1157. return -ENOMEM;
  1158. }
  1159. for (i = 0; i < dev->video_mode.num_alt; i++) {
  1160. u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
  1161. desc.wMaxPacketSize);
  1162. dev->video_mode.alt_max_pkt_size[i] =
  1163. (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
  1164. cx231xx_info("Alternate setting %i, max size= %i\n", i,
  1165. dev->video_mode.alt_max_pkt_size[i]);
  1166. }
  1167. /* compute alternate max packet sizes for vbi */
  1168. uif = udev->actconfig->interface[dev->current_pcb_config.
  1169. hs_config_info[0].interface_info.
  1170. vanc_index + 1];
  1171. dev->vbi_mode.end_point_addr =
  1172. uif->altsetting[0].endpoint[isoc_pipe].desc.
  1173. bEndpointAddress;
  1174. dev->vbi_mode.num_alt = uif->num_altsetting;
  1175. cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
  1176. dev->vbi_mode.end_point_addr,
  1177. dev->vbi_mode.num_alt);
  1178. dev->vbi_mode.alt_max_pkt_size =
  1179. kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL);
  1180. if (dev->vbi_mode.alt_max_pkt_size == NULL) {
  1181. cx231xx_errdev("out of memory!\n");
  1182. clear_bit(dev->devno, &cx231xx_devused);
  1183. v4l2_device_unregister(&dev->v4l2_dev);
  1184. kfree(dev);
  1185. dev = NULL;
  1186. return -ENOMEM;
  1187. }
  1188. for (i = 0; i < dev->vbi_mode.num_alt; i++) {
  1189. u16 tmp =
  1190. le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
  1191. desc.wMaxPacketSize);
  1192. dev->vbi_mode.alt_max_pkt_size[i] =
  1193. (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
  1194. cx231xx_info("Alternate setting %i, max size= %i\n", i,
  1195. dev->vbi_mode.alt_max_pkt_size[i]);
  1196. }
  1197. /* compute alternate max packet sizes for sliced CC */
  1198. uif = udev->actconfig->interface[dev->current_pcb_config.
  1199. hs_config_info[0].interface_info.
  1200. hanc_index + 1];
  1201. dev->sliced_cc_mode.end_point_addr =
  1202. uif->altsetting[0].endpoint[isoc_pipe].desc.
  1203. bEndpointAddress;
  1204. dev->sliced_cc_mode.num_alt = uif->num_altsetting;
  1205. cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
  1206. dev->sliced_cc_mode.end_point_addr,
  1207. dev->sliced_cc_mode.num_alt);
  1208. dev->sliced_cc_mode.alt_max_pkt_size =
  1209. kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL);
  1210. if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
  1211. cx231xx_errdev("out of memory!\n");
  1212. clear_bit(dev->devno, &cx231xx_devused);
  1213. v4l2_device_unregister(&dev->v4l2_dev);
  1214. kfree(dev);
  1215. dev = NULL;
  1216. return -ENOMEM;
  1217. }
  1218. for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
  1219. u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
  1220. desc.wMaxPacketSize);
  1221. dev->sliced_cc_mode.alt_max_pkt_size[i] =
  1222. (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
  1223. cx231xx_info("Alternate setting %i, max size= %i\n", i,
  1224. dev->sliced_cc_mode.alt_max_pkt_size[i]);
  1225. }
  1226. if (dev->current_pcb_config.ts1_source != 0xff) {
  1227. /* compute alternate max packet sizes for TS1 */
  1228. uif = udev->actconfig->interface[dev->current_pcb_config.
  1229. hs_config_info[0].
  1230. interface_info.
  1231. ts1_index + 1];
  1232. dev->ts1_mode.end_point_addr =
  1233. uif->altsetting[0].endpoint[isoc_pipe].
  1234. desc.bEndpointAddress;
  1235. dev->ts1_mode.num_alt = uif->num_altsetting;
  1236. cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
  1237. dev->ts1_mode.end_point_addr,
  1238. dev->ts1_mode.num_alt);
  1239. dev->ts1_mode.alt_max_pkt_size =
  1240. kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL);
  1241. if (dev->ts1_mode.alt_max_pkt_size == NULL) {
  1242. cx231xx_errdev("out of memory!\n");
  1243. clear_bit(dev->devno, &cx231xx_devused);
  1244. v4l2_device_unregister(&dev->v4l2_dev);
  1245. kfree(dev);
  1246. dev = NULL;
  1247. return -ENOMEM;
  1248. }
  1249. for (i = 0; i < dev->ts1_mode.num_alt; i++) {
  1250. u16 tmp = le16_to_cpu(uif->altsetting[i].
  1251. endpoint[isoc_pipe].desc.
  1252. wMaxPacketSize);
  1253. dev->ts1_mode.alt_max_pkt_size[i] =
  1254. (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
  1255. cx231xx_info("Alternate setting %i, max size= %i\n", i,
  1256. dev->ts1_mode.alt_max_pkt_size[i]);
  1257. }
  1258. }
  1259. if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) {
  1260. cx231xx_enable_OSC(dev);
  1261. cx231xx_reset_out(dev);
  1262. cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
  1263. }
  1264. if (dev->model == CX231XX_BOARD_CNXT_RDE_253S)
  1265. cx231xx_sleep_s5h1432(dev);
  1266. /* load other modules required */
  1267. request_modules(dev);
  1268. return 0;
  1269. }
  1270. /*
  1271. * cx231xx_usb_disconnect()
  1272. * called when the device gets diconencted
  1273. * video device will be unregistered on v4l2_close in case it is still open
  1274. */
  1275. static void cx231xx_usb_disconnect(struct usb_interface *interface)
  1276. {
  1277. struct cx231xx *dev;
  1278. dev = usb_get_intfdata(interface);
  1279. usb_set_intfdata(interface, NULL);
  1280. if (!dev)
  1281. return;
  1282. if (!dev->udev)
  1283. return;
  1284. dev->state |= DEV_DISCONNECTED;
  1285. flush_request_modules(dev);
  1286. /* wait until all current v4l2 io is finished then deallocate
  1287. resources */
  1288. mutex_lock(&dev->lock);
  1289. wake_up_interruptible_all(&dev->open);
  1290. if (dev->users) {
  1291. cx231xx_warn
  1292. ("device %s is open! Deregistration and memory "
  1293. "deallocation are deferred on close.\n",
  1294. video_device_node_name(dev->vdev));
  1295. /* Even having users, it is safe to remove the RC i2c driver */
  1296. cx231xx_ir_exit(dev);
  1297. if (dev->USE_ISO)
  1298. cx231xx_uninit_isoc(dev);
  1299. else
  1300. cx231xx_uninit_bulk(dev);
  1301. wake_up_interruptible(&dev->wait_frame);
  1302. wake_up_interruptible(&dev->wait_stream);
  1303. } else {
  1304. }
  1305. cx231xx_close_extension(dev);
  1306. mutex_unlock(&dev->lock);
  1307. if (!dev->users)
  1308. cx231xx_release_resources(dev);
  1309. }
  1310. static struct usb_driver cx231xx_usb_driver = {
  1311. .name = "cx231xx",
  1312. .probe = cx231xx_usb_probe,
  1313. .disconnect = cx231xx_usb_disconnect,
  1314. .id_table = cx231xx_id_table,
  1315. };
  1316. module_usb_driver(cx231xx_usb_driver);