cx231xx-cards.c 37 KB

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