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