ath3k.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. #include <linux/module.h>
  20. #include <linux/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/slab.h>
  23. #include <linux/types.h>
  24. #include <linux/errno.h>
  25. #include <linux/device.h>
  26. #include <linux/firmware.h>
  27. #include <linux/usb.h>
  28. #include <net/bluetooth/bluetooth.h>
  29. #define VERSION "1.0"
  30. static struct usb_device_id ath3k_table[] = {
  31. /* Atheros AR3011 */
  32. { USB_DEVICE(0x0CF3, 0x3000) },
  33. /* Atheros AR3011 with sflash firmware*/
  34. { USB_DEVICE(0x0CF3, 0x3002) },
  35. /* Atheros AR9285 Malbec with sflash firmware */
  36. { USB_DEVICE(0x03F0, 0x311D) },
  37. { } /* Terminating entry */
  38. };
  39. MODULE_DEVICE_TABLE(usb, ath3k_table);
  40. #define USB_REQ_DFU_DNLOAD 1
  41. #define BULK_SIZE 4096
  42. static int ath3k_load_firmware(struct usb_device *udev,
  43. const struct firmware *firmware)
  44. {
  45. u8 *send_buf;
  46. int err, pipe, len, size, sent = 0;
  47. int count = firmware->size;
  48. BT_DBG("udev %p", udev);
  49. pipe = usb_sndctrlpipe(udev, 0);
  50. send_buf = kmalloc(BULK_SIZE, GFP_ATOMIC);
  51. if (!send_buf) {
  52. BT_ERR("Can't allocate memory chunk for firmware");
  53. return -ENOMEM;
  54. }
  55. memcpy(send_buf, firmware->data, 20);
  56. if ((err = usb_control_msg(udev, pipe,
  57. USB_REQ_DFU_DNLOAD,
  58. USB_TYPE_VENDOR, 0, 0,
  59. send_buf, 20, USB_CTRL_SET_TIMEOUT)) < 0) {
  60. BT_ERR("Can't change to loading configuration err");
  61. goto error;
  62. }
  63. sent += 20;
  64. count -= 20;
  65. while (count) {
  66. size = min_t(uint, count, BULK_SIZE);
  67. pipe = usb_sndbulkpipe(udev, 0x02);
  68. memcpy(send_buf, firmware->data + sent, size);
  69. err = usb_bulk_msg(udev, pipe, send_buf, size,
  70. &len, 3000);
  71. if (err || (len != size)) {
  72. BT_ERR("Error in firmware loading err = %d,"
  73. "len = %d, size = %d", err, len, size);
  74. goto error;
  75. }
  76. sent += size;
  77. count -= size;
  78. }
  79. kfree(send_buf);
  80. return 0;
  81. error:
  82. kfree(send_buf);
  83. return err;
  84. }
  85. static int ath3k_probe(struct usb_interface *intf,
  86. const struct usb_device_id *id)
  87. {
  88. const struct firmware *firmware;
  89. struct usb_device *udev = interface_to_usbdev(intf);
  90. BT_DBG("intf %p id %p", intf, id);
  91. if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
  92. return -ENODEV;
  93. if (request_firmware(&firmware, "ath3k-1.fw", &udev->dev) < 0) {
  94. return -EIO;
  95. }
  96. if (ath3k_load_firmware(udev, firmware)) {
  97. release_firmware(firmware);
  98. return -EIO;
  99. }
  100. release_firmware(firmware);
  101. return 0;
  102. }
  103. static void ath3k_disconnect(struct usb_interface *intf)
  104. {
  105. BT_DBG("ath3k_disconnect intf %p", intf);
  106. }
  107. static struct usb_driver ath3k_driver = {
  108. .name = "ath3k",
  109. .probe = ath3k_probe,
  110. .disconnect = ath3k_disconnect,
  111. .id_table = ath3k_table,
  112. };
  113. static int __init ath3k_init(void)
  114. {
  115. BT_INFO("Atheros AR30xx firmware driver ver %s", VERSION);
  116. return usb_register(&ath3k_driver);
  117. }
  118. static void __exit ath3k_exit(void)
  119. {
  120. usb_deregister(&ath3k_driver);
  121. }
  122. module_init(ath3k_init);
  123. module_exit(ath3k_exit);
  124. MODULE_AUTHOR("Atheros Communications");
  125. MODULE_DESCRIPTION("Atheros AR30xx firmware driver");
  126. MODULE_VERSION(VERSION);
  127. MODULE_LICENSE("GPL");
  128. MODULE_FIRMWARE("ath3k-1.fw");