blob: 2050e4c415b187612d0af6d7357615600b2d8184 [file] [log] [blame]
Uri Shkolnik6d4e6972009-05-12 07:57:54 -03001/****************************************************************
2
3Siano Mobile Silicon, Inc.
4MDTV receiver kernel modules.
5Copyright (C) 2005-2009, Uri Shkolnik, Anatoly Greenblat
6
7This program is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 2 of the License, or
10(at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20****************************************************************/
Steven Toth8d4f9d02008-05-22 18:05:26 -030021
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Paul Gortmaker7a707b82011-07-03 14:03:12 -040027#include <linux/module.h>
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030028
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030029#include "smscoreapi.h"
Michael Krufky1c11d542008-06-18 22:09:55 -030030#include "sms-cards.h"
Uri Shkolnikc7ce8d32009-05-12 08:24:07 -030031#include "smsendian.h"
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030032
Michael Krufky0d02efe2009-02-27 02:42:16 -030033static int sms_dbg;
34module_param_named(debug, sms_dbg, int, 0644);
35MODULE_PARM_DESC(debug, "set debug level (info=1, adv=2 (or-able))");
36
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030037#define USB1_BUFFER_SIZE 0x1000
38#define USB2_BUFFER_SIZE 0x4000
39
40#define MAX_BUFFERS 50
41#define MAX_URBS 10
42
Michael Krufky18245e12008-06-15 17:52:24 -030043struct smsusb_device_t;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030044
Michael Krufky18245e12008-06-15 17:52:24 -030045struct smsusb_urb_t {
46 struct smscore_buffer_t *cb;
47 struct smsusb_device_t *dev;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030048
Michael Krufky18245e12008-06-15 17:52:24 -030049 struct urb urb;
50};
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030051
Michael Krufky18245e12008-06-15 17:52:24 -030052struct smsusb_device_t {
Michael Krufkya83ccdd2008-05-06 03:11:51 -030053 struct usb_device *udev;
Michael Krufky18245e12008-06-15 17:52:24 -030054 struct smscore_device_t *coredev;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030055
Michael Krufky18245e12008-06-15 17:52:24 -030056 struct smsusb_urb_t surbs[MAX_URBS];
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030057
Michael Krufky82237412008-06-15 15:14:13 -030058 int response_alignment;
59 int buffer_size;
Michael Krufky18245e12008-06-15 17:52:24 -030060};
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030061
Michael Krufky0c071f32008-06-21 02:44:02 -030062static int smsusb_submit_urb(struct smsusb_device_t *dev,
63 struct smsusb_urb_t *surb);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030064
Michael Krufky0c071f32008-06-21 02:44:02 -030065static void smsusb_onresponse(struct urb *urb)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030066{
Michael Krufky18245e12008-06-15 17:52:24 -030067 struct smsusb_urb_t *surb = (struct smsusb_urb_t *) urb->context;
68 struct smsusb_device_t *dev = surb->dev;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030069
Uri Shkolnik8f12d0a2009-05-12 11:28:41 -030070 if (urb->status == -ESHUTDOWN) {
71 sms_err("error, urb status %d (-ESHUTDOWN), %d bytes",
Michael Krufkyeb250942008-06-19 22:07:23 -030072 urb->status, urb->actual_length);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030073 return;
74 }
75
Uri Shkolnik8f12d0a2009-05-12 11:28:41 -030076 if ((urb->actual_length > 0) && (urb->status == 0)) {
77 struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *)surb->cb->p;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030078
Uri Shkolnik9c9c68a2009-05-14 16:27:16 -030079 smsendian_handle_message_header(phdr);
Michael Krufky82237412008-06-15 15:14:13 -030080 if (urb->actual_length >= phdr->msgLength) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030081 surb->cb->size = phdr->msgLength;
82
Michael Krufky82237412008-06-15 15:14:13 -030083 if (dev->response_alignment &&
84 (phdr->msgFlags & MSG_HDR_FLAG_SPLIT_MSG)) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030085
Michael Krufky82237412008-06-15 15:14:13 -030086 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) {
Michael Krufkyeb250942008-06-19 22:07:23 -030093 sms_err("invalid response "
94 "msglen %d offset %d "
95 "size %d",
96 phdr->msgLength,
97 surb->cb->offset,
98 urb->actual_length);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030099 goto exit_and_resubmit;
100 }
101
Michael Krufky82237412008-06-15 15:14:13 -0300102 /* move buffer pointer and
103 * copy header to its new location */
Michael Krufky55ad3102008-05-06 03:52:44 -0300104 memcpy((char *) phdr + surb->cb->offset,
Michael Krufky18245e12008-06-15 17:52:24 -0300105 phdr, sizeof(struct SmsMsgHdr_ST));
Michael Krufky82237412008-06-15 15:14:13 -0300106 } else
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300107 surb->cb->offset = 0;
108
Mauro Carvalho Chehab4c3bdb52013-03-09 09:27:39 -0300109 sms_debug("received %s(%d) size: %d",
110 smscore_translate_msg(phdr->msgType),
111 phdr->msgType, phdr->msgLength);
112
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300113 smscore_onresponse(dev->coredev, surb->cb);
114 surb->cb = NULL;
Michael Krufky82237412008-06-15 15:14:13 -0300115 } else {
Michael Krufkyeb250942008-06-19 22:07:23 -0300116 sms_err("invalid response "
117 "msglen %d actual %d",
118 phdr->msgLength, urb->actual_length);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300119 }
Uri Shkolnik8f12d0a2009-05-12 11:28:41 -0300120 } else
121 sms_err("error, urb status %d, %d bytes",
122 urb->status, urb->actual_length);
123
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300124
125exit_and_resubmit:
126 smsusb_submit_urb(dev, surb);
127}
128
Michael Krufky0c071f32008-06-21 02:44:02 -0300129static int smsusb_submit_urb(struct smsusb_device_t *dev,
130 struct smsusb_urb_t *surb)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300131{
Michael Krufky82237412008-06-15 15:14:13 -0300132 if (!surb->cb) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300133 surb->cb = smscore_getbuffer(dev->coredev);
Michael Krufky82237412008-06-15 15:14:13 -0300134 if (!surb->cb) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300135 sms_err("smscore_getbuffer(...) returned NULL");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300136 return -ENOMEM;
137 }
138 }
139
140 usb_fill_bulk_urb(
141 &surb->urb,
142 dev->udev,
143 usb_rcvbulkpipe(dev->udev, 0x81),
144 surb->cb->p,
145 dev->buffer_size,
146 smsusb_onresponse,
147 surb
148 );
149 surb->urb.transfer_dma = surb->cb->phys;
150 surb->urb.transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
151
152 return usb_submit_urb(&surb->urb, GFP_ATOMIC);
153}
154
Michael Krufky0c071f32008-06-21 02:44:02 -0300155static void smsusb_stop_streaming(struct smsusb_device_t *dev)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300156{
157 int i;
158
Michael Krufkyfa830e82008-06-15 15:52:43 -0300159 for (i = 0; i < MAX_URBS; i++) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300160 usb_kill_urb(&dev->surbs[i].urb);
161
Michael Krufky82237412008-06-15 15:14:13 -0300162 if (dev->surbs[i].cb) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300163 smscore_putbuffer(dev->coredev, dev->surbs[i].cb);
164 dev->surbs[i].cb = NULL;
165 }
166 }
167}
168
Michael Krufky0c071f32008-06-21 02:44:02 -0300169static int smsusb_start_streaming(struct smsusb_device_t *dev)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300170{
171 int i, rc;
172
Michael Krufkyfa830e82008-06-15 15:52:43 -0300173 for (i = 0; i < MAX_URBS; i++) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300174 rc = smsusb_submit_urb(dev, &dev->surbs[i]);
Michael Krufky82237412008-06-15 15:14:13 -0300175 if (rc < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300176 sms_err("smsusb_submit_urb(...) failed");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300177 smsusb_stop_streaming(dev);
178 break;
179 }
180 }
181
182 return rc;
183}
184
Michael Krufky0c071f32008-06-21 02:44:02 -0300185static int smsusb_sendrequest(void *context, void *buffer, size_t size)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300186{
Michael Krufky18245e12008-06-15 17:52:24 -0300187 struct smsusb_device_t *dev = (struct smsusb_device_t *) context;
Mauro Carvalho Chehab4c3bdb52013-03-09 09:27:39 -0300188 struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) buffer;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300189 int dummy;
190
Mauro Carvalho Chehab4c3bdb52013-03-09 09:27:39 -0300191 sms_debug("sending %s(%d) size: %d",
192 smscore_translate_msg(phdr->msgType), phdr->msgType,
193 phdr->msgLength);
194
Uri Shkolnikc7ce8d32009-05-12 08:24:07 -0300195 smsendian_handle_message_header((struct SmsMsgHdr_ST *)buffer);
Michael Krufky82237412008-06-15 15:14:13 -0300196 return usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 2),
197 buffer, size, &dummy, 1000);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300198}
199
Michael Krufky0c071f32008-06-21 02:44:02 -0300200static char *smsusb1_fw_lkup[] = {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300201 "dvbt_stellar_usb.inp",
202 "dvbh_stellar_usb.inp",
203 "tdmb_stellar_usb.inp",
204 "none",
205 "dvbt_bda_stellar_usb.inp",
206};
207
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300208static inline char *sms_get_fw_name(int mode, int board_id)
209{
210 char **fw = sms_get_board(board_id)->fw;
211 return (fw && fw[mode]) ? fw[mode] : smsusb1_fw_lkup[mode];
212}
213
214static int smsusb1_load_firmware(struct usb_device *udev, int id, int board_id)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300215{
216 const struct firmware *fw;
Michael Krufkya83ccdd2008-05-06 03:11:51 -0300217 u8 *fw_buffer;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300218 int rc, dummy;
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300219 char *fw_filename;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300220
Michael Krufky82237412008-06-15 15:14:13 -0300221 if (id < DEVICE_MODE_DVBT || id > DEVICE_MODE_DVBT_BDA) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300222 sms_err("invalid firmware id specified %d", id);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300223 return -EINVAL;
224 }
225
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300226 fw_filename = sms_get_fw_name(id, board_id);
227
228 rc = request_firmware(&fw, fw_filename, &udev->dev);
Michael Krufky82237412008-06-15 15:14:13 -0300229 if (rc < 0) {
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300230 sms_warn("failed to open \"%s\" mode %d, "
231 "trying again with default firmware", fw_filename, id);
232
233 fw_filename = smsusb1_fw_lkup[id];
234 rc = request_firmware(&fw, fw_filename, &udev->dev);
235 if (rc < 0) {
236 sms_warn("failed to open \"%s\" mode %d",
237 fw_filename, id);
238
239 return rc;
240 }
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300241 }
242
243 fw_buffer = kmalloc(fw->size, GFP_KERNEL);
Michael Krufky82237412008-06-15 15:14:13 -0300244 if (fw_buffer) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300245 memcpy(fw_buffer, fw->data, fw->size);
246
Michael Krufky82237412008-06-15 15:14:13 -0300247 rc = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 2),
248 fw_buffer, fw->size, &dummy, 1000);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300249
Michael Krufky0f2a1ee2008-06-28 20:53:45 -0300250 sms_info("sent %zd(%d) bytes, rc %d", fw->size, dummy, rc);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300251
252 kfree(fw_buffer);
Michael Krufky82237412008-06-15 15:14:13 -0300253 } else {
Michael Krufkyeb250942008-06-19 22:07:23 -0300254 sms_err("failed to allocate firmware buffer");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300255 rc = -ENOMEM;
256 }
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300257 sms_info("read FW %s, size=%zd", fw_filename, fw->size);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300258
259 release_firmware(fw);
260
261 return rc;
262}
263
Michael Krufky0c071f32008-06-21 02:44:02 -0300264static void smsusb1_detectmode(void *context, int *mode)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300265{
Michael Krufky18245e12008-06-15 17:52:24 -0300266 char *product_string =
267 ((struct smsusb_device_t *) context)->udev->product;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300268
269 *mode = DEVICE_MODE_NONE;
270
Michael Krufky82237412008-06-15 15:14:13 -0300271 if (!product_string) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300272 product_string = "none";
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300273 sms_err("product string not found");
Michael Krufky82237412008-06-15 15:14:13 -0300274 } else if (strstr(product_string, "DVBH"))
275 *mode = 1;
276 else if (strstr(product_string, "BDA"))
277 *mode = 4;
278 else if (strstr(product_string, "DVBT"))
279 *mode = 0;
280 else if (strstr(product_string, "TDMB"))
281 *mode = 2;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300282
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300283 sms_info("%d \"%s\"", *mode, product_string);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300284}
285
Michael Krufky0c071f32008-06-21 02:44:02 -0300286static int smsusb1_setmode(void *context, int mode)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300287{
Michael Krufky18245e12008-06-15 17:52:24 -0300288 struct SmsMsgHdr_ST Msg = { MSG_SW_RELOAD_REQ, 0, HIF_TASK,
289 sizeof(struct SmsMsgHdr_ST), 0 };
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300290
Michael Krufky82237412008-06-15 15:14:13 -0300291 if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_DVBT_BDA) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300292 sms_err("invalid firmware id specified %d", mode);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300293 return -EINVAL;
294 }
295
296 return smsusb_sendrequest(context, &Msg, sizeof(Msg));
297}
298
Michael Krufky0c071f32008-06-21 02:44:02 -0300299static void smsusb_term_device(struct usb_interface *intf)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300300{
Joe Perches8350e152010-11-30 18:42:07 -0300301 struct smsusb_device_t *dev = usb_get_intfdata(intf);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300302
Michael Krufky82237412008-06-15 15:14:13 -0300303 if (dev) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300304 smsusb_stop_streaming(dev);
305
Michael Krufkyfa830e82008-06-15 15:52:43 -0300306 /* unregister from smscore */
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300307 if (dev->coredev)
308 smscore_unregister_device(dev->coredev);
309
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300310 sms_info("device %p destroyed", dev);
Jesper Juhl08921ac2011-04-21 18:11:25 -0300311 kfree(dev);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300312 }
313
314 usb_set_intfdata(intf, NULL);
315}
316
Michael Krufky0c071f32008-06-21 02:44:02 -0300317static int smsusb_init_device(struct usb_interface *intf, int board_id)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300318{
Michael Krufky18245e12008-06-15 17:52:24 -0300319 struct smsdevice_params_t params;
320 struct smsusb_device_t *dev;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300321 int i, rc;
322
Michael Krufkyfa830e82008-06-15 15:52:43 -0300323 /* create device object */
Michael Krufky18245e12008-06-15 17:52:24 -0300324 dev = kzalloc(sizeof(struct smsusb_device_t), GFP_KERNEL);
Michael Krufky82237412008-06-15 15:14:13 -0300325 if (!dev) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300326 sms_err("kzalloc(sizeof(struct smsusb_device_t) failed");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300327 return -ENOMEM;
328 }
329
330 memset(&params, 0, sizeof(params));
331 usb_set_intfdata(intf, dev);
332 dev->udev = interface_to_usbdev(intf);
333
Michael Krufky2708e882008-06-21 05:24:38 -0300334 params.device_type = sms_get_board(board_id)->type;
Michael Krufky73104fb2008-06-14 18:27:18 -0300335
Michael Krufky2708e882008-06-21 05:24:38 -0300336 switch (params.device_type) {
Michael Krufky1c11d542008-06-18 22:09:55 -0300337 case SMS_STELLAR:
Michael Krufkyf17407a2008-06-14 00:43:26 -0300338 dev->buffer_size = USB1_BUFFER_SIZE;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300339
Michael Krufkyf17407a2008-06-14 00:43:26 -0300340 params.setmode_handler = smsusb1_setmode;
341 params.detectmode_handler = smsusb1_detectmode;
Michael Krufkyf17407a2008-06-14 00:43:26 -0300342 break;
343 default:
Michael Krufky2708e882008-06-21 05:24:38 -0300344 sms_err("Unspecified sms device type!");
345 /* fall-thru */
346 case SMS_NOVA_A0:
347 case SMS_NOVA_B0:
348 case SMS_VEGA:
Michael Krufkyf17407a2008-06-14 00:43:26 -0300349 dev->buffer_size = USB2_BUFFER_SIZE;
Michael Krufky82237412008-06-15 15:14:13 -0300350 dev->response_alignment =
Uri Shkolnikc7ce8d32009-05-12 08:24:07 -0300351 le16_to_cpu(dev->udev->ep_in[1]->desc.wMaxPacketSize) -
352 sizeof(struct SmsMsgHdr_ST);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300353
Michael Krufkyf17407a2008-06-14 00:43:26 -0300354 params.flags |= SMS_DEVICE_FAMILY2;
355 break;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300356 }
357
358 params.device = &dev->udev->dev;
359 params.buffer_size = dev->buffer_size;
360 params.num_buffers = MAX_BUFFERS;
361 params.sendrequest_handler = smsusb_sendrequest;
362 params.context = dev;
Mauro Carvalho Chehab1722f3b2010-08-01 15:30:50 -0300363 usb_make_path(dev->udev, params.devpath, sizeof(params.devpath));
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300364
Michael Krufky82237412008-06-15 15:14:13 -0300365 /* register in smscore */
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300366 rc = smscore_register_device(&params, &dev->coredev);
Michael Krufky82237412008-06-15 15:14:13 -0300367 if (rc < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300368 sms_err("smscore_register_device(...) failed, rc %d", rc);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300369 smsusb_term_device(intf);
370 return rc;
371 }
372
Michael Krufky1c11d542008-06-18 22:09:55 -0300373 smscore_set_board_id(dev->coredev, board_id);
374
Michael Krufkyfa830e82008-06-15 15:52:43 -0300375 /* initialize urbs */
Michael Krufky82237412008-06-15 15:14:13 -0300376 for (i = 0; i < MAX_URBS; i++) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300377 dev->surbs[i].dev = dev;
378 usb_init_urb(&dev->surbs[i].urb);
379 }
380
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300381 sms_info("smsusb_start_streaming(...).");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300382 rc = smsusb_start_streaming(dev);
Michael Krufky82237412008-06-15 15:14:13 -0300383 if (rc < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300384 sms_err("smsusb_start_streaming(...) failed");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300385 smsusb_term_device(intf);
386 return rc;
387 }
388
389 rc = smscore_start_device(dev->coredev);
Michael Krufky82237412008-06-15 15:14:13 -0300390 if (rc < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300391 sms_err("smscore_start_device(...) failed");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300392 smsusb_term_device(intf);
393 return rc;
394 }
395
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300396 sms_info("device %p created", dev);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300397
398 return rc;
399}
400
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -0800401static int smsusb_probe(struct usb_interface *intf,
Michael Krufky0c071f32008-06-21 02:44:02 -0300402 const struct usb_device_id *id)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300403{
404 struct usb_device *udev = interface_to_usbdev(intf);
405 char devpath[32];
406 int i, rc;
407
Michael Krufkyf17407a2008-06-14 00:43:26 -0300408 rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x81));
409 rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x02));
410
Michael Krufky82237412008-06-15 15:14:13 -0300411 if (intf->num_altsetting > 0) {
Michael Krufky59bf6b82008-06-15 16:50:11 -0300412 rc = usb_set_interface(
413 udev, intf->cur_altsetting->desc.bInterfaceNumber, 0);
Michael Krufky82237412008-06-15 15:14:13 -0300414 if (rc < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300415 sms_err("usb_set_interface failed, rc %d", rc);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300416 return rc;
417 }
418 }
419
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300420 sms_info("smsusb_probe %d",
Michael Krufky82237412008-06-15 15:14:13 -0300421 intf->cur_altsetting->desc.bInterfaceNumber);
Michael Krufkyfa830e82008-06-15 15:52:43 -0300422 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++)
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300423 sms_info("endpoint %d %02x %02x %d", i,
Michael Krufky82237412008-06-15 15:14:13 -0300424 intf->cur_altsetting->endpoint[i].desc.bEndpointAddress,
425 intf->cur_altsetting->endpoint[i].desc.bmAttributes,
426 intf->cur_altsetting->endpoint[i].desc.wMaxPacketSize);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300427
Michael Krufky82237412008-06-15 15:14:13 -0300428 if ((udev->actconfig->desc.bNumInterfaces == 2) &&
429 (intf->cur_altsetting->desc.bInterfaceNumber == 0)) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300430 sms_err("rom interface 0 is not used");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300431 return -ENODEV;
432 }
433
Michael Krufky82237412008-06-15 15:14:13 -0300434 if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
435 snprintf(devpath, sizeof(devpath), "usb\\%d-%s",
436 udev->bus->busnum, udev->devpath);
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300437 sms_info("stellar device was found.");
Michael Krufky59bf6b82008-06-15 16:50:11 -0300438 return smsusb1_load_firmware(
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300439 udev, smscore_registry_getmode(devpath),
440 id->driver_info);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300441 }
442
Michael Krufky1c11d542008-06-18 22:09:55 -0300443 rc = smsusb_init_device(intf, id->driver_info);
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300444 sms_info("rc %d", rc);
Michael Krufky05860f22008-08-31 17:39:58 -0300445 sms_board_load_modules(id->driver_info);
Michael Krufkyf17407a2008-06-14 00:43:26 -0300446 return rc;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300447}
448
Michael Krufky0c071f32008-06-21 02:44:02 -0300449static void smsusb_disconnect(struct usb_interface *intf)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300450{
451 smsusb_term_device(intf);
452}
453
Uri Shkolnik2f56c342008-11-22 14:08:46 -0300454static int smsusb_suspend(struct usb_interface *intf, pm_message_t msg)
455{
Joe Perches8350e152010-11-30 18:42:07 -0300456 struct smsusb_device_t *dev = usb_get_intfdata(intf);
Michael Krufkyb9391f42008-08-31 16:08:15 -0300457 printk(KERN_INFO "%s: Entering status %d.\n", __func__, msg.event);
Uri Shkolnik2f56c342008-11-22 14:08:46 -0300458 smsusb_stop_streaming(dev);
459 return 0;
460}
461
462static int smsusb_resume(struct usb_interface *intf)
463{
464 int rc, i;
Joe Perches8350e152010-11-30 18:42:07 -0300465 struct smsusb_device_t *dev = usb_get_intfdata(intf);
Uri Shkolnik2f56c342008-11-22 14:08:46 -0300466 struct usb_device *udev = interface_to_usbdev(intf);
467
Michael Krufkyb9391f42008-08-31 16:08:15 -0300468 printk(KERN_INFO "%s: Entering.\n", __func__);
Uri Shkolnik2f56c342008-11-22 14:08:46 -0300469 usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x81));
470 usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x02));
471
472 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++)
473 printk(KERN_INFO "endpoint %d %02x %02x %d\n", i,
474 intf->cur_altsetting->endpoint[i].desc.bEndpointAddress,
475 intf->cur_altsetting->endpoint[i].desc.bmAttributes,
476 intf->cur_altsetting->endpoint[i].desc.wMaxPacketSize);
477
478 if (intf->num_altsetting > 0) {
479 rc = usb_set_interface(udev,
480 intf->cur_altsetting->desc.
481 bInterfaceNumber, 0);
482 if (rc < 0) {
Michael Krufkyb9391f42008-08-31 16:08:15 -0300483 printk(KERN_INFO "%s usb_set_interface failed, "
484 "rc %d\n", __func__, rc);
Uri Shkolnik2f56c342008-11-22 14:08:46 -0300485 return rc;
486 }
487 }
488
489 smsusb_start_streaming(dev);
490 return 0;
491}
492
Greg Kroah-Hartmand04dbd12012-08-17 17:48:26 -0700493static const struct usb_device_id smsusb_id_table[] = {
Michael Krufky841a3f02008-08-31 17:03:15 -0300494 { USB_DEVICE(0x187f, 0x0010),
495 .driver_info = SMS1XXX_BOARD_SIANO_STELLAR },
496 { USB_DEVICE(0x187f, 0x0100),
497 .driver_info = SMS1XXX_BOARD_SIANO_STELLAR },
498 { USB_DEVICE(0x187f, 0x0200),
499 .driver_info = SMS1XXX_BOARD_SIANO_NOVA_A },
500 { USB_DEVICE(0x187f, 0x0201),
501 .driver_info = SMS1XXX_BOARD_SIANO_NOVA_B },
502 { USB_DEVICE(0x187f, 0x0300),
503 .driver_info = SMS1XXX_BOARD_SIANO_VEGA },
Michael Krufky841a3f02008-08-31 17:03:15 -0300504 { USB_DEVICE(0x2040, 0x1700),
505 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_CATAMOUNT },
506 { USB_DEVICE(0x2040, 0x1800),
507 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_OKEMO_A },
508 { USB_DEVICE(0x2040, 0x1801),
509 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_OKEMO_B },
510 { USB_DEVICE(0x2040, 0x2000),
511 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
512 { USB_DEVICE(0x2040, 0x2009),
513 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2 },
514 { USB_DEVICE(0x2040, 0x200a),
515 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
516 { USB_DEVICE(0x2040, 0x2010),
517 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
518 { USB_DEVICE(0x2040, 0x2011),
519 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
520 { USB_DEVICE(0x2040, 0x2019),
521 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
522 { USB_DEVICE(0x2040, 0x5500),
523 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
524 { USB_DEVICE(0x2040, 0x5510),
525 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
526 { USB_DEVICE(0x2040, 0x5520),
527 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
528 { USB_DEVICE(0x2040, 0x5530),
529 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
530 { USB_DEVICE(0x2040, 0x5580),
531 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
532 { USB_DEVICE(0x2040, 0x5590),
533 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
Uri Shkolnikd0b661802009-05-19 09:51:41 -0300534 { USB_DEVICE(0x187f, 0x0202),
535 .driver_info = SMS1XXX_BOARD_SIANO_NICE },
536 { USB_DEVICE(0x187f, 0x0301),
537 .driver_info = SMS1XXX_BOARD_SIANO_VENICE },
Michael Krufky78c948a2009-10-21 18:27:29 -0300538 { USB_DEVICE(0x2040, 0xb900),
539 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
540 { USB_DEVICE(0x2040, 0xb910),
541 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
Michael Krufky20d15a22009-11-30 18:22:10 -0300542 { USB_DEVICE(0x2040, 0xb980),
543 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
544 { USB_DEVICE(0x2040, 0xb990),
545 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
Michael Krufky78c948a2009-10-21 18:27:29 -0300546 { USB_DEVICE(0x2040, 0xc000),
547 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
Michael Krufky20d15a22009-11-30 18:22:10 -0300548 { USB_DEVICE(0x2040, 0xc010),
549 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
550 { USB_DEVICE(0x2040, 0xc080),
551 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
552 { USB_DEVICE(0x2040, 0xc090),
553 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
Michael Krufky4d1b58b2012-03-22 13:55:05 -0300554 { USB_DEVICE(0x2040, 0xc0a0),
555 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
Michael Krufky3e1141e2012-05-25 09:29:12 -0300556 { USB_DEVICE(0x2040, 0xf5a0),
557 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
Uri Shkolnikd0b661802009-05-19 09:51:41 -0300558 { } /* Terminating entry */
559 };
560
Michael Krufky841a3f02008-08-31 17:03:15 -0300561MODULE_DEVICE_TABLE(usb, smsusb_id_table);
562
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300563static struct usb_driver smsusb_driver = {
Uri Shkolnikdba843a2008-08-31 00:44:04 -0300564 .name = "smsusb",
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300565 .probe = smsusb_probe,
Michael Krufky82237412008-06-15 15:14:13 -0300566 .disconnect = smsusb_disconnect,
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300567 .id_table = smsusb_id_table,
Uri Shkolnik2f56c342008-11-22 14:08:46 -0300568
569 .suspend = smsusb_suspend,
570 .resume = smsusb_resume,
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300571};
572
Greg Kroah-Hartmanecb3b2b2011-11-18 09:46:12 -0800573module_usb_driver(smsusb_driver);
Uri Shkolnike0f14c22008-08-31 00:44:04 -0300574
Uri Shkolnik05a073762009-05-17 09:17:51 -0300575MODULE_DESCRIPTION("Driver for the Siano SMS1xxx USB dongle");
Uri Shkolnike0f14c22008-08-31 00:44:04 -0300576MODULE_AUTHOR("Siano Mobile Silicon, INC. (uris@siano-ms.com)");
577MODULE_LICENSE("GPL");