Vikram Kandukuri | 9670d80 | 2010-01-06 19:04:15 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 35 | static struct usb_device_id ath3k_table[] = { |
| 36 | /* Atheros AR3011 */ |
| 37 | { USB_DEVICE(0x0CF3, 0x3000) }, |
Bala Shanmugam | be93112 | 2010-11-26 17:35:46 +0530 | [diff] [blame] | 38 | |
| 39 | /* Atheros AR3011 with sflash firmware*/ |
| 40 | { USB_DEVICE(0x0CF3, 0x3002) }, |
| 41 | |
Cho, Yu-Chen | 509e786 | 2011-01-26 17:10:59 +0800 | [diff] [blame] | 42 | /* Atheros AR9285 Malbec with sflash firmware */ |
| 43 | { USB_DEVICE(0x03F0, 0x311D) }, |
Vikram Kandukuri | 9670d80 | 2010-01-06 19:04:15 +0530 | [diff] [blame] | 44 | { } /* Terminating entry */ |
| 45 | }; |
| 46 | |
| 47 | MODULE_DEVICE_TABLE(usb, ath3k_table); |
| 48 | |
| 49 | #define USB_REQ_DFU_DNLOAD 1 |
| 50 | #define BULK_SIZE 4096 |
| 51 | |
Alexander Holler | 86e0928 | 2010-11-22 21:09:01 +0100 | [diff] [blame] | 52 | static int ath3k_load_firmware(struct usb_device *udev, |
| 53 | const struct firmware *firmware) |
Vikram Kandukuri | 9670d80 | 2010-01-06 19:04:15 +0530 | [diff] [blame] | 54 | { |
| 55 | u8 *send_buf; |
| 56 | int err, pipe, len, size, sent = 0; |
Alexander Holler | 86e0928 | 2010-11-22 21:09:01 +0100 | [diff] [blame] | 57 | int count = firmware->size; |
Vikram Kandukuri | 9670d80 | 2010-01-06 19:04:15 +0530 | [diff] [blame] | 58 | |
Alexander Holler | 86e0928 | 2010-11-22 21:09:01 +0100 | [diff] [blame] | 59 | BT_DBG("udev %p", udev); |
Vikram Kandukuri | 9670d80 | 2010-01-06 19:04:15 +0530 | [diff] [blame] | 60 | |
Alexander Holler | 86e0928 | 2010-11-22 21:09:01 +0100 | [diff] [blame] | 61 | pipe = usb_sndctrlpipe(udev, 0); |
Vikram Kandukuri | 9670d80 | 2010-01-06 19:04:15 +0530 | [diff] [blame] | 62 | |
| 63 | send_buf = kmalloc(BULK_SIZE, GFP_ATOMIC); |
| 64 | if (!send_buf) { |
| 65 | BT_ERR("Can't allocate memory chunk for firmware"); |
| 66 | return -ENOMEM; |
| 67 | } |
| 68 | |
Alexander Holler | 86e0928 | 2010-11-22 21:09:01 +0100 | [diff] [blame] | 69 | memcpy(send_buf, firmware->data, 20); |
| 70 | if ((err = usb_control_msg(udev, pipe, |
| 71 | USB_REQ_DFU_DNLOAD, |
| 72 | USB_TYPE_VENDOR, 0, 0, |
| 73 | send_buf, 20, USB_CTRL_SET_TIMEOUT)) < 0) { |
| 74 | BT_ERR("Can't change to loading configuration err"); |
| 75 | goto error; |
| 76 | } |
| 77 | sent += 20; |
| 78 | count -= 20; |
| 79 | |
Vikram Kandukuri | 9670d80 | 2010-01-06 19:04:15 +0530 | [diff] [blame] | 80 | while (count) { |
| 81 | size = min_t(uint, count, BULK_SIZE); |
Alexander Holler | 86e0928 | 2010-11-22 21:09:01 +0100 | [diff] [blame] | 82 | pipe = usb_sndbulkpipe(udev, 0x02); |
| 83 | memcpy(send_buf, firmware->data + sent, size); |
Vikram Kandukuri | 9670d80 | 2010-01-06 19:04:15 +0530 | [diff] [blame] | 84 | |
Alexander Holler | 86e0928 | 2010-11-22 21:09:01 +0100 | [diff] [blame] | 85 | err = usb_bulk_msg(udev, pipe, send_buf, size, |
Vikram Kandukuri | 9670d80 | 2010-01-06 19:04:15 +0530 | [diff] [blame] | 86 | &len, 3000); |
| 87 | |
| 88 | if (err || (len != size)) { |
| 89 | BT_ERR("Error in firmware loading err = %d," |
| 90 | "len = %d, size = %d", err, len, size); |
| 91 | goto error; |
| 92 | } |
| 93 | |
| 94 | sent += size; |
| 95 | count -= size; |
| 96 | } |
| 97 | |
| 98 | kfree(send_buf); |
| 99 | return 0; |
| 100 | |
| 101 | error: |
| 102 | kfree(send_buf); |
| 103 | return err; |
| 104 | } |
| 105 | |
| 106 | static int ath3k_probe(struct usb_interface *intf, |
| 107 | const struct usb_device_id *id) |
| 108 | { |
| 109 | const struct firmware *firmware; |
| 110 | struct usb_device *udev = interface_to_usbdev(intf); |
Rogério Brito | 84f0e17 | 2011-02-03 01:42:05 -0200 | [diff] [blame] | 111 | int ret; |
Vikram Kandukuri | 9670d80 | 2010-01-06 19:04:15 +0530 | [diff] [blame] | 112 | |
| 113 | BT_DBG("intf %p id %p", intf, id); |
| 114 | |
| 115 | if (intf->cur_altsetting->desc.bInterfaceNumber != 0) |
| 116 | return -ENODEV; |
| 117 | |
Vikram Kandukuri | 9670d80 | 2010-01-06 19:04:15 +0530 | [diff] [blame] | 118 | if (request_firmware(&firmware, "ath3k-1.fw", &udev->dev) < 0) { |
Vikram Kandukuri | 9670d80 | 2010-01-06 19:04:15 +0530 | [diff] [blame] | 119 | return -EIO; |
| 120 | } |
| 121 | |
Rogério Brito | 84f0e17 | 2011-02-03 01:42:05 -0200 | [diff] [blame] | 122 | ret = ath3k_load_firmware(udev, firmware); |
Alexander Holler | 86e0928 | 2010-11-22 21:09:01 +0100 | [diff] [blame] | 123 | release_firmware(firmware); |
Vikram Kandukuri | 9670d80 | 2010-01-06 19:04:15 +0530 | [diff] [blame] | 124 | |
Rogério Brito | 84f0e17 | 2011-02-03 01:42:05 -0200 | [diff] [blame] | 125 | return ret; |
Vikram Kandukuri | 9670d80 | 2010-01-06 19:04:15 +0530 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | static void ath3k_disconnect(struct usb_interface *intf) |
| 129 | { |
Vikram Kandukuri | 9670d80 | 2010-01-06 19:04:15 +0530 | [diff] [blame] | 130 | BT_DBG("ath3k_disconnect intf %p", intf); |
Vikram Kandukuri | 9670d80 | 2010-01-06 19:04:15 +0530 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | static struct usb_driver ath3k_driver = { |
| 134 | .name = "ath3k", |
| 135 | .probe = ath3k_probe, |
| 136 | .disconnect = ath3k_disconnect, |
| 137 | .id_table = ath3k_table, |
| 138 | }; |
| 139 | |
| 140 | static int __init ath3k_init(void) |
| 141 | { |
| 142 | BT_INFO("Atheros AR30xx firmware driver ver %s", VERSION); |
| 143 | return usb_register(&ath3k_driver); |
| 144 | } |
| 145 | |
| 146 | static void __exit ath3k_exit(void) |
| 147 | { |
| 148 | usb_deregister(&ath3k_driver); |
| 149 | } |
| 150 | |
| 151 | module_init(ath3k_init); |
| 152 | module_exit(ath3k_exit); |
| 153 | |
| 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"); |