cx231xx-cards.c 31 KB

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