2 * Copyright (c) 2007-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <linux/module.h>
19 #include <linux/usb.h>
24 /* usb device object */
26 struct usb_device *udev;
27 struct usb_interface *interface;
33 /* diagnostic command defnitions */
34 #define ATH6KL_USB_CONTROL_REQ_SEND_BMI_CMD 1
35 #define ATH6KL_USB_CONTROL_REQ_RECV_BMI_RESP 2
36 #define ATH6KL_USB_CONTROL_REQ_DIAG_CMD 3
37 #define ATH6KL_USB_CONTROL_REQ_DIAG_RESP 4
39 #define ATH6KL_USB_CTRL_DIAG_CC_READ 0
40 #define ATH6KL_USB_CTRL_DIAG_CC_WRITE 1
42 struct ath6kl_usb_ctrl_diag_cmd_write {
49 struct ath6kl_usb_ctrl_diag_cmd_read {
54 struct ath6kl_usb_ctrl_diag_resp_read {
58 #define ATH6KL_USB_MAX_DIAG_CMD (sizeof(struct ath6kl_usb_ctrl_diag_cmd_write))
59 #define ATH6KL_USB_MAX_DIAG_RESP (sizeof(struct ath6kl_usb_ctrl_diag_resp_read))
61 static void ath6kl_usb_destroy(struct ath6kl_usb *ar_usb)
63 usb_set_intfdata(ar_usb->interface, NULL);
65 kfree(ar_usb->diag_cmd_buffer);
66 kfree(ar_usb->diag_resp_buffer);
71 static struct ath6kl_usb *ath6kl_usb_create(struct usb_interface *interface)
73 struct ath6kl_usb *ar_usb = NULL;
74 struct usb_device *dev = interface_to_usbdev(interface);
77 ar_usb = kzalloc(sizeof(struct ath6kl_usb), GFP_KERNEL);
79 goto fail_ath6kl_usb_create;
81 memset(ar_usb, 0, sizeof(struct ath6kl_usb));
82 usb_set_intfdata(interface, ar_usb);
84 ar_usb->interface = interface;
86 ar_usb->diag_cmd_buffer = kzalloc(ATH6KL_USB_MAX_DIAG_CMD, GFP_KERNEL);
87 if (ar_usb->diag_cmd_buffer == NULL) {
89 goto fail_ath6kl_usb_create;
92 ar_usb->diag_resp_buffer = kzalloc(ATH6KL_USB_MAX_DIAG_RESP,
94 if (ar_usb->diag_resp_buffer == NULL) {
96 goto fail_ath6kl_usb_create;
99 fail_ath6kl_usb_create:
101 ath6kl_usb_destroy(ar_usb);
107 static void ath6kl_usb_device_detached(struct usb_interface *interface)
109 struct ath6kl_usb *ar_usb;
111 ar_usb = usb_get_intfdata(interface);
115 ath6kl_stop_txrx(ar_usb->ar);
117 ath6kl_core_cleanup(ar_usb->ar);
119 ath6kl_usb_destroy(ar_usb);
122 static int ath6kl_usb_submit_ctrl_out(struct ath6kl_usb *ar_usb,
123 u8 req, u16 value, u16 index, void *data,
130 buf = kmalloc(size, GFP_KERNEL);
134 memcpy(buf, data, size);
137 /* note: if successful returns number of bytes transfered */
138 ret = usb_control_msg(ar_usb->udev,
139 usb_sndctrlpipe(ar_usb->udev, 0),
141 USB_DIR_OUT | USB_TYPE_VENDOR |
142 USB_RECIP_DEVICE, value, index, buf,
146 ath6kl_dbg(ATH6KL_DBG_USB, "%s failed,result = %d\n",
155 static int ath6kl_usb_submit_ctrl_in(struct ath6kl_usb *ar_usb,
156 u8 req, u16 value, u16 index, void *data,
163 buf = kmalloc(size, GFP_KERNEL);
168 /* note: if successful returns number of bytes transfered */
169 ret = usb_control_msg(ar_usb->udev,
170 usb_rcvctrlpipe(ar_usb->udev, 0),
172 USB_DIR_IN | USB_TYPE_VENDOR |
173 USB_RECIP_DEVICE, value, index, buf,
177 ath6kl_dbg(ATH6KL_DBG_USB, "%s failed,result = %d\n",
181 memcpy((u8 *) data, buf, size);
188 static int ath6kl_usb_ctrl_msg_exchange(struct ath6kl_usb *ar_usb,
189 u8 req_val, u8 *req_buf, u32 req_len,
190 u8 resp_val, u8 *resp_buf, u32 *resp_len)
195 ret = ath6kl_usb_submit_ctrl_out(ar_usb, req_val, 0, 0,
201 if (resp_buf == NULL) {
202 /* no expected response */
207 ret = ath6kl_usb_submit_ctrl_in(ar_usb, resp_val, 0, 0,
208 resp_buf, *resp_len);
213 static int ath6kl_usb_diag_read32(struct ath6kl *ar, u32 address, u32 *data)
215 struct ath6kl_usb *ar_usb = ar->hif_priv;
216 struct ath6kl_usb_ctrl_diag_resp_read *resp;
217 struct ath6kl_usb_ctrl_diag_cmd_read *cmd;
221 cmd = (struct ath6kl_usb_ctrl_diag_cmd_read *) ar_usb->diag_cmd_buffer;
223 memset(cmd, 0, sizeof(*cmd));
224 cmd->cmd = ATH6KL_USB_CTRL_DIAG_CC_READ;
225 cmd->address = cpu_to_le32(address);
226 resp_len = sizeof(*resp);
228 ret = ath6kl_usb_ctrl_msg_exchange(ar_usb,
229 ATH6KL_USB_CONTROL_REQ_DIAG_CMD,
231 sizeof(struct ath6kl_usb_ctrl_diag_cmd_write),
232 ATH6KL_USB_CONTROL_REQ_DIAG_RESP,
233 ar_usb->diag_resp_buffer, &resp_len);
238 resp = (struct ath6kl_usb_ctrl_diag_resp_read *)
239 ar_usb->diag_resp_buffer;
241 *data = le32_to_cpu(resp->value);
246 static int ath6kl_usb_diag_write32(struct ath6kl *ar, u32 address, __le32 data)
248 struct ath6kl_usb *ar_usb = ar->hif_priv;
249 struct ath6kl_usb_ctrl_diag_cmd_write *cmd;
251 cmd = (struct ath6kl_usb_ctrl_diag_cmd_write *) ar_usb->diag_cmd_buffer;
253 memset(cmd, 0, sizeof(struct ath6kl_usb_ctrl_diag_cmd_write));
254 cmd->cmd = cpu_to_le32(ATH6KL_USB_CTRL_DIAG_CC_WRITE);
255 cmd->address = cpu_to_le32(address);
258 return ath6kl_usb_ctrl_msg_exchange(ar_usb,
259 ATH6KL_USB_CONTROL_REQ_DIAG_CMD,
266 static int ath6kl_usb_bmi_read(struct ath6kl *ar, u8 *buf, u32 len)
268 struct ath6kl_usb *ar_usb = ar->hif_priv;
272 ret = ath6kl_usb_submit_ctrl_in(ar_usb,
273 ATH6KL_USB_CONTROL_REQ_RECV_BMI_RESP,
276 ath6kl_err("Unable to read the bmi data from the device: %d\n",
284 static int ath6kl_usb_bmi_write(struct ath6kl *ar, u8 *buf, u32 len)
286 struct ath6kl_usb *ar_usb = ar->hif_priv;
290 ret = ath6kl_usb_submit_ctrl_out(ar_usb,
291 ATH6KL_USB_CONTROL_REQ_SEND_BMI_CMD,
294 ath6kl_err("unable to send the bmi data to the device: %d\n",
302 static int ath6kl_usb_power_on(struct ath6kl *ar)
307 static int ath6kl_usb_power_off(struct ath6kl *ar)
312 static const struct ath6kl_hif_ops ath6kl_usb_ops = {
313 .diag_read32 = ath6kl_usb_diag_read32,
314 .diag_write32 = ath6kl_usb_diag_write32,
315 .bmi_read = ath6kl_usb_bmi_read,
316 .bmi_write = ath6kl_usb_bmi_write,
317 .power_on = ath6kl_usb_power_on,
318 .power_off = ath6kl_usb_power_off,
321 /* ath6kl usb driver registered functions */
322 static int ath6kl_usb_probe(struct usb_interface *interface,
323 const struct usb_device_id *id)
325 struct usb_device *dev = interface_to_usbdev(interface);
327 struct ath6kl_usb *ar_usb = NULL;
328 int vendor_id, product_id;
333 vendor_id = le16_to_cpu(dev->descriptor.idVendor);
334 product_id = le16_to_cpu(dev->descriptor.idProduct);
336 ath6kl_dbg(ATH6KL_DBG_USB, "vendor_id = %04x\n", vendor_id);
337 ath6kl_dbg(ATH6KL_DBG_USB, "product_id = %04x\n", product_id);
339 if (interface->cur_altsetting)
340 ath6kl_dbg(ATH6KL_DBG_USB, "USB Interface %d\n",
341 interface->cur_altsetting->desc.bInterfaceNumber);
344 if (dev->speed == USB_SPEED_HIGH)
345 ath6kl_dbg(ATH6KL_DBG_USB, "USB 2.0 Host\n");
347 ath6kl_dbg(ATH6KL_DBG_USB, "USB 1.1 Host\n");
349 ar_usb = ath6kl_usb_create(interface);
351 if (ar_usb == NULL) {
356 ar = ath6kl_core_create(&ar_usb->udev->dev);
358 ath6kl_err("Failed to alloc ath6kl core\n");
360 goto err_usb_destroy;
363 ar->hif_priv = ar_usb;
364 ar->hif_type = ATH6KL_HIF_TYPE_USB;
365 ar->hif_ops = &ath6kl_usb_ops;
366 ar->mbox_info.block_size = 16;
367 ar->bmi.max_data_size = 252;
371 ret = ath6kl_core_init(ar, ATH6KL_HTC_TYPE_MBOX);
373 ath6kl_err("Failed to init ath6kl core: %d\n", ret);
380 ath6kl_core_destroy(ar);
382 ath6kl_usb_destroy(ar_usb);
389 static void ath6kl_usb_remove(struct usb_interface *interface)
391 usb_put_dev(interface_to_usbdev(interface));
392 ath6kl_usb_device_detached(interface);
395 /* table of devices that work with this driver */
396 static struct usb_device_id ath6kl_usb_ids[] = {
397 {USB_DEVICE(0x0cf3, 0x9374)},
398 { /* Terminating entry */ },
401 MODULE_DEVICE_TABLE(usb, ath6kl_usb_ids);
403 static struct usb_driver ath6kl_usb_driver = {
404 .name = "ath6kl_usb",
405 .probe = ath6kl_usb_probe,
406 .disconnect = ath6kl_usb_remove,
407 .id_table = ath6kl_usb_ids,
410 static int ath6kl_usb_init(void)
412 usb_register(&ath6kl_usb_driver);
416 static void ath6kl_usb_exit(void)
418 usb_deregister(&ath6kl_usb_driver);
421 module_init(ath6kl_usb_init);
422 module_exit(ath6kl_usb_exit);
424 MODULE_AUTHOR("Atheros Communications, Inc.");
425 MODULE_DESCRIPTION("Driver support for Atheros AR600x USB devices");
426 MODULE_LICENSE("Dual BSD/GPL");
427 MODULE_FIRMWARE(AR6004_HW_1_0_FIRMWARE_FILE);
428 MODULE_FIRMWARE(AR6004_HW_1_0_BOARD_DATA_FILE);
429 MODULE_FIRMWARE(AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE);
430 MODULE_FIRMWARE(AR6004_HW_1_1_FIRMWARE_FILE);
431 MODULE_FIRMWARE(AR6004_HW_1_1_BOARD_DATA_FILE);
432 MODULE_FIRMWARE(AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE);