--- zzzz-none-000/linux-3.10.107/drivers/media/usb/siano/smsusb.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/media/usb/siano/smsusb.c 2021-02-04 17:41:59.000000000 +0000 @@ -19,6 +19,8 @@ ****************************************************************/ +#include "smscoreapi.h" + #include #include #include @@ -26,14 +28,9 @@ #include #include -#include "smscoreapi.h" #include "sms-cards.h" #include "smsendian.h" -static int sms_dbg; -module_param_named(debug, sms_dbg, int, 0644); -MODULE_PARM_DESC(debug, "set debug level (info=1, adv=2 (or-able))"); - #define USB1_BUFFER_SIZE 0x1000 #define USB2_BUFFER_SIZE 0x2000 @@ -87,7 +84,7 @@ struct smsusb_device_t *dev = surb->dev; if (urb->status == -ESHUTDOWN) { - sms_err("error, urb status %d (-ESHUTDOWN), %d bytes", + pr_err("error, urb status %d (-ESHUTDOWN), %d bytes\n", urb->status, urb->actual_length); return; } @@ -109,9 +106,7 @@ /* sanity check */ if (((int) phdr->msg_length + surb->cb->offset) > urb->actual_length) { - sms_err("invalid response " - "msglen %d offset %d " - "size %d", + pr_err("invalid response msglen %d offset %d size %d\n", phdr->msg_length, surb->cb->offset, urb->actual_length); @@ -125,7 +120,7 @@ } else surb->cb->offset = 0; - sms_debug("received %s(%d) size: %d", + pr_debug("received %s(%d) size: %d\n", smscore_translate_msg(phdr->msg_type), phdr->msg_type, phdr->msg_length); @@ -134,12 +129,11 @@ smscore_onresponse(dev->coredev, surb->cb); surb->cb = NULL; } else { - sms_err("invalid response " - "msglen %d actual %d", + pr_err("invalid response msglen %d actual %d\n", phdr->msg_length, urb->actual_length); } } else - sms_err("error, urb status %d, %d bytes", + pr_err("error, urb status %d, %d bytes\n", urb->status, urb->actual_length); @@ -153,7 +147,7 @@ if (!surb->cb) { surb->cb = smscore_getbuffer(dev->coredev); if (!surb->cb) { - sms_err("smscore_getbuffer(...) returned NULL"); + pr_err("smscore_getbuffer(...) returned NULL\n"); return -ENOMEM; } } @@ -194,7 +188,7 @@ for (i = 0; i < MAX_URBS; i++) { rc = smsusb_submit_urb(dev, &dev->surbs[i]); if (rc < 0) { - sms_err("smsusb_submit_urb(...) failed"); + pr_err("smsusb_submit_urb(...) failed\n"); smsusb_stop_streaming(dev); break; } @@ -209,15 +203,17 @@ struct sms_msg_hdr *phdr; int dummy, ret; - if (dev->state != SMSUSB_ACTIVE) + if (dev->state != SMSUSB_ACTIVE) { + pr_debug("Device not active yet\n"); return -ENOENT; + } phdr = kmalloc(size, GFP_KERNEL); if (!phdr) return -ENOMEM; memcpy(phdr, buffer, size); - sms_debug("sending %s(%d) size: %d", + pr_debug("sending %s(%d) size: %d\n", smscore_translate_msg(phdr->msg_type), phdr->msg_type, phdr->msg_length); @@ -251,8 +247,11 @@ int rc, dummy; char *fw_filename; + if (id < 0) + id = sms_get_board(board_id)->default_mode; + if (id < DEVICE_MODE_DVBT || id > DEVICE_MODE_DVBT_BDA) { - sms_err("invalid firmware id specified %d", id); + pr_err("invalid firmware id specified %d\n", id); return -EINVAL; } @@ -260,13 +259,13 @@ rc = request_firmware(&fw, fw_filename, &udev->dev); if (rc < 0) { - sms_warn("failed to open \"%s\" mode %d, " - "trying again with default firmware", fw_filename, id); + pr_warn("failed to open '%s' mode %d, trying again with default firmware\n", + fw_filename, id); fw_filename = smsusb1_fw_lkup[id]; rc = request_firmware(&fw, fw_filename, &udev->dev); if (rc < 0) { - sms_warn("failed to open \"%s\" mode %d", + pr_warn("failed to open '%s' mode %d\n", fw_filename, id); return rc; @@ -280,14 +279,14 @@ rc = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 2), fw_buffer, fw->size, &dummy, 1000); - sms_info("sent %zd(%d) bytes, rc %d", fw->size, dummy, rc); + pr_debug("sent %zu(%d) bytes, rc %d\n", fw->size, dummy, rc); kfree(fw_buffer); } else { - sms_err("failed to allocate firmware buffer"); + pr_err("failed to allocate firmware buffer\n"); rc = -ENOMEM; } - sms_info("read FW %s, size=%zd", fw_filename, fw->size); + pr_debug("read FW %s, size=%zu\n", fw_filename, fw->size); release_firmware(fw); @@ -303,7 +302,7 @@ if (!product_string) { product_string = "none"; - sms_err("product string not found"); + pr_err("product string not found\n"); } else if (strstr(product_string, "DVBH")) *mode = 1; else if (strstr(product_string, "BDA")) @@ -313,7 +312,7 @@ else if (strstr(product_string, "TDMB")) *mode = 2; - sms_info("%d \"%s\"", *mode, product_string); + pr_debug("%d \"%s\"\n", *mode, product_string); } static int smsusb1_setmode(void *context, int mode) @@ -322,7 +321,7 @@ sizeof(struct sms_msg_hdr), 0 }; if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_DVBT_BDA) { - sms_err("invalid firmware id specified %d", mode); + pr_err("invalid firmware id specified %d\n", mode); return -EINVAL; } @@ -342,25 +341,61 @@ if (dev->coredev) smscore_unregister_device(dev->coredev); - sms_info("device 0x%p destroyed", dev); + pr_debug("device 0x%p destroyed\n", dev); kfree(dev); } usb_set_intfdata(intf, NULL); } +static void *siano_media_device_register(struct smsusb_device_t *dev, + int board_id) +{ +#ifdef CONFIG_MEDIA_CONTROLLER_DVB + struct media_device *mdev; + struct usb_device *udev = dev->udev; + struct sms_board *board = sms_get_board(board_id); + int ret; + + mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); + if (!mdev) + return NULL; + + mdev->dev = &udev->dev; + strlcpy(mdev->model, board->name, sizeof(mdev->model)); + if (udev->serial) + strlcpy(mdev->serial, udev->serial, sizeof(mdev->serial)); + strcpy(mdev->bus_info, udev->devpath); + mdev->hw_revision = le16_to_cpu(udev->descriptor.bcdDevice); + mdev->driver_version = LINUX_VERSION_CODE; + + ret = media_device_register(mdev); + if (ret) { + pr_err("Couldn't create a media device. Error: %d\n", + ret); + kfree(mdev); + return NULL; + } + + pr_info("media controller created\n"); + + return mdev; +#else + return NULL; +#endif +} + static int smsusb_init_device(struct usb_interface *intf, int board_id) { struct smsdevice_params_t params; struct smsusb_device_t *dev; + void *mdev; int i, rc; /* create device object */ dev = kzalloc(sizeof(struct smsusb_device_t), GFP_KERNEL); - if (!dev) { - sms_err("kzalloc(sizeof(struct smsusb_device_t) failed"); + if (!dev) return -ENOMEM; - } memset(¶ms, 0, sizeof(params)); usb_set_intfdata(intf, dev); @@ -377,7 +412,7 @@ params.detectmode_handler = smsusb1_detectmode; break; case SMS_UNKNOWN_TYPE: - sms_err("Unspecified sms device type!"); + pr_err("Unspecified sms device type!\n"); /* fall-thru */ default: dev->buffer_size = USB2_BUFFER_SIZE; @@ -396,7 +431,7 @@ dev->out_ep = intf->cur_altsetting->endpoint[i].desc.bEndpointAddress; } - sms_info("in_ep = %02x, out_ep = %02x", + pr_debug("in_ep = %02x, out_ep = %02x\n", dev->in_ep, dev->out_ep); params.device = &dev->udev->dev; @@ -406,11 +441,17 @@ params.context = dev; usb_make_path(dev->udev, params.devpath, sizeof(params.devpath)); + mdev = siano_media_device_register(dev, board_id); + /* register in smscore */ - rc = smscore_register_device(¶ms, &dev->coredev); + rc = smscore_register_device(¶ms, &dev->coredev, mdev); if (rc < 0) { - sms_err("smscore_register_device(...) failed, rc %d", rc); + pr_err("smscore_register_device(...) failed, rc %d\n", rc); smsusb_term_device(intf); +#ifdef CONFIG_MEDIA_CONTROLLER_DVB + media_device_unregister(mdev); +#endif + kfree(mdev); return rc; } @@ -424,10 +465,10 @@ usb_init_urb(&dev->surbs[i].urb); } - sms_info("smsusb_start_streaming(...)."); + pr_debug("smsusb_start_streaming(...).\n"); rc = smsusb_start_streaming(dev); if (rc < 0) { - sms_err("smsusb_start_streaming(...) failed"); + pr_err("smsusb_start_streaming(...) failed\n"); smsusb_term_device(intf); return rc; } @@ -436,12 +477,12 @@ rc = smscore_start_device(dev->coredev); if (rc < 0) { - sms_err("smscore_start_device(...) failed"); + pr_err("smscore_start_device(...) failed\n"); smsusb_term_device(intf); return rc; } - sms_info("device 0x%p created", dev); + pr_debug("device 0x%p created\n", dev); return rc; } @@ -453,14 +494,15 @@ char devpath[32]; int i, rc; - sms_info("interface number %d", + pr_info("board id=%lu, interface number %d\n", + id->driver_info, intf->cur_altsetting->desc.bInterfaceNumber); if (sms_get_board(id->driver_info)->intf_num != intf->cur_altsetting->desc.bInterfaceNumber) { - sms_err("interface number is %d expecting %d", - sms_get_board(id->driver_info)->intf_num, - intf->cur_altsetting->desc.bInterfaceNumber); + pr_debug("interface %d won't be used. Expecting interface %d to popup\n", + intf->cur_altsetting->desc.bInterfaceNumber, + sms_get_board(id->driver_info)->intf_num); return -ENODEV; } @@ -469,15 +511,15 @@ intf->cur_altsetting->desc.bInterfaceNumber, 0); if (rc < 0) { - sms_err("usb_set_interface failed, rc %d", rc); + pr_err("usb_set_interface failed, rc %d\n", rc); return rc; } } - sms_info("smsusb_probe %d", + pr_debug("smsusb_probe %d\n", intf->cur_altsetting->desc.bInterfaceNumber); for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { - sms_info("endpoint %d %02x %02x %d", i, + pr_debug("endpoint %d %02x %02x %d\n", i, intf->cur_altsetting->endpoint[i].desc.bEndpointAddress, intf->cur_altsetting->endpoint[i].desc.bmAttributes, intf->cur_altsetting->endpoint[i].desc.wMaxPacketSize); @@ -491,22 +533,34 @@ } if ((udev->actconfig->desc.bNumInterfaces == 2) && (intf->cur_altsetting->desc.bInterfaceNumber == 0)) { - sms_err("rom interface 0 is not used"); + pr_debug("rom interface 0 is not used\n"); return -ENODEV; } if (id->driver_info == SMS1XXX_BOARD_SIANO_STELLAR_ROM) { - sms_info("stellar device was found."); + /* Detected a Siano Stellar uninitialized */ + snprintf(devpath, sizeof(devpath), "usb\\%d-%s", udev->bus->busnum, udev->devpath); - sms_info("stellar device was found."); - return smsusb1_load_firmware( + pr_info("stellar device in cold state was found at %s.\n", + devpath); + rc = smsusb1_load_firmware( udev, smscore_registry_getmode(devpath), id->driver_info); + + /* This device will reset and gain another USB ID */ + if (!rc) + pr_info("stellar device now in warm state\n"); + else + pr_err("Failed to put stellar in warm state. Error: %d\n", + rc); + + return rc; + } else { + rc = smsusb_init_device(intf, id->driver_info); } - rc = smsusb_init_device(intf, id->driver_info); - sms_info("rc %d", rc); + pr_info("Device initialized with return code %d\n", rc); sms_board_load_modules(id->driver_info); return rc; } @@ -558,10 +612,13 @@ } static const struct usb_device_id smsusb_id_table[] = { + /* This device is only present before firmware load */ { USB_DEVICE(0x187f, 0x0010), - .driver_info = SMS1XXX_BOARD_SIANO_STELLAR }, + .driver_info = SMS1XXX_BOARD_SIANO_STELLAR_ROM }, + /* This device pops up after firmware load */ { USB_DEVICE(0x187f, 0x0100), .driver_info = SMS1XXX_BOARD_SIANO_STELLAR }, + { USB_DEVICE(0x187f, 0x0200), .driver_info = SMS1XXX_BOARD_SIANO_NOVA_A }, { USB_DEVICE(0x187f, 0x0201), @@ -642,6 +699,10 @@ .driver_info = SMS1XXX_BOARD_ZTE_DVB_DATA_CARD }, { USB_DEVICE(0x19D2, 0x0078), .driver_info = SMS1XXX_BOARD_ONDA_MDTV_DATA_CARD }, + { USB_DEVICE(0x3275, 0x0080), + .driver_info = SMS1XXX_BOARD_SIANO_RIO }, + { USB_DEVICE(0x2013, 0x0257), + .driver_info = SMS1XXX_BOARD_PCTV_77E }, { } /* Terminating entry */ };