cx231xx-cards.c 36 KB

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