blob: acd3d1e82e03e18f70b6ac5bb3682e7cd1f77f79 [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
Mauro Carvalho Chehab05f0ffb2013-03-06 09:53:50 -030038#define USB2_BUFFER_SIZE 0x2000
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030039
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
Mauro Carvalho Chehab05f0ffb2013-03-06 09:53:50 -030045enum smsusb_state {
46 SMSUSB_DISCONNECTED,
47 SMSUSB_SUSPENDED,
48 SMSUSB_ACTIVE
49};
50
Michael Krufky18245e12008-06-15 17:52:24 -030051struct smsusb_urb_t {
Mauro Carvalho Chehab05f0ffb2013-03-06 09:53:50 -030052 struct list_head entry;
Michael Krufky18245e12008-06-15 17:52:24 -030053 struct smscore_buffer_t *cb;
Mauro Carvalho Chehab05f0ffb2013-03-06 09:53:50 -030054 struct smsusb_device_t *dev;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030055
Michael Krufky18245e12008-06-15 17:52:24 -030056 struct urb urb;
57};
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030058
Michael Krufky18245e12008-06-15 17:52:24 -030059struct smsusb_device_t {
Michael Krufkya83ccdd2008-05-06 03:11:51 -030060 struct usb_device *udev;
Michael Krufky18245e12008-06-15 17:52:24 -030061 struct smscore_device_t *coredev;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030062
Michael Krufky18245e12008-06-15 17:52:24 -030063 struct smsusb_urb_t surbs[MAX_URBS];
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030064
Michael Krufky82237412008-06-15 15:14:13 -030065 int response_alignment;
66 int buffer_size;
Mauro Carvalho Chehab05f0ffb2013-03-06 09:53:50 -030067
68 unsigned char in_ep;
69 unsigned char out_ep;
70 enum smsusb_state state;
Michael Krufky18245e12008-06-15 17:52:24 -030071};
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030072
Michael Krufky0c071f32008-06-21 02:44:02 -030073static int smsusb_submit_urb(struct smsusb_device_t *dev,
74 struct smsusb_urb_t *surb);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030075
Mauro Carvalho Chehab05f0ffb2013-03-06 09:53:50 -030076/**
77 * Completing URB's callback handler - top half (interrupt context)
78 * adds completing sms urb to the global surbs list and activtes the worker
79 * thread the surb
80 * IMPORTANT - blocking functions must not be called from here !!!
81
82 * @param urb pointer to a completing urb object
83 */
Michael Krufky0c071f32008-06-21 02:44:02 -030084static void smsusb_onresponse(struct urb *urb)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030085{
Michael Krufky18245e12008-06-15 17:52:24 -030086 struct smsusb_urb_t *surb = (struct smsusb_urb_t *) urb->context;
87 struct smsusb_device_t *dev = surb->dev;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030088
Uri Shkolnik8f12d0a2009-05-12 11:28:41 -030089 if (urb->status == -ESHUTDOWN) {
90 sms_err("error, urb status %d (-ESHUTDOWN), %d bytes",
Michael Krufkyeb250942008-06-19 22:07:23 -030091 urb->status, urb->actual_length);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030092 return;
93 }
94
Uri Shkolnik8f12d0a2009-05-12 11:28:41 -030095 if ((urb->actual_length > 0) && (urb->status == 0)) {
96 struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *)surb->cb->p;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -030097
Uri Shkolnik9c9c68a2009-05-14 16:27:16 -030098 smsendian_handle_message_header(phdr);
Michael Krufky82237412008-06-15 15:14:13 -030099 if (urb->actual_length >= phdr->msgLength) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300100 surb->cb->size = phdr->msgLength;
101
Michael Krufky82237412008-06-15 15:14:13 -0300102 if (dev->response_alignment &&
103 (phdr->msgFlags & MSG_HDR_FLAG_SPLIT_MSG)) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300104
Michael Krufky82237412008-06-15 15:14:13 -0300105 surb->cb->offset =
106 dev->response_alignment +
107 ((phdr->msgFlags >> 8) & 3);
108
109 /* sanity check */
110 if (((int) phdr->msgLength +
111 surb->cb->offset) > urb->actual_length) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300112 sms_err("invalid response "
113 "msglen %d offset %d "
114 "size %d",
115 phdr->msgLength,
116 surb->cb->offset,
117 urb->actual_length);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300118 goto exit_and_resubmit;
119 }
120
Michael Krufky82237412008-06-15 15:14:13 -0300121 /* move buffer pointer and
122 * copy header to its new location */
Michael Krufky55ad3102008-05-06 03:52:44 -0300123 memcpy((char *) phdr + surb->cb->offset,
Michael Krufky18245e12008-06-15 17:52:24 -0300124 phdr, sizeof(struct SmsMsgHdr_ST));
Michael Krufky82237412008-06-15 15:14:13 -0300125 } else
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300126 surb->cb->offset = 0;
127
Mauro Carvalho Chehab4c3bdb52013-03-09 09:27:39 -0300128 sms_debug("received %s(%d) size: %d",
129 smscore_translate_msg(phdr->msgType),
130 phdr->msgType, phdr->msgLength);
131
Mauro Carvalho Chehab80ccb512013-03-09 11:34:56 -0300132 smsendian_handle_rx_message((struct SmsMsgData_ST *) phdr);
133
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300134 smscore_onresponse(dev->coredev, surb->cb);
135 surb->cb = NULL;
Michael Krufky82237412008-06-15 15:14:13 -0300136 } else {
Michael Krufkyeb250942008-06-19 22:07:23 -0300137 sms_err("invalid response "
138 "msglen %d actual %d",
139 phdr->msgLength, urb->actual_length);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300140 }
Uri Shkolnik8f12d0a2009-05-12 11:28:41 -0300141 } else
142 sms_err("error, urb status %d, %d bytes",
143 urb->status, urb->actual_length);
144
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300145
146exit_and_resubmit:
147 smsusb_submit_urb(dev, surb);
148}
149
Michael Krufky0c071f32008-06-21 02:44:02 -0300150static int smsusb_submit_urb(struct smsusb_device_t *dev,
151 struct smsusb_urb_t *surb)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300152{
Michael Krufky82237412008-06-15 15:14:13 -0300153 if (!surb->cb) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300154 surb->cb = smscore_getbuffer(dev->coredev);
Michael Krufky82237412008-06-15 15:14:13 -0300155 if (!surb->cb) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300156 sms_err("smscore_getbuffer(...) returned NULL");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300157 return -ENOMEM;
158 }
159 }
160
161 usb_fill_bulk_urb(
162 &surb->urb,
163 dev->udev,
Mauro Carvalho Chehab05f0ffb2013-03-06 09:53:50 -0300164 usb_rcvbulkpipe(dev->udev, dev->in_ep),
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300165 surb->cb->p,
166 dev->buffer_size,
167 smsusb_onresponse,
168 surb
169 );
170 surb->urb.transfer_dma = surb->cb->phys;
171 surb->urb.transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
172
173 return usb_submit_urb(&surb->urb, GFP_ATOMIC);
174}
175
Michael Krufky0c071f32008-06-21 02:44:02 -0300176static void smsusb_stop_streaming(struct smsusb_device_t *dev)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300177{
178 int i;
179
Michael Krufkyfa830e82008-06-15 15:52:43 -0300180 for (i = 0; i < MAX_URBS; i++) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300181 usb_kill_urb(&dev->surbs[i].urb);
182
Michael Krufky82237412008-06-15 15:14:13 -0300183 if (dev->surbs[i].cb) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300184 smscore_putbuffer(dev->coredev, dev->surbs[i].cb);
185 dev->surbs[i].cb = NULL;
186 }
187 }
188}
189
Michael Krufky0c071f32008-06-21 02:44:02 -0300190static int smsusb_start_streaming(struct smsusb_device_t *dev)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300191{
192 int i, rc;
193
Michael Krufkyfa830e82008-06-15 15:52:43 -0300194 for (i = 0; i < MAX_URBS; i++) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300195 rc = smsusb_submit_urb(dev, &dev->surbs[i]);
Michael Krufky82237412008-06-15 15:14:13 -0300196 if (rc < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300197 sms_err("smsusb_submit_urb(...) failed");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300198 smsusb_stop_streaming(dev);
199 break;
200 }
201 }
202
203 return rc;
204}
205
Michael Krufky0c071f32008-06-21 02:44:02 -0300206static int smsusb_sendrequest(void *context, void *buffer, size_t size)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300207{
Michael Krufky18245e12008-06-15 17:52:24 -0300208 struct smsusb_device_t *dev = (struct smsusb_device_t *) context;
Mauro Carvalho Chehab4c3bdb52013-03-09 09:27:39 -0300209 struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) buffer;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300210 int dummy;
211
Mauro Carvalho Chehab80ccb512013-03-09 11:34:56 -0300212 if (dev->state != SMSUSB_ACTIVE)
213 return -ENOENT;
214
Mauro Carvalho Chehab4c3bdb52013-03-09 09:27:39 -0300215 sms_debug("sending %s(%d) size: %d",
216 smscore_translate_msg(phdr->msgType), phdr->msgType,
217 phdr->msgLength);
218
Mauro Carvalho Chehab80ccb512013-03-09 11:34:56 -0300219 smsendian_handle_tx_message((struct SmsMsgData_ST *) phdr);
Uri Shkolnikc7ce8d32009-05-12 08:24:07 -0300220 smsendian_handle_message_header((struct SmsMsgHdr_ST *)buffer);
Michael Krufky82237412008-06-15 15:14:13 -0300221 return usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 2),
222 buffer, size, &dummy, 1000);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300223}
224
Michael Krufky0c071f32008-06-21 02:44:02 -0300225static char *smsusb1_fw_lkup[] = {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300226 "dvbt_stellar_usb.inp",
227 "dvbh_stellar_usb.inp",
228 "tdmb_stellar_usb.inp",
229 "none",
230 "dvbt_bda_stellar_usb.inp",
231};
232
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300233static inline char *sms_get_fw_name(int mode, int board_id)
234{
235 char **fw = sms_get_board(board_id)->fw;
236 return (fw && fw[mode]) ? fw[mode] : smsusb1_fw_lkup[mode];
237}
238
239static int smsusb1_load_firmware(struct usb_device *udev, int id, int board_id)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300240{
241 const struct firmware *fw;
Michael Krufkya83ccdd2008-05-06 03:11:51 -0300242 u8 *fw_buffer;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300243 int rc, dummy;
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300244 char *fw_filename;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300245
Michael Krufky82237412008-06-15 15:14:13 -0300246 if (id < DEVICE_MODE_DVBT || id > DEVICE_MODE_DVBT_BDA) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300247 sms_err("invalid firmware id specified %d", id);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300248 return -EINVAL;
249 }
250
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300251 fw_filename = sms_get_fw_name(id, board_id);
252
253 rc = request_firmware(&fw, fw_filename, &udev->dev);
Michael Krufky82237412008-06-15 15:14:13 -0300254 if (rc < 0) {
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300255 sms_warn("failed to open \"%s\" mode %d, "
256 "trying again with default firmware", fw_filename, id);
257
258 fw_filename = smsusb1_fw_lkup[id];
259 rc = request_firmware(&fw, fw_filename, &udev->dev);
260 if (rc < 0) {
261 sms_warn("failed to open \"%s\" mode %d",
262 fw_filename, id);
263
264 return rc;
265 }
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300266 }
267
268 fw_buffer = kmalloc(fw->size, GFP_KERNEL);
Michael Krufky82237412008-06-15 15:14:13 -0300269 if (fw_buffer) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300270 memcpy(fw_buffer, fw->data, fw->size);
271
Michael Krufky82237412008-06-15 15:14:13 -0300272 rc = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 2),
273 fw_buffer, fw->size, &dummy, 1000);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300274
Michael Krufky0f2a1ee2008-06-28 20:53:45 -0300275 sms_info("sent %zd(%d) bytes, rc %d", fw->size, dummy, rc);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300276
277 kfree(fw_buffer);
Michael Krufky82237412008-06-15 15:14:13 -0300278 } else {
Michael Krufkyeb250942008-06-19 22:07:23 -0300279 sms_err("failed to allocate firmware buffer");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300280 rc = -ENOMEM;
281 }
Michael Krufky1fbc3ca2008-07-01 04:35:26 -0300282 sms_info("read FW %s, size=%zd", fw_filename, fw->size);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300283
284 release_firmware(fw);
285
286 return rc;
287}
288
Michael Krufky0c071f32008-06-21 02:44:02 -0300289static void smsusb1_detectmode(void *context, int *mode)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300290{
Michael Krufky18245e12008-06-15 17:52:24 -0300291 char *product_string =
292 ((struct smsusb_device_t *) context)->udev->product;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300293
294 *mode = DEVICE_MODE_NONE;
295
Michael Krufky82237412008-06-15 15:14:13 -0300296 if (!product_string) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300297 product_string = "none";
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300298 sms_err("product string not found");
Michael Krufky82237412008-06-15 15:14:13 -0300299 } else if (strstr(product_string, "DVBH"))
300 *mode = 1;
301 else if (strstr(product_string, "BDA"))
302 *mode = 4;
303 else if (strstr(product_string, "DVBT"))
304 *mode = 0;
305 else if (strstr(product_string, "TDMB"))
306 *mode = 2;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300307
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300308 sms_info("%d \"%s\"", *mode, product_string);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300309}
310
Michael Krufky0c071f32008-06-21 02:44:02 -0300311static int smsusb1_setmode(void *context, int mode)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300312{
Michael Krufky18245e12008-06-15 17:52:24 -0300313 struct SmsMsgHdr_ST Msg = { MSG_SW_RELOAD_REQ, 0, HIF_TASK,
314 sizeof(struct SmsMsgHdr_ST), 0 };
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300315
Michael Krufky82237412008-06-15 15:14:13 -0300316 if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_DVBT_BDA) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300317 sms_err("invalid firmware id specified %d", mode);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300318 return -EINVAL;
319 }
320
321 return smsusb_sendrequest(context, &Msg, sizeof(Msg));
322}
323
Michael Krufky0c071f32008-06-21 02:44:02 -0300324static void smsusb_term_device(struct usb_interface *intf)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300325{
Joe Perches8350e152010-11-30 18:42:07 -0300326 struct smsusb_device_t *dev = usb_get_intfdata(intf);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300327
Michael Krufky82237412008-06-15 15:14:13 -0300328 if (dev) {
Mauro Carvalho Chehab05f0ffb2013-03-06 09:53:50 -0300329 dev->state = SMSUSB_DISCONNECTED;
330
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300331 smsusb_stop_streaming(dev);
332
Michael Krufkyfa830e82008-06-15 15:52:43 -0300333 /* unregister from smscore */
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300334 if (dev->coredev)
335 smscore_unregister_device(dev->coredev);
336
Mauro Carvalho Chehab05f0ffb2013-03-06 09:53:50 -0300337 sms_info("device 0x%p destroyed", dev);
Jesper Juhl08921ac2011-04-21 18:11:25 -0300338 kfree(dev);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300339 }
340
341 usb_set_intfdata(intf, NULL);
342}
343
Michael Krufky0c071f32008-06-21 02:44:02 -0300344static int smsusb_init_device(struct usb_interface *intf, int board_id)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300345{
Michael Krufky18245e12008-06-15 17:52:24 -0300346 struct smsdevice_params_t params;
347 struct smsusb_device_t *dev;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300348 int i, rc;
349
Michael Krufkyfa830e82008-06-15 15:52:43 -0300350 /* create device object */
Michael Krufky18245e12008-06-15 17:52:24 -0300351 dev = kzalloc(sizeof(struct smsusb_device_t), GFP_KERNEL);
Michael Krufky82237412008-06-15 15:14:13 -0300352 if (!dev) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300353 sms_err("kzalloc(sizeof(struct smsusb_device_t) failed");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300354 return -ENOMEM;
355 }
356
357 memset(&params, 0, sizeof(params));
358 usb_set_intfdata(intf, dev);
359 dev->udev = interface_to_usbdev(intf);
Mauro Carvalho Chehab05f0ffb2013-03-06 09:53:50 -0300360 dev->state = SMSUSB_DISCONNECTED;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300361
Michael Krufky2708e882008-06-21 05:24:38 -0300362 params.device_type = sms_get_board(board_id)->type;
Michael Krufky73104fb2008-06-14 18:27:18 -0300363
Michael Krufky2708e882008-06-21 05:24:38 -0300364 switch (params.device_type) {
Michael Krufky1c11d542008-06-18 22:09:55 -0300365 case SMS_STELLAR:
Michael Krufkyf17407a2008-06-14 00:43:26 -0300366 dev->buffer_size = USB1_BUFFER_SIZE;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300367
Michael Krufkyf17407a2008-06-14 00:43:26 -0300368 params.setmode_handler = smsusb1_setmode;
369 params.detectmode_handler = smsusb1_detectmode;
Michael Krufkyf17407a2008-06-14 00:43:26 -0300370 break;
371 default:
Michael Krufky2708e882008-06-21 05:24:38 -0300372 sms_err("Unspecified sms device type!");
373 /* fall-thru */
374 case SMS_NOVA_A0:
375 case SMS_NOVA_B0:
376 case SMS_VEGA:
Mauro Carvalho Chehab05f0ffb2013-03-06 09:53:50 -0300377 case SMS_VENICE:
378 case SMS_DENVER_1530:
Michael Krufkyf17407a2008-06-14 00:43:26 -0300379 dev->buffer_size = USB2_BUFFER_SIZE;
Michael Krufky82237412008-06-15 15:14:13 -0300380 dev->response_alignment =
Uri Shkolnikc7ce8d32009-05-12 08:24:07 -0300381 le16_to_cpu(dev->udev->ep_in[1]->desc.wMaxPacketSize) -
382 sizeof(struct SmsMsgHdr_ST);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300383
Michael Krufkyf17407a2008-06-14 00:43:26 -0300384 params.flags |= SMS_DEVICE_FAMILY2;
385 break;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300386 }
387
Mauro Carvalho Chehab05f0ffb2013-03-06 09:53:50 -0300388 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
389 if (intf->cur_altsetting->endpoint[i].desc. bEndpointAddress & USB_DIR_IN)
390 dev->in_ep = intf->cur_altsetting->endpoint[i].desc.bEndpointAddress;
391 else
392 dev->out_ep = intf->cur_altsetting->endpoint[i].desc.bEndpointAddress;
393 }
394
395 sms_info("in_ep = %02x, out_ep = %02x",
396 dev->in_ep, dev->out_ep);
397
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300398 params.device = &dev->udev->dev;
399 params.buffer_size = dev->buffer_size;
400 params.num_buffers = MAX_BUFFERS;
401 params.sendrequest_handler = smsusb_sendrequest;
402 params.context = dev;
Mauro Carvalho Chehab1722f3b2010-08-01 15:30:50 -0300403 usb_make_path(dev->udev, params.devpath, sizeof(params.devpath));
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300404
Michael Krufky82237412008-06-15 15:14:13 -0300405 /* register in smscore */
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300406 rc = smscore_register_device(&params, &dev->coredev);
Michael Krufky82237412008-06-15 15:14:13 -0300407 if (rc < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300408 sms_err("smscore_register_device(...) failed, rc %d", rc);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300409 smsusb_term_device(intf);
410 return rc;
411 }
412
Michael Krufky1c11d542008-06-18 22:09:55 -0300413 smscore_set_board_id(dev->coredev, board_id);
414
Michael Krufkyfa830e82008-06-15 15:52:43 -0300415 /* initialize urbs */
Michael Krufky82237412008-06-15 15:14:13 -0300416 for (i = 0; i < MAX_URBS; i++) {
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300417 dev->surbs[i].dev = dev;
418 usb_init_urb(&dev->surbs[i].urb);
419 }
420
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300421 sms_info("smsusb_start_streaming(...).");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300422 rc = smsusb_start_streaming(dev);
Michael Krufky82237412008-06-15 15:14:13 -0300423 if (rc < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300424 sms_err("smsusb_start_streaming(...) failed");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300425 smsusb_term_device(intf);
426 return rc;
427 }
428
Mauro Carvalho Chehab05f0ffb2013-03-06 09:53:50 -0300429 dev->state = SMSUSB_ACTIVE;
430
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300431 rc = smscore_start_device(dev->coredev);
Michael Krufky82237412008-06-15 15:14:13 -0300432 if (rc < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300433 sms_err("smscore_start_device(...) failed");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300434 smsusb_term_device(intf);
435 return rc;
436 }
437
Mauro Carvalho Chehab05f0ffb2013-03-06 09:53:50 -0300438 sms_info("device 0x%p created", dev);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300439
440 return rc;
441}
442
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -0800443static int smsusb_probe(struct usb_interface *intf,
Michael Krufky0c071f32008-06-21 02:44:02 -0300444 const struct usb_device_id *id)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300445{
446 struct usb_device *udev = interface_to_usbdev(intf);
Mauro Carvalho Chehab347d8f12013-03-05 22:35:44 -0300447 char devpath[32];
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300448 int i, rc;
449
Mauro Carvalho Chehab05f0ffb2013-03-06 09:53:50 -0300450 sms_info("interface number %d",
451 intf->cur_altsetting->desc.bInterfaceNumber);
Michael Krufkyf17407a2008-06-14 00:43:26 -0300452
Mauro Carvalho Chehab05f0ffb2013-03-06 09:53:50 -0300453 if (sms_get_board(id->driver_info)->intf_num !=
454 intf->cur_altsetting->desc.bInterfaceNumber) {
455 sms_err("interface number is %d expecting %d",
456 sms_get_board(id->driver_info)->intf_num,
457 intf->cur_altsetting->desc.bInterfaceNumber);
458 return -ENODEV;
459 }
460
461 if (intf->num_altsetting > 1) {
462 rc = usb_set_interface(udev,
463 intf->cur_altsetting->desc.bInterfaceNumber,
464 0);
Michael Krufky82237412008-06-15 15:14:13 -0300465 if (rc < 0) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300466 sms_err("usb_set_interface failed, rc %d", rc);
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300467 return rc;
468 }
469 }
470
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300471 sms_info("smsusb_probe %d",
Michael Krufky82237412008-06-15 15:14:13 -0300472 intf->cur_altsetting->desc.bInterfaceNumber);
Mauro Carvalho Chehab05f0ffb2013-03-06 09:53:50 -0300473 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300474 sms_info("endpoint %d %02x %02x %d", i,
Michael Krufky82237412008-06-15 15:14:13 -0300475 intf->cur_altsetting->endpoint[i].desc.bEndpointAddress,
476 intf->cur_altsetting->endpoint[i].desc.bmAttributes,
477 intf->cur_altsetting->endpoint[i].desc.wMaxPacketSize);
Mauro Carvalho Chehab05f0ffb2013-03-06 09:53:50 -0300478 if (intf->cur_altsetting->endpoint[i].desc.bEndpointAddress &
479 USB_DIR_IN)
480 rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev,
481 intf->cur_altsetting->endpoint[i].desc.bEndpointAddress));
482 else
483 rc = usb_clear_halt(udev, usb_sndbulkpipe(udev,
484 intf->cur_altsetting->endpoint[i].desc.bEndpointAddress));
485 }
Michael Krufky82237412008-06-15 15:14:13 -0300486 if ((udev->actconfig->desc.bNumInterfaces == 2) &&
487 (intf->cur_altsetting->desc.bInterfaceNumber == 0)) {
Michael Krufkyeb250942008-06-19 22:07:23 -0300488 sms_err("rom interface 0 is not used");
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300489 return -ENODEV;
490 }
491
Mauro Carvalho Chehab347d8f12013-03-05 22:35:44 -0300492 if (id->driver_info == SMS1XXX_BOARD_SIANO_STELLAR_ROM) {
493 sms_info("stellar device was found.");
494 snprintf(devpath, sizeof(devpath), "usb\\%d-%s",
495 udev->bus->busnum, udev->devpath);
496 sms_info("stellar device was found.");
497 return smsusb1_load_firmware(
498 udev, smscore_registry_getmode(devpath),
499 id->driver_info);
500 }
501
Michael Krufky1c11d542008-06-18 22:09:55 -0300502 rc = smsusb_init_device(intf, id->driver_info);
Michael Krufkya0c0abc2008-06-19 20:35:21 -0300503 sms_info("rc %d", rc);
Michael Krufky05860f22008-08-31 17:39:58 -0300504 sms_board_load_modules(id->driver_info);
Michael Krufkyf17407a2008-06-14 00:43:26 -0300505 return rc;
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300506}
507
Michael Krufky0c071f32008-06-21 02:44:02 -0300508static void smsusb_disconnect(struct usb_interface *intf)
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300509{
510 smsusb_term_device(intf);
511}
512
Uri Shkolnik2f56c342008-11-22 14:08:46 -0300513static int smsusb_suspend(struct usb_interface *intf, pm_message_t msg)
514{
Joe Perches8350e152010-11-30 18:42:07 -0300515 struct smsusb_device_t *dev = usb_get_intfdata(intf);
Mauro Carvalho Chehab05f0ffb2013-03-06 09:53:50 -0300516 printk(KERN_INFO "%s Entering status %d.\n", __func__, msg.event);
517 dev->state = SMSUSB_SUSPENDED;
518 /*smscore_set_power_mode(dev, SMS_POWER_MODE_SUSPENDED);*/
Uri Shkolnik2f56c342008-11-22 14:08:46 -0300519 smsusb_stop_streaming(dev);
520 return 0;
521}
522
523static int smsusb_resume(struct usb_interface *intf)
524{
525 int rc, i;
Joe Perches8350e152010-11-30 18:42:07 -0300526 struct smsusb_device_t *dev = usb_get_intfdata(intf);
Uri Shkolnik2f56c342008-11-22 14:08:46 -0300527 struct usb_device *udev = interface_to_usbdev(intf);
528
Mauro Carvalho Chehab05f0ffb2013-03-06 09:53:50 -0300529 printk(KERN_INFO "%s Entering.\n", __func__);
530 usb_clear_halt(udev, usb_rcvbulkpipe(udev, dev->in_ep));
531 usb_clear_halt(udev, usb_sndbulkpipe(udev, dev->out_ep));
Uri Shkolnik2f56c342008-11-22 14:08:46 -0300532
533 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++)
534 printk(KERN_INFO "endpoint %d %02x %02x %d\n", i,
535 intf->cur_altsetting->endpoint[i].desc.bEndpointAddress,
536 intf->cur_altsetting->endpoint[i].desc.bmAttributes,
537 intf->cur_altsetting->endpoint[i].desc.wMaxPacketSize);
538
539 if (intf->num_altsetting > 0) {
540 rc = usb_set_interface(udev,
541 intf->cur_altsetting->desc.
542 bInterfaceNumber, 0);
543 if (rc < 0) {
Michael Krufkyb9391f42008-08-31 16:08:15 -0300544 printk(KERN_INFO "%s usb_set_interface failed, "
545 "rc %d\n", __func__, rc);
Uri Shkolnik2f56c342008-11-22 14:08:46 -0300546 return rc;
547 }
548 }
549
550 smsusb_start_streaming(dev);
551 return 0;
552}
553
Greg Kroah-Hartmand04dbd12012-08-17 17:48:26 -0700554static const struct usb_device_id smsusb_id_table[] = {
Michael Krufky841a3f02008-08-31 17:03:15 -0300555 { USB_DEVICE(0x187f, 0x0010),
556 .driver_info = SMS1XXX_BOARD_SIANO_STELLAR },
557 { USB_DEVICE(0x187f, 0x0100),
558 .driver_info = SMS1XXX_BOARD_SIANO_STELLAR },
559 { USB_DEVICE(0x187f, 0x0200),
560 .driver_info = SMS1XXX_BOARD_SIANO_NOVA_A },
561 { USB_DEVICE(0x187f, 0x0201),
562 .driver_info = SMS1XXX_BOARD_SIANO_NOVA_B },
563 { USB_DEVICE(0x187f, 0x0300),
564 .driver_info = SMS1XXX_BOARD_SIANO_VEGA },
Michael Krufky841a3f02008-08-31 17:03:15 -0300565 { USB_DEVICE(0x2040, 0x1700),
566 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_CATAMOUNT },
567 { USB_DEVICE(0x2040, 0x1800),
568 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_OKEMO_A },
569 { USB_DEVICE(0x2040, 0x1801),
570 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_OKEMO_B },
571 { USB_DEVICE(0x2040, 0x2000),
572 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
573 { USB_DEVICE(0x2040, 0x2009),
574 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2 },
575 { USB_DEVICE(0x2040, 0x200a),
576 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
577 { USB_DEVICE(0x2040, 0x2010),
578 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
579 { USB_DEVICE(0x2040, 0x2011),
580 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
581 { USB_DEVICE(0x2040, 0x2019),
582 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
583 { USB_DEVICE(0x2040, 0x5500),
584 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
585 { USB_DEVICE(0x2040, 0x5510),
586 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
587 { USB_DEVICE(0x2040, 0x5520),
588 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
589 { USB_DEVICE(0x2040, 0x5530),
590 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
591 { USB_DEVICE(0x2040, 0x5580),
592 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
593 { USB_DEVICE(0x2040, 0x5590),
594 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
Uri Shkolnikd0b661802009-05-19 09:51:41 -0300595 { USB_DEVICE(0x187f, 0x0202),
596 .driver_info = SMS1XXX_BOARD_SIANO_NICE },
597 { USB_DEVICE(0x187f, 0x0301),
598 .driver_info = SMS1XXX_BOARD_SIANO_VENICE },
Michael Krufky78c948a2009-10-21 18:27:29 -0300599 { USB_DEVICE(0x2040, 0xb900),
600 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
601 { USB_DEVICE(0x2040, 0xb910),
602 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
Michael Krufky20d15a22009-11-30 18:22:10 -0300603 { USB_DEVICE(0x2040, 0xb980),
604 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
605 { USB_DEVICE(0x2040, 0xb990),
606 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
Michael Krufky78c948a2009-10-21 18:27:29 -0300607 { USB_DEVICE(0x2040, 0xc000),
608 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
Michael Krufky20d15a22009-11-30 18:22:10 -0300609 { USB_DEVICE(0x2040, 0xc010),
610 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
611 { USB_DEVICE(0x2040, 0xc080),
612 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
613 { USB_DEVICE(0x2040, 0xc090),
614 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
Michael Krufky4d1b58b2012-03-22 13:55:05 -0300615 { USB_DEVICE(0x2040, 0xc0a0),
616 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
Michael Krufky3e1141e2012-05-25 09:29:12 -0300617 { USB_DEVICE(0x2040, 0xf5a0),
618 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
Mauro Carvalho Chehab347d8f12013-03-05 22:35:44 -0300619 { USB_DEVICE(0x187f, 0x0202),
620 .driver_info = SMS1XXX_BOARD_SIANO_NICE },
621 { USB_DEVICE(0x187f, 0x0301),
622 .driver_info = SMS1XXX_BOARD_SIANO_VENICE },
623 { USB_DEVICE(0x187f, 0x0302),
624 .driver_info = SMS1XXX_BOARD_SIANO_VENICE },
625 { USB_DEVICE(0x187f, 0x0310),
626 .driver_info = SMS1XXX_BOARD_SIANO_MING },
627 { USB_DEVICE(0x187f, 0x0500),
628 .driver_info = SMS1XXX_BOARD_SIANO_PELE },
629 { USB_DEVICE(0x187f, 0x0600),
630 .driver_info = SMS1XXX_BOARD_SIANO_RIO },
631 { USB_DEVICE(0x187f, 0x0700),
632 .driver_info = SMS1XXX_BOARD_SIANO_DENVER_2160 },
633 { USB_DEVICE(0x187f, 0x0800),
634 .driver_info = SMS1XXX_BOARD_SIANO_DENVER_1530 },
635 { USB_DEVICE(0x19D2, 0x0086),
636 .driver_info = SMS1XXX_BOARD_ZTE_DVB_DATA_CARD },
637 { USB_DEVICE(0x19D2, 0x0078),
638 .driver_info = SMS1XXX_BOARD_ONDA_MDTV_DATA_CARD },
Uri Shkolnikd0b661802009-05-19 09:51:41 -0300639 { } /* Terminating entry */
640 };
641
Michael Krufky841a3f02008-08-31 17:03:15 -0300642MODULE_DEVICE_TABLE(usb, smsusb_id_table);
643
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300644static struct usb_driver smsusb_driver = {
Uri Shkolnikdba843a2008-08-31 00:44:04 -0300645 .name = "smsusb",
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300646 .probe = smsusb_probe,
Michael Krufky82237412008-06-15 15:14:13 -0300647 .disconnect = smsusb_disconnect,
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300648 .id_table = smsusb_id_table,
Uri Shkolnik2f56c342008-11-22 14:08:46 -0300649
650 .suspend = smsusb_suspend,
651 .resume = smsusb_resume,
Michael Krufky2e5c1ec82008-05-19 18:56:13 -0300652};
653
Greg Kroah-Hartmanecb3b2b2011-11-18 09:46:12 -0800654module_usb_driver(smsusb_driver);
Uri Shkolnike0f14c22008-08-31 00:44:04 -0300655
Uri Shkolnik05a073762009-05-17 09:17:51 -0300656MODULE_DESCRIPTION("Driver for the Siano SMS1xxx USB dongle");
Uri Shkolnike0f14c22008-08-31 00:44:04 -0300657MODULE_AUTHOR("Siano Mobile Silicon, INC. (uris@siano-ms.com)");
658MODULE_LICENSE("GPL");