go7007-usb.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  1. /*
  2. * Copyright (C) 2005-2006 Micronas USA Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License (Version 2) as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  14. #include <linux/module.h>
  15. #include <linux/kernel.h>
  16. #include <linux/wait.h>
  17. #include <linux/list.h>
  18. #include <linux/slab.h>
  19. #include <linux/time.h>
  20. #include <linux/mm.h>
  21. #include <linux/usb.h>
  22. #include <linux/i2c.h>
  23. #include <asm/byteorder.h>
  24. #include <media/i2c/saa7115.h>
  25. #include <media/tuner.h>
  26. #include <media/i2c/uda1342.h>
  27. #include "go7007-priv.h"
  28. static unsigned int assume_endura;
  29. module_param(assume_endura, int, 0644);
  30. MODULE_PARM_DESC(assume_endura,
  31. "when probing fails, hardware is a Pelco Endura");
  32. /* #define GO7007_I2C_DEBUG */ /* for debugging the EZ-USB I2C adapter */
  33. #define HPI_STATUS_ADDR 0xFFF4
  34. #define INT_PARAM_ADDR 0xFFF6
  35. #define INT_INDEX_ADDR 0xFFF8
  36. /*
  37. * Pipes on EZ-USB interface:
  38. * 0 snd - Control
  39. * 0 rcv - Control
  40. * 2 snd - Download firmware (control)
  41. * 4 rcv - Read Interrupt (interrupt)
  42. * 6 rcv - Read Video (bulk)
  43. * 8 rcv - Read Audio (bulk)
  44. */
  45. #define GO7007_USB_EZUSB (1<<0)
  46. #define GO7007_USB_EZUSB_I2C (1<<1)
  47. struct go7007_usb_board {
  48. unsigned int flags;
  49. struct go7007_board_info main_info;
  50. };
  51. struct go7007_usb {
  52. const struct go7007_usb_board *board;
  53. struct mutex i2c_lock;
  54. struct usb_device *usbdev;
  55. struct urb *video_urbs[8];
  56. struct urb *audio_urbs[8];
  57. struct urb *intr_urb;
  58. };
  59. /*********************** Product specification data ***********************/
  60. static const struct go7007_usb_board board_matrix_ii = {
  61. .flags = GO7007_USB_EZUSB,
  62. .main_info = {
  63. .flags = GO7007_BOARD_HAS_AUDIO |
  64. GO7007_BOARD_USE_ONBOARD_I2C,
  65. .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
  66. GO7007_AUDIO_WORD_16,
  67. .audio_rate = 48000,
  68. .audio_bclk_div = 8,
  69. .audio_main_div = 2,
  70. .hpi_buffer_cap = 7,
  71. .sensor_flags = GO7007_SENSOR_656 |
  72. GO7007_SENSOR_VALID_ENABLE |
  73. GO7007_SENSOR_TV |
  74. GO7007_SENSOR_SAA7115 |
  75. GO7007_SENSOR_VBI |
  76. GO7007_SENSOR_SCALING,
  77. .num_i2c_devs = 1,
  78. .i2c_devs = {
  79. {
  80. .type = "saa7115",
  81. .addr = 0x20,
  82. .is_video = 1,
  83. },
  84. },
  85. .num_inputs = 2,
  86. .inputs = {
  87. {
  88. .video_input = 0,
  89. .name = "Composite",
  90. },
  91. {
  92. .video_input = 9,
  93. .name = "S-Video",
  94. },
  95. },
  96. .video_config = SAA7115_IDQ_IS_DEFAULT,
  97. },
  98. };
  99. static const struct go7007_usb_board board_matrix_reload = {
  100. .flags = GO7007_USB_EZUSB,
  101. .main_info = {
  102. .flags = GO7007_BOARD_HAS_AUDIO |
  103. GO7007_BOARD_USE_ONBOARD_I2C,
  104. .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
  105. GO7007_AUDIO_I2S_MASTER |
  106. GO7007_AUDIO_WORD_16,
  107. .audio_rate = 48000,
  108. .audio_bclk_div = 8,
  109. .audio_main_div = 2,
  110. .hpi_buffer_cap = 7,
  111. .sensor_flags = GO7007_SENSOR_656 |
  112. GO7007_SENSOR_TV,
  113. .num_i2c_devs = 1,
  114. .i2c_devs = {
  115. {
  116. .type = "saa7113",
  117. .addr = 0x25,
  118. .is_video = 1,
  119. },
  120. },
  121. .num_inputs = 2,
  122. .inputs = {
  123. {
  124. .video_input = 0,
  125. .name = "Composite",
  126. },
  127. {
  128. .video_input = 9,
  129. .name = "S-Video",
  130. },
  131. },
  132. .video_config = SAA7115_IDQ_IS_DEFAULT,
  133. },
  134. };
  135. static const struct go7007_usb_board board_star_trek = {
  136. .flags = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
  137. .main_info = {
  138. .flags = GO7007_BOARD_HAS_AUDIO, /* |
  139. GO7007_BOARD_HAS_TUNER, */
  140. .sensor_flags = GO7007_SENSOR_656 |
  141. GO7007_SENSOR_VALID_ENABLE |
  142. GO7007_SENSOR_TV |
  143. GO7007_SENSOR_SAA7115 |
  144. GO7007_SENSOR_VBI |
  145. GO7007_SENSOR_SCALING,
  146. .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
  147. GO7007_AUDIO_WORD_16,
  148. .audio_bclk_div = 8,
  149. .audio_main_div = 2,
  150. .hpi_buffer_cap = 7,
  151. .num_i2c_devs = 1,
  152. .i2c_devs = {
  153. {
  154. .type = "saa7115",
  155. .addr = 0x20,
  156. .is_video = 1,
  157. },
  158. },
  159. .num_inputs = 2,
  160. .inputs = {
  161. /* {
  162. * .video_input = 3,
  163. * .audio_index = AUDIO_TUNER,
  164. * .name = "Tuner",
  165. * },
  166. */
  167. {
  168. .video_input = 1,
  169. /* .audio_index = AUDIO_EXTERN, */
  170. .name = "Composite",
  171. },
  172. {
  173. .video_input = 8,
  174. /* .audio_index = AUDIO_EXTERN, */
  175. .name = "S-Video",
  176. },
  177. },
  178. .video_config = SAA7115_IDQ_IS_DEFAULT,
  179. },
  180. };
  181. static const struct go7007_usb_board board_px_tv402u = {
  182. .flags = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
  183. .main_info = {
  184. .flags = GO7007_BOARD_HAS_AUDIO |
  185. GO7007_BOARD_HAS_TUNER,
  186. .sensor_flags = GO7007_SENSOR_656 |
  187. GO7007_SENSOR_VALID_ENABLE |
  188. GO7007_SENSOR_TV |
  189. GO7007_SENSOR_SAA7115 |
  190. GO7007_SENSOR_VBI |
  191. GO7007_SENSOR_SCALING,
  192. .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
  193. GO7007_AUDIO_WORD_16,
  194. .audio_bclk_div = 8,
  195. .audio_main_div = 2,
  196. .hpi_buffer_cap = 7,
  197. .num_i2c_devs = 5,
  198. .i2c_devs = {
  199. {
  200. .type = "saa7115",
  201. .addr = 0x20,
  202. .is_video = 1,
  203. },
  204. {
  205. .type = "uda1342",
  206. .addr = 0x1a,
  207. .is_audio = 1,
  208. },
  209. {
  210. .type = "tuner",
  211. .addr = 0x60,
  212. },
  213. {
  214. .type = "tuner",
  215. .addr = 0x43,
  216. },
  217. {
  218. .type = "sony-btf-mpx",
  219. .addr = 0x44,
  220. },
  221. },
  222. .num_inputs = 3,
  223. .inputs = {
  224. {
  225. .video_input = 3,
  226. .audio_index = 0,
  227. .name = "Tuner",
  228. },
  229. {
  230. .video_input = 1,
  231. .audio_index = 1,
  232. .name = "Composite",
  233. },
  234. {
  235. .video_input = 8,
  236. .audio_index = 1,
  237. .name = "S-Video",
  238. },
  239. },
  240. .video_config = SAA7115_IDQ_IS_DEFAULT,
  241. .num_aud_inputs = 2,
  242. .aud_inputs = {
  243. {
  244. .audio_input = UDA1342_IN2,
  245. .name = "Tuner",
  246. },
  247. {
  248. .audio_input = UDA1342_IN1,
  249. .name = "Line In",
  250. },
  251. },
  252. },
  253. };
  254. static const struct go7007_usb_board board_xmen = {
  255. .flags = 0,
  256. .main_info = {
  257. .flags = GO7007_BOARD_USE_ONBOARD_I2C,
  258. .hpi_buffer_cap = 0,
  259. .sensor_flags = GO7007_SENSOR_VREF_POLAR,
  260. .sensor_width = 320,
  261. .sensor_height = 240,
  262. .sensor_framerate = 30030,
  263. .audio_flags = GO7007_AUDIO_ONE_CHANNEL |
  264. GO7007_AUDIO_I2S_MODE_3 |
  265. GO7007_AUDIO_WORD_14 |
  266. GO7007_AUDIO_I2S_MASTER |
  267. GO7007_AUDIO_BCLK_POLAR |
  268. GO7007_AUDIO_OKI_MODE,
  269. .audio_rate = 8000,
  270. .audio_bclk_div = 48,
  271. .audio_main_div = 1,
  272. .num_i2c_devs = 1,
  273. .i2c_devs = {
  274. {
  275. .type = "ov7640",
  276. .addr = 0x21,
  277. },
  278. },
  279. .num_inputs = 1,
  280. .inputs = {
  281. {
  282. .name = "Camera",
  283. },
  284. },
  285. },
  286. };
  287. static const struct go7007_usb_board board_matrix_revolution = {
  288. .flags = GO7007_USB_EZUSB,
  289. .main_info = {
  290. .flags = GO7007_BOARD_HAS_AUDIO |
  291. GO7007_BOARD_USE_ONBOARD_I2C,
  292. .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
  293. GO7007_AUDIO_I2S_MASTER |
  294. GO7007_AUDIO_WORD_16,
  295. .audio_rate = 48000,
  296. .audio_bclk_div = 8,
  297. .audio_main_div = 2,
  298. .hpi_buffer_cap = 7,
  299. .sensor_flags = GO7007_SENSOR_656 |
  300. GO7007_SENSOR_TV |
  301. GO7007_SENSOR_VBI,
  302. .num_i2c_devs = 1,
  303. .i2c_devs = {
  304. {
  305. .type = "tw9903",
  306. .is_video = 1,
  307. .addr = 0x44,
  308. },
  309. },
  310. .num_inputs = 2,
  311. .inputs = {
  312. {
  313. .video_input = 2,
  314. .name = "Composite",
  315. },
  316. {
  317. .video_input = 8,
  318. .name = "S-Video",
  319. },
  320. },
  321. },
  322. };
  323. #if 0
  324. static const struct go7007_usb_board board_lifeview_lr192 = {
  325. .flags = GO7007_USB_EZUSB,
  326. .main_info = {
  327. .flags = GO7007_BOARD_HAS_AUDIO |
  328. GO7007_BOARD_USE_ONBOARD_I2C,
  329. .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
  330. GO7007_AUDIO_WORD_16,
  331. .audio_rate = 48000,
  332. .audio_bclk_div = 8,
  333. .audio_main_div = 2,
  334. .hpi_buffer_cap = 7,
  335. .sensor_flags = GO7007_SENSOR_656 |
  336. GO7007_SENSOR_VALID_ENABLE |
  337. GO7007_SENSOR_TV |
  338. GO7007_SENSOR_VBI |
  339. GO7007_SENSOR_SCALING,
  340. .num_i2c_devs = 0,
  341. .num_inputs = 1,
  342. .inputs = {
  343. {
  344. .video_input = 0,
  345. .name = "Composite",
  346. },
  347. },
  348. },
  349. };
  350. #endif
  351. static const struct go7007_usb_board board_endura = {
  352. .flags = 0,
  353. .main_info = {
  354. .flags = 0,
  355. .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
  356. GO7007_AUDIO_I2S_MASTER |
  357. GO7007_AUDIO_WORD_16,
  358. .audio_rate = 8000,
  359. .audio_bclk_div = 48,
  360. .audio_main_div = 8,
  361. .hpi_buffer_cap = 0,
  362. .sensor_flags = GO7007_SENSOR_656 |
  363. GO7007_SENSOR_TV,
  364. .sensor_h_offset = 8,
  365. .num_i2c_devs = 0,
  366. .num_inputs = 1,
  367. .inputs = {
  368. {
  369. .name = "Camera",
  370. },
  371. },
  372. },
  373. };
  374. static const struct go7007_usb_board board_adlink_mpg24 = {
  375. .flags = 0,
  376. .main_info = {
  377. .flags = GO7007_BOARD_USE_ONBOARD_I2C,
  378. .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
  379. GO7007_AUDIO_I2S_MASTER |
  380. GO7007_AUDIO_WORD_16,
  381. .audio_rate = 48000,
  382. .audio_bclk_div = 8,
  383. .audio_main_div = 2,
  384. .hpi_buffer_cap = 0,
  385. .sensor_flags = GO7007_SENSOR_656 |
  386. GO7007_SENSOR_TV |
  387. GO7007_SENSOR_VBI,
  388. .num_i2c_devs = 1,
  389. .i2c_devs = {
  390. {
  391. .type = "tw2804",
  392. .addr = 0x00, /* yes, really */
  393. .flags = I2C_CLIENT_TEN,
  394. .is_video = 1,
  395. },
  396. },
  397. .num_inputs = 1,
  398. .inputs = {
  399. {
  400. .name = "Composite",
  401. },
  402. },
  403. },
  404. };
  405. static const struct go7007_usb_board board_sensoray_2250 = {
  406. .flags = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
  407. .main_info = {
  408. .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
  409. GO7007_AUDIO_I2S_MASTER |
  410. GO7007_AUDIO_WORD_16,
  411. .flags = GO7007_BOARD_HAS_AUDIO,
  412. .audio_rate = 48000,
  413. .audio_bclk_div = 8,
  414. .audio_main_div = 2,
  415. .hpi_buffer_cap = 7,
  416. .sensor_flags = GO7007_SENSOR_656 |
  417. GO7007_SENSOR_TV,
  418. .num_i2c_devs = 1,
  419. .i2c_devs = {
  420. {
  421. .type = "s2250",
  422. .addr = 0x43,
  423. .is_video = 1,
  424. .is_audio = 1,
  425. },
  426. },
  427. .num_inputs = 2,
  428. .inputs = {
  429. {
  430. .video_input = 0,
  431. .name = "Composite",
  432. },
  433. {
  434. .video_input = 1,
  435. .name = "S-Video",
  436. },
  437. },
  438. .num_aud_inputs = 3,
  439. .aud_inputs = {
  440. {
  441. .audio_input = 0,
  442. .name = "Line In",
  443. },
  444. {
  445. .audio_input = 1,
  446. .name = "Mic",
  447. },
  448. {
  449. .audio_input = 2,
  450. .name = "Mic Boost",
  451. },
  452. },
  453. },
  454. };
  455. static const struct go7007_usb_board board_ads_usbav_709 = {
  456. .flags = GO7007_USB_EZUSB,
  457. .main_info = {
  458. .flags = GO7007_BOARD_HAS_AUDIO |
  459. GO7007_BOARD_USE_ONBOARD_I2C,
  460. .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
  461. GO7007_AUDIO_I2S_MASTER |
  462. GO7007_AUDIO_WORD_16,
  463. .audio_rate = 48000,
  464. .audio_bclk_div = 8,
  465. .audio_main_div = 2,
  466. .hpi_buffer_cap = 7,
  467. .sensor_flags = GO7007_SENSOR_656 |
  468. GO7007_SENSOR_TV |
  469. GO7007_SENSOR_VBI,
  470. .num_i2c_devs = 1,
  471. .i2c_devs = {
  472. {
  473. .type = "tw9906",
  474. .is_video = 1,
  475. .addr = 0x44,
  476. },
  477. },
  478. .num_inputs = 2,
  479. .inputs = {
  480. {
  481. .video_input = 0,
  482. .name = "Composite",
  483. },
  484. {
  485. .video_input = 10,
  486. .name = "S-Video",
  487. },
  488. },
  489. },
  490. };
  491. static const struct usb_device_id go7007_usb_id_table[] = {
  492. {
  493. .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
  494. USB_DEVICE_ID_MATCH_INT_INFO,
  495. .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
  496. .idProduct = 0x7007, /* Product ID of GO7007SB chip */
  497. .bcdDevice_lo = 0x200, /* Revision number of XMen */
  498. .bcdDevice_hi = 0x200,
  499. .bInterfaceClass = 255,
  500. .bInterfaceSubClass = 0,
  501. .bInterfaceProtocol = 255,
  502. .driver_info = (kernel_ulong_t)GO7007_BOARDID_XMEN,
  503. },
  504. {
  505. .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
  506. .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
  507. .idProduct = 0x7007, /* Product ID of GO7007SB chip */
  508. .bcdDevice_lo = 0x202, /* Revision number of Matrix II */
  509. .bcdDevice_hi = 0x202,
  510. .driver_info = (kernel_ulong_t)GO7007_BOARDID_MATRIX_II,
  511. },
  512. {
  513. .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
  514. .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
  515. .idProduct = 0x7007, /* Product ID of GO7007SB chip */
  516. .bcdDevice_lo = 0x204, /* Revision number of Matrix */
  517. .bcdDevice_hi = 0x204, /* Reloaded */
  518. .driver_info = (kernel_ulong_t)GO7007_BOARDID_MATRIX_RELOAD,
  519. },
  520. {
  521. .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
  522. USB_DEVICE_ID_MATCH_INT_INFO,
  523. .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
  524. .idProduct = 0x7007, /* Product ID of GO7007SB chip */
  525. .bcdDevice_lo = 0x205, /* Revision number of XMen-II */
  526. .bcdDevice_hi = 0x205,
  527. .bInterfaceClass = 255,
  528. .bInterfaceSubClass = 0,
  529. .bInterfaceProtocol = 255,
  530. .driver_info = (kernel_ulong_t)GO7007_BOARDID_XMEN_II,
  531. },
  532. {
  533. .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
  534. .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
  535. .idProduct = 0x7007, /* Product ID of GO7007SB chip */
  536. .bcdDevice_lo = 0x208, /* Revision number of Star Trek */
  537. .bcdDevice_hi = 0x208,
  538. .driver_info = (kernel_ulong_t)GO7007_BOARDID_STAR_TREK,
  539. },
  540. {
  541. .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
  542. USB_DEVICE_ID_MATCH_INT_INFO,
  543. .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
  544. .idProduct = 0x7007, /* Product ID of GO7007SB chip */
  545. .bcdDevice_lo = 0x209, /* Revision number of XMen-III */
  546. .bcdDevice_hi = 0x209,
  547. .bInterfaceClass = 255,
  548. .bInterfaceSubClass = 0,
  549. .bInterfaceProtocol = 255,
  550. .driver_info = (kernel_ulong_t)GO7007_BOARDID_XMEN_III,
  551. },
  552. {
  553. .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
  554. .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
  555. .idProduct = 0x7007, /* Product ID of GO7007SB chip */
  556. .bcdDevice_lo = 0x210, /* Revision number of Matrix */
  557. .bcdDevice_hi = 0x210, /* Revolution */
  558. .driver_info = (kernel_ulong_t)GO7007_BOARDID_MATRIX_REV,
  559. },
  560. {
  561. .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
  562. .idVendor = 0x093b, /* Vendor ID of Plextor */
  563. .idProduct = 0xa102, /* Product ID of M402U */
  564. .bcdDevice_lo = 0x1, /* revision number of Blueberry */
  565. .bcdDevice_hi = 0x1,
  566. .driver_info = (kernel_ulong_t)GO7007_BOARDID_PX_M402U,
  567. },
  568. {
  569. .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
  570. .idVendor = 0x093b, /* Vendor ID of Plextor */
  571. .idProduct = 0xa104, /* Product ID of TV402U */
  572. .bcdDevice_lo = 0x1,
  573. .bcdDevice_hi = 0x1,
  574. .driver_info = (kernel_ulong_t)GO7007_BOARDID_PX_TV402U,
  575. },
  576. {
  577. .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
  578. .idVendor = 0x10fd, /* Vendor ID of Anubis Electronics */
  579. .idProduct = 0xde00, /* Product ID of Lifeview LR192 */
  580. .bcdDevice_lo = 0x1,
  581. .bcdDevice_hi = 0x1,
  582. .driver_info = (kernel_ulong_t)GO7007_BOARDID_LIFEVIEW_LR192,
  583. },
  584. {
  585. .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
  586. .idVendor = 0x1943, /* Vendor ID Sensoray */
  587. .idProduct = 0x2250, /* Product ID of 2250/2251 */
  588. .bcdDevice_lo = 0x1,
  589. .bcdDevice_hi = 0x1,
  590. .driver_info = (kernel_ulong_t)GO7007_BOARDID_SENSORAY_2250,
  591. },
  592. {
  593. .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
  594. .idVendor = 0x06e1, /* Vendor ID of ADS Technologies */
  595. .idProduct = 0x0709, /* Product ID of DVD Xpress DX2 */
  596. .bcdDevice_lo = 0x204,
  597. .bcdDevice_hi = 0x204,
  598. .driver_info = (kernel_ulong_t)GO7007_BOARDID_ADS_USBAV_709,
  599. },
  600. { } /* Terminating entry */
  601. };
  602. MODULE_DEVICE_TABLE(usb, go7007_usb_id_table);
  603. /********************* Driver for EZ-USB HPI interface *********************/
  604. static int go7007_usb_vendor_request(struct go7007 *go, int request,
  605. int value, int index, void *transfer_buffer, int length, int in)
  606. {
  607. struct go7007_usb *usb = go->hpi_context;
  608. int timeout = 5000;
  609. if (in) {
  610. return usb_control_msg(usb->usbdev,
  611. usb_rcvctrlpipe(usb->usbdev, 0), request,
  612. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
  613. value, index, transfer_buffer, length, timeout);
  614. } else {
  615. return usb_control_msg(usb->usbdev,
  616. usb_sndctrlpipe(usb->usbdev, 0), request,
  617. USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  618. value, index, transfer_buffer, length, timeout);
  619. }
  620. }
  621. static int go7007_usb_interface_reset(struct go7007 *go)
  622. {
  623. struct go7007_usb *usb = go->hpi_context;
  624. u16 intr_val, intr_data;
  625. if (go->status == STATUS_SHUTDOWN)
  626. return -1;
  627. /* Reset encoder */
  628. if (go7007_write_interrupt(go, 0x0001, 0x0001) < 0)
  629. return -1;
  630. msleep(100);
  631. if (usb->board->flags & GO7007_USB_EZUSB) {
  632. /* Reset buffer in EZ-USB */
  633. pr_debug("resetting EZ-USB buffers\n");
  634. if (go7007_usb_vendor_request(go, 0x10, 0, 0, NULL, 0, 0) < 0 ||
  635. go7007_usb_vendor_request(go, 0x10, 0, 0, NULL, 0, 0) < 0)
  636. return -1;
  637. /* Reset encoder again */
  638. if (go7007_write_interrupt(go, 0x0001, 0x0001) < 0)
  639. return -1;
  640. msleep(100);
  641. }
  642. /* Wait for an interrupt to indicate successful hardware reset */
  643. if (go7007_read_interrupt(go, &intr_val, &intr_data) < 0 ||
  644. (intr_val & ~0x1) != 0x55aa) {
  645. dev_err(go->dev, "unable to reset the USB interface\n");
  646. return -1;
  647. }
  648. return 0;
  649. }
  650. static int go7007_usb_ezusb_write_interrupt(struct go7007 *go,
  651. int addr, int data)
  652. {
  653. struct go7007_usb *usb = go->hpi_context;
  654. int i, r;
  655. u16 status_reg = 0;
  656. int timeout = 500;
  657. pr_debug("WriteInterrupt: %04x %04x\n", addr, data);
  658. for (i = 0; i < 100; ++i) {
  659. r = usb_control_msg(usb->usbdev,
  660. usb_rcvctrlpipe(usb->usbdev, 0), 0x14,
  661. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
  662. 0, HPI_STATUS_ADDR, go->usb_buf,
  663. sizeof(status_reg), timeout);
  664. if (r < 0)
  665. break;
  666. status_reg = le16_to_cpu(*((__le16 *)go->usb_buf));
  667. if (!(status_reg & 0x0010))
  668. break;
  669. msleep(10);
  670. }
  671. if (r < 0)
  672. goto write_int_error;
  673. if (i == 100) {
  674. dev_err(go->dev, "device is hung, status reg = 0x%04x\n", status_reg);
  675. return -1;
  676. }
  677. r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 0), 0x12,
  678. USB_TYPE_VENDOR | USB_RECIP_DEVICE, data,
  679. INT_PARAM_ADDR, NULL, 0, timeout);
  680. if (r < 0)
  681. goto write_int_error;
  682. r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 0),
  683. 0x12, USB_TYPE_VENDOR | USB_RECIP_DEVICE, addr,
  684. INT_INDEX_ADDR, NULL, 0, timeout);
  685. if (r < 0)
  686. goto write_int_error;
  687. return 0;
  688. write_int_error:
  689. dev_err(go->dev, "error in WriteInterrupt: %d\n", r);
  690. return r;
  691. }
  692. static int go7007_usb_onboard_write_interrupt(struct go7007 *go,
  693. int addr, int data)
  694. {
  695. struct go7007_usb *usb = go->hpi_context;
  696. int r;
  697. int timeout = 500;
  698. pr_debug("WriteInterrupt: %04x %04x\n", addr, data);
  699. go->usb_buf[0] = data & 0xff;
  700. go->usb_buf[1] = data >> 8;
  701. go->usb_buf[2] = addr & 0xff;
  702. go->usb_buf[3] = addr >> 8;
  703. go->usb_buf[4] = go->usb_buf[5] = go->usb_buf[6] = go->usb_buf[7] = 0;
  704. r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 2), 0x00,
  705. USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 0x55aa,
  706. 0xf0f0, go->usb_buf, 8, timeout);
  707. if (r < 0) {
  708. dev_err(go->dev, "error in WriteInterrupt: %d\n", r);
  709. return r;
  710. }
  711. return 0;
  712. }
  713. static void go7007_usb_readinterrupt_complete(struct urb *urb)
  714. {
  715. struct go7007 *go = (struct go7007 *)urb->context;
  716. __le16 *regs = (__le16 *)urb->transfer_buffer;
  717. int status = urb->status;
  718. if (status) {
  719. if (status != -ESHUTDOWN &&
  720. go->status != STATUS_SHUTDOWN) {
  721. dev_err(go->dev, "error in read interrupt: %d\n", urb->status);
  722. } else {
  723. wake_up(&go->interrupt_waitq);
  724. return;
  725. }
  726. } else if (urb->actual_length != urb->transfer_buffer_length) {
  727. dev_err(go->dev, "short read in interrupt pipe!\n");
  728. } else {
  729. go->interrupt_available = 1;
  730. go->interrupt_data = __le16_to_cpu(regs[0]);
  731. go->interrupt_value = __le16_to_cpu(regs[1]);
  732. pr_debug("ReadInterrupt: %04x %04x\n",
  733. go->interrupt_value, go->interrupt_data);
  734. }
  735. wake_up(&go->interrupt_waitq);
  736. }
  737. static int go7007_usb_read_interrupt(struct go7007 *go)
  738. {
  739. struct go7007_usb *usb = go->hpi_context;
  740. int r;
  741. r = usb_submit_urb(usb->intr_urb, GFP_KERNEL);
  742. if (r < 0) {
  743. dev_err(go->dev, "unable to submit interrupt urb: %d\n", r);
  744. return r;
  745. }
  746. return 0;
  747. }
  748. static void go7007_usb_read_video_pipe_complete(struct urb *urb)
  749. {
  750. struct go7007 *go = (struct go7007 *)urb->context;
  751. int r, status = urb->status;
  752. if (!vb2_is_streaming(&go->vidq)) {
  753. wake_up_interruptible(&go->frame_waitq);
  754. return;
  755. }
  756. if (status) {
  757. dev_err(go->dev, "error in video pipe: %d\n", status);
  758. return;
  759. }
  760. if (urb->actual_length != urb->transfer_buffer_length) {
  761. dev_err(go->dev, "short read in video pipe!\n");
  762. return;
  763. }
  764. go7007_parse_video_stream(go, urb->transfer_buffer, urb->actual_length);
  765. r = usb_submit_urb(urb, GFP_ATOMIC);
  766. if (r < 0)
  767. dev_err(go->dev, "error in video pipe: %d\n", r);
  768. }
  769. static void go7007_usb_read_audio_pipe_complete(struct urb *urb)
  770. {
  771. struct go7007 *go = (struct go7007 *)urb->context;
  772. int r, status = urb->status;
  773. if (!vb2_is_streaming(&go->vidq))
  774. return;
  775. if (status) {
  776. dev_err(go->dev, "error in audio pipe: %d\n",
  777. status);
  778. return;
  779. }
  780. if (urb->actual_length != urb->transfer_buffer_length) {
  781. dev_err(go->dev, "short read in audio pipe!\n");
  782. return;
  783. }
  784. if (go->audio_deliver != NULL)
  785. go->audio_deliver(go, urb->transfer_buffer, urb->actual_length);
  786. r = usb_submit_urb(urb, GFP_ATOMIC);
  787. if (r < 0)
  788. dev_err(go->dev, "error in audio pipe: %d\n", r);
  789. }
  790. static int go7007_usb_stream_start(struct go7007 *go)
  791. {
  792. struct go7007_usb *usb = go->hpi_context;
  793. int i, r;
  794. for (i = 0; i < 8; ++i) {
  795. r = usb_submit_urb(usb->video_urbs[i], GFP_KERNEL);
  796. if (r < 0) {
  797. dev_err(go->dev, "error submitting video urb %d: %d\n", i, r);
  798. goto video_submit_failed;
  799. }
  800. }
  801. if (!go->audio_enabled)
  802. return 0;
  803. for (i = 0; i < 8; ++i) {
  804. r = usb_submit_urb(usb->audio_urbs[i], GFP_KERNEL);
  805. if (r < 0) {
  806. dev_err(go->dev, "error submitting audio urb %d: %d\n", i, r);
  807. goto audio_submit_failed;
  808. }
  809. }
  810. return 0;
  811. audio_submit_failed:
  812. for (i = 0; i < 7; ++i)
  813. usb_kill_urb(usb->audio_urbs[i]);
  814. video_submit_failed:
  815. for (i = 0; i < 8; ++i)
  816. usb_kill_urb(usb->video_urbs[i]);
  817. return -1;
  818. }
  819. static int go7007_usb_stream_stop(struct go7007 *go)
  820. {
  821. struct go7007_usb *usb = go->hpi_context;
  822. int i;
  823. if (go->status == STATUS_SHUTDOWN)
  824. return 0;
  825. for (i = 0; i < 8; ++i)
  826. usb_kill_urb(usb->video_urbs[i]);
  827. if (go->audio_enabled)
  828. for (i = 0; i < 8; ++i)
  829. usb_kill_urb(usb->audio_urbs[i]);
  830. return 0;
  831. }
  832. static int go7007_usb_send_firmware(struct go7007 *go, u8 *data, int len)
  833. {
  834. struct go7007_usb *usb = go->hpi_context;
  835. int transferred, pipe;
  836. int timeout = 500;
  837. pr_debug("DownloadBuffer sending %d bytes\n", len);
  838. if (usb->board->flags & GO7007_USB_EZUSB)
  839. pipe = usb_sndbulkpipe(usb->usbdev, 2);
  840. else
  841. pipe = usb_sndbulkpipe(usb->usbdev, 3);
  842. return usb_bulk_msg(usb->usbdev, pipe, data, len,
  843. &transferred, timeout);
  844. }
  845. static void go7007_usb_release(struct go7007 *go)
  846. {
  847. struct go7007_usb *usb = go->hpi_context;
  848. struct urb *vurb, *aurb;
  849. int i;
  850. if (usb->intr_urb) {
  851. usb_kill_urb(usb->intr_urb);
  852. kfree(usb->intr_urb->transfer_buffer);
  853. usb_free_urb(usb->intr_urb);
  854. }
  855. /* Free USB-related structs */
  856. for (i = 0; i < 8; ++i) {
  857. vurb = usb->video_urbs[i];
  858. if (vurb) {
  859. usb_kill_urb(vurb);
  860. kfree(vurb->transfer_buffer);
  861. usb_free_urb(vurb);
  862. }
  863. aurb = usb->audio_urbs[i];
  864. if (aurb) {
  865. usb_kill_urb(aurb);
  866. kfree(aurb->transfer_buffer);
  867. usb_free_urb(aurb);
  868. }
  869. }
  870. kfree(go->hpi_context);
  871. }
  872. static const struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops = {
  873. .interface_reset = go7007_usb_interface_reset,
  874. .write_interrupt = go7007_usb_ezusb_write_interrupt,
  875. .read_interrupt = go7007_usb_read_interrupt,
  876. .stream_start = go7007_usb_stream_start,
  877. .stream_stop = go7007_usb_stream_stop,
  878. .send_firmware = go7007_usb_send_firmware,
  879. .release = go7007_usb_release,
  880. };
  881. static const struct go7007_hpi_ops go7007_usb_onboard_hpi_ops = {
  882. .interface_reset = go7007_usb_interface_reset,
  883. .write_interrupt = go7007_usb_onboard_write_interrupt,
  884. .read_interrupt = go7007_usb_read_interrupt,
  885. .stream_start = go7007_usb_stream_start,
  886. .stream_stop = go7007_usb_stream_stop,
  887. .send_firmware = go7007_usb_send_firmware,
  888. .release = go7007_usb_release,
  889. };
  890. /********************* Driver for EZ-USB I2C adapter *********************/
  891. static int go7007_usb_i2c_master_xfer(struct i2c_adapter *adapter,
  892. struct i2c_msg msgs[], int num)
  893. {
  894. struct go7007 *go = i2c_get_adapdata(adapter);
  895. struct go7007_usb *usb = go->hpi_context;
  896. u8 *buf = go->usb_buf;
  897. int buf_len, i;
  898. int ret = -EIO;
  899. if (go->status == STATUS_SHUTDOWN)
  900. return -ENODEV;
  901. mutex_lock(&usb->i2c_lock);
  902. for (i = 0; i < num; ++i) {
  903. /* The hardware command is "write some bytes then read some
  904. * bytes", so we try to coalesce a write followed by a read
  905. * into a single USB transaction */
  906. if (i + 1 < num && msgs[i].addr == msgs[i + 1].addr &&
  907. !(msgs[i].flags & I2C_M_RD) &&
  908. (msgs[i + 1].flags & I2C_M_RD)) {
  909. #ifdef GO7007_I2C_DEBUG
  910. pr_debug("i2c write/read %d/%d bytes on %02x\n",
  911. msgs[i].len, msgs[i + 1].len, msgs[i].addr);
  912. #endif
  913. buf[0] = 0x01;
  914. buf[1] = msgs[i].len + 1;
  915. buf[2] = msgs[i].addr << 1;
  916. memcpy(&buf[3], msgs[i].buf, msgs[i].len);
  917. buf_len = msgs[i].len + 3;
  918. buf[buf_len++] = msgs[++i].len;
  919. } else if (msgs[i].flags & I2C_M_RD) {
  920. #ifdef GO7007_I2C_DEBUG
  921. pr_debug("i2c read %d bytes on %02x\n",
  922. msgs[i].len, msgs[i].addr);
  923. #endif
  924. buf[0] = 0x01;
  925. buf[1] = 1;
  926. buf[2] = msgs[i].addr << 1;
  927. buf[3] = msgs[i].len;
  928. buf_len = 4;
  929. } else {
  930. #ifdef GO7007_I2C_DEBUG
  931. pr_debug("i2c write %d bytes on %02x\n",
  932. msgs[i].len, msgs[i].addr);
  933. #endif
  934. buf[0] = 0x00;
  935. buf[1] = msgs[i].len + 1;
  936. buf[2] = msgs[i].addr << 1;
  937. memcpy(&buf[3], msgs[i].buf, msgs[i].len);
  938. buf_len = msgs[i].len + 3;
  939. buf[buf_len++] = 0;
  940. }
  941. if (go7007_usb_vendor_request(go, 0x24, 0, 0,
  942. buf, buf_len, 0) < 0)
  943. goto i2c_done;
  944. if (msgs[i].flags & I2C_M_RD) {
  945. memset(buf, 0, msgs[i].len + 1);
  946. if (go7007_usb_vendor_request(go, 0x25, 0, 0, buf,
  947. msgs[i].len + 1, 1) < 0)
  948. goto i2c_done;
  949. memcpy(msgs[i].buf, buf + 1, msgs[i].len);
  950. }
  951. }
  952. ret = num;
  953. i2c_done:
  954. mutex_unlock(&usb->i2c_lock);
  955. return ret;
  956. }
  957. static u32 go7007_usb_functionality(struct i2c_adapter *adapter)
  958. {
  959. /* No errors are reported by the hardware, so we don't bother
  960. * supporting quick writes to avoid confusing probing */
  961. return (I2C_FUNC_SMBUS_EMUL) & ~I2C_FUNC_SMBUS_QUICK;
  962. }
  963. static const struct i2c_algorithm go7007_usb_algo = {
  964. .master_xfer = go7007_usb_i2c_master_xfer,
  965. .functionality = go7007_usb_functionality,
  966. };
  967. static struct i2c_adapter go7007_usb_adap_templ = {
  968. .owner = THIS_MODULE,
  969. .name = "WIS GO7007SB EZ-USB",
  970. .algo = &go7007_usb_algo,
  971. };
  972. /********************* USB add/remove functions *********************/
  973. static int go7007_usb_probe(struct usb_interface *intf,
  974. const struct usb_device_id *id)
  975. {
  976. struct go7007 *go;
  977. struct go7007_usb *usb;
  978. const struct go7007_usb_board *board;
  979. struct usb_device *usbdev = interface_to_usbdev(intf);
  980. unsigned num_i2c_devs;
  981. char *name;
  982. int video_pipe, i, v_urb_len;
  983. pr_debug("probing new GO7007 USB board\n");
  984. switch (id->driver_info) {
  985. case GO7007_BOARDID_MATRIX_II:
  986. name = "WIS Matrix II or compatible";
  987. board = &board_matrix_ii;
  988. break;
  989. case GO7007_BOARDID_MATRIX_RELOAD:
  990. name = "WIS Matrix Reloaded or compatible";
  991. board = &board_matrix_reload;
  992. break;
  993. case GO7007_BOARDID_MATRIX_REV:
  994. name = "WIS Matrix Revolution or compatible";
  995. board = &board_matrix_revolution;
  996. break;
  997. case GO7007_BOARDID_STAR_TREK:
  998. name = "WIS Star Trek or compatible";
  999. board = &board_star_trek;
  1000. break;
  1001. case GO7007_BOARDID_XMEN:
  1002. name = "WIS XMen or compatible";
  1003. board = &board_xmen;
  1004. break;
  1005. case GO7007_BOARDID_XMEN_II:
  1006. name = "WIS XMen II or compatible";
  1007. board = &board_xmen;
  1008. break;
  1009. case GO7007_BOARDID_XMEN_III:
  1010. name = "WIS XMen III or compatible";
  1011. board = &board_xmen;
  1012. break;
  1013. case GO7007_BOARDID_PX_M402U:
  1014. name = "Plextor PX-M402U";
  1015. board = &board_matrix_ii;
  1016. break;
  1017. case GO7007_BOARDID_PX_TV402U:
  1018. name = "Plextor PX-TV402U (unknown tuner)";
  1019. board = &board_px_tv402u;
  1020. break;
  1021. case GO7007_BOARDID_LIFEVIEW_LR192:
  1022. dev_err(&intf->dev, "The Lifeview TV Walker Ultra is not supported. Sorry!\n");
  1023. return -ENODEV;
  1024. #if 0
  1025. name = "Lifeview TV Walker Ultra";
  1026. board = &board_lifeview_lr192;
  1027. #endif
  1028. break;
  1029. case GO7007_BOARDID_SENSORAY_2250:
  1030. dev_info(&intf->dev, "Sensoray 2250 found\n");
  1031. name = "Sensoray 2250/2251";
  1032. board = &board_sensoray_2250;
  1033. break;
  1034. case GO7007_BOARDID_ADS_USBAV_709:
  1035. name = "ADS Tech DVD Xpress DX2";
  1036. board = &board_ads_usbav_709;
  1037. break;
  1038. default:
  1039. dev_err(&intf->dev, "unknown board ID %d!\n",
  1040. (unsigned int)id->driver_info);
  1041. return -ENODEV;
  1042. }
  1043. go = go7007_alloc(&board->main_info, &intf->dev);
  1044. if (go == NULL)
  1045. return -ENOMEM;
  1046. usb = kzalloc(sizeof(struct go7007_usb), GFP_KERNEL);
  1047. if (usb == NULL) {
  1048. kfree(go);
  1049. return -ENOMEM;
  1050. }
  1051. usb->board = board;
  1052. usb->usbdev = usbdev;
  1053. usb_make_path(usbdev, go->bus_info, sizeof(go->bus_info));
  1054. go->board_id = id->driver_info;
  1055. strncpy(go->name, name, sizeof(go->name));
  1056. if (board->flags & GO7007_USB_EZUSB)
  1057. go->hpi_ops = &go7007_usb_ezusb_hpi_ops;
  1058. else
  1059. go->hpi_ops = &go7007_usb_onboard_hpi_ops;
  1060. go->hpi_context = usb;
  1061. /* Allocate the URB and buffer for receiving incoming interrupts */
  1062. usb->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
  1063. if (usb->intr_urb == NULL)
  1064. goto allocfail;
  1065. usb->intr_urb->transfer_buffer = kmalloc_array(2, sizeof(u16),
  1066. GFP_KERNEL);
  1067. if (usb->intr_urb->transfer_buffer == NULL)
  1068. goto allocfail;
  1069. if (go->board_id == GO7007_BOARDID_SENSORAY_2250)
  1070. usb_fill_bulk_urb(usb->intr_urb, usb->usbdev,
  1071. usb_rcvbulkpipe(usb->usbdev, 4),
  1072. usb->intr_urb->transfer_buffer, 2*sizeof(u16),
  1073. go7007_usb_readinterrupt_complete, go);
  1074. else
  1075. usb_fill_int_urb(usb->intr_urb, usb->usbdev,
  1076. usb_rcvintpipe(usb->usbdev, 4),
  1077. usb->intr_urb->transfer_buffer, 2*sizeof(u16),
  1078. go7007_usb_readinterrupt_complete, go, 8);
  1079. usb_set_intfdata(intf, &go->v4l2_dev);
  1080. /* Boot the GO7007 */
  1081. if (go7007_boot_encoder(go, go->board_info->flags &
  1082. GO7007_BOARD_USE_ONBOARD_I2C) < 0)
  1083. goto allocfail;
  1084. /* Register the EZ-USB I2C adapter, if we're using it */
  1085. if (board->flags & GO7007_USB_EZUSB_I2C) {
  1086. memcpy(&go->i2c_adapter, &go7007_usb_adap_templ,
  1087. sizeof(go7007_usb_adap_templ));
  1088. mutex_init(&usb->i2c_lock);
  1089. go->i2c_adapter.dev.parent = go->dev;
  1090. i2c_set_adapdata(&go->i2c_adapter, go);
  1091. if (i2c_add_adapter(&go->i2c_adapter) < 0) {
  1092. dev_err(go->dev, "error: i2c_add_adapter failed\n");
  1093. goto allocfail;
  1094. }
  1095. go->i2c_adapter_online = 1;
  1096. }
  1097. /* Pelco and Adlink reused the XMen and XMen-III vendor and product
  1098. * IDs for their own incompatible designs. We can detect XMen boards
  1099. * by probing the sensor, but there is no way to probe the sensors on
  1100. * the Pelco and Adlink designs so we default to the Adlink. If it
  1101. * is actually a Pelco, the user must set the assume_endura module
  1102. * parameter. */
  1103. if ((go->board_id == GO7007_BOARDID_XMEN ||
  1104. go->board_id == GO7007_BOARDID_XMEN_III) &&
  1105. go->i2c_adapter_online) {
  1106. union i2c_smbus_data data;
  1107. /* Check to see if register 0x0A is 0x76 */
  1108. i2c_smbus_xfer(&go->i2c_adapter, 0x21, I2C_CLIENT_SCCB,
  1109. I2C_SMBUS_READ, 0x0A, I2C_SMBUS_BYTE_DATA, &data);
  1110. if (data.byte != 0x76) {
  1111. if (assume_endura) {
  1112. go->board_id = GO7007_BOARDID_ENDURA;
  1113. usb->board = board = &board_endura;
  1114. go->board_info = &board->main_info;
  1115. strncpy(go->name, "Pelco Endura",
  1116. sizeof(go->name));
  1117. } else {
  1118. u16 channel;
  1119. /* read channel number from GPIO[1:0] */
  1120. go7007_read_addr(go, 0x3c81, &channel);
  1121. channel &= 0x3;
  1122. go->board_id = GO7007_BOARDID_ADLINK_MPG24;
  1123. usb->board = board = &board_adlink_mpg24;
  1124. go->board_info = &board->main_info;
  1125. go->channel_number = channel;
  1126. snprintf(go->name, sizeof(go->name),
  1127. "Adlink PCI-MPG24, channel #%d",
  1128. channel);
  1129. }
  1130. go7007_update_board(go);
  1131. }
  1132. }
  1133. num_i2c_devs = go->board_info->num_i2c_devs;
  1134. /* Probe the tuner model on the TV402U */
  1135. if (go->board_id == GO7007_BOARDID_PX_TV402U) {
  1136. /* Board strapping indicates tuner model */
  1137. if (go7007_usb_vendor_request(go, 0x41, 0, 0, go->usb_buf, 3,
  1138. 1) < 0) {
  1139. dev_err(go->dev, "GPIO read failed!\n");
  1140. goto allocfail;
  1141. }
  1142. switch (go->usb_buf[0] >> 6) {
  1143. case 1:
  1144. go->tuner_type = TUNER_SONY_BTF_PG472Z;
  1145. go->std = V4L2_STD_PAL;
  1146. strncpy(go->name, "Plextor PX-TV402U-EU",
  1147. sizeof(go->name));
  1148. break;
  1149. case 2:
  1150. go->tuner_type = TUNER_SONY_BTF_PK467Z;
  1151. go->std = V4L2_STD_NTSC_M_JP;
  1152. num_i2c_devs -= 2;
  1153. strncpy(go->name, "Plextor PX-TV402U-JP",
  1154. sizeof(go->name));
  1155. break;
  1156. case 3:
  1157. go->tuner_type = TUNER_SONY_BTF_PB463Z;
  1158. num_i2c_devs -= 2;
  1159. strncpy(go->name, "Plextor PX-TV402U-NA",
  1160. sizeof(go->name));
  1161. break;
  1162. default:
  1163. pr_debug("unable to detect tuner type!\n");
  1164. break;
  1165. }
  1166. /* Configure tuner mode selection inputs connected
  1167. * to the EZ-USB GPIO output pins */
  1168. if (go7007_usb_vendor_request(go, 0x40, 0x7f02, 0,
  1169. NULL, 0, 0) < 0) {
  1170. dev_err(go->dev, "GPIO write failed!\n");
  1171. goto allocfail;
  1172. }
  1173. }
  1174. /* Print a nasty message if the user attempts to use a USB2.0 device in
  1175. * a USB1.1 port. There will be silent corruption of the stream. */
  1176. if ((board->flags & GO7007_USB_EZUSB) &&
  1177. usbdev->speed != USB_SPEED_HIGH)
  1178. dev_err(go->dev, "*** WARNING *** This device must be connected to a USB 2.0 port! Attempting to capture video through a USB 1.1 port will result in stream corruption, even at low bitrates!\n");
  1179. /* Allocate the URBs and buffers for receiving the video stream */
  1180. if (board->flags & GO7007_USB_EZUSB) {
  1181. v_urb_len = 1024;
  1182. video_pipe = usb_rcvbulkpipe(usb->usbdev, 6);
  1183. } else {
  1184. v_urb_len = 512;
  1185. video_pipe = usb_rcvbulkpipe(usb->usbdev, 1);
  1186. }
  1187. for (i = 0; i < 8; ++i) {
  1188. usb->video_urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
  1189. if (usb->video_urbs[i] == NULL)
  1190. goto allocfail;
  1191. usb->video_urbs[i]->transfer_buffer =
  1192. kmalloc(v_urb_len, GFP_KERNEL);
  1193. if (usb->video_urbs[i]->transfer_buffer == NULL)
  1194. goto allocfail;
  1195. usb_fill_bulk_urb(usb->video_urbs[i], usb->usbdev, video_pipe,
  1196. usb->video_urbs[i]->transfer_buffer, v_urb_len,
  1197. go7007_usb_read_video_pipe_complete, go);
  1198. }
  1199. /* Allocate the URBs and buffers for receiving the audio stream */
  1200. if ((board->flags & GO7007_USB_EZUSB) &&
  1201. (board->main_info.flags & GO7007_BOARD_HAS_AUDIO)) {
  1202. for (i = 0; i < 8; ++i) {
  1203. usb->audio_urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
  1204. if (usb->audio_urbs[i] == NULL)
  1205. goto allocfail;
  1206. usb->audio_urbs[i]->transfer_buffer = kmalloc(4096,
  1207. GFP_KERNEL);
  1208. if (usb->audio_urbs[i]->transfer_buffer == NULL)
  1209. goto allocfail;
  1210. usb_fill_bulk_urb(usb->audio_urbs[i], usb->usbdev,
  1211. usb_rcvbulkpipe(usb->usbdev, 8),
  1212. usb->audio_urbs[i]->transfer_buffer, 4096,
  1213. go7007_usb_read_audio_pipe_complete, go);
  1214. }
  1215. }
  1216. /* Do any final GO7007 initialization, then register the
  1217. * V4L2 and ALSA interfaces */
  1218. if (go7007_register_encoder(go, num_i2c_devs) < 0)
  1219. goto allocfail;
  1220. go->status = STATUS_ONLINE;
  1221. return 0;
  1222. allocfail:
  1223. go7007_usb_release(go);
  1224. kfree(go);
  1225. return -ENOMEM;
  1226. }
  1227. static void go7007_usb_disconnect(struct usb_interface *intf)
  1228. {
  1229. struct go7007 *go = to_go7007(usb_get_intfdata(intf));
  1230. mutex_lock(&go->queue_lock);
  1231. mutex_lock(&go->serialize_lock);
  1232. if (go->audio_enabled)
  1233. go7007_snd_remove(go);
  1234. go->status = STATUS_SHUTDOWN;
  1235. v4l2_device_disconnect(&go->v4l2_dev);
  1236. video_unregister_device(&go->vdev);
  1237. mutex_unlock(&go->serialize_lock);
  1238. mutex_unlock(&go->queue_lock);
  1239. v4l2_device_put(&go->v4l2_dev);
  1240. }
  1241. static struct usb_driver go7007_usb_driver = {
  1242. .name = "go7007",
  1243. .probe = go7007_usb_probe,
  1244. .disconnect = go7007_usb_disconnect,
  1245. .id_table = go7007_usb_id_table,
  1246. };
  1247. module_usb_driver(go7007_usb_driver);
  1248. MODULE_LICENSE("GPL v2");