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