^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Generic platform ehci driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2007 Steven Brown <sbrown@cortland.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright 2010-2012 Hauke Mehrtens <hauke@hauke-m.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright 2014 Hans de Goede <hdegoede@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Derived from the ohci-ssb driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright 2007 Michael Buesch <m@bues.ch>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Derived from the EHCI-PCI driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Copyright (c) 2000-2004 by David Brownell
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Derived from the ohci-pci driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Copyright 1999 Roman Weissgaerber
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Copyright 2000-2002 David Brownell
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Copyright 1999 Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Copyright 1999 Gregory P. Smith
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/hrtimer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/reset.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/sys_soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/usb/hcd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/usb/ehci_pdriver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/usb/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include "ehci.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define DRIVER_DESC "EHCI generic platform driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define EHCI_MAX_CLKS 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define hcd_to_ehci_priv(h) ((struct ehci_platform_priv *)hcd_to_ehci(h)->priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define BCM_USB_FIFO_THRESHOLD 0x00800040
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define bcm_iproc_insnreg01 hostpc[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct ehci_platform_priv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct clk *clks[EHCI_MAX_CLKS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct reset_control *rsts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) bool reset_on_resume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) bool quirk_poll;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct timer_list poll_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct delayed_work poll_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static const char hcd_name[] = "ehci-platform";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static void ehci_rockchip_relinquish_port(struct usb_hcd *hcd, int portnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct ehci_hcd *ehci = hcd_to_ehci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) u32 __iomem *status_reg = &ehci->regs->port_status[--portnum];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) u32 portsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) portsc = ehci_readl(ehci, status_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) portsc &= ~(PORT_OWNER | PORT_RWC_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) ehci_writel(ehci, portsc, status_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #define USIC_MICROFRAME_OFFSET 0x90
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define USIC_SCALE_DOWN_OFFSET 0xa0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define USIC_ENABLE_OFFSET 0xb0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define USIC_ENABLE BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #define USIC_SCALE_DOWN BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define USIC_MICROFRAME_COUNT 0x1d4d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static void ehci_usic_init(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct ehci_hcd *ehci = hcd_to_ehci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) ehci_writel(ehci, USIC_ENABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) hcd->regs + USIC_ENABLE_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) ehci_writel(ehci, USIC_MICROFRAME_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) hcd->regs + USIC_MICROFRAME_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) ehci_writel(ehci, USIC_SCALE_DOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) hcd->regs + USIC_SCALE_DOWN_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static int ehci_platform_reset(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct platform_device *pdev = to_platform_device(hcd->self.controller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct usb_ehci_pdata *pdata = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct ehci_hcd *ehci = hcd_to_ehci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) ehci->has_synopsys_hc_bug = pdata->has_synopsys_hc_bug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (pdata->pre_setup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) retval = pdata->pre_setup(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) ehci->caps = hcd->regs + pdata->caps_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) retval = ehci_setup(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (pdata->no_io_watchdog)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) ehci->need_io_watchdog = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (of_device_is_compatible(pdev->dev.of_node, "brcm,xgs-iproc-ehci"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) ehci_writel(ehci, BCM_USB_FIFO_THRESHOLD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) &ehci->regs->bcm_iproc_insnreg01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static int ehci_platform_power_on(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct usb_hcd *hcd = platform_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int clk, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) for (clk = 0; clk < EHCI_MAX_CLKS && priv->clks[clk]; clk++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ret = clk_prepare_enable(priv->clks[clk]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) goto err_disable_clks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) err_disable_clks:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) while (--clk >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) clk_disable_unprepare(priv->clks[clk]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static void ehci_platform_power_off(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct usb_hcd *hcd = platform_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) int clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) for (clk = EHCI_MAX_CLKS - 1; clk >= 0; clk--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (priv->clks[clk])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) clk_disable_unprepare(priv->clks[clk]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static struct hc_driver __read_mostly ehci_platform_hc_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static const struct ehci_driver_overrides platform_overrides __initconst = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) .reset = ehci_platform_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) .extra_priv_size = sizeof(struct ehci_platform_priv),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static struct usb_ehci_pdata ehci_platform_defaults = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) .power_on = ehci_platform_power_on,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) .power_suspend = ehci_platform_power_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) .power_off = ehci_platform_power_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * quirk_poll_check_port_status - Poll port_status if the device sticks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * @ehci: the ehci hcd pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * Since EHCI/OHCI controllers on R-Car Gen3 SoCs are possible to be getting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * stuck very rarely after a full/low usb device was disconnected. To
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * detect such a situation, the controllers require a special way which poll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * the EHCI PORTSC register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * Return: true if the controller's port_status indicated getting stuck
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static bool quirk_poll_check_port_status(struct ehci_hcd *ehci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) u32 port_status = ehci_readl(ehci, &ehci->regs->port_status[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (!(port_status & PORT_OWNER) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) (port_status & PORT_POWER) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) !(port_status & PORT_CONNECT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) (port_status & PORT_LS_MASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * quirk_poll_rebind_companion - rebind comanion device to recover
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * @ehci: the ehci hcd pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * Since EHCI/OHCI controllers on R-Car Gen3 SoCs are possible to be getting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * stuck very rarely after a full/low usb device was disconnected. To
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * recover from such a situation, the controllers require changing the OHCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * functional state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static void quirk_poll_rebind_companion(struct ehci_hcd *ehci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct device *companion_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct usb_hcd *hcd = ehci_to_hcd(ehci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) companion_dev = usb_of_get_companion_dev(hcd->self.controller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (!companion_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) device_release_driver(companion_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (device_attach(companion_dev) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) ehci_err(ehci, "%s: failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) put_device(companion_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static void quirk_poll_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct ehci_platform_priv *priv =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) container_of(to_delayed_work(work), struct ehci_platform_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) poll_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) struct ehci_hcd *ehci = container_of((void *)priv, struct ehci_hcd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* check the status twice to reduce misdetection rate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (!quirk_poll_check_port_status(ehci))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) udelay(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (!quirk_poll_check_port_status(ehci))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) ehci_dbg(ehci, "%s: detected getting stuck. rebind now!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) quirk_poll_rebind_companion(ehci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static void quirk_poll_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) struct ehci_platform_priv *priv = from_timer(priv, t, poll_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct ehci_hcd *ehci = container_of((void *)priv, struct ehci_hcd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (quirk_poll_check_port_status(ehci)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * Now scheduling the work for testing the port more. Note that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * updating the status is possible to be delayed when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * reconnection. So, this uses delayed work with 5 ms delay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * to avoid misdetection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) schedule_delayed_work(&priv->poll_work, msecs_to_jiffies(5));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) mod_timer(&priv->poll_timer, jiffies + HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static void quirk_poll_init(struct ehci_platform_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) INIT_DELAYED_WORK(&priv->poll_work, quirk_poll_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) timer_setup(&priv->poll_timer, quirk_poll_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) mod_timer(&priv->poll_timer, jiffies + HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static void quirk_poll_end(struct ehci_platform_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) del_timer_sync(&priv->poll_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) cancel_delayed_work(&priv->poll_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static const struct soc_device_attribute quirk_poll_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) { .family = "R-Car Gen3" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) { /* sentinel*/ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static int ehci_platform_probe(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct usb_hcd *hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) struct resource *res_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) struct ehci_platform_priv *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct ehci_hcd *ehci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) int err, irq, clk = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) struct device *companion_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) struct device_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (usb_disabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * Use reasonable defaults so platforms don't have to provide these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * with DT probing on ARM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (!pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) pdata = &ehci_platform_defaults;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) err = dma_coerce_mask_and_coherent(&dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) pdata->dma_mask_64 ? DMA_BIT_MASK(64) : DMA_BIT_MASK(32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) dev_err(&dev->dev, "Error: DMA mask configuration failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) irq = platform_get_irq(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (irq < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) dev_name(&dev->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (!hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) platform_set_drvdata(dev, hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) dev->dev.platform_data = pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) priv = hcd_to_ehci_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) ehci = hcd_to_ehci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (pdata == &ehci_platform_defaults && dev->dev.of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) if (of_property_read_bool(dev->dev.of_node, "big-endian-regs"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) ehci->big_endian_mmio = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (of_property_read_bool(dev->dev.of_node, "big-endian-desc"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) ehci->big_endian_desc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) if (of_property_read_bool(dev->dev.of_node, "big-endian"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) ehci->big_endian_mmio = ehci->big_endian_desc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (of_property_read_bool(dev->dev.of_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) "needs-reset-on-resume"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) priv->reset_on_resume = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (of_property_read_bool(dev->dev.of_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) "has-transaction-translator"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) hcd->has_tt = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (of_device_is_compatible(dev->dev.of_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) "aspeed,ast2500-ehci") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) of_device_is_compatible(dev->dev.of_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) "aspeed,ast2600-ehci"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) ehci->is_aspeed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) if (soc_device_match(quirk_poll_match))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) priv->quirk_poll = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if (of_machine_is_compatible("rockchip,rk3288") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) of_property_read_bool(dev->dev.of_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) "rockchip-relinquish-port"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) ehci_platform_hc_driver.relinquish_port =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) ehci_rockchip_relinquish_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) for (clk = 0; clk < EHCI_MAX_CLKS; clk++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) priv->clks[clk] = of_clk_get(dev->dev.of_node, clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) if (IS_ERR(priv->clks[clk])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) err = PTR_ERR(priv->clks[clk]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) if (err == -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) goto err_put_clks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) priv->clks[clk] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) priv->rsts = devm_reset_control_array_get_optional_shared(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) if (IS_ERR(priv->rsts)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) err = PTR_ERR(priv->rsts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) goto err_put_clks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) err = reset_control_deassert(priv->rsts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) goto err_put_clks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (pdata->big_endian_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) ehci->big_endian_desc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) if (pdata->big_endian_mmio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) ehci->big_endian_mmio = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (pdata->has_tt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) hcd->has_tt = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (pdata->reset_on_resume)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) priv->reset_on_resume = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) #ifndef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (ehci->big_endian_mmio) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) dev_err(&dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) "Error: CONFIG_USB_EHCI_BIG_ENDIAN_MMIO not set\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) goto err_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) #ifndef CONFIG_USB_EHCI_BIG_ENDIAN_DESC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (ehci->big_endian_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) dev_err(&dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) "Error: CONFIG_USB_EHCI_BIG_ENDIAN_DESC not set\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) goto err_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) pm_runtime_set_active(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) pm_runtime_enable(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) pm_runtime_get_sync(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if (pdata->power_on) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) err = pdata->power_on(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) goto err_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (IS_ERR(hcd->regs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) err = PTR_ERR(hcd->regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) goto err_power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) hcd->rsrc_start = res_mem->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) hcd->rsrc_len = resource_size(res_mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) err = usb_add_hcd(hcd, irq, IRQF_SHARED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) goto err_power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) if (of_usb_get_phy_mode(dev->dev.of_node) == USBPHY_INTERFACE_MODE_HSIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) ehci_usic_init(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (of_device_is_compatible(dev->dev.of_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) "rockchip,rk3588-ehci")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) companion_dev = usb_of_get_companion_dev(hcd->self.controller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) if (companion_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) link = device_link_add(companion_dev, hcd->self.controller,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) DL_FLAG_STATELESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) put_device(companion_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (!link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) dev_err(&dev->dev, "Unable to link %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) dev_name(companion_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) goto err_power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) device_wakeup_enable(hcd->self.controller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) device_enable_async_suspend(hcd->self.controller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) platform_set_drvdata(dev, hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) if (priv->quirk_poll)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) quirk_poll_init(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) err_power:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) if (pdata->power_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) pdata->power_off(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) err_reset:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) pm_runtime_put_sync(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) pm_runtime_disable(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) reset_control_assert(priv->rsts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) err_put_clks:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) while (--clk >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) clk_put(priv->clks[clk]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) if (pdata == &ehci_platform_defaults)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) dev->dev.platform_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) usb_put_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) static int ehci_platform_remove(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) struct usb_hcd *hcd = platform_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) struct device *companion_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) int clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) if (priv->quirk_poll)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) quirk_poll_end(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if (of_device_is_compatible(dev->dev.of_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) "rockchip,rk3588-ehci")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) companion_dev = usb_of_get_companion_dev(hcd->self.controller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (companion_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) device_link_remove(companion_dev, hcd->self.controller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) put_device(companion_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) usb_remove_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) if (pdata->power_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) pdata->power_off(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) reset_control_assert(priv->rsts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) for (clk = 0; clk < EHCI_MAX_CLKS && priv->clks[clk]; clk++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) clk_put(priv->clks[clk]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) usb_put_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) pm_runtime_put_sync(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) pm_runtime_disable(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) if (pdata == &ehci_platform_defaults)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) dev->dev.platform_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) static int __maybe_unused ehci_platform_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) struct usb_hcd *hcd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) struct usb_ehci_pdata *pdata = dev_get_platdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) bool do_wakeup = device_may_wakeup(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) if (priv->quirk_poll)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) quirk_poll_end(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) ret = ehci_suspend(hcd, do_wakeup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) if (pdata->power_suspend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) pdata->power_suspend(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) static int __maybe_unused ehci_platform_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) struct usb_hcd *hcd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) struct usb_ehci_pdata *pdata = dev_get_platdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) struct device *companion_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) if (pdata->power_on) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) int err = pdata->power_on(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) companion_dev = usb_of_get_companion_dev(hcd->self.controller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) if (companion_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) if (!device_is_dependent(hcd->self.controller, companion_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) device_pm_wait_for_dev(hcd->self.controller, companion_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) put_device(companion_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) ehci_resume(hcd, priv->reset_on_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) pm_runtime_disable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) pm_runtime_set_active(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) pm_runtime_enable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) if (priv->quirk_poll)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) quirk_poll_init(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) static const struct of_device_id vt8500_ehci_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) { .compatible = "via,vt8500-ehci", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) { .compatible = "wm,prizm-ehci", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) { .compatible = "generic-ehci", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) { .compatible = "cavium,octeon-6335-ehci", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) MODULE_DEVICE_TABLE(of, vt8500_ehci_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) #ifdef CONFIG_ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) static const struct acpi_device_id ehci_acpi_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) { "PNP0D20", 0 }, /* EHCI controller without debug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) MODULE_DEVICE_TABLE(acpi, ehci_acpi_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) static const struct platform_device_id ehci_platform_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) { "ehci-platform", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) MODULE_DEVICE_TABLE(platform, ehci_platform_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) static SIMPLE_DEV_PM_OPS(ehci_platform_pm_ops, ehci_platform_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) ehci_platform_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) static struct platform_driver ehci_platform_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) .id_table = ehci_platform_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) .probe = ehci_platform_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) .remove = ehci_platform_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) .shutdown = usb_hcd_platform_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) .name = "ehci-platform",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) .pm = pm_ptr(&ehci_platform_pm_ops),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) .of_match_table = vt8500_ehci_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) .acpi_match_table = ACPI_PTR(ehci_acpi_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) static int __init ehci_platform_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) if (usb_disabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) pr_info("%s: " DRIVER_DESC "\n", hcd_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) ehci_init_driver(&ehci_platform_hc_driver, &platform_overrides);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) return platform_driver_register(&ehci_platform_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) module_init(ehci_platform_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) static void __exit ehci_platform_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) platform_driver_unregister(&ehci_platform_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) module_exit(ehci_platform_cleanup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) MODULE_AUTHOR("Hauke Mehrtens");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) MODULE_AUTHOR("Alan Stern");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) MODULE_LICENSE("GPL");