ath3k.c 3.6 KB

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