blob: 63c004a25e0b811badb95b5b4d5029bcbc031548 [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
109 smscore_onresponse(dev->coredev, surb->cb);
110 surb->cb = NULL;
Michael Krufky82237412008-06-15 15:14:13 -0300111 } else {
Michael Krufkyeb250942008-06-19 22:07:23 -0300112 sms_err("invalid response "
113 "msglen %d actual %d",
114 phdr->msgLength, urb->actual_length);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300115 }
Uri Shkolnik8f12d0a2009-05-12 11:28:41 -0300116 } else
117 sms_err("error, urb status %d, %d bytes",
118 urb->status, urb->actual_length);
119
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300120
121exit_and_resubmit:
122 smsusb_submit_urb(dev, surb);
123}
124
Michael Krufky0c071f32008-06-21 02:44:02 -0300125static int smsusb_submit_urb(struct smsusb_device_t *dev,
126 struct smsusb_urb_t *surb)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300127{
Michael Krufky82237412008-06-15 15:14:13 -0300128 if (!surb->cb) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300129 surb->cb = smscore_getbuffer(dev->coredev);
Michael Krufky82237412008-06-15 15:14:13 -0300130 if (!surb->cb) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300131 sms_err("smscore_getbuffer(...) returned NULL");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300132 return -ENOMEM;
133 }
134 }
135
136 usb_fill_bulk_urb(
137 &surb->urb,
138 dev->udev,
139 usb_rcvbulkpipe(dev->udev, 0x81),
140 surb->cb->p,
141 dev->buffer_size,
142 smsusb_onresponse,
143 surb
144 );
145 surb->urb.transfer_dma = surb->cb->phys;
146 surb->urb.transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
147
148 return usb_submit_urb(&surb->urb, GFP_ATOMIC);
149}
150
Michael Krufky0c071f32008-06-21 02:44:02 -0300151static void smsusb_stop_streaming(struct smsusb_device_t *dev)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300152{
153 int i;
154
Michael Krufkyfa830e82008-06-15 15:52:43 -0300155 for (i = 0; i < MAX_URBS; i++) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300156 usb_kill_urb(&dev->surbs[i].urb);
157
Michael Krufky82237412008-06-15 15:14:13 -0300158 if (dev->surbs[i].cb) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300159 smscore_putbuffer(dev->coredev, dev->surbs[i].cb);
160 dev->surbs[i].cb = NULL;
161 }
162 }
163}
164
Michael Krufky0c071f32008-06-21 02:44:02 -0300165static int smsusb_start_streaming(struct smsusb_device_t *dev)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300166{
167 int i, rc;
168
Michael Krufkyfa830e82008-06-15 15:52:43 -0300169 for (i = 0; i < MAX_URBS; i++) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300170 rc = smsusb_submit_urb(dev, &dev->surbs[i]);
Michael Krufky82237412008-06-15 15:14:13 -0300171 if (rc < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300172 sms_err("smsusb_submit_urb(...) failed");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300173 smsusb_stop_streaming(dev);
174 break;
175 }
176 }
177
178 return rc;
179}
180
Michael Krufky0c071f32008-06-21 02:44:02 -0300181static int smsusb_sendrequest(void *context, void *buffer, size_t size)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300182{
Michael Krufky18245e12008-06-15 17:52:24 -0300183 struct smsusb_device_t *dev = (struct smsusb_device_t *) context;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300184 int dummy;
185
Uri Shkolnikc7ce8d32009-05-12 08:24:07 -0300186 smsendian_handle_message_header((struct SmsMsgHdr_ST *)buffer);
Michael Krufky82237412008-06-15 15:14:13 -0300187 return usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 2),
188 buffer, size, &dummy, 1000);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300189}
190
Michael Krufky0c071f32008-06-21 02:44:02 -0300191static char *smsusb1_fw_lkup[] = {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300192 "dvbt_stellar_usb.inp",
193 "dvbh_stellar_usb.inp",
194 "tdmb_stellar_usb.inp",
195 "none",
196 "dvbt_bda_stellar_usb.inp",
197};
198
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300199static inline char *sms_get_fw_name(int mode, int board_id)
200{
201 char **fw = sms_get_board(board_id)->fw;
202 return (fw && fw[mode]) ? fw[mode] : smsusb1_fw_lkup[mode];
203}
204
205static int smsusb1_load_firmware(struct usb_device *udev, int id, int board_id)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300206{
207 const struct firmware *fw;
Michael Krufkya83ccdd2008-05-06 03:11:51 -0300208 u8 *fw_buffer;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300209 int rc, dummy;
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300210 char *fw_filename;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300211
Michael Krufky82237412008-06-15 15:14:13 -0300212 if (id < DEVICE_MODE_DVBT || id > DEVICE_MODE_DVBT_BDA) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300213 sms_err("invalid firmware id specified %d", id);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300214 return -EINVAL;
215 }
216
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300217 fw_filename = sms_get_fw_name(id, board_id);
218
219 rc = request_firmware(&fw, fw_filename, &udev->dev);
Michael Krufky82237412008-06-15 15:14:13 -0300220 if (rc < 0) {
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300221 sms_warn("failed to open \"%s\" mode %d, "
222 "trying again with default firmware", fw_filename, id);
223
224 fw_filename = smsusb1_fw_lkup[id];
225 rc = request_firmware(&fw, fw_filename, &udev->dev);
226 if (rc < 0) {
227 sms_warn("failed to open \"%s\" mode %d",
228 fw_filename, id);
229
230 return rc;
231 }
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300232 }
233
234 fw_buffer = kmalloc(fw->size, GFP_KERNEL);
Michael Krufky82237412008-06-15 15:14:13 -0300235 if (fw_buffer) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300236 memcpy(fw_buffer, fw->data, fw->size);
237
Michael Krufky82237412008-06-15 15:14:13 -0300238 rc = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 2),
239 fw_buffer, fw->size, &dummy, 1000);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300240
Michael Krufky0f2a1ee2008-06-28 20:53:45 -0300241 sms_info("sent %zd(%d) bytes, rc %d", fw->size, dummy, rc);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300242
243 kfree(fw_buffer);
Michael Krufky82237412008-06-15 15:14:13 -0300244 } else {
Michael Krufkyeb250942008-06-19 22:07:23 -0300245 sms_err("failed to allocate firmware buffer");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300246 rc = -ENOMEM;
247 }
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300248 sms_info("read FW %s, size=%zd", fw_filename, fw->size);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300249
250 release_firmware(fw);
251
252 return rc;
253}
254
Michael Krufky0c071f32008-06-21 02:44:02 -0300255static void smsusb1_detectmode(void *context, int *mode)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300256{
Michael Krufky18245e12008-06-15 17:52:24 -0300257 char *product_string =
258 ((struct smsusb_device_t *) context)->udev->product;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300259
260 *mode = DEVICE_MODE_NONE;
261
Michael Krufky82237412008-06-15 15:14:13 -0300262 if (!product_string) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300263 product_string = "none";
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300264 sms_err("product string not found");
Michael Krufky82237412008-06-15 15:14:13 -0300265 } else if (strstr(product_string, "DVBH"))
266 *mode = 1;
267 else if (strstr(product_string, "BDA"))
268 *mode = 4;
269 else if (strstr(product_string, "DVBT"))
270 *mode = 0;
271 else if (strstr(product_string, "TDMB"))
272 *mode = 2;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300273
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300274 sms_info("%d \"%s\"", *mode, product_string);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300275}
276
Michael Krufky0c071f32008-06-21 02:44:02 -0300277static int smsusb1_setmode(void *context, int mode)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300278{
Michael Krufky18245e12008-06-15 17:52:24 -0300279 struct SmsMsgHdr_ST Msg = { MSG_SW_RELOAD_REQ, 0, HIF_TASK,
280 sizeof(struct SmsMsgHdr_ST), 0 };
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300281
Michael Krufky82237412008-06-15 15:14:13 -0300282 if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_DVBT_BDA) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300283 sms_err("invalid firmware id specified %d", mode);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300284 return -EINVAL;
285 }
286
287 return smsusb_sendrequest(context, &Msg, sizeof(Msg));
288}
289
Michael Krufky0c071f32008-06-21 02:44:02 -0300290static void smsusb_term_device(struct usb_interface *intf)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300291{
Joe Perches8350e152010-11-30 18:42:07 -0300292 struct smsusb_device_t *dev = usb_get_intfdata(intf);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300293
Michael Krufky82237412008-06-15 15:14:13 -0300294 if (dev) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300295 smsusb_stop_streaming(dev);
296
Michael Krufkyfa830e82008-06-15 15:52:43 -0300297 /* unregister from smscore */
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300298 if (dev->coredev)
299 smscore_unregister_device(dev->coredev);
300
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300301 sms_info("device %p destroyed", dev);
Jesper Juhl08921ac2011-04-21 18:11:25 -0300302 kfree(dev);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300303 }
304
305 usb_set_intfdata(intf, NULL);
306}
307
Michael Krufky0c071f32008-06-21 02:44:02 -0300308static int smsusb_init_device(struct usb_interface *intf, int board_id)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300309{
Michael Krufky18245e12008-06-15 17:52:24 -0300310 struct smsdevice_params_t params;
311 struct smsusb_device_t *dev;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300312 int i, rc;
313
Michael Krufkyfa830e82008-06-15 15:52:43 -0300314 /* create device object */
Michael Krufky18245e12008-06-15 17:52:24 -0300315 dev = kzalloc(sizeof(struct smsusb_device_t), GFP_KERNEL);
Michael Krufky82237412008-06-15 15:14:13 -0300316 if (!dev) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300317 sms_err("kzalloc(sizeof(struct smsusb_device_t) failed");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300318 return -ENOMEM;
319 }
320
321 memset(&params, 0, sizeof(params));
322 usb_set_intfdata(intf, dev);
323 dev->udev = interface_to_usbdev(intf);
324
Michael Krufky2708e882008-06-21 05:24:38 -0300325 params.device_type = sms_get_board(board_id)->type;
Michael Krufky73104fb2008-06-14 18:27:18 -0300326
Michael Krufky2708e882008-06-21 05:24:38 -0300327 switch (params.device_type) {
Michael Krufky1c11d542008-06-18 22:09:55 -0300328 case SMS_STELLAR:
Michael Krufkyf17407a2008-06-14 00:43:26 -0300329 dev->buffer_size = USB1_BUFFER_SIZE;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300330
Michael Krufkyf17407a2008-06-14 00:43:26 -0300331 params.setmode_handler = smsusb1_setmode;
332 params.detectmode_handler = smsusb1_detectmode;
Michael Krufkyf17407a2008-06-14 00:43:26 -0300333 break;
334 default:
Michael Krufky2708e882008-06-21 05:24:38 -0300335 sms_err("Unspecified sms device type!");
336 /* fall-thru */
337 case SMS_NOVA_A0:
338 case SMS_NOVA_B0:
339 case SMS_VEGA:
Michael Krufkyf17407a2008-06-14 00:43:26 -0300340 dev->buffer_size = USB2_BUFFER_SIZE;
Michael Krufky82237412008-06-15 15:14:13 -0300341 dev->response_alignment =
Uri Shkolnikc7ce8d32009-05-12 08:24:07 -0300342 le16_to_cpu(dev->udev->ep_in[1]->desc.wMaxPacketSize) -
343 sizeof(struct SmsMsgHdr_ST);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300344
Michael Krufkyf17407a2008-06-14 00:43:26 -0300345 params.flags |= SMS_DEVICE_FAMILY2;
346 break;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300347 }
348
349 params.device = &dev->udev->dev;
350 params.buffer_size = dev->buffer_size;
351 params.num_buffers = MAX_BUFFERS;
352 params.sendrequest_handler = smsusb_sendrequest;
353 params.context = dev;
Mauro Carvalho Chehab1722f3b2010-08-01 15:30:50 -0300354 usb_make_path(dev->udev, params.devpath, sizeof(params.devpath));
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300355
Michael Krufky82237412008-06-15 15:14:13 -0300356 /* register in smscore */
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300357 rc = smscore_register_device(&params, &dev->coredev);
Michael Krufky82237412008-06-15 15:14:13 -0300358 if (rc < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300359 sms_err("smscore_register_device(...) failed, rc %d", rc);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300360 smsusb_term_device(intf);
361 return rc;
362 }
363
Michael Krufky1c11d542008-06-18 22:09:55 -0300364 smscore_set_board_id(dev->coredev, board_id);
365
Michael Krufkyfa830e82008-06-15 15:52:43 -0300366 /* initialize urbs */
Michael Krufky82237412008-06-15 15:14:13 -0300367 for (i = 0; i < MAX_URBS; i++) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300368 dev->surbs[i].dev = dev;
369 usb_init_urb(&dev->surbs[i].urb);
370 }
371
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300372 sms_info("smsusb_start_streaming(...).");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300373 rc = smsusb_start_streaming(dev);
Michael Krufky82237412008-06-15 15:14:13 -0300374 if (rc < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300375 sms_err("smsusb_start_streaming(...) failed");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300376 smsusb_term_device(intf);
377 return rc;
378 }
379
380 rc = smscore_start_device(dev->coredev);
Michael Krufky82237412008-06-15 15:14:13 -0300381 if (rc < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300382 sms_err("smscore_start_device(...) failed");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300383 smsusb_term_device(intf);
384 return rc;
385 }
386
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300387 sms_info("device %p created", dev);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300388
389 return rc;
390}
391
Márton Németh2184dda2009-12-11 20:05:10 -0300392static int __devinit smsusb_probe(struct usb_interface *intf,
Michael Krufky0c071f32008-06-21 02:44:02 -0300393 const struct usb_device_id *id)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300394{
395 struct usb_device *udev = interface_to_usbdev(intf);
396 char devpath[32];
397 int i, rc;
398
Michael Krufkyf17407a2008-06-14 00:43:26 -0300399 rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x81));
400 rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x02));
401
Michael Krufky82237412008-06-15 15:14:13 -0300402 if (intf->num_altsetting > 0) {
Michael Krufky59bf6b82008-06-15 16:50:11 -0300403 rc = usb_set_interface(
404 udev, intf->cur_altsetting->desc.bInterfaceNumber, 0);
Michael Krufky82237412008-06-15 15:14:13 -0300405 if (rc < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300406 sms_err("usb_set_interface failed, rc %d", rc);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300407 return rc;
408 }
409 }
410
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300411 sms_info("smsusb_probe %d",
Michael Krufky82237412008-06-15 15:14:13 -0300412 intf->cur_altsetting->desc.bInterfaceNumber);
Michael Krufkyfa830e82008-06-15 15:52:43 -0300413 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++)
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300414 sms_info("endpoint %d %02x %02x %d", i,
Michael Krufky82237412008-06-15 15:14:13 -0300415 intf->cur_altsetting->endpoint[i].desc.bEndpointAddress,
416 intf->cur_altsetting->endpoint[i].desc.bmAttributes,
417 intf->cur_altsetting->endpoint[i].desc.wMaxPacketSize);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300418
Michael Krufky82237412008-06-15 15:14:13 -0300419 if ((udev->actconfig->desc.bNumInterfaces == 2) &&
420 (intf->cur_altsetting->desc.bInterfaceNumber == 0)) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300421 sms_err("rom interface 0 is not used");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300422 return -ENODEV;
423 }
424
Michael Krufky82237412008-06-15 15:14:13 -0300425 if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
426 snprintf(devpath, sizeof(devpath), "usb\\%d-%s",
427 udev->bus->busnum, udev->devpath);
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300428 sms_info("stellar device was found.");
Michael Krufky59bf6b82008-06-15 16:50:11 -0300429 return smsusb1_load_firmware(
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300430 udev, smscore_registry_getmode(devpath),
431 id->driver_info);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300432 }
433
Michael Krufky1c11d542008-06-18 22:09:55 -0300434 rc = smsusb_init_device(intf, id->driver_info);
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300435 sms_info("rc %d", rc);
Michael Krufky05860f22008-08-31 17:39:58 -0300436 sms_board_load_modules(id->driver_info);
Michael Krufkyf17407a2008-06-14 00:43:26 -0300437 return rc;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300438}
439
Michael Krufky0c071f32008-06-21 02:44:02 -0300440static void smsusb_disconnect(struct usb_interface *intf)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300441{
442 smsusb_term_device(intf);
443}
444
Uri Shkolnik2f56c342008-11-22 14:08:46 -0300445static int smsusb_suspend(struct usb_interface *intf, pm_message_t msg)
446{
Joe Perches8350e152010-11-30 18:42:07 -0300447 struct smsusb_device_t *dev = usb_get_intfdata(intf);
Michael Krufkyb9391f42008-08-31 16:08:15 -0300448 printk(KERN_INFO "%s: Entering status %d.\n", __func__, msg.event);
Uri Shkolnik2f56c342008-11-22 14:08:46 -0300449 smsusb_stop_streaming(dev);
450 return 0;
451}
452
453static int smsusb_resume(struct usb_interface *intf)
454{
455 int rc, i;
Joe Perches8350e152010-11-30 18:42:07 -0300456 struct smsusb_device_t *dev = usb_get_intfdata(intf);
Uri Shkolnik2f56c342008-11-22 14:08:46 -0300457 struct usb_device *udev = interface_to_usbdev(intf);
458
Michael Krufkyb9391f42008-08-31 16:08:15 -0300459 printk(KERN_INFO "%s: Entering.\n", __func__);
Uri Shkolnik2f56c342008-11-22 14:08:46 -0300460 usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x81));
461 usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x02));
462
463 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++)
464 printk(KERN_INFO "endpoint %d %02x %02x %d\n", i,
465 intf->cur_altsetting->endpoint[i].desc.bEndpointAddress,
466 intf->cur_altsetting->endpoint[i].desc.bmAttributes,
467 intf->cur_altsetting->endpoint[i].desc.wMaxPacketSize);
468
469 if (intf->num_altsetting > 0) {
470 rc = usb_set_interface(udev,
471 intf->cur_altsetting->desc.
472 bInterfaceNumber, 0);
473 if (rc < 0) {
Michael Krufkyb9391f42008-08-31 16:08:15 -0300474 printk(KERN_INFO "%s usb_set_interface failed, "
475 "rc %d\n", __func__, rc);
Uri Shkolnik2f56c342008-11-22 14:08:46 -0300476 return rc;
477 }
478 }
479
480 smsusb_start_streaming(dev);
481 return 0;
482}
483
Márton Németh2184dda2009-12-11 20:05:10 -0300484static const struct usb_device_id smsusb_id_table[] __devinitconst = {
Michael Krufky841a3f02008-08-31 17:03:15 -0300485 { USB_DEVICE(0x187f, 0x0010),
486 .driver_info = SMS1XXX_BOARD_SIANO_STELLAR },
487 { USB_DEVICE(0x187f, 0x0100),
488 .driver_info = SMS1XXX_BOARD_SIANO_STELLAR },
489 { USB_DEVICE(0x187f, 0x0200),
490 .driver_info = SMS1XXX_BOARD_SIANO_NOVA_A },
491 { USB_DEVICE(0x187f, 0x0201),
492 .driver_info = SMS1XXX_BOARD_SIANO_NOVA_B },
493 { USB_DEVICE(0x187f, 0x0300),
494 .driver_info = SMS1XXX_BOARD_SIANO_VEGA },
Michael Krufky841a3f02008-08-31 17:03:15 -0300495 { USB_DEVICE(0x2040, 0x1700),
496 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_CATAMOUNT },
497 { USB_DEVICE(0x2040, 0x1800),
498 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_OKEMO_A },
499 { USB_DEVICE(0x2040, 0x1801),
500 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_OKEMO_B },
501 { USB_DEVICE(0x2040, 0x2000),
502 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
503 { USB_DEVICE(0x2040, 0x2009),
504 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2 },
505 { USB_DEVICE(0x2040, 0x200a),
506 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
507 { USB_DEVICE(0x2040, 0x2010),
508 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
509 { USB_DEVICE(0x2040, 0x2011),
510 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
511 { USB_DEVICE(0x2040, 0x2019),
512 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
513 { USB_DEVICE(0x2040, 0x5500),
514 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
515 { USB_DEVICE(0x2040, 0x5510),
516 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
517 { USB_DEVICE(0x2040, 0x5520),
518 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
519 { USB_DEVICE(0x2040, 0x5530),
520 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
521 { USB_DEVICE(0x2040, 0x5580),
522 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
523 { USB_DEVICE(0x2040, 0x5590),
524 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
Uri Shkolnikd0b661802009-05-19 09:51:41 -0300525 { USB_DEVICE(0x187f, 0x0202),
526 .driver_info = SMS1XXX_BOARD_SIANO_NICE },
527 { USB_DEVICE(0x187f, 0x0301),
528 .driver_info = SMS1XXX_BOARD_SIANO_VENICE },
Michael Krufky78c948a2009-10-21 18:27:29 -0300529 { USB_DEVICE(0x2040, 0xb900),
530 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
531 { USB_DEVICE(0x2040, 0xb910),
532 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
Michael Krufky20d15a22009-11-30 18:22:10 -0300533 { USB_DEVICE(0x2040, 0xb980),
534 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
535 { USB_DEVICE(0x2040, 0xb990),
536 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
Michael Krufky78c948a2009-10-21 18:27:29 -0300537 { USB_DEVICE(0x2040, 0xc000),
538 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
Michael Krufky20d15a22009-11-30 18:22:10 -0300539 { USB_DEVICE(0x2040, 0xc010),
540 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
541 { USB_DEVICE(0x2040, 0xc080),
542 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
543 { USB_DEVICE(0x2040, 0xc090),
544 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
Michael Krufky4d1b58b2012-03-22 13:55:05 -0300545 { USB_DEVICE(0x2040, 0xc0a0),
546 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
Uri Shkolnikd0b661802009-05-19 09:51:41 -0300547 { } /* Terminating entry */
548 };
549
Michael Krufky841a3f02008-08-31 17:03:15 -0300550MODULE_DEVICE_TABLE(usb, smsusb_id_table);
551
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300552static struct usb_driver smsusb_driver = {
Uri Shkolnikdba843a2008-08-31 00:44:04 -0300553 .name = "smsusb",
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300554 .probe = smsusb_probe,
Michael Krufky82237412008-06-15 15:14:13 -0300555 .disconnect = smsusb_disconnect,
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300556 .id_table = smsusb_id_table,
Uri Shkolnik2f56c342008-11-22 14:08:46 -0300557
558 .suspend = smsusb_suspend,
559 .resume = smsusb_resume,
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300560};
561
Greg Kroah-Hartmanecb3b2b2011-11-18 09:46:12 -0800562module_usb_driver(smsusb_driver);
Uri Shkolnike0f14c22008-08-31 00:44:04 -0300563
Uri Shkolnik05a073762009-05-17 09:17:51 -0300564MODULE_DESCRIPTION("Driver for the Siano SMS1xxx USB dongle");
Uri Shkolnike0f14c22008-08-31 00:44:04 -0300565MODULE_AUTHOR("Siano Mobile Silicon, INC. (uris@siano-ms.com)");
566MODULE_LICENSE("GPL");