cx231xx-cards.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382
  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. };
  579. const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
  580. /* table of devices that work with this driver */
  581. struct usb_device_id cx231xx_id_table[] = {
  582. {USB_DEVICE(0x0572, 0x5A3C),
  583. .driver_info = CX231XX_BOARD_UNKNOWN},
  584. {USB_DEVICE(0x0572, 0x58A2),
  585. .driver_info = CX231XX_BOARD_CNXT_CARRAERA},
  586. {USB_DEVICE(0x0572, 0x58A1),
  587. .driver_info = CX231XX_BOARD_CNXT_SHELBY},
  588. {USB_DEVICE(0x0572, 0x58A4),
  589. .driver_info = CX231XX_BOARD_CNXT_RDE_253S},
  590. {USB_DEVICE(0x0572, 0x58A5),
  591. .driver_info = CX231XX_BOARD_CNXT_RDU_253S},
  592. {USB_DEVICE(0x0572, 0x58A6),
  593. .driver_info = CX231XX_BOARD_CNXT_VIDEO_GRABBER},
  594. {USB_DEVICE(0x0572, 0x589E),
  595. .driver_info = CX231XX_BOARD_CNXT_RDE_250},
  596. {USB_DEVICE(0x0572, 0x58A0),
  597. .driver_info = CX231XX_BOARD_CNXT_RDU_250},
  598. {USB_DEVICE(0x2040, 0xb110),
  599. .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL},
  600. {USB_DEVICE(0x2040, 0xb111),
  601. .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC},
  602. {USB_DEVICE(0x2040, 0xb120),
  603. .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
  604. {USB_DEVICE(0x2040, 0xb140),
  605. .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
  606. {USB_DEVICE(0x2040, 0xc200),
  607. .driver_info = CX231XX_BOARD_HAUPPAUGE_USBLIVE2},
  608. {USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x4000, 0x4001),
  609. .driver_info = CX231XX_BOARD_PV_PLAYTV_USB_HYBRID},
  610. {USB_DEVICE(USB_VID_PIXELVIEW, 0x5014),
  611. .driver_info = CX231XX_BOARD_PV_XCAPTURE_USB},
  612. {USB_DEVICE(0x1b80, 0xe424),
  613. .driver_info = CX231XX_BOARD_KWORLD_UB430_USB_HYBRID},
  614. {USB_DEVICE(0x1f4d, 0x0237),
  615. .driver_info = CX231XX_BOARD_ICONBIT_U100},
  616. {},
  617. };
  618. MODULE_DEVICE_TABLE(usb, cx231xx_id_table);
  619. /* cx231xx_tuner_callback
  620. * will be used to reset XC5000 tuner using GPIO pin
  621. */
  622. int cx231xx_tuner_callback(void *ptr, int component, int command, int arg)
  623. {
  624. int rc = 0;
  625. struct cx231xx *dev = ptr;
  626. if (dev->tuner_type == TUNER_XC5000) {
  627. if (command == XC5000_TUNER_RESET) {
  628. cx231xx_info
  629. ("Tuner CB: RESET: cmd %d : tuner type %d \n",
  630. command, dev->tuner_type);
  631. cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
  632. 1);
  633. msleep(10);
  634. cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
  635. 0);
  636. msleep(330);
  637. cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
  638. 1);
  639. msleep(10);
  640. }
  641. } else if (dev->tuner_type == TUNER_NXP_TDA18271) {
  642. switch (command) {
  643. case TDA18271_CALLBACK_CMD_AGC_ENABLE:
  644. if (dev->model == CX231XX_BOARD_PV_PLAYTV_USB_HYBRID)
  645. rc = cx231xx_set_agc_analog_digital_mux_select(dev, arg);
  646. break;
  647. default:
  648. rc = -EINVAL;
  649. break;
  650. }
  651. }
  652. return rc;
  653. }
  654. EXPORT_SYMBOL_GPL(cx231xx_tuner_callback);
  655. void cx231xx_reset_out(struct cx231xx *dev)
  656. {
  657. cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
  658. msleep(200);
  659. cx231xx_set_gpio_value(dev, CX23417_RESET, 0);
  660. msleep(200);
  661. cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
  662. }
  663. void cx231xx_enable_OSC(struct cx231xx *dev)
  664. {
  665. cx231xx_set_gpio_value(dev, CX23417_OSC_EN, 1);
  666. }
  667. void cx231xx_sleep_s5h1432(struct cx231xx *dev)
  668. {
  669. cx231xx_set_gpio_value(dev, SLEEP_S5H1432, 0);
  670. }
  671. static inline void cx231xx_set_model(struct cx231xx *dev)
  672. {
  673. memcpy(&dev->board, &cx231xx_boards[dev->model], sizeof(dev->board));
  674. }
  675. /* Since cx231xx_pre_card_setup() requires a proper dev->model,
  676. * this won't work for boards with generic PCI IDs
  677. */
  678. void cx231xx_pre_card_setup(struct cx231xx *dev)
  679. {
  680. cx231xx_set_model(dev);
  681. cx231xx_info("Identified as %s (card=%d)\n",
  682. dev->board.name, dev->model);
  683. /* set the direction for GPIO pins */
  684. if (dev->board.tuner_gpio) {
  685. cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
  686. cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
  687. }
  688. if (dev->board.tuner_sif_gpio >= 0)
  689. cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
  690. /* request some modules if any required */
  691. /* set the mode to Analog mode initially */
  692. cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
  693. /* Unlock device */
  694. /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */
  695. }
  696. static void cx231xx_config_tuner(struct cx231xx *dev)
  697. {
  698. struct tuner_setup tun_setup;
  699. struct v4l2_frequency f;
  700. if (dev->tuner_type == TUNER_ABSENT)
  701. return;
  702. tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
  703. tun_setup.type = dev->tuner_type;
  704. tun_setup.addr = dev->tuner_addr;
  705. tun_setup.tuner_callback = cx231xx_tuner_callback;
  706. tuner_call(dev, tuner, s_type_addr, &tun_setup);
  707. #if 0
  708. if (tun_setup.type == TUNER_XC5000) {
  709. static struct xc2028_ctrl ctrl = {
  710. .fname = XC5000_DEFAULT_FIRMWARE,
  711. .max_len = 64,
  712. .demod = 0;
  713. };
  714. struct v4l2_priv_tun_config cfg = {
  715. .tuner = dev->tuner_type,
  716. .priv = &ctrl,
  717. };
  718. tuner_call(dev, tuner, s_config, &cfg);
  719. }
  720. #endif
  721. /* configure tuner */
  722. f.tuner = 0;
  723. f.type = V4L2_TUNER_ANALOG_TV;
  724. f.frequency = 9076; /* just a magic number */
  725. dev->ctl_freq = f.frequency;
  726. call_all(dev, tuner, s_frequency, &f);
  727. }
  728. void cx231xx_card_setup(struct cx231xx *dev)
  729. {
  730. cx231xx_set_model(dev);
  731. dev->tuner_type = cx231xx_boards[dev->model].tuner_type;
  732. if (cx231xx_boards[dev->model].tuner_addr)
  733. dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr;
  734. /* request some modules */
  735. if (dev->board.decoder == CX231XX_AVDECODER) {
  736. dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
  737. &dev->i2c_bus[0].i2c_adap,
  738. "cx25840", 0x88 >> 1, NULL);
  739. if (dev->sd_cx25840 == NULL)
  740. cx231xx_info("cx25840 subdev registration failure\n");
  741. cx25840_call(dev, core, load_fw);
  742. }
  743. /* Initialize the tuner */
  744. if (dev->board.tuner_type != TUNER_ABSENT) {
  745. dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev,
  746. &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
  747. "tuner",
  748. dev->tuner_addr, NULL);
  749. if (dev->sd_tuner == NULL)
  750. cx231xx_info("tuner subdev registration failure\n");
  751. else
  752. cx231xx_config_tuner(dev);
  753. }
  754. }
  755. /*
  756. * cx231xx_config()
  757. * inits registers with sane defaults
  758. */
  759. int cx231xx_config(struct cx231xx *dev)
  760. {
  761. /* TBD need to add cx231xx specific code */
  762. dev->mute = 1; /* maybe not the right place... */
  763. dev->volume = 0x1f;
  764. return 0;
  765. }
  766. /*
  767. * cx231xx_config_i2c()
  768. * configure i2c attached devices
  769. */
  770. void cx231xx_config_i2c(struct cx231xx *dev)
  771. {
  772. /* u32 input = INPUT(dev->video_input)->vmux; */
  773. call_all(dev, video, s_stream, 1);
  774. }
  775. /*
  776. * cx231xx_realease_resources()
  777. * unregisters the v4l2,i2c and usb devices
  778. * called when the device gets disconected or at module unload
  779. */
  780. void cx231xx_release_resources(struct cx231xx *dev)
  781. {
  782. cx231xx_release_analog_resources(dev);
  783. cx231xx_remove_from_devlist(dev);
  784. cx231xx_ir_exit(dev);
  785. /* Release I2C buses */
  786. cx231xx_dev_uninit(dev);
  787. /* delete v4l2 device */
  788. v4l2_device_unregister(&dev->v4l2_dev);
  789. usb_put_dev(dev->udev);
  790. /* Mark device as unused */
  791. clear_bit(dev->devno, &cx231xx_devused);
  792. kfree(dev->video_mode.alt_max_pkt_size);
  793. kfree(dev->vbi_mode.alt_max_pkt_size);
  794. kfree(dev->sliced_cc_mode.alt_max_pkt_size);
  795. kfree(dev->ts1_mode.alt_max_pkt_size);
  796. kfree(dev);
  797. }
  798. /*
  799. * cx231xx_init_dev()
  800. * allocates and inits the device structs, registers i2c bus and v4l device
  801. */
  802. static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
  803. int minor)
  804. {
  805. int retval = -ENOMEM;
  806. int errCode;
  807. unsigned int maxh, maxw;
  808. dev->udev = udev;
  809. mutex_init(&dev->lock);
  810. mutex_init(&dev->ctrl_urb_lock);
  811. mutex_init(&dev->gpio_i2c_lock);
  812. mutex_init(&dev->i2c_lock);
  813. spin_lock_init(&dev->video_mode.slock);
  814. spin_lock_init(&dev->vbi_mode.slock);
  815. spin_lock_init(&dev->sliced_cc_mode.slock);
  816. init_waitqueue_head(&dev->open);
  817. init_waitqueue_head(&dev->wait_frame);
  818. init_waitqueue_head(&dev->wait_stream);
  819. dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg;
  820. dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg;
  821. dev->cx231xx_send_usb_command = cx231xx_send_usb_command;
  822. dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read;
  823. dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write;
  824. /* Query cx231xx to find what pcb config it is related to */
  825. initialize_cx231xx(dev);
  826. /*To workaround error number=-71 on EP0 for VideoGrabber,
  827. need set alt here.*/
  828. if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER ||
  829. dev->model == CX231XX_BOARD_HAUPPAUGE_USBLIVE2) {
  830. cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
  831. cx231xx_set_alt_setting(dev, INDEX_VANC, 1);
  832. }
  833. /* Cx231xx pre card setup */
  834. cx231xx_pre_card_setup(dev);
  835. errCode = cx231xx_config(dev);
  836. if (errCode) {
  837. cx231xx_errdev("error configuring device\n");
  838. return -ENOMEM;
  839. }
  840. /* set default norm */
  841. dev->norm = dev->board.norm;
  842. /* register i2c bus */
  843. errCode = cx231xx_dev_init(dev);
  844. if (errCode < 0) {
  845. cx231xx_dev_uninit(dev);
  846. cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
  847. __func__, errCode);
  848. return errCode;
  849. }
  850. /* Do board specific init */
  851. cx231xx_card_setup(dev);
  852. /* configure the device */
  853. cx231xx_config_i2c(dev);
  854. maxw = norm_maxw(dev);
  855. maxh = norm_maxh(dev);
  856. /* set default image size */
  857. dev->width = maxw;
  858. dev->height = maxh;
  859. dev->interlaced = 0;
  860. dev->video_input = 0;
  861. errCode = cx231xx_config(dev);
  862. if (errCode < 0) {
  863. cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
  864. __func__, errCode);
  865. return errCode;
  866. }
  867. /* init video dma queues */
  868. INIT_LIST_HEAD(&dev->video_mode.vidq.active);
  869. INIT_LIST_HEAD(&dev->video_mode.vidq.queued);
  870. /* init vbi dma queues */
  871. INIT_LIST_HEAD(&dev->vbi_mode.vidq.active);
  872. INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued);
  873. /* Reset other chips required if they are tied up with GPIO pins */
  874. cx231xx_add_into_devlist(dev);
  875. if (dev->board.has_417) {
  876. printk(KERN_INFO "attach 417 %d\n", dev->model);
  877. if (cx231xx_417_register(dev) < 0) {
  878. printk(KERN_ERR
  879. "%s() Failed to register 417 on VID_B\n",
  880. __func__);
  881. }
  882. }
  883. retval = cx231xx_register_analog_devices(dev);
  884. if (retval < 0) {
  885. cx231xx_release_resources(dev);
  886. return retval;
  887. }
  888. cx231xx_ir_init(dev);
  889. cx231xx_init_extension(dev);
  890. return 0;
  891. }
  892. #if defined(CONFIG_MODULES) && defined(MODULE)
  893. static void request_module_async(struct work_struct *work)
  894. {
  895. struct cx231xx *dev = container_of(work,
  896. struct cx231xx, request_module_wk);
  897. if (dev->has_alsa_audio)
  898. request_module("cx231xx-alsa");
  899. if (dev->board.has_dvb)
  900. request_module("cx231xx-dvb");
  901. }
  902. static void request_modules(struct cx231xx *dev)
  903. {
  904. INIT_WORK(&dev->request_module_wk, request_module_async);
  905. schedule_work(&dev->request_module_wk);
  906. }
  907. static void flush_request_modules(struct cx231xx *dev)
  908. {
  909. flush_work_sync(&dev->request_module_wk);
  910. }
  911. #else
  912. #define request_modules(dev)
  913. #define flush_request_modules(dev)
  914. #endif /* CONFIG_MODULES */
  915. /*
  916. * cx231xx_usb_probe()
  917. * checks for supported devices
  918. */
  919. static int cx231xx_usb_probe(struct usb_interface *interface,
  920. const struct usb_device_id *id)
  921. {
  922. struct usb_device *udev;
  923. struct usb_interface *uif;
  924. struct cx231xx *dev = NULL;
  925. int retval = -ENODEV;
  926. int nr = 0, ifnum;
  927. int i, isoc_pipe = 0;
  928. char *speed;
  929. char descr[255] = "";
  930. struct usb_interface_assoc_descriptor *assoc_desc;
  931. udev = usb_get_dev(interface_to_usbdev(interface));
  932. ifnum = interface->altsetting[0].desc.bInterfaceNumber;
  933. /*
  934. * Interface number 0 - IR interface (handled by mceusb driver)
  935. * Interface number 1 - AV interface (handled by this driver)
  936. */
  937. if (ifnum != 1)
  938. return -ENODEV;
  939. /* Check to see next free device and mark as used */
  940. do {
  941. nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
  942. if (nr >= CX231XX_MAXBOARDS) {
  943. /* No free device slots */
  944. cx231xx_err(DRIVER_NAME ": Supports only %i devices.\n",
  945. CX231XX_MAXBOARDS);
  946. return -ENOMEM;
  947. }
  948. } while (test_and_set_bit(nr, &cx231xx_devused));
  949. /* allocate memory for our device state and initialize it */
  950. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  951. if (dev == NULL) {
  952. cx231xx_err(DRIVER_NAME ": out of memory!\n");
  953. clear_bit(nr, &cx231xx_devused);
  954. return -ENOMEM;
  955. }
  956. snprintf(dev->name, 29, "cx231xx #%d", nr);
  957. dev->devno = nr;
  958. dev->model = id->driver_info;
  959. dev->video_mode.alt = -1;
  960. dev->interface_count++;
  961. /* reset gpio dir and value */
  962. dev->gpio_dir = 0;
  963. dev->gpio_val = 0;
  964. dev->xc_fw_load_done = 0;
  965. dev->has_alsa_audio = 1;
  966. dev->power_mode = -1;
  967. atomic_set(&dev->devlist_count, 0);
  968. /* 0 - vbi ; 1 -sliced cc mode */
  969. dev->vbi_or_sliced_cc_mode = 0;
  970. /* get maximum no.of IAD interfaces */
  971. assoc_desc = udev->actconfig->intf_assoc[0];
  972. dev->max_iad_interface_count = assoc_desc->bInterfaceCount;
  973. /* init CIR module TBD */
  974. /*mode_tv: digital=1 or analog=0*/
  975. dev->mode_tv = 0;
  976. dev->USE_ISO = transfer_mode;
  977. switch (udev->speed) {
  978. case USB_SPEED_LOW:
  979. speed = "1.5";
  980. break;
  981. case USB_SPEED_UNKNOWN:
  982. case USB_SPEED_FULL:
  983. speed = "12";
  984. break;
  985. case USB_SPEED_HIGH:
  986. speed = "480";
  987. break;
  988. default:
  989. speed = "unknown";
  990. }
  991. if (udev->manufacturer)
  992. strlcpy(descr, udev->manufacturer, sizeof(descr));
  993. if (udev->product) {
  994. if (*descr)
  995. strlcat(descr, " ", sizeof(descr));
  996. strlcat(descr, udev->product, sizeof(descr));
  997. }
  998. if (*descr)
  999. strlcat(descr, " ", sizeof(descr));
  1000. cx231xx_info("New device %s@ %s Mbps "
  1001. "(%04x:%04x) with %d interfaces\n",
  1002. descr,
  1003. speed,
  1004. le16_to_cpu(udev->descriptor.idVendor),
  1005. le16_to_cpu(udev->descriptor.idProduct),
  1006. dev->max_iad_interface_count);
  1007. /* increment interface count */
  1008. dev->interface_count++;
  1009. /* get device number */
  1010. nr = dev->devno;
  1011. assoc_desc = udev->actconfig->intf_assoc[0];
  1012. if (assoc_desc->bFirstInterface != ifnum) {
  1013. cx231xx_err(DRIVER_NAME ": Not found "
  1014. "matching IAD interface\n");
  1015. clear_bit(dev->devno, &cx231xx_devused);
  1016. kfree(dev);
  1017. dev = NULL;
  1018. return -ENODEV;
  1019. }
  1020. cx231xx_info("registering interface %d\n", ifnum);
  1021. /* save our data pointer in this interface device */
  1022. usb_set_intfdata(interface, dev);
  1023. /*
  1024. * AV device initialization - only done at the last interface
  1025. */
  1026. /* Create v4l2 device */
  1027. retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
  1028. if (retval) {
  1029. cx231xx_errdev("v4l2_device_register failed\n");
  1030. clear_bit(dev->devno, &cx231xx_devused);
  1031. kfree(dev);
  1032. dev = NULL;
  1033. return -EIO;
  1034. }
  1035. /* allocate device struct */
  1036. retval = cx231xx_init_dev(dev, udev, nr);
  1037. if (retval) {
  1038. clear_bit(dev->devno, &cx231xx_devused);
  1039. v4l2_device_unregister(&dev->v4l2_dev);
  1040. kfree(dev);
  1041. dev = NULL;
  1042. usb_set_intfdata(interface, NULL);
  1043. return retval;
  1044. }
  1045. /* compute alternate max packet sizes for video */
  1046. uif = udev->actconfig->interface[dev->current_pcb_config.
  1047. hs_config_info[0].interface_info.video_index + 1];
  1048. dev->video_mode.end_point_addr = le16_to_cpu(uif->altsetting[0].
  1049. endpoint[isoc_pipe].desc.bEndpointAddress);
  1050. dev->video_mode.num_alt = uif->num_altsetting;
  1051. cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
  1052. dev->video_mode.end_point_addr,
  1053. dev->video_mode.num_alt);
  1054. dev->video_mode.alt_max_pkt_size =
  1055. kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL);
  1056. if (dev->video_mode.alt_max_pkt_size == NULL) {
  1057. cx231xx_errdev("out of memory!\n");
  1058. clear_bit(dev->devno, &cx231xx_devused);
  1059. v4l2_device_unregister(&dev->v4l2_dev);
  1060. kfree(dev);
  1061. dev = NULL;
  1062. return -ENOMEM;
  1063. }
  1064. for (i = 0; i < dev->video_mode.num_alt; i++) {
  1065. u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
  1066. desc.wMaxPacketSize);
  1067. dev->video_mode.alt_max_pkt_size[i] =
  1068. (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
  1069. cx231xx_info("Alternate setting %i, max size= %i\n", i,
  1070. dev->video_mode.alt_max_pkt_size[i]);
  1071. }
  1072. /* compute alternate max packet sizes for vbi */
  1073. uif = udev->actconfig->interface[dev->current_pcb_config.
  1074. hs_config_info[0].interface_info.
  1075. vanc_index + 1];
  1076. dev->vbi_mode.end_point_addr =
  1077. le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
  1078. bEndpointAddress);
  1079. dev->vbi_mode.num_alt = uif->num_altsetting;
  1080. cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
  1081. dev->vbi_mode.end_point_addr,
  1082. dev->vbi_mode.num_alt);
  1083. dev->vbi_mode.alt_max_pkt_size =
  1084. kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL);
  1085. if (dev->vbi_mode.alt_max_pkt_size == NULL) {
  1086. cx231xx_errdev("out of memory!\n");
  1087. clear_bit(dev->devno, &cx231xx_devused);
  1088. v4l2_device_unregister(&dev->v4l2_dev);
  1089. kfree(dev);
  1090. dev = NULL;
  1091. return -ENOMEM;
  1092. }
  1093. for (i = 0; i < dev->vbi_mode.num_alt; i++) {
  1094. u16 tmp =
  1095. le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
  1096. desc.wMaxPacketSize);
  1097. dev->vbi_mode.alt_max_pkt_size[i] =
  1098. (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
  1099. cx231xx_info("Alternate setting %i, max size= %i\n", i,
  1100. dev->vbi_mode.alt_max_pkt_size[i]);
  1101. }
  1102. /* compute alternate max packet sizes for sliced CC */
  1103. uif = udev->actconfig->interface[dev->current_pcb_config.
  1104. hs_config_info[0].interface_info.
  1105. hanc_index + 1];
  1106. dev->sliced_cc_mode.end_point_addr =
  1107. le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
  1108. bEndpointAddress);
  1109. dev->sliced_cc_mode.num_alt = uif->num_altsetting;
  1110. cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
  1111. dev->sliced_cc_mode.end_point_addr,
  1112. dev->sliced_cc_mode.num_alt);
  1113. dev->sliced_cc_mode.alt_max_pkt_size =
  1114. kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL);
  1115. if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
  1116. cx231xx_errdev("out of memory!\n");
  1117. clear_bit(dev->devno, &cx231xx_devused);
  1118. v4l2_device_unregister(&dev->v4l2_dev);
  1119. kfree(dev);
  1120. dev = NULL;
  1121. return -ENOMEM;
  1122. }
  1123. for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
  1124. u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
  1125. desc.wMaxPacketSize);
  1126. dev->sliced_cc_mode.alt_max_pkt_size[i] =
  1127. (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
  1128. cx231xx_info("Alternate setting %i, max size= %i\n", i,
  1129. dev->sliced_cc_mode.alt_max_pkt_size[i]);
  1130. }
  1131. if (dev->current_pcb_config.ts1_source != 0xff) {
  1132. /* compute alternate max packet sizes for TS1 */
  1133. uif = udev->actconfig->interface[dev->current_pcb_config.
  1134. hs_config_info[0].
  1135. interface_info.
  1136. ts1_index + 1];
  1137. dev->ts1_mode.end_point_addr =
  1138. le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].
  1139. desc.bEndpointAddress);
  1140. dev->ts1_mode.num_alt = uif->num_altsetting;
  1141. cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
  1142. dev->ts1_mode.end_point_addr,
  1143. dev->ts1_mode.num_alt);
  1144. dev->ts1_mode.alt_max_pkt_size =
  1145. kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL);
  1146. if (dev->ts1_mode.alt_max_pkt_size == NULL) {
  1147. cx231xx_errdev("out of memory!\n");
  1148. clear_bit(dev->devno, &cx231xx_devused);
  1149. v4l2_device_unregister(&dev->v4l2_dev);
  1150. kfree(dev);
  1151. dev = NULL;
  1152. return -ENOMEM;
  1153. }
  1154. for (i = 0; i < dev->ts1_mode.num_alt; i++) {
  1155. u16 tmp = le16_to_cpu(uif->altsetting[i].
  1156. endpoint[isoc_pipe].desc.
  1157. wMaxPacketSize);
  1158. dev->ts1_mode.alt_max_pkt_size[i] =
  1159. (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
  1160. cx231xx_info("Alternate setting %i, max size= %i\n", i,
  1161. dev->ts1_mode.alt_max_pkt_size[i]);
  1162. }
  1163. }
  1164. if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) {
  1165. cx231xx_enable_OSC(dev);
  1166. cx231xx_reset_out(dev);
  1167. cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
  1168. }
  1169. if (dev->model == CX231XX_BOARD_CNXT_RDE_253S)
  1170. cx231xx_sleep_s5h1432(dev);
  1171. /* load other modules required */
  1172. request_modules(dev);
  1173. return 0;
  1174. }
  1175. /*
  1176. * cx231xx_usb_disconnect()
  1177. * called when the device gets diconencted
  1178. * video device will be unregistered on v4l2_close in case it is still open
  1179. */
  1180. static void cx231xx_usb_disconnect(struct usb_interface *interface)
  1181. {
  1182. struct cx231xx *dev;
  1183. dev = usb_get_intfdata(interface);
  1184. usb_set_intfdata(interface, NULL);
  1185. if (!dev)
  1186. return;
  1187. if (!dev->udev)
  1188. return;
  1189. dev->state |= DEV_DISCONNECTED;
  1190. flush_request_modules(dev);
  1191. /* wait until all current v4l2 io is finished then deallocate
  1192. resources */
  1193. mutex_lock(&dev->lock);
  1194. wake_up_interruptible_all(&dev->open);
  1195. if (dev->users) {
  1196. cx231xx_warn
  1197. ("device %s is open! Deregistration and memory "
  1198. "deallocation are deferred on close.\n",
  1199. video_device_node_name(dev->vdev));
  1200. /* Even having users, it is safe to remove the RC i2c driver */
  1201. cx231xx_ir_exit(dev);
  1202. if (dev->USE_ISO)
  1203. cx231xx_uninit_isoc(dev);
  1204. else
  1205. cx231xx_uninit_bulk(dev);
  1206. wake_up_interruptible(&dev->wait_frame);
  1207. wake_up_interruptible(&dev->wait_stream);
  1208. } else {
  1209. }
  1210. cx231xx_close_extension(dev);
  1211. mutex_unlock(&dev->lock);
  1212. if (!dev->users)
  1213. cx231xx_release_resources(dev);
  1214. }
  1215. static struct usb_driver cx231xx_usb_driver = {
  1216. .name = "cx231xx",
  1217. .probe = cx231xx_usb_probe,
  1218. .disconnect = cx231xx_usb_disconnect,
  1219. .id_table = cx231xx_id_table,
  1220. };
  1221. module_usb_driver(cx231xx_usb_driver);