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