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