^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) * Samsung Exynos USB HOST EHCI Controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2011 Samsung Electronics Co.Ltd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author: Jingoo Han <jg1.han@samsung.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Author: Joonyoung Shim <jy0922.shim@samsung.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.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_gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/phy/phy.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/usb/hcd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "ehci.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define DRIVER_DESC "EHCI Exynos driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define EHCI_INSNREG00(base) (base + 0x90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define EHCI_INSNREG00_ENA_INCR16 (0x1 << 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define EHCI_INSNREG00_ENA_INCR8 (0x1 << 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define EHCI_INSNREG00_ENA_INCR4 (0x1 << 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define EHCI_INSNREG00_ENA_INCRX_ALIGN (0x1 << 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define EHCI_INSNREG00_ENABLE_DMA_BURST \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) (EHCI_INSNREG00_ENA_INCR16 | EHCI_INSNREG00_ENA_INCR8 | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) EHCI_INSNREG00_ENA_INCR4 | EHCI_INSNREG00_ENA_INCRX_ALIGN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static const char hcd_name[] = "ehci-exynos";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static struct hc_driver __read_mostly exynos_ehci_hc_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define PHY_NUMBER 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct exynos_ehci_hcd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct clk *clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct device_node *of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct phy *phy[PHY_NUMBER];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) bool legacy_phy;
^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) #define to_exynos_ehci(hcd) (struct exynos_ehci_hcd *)(hcd_to_ehci(hcd)->priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static int exynos_ehci_get_phy(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct exynos_ehci_hcd *exynos_ehci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct device_node *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct phy *phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) int phy_number, num_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* Get PHYs for the controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) num_phys = of_count_phandle_with_args(dev->of_node, "phys",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) "#phy-cells");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) for (phy_number = 0; phy_number < num_phys; phy_number++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) phy = devm_of_phy_get_by_index(dev, dev->of_node, phy_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (IS_ERR(phy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return PTR_ERR(phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) exynos_ehci->phy[phy_number] = phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (num_phys > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /* Get PHYs using legacy bindings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) for_each_available_child_of_node(dev->of_node, child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) ret = of_property_read_u32(child, "reg", &phy_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) dev_err(dev, "Failed to parse device tree\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) of_node_put(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (phy_number >= PHY_NUMBER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) dev_err(dev, "Invalid number of PHYs\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) of_node_put(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) phy = devm_of_phy_get(dev, child, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) exynos_ehci->phy[phy_number] = phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (IS_ERR(phy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) ret = PTR_ERR(phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (ret == -EPROBE_DEFER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) of_node_put(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) } else if (ret != -ENOSYS && ret != -ENODEV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) "Error retrieving usb2 phy: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) of_node_put(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) exynos_ehci->legacy_phy = true;
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static int exynos_ehci_phy_enable(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct usb_hcd *hcd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) for (i = 0; ret == 0 && i < PHY_NUMBER; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (!IS_ERR(exynos_ehci->phy[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) ret = phy_power_on(exynos_ehci->phy[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) for (i--; i >= 0; i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if (!IS_ERR(exynos_ehci->phy[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) phy_power_off(exynos_ehci->phy[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static void exynos_ehci_phy_disable(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct usb_hcd *hcd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) for (i = 0; i < PHY_NUMBER; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (!IS_ERR(exynos_ehci->phy[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) phy_power_off(exynos_ehci->phy[i]);
^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) static void exynos_setup_vbus_gpio(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (!dev->of_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) gpio = of_get_named_gpio(dev->of_node, "samsung,vbus-gpio", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (!gpio_is_valid(gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) err = devm_gpio_request_one(dev, gpio, GPIOF_OUT_INIT_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) "ehci_vbus_gpio");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) dev_err(dev, "can't request ehci vbus gpio %d", gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static int exynos_ehci_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct exynos_ehci_hcd *exynos_ehci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct usb_hcd *hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct ehci_hcd *ehci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * Right now device-tree probed devices don't get dma_mask set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * Since shared usb code relies on it, set it here for now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * Once we move to full device tree support this will vanish off.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) err = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) exynos_setup_vbus_gpio(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) hcd = usb_create_hcd(&exynos_ehci_hc_driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) &pdev->dev, dev_name(&pdev->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (!hcd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) dev_err(&pdev->dev, "Unable to create HCD\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) exynos_ehci = to_exynos_ehci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) err = exynos_ehci_get_phy(&pdev->dev, exynos_ehci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) goto fail_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) exynos_ehci->clk = devm_clk_get(&pdev->dev, "usbhost");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (IS_ERR(exynos_ehci->clk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) dev_err(&pdev->dev, "Failed to get usbhost clock\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) err = PTR_ERR(exynos_ehci->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) goto fail_clk;
^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) err = clk_prepare_enable(exynos_ehci->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) goto fail_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) hcd->regs = devm_ioremap_resource(&pdev->dev, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (IS_ERR(hcd->regs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) err = PTR_ERR(hcd->regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) goto fail_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) hcd->rsrc_start = res->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) hcd->rsrc_len = resource_size(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) irq = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (irq < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) err = irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) goto fail_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) err = exynos_ehci_phy_enable(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) dev_err(&pdev->dev, "Failed to enable USB phy\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) goto fail_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) ehci = hcd_to_ehci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) ehci->caps = hcd->regs;
^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) * Workaround: reset of_node pointer to avoid conflict between legacy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * Exynos EHCI port subnodes and generic USB device bindings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) exynos_ehci->of_node = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (exynos_ehci->legacy_phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) pdev->dev.of_node = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /* DMA burst Enable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) err = usb_add_hcd(hcd, irq, IRQF_SHARED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) dev_err(&pdev->dev, "Failed to add USB HCD\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) goto fail_add_hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) device_wakeup_enable(hcd->self.controller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) platform_set_drvdata(pdev, hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) fail_add_hcd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) exynos_ehci_phy_disable(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) pdev->dev.of_node = exynos_ehci->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) fail_io:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) clk_disable_unprepare(exynos_ehci->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) fail_clk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) usb_put_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static int exynos_ehci_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct usb_hcd *hcd = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) pdev->dev.of_node = exynos_ehci->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) usb_remove_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) exynos_ehci_phy_disable(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) clk_disable_unprepare(exynos_ehci->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) usb_put_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static int exynos_ehci_suspend(struct 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 = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) bool do_wakeup = device_may_wakeup(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) rc = ehci_suspend(hcd, do_wakeup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) exynos_ehci_phy_disable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) clk_disable_unprepare(exynos_ehci->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static int exynos_ehci_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) struct usb_hcd *hcd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) ret = clk_prepare_enable(exynos_ehci->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) ret = exynos_ehci_phy_enable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) dev_err(dev, "Failed to enable USB phy\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) clk_disable_unprepare(exynos_ehci->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) /* DMA burst Enable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) ehci_resume(hcd, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) #define exynos_ehci_suspend NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) #define exynos_ehci_resume NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static const struct dev_pm_ops exynos_ehci_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) .suspend = exynos_ehci_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) .resume = exynos_ehci_resume,
^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) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) static const struct of_device_id exynos_ehci_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) { .compatible = "samsung,exynos4210-ehci" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) MODULE_DEVICE_TABLE(of, exynos_ehci_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) static struct platform_driver exynos_ehci_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) .probe = exynos_ehci_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) .remove = exynos_ehci_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 = "exynos-ehci",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) .pm = &exynos_ehci_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) .of_match_table = of_match_ptr(exynos_ehci_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static const struct ehci_driver_overrides exynos_overrides __initconst = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) .extra_priv_size = sizeof(struct exynos_ehci_hcd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) static int __init ehci_exynos_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if (usb_disabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) pr_info("%s: " DRIVER_DESC "\n", hcd_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) ehci_init_driver(&exynos_ehci_hc_driver, &exynos_overrides);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) return platform_driver_register(&exynos_ehci_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) module_init(ehci_exynos_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_exynos_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(&exynos_ehci_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) module_exit(ehci_exynos_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_ALIAS("platform:exynos-ehci");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) MODULE_AUTHOR("Jingoo Han");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) MODULE_AUTHOR("Joonyoung Shim");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) MODULE_LICENSE("GPL v2");