flexcop-usb.c 16 KB

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