diff options
Diffstat (limited to 'drivers/media/dvb/b2c2/flexcop-usb.c')
-rw-r--r-- | drivers/media/dvb/b2c2/flexcop-usb.c | 368 |
1 files changed, 199 insertions, 169 deletions
diff --git a/drivers/media/dvb/b2c2/flexcop-usb.c b/drivers/media/dvb/b2c2/flexcop-usb.c index ae0d76a5d51d..bedcfb671624 100644 --- a/drivers/media/dvb/b2c2/flexcop-usb.c +++ b/drivers/media/dvb/b2c2/flexcop-usb.c | |||
@@ -1,11 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III | 2 | * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III |
3 | * | 3 | * flexcop-usb.c - covers the USB part |
4 | * flexcop-usb.c - covers the USB part. | 4 | * see flexcop.c for copyright information |
5 | * | ||
6 | * see flexcop.c for copyright information. | ||
7 | */ | 5 | */ |
8 | |||
9 | #define FC_LOG_PREFIX "flexcop_usb" | 6 | #define FC_LOG_PREFIX "flexcop_usb" |
10 | #include "flexcop-usb.h" | 7 | #include "flexcop-usb.h" |
11 | #include "flexcop-common.h" | 8 | #include "flexcop-common.h" |
@@ -18,42 +15,47 @@ | |||
18 | /* debug */ | 15 | /* debug */ |
19 | #ifdef CONFIG_DVB_B2C2_FLEXCOP_DEBUG | 16 | #ifdef CONFIG_DVB_B2C2_FLEXCOP_DEBUG |
20 | #define dprintk(level,args...) \ | 17 | #define dprintk(level,args...) \ |
21 | do { if ((debug & level)) { printk(args); } } while (0) | 18 | do { if ((debug & level)) printk(args); } while (0) |
22 | #define debug_dump(b,l,method) {\ | 19 | |
20 | #define debug_dump(b, l, method) do {\ | ||
23 | int i; \ | 21 | int i; \ |
24 | for (i = 0; i < l; i++) method("%02x ", b[i]); \ | 22 | for (i = 0; i < l; i++) \ |
25 | method("\n");\ | 23 | method("%02x ", b[i]); \ |
26 | } | 24 | method("\n"); \ |
25 | } while (0) | ||
27 | 26 | ||
28 | #define DEBSTATUS "" | 27 | #define DEBSTATUS "" |
29 | #else | 28 | #else |
30 | #define dprintk(level,args...) | 29 | #define dprintk(level, args...) |
31 | #define debug_dump(b,l,method) | 30 | #define debug_dump(b, l, method) |
32 | #define DEBSTATUS " (debugging is not enabled)" | 31 | #define DEBSTATUS " (debugging is not enabled)" |
33 | #endif | 32 | #endif |
34 | 33 | ||
35 | static int debug; | 34 | static int debug; |
36 | module_param(debug, int, 0644); | 35 | module_param(debug, int, 0644); |
37 | MODULE_PARM_DESC(debug, "set debugging level (1=info,ts=2,ctrl=4,i2c=8,v8mem=16 (or-able))." DEBSTATUS); | 36 | MODULE_PARM_DESC(debug, "set debugging level (1=info,ts=2," |
37 | "ctrl=4,i2c=8,v8mem=16 (or-able))." DEBSTATUS); | ||
38 | #undef DEBSTATUS | 38 | #undef DEBSTATUS |
39 | 39 | ||
40 | #define deb_info(args...) dprintk(0x01,args) | 40 | #define deb_info(args...) dprintk(0x01, args) |
41 | #define deb_ts(args...) dprintk(0x02,args) | 41 | #define deb_ts(args...) dprintk(0x02, args) |
42 | #define deb_ctrl(args...) dprintk(0x04,args) | 42 | #define deb_ctrl(args...) dprintk(0x04, args) |
43 | #define deb_i2c(args...) dprintk(0x08,args) | 43 | #define deb_i2c(args...) dprintk(0x08, args) |
44 | #define deb_v8(args...) dprintk(0x10,args) | 44 | #define deb_v8(args...) dprintk(0x10, args) |
45 | 45 | ||
46 | /* JLP 111700: we will include the 1 bit gap between the upper and lower 3 bits | 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. | 47 | * in the IBI address, to make the V8 code simpler. |
48 | * PCI ADDRESS FORMAT: 0x71C -> 0000 0111 0001 1100 (these are the six bits used) | 48 | * PCI ADDRESS FORMAT: 0x71C -> 0000 0111 0001 1100 (the six bits used) |
49 | * in general: 0000 0HHH 000L LL00 | 49 | * in general: 0000 0HHH 000L LL00 |
50 | * IBI ADDRESS FORMAT: RHHH BLLL | 50 | * IBI ADDRESS FORMAT: RHHH BLLL |
51 | * | 51 | * |
52 | * where R is the read(1)/write(0) bit, B is the busy bit | 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. | 53 | * and HHH and LLL are the two sets of three bits from the PCI address. |
54 | */ | 54 | */ |
55 | #define B2C2_FLEX_PCIOFFSET_TO_INTERNALADDR(usPCI) (u8) (((usPCI >> 2) & 0x07) + ((usPCI >> 4) & 0x70)) | 55 | #define B2C2_FLEX_PCIOFFSET_TO_INTERNALADDR(usPCI) (u8) \ |
56 | #define B2C2_FLEX_INTERNALADDR_TO_PCIOFFSET(ucAddr) (u16) (((ucAddr & 0x07) << 2) + ((ucAddr & 0x70) << 4)) | 56 | (((usPCI >> 2) & 0x07) + ((usPCI >> 4) & 0x70)) |
57 | #define B2C2_FLEX_INTERNALADDR_TO_PCIOFFSET(ucAddr) (u16) \ | ||
58 | (((ucAddr & 0x07) << 2) + ((ucAddr & 0x70) << 4)) | ||
57 | 59 | ||
58 | /* | 60 | /* |
59 | * DKT 020228 | 61 | * DKT 020228 |
@@ -69,12 +71,13 @@ static int flexcop_usb_readwrite_dw(struct flexcop_device *fc, u16 wRegOffsPCI, | |||
69 | struct flexcop_usb *fc_usb = fc->bus_specific; | 71 | struct flexcop_usb *fc_usb = fc->bus_specific; |
70 | u8 request = read ? B2C2_USB_READ_REG : B2C2_USB_WRITE_REG; | 72 | u8 request = read ? B2C2_USB_READ_REG : B2C2_USB_WRITE_REG; |
71 | u8 request_type = (read ? USB_DIR_IN : USB_DIR_OUT) | USB_TYPE_VENDOR; | 73 | u8 request_type = (read ? USB_DIR_IN : USB_DIR_OUT) | USB_TYPE_VENDOR; |
72 | u8 wAddress = B2C2_FLEX_PCIOFFSET_TO_INTERNALADDR(wRegOffsPCI) | (read ? 0x80 : 0); | 74 | u8 wAddress = B2C2_FLEX_PCIOFFSET_TO_INTERNALADDR(wRegOffsPCI) | |
75 | (read ? 0x80 : 0); | ||
73 | 76 | ||
74 | int len = usb_control_msg(fc_usb->udev, | 77 | int len = usb_control_msg(fc_usb->udev, |
75 | read ? B2C2_USB_CTRL_PIPE_IN : B2C2_USB_CTRL_PIPE_OUT, | 78 | read ? B2C2_USB_CTRL_PIPE_IN : B2C2_USB_CTRL_PIPE_OUT, |
76 | request, | 79 | request, |
77 | request_type, /* 0xc0 read or 0x40 write*/ | 80 | request_type, /* 0xc0 read or 0x40 write */ |
78 | wAddress, | 81 | wAddress, |
79 | 0, | 82 | 0, |
80 | val, | 83 | val, |
@@ -82,55 +85,49 @@ static int flexcop_usb_readwrite_dw(struct flexcop_device *fc, u16 wRegOffsPCI, | |||
82 | B2C2_WAIT_FOR_OPERATION_RDW * HZ); | 85 | B2C2_WAIT_FOR_OPERATION_RDW * HZ); |
83 | 86 | ||
84 | if (len != sizeof(u32)) { | 87 | if (len != sizeof(u32)) { |
85 | err("error while %s dword from %d (%d).",read ? "reading" : "writing", | 88 | err("error while %s dword from %d (%d).", read ? "reading" : |
86 | wAddress,wRegOffsPCI); | 89 | "writing", wAddress, wRegOffsPCI); |
87 | return -EIO; | 90 | return -EIO; |
88 | } | 91 | } |
89 | return 0; | 92 | return 0; |
90 | } | 93 | } |
91 | |||
92 | /* | 94 | /* |
93 | * DKT 010817 - add support for V8 memory read/write and flash update | 95 | * DKT 010817 - add support for V8 memory read/write and flash update |
94 | */ | 96 | */ |
95 | static int flexcop_usb_v8_memory_req(struct flexcop_usb *fc_usb, | 97 | static int flexcop_usb_v8_memory_req(struct flexcop_usb *fc_usb, |
96 | flexcop_usb_request_t req, u8 page, u16 wAddress, | 98 | flexcop_usb_request_t req, u8 page, u16 wAddress, |
97 | u8 *pbBuffer,u32 buflen) | 99 | u8 *pbBuffer, u32 buflen) |
98 | { | 100 | { |
99 | // u8 dwRequestType; | ||
100 | u8 request_type = USB_TYPE_VENDOR; | 101 | u8 request_type = USB_TYPE_VENDOR; |
101 | u16 wIndex; | 102 | u16 wIndex; |
102 | int nWaitTime,pipe,len; | 103 | int nWaitTime, pipe, len; |
103 | |||
104 | wIndex = page << 8; | 104 | wIndex = page << 8; |
105 | 105 | ||
106 | switch (req) { | 106 | switch (req) { |
107 | case B2C2_USB_READ_V8_MEM: | 107 | case B2C2_USB_READ_V8_MEM: |
108 | nWaitTime = B2C2_WAIT_FOR_OPERATION_V8READ; | 108 | nWaitTime = B2C2_WAIT_FOR_OPERATION_V8READ; |
109 | request_type |= USB_DIR_IN; | 109 | request_type |= USB_DIR_IN; |
110 | // dwRequestType = (u8) RTYPE_READ_V8_MEMORY; | 110 | pipe = B2C2_USB_CTRL_PIPE_IN; |
111 | pipe = B2C2_USB_CTRL_PIPE_IN; | ||
112 | break; | 111 | break; |
113 | case B2C2_USB_WRITE_V8_MEM: | 112 | case B2C2_USB_WRITE_V8_MEM: |
114 | wIndex |= pbBuffer[0]; | 113 | wIndex |= pbBuffer[0]; |
115 | request_type |= USB_DIR_OUT; | 114 | request_type |= USB_DIR_OUT; |
116 | nWaitTime = B2C2_WAIT_FOR_OPERATION_V8WRITE; | 115 | nWaitTime = B2C2_WAIT_FOR_OPERATION_V8WRITE; |
117 | // dwRequestType = (u8) RTYPE_WRITE_V8_MEMORY; | 116 | pipe = B2C2_USB_CTRL_PIPE_OUT; |
118 | pipe = B2C2_USB_CTRL_PIPE_OUT; | ||
119 | break; | 117 | break; |
120 | case B2C2_USB_FLASH_BLOCK: | 118 | case B2C2_USB_FLASH_BLOCK: |
121 | request_type |= USB_DIR_OUT; | 119 | request_type |= USB_DIR_OUT; |
122 | nWaitTime = B2C2_WAIT_FOR_OPERATION_V8FLASH; | 120 | nWaitTime = B2C2_WAIT_FOR_OPERATION_V8FLASH; |
123 | // dwRequestType = (u8) RTYPE_WRITE_V8_FLASH; | 121 | pipe = B2C2_USB_CTRL_PIPE_OUT; |
124 | pipe = B2C2_USB_CTRL_PIPE_OUT; | ||
125 | break; | 122 | break; |
126 | default: | 123 | default: |
127 | deb_info("unsupported request for v8_mem_req %x.\n",req); | 124 | deb_info("unsupported request for v8_mem_req %x.\n", req); |
128 | return -EINVAL; | 125 | return -EINVAL; |
129 | } | 126 | } |
130 | deb_v8("v8mem: %02x %02x %04x %04x, len: %d\n",request_type,req, | 127 | deb_v8("v8mem: %02x %02x %04x %04x, len: %d\n", request_type, req, |
131 | wAddress,wIndex,buflen); | 128 | wAddress, wIndex, buflen); |
132 | 129 | ||
133 | len = usb_control_msg(fc_usb->udev,pipe, | 130 | len = usb_control_msg(fc_usb->udev, pipe, |
134 | req, | 131 | req, |
135 | request_type, | 132 | request_type, |
136 | wAddress, | 133 | wAddress, |
@@ -139,39 +136,53 @@ static int flexcop_usb_v8_memory_req(struct flexcop_usb *fc_usb, | |||
139 | buflen, | 136 | buflen, |
140 | nWaitTime * HZ); | 137 | nWaitTime * HZ); |
141 | 138 | ||
142 | debug_dump(pbBuffer,len,deb_v8); | 139 | debug_dump(pbBuffer, len, deb_v8); |
143 | |||
144 | return len == buflen ? 0 : -EIO; | 140 | return len == buflen ? 0 : -EIO; |
145 | } | 141 | } |
146 | 142 | ||
147 | #define bytes_left_to_read_on_page(paddr,buflen) \ | 143 | #define bytes_left_to_read_on_page(paddr,buflen) \ |
148 | ((V8_MEMORY_PAGE_SIZE - (paddr & V8_MEMORY_PAGE_MASK)) > buflen \ | 144 | ((V8_MEMORY_PAGE_SIZE - (paddr & V8_MEMORY_PAGE_MASK)) > buflen \ |
149 | ? buflen : (V8_MEMORY_PAGE_SIZE - (paddr & V8_MEMORY_PAGE_MASK))) | 145 | ? buflen : (V8_MEMORY_PAGE_SIZE - (paddr & V8_MEMORY_PAGE_MASK))) |
150 | 146 | ||
151 | static int flexcop_usb_memory_req(struct flexcop_usb *fc_usb,flexcop_usb_request_t req, | 147 | static int flexcop_usb_memory_req(struct flexcop_usb *fc_usb, |
152 | flexcop_usb_mem_page_t page_start, u32 addr, int extended, u8 *buf, u32 len) | 148 | flexcop_usb_request_t req, flexcop_usb_mem_page_t page_start, |
149 | u32 addr, int extended, u8 *buf, u32 len) | ||
153 | { | 150 | { |
154 | int i,ret = 0; | 151 | int i,ret = 0; |
155 | u16 wMax; | 152 | u16 wMax; |
156 | u32 pagechunk = 0; | 153 | u32 pagechunk = 0; |
157 | 154 | ||
158 | switch(req) { | 155 | switch(req) { |
159 | case B2C2_USB_READ_V8_MEM: wMax = USB_MEM_READ_MAX; break; | 156 | case B2C2_USB_READ_V8_MEM: |
160 | case B2C2_USB_WRITE_V8_MEM: wMax = USB_MEM_WRITE_MAX; break; | 157 | wMax = USB_MEM_READ_MAX; |
161 | case B2C2_USB_FLASH_BLOCK: wMax = USB_FLASH_MAX; break; | 158 | break; |
162 | default: | 159 | case B2C2_USB_WRITE_V8_MEM: |
163 | return -EINVAL; | 160 | wMax = USB_MEM_WRITE_MAX; |
161 | break; | ||
162 | case B2C2_USB_FLASH_BLOCK: | ||
163 | wMax = USB_FLASH_MAX; | ||
164 | break; | ||
165 | default: | ||
166 | return -EINVAL; | ||
164 | break; | 167 | break; |
165 | } | 168 | } |
166 | for (i = 0; i < len;) { | 169 | for (i = 0; i < len;) { |
167 | pagechunk = wMax < bytes_left_to_read_on_page(addr,len) ? wMax : bytes_left_to_read_on_page(addr,len); | 170 | pagechunk = |
168 | deb_info("%x\n",(addr & V8_MEMORY_PAGE_MASK) | (V8_MEMORY_EXTENDED*extended)); | 171 | wMax < bytes_left_to_read_on_page(addr, len) ? |
169 | if ((ret = flexcop_usb_v8_memory_req(fc_usb,req, | 172 | wMax : |
170 | page_start + (addr / V8_MEMORY_PAGE_SIZE), /* actual page */ | 173 | bytes_left_to_read_on_page(addr, len); |
171 | (addr & V8_MEMORY_PAGE_MASK) | (V8_MEMORY_EXTENDED*extended), | 174 | deb_info("%x\n", |
172 | &buf[i],pagechunk)) < 0) | 175 | (addr & V8_MEMORY_PAGE_MASK) | |
176 | (V8_MEMORY_EXTENDED*extended)); | ||
177 | |||
178 | ret = flexcop_usb_v8_memory_req(fc_usb, req, | ||
179 | page_start + (addr / V8_MEMORY_PAGE_SIZE), | ||
180 | (addr & V8_MEMORY_PAGE_MASK) | | ||
181 | (V8_MEMORY_EXTENDED*extended), | ||
182 | &buf[i], pagechunk); | ||
183 | |||
184 | if (ret < 0) | ||
173 | return ret; | 185 | return ret; |
174 | |||
175 | addr += pagechunk; | 186 | addr += pagechunk; |
176 | len -= pagechunk; | 187 | len -= pagechunk; |
177 | } | 188 | } |
@@ -180,8 +191,9 @@ static int flexcop_usb_memory_req(struct flexcop_usb *fc_usb,flexcop_usb_request | |||
180 | 191 | ||
181 | static int flexcop_usb_get_mac_addr(struct flexcop_device *fc, int extended) | 192 | static int flexcop_usb_get_mac_addr(struct flexcop_device *fc, int extended) |
182 | { | 193 | { |
183 | return flexcop_usb_memory_req(fc->bus_specific,B2C2_USB_READ_V8_MEM, | 194 | return flexcop_usb_memory_req(fc->bus_specific, B2C2_USB_READ_V8_MEM, |
184 | V8_MEMORY_PAGE_FLASH,0x1f010,1,fc->dvb_adapter.proposed_mac,6); | 195 | V8_MEMORY_PAGE_FLASH, 0x1f010, 1, |
196 | fc->dvb_adapter.proposed_mac, 6); | ||
185 | } | 197 | } |
186 | 198 | ||
187 | #if 0 | 199 | #if 0 |
@@ -191,11 +203,8 @@ static int flexcop_usb_utility_req(struct flexcop_usb *fc_usb, int set, | |||
191 | { | 203 | { |
192 | u16 wValue; | 204 | u16 wValue; |
193 | u8 request_type = (set ? USB_DIR_OUT : USB_DIR_IN) | USB_TYPE_VENDOR; | 205 | u8 request_type = (set ? USB_DIR_OUT : USB_DIR_IN) | USB_TYPE_VENDOR; |
194 | // u8 dwRequestType = (u8) RTYPE_GENERIC, | ||
195 | int nWaitTime = 2, | 206 | int nWaitTime = 2, |
196 | pipe = set ? B2C2_USB_CTRL_PIPE_OUT : B2C2_USB_CTRL_PIPE_IN, | 207 | pipe = set ? B2C2_USB_CTRL_PIPE_OUT : B2C2_USB_CTRL_PIPE_IN, len; |
197 | len; | ||
198 | |||
199 | wValue = (func << 8) | extra; | 208 | wValue = (func << 8) | extra; |
200 | 209 | ||
201 | len = usb_control_msg(fc_usb->udev,pipe, | 210 | len = usb_control_msg(fc_usb->udev,pipe, |
@@ -218,36 +227,35 @@ static int flexcop_usb_i2c_req(struct flexcop_i2c_adapter *i2c, | |||
218 | struct flexcop_usb *fc_usb = i2c->fc->bus_specific; | 227 | struct flexcop_usb *fc_usb = i2c->fc->bus_specific; |
219 | u16 wValue, wIndex; | 228 | u16 wValue, wIndex; |
220 | int nWaitTime,pipe,len; | 229 | int nWaitTime,pipe,len; |
221 | // u8 dwRequestType; | ||
222 | u8 request_type = USB_TYPE_VENDOR; | 230 | u8 request_type = USB_TYPE_VENDOR; |
223 | 231 | ||
224 | switch (func) { | 232 | switch (func) { |
225 | case USB_FUNC_I2C_WRITE: | 233 | case USB_FUNC_I2C_WRITE: |
226 | case USB_FUNC_I2C_MULTIWRITE: | 234 | case USB_FUNC_I2C_MULTIWRITE: |
227 | case USB_FUNC_I2C_REPEATWRITE: | 235 | case USB_FUNC_I2C_REPEATWRITE: |
228 | /* DKT 020208 - add this to support special case of DiSEqC */ | 236 | /* DKT 020208 - add this to support special case of DiSEqC */ |
229 | case USB_FUNC_I2C_CHECKWRITE: | 237 | case USB_FUNC_I2C_CHECKWRITE: |
230 | pipe = B2C2_USB_CTRL_PIPE_OUT; | 238 | pipe = B2C2_USB_CTRL_PIPE_OUT; |
231 | nWaitTime = 2; | 239 | nWaitTime = 2; |
232 | // dwRequestType = (u8) RTYPE_GENERIC; | 240 | request_type |= USB_DIR_OUT; |
233 | request_type |= USB_DIR_OUT; | ||
234 | break; | 241 | break; |
235 | case USB_FUNC_I2C_READ: | 242 | case USB_FUNC_I2C_READ: |
236 | case USB_FUNC_I2C_REPEATREAD: | 243 | case USB_FUNC_I2C_REPEATREAD: |
237 | pipe = B2C2_USB_CTRL_PIPE_IN; | 244 | pipe = B2C2_USB_CTRL_PIPE_IN; |
238 | nWaitTime = 2; | 245 | nWaitTime = 2; |
239 | // dwRequestType = (u8) RTYPE_GENERIC; | 246 | request_type |= USB_DIR_IN; |
240 | request_type |= USB_DIR_IN; | ||
241 | break; | 247 | break; |
242 | default: | 248 | default: |
243 | deb_info("unsupported function for i2c_req %x\n",func); | 249 | deb_info("unsupported function for i2c_req %x\n", func); |
244 | return -EINVAL; | 250 | return -EINVAL; |
245 | } | 251 | } |
246 | wValue = (func << 8) | (i2c->port << 4); | 252 | wValue = (func << 8) | (i2c->port << 4); |
247 | wIndex = (chipaddr << 8 ) | addr; | 253 | wIndex = (chipaddr << 8 ) | addr; |
248 | 254 | ||
249 | deb_i2c("i2c %2d: %02x %02x %02x %02x %02x %02x\n",func,request_type,req, | 255 | deb_i2c("i2c %2d: %02x %02x %02x %02x %02x %02x\n", |
250 | wValue & 0xff, wValue >> 8, wIndex & 0xff, wIndex >> 8); | 256 | func, request_type, req, |
257 | wValue & 0xff, wValue >> 8, | ||
258 | wIndex & 0xff, wIndex >> 8); | ||
251 | 259 | ||
252 | len = usb_control_msg(fc_usb->udev,pipe, | 260 | len = usb_control_msg(fc_usb->udev,pipe, |
253 | req, | 261 | req, |
@@ -257,44 +265,49 @@ static int flexcop_usb_i2c_req(struct flexcop_i2c_adapter *i2c, | |||
257 | buf, | 265 | buf, |
258 | buflen, | 266 | buflen, |
259 | nWaitTime * HZ); | 267 | nWaitTime * HZ); |
260 | |||
261 | return len == buflen ? 0 : -EREMOTEIO; | 268 | return len == buflen ? 0 : -EREMOTEIO; |
262 | } | 269 | } |
263 | 270 | ||
264 | /* actual bus specific access functions, make sure prototype are/will be equal to pci */ | 271 | /* actual bus specific access functions, |
265 | static flexcop_ibi_value flexcop_usb_read_ibi_reg(struct flexcop_device *fc, flexcop_ibi_register reg) | 272 | make sure prototype are/will be equal to pci */ |
273 | static flexcop_ibi_value flexcop_usb_read_ibi_reg(struct flexcop_device *fc, | ||
274 | flexcop_ibi_register reg) | ||
266 | { | 275 | { |
267 | flexcop_ibi_value val; | 276 | flexcop_ibi_value val; |
268 | val.raw = 0; | 277 | val.raw = 0; |
269 | flexcop_usb_readwrite_dw(fc,reg, &val.raw, 1); | 278 | flexcop_usb_readwrite_dw(fc, reg, &val.raw, 1); |
270 | return val; | 279 | return val; |
271 | } | 280 | } |
272 | 281 | ||
273 | static int flexcop_usb_write_ibi_reg(struct flexcop_device *fc, flexcop_ibi_register reg, flexcop_ibi_value val) | 282 | static int flexcop_usb_write_ibi_reg(struct flexcop_device *fc, |
283 | flexcop_ibi_register reg, flexcop_ibi_value val) | ||
274 | { | 284 | { |
275 | return flexcop_usb_readwrite_dw(fc,reg, &val.raw, 0); | 285 | return flexcop_usb_readwrite_dw(fc, reg, &val.raw, 0); |
276 | } | 286 | } |
277 | 287 | ||
278 | static int flexcop_usb_i2c_request(struct flexcop_i2c_adapter *i2c, | 288 | static int flexcop_usb_i2c_request(struct flexcop_i2c_adapter *i2c, |
279 | flexcop_access_op_t op, u8 chipaddr, u8 addr, u8 *buf, u16 len) | 289 | flexcop_access_op_t op, u8 chipaddr, u8 addr, u8 *buf, u16 len) |
280 | { | 290 | { |
281 | if (op == FC_READ) | 291 | if (op == FC_READ) |
282 | return flexcop_usb_i2c_req(i2c, B2C2_USB_I2C_REQUEST, | 292 | return flexcop_usb_i2c_req(i2c, B2C2_USB_I2C_REQUEST, |
283 | USB_FUNC_I2C_READ, chipaddr, addr, buf, len); | 293 | USB_FUNC_I2C_READ, chipaddr, addr, buf, len); |
284 | else | 294 | else |
285 | return flexcop_usb_i2c_req(i2c, B2C2_USB_I2C_REQUEST, | 295 | return flexcop_usb_i2c_req(i2c, B2C2_USB_I2C_REQUEST, |
286 | USB_FUNC_I2C_WRITE, chipaddr, addr, buf, len); | 296 | USB_FUNC_I2C_WRITE, chipaddr, addr, buf, len); |
287 | } | 297 | } |
288 | 298 | ||
289 | static void flexcop_usb_process_frame(struct flexcop_usb *fc_usb, u8 *buffer, int buffer_length) | 299 | static void flexcop_usb_process_frame(struct flexcop_usb *fc_usb, |
300 | u8 *buffer, int buffer_length) | ||
290 | { | 301 | { |
291 | u8 *b; | 302 | u8 *b; |
292 | int l; | 303 | int l; |
293 | 304 | ||
294 | deb_ts("tmp_buffer_length=%d, buffer_length=%d\n", fc_usb->tmp_buffer_length, buffer_length); | 305 | deb_ts("tmp_buffer_length=%d, buffer_length=%d\n", |
306 | fc_usb->tmp_buffer_length, buffer_length); | ||
295 | 307 | ||
296 | if (fc_usb->tmp_buffer_length > 0) { | 308 | if (fc_usb->tmp_buffer_length > 0) { |
297 | memcpy(fc_usb->tmp_buffer+fc_usb->tmp_buffer_length, buffer, buffer_length); | 309 | memcpy(fc_usb->tmp_buffer+fc_usb->tmp_buffer_length, buffer, |
310 | buffer_length); | ||
298 | fc_usb->tmp_buffer_length += buffer_length; | 311 | fc_usb->tmp_buffer_length += buffer_length; |
299 | b = fc_usb->tmp_buffer; | 312 | b = fc_usb->tmp_buffer; |
300 | l = fc_usb->tmp_buffer_length; | 313 | l = fc_usb->tmp_buffer_length; |
@@ -304,23 +317,26 @@ static void flexcop_usb_process_frame(struct flexcop_usb *fc_usb, u8 *buffer, in | |||
304 | } | 317 | } |
305 | 318 | ||
306 | while (l >= 190) { | 319 | while (l >= 190) { |
307 | if (*b == 0xff) | 320 | if (*b == 0xff) { |
308 | switch (*(b+1) & 0x03) { | 321 | switch (*(b+1) & 0x03) { |
309 | case 0x01: /* media packet */ | 322 | case 0x01: /* media packet */ |
310 | if ( *(b+2) == 0x47 ) | 323 | if (*(b+2) == 0x47) |
311 | flexcop_pass_dmx_packets(fc_usb->fc_dev, b+2, 1); | 324 | flexcop_pass_dmx_packets( |
312 | else | 325 | fc_usb->fc_dev, b+2, 1); |
313 | deb_ts("not ts packet %02x %02x %02x %02x \n", *(b+2), *(b+3), *(b+4), *(b+5) ); | 326 | else |
314 | 327 | deb_ts( | |
315 | b += 190; | 328 | "not ts packet %02x %02x %02x %02x \n", |
316 | l -= 190; | 329 | *(b+2), *(b+3), |
330 | *(b+4), *(b+5)); | ||
331 | b += 190; | ||
332 | l -= 190; | ||
317 | break; | 333 | break; |
318 | default: | 334 | default: |
319 | deb_ts("wrong packet type\n"); | 335 | deb_ts("wrong packet type\n"); |
320 | l = 0; | 336 | l = 0; |
321 | break; | 337 | break; |
322 | } | 338 | } |
323 | else { | 339 | } else { |
324 | deb_ts("wrong header\n"); | 340 | deb_ts("wrong header\n"); |
325 | l = 0; | 341 | l = 0; |
326 | } | 342 | } |
@@ -337,23 +353,26 @@ static void flexcop_usb_urb_complete(struct urb *urb) | |||
337 | int i; | 353 | int i; |
338 | 354 | ||
339 | if (urb->actual_length > 0) | 355 | if (urb->actual_length > 0) |
340 | deb_ts("urb completed, bufsize: %d actlen; %d\n",urb->transfer_buffer_length, urb->actual_length); | 356 | deb_ts("urb completed, bufsize: %d actlen; %d\n", |
357 | urb->transfer_buffer_length, urb->actual_length); | ||
341 | 358 | ||
342 | for (i = 0; i < urb->number_of_packets; i++) { | 359 | for (i = 0; i < urb->number_of_packets; i++) { |
343 | if (urb->iso_frame_desc[i].status < 0) { | 360 | if (urb->iso_frame_desc[i].status < 0) { |
344 | err("iso frame descriptor %d has an error: %d\n",i,urb->iso_frame_desc[i].status); | 361 | err("iso frame descriptor %d has an error: %d\n", i, |
362 | urb->iso_frame_desc[i].status); | ||
345 | } else | 363 | } else |
346 | if (urb->iso_frame_desc[i].actual_length > 0) { | 364 | if (urb->iso_frame_desc[i].actual_length > 0) { |
347 | deb_ts("passed %d bytes to the demux\n",urb->iso_frame_desc[i].actual_length); | 365 | deb_ts("passed %d bytes to the demux\n", |
366 | urb->iso_frame_desc[i].actual_length); | ||
348 | 367 | ||
349 | flexcop_usb_process_frame(fc_usb, | 368 | flexcop_usb_process_frame(fc_usb, |
350 | urb->transfer_buffer + urb->iso_frame_desc[i].offset, | 369 | urb->transfer_buffer + |
370 | urb->iso_frame_desc[i].offset, | ||
351 | urb->iso_frame_desc[i].actual_length); | 371 | urb->iso_frame_desc[i].actual_length); |
352 | } | 372 | } |
353 | urb->iso_frame_desc[i].status = 0; | 373 | urb->iso_frame_desc[i].status = 0; |
354 | urb->iso_frame_desc[i].actual_length = 0; | 374 | urb->iso_frame_desc[i].actual_length = 0; |
355 | } | 375 | } |
356 | |||
357 | usb_submit_urb(urb,GFP_ATOMIC); | 376 | usb_submit_urb(urb,GFP_ATOMIC); |
358 | } | 377 | } |
359 | 378 | ||
@@ -374,35 +393,47 @@ static void flexcop_usb_transfer_exit(struct flexcop_usb *fc_usb) | |||
374 | } | 393 | } |
375 | 394 | ||
376 | if (fc_usb->iso_buffer != NULL) | 395 | if (fc_usb->iso_buffer != NULL) |
377 | pci_free_consistent(NULL,fc_usb->buffer_size, fc_usb->iso_buffer, fc_usb->dma_addr); | 396 | pci_free_consistent(NULL, |
397 | fc_usb->buffer_size, fc_usb->iso_buffer, | ||
398 | fc_usb->dma_addr); | ||
378 | } | 399 | } |
379 | 400 | ||
380 | static int flexcop_usb_transfer_init(struct flexcop_usb *fc_usb) | 401 | static int flexcop_usb_transfer_init(struct flexcop_usb *fc_usb) |
381 | { | 402 | { |
382 | u16 frame_size = le16_to_cpu(fc_usb->uintf->cur_altsetting->endpoint[0].desc.wMaxPacketSize); | 403 | u16 frame_size = le16_to_cpu( |
383 | int bufsize = B2C2_USB_NUM_ISO_URB * B2C2_USB_FRAMES_PER_ISO * frame_size,i,j,ret; | 404 | fc_usb->uintf->cur_altsetting->endpoint[0].desc.wMaxPacketSize); |
405 | int bufsize = B2C2_USB_NUM_ISO_URB * B2C2_USB_FRAMES_PER_ISO * | ||
406 | frame_size, i, j, ret; | ||
384 | int buffer_offset = 0; | 407 | int buffer_offset = 0; |
385 | 408 | ||
386 | deb_ts("creating %d iso-urbs with %d frames each of %d bytes size = %d.\n", | 409 | deb_ts("creating %d iso-urbs with %d frames " |
387 | B2C2_USB_NUM_ISO_URB, B2C2_USB_FRAMES_PER_ISO, frame_size,bufsize); | 410 | "each of %d bytes size = %d.\n", B2C2_USB_NUM_ISO_URB, |
411 | B2C2_USB_FRAMES_PER_ISO, frame_size, bufsize); | ||
388 | 412 | ||
389 | fc_usb->iso_buffer = pci_alloc_consistent(NULL,bufsize,&fc_usb->dma_addr); | 413 | fc_usb->iso_buffer = pci_alloc_consistent(NULL, |
414 | bufsize, &fc_usb->dma_addr); | ||
390 | if (fc_usb->iso_buffer == NULL) | 415 | if (fc_usb->iso_buffer == NULL) |
391 | return -ENOMEM; | 416 | return -ENOMEM; |
417 | |||
392 | memset(fc_usb->iso_buffer, 0, bufsize); | 418 | memset(fc_usb->iso_buffer, 0, bufsize); |
393 | fc_usb->buffer_size = bufsize; | 419 | fc_usb->buffer_size = bufsize; |
394 | 420 | ||
395 | /* creating iso urbs */ | 421 | /* creating iso urbs */ |
396 | for (i = 0; i < B2C2_USB_NUM_ISO_URB; i++) | 422 | for (i = 0; i < B2C2_USB_NUM_ISO_URB; i++) { |
397 | if (!(fc_usb->iso_urb[i] = usb_alloc_urb(B2C2_USB_FRAMES_PER_ISO,GFP_ATOMIC))) { | 423 | fc_usb->iso_urb[i] = usb_alloc_urb(B2C2_USB_FRAMES_PER_ISO, |
424 | GFP_ATOMIC); | ||
425 | if (fc_usb->iso_urb[i] == NULL) { | ||
398 | ret = -ENOMEM; | 426 | ret = -ENOMEM; |
399 | goto urb_error; | 427 | goto urb_error; |
400 | } | 428 | } |
429 | } | ||
430 | |||
401 | /* initialising and submitting iso urbs */ | 431 | /* initialising and submitting iso urbs */ |
402 | for (i = 0; i < B2C2_USB_NUM_ISO_URB; i++) { | 432 | for (i = 0; i < B2C2_USB_NUM_ISO_URB; i++) { |
403 | int frame_offset = 0; | 433 | int frame_offset = 0; |
404 | struct urb *urb = fc_usb->iso_urb[i]; | 434 | struct urb *urb = fc_usb->iso_urb[i]; |
405 | deb_ts("initializing and submitting urb no. %d (buf_offset: %d).\n",i,buffer_offset); | 435 | deb_ts("initializing and submitting urb no. %d " |
436 | "(buf_offset: %d).\n", i, buffer_offset); | ||
406 | 437 | ||
407 | urb->dev = fc_usb->udev; | 438 | urb->dev = fc_usb->udev; |
408 | urb->context = fc_usb; | 439 | urb->context = fc_usb; |
@@ -416,26 +447,26 @@ static int flexcop_usb_transfer_init(struct flexcop_usb *fc_usb) | |||
416 | 447 | ||
417 | buffer_offset += frame_size * B2C2_USB_FRAMES_PER_ISO; | 448 | buffer_offset += frame_size * B2C2_USB_FRAMES_PER_ISO; |
418 | for (j = 0; j < B2C2_USB_FRAMES_PER_ISO; j++) { | 449 | for (j = 0; j < B2C2_USB_FRAMES_PER_ISO; j++) { |
419 | deb_ts("urb no: %d, frame: %d, frame_offset: %d\n",i,j,frame_offset); | 450 | deb_ts("urb no: %d, frame: %d, frame_offset: %d\n", |
451 | i, j, frame_offset); | ||
420 | urb->iso_frame_desc[j].offset = frame_offset; | 452 | urb->iso_frame_desc[j].offset = frame_offset; |
421 | urb->iso_frame_desc[j].length = frame_size; | 453 | urb->iso_frame_desc[j].length = frame_size; |
422 | frame_offset += frame_size; | 454 | frame_offset += frame_size; |
423 | } | 455 | } |
424 | 456 | ||
425 | if ((ret = usb_submit_urb(fc_usb->iso_urb[i],GFP_ATOMIC))) { | 457 | if ((ret = usb_submit_urb(fc_usb->iso_urb[i],GFP_ATOMIC))) { |
426 | err("submitting urb %d failed with %d.",i,ret); | 458 | err("submitting urb %d failed with %d.", i, ret); |
427 | goto urb_error; | 459 | goto urb_error; |
428 | } | 460 | } |
429 | deb_ts("submitted urb no. %d.\n",i); | 461 | deb_ts("submitted urb no. %d.\n",i); |
430 | } | 462 | } |
431 | 463 | ||
432 | /* SRAM */ | 464 | /* SRAM */ |
433 | 465 | flexcop_sram_set_dest(fc_usb->fc_dev, FC_SRAM_DEST_MEDIA | | |
434 | flexcop_sram_set_dest(fc_usb->fc_dev,FC_SRAM_DEST_MEDIA | FC_SRAM_DEST_NET | | 466 | FC_SRAM_DEST_NET | FC_SRAM_DEST_CAO | FC_SRAM_DEST_CAI, |
435 | FC_SRAM_DEST_CAO | FC_SRAM_DEST_CAI, FC_SRAM_DEST_TARGET_WAN_USB); | 467 | FC_SRAM_DEST_TARGET_WAN_USB); |
436 | flexcop_wan_set_speed(fc_usb->fc_dev,FC_WAN_SPEED_8MBITS); | 468 | flexcop_wan_set_speed(fc_usb->fc_dev, FC_WAN_SPEED_8MBITS); |
437 | flexcop_sram_ctrl(fc_usb->fc_dev,1,1,1); | 469 | flexcop_sram_ctrl(fc_usb->fc_dev, 1, 1, 1); |
438 | |||
439 | return 0; | 470 | return 0; |
440 | 471 | ||
441 | urb_error: | 472 | urb_error: |
@@ -448,20 +479,20 @@ static int flexcop_usb_init(struct flexcop_usb *fc_usb) | |||
448 | /* use the alternate setting with the larges buffer */ | 479 | /* use the alternate setting with the larges buffer */ |
449 | usb_set_interface(fc_usb->udev,0,1); | 480 | usb_set_interface(fc_usb->udev,0,1); |
450 | switch (fc_usb->udev->speed) { | 481 | switch (fc_usb->udev->speed) { |
451 | case USB_SPEED_LOW: | 482 | case USB_SPEED_LOW: |
452 | err("cannot handle USB speed because it is to sLOW."); | 483 | err("cannot handle USB speed because it is too slow."); |
453 | return -ENODEV; | 484 | return -ENODEV; |
454 | break; | 485 | break; |
455 | case USB_SPEED_FULL: | 486 | case USB_SPEED_FULL: |
456 | info("running at FULL speed."); | 487 | info("running at FULL speed."); |
457 | break; | 488 | break; |
458 | case USB_SPEED_HIGH: | 489 | case USB_SPEED_HIGH: |
459 | info("running at HIGH speed."); | 490 | info("running at HIGH speed."); |
460 | break; | 491 | break; |
461 | case USB_SPEED_UNKNOWN: /* fall through */ | 492 | case USB_SPEED_UNKNOWN: /* fall through */ |
462 | default: | 493 | default: |
463 | err("cannot handle USB speed because it is unkown."); | 494 | err("cannot handle USB speed because it is unknown."); |
464 | return -ENODEV; | 495 | return -ENODEV; |
465 | } | 496 | } |
466 | usb_set_intfdata(fc_usb->uintf, fc_usb); | 497 | usb_set_intfdata(fc_usb->uintf, fc_usb); |
467 | return 0; | 498 | return 0; |
@@ -485,7 +516,7 @@ static int flexcop_usb_probe(struct usb_interface *intf, | |||
485 | return -ENOMEM; | 516 | return -ENOMEM; |
486 | } | 517 | } |
487 | 518 | ||
488 | /* general flexcop init */ | 519 | /* general flexcop init */ |
489 | fc_usb = fc->bus_specific; | 520 | fc_usb = fc->bus_specific; |
490 | fc_usb->fc_dev = fc; | 521 | fc_usb->fc_dev = fc; |
491 | 522 | ||
@@ -502,21 +533,21 @@ static int flexcop_usb_probe(struct usb_interface *intf, | |||
502 | fc->dev = &udev->dev; | 533 | fc->dev = &udev->dev; |
503 | fc->owner = THIS_MODULE; | 534 | fc->owner = THIS_MODULE; |
504 | 535 | ||
505 | /* bus specific part */ | 536 | /* bus specific part */ |
506 | fc_usb->udev = udev; | 537 | fc_usb->udev = udev; |
507 | fc_usb->uintf = intf; | 538 | fc_usb->uintf = intf; |
508 | if ((ret = flexcop_usb_init(fc_usb)) != 0) | 539 | if ((ret = flexcop_usb_init(fc_usb)) != 0) |
509 | goto err_kfree; | 540 | goto err_kfree; |
510 | 541 | ||
511 | /* init flexcop */ | 542 | /* init flexcop */ |
512 | if ((ret = flexcop_device_initialize(fc)) != 0) | 543 | if ((ret = flexcop_device_initialize(fc)) != 0) |
513 | goto err_usb_exit; | 544 | goto err_usb_exit; |
514 | 545 | ||
515 | /* xfer init */ | 546 | /* xfer init */ |
516 | if ((ret = flexcop_usb_transfer_init(fc_usb)) != 0) | 547 | if ((ret = flexcop_usb_transfer_init(fc_usb)) != 0) |
517 | goto err_fc_exit; | 548 | goto err_fc_exit; |
518 | 549 | ||
519 | info("%s successfully initialized and connected.",DRIVER_NAME); | 550 | info("%s successfully initialized and connected.", DRIVER_NAME); |
520 | return 0; | 551 | return 0; |
521 | 552 | ||
522 | err_fc_exit: | 553 | err_fc_exit: |
@@ -535,12 +566,12 @@ static void flexcop_usb_disconnect(struct usb_interface *intf) | |||
535 | flexcop_device_exit(fc_usb->fc_dev); | 566 | flexcop_device_exit(fc_usb->fc_dev); |
536 | flexcop_usb_exit(fc_usb); | 567 | flexcop_usb_exit(fc_usb); |
537 | flexcop_device_kfree(fc_usb->fc_dev); | 568 | flexcop_device_kfree(fc_usb->fc_dev); |
538 | info("%s successfully deinitialized and disconnected.",DRIVER_NAME); | 569 | info("%s successfully deinitialized and disconnected.", DRIVER_NAME); |
539 | } | 570 | } |
540 | 571 | ||
541 | static struct usb_device_id flexcop_usb_table [] = { | 572 | static struct usb_device_id flexcop_usb_table [] = { |
542 | { USB_DEVICE(0x0af7, 0x0101) }, | 573 | { USB_DEVICE(0x0af7, 0x0101) }, |
543 | { } | 574 | { } |
544 | }; | 575 | }; |
545 | MODULE_DEVICE_TABLE (usb, flexcop_usb_table); | 576 | MODULE_DEVICE_TABLE (usb, flexcop_usb_table); |
546 | 577 | ||
@@ -557,10 +588,9 @@ static int __init flexcop_usb_module_init(void) | |||
557 | { | 588 | { |
558 | int result; | 589 | int result; |
559 | if ((result = usb_register(&flexcop_usb_driver))) { | 590 | if ((result = usb_register(&flexcop_usb_driver))) { |
560 | err("usb_register failed. (%d)",result); | 591 | err("usb_register failed. (%d)", result); |
561 | return result; | 592 | return result; |
562 | } | 593 | } |
563 | |||
564 | return 0; | 594 | return 0; |
565 | } | 595 | } |
566 | 596 | ||