cx231xx-cards.c 36 KB

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