3 * Broadcom Blutonium firmware driver
5 * Copyright (C) 2003 Maxim Krasnyansky <maxk@qualcomm.com>
6 * Copyright (C) 2003 Marcel Holtmann <marcel@holtmann.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/init.h>
29 #include <linux/slab.h>
30 #include <linux/types.h>
31 #include <linux/errno.h>
33 #include <linux/device.h>
34 #include <linux/firmware.h>
36 #include <linux/usb.h>
38 #include <net/bluetooth/bluetooth.h>
42 static struct usb_device_id bcm203x_table
[] = {
43 /* Broadcom Blutonium (BCM2033) */
44 { USB_DEVICE(0x0a5c, 0x2033) },
46 { } /* Terminating entry */
49 MODULE_DEVICE_TABLE(usb
, bcm203x_table
);
51 #define BCM203X_ERROR 0
52 #define BCM203X_RESET 1
53 #define BCM203X_LOAD_MINIDRV 2
54 #define BCM203X_SELECT_MEMORY 3
55 #define BCM203X_CHECK_MEMORY 4
56 #define BCM203X_LOAD_FIRMWARE 5
57 #define BCM203X_CHECK_FIRMWARE 6
59 #define BCM203X_IN_EP 0x81
60 #define BCM203X_OUT_EP 0x02
63 struct usb_device
*udev
;
67 struct work_struct work
;
70 unsigned char *buffer
;
72 unsigned char *fw_data
;
77 static void bcm203x_complete(struct urb
*urb
)
79 struct bcm203x_data
*data
= urb
->context
;
80 struct usb_device
*udev
= urb
->dev
;
83 BT_DBG("udev %p urb %p", udev
, urb
);
86 BT_ERR("URB failed with status %d", urb
->status
);
87 data
->state
= BCM203X_ERROR
;
91 switch (data
->state
) {
92 case BCM203X_LOAD_MINIDRV
:
93 memcpy(data
->buffer
, "#", 1);
95 usb_fill_bulk_urb(urb
, udev
, usb_sndbulkpipe(udev
, BCM203X_OUT_EP
),
96 data
->buffer
, 1, bcm203x_complete
, data
);
98 data
->state
= BCM203X_SELECT_MEMORY
;
100 schedule_work(&data
->work
);
103 case BCM203X_SELECT_MEMORY
:
104 usb_fill_int_urb(urb
, udev
, usb_rcvintpipe(udev
, BCM203X_IN_EP
),
105 data
->buffer
, 32, bcm203x_complete
, data
, 1);
107 data
->state
= BCM203X_CHECK_MEMORY
;
109 if (usb_submit_urb(data
->urb
, GFP_ATOMIC
) < 0)
110 BT_ERR("Can't submit URB");
113 case BCM203X_CHECK_MEMORY
:
114 if (data
->buffer
[0] != '#') {
115 BT_ERR("Memory select failed");
116 data
->state
= BCM203X_ERROR
;
120 data
->state
= BCM203X_LOAD_FIRMWARE
;
122 case BCM203X_LOAD_FIRMWARE
:
123 if (data
->fw_sent
== data
->fw_size
) {
124 usb_fill_int_urb(urb
, udev
, usb_rcvintpipe(udev
, BCM203X_IN_EP
),
125 data
->buffer
, 32, bcm203x_complete
, data
, 1);
127 data
->state
= BCM203X_CHECK_FIRMWARE
;
129 len
= min_t(uint
, data
->fw_size
- data
->fw_sent
, 4096);
131 usb_fill_bulk_urb(urb
, udev
, usb_sndbulkpipe(udev
, BCM203X_OUT_EP
),
132 data
->fw_data
+ data
->fw_sent
, len
, bcm203x_complete
, data
);
134 data
->fw_sent
+= len
;
137 if (usb_submit_urb(data
->urb
, GFP_ATOMIC
) < 0)
138 BT_ERR("Can't submit URB");
141 case BCM203X_CHECK_FIRMWARE
:
142 if (data
->buffer
[0] != '.') {
143 BT_ERR("Firmware loading failed");
144 data
->state
= BCM203X_ERROR
;
148 data
->state
= BCM203X_RESET
;
153 static void bcm203x_work(struct work_struct
*work
)
155 struct bcm203x_data
*data
=
156 container_of(work
, struct bcm203x_data
, work
);
158 if (usb_submit_urb(data
->urb
, GFP_ATOMIC
) < 0)
159 BT_ERR("Can't submit URB");
162 static int bcm203x_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
164 const struct firmware
*firmware
;
165 struct usb_device
*udev
= interface_to_usbdev(intf
);
166 struct bcm203x_data
*data
;
169 BT_DBG("intf %p id %p", intf
, id
);
171 if (intf
->cur_altsetting
->desc
.bInterfaceNumber
!= 0)
174 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
176 BT_ERR("Can't allocate memory for data structure");
181 data
->state
= BCM203X_LOAD_MINIDRV
;
183 data
->urb
= usb_alloc_urb(0, GFP_KERNEL
);
185 BT_ERR("Can't allocate URB");
190 if (request_firmware(&firmware
, "BCM2033-MD.hex", &udev
->dev
) < 0) {
191 BT_ERR("Mini driver request failed");
192 usb_free_urb(data
->urb
);
197 BT_DBG("minidrv data %p size %zu", firmware
->data
, firmware
->size
);
199 size
= max_t(uint
, firmware
->size
, 4096);
201 data
->buffer
= kmalloc(size
, GFP_KERNEL
);
203 BT_ERR("Can't allocate memory for mini driver");
204 release_firmware(firmware
);
205 usb_free_urb(data
->urb
);
210 memcpy(data
->buffer
, firmware
->data
, firmware
->size
);
212 usb_fill_bulk_urb(data
->urb
, udev
, usb_sndbulkpipe(udev
, BCM203X_OUT_EP
),
213 data
->buffer
, firmware
->size
, bcm203x_complete
, data
);
215 release_firmware(firmware
);
217 if (request_firmware(&firmware
, "BCM2033-FW.bin", &udev
->dev
) < 0) {
218 BT_ERR("Firmware request failed");
219 usb_free_urb(data
->urb
);
225 BT_DBG("firmware data %p size %zu", firmware
->data
, firmware
->size
);
227 data
->fw_data
= kmalloc(firmware
->size
, GFP_KERNEL
);
228 if (!data
->fw_data
) {
229 BT_ERR("Can't allocate memory for firmware image");
230 release_firmware(firmware
);
231 usb_free_urb(data
->urb
);
237 memcpy(data
->fw_data
, firmware
->data
, firmware
->size
);
238 data
->fw_size
= firmware
->size
;
241 release_firmware(firmware
);
243 INIT_WORK(&data
->work
, bcm203x_work
);
245 usb_set_intfdata(intf
, data
);
247 schedule_work(&data
->work
);
252 static void bcm203x_disconnect(struct usb_interface
*intf
)
254 struct bcm203x_data
*data
= usb_get_intfdata(intf
);
256 BT_DBG("intf %p", intf
);
258 usb_kill_urb(data
->urb
);
260 usb_set_intfdata(intf
, NULL
);
262 usb_free_urb(data
->urb
);
263 kfree(data
->fw_data
);
268 static struct usb_driver bcm203x_driver
= {
270 .probe
= bcm203x_probe
,
271 .disconnect
= bcm203x_disconnect
,
272 .id_table
= bcm203x_table
,
275 static int __init
bcm203x_init(void)
279 BT_INFO("Broadcom Blutonium firmware driver ver %s", VERSION
);
281 err
= usb_register(&bcm203x_driver
);
283 BT_ERR("Failed to register USB driver");
288 static void __exit
bcm203x_exit(void)
290 usb_deregister(&bcm203x_driver
);
293 module_init(bcm203x_init
);
294 module_exit(bcm203x_exit
);
296 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
297 MODULE_DESCRIPTION("Broadcom Blutonium firmware driver ver " VERSION
);
298 MODULE_VERSION(VERSION
);
299 MODULE_LICENSE("GPL");
300 MODULE_FIRMWARE("BCM2033-MD.hex");
301 MODULE_FIRMWARE("BCM2033-FW.bin");