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