2 * Copyright (c) 2008-2009 Atheros Communications 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 as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/init.h>
24 #include <linux/slab.h>
25 #include <linux/types.h>
26 #include <linux/errno.h>
27 #include <linux/device.h>
28 #include <linux/firmware.h>
29 #include <linux/usb.h>
30 #include <net/bluetooth/bluetooth.h>
35 static struct usb_device_id ath3k_table
[] = {
37 { USB_DEVICE(0x0CF3, 0x3000) },
39 /* Atheros AR3011 with sflash firmware*/
40 { USB_DEVICE(0x0CF3, 0x3002) },
42 { } /* Terminating entry */
45 MODULE_DEVICE_TABLE(usb
, ath3k_table
);
47 #define USB_REQ_DFU_DNLOAD 1
48 #define BULK_SIZE 4096
50 static int ath3k_load_firmware(struct usb_device
*udev
,
51 const struct firmware
*firmware
)
54 int err
, pipe
, len
, size
, sent
= 0;
55 int count
= firmware
->size
;
57 BT_DBG("udev %p", udev
);
59 pipe
= usb_sndctrlpipe(udev
, 0);
61 send_buf
= kmalloc(BULK_SIZE
, GFP_ATOMIC
);
63 BT_ERR("Can't allocate memory chunk for firmware");
67 memcpy(send_buf
, firmware
->data
, 20);
68 if ((err
= usb_control_msg(udev
, pipe
,
70 USB_TYPE_VENDOR
, 0, 0,
71 send_buf
, 20, USB_CTRL_SET_TIMEOUT
)) < 0) {
72 BT_ERR("Can't change to loading configuration err");
79 size
= min_t(uint
, count
, BULK_SIZE
);
80 pipe
= usb_sndbulkpipe(udev
, 0x02);
81 memcpy(send_buf
, firmware
->data
+ sent
, size
);
83 err
= usb_bulk_msg(udev
, pipe
, send_buf
, size
,
86 if (err
|| (len
!= size
)) {
87 BT_ERR("Error in firmware loading err = %d,"
88 "len = %d, size = %d", err
, len
, size
);
104 static int ath3k_probe(struct usb_interface
*intf
,
105 const struct usb_device_id
*id
)
107 const struct firmware
*firmware
;
108 struct usb_device
*udev
= interface_to_usbdev(intf
);
110 BT_DBG("intf %p id %p", intf
, id
);
112 if (intf
->cur_altsetting
->desc
.bInterfaceNumber
!= 0)
115 if (request_firmware(&firmware
, "ath3k-1.fw", &udev
->dev
) < 0) {
119 if (ath3k_load_firmware(udev
, firmware
)) {
120 release_firmware(firmware
);
123 release_firmware(firmware
);
128 static void ath3k_disconnect(struct usb_interface
*intf
)
130 BT_DBG("ath3k_disconnect intf %p", intf
);
133 static struct usb_driver ath3k_driver
= {
135 .probe
= ath3k_probe
,
136 .disconnect
= ath3k_disconnect
,
137 .id_table
= ath3k_table
,
140 static int __init
ath3k_init(void)
142 BT_INFO("Atheros AR30xx firmware driver ver %s", VERSION
);
143 return usb_register(&ath3k_driver
);
146 static void __exit
ath3k_exit(void)
148 usb_deregister(&ath3k_driver
);
151 module_init(ath3k_init
);
152 module_exit(ath3k_exit
);
154 MODULE_AUTHOR("Atheros Communications");
155 MODULE_DESCRIPTION("Atheros AR30xx firmware driver");
156 MODULE_VERSION(VERSION
);
157 MODULE_LICENSE("GPL");
158 MODULE_FIRMWARE("ath3k-1.fw");