go7007-usb.c 33 KB

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