ARM: EXYNOS: Drop legacy Exynos4 clock suspend/resume code
[cascardo/linux.git] / drivers / staging / media / go7007 / go7007-loader.c
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  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software Foundation,
15  * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16  */
17
18 #include <linux/module.h>
19 #include <linux/slab.h>
20 #include <linux/usb.h>
21 #include <linux/firmware.h>
22 #include <cypress_firmware.h>
23
24 struct fw_config {
25         u16 vendor;
26         u16 product;
27         const char * const fw_name1;
28         const char * const fw_name2;
29 };
30
31 struct fw_config fw_configs[] = {
32         { 0x1943, 0xa250, "go7007/s2250-1.fw", "go7007/s2250-2.fw" },
33         { 0x093b, 0xa002, "go7007/px-m402u.fw", NULL },
34         { 0x093b, 0xa004, "go7007/px-tv402u.fw", NULL },
35         { 0x0eb1, 0x6666, "go7007/lr192.fw", NULL },
36         { 0x0eb1, 0x6668, "go7007/wis-startrek.fw", NULL },
37         { 0, 0, NULL, NULL }
38 };
39 MODULE_FIRMWARE("go7007/s2250-1.fw");
40 MODULE_FIRMWARE("go7007/s2250-2.fw");
41 MODULE_FIRMWARE("go7007/px-m402u.fw");
42 MODULE_FIRMWARE("go7007/px-tv402u.fw");
43 MODULE_FIRMWARE("go7007/lr192.fw");
44 MODULE_FIRMWARE("go7007/wis-startrek.fw");
45
46 static int go7007_loader_probe(struct usb_interface *interface,
47                                 const struct usb_device_id *id)
48 {
49         struct usb_device *usbdev;
50         const struct firmware *fw;
51         u16 vendor, product;
52         const char *fw1, *fw2;
53         int ret;
54         int i;
55
56         usbdev = usb_get_dev(interface_to_usbdev(interface));
57         if (!usbdev)
58                 goto failed2;
59
60         if (usbdev->descriptor.bNumConfigurations != 1) {
61                 dev_err(&interface->dev, "can't handle multiple config\n");
62                 return -ENODEV;
63         }
64
65         vendor = le16_to_cpu(usbdev->descriptor.idVendor);
66         product = le16_to_cpu(usbdev->descriptor.idProduct);
67
68         for (i = 0; fw_configs[i].fw_name1; i++)
69                 if (fw_configs[i].vendor == vendor &&
70                     fw_configs[i].product == product)
71                         break;
72
73         /* Should never happen */
74         if (fw_configs[i].fw_name1 == NULL)
75                 goto failed2;
76
77         fw1 = fw_configs[i].fw_name1;
78         fw2 = fw_configs[i].fw_name2;
79
80         dev_info(&interface->dev, "loading firmware %s\n", fw1);
81
82         if (request_firmware(&fw, fw1, &usbdev->dev)) {
83                 dev_err(&interface->dev,
84                         "unable to load firmware from file \"%s\"\n", fw1);
85                 goto failed2;
86         }
87         ret = cypress_load_firmware(usbdev, fw, CYPRESS_FX2);
88         release_firmware(fw);
89         if (0 != ret) {
90                 dev_err(&interface->dev, "loader download failed\n");
91                 goto failed2;
92         }
93
94         if (fw2 == NULL)
95                 return 0;
96
97         if (request_firmware(&fw, fw2, &usbdev->dev)) {
98                 dev_err(&interface->dev,
99                         "unable to load firmware from file \"%s\"\n", fw2);
100                 goto failed2;
101         }
102         ret = cypress_load_firmware(usbdev, fw, CYPRESS_FX2);
103         release_firmware(fw);
104         if (0 != ret) {
105                 dev_err(&interface->dev, "firmware download failed\n");
106                 goto failed2;
107         }
108         return 0;
109
110 failed2:
111         dev_err(&interface->dev, "probe failed\n");
112         return -ENODEV;
113 }
114
115 static void go7007_loader_disconnect(struct usb_interface *interface)
116 {
117         dev_info(&interface->dev, "disconnect\n");
118         usb_set_intfdata(interface, NULL);
119 }
120
121 static const struct usb_device_id go7007_loader_ids[] = {
122         { USB_DEVICE(0x1943, 0xa250) },
123         { USB_DEVICE(0x093b, 0xa002) },
124         { USB_DEVICE(0x093b, 0xa004) },
125         { USB_DEVICE(0x0eb1, 0x6666) },
126         { USB_DEVICE(0x0eb1, 0x6668) },
127         {}                          /* Terminating entry */
128 };
129
130 MODULE_DEVICE_TABLE(usb, go7007_loader_ids);
131
132 static struct usb_driver go7007_loader_driver = {
133         .name           = "go7007-loader",
134         .probe          = go7007_loader_probe,
135         .disconnect     = go7007_loader_disconnect,
136         .id_table       = go7007_loader_ids,
137 };
138
139 module_usb_driver(go7007_loader_driver);
140
141 MODULE_AUTHOR("");
142 MODULE_DESCRIPTION("firmware loader for go7007-usb");
143 MODULE_LICENSE("GPL v2");