^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) * xhci-plat.c - xHCI host controller driver platform Bus Glue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2012 Texas Instruments Incorporated - https://www.ti.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * A lot of code borrowed from the Linux xHCI driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/usb/phy.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/usb/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "xhci.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "xhci-plat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "xhci-mvebu.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "xhci-rcar.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static struct hc_driver __read_mostly xhci_plat_hc_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static int xhci_plat_setup(struct usb_hcd *hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static int xhci_plat_start(struct usb_hcd *hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static const struct xhci_driver_overrides xhci_plat_overrides __initconst = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) .extra_priv_size = sizeof(struct xhci_plat_priv),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) .reset = xhci_plat_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) .start = xhci_plat_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static void xhci_priv_plat_start(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if (priv->plat_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) priv->plat_start(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static int xhci_priv_plat_setup(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) if (!priv->plat_setup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return priv->plat_setup(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static int xhci_priv_init_quirk(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (!priv->init_quirk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return priv->init_quirk(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static int xhci_priv_suspend_quirk(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (!priv->suspend_quirk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) return priv->suspend_quirk(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static int xhci_priv_resume_quirk(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (!priv->resume_quirk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) return priv->resume_quirk(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct xhci_plat_priv *priv = xhci_to_priv(xhci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * As of now platform drivers don't provide MSI support so we ensure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * here that the generic code does not try to make a pci_dev from our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * dev struct in order to setup MSI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) xhci->quirks |= XHCI_PLAT | priv->quirks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* called during probe() after chip reset completes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static int xhci_plat_setup(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) ret = xhci_priv_init_quirk(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return xhci_gen_setup(hcd, xhci_plat_quirks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static int xhci_plat_start(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) xhci_priv_plat_start(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return xhci_run(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static const struct xhci_plat_priv xhci_plat_marvell_armada = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .init_quirk = xhci_mvebu_mbus_init_quirk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static const struct xhci_plat_priv xhci_plat_marvell_armada3700 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) .plat_setup = xhci_mvebu_a3700_plat_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .init_quirk = xhci_mvebu_a3700_init_quirk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static const struct xhci_plat_priv xhci_plat_renesas_rcar_gen2 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) SET_XHCI_PLAT_PRIV_FOR_RCAR(XHCI_RCAR_FIRMWARE_NAME_V1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static const struct xhci_plat_priv xhci_plat_renesas_rcar_gen3 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) SET_XHCI_PLAT_PRIV_FOR_RCAR(XHCI_RCAR_FIRMWARE_NAME_V3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static const struct xhci_plat_priv xhci_plat_brcm = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .quirks = XHCI_RESET_ON_RESUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static const struct of_device_id usb_xhci_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .compatible = "generic-xhci",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) .compatible = "xhci-platform",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) #ifndef CONFIG_ARCH_ROCKCHIP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) .compatible = "marvell,armada-375-xhci",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) .data = &xhci_plat_marvell_armada,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) .compatible = "marvell,armada-380-xhci",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) .data = &xhci_plat_marvell_armada,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) .compatible = "marvell,armada3700-xhci",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) .data = &xhci_plat_marvell_armada3700,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) .compatible = "renesas,xhci-r8a7790",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) .data = &xhci_plat_renesas_rcar_gen2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) .compatible = "renesas,xhci-r8a7791",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) .data = &xhci_plat_renesas_rcar_gen2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) .compatible = "renesas,xhci-r8a7793",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) .data = &xhci_plat_renesas_rcar_gen2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) .compatible = "renesas,xhci-r8a7795",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) .data = &xhci_plat_renesas_rcar_gen3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) .compatible = "renesas,xhci-r8a7796",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) .data = &xhci_plat_renesas_rcar_gen3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) .compatible = "renesas,rcar-gen2-xhci",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) .data = &xhci_plat_renesas_rcar_gen2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) .compatible = "renesas,rcar-gen3-xhci",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) .data = &xhci_plat_renesas_rcar_gen3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) .compatible = "brcm,xhci-brcm-v2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) .data = &xhci_plat_brcm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) .compatible = "brcm,bcm7445-xhci",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) .data = &xhci_plat_brcm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) MODULE_DEVICE_TABLE(of, usb_xhci_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static struct xhci_plat_priv_overwrite xhci_plat_vendor_overwrite;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) int xhci_plat_register_vendor_ops(struct xhci_vendor_ops *vendor_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (vendor_ops == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) xhci_plat_vendor_overwrite.vendor_ops = vendor_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) EXPORT_SYMBOL_GPL(xhci_plat_register_vendor_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static int xhci_vendor_init(struct xhci_hcd *xhci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) struct xhci_vendor_ops *ops = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (xhci_plat_vendor_overwrite.vendor_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) ops = xhci->vendor_ops = xhci_plat_vendor_overwrite.vendor_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (ops && ops->vendor_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return ops->vendor_init(xhci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static void xhci_vendor_cleanup(struct xhci_hcd *xhci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct xhci_vendor_ops *ops = xhci_vendor_get_ops(xhci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (ops && ops->vendor_cleanup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) ops->vendor_cleanup(xhci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) xhci->vendor_ops = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static int xhci_plat_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) const struct xhci_plat_priv *priv_match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) const struct hc_driver *driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) struct device *sysdev, *tmpdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct xhci_hcd *xhci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) struct usb_hcd *hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct xhci_plat_priv *priv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (usb_disabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) driver = &xhci_plat_hc_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) irq = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (irq < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * sysdev must point to a device that is known to the system firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * or PCI hardware. We handle these three cases here:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * 1. xhci_plat comes from firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * 2. xhci_plat is child of a device from firmware (dwc3-plat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * 3. xhci_plat is grandchild of a pci device (dwc3-pci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) for (sysdev = &pdev->dev; sysdev; sysdev = sysdev->parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (is_of_node(sysdev->fwnode) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) is_acpi_device_node(sysdev->fwnode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) #ifdef CONFIG_PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) else if (sysdev->bus == &pci_bus_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (!sysdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) sysdev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /* Try to set 64-bit DMA first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (WARN_ON(!sysdev->dma_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) /* Platform did not initialize dma_mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) ret = dma_coerce_mask_and_coherent(sysdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) DMA_BIT_MASK(64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) ret = dma_set_mask_and_coherent(sysdev, DMA_BIT_MASK(64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) /* If seting 64-bit DMA mask fails, fall back to 32-bit DMA mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) ret = dma_set_mask_and_coherent(sysdev, DMA_BIT_MASK(32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) pm_runtime_set_active(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) pm_runtime_enable(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) pm_runtime_get_noresume(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) hcd = __usb_create_hcd(driver, sysdev, &pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) dev_name(&pdev->dev), NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (!hcd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) goto disable_runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) if (IS_ERR(hcd->regs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) ret = PTR_ERR(hcd->regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) goto put_hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) hcd->rsrc_start = res->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) hcd->rsrc_len = resource_size(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) xhci = hcd_to_xhci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * Not all platforms have clks so it is not an error if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * clock do not exist.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) xhci->reg_clk = devm_clk_get_optional(&pdev->dev, "reg");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (IS_ERR(xhci->reg_clk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) ret = PTR_ERR(xhci->reg_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) goto put_hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) ret = clk_prepare_enable(xhci->reg_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) goto put_hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) xhci->clk = devm_clk_get_optional(&pdev->dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (IS_ERR(xhci->clk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) ret = PTR_ERR(xhci->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) goto disable_reg_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) ret = clk_prepare_enable(xhci->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) goto disable_reg_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (pdev->dev.of_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) priv_match = of_device_get_match_data(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) priv_match = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) if (priv_match) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) priv = hcd_to_xhci_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) /* Just copy data for now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) *priv = *priv_match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) device_set_wakeup_capable(&pdev->dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) xhci->main_hcd = hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) xhci->shared_hcd = __usb_create_hcd(driver, sysdev, &pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) dev_name(&pdev->dev), hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (!xhci->shared_hcd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) goto disable_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) /* imod_interval is the interrupt moderation value in nanoseconds. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) xhci->imod_interval = 40000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) /* Iterate over all parent nodes for finding quirks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) for (tmpdev = &pdev->dev; tmpdev; tmpdev = tmpdev->parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) if (device_property_read_bool(tmpdev, "usb2-lpm-disable"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) xhci->quirks |= XHCI_HW_LPM_DISABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) if (device_property_read_bool(tmpdev, "usb3-lpm-capable"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) xhci->quirks |= XHCI_LPM_SUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (device_property_read_bool(tmpdev, "quirk-broken-port-ped"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) xhci->quirks |= XHCI_BROKEN_PORT_PED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (device_property_read_bool(tmpdev, "quirk-skip-phy-init"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) xhci->quirks |= XHCI_SKIP_PHY_INIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if (device_property_read_bool(tmpdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) "xhci-u2-broken-suspend"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) xhci->quirks |= XHCI_U2_BROKEN_SUSPEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) device_property_read_u32(tmpdev, "imod-interval-ns",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) &xhci->imod_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) hcd->usb_phy = devm_usb_get_phy_by_phandle(sysdev, "usb-phy", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) if (IS_ERR(hcd->usb_phy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) ret = PTR_ERR(hcd->usb_phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (ret == -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) goto put_usb3_hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) hcd->usb_phy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) ret = usb_phy_init(hcd->usb_phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) goto put_usb3_hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) ret = xhci_vendor_init(xhci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) goto disable_usb_phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) hcd->tpl_support = of_usb_host_tpl_support(sysdev->of_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) xhci->shared_hcd->tpl_support = hcd->tpl_support;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (priv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) ret = xhci_priv_plat_setup(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) goto disable_usb_phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if ((xhci->quirks & XHCI_SKIP_PHY_INIT) || (priv && (priv->quirks & XHCI_SKIP_PHY_INIT)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) hcd->skip_phy_initialization = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) if (priv && (priv->quirks & XHCI_SG_TRB_CACHE_SIZE_QUIRK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) xhci->quirks |= XHCI_SG_TRB_CACHE_SIZE_QUIRK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) goto disable_usb_phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (HCC_MAX_PSA(xhci->hcc_params) >= 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) xhci->shared_hcd->can_do_streams = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) goto dealloc_usb2_hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) device_enable_async_suspend(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) pm_runtime_put_noidle(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) * Prevent runtime pm from being on as default, users should enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) * runtime pm using power/control in sysfs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) pm_runtime_forbid(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) dealloc_usb2_hcd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) usb_remove_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) disable_usb_phy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) usb_phy_shutdown(hcd->usb_phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) put_usb3_hcd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) usb_put_hcd(xhci->shared_hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) disable_clk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) clk_disable_unprepare(xhci->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) disable_reg_clk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) clk_disable_unprepare(xhci->reg_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) put_hcd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) usb_put_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) disable_runtime:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) pm_runtime_put_noidle(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) pm_runtime_disable(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) static int xhci_plat_remove(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) struct usb_hcd *hcd = platform_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) struct xhci_hcd *xhci = hcd_to_xhci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) struct clk *clk = xhci->clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) struct clk *reg_clk = xhci->reg_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) struct usb_hcd *shared_hcd = xhci->shared_hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) pm_runtime_get_sync(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) xhci->xhc_state |= XHCI_STATE_REMOVING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) usb_remove_hcd(shared_hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) xhci->shared_hcd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) usb_phy_shutdown(hcd->usb_phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) usb_remove_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) xhci_vendor_cleanup(xhci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) usb_put_hcd(shared_hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) clk_disable_unprepare(clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) clk_disable_unprepare(reg_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) usb_put_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) pm_runtime_disable(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) pm_runtime_put_noidle(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) pm_runtime_set_suspended(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) static int __maybe_unused xhci_plat_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) struct usb_hcd *hcd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) struct xhci_hcd *xhci = hcd_to_xhci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) if (pm_runtime_suspended(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) pm_runtime_resume(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) ret = xhci_priv_suspend_quirk(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) * xhci_suspend() needs `do_wakeup` to know whether host is allowed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) * to do wakeup during suspend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) return xhci_suspend(xhci, device_may_wakeup(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) static int __maybe_unused xhci_plat_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) struct usb_hcd *hcd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) struct xhci_hcd *xhci = hcd_to_xhci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) ret = xhci_priv_resume_quirk(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) ret = xhci_resume(xhci, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) pm_runtime_disable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) pm_runtime_set_active(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) pm_runtime_enable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) static int __maybe_unused xhci_plat_runtime_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) struct usb_hcd *hcd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) struct xhci_hcd *xhci = hcd_to_xhci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) ret = xhci_priv_suspend_quirk(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) return xhci_suspend(xhci, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) static int __maybe_unused xhci_plat_runtime_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) struct usb_hcd *hcd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) struct xhci_hcd *xhci = hcd_to_xhci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) return xhci_resume(xhci, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) static const struct dev_pm_ops xhci_plat_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) SET_SYSTEM_SLEEP_PM_OPS(xhci_plat_suspend, xhci_plat_resume)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) SET_RUNTIME_PM_OPS(xhci_plat_runtime_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) xhci_plat_runtime_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) #ifdef CONFIG_ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) static const struct acpi_device_id usb_xhci_acpi_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) /* XHCI-compliant USB Controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) { "PNP0D10", },
^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) MODULE_DEVICE_TABLE(acpi, usb_xhci_acpi_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) static struct platform_driver usb_xhci_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) .probe = xhci_plat_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) .remove = xhci_plat_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) .shutdown = usb_hcd_platform_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) .name = "xhci-hcd",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) .pm = &xhci_plat_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) .of_match_table = of_match_ptr(usb_xhci_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) .acpi_match_table = ACPI_PTR(usb_xhci_acpi_match),
^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_ALIAS("platform:xhci-hcd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) static int __init xhci_plat_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) xhci_init_driver(&xhci_plat_hc_driver, &xhci_plat_overrides);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) return platform_driver_register(&usb_xhci_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) module_init(xhci_plat_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) static void __exit xhci_plat_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) platform_driver_unregister(&usb_xhci_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) module_exit(xhci_plat_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) MODULE_DESCRIPTION("xHCI Platform Host Controller Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) MODULE_LICENSE("GPL");