GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / staging / go7007 / s2250-loader.c
blob7547a8f77345a00fc3c261ed0624eb3a31b95306
1 /*
2 * Copyright (C) 2008 Sensoray Company Inc.
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.
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.
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.
18 #include <linux/module.h>
19 #include <linux/init.h>
20 #include <linux/slab.h>
21 #include <linux/smp_lock.h>
22 #include <linux/usb.h>
23 #include <dvb-usb.h>
25 #define S2250_LOADER_FIRMWARE "s2250_loader.fw"
26 #define S2250_FIRMWARE "s2250.fw"
28 typedef struct device_extension_s {
29 struct kref kref;
30 int minor;
31 struct usb_device *usbdev;
32 } device_extension_t, *pdevice_extension_t;
34 #define USB_s2250loader_MAJOR 240
35 #define USB_s2250loader_MINOR_BASE 0
36 #define MAX_DEVICES 256
38 static pdevice_extension_t s2250_dev_table[MAX_DEVICES];
39 static DEFINE_MUTEX(s2250_dev_table_mutex);
41 #define to_s2250loader_dev_common(d) container_of(d, device_extension_t, kref)
42 static void s2250loader_delete(struct kref *kref)
44 pdevice_extension_t s = to_s2250loader_dev_common(kref);
45 s2250_dev_table[s->minor] = NULL;
46 kfree(s);
49 static int s2250loader_probe(struct usb_interface *interface,
50 const struct usb_device_id *id)
52 struct usb_device *usbdev;
53 int minor, ret;
54 pdevice_extension_t s = NULL;
55 const struct firmware *fw;
57 usbdev = usb_get_dev(interface_to_usbdev(interface));
58 if (!usbdev) {
59 printk(KERN_ERR "Enter s2250loader_probe failed\n");
60 return -1;
62 printk(KERN_INFO "Enter s2250loader_probe 2.6 kernel\n");
63 printk(KERN_INFO "vendor id 0x%x, device id 0x%x devnum:%d\n",
64 usbdev->descriptor.idVendor, usbdev->descriptor.idProduct,
65 usbdev->devnum);
67 if (usbdev->descriptor.bNumConfigurations != 1) {
68 printk(KERN_ERR "can't handle multiple config\n");
69 return -1;
71 mutex_lock(&s2250_dev_table_mutex);
73 for (minor = 0; minor < MAX_DEVICES; minor++) {
74 if (s2250_dev_table[minor] == NULL)
75 break;
78 if (minor < 0 || minor >= MAX_DEVICES) {
79 printk(KERN_ERR "Invalid minor: %d\n", minor);
80 goto failed;
83 /* Allocate dev data structure */
84 s = kmalloc(sizeof(device_extension_t), GFP_KERNEL);
85 if (s == NULL) {
86 printk(KERN_ERR "Out of memory\n");
87 goto failed;
89 s2250_dev_table[minor] = s;
91 printk(KERN_INFO "s2250loader_probe: Device %d on Bus %d Minor %d\n",
92 usbdev->devnum, usbdev->bus->busnum, minor);
94 memset(s, 0, sizeof(device_extension_t));
95 s->usbdev = usbdev;
96 printk(KERN_INFO "loading 2250 loader\n");
98 kref_init(&(s->kref));
100 mutex_unlock(&s2250_dev_table_mutex);
102 if (request_firmware(&fw, S2250_LOADER_FIRMWARE, &usbdev->dev)) {
103 printk(KERN_ERR
104 "s2250: unable to load firmware from file \"%s\"\n",
105 S2250_LOADER_FIRMWARE);
106 goto failed2;
108 ret = usb_cypress_load_firmware(usbdev, fw, CYPRESS_FX2);
109 release_firmware(fw);
110 if (0 != ret) {
111 printk(KERN_ERR "loader download failed\n");
112 goto failed2;
115 if (request_firmware(&fw, S2250_FIRMWARE, &usbdev->dev)) {
116 printk(KERN_ERR
117 "s2250: unable to load firmware from file \"%s\"\n",
118 S2250_FIRMWARE);
119 goto failed2;
121 ret = usb_cypress_load_firmware(usbdev, fw, CYPRESS_FX2);
122 release_firmware(fw);
123 if (0 != ret) {
124 printk(KERN_ERR "firmware_s2250 download failed\n");
125 goto failed2;
128 usb_set_intfdata(interface, s);
129 return 0;
131 failed:
132 mutex_unlock(&s2250_dev_table_mutex);
133 failed2:
134 if (s)
135 kref_put(&(s->kref), s2250loader_delete);
137 printk(KERN_ERR "probe failed\n");
138 return -1;
141 static void s2250loader_disconnect(struct usb_interface *interface)
143 pdevice_extension_t s;
144 printk(KERN_INFO "s2250: disconnect\n");
145 lock_kernel();
146 s = usb_get_intfdata(interface);
147 usb_set_intfdata(interface, NULL);
148 kref_put(&(s->kref), s2250loader_delete);
149 unlock_kernel();
152 static const struct usb_device_id s2250loader_ids[] = {
153 {USB_DEVICE(0x1943, 0xa250)},
154 {} /* Terminating entry */
157 MODULE_DEVICE_TABLE(usb, s2250loader_ids);
159 static struct usb_driver s2250loader_driver = {
160 .name = "s2250-loader",
161 .probe = s2250loader_probe,
162 .disconnect = s2250loader_disconnect,
163 .id_table = s2250loader_ids,
166 static int __init s2250loader_init(void)
168 int r;
169 unsigned i = 0;
171 for (i = 0; i < MAX_DEVICES; i++)
172 s2250_dev_table[i] = NULL;
174 r = usb_register(&s2250loader_driver);
175 if (r) {
176 printk(KERN_ERR "usb_register failed. Error number %d\n", r);
177 return -1;
180 printk(KERN_INFO "s2250loader_init: driver registered\n");
181 return 0;
183 module_init(s2250loader_init);
185 static void __exit s2250loader_cleanup(void)
187 printk(KERN_INFO "s2250loader_cleanup\n");
188 usb_deregister(&s2250loader_driver);
190 module_exit(s2250loader_cleanup);
192 MODULE_AUTHOR("");
193 MODULE_DESCRIPTION("firmware loader for Sensoray 2250/2251");
194 MODULE_LICENSE("GPL v2");