flexcop-usb.c 16 KB

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