Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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)  * ST EHCI driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2014 STMicroelectronics – All Rights Reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Author: Peter Griffin <peter.griffin@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Derived from ehci-platform.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/hrtimer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/phy/phy.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/reset.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/usb/hcd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/usb/ehci_pdriver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/pinctrl/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include "ehci.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define USB_MAX_CLKS 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) struct st_ehci_platform_priv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct clk *clks[USB_MAX_CLKS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct clk *clk48;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct reset_control *rst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct reset_control *pwr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct phy *phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define DRIVER_DESC "EHCI STMicroelectronics driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define hcd_to_ehci_priv(h) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	((struct st_ehci_platform_priv *)hcd_to_ehci(h)->priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static const char hcd_name[] = "ehci-st";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define EHCI_CAPS_SIZE 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define AHB2STBUS_INSREG01 (EHCI_CAPS_SIZE + 0x84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static int st_ehci_platform_reset(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct platform_device *pdev = to_platform_device(hcd->self.controller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct usb_ehci_pdata *pdata = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	u32 threshold;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	/* Set EHCI packet buffer IN/OUT threshold to 128 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	threshold = 128 | (128 << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	writel(threshold, hcd->regs + AHB2STBUS_INSREG01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	ehci->caps = hcd->regs + pdata->caps_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	return ehci_setup(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static int st_ehci_platform_power_on(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct usb_hcd *hcd = platform_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct st_ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	int clk, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	ret = reset_control_deassert(priv->pwr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	ret = reset_control_deassert(priv->rst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		goto err_assert_power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	/* some SoCs don't have a dedicated 48Mhz clock, but those that do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	   need the rate to be explicitly set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (priv->clk48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		ret = clk_set_rate(priv->clk48, 48000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			goto err_assert_reset;
^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) 	for (clk = 0; clk < USB_MAX_CLKS && priv->clks[clk]; clk++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		ret = clk_prepare_enable(priv->clks[clk]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			goto err_disable_clks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	ret = phy_init(priv->phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		goto err_disable_clks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	ret = phy_power_on(priv->phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		goto err_exit_phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) err_exit_phy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	phy_exit(priv->phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) err_disable_clks:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	while (--clk >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		clk_disable_unprepare(priv->clks[clk]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) err_assert_reset:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	reset_control_assert(priv->rst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) err_assert_power:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	reset_control_assert(priv->pwr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static void st_ehci_platform_power_off(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct usb_hcd *hcd = platform_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	struct st_ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	int clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	reset_control_assert(priv->pwr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	reset_control_assert(priv->rst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	phy_power_off(priv->phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	phy_exit(priv->phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	for (clk = USB_MAX_CLKS - 1; clk >= 0; clk--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		if (priv->clks[clk])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			clk_disable_unprepare(priv->clks[clk]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^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 struct hc_driver __read_mostly ehci_platform_hc_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static const struct ehci_driver_overrides platform_overrides __initconst = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	.reset =		st_ehci_platform_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	.extra_priv_size =	sizeof(struct st_ehci_platform_priv),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static struct usb_ehci_pdata ehci_platform_defaults = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	.power_on =		st_ehci_platform_power_on,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	.power_suspend =	st_ehci_platform_power_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	.power_off =		st_ehci_platform_power_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static int st_ehci_platform_probe(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	struct usb_hcd *hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	struct resource *res_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	struct usb_ehci_pdata *pdata = &ehci_platform_defaults;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	struct st_ehci_platform_priv *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	int err, irq, clk = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	if (usb_disabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	irq = platform_get_irq(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	if (irq < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		return irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (!res_mem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		dev_err(&dev->dev, "no memory resource provided");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			     dev_name(&dev->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	if (!hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	platform_set_drvdata(dev, hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	dev->dev.platform_data = pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	priv = hcd_to_ehci_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	priv->phy = devm_phy_get(&dev->dev, "usb");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	if (IS_ERR(priv->phy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		err = PTR_ERR(priv->phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		goto err_put_hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	for (clk = 0; clk < USB_MAX_CLKS; clk++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		priv->clks[clk] = of_clk_get(dev->dev.of_node, clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		if (IS_ERR(priv->clks[clk])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			err = PTR_ERR(priv->clks[clk]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			if (err == -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 				goto err_put_clks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			priv->clks[clk] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	/* some SoCs don't have a dedicated 48Mhz clock, but those that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	   do need the rate to be explicitly set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	priv->clk48 = devm_clk_get(&dev->dev, "clk48");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	if (IS_ERR(priv->clk48)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		dev_info(&dev->dev, "48MHz clk not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		priv->clk48 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	priv->pwr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		devm_reset_control_get_optional_shared(&dev->dev, "power");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	if (IS_ERR(priv->pwr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		err = PTR_ERR(priv->pwr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		if (err == -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			goto err_put_clks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		priv->pwr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	priv->rst =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		devm_reset_control_get_optional_shared(&dev->dev, "softreset");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	if (IS_ERR(priv->rst)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		err = PTR_ERR(priv->rst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		if (err == -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			goto err_put_clks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		priv->rst = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (pdata->power_on) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		err = pdata->power_on(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			goto err_put_clks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	hcd->rsrc_start = res_mem->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	hcd->rsrc_len = resource_size(res_mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (IS_ERR(hcd->regs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		err = PTR_ERR(hcd->regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		goto err_put_clks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	err = usb_add_hcd(hcd, irq, IRQF_SHARED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		goto err_put_clks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	device_wakeup_enable(hcd->self.controller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	platform_set_drvdata(dev, hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) err_put_clks:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	while (--clk >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		clk_put(priv->clks[clk]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) err_put_hcd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	if (pdata == &ehci_platform_defaults)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		dev->dev.platform_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	usb_put_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static int st_ehci_platform_remove(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	struct usb_hcd *hcd = platform_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	struct st_ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	int clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	usb_remove_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (pdata->power_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		pdata->power_off(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	for (clk = 0; clk < USB_MAX_CLKS && priv->clks[clk]; clk++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		clk_put(priv->clks[clk]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	usb_put_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	if (pdata == &ehci_platform_defaults)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		dev->dev.platform_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static int st_ehci_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	struct usb_hcd *hcd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	struct usb_ehci_pdata *pdata = dev_get_platdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	bool do_wakeup = device_may_wakeup(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	ret = ehci_suspend(hcd, do_wakeup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (pdata->power_suspend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		pdata->power_suspend(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	pinctrl_pm_select_sleep_state(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static int st_ehci_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	struct usb_hcd *hcd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	struct usb_ehci_pdata *pdata = dev_get_platdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	pinctrl_pm_select_default_state(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	if (pdata->power_on) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		err = pdata->power_on(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	ehci_resume(hcd, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static SIMPLE_DEV_PM_OPS(st_ehci_pm_ops, st_ehci_suspend, st_ehci_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) #endif /* CONFIG_PM_SLEEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static const struct of_device_id st_ehci_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	{ .compatible = "st,st-ehci-300x", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	{ /* sentinel */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) MODULE_DEVICE_TABLE(of, st_ehci_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) static struct platform_driver ehci_platform_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	.probe		= st_ehci_platform_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	.remove		= st_ehci_platform_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	.shutdown	= usb_hcd_platform_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		.name	= "st-ehci",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		.pm	= &st_ehci_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		.of_match_table = st_ehci_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) static int __init ehci_platform_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	if (usb_disabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	pr_info("%s: " DRIVER_DESC "\n", hcd_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	ehci_init_driver(&ehci_platform_hc_driver, &platform_overrides);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	return platform_driver_register(&ehci_platform_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) module_init(ehci_platform_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) static void __exit ehci_platform_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	platform_driver_unregister(&ehci_platform_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) module_exit(ehci_platform_cleanup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) MODULE_AUTHOR("Peter Griffin <peter.griffin@linaro.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) MODULE_LICENSE("GPL");