ath3k.c 3.8 KB

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