linux/drivers/media/usb/go7007/go7007-loader.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0-only
   2/*
   3 * Copyright (C) 2008 Sensoray Company Inc.
   4 */
   5
   6#include <linux/module.h>
   7#include <linux/slab.h>
   8#include <linux/usb.h>
   9#include <linux/firmware.h>
  10#include <cypress_firmware.h>
  11
  12struct fw_config {
  13        u16 vendor;
  14        u16 product;
  15        const char * const fw_name1;
  16        const char * const fw_name2;
  17};
  18
  19static struct fw_config fw_configs[] = {
  20        { 0x1943, 0xa250, "go7007/s2250-1.fw", "go7007/s2250-2.fw" },
  21        { 0x093b, 0xa002, "go7007/px-m402u.fw", NULL },
  22        { 0x093b, 0xa004, "go7007/px-tv402u.fw", NULL },
  23        { 0x0eb1, 0x6666, "go7007/lr192.fw", NULL },
  24        { 0x0eb1, 0x6668, "go7007/wis-startrek.fw", NULL },
  25        { 0, 0, NULL, NULL }
  26};
  27MODULE_FIRMWARE("go7007/s2250-1.fw");
  28MODULE_FIRMWARE("go7007/s2250-2.fw");
  29MODULE_FIRMWARE("go7007/px-m402u.fw");
  30MODULE_FIRMWARE("go7007/px-tv402u.fw");
  31MODULE_FIRMWARE("go7007/lr192.fw");
  32MODULE_FIRMWARE("go7007/wis-startrek.fw");
  33
  34static int go7007_loader_probe(struct usb_interface *interface,
  35                                const struct usb_device_id *id)
  36{
  37        struct usb_device *usbdev;
  38        const struct firmware *fw;
  39        u16 vendor, product;
  40        const char *fw1, *fw2;
  41        int ret;
  42        int i;
  43
  44        usbdev = usb_get_dev(interface_to_usbdev(interface));
  45        if (!usbdev)
  46                goto failed2;
  47
  48        if (usbdev->descriptor.bNumConfigurations != 1) {
  49                dev_err(&interface->dev, "can't handle multiple config\n");
  50                goto failed2;
  51        }
  52
  53        vendor = le16_to_cpu(usbdev->descriptor.idVendor);
  54        product = le16_to_cpu(usbdev->descriptor.idProduct);
  55
  56        for (i = 0; fw_configs[i].fw_name1; i++)
  57                if (fw_configs[i].vendor == vendor &&
  58                    fw_configs[i].product == product)
  59                        break;
  60
  61        /* Should never happen */
  62        if (fw_configs[i].fw_name1 == NULL)
  63                goto failed2;
  64
  65        fw1 = fw_configs[i].fw_name1;
  66        fw2 = fw_configs[i].fw_name2;
  67
  68        dev_info(&interface->dev, "loading firmware %s\n", fw1);
  69
  70        if (request_firmware(&fw, fw1, &usbdev->dev)) {
  71                dev_err(&interface->dev,
  72                        "unable to load firmware from file \"%s\"\n", fw1);
  73                goto failed2;
  74        }
  75        ret = cypress_load_firmware(usbdev, fw, CYPRESS_FX2);
  76        release_firmware(fw);
  77        if (0 != ret) {
  78                dev_err(&interface->dev, "loader download failed\n");
  79                goto failed2;
  80        }
  81
  82        if (fw2 == NULL)
  83                return 0;
  84
  85        if (request_firmware(&fw, fw2, &usbdev->dev)) {
  86                dev_err(&interface->dev,
  87                        "unable to load firmware from file \"%s\"\n", fw2);
  88                goto failed2;
  89        }
  90        ret = cypress_load_firmware(usbdev, fw, CYPRESS_FX2);
  91        release_firmware(fw);
  92        if (0 != ret) {
  93                dev_err(&interface->dev, "firmware download failed\n");
  94                goto failed2;
  95        }
  96        return 0;
  97
  98failed2:
  99        usb_put_dev(usbdev);
 100        dev_err(&interface->dev, "probe failed\n");
 101        return -ENODEV;
 102}
 103
 104static void go7007_loader_disconnect(struct usb_interface *interface)
 105{
 106        dev_info(&interface->dev, "disconnect\n");
 107        usb_put_dev(interface_to_usbdev(interface));
 108        usb_set_intfdata(interface, NULL);
 109}
 110
 111static const struct usb_device_id go7007_loader_ids[] = {
 112        { USB_DEVICE(0x1943, 0xa250) },
 113        { USB_DEVICE(0x093b, 0xa002) },
 114        { USB_DEVICE(0x093b, 0xa004) },
 115        { USB_DEVICE(0x0eb1, 0x6666) },
 116        { USB_DEVICE(0x0eb1, 0x6668) },
 117        {}                          /* Terminating entry */
 118};
 119
 120MODULE_DEVICE_TABLE(usb, go7007_loader_ids);
 121
 122static struct usb_driver go7007_loader_driver = {
 123        .name           = "go7007-loader",
 124        .probe          = go7007_loader_probe,
 125        .disconnect     = go7007_loader_disconnect,
 126        .id_table       = go7007_loader_ids,
 127};
 128
 129module_usb_driver(go7007_loader_driver);
 130
 131MODULE_AUTHOR("");
 132MODULE_DESCRIPTION("firmware loader for go7007-usb");
 133MODULE_LICENSE("GPL v2");
 134