flexcop-usb.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. /*
  2. * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III
  3. *
  4. * flexcop-usb.c - covers the USB part.
  5. *
  6. * see flexcop.c for copyright information.
  7. */
  8. #define FC_LOG_PREFIX "flexcop_usb"
  9. #include "flexcop-usb.h"
  10. #include "flexcop-common.h"
  11. /* Version information */
  12. #define DRIVER_VERSION "0.1"
  13. #define DRIVER_NAME "Technisat/B2C2 FlexCop II/IIb/III Digital TV USB Driver"
  14. #define DRIVER_AUTHOR "Patrick Boettcher <patrick.boettcher@desy.de>"
  15. /* debug */
  16. #ifdef CONFIG_DVB_B2C2_FLEXCOP_DEBUG
  17. #define dprintk(level,args...) \
  18. do { if ((debug & level)) { printk(args); } } while (0)
  19. #define debug_dump(b,l,method) {\
  20. int i; \
  21. for (i = 0; i < l; i++) method("%02x ", b[i]); \
  22. method("\n");\
  23. }
  24. #define DEBSTATUS ""
  25. #else
  26. #define dprintk(level,args...)
  27. #define debug_dump(b,l,method)
  28. #define DEBSTATUS " (debugging is not enabled)"
  29. #endif
  30. static int debug;
  31. module_param(debug, int, 0644);
  32. MODULE_PARM_DESC(debug, "set debugging level (1=info,ts=2,ctrl=4,i2c=8,v8mem=16 (or-able))." DEBSTATUS);
  33. #undef DEBSTATUS
  34. #define deb_info(args...) dprintk(0x01,args)
  35. #define deb_ts(args...) dprintk(0x02,args)
  36. #define deb_ctrl(args...) dprintk(0x04,args)
  37. #define deb_i2c(args...) dprintk(0x08,args)
  38. #define deb_v8(args...) dprintk(0x10,args)
  39. /* JLP 111700: we will include the 1 bit gap between the upper and lower 3 bits
  40. * in the IBI address, to make the V8 code simpler.
  41. * PCI ADDRESS FORMAT: 0x71C -> 0000 0111 0001 1100 (these are the six bits used)
  42. * in general: 0000 0HHH 000L LL00
  43. * IBI ADDRESS FORMAT: RHHH BLLL
  44. *
  45. * where R is the read(1)/write(0) bit, B is the busy bit
  46. * and HHH and LLL are the two sets of three bits from the PCI address.
  47. */
  48. #define B2C2_FLEX_PCIOFFSET_TO_INTERNALADDR(usPCI) (u8) (((usPCI >> 2) & 0x07) + ((usPCI >> 4) & 0x70))
  49. #define B2C2_FLEX_INTERNALADDR_TO_PCIOFFSET(ucAddr) (u16) (((ucAddr & 0x07) << 2) + ((ucAddr & 0x70) << 4))
  50. /*
  51. * DKT 020228
  52. * - forget about this VENDOR_BUFFER_SIZE, read and write register
  53. * deal with DWORD or 4 bytes, that should be should from now on
  54. * - from now on, we don't support anything older than firm 1.00
  55. * I eliminated the write register as a 2 trip of writing hi word and lo word
  56. * and force this to write only 4 bytes at a time.
  57. * NOTE: this should work with all the firmware from 1.00 and newer
  58. */
  59. static int flexcop_usb_readwrite_dw(struct flexcop_device *fc, u16 wRegOffsPCI, u32 *val, u8 read)
  60. {
  61. struct flexcop_usb *fc_usb = fc->bus_specific;
  62. u8 request = read ? B2C2_USB_READ_REG : B2C2_USB_WRITE_REG;
  63. u8 request_type = (read ? USB_DIR_IN : USB_DIR_OUT) | USB_TYPE_VENDOR;
  64. u8 wAddress = B2C2_FLEX_PCIOFFSET_TO_INTERNALADDR(wRegOffsPCI) | (read ? 0x80 : 0);
  65. int len = usb_control_msg(fc_usb->udev,
  66. read ? B2C2_USB_CTRL_PIPE_IN : B2C2_USB_CTRL_PIPE_OUT,
  67. request,
  68. request_type, /* 0xc0 read or 0x40 write*/
  69. wAddress,
  70. 0,
  71. val,
  72. sizeof(u32),
  73. B2C2_WAIT_FOR_OPERATION_RDW * HZ);
  74. if (len != sizeof(u32)) {
  75. err("error while %s dword from %d (%d).",read ? "reading" : "writing",
  76. wAddress,wRegOffsPCI);
  77. return -EIO;
  78. }
  79. return 0;
  80. }
  81. /*
  82. * DKT 010817 - add support for V8 memory read/write and flash update
  83. */
  84. static int flexcop_usb_v8_memory_req(struct flexcop_usb *fc_usb,
  85. flexcop_usb_request_t req, u8 page, u16 wAddress,
  86. u8 *pbBuffer,u32 buflen)
  87. {
  88. // u8 dwRequestType;
  89. u8 request_type = USB_TYPE_VENDOR;
  90. u16 wIndex;
  91. int nWaitTime,pipe,len;
  92. wIndex = page << 8;
  93. switch (req) {
  94. case B2C2_USB_READ_V8_MEM:
  95. nWaitTime = B2C2_WAIT_FOR_OPERATION_V8READ;
  96. request_type |= USB_DIR_IN;
  97. // dwRequestType = (u8) RTYPE_READ_V8_MEMORY;
  98. pipe = B2C2_USB_CTRL_PIPE_IN;
  99. break;
  100. case B2C2_USB_WRITE_V8_MEM:
  101. wIndex |= pbBuffer[0];
  102. request_type |= USB_DIR_OUT;
  103. nWaitTime = B2C2_WAIT_FOR_OPERATION_V8WRITE;
  104. // dwRequestType = (u8) RTYPE_WRITE_V8_MEMORY;
  105. pipe = B2C2_USB_CTRL_PIPE_OUT;
  106. break;
  107. case B2C2_USB_FLASH_BLOCK:
  108. request_type |= USB_DIR_OUT;
  109. nWaitTime = B2C2_WAIT_FOR_OPERATION_V8FLASH;
  110. // dwRequestType = (u8) RTYPE_WRITE_V8_FLASH;
  111. pipe = B2C2_USB_CTRL_PIPE_OUT;
  112. break;
  113. default:
  114. deb_info("unsupported request for v8_mem_req %x.\n",req);
  115. return -EINVAL;
  116. }
  117. deb_v8("v8mem: %02x %02x %04x %04x, len: %d\n",request_type,req,
  118. wAddress,wIndex,buflen);
  119. len = usb_control_msg(fc_usb->udev,pipe,
  120. req,
  121. request_type,
  122. wAddress,
  123. wIndex,
  124. pbBuffer,
  125. buflen,
  126. nWaitTime * HZ);
  127. debug_dump(pbBuffer,len,deb_v8);
  128. return len == buflen ? 0 : -EIO;
  129. }
  130. #define bytes_left_to_read_on_page(paddr,buflen) \
  131. ((V8_MEMORY_PAGE_SIZE - (paddr & V8_MEMORY_PAGE_MASK)) > buflen \
  132. ? buflen : (V8_MEMORY_PAGE_SIZE - (paddr & V8_MEMORY_PAGE_MASK)))
  133. static int flexcop_usb_memory_req(struct flexcop_usb *fc_usb,flexcop_usb_request_t req,
  134. flexcop_usb_mem_page_t page_start, u32 addr, int extended, u8 *buf, u32 len)
  135. {
  136. int i,ret = 0;
  137. u16 wMax;
  138. u32 pagechunk = 0;
  139. switch(req) {
  140. case B2C2_USB_READ_V8_MEM: wMax = USB_MEM_READ_MAX; break;
  141. case B2C2_USB_WRITE_V8_MEM: wMax = USB_MEM_WRITE_MAX; break;
  142. case B2C2_USB_FLASH_BLOCK: wMax = USB_FLASH_MAX; break;
  143. default:
  144. return -EINVAL;
  145. break;
  146. }
  147. for (i = 0; i < len;) {
  148. pagechunk = wMax < bytes_left_to_read_on_page(addr,len) ? wMax : bytes_left_to_read_on_page(addr,len);
  149. deb_info("%x\n",(addr & V8_MEMORY_PAGE_MASK) | (V8_MEMORY_EXTENDED*extended));
  150. if ((ret = flexcop_usb_v8_memory_req(fc_usb,req,
  151. page_start + (addr / V8_MEMORY_PAGE_SIZE), /* actual page */
  152. (addr & V8_MEMORY_PAGE_MASK) | (V8_MEMORY_EXTENDED*extended),
  153. &buf[i],pagechunk)) < 0)
  154. return ret;
  155. addr += pagechunk;
  156. len -= pagechunk;
  157. }
  158. return 0;
  159. }
  160. static int flexcop_usb_get_mac_addr(struct flexcop_device *fc, int extended)
  161. {
  162. return flexcop_usb_memory_req(fc->bus_specific,B2C2_USB_READ_V8_MEM,
  163. V8_MEMORY_PAGE_FLASH,0x1f010,1,fc->dvb_adapter.proposed_mac,6);
  164. }
  165. #if 0
  166. static int flexcop_usb_utility_req(struct flexcop_usb *fc_usb, int set,
  167. flexcop_usb_utility_function_t func, u8 extra, u16 wIndex,
  168. u16 buflen, u8 *pvBuffer)
  169. {
  170. u16 wValue;
  171. u8 request_type = (set ? USB_DIR_OUT : USB_DIR_IN) | USB_TYPE_VENDOR;
  172. // u8 dwRequestType = (u8) RTYPE_GENERIC,
  173. int nWaitTime = 2,
  174. pipe = set ? B2C2_USB_CTRL_PIPE_OUT : B2C2_USB_CTRL_PIPE_IN,
  175. len;
  176. wValue = (func << 8) | extra;
  177. len = usb_control_msg(fc_usb->udev,pipe,
  178. B2C2_USB_UTILITY,
  179. request_type,
  180. wValue,
  181. wIndex,
  182. pvBuffer,
  183. buflen,
  184. nWaitTime * HZ);
  185. return len == buflen ? 0 : -EIO;
  186. }
  187. #endif
  188. /* usb i2c stuff */
  189. static int flexcop_usb_i2c_req(struct flexcop_usb *fc_usb,
  190. flexcop_usb_request_t req, flexcop_usb_i2c_function_t func,
  191. flexcop_i2c_port_t port, u8 chipaddr, u8 addr, u8 *buf, u8 buflen)
  192. {
  193. u16 wValue, wIndex;
  194. int nWaitTime,pipe,len;
  195. // u8 dwRequestType;
  196. u8 request_type = USB_TYPE_VENDOR;
  197. switch (func) {
  198. case USB_FUNC_I2C_WRITE:
  199. case USB_FUNC_I2C_MULTIWRITE:
  200. case USB_FUNC_I2C_REPEATWRITE:
  201. /* DKT 020208 - add this to support special case of DiSEqC */
  202. case USB_FUNC_I2C_CHECKWRITE:
  203. pipe = B2C2_USB_CTRL_PIPE_OUT;
  204. nWaitTime = 2;
  205. // dwRequestType = (u8) RTYPE_GENERIC;
  206. request_type |= USB_DIR_OUT;
  207. break;
  208. case USB_FUNC_I2C_READ:
  209. case USB_FUNC_I2C_REPEATREAD:
  210. pipe = B2C2_USB_CTRL_PIPE_IN;
  211. nWaitTime = 2;
  212. // dwRequestType = (u8) RTYPE_GENERIC;
  213. request_type |= USB_DIR_IN;
  214. break;
  215. default:
  216. deb_info("unsupported function for i2c_req %x\n",func);
  217. return -EINVAL;
  218. }
  219. wValue = (func << 8 ) | (port << 4);
  220. wIndex = (chipaddr << 8 ) | addr;
  221. deb_i2c("i2c %2d: %02x %02x %02x %02x %02x %02x\n",func,request_type,req,
  222. ((wValue && 0xff) << 8),wValue >> 8,((wIndex && 0xff) << 8),wIndex >> 8);
  223. len = usb_control_msg(fc_usb->udev,pipe,
  224. req,
  225. request_type,
  226. wValue,
  227. wIndex,
  228. buf,
  229. buflen,
  230. nWaitTime * HZ);
  231. return len == buflen ? 0 : -EREMOTEIO;
  232. }
  233. /* actual bus specific access functions, make sure prototype are/will be equal to pci */
  234. static flexcop_ibi_value flexcop_usb_read_ibi_reg(struct flexcop_device *fc, flexcop_ibi_register reg)
  235. {
  236. flexcop_ibi_value val;
  237. val.raw = 0;
  238. flexcop_usb_readwrite_dw(fc,reg, &val.raw, 1);
  239. return val;
  240. }
  241. static int flexcop_usb_write_ibi_reg(struct flexcop_device *fc, flexcop_ibi_register reg, flexcop_ibi_value val)
  242. {
  243. return flexcop_usb_readwrite_dw(fc,reg, &val.raw, 0);
  244. }
  245. static int flexcop_usb_i2c_request(struct flexcop_device *fc, flexcop_access_op_t op,
  246. flexcop_i2c_port_t port, u8 chipaddr, u8 addr, u8 *buf, u16 len)
  247. {
  248. if (op == FC_READ)
  249. return flexcop_usb_i2c_req(fc->bus_specific,B2C2_USB_I2C_REQUEST,USB_FUNC_I2C_READ,port,chipaddr,addr,buf,len);
  250. else
  251. return flexcop_usb_i2c_req(fc->bus_specific,B2C2_USB_I2C_REQUEST,USB_FUNC_I2C_WRITE,port,chipaddr,addr,buf,len);
  252. }
  253. static void flexcop_usb_process_frame(struct flexcop_usb *fc_usb, u8 *buffer, int buffer_length)
  254. {
  255. u8 *b;
  256. int l;
  257. deb_ts("tmp_buffer_length=%d, buffer_length=%d\n", fc_usb->tmp_buffer_length, buffer_length);
  258. if (fc_usb->tmp_buffer_length > 0) {
  259. memcpy(fc_usb->tmp_buffer+fc_usb->tmp_buffer_length, buffer, buffer_length);
  260. fc_usb->tmp_buffer_length += buffer_length;
  261. b = fc_usb->tmp_buffer;
  262. l = fc_usb->tmp_buffer_length;
  263. } else {
  264. b=buffer;
  265. l=buffer_length;
  266. }
  267. while (l >= 190) {
  268. if (*b == 0xff)
  269. switch (*(b+1) & 0x03) {
  270. case 0x01: /* media packet */
  271. if ( *(b+2) == 0x47 )
  272. flexcop_pass_dmx_packets(fc_usb->fc_dev, b+2, 1);
  273. else
  274. deb_ts("not ts packet %02x %02x %02x %02x \n", *(b+2), *(b+3), *(b+4), *(b+5) );
  275. b += 190;
  276. l -= 190;
  277. break;
  278. default:
  279. deb_ts("wrong packet type\n");
  280. l = 0;
  281. break;
  282. }
  283. else {
  284. deb_ts("wrong header\n");
  285. l = 0;
  286. }
  287. }
  288. if (l>0)
  289. memcpy(fc_usb->tmp_buffer, b, l);
  290. fc_usb->tmp_buffer_length = l;
  291. }
  292. static void flexcop_usb_urb_complete(struct urb *urb, struct pt_regs *ptregs)
  293. {
  294. struct flexcop_usb *fc_usb = urb->context;
  295. int i;
  296. if (urb->actual_length > 0)
  297. deb_ts("urb completed, bufsize: %d actlen; %d\n",urb->transfer_buffer_length, urb->actual_length);
  298. for (i = 0; i < urb->number_of_packets; i++) {
  299. if (urb->iso_frame_desc[i].status < 0) {
  300. err("iso frame descriptor %d has an error: %d\n",i,urb->iso_frame_desc[i].status);
  301. } else
  302. if (urb->iso_frame_desc[i].actual_length > 0) {
  303. deb_ts("passed %d bytes to the demux\n",urb->iso_frame_desc[i].actual_length);
  304. flexcop_usb_process_frame(fc_usb,
  305. urb->transfer_buffer + urb->iso_frame_desc[i].offset,
  306. urb->iso_frame_desc[i].actual_length);
  307. }
  308. urb->iso_frame_desc[i].status = 0;
  309. urb->iso_frame_desc[i].actual_length = 0;
  310. }
  311. usb_submit_urb(urb,GFP_ATOMIC);
  312. }
  313. static int flexcop_usb_stream_control(struct flexcop_device *fc, int onoff)
  314. {
  315. /* submit/kill iso packets */
  316. return 0;
  317. }
  318. static void flexcop_usb_transfer_exit(struct flexcop_usb *fc_usb)
  319. {
  320. int i;
  321. for (i = 0; i < B2C2_USB_NUM_ISO_URB; i++)
  322. if (fc_usb->iso_urb[i] != NULL) {
  323. deb_ts("unlinking/killing urb no. %d\n",i);
  324. usb_kill_urb(fc_usb->iso_urb[i]);
  325. usb_free_urb(fc_usb->iso_urb[i]);
  326. }
  327. if (fc_usb->iso_buffer != NULL)
  328. pci_free_consistent(NULL,fc_usb->buffer_size, fc_usb->iso_buffer, fc_usb->dma_addr);
  329. }
  330. static int flexcop_usb_transfer_init(struct flexcop_usb *fc_usb)
  331. {
  332. u16 frame_size = fc_usb->uintf->cur_altsetting->endpoint[0].desc.wMaxPacketSize;
  333. int bufsize = B2C2_USB_NUM_ISO_URB * B2C2_USB_FRAMES_PER_ISO * frame_size,i,j,ret;
  334. int buffer_offset = 0;
  335. deb_ts("creating %d iso-urbs with %d frames each of %d bytes size = %d.\n",
  336. B2C2_USB_NUM_ISO_URB, B2C2_USB_FRAMES_PER_ISO, frame_size,bufsize);
  337. fc_usb->iso_buffer = pci_alloc_consistent(NULL,bufsize,&fc_usb->dma_addr);
  338. if (fc_usb->iso_buffer == NULL)
  339. return -ENOMEM;
  340. memset(fc_usb->iso_buffer, 0, bufsize);
  341. fc_usb->buffer_size = bufsize;
  342. /* creating iso urbs */
  343. for (i = 0; i < B2C2_USB_NUM_ISO_URB; i++)
  344. if (!(fc_usb->iso_urb[i] = usb_alloc_urb(B2C2_USB_FRAMES_PER_ISO,GFP_ATOMIC))) {
  345. ret = -ENOMEM;
  346. goto urb_error;
  347. }
  348. /* initialising and submitting iso urbs */
  349. for (i = 0; i < B2C2_USB_NUM_ISO_URB; i++) {
  350. int frame_offset = 0;
  351. struct urb *urb = fc_usb->iso_urb[i];
  352. deb_ts("initializing and submitting urb no. %d (buf_offset: %d).\n",i,buffer_offset);
  353. urb->dev = fc_usb->udev;
  354. urb->context = fc_usb;
  355. urb->complete = flexcop_usb_urb_complete;
  356. urb->pipe = B2C2_USB_DATA_PIPE;
  357. urb->transfer_flags = URB_ISO_ASAP;
  358. urb->interval = 1;
  359. urb->number_of_packets = B2C2_USB_FRAMES_PER_ISO;
  360. urb->transfer_buffer_length = frame_size * B2C2_USB_FRAMES_PER_ISO;
  361. urb->transfer_buffer = fc_usb->iso_buffer + buffer_offset;
  362. buffer_offset += frame_size * B2C2_USB_FRAMES_PER_ISO;
  363. for (j = 0; j < B2C2_USB_FRAMES_PER_ISO; j++) {
  364. deb_ts("urb no: %d, frame: %d, frame_offset: %d\n",i,j,frame_offset);
  365. urb->iso_frame_desc[j].offset = frame_offset;
  366. urb->iso_frame_desc[j].length = frame_size;
  367. frame_offset += frame_size;
  368. }
  369. if ((ret = usb_submit_urb(fc_usb->iso_urb[i],GFP_ATOMIC))) {
  370. err("submitting urb %d failed with %d.",i,ret);
  371. goto urb_error;
  372. }
  373. deb_ts("submitted urb no. %d.\n",i);
  374. }
  375. /* SRAM */
  376. flexcop_sram_set_dest(fc_usb->fc_dev,FC_SRAM_DEST_MEDIA | FC_SRAM_DEST_NET |
  377. FC_SRAM_DEST_CAO | FC_SRAM_DEST_CAI, FC_SRAM_DEST_TARGET_WAN_USB);
  378. flexcop_wan_set_speed(fc_usb->fc_dev,FC_WAN_SPEED_8MBITS);
  379. flexcop_sram_ctrl(fc_usb->fc_dev,1,1,1);
  380. ret = 0;
  381. goto success;
  382. urb_error:
  383. flexcop_usb_transfer_exit(fc_usb);
  384. success:
  385. return ret;
  386. }
  387. static int flexcop_usb_init(struct flexcop_usb *fc_usb)
  388. {
  389. /* use the alternate setting with the larges buffer */
  390. usb_set_interface(fc_usb->udev,0,1);
  391. switch (fc_usb->udev->speed) {
  392. case USB_SPEED_LOW:
  393. err("cannot handle USB speed because it is to sLOW.");
  394. return -ENODEV;
  395. break;
  396. case USB_SPEED_FULL:
  397. info("running at FULL speed.");
  398. break;
  399. case USB_SPEED_HIGH:
  400. info("running at HIGH speed.");
  401. break;
  402. case USB_SPEED_UNKNOWN: /* fall through */
  403. default:
  404. err("cannot handle USB speed because it is unkown.");
  405. return -ENODEV;
  406. }
  407. usb_set_intfdata(fc_usb->uintf, fc_usb);
  408. return 0;
  409. }
  410. static void flexcop_usb_exit(struct flexcop_usb *fc_usb)
  411. {
  412. usb_set_intfdata(fc_usb->uintf, NULL);
  413. }
  414. static int flexcop_usb_probe(struct usb_interface *intf,
  415. const struct usb_device_id *id)
  416. {
  417. struct usb_device *udev = interface_to_usbdev(intf);
  418. struct flexcop_usb *fc_usb = NULL;
  419. struct flexcop_device *fc = NULL;
  420. int ret;
  421. if ((fc = flexcop_device_kmalloc(sizeof(struct flexcop_usb))) == NULL) {
  422. err("out of memory\n");
  423. return -ENOMEM;
  424. }
  425. /* general flexcop init */
  426. fc_usb = fc->bus_specific;
  427. fc_usb->fc_dev = fc;
  428. fc->read_ibi_reg = flexcop_usb_read_ibi_reg;
  429. fc->write_ibi_reg = flexcop_usb_write_ibi_reg;
  430. fc->i2c_request = flexcop_usb_i2c_request;
  431. fc->get_mac_addr = flexcop_usb_get_mac_addr;
  432. fc->stream_control = flexcop_usb_stream_control;
  433. fc->pid_filtering = 1;
  434. fc->bus_type = FC_USB;
  435. fc->dev = &udev->dev;
  436. fc->owner = THIS_MODULE;
  437. /* bus specific part */
  438. fc_usb->udev = udev;
  439. fc_usb->uintf = intf;
  440. if ((ret = flexcop_usb_init(fc_usb)) != 0)
  441. goto err_kfree;
  442. /* init flexcop */
  443. if ((ret = flexcop_device_initialize(fc)) != 0)
  444. goto err_usb_exit;
  445. /* xfer init */
  446. if ((ret = flexcop_usb_transfer_init(fc_usb)) != 0)
  447. goto err_fc_exit;
  448. info("%s successfully initialized and connected.",DRIVER_NAME);
  449. ret = 0;
  450. goto success;
  451. err_fc_exit:
  452. flexcop_device_exit(fc);
  453. err_usb_exit:
  454. flexcop_usb_exit(fc_usb);
  455. err_kfree:
  456. flexcop_device_kfree(fc);
  457. success:
  458. return ret;
  459. }
  460. static void flexcop_usb_disconnect(struct usb_interface *intf)
  461. {
  462. struct flexcop_usb *fc_usb = usb_get_intfdata(intf);
  463. flexcop_usb_transfer_exit(fc_usb);
  464. flexcop_device_exit(fc_usb->fc_dev);
  465. flexcop_usb_exit(fc_usb);
  466. flexcop_device_kfree(fc_usb->fc_dev);
  467. info("%s successfully deinitialized and disconnected.",DRIVER_NAME);
  468. }
  469. static struct usb_device_id flexcop_usb_table [] = {
  470. { USB_DEVICE(0x0af7, 0x0101) },
  471. { }
  472. };
  473. MODULE_DEVICE_TABLE (usb, flexcop_usb_table);
  474. /* usb specific object needed to register this driver with the usb subsystem */
  475. static struct usb_driver flexcop_usb_driver = {
  476. .name = "b2c2_flexcop_usb",
  477. .probe = flexcop_usb_probe,
  478. .disconnect = flexcop_usb_disconnect,
  479. .id_table = flexcop_usb_table,
  480. };
  481. /* module stuff */
  482. static int __init flexcop_usb_module_init(void)
  483. {
  484. int result;
  485. if ((result = usb_register(&flexcop_usb_driver))) {
  486. err("usb_register failed. (%d)",result);
  487. return result;
  488. }
  489. return 0;
  490. }
  491. static void __exit flexcop_usb_module_exit(void)
  492. {
  493. /* deregister this driver from the USB subsystem */
  494. usb_deregister(&flexcop_usb_driver);
  495. }
  496. module_init(flexcop_usb_module_init);
  497. module_exit(flexcop_usb_module_exit);
  498. MODULE_AUTHOR(DRIVER_AUTHOR);
  499. MODULE_DESCRIPTION(DRIVER_NAME);
  500. MODULE_LICENSE("GPL");