fix missing licenses
[open-ath9k-htc-firmware.git] / target_firmware / magpie_fw_dev / target / hif / usb_api_main_patch.c
index f6be408b14d41b72d430f9003cf064129efee1b4..b7cbfab02f08f149569431a11e064f1ff10320f4 100644 (file)
@@ -1,3 +1,44 @@
+/*
+ * Copyright (c) 2013 Qualcomm Atheros, Inc.
+ * Copyright (c) 2016 Oleksij Rempel <linux@rempel-privat.de>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted (subject to the limitations in the
+ * disclaimer below) provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *  * Neither the name of Qualcomm Atheros nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
+ * GRANTED BY THIS LICENSE.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
+ * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* shared patches for k2 and magpie */
+
+#include <ah_osdep.h>
+#include <rom.h>
 
 #include "usb_defs.h"
 #include "usb_type.h"
@@ -8,6 +49,8 @@
 #include "athos_api.h"
 #include "usbfifo_api.h"
 
+#include "adf_os_io.h"
+
 #include "sys_cfg.h"
 
 #define USB_EP4_MAX_PKT_SIZE bUSB_EP_MAX_PKT_SIZE_64
 
 extern USB_FIFO_CONFIG usbFifoConf;
 extern Action eUsbCxFinishAction;
+extern void _fw_usb_suspend_reboot();
+
+typedef void (* USBFIFO_recv_command)(VBUF *cmd);
+USBFIFO_recv_command m_origUsbfifoRecvCmd = NULL;
+
+void _fw_usbfifo_recv_command(VBUF *buf)
+{
+       uint8_t *cmd_data;
+       uint32_t tmp;
+
+       cmd_data = (uint8_t *)(buf->desc_list->buf_addr +
+                               buf->desc_list->data_offset);
+       tmp = *((uint32_t *)cmd_data);
+       if (tmp == 0xFFFFFFFF)
+               _fw_usb_suspend_reboot();
+       else
+               m_origUsbfifoRecvCmd(buf);
+}
+
+void _fw_usbfifo_init(USB_FIFO_CONFIG *pConfig)
+{
+       m_origUsbfifoRecvCmd = pConfig->recv_command;
+
+       usbFifoConf.get_command_buf = pConfig->get_command_buf;
+       usbFifoConf.recv_command    = _fw_usbfifo_recv_command;
+       usbFifoConf.get_event_buf   = pConfig->get_event_buf;
+       usbFifoConf.send_event_done = pConfig->send_event_done;
+}
 
 void cold_reboot(void)
 {
        A_PRINTF("Cold reboot initiated.");
 #if defined(PROJECT_MAGPIE)
-       HAL_WORD_REG_WRITE(WATCH_DOG_MAGIC_PATTERN_ADDR, 0);
+       iowrite32(WATCH_DOG_MAGIC_PATTERN_ADDR, 0);
 #elif defined(PROJECT_K2)
-       HAL_WORD_REG_WRITE(MAGPIE_REG_RST_STATUS_ADDR, 0);
+       iowrite32(MAGPIE_REG_RST_STATUS_ADDR, 0);
 #endif /* #if defined(PROJECT_MAGPIE) */
        A_USB_JUMP_BOOT();
 }
@@ -68,7 +139,7 @@ void usb_status_in_patch(void)
        /* INT use EP3 */
        for (count = 0; count < (reg_buf_len / 4); count++)
        {
-               USB_WORD_REG_WRITE(ZM_EP3_DATA_OFFSET, *regaddr);
+               iowrite32_usb(ZM_EP3_DATA_OFFSET, *regaddr);
                regaddr++;
        }
 
@@ -77,20 +148,20 @@ void usb_status_in_patch(void)
        if (remainder) {
                switch(remainder) {
                case 3:
-                       USB_WORD_REG_WRITE(ZM_CBUS_FIFO_SIZE_OFFSET, 0x7);
+                       iowrite32_usb(ZM_CBUS_FIFO_SIZE_OFFSET, 0x7);
                        break;
                case 2:
-                       USB_WORD_REG_WRITE(ZM_CBUS_FIFO_SIZE_OFFSET, 0x3);
+                       iowrite32_usb(ZM_CBUS_FIFO_SIZE_OFFSET, 0x3);
                        break;
                case 1:
-                       USB_WORD_REG_WRITE(ZM_CBUS_FIFO_SIZE_OFFSET, 0x1);
+                       iowrite32_usb(ZM_CBUS_FIFO_SIZE_OFFSET, 0x1);
                        break;
                }
 
-               USB_WORD_REG_WRITE(ZM_EP3_DATA_OFFSET, *regaddr);
+               iowrite32_usb(ZM_EP3_DATA_OFFSET, *regaddr);
 
                /* Restore CBus FIFO size to word size */
-               USB_WORD_REG_WRITE(ZM_CBUS_FIFO_SIZE_OFFSET, 0xF);
+               iowrite32_usb(ZM_CBUS_FIFO_SIZE_OFFSET, 0xF);
        }
 
        mUSB_EP3_XFER_DONE();
@@ -116,7 +187,7 @@ void usb_reg_out_patch(void)
        static BOOLEAN cmd_is_new = TRUE;
 
        /* get the size of this transcation */
-       usbfifolen = USB_BYTE_REG_READ(ZM_EP4_BYTE_COUNT_LOW_OFFSET);
+       usbfifolen = ioread8_usb(ZM_EP4_BYTE_COUNT_LOW_OFFSET);
 
        if (usbfifolen > USB_EP4_MAX_PKT_SIZE) {
                A_PRINTF("EP4 FIFO Bug? Buffer is too big: %x\n", usbfifolen);
@@ -168,7 +239,7 @@ void usb_reg_out_patch(void)
        /* retrieve the data from fifo */
        for(ii = 0; ii < usbfifolen; ii++) {
                /* read fifo data out */
-               ep4_data = USB_WORD_REG_READ(ZM_EP4_DATA_OFFSET);
+               ep4_data = ioread32_usb(ZM_EP4_DATA_OFFSET);
                *regaddr = ep4_data;
                regaddr++;
        }
@@ -193,7 +264,7 @@ err:
         * but if we return here, the ep4 fifo will be lock out,
         * so that we still read them out but just drop it? */
        for(ii = 0; ii < usbfifolen; ii++)
-               ep4_data = USB_WORD_REG_READ(ZM_EP4_DATA_OFFSET);
+               ep4_data = ioread32_usb(ZM_EP4_DATA_OFFSET);
 
 done:
        /* mUSB_STATUS_IN_INT_ENABLE(); */
@@ -347,3 +418,76 @@ BOOLEAN bStandardCommand_patch(void)
                return bStandardCommand();
 }
 
+/*
+ * usb descriptor patch
+ */
+
+extern uint16_t                *u8ConfigDescriptorEX;
+extern uint16_t                *pu8DescriptorEX;
+extern uint16_t                u16TxRxCounter;
+extern SetupPacket     ControlCmd;
+extern uint16_t                *u8UsbDeviceDescriptor;
+extern BOOLEAN         bGet_descriptor(void);
+
+uint16_t ConfigDescriptorPatch[30];
+uint16_t UsbDeviceDescriptorPatch[9];
+
+#define BCD_DEVICE_OFFSET              6
+#define BCD_DEVICE_FW_SIGNATURE                0xffff
+#define VENDOR_ID_OFFSET               4
+#define PRODUCT_ID_OFFSET              5
+
+#define EP3_TRANSFER_TYPE_OFFSET       17
+#define EP3_INT_INTERVAL               19
+#define EP4_TRANSFER_TYPE_OFFSET       21
+#define EP4_INT_INTERVAL               22
+
+BOOLEAN bGet_descriptor_patch(void)
+{
+       if (mDEV_REQ_VALUE_HIGH() == 1)
+       {
+               uint8_t *p = (uint8_t *)u8UsbDeviceDescriptor;
+
+               /* Copy Usb Device Descriptor */
+               ath_hal_memcpy(UsbDeviceDescriptorPatch, p,
+                               sizeof(UsbDeviceDescriptorPatch));
+
+               /* Change bcdDevice. we need it to detect if FW
+                * was uploaded. */
+               UsbDeviceDescriptorPatch[BCD_DEVICE_OFFSET] =
+                       BCD_DEVICE_FW_SIGNATURE;
+
+               pu8DescriptorEX = UsbDeviceDescriptorPatch;
+               u16TxRxCounter = mTABLE_LEN(u8UsbDeviceDescriptor[0]);
+
+               if (u16TxRxCounter > mDEV_REQ_LENGTH())
+                       u16TxRxCounter = mDEV_REQ_LENGTH();
+
+               A_USB_EP0_TX_DATA();
+
+               return TRUE;
+       } else if (mDEV_REQ_VALUE_HIGH() == 2) {
+               uint8_t *p = (uint8_t *)u8ConfigDescriptorEX;
+
+               /* Copy ConfigDescriptor */
+               ath_hal_memcpy(ConfigDescriptorPatch, p,
+                               sizeof(ConfigDescriptorPatch));
+
+                /* place holder for EPx patches */
+
+               if (mDEV_REQ_VALUE_LOW() == 0) {
+                       /* configuration no: 0 */
+                       pu8DescriptorEX = ConfigDescriptorPatch;
+                       u16TxRxCounter = ConfigDescriptorPatch[1];
+               } else
+                       return FALSE;
+
+               if (u16TxRxCounter > mDEV_REQ_LENGTH())
+                       u16TxRxCounter = mDEV_REQ_LENGTH();
+
+               A_USB_EP0_TX_DATA();
+               return TRUE;
+       } else
+               return bGet_descriptor();
+}
+