Commit | Line | Data |
---|---|---|
b11869db PE |
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. | |
b11869db PE |
12 | */ |
13 | ||
14 | #include <linux/module.h> | |
5a0e3ad6 | 15 | #include <linux/slab.h> |
b11869db | 16 | #include <linux/usb.h> |
c046981f HV |
17 | #include <linux/firmware.h> |
18 | #include <cypress_firmware.h> | |
b11869db | 19 | |
0ee3d4d5 HV |
20 | struct fw_config { |
21 | u16 vendor; | |
22 | u16 product; | |
23 | const char * const fw_name1; | |
24 | const char * const fw_name2; | |
25 | }; | |
b11869db | 26 | |
04ad3a64 | 27 | static struct fw_config fw_configs[] = { |
0ee3d4d5 HV |
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"); | |
b11869db | 41 | |
e129c974 | 42 | static int go7007_loader_probe(struct usb_interface *interface, |
b11869db PE |
43 | const struct usb_device_id *id) |
44 | { | |
45 | struct usb_device *usbdev; | |
b11869db | 46 | const struct firmware *fw; |
0ee3d4d5 HV |
47 | u16 vendor, product; |
48 | const char *fw1, *fw2; | |
49 | int ret; | |
50 | int i; | |
b11869db PE |
51 | |
52 | usbdev = usb_get_dev(interface_to_usbdev(interface)); | |
0ee3d4d5 HV |
53 | if (!usbdev) |
54 | goto failed2; | |
b11869db PE |
55 | |
56 | if (usbdev->descriptor.bNumConfigurations != 1) { | |
b11558a3 | 57 | dev_err(&interface->dev, "can't handle multiple config\n"); |
50c88544 | 58 | goto failed2; |
b11869db PE |
59 | } |
60 | ||
0ee3d4d5 HV |
61 | vendor = le16_to_cpu(usbdev->descriptor.idVendor); |
62 | product = le16_to_cpu(usbdev->descriptor.idProduct); | |
b11869db | 63 | |
0ee3d4d5 HV |
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; | |
b11869db | 68 | |
0ee3d4d5 HV |
69 | /* Should never happen */ |
70 | if (fw_configs[i].fw_name1 == NULL) | |
71 | goto failed2; | |
b11869db | 72 | |
0ee3d4d5 HV |
73 | fw1 = fw_configs[i].fw_name1; |
74 | fw2 = fw_configs[i].fw_name2; | |
b11869db | 75 | |
0ee3d4d5 | 76 | dev_info(&interface->dev, "loading firmware %s\n", fw1); |
b11869db | 77 | |
0ee3d4d5 | 78 | if (request_firmware(&fw, fw1, &usbdev->dev)) { |
b11558a3 | 79 | dev_err(&interface->dev, |
0ee3d4d5 | 80 | "unable to load firmware from file \"%s\"\n", fw1); |
b11869db PE |
81 | goto failed2; |
82 | } | |
79a63c60 | 83 | ret = cypress_load_firmware(usbdev, fw, CYPRESS_FX2); |
b11869db PE |
84 | release_firmware(fw); |
85 | if (0 != ret) { | |
b11558a3 | 86 | dev_err(&interface->dev, "loader download failed\n"); |
b11869db PE |
87 | goto failed2; |
88 | } | |
89 | ||
0ee3d4d5 HV |
90 | if (fw2 == NULL) |
91 | return 0; | |
92 | ||
93 | if (request_firmware(&fw, fw2, &usbdev->dev)) { | |
b11558a3 | 94 | dev_err(&interface->dev, |
0ee3d4d5 | 95 | "unable to load firmware from file \"%s\"\n", fw2); |
b11869db PE |
96 | goto failed2; |
97 | } | |
79a63c60 | 98 | ret = cypress_load_firmware(usbdev, fw, CYPRESS_FX2); |
b11869db PE |
99 | release_firmware(fw); |
100 | if (0 != ret) { | |
e129c974 | 101 | dev_err(&interface->dev, "firmware download failed\n"); |
b11869db PE |
102 | goto failed2; |
103 | } | |
b11869db PE |
104 | return 0; |
105 | ||
b11869db | 106 | failed2: |
50c88544 | 107 | usb_put_dev(usbdev); |
b11558a3 | 108 | dev_err(&interface->dev, "probe failed\n"); |
0ee3d4d5 | 109 | return -ENODEV; |
b11869db PE |
110 | } |
111 | ||
e129c974 | 112 | static void go7007_loader_disconnect(struct usb_interface *interface) |
b11869db | 113 | { |
e129c974 | 114 | dev_info(&interface->dev, "disconnect\n"); |
50c88544 | 115 | usb_put_dev(interface_to_usbdev(interface)); |
b11869db | 116 | usb_set_intfdata(interface, NULL); |
b11869db PE |
117 | } |
118 | ||
e129c974 | 119 | static const struct usb_device_id go7007_loader_ids[] = { |
0ee3d4d5 HV |
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) }, | |
b11869db PE |
125 | {} /* Terminating entry */ |
126 | }; | |
127 | ||
e129c974 | 128 | MODULE_DEVICE_TABLE(usb, go7007_loader_ids); |
b11869db | 129 | |
e129c974 HV |
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, | |
b11869db PE |
135 | }; |
136 | ||
e129c974 | 137 | module_usb_driver(go7007_loader_driver); |
832b6a89 PE |
138 | |
139 | MODULE_AUTHOR(""); | |
0ee3d4d5 | 140 | MODULE_DESCRIPTION("firmware loader for go7007-usb"); |
832b6a89 | 141 | MODULE_LICENSE("GPL v2"); |