Steven Toth | 8d4f9d0 | 2008-05-22 18:05:26 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the Siano SMS10xx USB dongle |
| 3 | * |
Michael Krufky | 8544706 | 2008-05-22 18:29:20 -0300 | [diff] [blame] | 4 | * author: Anatoly Greenblat |
| 5 | * |
| 6 | * Copyright (c), 2005-2008 Siano Mobile Silicon, Inc. |
Steven Toth | 8d4f9d0 | 2008-05-22 18:05:26 -0300 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
Michael Krufky | 8544706 | 2008-05-22 18:29:20 -0300 | [diff] [blame] | 9 | * it under the terms of the GNU General Public License version 3 as |
| 10 | * published by the Free Software Foundation; |
Steven Toth | 8d4f9d0 | 2008-05-22 18:05:26 -0300 | [diff] [blame] | 11 | * |
Michael Krufky | 8544706 | 2008-05-22 18:29:20 -0300 | [diff] [blame] | 12 | * Software distributed under the License is distributed on an "AS IS" |
| 13 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. |
Steven Toth | 8d4f9d0 | 2008-05-22 18:05:26 -0300 | [diff] [blame] | 14 | * |
Michael Krufky | 8544706 | 2008-05-22 18:29:20 -0300 | [diff] [blame] | 15 | * See the GNU General Public License for more details. |
Steven Toth | 8d4f9d0 | 2008-05-22 18:05:26 -0300 | [diff] [blame] | 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 22 | #include <linux/kernel.h> |
| 23 | #include <linux/init.h> |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 24 | #include <linux/usb.h> |
| 25 | #include <linux/firmware.h> |
| 26 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 27 | #include "smscoreapi.h" |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 28 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 29 | #define USB1_BUFFER_SIZE 0x1000 |
| 30 | #define USB2_BUFFER_SIZE 0x4000 |
| 31 | |
| 32 | #define MAX_BUFFERS 50 |
| 33 | #define MAX_URBS 10 |
| 34 | |
Michael Krufky | 73104fb | 2008-06-14 18:27:18 -0300 | [diff] [blame^] | 35 | /* TO DO: move these to a header file */ |
| 36 | #define USB_VID_SIANO 0x187f |
| 37 | |
| 38 | #define USB_PID_STELLAR 0x0100 |
| 39 | #define USB_PID_NOVA_A 0x0200 |
| 40 | #define USB_PID_NOVA_B 0x0201 |
| 41 | #define USB_PID_VEGA 0x0300 |
| 42 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 43 | typedef struct _smsusb_device smsusb_device_t; |
| 44 | |
| 45 | typedef struct _smsusb_urb |
| 46 | { |
| 47 | smscore_buffer_t *cb; |
| 48 | smsusb_device_t *dev; |
| 49 | |
| 50 | struct urb urb; |
| 51 | } smsusb_urb_t; |
| 52 | |
| 53 | typedef struct _smsusb_device |
| 54 | { |
Michael Krufky | a83ccdd | 2008-05-06 03:11:51 -0300 | [diff] [blame] | 55 | struct usb_device *udev; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 56 | smscore_device_t *coredev; |
| 57 | |
| 58 | smsusb_urb_t surbs[MAX_URBS]; |
| 59 | |
| 60 | int response_alignment; |
| 61 | int buffer_size; |
| 62 | } *psmsusb_device_t; |
| 63 | |
Michael Krufky | a83ccdd | 2008-05-06 03:11:51 -0300 | [diff] [blame] | 64 | int smsusb_submit_urb(smsusb_device_t *dev, smsusb_urb_t *surb); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 65 | |
| 66 | void smsusb_onresponse(struct urb *urb) |
| 67 | { |
| 68 | smsusb_urb_t *surb = (smsusb_urb_t *) urb->context; |
| 69 | smsusb_device_t *dev = surb->dev; |
| 70 | |
| 71 | if (urb->status < 0) |
| 72 | { |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 73 | printk(KERN_INFO "%s error, urb status %d, %d bytes\n", __func__, urb->status, urb->actual_length); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 74 | return; |
| 75 | } |
| 76 | |
| 77 | if (urb->actual_length > 0) |
| 78 | { |
| 79 | SmsMsgHdr_ST *phdr = (SmsMsgHdr_ST *) surb->cb->p; |
| 80 | |
| 81 | if (urb->actual_length >= phdr->msgLength) |
| 82 | { |
| 83 | surb->cb->size = phdr->msgLength; |
| 84 | |
| 85 | if (dev->response_alignment && (phdr->msgFlags & MSG_HDR_FLAG_SPLIT_MSG)) |
| 86 | { |
| 87 | surb->cb->offset = dev->response_alignment + ((phdr->msgFlags >> 8) & 3); |
| 88 | |
| 89 | // sanity check |
| 90 | if (((int) phdr->msgLength + surb->cb->offset) > urb->actual_length) |
| 91 | { |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 92 | printk("%s: invalid response msglen %d offset %d size %d\n", __func__, phdr->msgLength, surb->cb->offset, urb->actual_length); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 93 | goto exit_and_resubmit; |
| 94 | } |
| 95 | |
| 96 | // move buffer pointer and copy header to its new location |
Michael Krufky | 55ad310 | 2008-05-06 03:52:44 -0300 | [diff] [blame] | 97 | memcpy((char *) phdr + surb->cb->offset, |
| 98 | phdr, sizeof(SmsMsgHdr_ST)); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 99 | } |
| 100 | else |
| 101 | surb->cb->offset = 0; |
| 102 | |
| 103 | smscore_onresponse(dev->coredev, surb->cb); |
| 104 | surb->cb = NULL; |
| 105 | } |
| 106 | else |
| 107 | { |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 108 | printk("%s invalid response msglen %d actual %d\n", __func__, phdr->msgLength, urb->actual_length); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
| 112 | exit_and_resubmit: |
| 113 | smsusb_submit_urb(dev, surb); |
| 114 | } |
| 115 | |
Michael Krufky | a83ccdd | 2008-05-06 03:11:51 -0300 | [diff] [blame] | 116 | int smsusb_submit_urb(smsusb_device_t *dev, smsusb_urb_t *surb) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 117 | { |
| 118 | if (!surb->cb) |
| 119 | { |
| 120 | surb->cb = smscore_getbuffer(dev->coredev); |
| 121 | if (!surb->cb) |
| 122 | { |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 123 | printk(KERN_INFO "%s smscore_getbuffer(...) returned NULL\n", __func__); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 124 | return -ENOMEM; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | usb_fill_bulk_urb( |
| 129 | &surb->urb, |
| 130 | dev->udev, |
| 131 | usb_rcvbulkpipe(dev->udev, 0x81), |
| 132 | surb->cb->p, |
| 133 | dev->buffer_size, |
| 134 | smsusb_onresponse, |
| 135 | surb |
| 136 | ); |
| 137 | surb->urb.transfer_dma = surb->cb->phys; |
| 138 | surb->urb.transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 139 | |
| 140 | return usb_submit_urb(&surb->urb, GFP_ATOMIC); |
| 141 | } |
| 142 | |
Michael Krufky | a83ccdd | 2008-05-06 03:11:51 -0300 | [diff] [blame] | 143 | void smsusb_stop_streaming(smsusb_device_t *dev) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 144 | { |
| 145 | int i; |
| 146 | |
| 147 | for (i = 0; i < MAX_URBS; i ++) |
| 148 | { |
| 149 | usb_kill_urb(&dev->surbs[i].urb); |
| 150 | |
| 151 | if (dev->surbs[i].cb) |
| 152 | { |
| 153 | smscore_putbuffer(dev->coredev, dev->surbs[i].cb); |
| 154 | dev->surbs[i].cb = NULL; |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
Michael Krufky | a83ccdd | 2008-05-06 03:11:51 -0300 | [diff] [blame] | 159 | int smsusb_start_streaming(smsusb_device_t *dev) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 160 | { |
| 161 | int i, rc; |
| 162 | |
| 163 | for (i = 0; i < MAX_URBS; i ++) |
| 164 | { |
| 165 | rc = smsusb_submit_urb(dev, &dev->surbs[i]); |
| 166 | if (rc < 0) |
| 167 | { |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 168 | printk(KERN_INFO "%s smsusb_submit_urb(...) failed\n", __func__); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 169 | smsusb_stop_streaming(dev); |
| 170 | break; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | return rc; |
| 175 | } |
| 176 | |
| 177 | int smsusb_sendrequest(void *context, void *buffer, size_t size) |
| 178 | { |
Michael Krufky | a83ccdd | 2008-05-06 03:11:51 -0300 | [diff] [blame] | 179 | smsusb_device_t *dev = (smsusb_device_t *) context; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 180 | int dummy; |
| 181 | |
| 182 | return usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 2), buffer, size, &dummy, 1000); |
| 183 | } |
| 184 | |
| 185 | char *smsusb1_fw_lkup[] = |
| 186 | { |
| 187 | "dvbt_stellar_usb.inp", |
| 188 | "dvbh_stellar_usb.inp", |
| 189 | "tdmb_stellar_usb.inp", |
| 190 | "none", |
| 191 | "dvbt_bda_stellar_usb.inp", |
| 192 | }; |
| 193 | |
| 194 | int smsusb1_load_firmware(struct usb_device *udev, int id) |
| 195 | { |
| 196 | const struct firmware *fw; |
Michael Krufky | a83ccdd | 2008-05-06 03:11:51 -0300 | [diff] [blame] | 197 | u8 *fw_buffer; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 198 | int rc, dummy; |
| 199 | |
| 200 | if (id < DEVICE_MODE_DVBT || id > DEVICE_MODE_DVBT_BDA) |
| 201 | { |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 202 | printk(KERN_INFO "%s invalid firmware id specified %d\n", __func__, id); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 203 | return -EINVAL; |
| 204 | } |
| 205 | |
| 206 | rc = request_firmware(&fw, smsusb1_fw_lkup[id], &udev->dev); |
| 207 | if (rc < 0) |
| 208 | { |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 209 | printk(KERN_INFO "%s failed to open \"%s\" mode %d\n", __func__, smsusb1_fw_lkup[id], id); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 210 | return rc; |
| 211 | } |
| 212 | |
| 213 | fw_buffer = kmalloc(fw->size, GFP_KERNEL); |
| 214 | if (fw_buffer) |
| 215 | { |
| 216 | memcpy(fw_buffer, fw->data, fw->size); |
| 217 | |
| 218 | rc = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 2), fw_buffer, fw->size, &dummy, 1000); |
| 219 | |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 220 | printk(KERN_INFO "%s: sent %d(%d) bytes, rc %d\n", __func__, fw->size, dummy, rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 221 | |
| 222 | kfree(fw_buffer); |
| 223 | } |
| 224 | else |
| 225 | { |
| 226 | printk(KERN_INFO "failed to allocate firmware buffer\n"); |
| 227 | rc = -ENOMEM; |
| 228 | } |
| 229 | |
| 230 | release_firmware(fw); |
| 231 | |
| 232 | return rc; |
| 233 | } |
| 234 | |
| 235 | void smsusb1_detectmode(void *context, int *mode) |
| 236 | { |
| 237 | char *product_string = ((smsusb_device_t *) context)->udev->product; |
| 238 | |
| 239 | *mode = DEVICE_MODE_NONE; |
| 240 | |
| 241 | if (!product_string) |
| 242 | { |
| 243 | product_string = "none"; |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 244 | printk("%s product string not found\n", __func__); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 245 | } |
| 246 | else |
| 247 | { |
| 248 | if (strstr(product_string, "DVBH")) |
| 249 | *mode = 1; |
| 250 | else if (strstr(product_string, "BDA")) |
| 251 | *mode = 4; |
| 252 | else if (strstr(product_string, "DVBT")) |
| 253 | *mode = 0; |
| 254 | else if (strstr(product_string, "TDMB")) |
| 255 | *mode = 2; |
| 256 | } |
| 257 | |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 258 | printk("%s: %d \"%s\"\n", __func__, *mode, product_string); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | int smsusb1_setmode(void *context, int mode) |
| 262 | { |
| 263 | SmsMsgHdr_ST Msg = { MSG_SW_RELOAD_REQ, 0, HIF_TASK, sizeof(SmsMsgHdr_ST), 0 }; |
| 264 | |
| 265 | if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_DVBT_BDA) |
| 266 | { |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 267 | printk(KERN_INFO "%s invalid firmware id specified %d\n", __func__, mode); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 268 | return -EINVAL; |
| 269 | } |
| 270 | |
| 271 | return smsusb_sendrequest(context, &Msg, sizeof(Msg)); |
| 272 | } |
| 273 | |
| 274 | void smsusb_term_device(struct usb_interface *intf) |
| 275 | { |
Michael Krufky | 55ad310 | 2008-05-06 03:52:44 -0300 | [diff] [blame] | 276 | smsusb_device_t *dev = (smsusb_device_t *) usb_get_intfdata(intf); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 277 | |
| 278 | if (dev) |
| 279 | { |
| 280 | smsusb_stop_streaming(dev); |
| 281 | |
| 282 | // unregister from smscore |
| 283 | if (dev->coredev) |
| 284 | smscore_unregister_device(dev->coredev); |
| 285 | |
| 286 | kfree(dev); |
| 287 | |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 288 | printk(KERN_INFO "%s device %p destroyed\n", __func__, dev); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | usb_set_intfdata(intf, NULL); |
| 292 | } |
| 293 | |
| 294 | int smsusb_init_device(struct usb_interface *intf) |
| 295 | { |
| 296 | smsdevice_params_t params; |
Michael Krufky | a83ccdd | 2008-05-06 03:11:51 -0300 | [diff] [blame] | 297 | smsusb_device_t *dev; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 298 | int i, rc; |
| 299 | |
| 300 | // create device object |
| 301 | dev = kzalloc(sizeof(smsusb_device_t), GFP_KERNEL); |
| 302 | if (!dev) |
| 303 | { |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 304 | printk(KERN_INFO "%s kzalloc(sizeof(smsusb_device_t) failed\n", __func__); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 305 | return -ENOMEM; |
| 306 | } |
| 307 | |
| 308 | memset(¶ms, 0, sizeof(params)); |
| 309 | usb_set_intfdata(intf, dev); |
| 310 | dev->udev = interface_to_usbdev(intf); |
| 311 | |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 312 | switch (dev->udev->descriptor.idProduct) { |
Michael Krufky | 73104fb | 2008-06-14 18:27:18 -0300 | [diff] [blame^] | 313 | |
| 314 | case USB_PID_STELLAR: |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 315 | dev->buffer_size = USB1_BUFFER_SIZE; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 316 | |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 317 | params.setmode_handler = smsusb1_setmode; |
| 318 | params.detectmode_handler = smsusb1_detectmode; |
| 319 | params.device_type = SMS_STELLAR; |
| 320 | printk(KERN_INFO "%s stellar device found\n", __func__ ); |
| 321 | break; |
| 322 | default: |
Michael Krufky | 73104fb | 2008-06-14 18:27:18 -0300 | [diff] [blame^] | 323 | switch (dev->udev->descriptor.idProduct) { |
| 324 | case USB_PID_NOVA_A: |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 325 | params.device_type = SMS_NOVA_A0; |
Michael Krufky | 494d24c | 2008-06-14 07:40:41 -0300 | [diff] [blame] | 326 | printk(KERN_INFO "%s nova A0 found\n", __func__ ); |
Michael Krufky | 73104fb | 2008-06-14 18:27:18 -0300 | [diff] [blame^] | 327 | break; |
| 328 | default: |
| 329 | case USB_PID_NOVA_B: |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 330 | params.device_type = SMS_NOVA_B0; |
Michael Krufky | 494d24c | 2008-06-14 07:40:41 -0300 | [diff] [blame] | 331 | printk(KERN_INFO "%s nova B0 found\n", __func__); |
Michael Krufky | 73104fb | 2008-06-14 18:27:18 -0300 | [diff] [blame^] | 332 | break; |
| 333 | case USB_PID_VEGA: |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 334 | params.device_type = SMS_VEGA; |
Michael Krufky | 494d24c | 2008-06-14 07:40:41 -0300 | [diff] [blame] | 335 | printk(KERN_INFO "%s Vega found\n", __func__); |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 336 | } |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 337 | |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 338 | dev->buffer_size = USB2_BUFFER_SIZE; |
| 339 | dev->response_alignment = dev->udev->ep_in[1]->desc.wMaxPacketSize - sizeof(SmsMsgHdr_ST); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 340 | |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 341 | params.flags |= SMS_DEVICE_FAMILY2; |
| 342 | break; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | params.device = &dev->udev->dev; |
| 346 | params.buffer_size = dev->buffer_size; |
| 347 | params.num_buffers = MAX_BUFFERS; |
| 348 | params.sendrequest_handler = smsusb_sendrequest; |
| 349 | params.context = dev; |
| 350 | snprintf(params.devpath, sizeof(params.devpath), "usb\\%d-%s", dev->udev->bus->busnum, dev->udev->devpath); |
| 351 | |
| 352 | // register in smscore |
| 353 | rc = smscore_register_device(¶ms, &dev->coredev); |
| 354 | if (rc < 0) |
| 355 | { |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 356 | printk(KERN_INFO "%s smscore_register_device(...) failed, rc %d\n", __func__, rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 357 | smsusb_term_device(intf); |
| 358 | return rc; |
| 359 | } |
| 360 | |
| 361 | // initialize urbs |
| 362 | for (i = 0; i < MAX_URBS; i ++) |
| 363 | { |
| 364 | dev->surbs[i].dev = dev; |
| 365 | usb_init_urb(&dev->surbs[i].urb); |
| 366 | } |
| 367 | |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 368 | printk(KERN_INFO "%s smsusb_start_streaming(...).\n", __func__); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 369 | rc = smsusb_start_streaming(dev); |
| 370 | if (rc < 0) |
| 371 | { |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 372 | printk(KERN_INFO "%s smsusb_start_streaming(...) failed\n", __func__); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 373 | smsusb_term_device(intf); |
| 374 | return rc; |
| 375 | } |
| 376 | |
| 377 | rc = smscore_start_device(dev->coredev); |
| 378 | if (rc < 0) |
| 379 | { |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 380 | printk(KERN_INFO "%s smscore_start_device(...) failed\n", __func__); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 381 | smsusb_term_device(intf); |
| 382 | return rc; |
| 383 | } |
| 384 | |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 385 | printk(KERN_INFO "%s device %p created\n", __func__, dev); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 386 | |
| 387 | return rc; |
| 388 | } |
| 389 | |
| 390 | int smsusb_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 391 | { |
| 392 | struct usb_device *udev = interface_to_usbdev(intf); |
| 393 | char devpath[32]; |
| 394 | int i, rc; |
| 395 | |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 396 | rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x81)); |
| 397 | rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x02)); |
| 398 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 399 | if (intf->num_altsetting > 0) |
| 400 | { |
| 401 | rc = usb_set_interface(udev, intf->cur_altsetting->desc.bInterfaceNumber, 0); |
| 402 | if (rc < 0) |
| 403 | { |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 404 | printk(KERN_INFO "%s usb_set_interface failed, rc %d\n", __func__, rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 405 | return rc; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | printk(KERN_INFO "smsusb_probe %d\n", intf->cur_altsetting->desc.bInterfaceNumber); |
| 410 | for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i ++) |
| 411 | printk(KERN_INFO "endpoint %d %02x %02x %d\n", i, intf->cur_altsetting->endpoint[i].desc.bEndpointAddress, intf->cur_altsetting->endpoint[i].desc.bmAttributes, intf->cur_altsetting->endpoint[i].desc.wMaxPacketSize); |
| 412 | |
| 413 | if (udev->actconfig->desc.bNumInterfaces == 2 && intf->cur_altsetting->desc.bInterfaceNumber == 0) |
| 414 | { |
| 415 | printk(KERN_INFO "rom interface 0 is not used\n"); |
| 416 | return -ENODEV; |
| 417 | } |
| 418 | |
| 419 | if (intf->cur_altsetting->desc.bInterfaceNumber == 1) |
| 420 | { |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 421 | snprintf(devpath, sizeof(devpath), "usb\\%d-%s", udev->bus->busnum, udev->devpath); |
| 422 | printk(KERN_INFO "stellar device was found.\n"); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 423 | return smsusb1_load_firmware(udev, smscore_registry_getmode(devpath)); |
| 424 | } |
| 425 | |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 426 | rc = smsusb_init_device(intf); |
Michael Krufky | 494d24c | 2008-06-14 07:40:41 -0300 | [diff] [blame] | 427 | printk(KERN_INFO "%s rc %d\n", __func__, rc); |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 428 | return rc; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | void smsusb_disconnect(struct usb_interface *intf) |
| 432 | { |
| 433 | smsusb_term_device(intf); |
| 434 | } |
| 435 | |
Steven Toth | 7d18d2e | 2008-05-22 18:07:39 -0300 | [diff] [blame] | 436 | static struct usb_device_id smsusb_id_table [] = { |
Michael Krufky | 73104fb | 2008-06-14 18:27:18 -0300 | [diff] [blame^] | 437 | { USB_DEVICE(USB_VID_SIANO, 0x0010) }, |
| 438 | { USB_DEVICE(USB_VID_SIANO, USB_PID_STELLAR) }, |
| 439 | { USB_DEVICE(USB_VID_SIANO, USB_PID_NOVA_A) }, |
Steven Toth | 7d18d2e | 2008-05-22 18:07:39 -0300 | [diff] [blame] | 440 | { } /* Terminating entry */ |
| 441 | }; |
| 442 | MODULE_DEVICE_TABLE (usb, smsusb_id_table); |
| 443 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 444 | static struct usb_driver smsusb_driver = { |
| 445 | .name = "smsusb", |
| 446 | .probe = smsusb_probe, |
| 447 | .disconnect = smsusb_disconnect, |
| 448 | .id_table = smsusb_id_table, |
| 449 | }; |
| 450 | |
Steven Toth | eae5566 | 2008-05-22 18:04:36 -0300 | [diff] [blame] | 451 | int smsusb_register(void) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 452 | { |
| 453 | int rc = usb_register(&smsusb_driver); |
| 454 | if (rc) |
| 455 | printk(KERN_INFO "usb_register failed. Error number %d\n", rc); |
| 456 | |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 457 | printk(KERN_INFO "%s\n", __func__); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 458 | |
| 459 | return rc; |
| 460 | } |
| 461 | |
Steven Toth | eae5566 | 2008-05-22 18:04:36 -0300 | [diff] [blame] | 462 | void smsusb_unregister(void) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 463 | { |
Steven Toth | 3dd24378 | 2008-05-22 18:01:02 -0300 | [diff] [blame] | 464 | /* Regular USB Cleanup */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 465 | usb_deregister(&smsusb_driver); |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 466 | printk(KERN_INFO "%s\n", __func__); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 467 | } |
| 468 | |