cx231xx-cards.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401
  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. dev->mute = 1; /* maybe not the right place... */
  792. dev->volume = 0x1f;
  793. return 0;
  794. }
  795. /*
  796. * cx231xx_config_i2c()
  797. * configure i2c attached devices
  798. */
  799. void cx231xx_config_i2c(struct cx231xx *dev)
  800. {
  801. /* u32 input = INPUT(dev->video_input)->vmux; */
  802. call_all(dev, video, s_stream, 1);
  803. }
  804. /*
  805. * cx231xx_realease_resources()
  806. * unregisters the v4l2,i2c and usb devices
  807. * called when the device gets disconected or at module unload
  808. */
  809. void cx231xx_release_resources(struct cx231xx *dev)
  810. {
  811. cx231xx_release_analog_resources(dev);
  812. cx231xx_remove_from_devlist(dev);
  813. cx231xx_ir_exit(dev);
  814. /* Release I2C buses */
  815. cx231xx_dev_uninit(dev);
  816. /* delete v4l2 device */
  817. v4l2_device_unregister(&dev->v4l2_dev);
  818. usb_put_dev(dev->udev);
  819. /* Mark device as unused */
  820. clear_bit(dev->devno, &cx231xx_devused);
  821. kfree(dev->video_mode.alt_max_pkt_size);
  822. kfree(dev->vbi_mode.alt_max_pkt_size);
  823. kfree(dev->sliced_cc_mode.alt_max_pkt_size);
  824. kfree(dev->ts1_mode.alt_max_pkt_size);
  825. kfree(dev);
  826. }
  827. /*
  828. * cx231xx_init_dev()
  829. * allocates and inits the device structs, registers i2c bus and v4l device
  830. */
  831. static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
  832. int minor)
  833. {
  834. int retval = -ENOMEM;
  835. int errCode;
  836. unsigned int maxh, maxw;
  837. dev->udev = udev;
  838. mutex_init(&dev->lock);
  839. mutex_init(&dev->ctrl_urb_lock);
  840. mutex_init(&dev->gpio_i2c_lock);
  841. mutex_init(&dev->i2c_lock);
  842. spin_lock_init(&dev->video_mode.slock);
  843. spin_lock_init(&dev->vbi_mode.slock);
  844. spin_lock_init(&dev->sliced_cc_mode.slock);
  845. init_waitqueue_head(&dev->open);
  846. init_waitqueue_head(&dev->wait_frame);
  847. init_waitqueue_head(&dev->wait_stream);
  848. dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg;
  849. dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg;
  850. dev->cx231xx_send_usb_command = cx231xx_send_usb_command;
  851. dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read;
  852. dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write;
  853. /* Query cx231xx to find what pcb config it is related to */
  854. initialize_cx231xx(dev);
  855. /*To workaround error number=-71 on EP0 for VideoGrabber,
  856. need set alt here.*/
  857. if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER ||
  858. dev->model == CX231XX_BOARD_HAUPPAUGE_USBLIVE2) {
  859. cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
  860. cx231xx_set_alt_setting(dev, INDEX_VANC, 1);
  861. }
  862. /* Cx231xx pre card setup */
  863. cx231xx_pre_card_setup(dev);
  864. errCode = cx231xx_config(dev);
  865. if (errCode) {
  866. cx231xx_errdev("error configuring device\n");
  867. return -ENOMEM;
  868. }
  869. /* set default norm */
  870. dev->norm = dev->board.norm;
  871. /* register i2c bus */
  872. errCode = cx231xx_dev_init(dev);
  873. if (errCode < 0) {
  874. cx231xx_dev_uninit(dev);
  875. cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
  876. __func__, errCode);
  877. return errCode;
  878. }
  879. /* Do board specific init */
  880. cx231xx_card_setup(dev);
  881. /* configure the device */
  882. cx231xx_config_i2c(dev);
  883. maxw = norm_maxw(dev);
  884. maxh = norm_maxh(dev);
  885. /* set default image size */
  886. dev->width = maxw;
  887. dev->height = maxh;
  888. dev->interlaced = 0;
  889. dev->video_input = 0;
  890. errCode = cx231xx_config(dev);
  891. if (errCode < 0) {
  892. cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
  893. __func__, errCode);
  894. return errCode;
  895. }
  896. /* init video dma queues */
  897. INIT_LIST_HEAD(&dev->video_mode.vidq.active);
  898. INIT_LIST_HEAD(&dev->video_mode.vidq.queued);
  899. /* init vbi dma queues */
  900. INIT_LIST_HEAD(&dev->vbi_mode.vidq.active);
  901. INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued);
  902. /* Reset other chips required if they are tied up with GPIO pins */
  903. cx231xx_add_into_devlist(dev);
  904. if (dev->board.has_417) {
  905. printk(KERN_INFO "attach 417 %d\n", dev->model);
  906. if (cx231xx_417_register(dev) < 0) {
  907. printk(KERN_ERR
  908. "%s() Failed to register 417 on VID_B\n",
  909. __func__);
  910. }
  911. }
  912. retval = cx231xx_register_analog_devices(dev);
  913. if (retval < 0) {
  914. cx231xx_release_resources(dev);
  915. return retval;
  916. }
  917. cx231xx_ir_init(dev);
  918. cx231xx_init_extension(dev);
  919. return 0;
  920. }
  921. #if defined(CONFIG_MODULES) && defined(MODULE)
  922. static void request_module_async(struct work_struct *work)
  923. {
  924. struct cx231xx *dev = container_of(work,
  925. struct cx231xx, request_module_wk);
  926. if (dev->has_alsa_audio)
  927. request_module("cx231xx-alsa");
  928. if (dev->board.has_dvb)
  929. request_module("cx231xx-dvb");
  930. }
  931. static void request_modules(struct cx231xx *dev)
  932. {
  933. INIT_WORK(&dev->request_module_wk, request_module_async);
  934. schedule_work(&dev->request_module_wk);
  935. }
  936. static void flush_request_modules(struct cx231xx *dev)
  937. {
  938. flush_work(&dev->request_module_wk);
  939. }
  940. #else
  941. #define request_modules(dev)
  942. #define flush_request_modules(dev)
  943. #endif /* CONFIG_MODULES */
  944. /*
  945. * cx231xx_usb_probe()
  946. * checks for supported devices
  947. */
  948. static int cx231xx_usb_probe(struct usb_interface *interface,
  949. const struct usb_device_id *id)
  950. {
  951. struct usb_device *udev;
  952. struct usb_interface *uif;
  953. struct cx231xx *dev = NULL;
  954. int retval = -ENODEV;
  955. int nr = 0, ifnum;
  956. int i, isoc_pipe = 0;
  957. char *speed;
  958. struct usb_interface_assoc_descriptor *assoc_desc;
  959. udev = usb_get_dev(interface_to_usbdev(interface));
  960. ifnum = interface->altsetting[0].desc.bInterfaceNumber;
  961. /*
  962. * Interface number 0 - IR interface (handled by mceusb driver)
  963. * Interface number 1 - AV interface (handled by this driver)
  964. */
  965. if (ifnum != 1)
  966. return -ENODEV;
  967. /* Check to see next free device and mark as used */
  968. do {
  969. nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
  970. if (nr >= CX231XX_MAXBOARDS) {
  971. /* No free device slots */
  972. cx231xx_err(DRIVER_NAME ": Supports only %i devices.\n",
  973. CX231XX_MAXBOARDS);
  974. return -ENOMEM;
  975. }
  976. } while (test_and_set_bit(nr, &cx231xx_devused));
  977. /* allocate memory for our device state and initialize it */
  978. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  979. if (dev == NULL) {
  980. cx231xx_err(DRIVER_NAME ": out of memory!\n");
  981. clear_bit(nr, &cx231xx_devused);
  982. return -ENOMEM;
  983. }
  984. snprintf(dev->name, 29, "cx231xx #%d", nr);
  985. dev->devno = nr;
  986. dev->model = id->driver_info;
  987. dev->video_mode.alt = -1;
  988. dev->interface_count++;
  989. /* reset gpio dir and value */
  990. dev->gpio_dir = 0;
  991. dev->gpio_val = 0;
  992. dev->xc_fw_load_done = 0;
  993. dev->has_alsa_audio = 1;
  994. dev->power_mode = -1;
  995. atomic_set(&dev->devlist_count, 0);
  996. /* 0 - vbi ; 1 -sliced cc mode */
  997. dev->vbi_or_sliced_cc_mode = 0;
  998. /* get maximum no.of IAD interfaces */
  999. assoc_desc = udev->actconfig->intf_assoc[0];
  1000. dev->max_iad_interface_count = assoc_desc->bInterfaceCount;
  1001. /* init CIR module TBD */
  1002. /*mode_tv: digital=1 or analog=0*/
  1003. dev->mode_tv = 0;
  1004. dev->USE_ISO = transfer_mode;
  1005. switch (udev->speed) {
  1006. case USB_SPEED_LOW:
  1007. speed = "1.5";
  1008. break;
  1009. case USB_SPEED_UNKNOWN:
  1010. case USB_SPEED_FULL:
  1011. speed = "12";
  1012. break;
  1013. case USB_SPEED_HIGH:
  1014. speed = "480";
  1015. break;
  1016. default:
  1017. speed = "unknown";
  1018. }
  1019. cx231xx_info("New device %s %s @ %s Mbps "
  1020. "(%04x:%04x) with %d interfaces\n",
  1021. udev->manufacturer ? udev->manufacturer : "",
  1022. udev->product ? udev->product : "",
  1023. speed,
  1024. le16_to_cpu(udev->descriptor.idVendor),
  1025. le16_to_cpu(udev->descriptor.idProduct),
  1026. dev->max_iad_interface_count);
  1027. /* increment interface count */
  1028. dev->interface_count++;
  1029. /* get device number */
  1030. nr = dev->devno;
  1031. assoc_desc = udev->actconfig->intf_assoc[0];
  1032. if (assoc_desc->bFirstInterface != ifnum) {
  1033. cx231xx_err(DRIVER_NAME ": Not found "
  1034. "matching IAD interface\n");
  1035. clear_bit(dev->devno, &cx231xx_devused);
  1036. kfree(dev);
  1037. dev = NULL;
  1038. return -ENODEV;
  1039. }
  1040. cx231xx_info("registering interface %d\n", ifnum);
  1041. /* save our data pointer in this interface device */
  1042. usb_set_intfdata(interface, dev);
  1043. /*
  1044. * AV device initialization - only done at the last interface
  1045. */
  1046. /* Create v4l2 device */
  1047. retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
  1048. if (retval) {
  1049. cx231xx_errdev("v4l2_device_register failed\n");
  1050. clear_bit(dev->devno, &cx231xx_devused);
  1051. kfree(dev);
  1052. dev = NULL;
  1053. return -EIO;
  1054. }
  1055. /* allocate device struct */
  1056. retval = cx231xx_init_dev(dev, udev, nr);
  1057. if (retval) {
  1058. clear_bit(dev->devno, &cx231xx_devused);
  1059. v4l2_device_unregister(&dev->v4l2_dev);
  1060. kfree(dev);
  1061. dev = NULL;
  1062. usb_set_intfdata(interface, NULL);
  1063. return retval;
  1064. }
  1065. /* compute alternate max packet sizes for video */
  1066. uif = udev->actconfig->interface[dev->current_pcb_config.
  1067. hs_config_info[0].interface_info.video_index + 1];
  1068. dev->video_mode.end_point_addr = le16_to_cpu(uif->altsetting[0].
  1069. endpoint[isoc_pipe].desc.bEndpointAddress);
  1070. dev->video_mode.num_alt = uif->num_altsetting;
  1071. cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
  1072. dev->video_mode.end_point_addr,
  1073. dev->video_mode.num_alt);
  1074. dev->video_mode.alt_max_pkt_size =
  1075. kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL);
  1076. if (dev->video_mode.alt_max_pkt_size == NULL) {
  1077. cx231xx_errdev("out of memory!\n");
  1078. clear_bit(dev->devno, &cx231xx_devused);
  1079. v4l2_device_unregister(&dev->v4l2_dev);
  1080. kfree(dev);
  1081. dev = NULL;
  1082. return -ENOMEM;
  1083. }
  1084. for (i = 0; i < dev->video_mode.num_alt; i++) {
  1085. u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
  1086. desc.wMaxPacketSize);
  1087. dev->video_mode.alt_max_pkt_size[i] =
  1088. (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
  1089. cx231xx_info("Alternate setting %i, max size= %i\n", i,
  1090. dev->video_mode.alt_max_pkt_size[i]);
  1091. }
  1092. /* compute alternate max packet sizes for vbi */
  1093. uif = udev->actconfig->interface[dev->current_pcb_config.
  1094. hs_config_info[0].interface_info.
  1095. vanc_index + 1];
  1096. dev->vbi_mode.end_point_addr =
  1097. le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
  1098. bEndpointAddress);
  1099. dev->vbi_mode.num_alt = uif->num_altsetting;
  1100. cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
  1101. dev->vbi_mode.end_point_addr,
  1102. dev->vbi_mode.num_alt);
  1103. dev->vbi_mode.alt_max_pkt_size =
  1104. kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL);
  1105. if (dev->vbi_mode.alt_max_pkt_size == NULL) {
  1106. cx231xx_errdev("out of memory!\n");
  1107. clear_bit(dev->devno, &cx231xx_devused);
  1108. v4l2_device_unregister(&dev->v4l2_dev);
  1109. kfree(dev);
  1110. dev = NULL;
  1111. return -ENOMEM;
  1112. }
  1113. for (i = 0; i < dev->vbi_mode.num_alt; i++) {
  1114. u16 tmp =
  1115. le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
  1116. desc.wMaxPacketSize);
  1117. dev->vbi_mode.alt_max_pkt_size[i] =
  1118. (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
  1119. cx231xx_info("Alternate setting %i, max size= %i\n", i,
  1120. dev->vbi_mode.alt_max_pkt_size[i]);
  1121. }
  1122. /* compute alternate max packet sizes for sliced CC */
  1123. uif = udev->actconfig->interface[dev->current_pcb_config.
  1124. hs_config_info[0].interface_info.
  1125. hanc_index + 1];
  1126. dev->sliced_cc_mode.end_point_addr =
  1127. le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
  1128. bEndpointAddress);
  1129. dev->sliced_cc_mode.num_alt = uif->num_altsetting;
  1130. cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
  1131. dev->sliced_cc_mode.end_point_addr,
  1132. dev->sliced_cc_mode.num_alt);
  1133. dev->sliced_cc_mode.alt_max_pkt_size =
  1134. kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL);
  1135. if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
  1136. cx231xx_errdev("out of memory!\n");
  1137. clear_bit(dev->devno, &cx231xx_devused);
  1138. v4l2_device_unregister(&dev->v4l2_dev);
  1139. kfree(dev);
  1140. dev = NULL;
  1141. return -ENOMEM;
  1142. }
  1143. for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
  1144. u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
  1145. desc.wMaxPacketSize);
  1146. dev->sliced_cc_mode.alt_max_pkt_size[i] =
  1147. (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
  1148. cx231xx_info("Alternate setting %i, max size= %i\n", i,
  1149. dev->sliced_cc_mode.alt_max_pkt_size[i]);
  1150. }
  1151. if (dev->current_pcb_config.ts1_source != 0xff) {
  1152. /* compute alternate max packet sizes for TS1 */
  1153. uif = udev->actconfig->interface[dev->current_pcb_config.
  1154. hs_config_info[0].
  1155. interface_info.
  1156. ts1_index + 1];
  1157. dev->ts1_mode.end_point_addr =
  1158. le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].
  1159. desc.bEndpointAddress);
  1160. dev->ts1_mode.num_alt = uif->num_altsetting;
  1161. cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
  1162. dev->ts1_mode.end_point_addr,
  1163. dev->ts1_mode.num_alt);
  1164. dev->ts1_mode.alt_max_pkt_size =
  1165. kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL);
  1166. if (dev->ts1_mode.alt_max_pkt_size == NULL) {
  1167. cx231xx_errdev("out of memory!\n");
  1168. clear_bit(dev->devno, &cx231xx_devused);
  1169. v4l2_device_unregister(&dev->v4l2_dev);
  1170. kfree(dev);
  1171. dev = NULL;
  1172. return -ENOMEM;
  1173. }
  1174. for (i = 0; i < dev->ts1_mode.num_alt; i++) {
  1175. u16 tmp = le16_to_cpu(uif->altsetting[i].
  1176. endpoint[isoc_pipe].desc.
  1177. wMaxPacketSize);
  1178. dev->ts1_mode.alt_max_pkt_size[i] =
  1179. (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
  1180. cx231xx_info("Alternate setting %i, max size= %i\n", i,
  1181. dev->ts1_mode.alt_max_pkt_size[i]);
  1182. }
  1183. }
  1184. if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) {
  1185. cx231xx_enable_OSC(dev);
  1186. cx231xx_reset_out(dev);
  1187. cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
  1188. }
  1189. if (dev->model == CX231XX_BOARD_CNXT_RDE_253S)
  1190. cx231xx_sleep_s5h1432(dev);
  1191. /* load other modules required */
  1192. request_modules(dev);
  1193. return 0;
  1194. }
  1195. /*
  1196. * cx231xx_usb_disconnect()
  1197. * called when the device gets diconencted
  1198. * video device will be unregistered on v4l2_close in case it is still open
  1199. */
  1200. static void cx231xx_usb_disconnect(struct usb_interface *interface)
  1201. {
  1202. struct cx231xx *dev;
  1203. dev = usb_get_intfdata(interface);
  1204. usb_set_intfdata(interface, NULL);
  1205. if (!dev)
  1206. return;
  1207. if (!dev->udev)
  1208. return;
  1209. dev->state |= DEV_DISCONNECTED;
  1210. flush_request_modules(dev);
  1211. /* wait until all current v4l2 io is finished then deallocate
  1212. resources */
  1213. mutex_lock(&dev->lock);
  1214. wake_up_interruptible_all(&dev->open);
  1215. if (dev->users) {
  1216. cx231xx_warn
  1217. ("device %s is open! Deregistration and memory "
  1218. "deallocation are deferred on close.\n",
  1219. video_device_node_name(dev->vdev));
  1220. /* Even having users, it is safe to remove the RC i2c driver */
  1221. cx231xx_ir_exit(dev);
  1222. if (dev->USE_ISO)
  1223. cx231xx_uninit_isoc(dev);
  1224. else
  1225. cx231xx_uninit_bulk(dev);
  1226. wake_up_interruptible(&dev->wait_frame);
  1227. wake_up_interruptible(&dev->wait_stream);
  1228. } else {
  1229. }
  1230. cx231xx_close_extension(dev);
  1231. mutex_unlock(&dev->lock);
  1232. if (!dev->users)
  1233. cx231xx_release_resources(dev);
  1234. }
  1235. static struct usb_driver cx231xx_usb_driver = {
  1236. .name = "cx231xx",
  1237. .probe = cx231xx_usb_probe,
  1238. .disconnect = cx231xx_usb_disconnect,
  1239. .id_table = cx231xx_id_table,
  1240. };
  1241. module_usb_driver(cx231xx_usb_driver);