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