2 * Copyright (c) 2007-2011 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <linux/module.h>
18 #include <linux/usb.h>
23 /* usb device object */
25 struct usb_device *udev;
26 struct usb_interface *interface;
32 /* diagnostic command defnitions */
33 #define ATH6KL_USB_CONTROL_REQ_SEND_BMI_CMD 1
34 #define ATH6KL_USB_CONTROL_REQ_RECV_BMI_RESP 2
35 #define ATH6KL_USB_CONTROL_REQ_DIAG_CMD 3
36 #define ATH6KL_USB_CONTROL_REQ_DIAG_RESP 4
38 #define ATH6KL_USB_CTRL_DIAG_CC_READ 0
39 #define ATH6KL_USB_CTRL_DIAG_CC_WRITE 1
41 struct ath6kl_usb_ctrl_diag_cmd_write {
48 struct ath6kl_usb_ctrl_diag_cmd_read {
53 struct ath6kl_usb_ctrl_diag_resp_read {
57 #define ATH6KL_USB_MAX_DIAG_CMD (sizeof(struct ath6kl_usb_ctrl_diag_cmd_write))
58 #define ATH6KL_USB_MAX_DIAG_RESP (sizeof(struct ath6kl_usb_ctrl_diag_resp_read))
60 static void ath6kl_usb_destroy(struct ath6kl_usb *ar_usb)
62 usb_set_intfdata(ar_usb->interface, NULL);
64 kfree(ar_usb->diag_cmd_buffer);
65 kfree(ar_usb->diag_resp_buffer);
70 static struct ath6kl_usb *ath6kl_usb_create(struct usb_interface *interface)
72 struct ath6kl_usb *ar_usb = NULL;
73 struct usb_device *dev = interface_to_usbdev(interface);
76 ar_usb = kzalloc(sizeof(struct ath6kl_usb), GFP_KERNEL);
78 goto fail_ath6kl_usb_create;
80 memset(ar_usb, 0, sizeof(struct ath6kl_usb));
81 usb_set_intfdata(interface, ar_usb);
83 ar_usb->interface = interface;
85 ar_usb->diag_cmd_buffer = kzalloc(ATH6KL_USB_MAX_DIAG_CMD, GFP_KERNEL);
86 if (ar_usb->diag_cmd_buffer == NULL) {
88 goto fail_ath6kl_usb_create;
91 ar_usb->diag_resp_buffer = kzalloc(ATH6KL_USB_MAX_DIAG_RESP,
93 if (ar_usb->diag_resp_buffer == NULL) {
95 goto fail_ath6kl_usb_create;
98 fail_ath6kl_usb_create:
100 ath6kl_usb_destroy(ar_usb);
106 static void ath6kl_usb_device_detached(struct usb_interface *interface)
108 struct ath6kl_usb *ar_usb;
110 ar_usb = usb_get_intfdata(interface);
114 ath6kl_stop_txrx(ar_usb->ar);
116 ath6kl_core_cleanup(ar_usb->ar);
118 ath6kl_usb_destroy(ar_usb);
121 static int ath6kl_usb_submit_ctrl_out(struct ath6kl_usb *ar_usb,
122 u8 req, u16 value, u16 index, void *data,
129 buf = kmalloc(size, GFP_KERNEL);
133 memcpy(buf, data, size);
136 /* note: if successful returns number of bytes transfered */
137 ret = usb_control_msg(ar_usb->udev,
138 usb_sndctrlpipe(ar_usb->udev, 0),
140 USB_DIR_OUT | USB_TYPE_VENDOR |
141 USB_RECIP_DEVICE, value, index, buf,
145 ath6kl_dbg(ATH6KL_DBG_USB, "%s failed,result = %d\n",
154 static int ath6kl_usb_submit_ctrl_in(struct ath6kl_usb *ar_usb,
155 u8 req, u16 value, u16 index, void *data,
162 buf = kmalloc(size, GFP_KERNEL);
167 /* note: if successful returns number of bytes transfered */
168 ret = usb_control_msg(ar_usb->udev,
169 usb_rcvctrlpipe(ar_usb->udev, 0),
171 USB_DIR_IN | USB_TYPE_VENDOR |
172 USB_RECIP_DEVICE, value, index, buf,
176 ath6kl_dbg(ATH6KL_DBG_USB, "%s failed,result = %d\n",
180 memcpy((u8 *) data, buf, size);
187 static int ath6kl_usb_ctrl_msg_exchange(struct ath6kl_usb *ar_usb,
188 u8 req_val, u8 *req_buf, u32 req_len,
189 u8 resp_val, u8 *resp_buf, u32 *resp_len)
194 ret = ath6kl_usb_submit_ctrl_out(ar_usb, req_val, 0, 0,
200 if (resp_buf == NULL) {
201 /* no expected response */
206 ret = ath6kl_usb_submit_ctrl_in(ar_usb, resp_val, 0, 0,
207 resp_buf, *resp_len);
212 static int ath6kl_usb_diag_read32(struct ath6kl *ar, u32 address, u32 *data)
214 struct ath6kl_usb *ar_usb = ar->hif_priv;
215 struct ath6kl_usb_ctrl_diag_resp_read *resp;
216 struct ath6kl_usb_ctrl_diag_cmd_read *cmd;
220 cmd = (struct ath6kl_usb_ctrl_diag_cmd_read *) ar_usb->diag_cmd_buffer;
222 memset(cmd, 0, sizeof(*cmd));
223 cmd->cmd = ATH6KL_USB_CTRL_DIAG_CC_READ;
224 cmd->address = cpu_to_le32(address);
225 resp_len = sizeof(*resp);
227 ret = ath6kl_usb_ctrl_msg_exchange(ar_usb,
228 ATH6KL_USB_CONTROL_REQ_DIAG_CMD,
230 sizeof(struct ath6kl_usb_ctrl_diag_cmd_write),
231 ATH6KL_USB_CONTROL_REQ_DIAG_RESP,
232 ar_usb->diag_resp_buffer, &resp_len);
237 resp = (struct ath6kl_usb_ctrl_diag_resp_read *)
238 ar_usb->diag_resp_buffer;
240 *data = le32_to_cpu(resp->value);
245 static int ath6kl_usb_diag_write32(struct ath6kl *ar, u32 address, __le32 data)
247 struct ath6kl_usb *ar_usb = ar->hif_priv;
248 struct ath6kl_usb_ctrl_diag_cmd_write *cmd;
250 cmd = (struct ath6kl_usb_ctrl_diag_cmd_write *) ar_usb->diag_cmd_buffer;
252 memset(cmd, 0, sizeof(struct ath6kl_usb_ctrl_diag_cmd_write));
253 cmd->cmd = cpu_to_le32(ATH6KL_USB_CTRL_DIAG_CC_WRITE);
254 cmd->address = cpu_to_le32(address);
257 return ath6kl_usb_ctrl_msg_exchange(ar_usb,
258 ATH6KL_USB_CONTROL_REQ_DIAG_CMD,
265 static int ath6kl_usb_bmi_read(struct ath6kl *ar, u8 *buf, u32 len)
267 struct ath6kl_usb *ar_usb = ar->hif_priv;
271 ret = ath6kl_usb_submit_ctrl_in(ar_usb,
272 ATH6KL_USB_CONTROL_REQ_RECV_BMI_RESP,
275 ath6kl_err("Unable to read the bmi data from the device: %d\n",
283 static int ath6kl_usb_bmi_write(struct ath6kl *ar, u8 *buf, u32 len)
285 struct ath6kl_usb *ar_usb = ar->hif_priv;
289 ret = ath6kl_usb_submit_ctrl_out(ar_usb,
290 ATH6KL_USB_CONTROL_REQ_SEND_BMI_CMD,
293 ath6kl_err("unable to send the bmi data to the device: %d\n",
301 static int ath6kl_usb_power_on(struct ath6kl *ar)
306 static int ath6kl_usb_power_off(struct ath6kl *ar)
311 static const struct ath6kl_hif_ops ath6kl_usb_ops = {
312 .diag_read32 = ath6kl_usb_diag_read32,
313 .diag_write32 = ath6kl_usb_diag_write32,
314 .bmi_read = ath6kl_usb_bmi_read,
315 .bmi_write = ath6kl_usb_bmi_write,
316 .power_on = ath6kl_usb_power_on,
317 .power_off = ath6kl_usb_power_off,
320 /* ath6kl usb driver registered functions */
321 static int ath6kl_usb_probe(struct usb_interface *interface,
322 const struct usb_device_id *id)
324 struct usb_device *dev = interface_to_usbdev(interface);
326 struct ath6kl_usb *ar_usb = NULL;
327 int vendor_id, product_id;
332 vendor_id = le16_to_cpu(dev->descriptor.idVendor);
333 product_id = le16_to_cpu(dev->descriptor.idProduct);
335 ath6kl_dbg(ATH6KL_DBG_USB, "vendor_id = %04x\n", vendor_id);
336 ath6kl_dbg(ATH6KL_DBG_USB, "product_id = %04x\n", product_id);
338 if (interface->cur_altsetting)
339 ath6kl_dbg(ATH6KL_DBG_USB, "USB Interface %d\n",
340 interface->cur_altsetting->desc.bInterfaceNumber);
343 if (dev->speed == USB_SPEED_HIGH)
344 ath6kl_dbg(ATH6KL_DBG_USB, "USB 2.0 Host\n");
346 ath6kl_dbg(ATH6KL_DBG_USB, "USB 1.1 Host\n");
348 ar_usb = ath6kl_usb_create(interface);
350 if (ar_usb == NULL) {
355 ar = ath6kl_core_alloc(&ar_usb->udev->dev);
357 ath6kl_err("Failed to alloc ath6kl core\n");
359 goto err_usb_destroy;
362 ar->hif_priv = ar_usb;
363 ar->hif_type = ATH6KL_HIF_TYPE_USB;
364 ar->hif_ops = &ath6kl_usb_ops;
365 ar->mbox_info.block_size = 16;
366 ar->bmi.max_data_size = 252;
370 ret = ath6kl_core_init(ar);
372 ath6kl_err("Failed to init ath6kl core: %d\n", ret);
379 ath6kl_core_free(ar);
381 ath6kl_usb_destroy(ar_usb);
388 static void ath6kl_usb_remove(struct usb_interface *interface)
390 usb_put_dev(interface_to_usbdev(interface));
391 ath6kl_usb_device_detached(interface);
394 /* table of devices that work with this driver */
395 static struct usb_device_id ath6kl_usb_ids[] = {
396 {USB_DEVICE(0x0cf3, 0x9374)},
397 { /* Terminating entry */ },
400 MODULE_DEVICE_TABLE(usb, ath6kl_usb_ids);
402 static struct usb_driver ath6kl_usb_driver = {
403 .name = "ath6kl_usb",
404 .probe = ath6kl_usb_probe,
405 .disconnect = ath6kl_usb_remove,
406 .id_table = ath6kl_usb_ids,
409 static int ath6kl_usb_init(void)
411 usb_register(&ath6kl_usb_driver);
415 static void ath6kl_usb_exit(void)
417 usb_deregister(&ath6kl_usb_driver);
420 module_init(ath6kl_usb_init);
421 module_exit(ath6kl_usb_exit);
423 MODULE_AUTHOR("Atheros Communications, Inc.");
424 MODULE_DESCRIPTION("Driver support for Atheros AR600x USB devices");
425 MODULE_LICENSE("Dual BSD/GPL");
427 MODULE_FIRMWARE(AR6004_HW_1_0_FW_DIR "/" 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_FW_DIR "/" 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);