blob: 6dcd55a74c0abbdc6a7d00e2b9896b1cb9acc4b9 [file] [log] [blame]
Vikram Kandukuri9670d802010-01-06 19:04:15 +05301/*
2 * Copyright (c) 2008-2009 Atheros Communications Inc.
3 *
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.
8 *
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.
13 *
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
17 *
18 */
19
20
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>
31
32#define VERSION "1.0"
33
34
35static struct usb_device_id ath3k_table[] = {
36 /* Atheros AR3011 */
37 { USB_DEVICE(0x0CF3, 0x3000) },
Bala Shanmugambe931122010-11-26 17:35:46 +053038
39 /* Atheros AR3011 with sflash firmware*/
40 { USB_DEVICE(0x0CF3, 0x3002) },
41
Cho, Yu-Chen509e7862011-01-26 17:10:59 +080042 /* Atheros AR9285 Malbec with sflash firmware */
43 { USB_DEVICE(0x03F0, 0x311D) },
Cho, Yu-Chene9036e32011-02-15 10:20:07 +080044
45 /* Atheros AR5BBU12 with sflash firmware */
46 { USB_DEVICE(0x0489, 0xE02C) },
Vikram Kandukuri9670d802010-01-06 19:04:15 +053047 { } /* Terminating entry */
48};
49
50MODULE_DEVICE_TABLE(usb, ath3k_table);
51
52#define USB_REQ_DFU_DNLOAD 1
53#define BULK_SIZE 4096
54
Alexander Holler86e09282010-11-22 21:09:01 +010055static int ath3k_load_firmware(struct usb_device *udev,
56 const struct firmware *firmware)
Vikram Kandukuri9670d802010-01-06 19:04:15 +053057{
58 u8 *send_buf;
59 int err, pipe, len, size, sent = 0;
Alexander Holler86e09282010-11-22 21:09:01 +010060 int count = firmware->size;
Vikram Kandukuri9670d802010-01-06 19:04:15 +053061
Alexander Holler86e09282010-11-22 21:09:01 +010062 BT_DBG("udev %p", udev);
Vikram Kandukuri9670d802010-01-06 19:04:15 +053063
Alexander Holler86e09282010-11-22 21:09:01 +010064 pipe = usb_sndctrlpipe(udev, 0);
Vikram Kandukuri9670d802010-01-06 19:04:15 +053065
66 send_buf = kmalloc(BULK_SIZE, GFP_ATOMIC);
67 if (!send_buf) {
68 BT_ERR("Can't allocate memory chunk for firmware");
69 return -ENOMEM;
70 }
71
Alexander Holler86e09282010-11-22 21:09:01 +010072 memcpy(send_buf, firmware->data, 20);
73 if ((err = usb_control_msg(udev, pipe,
74 USB_REQ_DFU_DNLOAD,
75 USB_TYPE_VENDOR, 0, 0,
76 send_buf, 20, USB_CTRL_SET_TIMEOUT)) < 0) {
77 BT_ERR("Can't change to loading configuration err");
78 goto error;
79 }
80 sent += 20;
81 count -= 20;
82
Vikram Kandukuri9670d802010-01-06 19:04:15 +053083 while (count) {
84 size = min_t(uint, count, BULK_SIZE);
Alexander Holler86e09282010-11-22 21:09:01 +010085 pipe = usb_sndbulkpipe(udev, 0x02);
86 memcpy(send_buf, firmware->data + sent, size);
Vikram Kandukuri9670d802010-01-06 19:04:15 +053087
Alexander Holler86e09282010-11-22 21:09:01 +010088 err = usb_bulk_msg(udev, pipe, send_buf, size,
Vikram Kandukuri9670d802010-01-06 19:04:15 +053089 &len, 3000);
90
91 if (err || (len != size)) {
92 BT_ERR("Error in firmware loading err = %d,"
93 "len = %d, size = %d", err, len, size);
94 goto error;
95 }
96
97 sent += size;
98 count -= size;
99 }
100
101 kfree(send_buf);
102 return 0;
103
104error:
105 kfree(send_buf);
106 return err;
107}
108
109static int ath3k_probe(struct usb_interface *intf,
110 const struct usb_device_id *id)
111{
112 const struct firmware *firmware;
113 struct usb_device *udev = interface_to_usbdev(intf);
Vikram Kandukuri9670d802010-01-06 19:04:15 +0530114
115 BT_DBG("intf %p id %p", intf, id);
116
117 if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
118 return -ENODEV;
119
Vikram Kandukuri9670d802010-01-06 19:04:15 +0530120 if (request_firmware(&firmware, "ath3k-1.fw", &udev->dev) < 0) {
Vikram Kandukuri9670d802010-01-06 19:04:15 +0530121 return -EIO;
122 }
123
Alexander Holler86e09282010-11-22 21:09:01 +0100124 if (ath3k_load_firmware(udev, firmware)) {
Vikram Kandukuri9670d802010-01-06 19:04:15 +0530125 release_firmware(firmware);
Vikram Kandukuri9670d802010-01-06 19:04:15 +0530126 return -EIO;
127 }
Alexander Holler86e09282010-11-22 21:09:01 +0100128 release_firmware(firmware);
Vikram Kandukuri9670d802010-01-06 19:04:15 +0530129
130 return 0;
131}
132
133static void ath3k_disconnect(struct usb_interface *intf)
134{
Vikram Kandukuri9670d802010-01-06 19:04:15 +0530135 BT_DBG("ath3k_disconnect intf %p", intf);
Vikram Kandukuri9670d802010-01-06 19:04:15 +0530136}
137
138static struct usb_driver ath3k_driver = {
139 .name = "ath3k",
140 .probe = ath3k_probe,
141 .disconnect = ath3k_disconnect,
142 .id_table = ath3k_table,
143};
144
145static int __init ath3k_init(void)
146{
147 BT_INFO("Atheros AR30xx firmware driver ver %s", VERSION);
148 return usb_register(&ath3k_driver);
149}
150
151static void __exit ath3k_exit(void)
152{
153 usb_deregister(&ath3k_driver);
154}
155
156module_init(ath3k_init);
157module_exit(ath3k_exit);
158
159MODULE_AUTHOR("Atheros Communications");
160MODULE_DESCRIPTION("Atheros AR30xx firmware driver");
161MODULE_VERSION(VERSION);
162MODULE_LICENSE("GPL");
163MODULE_FIRMWARE("ath3k-1.fw");