Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | * USB driver for Gigaset 307x directly or using M105 Data. |
| 3 | * |
Tilman Schmidt | 70440cf | 2006-04-10 22:55:14 -0700 | [diff] [blame] | 4 | * Copyright (c) 2001 by Stefan Eilers |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 5 | * and Hansjoerg Lipp <hjlipp@web.de>. |
| 6 | * |
| 7 | * This driver was derived from the USB skeleton driver by |
| 8 | * Greg Kroah-Hartman <greg@kroah.com> |
| 9 | * |
| 10 | * ===================================================================== |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * ===================================================================== |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include "gigaset.h" |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 19 | #include <linux/usb.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/moduleparam.h> |
| 22 | |
| 23 | /* Version Information */ |
Tilman Schmidt | 70440cf | 2006-04-10 22:55:14 -0700 | [diff] [blame] | 24 | #define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Stefan Eilers" |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 25 | #define DRIVER_DESC "USB Driver for Gigaset 307x using M105" |
| 26 | |
| 27 | /* Module parameters */ |
| 28 | |
| 29 | static int startmode = SM_ISDN; |
| 30 | static int cidmode = 1; |
| 31 | |
| 32 | module_param(startmode, int, S_IRUGO); |
| 33 | module_param(cidmode, int, S_IRUGO); |
| 34 | MODULE_PARM_DESC(startmode, "start in isdn4linux mode"); |
| 35 | MODULE_PARM_DESC(cidmode, "Call-ID mode"); |
| 36 | |
| 37 | #define GIGASET_MINORS 1 |
| 38 | #define GIGASET_MINOR 8 |
| 39 | #define GIGASET_MODULENAME "usb_gigaset" |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 40 | #define GIGASET_DEVNAME "ttyGU" |
| 41 | |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 42 | #define IF_WRITEBUF 2000 /* arbitrary limit */ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 43 | |
| 44 | /* Values for the Gigaset M105 Data */ |
| 45 | #define USB_M105_VENDOR_ID 0x0681 |
| 46 | #define USB_M105_PRODUCT_ID 0x0009 |
| 47 | |
| 48 | /* table of devices that work with this driver */ |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 49 | static const struct usb_device_id gigaset_table[] = { |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 50 | { USB_DEVICE(USB_M105_VENDOR_ID, USB_M105_PRODUCT_ID) }, |
| 51 | { } /* Terminating entry */ |
| 52 | }; |
| 53 | |
| 54 | MODULE_DEVICE_TABLE(usb, gigaset_table); |
| 55 | |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 56 | /* |
| 57 | * Control requests (empty fields: 00) |
| 58 | * |
| 59 | * RT|RQ|VALUE|INDEX|LEN |DATA |
| 60 | * In: |
| 61 | * C1 08 01 |
| 62 | * Get flags (1 byte). Bits: 0=dtr,1=rts,3-7:? |
| 63 | * C1 0F ll ll |
| 64 | * Get device information/status (llll: 0x200 and 0x40 seen). |
| 65 | * Real size: I only saw MIN(llll,0x64). |
| 66 | * Contents: seems to be always the same... |
| 67 | * offset 0x00: Length of this structure (0x64) (len: 1,2,3 bytes) |
| 68 | * offset 0x3c: String (16 bit chars): "MCCI USB Serial V2.0" |
| 69 | * rest: ? |
| 70 | * Out: |
| 71 | * 41 11 |
| 72 | * Initialize/reset device ? |
| 73 | * 41 00 xx 00 |
| 74 | * ? (xx=00 or 01; 01 on start, 00 on close) |
| 75 | * 41 07 vv mm |
| 76 | * Set/clear flags vv=value, mm=mask (see RQ 08) |
| 77 | * 41 12 xx |
| 78 | * Used before the following configuration requests are issued |
| 79 | * (with xx=0x0f). I've seen other values<0xf, though. |
| 80 | * 41 01 xx xx |
| 81 | * Set baud rate. xxxx=ceil(0x384000/rate)=trunc(0x383fff/rate)+1. |
| 82 | * 41 03 ps bb |
| 83 | * Set byte size and parity. p: 0x20=even,0x10=odd,0x00=no parity |
| 84 | * [ 0x30: m, 0x40: s ] |
| 85 | * [s: 0: 1 stop bit; 1: 1.5; 2: 2] |
| 86 | * bb: bits/byte (seen 7 and 8) |
| 87 | * 41 13 -- -- -- -- 10 00 ww 00 00 00 xx 00 00 00 yy 00 00 00 zz 00 00 00 |
| 88 | * ?? |
| 89 | * Initialization: 01, 40, 00, 00 |
| 90 | * Open device: 00 40, 00, 00 |
| 91 | * yy and zz seem to be equal, either 0x00 or 0x0a |
| 92 | * (ww,xx) pairs seen: (00,00), (00,40), (01,40), (09,80), (19,80) |
| 93 | * 41 19 -- -- -- -- 06 00 00 00 00 xx 11 13 |
| 94 | * Used after every "configuration sequence" (RQ 12, RQs 01/03/13). |
| 95 | * xx is usually 0x00 but was 0x7e before starting data transfer |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 96 | * in unimodem mode. So, this might be an array of characters that |
| 97 | * need special treatment ("commit all bufferd data"?), 11=^Q, 13=^S. |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 98 | * |
| 99 | * Unimodem mode: use "modprobe ppp_async flag_time=0" as the device _needs_ two |
| 100 | * flags per packet. |
| 101 | */ |
| 102 | |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 103 | /* functions called if a device of this driver is connected/disconnected */ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 104 | static int gigaset_probe(struct usb_interface *interface, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 105 | const struct usb_device_id *id); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 106 | static void gigaset_disconnect(struct usb_interface *interface); |
| 107 | |
Tilman Schmidt | 1ff0a52 | 2008-02-06 01:38:27 -0800 | [diff] [blame] | 108 | /* functions called before/after suspend */ |
| 109 | static int gigaset_suspend(struct usb_interface *intf, pm_message_t message); |
| 110 | static int gigaset_resume(struct usb_interface *intf); |
| 111 | static int gigaset_pre_reset(struct usb_interface *intf); |
| 112 | |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 113 | static struct gigaset_driver *driver; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 114 | |
| 115 | /* usb specific object needed to register this driver with the usb subsystem */ |
| 116 | static struct usb_driver gigaset_usb_driver = { |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 117 | .name = GIGASET_MODULENAME, |
| 118 | .probe = gigaset_probe, |
| 119 | .disconnect = gigaset_disconnect, |
| 120 | .id_table = gigaset_table, |
Tilman Schmidt | 1ff0a52 | 2008-02-06 01:38:27 -0800 | [diff] [blame] | 121 | .suspend = gigaset_suspend, |
| 122 | .resume = gigaset_resume, |
| 123 | .reset_resume = gigaset_resume, |
| 124 | .pre_reset = gigaset_pre_reset, |
| 125 | .post_reset = gigaset_resume, |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | struct usb_cardstate { |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 129 | struct usb_device *udev; /* usb device pointer */ |
| 130 | struct usb_interface *interface; /* interface for this device */ |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 131 | int busy; /* bulk output in progress */ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 132 | |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 133 | /* Output buffer */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 134 | unsigned char *bulk_out_buffer; |
| 135 | int bulk_out_size; |
| 136 | __u8 bulk_out_endpointAddr; |
| 137 | struct urb *bulk_out_urb; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 138 | |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 139 | /* Input buffer */ |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 140 | unsigned char *rcvbuf; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 141 | int rcvbuf_size; |
| 142 | struct urb *read_urb; |
| 143 | __u8 int_in_endpointAddr; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 144 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 145 | char bchars[6]; /* for request 0x19 */ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 146 | }; |
| 147 | |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 148 | static inline unsigned tiocm_to_gigaset(unsigned state) |
| 149 | { |
| 150 | return ((state & TIOCM_DTR) ? 1 : 0) | ((state & TIOCM_RTS) ? 2 : 0); |
| 151 | } |
| 152 | |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 153 | static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 154 | unsigned new_state) |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 155 | { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 156 | struct usb_device *udev = cs->hw.usb->udev; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 157 | unsigned mask, val; |
| 158 | int r; |
| 159 | |
| 160 | mask = tiocm_to_gigaset(old_state ^ new_state); |
| 161 | val = tiocm_to_gigaset(new_state); |
| 162 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 163 | gig_dbg(DEBUG_USBREQ, "set flags 0x%02x with mask 0x%02x", val, mask); |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 164 | r = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 7, 0x41, |
| 165 | (val & 0xff) | ((mask & 0xff) << 8), 0, |
| 166 | NULL, 0, 2000 /* timeout? */); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 167 | if (r < 0) |
| 168 | return r; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 169 | return 0; |
| 170 | } |
| 171 | |
Tilman Schmidt | b88bd95 | 2009-05-13 12:44:18 +0000 | [diff] [blame] | 172 | /* |
| 173 | * Set M105 configuration value |
| 174 | * using undocumented device commands reverse engineered from USB traces |
| 175 | * of the Siemens Windows driver |
| 176 | */ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 177 | static int set_value(struct cardstate *cs, u8 req, u16 val) |
| 178 | { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 179 | struct usb_device *udev = cs->hw.usb->udev; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 180 | int r, r2; |
| 181 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 182 | gig_dbg(DEBUG_USBREQ, "request %02x (%04x)", |
| 183 | (unsigned)req, (unsigned)val); |
| 184 | r = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x12, 0x41, |
| 185 | 0xf /*?*/, 0, NULL, 0, 2000 /*?*/); |
| 186 | /* no idea what this does */ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 187 | if (r < 0) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 188 | dev_err(&udev->dev, "error %d on request 0x12\n", -r); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 189 | return r; |
| 190 | } |
| 191 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 192 | r = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), req, 0x41, |
| 193 | val, 0, NULL, 0, 2000 /*?*/); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 194 | if (r < 0) |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 195 | dev_err(&udev->dev, "error %d on request 0x%02x\n", |
| 196 | -r, (unsigned)req); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 197 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 198 | r2 = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41, |
| 199 | 0, 0, cs->hw.usb->bchars, 6, 2000 /*?*/); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 200 | if (r2 < 0) |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 201 | dev_err(&udev->dev, "error %d on request 0x19\n", -r2); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 202 | |
| 203 | return r < 0 ? r : (r2 < 0 ? r2 : 0); |
| 204 | } |
| 205 | |
Tilman Schmidt | b88bd95 | 2009-05-13 12:44:18 +0000 | [diff] [blame] | 206 | /* |
| 207 | * set the baud rate on the internal serial adapter |
| 208 | * using the undocumented parameter setting command |
| 209 | */ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 210 | static int gigaset_baud_rate(struct cardstate *cs, unsigned cflag) |
| 211 | { |
| 212 | u16 val; |
| 213 | u32 rate; |
| 214 | |
| 215 | cflag &= CBAUD; |
| 216 | |
| 217 | switch (cflag) { |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 218 | case B300: rate = 300; break; |
| 219 | case B600: rate = 600; break; |
| 220 | case B1200: rate = 1200; break; |
| 221 | case B2400: rate = 2400; break; |
| 222 | case B4800: rate = 4800; break; |
| 223 | case B9600: rate = 9600; break; |
| 224 | case B19200: rate = 19200; break; |
| 225 | case B38400: rate = 38400; break; |
| 226 | case B57600: rate = 57600; break; |
| 227 | case B115200: rate = 115200; break; |
| 228 | default: |
| 229 | rate = 9600; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 230 | dev_err(cs->dev, "unsupported baudrate request 0x%x," |
| 231 | " using default of B9600\n", cflag); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | val = 0x383fff / rate + 1; |
| 235 | |
| 236 | return set_value(cs, 1, val); |
| 237 | } |
| 238 | |
Tilman Schmidt | b88bd95 | 2009-05-13 12:44:18 +0000 | [diff] [blame] | 239 | /* |
| 240 | * set the line format on the internal serial adapter |
| 241 | * using the undocumented parameter setting command |
| 242 | */ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 243 | static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag) |
| 244 | { |
| 245 | u16 val = 0; |
| 246 | |
| 247 | /* set the parity */ |
| 248 | if (cflag & PARENB) |
| 249 | val |= (cflag & PARODD) ? 0x10 : 0x20; |
| 250 | |
| 251 | /* set the number of data bits */ |
| 252 | switch (cflag & CSIZE) { |
| 253 | case CS5: |
| 254 | val |= 5 << 8; break; |
| 255 | case CS6: |
| 256 | val |= 6 << 8; break; |
| 257 | case CS7: |
| 258 | val |= 7 << 8; break; |
| 259 | case CS8: |
| 260 | val |= 8 << 8; break; |
| 261 | default: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 262 | dev_err(cs->dev, "CSIZE was not CS5-CS8, using default of 8\n"); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 263 | val |= 8 << 8; |
| 264 | break; |
| 265 | } |
| 266 | |
| 267 | /* set the number of stop bits */ |
| 268 | if (cflag & CSTOPB) { |
| 269 | if ((cflag & CSIZE) == CS5) |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 270 | val |= 1; /* 1.5 stop bits */ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 271 | else |
| 272 | val |= 2; /* 2 stop bits */ |
| 273 | } |
| 274 | |
| 275 | return set_value(cs, 3, val); |
| 276 | } |
| 277 | |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 278 | |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 279 | /*============================================================================*/ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 280 | static int gigaset_init_bchannel(struct bc_state *bcs) |
| 281 | { |
| 282 | /* nothing to do for M10x */ |
| 283 | gigaset_bchannel_up(bcs); |
| 284 | return 0; |
| 285 | } |
| 286 | |
| 287 | static int gigaset_close_bchannel(struct bc_state *bcs) |
| 288 | { |
| 289 | /* nothing to do for M10x */ |
| 290 | gigaset_bchannel_down(bcs); |
| 291 | return 0; |
| 292 | } |
| 293 | |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 294 | static int write_modem(struct cardstate *cs); |
| 295 | static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb); |
| 296 | |
| 297 | |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 298 | /* Write tasklet handler: Continue sending current skb, or send command, or |
| 299 | * start sending an skb from the send queue. |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 300 | */ |
| 301 | static void gigaset_modem_fill(unsigned long data) |
| 302 | { |
| 303 | struct cardstate *cs = (struct cardstate *) data; |
| 304 | struct bc_state *bcs = &cs->bcs[0]; /* only one channel */ |
| 305 | struct cmdbuf_t *cb; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 306 | int again; |
| 307 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 308 | gig_dbg(DEBUG_OUTPUT, "modem_fill"); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 309 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 310 | if (cs->hw.usb->busy) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 311 | gig_dbg(DEBUG_OUTPUT, "modem_fill: busy"); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 312 | return; |
| 313 | } |
| 314 | |
| 315 | do { |
| 316 | again = 0; |
| 317 | if (!bcs->tx_skb) { /* no skb is being sent */ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 318 | cb = cs->cmdbuf; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 319 | if (cb) { /* commands to send? */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 320 | gig_dbg(DEBUG_OUTPUT, "modem_fill: cb"); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 321 | if (send_cb(cs, cb) < 0) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 322 | gig_dbg(DEBUG_OUTPUT, |
| 323 | "modem_fill: send_cb failed"); |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 324 | again = 1; /* no callback will be |
| 325 | called! */ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 326 | } |
| 327 | } else { /* skbs to send? */ |
| 328 | bcs->tx_skb = skb_dequeue(&bcs->squeue); |
| 329 | if (bcs->tx_skb) |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 330 | gig_dbg(DEBUG_INTR, |
| 331 | "Dequeued skb (Adr: %lx)!", |
| 332 | (unsigned long) bcs->tx_skb); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | |
| 336 | if (bcs->tx_skb) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 337 | gig_dbg(DEBUG_OUTPUT, "modem_fill: tx_skb"); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 338 | if (write_modem(cs) < 0) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 339 | gig_dbg(DEBUG_OUTPUT, |
| 340 | "modem_fill: write_modem failed"); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 341 | again = 1; /* no callback will be called! */ |
| 342 | } |
| 343 | } |
| 344 | } while (again); |
| 345 | } |
| 346 | |
Tilman Schmidt | b88bd95 | 2009-05-13 12:44:18 +0000 | [diff] [blame] | 347 | /* |
| 348 | * Interrupt Input URB completion routine |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 349 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 350 | static void gigaset_read_int_callback(struct urb *urb) |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 351 | { |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 352 | struct cardstate *cs = urb->context; |
| 353 | struct inbuf_t *inbuf = cs->inbuf; |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 354 | int status = urb->status; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 355 | int r; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 356 | unsigned numbytes; |
| 357 | unsigned char *src; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 358 | unsigned long flags; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 359 | |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 360 | if (!status) { |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 361 | numbytes = urb->actual_length; |
| 362 | |
| 363 | if (numbytes) { |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 364 | src = cs->hw.usb->rcvbuf; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 365 | if (unlikely(*src)) |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 366 | dev_warn(cs->dev, |
| 367 | "%s: There was no leading 0, but 0x%02x!\n", |
| 368 | __func__, (unsigned) *src); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 369 | ++src; /* skip leading 0x00 */ |
| 370 | --numbytes; |
| 371 | if (gigaset_fill_inbuf(inbuf, src, numbytes)) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 372 | gig_dbg(DEBUG_INTR, "%s-->BH", __func__); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 373 | gigaset_schedule_event(inbuf->cs); |
| 374 | } |
| 375 | } else |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 376 | gig_dbg(DEBUG_INTR, "Received zero block length"); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 377 | } else { |
| 378 | /* The urb might have been killed. */ |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 379 | gig_dbg(DEBUG_ANY, "%s - nonzero status received: %d", |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 380 | __func__, status); |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 381 | if (status == -ENOENT || status == -ESHUTDOWN) |
| 382 | /* killed or endpoint shutdown: don't resubmit */ |
| 383 | return; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 384 | } |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 385 | |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 386 | /* resubmit URB */ |
| 387 | spin_lock_irqsave(&cs->lock, flags); |
| 388 | if (!cs->connected) { |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 389 | spin_unlock_irqrestore(&cs->lock, flags); |
Tilman Schmidt | c8770dc | 2008-12-26 01:21:29 -0800 | [diff] [blame] | 390 | pr_err("%s: disconnected\n", __func__); |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 391 | return; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 392 | } |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 393 | r = usb_submit_urb(urb, GFP_ATOMIC); |
| 394 | spin_unlock_irqrestore(&cs->lock, flags); |
| 395 | if (r) |
| 396 | dev_err(cs->dev, "error %d resubmitting URB\n", -r); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 400 | /* This callback routine is called when data was transmitted to the device. */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 401 | static void gigaset_write_bulk_callback(struct urb *urb) |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 402 | { |
Tilman Schmidt | d48c778 | 2006-04-10 22:55:08 -0700 | [diff] [blame] | 403 | struct cardstate *cs = urb->context; |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 404 | int status = urb->status; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 405 | unsigned long flags; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 406 | |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 407 | switch (status) { |
| 408 | case 0: /* normal completion */ |
| 409 | break; |
| 410 | case -ENOENT: /* killed */ |
| 411 | gig_dbg(DEBUG_ANY, "%s: killed", __func__); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 412 | cs->hw.usb->busy = 0; |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 413 | return; |
| 414 | default: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 415 | dev_err(cs->dev, "bulk transfer failed (status %d)\n", |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 416 | -status); |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 417 | /* That's all we can do. Communication problems |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 418 | are handled by timeouts or network protocols. */ |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 419 | } |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 420 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 421 | spin_lock_irqsave(&cs->lock, flags); |
| 422 | if (!cs->connected) { |
Tilman Schmidt | c8770dc | 2008-12-26 01:21:29 -0800 | [diff] [blame] | 423 | pr_err("%s: disconnected\n", __func__); |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 424 | } else { |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 425 | cs->hw.usb->busy = 0; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 426 | tasklet_schedule(&cs->write_tasklet); |
| 427 | } |
| 428 | spin_unlock_irqrestore(&cs->lock, flags); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb) |
| 432 | { |
| 433 | struct cmdbuf_t *tcb; |
| 434 | unsigned long flags; |
| 435 | int count; |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 436 | int status = -ENOENT; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 437 | struct usb_cardstate *ucs = cs->hw.usb; |
| 438 | |
| 439 | do { |
| 440 | if (!cb->len) { |
| 441 | tcb = cb; |
| 442 | |
| 443 | spin_lock_irqsave(&cs->cmdlock, flags); |
| 444 | cs->cmdbytes -= cs->curlen; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 445 | gig_dbg(DEBUG_OUTPUT, "send_cb: sent %u bytes, %u left", |
| 446 | cs->curlen, cs->cmdbytes); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 447 | cs->cmdbuf = cb = cb->next; |
| 448 | if (cb) { |
| 449 | cb->prev = NULL; |
| 450 | cs->curlen = cb->len; |
| 451 | } else { |
| 452 | cs->lastcmdbuf = NULL; |
| 453 | cs->curlen = 0; |
| 454 | } |
| 455 | spin_unlock_irqrestore(&cs->cmdlock, flags); |
| 456 | |
| 457 | if (tcb->wake_tasklet) |
| 458 | tasklet_schedule(tcb->wake_tasklet); |
| 459 | kfree(tcb); |
| 460 | } |
| 461 | if (cb) { |
| 462 | count = min(cb->len, ucs->bulk_out_size); |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 463 | gig_dbg(DEBUG_OUTPUT, "send_cb: send %d bytes", count); |
| 464 | |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 465 | usb_fill_bulk_urb(ucs->bulk_out_urb, ucs->udev, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 466 | usb_sndbulkpipe(ucs->udev, |
| 467 | ucs->bulk_out_endpointAddr & 0x0f), |
| 468 | cb->buf + cb->offset, count, |
| 469 | gigaset_write_bulk_callback, cs); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 470 | |
| 471 | cb->offset += count; |
| 472 | cb->len -= count; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 473 | ucs->busy = 1; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 474 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 475 | spin_lock_irqsave(&cs->lock, flags); |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 476 | status = cs->connected ? |
| 477 | usb_submit_urb(ucs->bulk_out_urb, GFP_ATOMIC) : |
| 478 | -ENODEV; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 479 | spin_unlock_irqrestore(&cs->lock, flags); |
| 480 | |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 481 | if (status) { |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 482 | ucs->busy = 0; |
Tilman Schmidt | 5002779 | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 483 | dev_err(cs->dev, |
| 484 | "could not submit urb (error %d)\n", |
| 485 | -status); |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 486 | cb->len = 0; /* skip urb => remove cb+wakeup |
| 487 | in next loop cycle */ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 488 | } |
| 489 | } |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 490 | } while (cb && status); /* next command on error */ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 491 | |
| 492 | return status; |
| 493 | } |
| 494 | |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 495 | /* Send command to device. */ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 496 | static int gigaset_write_cmd(struct cardstate *cs, const unsigned char *buf, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 497 | int len, struct tasklet_struct *wake_tasklet) |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 498 | { |
| 499 | struct cmdbuf_t *cb; |
| 500 | unsigned long flags; |
| 501 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 502 | gigaset_dbg_buffer(cs->mstate != MS_LOCKED ? |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 503 | DEBUG_TRANSCMD : DEBUG_LOCKCMD, |
Tilman Schmidt | 0137150 | 2006-04-10 22:55:11 -0700 | [diff] [blame] | 504 | "CMD Transmit", len, buf); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 505 | |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 506 | if (len <= 0) |
| 507 | return 0; |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 508 | cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC); |
| 509 | if (!cb) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 510 | dev_err(cs->dev, "%s: out of memory\n", __func__); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 511 | return -ENOMEM; |
| 512 | } |
| 513 | |
| 514 | memcpy(cb->buf, buf, len); |
| 515 | cb->len = len; |
| 516 | cb->offset = 0; |
| 517 | cb->next = NULL; |
| 518 | cb->wake_tasklet = wake_tasklet; |
| 519 | |
| 520 | spin_lock_irqsave(&cs->cmdlock, flags); |
| 521 | cb->prev = cs->lastcmdbuf; |
| 522 | if (cs->lastcmdbuf) |
| 523 | cs->lastcmdbuf->next = cb; |
| 524 | else { |
| 525 | cs->cmdbuf = cb; |
| 526 | cs->curlen = len; |
| 527 | } |
| 528 | cs->cmdbytes += len; |
| 529 | cs->lastcmdbuf = cb; |
| 530 | spin_unlock_irqrestore(&cs->cmdlock, flags); |
| 531 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 532 | spin_lock_irqsave(&cs->lock, flags); |
| 533 | if (cs->connected) |
| 534 | tasklet_schedule(&cs->write_tasklet); |
| 535 | spin_unlock_irqrestore(&cs->lock, flags); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 536 | return len; |
| 537 | } |
| 538 | |
| 539 | static int gigaset_write_room(struct cardstate *cs) |
| 540 | { |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 541 | unsigned bytes; |
| 542 | |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 543 | bytes = cs->cmdbytes; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 544 | return bytes < IF_WRITEBUF ? IF_WRITEBUF - bytes : 0; |
| 545 | } |
| 546 | |
| 547 | static int gigaset_chars_in_buffer(struct cardstate *cs) |
| 548 | { |
| 549 | return cs->cmdbytes; |
| 550 | } |
| 551 | |
Tilman Schmidt | b88bd95 | 2009-05-13 12:44:18 +0000 | [diff] [blame] | 552 | /* |
| 553 | * set the break characters on the internal serial adapter |
| 554 | * using undocumented device commands reverse engineered from USB traces |
| 555 | * of the Siemens Windows driver |
| 556 | */ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 557 | static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6]) |
| 558 | { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 559 | struct usb_device *udev = cs->hw.usb->udev; |
| 560 | |
Tilman Schmidt | 0137150 | 2006-04-10 22:55:11 -0700 | [diff] [blame] | 561 | gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 562 | memcpy(cs->hw.usb->bchars, buf, 6); |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 563 | return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41, |
| 564 | 0, 0, &buf, 6, 2000); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | static int gigaset_freebcshw(struct bc_state *bcs) |
| 568 | { |
Tilman Schmidt | 21d3649 | 2007-05-08 20:27:03 -0700 | [diff] [blame] | 569 | /* unused */ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 570 | return 1; |
| 571 | } |
| 572 | |
| 573 | /* Initialize the b-channel structure */ |
| 574 | static int gigaset_initbcshw(struct bc_state *bcs) |
| 575 | { |
Tilman Schmidt | 21d3649 | 2007-05-08 20:27:03 -0700 | [diff] [blame] | 576 | /* unused */ |
| 577 | bcs->hw.usb = NULL; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 578 | return 1; |
| 579 | } |
| 580 | |
| 581 | static void gigaset_reinitbcshw(struct bc_state *bcs) |
| 582 | { |
Tilman Schmidt | 21d3649 | 2007-05-08 20:27:03 -0700 | [diff] [blame] | 583 | /* nothing to do for M10x */ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | static void gigaset_freecshw(struct cardstate *cs) |
| 587 | { |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 588 | tasklet_kill(&cs->write_tasklet); |
| 589 | kfree(cs->hw.usb); |
| 590 | } |
| 591 | |
| 592 | static int gigaset_initcshw(struct cardstate *cs) |
| 593 | { |
| 594 | struct usb_cardstate *ucs; |
| 595 | |
| 596 | cs->hw.usb = ucs = |
| 597 | kmalloc(sizeof(struct usb_cardstate), GFP_KERNEL); |
Tilman Schmidt | c8770dc | 2008-12-26 01:21:29 -0800 | [diff] [blame] | 598 | if (!ucs) { |
| 599 | pr_err("out of memory\n"); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 600 | return 0; |
Tilman Schmidt | c8770dc | 2008-12-26 01:21:29 -0800 | [diff] [blame] | 601 | } |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 602 | |
| 603 | ucs->bchars[0] = 0; |
| 604 | ucs->bchars[1] = 0; |
| 605 | ucs->bchars[2] = 0; |
| 606 | ucs->bchars[3] = 0; |
| 607 | ucs->bchars[4] = 0x11; |
| 608 | ucs->bchars[5] = 0x13; |
| 609 | ucs->bulk_out_buffer = NULL; |
| 610 | ucs->bulk_out_urb = NULL; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 611 | ucs->read_urb = NULL; |
| 612 | tasklet_init(&cs->write_tasklet, |
Joe Perches | 5452fee | 2009-11-19 09:55:53 +0000 | [diff] [blame] | 613 | gigaset_modem_fill, (unsigned long) cs); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 614 | |
| 615 | return 1; |
| 616 | } |
| 617 | |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 618 | /* Send data from current skb to the device. */ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 619 | static int write_modem(struct cardstate *cs) |
| 620 | { |
Tilman Schmidt | d48c778 | 2006-04-10 22:55:08 -0700 | [diff] [blame] | 621 | int ret = 0; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 622 | int count; |
| 623 | struct bc_state *bcs = &cs->bcs[0]; /* only one channel */ |
| 624 | struct usb_cardstate *ucs = cs->hw.usb; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 625 | unsigned long flags; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 626 | |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 627 | gig_dbg(DEBUG_OUTPUT, "len: %d...", bcs->tx_skb->len); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 628 | |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 629 | if (!bcs->tx_skb->len) { |
| 630 | dev_kfree_skb_any(bcs->tx_skb); |
| 631 | bcs->tx_skb = NULL; |
| 632 | return -EINVAL; |
| 633 | } |
| 634 | |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 635 | /* Copy data to bulk out buffer and transmit data */ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 636 | count = min(bcs->tx_skb->len, (unsigned) ucs->bulk_out_size); |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 637 | skb_copy_from_linear_data(bcs->tx_skb, ucs->bulk_out_buffer, count); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 638 | skb_pull(bcs->tx_skb, count); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 639 | ucs->busy = 1; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 640 | gig_dbg(DEBUG_OUTPUT, "write_modem: send %d bytes", count); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 641 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 642 | spin_lock_irqsave(&cs->lock, flags); |
| 643 | if (cs->connected) { |
| 644 | usb_fill_bulk_urb(ucs->bulk_out_urb, ucs->udev, |
| 645 | usb_sndbulkpipe(ucs->udev, |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 646 | ucs->bulk_out_endpointAddr & |
| 647 | 0x0f), |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 648 | ucs->bulk_out_buffer, count, |
| 649 | gigaset_write_bulk_callback, cs); |
Christoph Lameter | 54e6ecb | 2006-12-06 20:33:16 -0800 | [diff] [blame] | 650 | ret = usb_submit_urb(ucs->bulk_out_urb, GFP_ATOMIC); |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 651 | } else { |
| 652 | ret = -ENODEV; |
| 653 | } |
| 654 | spin_unlock_irqrestore(&cs->lock, flags); |
| 655 | |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 656 | if (ret) { |
Tilman Schmidt | 5002779 | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 657 | dev_err(cs->dev, "could not submit urb (error %d)\n", -ret); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 658 | ucs->busy = 0; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 659 | } |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 660 | |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 661 | if (!bcs->tx_skb->len) { |
| 662 | /* skb sent completely */ |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 663 | gigaset_skb_sent(bcs, bcs->tx_skb); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 664 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 665 | gig_dbg(DEBUG_INTR, "kfree skb (Adr: %lx)!", |
| 666 | (unsigned long) bcs->tx_skb); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 667 | dev_kfree_skb_any(bcs->tx_skb); |
| 668 | bcs->tx_skb = NULL; |
| 669 | } |
| 670 | |
| 671 | return ret; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | static int gigaset_probe(struct usb_interface *interface, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 675 | const struct usb_device_id *id) |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 676 | { |
| 677 | int retval; |
| 678 | struct usb_device *udev = interface_to_usbdev(interface); |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 679 | struct usb_host_interface *hostif = interface->cur_altsetting; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 680 | struct cardstate *cs = NULL; |
| 681 | struct usb_cardstate *ucs = NULL; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 682 | struct usb_endpoint_descriptor *endpoint; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 683 | int buffer_size; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 684 | |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 685 | gig_dbg(DEBUG_ANY, "%s: Check if device matches ...", __func__); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 686 | |
| 687 | /* See if the device offered us matches what we can accept */ |
Alexey Dobriyan | bfe2e93 | 2006-05-15 09:44:35 -0700 | [diff] [blame] | 688 | if ((le16_to_cpu(udev->descriptor.idVendor) != USB_M105_VENDOR_ID) || |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 689 | (le16_to_cpu(udev->descriptor.idProduct) != USB_M105_PRODUCT_ID)) { |
| 690 | gig_dbg(DEBUG_ANY, "device ID (0x%x, 0x%x) not for me - skip", |
| 691 | le16_to_cpu(udev->descriptor.idVendor), |
| 692 | le16_to_cpu(udev->descriptor.idProduct)); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 693 | return -ENODEV; |
| 694 | } |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 695 | if (hostif->desc.bInterfaceNumber != 0) { |
| 696 | gig_dbg(DEBUG_ANY, "interface %d not for me - skip", |
| 697 | hostif->desc.bInterfaceNumber); |
| 698 | return -ENODEV; |
| 699 | } |
| 700 | if (hostif->desc.bAlternateSetting != 0) { |
| 701 | dev_notice(&udev->dev, "unsupported altsetting %d - skip", |
| 702 | hostif->desc.bAlternateSetting); |
| 703 | return -ENODEV; |
| 704 | } |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 705 | if (hostif->desc.bInterfaceClass != 255) { |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 706 | dev_notice(&udev->dev, "unsupported interface class %d - skip", |
| 707 | hostif->desc.bInterfaceClass); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 708 | return -ENODEV; |
| 709 | } |
| 710 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 711 | dev_info(&udev->dev, "%s: Device matched ... !\n", __func__); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 712 | |
Tilman Schmidt | e468c04 | 2008-02-06 01:38:29 -0800 | [diff] [blame] | 713 | /* allocate memory for our device state and intialize it */ |
| 714 | cs = gigaset_initcs(driver, 1, 1, 0, cidmode, GIGASET_MODULENAME); |
| 715 | if (!cs) |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 716 | return -ENODEV; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 717 | ucs = cs->hw.usb; |
| 718 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 719 | /* save off device structure ptrs for later use */ |
| 720 | usb_get_dev(udev); |
| 721 | ucs->udev = udev; |
| 722 | ucs->interface = interface; |
Tilman Schmidt | b1d4746 | 2006-04-10 22:55:07 -0700 | [diff] [blame] | 723 | cs->dev = &interface->dev; |
| 724 | |
| 725 | /* save address of controller structure */ |
Tilman Schmidt | b88bd95 | 2009-05-13 12:44:18 +0000 | [diff] [blame] | 726 | usb_set_intfdata(interface, cs); |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 727 | |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 728 | endpoint = &hostif->endpoint[0].desc; |
| 729 | |
| 730 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); |
| 731 | ucs->bulk_out_size = buffer_size; |
| 732 | ucs->bulk_out_endpointAddr = endpoint->bEndpointAddress; |
| 733 | ucs->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL); |
| 734 | if (!ucs->bulk_out_buffer) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 735 | dev_err(cs->dev, "Couldn't allocate bulk_out_buffer\n"); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 736 | retval = -ENOMEM; |
| 737 | goto error; |
| 738 | } |
| 739 | |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 740 | ucs->bulk_out_urb = usb_alloc_urb(0, GFP_KERNEL); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 741 | if (!ucs->bulk_out_urb) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 742 | dev_err(cs->dev, "Couldn't allocate bulk_out_urb\n"); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 743 | retval = -ENOMEM; |
| 744 | goto error; |
| 745 | } |
| 746 | |
| 747 | endpoint = &hostif->endpoint[1].desc; |
| 748 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 749 | ucs->busy = 0; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 750 | |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 751 | ucs->read_urb = usb_alloc_urb(0, GFP_KERNEL); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 752 | if (!ucs->read_urb) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 753 | dev_err(cs->dev, "No free urbs available\n"); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 754 | retval = -ENOMEM; |
| 755 | goto error; |
| 756 | } |
| 757 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); |
| 758 | ucs->rcvbuf_size = buffer_size; |
| 759 | ucs->int_in_endpointAddr = endpoint->bEndpointAddress; |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 760 | ucs->rcvbuf = kmalloc(buffer_size, GFP_KERNEL); |
| 761 | if (!ucs->rcvbuf) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 762 | dev_err(cs->dev, "Couldn't allocate rcvbuf\n"); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 763 | retval = -ENOMEM; |
| 764 | goto error; |
| 765 | } |
| 766 | /* Fill the interrupt urb and send it to the core */ |
| 767 | usb_fill_int_urb(ucs->read_urb, udev, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 768 | usb_rcvintpipe(udev, |
| 769 | endpoint->bEndpointAddress & 0x0f), |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 770 | ucs->rcvbuf, buffer_size, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 771 | gigaset_read_int_callback, |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 772 | cs, endpoint->bInterval); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 773 | |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 774 | retval = usb_submit_urb(ucs->read_urb, GFP_KERNEL); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 775 | if (retval) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 776 | dev_err(cs->dev, "Could not submit URB (error %d)\n", -retval); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 777 | goto error; |
| 778 | } |
| 779 | |
| 780 | /* tell common part that the device is ready */ |
| 781 | if (startmode == SM_LOCKED) |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 782 | cs->mstate = MS_LOCKED; |
Tilman Schmidt | b1d4746 | 2006-04-10 22:55:07 -0700 | [diff] [blame] | 783 | |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 784 | if (!gigaset_start(cs)) { |
| 785 | tasklet_kill(&cs->write_tasklet); |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 786 | retval = -ENODEV; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 787 | goto error; |
| 788 | } |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 789 | return 0; |
| 790 | |
| 791 | error: |
Mariusz Kozlowski | ead54fc | 2006-11-08 15:34:17 +0100 | [diff] [blame] | 792 | usb_kill_urb(ucs->read_urb); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 793 | kfree(ucs->bulk_out_buffer); |
Mariusz Kozlowski | ead54fc | 2006-11-08 15:34:17 +0100 | [diff] [blame] | 794 | usb_free_urb(ucs->bulk_out_urb); |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 795 | kfree(ucs->rcvbuf); |
Mariusz Kozlowski | ead54fc | 2006-11-08 15:34:17 +0100 | [diff] [blame] | 796 | usb_free_urb(ucs->read_urb); |
Tilman Schmidt | b1d4746 | 2006-04-10 22:55:07 -0700 | [diff] [blame] | 797 | usb_set_intfdata(interface, NULL); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 798 | ucs->read_urb = ucs->bulk_out_urb = NULL; |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 799 | ucs->rcvbuf = ucs->bulk_out_buffer = NULL; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 800 | usb_put_dev(ucs->udev); |
| 801 | ucs->udev = NULL; |
| 802 | ucs->interface = NULL; |
Tilman Schmidt | e468c04 | 2008-02-06 01:38:29 -0800 | [diff] [blame] | 803 | gigaset_freecs(cs); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 804 | return retval; |
| 805 | } |
| 806 | |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 807 | static void gigaset_disconnect(struct usb_interface *interface) |
| 808 | { |
| 809 | struct cardstate *cs; |
| 810 | struct usb_cardstate *ucs; |
| 811 | |
| 812 | cs = usb_get_intfdata(interface); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 813 | ucs = cs->hw.usb; |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 814 | |
| 815 | dev_info(cs->dev, "disconnecting Gigaset USB adapter\n"); |
| 816 | |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 817 | usb_kill_urb(ucs->read_urb); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 818 | |
| 819 | gigaset_stop(cs); |
| 820 | |
Tilman Schmidt | b1d4746 | 2006-04-10 22:55:07 -0700 | [diff] [blame] | 821 | usb_set_intfdata(interface, NULL); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 822 | tasklet_kill(&cs->write_tasklet); |
| 823 | |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 824 | usb_kill_urb(ucs->bulk_out_urb); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 825 | |
| 826 | kfree(ucs->bulk_out_buffer); |
Mariusz Kozlowski | ead54fc | 2006-11-08 15:34:17 +0100 | [diff] [blame] | 827 | usb_free_urb(ucs->bulk_out_urb); |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 828 | kfree(ucs->rcvbuf); |
Mariusz Kozlowski | ead54fc | 2006-11-08 15:34:17 +0100 | [diff] [blame] | 829 | usb_free_urb(ucs->read_urb); |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 830 | ucs->read_urb = ucs->bulk_out_urb = NULL; |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 831 | ucs->rcvbuf = ucs->bulk_out_buffer = NULL; |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 832 | |
Tilman Schmidt | b1d4746 | 2006-04-10 22:55:07 -0700 | [diff] [blame] | 833 | usb_put_dev(ucs->udev); |
| 834 | ucs->interface = NULL; |
| 835 | ucs->udev = NULL; |
| 836 | cs->dev = NULL; |
Tilman Schmidt | e468c04 | 2008-02-06 01:38:29 -0800 | [diff] [blame] | 837 | gigaset_freecs(cs); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 838 | } |
| 839 | |
Tilman Schmidt | 1ff0a52 | 2008-02-06 01:38:27 -0800 | [diff] [blame] | 840 | /* gigaset_suspend |
| 841 | * This function is called before the USB connection is suspended or reset. |
| 842 | */ |
| 843 | static int gigaset_suspend(struct usb_interface *intf, pm_message_t message) |
| 844 | { |
| 845 | struct cardstate *cs = usb_get_intfdata(intf); |
| 846 | |
| 847 | /* stop activity */ |
| 848 | cs->connected = 0; /* prevent rescheduling */ |
| 849 | usb_kill_urb(cs->hw.usb->read_urb); |
| 850 | tasklet_kill(&cs->write_tasklet); |
| 851 | usb_kill_urb(cs->hw.usb->bulk_out_urb); |
| 852 | |
| 853 | gig_dbg(DEBUG_SUSPEND, "suspend complete"); |
| 854 | return 0; |
| 855 | } |
| 856 | |
| 857 | /* gigaset_resume |
| 858 | * This function is called after the USB connection has been resumed or reset. |
| 859 | */ |
| 860 | static int gigaset_resume(struct usb_interface *intf) |
| 861 | { |
| 862 | struct cardstate *cs = usb_get_intfdata(intf); |
| 863 | int rc; |
| 864 | |
| 865 | /* resubmit interrupt URB */ |
| 866 | cs->connected = 1; |
| 867 | rc = usb_submit_urb(cs->hw.usb->read_urb, GFP_KERNEL); |
| 868 | if (rc) { |
| 869 | dev_err(cs->dev, "Could not submit read URB (error %d)\n", -rc); |
| 870 | return rc; |
| 871 | } |
| 872 | |
| 873 | gig_dbg(DEBUG_SUSPEND, "resume complete"); |
| 874 | return 0; |
| 875 | } |
| 876 | |
| 877 | /* gigaset_pre_reset |
| 878 | * This function is called before the USB connection is reset. |
| 879 | */ |
| 880 | static int gigaset_pre_reset(struct usb_interface *intf) |
| 881 | { |
| 882 | /* same as suspend */ |
| 883 | return gigaset_suspend(intf, PMSG_ON); |
| 884 | } |
| 885 | |
Tilman Schmidt | 35dc845 | 2007-03-29 01:20:34 -0700 | [diff] [blame] | 886 | static const struct gigaset_ops ops = { |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 887 | gigaset_write_cmd, |
| 888 | gigaset_write_room, |
| 889 | gigaset_chars_in_buffer, |
| 890 | gigaset_brkchars, |
| 891 | gigaset_init_bchannel, |
| 892 | gigaset_close_bchannel, |
| 893 | gigaset_initbcshw, |
| 894 | gigaset_freebcshw, |
| 895 | gigaset_reinitbcshw, |
| 896 | gigaset_initcshw, |
| 897 | gigaset_freecshw, |
| 898 | gigaset_set_modem_ctrl, |
| 899 | gigaset_baud_rate, |
| 900 | gigaset_set_line_ctrl, |
| 901 | gigaset_m10x_send_skb, |
| 902 | gigaset_m10x_input, |
| 903 | }; |
| 904 | |
Tilman Schmidt | b88bd95 | 2009-05-13 12:44:18 +0000 | [diff] [blame] | 905 | /* |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 906 | * This function is called while kernel-module is loaded |
| 907 | */ |
| 908 | static int __init usb_gigaset_init(void) |
| 909 | { |
| 910 | int result; |
| 911 | |
| 912 | /* allocate memory for our driver state and intialize it */ |
Tilman Schmidt | 2032e2c | 2009-10-25 09:30:07 +0000 | [diff] [blame] | 913 | driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS, |
| 914 | GIGASET_MODULENAME, GIGASET_DEVNAME, |
| 915 | &ops, THIS_MODULE); |
| 916 | if (driver == NULL) |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 917 | goto error; |
| 918 | |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 919 | /* register this driver with the USB subsystem */ |
| 920 | result = usb_register(&gigaset_usb_driver); |
| 921 | if (result < 0) { |
Tilman Schmidt | c8770dc | 2008-12-26 01:21:29 -0800 | [diff] [blame] | 922 | pr_err("error %d registering USB driver\n", -result); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 923 | goto error; |
| 924 | } |
| 925 | |
Tilman Schmidt | c8770dc | 2008-12-26 01:21:29 -0800 | [diff] [blame] | 926 | pr_info(DRIVER_DESC "\n"); |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 927 | return 0; |
| 928 | |
Tilman Schmidt | e468c04 | 2008-02-06 01:38:29 -0800 | [diff] [blame] | 929 | error: |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 930 | if (driver) |
| 931 | gigaset_freedriver(driver); |
| 932 | driver = NULL; |
| 933 | return -1; |
| 934 | } |
| 935 | |
Tilman Schmidt | b88bd95 | 2009-05-13 12:44:18 +0000 | [diff] [blame] | 936 | /* |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 937 | * This function is called while unloading the kernel-module |
| 938 | */ |
| 939 | static void __exit usb_gigaset_exit(void) |
| 940 | { |
Tilman Schmidt | e468c04 | 2008-02-06 01:38:29 -0800 | [diff] [blame] | 941 | int i; |
| 942 | |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 943 | gigaset_blockdriver(driver); /* => probe will fail |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 944 | * => no gigaset_start any more |
| 945 | */ |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 946 | |
Tilman Schmidt | e468c04 | 2008-02-06 01:38:29 -0800 | [diff] [blame] | 947 | /* stop all connected devices */ |
| 948 | for (i = 0; i < driver->minors; i++) |
| 949 | gigaset_shutdown(driver->cs + i); |
| 950 | |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 951 | /* from now on, no isdn callback should be possible */ |
| 952 | |
| 953 | /* deregister this driver with the USB subsystem */ |
| 954 | usb_deregister(&gigaset_usb_driver); |
| 955 | /* this will call the disconnect-callback */ |
| 956 | /* from now on, no disconnect/probe callback should be running */ |
| 957 | |
Hansjoerg Lipp | 07dc1f9 | 2006-03-26 01:38:37 -0800 | [diff] [blame] | 958 | gigaset_freedriver(driver); |
| 959 | driver = NULL; |
| 960 | } |
| 961 | |
| 962 | |
| 963 | module_init(usb_gigaset_init); |
| 964 | module_exit(usb_gigaset_exit); |
| 965 | |
| 966 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 967 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 968 | |
| 969 | MODULE_LICENSE("GPL"); |