Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * speedtch.c - Alcatel SpeedTouch USB xDSL modem driver |
| 3 | * |
| 4 | * Copyright (C) 2001, Alcatel |
| 5 | * Copyright (C) 2003, Duncan Sands |
| 6 | * Copyright (C) 2004, David Woodhouse |
| 7 | * |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 8 | * Based on "modem_run.c", copyright (C) 2001, Benoit Papillault |
| 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the Free |
| 12 | * Software Foundation; either version 2 of the License, or (at your option) |
| 13 | * any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 18 | * more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License along with |
| 21 | * this program; if not, write to the Free Software Foundation, Inc., 59 |
| 22 | * Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 23 | * |
| 24 | ******************************************************************************/ |
| 25 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 26 | #include <asm/page.h> |
| 27 | #include <linux/device.h> |
| 28 | #include <linux/errno.h> |
| 29 | #include <linux/firmware.h> |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 30 | #include <linux/init.h> |
| 31 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/module.h> |
| 33 | #include <linux/moduleparam.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/slab.h> |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 35 | #include <linux/stat.h> |
| 36 | #include <linux/timer.h> |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 37 | #include <linux/types.h> |
David Brownell | 5f84813 | 2006-12-16 15:34:53 -0800 | [diff] [blame] | 38 | #include <linux/usb/ch9.h> |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 39 | #include <linux/workqueue.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 41 | #include "usbatm.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | #define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>" |
Duncan Sands | 9b0e54a | 2006-01-13 11:08:05 +0100 | [diff] [blame] | 44 | #define DRIVER_VERSION "1.10" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #define DRIVER_DESC "Alcatel SpeedTouch USB driver version " DRIVER_VERSION |
| 46 | |
| 47 | static const char speedtch_driver_name[] = "speedtch"; |
| 48 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 49 | #define CTRL_TIMEOUT 2000 /* milliseconds */ |
| 50 | #define DATA_TIMEOUT 2000 /* milliseconds */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 52 | #define OFFSET_7 0 /* size 1 */ |
| 53 | #define OFFSET_b 1 /* size 8 */ |
| 54 | #define OFFSET_d 9 /* size 4 */ |
| 55 | #define OFFSET_e 13 /* size 1 */ |
| 56 | #define OFFSET_f 14 /* size 1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 58 | #define SIZE_7 1 |
| 59 | #define SIZE_b 8 |
| 60 | #define SIZE_d 4 |
| 61 | #define SIZE_e 1 |
| 62 | #define SIZE_f 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 64 | #define MIN_POLL_DELAY 5000 /* milliseconds */ |
| 65 | #define MAX_POLL_DELAY 60000 /* milliseconds */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 67 | #define RESUBMIT_DELAY 1000 /* milliseconds */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 69 | #define DEFAULT_BULK_ALTSETTING 1 |
Duncan Sands | 67c752b | 2006-04-28 18:44:06 +0200 | [diff] [blame] | 70 | #define DEFAULT_ISOC_ALTSETTING 3 |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 71 | #define DEFAULT_DL_512_FIRST 0 |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 72 | #define DEFAULT_ENABLE_ISOC 0 |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 73 | #define DEFAULT_SW_BUFFERING 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 75 | static unsigned int altsetting = 0; /* zero means: use the default */ |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 76 | static int dl_512_first = DEFAULT_DL_512_FIRST; |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 77 | static int enable_isoc = DEFAULT_ENABLE_ISOC; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 78 | static int sw_buffering = DEFAULT_SW_BUFFERING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Duncan Sands | 6a4f1b4 | 2006-10-05 10:40:55 +0200 | [diff] [blame] | 80 | #define DEFAULT_B_MAX_DSL 8128 |
| 81 | #define DEFAULT_MODEM_MODE 11 |
| 82 | #define MODEM_OPTION_LENGTH 16 |
| 83 | static const unsigned char DEFAULT_MODEM_OPTION[MODEM_OPTION_LENGTH] = { |
| 84 | 0x10, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 85 | }; |
| 86 | |
| 87 | static unsigned int BMaxDSL = DEFAULT_B_MAX_DSL; |
| 88 | static unsigned char ModemMode = DEFAULT_MODEM_MODE; |
| 89 | static unsigned char ModemOption[MODEM_OPTION_LENGTH]; |
Al Viro | 64a6f95 | 2007-10-14 19:35:30 +0100 | [diff] [blame] | 90 | static unsigned int num_ModemOption; |
Duncan Sands | 6a4f1b4 | 2006-10-05 10:40:55 +0200 | [diff] [blame] | 91 | |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 92 | module_param(altsetting, uint, S_IRUGO | S_IWUSR); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 93 | MODULE_PARM_DESC(altsetting, |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 94 | "Alternative setting for data interface (bulk_default: " |
| 95 | __MODULE_STRING(DEFAULT_BULK_ALTSETTING) "; isoc_default: " |
| 96 | __MODULE_STRING(DEFAULT_ISOC_ALTSETTING) ")"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 98 | module_param(dl_512_first, bool, S_IRUGO | S_IWUSR); |
| 99 | MODULE_PARM_DESC(dl_512_first, |
| 100 | "Read 512 bytes before sending firmware (default: " |
| 101 | __MODULE_STRING(DEFAULT_DL_512_FIRST) ")"); |
| 102 | |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 103 | module_param(enable_isoc, bool, S_IRUGO | S_IWUSR); |
| 104 | MODULE_PARM_DESC(enable_isoc, |
| 105 | "Use isochronous transfers if available (default: " |
| 106 | __MODULE_STRING(DEFAULT_ENABLE_ISOC) ")"); |
| 107 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 108 | module_param(sw_buffering, bool, S_IRUGO | S_IWUSR); |
| 109 | MODULE_PARM_DESC(sw_buffering, |
| 110 | "Enable software buffering (default: " |
| 111 | __MODULE_STRING(DEFAULT_SW_BUFFERING) ")"); |
| 112 | |
Duncan Sands | 6a4f1b4 | 2006-10-05 10:40:55 +0200 | [diff] [blame] | 113 | module_param(BMaxDSL, uint, S_IRUGO | S_IWUSR); |
| 114 | MODULE_PARM_DESC(BMaxDSL, |
| 115 | "default: " __MODULE_STRING(DEFAULT_B_MAX_DSL)); |
| 116 | |
| 117 | module_param(ModemMode, byte, S_IRUGO | S_IWUSR); |
| 118 | MODULE_PARM_DESC(ModemMode, |
| 119 | "default: " __MODULE_STRING(DEFAULT_MODEM_MODE)); |
| 120 | |
| 121 | module_param_array(ModemOption, byte, &num_ModemOption, S_IRUGO); |
| 122 | MODULE_PARM_DESC(ModemOption, "default: 0x10,0x00,0x00,0x00,0x20"); |
| 123 | |
Duncan Sands | 6f74947 | 2006-01-13 10:52:38 +0100 | [diff] [blame] | 124 | #define INTERFACE_DATA 1 |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 125 | #define ENDPOINT_INT 0x81 |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 126 | #define ENDPOINT_BULK_DATA 0x07 |
| 127 | #define ENDPOINT_ISOC_DATA 0x07 |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 128 | #define ENDPOINT_FIRMWARE 0x05 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
| 130 | #define hex2int(c) ( (c >= '0') && (c <= '9') ? (c - '0') : ((c & 0xf) + 9) ) |
| 131 | |
Duncan Sands | 6a4f1b4 | 2006-10-05 10:40:55 +0200 | [diff] [blame] | 132 | struct speedtch_params { |
| 133 | unsigned int altsetting; |
| 134 | unsigned int BMaxDSL; |
| 135 | unsigned char ModemMode; |
| 136 | unsigned char ModemOption[MODEM_OPTION_LENGTH]; |
| 137 | }; |
| 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | struct speedtch_instance_data { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 140 | struct usbatm_data *usbatm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Duncan Sands | 6a4f1b4 | 2006-10-05 10:40:55 +0200 | [diff] [blame] | 142 | struct speedtch_params params; /* set in probe, constant afterwards */ |
Duncan Sands | 6f74947 | 2006-01-13 10:52:38 +0100 | [diff] [blame] | 143 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 144 | struct delayed_work status_checker; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 145 | |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 146 | unsigned char last_status; |
| 147 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 148 | int poll_delay; /* milliseconds */ |
| 149 | |
| 150 | struct timer_list resubmit_timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | struct urb *int_urb; |
| 152 | unsigned char int_data[16]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
Duncan Sands | 6a4f1b4 | 2006-10-05 10:40:55 +0200 | [diff] [blame] | 154 | unsigned char scratch_buffer[16]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | /*************** |
| 158 | ** firmware ** |
| 159 | ***************/ |
| 160 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 161 | static void speedtch_set_swbuff(struct speedtch_instance_data *instance, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 163 | struct usbatm_data *usbatm = instance->usbatm; |
| 164 | struct usb_device *usb_dev = usbatm->usb_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | int ret; |
| 166 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 167 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
| 168 | 0x32, 0x40, state ? 0x01 : 0x00, 0x00, NULL, 0, CTRL_TIMEOUT); |
| 169 | if (ret < 0) |
| 170 | usb_warn(usbatm, |
| 171 | "%sabling SW buffering: usb_control_msg returned %d\n", |
| 172 | state ? "En" : "Dis", ret); |
| 173 | else |
| 174 | dbg("speedtch_set_swbuff: %sbled SW buffering", state ? "En" : "Dis"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static void speedtch_test_sequence(struct speedtch_instance_data *instance) |
| 178 | { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 179 | struct usbatm_data *usbatm = instance->usbatm; |
| 180 | struct usb_device *usb_dev = usbatm->usb_dev; |
| 181 | unsigned char *buf = instance->scratch_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | int ret; |
| 183 | |
| 184 | /* URB 147 */ |
| 185 | buf[0] = 0x1c; |
| 186 | buf[1] = 0x50; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 187 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
| 188 | 0x01, 0x40, 0x0b, 0x00, buf, 2, CTRL_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | if (ret < 0) |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 190 | usb_warn(usbatm, "%s failed on URB147: %d\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
| 192 | /* URB 148 */ |
| 193 | buf[0] = 0x32; |
| 194 | buf[1] = 0x00; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 195 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
| 196 | 0x01, 0x40, 0x02, 0x00, buf, 2, CTRL_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | if (ret < 0) |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 198 | usb_warn(usbatm, "%s failed on URB148: %d\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | /* URB 149 */ |
| 201 | buf[0] = 0x01; |
| 202 | buf[1] = 0x00; |
| 203 | buf[2] = 0x01; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 204 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
| 205 | 0x01, 0x40, 0x03, 0x00, buf, 3, CTRL_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | if (ret < 0) |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 207 | usb_warn(usbatm, "%s failed on URB149: %d\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | /* URB 150 */ |
| 210 | buf[0] = 0x01; |
| 211 | buf[1] = 0x00; |
| 212 | buf[2] = 0x01; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 213 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
| 214 | 0x01, 0x40, 0x04, 0x00, buf, 3, CTRL_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | if (ret < 0) |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 216 | usb_warn(usbatm, "%s failed on URB150: %d\n", __func__, ret); |
Duncan Sands | 6a4f1b4 | 2006-10-05 10:40:55 +0200 | [diff] [blame] | 217 | |
| 218 | /* Extra initialisation in recent drivers - gives higher speeds */ |
| 219 | |
| 220 | /* URBext1 */ |
| 221 | buf[0] = instance->params.ModemMode; |
| 222 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
| 223 | 0x01, 0x40, 0x11, 0x00, buf, 1, CTRL_TIMEOUT); |
| 224 | if (ret < 0) |
| 225 | usb_warn(usbatm, "%s failed on URBext1: %d\n", __func__, ret); |
| 226 | |
| 227 | /* URBext2 */ |
| 228 | /* This seems to be the one which actually triggers the higher sync |
| 229 | rate -- it does require the new firmware too, although it works OK |
| 230 | with older firmware */ |
| 231 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
| 232 | 0x01, 0x40, 0x14, 0x00, |
| 233 | instance->params.ModemOption, |
| 234 | MODEM_OPTION_LENGTH, CTRL_TIMEOUT); |
| 235 | if (ret < 0) |
| 236 | usb_warn(usbatm, "%s failed on URBext2: %d\n", __func__, ret); |
| 237 | |
| 238 | /* URBext3 */ |
| 239 | buf[0] = instance->params.BMaxDSL & 0xff; |
| 240 | buf[1] = instance->params.BMaxDSL >> 8; |
| 241 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
| 242 | 0x01, 0x40, 0x12, 0x00, buf, 2, CTRL_TIMEOUT); |
| 243 | if (ret < 0) |
| 244 | usb_warn(usbatm, "%s failed on URBext3: %d\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 247 | static int speedtch_upload_firmware(struct speedtch_instance_data *instance, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | const struct firmware *fw1, |
| 249 | const struct firmware *fw2) |
| 250 | { |
| 251 | unsigned char *buffer; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 252 | struct usbatm_data *usbatm = instance->usbatm; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 253 | struct usb_device *usb_dev = usbatm->usb_dev; |
| 254 | int actual_length; |
| 255 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | int offset; |
| 257 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 258 | usb_dbg(usbatm, "%s entered\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
| 260 | if (!(buffer = (unsigned char *)__get_free_page(GFP_KERNEL))) { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 261 | ret = -ENOMEM; |
| 262 | usb_dbg(usbatm, "%s: no memory for buffer!\n", __func__); |
| 263 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Micah Gruber | 011db81 | 2007-09-05 13:49:58 +0800 | [diff] [blame] | 266 | if (!usb_ifnum_to_if(usb_dev, 2)) { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 267 | ret = -ENODEV; |
| 268 | usb_dbg(usbatm, "%s: interface not found!\n", __func__); |
| 269 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | /* URB 7 */ |
| 273 | if (dl_512_first) { /* some modems need a read before writing the firmware */ |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 274 | ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | buffer, 0x200, &actual_length, 2000); |
| 276 | |
| 277 | if (ret < 0 && ret != -ETIMEDOUT) |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 278 | usb_warn(usbatm, "%s: read BLOCK0 from modem failed (%d)!\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | else |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 280 | usb_dbg(usbatm, "%s: BLOCK0 downloaded (%d bytes)\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /* URB 8 : both leds are static green */ |
| 284 | for (offset = 0; offset < fw1->size; offset += PAGE_SIZE) { |
| 285 | int thislen = min_t(int, PAGE_SIZE, fw1->size - offset); |
| 286 | memcpy(buffer, fw1->data + offset, thislen); |
| 287 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 288 | ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, ENDPOINT_FIRMWARE), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | buffer, thislen, &actual_length, DATA_TIMEOUT); |
| 290 | |
| 291 | if (ret < 0) { |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 292 | usb_err(usbatm, "%s: write BLOCK1 to modem failed (%d)!\n", __func__, ret); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 293 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | } |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 295 | usb_dbg(usbatm, "%s: BLOCK1 uploaded (%zu bytes)\n", __func__, fw1->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | /* USB led blinking green, ADSL led off */ |
| 299 | |
| 300 | /* URB 11 */ |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 301 | ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | buffer, 0x200, &actual_length, DATA_TIMEOUT); |
| 303 | |
| 304 | if (ret < 0) { |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 305 | usb_err(usbatm, "%s: read BLOCK2 from modem failed (%d)!\n", __func__, ret); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 306 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | } |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 308 | usb_dbg(usbatm, "%s: BLOCK2 downloaded (%d bytes)\n", __func__, actual_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
| 310 | /* URBs 12 to 139 - USB led blinking green, ADSL led off */ |
| 311 | for (offset = 0; offset < fw2->size; offset += PAGE_SIZE) { |
| 312 | int thislen = min_t(int, PAGE_SIZE, fw2->size - offset); |
| 313 | memcpy(buffer, fw2->data + offset, thislen); |
| 314 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 315 | ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, ENDPOINT_FIRMWARE), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | buffer, thislen, &actual_length, DATA_TIMEOUT); |
| 317 | |
| 318 | if (ret < 0) { |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 319 | usb_err(usbatm, "%s: write BLOCK3 to modem failed (%d)!\n", __func__, ret); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 320 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } |
| 322 | } |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 323 | usb_dbg(usbatm, "%s: BLOCK3 uploaded (%zu bytes)\n", __func__, fw2->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
| 325 | /* USB led static green, ADSL led static red */ |
| 326 | |
| 327 | /* URB 142 */ |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 328 | ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | buffer, 0x200, &actual_length, DATA_TIMEOUT); |
| 330 | |
| 331 | if (ret < 0) { |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 332 | usb_err(usbatm, "%s: read BLOCK4 from modem failed (%d)!\n", __func__, ret); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 333 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | /* success */ |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 337 | usb_dbg(usbatm, "%s: BLOCK4 downloaded (%d bytes)\n", __func__, actual_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
| 339 | /* Delay to allow firmware to start up. We can do this here |
| 340 | because we're in our own kernel thread anyway. */ |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 341 | msleep_interruptible(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
Duncan Sands | 6a4f1b4 | 2006-10-05 10:40:55 +0200 | [diff] [blame] | 343 | if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, instance->params.altsetting)) < 0) { |
| 344 | usb_err(usbatm, "%s: setting interface to %d failed (%d)!\n", __func__, instance->params.altsetting, ret); |
Duncan Sands | 6f74947 | 2006-01-13 10:52:38 +0100 | [diff] [blame] | 345 | goto out_free; |
| 346 | } |
| 347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | /* Enable software buffering, if requested */ |
| 349 | if (sw_buffering) |
| 350 | speedtch_set_swbuff(instance, 1); |
| 351 | |
| 352 | /* Magic spell; don't ask us what this does */ |
| 353 | speedtch_test_sequence(instance); |
| 354 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 355 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 357 | out_free: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | free_page((unsigned long)buffer); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 359 | out: |
| 360 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 363 | static int speedtch_find_firmware(struct usbatm_data *usbatm, struct usb_interface *intf, |
| 364 | int phase, const struct firmware **fw_p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 366 | struct device *dev = &intf->dev; |
| 367 | const u16 bcdDevice = le16_to_cpu(interface_to_usbdev(intf)->descriptor.bcdDevice); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | const u8 major_revision = bcdDevice >> 8; |
| 369 | const u8 minor_revision = bcdDevice & 0xff; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 370 | char buf[24]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
| 372 | sprintf(buf, "speedtch-%d.bin.%x.%02x", phase, major_revision, minor_revision); |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 373 | usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 375 | if (request_firmware(fw_p, buf, dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | sprintf(buf, "speedtch-%d.bin.%x", phase, major_revision); |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 377 | usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 379 | if (request_firmware(fw_p, buf, dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | sprintf(buf, "speedtch-%d.bin", phase); |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 381 | usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 383 | if (request_firmware(fw_p, buf, dev)) { |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 384 | usb_err(usbatm, "%s: no stage %d firmware found!\n", __func__, phase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | return -ENOENT; |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 390 | usb_info(usbatm, "found stage %d firmware %s\n", phase, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
| 392 | return 0; |
| 393 | } |
| 394 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 395 | static int speedtch_heavy_init(struct usbatm_data *usbatm, struct usb_interface *intf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | { |
| 397 | const struct firmware *fw1, *fw2; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 398 | struct speedtch_instance_data *instance = usbatm->driver_data; |
| 399 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 401 | if ((ret = speedtch_find_firmware(usbatm, intf, 1, &fw1)) < 0) |
| 402 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 404 | if ((ret = speedtch_find_firmware(usbatm, intf, 2, &fw2)) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | release_firmware(fw1); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 406 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 409 | if ((ret = speedtch_upload_firmware(instance, fw1, fw2)) < 0) |
| 410 | usb_err(usbatm, "%s: firmware upload failed (%d)!\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 412 | release_firmware(fw2); |
| 413 | release_firmware(fw1); |
| 414 | |
| 415 | return ret; |
| 416 | } |
| 417 | |
| 418 | |
| 419 | /********** |
| 420 | ** ATM ** |
| 421 | **********/ |
| 422 | |
| 423 | static int speedtch_read_status(struct speedtch_instance_data *instance) |
| 424 | { |
| 425 | struct usbatm_data *usbatm = instance->usbatm; |
| 426 | struct usb_device *usb_dev = usbatm->usb_dev; |
| 427 | unsigned char *buf = instance->scratch_buffer; |
| 428 | int ret; |
| 429 | |
Duncan Sands | 6a4f1b4 | 2006-10-05 10:40:55 +0200 | [diff] [blame] | 430 | memset(buf, 0, 16); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 431 | |
| 432 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
| 433 | 0x12, 0xc0, 0x07, 0x00, buf + OFFSET_7, SIZE_7, |
| 434 | CTRL_TIMEOUT); |
| 435 | if (ret < 0) { |
| 436 | atm_dbg(usbatm, "%s: MSG 7 failed\n", __func__); |
| 437 | return ret; |
| 438 | } |
| 439 | |
| 440 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
| 441 | 0x12, 0xc0, 0x0b, 0x00, buf + OFFSET_b, SIZE_b, |
| 442 | CTRL_TIMEOUT); |
| 443 | if (ret < 0) { |
| 444 | atm_dbg(usbatm, "%s: MSG B failed\n", __func__); |
| 445 | return ret; |
| 446 | } |
| 447 | |
| 448 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
| 449 | 0x12, 0xc0, 0x0d, 0x00, buf + OFFSET_d, SIZE_d, |
| 450 | CTRL_TIMEOUT); |
| 451 | if (ret < 0) { |
| 452 | atm_dbg(usbatm, "%s: MSG D failed\n", __func__); |
| 453 | return ret; |
| 454 | } |
| 455 | |
| 456 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
| 457 | 0x01, 0xc0, 0x0e, 0x00, buf + OFFSET_e, SIZE_e, |
| 458 | CTRL_TIMEOUT); |
| 459 | if (ret < 0) { |
| 460 | atm_dbg(usbatm, "%s: MSG E failed\n", __func__); |
| 461 | return ret; |
| 462 | } |
| 463 | |
| 464 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
| 465 | 0x01, 0xc0, 0x0f, 0x00, buf + OFFSET_f, SIZE_f, |
| 466 | CTRL_TIMEOUT); |
| 467 | if (ret < 0) { |
| 468 | atm_dbg(usbatm, "%s: MSG F failed\n", __func__); |
| 469 | return ret; |
| 470 | } |
| 471 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | return 0; |
| 473 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 475 | static int speedtch_start_synchro(struct speedtch_instance_data *instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 477 | struct usbatm_data *usbatm = instance->usbatm; |
| 478 | struct usb_device *usb_dev = usbatm->usb_dev; |
| 479 | unsigned char *buf = instance->scratch_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 482 | atm_dbg(usbatm, "%s entered\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 484 | memset(buf, 0, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 486 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
| 487 | 0x12, 0xc0, 0x04, 0x00, |
| 488 | buf, 2, CTRL_TIMEOUT); |
| 489 | |
| 490 | if (ret < 0) |
| 491 | atm_warn(usbatm, "failed to start ADSL synchronisation: %d\n", ret); |
| 492 | else |
| 493 | atm_dbg(usbatm, "%s: modem prodded. %d bytes returned: %02x %02x\n", |
| 494 | __func__, ret, buf[0], buf[1]); |
| 495 | |
| 496 | return ret; |
| 497 | } |
| 498 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 499 | static void speedtch_check_status(struct work_struct *work) |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 500 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 501 | struct speedtch_instance_data *instance = |
| 502 | container_of(work, struct speedtch_instance_data, |
| 503 | status_checker.work); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 504 | struct usbatm_data *usbatm = instance->usbatm; |
| 505 | struct atm_dev *atm_dev = usbatm->atm_dev; |
| 506 | unsigned char *buf = instance->scratch_buffer; |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 507 | int down_speed, up_speed, ret; |
| 508 | unsigned char status; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 509 | |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 510 | #ifdef VERBOSE_DEBUG |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 511 | atm_dbg(usbatm, "%s entered\n", __func__); |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 512 | #endif |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 513 | |
| 514 | ret = speedtch_read_status(instance); |
| 515 | if (ret < 0) { |
| 516 | atm_warn(usbatm, "error %d fetching device status\n", ret); |
Duncan Sands | cd5c08f | 2005-06-23 09:23:10 +0200 | [diff] [blame] | 517 | instance->poll_delay = min(2 * instance->poll_delay, MAX_POLL_DELAY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | return; |
| 519 | } |
| 520 | |
Duncan Sands | cd5c08f | 2005-06-23 09:23:10 +0200 | [diff] [blame] | 521 | instance->poll_delay = max(instance->poll_delay / 2, MIN_POLL_DELAY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 523 | status = buf[OFFSET_7]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 525 | if ((status != instance->last_status) || !status) { |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 526 | atm_dbg(usbatm, "%s: line state 0x%02x\n", __func__, status); |
| 527 | |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 528 | switch (status) { |
| 529 | case 0: |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 530 | atm_dev->signal = ATM_PHY_SIG_LOST; |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 531 | if (instance->last_status) |
David S. Miller | 52fbae2 | 2005-07-25 19:54:35 -0700 | [diff] [blame] | 532 | atm_info(usbatm, "ADSL line is down\n"); |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 533 | /* It may never resync again unless we ask it to... */ |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 534 | ret = speedtch_start_synchro(instance); |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 535 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 537 | case 0x08: |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 538 | atm_dev->signal = ATM_PHY_SIG_UNKNOWN; |
David S. Miller | 52fbae2 | 2005-07-25 19:54:35 -0700 | [diff] [blame] | 539 | atm_info(usbatm, "ADSL line is blocked?\n"); |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 540 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 542 | case 0x10: |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 543 | atm_dev->signal = ATM_PHY_SIG_LOST; |
David S. Miller | 52fbae2 | 2005-07-25 19:54:35 -0700 | [diff] [blame] | 544 | atm_info(usbatm, "ADSL line is synchronising\n"); |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 545 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 547 | case 0x20: |
| 548 | down_speed = buf[OFFSET_b] | (buf[OFFSET_b + 1] << 8) |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 549 | | (buf[OFFSET_b + 2] << 16) | (buf[OFFSET_b + 3] << 24); |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 550 | up_speed = buf[OFFSET_b + 4] | (buf[OFFSET_b + 5] << 8) |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 551 | | (buf[OFFSET_b + 6] << 16) | (buf[OFFSET_b + 7] << 24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 553 | if (!(down_speed & 0x0000ffff) && !(up_speed & 0x0000ffff)) { |
| 554 | down_speed >>= 16; |
| 555 | up_speed >>= 16; |
| 556 | } |
| 557 | |
| 558 | atm_dev->link_rate = down_speed * 1000 / 424; |
| 559 | atm_dev->signal = ATM_PHY_SIG_FOUND; |
| 560 | |
| 561 | atm_info(usbatm, |
Duncan Sands | 322a95b | 2005-06-23 09:20:50 +0200 | [diff] [blame] | 562 | "ADSL line is up (%d kb/s down | %d kb/s up)\n", |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 563 | down_speed, up_speed); |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 564 | break; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 565 | |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 566 | default: |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 567 | atm_dev->signal = ATM_PHY_SIG_UNKNOWN; |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 568 | atm_info(usbatm, "unknown line state %02x\n", status); |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 569 | break; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 570 | } |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 571 | |
| 572 | instance->last_status = status; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 573 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | } |
| 575 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 576 | static void speedtch_status_poll(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 578 | struct speedtch_instance_data *instance = (void *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 580 | schedule_delayed_work(&instance->status_checker, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 582 | /* The following check is racy, but the race is harmless */ |
| 583 | if (instance->poll_delay < MAX_POLL_DELAY) |
| 584 | mod_timer(&instance->status_checker.timer, jiffies + msecs_to_jiffies(instance->poll_delay)); |
| 585 | else |
David S. Miller | 52fbae2 | 2005-07-25 19:54:35 -0700 | [diff] [blame] | 586 | atm_warn(instance->usbatm, "Too many failures - disabling line status polling\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | } |
| 588 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 589 | static void speedtch_resubmit_int(unsigned long data) |
| 590 | { |
| 591 | struct speedtch_instance_data *instance = (void *)data; |
| 592 | struct urb *int_urb = instance->int_urb; |
| 593 | int ret; |
| 594 | |
| 595 | atm_dbg(instance->usbatm, "%s entered\n", __func__); |
| 596 | |
| 597 | if (int_urb) { |
| 598 | ret = usb_submit_urb(int_urb, GFP_ATOMIC); |
| 599 | if (!ret) |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 600 | schedule_delayed_work(&instance->status_checker, 0); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 601 | else { |
| 602 | atm_dbg(instance->usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret); |
| 603 | mod_timer(&instance->resubmit_timer, jiffies + msecs_to_jiffies(RESUBMIT_DELAY)); |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 608 | static void speedtch_handle_int(struct urb *int_urb) |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 609 | { |
| 610 | struct speedtch_instance_data *instance = int_urb->context; |
| 611 | struct usbatm_data *usbatm = instance->usbatm; |
| 612 | unsigned int count = int_urb->actual_length; |
Greg Kroah-Hartman | 9a5a3e9 | 2007-07-18 10:58:02 -0700 | [diff] [blame] | 613 | int status = int_urb->status; |
| 614 | int ret; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 615 | |
| 616 | /* The magic interrupt for "up state" */ |
Jesper Juhl | 3c6bee1 | 2006-01-09 20:54:01 -0800 | [diff] [blame] | 617 | static const unsigned char up_int[6] = { 0xa1, 0x00, 0x01, 0x00, 0x00, 0x00 }; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 618 | /* The magic interrupt for "down state" */ |
Jesper Juhl | 3c6bee1 | 2006-01-09 20:54:01 -0800 | [diff] [blame] | 619 | static const unsigned char down_int[6] = { 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 620 | |
| 621 | atm_dbg(usbatm, "%s entered\n", __func__); |
| 622 | |
Greg Kroah-Hartman | 9a5a3e9 | 2007-07-18 10:58:02 -0700 | [diff] [blame] | 623 | if (status < 0) { |
| 624 | atm_dbg(usbatm, "%s: nonzero urb status %d!\n", __func__, status); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 625 | goto fail; |
| 626 | } |
| 627 | |
| 628 | if ((count == 6) && !memcmp(up_int, instance->int_data, 6)) { |
| 629 | del_timer(&instance->status_checker.timer); |
David S. Miller | 52fbae2 | 2005-07-25 19:54:35 -0700 | [diff] [blame] | 630 | atm_info(usbatm, "DSL line goes up\n"); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 631 | } else if ((count == 6) && !memcmp(down_int, instance->int_data, 6)) { |
David S. Miller | 52fbae2 | 2005-07-25 19:54:35 -0700 | [diff] [blame] | 632 | atm_info(usbatm, "DSL line goes down\n"); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 633 | } else { |
| 634 | int i; |
| 635 | |
| 636 | atm_dbg(usbatm, "%s: unknown interrupt packet of length %d:", __func__, count); |
| 637 | for (i = 0; i < count; i++) |
| 638 | printk(" %02x", instance->int_data[i]); |
| 639 | printk("\n"); |
| 640 | goto fail; |
| 641 | } |
| 642 | |
| 643 | if ((int_urb = instance->int_urb)) { |
| 644 | ret = usb_submit_urb(int_urb, GFP_ATOMIC); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 645 | schedule_delayed_work(&instance->status_checker, 0); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 646 | if (ret < 0) { |
| 647 | atm_dbg(usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret); |
| 648 | goto fail; |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | return; |
| 653 | |
| 654 | fail: |
| 655 | if ((int_urb = instance->int_urb)) |
| 656 | mod_timer(&instance->resubmit_timer, jiffies + msecs_to_jiffies(RESUBMIT_DELAY)); |
| 657 | } |
| 658 | |
| 659 | static int speedtch_atm_start(struct usbatm_data *usbatm, struct atm_dev *atm_dev) |
| 660 | { |
| 661 | struct usb_device *usb_dev = usbatm->usb_dev; |
| 662 | struct speedtch_instance_data *instance = usbatm->driver_data; |
| 663 | int i, ret; |
| 664 | unsigned char mac_str[13]; |
| 665 | |
| 666 | atm_dbg(usbatm, "%s entered\n", __func__); |
| 667 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 668 | /* Set MAC address, it is stored in the serial number */ |
| 669 | memset(atm_dev->esi, 0, sizeof(atm_dev->esi)); |
| 670 | if (usb_string(usb_dev, usb_dev->descriptor.iSerialNumber, mac_str, sizeof(mac_str)) == 12) { |
| 671 | for (i = 0; i < 6; i++) |
| 672 | atm_dev->esi[i] = (hex2int(mac_str[i * 2]) * 16) + (hex2int(mac_str[i * 2 + 1])); |
| 673 | } |
| 674 | |
| 675 | /* Start modem synchronisation */ |
| 676 | ret = speedtch_start_synchro(instance); |
| 677 | |
| 678 | /* Set up interrupt endpoint */ |
| 679 | if (instance->int_urb) { |
| 680 | ret = usb_submit_urb(instance->int_urb, GFP_KERNEL); |
| 681 | if (ret < 0) { |
| 682 | /* Doesn't matter; we'll poll anyway */ |
| 683 | atm_dbg(usbatm, "%s: submission of interrupt URB failed (%d)!\n", __func__, ret); |
| 684 | usb_free_urb(instance->int_urb); |
| 685 | instance->int_urb = NULL; |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | /* Start status polling */ |
| 690 | mod_timer(&instance->status_checker.timer, jiffies + msecs_to_jiffies(1000)); |
| 691 | |
| 692 | return 0; |
| 693 | } |
| 694 | |
| 695 | static void speedtch_atm_stop(struct usbatm_data *usbatm, struct atm_dev *atm_dev) |
| 696 | { |
| 697 | struct speedtch_instance_data *instance = usbatm->driver_data; |
| 698 | struct urb *int_urb = instance->int_urb; |
| 699 | |
| 700 | atm_dbg(usbatm, "%s entered\n", __func__); |
| 701 | |
| 702 | del_timer_sync(&instance->status_checker.timer); |
| 703 | |
| 704 | /* |
| 705 | * Since resubmit_timer and int_urb can schedule themselves and |
| 706 | * each other, shutting them down correctly takes some care |
| 707 | */ |
| 708 | instance->int_urb = NULL; /* signal shutdown */ |
| 709 | mb(); |
| 710 | usb_kill_urb(int_urb); |
| 711 | del_timer_sync(&instance->resubmit_timer); |
| 712 | /* |
| 713 | * At this point, speedtch_handle_int and speedtch_resubmit_int |
| 714 | * can run or be running, but instance->int_urb == NULL means that |
| 715 | * they will not reschedule |
| 716 | */ |
| 717 | usb_kill_urb(int_urb); |
| 718 | del_timer_sync(&instance->resubmit_timer); |
| 719 | usb_free_urb(int_urb); |
| 720 | |
| 721 | flush_scheduled_work(); |
| 722 | } |
| 723 | |
Alan Stern | 8fc7aea | 2008-10-20 09:52:12 -0400 | [diff] [blame] | 724 | static int speedtch_pre_reset(struct usb_interface *intf) |
| 725 | { |
| 726 | return 0; |
| 727 | } |
| 728 | |
| 729 | static int speedtch_post_reset(struct usb_interface *intf) |
| 730 | { |
| 731 | return 0; |
| 732 | } |
| 733 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 734 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | /********** |
| 736 | ** USB ** |
| 737 | **********/ |
| 738 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 739 | static struct usb_device_id speedtch_usb_ids[] = { |
| 740 | {USB_DEVICE(0x06b9, 0x4061)}, |
| 741 | {} |
| 742 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 744 | MODULE_DEVICE_TABLE(usb, speedtch_usb_ids); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 746 | static int speedtch_usb_probe(struct usb_interface *, const struct usb_device_id *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 748 | static struct usb_driver speedtch_usb_driver = { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 749 | .name = speedtch_driver_name, |
| 750 | .probe = speedtch_usb_probe, |
| 751 | .disconnect = usbatm_usb_disconnect, |
Alan Stern | 8fc7aea | 2008-10-20 09:52:12 -0400 | [diff] [blame] | 752 | .pre_reset = speedtch_pre_reset, |
| 753 | .post_reset = speedtch_post_reset, |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 754 | .id_table = speedtch_usb_ids |
| 755 | }; |
| 756 | |
| 757 | static void speedtch_release_interfaces(struct usb_device *usb_dev, int num_interfaces) { |
| 758 | struct usb_interface *cur_intf; |
| 759 | int i; |
| 760 | |
| 761 | for(i = 0; i < num_interfaces; i++) |
| 762 | if ((cur_intf = usb_ifnum_to_if(usb_dev, i))) { |
| 763 | usb_set_intfdata(cur_intf, NULL); |
| 764 | usb_driver_release_interface(&speedtch_usb_driver, cur_intf); |
| 765 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 768 | static int speedtch_bind(struct usbatm_data *usbatm, |
| 769 | struct usb_interface *intf, |
Duncan Sands | 35644b0 | 2006-01-17 11:16:13 +0100 | [diff] [blame] | 770 | const struct usb_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 772 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 773 | struct usb_interface *cur_intf, *data_intf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | struct speedtch_instance_data *instance; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 775 | int ifnum = intf->altsetting->desc.bInterfaceNumber; |
| 776 | int num_interfaces = usb_dev->actconfig->desc.bNumInterfaces; |
| 777 | int i, ret; |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 778 | int use_isoc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 780 | usb_dbg(usbatm, "%s entered\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 782 | /* sanity checks */ |
| 783 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 784 | if (usb_dev->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC) { |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 785 | usb_err(usbatm, "%s: wrong device class %d\n", __func__, usb_dev->descriptor.bDeviceClass); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | return -ENODEV; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 787 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 789 | if (!(data_intf = usb_ifnum_to_if(usb_dev, INTERFACE_DATA))) { |
| 790 | usb_err(usbatm, "%s: data interface not found!\n", __func__); |
| 791 | return -ENODEV; |
| 792 | } |
| 793 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 794 | /* claim all interfaces */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 796 | for (i=0; i < num_interfaces; i++) { |
| 797 | cur_intf = usb_ifnum_to_if(usb_dev, i); |
| 798 | |
| 799 | if ((i != ifnum) && cur_intf) { |
| 800 | ret = usb_driver_claim_interface(&speedtch_usb_driver, cur_intf, usbatm); |
| 801 | |
| 802 | if (ret < 0) { |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 803 | usb_err(usbatm, "%s: failed to claim interface %2d (%d)!\n", __func__, i, ret); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 804 | speedtch_release_interfaces(usb_dev, i); |
| 805 | return ret; |
| 806 | } |
| 807 | } |
| 808 | } |
| 809 | |
Duncan Sands | 9a734ef | 2006-01-13 09:38:22 +0100 | [diff] [blame] | 810 | instance = kzalloc(sizeof(*instance), GFP_KERNEL); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 811 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | if (!instance) { |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 813 | usb_err(usbatm, "%s: no memory for instance data!\n", __func__); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 814 | ret = -ENOMEM; |
| 815 | goto fail_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | } |
| 817 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 818 | instance->usbatm = usbatm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | |
Duncan Sands | 6a4f1b4 | 2006-10-05 10:40:55 +0200 | [diff] [blame] | 820 | /* module parameters may change at any moment, so take a snapshot */ |
| 821 | instance->params.altsetting = altsetting; |
| 822 | instance->params.BMaxDSL = BMaxDSL; |
| 823 | instance->params.ModemMode = ModemMode; |
| 824 | memcpy(instance->params.ModemOption, DEFAULT_MODEM_OPTION, MODEM_OPTION_LENGTH); |
| 825 | memcpy(instance->params.ModemOption, ModemOption, num_ModemOption); |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 826 | use_isoc = enable_isoc; |
Duncan Sands | 6f74947 | 2006-01-13 10:52:38 +0100 | [diff] [blame] | 827 | |
Duncan Sands | 6a4f1b4 | 2006-10-05 10:40:55 +0200 | [diff] [blame] | 828 | if (instance->params.altsetting) |
| 829 | if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, instance->params.altsetting)) < 0) { |
| 830 | usb_err(usbatm, "%s: setting interface to %2d failed (%d)!\n", __func__, instance->params.altsetting, ret); |
| 831 | instance->params.altsetting = 0; /* fall back to default */ |
Duncan Sands | 6f74947 | 2006-01-13 10:52:38 +0100 | [diff] [blame] | 832 | } |
| 833 | |
Duncan Sands | 6a4f1b4 | 2006-10-05 10:40:55 +0200 | [diff] [blame] | 834 | if (!instance->params.altsetting && use_isoc) |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 835 | if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, DEFAULT_ISOC_ALTSETTING)) < 0) { |
| 836 | usb_dbg(usbatm, "%s: setting interface to %2d failed (%d)!\n", __func__, DEFAULT_ISOC_ALTSETTING, ret); |
| 837 | use_isoc = 0; /* fall back to bulk */ |
| 838 | } |
| 839 | |
| 840 | if (use_isoc) { |
| 841 | const struct usb_host_interface *desc = data_intf->cur_altsetting; |
| 842 | const __u8 target_address = USB_DIR_IN | usbatm->driver->isoc_in; |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 843 | |
| 844 | use_isoc = 0; /* fall back to bulk if endpoint not found */ |
| 845 | |
| 846 | for (i=0; i<desc->desc.bNumEndpoints; i++) { |
| 847 | const struct usb_endpoint_descriptor *endpoint_desc = &desc->endpoint[i].desc; |
| 848 | |
| 849 | if ((endpoint_desc->bEndpointAddress == target_address)) { |
Luiz Fernando N. Capitulino | c5dd1f9 | 2006-10-26 13:02:58 -0300 | [diff] [blame] | 850 | use_isoc = |
| 851 | usb_endpoint_xfer_isoc(endpoint_desc); |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 852 | break; |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | if (!use_isoc) |
| 857 | usb_info(usbatm, "isochronous transfer not supported - using bulk\n"); |
| 858 | } |
| 859 | |
Duncan Sands | 6a4f1b4 | 2006-10-05 10:40:55 +0200 | [diff] [blame] | 860 | if (!use_isoc && !instance->params.altsetting) |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 861 | if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, DEFAULT_BULK_ALTSETTING)) < 0) { |
| 862 | usb_err(usbatm, "%s: setting interface to %2d failed (%d)!\n", __func__, DEFAULT_BULK_ALTSETTING, ret); |
Duncan Sands | 6f74947 | 2006-01-13 10:52:38 +0100 | [diff] [blame] | 863 | goto fail_free; |
| 864 | } |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 865 | |
Duncan Sands | 6a4f1b4 | 2006-10-05 10:40:55 +0200 | [diff] [blame] | 866 | if (!instance->params.altsetting) |
| 867 | instance->params.altsetting = use_isoc ? DEFAULT_ISOC_ALTSETTING : DEFAULT_BULK_ALTSETTING; |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 868 | |
| 869 | usbatm->flags |= (use_isoc ? UDSL_USE_ISOC : 0); |
Duncan Sands | 6f74947 | 2006-01-13 10:52:38 +0100 | [diff] [blame] | 870 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 871 | INIT_DELAYED_WORK(&instance->status_checker, speedtch_check_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 873 | instance->status_checker.timer.function = speedtch_status_poll; |
| 874 | instance->status_checker.timer.data = (unsigned long)instance; |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 875 | instance->last_status = 0xff; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 876 | instance->poll_delay = MIN_POLL_DELAY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 878 | init_timer(&instance->resubmit_timer); |
| 879 | instance->resubmit_timer.function = speedtch_resubmit_int; |
| 880 | instance->resubmit_timer.data = (unsigned long)instance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 882 | instance->int_urb = usb_alloc_urb(0, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 884 | if (instance->int_urb) |
| 885 | usb_fill_int_urb(instance->int_urb, usb_dev, |
| 886 | usb_rcvintpipe(usb_dev, ENDPOINT_INT), |
| 887 | instance->int_data, sizeof(instance->int_data), |
| 888 | speedtch_handle_int, instance, 50); |
| 889 | else |
| 890 | usb_dbg(usbatm, "%s: no memory for interrupt urb!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 892 | /* check whether the modem already seems to be alive */ |
| 893 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
| 894 | 0x12, 0xc0, 0x07, 0x00, |
| 895 | instance->scratch_buffer + OFFSET_7, SIZE_7, 500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 897 | usbatm->flags |= (ret == SIZE_7 ? UDSL_SKIP_HEAVY_INIT : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | |
Duncan Sands | 35644b0 | 2006-01-17 11:16:13 +0100 | [diff] [blame] | 899 | usb_dbg(usbatm, "%s: firmware %s loaded\n", __func__, usbatm->flags & UDSL_SKIP_HEAVY_INIT ? "already" : "not"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
Duncan Sands | 35644b0 | 2006-01-17 11:16:13 +0100 | [diff] [blame] | 901 | if (!(usbatm->flags & UDSL_SKIP_HEAVY_INIT)) |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 902 | if ((ret = usb_reset_device(usb_dev)) < 0) { |
| 903 | usb_err(usbatm, "%s: device reset failed (%d)!\n", __func__, ret); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 904 | goto fail_free; |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 905 | } |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 906 | |
| 907 | usbatm->driver_data = instance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | |
| 909 | return 0; |
| 910 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 911 | fail_free: |
| 912 | usb_free_urb(instance->int_urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | kfree(instance); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 914 | fail_release: |
| 915 | speedtch_release_interfaces(usb_dev, num_interfaces); |
| 916 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 919 | static void speedtch_unbind(struct usbatm_data *usbatm, struct usb_interface *intf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 921 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
| 922 | struct speedtch_instance_data *instance = usbatm->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 924 | usb_dbg(usbatm, "%s entered\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 926 | speedtch_release_interfaces(usb_dev, usb_dev->actconfig->desc.bNumInterfaces); |
| 927 | usb_free_urb(instance->int_urb); |
| 928 | kfree(instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | } |
| 930 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | /*********** |
| 933 | ** init ** |
| 934 | ***********/ |
| 935 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 936 | static struct usbatm_driver speedtch_usbatm_driver = { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 937 | .driver_name = speedtch_driver_name, |
| 938 | .bind = speedtch_bind, |
| 939 | .heavy_init = speedtch_heavy_init, |
| 940 | .unbind = speedtch_unbind, |
| 941 | .atm_start = speedtch_atm_start, |
| 942 | .atm_stop = speedtch_atm_stop, |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 943 | .bulk_in = ENDPOINT_BULK_DATA, |
| 944 | .bulk_out = ENDPOINT_BULK_DATA, |
| 945 | .isoc_in = ENDPOINT_ISOC_DATA |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 946 | }; |
| 947 | |
| 948 | static int speedtch_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 949 | { |
| 950 | return usbatm_usb_probe(intf, id, &speedtch_usbatm_driver); |
| 951 | } |
| 952 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | static int __init speedtch_usb_init(void) |
| 954 | { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 955 | dbg("%s: driver version %s", __func__, DRIVER_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | |
| 957 | return usb_register(&speedtch_usb_driver); |
| 958 | } |
| 959 | |
| 960 | static void __exit speedtch_usb_cleanup(void) |
| 961 | { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 962 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | |
| 964 | usb_deregister(&speedtch_usb_driver); |
| 965 | } |
| 966 | |
| 967 | module_init(speedtch_usb_init); |
| 968 | module_exit(speedtch_usb_cleanup); |
| 969 | |
| 970 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 971 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 972 | MODULE_LICENSE("GPL"); |
| 973 | MODULE_VERSION(DRIVER_VERSION); |