X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=carlfw%2Fusb%2Fusb.c;h=0c66b8275b636e91d0a0c94e4070c32777ed6e68;hb=159041386daf775e24deefc1348288439e70c988;hp=f4b95d8b7e6d13cac23c39f17f210ad34e717d3b;hpb=6476369c2c6d4ba487408cb5daff8df0480d6b4a;p=carl9170fw.git diff --git a/carlfw/usb/usb.c b/carlfw/usb/usb.c index f4b95d8..0c66b82 100644 --- a/carlfw/usb/usb.c +++ b/carlfw/usb/usb.c @@ -6,7 +6,7 @@ * Copyright (c) 2000-2005 ZyDAS Technology Corporation * Copyright (c) 2007-2009 Atheros Communications, Inc. * Copyright 2009 Johannes Berg - * Copyright 2009 Christian Lamparter + * Copyright 2009-2011 Christian Lamparter * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -175,6 +175,7 @@ static void usb_reset_eps(void) for (i = 1; i < __AR9170_USB_NUM_MAX_EP; i++) { usb_set_input_ep_toggle(i); usb_clear_input_ep_toggle(i); + usb_clear_input_ep_stall(i); } /* @@ -184,12 +185,12 @@ static void usb_reset_eps(void) for (i = 1; i < __AR9170_USB_NUM_MAX_EP; i++) { usb_set_output_ep_toggle(i); usb_clear_output_ep_toggle(i); + usb_clear_output_ep_stall(i); } } #endif /* CONFIG_CARL9170FW_USB_MODESWITCH */ -#ifdef CONFIG_CARL9170FW_USB_INIT_FIRMWARE static void usb_pta_init(void) { unsigned int usb_dma_ctrl = 0; @@ -251,13 +252,10 @@ static void usb_pta_init(void) set(AR9170_USB_REG_DMA_CTL, usb_dma_ctrl); } -#endif /* CONFIG_CARL9170FW_USB_INIT_FIRMWARE */ void usb_init(void) { -#ifdef CONFIG_CARL9170FW_USB_INIT_FIRMWARE usb_pta_init(); -#endif /* CONFIG_CARL9170FW_USB_INIT_FIRMWARE */ fw.usb.config = 1; /* @@ -341,7 +339,30 @@ static int usb_get_status(const struct usb_ctrlrequest *ctrl) status = cpu_to_le16(0); break; - case USB_RECIP_ENDPOINT: + case USB_RECIP_ENDPOINT: { + unsigned int ep = le16_to_cpu(ctrl->wIndex) & 0xf; + unsigned int dir = le16_to_cpu(ctrl->wIndex) & USB_DIR_MASK; + + if (ep == 0) { + status = !!(getb(AR9170_USB_REG_CX_CONFIG_STATUS) & BIT(2)); + } else { + unsigned int addr; + + if (dir == USB_DIR_IN) + addr = AR9170_USB_REG_EP_IN_MAX_SIZE_HIGH; + else + addr = AR9170_USB_REG_EP_OUT_MAX_SIZE_HIGH; + + addr += (ep << 1); + + /* + * AR9170_USB_EP_OUT_STALL == AR9170_USB_EP_IN_STALL + * so it doesn't matter which one we use + */ + status = !!(getb(addr) & AR9170_USB_EP_OUT_STALL); + } + break; + } case USB_RECIP_OTHER: default: break; @@ -575,7 +596,8 @@ static int usb_get_interface(const struct usb_ctrlrequest *ctrl) static int usb_manipulate_feature(const struct usb_ctrlrequest *ctrl, bool __unused clear) { unsigned int feature; - if (USB_CHECK_REQTYPE(ctrl, USB_RECIP_DEVICE, USB_DIR_OUT)) + + if ((ctrl->bRequestType & USB_DIR_MASK) != USB_DIR_OUT) return -1; if (usb_configured() == false) @@ -583,19 +605,61 @@ static int usb_manipulate_feature(const struct usb_ctrlrequest *ctrl, bool __unu feature = le16_to_cpu(ctrl->wValue); + switch (ctrl->bRequestType & USB_RECIP_MASK) { + case USB_RECIP_DEVICE: { #ifdef CONFIG_CARL9170FW_WOL - if (feature & USB_DEVICE_REMOTE_WAKEUP) { + if (feature & USB_DEVICE_REMOTE_WAKEUP) { + if (clear) + usb_disable_remote_wakeup(); + else + usb_enable_remote_wakeup(); + } +#endif /* CONFIG_CARL9170FW_WOL */ + if (clear) - usb_disable_remote_wakeup(); + fw.usb.device_feature &= ~feature; else - usb_enable_remote_wakeup(); - } -#endif /* CONFIG_CARL9170FW_WOL */ + fw.usb.device_feature |= feature; + + + break; + } + + case USB_RECIP_ENDPOINT: { + unsigned int ep, dir; - if (clear) - fw.usb.device_feature &= ~feature; - else - fw.usb.device_feature |= feature; + ep = le16_to_cpu(ctrl->wIndex) & 0xf; + dir = le16_to_cpu(ctrl->wIndex) & USB_DIR_MASK; + if (ep == 0) { + /* According to the spec, EP cannot be stopped this way. */ + return -1; + } else { + unsigned int addr; + + if (dir == USB_DIR_IN) + addr = AR9170_USB_REG_EP_IN_MAX_SIZE_HIGH; + else + addr = AR9170_USB_REG_EP_OUT_MAX_SIZE_HIGH; + + addr += (ep << 1); + + if (clear) + andb(addr, ~AR9170_USB_EP_OUT_STALL); + else + orb(addr, AR9170_USB_EP_OUT_STALL); + } + break; + } + + case USB_RECIP_INTERFACE: + /* + * the current USB Specification Revision 2 + * specifies no interface features. + */ + + default: + return -1; + } return 1; } @@ -649,7 +713,7 @@ static int usb_standard_command(const struct usb_ctrlrequest *ctrl __unused) case USB_REQ_CLEAR_FEATURE: case USB_REQ_SET_FEATURE: - usb_manipulate_feature(ctrl, ctrl->bRequest == USB_REQ_CLEAR_FEATURE); + status = usb_manipulate_feature(ctrl, ctrl->bRequest == USB_REQ_CLEAR_FEATURE); break; case USB_REQ_SET_ADDRESS: