cx231xx-cards.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399
  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. .has_417 = 1,
  248. .input = {{
  249. .type = CX231XX_VMUX_COMPOSITE1,
  250. .vmux = CX231XX_VIN_2_1,
  251. .amux = CX231XX_AMUX_LINE_IN,
  252. .gpio = NULL,
  253. }, {
  254. .type = CX231XX_VMUX_SVIDEO,
  255. .vmux = CX231XX_VIN_1_1 |
  256. (CX231XX_VIN_1_2 << 8) |
  257. CX25840_SVIDEO_ON,
  258. .amux = CX231XX_AMUX_LINE_IN,
  259. .gpio = NULL,
  260. }
  261. },
  262. },
  263. [CX231XX_BOARD_CNXT_RDE_250] = {
  264. .name = "Conexant Hybrid TV - rde 250",
  265. .tuner_type = TUNER_XC5000,
  266. .tuner_addr = 0x61,
  267. .tuner_gpio = RDE250_XCV_TUNER,
  268. .tuner_sif_gpio = 0x05,
  269. .tuner_scl_gpio = 0x1a,
  270. .tuner_sda_gpio = 0x1b,
  271. .decoder = CX231XX_AVDECODER,
  272. .output_mode = OUT_MODE_VIP11,
  273. .demod_xfer_mode = 0,
  274. .ctl_pin_status_mask = 0xFFFFFFC4,
  275. .agc_analog_digital_select_gpio = 0x0c,
  276. .gpio_pin_status_mask = 0x4001000,
  277. .tuner_i2c_master = 1,
  278. .demod_i2c_master = 2,
  279. .has_dvb = 1,
  280. .demod_addr = 0x02,
  281. .norm = V4L2_STD_PAL,
  282. .input = {{
  283. .type = CX231XX_VMUX_TELEVISION,
  284. .vmux = CX231XX_VIN_2_1,
  285. .amux = CX231XX_AMUX_VIDEO,
  286. .gpio = NULL,
  287. }
  288. },
  289. },
  290. [CX231XX_BOARD_CNXT_RDU_250] = {
  291. .name = "Conexant Hybrid TV - RDU 250",
  292. .tuner_type = TUNER_XC5000,
  293. .tuner_addr = 0x61,
  294. .tuner_gpio = RDE250_XCV_TUNER,
  295. .tuner_sif_gpio = 0x05,
  296. .tuner_scl_gpio = 0x1a,
  297. .tuner_sda_gpio = 0x1b,
  298. .decoder = CX231XX_AVDECODER,
  299. .output_mode = OUT_MODE_VIP11,
  300. .demod_xfer_mode = 0,
  301. .ctl_pin_status_mask = 0xFFFFFFC4,
  302. .agc_analog_digital_select_gpio = 0x0c,
  303. .gpio_pin_status_mask = 0x4001000,
  304. .tuner_i2c_master = 1,
  305. .demod_i2c_master = 2,
  306. .has_dvb = 1,
  307. .demod_addr = 0x32,
  308. .norm = V4L2_STD_NTSC,
  309. .input = {{
  310. .type = CX231XX_VMUX_TELEVISION,
  311. .vmux = CX231XX_VIN_2_1,
  312. .amux = CX231XX_AMUX_VIDEO,
  313. .gpio = NULL,
  314. }
  315. },
  316. },
  317. [CX231XX_BOARD_HAUPPAUGE_EXETER] = {
  318. .name = "Hauppauge EXETER",
  319. .tuner_type = TUNER_NXP_TDA18271,
  320. .tuner_addr = 0x60,
  321. .tuner_gpio = RDE250_XCV_TUNER,
  322. .tuner_sif_gpio = 0x05,
  323. .tuner_scl_gpio = 0x1a,
  324. .tuner_sda_gpio = 0x1b,
  325. .decoder = CX231XX_AVDECODER,
  326. .output_mode = OUT_MODE_VIP11,
  327. .demod_xfer_mode = 0,
  328. .ctl_pin_status_mask = 0xFFFFFFC4,
  329. .agc_analog_digital_select_gpio = 0x0c,
  330. .gpio_pin_status_mask = 0x4001000,
  331. .tuner_i2c_master = 1,
  332. .demod_i2c_master = 2,
  333. .has_dvb = 1,
  334. .demod_addr = 0x0e,
  335. .norm = V4L2_STD_NTSC,
  336. .input = {{
  337. .type = CX231XX_VMUX_TELEVISION,
  338. .vmux = CX231XX_VIN_3_1,
  339. .amux = CX231XX_AMUX_VIDEO,
  340. .gpio = NULL,
  341. }, {
  342. .type = CX231XX_VMUX_COMPOSITE1,
  343. .vmux = CX231XX_VIN_2_1,
  344. .amux = CX231XX_AMUX_LINE_IN,
  345. .gpio = NULL,
  346. }, {
  347. .type = CX231XX_VMUX_SVIDEO,
  348. .vmux = CX231XX_VIN_1_1 |
  349. (CX231XX_VIN_1_2 << 8) |
  350. CX25840_SVIDEO_ON,
  351. .amux = CX231XX_AMUX_LINE_IN,
  352. .gpio = NULL,
  353. } },
  354. },
  355. [CX231XX_BOARD_HAUPPAUGE_USBLIVE2] = {
  356. .name = "Hauppauge USB Live 2",
  357. .tuner_type = TUNER_ABSENT,
  358. .decoder = CX231XX_AVDECODER,
  359. .output_mode = OUT_MODE_VIP11,
  360. .demod_xfer_mode = 0,
  361. .ctl_pin_status_mask = 0xFFFFFFC4,
  362. .agc_analog_digital_select_gpio = 0x0c,
  363. .gpio_pin_status_mask = 0x4001000,
  364. .norm = V4L2_STD_NTSC,
  365. .no_alt_vanc = 1,
  366. .external_av = 1,
  367. .dont_use_port_3 = 1,
  368. .input = {{
  369. .type = CX231XX_VMUX_COMPOSITE1,
  370. .vmux = CX231XX_VIN_2_1,
  371. .amux = CX231XX_AMUX_LINE_IN,
  372. .gpio = NULL,
  373. }, {
  374. .type = CX231XX_VMUX_SVIDEO,
  375. .vmux = CX231XX_VIN_1_1 |
  376. (CX231XX_VIN_1_2 << 8) |
  377. CX25840_SVIDEO_ON,
  378. .amux = CX231XX_AMUX_LINE_IN,
  379. .gpio = NULL,
  380. } },
  381. },
  382. [CX231XX_BOARD_KWORLD_UB430_USB_HYBRID] = {
  383. .name = "Kworld UB430 USB Hybrid",
  384. .tuner_type = TUNER_NXP_TDA18271,
  385. .tuner_addr = 0x60,
  386. .decoder = CX231XX_AVDECODER,
  387. .output_mode = OUT_MODE_VIP11,
  388. .demod_xfer_mode = 0,
  389. .ctl_pin_status_mask = 0xFFFFFFC4,
  390. .agc_analog_digital_select_gpio = 0x11, /* According with PV cxPolaris.inf file */
  391. .tuner_sif_gpio = -1,
  392. .tuner_scl_gpio = -1,
  393. .tuner_sda_gpio = -1,
  394. .gpio_pin_status_mask = 0x4001000,
  395. .tuner_i2c_master = 2,
  396. .demod_i2c_master = 1,
  397. .ir_i2c_master = 2,
  398. .has_dvb = 1,
  399. .demod_addr = 0x10,
  400. .norm = V4L2_STD_PAL_M,
  401. .input = {{
  402. .type = CX231XX_VMUX_TELEVISION,
  403. .vmux = CX231XX_VIN_3_1,
  404. .amux = CX231XX_AMUX_VIDEO,
  405. .gpio = NULL,
  406. }, {
  407. .type = CX231XX_VMUX_COMPOSITE1,
  408. .vmux = CX231XX_VIN_2_1,
  409. .amux = CX231XX_AMUX_LINE_IN,
  410. .gpio = NULL,
  411. }, {
  412. .type = CX231XX_VMUX_SVIDEO,
  413. .vmux = CX231XX_VIN_1_1 |
  414. (CX231XX_VIN_1_2 << 8) |
  415. CX25840_SVIDEO_ON,
  416. .amux = CX231XX_AMUX_LINE_IN,
  417. .gpio = NULL,
  418. } },
  419. },
  420. [CX231XX_BOARD_PV_PLAYTV_USB_HYBRID] = {
  421. .name = "Pixelview PlayTV USB Hybrid",
  422. .tuner_type = TUNER_NXP_TDA18271,
  423. .tuner_addr = 0x60,
  424. .decoder = CX231XX_AVDECODER,
  425. .output_mode = OUT_MODE_VIP11,
  426. .demod_xfer_mode = 0,
  427. .ctl_pin_status_mask = 0xFFFFFFC4,
  428. .agc_analog_digital_select_gpio = 0x00, /* According with PV cxPolaris.inf file */
  429. .tuner_sif_gpio = -1,
  430. .tuner_scl_gpio = -1,
  431. .tuner_sda_gpio = -1,
  432. .gpio_pin_status_mask = 0x4001000,
  433. .tuner_i2c_master = 2,
  434. .demod_i2c_master = 1,
  435. .ir_i2c_master = 2,
  436. .rc_map_name = RC_MAP_PIXELVIEW_002T,
  437. .has_dvb = 1,
  438. .demod_addr = 0x10,
  439. .norm = V4L2_STD_PAL_M,
  440. .input = {{
  441. .type = CX231XX_VMUX_TELEVISION,
  442. .vmux = CX231XX_VIN_3_1,
  443. .amux = CX231XX_AMUX_VIDEO,
  444. .gpio = NULL,
  445. }, {
  446. .type = CX231XX_VMUX_COMPOSITE1,
  447. .vmux = CX231XX_VIN_2_1,
  448. .amux = CX231XX_AMUX_LINE_IN,
  449. .gpio = NULL,
  450. }, {
  451. .type = CX231XX_VMUX_SVIDEO,
  452. .vmux = CX231XX_VIN_1_1 |
  453. (CX231XX_VIN_1_2 << 8) |
  454. CX25840_SVIDEO_ON,
  455. .amux = CX231XX_AMUX_LINE_IN,
  456. .gpio = NULL,
  457. } },
  458. },
  459. [CX231XX_BOARD_PV_XCAPTURE_USB] = {
  460. .name = "Pixelview Xcapture USB",
  461. .tuner_type = TUNER_ABSENT,
  462. .decoder = CX231XX_AVDECODER,
  463. .output_mode = OUT_MODE_VIP11,
  464. .demod_xfer_mode = 0,
  465. .ctl_pin_status_mask = 0xFFFFFFC4,
  466. .agc_analog_digital_select_gpio = 0x0c,
  467. .gpio_pin_status_mask = 0x4001000,
  468. .norm = V4L2_STD_NTSC,
  469. .no_alt_vanc = 1,
  470. .external_av = 1,
  471. .dont_use_port_3 = 1,
  472. .input = {{
  473. .type = CX231XX_VMUX_COMPOSITE1,
  474. .vmux = CX231XX_VIN_2_1,
  475. .amux = CX231XX_AMUX_LINE_IN,
  476. .gpio = NULL,
  477. }, {
  478. .type = CX231XX_VMUX_SVIDEO,
  479. .vmux = CX231XX_VIN_1_1 |
  480. (CX231XX_VIN_1_2 << 8) |
  481. CX25840_SVIDEO_ON,
  482. .amux = CX231XX_AMUX_LINE_IN,
  483. .gpio = NULL,
  484. }
  485. },
  486. },
  487. [CX231XX_BOARD_ICONBIT_U100] = {
  488. .name = "Iconbit Analog Stick U100 FM",
  489. .tuner_type = TUNER_ABSENT,
  490. .decoder = CX231XX_AVDECODER,
  491. .output_mode = OUT_MODE_VIP11,
  492. .demod_xfer_mode = 0,
  493. .ctl_pin_status_mask = 0xFFFFFFC4,
  494. .agc_analog_digital_select_gpio = 0x1C,
  495. .gpio_pin_status_mask = 0x4001000,
  496. .input = {{
  497. .type = CX231XX_VMUX_COMPOSITE1,
  498. .vmux = CX231XX_VIN_2_1,
  499. .amux = CX231XX_AMUX_LINE_IN,
  500. .gpio = NULL,
  501. }, {
  502. .type = CX231XX_VMUX_SVIDEO,
  503. .vmux = CX231XX_VIN_1_1 |
  504. (CX231XX_VIN_1_2 << 8) |
  505. CX25840_SVIDEO_ON,
  506. .amux = CX231XX_AMUX_LINE_IN,
  507. .gpio = NULL,
  508. } },
  509. },
  510. [CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL] = {
  511. .name = "Hauppauge WinTV USB2 FM (PAL)",
  512. .tuner_type = TUNER_NXP_TDA18271,
  513. .tuner_addr = 0x60,
  514. .tuner_gpio = RDE250_XCV_TUNER,
  515. .tuner_sif_gpio = 0x05,
  516. .tuner_scl_gpio = 0x1a,
  517. .tuner_sda_gpio = 0x1b,
  518. .decoder = CX231XX_AVDECODER,
  519. .output_mode = OUT_MODE_VIP11,
  520. .ctl_pin_status_mask = 0xFFFFFFC4,
  521. .agc_analog_digital_select_gpio = 0x0c,
  522. .gpio_pin_status_mask = 0x4001000,
  523. .tuner_i2c_master = 1,
  524. .norm = V4L2_STD_PAL,
  525. .input = {{
  526. .type = CX231XX_VMUX_TELEVISION,
  527. .vmux = CX231XX_VIN_3_1,
  528. .amux = CX231XX_AMUX_VIDEO,
  529. .gpio = NULL,
  530. }, {
  531. .type = CX231XX_VMUX_COMPOSITE1,
  532. .vmux = CX231XX_VIN_2_1,
  533. .amux = CX231XX_AMUX_LINE_IN,
  534. .gpio = NULL,
  535. }, {
  536. .type = CX231XX_VMUX_SVIDEO,
  537. .vmux = CX231XX_VIN_1_1 |
  538. (CX231XX_VIN_1_2 << 8) |
  539. CX25840_SVIDEO_ON,
  540. .amux = CX231XX_AMUX_LINE_IN,
  541. .gpio = NULL,
  542. } },
  543. },
  544. [CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC] = {
  545. .name = "Hauppauge WinTV USB2 FM (NTSC)",
  546. .tuner_type = TUNER_NXP_TDA18271,
  547. .tuner_addr = 0x60,
  548. .tuner_gpio = RDE250_XCV_TUNER,
  549. .tuner_sif_gpio = 0x05,
  550. .tuner_scl_gpio = 0x1a,
  551. .tuner_sda_gpio = 0x1b,
  552. .decoder = CX231XX_AVDECODER,
  553. .output_mode = OUT_MODE_VIP11,
  554. .ctl_pin_status_mask = 0xFFFFFFC4,
  555. .agc_analog_digital_select_gpio = 0x0c,
  556. .gpio_pin_status_mask = 0x4001000,
  557. .tuner_i2c_master = 1,
  558. .norm = V4L2_STD_NTSC,
  559. .input = {{
  560. .type = CX231XX_VMUX_TELEVISION,
  561. .vmux = CX231XX_VIN_3_1,
  562. .amux = CX231XX_AMUX_VIDEO,
  563. .gpio = NULL,
  564. }, {
  565. .type = CX231XX_VMUX_COMPOSITE1,
  566. .vmux = CX231XX_VIN_2_1,
  567. .amux = CX231XX_AMUX_LINE_IN,
  568. .gpio = NULL,
  569. }, {
  570. .type = CX231XX_VMUX_SVIDEO,
  571. .vmux = CX231XX_VIN_1_1 |
  572. (CX231XX_VIN_1_2 << 8) |
  573. CX25840_SVIDEO_ON,
  574. .amux = CX231XX_AMUX_LINE_IN,
  575. .gpio = NULL,
  576. } },
  577. },
  578. [CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2] = {
  579. .name = "Elgato Video Capture V2",
  580. .tuner_type = TUNER_ABSENT,
  581. .decoder = CX231XX_AVDECODER,
  582. .output_mode = OUT_MODE_VIP11,
  583. .demod_xfer_mode = 0,
  584. .ctl_pin_status_mask = 0xFFFFFFC4,
  585. .agc_analog_digital_select_gpio = 0x0c,
  586. .gpio_pin_status_mask = 0x4001000,
  587. .norm = V4L2_STD_NTSC,
  588. .no_alt_vanc = 1,
  589. .external_av = 1,
  590. .dont_use_port_3 = 1,
  591. .input = {{
  592. .type = CX231XX_VMUX_COMPOSITE1,
  593. .vmux = CX231XX_VIN_2_1,
  594. .amux = CX231XX_AMUX_LINE_IN,
  595. .gpio = NULL,
  596. }, {
  597. .type = CX231XX_VMUX_SVIDEO,
  598. .vmux = CX231XX_VIN_1_1 |
  599. (CX231XX_VIN_1_2 << 8) |
  600. CX25840_SVIDEO_ON,
  601. .amux = CX231XX_AMUX_LINE_IN,
  602. .gpio = NULL,
  603. } },
  604. },
  605. };
  606. const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
  607. /* table of devices that work with this driver */
  608. struct usb_device_id cx231xx_id_table[] = {
  609. {USB_DEVICE(0x0572, 0x5A3C),
  610. .driver_info = CX231XX_BOARD_UNKNOWN},
  611. {USB_DEVICE(0x0572, 0x58A2),
  612. .driver_info = CX231XX_BOARD_CNXT_CARRAERA},
  613. {USB_DEVICE(0x0572, 0x58A1),
  614. .driver_info = CX231XX_BOARD_CNXT_SHELBY},
  615. {USB_DEVICE(0x0572, 0x58A4),
  616. .driver_info = CX231XX_BOARD_CNXT_RDE_253S},
  617. {USB_DEVICE(0x0572, 0x58A5),
  618. .driver_info = CX231XX_BOARD_CNXT_RDU_253S},
  619. {USB_DEVICE(0x0572, 0x58A6),
  620. .driver_info = CX231XX_BOARD_CNXT_VIDEO_GRABBER},
  621. {USB_DEVICE(0x0572, 0x589E),
  622. .driver_info = CX231XX_BOARD_CNXT_RDE_250},
  623. {USB_DEVICE(0x0572, 0x58A0),
  624. .driver_info = CX231XX_BOARD_CNXT_RDU_250},
  625. {USB_DEVICE(0x2040, 0xb110),
  626. .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL},
  627. {USB_DEVICE(0x2040, 0xb111),
  628. .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC},
  629. {USB_DEVICE(0x2040, 0xb120),
  630. .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
  631. {USB_DEVICE(0x2040, 0xb140),
  632. .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
  633. {USB_DEVICE(0x2040, 0xc200),
  634. .driver_info = CX231XX_BOARD_HAUPPAUGE_USBLIVE2},
  635. {USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x4000, 0x4001),
  636. .driver_info = CX231XX_BOARD_PV_PLAYTV_USB_HYBRID},
  637. {USB_DEVICE(USB_VID_PIXELVIEW, 0x5014),
  638. .driver_info = CX231XX_BOARD_PV_XCAPTURE_USB},
  639. {USB_DEVICE(0x1b80, 0xe424),
  640. .driver_info = CX231XX_BOARD_KWORLD_UB430_USB_HYBRID},
  641. {USB_DEVICE(0x1f4d, 0x0237),
  642. .driver_info = CX231XX_BOARD_ICONBIT_U100},
  643. {USB_DEVICE(0x0fd9, 0x0037),
  644. .driver_info = CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2},
  645. {},
  646. };
  647. MODULE_DEVICE_TABLE(usb, cx231xx_id_table);
  648. /* cx231xx_tuner_callback
  649. * will be used to reset XC5000 tuner using GPIO pin
  650. */
  651. int cx231xx_tuner_callback(void *ptr, int component, int command, int arg)
  652. {
  653. int rc = 0;
  654. struct cx231xx *dev = ptr;
  655. if (dev->tuner_type == TUNER_XC5000) {
  656. if (command == XC5000_TUNER_RESET) {
  657. cx231xx_info
  658. ("Tuner CB: RESET: cmd %d : tuner type %d \n",
  659. command, dev->tuner_type);
  660. cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
  661. 1);
  662. msleep(10);
  663. cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
  664. 0);
  665. msleep(330);
  666. cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
  667. 1);
  668. msleep(10);
  669. }
  670. } else if (dev->tuner_type == TUNER_NXP_TDA18271) {
  671. switch (command) {
  672. case TDA18271_CALLBACK_CMD_AGC_ENABLE:
  673. if (dev->model == CX231XX_BOARD_PV_PLAYTV_USB_HYBRID)
  674. rc = cx231xx_set_agc_analog_digital_mux_select(dev, arg);
  675. break;
  676. default:
  677. rc = -EINVAL;
  678. break;
  679. }
  680. }
  681. return rc;
  682. }
  683. EXPORT_SYMBOL_GPL(cx231xx_tuner_callback);
  684. static void cx231xx_reset_out(struct cx231xx *dev)
  685. {
  686. cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
  687. msleep(200);
  688. cx231xx_set_gpio_value(dev, CX23417_RESET, 0);
  689. msleep(200);
  690. cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
  691. }
  692. static void cx231xx_enable_OSC(struct cx231xx *dev)
  693. {
  694. cx231xx_set_gpio_value(dev, CX23417_OSC_EN, 1);
  695. }
  696. static void cx231xx_sleep_s5h1432(struct cx231xx *dev)
  697. {
  698. cx231xx_set_gpio_value(dev, SLEEP_S5H1432, 0);
  699. }
  700. static inline void cx231xx_set_model(struct cx231xx *dev)
  701. {
  702. dev->board = cx231xx_boards[dev->model];
  703. }
  704. /* Since cx231xx_pre_card_setup() requires a proper dev->model,
  705. * this won't work for boards with generic PCI IDs
  706. */
  707. void cx231xx_pre_card_setup(struct cx231xx *dev)
  708. {
  709. cx231xx_set_model(dev);
  710. cx231xx_info("Identified as %s (card=%d)\n",
  711. dev->board.name, dev->model);
  712. /* set the direction for GPIO pins */
  713. if (dev->board.tuner_gpio) {
  714. cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
  715. cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
  716. }
  717. if (dev->board.tuner_sif_gpio >= 0)
  718. cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
  719. /* request some modules if any required */
  720. /* set the mode to Analog mode initially */
  721. cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
  722. /* Unlock device */
  723. /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */
  724. }
  725. static void cx231xx_config_tuner(struct cx231xx *dev)
  726. {
  727. struct tuner_setup tun_setup;
  728. struct v4l2_frequency f;
  729. if (dev->tuner_type == TUNER_ABSENT)
  730. return;
  731. tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
  732. tun_setup.type = dev->tuner_type;
  733. tun_setup.addr = dev->tuner_addr;
  734. tun_setup.tuner_callback = cx231xx_tuner_callback;
  735. tuner_call(dev, tuner, s_type_addr, &tun_setup);
  736. #if 0
  737. if (tun_setup.type == TUNER_XC5000) {
  738. static struct xc2028_ctrl ctrl = {
  739. .fname = XC5000_DEFAULT_FIRMWARE,
  740. .max_len = 64,
  741. .demod = 0;
  742. };
  743. struct v4l2_priv_tun_config cfg = {
  744. .tuner = dev->tuner_type,
  745. .priv = &ctrl,
  746. };
  747. tuner_call(dev, tuner, s_config, &cfg);
  748. }
  749. #endif
  750. /* configure tuner */
  751. f.tuner = 0;
  752. f.type = V4L2_TUNER_ANALOG_TV;
  753. f.frequency = 9076; /* just a magic number */
  754. dev->ctl_freq = f.frequency;
  755. call_all(dev, tuner, s_frequency, &f);
  756. }
  757. void cx231xx_card_setup(struct cx231xx *dev)
  758. {
  759. cx231xx_set_model(dev);
  760. dev->tuner_type = cx231xx_boards[dev->model].tuner_type;
  761. if (cx231xx_boards[dev->model].tuner_addr)
  762. dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr;
  763. /* request some modules */
  764. if (dev->board.decoder == CX231XX_AVDECODER) {
  765. dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
  766. &dev->i2c_bus[0].i2c_adap,
  767. "cx25840", 0x88 >> 1, NULL);
  768. if (dev->sd_cx25840 == NULL)
  769. cx231xx_info("cx25840 subdev registration failure\n");
  770. cx25840_call(dev, core, load_fw);
  771. }
  772. /* Initialize the tuner */
  773. if (dev->board.tuner_type != TUNER_ABSENT) {
  774. dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev,
  775. &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
  776. "tuner",
  777. dev->tuner_addr, NULL);
  778. if (dev->sd_tuner == NULL)
  779. cx231xx_info("tuner subdev registration failure\n");
  780. else
  781. cx231xx_config_tuner(dev);
  782. }
  783. }
  784. /*
  785. * cx231xx_config()
  786. * inits registers with sane defaults
  787. */
  788. int cx231xx_config(struct cx231xx *dev)
  789. {
  790. /* TBD need to add cx231xx specific code */
  791. return 0;
  792. }
  793. /*
  794. * cx231xx_config_i2c()
  795. * configure i2c attached devices
  796. */
  797. void cx231xx_config_i2c(struct cx231xx *dev)
  798. {
  799. /* u32 input = INPUT(dev->video_input)->vmux; */
  800. call_all(dev, video, s_stream, 1);
  801. }
  802. /*
  803. * cx231xx_realease_resources()
  804. * unregisters the v4l2,i2c and usb devices
  805. * called when the device gets disconected or at module unload
  806. */
  807. void cx231xx_release_resources(struct cx231xx *dev)
  808. {
  809. cx231xx_release_analog_resources(dev);
  810. cx231xx_remove_from_devlist(dev);
  811. cx231xx_ir_exit(dev);
  812. /* Release I2C buses */
  813. cx231xx_dev_uninit(dev);
  814. /* delete v4l2 device */
  815. v4l2_device_unregister(&dev->v4l2_dev);
  816. usb_put_dev(dev->udev);
  817. /* Mark device as unused */
  818. clear_bit(dev->devno, &cx231xx_devused);
  819. kfree(dev->video_mode.alt_max_pkt_size);
  820. kfree(dev->vbi_mode.alt_max_pkt_size);
  821. kfree(dev->sliced_cc_mode.alt_max_pkt_size);
  822. kfree(dev->ts1_mode.alt_max_pkt_size);
  823. kfree(dev);
  824. }
  825. /*
  826. * cx231xx_init_dev()
  827. * allocates and inits the device structs, registers i2c bus and v4l device
  828. */
  829. static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
  830. int minor)
  831. {
  832. int retval = -ENOMEM;
  833. int errCode;
  834. unsigned int maxh, maxw;
  835. dev->udev = udev;
  836. mutex_init(&dev->lock);
  837. mutex_init(&dev->ctrl_urb_lock);
  838. mutex_init(&dev->gpio_i2c_lock);
  839. mutex_init(&dev->i2c_lock);
  840. spin_lock_init(&dev->video_mode.slock);
  841. spin_lock_init(&dev->vbi_mode.slock);
  842. spin_lock_init(&dev->sliced_cc_mode.slock);
  843. init_waitqueue_head(&dev->open);
  844. init_waitqueue_head(&dev->wait_frame);
  845. init_waitqueue_head(&dev->wait_stream);
  846. dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg;
  847. dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg;
  848. dev->cx231xx_send_usb_command = cx231xx_send_usb_command;
  849. dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read;
  850. dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write;
  851. /* Query cx231xx to find what pcb config it is related to */
  852. initialize_cx231xx(dev);
  853. /*To workaround error number=-71 on EP0 for VideoGrabber,
  854. need set alt here.*/
  855. if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER ||
  856. dev->model == CX231XX_BOARD_HAUPPAUGE_USBLIVE2) {
  857. cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
  858. cx231xx_set_alt_setting(dev, INDEX_VANC, 1);
  859. }
  860. /* Cx231xx pre card setup */
  861. cx231xx_pre_card_setup(dev);
  862. errCode = cx231xx_config(dev);
  863. if (errCode) {
  864. cx231xx_errdev("error configuring device\n");
  865. return -ENOMEM;
  866. }
  867. /* set default norm */
  868. dev->norm = dev->board.norm;
  869. /* register i2c bus */
  870. errCode = cx231xx_dev_init(dev);
  871. if (errCode < 0) {
  872. cx231xx_dev_uninit(dev);
  873. cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
  874. __func__, errCode);
  875. return errCode;
  876. }
  877. /* Do board specific init */
  878. cx231xx_card_setup(dev);
  879. /* configure the device */
  880. cx231xx_config_i2c(dev);
  881. maxw = norm_maxw(dev);
  882. maxh = norm_maxh(dev);
  883. /* set default image size */
  884. dev->width = maxw;
  885. dev->height = maxh;
  886. dev->interlaced = 0;
  887. dev->video_input = 0;
  888. errCode = cx231xx_config(dev);
  889. if (errCode < 0) {
  890. cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
  891. __func__, errCode);
  892. return errCode;
  893. }
  894. /* init video dma queues */
  895. INIT_LIST_HEAD(&dev->video_mode.vidq.active);
  896. INIT_LIST_HEAD(&dev->video_mode.vidq.queued);
  897. /* init vbi dma queues */
  898. INIT_LIST_HEAD(&dev->vbi_mode.vidq.active);
  899. INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued);
  900. /* Reset other chips required if they are tied up with GPIO pins */
  901. cx231xx_add_into_devlist(dev);
  902. if (dev->board.has_417) {
  903. printk(KERN_INFO "attach 417 %d\n", dev->model);
  904. if (cx231xx_417_register(dev) < 0) {
  905. printk(KERN_ERR
  906. "%s() Failed to register 417 on VID_B\n",
  907. __func__);
  908. }
  909. }
  910. retval = cx231xx_register_analog_devices(dev);
  911. if (retval < 0) {
  912. cx231xx_release_resources(dev);
  913. return retval;
  914. }
  915. cx231xx_ir_init(dev);
  916. cx231xx_init_extension(dev);
  917. return 0;
  918. }
  919. #if defined(CONFIG_MODULES) && defined(MODULE)
  920. static void request_module_async(struct work_struct *work)
  921. {
  922. struct cx231xx *dev = container_of(work,
  923. struct cx231xx, request_module_wk);
  924. if (dev->has_alsa_audio)
  925. request_module("cx231xx-alsa");
  926. if (dev->board.has_dvb)
  927. request_module("cx231xx-dvb");
  928. }
  929. static void request_modules(struct cx231xx *dev)
  930. {
  931. INIT_WORK(&dev->request_module_wk, request_module_async);
  932. schedule_work(&dev->request_module_wk);
  933. }
  934. static void flush_request_modules(struct cx231xx *dev)
  935. {
  936. flush_work(&dev->request_module_wk);
  937. }
  938. #else
  939. #define request_modules(dev)
  940. #define flush_request_modules(dev)
  941. #endif /* CONFIG_MODULES */
  942. /*
  943. * cx231xx_usb_probe()
  944. * checks for supported devices
  945. */
  946. static int cx231xx_usb_probe(struct usb_interface *interface,
  947. const struct usb_device_id *id)
  948. {
  949. struct usb_device *udev;
  950. struct usb_interface *uif;
  951. struct cx231xx *dev = NULL;
  952. int retval = -ENODEV;
  953. int nr = 0, ifnum;
  954. int i, isoc_pipe = 0;
  955. char *speed;
  956. struct usb_interface_assoc_descriptor *assoc_desc;
  957. udev = usb_get_dev(interface_to_usbdev(interface));
  958. ifnum = interface->altsetting[0].desc.bInterfaceNumber;
  959. /*
  960. * Interface number 0 - IR interface (handled by mceusb driver)
  961. * Interface number 1 - AV interface (handled by this driver)
  962. */
  963. if (ifnum != 1)
  964. return -ENODEV;
  965. /* Check to see next free device and mark as used */
  966. do {
  967. nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
  968. if (nr >= CX231XX_MAXBOARDS) {
  969. /* No free device slots */
  970. cx231xx_err(DRIVER_NAME ": Supports only %i devices.\n",
  971. CX231XX_MAXBOARDS);
  972. return -ENOMEM;
  973. }
  974. } while (test_and_set_bit(nr, &cx231xx_devused));
  975. /* allocate memory for our device state and initialize it */
  976. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  977. if (dev == NULL) {
  978. cx231xx_err(DRIVER_NAME ": out of memory!\n");
  979. clear_bit(nr, &cx231xx_devused);
  980. return -ENOMEM;
  981. }
  982. snprintf(dev->name, 29, "cx231xx #%d", nr);
  983. dev->devno = nr;
  984. dev->model = id->driver_info;
  985. dev->video_mode.alt = -1;
  986. dev->interface_count++;
  987. /* reset gpio dir and value */
  988. dev->gpio_dir = 0;
  989. dev->gpio_val = 0;
  990. dev->xc_fw_load_done = 0;
  991. dev->has_alsa_audio = 1;
  992. dev->power_mode = -1;
  993. atomic_set(&dev->devlist_count, 0);
  994. /* 0 - vbi ; 1 -sliced cc mode */
  995. dev->vbi_or_sliced_cc_mode = 0;
  996. /* get maximum no.of IAD interfaces */
  997. assoc_desc = udev->actconfig->intf_assoc[0];
  998. dev->max_iad_interface_count = assoc_desc->bInterfaceCount;
  999. /* init CIR module TBD */
  1000. /*mode_tv: digital=1 or analog=0*/
  1001. dev->mode_tv = 0;
  1002. dev->USE_ISO = transfer_mode;
  1003. switch (udev->speed) {
  1004. case USB_SPEED_LOW:
  1005. speed = "1.5";
  1006. break;
  1007. case USB_SPEED_UNKNOWN:
  1008. case USB_SPEED_FULL:
  1009. speed = "12";
  1010. break;
  1011. case USB_SPEED_HIGH:
  1012. speed = "480";
  1013. break;
  1014. default:
  1015. speed = "unknown";
  1016. }
  1017. cx231xx_info("New device %s %s @ %s Mbps "
  1018. "(%04x:%04x) with %d interfaces\n",
  1019. udev->manufacturer ? udev->manufacturer : "",
  1020. udev->product ? udev->product : "",
  1021. speed,
  1022. le16_to_cpu(udev->descriptor.idVendor),
  1023. le16_to_cpu(udev->descriptor.idProduct),
  1024. dev->max_iad_interface_count);
  1025. /* increment interface count */
  1026. dev->interface_count++;
  1027. /* get device number */
  1028. nr = dev->devno;
  1029. assoc_desc = udev->actconfig->intf_assoc[0];
  1030. if (assoc_desc->bFirstInterface != ifnum) {
  1031. cx231xx_err(DRIVER_NAME ": Not found "
  1032. "matching IAD interface\n");
  1033. clear_bit(dev->devno, &cx231xx_devused);
  1034. kfree(dev);
  1035. dev = NULL;
  1036. return -ENODEV;
  1037. }
  1038. cx231xx_info("registering interface %d\n", ifnum);
  1039. /* save our data pointer in this interface device */
  1040. usb_set_intfdata(interface, dev);
  1041. /*
  1042. * AV device initialization - only done at the last interface
  1043. */
  1044. /* Create v4l2 device */
  1045. retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
  1046. if (retval) {
  1047. cx231xx_errdev("v4l2_device_register failed\n");
  1048. clear_bit(dev->devno, &cx231xx_devused);
  1049. kfree(dev);
  1050. dev = NULL;
  1051. return -EIO;
  1052. }
  1053. /* allocate device struct */
  1054. retval = cx231xx_init_dev(dev, udev, nr);
  1055. if (retval) {
  1056. clear_bit(dev->devno, &cx231xx_devused);
  1057. v4l2_device_unregister(&dev->v4l2_dev);
  1058. kfree(dev);
  1059. dev = NULL;
  1060. usb_set_intfdata(interface, NULL);
  1061. return retval;
  1062. }
  1063. /* compute alternate max packet sizes for video */
  1064. uif = udev->actconfig->interface[dev->current_pcb_config.
  1065. hs_config_info[0].interface_info.video_index + 1];
  1066. dev->video_mode.end_point_addr = le16_to_cpu(uif->altsetting[0].
  1067. endpoint[isoc_pipe].desc.bEndpointAddress);
  1068. dev->video_mode.num_alt = uif->num_altsetting;
  1069. cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
  1070. dev->video_mode.end_point_addr,
  1071. dev->video_mode.num_alt);
  1072. dev->video_mode.alt_max_pkt_size =
  1073. kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL);
  1074. if (dev->video_mode.alt_max_pkt_size == NULL) {
  1075. cx231xx_errdev("out of memory!\n");
  1076. clear_bit(dev->devno, &cx231xx_devused);
  1077. v4l2_device_unregister(&dev->v4l2_dev);
  1078. kfree(dev);
  1079. dev = NULL;
  1080. return -ENOMEM;
  1081. }
  1082. for (i = 0; i < dev->video_mode.num_alt; i++) {
  1083. u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
  1084. desc.wMaxPacketSize);
  1085. dev->video_mode.alt_max_pkt_size[i] =
  1086. (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
  1087. cx231xx_info("Alternate setting %i, max size= %i\n", i,
  1088. dev->video_mode.alt_max_pkt_size[i]);
  1089. }
  1090. /* compute alternate max packet sizes for vbi */
  1091. uif = udev->actconfig->interface[dev->current_pcb_config.
  1092. hs_config_info[0].interface_info.
  1093. vanc_index + 1];
  1094. dev->vbi_mode.end_point_addr =
  1095. le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
  1096. bEndpointAddress);
  1097. dev->vbi_mode.num_alt = uif->num_altsetting;
  1098. cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
  1099. dev->vbi_mode.end_point_addr,
  1100. dev->vbi_mode.num_alt);
  1101. dev->vbi_mode.alt_max_pkt_size =
  1102. kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL);
  1103. if (dev->vbi_mode.alt_max_pkt_size == NULL) {
  1104. cx231xx_errdev("out of memory!\n");
  1105. clear_bit(dev->devno, &cx231xx_devused);
  1106. v4l2_device_unregister(&dev->v4l2_dev);
  1107. kfree(dev);
  1108. dev = NULL;
  1109. return -ENOMEM;
  1110. }
  1111. for (i = 0; i < dev->vbi_mode.num_alt; i++) {
  1112. u16 tmp =
  1113. le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
  1114. desc.wMaxPacketSize);
  1115. dev->vbi_mode.alt_max_pkt_size[i] =
  1116. (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
  1117. cx231xx_info("Alternate setting %i, max size= %i\n", i,
  1118. dev->vbi_mode.alt_max_pkt_size[i]);
  1119. }
  1120. /* compute alternate max packet sizes for sliced CC */
  1121. uif = udev->actconfig->interface[dev->current_pcb_config.
  1122. hs_config_info[0].interface_info.
  1123. hanc_index + 1];
  1124. dev->sliced_cc_mode.end_point_addr =
  1125. le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
  1126. bEndpointAddress);
  1127. dev->sliced_cc_mode.num_alt = uif->num_altsetting;
  1128. cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
  1129. dev->sliced_cc_mode.end_point_addr,
  1130. dev->sliced_cc_mode.num_alt);
  1131. dev->sliced_cc_mode.alt_max_pkt_size =
  1132. kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL);
  1133. if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
  1134. cx231xx_errdev("out of memory!\n");
  1135. clear_bit(dev->devno, &cx231xx_devused);
  1136. v4l2_device_unregister(&dev->v4l2_dev);
  1137. kfree(dev);
  1138. dev = NULL;
  1139. return -ENOMEM;
  1140. }
  1141. for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
  1142. u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
  1143. desc.wMaxPacketSize);
  1144. dev->sliced_cc_mode.alt_max_pkt_size[i] =
  1145. (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
  1146. cx231xx_info("Alternate setting %i, max size= %i\n", i,
  1147. dev->sliced_cc_mode.alt_max_pkt_size[i]);
  1148. }
  1149. if (dev->current_pcb_config.ts1_source != 0xff) {
  1150. /* compute alternate max packet sizes for TS1 */
  1151. uif = udev->actconfig->interface[dev->current_pcb_config.
  1152. hs_config_info[0].
  1153. interface_info.
  1154. ts1_index + 1];
  1155. dev->ts1_mode.end_point_addr =
  1156. le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].
  1157. desc.bEndpointAddress);
  1158. dev->ts1_mode.num_alt = uif->num_altsetting;
  1159. cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
  1160. dev->ts1_mode.end_point_addr,
  1161. dev->ts1_mode.num_alt);
  1162. dev->ts1_mode.alt_max_pkt_size =
  1163. kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL);
  1164. if (dev->ts1_mode.alt_max_pkt_size == NULL) {
  1165. cx231xx_errdev("out of memory!\n");
  1166. clear_bit(dev->devno, &cx231xx_devused);
  1167. v4l2_device_unregister(&dev->v4l2_dev);
  1168. kfree(dev);
  1169. dev = NULL;
  1170. return -ENOMEM;
  1171. }
  1172. for (i = 0; i < dev->ts1_mode.num_alt; i++) {
  1173. u16 tmp = le16_to_cpu(uif->altsetting[i].
  1174. endpoint[isoc_pipe].desc.
  1175. wMaxPacketSize);
  1176. dev->ts1_mode.alt_max_pkt_size[i] =
  1177. (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
  1178. cx231xx_info("Alternate setting %i, max size= %i\n", i,
  1179. dev->ts1_mode.alt_max_pkt_size[i]);
  1180. }
  1181. }
  1182. if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) {
  1183. cx231xx_enable_OSC(dev);
  1184. cx231xx_reset_out(dev);
  1185. cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
  1186. }
  1187. if (dev->model == CX231XX_BOARD_CNXT_RDE_253S)
  1188. cx231xx_sleep_s5h1432(dev);
  1189. /* load other modules required */
  1190. request_modules(dev);
  1191. return 0;
  1192. }
  1193. /*
  1194. * cx231xx_usb_disconnect()
  1195. * called when the device gets diconencted
  1196. * video device will be unregistered on v4l2_close in case it is still open
  1197. */
  1198. static void cx231xx_usb_disconnect(struct usb_interface *interface)
  1199. {
  1200. struct cx231xx *dev;
  1201. dev = usb_get_intfdata(interface);
  1202. usb_set_intfdata(interface, NULL);
  1203. if (!dev)
  1204. return;
  1205. if (!dev->udev)
  1206. return;
  1207. dev->state |= DEV_DISCONNECTED;
  1208. flush_request_modules(dev);
  1209. /* wait until all current v4l2 io is finished then deallocate
  1210. resources */
  1211. mutex_lock(&dev->lock);
  1212. wake_up_interruptible_all(&dev->open);
  1213. if (dev->users) {
  1214. cx231xx_warn
  1215. ("device %s is open! Deregistration and memory "
  1216. "deallocation are deferred on close.\n",
  1217. video_device_node_name(dev->vdev));
  1218. /* Even having users, it is safe to remove the RC i2c driver */
  1219. cx231xx_ir_exit(dev);
  1220. if (dev->USE_ISO)
  1221. cx231xx_uninit_isoc(dev);
  1222. else
  1223. cx231xx_uninit_bulk(dev);
  1224. wake_up_interruptible(&dev->wait_frame);
  1225. wake_up_interruptible(&dev->wait_stream);
  1226. } else {
  1227. }
  1228. cx231xx_close_extension(dev);
  1229. mutex_unlock(&dev->lock);
  1230. if (!dev->users)
  1231. cx231xx_release_resources(dev);
  1232. }
  1233. static struct usb_driver cx231xx_usb_driver = {
  1234. .name = "cx231xx",
  1235. .probe = cx231xx_usb_probe,
  1236. .disconnect = cx231xx_usb_disconnect,
  1237. .id_table = cx231xx_id_table,
  1238. };
  1239. module_usb_driver(cx231xx_usb_driver);