[U-Boot] [PATCH v2 3/4] usb: gadget: at91_udc: add at91_udc into U-Boot

Heiko Schocher hs at denx.de
Mon Aug 10 08:14:26 CEST 2015


add U-Boot specific changes to the at91_udc linux driver,
so it works with U-Boot.

Signed-off-by: Heiko Schocher <hs at denx.de>
---

Changes in v2:
- new in version 2, contains U-Boot changes

 drivers/usb/gadget/Makefile   |   1 +
 drivers/usb/gadget/at91_udc.c | 485 +++++++++---------------------------------
 drivers/usb/gadget/at91_udc.h |  19 +-
 include/linux/usb/at91_udc.h  |  33 ++-
 4 files changed, 123 insertions(+), 415 deletions(-)

diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 4c11a7e..6288ecf 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -10,6 +10,7 @@ obj-$(CONFIG_USB_ETHER) += epautoconf.o config.o usbstring.o
 
 # new USB gadget layer dependencies
 ifdef CONFIG_USB_GADGET
+obj-$(CONFIG_USB_GADGET_AT91) += at91_udc.o
 obj-$(CONFIG_USB_GADGET_ATMEL_USBA) += atmel_usba_udc.o
 obj-$(CONFIG_USB_GADGET_BCM_UDC_OTG_PHY) += bcm_udc_otg_phy.o
 obj-$(CONFIG_USB_GADGET_S3C_UDC_OTG) += s3c_udc_otg.o
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index eb2999c..0ff4f80 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -1,50 +1,37 @@
 /*
+ * from linux:
+ * b2ba27a5c56ff: usb: gadget: at91_udc: move prepare clk into process context
+ *
  * at91_udc -- driver for at91-series USB peripheral controller
  *
  * Copyright (C) 2004 by Thomas Rathbone
  * Copyright (C) 2005 by HP Labs
  * Copyright (C) 2005 by David Brownell
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * SPDX-License-Identifier:	GPL-2.0+
  */
 
 #undef	VERBOSE_DEBUG
 #undef	PACKET_TRACE
 
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/platform_device.h>
-#include <linux/delay.h>
-#include <linux/ioport.h>
-#include <linux/slab.h>
-#include <linux/errno.h>
-#include <linux/list.h>
-#include <linux/interrupt.h>
-#include <linux/proc_fs.h>
-#include <linux/prefetch.h>
-#include <linux/clk.h>
-#include <linux/usb/ch9.h>
-#include <linux/usb/gadget.h>
-#include <linux/of.h>
-#include <linux/of_gpio.h>
-#include <linux/platform_data/atmel.h>
-
-#include <asm/byteorder.h>
-#include <mach/hardware.h>
+#include <common.h>
+#include <asm/errno.h>
 #include <asm/io.h>
-#include <asm/irq.h>
 #include <asm/gpio.h>
-
 #include <mach/cpu.h>
-#include <mach/at91sam9261_matrix.h>
-#include <mach/at91_matrix.h>
+#include <asm/hardware.h>
+#if defined(CONFIG_AT91SAM9261)
+#include <asm/arch/at91sam9260_matrix.h>
+#endif
+#include <linux/list.h>
+#include <linux/usb/ch9.h>
+#include <linux/usb/gadget.h>
+#include <linux/usb/at91_udc.h>
+#include <malloc.h>
+#include <usb/lin_gadget_compat.h>
 
 #include "at91_udc.h"
 
-
 /*
  * This controller is simple and PIO-only.  It's used in many AT91-series
  * full speed USB controllers, including the at91rm9200 (arm920T, with MMU),
@@ -267,7 +254,7 @@ static void done(struct at91_ep *ep, struct at91_request *req, int status)
 
 	ep->stopped = 1;
 	spin_unlock(&udc->lock);
-	usb_gadget_giveback_request(&ep->ep, &req->req);
+	req->req.complete(&ep->ep, &req->req);
 	spin_lock(&udc->lock);
 	ep->stopped = stopped;
 
@@ -331,7 +318,7 @@ rescan:
 		req->req.status = -EOVERFLOW;
 		count = bufferspace;
 	}
-	__raw_readsb(dreg, buf, count);
+	__raw_readsb((unsigned long)dreg, buf, count);
 
 	/* release and swap pingpong mem bank */
 	csr |= CLR_FX;
@@ -433,7 +420,7 @@ static int write_fifo(struct at91_ep *ep, struct at91_request *req)
 	 * recover when the actual bytecount matters (e.g. for USB Test
 	 * and Measurement Class devices).
 	 */
-	__raw_writesb(dreg, buf, count);
+	__raw_writesb((unsigned long)dreg, buf, count);
 	csr &= ~SET_FX;
 	csr |= CLR_FX | AT91_UDP_TXPKTRDY;
 	__raw_writel(csr, creg);
@@ -702,14 +689,11 @@ static int at91_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
 	struct at91_ep		*ep;
 	struct at91_request	*req;
 	unsigned long		flags;
-	struct at91_udc		*udc;
 
 	ep = container_of(_ep, struct at91_ep, ep);
 	if (!_ep || ep->ep.name == ep0name)
 		return -EINVAL;
 
-	udc = ep->udc;
-
 	spin_lock_irqsave(&udc->lock, flags);
 
 	/* make sure it's actually queued on this endpoint */
@@ -858,7 +842,7 @@ static void reset_gadget(struct at91_udc *udc)
 	}
 	if (driver) {
 		spin_unlock(&udc->lock);
-		usb_gadget_udc_reset(&udc->gadget, driver);
+		udc->driver->disconnect(&udc->gadget);
 		spin_lock(&udc->lock);
 	}
 
@@ -894,11 +878,6 @@ static void clk_on(struct at91_udc *udc)
 	if (udc->clocked)
 		return;
 	udc->clocked = 1;
-
-	if (IS_ENABLED(CONFIG_COMMON_CLK))
-		clk_enable(udc->uclk);
-	clk_enable(udc->iclk);
-	clk_enable(udc->fclk);
 }
 
 static void clk_off(struct at91_udc *udc)
@@ -907,12 +886,30 @@ static void clk_off(struct at91_udc *udc)
 		return;
 	udc->clocked = 0;
 	udc->gadget.speed = USB_SPEED_UNKNOWN;
-	clk_disable(udc->fclk);
-	clk_disable(udc->iclk);
-	if (IS_ENABLED(CONFIG_COMMON_CLK))
-		clk_disable(udc->uclk);
 }
 
+#if defined(CONFIG_AT91SAM9261)
+static int at91_usb_pud(int on)
+{
+	struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
+	unsigned long pucr;
+
+	pucr = readl(&matrix->pucr);
+	if (on)
+		pucr |= AT91_MATRIX_USBPUCR_PUON;
+	else
+		pucr &= ~AT91_MATRIX_USBPUCR_PUON;
+	writel(pucr, &matrix->pucr);
+
+	return 0;
+}
+#else
+static int at91_usb_pud(int on)
+{
+	return 0;
+}
+#endif
+
 /*
  * activate/deactivate link with host; minimize power usage for
  * inactive links by cutting clocks and transceiver power.
@@ -937,11 +934,7 @@ static void pullup(struct at91_udc *udc, int is_on)
 			txvc |= AT91_UDP_TXVC_PUON;
 			at91_udp_write(udc, AT91_UDP_TXVC, txvc);
 		} else if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) {
-			u32	usbpucr;
-
-			usbpucr = at91_matrix_read(AT91_MATRIX_USBPUCR);
-			usbpucr |= AT91_MATRIX_USBPUCR_PUON;
-			at91_matrix_write(AT91_MATRIX_USBPUCR, usbpucr);
+			at91_usb_pud(1);
 		}
 	} else {
 		stop_activity(udc);
@@ -955,11 +948,7 @@ static void pullup(struct at91_udc *udc, int is_on)
 			txvc &= ~AT91_UDP_TXVC_PUON;
 			at91_udp_write(udc, AT91_UDP_TXVC, txvc);
 		} else if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) {
-			u32	usbpucr;
-
-			usbpucr = at91_matrix_read(AT91_MATRIX_USBPUCR);
-			usbpucr &= ~AT91_MATRIX_USBPUCR_PUON;
-			at91_matrix_write(AT91_MATRIX_USBPUCR, usbpucr);
+			at91_usb_pud(0);
 		}
 		clk_off(udc);
 	}
@@ -1418,9 +1407,8 @@ static void handle_ep0(struct at91_udc *udc)
 	}
 }
 
-static irqreturn_t at91_udc_irq (int irq, void *_udc)
+static irqreturn_t at91_udc_irq(struct at91_udc *udc)
 {
-	struct at91_udc		*udc = _udc;
 	u32			rescans = 5;
 	int			disable_clock = 0;
 	unsigned long		flags;
@@ -1603,55 +1591,11 @@ static struct at91_udc controller = {
 	/* ep6 and ep7 are also reserved (custom silicon might use them) */
 };
 
-static void at91_vbus_update(struct at91_udc *udc, unsigned value)
-{
-	value ^= udc->board.vbus_active_low;
-	if (value != udc->vbus)
-		at91_vbus_session(&udc->gadget, value);
-}
-
-static irqreturn_t at91_vbus_irq(int irq, void *_udc)
-{
-	struct at91_udc	*udc = _udc;
-
-	/* vbus needs at least brief debouncing */
-	udelay(10);
-	at91_vbus_update(udc, gpio_get_value(udc->board.vbus_pin));
-
-	return IRQ_HANDLED;
-}
-
-static void at91_vbus_timer_work(struct work_struct *work)
-{
-	struct at91_udc *udc = container_of(work, struct at91_udc,
-					    vbus_timer_work);
-
-	at91_vbus_update(udc, gpio_get_value_cansleep(udc->board.vbus_pin));
-
-	if (!timer_pending(&udc->vbus_timer))
-		mod_timer(&udc->vbus_timer, jiffies + VBUS_POLL_TIMEOUT);
-}
-
-static void at91_vbus_timer(unsigned long data)
-{
-	struct at91_udc *udc = (struct at91_udc *)data;
-
-	/*
-	 * If we are polling vbus it is likely that the gpio is on an
-	 * bus such as i2c or spi which may sleep, so schedule some work
-	 * to read the vbus gpio
-	 */
-	schedule_work(&udc->vbus_timer_work);
-}
-
 static int at91_start(struct usb_gadget *gadget,
 		struct usb_gadget_driver *driver)
 {
-	struct at91_udc	*udc;
+	struct at91_udc *udc = &controller;
 
-	udc = container_of(gadget, struct at91_udc, gadget);
-	udc->driver = driver;
-	udc->gadget.dev.of_node = udc->pdev->dev.of_node;
 	udc->enabled = 1;
 	udc->selfpowered = 1;
 
@@ -1664,6 +1608,7 @@ static int at91_stop(struct usb_gadget *gadget)
 	unsigned long	flags;
 
 	udc = container_of(gadget, struct at91_udc, gadget);
+
 	spin_lock_irqsave(&udc->lock, flags);
 	udc->enabled = 0;
 	at91_udp_write(udc, AT91_UDP_IDR, ~0);
@@ -1676,82 +1621,74 @@ static int at91_stop(struct usb_gadget *gadget)
 
 /*-------------------------------------------------------------------------*/
 
-static void at91udc_shutdown(struct platform_device *dev)
+int usb_gadget_handle_interrupts(int index)
 {
-	struct at91_udc *udc = platform_get_drvdata(dev);
-	unsigned long	flags;
+	struct at91_udc *udc = &controller;
 
-	/* force disconnect on reboot */
-	spin_lock_irqsave(&udc->lock, flags);
-	pullup(platform_get_drvdata(dev), 0);
-	spin_unlock_irqrestore(&udc->lock, flags);
+	return at91_udc_irq(udc);
 }
 
-static void at91udc_of_init(struct at91_udc *udc,
-				     struct device_node *np)
+int usb_gadget_register_driver(struct usb_gadget_driver *driver)
 {
-	struct at91_udc_data *board = &udc->board;
-	u32 val;
-	enum of_gpio_flags flags;
+	struct at91_udc *udc = &controller;
+	int ret;
 
-	if (of_property_read_u32(np, "atmel,vbus-polled", &val) == 0)
-		board->vbus_polled = 1;
+	if (!driver || !driver->bind || !driver->setup) {
+		printf("bad paramter\n");
+		return -EINVAL;
+	}
 
-	board->vbus_pin = of_get_named_gpio_flags(np, "atmel,vbus-gpio", 0,
-						  &flags);
-	board->vbus_active_low = (flags & OF_GPIO_ACTIVE_LOW) ? 1 : 0;
+	if (udc->driver) {
+		printf("UDC already has a gadget driver\n");
+		return -EBUSY;
+	}
+
+	at91_start(&udc->gadget, driver);
+
+	udc->driver = driver;
 
-	board->pullup_pin = of_get_named_gpio_flags(np, "atmel,pullup-gpio", 0,
-						  &flags);
+	ret = driver->bind(&udc->gadget);
+	if (ret) {
+		error("driver->bind() returned %d\n", ret);
+		udc->driver = NULL;
+	}
 
-	board->pullup_active_low = (flags & OF_GPIO_ACTIVE_LOW) ? 1 : 0;
+	return ret;
 }
 
-static int at91udc_probe(struct platform_device *pdev)
+int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
 {
-	struct device	*dev = &pdev->dev;
-	struct at91_udc	*udc;
-	int		retval;
-	struct resource	*res;
-
-	if (!dev_get_platdata(dev) && !pdev->dev.of_node) {
-		/* small (so we copy it) but critical! */
-		DBG("missing platform_data\n");
-		return -ENODEV;
+	struct at91_udc *udc = &controller;
+
+	if (!driver || !driver->unbind || !driver->disconnect) {
+		error("bad paramter\n");
+		return -EINVAL;
 	}
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -ENXIO;
+	driver->disconnect(&udc->gadget);
+	driver->unbind(&udc->gadget);
+	udc->driver = NULL;
 
-	if (!request_mem_region(res->start, resource_size(res), driver_name)) {
-		DBG("someone's using UDC memory\n");
-		return -EBUSY;
-	}
+	at91_stop(&udc->gadget);
+
+	return 0;
+}
+
+int at91_udc_probe(struct at91_udc_data *pdata)
+{
+	struct at91_udc *udc;
+	int retval;
 
-	/* init software state */
 	udc = &controller;
-	udc->gadget.dev.parent = dev;
-	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node)
-		at91udc_of_init(udc, pdev->dev.of_node);
-	else
-		memcpy(&udc->board, dev_get_platdata(dev),
-		       sizeof(struct at91_udc_data));
-	udc->pdev = pdev;
+	memcpy(&udc->board, pdata, sizeof(struct at91_udc_data));
 	udc->enabled = 0;
-	spin_lock_init(&udc->lock);
 
 	/* rm9200 needs manual D+ pullup; off by default */
 	if (cpu_is_at91rm9200()) {
-		if (!gpio_is_valid(udc->board.pullup_pin)) {
-			DBG("no D+ pullup?\n");
-			retval = -ENODEV;
-			goto fail0;
-		}
 		retval = gpio_request(udc->board.pullup_pin, "udc_pullup");
 		if (retval) {
 			DBG("D+ pullup is busy\n");
-			goto fail0;
+			return retval;
 		}
 		gpio_direction_output(udc->board.pullup_pin,
 				udc->board.pullup_active_low);
@@ -1770,249 +1707,25 @@ static int at91udc_probe(struct platform_device *pdev)
 		udc->ep[3].maxpacket = 64;
 	}
 
-	udc->udp_baseaddr = ioremap(res->start, resource_size(res));
-	if (!udc->udp_baseaddr) {
-		retval = -ENOMEM;
-		goto fail0a;
-	}
-
+	udc->udp_baseaddr = (void *)udc->board.baseaddr;
 	udc_reinit(udc);
 
-	/* get interface and function clocks */
-	udc->iclk = clk_get(dev, "udc_clk");
-	udc->fclk = clk_get(dev, "udpck");
-	if (IS_ENABLED(CONFIG_COMMON_CLK))
-		udc->uclk = clk_get(dev, "usb_clk");
-	if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk) ||
-	    (IS_ENABLED(CONFIG_COMMON_CLK) && IS_ERR(udc->uclk))) {
-		DBG("clocks missing\n");
-		retval = -ENODEV;
-		goto fail1;
-	}
-
-	/* don't do anything until we have both gadget driver and VBUS */
-	if (IS_ENABLED(CONFIG_COMMON_CLK)) {
-		clk_set_rate(udc->uclk, 48000000);
-		retval = clk_prepare(udc->uclk);
-		if (retval)
-			goto fail1;
-	}
-	retval = clk_prepare(udc->fclk);
-	if (retval)
-		goto fail1a;
+	/* enable clocks ??? or do this in board code ****/
 
-	retval = clk_prepare_enable(udc->iclk);
-	if (retval)
-		goto fail1b;
+	/* IRQ setup */
 	at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
 	at91_udp_write(udc, AT91_UDP_IDR, 0xffffffff);
 	/* Clear all pending interrupts - UDP may be used by bootloader. */
 	at91_udp_write(udc, AT91_UDP_ICR, 0xffffffff);
-	clk_disable(udc->iclk);
-
-	/* request UDC and maybe VBUS irqs */
-	udc->udp_irq = platform_get_irq(pdev, 0);
-	retval = request_irq(udc->udp_irq, at91_udc_irq,
-			0, driver_name, udc);
-	if (retval < 0) {
-		DBG("request irq %d failed\n", udc->udp_irq);
-		goto fail1c;
-	}
-	if (gpio_is_valid(udc->board.vbus_pin)) {
-		retval = gpio_request(udc->board.vbus_pin, "udc_vbus");
-		if (retval < 0) {
-			DBG("request vbus pin failed\n");
-			goto fail2;
-		}
-		gpio_direction_input(udc->board.vbus_pin);
 
-		/*
-		 * Get the initial state of VBUS - we cannot expect
-		 * a pending interrupt.
-		 */
-		udc->vbus = gpio_get_value_cansleep(udc->board.vbus_pin) ^
-			udc->board.vbus_active_low;
-
-		if (udc->board.vbus_polled) {
-			INIT_WORK(&udc->vbus_timer_work, at91_vbus_timer_work);
-			setup_timer(&udc->vbus_timer, at91_vbus_timer,
-				    (unsigned long)udc);
-			mod_timer(&udc->vbus_timer,
-				  jiffies + VBUS_POLL_TIMEOUT);
-		} else {
-			if (request_irq(gpio_to_irq(udc->board.vbus_pin),
-					at91_vbus_irq, 0, driver_name, udc)) {
-				DBG("request vbus irq %d failed\n",
-				    udc->board.vbus_pin);
-				retval = -EBUSY;
-				goto fail3;
-			}
-		}
-	} else {
+	if (udc->board.vbus_pin)
+		printf("%s: gpio vbus pin not supported yet.\n", __func__);
+	else
 		DBG("no VBUS detection, assuming always-on\n");
-		udc->vbus = 1;
-	}
-	retval = usb_add_gadget_udc(dev, &udc->gadget);
-	if (retval)
-		goto fail4;
-	dev_set_drvdata(dev, udc);
-	device_init_wakeup(dev, 1);
-	create_debug_file(udc);
-
-	INFO("%s version %s\n", driver_name, DRIVER_VERSION);
-	return 0;
-fail4:
-	if (gpio_is_valid(udc->board.vbus_pin) && !udc->board.vbus_polled)
-		free_irq(gpio_to_irq(udc->board.vbus_pin), udc);
-fail3:
-	if (gpio_is_valid(udc->board.vbus_pin))
-		gpio_free(udc->board.vbus_pin);
-fail2:
-	free_irq(udc->udp_irq, udc);
-fail1c:
-	clk_unprepare(udc->iclk);
-fail1b:
-	clk_unprepare(udc->fclk);
-fail1a:
-	if (IS_ENABLED(CONFIG_COMMON_CLK))
-		clk_unprepare(udc->uclk);
-fail1:
-	if (IS_ENABLED(CONFIG_COMMON_CLK) && !IS_ERR(udc->uclk))
-		clk_put(udc->uclk);
-	if (!IS_ERR(udc->fclk))
-		clk_put(udc->fclk);
-	if (!IS_ERR(udc->iclk))
-		clk_put(udc->iclk);
-	iounmap(udc->udp_baseaddr);
-fail0a:
-	if (cpu_is_at91rm9200())
-		gpio_free(udc->board.pullup_pin);
-fail0:
-	release_mem_region(res->start, resource_size(res));
-	DBG("%s probe failed, %d\n", driver_name, retval);
-	return retval;
-}
-
-static int __exit at91udc_remove(struct platform_device *pdev)
-{
-	struct at91_udc *udc = platform_get_drvdata(pdev);
-	struct resource *res;
-	unsigned long	flags;
-
-	DBG("remove\n");
-
-	usb_del_gadget_udc(&udc->gadget);
-	if (udc->driver)
-		return -EBUSY;
-
-	spin_lock_irqsave(&udc->lock, flags);
-	pullup(udc, 0);
-	spin_unlock_irqrestore(&udc->lock, flags);
-
-	device_init_wakeup(&pdev->dev, 0);
-	remove_debug_file(udc);
-	if (gpio_is_valid(udc->board.vbus_pin)) {
-		free_irq(gpio_to_irq(udc->board.vbus_pin), udc);
-		gpio_free(udc->board.vbus_pin);
-	}
-	free_irq(udc->udp_irq, udc);
-	iounmap(udc->udp_baseaddr);
 
-	if (cpu_is_at91rm9200())
-		gpio_free(udc->board.pullup_pin);
+	udc->vbus = 1;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	release_mem_region(res->start, resource_size(res));
-
-	if (IS_ENABLED(CONFIG_COMMON_CLK))
-		clk_unprepare(udc->uclk);
-	clk_unprepare(udc->fclk);
-	clk_unprepare(udc->iclk);
-
-	clk_put(udc->iclk);
-	clk_put(udc->fclk);
-	if (IS_ENABLED(CONFIG_COMMON_CLK))
-		clk_put(udc->uclk);
-
-	return 0;
-}
-
-#ifdef CONFIG_PM
-static int at91udc_suspend(struct platform_device *pdev, pm_message_t mesg)
-{
-	struct at91_udc *udc = platform_get_drvdata(pdev);
-	int		wake = udc->driver && device_may_wakeup(&pdev->dev);
-	unsigned long	flags;
-
-	/* Unless we can act normally to the host (letting it wake us up
-	 * whenever it has work for us) force disconnect.  Wakeup requires
-	 * PLLB for USB events (signaling for reset, wakeup, or incoming
-	 * tokens) and VBUS irqs (on systems which support them).
-	 */
-	if ((!udc->suspended && udc->addr)
-			|| !wake
-			|| at91_suspend_entering_slow_clock()) {
-		spin_lock_irqsave(&udc->lock, flags);
-		pullup(udc, 0);
-		wake = 0;
-		spin_unlock_irqrestore(&udc->lock, flags);
-	} else
-		enable_irq_wake(udc->udp_irq);
-
-	udc->active_suspend = wake;
-	if (gpio_is_valid(udc->board.vbus_pin) && !udc->board.vbus_polled && wake)
-		enable_irq_wake(udc->board.vbus_pin);
-	return 0;
-}
-
-static int at91udc_resume(struct platform_device *pdev)
-{
-	struct at91_udc *udc = platform_get_drvdata(pdev);
-	unsigned long	flags;
-
-	if (gpio_is_valid(udc->board.vbus_pin) && !udc->board.vbus_polled &&
-	    udc->active_suspend)
-		disable_irq_wake(udc->board.vbus_pin);
+	INFO("%s version %s\n", driver_name, DRIVER_VERSION);
 
-	/* maybe reconnect to host; if so, clocks on */
-	if (udc->active_suspend)
-		disable_irq_wake(udc->udp_irq);
-	else {
-		spin_lock_irqsave(&udc->lock, flags);
-		pullup(udc, 1);
-		spin_unlock_irqrestore(&udc->lock, flags);
-	}
 	return 0;
 }
-#else
-#define	at91udc_suspend	NULL
-#define	at91udc_resume	NULL
-#endif
-
-#if defined(CONFIG_OF)
-static const struct of_device_id at91_udc_dt_ids[] = {
-	{ .compatible = "atmel,at91rm9200-udc" },
-	{ /* sentinel */ }
-};
-
-MODULE_DEVICE_TABLE(of, at91_udc_dt_ids);
-#endif
-
-static struct platform_driver at91_udc_driver = {
-	.remove		= __exit_p(at91udc_remove),
-	.shutdown	= at91udc_shutdown,
-	.suspend	= at91udc_suspend,
-	.resume		= at91udc_resume,
-	.driver		= {
-		.name	= (char *) driver_name,
-		.owner	= THIS_MODULE,
-		.of_match_table	= of_match_ptr(at91_udc_dt_ids),
-	},
-};
-
-module_platform_driver_probe(at91_udc_driver, at91udc_probe);
-
-MODULE_DESCRIPTION("AT91 udc driver");
-MODULE_AUTHOR("Thomas Rathbone, David Brownell");
-MODULE_LICENSE("GPL");
-MODULE_ALIAS("platform:at91_udc");
diff --git a/drivers/usb/gadget/at91_udc.h b/drivers/usb/gadget/at91_udc.h
index 0175246..2d947d4 100644
--- a/drivers/usb/gadget/at91_udc.h
+++ b/drivers/usb/gadget/at91_udc.h
@@ -1,12 +1,12 @@
 /*
+ * from linux:
+ * b2ba27a5c56ff: usb: gadget: at91_udc: move prepare clk into process context
+ *
  * Copyright (C) 2004 by Thomas Rathbone, HP Labs
  * Copyright (C) 2005 by Ivan Kokshaysky
  * Copyright (C) 2006 by SAN People
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * SPDX-License-Identifier:	GPL-2.0+
  */
 
 #ifndef AT91_UDC_H
@@ -126,9 +126,6 @@ struct at91_udc {
 	unsigned			active_suspend:1;
 	u8				addr;
 	struct at91_udc_data		board;
-	struct clk			*iclk, *fclk, *uclk;
-	struct platform_device		*pdev;
-	struct proc_dir_entry		*pde;
 	void __iomem			*udp_baseaddr;
 	int				udp_irq;
 	spinlock_t			lock;
@@ -160,10 +157,10 @@ struct at91_request {
 #    define PACKET(stuff...)	do{}while(0)
 #endif
 
-#define ERR(stuff...)		pr_err("udc: " stuff)
-#define WARNING(stuff...)	pr_warning("udc: " stuff)
-#define INFO(stuff...)		pr_info("udc: " stuff)
-#define DBG(stuff...)		pr_debug("udc: " stuff)
+#define ERR(stuff...)		debug("udc: " stuff)
+#define WARNING(stuff...)	debug("udc: " stuff)
+#define INFO(stuff...)		debug("udc: " stuff)
+#define DBG(stuff...)		debug("udc: " stuff)
 
 #endif
 
diff --git a/include/linux/usb/at91_udc.h b/include/linux/usb/at91_udc.h
index ba99af2..eb88e1d 100644
--- a/include/linux/usb/at91_udc.h
+++ b/include/linux/usb/at91_udc.h
@@ -1,23 +1,20 @@
 /*
- * Platform data definitions for Atmel USBA gadget driver.
+ * Platform data definitions for Atmel USBA gadget driver
+ * [Original from Linux kernel: include/linux/usb/atmel_usba_udc.h]
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
  */
-#ifndef __LINUX_USB_USBA_H
-#define __LINUX_USB_USBA_H
+#ifndef __LINUX_USB_AT91_UDC_H__
+#define __LINUX_USB_AT91_UDC_H__
 
-struct usba_ep_data {
-	char	*name;
-	int	index;
-	int	fifo_size;
-	int	nr_banks;
-	int	can_dma;
-	int	can_isoc;
+struct at91_udc_data {
+	int	vbus_pin;		/* high == host powering us */
+	u8	vbus_active_low;	/* vbus polarity */
+	u8	vbus_polled;		/* Use polling, not interrupt */
+	int	pullup_pin;		/* active == D+ pulled up */
+	u8	pullup_active_low;	/* true == pullup_pin is active low */
+	unsigned long	baseaddr;
 };
 
-struct usba_platform_data {
-	int			vbus_pin;
-	int			vbus_pin_inverted;
-	int			num_ep;
-	struct usba_ep_data	ep[0];
-};
-
-#endif /* __LINUX_USB_USBA_H */
+extern int at91_udc_probe(struct at91_udc_data *pdata);
+#endif
-- 
2.1.0



More information about the U-Boot mailing list