ramips: fix switch names for several boards in device tree
[openwrt/openwrt.git] / target / linux / ramips / patches-3.18 / 0062-mt7621-add-ECHI-OCHI-XCHI-support.patch
index d9d61ffa5c1981933dbda3e829148bcbc0acbf79..fb9b9f3e88110d49e6b9c5f0bc6865f7fdfa1435 100644 (file)
@@ -1,17 +1,6 @@
---- a/drivers/usb/Makefile
-+++ b/drivers/usb/Makefile
-@@ -11,6 +11,8 @@ obj-$(CONFIG_USB_DWC2)               += dwc2/
- obj-$(CONFIG_USB_MON)         += mon/
-+obj-$(CONFIG_USB_PHY)         += phy/
-+
- obj-$(CONFIG_PCI)             += host/
- obj-$(CONFIG_USB_EHCI_HCD)    += host/
- obj-$(CONFIG_USB_ISP116X_HCD) += host/
 --- a/drivers/usb/core/hcd-pci.c
 +++ b/drivers/usb/core/hcd-pci.c
-@@ -214,8 +214,13 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
+@@ -214,8 +214,13 @@ int usb_hcd_pci_probe(struct pci_dev *de
                goto disable_pci;
        }
  
@@ -27,7 +16,7 @@
                /* EHCI, OHCI */
 --- a/drivers/usb/core/hub.c
 +++ b/drivers/usb/core/hub.c
-@@ -1286,7 +1286,7 @@ static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type)
+@@ -1286,7 +1286,7 @@ static void hub_quiesce(struct usb_hub *
        if (type != HUB_SUSPEND) {
                /* Disconnect all the children */
                for (i = 0; i < hdev->maxchild; ++i) {
@@ -38,7 +27,7 @@
        }
 --- a/drivers/usb/core/port.c
 +++ b/drivers/usb/core/port.c
-@@ -480,8 +480,10 @@ void usb_hub_remove_port_device(struct usb_hub *hub, int port1)
+@@ -480,8 +480,10 @@ void usb_hub_remove_port_device(struct u
        struct usb_port *port_dev = hub->ports[port1 - 1];
        struct usb_port *peer;
  
@@ -55,7 +44,7 @@
  }
 --- a/drivers/usb/host/Kconfig
 +++ b/drivers/usb/host/Kconfig
-@@ -32,7 +32,12 @@ config USB_XHCI_PCI
+@@ -32,7 +32,13 @@ config USB_XHCI_PCI
         default y
  
  config USB_XHCI_PLATFORM
 +      bool "MTK MT7621 xHCI"
 +      depends on USB_XHCI_PLATFORM
 +      depends on SOC_MT7621
++      select USB_PHY
  
  config USB_XHCI_MVEBU
        tristate "xHCI support for Marvell Armada 375/38x"
+@@ -589,7 +595,7 @@ endif # USB_OHCI_HCD
+ config USB_UHCI_HCD
+       tristate "UHCI HCD (most Intel and VIA) support"
+-      depends on PCI || USB_UHCI_SUPPORT_NON_PCI_HC
++      depends on BROKEN && (PCI || USB_UHCI_SUPPORT_NON_PCI_HC)
+       ---help---
+         The Universal Host Controller Interface is a standard by Intel for
+         accessing the USB hardware in the PC (which is also called the USB
 --- a/drivers/usb/host/Makefile
 +++ b/drivers/usb/host/Makefile
 @@ -16,7 +16,12 @@ xhci-hcd-y := xhci.o xhci-mem.o
  obj-$(CONFIG_USB_XHCI_PLATFORM) += xhci-plat-hcd.o
  
  obj-$(CONFIG_USB_EHCI_HCD)    += ehci-hcd.o
---- a/drivers/usb/host/ehci-platform.c
-+++ b/drivers/usb/host/ehci-platform.c
-@@ -33,6 +33,8 @@
- #include <linux/usb.h>
- #include <linux/usb/hcd.h>
- #include <linux/usb/ehci_pdriver.h>
-+#include <linux/usb/phy.h>
-+#include <linux/usb/otg.h>
- #include "ehci.h"
-@@ -255,6 +257,15 @@ static int ehci_platform_probe(struct platform_device *dev)
-       hcd->rsrc_start = res_mem->start;
-       hcd->rsrc_len = resource_size(res_mem);
-+#ifdef CONFIG_USB_PHY
-+      hcd->phy = devm_usb_get_phy(&dev->dev, USB_PHY_TYPE_USB2);
-+      if (!IS_ERR_OR_NULL(hcd->phy)) {
-+              otg_set_host(hcd->phy->otg,
-+                              &hcd->self);
-+              usb_phy_init(hcd->phy);
-+      }
-+#endif
-+
-       hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
-       if (IS_ERR(hcd->regs)) {
-               err = PTR_ERR(hcd->regs);
 --- /dev/null
 +++ b/drivers/usb/host/mtk-phy-7621.c
 @@ -0,0 +1,445 @@
 +/***********************************/
 +#endif
 +
---- a/drivers/usb/host/ohci-platform.c
-+++ b/drivers/usb/host/ohci-platform.c
-@@ -27,7 +27,10 @@
- #include <linux/reset.h>
- #include <linux/usb/ohci_pdriver.h>
- #include <linux/usb.h>
-+#include <linux/usb/phy.h>
- #include <linux/usb/hcd.h>
-+#include <linux/dma-mapping.h>
-+#include <linux/of.h>
- #include "ohci.h"
-@@ -41,6 +44,7 @@ struct ohci_platform_priv {
-       struct phy *phy;
- };
-+static struct usb_ohci_pdata ohci_platform_defaults;
- static const char hcd_name[] = "ohci-platform";
- static int ohci_platform_reset(struct usb_hcd *hcd)
-@@ -239,6 +243,12 @@ static int ohci_platform_probe(struct platform_device *dev)
-       hcd->rsrc_start = res_mem->start;
-       hcd->rsrc_len = resource_size(res_mem);
-+#ifdef CONFIG_USB_PHY
-+      hcd->phy = devm_usb_get_phy(&dev->dev, USB_PHY_TYPE_USB2);
-+      if (!IS_ERR_OR_NULL(hcd->phy))
-+              usb_phy_init(hcd->phy);
-+#endif
-+
-       hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
-       if (IS_ERR(hcd->regs)) {
-               err = PTR_ERR(hcd->regs);
 --- a/drivers/usb/host/pci-quirks.h
 +++ b/drivers/usb/host/pci-quirks.h
 @@ -1,7 +1,7 @@
  
 --- a/drivers/usb/host/xhci-mem.c
 +++ b/drivers/usb/host/xhci-mem.c
-@@ -67,6 +67,9 @@ static struct xhci_segment *xhci_segment_alloc(struct xhci_hcd *xhci,
+@@ -67,6 +67,9 @@ static struct xhci_segment *xhci_segment
  
  static void xhci_segment_free(struct xhci_hcd *xhci, struct xhci_segment *seg)
  {
        if (seg->trbs) {
                dma_pool_free(xhci->segment_pool, seg->trbs, seg->dma);
                seg->trbs = NULL;
-@@ -1475,9 +1478,17 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
+@@ -1475,9 +1478,17 @@ int xhci_endpoint_init(struct xhci_hcd *
                        max_burst = (usb_endpoint_maxp(&ep->desc)
                                     & 0x1800) >> 11;
                }
 +#endif
 --- a/drivers/usb/host/xhci-plat.c
 +++ b/drivers/usb/host/xhci-plat.c
-@@ -33,6 +33,13 @@ static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
+@@ -33,6 +33,13 @@ static void xhci_plat_quirks(struct devi
         * dev struct in order to setup MSI
         */
        xhci->quirks |= XHCI_PLAT;
  }
  
  /* called during probe() after chip reset completes */
-@@ -79,7 +86,11 @@ static int xhci_plat_probe(struct platform_device *pdev)
+@@ -79,7 +86,11 @@ static int xhci_plat_probe(struct platfo
  
        driver = &xhci_plat_hc_driver;
  
  
 --- a/drivers/usb/host/xhci-ring.c
 +++ b/drivers/usb/host/xhci-ring.c
-@@ -254,16 +254,20 @@ static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring,
+@@ -254,16 +254,20 @@ static void inc_enq(struct xhci_hcd *xhc
  static inline int room_on_ring(struct xhci_hcd *xhci, struct xhci_ring *ring,
                unsigned int num_trbs)
  {
  
        return 1;
  }
-@@ -2799,6 +2803,7 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
+@@ -2805,6 +2809,7 @@ static int prepare_ring(struct xhci_hcd
                next = ring->enqueue;
  
                while (last_trb(xhci, ring, ring->enq_seg, next)) {
                        /* If we're not dealing with 0.95 hardware or isoc rings
                         * on AMD 0.96 host, clear the chain bit.
                         */
-@@ -2808,6 +2813,9 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
+@@ -2814,6 +2819,9 @@ static int prepare_ring(struct xhci_hcd
                                next->link.control &= cpu_to_le32(~TRB_CHAIN);
                        else
                                next->link.control |= cpu_to_le32(TRB_CHAIN);
  
                        wmb();
                        next->link.control ^= cpu_to_le32(TRB_CYCLE);
-@@ -2938,6 +2946,9 @@ static void giveback_first_trb(struct xhci_hcd *xhci, int slot_id,
+@@ -2944,6 +2952,9 @@ static void giveback_first_trb(struct xh
                start_trb->field[3] |= cpu_to_le32(start_cycle);
        else
                start_trb->field[3] &= cpu_to_le32(~TRB_CYCLE);
        xhci_ring_ep_doorbell(xhci, slot_id, ep_index, stream_id);
  }
  
-@@ -2993,6 +3004,29 @@ static u32 xhci_td_remainder(unsigned int remainder)
+@@ -2999,6 +3010,29 @@ static u32 xhci_td_remainder(unsigned in
                return (remainder >> 10) << 17;
  }
  
  /*
   * For xHCI 1.0 host controllers, TD size is the number of max packet sized
   * packets remaining in the TD (*not* including this TRB).
-@@ -3130,6 +3164,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
+@@ -3136,6 +3170,7 @@ static int queue_bulk_sg_tx(struct xhci_
                }
  
                /* Set the TRB length, TD size, and interrupter fields. */
                if (xhci->hci_version < 0x100) {
                        remainder = xhci_td_remainder(
                                        urb->transfer_buffer_length -
-@@ -3139,6 +3174,12 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
+@@ -3145,6 +3180,12 @@ static int queue_bulk_sg_tx(struct xhci_
                                        trb_buff_len, total_packet_count, urb,
                                        num_trbs - 1);
                }
                length_field = TRB_LEN(trb_buff_len) |
                        remainder |
                        TRB_INTR_TARGET(0);
-@@ -3201,6 +3242,9 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
+@@ -3207,6 +3248,9 @@ int xhci_queue_bulk_tx(struct xhci_hcd *
        int running_total, trb_buff_len, ret;
        unsigned int total_packet_count;
        u64 addr;
  
        if (urb->num_sgs)
                return queue_bulk_sg_tx(xhci, mem_flags, urb, slot_id, ep_index);
-@@ -3226,6 +3270,25 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
+@@ -3232,6 +3276,25 @@ int xhci_queue_bulk_tx(struct xhci_hcd *
                running_total += TRB_MAX_BUFF_SIZE;
        }
        /* FIXME: this doesn't deal with URB_ZERO_PACKET - need one more */
  
        ret = prepare_transfer(xhci, xhci->devs[slot_id],
                        ep_index, urb->stream_id,
-@@ -3285,6 +3348,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
+@@ -3291,6 +3354,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *
                        field |= TRB_ISP;
  
                /* Set the TRB length, TD size, and interrupter fields. */
                if (xhci->hci_version < 0x100) {
                        remainder = xhci_td_remainder(
                                        urb->transfer_buffer_length -
-@@ -3294,6 +3358,10 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
+@@ -3300,6 +3364,10 @@ int xhci_queue_bulk_tx(struct xhci_hcd *
                                        trb_buff_len, total_packet_count, urb,
                                        num_trbs - 1);
                }
                length_field = TRB_LEN(trb_buff_len) |
                        remainder |
                        TRB_INTR_TARGET(0);
-@@ -3383,7 +3451,11 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
+@@ -3389,7 +3457,11 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *
                field |= 0x1;
  
        /* xHCI 1.0 6.4.1.2.1: Transfer Type field */
                if (urb->transfer_buffer_length > 0) {
                        if (setup->bRequestType & USB_DIR_IN)
                                field |= TRB_TX_TYPE(TRB_DATA_IN);
-@@ -3407,7 +3479,12 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
+@@ -3413,7 +3485,12 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *
                field = TRB_TYPE(TRB_DATA);
  
        length_field = TRB_LEN(urb->transfer_buffer_length) |
                TRB_INTR_TARGET(0);
        if (urb->transfer_buffer_length > 0) {
                if (setup->bRequestType & USB_DIR_IN)
-@@ -3530,6 +3607,9 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
+@@ -3536,6 +3613,9 @@ static int xhci_queue_isoc_tx(struct xhc
        u64 start_addr, addr;
        int i, j;
        bool more_trbs_coming;
  
        ep_ring = xhci->devs[slot_id]->eps[ep_index].ring;
  
-@@ -3543,6 +3623,21 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
+@@ -3549,6 +3629,21 @@ static int xhci_queue_isoc_tx(struct xhc
        start_trb = &ep_ring->enqueue->generic;
        start_cycle = ep_ring->cycle_state;
  
        urb_priv = urb->hcpriv;
        /* Queue the first TRB, even if it's zero-length */
        for (i = 0; i < num_tds; i++) {
-@@ -3614,9 +3709,13 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
+@@ -3620,9 +3715,13 @@ static int xhci_queue_isoc_tx(struct xhc
                        } else {
                                td->last_trb = ep_ring->enqueue;
                                field |= TRB_IOC;
                                        /* Set BEI bit except for the last td */
                                        if (i < num_tds - 1)
                                                field |= TRB_BEI;
-@@ -3631,6 +3730,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
+@@ -3637,6 +3736,7 @@ static int xhci_queue_isoc_tx(struct xhc
                                trb_buff_len = td_remain_len;
  
                        /* Set the TRB length, TD size, & interrupter fields. */
                        if (xhci->hci_version < 0x100) {
                                remainder = xhci_td_remainder(
                                                td_len - running_total);
-@@ -3640,6 +3740,10 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
+@@ -3646,6 +3746,10 @@ static int xhci_queue_isoc_tx(struct xhc
                                                total_packet_count, urb,
                                                (trbs_per_td - j - 1));
                        }
  static int xhci_free_msi(struct xhci_hcd *xhci)
  {
        int i;
-@@ -448,6 +470,11 @@ static void compliance_mode_recovery(unsigned long arg)
+@@ -448,6 +470,11 @@ static void compliance_mode_recovery(uns
                                        "Attempting compliance mode recovery");
                        hcd = xhci->shared_hcd;
  
                        if (hcd->state == HC_STATE_SUSPENDED)
                                usb_hcd_resume_root_hub(hcd);
  
-@@ -497,6 +524,9 @@ static bool xhci_compliance_mode_recovery_timer_quirk_check(void)
+@@ -497,6 +524,9 @@ static bool xhci_compliance_mode_recover
  {
        const char *dmi_product_name, *dmi_sys_vendor;
  
        xhci_dbg_trace(xhci, trace_xhci_dbg_init,
                        "Finished xhci_run for USB2 roothub");
        return 0;
-@@ -1642,6 +1683,14 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
+@@ -1642,6 +1683,14 @@ int xhci_drop_endpoint(struct usb_hcd *h
        u32 drop_flag;
        u32 new_add_flags, new_drop_flags;
        int ret;
  
        ret = xhci_check_args(hcd, udev, ep, 1, true, __func__);
        if (ret <= 0)
-@@ -1689,6 +1738,40 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
+@@ -1689,6 +1738,40 @@ int xhci_drop_endpoint(struct usb_hcd *h
  
        xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep);
  
        xhci_dbg(xhci, "drop ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n",
                        (unsigned int) ep->desc.bEndpointAddress,
                        udev->slot_id,
-@@ -1721,6 +1804,19 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
+@@ -1721,6 +1804,19 @@ int xhci_add_endpoint(struct usb_hcd *hc
        u32 new_add_flags, new_drop_flags;
        struct xhci_virt_device *virt_dev;
        int ret = 0;
  
        ret = xhci_check_args(hcd, udev, ep, 1, true, __func__);
        if (ret <= 0) {
-@@ -1787,6 +1883,56 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
+@@ -1787,6 +1883,56 @@ int xhci_add_endpoint(struct usb_hcd *hc
                return -ENOMEM;
        }
  
        ctrl_ctx->add_flags |= cpu_to_le32(added_ctxs);
        new_add_flags = le32_to_cpu(ctrl_ctx->add_flags);
  
-@@ -4451,8 +4597,14 @@ static u16 xhci_call_host_update_timeout_for_endpoint(struct xhci_hcd *xhci,
+@@ -4451,8 +4597,14 @@ static u16 xhci_call_host_update_timeout
                u16 *timeout)
  {
        if (state == USB3_LPM_U1)
                return xhci_calculate_u2_timeout(xhci, udev, desc);
  
        return USB3_LPM_DISABLED;
-@@ -4837,7 +4989,9 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
+@@ -4837,7 +4989,9 @@ int xhci_gen_setup(struct usb_hcd *hcd,
        hcd->self.no_sg_constraint = 1;
  
        /* XHCI controllers don't stop the ep queue on short packets :| */
  
        if (usb_hcd_is_primary_hcd(hcd)) {
                xhci = kzalloc(sizeof(struct xhci_hcd), GFP_KERNEL);
-@@ -4900,6 +5054,10 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
+@@ -4900,6 +5054,10 @@ int xhci_gen_setup(struct usb_hcd *hcd,
                goto error;
        xhci_dbg(xhci, "Reset complete\n");
  
         * out in specific ways for hardware access.
 --- a/drivers/usb/host/xhci.h
 +++ b/drivers/usb/host/xhci.h
-@@ -32,6 +32,21 @@
+@@ -33,6 +33,21 @@
  #include      "xhci-ext-caps.h"
  #include "pci-quirks.h"
  
  /* xHCI PCI Configuration Registers */
  #define XHCI_SBRN_OFFSET      (0x60)
  
-@@ -1582,8 +1597,12 @@ struct xhci_hcd {
+@@ -1587,8 +1602,12 @@ struct xhci_hcd {
        /* Compliance Mode Recovery Data */
        struct timer_list       comp_mode_recovery_timer;
        u32                     port_status_u0;
  };
  
  /* convert between an HCD pointer and the corresponding EHCI_HCD */
-@@ -1731,6 +1750,26 @@ void xhci_urb_free_priv(struct xhci_hcd *xhci, struct urb_priv *urb_priv);
+@@ -1736,6 +1755,26 @@ void xhci_urb_free_priv(struct xhci_hcd
  void xhci_free_command(struct xhci_hcd *xhci,
                struct xhci_command *command);
  
  /* xHCI host controller glue */
  typedef void (*xhci_get_quirks_t)(struct device *, struct xhci_hcd *);
  int xhci_handshake(struct xhci_hcd *xhci, void __iomem *ptr,
---- a/drivers/usb/phy/Kconfig
-+++ b/drivers/usb/phy/Kconfig
-@@ -199,6 +199,14 @@ config USB_RCAR_GEN2_PHY
-         To compile this driver as a module, choose M here: the
-         module will be called phy-rcar-gen2-usb.
-+config RALINK_USBPHY
-+      bool "Ralink USB PHY controller Driver"
-+      depends on MIPS && RALINK
-+      select USB_PHY
-+      help
-+        Enable this to support ralink USB phy controller for ralink
-+        SoCs.
-+
- config USB_ULPI
-       bool "Generic ULPI Transceiver Driver"
-       depends on ARM || ARM64
---- a/drivers/usb/phy/Makefile
-+++ b/drivers/usb/phy/Makefile
-@@ -27,3 +27,4 @@ obj-$(CONFIG_USB_RCAR_GEN2_PHY)              += phy-rcar-gen2-usb.o
- obj-$(CONFIG_USB_ULPI)                        += phy-ulpi.o
- obj-$(CONFIG_USB_ULPI_VIEWPORT)               += phy-ulpi-viewport.o
- obj-$(CONFIG_KEYSTONE_USB_PHY)                += phy-keystone.o
-+obj-$(CONFIG_RALINK_USBPHY)           += ralink-phy.o
---- /dev/null
-+++ b/drivers/usb/phy/ralink-phy.c
-@@ -0,0 +1,193 @@
-+/*
-+ * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
-+ *
-+ * based on: Renesas R-Car USB phy driver
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+#include <linux/delay.h>
-+#include <linux/io.h>
-+#include <linux/usb/otg.h>
-+#include <linux/of_platform.h>
-+#include <linux/platform_device.h>
-+#include <linux/spinlock.h>
-+#include <linux/module.h>
-+#include <linux/reset.h>
-+
-+#include <asm/mach-ralink/ralink_regs.h>
-+
-+#define RT_SYSC_REG_SYSCFG1           0x014
-+#define RT_SYSC_REG_CLKCFG1           0x030
-+#define RT_SYSC_REG_USB_PHY_CFG       0x05c
-+
-+#define RT_RSTCTRL_UDEV               BIT(25)
-+#define RT_RSTCTRL_UHST               BIT(22)
-+#define RT_SYSCFG1_USB0_HOST_MODE     BIT(10)
-+
-+#define MT7620_CLKCFG1_UPHY0_CLK_EN   BIT(25)
-+#define MT7620_CLKCFG1_UPHY1_CLK_EN   BIT(22)
-+#define RT_CLKCFG1_UPHY1_CLK_EN       BIT(20)
-+#define RT_CLKCFG1_UPHY0_CLK_EN       BIT(18)
-+
-+#define USB_PHY_UTMI_8B60M            BIT(1)
-+#define UDEV_WAKEUP                   BIT(0)
-+
-+static atomic_t usb_pwr_ref = ATOMIC_INIT(0);
-+static struct reset_control *rstdev;
-+static struct reset_control *rsthost;
-+static u32 phy_clk;
-+
-+static void usb_phy_enable(int state)
-+{
-+      if (state)
-+              rt_sysc_m32(0, phy_clk, RT_SYSC_REG_CLKCFG1);
-+      else
-+              rt_sysc_m32(phy_clk, 0, RT_SYSC_REG_CLKCFG1);
-+      mdelay(100);
-+}
-+
-+static int usb_power_on(struct usb_phy *phy)
-+{
-+      if (atomic_inc_return(&usb_pwr_ref) == 1) {
-+              u32 t;
-+
-+              usb_phy_enable(1);
-+
-+//            reset_control_assert(rstdev);
-+//            reset_control_assert(rsthost);
-+
-+              if (OTG_STATE_B_HOST) {
-+                      rt_sysc_m32(0, RT_SYSCFG1_USB0_HOST_MODE, RT_SYSC_REG_SYSCFG1);
-+                      if (!IS_ERR(rsthost))
-+                              reset_control_deassert(rsthost);
-+                      if (!IS_ERR(rstdev))
-+                              reset_control_deassert(rstdev);
-+              } else {
-+                      rt_sysc_m32(RT_SYSCFG1_USB0_HOST_MODE, 0, RT_SYSC_REG_SYSCFG1);
-+                      if (!IS_ERR(rstdev))
-+                              reset_control_deassert(rstdev);
-+              }
-+              mdelay(100);
-+
-+              t = rt_sysc_r32(RT_SYSC_REG_USB_PHY_CFG);
-+              dev_info(phy->dev, "remote usb device wakeup %s\n",
-+                              (t & UDEV_WAKEUP) ? ("enabbled") : ("disabled"));
-+              if (t & USB_PHY_UTMI_8B60M)
-+                      dev_info(phy->dev, "UTMI 8bit 60MHz\n");
-+              else
-+                      dev_info(phy->dev, "UTMI 16bit 30MHz\n");
-+      }
-+
-+      return 0;
-+}
-+
-+static void usb_power_off(struct usb_phy *phy)
-+{
-+      if (atomic_dec_return(&usb_pwr_ref) == 0) {
-+              usb_phy_enable(0);
-+              if (!IS_ERR(rstdev))
-+                      reset_control_assert(rstdev);
-+              if (!IS_ERR(rsthost))
-+                      reset_control_assert(rsthost);
-+      }
-+}
-+
-+static int usb_set_host(struct usb_otg *otg, struct usb_bus *host)
-+{
-+      otg->gadget = NULL;
-+      otg->host = host;
-+
-+      return 0;
-+}
-+
-+static int usb_set_peripheral(struct usb_otg *otg,
-+              struct usb_gadget *gadget)
-+{
-+      otg->host = NULL;
-+      otg->gadget = gadget;
-+
-+      return 0;
-+}
-+
-+static const struct of_device_id ralink_usbphy_dt_match[] = {
-+      { .compatible = "ralink,rt3xxx-usbphy", .data = (void *) (RT_CLKCFG1_UPHY1_CLK_EN | RT_CLKCFG1_UPHY0_CLK_EN) },
-+      { .compatible = "ralink,mt7620a-usbphy", .data = (void *) (MT7620_CLKCFG1_UPHY1_CLK_EN | MT7620_CLKCFG1_UPHY0_CLK_EN) },
-+      {},
-+};
-+MODULE_DEVICE_TABLE(of, ralink_usbphy_dt_match);
-+
-+static int usb_phy_probe(struct platform_device *pdev)
-+{
-+      const struct of_device_id *match;
-+      struct device *dev = &pdev->dev;
-+      struct usb_otg *otg;
-+      struct usb_phy *phy;
-+      int ret;
-+
-+      match = of_match_device(ralink_usbphy_dt_match, &pdev->dev);
-+      phy_clk = (int) match->data;
-+
-+      rsthost = devm_reset_control_get(&pdev->dev, "host");
-+      rstdev = devm_reset_control_get(&pdev->dev, "device");
-+
-+      phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
-+      if (!phy) {
-+              dev_err(&pdev->dev, "unable to allocate memory for USB PHY\n");
-+              return -ENOMEM;
-+      }
-+
-+      otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL);
-+      if (!otg) {
-+              dev_err(&pdev->dev, "unable to allocate memory for USB OTG\n");
-+              return -ENOMEM;
-+      }
-+
-+      phy->dev = dev;
-+      phy->label = dev_name(dev);
-+      phy->init = usb_power_on;
-+      phy->shutdown = usb_power_off;
-+      otg->set_host = usb_set_host;
-+      otg->set_peripheral = usb_set_peripheral;
-+      otg->phy = phy;
-+      phy->otg = otg;
-+      ret = usb_add_phy(phy, USB_PHY_TYPE_USB2);
-+
-+      if (ret < 0) {
-+              dev_err(dev, "usb phy addition error\n");
-+              return ret;
-+      }
-+
-+      platform_set_drvdata(pdev, phy);
-+
-+      dev_info(&pdev->dev, "loaded\n");
-+
-+      return ret;
-+}
-+
-+static int usb_phy_remove(struct platform_device *pdev)
-+{
-+      struct usb_phy *phy = platform_get_drvdata(pdev);
-+
-+      usb_remove_phy(phy);
-+
-+      return 0;
-+}
-+
-+static struct platform_driver usb_phy_driver = {
-+      .driver         = {
-+              .owner  = THIS_MODULE,
-+              .name   = "rt3xxx-usbphy",
-+              .of_match_table = of_match_ptr(ralink_usbphy_dt_match),
-+      },
-+      .probe          = usb_phy_probe,
-+      .remove         = usb_phy_remove,
-+};
-+
-+module_platform_driver(usb_phy_driver);
-+
-+MODULE_LICENSE("GPL v2");
-+MODULE_DESCRIPTION("Ralink USB phy");
-+MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");