^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 OHCI 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 ohci-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/hrtimer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/phy/phy.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/reset.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/usb/ohci_pdriver.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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "ohci.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define USB_MAX_CLKS 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct st_ohci_platform_priv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct clk *clks[USB_MAX_CLKS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct clk *clk48;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct reset_control *rst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct reset_control *pwr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct phy *phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define DRIVER_DESC "OHCI STMicroelectronics driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define hcd_to_ohci_priv(h) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) ((struct st_ohci_platform_priv *)hcd_to_ohci(h)->priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static const char hcd_name[] = "ohci-st";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static int st_ohci_platform_power_on(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct usb_hcd *hcd = platform_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct st_ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) int clk, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) ret = reset_control_deassert(priv->pwr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) ret = reset_control_deassert(priv->rst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) goto err_assert_power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /* some SoCs don't have a dedicated 48Mhz clock, but those that do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) need the rate to be explicitly set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (priv->clk48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ret = clk_set_rate(priv->clk48, 48000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) goto err_assert_reset;
^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) for (clk = 0; clk < USB_MAX_CLKS && priv->clks[clk]; clk++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) ret = clk_prepare_enable(priv->clks[clk]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) goto err_disable_clks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) ret = phy_init(priv->phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) goto err_disable_clks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) ret = phy_power_on(priv->phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) goto err_exit_phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) err_exit_phy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) phy_exit(priv->phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) err_disable_clks:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) while (--clk >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) clk_disable_unprepare(priv->clks[clk]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) err_assert_reset:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) reset_control_assert(priv->rst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) err_assert_power:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) reset_control_assert(priv->pwr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static void st_ohci_platform_power_off(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct usb_hcd *hcd = platform_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct st_ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) int clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) reset_control_assert(priv->pwr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) reset_control_assert(priv->rst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) phy_power_off(priv->phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) phy_exit(priv->phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) for (clk = USB_MAX_CLKS - 1; clk >= 0; clk--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (priv->clks[clk])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) clk_disable_unprepare(priv->clks[clk]);
^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 struct hc_driver __read_mostly ohci_platform_hc_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static const struct ohci_driver_overrides platform_overrides __initconst = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .product_desc = "ST OHCI controller",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .extra_priv_size = sizeof(struct st_ohci_platform_priv),
^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 struct usb_ohci_pdata ohci_platform_defaults = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) .power_on = st_ohci_platform_power_on,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .power_suspend = st_ohci_platform_power_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) .power_off = st_ohci_platform_power_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static int st_ohci_platform_probe(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct usb_hcd *hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct resource *res_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct usb_ohci_pdata *pdata = &ohci_platform_defaults;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct st_ohci_platform_priv *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int err, irq, clk = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (usb_disabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) irq = platform_get_irq(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (irq < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (!res_mem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) dev_err(&dev->dev, "no memory resource provided");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) dev_name(&dev->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (!hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) platform_set_drvdata(dev, hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) dev->dev.platform_data = pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) priv = hcd_to_ohci_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) priv->phy = devm_phy_get(&dev->dev, "usb");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (IS_ERR(priv->phy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) err = PTR_ERR(priv->phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) goto err_put_hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) for (clk = 0; clk < USB_MAX_CLKS; clk++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) priv->clks[clk] = of_clk_get(dev->dev.of_node, clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (IS_ERR(priv->clks[clk])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) err = PTR_ERR(priv->clks[clk]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (err == -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) goto err_put_clks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) priv->clks[clk] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /* some SoCs don't have a dedicated 48Mhz clock, but those that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) do need the rate to be explicitly set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) priv->clk48 = devm_clk_get(&dev->dev, "clk48");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (IS_ERR(priv->clk48)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) dev_info(&dev->dev, "48MHz clk not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) priv->clk48 = NULL;
^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) priv->pwr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) devm_reset_control_get_optional_shared(&dev->dev, "power");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (IS_ERR(priv->pwr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) err = PTR_ERR(priv->pwr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) goto err_put_clks;
^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) priv->rst =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) devm_reset_control_get_optional_shared(&dev->dev, "softreset");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (IS_ERR(priv->rst)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) err = PTR_ERR(priv->rst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) goto err_put_clks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (pdata->power_on) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) err = pdata->power_on(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) goto err_power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) hcd->rsrc_start = res_mem->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) hcd->rsrc_len = resource_size(res_mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (IS_ERR(hcd->regs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) err = PTR_ERR(hcd->regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) goto err_power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) err = usb_add_hcd(hcd, irq, IRQF_SHARED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) goto err_power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) device_wakeup_enable(hcd->self.controller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) platform_set_drvdata(dev, hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) err_power:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (pdata->power_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) pdata->power_off(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) err_put_clks:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) while (--clk >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) clk_put(priv->clks[clk]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) err_put_hcd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (pdata == &ohci_platform_defaults)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) dev->dev.platform_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) usb_put_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static int st_ohci_platform_remove(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct usb_hcd *hcd = platform_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct st_ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) int clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) usb_remove_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (pdata->power_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) pdata->power_off(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) for (clk = 0; clk < USB_MAX_CLKS && priv->clks[clk]; clk++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) clk_put(priv->clks[clk]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) usb_put_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (pdata == &ohci_platform_defaults)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) dev->dev.platform_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static int st_ohci_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) struct usb_hcd *hcd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) struct usb_ohci_pdata *pdata = dev->platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) bool do_wakeup = device_may_wakeup(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) ret = ohci_suspend(hcd, do_wakeup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (pdata->power_suspend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) pdata->power_suspend(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static int st_ohci_resume(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_ohci_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) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (pdata->power_on) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) err = pdata->power_on(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) ohci_resume(hcd, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return 0;
^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) static SIMPLE_DEV_PM_OPS(st_ohci_pm_ops, st_ohci_suspend, st_ohci_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) #endif /* CONFIG_PM_SLEEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static const struct of_device_id st_ohci_platform_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) { .compatible = "st,st-ohci-300x", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) { /* sentinel */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) MODULE_DEVICE_TABLE(of, st_ohci_platform_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static struct platform_driver ohci_platform_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) .probe = st_ohci_platform_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) .remove = st_ohci_platform_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) .shutdown = usb_hcd_platform_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) .name = "st-ohci",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) .pm = &st_ohci_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) .of_match_table = st_ohci_platform_ids,
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static int __init ohci_platform_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (usb_disabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) pr_info("%s: " DRIVER_DESC "\n", hcd_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) ohci_init_driver(&ohci_platform_hc_driver, &platform_overrides);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return platform_driver_register(&ohci_platform_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) module_init(ohci_platform_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static void __exit ohci_platform_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) platform_driver_unregister(&ohci_platform_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) module_exit(ohci_platform_cleanup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) MODULE_AUTHOR("Peter Griffin <peter.griffin@linaro.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) MODULE_LICENSE("GPL");