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>
40 #ifndef CONFIG_BT_HCIBCM203X_DEBUG
47 static int ignore = 0;
49 static struct usb_device_id bcm203x_table[] = {
50 /* Broadcom Blutonium (BCM2033) */
51 { USB_DEVICE(0x0a5c, 0x2033) },
53 { } /* Terminating entry */
56 MODULE_DEVICE_TABLE(usb, bcm203x_table);
58 #define BCM203X_ERROR 0
59 #define BCM203X_RESET 1
60 #define BCM203X_LOAD_MINIDRV 2
61 #define BCM203X_SELECT_MEMORY 3
62 #define BCM203X_CHECK_MEMORY 4
63 #define BCM203X_LOAD_FIRMWARE 5
64 #define BCM203X_CHECK_FIRMWARE 6
66 #define BCM203X_IN_EP 0x81
67 #define BCM203X_OUT_EP 0x02
70 struct usb_device *udev;
74 struct work_struct work;
77 unsigned char *buffer;
79 unsigned char *fw_data;
84 static void bcm203x_complete(struct urb *urb)
86 struct bcm203x_data *data = urb->context;
87 struct usb_device *udev = urb->dev;
90 BT_DBG("udev %p urb %p", udev, urb);
93 BT_ERR("URB failed with status %d", urb->status);
94 data->state = BCM203X_ERROR;
98 switch (data->state) {
99 case BCM203X_LOAD_MINIDRV:
100 memcpy(data->buffer, "#", 1);
102 usb_fill_bulk_urb(urb, udev, usb_sndbulkpipe(udev, BCM203X_OUT_EP),
103 data->buffer, 1, bcm203x_complete, data);
105 data->state = BCM203X_SELECT_MEMORY;
107 schedule_work(&data->work);
110 case BCM203X_SELECT_MEMORY:
111 usb_fill_int_urb(urb, udev, usb_rcvintpipe(udev, BCM203X_IN_EP),
112 data->buffer, 32, bcm203x_complete, data, 1);
114 data->state = BCM203X_CHECK_MEMORY;
116 if (usb_submit_urb(data->urb, GFP_ATOMIC) < 0)
117 BT_ERR("Can't submit URB");
120 case BCM203X_CHECK_MEMORY:
121 if (data->buffer[0] != '#') {
122 BT_ERR("Memory select failed");
123 data->state = BCM203X_ERROR;
127 data->state = BCM203X_LOAD_FIRMWARE;
129 case BCM203X_LOAD_FIRMWARE:
130 if (data->fw_sent == data->fw_size) {
131 usb_fill_int_urb(urb, udev, usb_rcvintpipe(udev, BCM203X_IN_EP),
132 data->buffer, 32, bcm203x_complete, data, 1);
134 data->state = BCM203X_CHECK_FIRMWARE;
136 len = min_t(uint, data->fw_size - data->fw_sent, 4096);
138 usb_fill_bulk_urb(urb, udev, usb_sndbulkpipe(udev, BCM203X_OUT_EP),
139 data->fw_data + data->fw_sent, len, bcm203x_complete, data);
141 data->fw_sent += len;
144 if (usb_submit_urb(data->urb, GFP_ATOMIC) < 0)
145 BT_ERR("Can't submit URB");
148 case BCM203X_CHECK_FIRMWARE:
149 if (data->buffer[0] != '.') {
150 BT_ERR("Firmware loading failed");
151 data->state = BCM203X_ERROR;
155 data->state = BCM203X_RESET;
160 static void bcm203x_work(void *user_data)
162 struct bcm203x_data *data = user_data;
164 if (usb_submit_urb(data->urb, GFP_ATOMIC) < 0)
165 BT_ERR("Can't submit URB");
168 static int bcm203x_probe(struct usb_interface *intf, const struct usb_device_id *id)
170 const struct firmware *firmware;
171 struct usb_device *udev = interface_to_usbdev(intf);
172 struct bcm203x_data *data;
175 BT_DBG("intf %p id %p", intf, id);
177 if (ignore || (intf->cur_altsetting->desc.bInterfaceNumber != 0))
180 data = kzalloc(sizeof(*data), GFP_KERNEL);
182 BT_ERR("Can't allocate memory for data structure");
187 data->state = BCM203X_LOAD_MINIDRV;
189 data->urb = usb_alloc_urb(0, GFP_KERNEL);
191 BT_ERR("Can't allocate URB");
196 if (request_firmware(&firmware, "BCM2033-MD.hex", &udev->dev) < 0) {
197 BT_ERR("Mini driver request failed");
198 usb_free_urb(data->urb);
203 BT_DBG("minidrv data %p size %d", firmware->data, firmware->size);
205 size = max_t(uint, firmware->size, 4096);
207 data->buffer = kmalloc(size, GFP_KERNEL);
209 BT_ERR("Can't allocate memory for mini driver");
210 release_firmware(firmware);
211 usb_free_urb(data->urb);
216 memcpy(data->buffer, firmware->data, firmware->size);
218 usb_fill_bulk_urb(data->urb, udev, usb_sndbulkpipe(udev, BCM203X_OUT_EP),
219 data->buffer, firmware->size, bcm203x_complete, data);
221 release_firmware(firmware);
223 if (request_firmware(&firmware, "BCM2033-FW.bin", &udev->dev) < 0) {
224 BT_ERR("Firmware request failed");
225 usb_free_urb(data->urb);
231 BT_DBG("firmware data %p size %d", firmware->data, firmware->size);
233 data->fw_data = kmalloc(firmware->size, GFP_KERNEL);
234 if (!data->fw_data) {
235 BT_ERR("Can't allocate memory for firmware image");
236 release_firmware(firmware);
237 usb_free_urb(data->urb);
243 memcpy(data->fw_data, firmware->data, firmware->size);
244 data->fw_size = firmware->size;
247 release_firmware(firmware);
249 INIT_WORK(&data->work, bcm203x_work, (void *) data);
251 usb_set_intfdata(intf, data);
253 schedule_work(&data->work);
258 static void bcm203x_disconnect(struct usb_interface *intf)
260 struct bcm203x_data *data = usb_get_intfdata(intf);
262 BT_DBG("intf %p", intf);
264 usb_kill_urb(data->urb);
266 usb_set_intfdata(intf, NULL);
268 usb_free_urb(data->urb);
269 kfree(data->fw_data);
274 static struct usb_driver bcm203x_driver = {
276 .probe = bcm203x_probe,
277 .disconnect = bcm203x_disconnect,
278 .id_table = bcm203x_table,
281 static int __init bcm203x_init(void)
285 BT_INFO("Broadcom Blutonium firmware driver ver %s", VERSION);
287 err = usb_register(&bcm203x_driver);
289 BT_ERR("Failed to register USB driver");
294 static void __exit bcm203x_exit(void)
296 usb_deregister(&bcm203x_driver);
299 module_init(bcm203x_init);
300 module_exit(bcm203x_exit);
302 module_param(ignore, bool, 0644);
303 MODULE_PARM_DESC(ignore, "Ignore devices from the matching table");
305 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
306 MODULE_DESCRIPTION("Broadcom Blutonium firmware driver ver " VERSION);
307 MODULE_VERSION(VERSION);
308 MODULE_LICENSE("GPL");