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-1.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)  *  Copyright (C) 2004 SAN People (Pty) Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * AT91 Bus Glue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Based on fragments of 2.4 driver by Rick Bronson.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Based on ohci-omap.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * This file is licenced under the GPL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/of_platform.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/platform_data/atmel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/mfd/syscon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/usb/hcd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <soc/at91/atmel-sfr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include "ohci.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define valid_port(index)	((index) >= 0 && (index) < AT91_MAX_USBH_PORTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define at91_for_each_port(index)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		for ((index) = 0; (index) < AT91_MAX_USBH_PORTS; (index)++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) /* interface, function and usb clocks; sometimes also an AHB clock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define hcd_to_ohci_at91_priv(h) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	((struct ohci_at91_priv *)hcd_to_ohci(h)->priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define AT91_MAX_USBH_PORTS	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) struct at91_usbh_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	struct gpio_desc *vbus_pin[AT91_MAX_USBH_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	struct gpio_desc *overcurrent_pin[AT91_MAX_USBH_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	u8 ports;				/* number of ports on root hub */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	u8 overcurrent_supported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	u8 overcurrent_status[AT91_MAX_USBH_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	u8 overcurrent_changed[AT91_MAX_USBH_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) struct ohci_at91_priv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct clk *iclk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct clk *fclk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct clk *hclk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	bool clocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	bool wakeup;		/* Saved wake-up state for resume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct regmap *sfr_regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) /* interface and function clocks; sometimes also an AHB clock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #define DRIVER_DESC "OHCI Atmel driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static const char hcd_name[] = "ohci-atmel";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static struct hc_driver __read_mostly ohci_at91_hc_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) static const struct ohci_driver_overrides ohci_at91_drv_overrides __initconst = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	.extra_priv_size = sizeof(struct ohci_at91_priv),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^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) static void at91_start_clock(struct ohci_at91_priv *ohci_at91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (ohci_at91->clocked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	clk_set_rate(ohci_at91->fclk, 48000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	clk_prepare_enable(ohci_at91->hclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	clk_prepare_enable(ohci_at91->iclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	clk_prepare_enable(ohci_at91->fclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	ohci_at91->clocked = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static void at91_stop_clock(struct ohci_at91_priv *ohci_at91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (!ohci_at91->clocked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	clk_disable_unprepare(ohci_at91->fclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	clk_disable_unprepare(ohci_at91->iclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	clk_disable_unprepare(ohci_at91->hclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	ohci_at91->clocked = false;
^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 at91_start_hc(struct platform_device *pdev)
^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(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	struct ohci_regs __iomem *regs = hcd->regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	struct ohci_at91_priv *ohci_at91 = hcd_to_ohci_at91_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	dev_dbg(&pdev->dev, "start\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	 * Start the USB clocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	at91_start_clock(ohci_at91);
^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) 	 * The USB host controller must remain in reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	writel(0, &regs->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static void at91_stop_hc(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct usb_hcd *hcd = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct ohci_at91_priv *ohci_at91 = hcd_to_ohci_at91_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	dev_dbg(&pdev->dev, "stop\n");
^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) 	 * Put the USB host controller into reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	usb_hcd_platform_shutdown(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	 * Stop the USB clocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	at91_stop_clock(ohci_at91);
^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) 
^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 void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static struct regmap *at91_dt_syscon_sfr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	regmap = syscon_regmap_lookup_by_compatible("atmel,sama5d2-sfr");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (IS_ERR(regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		regmap = syscon_regmap_lookup_by_compatible("microchip,sam9x60-sfr");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		if (IS_ERR(regmap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			regmap = NULL;
^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) 	return regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /* configure so an HC device and id are always provided */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /* always called with process context; sleeping is OK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  * usb_hcd_at91_probe - initialize AT91-based HCDs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  * Context: !in_interrupt()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  * Allocates basic resources for this USB host controller, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  * then invokes the start() method for the HCD associated with it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  * through the hotplug entry's driver_data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static int usb_hcd_at91_probe(const struct hc_driver *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	struct at91_usbh_data *board;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	struct ohci_hcd *ohci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct usb_hcd *hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	struct ohci_at91_priv *ohci_at91;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	irq = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	if (irq < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		dev_dbg(dev, "hcd probe: missing irq resource\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		return irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	hcd = usb_create_hcd(driver, dev, "at91");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	if (!hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	ohci_at91 = hcd_to_ohci_at91_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	hcd->regs = devm_ioremap_resource(dev, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	if (IS_ERR(hcd->regs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		retval = PTR_ERR(hcd->regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	hcd->rsrc_start = res->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	hcd->rsrc_len = resource_size(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	ohci_at91->iclk = devm_clk_get(dev, "ohci_clk");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	if (IS_ERR(ohci_at91->iclk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		dev_err(dev, "failed to get ohci_clk\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		retval = PTR_ERR(ohci_at91->iclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	ohci_at91->fclk = devm_clk_get(dev, "uhpck");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (IS_ERR(ohci_at91->fclk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		dev_err(dev, "failed to get uhpck\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		retval = PTR_ERR(ohci_at91->fclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	ohci_at91->hclk = devm_clk_get(dev, "hclk");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	if (IS_ERR(ohci_at91->hclk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		dev_err(dev, "failed to get hclk\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		retval = PTR_ERR(ohci_at91->hclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	ohci_at91->sfr_regmap = at91_dt_syscon_sfr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (!ohci_at91->sfr_regmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		dev_dbg(dev, "failed to find sfr node\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	board = hcd->self.controller->platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	ohci = hcd_to_ohci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	ohci->num_ports = board->ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	at91_start_hc(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	 * The RemoteWakeupConnected bit has to be set explicitly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	 * before calling ohci_run. The reset value of this bit is 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	ohci->hc_control = OHCI_CTRL_RWC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (retval == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		device_wakeup_enable(hcd->self.controller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		return retval;
^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) 	/* Error handling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	at91_stop_hc(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	usb_put_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) /* may be called with controller, bus, and devices active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  * usb_hcd_at91_remove - shutdown processing for AT91-based HCDs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  * Context: !in_interrupt()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  * Reverses the effect of usb_hcd_at91_probe(), first invoking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  * the HCD's stop() method.  It is always called from a thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)  * context, "rmmod" or something similar.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static void usb_hcd_at91_remove(struct usb_hcd *hcd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 				struct platform_device *pdev)
^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) 	at91_stop_hc(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	usb_put_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /*-------------------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	if (!valid_port(port))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	gpiod_set_value(pdata->vbus_pin[port], enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	if (!valid_port(port))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	return gpiod_get_value(pdata->vbus_pin[port]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)  * Update the status data from the hub with the over-current indicator change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	struct at91_usbh_data *pdata = hcd->self.controller->platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	int length = ohci_hub_status_data(hcd, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	int port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	at91_for_each_port(port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		if (pdata->overcurrent_changed[port]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			if (!length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 				length = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			buf[0] |= 1 << (port + 1);
^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) 	return length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static int ohci_at91_port_suspend(struct regmap *regmap, u8 set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	u32 regval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	if (!regmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	ret = regmap_read(regmap, AT91_SFR_OHCIICR, &regval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	if (set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		regval |= AT91_OHCIICR_USB_SUSPEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		regval &= ~AT91_OHCIICR_USB_SUSPEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	regmap_write(regmap, AT91_SFR_OHCIICR, regval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	return 0;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  * 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 325)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 				 u16 wIndex, char *buf, u16 wLength)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	struct at91_usbh_data *pdata = dev_get_platdata(hcd->self.controller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	struct ohci_at91_priv *ohci_at91 = hcd_to_ohci_at91_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	struct usb_hub_descriptor *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	u32 *data = (u32 *)buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	dev_dbg(hcd->self.controller,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		"ohci_at91_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		hcd, typeReq, wValue, wIndex, buf, wLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	wIndex--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	switch (typeReq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	case SetPortFeature:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		switch (wValue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		case USB_PORT_FEAT_POWER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 			if (valid_port(wIndex)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 				ohci_at91_usb_set_power(pdata, wIndex, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 				ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		case USB_PORT_FEAT_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			dev_dbg(hcd->self.controller, "SetPortFeat: SUSPEND\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 			if (valid_port(wIndex) && ohci_at91->sfr_regmap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 				ohci_at91_port_suspend(ohci_at91->sfr_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 						       1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	case ClearPortFeature:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		switch (wValue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		case USB_PORT_FEAT_C_OVER_CURRENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			dev_dbg(hcd->self.controller,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 				"ClearPortFeature: C_OVER_CURRENT\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 			if (valid_port(wIndex)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 				pdata->overcurrent_changed[wIndex] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 				pdata->overcurrent_status[wIndex] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		case USB_PORT_FEAT_OVER_CURRENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 			dev_dbg(hcd->self.controller,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 				"ClearPortFeature: OVER_CURRENT\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 			if (valid_port(wIndex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 				pdata->overcurrent_status[wIndex] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		case USB_PORT_FEAT_POWER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 			dev_dbg(hcd->self.controller,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 				"ClearPortFeature: POWER\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 			if (valid_port(wIndex)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 				ohci_at91_usb_set_power(pdata, wIndex, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		case USB_PORT_FEAT_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 			dev_dbg(hcd->self.controller, "ClearPortFeature: SUSPEND\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 			if (valid_port(wIndex) && ohci_at91->sfr_regmap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 				ohci_at91_port_suspend(ohci_at91->sfr_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 						       0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	ret = ohci_hub_control(hcd, typeReq, wValue, wIndex + 1, buf, wLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	switch (typeReq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	case GetHubDescriptor:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		/* update the hub's descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		desc = (struct usb_hub_descriptor *)buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		dev_dbg(hcd->self.controller, "wHubCharacteristics 0x%04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 			desc->wHubCharacteristics);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		/* remove the old configurations for power-switching, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		 * over-current protection, and insert our new configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_LPSM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		desc->wHubCharacteristics |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 			cpu_to_le16(HUB_CHAR_INDV_PORT_LPSM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		if (pdata->overcurrent_supported) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 			desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_OCPM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 			desc->wHubCharacteristics |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 				cpu_to_le16(HUB_CHAR_INDV_PORT_OCPM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 			desc->wHubCharacteristics);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	case GetPortStatus:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		/* check port status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		if (valid_port(wIndex)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 			if (!ohci_at91_usb_get_power(pdata, wIndex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 				*data &= ~cpu_to_le32(RH_PS_PPS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 			if (pdata->overcurrent_changed[wIndex])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 				*data |= cpu_to_le32(RH_PS_OCIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 			if (pdata->overcurrent_status[wIndex])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 				*data |= cpu_to_le32(RH_PS_POCI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) /*-------------------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	struct platform_device *pdev = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	struct at91_usbh_data *pdata = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	int val, port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	/* From the GPIO notifying the over-current situation, find
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	 * out the corresponding port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	at91_for_each_port(port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		if (gpiod_to_irq(pdata->overcurrent_pin[port]) == irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	if (port == AT91_MAX_USBH_PORTS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		dev_err(& pdev->dev, "overcurrent interrupt from unknown GPIO\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		return IRQ_HANDLED;
^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) 	val = gpiod_get_value(pdata->overcurrent_pin[port]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	/* When notified of an over-current situation, disable power
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	   on the corresponding port, and mark this port in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	   over-current. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	if (!val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		ohci_at91_usb_set_power(pdata, port, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		pdata->overcurrent_status[port]  = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		pdata->overcurrent_changed[port] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	dev_dbg(& pdev->dev, "overcurrent situation %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		val ? "exited" : "notified");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) static const struct of_device_id at91_ohci_dt_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	{ .compatible = "atmel,at91rm9200-ohci" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	{ /* sentinel */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) MODULE_DEVICE_TABLE(of, at91_ohci_dt_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) /*-------------------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	struct at91_usbh_data	*pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	int			i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	int			ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	int			err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	u32			ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	/* Right now device-tree probed devices don't get dma_mask set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	 * Since shared usb code relies on it, set it here for now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	 * Once we have dma capability bindings this can go away.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	if (!pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	pdev->dev.platform_data = pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	if (!of_property_read_u32(np, "num-ports", &ports))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		pdata->ports = ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	at91_for_each_port(i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 		if (i >= pdata->ports)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		pdata->vbus_pin[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 			devm_gpiod_get_index_optional(&pdev->dev, "atmel,vbus",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 						      i, GPIOD_OUT_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		if (IS_ERR(pdata->vbus_pin[i])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 			err = PTR_ERR(pdata->vbus_pin[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 			dev_err(&pdev->dev, "unable to claim gpio \"vbus\": %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 			continue;
^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) 	at91_for_each_port(i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 		if (i >= pdata->ports)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		pdata->overcurrent_pin[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 			devm_gpiod_get_index_optional(&pdev->dev, "atmel,oc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 						      i, GPIOD_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 		if (!pdata->overcurrent_pin[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 		if (IS_ERR(pdata->overcurrent_pin[i])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 			err = PTR_ERR(pdata->overcurrent_pin[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 			dev_err(&pdev->dev, "unable to claim gpio \"overcurrent\": %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 		ret = devm_request_irq(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 				       gpiod_to_irq(pdata->overcurrent_pin[i]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 				       ohci_hcd_at91_overcurrent_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 				       IRQF_SHARED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 				       "ohci_overcurrent", pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 			dev_info(&pdev->dev, "failed to request gpio \"overcurrent\" IRQ\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	device_init_wakeup(&pdev->dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	struct at91_usbh_data	*pdata = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	int			i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	if (pdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 		at91_for_each_port(i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 			ohci_at91_usb_set_power(pdata, i, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	device_init_wakeup(&pdev->dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) static int __maybe_unused
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) ohci_hcd_at91_drv_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	struct usb_hcd	*hcd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	struct ohci_hcd	*ohci = hcd_to_ohci(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	struct ohci_at91_priv *ohci_at91 = hcd_to_ohci_at91_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	int		ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	 * Disable wakeup if we are going to sleep with slow clock mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	 * enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	ohci_at91->wakeup = device_may_wakeup(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 			&& !at91_suspend_entering_slow_clock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	if (ohci_at91->wakeup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 		enable_irq_wake(hcd->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	ret = ohci_suspend(hcd, ohci_at91->wakeup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 		if (ohci_at91->wakeup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 			disable_irq_wake(hcd->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	 * The integrated transceivers seem unable to notice disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	 * reconnect, or wakeup without the 48 MHz clock active.  so for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	 * correctness, always discard connection state (using reset).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	 * REVISIT: some boards will be able to turn VBUS off...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	if (!ohci_at91->wakeup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 		ohci->rh_state = OHCI_RH_HALTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 		/* flush the writes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 		(void) ohci_readl (ohci, &ohci->regs->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 		msleep(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 		ohci_at91_port_suspend(ohci_at91->sfr_regmap, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 		at91_stop_clock(ohci_at91);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 		ohci_at91_port_suspend(ohci_at91->sfr_regmap, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) static int __maybe_unused
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) ohci_hcd_at91_drv_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	struct usb_hcd	*hcd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	struct ohci_at91_priv *ohci_at91 = hcd_to_ohci_at91_priv(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	ohci_at91_port_suspend(ohci_at91->sfr_regmap, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	if (ohci_at91->wakeup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 		disable_irq_wake(hcd->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 		at91_start_clock(ohci_at91);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	ohci_resume(hcd, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) static SIMPLE_DEV_PM_OPS(ohci_hcd_at91_pm_ops, ohci_hcd_at91_drv_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 					ohci_hcd_at91_drv_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) static struct platform_driver ohci_hcd_at91_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	.probe		= ohci_hcd_at91_drv_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	.remove		= ohci_hcd_at91_drv_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	.shutdown	= usb_hcd_platform_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 		.name	= "at91_ohci",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 		.pm	= &ohci_hcd_at91_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 		.of_match_table	= at91_ohci_dt_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) static int __init ohci_at91_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	if (usb_disabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	pr_info("%s: " DRIVER_DESC "\n", hcd_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	ohci_init_driver(&ohci_at91_hc_driver, &ohci_at91_drv_overrides);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	 * The Atmel HW has some unusual quirks, which require Atmel-specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	 * workarounds. We override certain hc_driver functions here to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	 * achieve that. We explicitly do not enhance ohci_driver_overrides to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	 * allow this more easily, since this is an unusual case, and we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	 * want to encourage others to override these functions by making it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	 * too easy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	ohci_at91_hc_driver.hub_status_data	= ohci_at91_hub_status_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	ohci_at91_hc_driver.hub_control		= ohci_at91_hub_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	return platform_driver_register(&ohci_hcd_at91_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) module_init(ohci_at91_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) static void __exit ohci_at91_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	platform_driver_unregister(&ohci_hcd_at91_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) module_exit(ohci_at91_cleanup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) MODULE_ALIAS("platform:at91_ohci");