blob: 87a3c24454b9903e5ad0fdc6aba160cf512091d6 [file] [log] [blame]
Steven Toth8d4f9d02008-05-22 18:05:26 -03001/*
Michael Krufky8f373562008-06-28 17:09:28 -03002 * Driver for the Siano SMS1xxx USB dongle
Steven Toth8d4f9d02008-05-22 18:05:26 -03003 *
Michael Krufky85447062008-05-22 18:29:20 -03004 * author: Anatoly Greenblat
5 *
6 * Copyright (c), 2005-2008 Siano Mobile Silicon, Inc.
Steven Toth8d4f9d02008-05-22 18:05:26 -03007 *
8 * This program is free software; you can redistribute it and/or modify
Michael Krufky09a29b72008-09-03 16:48:17 -03009 * it under the terms of the GNU General Public License version 2 as
Michael Krufky85447062008-05-22 18:29:20 -030010 * published by the Free Software Foundation;
Steven Toth8d4f9d02008-05-22 18:05:26 -030011 *
Michael Krufky85447062008-05-22 18:29:20 -030012 * Software distributed under the License is distributed on an "AS IS"
13 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
Steven Toth8d4f9d02008-05-22 18:05:26 -030014 *
Michael Krufky85447062008-05-22 18:29:20 -030015 * See the GNU General Public License for more details.
Steven Toth8d4f9d02008-05-22 18:05:26 -030016 *
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 Krufky2e5c1ec82008-05-19 18:56:13 -030022#include <linux/kernel.h>
23#include <linux/init.h>
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030024#include <linux/usb.h>
25#include <linux/firmware.h>
26
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030027#include "smscoreapi.h"
Michael Krufky1c11d542008-06-18 22:09:55 -030028#include "sms-cards.h"
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030029
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030030#define USB1_BUFFER_SIZE 0x1000
31#define USB2_BUFFER_SIZE 0x4000
32
33#define MAX_BUFFERS 50
34#define MAX_URBS 10
35
Michael Krufky18245e12008-06-15 17:52:24 -030036struct smsusb_device_t;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030037
Michael Krufky18245e12008-06-15 17:52:24 -030038struct smsusb_urb_t {
39 struct smscore_buffer_t *cb;
40 struct smsusb_device_t *dev;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030041
Michael Krufky18245e12008-06-15 17:52:24 -030042 struct urb urb;
43};
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030044
Michael Krufky18245e12008-06-15 17:52:24 -030045struct smsusb_device_t {
Michael Krufkya83ccdd2008-05-06 03:11:51 -030046 struct usb_device *udev;
Michael Krufky18245e12008-06-15 17:52:24 -030047 struct smscore_device_t *coredev;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030048
Michael Krufky18245e12008-06-15 17:52:24 -030049 struct smsusb_urb_t surbs[MAX_URBS];
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030050
Michael Krufky82237412008-06-15 15:14:13 -030051 int response_alignment;
52 int buffer_size;
Michael Krufky18245e12008-06-15 17:52:24 -030053};
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030054
Michael Krufky0c071f32008-06-21 02:44:02 -030055static int smsusb_submit_urb(struct smsusb_device_t *dev,
56 struct smsusb_urb_t *surb);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030057
Michael Krufky0c071f32008-06-21 02:44:02 -030058static void smsusb_onresponse(struct urb *urb)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030059{
Michael Krufky18245e12008-06-15 17:52:24 -030060 struct smsusb_urb_t *surb = (struct smsusb_urb_t *) urb->context;
61 struct smsusb_device_t *dev = surb->dev;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030062
Michael Krufky82237412008-06-15 15:14:13 -030063 if (urb->status < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -030064 sms_err("error, urb status %d, %d bytes",
65 urb->status, urb->actual_length);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030066 return;
67 }
68
Michael Krufky82237412008-06-15 15:14:13 -030069 if (urb->actual_length > 0) {
Michael Krufky18245e12008-06-15 17:52:24 -030070 struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) surb->cb->p;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030071
Michael Krufky82237412008-06-15 15:14:13 -030072 if (urb->actual_length >= phdr->msgLength) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030073 surb->cb->size = phdr->msgLength;
74
Michael Krufky82237412008-06-15 15:14:13 -030075 if (dev->response_alignment &&
76 (phdr->msgFlags & MSG_HDR_FLAG_SPLIT_MSG)) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030077
Michael Krufky82237412008-06-15 15:14:13 -030078 surb->cb->offset =
79 dev->response_alignment +
80 ((phdr->msgFlags >> 8) & 3);
81
82 /* sanity check */
83 if (((int) phdr->msgLength +
84 surb->cb->offset) > urb->actual_length) {
Michael Krufkyeb250942008-06-19 22:07:23 -030085 sms_err("invalid response "
86 "msglen %d offset %d "
87 "size %d",
88 phdr->msgLength,
89 surb->cb->offset,
90 urb->actual_length);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030091 goto exit_and_resubmit;
92 }
93
Michael Krufky82237412008-06-15 15:14:13 -030094 /* move buffer pointer and
95 * copy header to its new location */
Michael Krufky55ad3102008-05-06 03:52:44 -030096 memcpy((char *) phdr + surb->cb->offset,
Michael Krufky18245e12008-06-15 17:52:24 -030097 phdr, sizeof(struct SmsMsgHdr_ST));
Michael Krufky82237412008-06-15 15:14:13 -030098 } else
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030099 surb->cb->offset = 0;
100
101 smscore_onresponse(dev->coredev, surb->cb);
102 surb->cb = NULL;
Michael Krufky82237412008-06-15 15:14:13 -0300103 } else {
Michael Krufkyeb250942008-06-19 22:07:23 -0300104 sms_err("invalid response "
105 "msglen %d actual %d",
106 phdr->msgLength, urb->actual_length);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300107 }
108 }
109
110exit_and_resubmit:
111 smsusb_submit_urb(dev, surb);
112}
113
Michael Krufky0c071f32008-06-21 02:44:02 -0300114static int smsusb_submit_urb(struct smsusb_device_t *dev,
115 struct smsusb_urb_t *surb)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300116{
Michael Krufky82237412008-06-15 15:14:13 -0300117 if (!surb->cb) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300118 surb->cb = smscore_getbuffer(dev->coredev);
Michael Krufky82237412008-06-15 15:14:13 -0300119 if (!surb->cb) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300120 sms_err("smscore_getbuffer(...) returned NULL");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300121 return -ENOMEM;
122 }
123 }
124
125 usb_fill_bulk_urb(
126 &surb->urb,
127 dev->udev,
128 usb_rcvbulkpipe(dev->udev, 0x81),
129 surb->cb->p,
130 dev->buffer_size,
131 smsusb_onresponse,
132 surb
133 );
134 surb->urb.transfer_dma = surb->cb->phys;
135 surb->urb.transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
136
137 return usb_submit_urb(&surb->urb, GFP_ATOMIC);
138}
139
Michael Krufky0c071f32008-06-21 02:44:02 -0300140static void smsusb_stop_streaming(struct smsusb_device_t *dev)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300141{
142 int i;
143
Michael Krufkyfa830e82008-06-15 15:52:43 -0300144 for (i = 0; i < MAX_URBS; i++) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300145 usb_kill_urb(&dev->surbs[i].urb);
146
Michael Krufky82237412008-06-15 15:14:13 -0300147 if (dev->surbs[i].cb) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300148 smscore_putbuffer(dev->coredev, dev->surbs[i].cb);
149 dev->surbs[i].cb = NULL;
150 }
151 }
152}
153
Michael Krufky0c071f32008-06-21 02:44:02 -0300154static int smsusb_start_streaming(struct smsusb_device_t *dev)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300155{
156 int i, rc;
157
Michael Krufkyfa830e82008-06-15 15:52:43 -0300158 for (i = 0; i < MAX_URBS; i++) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300159 rc = smsusb_submit_urb(dev, &dev->surbs[i]);
Michael Krufky82237412008-06-15 15:14:13 -0300160 if (rc < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300161 sms_err("smsusb_submit_urb(...) failed");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300162 smsusb_stop_streaming(dev);
163 break;
164 }
165 }
166
167 return rc;
168}
169
Michael Krufky0c071f32008-06-21 02:44:02 -0300170static int smsusb_sendrequest(void *context, void *buffer, size_t size)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300171{
Michael Krufky18245e12008-06-15 17:52:24 -0300172 struct smsusb_device_t *dev = (struct smsusb_device_t *) context;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300173 int dummy;
174
Michael Krufky82237412008-06-15 15:14:13 -0300175 return usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 2),
176 buffer, size, &dummy, 1000);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300177}
178
Michael Krufky0c071f32008-06-21 02:44:02 -0300179static char *smsusb1_fw_lkup[] = {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300180 "dvbt_stellar_usb.inp",
181 "dvbh_stellar_usb.inp",
182 "tdmb_stellar_usb.inp",
183 "none",
184 "dvbt_bda_stellar_usb.inp",
185};
186
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300187static inline char *sms_get_fw_name(int mode, int board_id)
188{
189 char **fw = sms_get_board(board_id)->fw;
190 return (fw && fw[mode]) ? fw[mode] : smsusb1_fw_lkup[mode];
191}
192
193static int smsusb1_load_firmware(struct usb_device *udev, int id, int board_id)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300194{
195 const struct firmware *fw;
Michael Krufkya83ccdd2008-05-06 03:11:51 -0300196 u8 *fw_buffer;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300197 int rc, dummy;
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300198 char *fw_filename;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300199
Michael Krufky82237412008-06-15 15:14:13 -0300200 if (id < DEVICE_MODE_DVBT || id > DEVICE_MODE_DVBT_BDA) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300201 sms_err("invalid firmware id specified %d", id);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300202 return -EINVAL;
203 }
204
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300205 fw_filename = sms_get_fw_name(id, board_id);
206
207 rc = request_firmware(&fw, fw_filename, &udev->dev);
Michael Krufky82237412008-06-15 15:14:13 -0300208 if (rc < 0) {
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300209 sms_warn("failed to open \"%s\" mode %d, "
210 "trying again with default firmware", fw_filename, id);
211
212 fw_filename = smsusb1_fw_lkup[id];
213 rc = request_firmware(&fw, fw_filename, &udev->dev);
214 if (rc < 0) {
215 sms_warn("failed to open \"%s\" mode %d",
216 fw_filename, id);
217
218 return rc;
219 }
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300220 }
221
222 fw_buffer = kmalloc(fw->size, GFP_KERNEL);
Michael Krufky82237412008-06-15 15:14:13 -0300223 if (fw_buffer) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300224 memcpy(fw_buffer, fw->data, fw->size);
225
Michael Krufky82237412008-06-15 15:14:13 -0300226 rc = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 2),
227 fw_buffer, fw->size, &dummy, 1000);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300228
Michael Krufky0f2a1ee2008-06-28 20:53:45 -0300229 sms_info("sent %zd(%d) bytes, rc %d", fw->size, dummy, rc);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300230
231 kfree(fw_buffer);
Michael Krufky82237412008-06-15 15:14:13 -0300232 } else {
Michael Krufkyeb250942008-06-19 22:07:23 -0300233 sms_err("failed to allocate firmware buffer");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300234 rc = -ENOMEM;
235 }
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300236 sms_info("read FW %s, size=%zd", fw_filename, fw->size);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300237
238 release_firmware(fw);
239
240 return rc;
241}
242
Michael Krufky0c071f32008-06-21 02:44:02 -0300243static void smsusb1_detectmode(void *context, int *mode)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300244{
Michael Krufky18245e12008-06-15 17:52:24 -0300245 char *product_string =
246 ((struct smsusb_device_t *) context)->udev->product;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300247
248 *mode = DEVICE_MODE_NONE;
249
Michael Krufky82237412008-06-15 15:14:13 -0300250 if (!product_string) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300251 product_string = "none";
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300252 sms_err("product string not found");
Michael Krufky82237412008-06-15 15:14:13 -0300253 } else if (strstr(product_string, "DVBH"))
254 *mode = 1;
255 else if (strstr(product_string, "BDA"))
256 *mode = 4;
257 else if (strstr(product_string, "DVBT"))
258 *mode = 0;
259 else if (strstr(product_string, "TDMB"))
260 *mode = 2;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300261
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300262 sms_info("%d \"%s\"", *mode, product_string);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300263}
264
Michael Krufky0c071f32008-06-21 02:44:02 -0300265static int smsusb1_setmode(void *context, int mode)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300266{
Michael Krufky18245e12008-06-15 17:52:24 -0300267 struct SmsMsgHdr_ST Msg = { MSG_SW_RELOAD_REQ, 0, HIF_TASK,
268 sizeof(struct SmsMsgHdr_ST), 0 };
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300269
Michael Krufky82237412008-06-15 15:14:13 -0300270 if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_DVBT_BDA) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300271 sms_err("invalid firmware id specified %d", mode);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300272 return -EINVAL;
273 }
274
275 return smsusb_sendrequest(context, &Msg, sizeof(Msg));
276}
277
Michael Krufky0c071f32008-06-21 02:44:02 -0300278static void smsusb_term_device(struct usb_interface *intf)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300279{
Michael Krufky18245e12008-06-15 17:52:24 -0300280 struct smsusb_device_t *dev =
281 (struct smsusb_device_t *) usb_get_intfdata(intf);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300282
Michael Krufky82237412008-06-15 15:14:13 -0300283 if (dev) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300284 smsusb_stop_streaming(dev);
285
Michael Krufkyfa830e82008-06-15 15:52:43 -0300286 /* unregister from smscore */
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300287 if (dev->coredev)
288 smscore_unregister_device(dev->coredev);
289
290 kfree(dev);
291
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300292 sms_info("device %p destroyed", dev);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300293 }
294
295 usb_set_intfdata(intf, NULL);
296}
297
Michael Krufky0c071f32008-06-21 02:44:02 -0300298static int smsusb_init_device(struct usb_interface *intf, int board_id)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300299{
Michael Krufky18245e12008-06-15 17:52:24 -0300300 struct smsdevice_params_t params;
301 struct smsusb_device_t *dev;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300302 int i, rc;
303
Michael Krufkyfa830e82008-06-15 15:52:43 -0300304 /* create device object */
Michael Krufky18245e12008-06-15 17:52:24 -0300305 dev = kzalloc(sizeof(struct smsusb_device_t), GFP_KERNEL);
Michael Krufky82237412008-06-15 15:14:13 -0300306 if (!dev) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300307 sms_err("kzalloc(sizeof(struct smsusb_device_t) failed");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300308 return -ENOMEM;
309 }
310
311 memset(&params, 0, sizeof(params));
312 usb_set_intfdata(intf, dev);
313 dev->udev = interface_to_usbdev(intf);
314
Michael Krufky2708e882008-06-21 05:24:38 -0300315 params.device_type = sms_get_board(board_id)->type;
Michael Krufky73104fb2008-06-14 18:27:18 -0300316
Michael Krufky2708e882008-06-21 05:24:38 -0300317 switch (params.device_type) {
Michael Krufky1c11d542008-06-18 22:09:55 -0300318 case SMS_STELLAR:
Michael Krufkyf17407a2008-06-14 00:43:26 -0300319 dev->buffer_size = USB1_BUFFER_SIZE;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300320
Michael Krufkyf17407a2008-06-14 00:43:26 -0300321 params.setmode_handler = smsusb1_setmode;
322 params.detectmode_handler = smsusb1_detectmode;
Michael Krufkyf17407a2008-06-14 00:43:26 -0300323 break;
324 default:
Michael Krufky2708e882008-06-21 05:24:38 -0300325 sms_err("Unspecified sms device type!");
326 /* fall-thru */
327 case SMS_NOVA_A0:
328 case SMS_NOVA_B0:
329 case SMS_VEGA:
Michael Krufkyf17407a2008-06-14 00:43:26 -0300330 dev->buffer_size = USB2_BUFFER_SIZE;
Michael Krufky82237412008-06-15 15:14:13 -0300331 dev->response_alignment =
332 dev->udev->ep_in[1]->desc.wMaxPacketSize -
Michael Krufky18245e12008-06-15 17:52:24 -0300333 sizeof(struct SmsMsgHdr_ST);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300334
Michael Krufkyf17407a2008-06-14 00:43:26 -0300335 params.flags |= SMS_DEVICE_FAMILY2;
336 break;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300337 }
338
339 params.device = &dev->udev->dev;
340 params.buffer_size = dev->buffer_size;
341 params.num_buffers = MAX_BUFFERS;
342 params.sendrequest_handler = smsusb_sendrequest;
343 params.context = dev;
Michael Krufky82237412008-06-15 15:14:13 -0300344 snprintf(params.devpath, sizeof(params.devpath),
345 "usb\\%d-%s", dev->udev->bus->busnum, dev->udev->devpath);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300346
Michael Krufky82237412008-06-15 15:14:13 -0300347 /* register in smscore */
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300348 rc = smscore_register_device(&params, &dev->coredev);
Michael Krufky82237412008-06-15 15:14:13 -0300349 if (rc < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300350 sms_err("smscore_register_device(...) failed, rc %d", rc);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300351 smsusb_term_device(intf);
352 return rc;
353 }
354
Michael Krufky1c11d542008-06-18 22:09:55 -0300355 smscore_set_board_id(dev->coredev, board_id);
356
Michael Krufkyfa830e82008-06-15 15:52:43 -0300357 /* initialize urbs */
Michael Krufky82237412008-06-15 15:14:13 -0300358 for (i = 0; i < MAX_URBS; i++) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300359 dev->surbs[i].dev = dev;
360 usb_init_urb(&dev->surbs[i].urb);
361 }
362
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300363 sms_info("smsusb_start_streaming(...).");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300364 rc = smsusb_start_streaming(dev);
Michael Krufky82237412008-06-15 15:14:13 -0300365 if (rc < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300366 sms_err("smsusb_start_streaming(...) failed");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300367 smsusb_term_device(intf);
368 return rc;
369 }
370
371 rc = smscore_start_device(dev->coredev);
Michael Krufky82237412008-06-15 15:14:13 -0300372 if (rc < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300373 sms_err("smscore_start_device(...) failed");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300374 smsusb_term_device(intf);
375 return rc;
376 }
377
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300378 sms_info("device %p created", dev);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300379
380 return rc;
381}
382
Michael Krufky0c071f32008-06-21 02:44:02 -0300383static int smsusb_probe(struct usb_interface *intf,
384 const struct usb_device_id *id)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300385{
386 struct usb_device *udev = interface_to_usbdev(intf);
387 char devpath[32];
388 int i, rc;
389
Michael Krufkyf17407a2008-06-14 00:43:26 -0300390 rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x81));
391 rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x02));
392
Michael Krufky82237412008-06-15 15:14:13 -0300393 if (intf->num_altsetting > 0) {
Michael Krufky59bf6b82008-06-15 16:50:11 -0300394 rc = usb_set_interface(
395 udev, intf->cur_altsetting->desc.bInterfaceNumber, 0);
Michael Krufky82237412008-06-15 15:14:13 -0300396 if (rc < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300397 sms_err("usb_set_interface failed, rc %d", rc);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300398 return rc;
399 }
400 }
401
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300402 sms_info("smsusb_probe %d",
Michael Krufky82237412008-06-15 15:14:13 -0300403 intf->cur_altsetting->desc.bInterfaceNumber);
Michael Krufkyfa830e82008-06-15 15:52:43 -0300404 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++)
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300405 sms_info("endpoint %d %02x %02x %d", i,
Michael Krufky82237412008-06-15 15:14:13 -0300406 intf->cur_altsetting->endpoint[i].desc.bEndpointAddress,
407 intf->cur_altsetting->endpoint[i].desc.bmAttributes,
408 intf->cur_altsetting->endpoint[i].desc.wMaxPacketSize);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300409
Michael Krufky82237412008-06-15 15:14:13 -0300410 if ((udev->actconfig->desc.bNumInterfaces == 2) &&
411 (intf->cur_altsetting->desc.bInterfaceNumber == 0)) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300412 sms_err("rom interface 0 is not used");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300413 return -ENODEV;
414 }
415
Michael Krufky82237412008-06-15 15:14:13 -0300416 if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
417 snprintf(devpath, sizeof(devpath), "usb\\%d-%s",
418 udev->bus->busnum, udev->devpath);
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300419 sms_info("stellar device was found.");
Michael Krufky59bf6b82008-06-15 16:50:11 -0300420 return smsusb1_load_firmware(
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300421 udev, smscore_registry_getmode(devpath),
422 id->driver_info);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300423 }
424
Michael Krufky1c11d542008-06-18 22:09:55 -0300425 rc = smsusb_init_device(intf, id->driver_info);
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300426 sms_info("rc %d", rc);
Michael Krufkyf17407a2008-06-14 00:43:26 -0300427 return rc;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300428}
429
Michael Krufky0c071f32008-06-21 02:44:02 -0300430static void smsusb_disconnect(struct usb_interface *intf)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300431{
432 smsusb_term_device(intf);
433}
434
435static struct usb_driver smsusb_driver = {
Michael Krufkyeb383bd2008-06-29 01:33:23 -0300436 .name = "sms1xxx",
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300437 .probe = smsusb_probe,
Michael Krufky82237412008-06-15 15:14:13 -0300438 .disconnect = smsusb_disconnect,
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300439 .id_table = smsusb_id_table,
440};
441
Steven Totheae55662008-05-22 18:04:36 -0300442int smsusb_register(void)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300443{
444 int rc = usb_register(&smsusb_driver);
445 if (rc)
Michael Krufkyeb250942008-06-19 22:07:23 -0300446 sms_err("usb_register failed. Error number %d", rc);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300447
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300448 sms_debug("");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300449
450 return rc;
451}
452
Steven Totheae55662008-05-22 18:04:36 -0300453void smsusb_unregister(void)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300454{
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300455 sms_debug("");
Steven Toth3dd243782008-05-22 18:01:02 -0300456 /* Regular USB Cleanup */
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300457 usb_deregister(&smsusb_driver);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300458}
459