22 #include <linux/kernel.h>
26 #include <linux/slab.h>
27 #include <linux/module.h>
37 #define USB1_BUFFER_SIZE 0x1000
38 #define USB2_BUFFER_SIZE 0x4000
40 #define MAX_BUFFERS 50
65 static void smsusb_onresponse(
struct urb *
urb)
71 sms_err(
"error, urb status %d (-ESHUTDOWN), %d bytes",
72 urb->status, urb->actual_length);
76 if ((urb->actual_length > 0) && (urb->status == 0)) {
80 if (urb->actual_length >= phdr->
msgLength) {
83 if (
dev->response_alignment &&
87 dev->response_alignment +
92 surb->
cb->offset) > urb->actual_length) {
94 "msglen %d offset %d "
99 goto exit_and_resubmit;
104 memcpy((
char *) phdr + surb->
cb->offset,
107 surb->
cb->offset = 0;
113 "msglen %d actual %d",
117 sms_err(
"error, urb status %d, %d bytes",
118 urb->status, urb->actual_length);
122 smsusb_submit_urb(
dev, surb);
131 sms_err(
"smscore_getbuffer(...) returned NULL");
139 usb_rcvbulkpipe(dev->
udev, 0x81),
145 surb->
urb.transfer_dma = surb->
cb->phys;
146 surb->
urb.transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
158 if (dev->
surbs[i].cb) {
170 rc = smsusb_submit_urb(dev, &dev->
surbs[i]);
172 sms_err(
"smsusb_submit_urb(...) failed");
173 smsusb_stop_streaming(dev);
188 buffer, size, &dummy, 1000);
191 static char *smsusb1_fw_lkup[] = {
192 "dvbt_stellar_usb.inp",
193 "dvbh_stellar_usb.inp",
194 "tdmb_stellar_usb.inp",
196 "dvbt_bda_stellar_usb.inp",
199 static inline char *sms_get_fw_name(
int mode,
int board_id)
202 return (fw && fw[mode]) ? fw[
mode] : smsusb1_fw_lkup[
mode];
205 static int smsusb1_load_firmware(
struct usb_device *
udev,
int id,
int board_id)
213 sms_err(
"invalid firmware id specified %d",
id);
217 fw_filename = sms_get_fw_name(
id, board_id);
221 sms_warn(
"failed to open \"%s\" mode %d, "
222 "trying again with default firmware", fw_filename,
id);
224 fw_filename = smsusb1_fw_lkup[
id];
227 sms_warn(
"failed to open \"%s\" mode %d",
239 fw_buffer, fw->
size, &dummy, 1000);
241 sms_info(
"sent %zd(%d) bytes, rc %d", fw->
size, dummy, rc);
245 sms_err(
"failed to allocate firmware buffer");
248 sms_info(
"read FW %s, size=%zd", fw_filename, fw->
size);
255 static void smsusb1_detectmode(
void *context,
int *mode)
257 char *product_string =
262 if (!product_string) {
263 product_string =
"none";
264 sms_err(
"product string not found");
265 }
else if (
strstr(product_string,
"DVBH"))
267 else if (
strstr(product_string,
"BDA"))
269 else if (
strstr(product_string,
"DVBT"))
271 else if (
strstr(product_string,
"TDMB"))
274 sms_info(
"%d \"%s\"", *mode, product_string);
277 static int smsusb1_setmode(
void *context,
int mode)
282 if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_DVBT_BDA) {
283 sms_err(
"invalid firmware id specified %d", mode);
287 return smsusb_sendrequest(context, &Msg,
sizeof(Msg));
295 smsusb_stop_streaming(dev);
301 sms_info(
"device %p destroyed", dev);
305 usb_set_intfdata(intf,
NULL);
308 static int smsusb_init_device(
struct usb_interface *intf,
int board_id)
317 sms_err(
"kzalloc(sizeof(struct smsusb_device_t) failed");
322 usb_set_intfdata(intf, dev);
323 dev->
udev = interface_to_usbdev(intf);
327 switch (
params.device_type) {
331 params.setmode_handler = smsusb1_setmode;
332 params.detectmode_handler = smsusb1_detectmode;
335 sms_err(
"Unspecified sms device type!");
352 params.sendrequest_handler = smsusb_sendrequest;
359 sms_err(
"smscore_register_device(...) failed, rc %d", rc);
360 smsusb_term_device(intf);
372 sms_info(
"smsusb_start_streaming(...).");
373 rc = smsusb_start_streaming(dev);
375 sms_err(
"smsusb_start_streaming(...) failed");
376 smsusb_term_device(intf);
382 sms_err(
"smscore_start_device(...) failed");
383 smsusb_term_device(intf);
395 struct usb_device *udev = interface_to_usbdev(intf);
402 if (intf->num_altsetting > 0) {
404 udev, intf->cur_altsetting->desc.bInterfaceNumber, 0);
406 sms_err(
"usb_set_interface failed, rc %d", rc);
412 intf->cur_altsetting->desc.bInterfaceNumber);
413 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++)
414 sms_info(
"endpoint %d %02x %02x %d", i,
415 intf->cur_altsetting->endpoint[i].desc.bEndpointAddress,
416 intf->cur_altsetting->endpoint[i].desc.bmAttributes,
417 intf->cur_altsetting->endpoint[i].desc.wMaxPacketSize);
419 if ((udev->actconfig->desc.bNumInterfaces == 2) &&
420 (intf->cur_altsetting->desc.bInterfaceNumber == 0)) {
421 sms_err(
"rom interface 0 is not used");
425 if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
426 snprintf(devpath,
sizeof(devpath),
"usb\\%d-%s",
427 udev->bus->busnum, udev->devpath);
428 sms_info(
"stellar device was found.");
429 return smsusb1_load_firmware(
434 rc = smsusb_init_device(intf, id->driver_info);
442 smsusb_term_device(intf);
449 smsusb_stop_streaming(dev);
457 struct usb_device *udev = interface_to_usbdev(intf);
463 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; 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);
469 if (intf->num_altsetting > 0) {
471 intf->cur_altsetting->desc.
475 "rc %d\n", __func__, rc);
480 smsusb_start_streaming(dev);
485 { USB_DEVICE(0x187f, 0x0010),
487 { USB_DEVICE(0x187f, 0x0100),
489 { USB_DEVICE(0x187f, 0x0200),
491 { USB_DEVICE(0x187f, 0x0201),
493 { USB_DEVICE(0x187f, 0x0300),
495 { USB_DEVICE(0x2040, 0x1700),
497 { USB_DEVICE(0x2040, 0x1800),
499 { USB_DEVICE(0x2040, 0x1801),
501 { USB_DEVICE(0x2040, 0x2000),
503 { USB_DEVICE(0x2040, 0x2009),
505 { USB_DEVICE(0x2040, 0x200a),
507 { USB_DEVICE(0x2040, 0x2010),
509 { USB_DEVICE(0x2040, 0x2011),
511 { USB_DEVICE(0x2040, 0x2019),
513 { USB_DEVICE(0x2040, 0x5500),
515 { USB_DEVICE(0x2040, 0x5510),
517 { USB_DEVICE(0x2040, 0x5520),
519 { USB_DEVICE(0x2040, 0x5530),
521 { USB_DEVICE(0x2040, 0x5580),
523 { USB_DEVICE(0x2040, 0x5590),
525 { USB_DEVICE(0x187f, 0x0202),
527 { USB_DEVICE(0x187f, 0x0301),
529 { USB_DEVICE(0x2040, 0xb900),
531 { USB_DEVICE(0x2040, 0xb910),
533 { USB_DEVICE(0x2040, 0xb980),
535 { USB_DEVICE(0x2040, 0xb990),
537 { USB_DEVICE(0x2040, 0xc000),
539 { USB_DEVICE(0x2040, 0xc010),
541 { USB_DEVICE(0x2040, 0xc080),
543 { USB_DEVICE(0x2040, 0xc090),
545 { USB_DEVICE(0x2040, 0xc0a0),
547 { USB_DEVICE(0x2040, 0xf5a0),
554 static struct usb_driver smsusb_driver = {
556 .probe = smsusb_probe,
557 .disconnect = smsusb_disconnect,
558 .id_table = smsusb_id_table,
560 .suspend = smsusb_suspend,
561 .resume = smsusb_resume,