cx231xx-cards.c 37 KB

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