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>
25 #define S2250_LOADER_FIRMWARE "s2250_loader.fw"
26 #define S2250_FIRMWARE "s2250.fw"
28 typedef struct device_extension_s
{
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
;
49 static int s2250loader_probe(struct usb_interface
*interface
,
50 const struct usb_device_id
*id
)
52 struct usb_device
*usbdev
;
54 pdevice_extension_t s
= NULL
;
55 const struct firmware
*fw
;
57 usbdev
= usb_get_dev(interface_to_usbdev(interface
));
59 printk(KERN_ERR
"Enter s2250loader_probe failed\n");
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
,
67 if (usbdev
->descriptor
.bNumConfigurations
!= 1) {
68 printk(KERN_ERR
"can't handle multiple config\n");
71 mutex_lock(&s2250_dev_table_mutex
);
73 for (minor
= 0; minor
< MAX_DEVICES
; minor
++) {
74 if (s2250_dev_table
[minor
] == NULL
)
78 if (minor
< 0 || minor
>= MAX_DEVICES
) {
79 printk(KERN_ERR
"Invalid minor: %d\n", minor
);
83 /* Allocate dev data structure */
84 s
= kmalloc(sizeof(device_extension_t
), GFP_KERNEL
);
86 printk(KERN_ERR
"Out of memory\n");
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
));
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
)) {
104 "s2250: unable to load firmware from file \"%s\"\n",
105 S2250_LOADER_FIRMWARE
);
108 ret
= usb_cypress_load_firmware(usbdev
, fw
, CYPRESS_FX2
);
109 release_firmware(fw
);
111 printk(KERN_ERR
"loader download failed\n");
115 if (request_firmware(&fw
, S2250_FIRMWARE
, &usbdev
->dev
)) {
117 "s2250: unable to load firmware from file \"%s\"\n",
121 ret
= usb_cypress_load_firmware(usbdev
, fw
, CYPRESS_FX2
);
122 release_firmware(fw
);
124 printk(KERN_ERR
"firmware_s2250 download failed\n");
128 usb_set_intfdata(interface
, s
);
132 mutex_unlock(&s2250_dev_table_mutex
);
135 kref_put(&(s
->kref
), s2250loader_delete
);
137 printk(KERN_ERR
"probe failed\n");
141 static void s2250loader_disconnect(struct usb_interface
*interface
)
143 pdevice_extension_t s
;
144 printk(KERN_INFO
"s2250: disconnect\n");
146 s
= usb_get_intfdata(interface
);
147 usb_set_intfdata(interface
, NULL
);
148 kref_put(&(s
->kref
), s2250loader_delete
);
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)
171 for (i
= 0; i
< MAX_DEVICES
; i
++)
172 s2250_dev_table
[i
] = NULL
;
174 r
= usb_register(&s2250loader_driver
);
176 printk(KERN_ERR
"usb_register failed. Error number %d\n", r
);
180 printk(KERN_INFO
"s2250loader_init: driver registered\n");
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
);
193 MODULE_DESCRIPTION("firmware loader for Sensoray 2250/2251");
194 MODULE_LICENSE("GPL v2");