^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) * OHCI HCD (Host Controller Driver) for USB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * TI DA8xx (OMAP-L1x) Bus Glue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Derived from: ohci-omap.c and ohci-s3c2410.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (C) 2008-2009 MontaVista Software, Inc. <source@mvista.com>
^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/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/jiffies.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/platform_device.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_data/usb-davinci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/regulator/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/usb/hcd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <asm/unaligned.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 DRIVER_DESC "DA8XX"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define DRV_NAME "ohci-da8xx"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static struct hc_driver __read_mostly ohci_da8xx_hc_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static int (*orig_ohci_hub_control)(struct usb_hcd *hcd, u16 typeReq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) u16 wValue, u16 wIndex, char *buf, u16 wLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct da8xx_ohci_hcd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct usb_hcd *hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct clk *usb11_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct phy *usb11_phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct regulator *vbus_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct notifier_block nb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct gpio_desc *oc_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define to_da8xx_ohci(hcd) (struct da8xx_ohci_hcd *)(hcd_to_ohci(hcd)->priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /* Over-current indicator change bitmask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static volatile u16 ocic_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static int ohci_da8xx_enable(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) ret = clk_prepare_enable(da8xx_ohci->usb11_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) ret = phy_init(da8xx_ohci->usb11_phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) goto err_phy_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) ret = phy_power_on(da8xx_ohci->usb11_phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) goto err_phy_power_on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) err_phy_power_on:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) phy_exit(da8xx_ohci->usb11_phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) err_phy_init:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) clk_disable_unprepare(da8xx_ohci->usb11_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^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) static void ohci_da8xx_disable(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) phy_power_off(da8xx_ohci->usb11_phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) phy_exit(da8xx_ohci->usb11_phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) clk_disable_unprepare(da8xx_ohci->usb11_clk);
^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 int ohci_da8xx_set_power(struct usb_hcd *hcd, int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct device *dev = hcd->self.controller;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (!da8xx_ohci->vbus_reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (on) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ret = regulator_enable(da8xx_ohci->vbus_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) dev_err(dev, "Failed to enable regulator: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) ret = regulator_disable(da8xx_ohci->vbus_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) dev_err(dev, "Failed to disable regulator: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static int ohci_da8xx_get_power(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (da8xx_ohci->vbus_reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return regulator_is_enabled(da8xx_ohci->vbus_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return 1;
^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 int ohci_da8xx_get_oci(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) unsigned int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (da8xx_ohci->oc_gpio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return gpiod_get_value_cansleep(da8xx_ohci->oc_gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (!da8xx_ohci->vbus_reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) ret = regulator_get_error_flags(da8xx_ohci->vbus_reg, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (flags & REGULATOR_ERROR_OVER_CURRENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static int ohci_da8xx_has_set_power(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (da8xx_ohci->vbus_reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static int ohci_da8xx_has_oci(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (da8xx_ohci->oc_gpio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (da8xx_ohci->vbus_reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static int ohci_da8xx_has_potpgt(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct device *dev = hcd->self.controller;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (hub && hub->potpgt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static int ohci_da8xx_regulator_event(struct notifier_block *nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) unsigned long event, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) struct da8xx_ohci_hcd *da8xx_ohci =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) container_of(nb, struct da8xx_ohci_hcd, nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (event & REGULATOR_EVENT_OVER_CURRENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) ocic_mask |= 1 << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) ohci_da8xx_set_power(da8xx_ohci->hcd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static irqreturn_t ohci_da8xx_oc_thread(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct da8xx_ohci_hcd *da8xx_ohci = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct device *dev = da8xx_ohci->hcd->self.controller;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (gpiod_get_value_cansleep(da8xx_ohci->oc_gpio) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) da8xx_ohci->vbus_reg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) ret = regulator_disable(da8xx_ohci->vbus_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) dev_err(dev, "Failed to disable regulator: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static int ohci_da8xx_register_notify(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) struct device *dev = hcd->self.controller;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (!da8xx_ohci->oc_gpio && da8xx_ohci->vbus_reg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) da8xx_ohci->nb.notifier_call = ohci_da8xx_regulator_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) ret = devm_regulator_register_notifier(da8xx_ohci->vbus_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) &da8xx_ohci->nb);
^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 (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) dev_err(dev, "Failed to register notifier: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return ret;
^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) static int ohci_da8xx_reset(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct device *dev = hcd->self.controller;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) struct ohci_hcd *ohci = hcd_to_ohci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) u32 rh_a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) dev_dbg(dev, "starting USB controller\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) result = ohci_da8xx_enable(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * DA8xx only have 1 port connected to the pins but the HC root hub
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * register A reports 2 ports, thus we'll have to override it...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) ohci->num_ports = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) result = ohci_setup(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (result < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) ohci_da8xx_disable(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * Since we're providing a board-specific root hub port power control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * and over-current reporting, we have to override the HC root hub A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * register's default value, so that ohci_hub_control() could return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * the correct hub descriptor...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) rh_a = ohci_readl(ohci, &ohci->regs->roothub.a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (ohci_da8xx_has_set_power(hcd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) rh_a &= ~RH_A_NPS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) rh_a |= RH_A_PSM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (ohci_da8xx_has_oci(hcd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) rh_a &= ~RH_A_NOCP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) rh_a |= RH_A_OCPM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (ohci_da8xx_has_potpgt(hcd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) rh_a &= ~RH_A_POTPGT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) rh_a |= hub->potpgt << 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) ohci_writel(ohci, rh_a, &ohci->regs->roothub.a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * Update the status data from the hub with the over-current indicator change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static int ohci_da8xx_hub_status_data(struct usb_hcd *hcd, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) int length = orig_ohci_hub_status_data(hcd, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /* See if we have OCIC bit set on port 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (ocic_mask & (1 << 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) dev_dbg(hcd->self.controller, "over-current indicator change "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) "on port 1\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (!length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) length = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) buf[0] |= 1 << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) return length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^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) * Look at the control requests to the root hub and see if we need to override.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) u16 wIndex, char *buf, u16 wLength)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) struct device *dev = hcd->self.controller;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) int temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) switch (typeReq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) case GetPortStatus:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) /* Check the port number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (wIndex != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) dev_dbg(dev, "GetPortStatus(%u)\n", wIndex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) temp = roothub_portstatus(hcd_to_ohci(hcd), wIndex - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) /* The port power status (PPS) bit defaults to 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (!ohci_da8xx_get_power(hcd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) temp &= ~RH_PS_PPS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) /* The port over-current indicator (POCI) bit is always 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) if (ohci_da8xx_get_oci(hcd) > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) temp |= RH_PS_POCI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /* The over-current indicator change (OCIC) bit is 0 too */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (ocic_mask & (1 << wIndex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) temp |= RH_PS_OCIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) put_unaligned(cpu_to_le32(temp), (__le32 *)buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) case SetPortFeature:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) temp = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) goto check_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) case ClearPortFeature:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) temp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) check_port:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) /* Check the port number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (wIndex != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) switch (wValue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) case USB_PORT_FEAT_POWER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) dev_dbg(dev, "%sPortFeature(%u): %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) temp ? "Set" : "Clear", wIndex, "POWER");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) return ohci_da8xx_set_power(hcd, temp) ? -EPIPE : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) case USB_PORT_FEAT_C_OVER_CURRENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) dev_dbg(dev, "%sPortFeature(%u): %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) temp ? "Set" : "Clear", wIndex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) "C_OVER_CURRENT");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) if (temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) ocic_mask |= 1 << wIndex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) ocic_mask &= ~(1 << wIndex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) return orig_ohci_hub_control(hcd, typeReq, wValue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) wIndex, buf, wLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) /*-------------------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) static const struct of_device_id da8xx_ohci_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) { .compatible = "ti,da830-ohci" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) MODULE_DEVICE_TABLE(of, da8xx_ohci_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) static int ohci_da8xx_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) struct da8xx_ohci_hcd *da8xx_ohci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) int error, hcd_irq, oc_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) struct usb_hcd *hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) struct resource *mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) hcd = usb_create_hcd(&ohci_da8xx_hc_driver, dev, dev_name(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) if (!hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) da8xx_ohci = to_da8xx_ohci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) da8xx_ohci->hcd = hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) da8xx_ohci->usb11_clk = devm_clk_get(dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) if (IS_ERR(da8xx_ohci->usb11_clk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) error = PTR_ERR(da8xx_ohci->usb11_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) if (error != -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) dev_err(dev, "Failed to get clock.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) da8xx_ohci->usb11_phy = devm_phy_get(dev, "usb-phy");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if (IS_ERR(da8xx_ohci->usb11_phy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) error = PTR_ERR(da8xx_ohci->usb11_phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (error != -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) dev_err(dev, "Failed to get phy.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) da8xx_ohci->vbus_reg = devm_regulator_get_optional(dev, "vbus");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (IS_ERR(da8xx_ohci->vbus_reg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) error = PTR_ERR(da8xx_ohci->vbus_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if (error == -ENODEV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) da8xx_ohci->vbus_reg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) } else if (error == -EPROBE_DEFER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) dev_err(dev, "Failed to get regulator\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) da8xx_ohci->oc_gpio = devm_gpiod_get_optional(dev, "oc", GPIOD_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) if (IS_ERR(da8xx_ohci->oc_gpio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) error = PTR_ERR(da8xx_ohci->oc_gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (da8xx_ohci->oc_gpio) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) oc_irq = gpiod_to_irq(da8xx_ohci->oc_gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (oc_irq < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) error = oc_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) error = devm_request_threaded_irq(dev, oc_irq, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) ohci_da8xx_oc_thread, IRQF_TRIGGER_RISING |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) "OHCI over-current indicator", da8xx_ohci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) hcd->regs = devm_ioremap_resource(dev, mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) if (IS_ERR(hcd->regs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) error = PTR_ERR(hcd->regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) hcd->rsrc_start = mem->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) hcd->rsrc_len = resource_size(mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) hcd_irq = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) if (hcd_irq < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) error = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) goto err;
^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) error = usb_add_hcd(hcd, hcd_irq, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) device_wakeup_enable(hcd->self.controller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) error = ohci_da8xx_register_notify(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) goto err_remove_hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) err_remove_hcd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) usb_remove_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) usb_put_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) static int ohci_da8xx_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) struct usb_hcd *hcd = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) usb_remove_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) usb_put_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) static int ohci_da8xx_suspend(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) pm_message_t message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) struct usb_hcd *hcd = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) struct ohci_hcd *ohci = hcd_to_ohci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) bool do_wakeup = device_may_wakeup(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) if (time_before(jiffies, ohci->next_statechange))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) msleep(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) ohci->next_statechange = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) ret = ohci_suspend(hcd, do_wakeup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) ohci_da8xx_disable(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) hcd->state = HC_STATE_SUSPENDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) static int ohci_da8xx_resume(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) struct usb_hcd *hcd = platform_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) struct ohci_hcd *ohci = hcd_to_ohci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) if (time_before(jiffies, ohci->next_statechange))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) msleep(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) ohci->next_statechange = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) ret = ohci_da8xx_enable(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) ohci_resume(hcd, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) static const struct ohci_driver_overrides da8xx_overrides __initconst = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) .reset = ohci_da8xx_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) .extra_priv_size = sizeof(struct da8xx_ohci_hcd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) * Driver definition to register with platform structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) static struct platform_driver ohci_hcd_da8xx_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) .probe = ohci_da8xx_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) .remove = ohci_da8xx_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) .shutdown = usb_hcd_platform_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) .suspend = ohci_da8xx_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) .resume = ohci_da8xx_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) .name = DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) .of_match_table = of_match_ptr(da8xx_ohci_ids),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) static int __init ohci_da8xx_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) if (usb_disabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) pr_info("%s: " DRIVER_DESC "\n", DRV_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) ohci_init_driver(&ohci_da8xx_hc_driver, &da8xx_overrides);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) * The Davinci da8xx HW has some unusual quirks, which require
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) * da8xx-specific workarounds. We override certain hc_driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) * functions here to achieve that. We explicitly do not enhance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) * ohci_driver_overrides to allow this more easily, since this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) * is an unusual case, and we don't want to encourage others to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) * override these functions by making it too easy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) orig_ohci_hub_control = ohci_da8xx_hc_driver.hub_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) orig_ohci_hub_status_data = ohci_da8xx_hc_driver.hub_status_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) ohci_da8xx_hc_driver.hub_status_data = ohci_da8xx_hub_status_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) ohci_da8xx_hc_driver.hub_control = ohci_da8xx_hub_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) return platform_driver_register(&ohci_hcd_da8xx_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) module_init(ohci_da8xx_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) static void __exit ohci_da8xx_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) platform_driver_unregister(&ohci_hcd_da8xx_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) module_exit(ohci_da8xx_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) MODULE_ALIAS("platform:" DRV_NAME);