linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/11] usb: gadget: at91_udc: Rework for multi-platform support
@ 2014-12-03 11:31 Boris Brezillon
  2014-12-03 11:32 ` [PATCH 01/11] usb: gadget: at91_udc: Fix clock names Boris Brezillon
                   ` (10 more replies)
  0 siblings, 11 replies; 17+ messages in thread
From: Boris Brezillon @ 2014-12-03 11:31 UTC (permalink / raw)
  To: Nicolas Ferre, Jean-Christophe Plagniol-Villard,
	Alexandre Belloni, Andrew Victor, Felipe Balbi,
	Greg Kroah-Hartman, linux-usb
  Cc: Arnd Bergmann, linux-arm-kernel, linux-kernel, Rob Herring,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, devicetree,
	Boris Brezillon

Hello,

This series reworks the at91_udc driver to prepare at91 for multi-platform
support.

It also include several fixes:
 - fix clock names to be consistent with other USB drivers
 - document clocks and clock-names properties in atmel-usb DT bindings doc

and some cleanup changes:
 - remove useless usb_clk
 - allocate at91_udc instance instead of using the statically defined one
 - simplify the probe and remove functions by using devm_ helpers
 - remove !DT specific code

The series depends on this patch [1] (which adds matrix registers definition).

Regards,

Boris

[1]https://lkml.org/lkml/2014/12/3/230

Boris Brezillon (11):
  usb: gadget: at91_udc: Fix clock names
  usb: gadget: at91_udc: Drop uclk clock
  usb: gadget: at91_udc: Document DT clocks and clock-names property
  ARM: at91/dt: at91sam9261: fix clocks and clock-names in udc
    definition
  usb: gadget: at91_udc: Remove non-DT handling code
  usb: gadget: at91_udc: Simplify probe and remove functions
  usb: gadget: at91_udc: Rework for multi-platform kernel support
  usb: gadget: at91_udc: Update DT binding documentation
  usb: gadget: at91_udc: Allocate udc instance
  ARM: at91/dt: declare matrix node as a syscon device
  ARM: at91/dt: fix at91 udc compatible strings

 .../devicetree/bindings/usb/atmel-usb.txt          |  10 +-
 arch/arm/boot/dts/at91sam9260.dtsi                 |   2 +-
 arch/arm/boot/dts/at91sam9261.dtsi                 |   9 +-
 arch/arm/boot/dts/at91sam9263.dtsi                 |   2 +-
 drivers/usb/gadget/udc/Kconfig                     |   1 +
 drivers/usb/gadget/udc/at91_udc.c                  | 530 +++++++++++----------
 drivers/usb/gadget/udc/at91_udc.h                  |   9 +-
 7 files changed, 298 insertions(+), 265 deletions(-)

-- 
1.9.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 01/11] usb: gadget: at91_udc: Fix clock names
  2014-12-03 11:31 [PATCH 00/11] usb: gadget: at91_udc: Rework for multi-platform support Boris Brezillon
@ 2014-12-03 11:32 ` Boris Brezillon
  2014-12-03 11:32 ` [PATCH 02/11] usb: gadget: at91_udc: Drop uclk clock Boris Brezillon
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Boris Brezillon @ 2014-12-03 11:32 UTC (permalink / raw)
  To: Nicolas Ferre, Jean-Christophe Plagniol-Villard,
	Alexandre Belloni, Andrew Victor, Felipe Balbi,
	Greg Kroah-Hartman, linux-usb
  Cc: Arnd Bergmann, linux-arm-kernel, linux-kernel, Rob Herring,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, devicetree,
	Boris Brezillon

The driver is requesting clock by their global name (those declared in the
clk_lookup list), but this only works with !CCF kernels.

Now that all SoCs have moved to CCF, fix the driver to use local names
(hclk and pclk).

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
 drivers/usb/gadget/udc/at91_udc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/at91_udc.c b/drivers/usb/gadget/udc/at91_udc.c
index 0716c19..ca6a4b8 100644
--- a/drivers/usb/gadget/udc/at91_udc.c
+++ b/drivers/usb/gadget/udc/at91_udc.c
@@ -1766,8 +1766,8 @@ static int at91udc_probe(struct platform_device *pdev)
 	udc_reinit(udc);
 
 	/* get interface and function clocks */
-	udc->iclk = clk_get(dev, "udc_clk");
-	udc->fclk = clk_get(dev, "udpck");
+	udc->iclk = clk_get(dev, "pclk");
+	udc->fclk = clk_get(dev, "hclk");
 	if (IS_ENABLED(CONFIG_COMMON_CLK))
 		udc->uclk = clk_get(dev, "usb_clk");
 	if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk) ||
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 02/11] usb: gadget: at91_udc: Drop uclk clock
  2014-12-03 11:31 [PATCH 00/11] usb: gadget: at91_udc: Rework for multi-platform support Boris Brezillon
  2014-12-03 11:32 ` [PATCH 01/11] usb: gadget: at91_udc: Fix clock names Boris Brezillon
@ 2014-12-03 11:32 ` Boris Brezillon
  2014-12-03 11:32 ` [PATCH 03/11] usb: gadget: at91_udc: Document DT clocks and clock-names property Boris Brezillon
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Boris Brezillon @ 2014-12-03 11:32 UTC (permalink / raw)
  To: Nicolas Ferre, Jean-Christophe Plagniol-Villard,
	Alexandre Belloni, Andrew Victor, Felipe Balbi,
	Greg Kroah-Hartman, linux-usb
  Cc: Arnd Bergmann, linux-arm-kernel, linux-kernel, Rob Herring,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, devicetree,
	Boris Brezillon

Now that at91 system clocks forward set_rate request to their parent we
can remove the uclk clock and directly call clk_set_rate on fclk.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
 drivers/usb/gadget/udc/at91_udc.c | 27 +++------------------------
 drivers/usb/gadget/udc/at91_udc.h |  2 +-
 2 files changed, 4 insertions(+), 25 deletions(-)

diff --git a/drivers/usb/gadget/udc/at91_udc.c b/drivers/usb/gadget/udc/at91_udc.c
index ca6a4b8..4ecb576 100644
--- a/drivers/usb/gadget/udc/at91_udc.c
+++ b/drivers/usb/gadget/udc/at91_udc.c
@@ -870,8 +870,6 @@ static void clk_on(struct at91_udc *udc)
 		return;
 	udc->clocked = 1;
 
-	if (IS_ENABLED(CONFIG_COMMON_CLK))
-		clk_enable(udc->uclk);
 	clk_enable(udc->iclk);
 	clk_enable(udc->fclk);
 }
@@ -884,8 +882,6 @@ static void clk_off(struct at91_udc *udc)
 	udc->gadget.speed = USB_SPEED_UNKNOWN;
 	clk_disable(udc->fclk);
 	clk_disable(udc->iclk);
-	if (IS_ENABLED(CONFIG_COMMON_CLK))
-		clk_disable(udc->uclk);
 }
 
 /*
@@ -1768,25 +1764,17 @@ static int at91udc_probe(struct platform_device *pdev)
 	/* get interface and function clocks */
 	udc->iclk = clk_get(dev, "pclk");
 	udc->fclk = clk_get(dev, "hclk");
-	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))) {
+	if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk)) {
 		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;
-	}
+	clk_set_rate(udc->fclk, 48000000);
 	retval = clk_prepare(udc->fclk);
 	if (retval)
-		goto fail1a;
+		goto fail1;
 
 	retval = clk_prepare_enable(udc->iclk);
 	if (retval)
@@ -1860,12 +1848,7 @@ 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))
@@ -1911,15 +1894,11 @@ static int __exit at91udc_remove(struct platform_device *pdev)
 	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;
 }
diff --git a/drivers/usb/gadget/udc/at91_udc.h b/drivers/usb/gadget/udc/at91_udc.h
index 0175246..e647d1c 100644
--- a/drivers/usb/gadget/udc/at91_udc.h
+++ b/drivers/usb/gadget/udc/at91_udc.h
@@ -126,7 +126,7 @@ struct at91_udc {
 	unsigned			active_suspend:1;
 	u8				addr;
 	struct at91_udc_data		board;
-	struct clk			*iclk, *fclk, *uclk;
+	struct clk			*iclk, *fclk;
 	struct platform_device		*pdev;
 	struct proc_dir_entry		*pde;
 	void __iomem			*udp_baseaddr;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 03/11] usb: gadget: at91_udc: Document DT clocks and clock-names property
  2014-12-03 11:31 [PATCH 00/11] usb: gadget: at91_udc: Rework for multi-platform support Boris Brezillon
  2014-12-03 11:32 ` [PATCH 01/11] usb: gadget: at91_udc: Fix clock names Boris Brezillon
  2014-12-03 11:32 ` [PATCH 02/11] usb: gadget: at91_udc: Drop uclk clock Boris Brezillon
@ 2014-12-03 11:32 ` Boris Brezillon
  2014-12-03 11:32 ` [PATCH 04/11] ARM: at91/dt: at91sam9261: fix clocks and clock-names in udc definition Boris Brezillon
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Boris Brezillon @ 2014-12-03 11:32 UTC (permalink / raw)
  To: Nicolas Ferre, Jean-Christophe Plagniol-Villard,
	Alexandre Belloni, Andrew Victor, Felipe Balbi,
	Greg Kroah-Hartman, linux-usb
  Cc: Arnd Bergmann, linux-arm-kernel, linux-kernel, Rob Herring,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, devicetree,
	Boris Brezillon

The at91_udc driver request 2 clocks, and thus need them to be defined in
the device tree.
Document the clocks and clock-names properties so that everybody use the
correct names.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
 Documentation/devicetree/bindings/usb/atmel-usb.txt | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/atmel-usb.txt b/Documentation/devicetree/bindings/usb/atmel-usb.txt
index bc2222c..6007231 100644
--- a/Documentation/devicetree/bindings/usb/atmel-usb.txt
+++ b/Documentation/devicetree/bindings/usb/atmel-usb.txt
@@ -36,6 +36,10 @@ Required properties:
  - compatible: Should be "atmel,at91rm9200-udc"
  - reg: Address and length of the register set for the device
  - interrupts: Should contain macb interrupt
+ - clocks: Should reference the peripheral and the AHB clocks
+ - clock-names: Should contains two strings
+		"pclk" for the peripheral clock
+		"hclk" for the AHB clock
 
 Optional properties:
  - atmel,vbus-gpio: If present, specifies a gpio that needs to be
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 04/11] ARM: at91/dt: at91sam9261: fix clocks and clock-names in udc definition
  2014-12-03 11:31 [PATCH 00/11] usb: gadget: at91_udc: Rework for multi-platform support Boris Brezillon
                   ` (2 preceding siblings ...)
  2014-12-03 11:32 ` [PATCH 03/11] usb: gadget: at91_udc: Document DT clocks and clock-names property Boris Brezillon
@ 2014-12-03 11:32 ` Boris Brezillon
  2014-12-03 11:32 ` [PATCH 05/11] usb: gadget: at91_udc: Remove non-DT handling code Boris Brezillon
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Boris Brezillon @ 2014-12-03 11:32 UTC (permalink / raw)
  To: Nicolas Ferre, Jean-Christophe Plagniol-Villard,
	Alexandre Belloni, Andrew Victor, Felipe Balbi,
	Greg Kroah-Hartman, linux-usb
  Cc: Arnd Bergmann, linux-arm-kernel, linux-kernel, Rob Herring,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, devicetree,
	Boris Brezillon

Peripheral clock is named pclk and system clock is named hclk (those are
the names expected by the at91_udc driver).

Drop the deprecated usb_clk (formerly used to configure the usb clock rate
which is now directly configurable through hclk).

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
 arch/arm/boot/dts/at91sam9261.dtsi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boot/dts/at91sam9261.dtsi b/arch/arm/boot/dts/at91sam9261.dtsi
index a81aab4..7119f1f 100644
--- a/arch/arm/boot/dts/at91sam9261.dtsi
+++ b/arch/arm/boot/dts/at91sam9261.dtsi
@@ -122,8 +122,8 @@
 				compatible = "atmel,at91rm9200-udc";
 				reg = <0xfffa4000 0x4000>;
 				interrupts = <10 IRQ_TYPE_LEVEL_HIGH 2>;
-				clocks = <&usb>, <&udc_clk>, <&udpck>;
-				clock-names = "usb_clk", "udc_clk", "udpck";
+				clocks = <&udc_clk>, <&udpck>;
+				clock-names = "pclk", "hclk";
 				status = "disabled";
 			};
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 05/11] usb: gadget: at91_udc: Remove non-DT handling code
  2014-12-03 11:31 [PATCH 00/11] usb: gadget: at91_udc: Rework for multi-platform support Boris Brezillon
                   ` (3 preceding siblings ...)
  2014-12-03 11:32 ` [PATCH 04/11] ARM: at91/dt: at91sam9261: fix clocks and clock-names in udc definition Boris Brezillon
@ 2014-12-03 11:32 ` Boris Brezillon
  2015-01-12 21:39   ` Felipe Balbi
  2014-12-03 11:32 ` [PATCH 06/11] usb: gadget: at91_udc: Simplify probe and remove functions Boris Brezillon
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 17+ messages in thread
From: Boris Brezillon @ 2014-12-03 11:32 UTC (permalink / raw)
  To: Nicolas Ferre, Jean-Christophe Plagniol-Villard,
	Alexandre Belloni, Andrew Victor, Felipe Balbi,
	Greg Kroah-Hartman, linux-usb
  Cc: Arnd Bergmann, linux-arm-kernel, linux-kernel, Rob Herring,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, devicetree,
	Boris Brezillon

Since non-DT board support has been removed from the at91 architecture we
can safely remove non-DT handling code.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
 drivers/usb/gadget/udc/Kconfig    |  1 +
 drivers/usb/gadget/udc/at91_udc.c | 16 ++--------------
 2 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 217365d..36a598d 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -32,6 +32,7 @@ menu "USB Peripheral Controller"
 config USB_AT91
 	tristate "Atmel AT91 USB Device Port"
 	depends on ARCH_AT91
+	depends on OF || COMPILE_TEST
 	help
 	   Many Atmel AT91 processors (such as the AT91RM2000) have a
 	   full speed USB Device Port with support for five configurable
diff --git a/drivers/usb/gadget/udc/at91_udc.c b/drivers/usb/gadget/udc/at91_udc.c
index 4ecb576..e7984c0 100644
--- a/drivers/usb/gadget/udc/at91_udc.c
+++ b/drivers/usb/gadget/udc/at91_udc.c
@@ -1697,12 +1697,6 @@ static int at91udc_probe(struct platform_device *pdev)
 	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;
-	}
-
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!res)
 		return -ENXIO;
@@ -1715,11 +1709,7 @@ static int at91udc_probe(struct platform_device *pdev)
 	/* 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));
+	at91udc_of_init(udc, pdev->dev.of_node);
 	udc->pdev = pdev;
 	udc->enabled = 0;
 	spin_lock_init(&udc->lock);
@@ -1955,14 +1945,12 @@ static int at91udc_resume(struct platform_device *pdev)
 #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),
@@ -1972,7 +1960,7 @@ static struct platform_driver at91_udc_driver = {
 	.driver		= {
 		.name	= (char *) driver_name,
 		.owner	= THIS_MODULE,
-		.of_match_table	= of_match_ptr(at91_udc_dt_ids),
+		.of_match_table	= at91_udc_dt_ids,
 	},
 };
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 06/11] usb: gadget: at91_udc: Simplify probe and remove functions
  2014-12-03 11:31 [PATCH 00/11] usb: gadget: at91_udc: Rework for multi-platform support Boris Brezillon
                   ` (4 preceding siblings ...)
  2014-12-03 11:32 ` [PATCH 05/11] usb: gadget: at91_udc: Remove non-DT handling code Boris Brezillon
@ 2014-12-03 11:32 ` Boris Brezillon
  2014-12-03 11:32 ` [PATCH 07/11] usb: gadget: at91_udc: Rework for multi-platform kernel support Boris Brezillon
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Boris Brezillon @ 2014-12-03 11:32 UTC (permalink / raw)
  To: Nicolas Ferre, Jean-Christophe Plagniol-Villard,
	Alexandre Belloni, Andrew Victor, Felipe Balbi,
	Greg Kroah-Hartman, linux-usb
  Cc: Arnd Bergmann, linux-arm-kernel, linux-kernel, Rob Herring,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, devicetree,
	Boris Brezillon

Make use of devm_ functions to simplify probe and remove code.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
 drivers/usb/gadget/udc/at91_udc.c | 116 +++++++++++++-------------------------
 1 file changed, 39 insertions(+), 77 deletions(-)

diff --git a/drivers/usb/gadget/udc/at91_udc.c b/drivers/usb/gadget/udc/at91_udc.c
index e7984c0..ef1ee07 100644
--- a/drivers/usb/gadget/udc/at91_udc.c
+++ b/drivers/usb/gadget/udc/at91_udc.c
@@ -1697,15 +1697,6 @@ static int at91udc_probe(struct platform_device *pdev)
 	int		retval;
 	struct resource	*res;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -ENXIO;
-
-	if (!request_mem_region(res->start, resource_size(res), driver_name)) {
-		DBG("someone's using UDC memory\n");
-		return -EBUSY;
-	}
-
 	/* init software state */
 	udc = &controller;
 	udc->gadget.dev.parent = dev;
@@ -1718,13 +1709,13 @@ static int at91udc_probe(struct platform_device *pdev)
 	if (cpu_is_at91rm9200()) {
 		if (!gpio_is_valid(udc->board.pullup_pin)) {
 			DBG("no D+ pullup?\n");
-			retval = -ENODEV;
-			goto fail0;
+			return -ENODEV;
 		}
-		retval = gpio_request(udc->board.pullup_pin, "udc_pullup");
+		retval = devm_gpio_request(dev, 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);
@@ -1743,32 +1734,32 @@ 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;
-	}
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	udc->udp_baseaddr = devm_ioremap_resource(dev, res);
+	if (IS_ERR(udc->udp_baseaddr))
+		return PTR_ERR(udc->udp_baseaddr);
 
 	udc_reinit(udc);
 
 	/* get interface and function clocks */
-	udc->iclk = clk_get(dev, "pclk");
-	udc->fclk = clk_get(dev, "hclk");
-	if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk)) {
-		DBG("clocks missing\n");
-		retval = -ENODEV;
-		goto fail1;
-	}
+	udc->iclk = devm_clk_get(dev, "pclk");
+	if (IS_ERR(udc->iclk))
+		return PTR_ERR(udc->iclk);
+
+	udc->fclk = devm_clk_get(dev, "hclk");
+	if (IS_ERR(udc->fclk))
+		return PTR_ERR(udc->fclk);
 
 	/* don't do anything until we have both gadget driver and VBUS */
 	clk_set_rate(udc->fclk, 48000000);
 	retval = clk_prepare(udc->fclk);
 	if (retval)
-		goto fail1;
+		return retval;
 
 	retval = clk_prepare_enable(udc->iclk);
 	if (retval)
-		goto fail1b;
+		goto err_unprepare_fclk;
+
 	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. */
@@ -1777,18 +1768,21 @@ static int at91udc_probe(struct platform_device *pdev)
 
 	/* 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) {
+	retval = devm_request_irq(dev, udc->udp_irq, at91_udc_irq, 0,
+				  driver_name, udc);
+	if (retval) {
 		DBG("request irq %d failed\n", udc->udp_irq);
-		goto fail1c;
+		goto err_unprepare_iclk;
 	}
+
 	if (gpio_is_valid(udc->board.vbus_pin)) {
-		retval = gpio_request(udc->board.vbus_pin, "udc_vbus");
-		if (retval < 0) {
+		retval = devm_gpio_request(dev, udc->board.vbus_pin,
+					   "udc_vbus");
+		if (retval) {
 			DBG("request vbus pin failed\n");
-			goto fail2;
+			goto err_unprepare_iclk;
 		}
+
 		gpio_direction_input(udc->board.vbus_pin);
 
 		/*
@@ -1805,12 +1799,13 @@ static int at91udc_probe(struct platform_device *pdev)
 			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)) {
+			retval = devm_request_irq(dev,
+					gpio_to_irq(udc->board.vbus_pin),
+					at91_vbus_irq, 0, driver_name, udc);
+			if (retval) {
 				DBG("request vbus irq %d failed\n",
 				    udc->board.vbus_pin);
-				retval = -EBUSY;
-				goto fail3;
+				goto err_unprepare_iclk;
 			}
 		}
 	} else {
@@ -1819,44 +1814,27 @@ static int at91udc_probe(struct platform_device *pdev)
 	}
 	retval = usb_add_gadget_udc(dev, &udc->gadget);
 	if (retval)
-		goto fail4;
+		goto err_unprepare_iclk;
 	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:
+
+err_unprepare_iclk:
 	clk_unprepare(udc->iclk);
-fail1b:
+err_unprepare_fclk:
 	clk_unprepare(udc->fclk);
-fail1:
-	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");
@@ -1871,25 +1849,9 @@ static int __exit at91udc_remove(struct platform_device *pdev)
 
 	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);
-
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	release_mem_region(res->start, resource_size(res));
-
 	clk_unprepare(udc->fclk);
 	clk_unprepare(udc->iclk);
 
-	clk_put(udc->iclk);
-	clk_put(udc->fclk);
-
 	return 0;
 }
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 07/11] usb: gadget: at91_udc: Rework for multi-platform kernel support
  2014-12-03 11:31 [PATCH 00/11] usb: gadget: at91_udc: Rework for multi-platform support Boris Brezillon
                   ` (5 preceding siblings ...)
  2014-12-03 11:32 ` [PATCH 06/11] usb: gadget: at91_udc: Simplify probe and remove functions Boris Brezillon
@ 2014-12-03 11:32 ` Boris Brezillon
  2014-12-03 11:32 ` [PATCH 08/11] usb: gadget: at91_udc: Update DT binding documentation Boris Brezillon
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Boris Brezillon @ 2014-12-03 11:32 UTC (permalink / raw)
  To: Nicolas Ferre, Jean-Christophe Plagniol-Villard,
	Alexandre Belloni, Andrew Victor, Felipe Balbi,
	Greg Kroah-Hartman, linux-usb
  Cc: Arnd Bergmann, linux-arm-kernel, linux-kernel, Rob Herring,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, devicetree,
	Boris Brezillon

cpu_is_at91xxx are a set of macros defined in mach/cpu.h and are here used
to detect the SoC we are booting on.
Use compatible string + a caps structure to replace those cpu_is_xxx tests.

Remove all mach and asm headers (which are now unused).

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
 drivers/usb/gadget/udc/at91_udc.c | 288 ++++++++++++++++++++++++++++----------
 drivers/usb/gadget/udc/at91_udc.h |   7 +
 2 files changed, 218 insertions(+), 77 deletions(-)

diff --git a/drivers/usb/gadget/udc/at91_udc.c b/drivers/usb/gadget/udc/at91_udc.c
index ef1ee07..f870c03 100644
--- a/drivers/usb/gadget/udc/at91_udc.c
+++ b/drivers/usb/gadget/udc/at91_udc.c
@@ -31,16 +31,9 @@
 #include <linux/of.h>
 #include <linux/of_gpio.h>
 #include <linux/platform_data/atmel.h>
-
-#include <asm/byteorder.h>
-#include <mach/hardware.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 <linux/regmap.h>
+#include <linux/mfd/syscon.h>
+#include <linux/mfd/syscon/atmel-matrix.h>
 
 #include "at91_udc.h"
 
@@ -890,8 +883,6 @@ static void clk_off(struct at91_udc *udc)
  */
 static void pullup(struct at91_udc *udc, int is_on)
 {
-	int	active = !udc->board.pullup_active_low;
-
 	if (!udc->enabled || !udc->vbus)
 		is_on = 0;
 	DBG("%sactive\n", is_on ? "" : "in");
@@ -900,40 +891,15 @@ static void pullup(struct at91_udc *udc, int is_on)
 		clk_on(udc);
 		at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_RXRSM);
 		at91_udp_write(udc, AT91_UDP_TXVC, 0);
-		if (cpu_is_at91rm9200())
-			gpio_set_value(udc->board.pullup_pin, active);
-		else if (cpu_is_at91sam9260() || cpu_is_at91sam9263() || cpu_is_at91sam9g20()) {
-			u32	txvc = at91_udp_read(udc, AT91_UDP_TXVC);
-
-			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);
-		}
 	} else {
 		stop_activity(udc);
 		at91_udp_write(udc, AT91_UDP_IDR, AT91_UDP_RXRSM);
 		at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
-		if (cpu_is_at91rm9200())
-			gpio_set_value(udc->board.pullup_pin, !active);
-		else if (cpu_is_at91sam9260() || cpu_is_at91sam9263() || cpu_is_at91sam9g20()) {
-			u32	txvc = at91_udp_read(udc, AT91_UDP_TXVC);
-
-			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);
-		}
 		clk_off(udc);
 	}
+
+	if (udc->caps && udc->caps->pullup)
+		udc->caps->pullup(udc, is_on);
 }
 
 /* vbus is here!  turn everything on that's ready */
@@ -1670,12 +1636,202 @@ static void at91udc_shutdown(struct platform_device *dev)
 	spin_unlock_irqrestore(&udc->lock, flags);
 }
 
-static void at91udc_of_init(struct at91_udc *udc,
-				     struct device_node *np)
+static int at91rm9200_udc_init(struct at91_udc *udc)
+{
+	struct at91_ep *ep;
+	int ret;
+	int i;
+
+	for (i = 0; i < NUM_ENDPOINTS; i++) {
+		ep = &udc->ep[i];
+
+		switch (i) {
+		case 0:
+		case 3:
+			ep->maxpacket = 8;
+			break;
+		case 1 ... 2:
+			ep->maxpacket = 64;
+			break;
+		case 4 ... 5:
+			ep->maxpacket = 256;
+			break;
+		}
+	}
+
+	if (!gpio_is_valid(udc->board.pullup_pin)) {
+		DBG("no D+ pullup?\n");
+		return -ENODEV;
+	}
+
+	ret = devm_gpio_request(&udc->pdev->dev, udc->board.pullup_pin,
+				"udc_pullup");
+	if (ret) {
+		DBG("D+ pullup is busy\n");
+		return ret;
+	}
+
+	gpio_direction_output(udc->board.pullup_pin,
+			      udc->board.pullup_active_low);
+
+	return 0;
+}
+
+static void at91rm9200_udc_pullup(struct at91_udc *udc, int is_on)
+{
+	int active = !udc->board.pullup_active_low;
+
+	if (is_on)
+		gpio_set_value(udc->board.pullup_pin, active);
+	else
+		gpio_set_value(udc->board.pullup_pin, !active);
+}
+
+static const struct at91_udc_caps at91rm9200_udc_caps = {
+	.init = at91rm9200_udc_init,
+	.pullup = at91rm9200_udc_pullup,
+};
+
+static int at91sam9260_udc_init(struct at91_udc *udc)
+{
+	struct at91_ep *ep;
+	int i;
+
+	for (i = 0; i < NUM_ENDPOINTS; i++) {
+		ep = &udc->ep[i];
+
+		switch (i) {
+		case 0 ... 3:
+			ep->maxpacket = 64;
+			break;
+		case 4 ... 5:
+			ep->maxpacket = 512;
+			break;
+		}
+	}
+
+	return 0;
+}
+
+static void at91sam9260_udc_pullup(struct at91_udc *udc, int is_on)
+{
+	u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC);
+
+	if (is_on)
+		txvc |= AT91_UDP_TXVC_PUON;
+	else
+		txvc &= ~AT91_UDP_TXVC_PUON;
+
+	at91_udp_write(udc, AT91_UDP_TXVC, txvc);
+}
+
+static const struct at91_udc_caps at91sam9260_udc_caps = {
+	.init = at91sam9260_udc_init,
+	.pullup = at91sam9260_udc_pullup,
+};
+
+static int at91sam9261_udc_init(struct at91_udc *udc)
+{
+	struct at91_ep *ep;
+	int i;
+
+	for (i = 0; i < NUM_ENDPOINTS; i++) {
+		ep = &udc->ep[i];
+
+		switch (i) {
+		case 0:
+			ep->maxpacket = 8;
+			break;
+		case 1 ... 3:
+			ep->maxpacket = 64;
+			break;
+		case 4 ... 5:
+			ep->maxpacket = 256;
+			break;
+		}
+	}
+
+	udc->matrix = syscon_regmap_lookup_by_phandle(udc->pdev->dev.of_node,
+						      "atmel,matrix");
+	if (IS_ERR(udc->matrix))
+		return PTR_ERR(udc->matrix);
+
+	return 0;
+}
+
+static void at91sam9261_udc_pullup(struct at91_udc *udc, int is_on)
+{
+	u32 usbpucr = 0;
+
+	if (is_on)
+		usbpucr = AT91_MATRIX_USBPUCR_PUON;
+
+	regmap_update_bits(udc->matrix, AT91SAM9261_MATRIX_USBPUCR_OFF,
+			   AT91_MATRIX_USBPUCR_PUON, usbpucr);
+}
+
+static const struct at91_udc_caps at91sam9261_udc_caps = {
+	.init = at91sam9261_udc_init,
+	.pullup = at91sam9261_udc_pullup,
+};
+
+static int at91sam9263_udc_init(struct at91_udc *udc)
+{
+	struct at91_ep *ep;
+	int i;
+
+	for (i = 0; i < NUM_ENDPOINTS; i++) {
+		ep = &udc->ep[i];
+
+		switch (i) {
+		case 0:
+		case 1:
+		case 2:
+		case 3:
+			ep->maxpacket = 64;
+			break;
+		case 4:
+		case 5:
+			ep->maxpacket = 256;
+			break;
+		}
+	}
+
+	return 0;
+}
+
+static const struct at91_udc_caps at91sam9263_udc_caps = {
+	.init = at91sam9263_udc_init,
+	.pullup = at91sam9260_udc_pullup,
+};
+
+static const struct of_device_id at91_udc_dt_ids[] = {
+	{
+		.compatible = "atmel,at91rm9200-udc",
+		.data = &at91rm9200_udc_caps,
+	},
+	{
+		.compatible = "atmel,at91sam9260-udc",
+		.data = &at91sam9260_udc_caps,
+	},
+	{
+		.compatible = "atmel,at91sam9261-udc",
+		.data = &at91sam9261_udc_caps,
+	},
+	{
+		.compatible = "atmel,at91sam9263-udc",
+		.data = &at91sam9263_udc_caps,
+	},
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, at91_udc_dt_ids);
+
+static void at91udc_of_init(struct at91_udc *udc, struct device_node *np)
 {
 	struct at91_udc_data *board = &udc->board;
-	u32 val;
+	const struct of_device_id *match;
 	enum of_gpio_flags flags;
+	u32 val;
 
 	if (of_property_read_u32(np, "atmel,vbus-polled", &val) == 0)
 		board->vbus_polled = 1;
@@ -1688,6 +1844,10 @@ static void at91udc_of_init(struct at91_udc *udc,
 						  &flags);
 
 	board->pullup_active_low = (flags & OF_GPIO_ACTIVE_LOW) ? 1 : 0;
+
+	match = of_match_node(at91_udc_dt_ids, np);
+	if (match)
+		udc->caps = match->data;
 }
 
 static int at91udc_probe(struct platform_device *pdev)
@@ -1696,6 +1856,8 @@ static int at91udc_probe(struct platform_device *pdev)
 	struct at91_udc	*udc;
 	int		retval;
 	struct resource	*res;
+	struct at91_ep	*ep;
+	int		i;
 
 	/* init software state */
 	udc = &controller;
@@ -1705,40 +1867,19 @@ static int at91udc_probe(struct platform_device *pdev)
 	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");
-			return -ENODEV;
-		}
-		retval = devm_gpio_request(dev, udc->board.pullup_pin,
-					   "udc_pullup");
-		if (retval) {
-			DBG("D+ pullup is busy\n");
-			return retval;
-		}
-		gpio_direction_output(udc->board.pullup_pin,
-				udc->board.pullup_active_low);
-	}
 
-	/* newer chips have more FIFO memory than rm9200 */
-	if (cpu_is_at91sam9260() || cpu_is_at91sam9g20()) {
-		udc->ep[0].maxpacket = 64;
-		udc->ep[3].maxpacket = 64;
-		udc->ep[4].maxpacket = 512;
-		udc->ep[5].maxpacket = 512;
-	} else if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) {
-		udc->ep[3].maxpacket = 64;
-	} else if (cpu_is_at91sam9263()) {
-		udc->ep[0].maxpacket = 64;
-		udc->ep[3].maxpacket = 64;
-	}
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	udc->udp_baseaddr = devm_ioremap_resource(dev, res);
 	if (IS_ERR(udc->udp_baseaddr))
 		return PTR_ERR(udc->udp_baseaddr);
 
+	if (udc->caps && udc->caps->init) {
+		retval = udc->caps->init(udc);
+		if (retval)
+			return retval;
+	}
+
 	udc_reinit(udc);
 
 	/* get interface and function clocks */
@@ -1907,13 +2048,6 @@ static int at91udc_resume(struct platform_device *pdev)
 #define	at91udc_resume	NULL
 #endif
 
-static const struct of_device_id at91_udc_dt_ids[] = {
-	{ .compatible = "atmel,at91rm9200-udc" },
-	{ /* sentinel */ }
-};
-
-MODULE_DEVICE_TABLE(of, at91_udc_dt_ids);
-
 static struct platform_driver at91_udc_driver = {
 	.remove		= __exit_p(at91udc_remove),
 	.shutdown	= at91udc_shutdown,
diff --git a/drivers/usb/gadget/udc/at91_udc.h b/drivers/usb/gadget/udc/at91_udc.h
index e647d1c..4fc0daa 100644
--- a/drivers/usb/gadget/udc/at91_udc.h
+++ b/drivers/usb/gadget/udc/at91_udc.h
@@ -107,6 +107,11 @@ struct at91_ep {
 	unsigned			fifo_bank:1;
 };
 
+struct at91_udc_caps {
+	int (*init)(struct at91_udc *udc);
+	void (*pullup)(struct at91_udc *udc, int is_on);
+};
+
 /*
  * driver is non-SMP, and just blocks IRQs whenever it needs
  * access protection for chip registers or driver state
@@ -115,6 +120,7 @@ struct at91_udc {
 	struct usb_gadget		gadget;
 	struct at91_ep			ep[NUM_ENDPOINTS];
 	struct usb_gadget_driver	*driver;
+	const struct at91_udc_caps	*caps;
 	unsigned			vbus:1;
 	unsigned			enabled:1;
 	unsigned			clocked:1;
@@ -134,6 +140,7 @@ struct at91_udc {
 	spinlock_t			lock;
 	struct timer_list		vbus_timer;
 	struct work_struct		vbus_timer_work;
+	struct regmap			*matrix;
 };
 
 static inline struct at91_udc *to_udc(struct usb_gadget *g)
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 08/11] usb: gadget: at91_udc: Update DT binding documentation
  2014-12-03 11:31 [PATCH 00/11] usb: gadget: at91_udc: Rework for multi-platform support Boris Brezillon
                   ` (6 preceding siblings ...)
  2014-12-03 11:32 ` [PATCH 07/11] usb: gadget: at91_udc: Rework for multi-platform kernel support Boris Brezillon
@ 2014-12-03 11:32 ` Boris Brezillon
  2014-12-03 11:32 ` [PATCH 09/11] usb: gadget: at91_udc: Allocate udc instance Boris Brezillon
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Boris Brezillon @ 2014-12-03 11:32 UTC (permalink / raw)
  To: Nicolas Ferre, Jean-Christophe Plagniol-Villard,
	Alexandre Belloni, Andrew Victor, Felipe Balbi,
	Greg Kroah-Hartman, linux-usb
  Cc: Arnd Bergmann, linux-arm-kernel, linux-kernel, Rob Herring,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, devicetree,
	Boris Brezillon

Three compatible strings have been added to the at91_udc driver.
Update the documentation accordingly.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
 Documentation/devicetree/bindings/usb/atmel-usb.txt | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/atmel-usb.txt b/Documentation/devicetree/bindings/usb/atmel-usb.txt
index 6007231..54a8121 100644
--- a/Documentation/devicetree/bindings/usb/atmel-usb.txt
+++ b/Documentation/devicetree/bindings/usb/atmel-usb.txt
@@ -33,7 +33,11 @@ usb1: ehci@00800000 {
 AT91 USB device controller
 
 Required properties:
- - compatible: Should be "atmel,at91rm9200-udc"
+ - compatible: Should be one of the following
+	       "atmel,at91rm9200-udc"
+	       "atmel,at91sam9260-udc"
+	       "atmel,at91sam9261-udc"
+	       "atmel,at91sam9263-udc"
  - reg: Address and length of the register set for the device
  - interrupts: Should contain macb interrupt
  - clocks: Should reference the peripheral and the AHB clocks
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 09/11] usb: gadget: at91_udc: Allocate udc instance
  2014-12-03 11:31 [PATCH 00/11] usb: gadget: at91_udc: Rework for multi-platform support Boris Brezillon
                   ` (7 preceding siblings ...)
  2014-12-03 11:32 ` [PATCH 08/11] usb: gadget: at91_udc: Update DT binding documentation Boris Brezillon
@ 2014-12-03 11:32 ` Boris Brezillon
  2014-12-03 11:32 ` [PATCH 10/11] ARM: at91/dt: declare matrix node as a syscon device Boris Brezillon
  2014-12-03 11:32 ` [PATCH 11/11] ARM: at91/dt: fix at91 udc compatible strings Boris Brezillon
  10 siblings, 0 replies; 17+ messages in thread
From: Boris Brezillon @ 2014-12-03 11:32 UTC (permalink / raw)
  To: Nicolas Ferre, Jean-Christophe Plagniol-Villard,
	Alexandre Belloni, Andrew Victor, Felipe Balbi,
	Greg Kroah-Hartman, linux-usb
  Cc: Arnd Bergmann, linux-arm-kernel, linux-kernel, Rob Herring,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, devicetree,
	Boris Brezillon

Allocate udc structure instead of relying on the statically declared
object.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
 drivers/usb/gadget/udc/at91_udc.c | 101 ++++++++++----------------------------
 1 file changed, 27 insertions(+), 74 deletions(-)

diff --git a/drivers/usb/gadget/udc/at91_udc.c b/drivers/usb/gadget/udc/at91_udc.c
index f870c03..2b20dd7 100644
--- a/drivers/usb/gadget/udc/at91_udc.c
+++ b/drivers/usb/gadget/udc/at91_udc.c
@@ -59,7 +59,15 @@
 #define	DRIVER_VERSION	"3 May 2006"
 
 static const char driver_name [] = "at91_udc";
-static const char ep0name[] = "ep0";
+static const char * const ep_names[] = {
+	"ep0",
+	"ep1",
+	"ep2",
+	"ep3-int",
+	"ep4",
+	"ep5",
+};
+#define ep0name		ep_names[0]
 
 #define VBUS_POLL_TIMEOUT	msecs_to_jiffies(1000)
 
@@ -1477,78 +1485,6 @@ static void nop_release(struct device *dev)
 	/* nothing to free */
 }
 
-static struct at91_udc controller = {
-	.gadget = {
-		.ops	= &at91_udc_ops,
-		.ep0	= &controller.ep[0].ep,
-		.name	= driver_name,
-		.dev	= {
-			.init_name = "gadget",
-			.release = nop_release,
-		}
-	},
-	.ep[0] = {
-		.ep = {
-			.name	= ep0name,
-			.ops	= &at91_ep_ops,
-		},
-		.udc		= &controller,
-		.maxpacket	= 8,
-		.int_mask	= 1 << 0,
-	},
-	.ep[1] = {
-		.ep = {
-			.name	= "ep1",
-			.ops	= &at91_ep_ops,
-		},
-		.udc		= &controller,
-		.is_pingpong	= 1,
-		.maxpacket	= 64,
-		.int_mask	= 1 << 1,
-	},
-	.ep[2] = {
-		.ep = {
-			.name	= "ep2",
-			.ops	= &at91_ep_ops,
-		},
-		.udc		= &controller,
-		.is_pingpong	= 1,
-		.maxpacket	= 64,
-		.int_mask	= 1 << 2,
-	},
-	.ep[3] = {
-		.ep = {
-			/* could actually do bulk too */
-			.name	= "ep3-int",
-			.ops	= &at91_ep_ops,
-		},
-		.udc		= &controller,
-		.maxpacket	= 8,
-		.int_mask	= 1 << 3,
-	},
-	.ep[4] = {
-		.ep = {
-			.name	= "ep4",
-			.ops	= &at91_ep_ops,
-		},
-		.udc		= &controller,
-		.is_pingpong	= 1,
-		.maxpacket	= 256,
-		.int_mask	= 1 << 4,
-	},
-	.ep[5] = {
-		.ep = {
-			.name	= "ep5",
-			.ops	= &at91_ep_ops,
-		},
-		.udc		= &controller,
-		.is_pingpong	= 1,
-		.maxpacket	= 256,
-		.int_mask	= 1 << 5,
-	},
-	/* 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;
@@ -1859,15 +1795,32 @@ static int at91udc_probe(struct platform_device *pdev)
 	struct at91_ep	*ep;
 	int		i;
 
+	udc = devm_kzalloc(dev, sizeof(*udc), GFP_KERNEL);
+	if (!udc)
+		return -ENOMEM;
+
 	/* init software state */
-	udc = &controller;
 	udc->gadget.dev.parent = dev;
 	at91udc_of_init(udc, pdev->dev.of_node);
 	udc->pdev = pdev;
 	udc->enabled = 0;
 	spin_lock_init(&udc->lock);
 
+	udc->gadget.ops = &at91_udc_ops;
+	udc->gadget.ep0 = &udc->ep[0].ep;
+	udc->gadget.name = driver_name;
+	udc->gadget.dev.init_name = "gadget";
+	udc->gadget.dev.release = nop_release;
 
+	for (i = 0; i < NUM_ENDPOINTS; i++) {
+		ep = &udc->ep[i];
+		ep->ep.name = ep_names[i];
+		ep->ep.ops = &at91_ep_ops;
+		ep->udc = udc;
+		ep->int_mask = BIT(i);
+		if (i != 0 && i != 3)
+			ep->is_pingpong = 1;
+	}
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	udc->udp_baseaddr = devm_ioremap_resource(dev, res);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 10/11] ARM: at91/dt: declare matrix node as a syscon device
  2014-12-03 11:31 [PATCH 00/11] usb: gadget: at91_udc: Rework for multi-platform support Boris Brezillon
                   ` (8 preceding siblings ...)
  2014-12-03 11:32 ` [PATCH 09/11] usb: gadget: at91_udc: Allocate udc instance Boris Brezillon
@ 2014-12-03 11:32 ` Boris Brezillon
  2014-12-03 11:32 ` [PATCH 11/11] ARM: at91/dt: fix at91 udc compatible strings Boris Brezillon
  10 siblings, 0 replies; 17+ messages in thread
From: Boris Brezillon @ 2014-12-03 11:32 UTC (permalink / raw)
  To: Nicolas Ferre, Jean-Christophe Plagniol-Villard,
	Alexandre Belloni, Andrew Victor, Felipe Balbi,
	Greg Kroah-Hartman, linux-usb
  Cc: Arnd Bergmann, linux-arm-kernel, linux-kernel, Rob Herring,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, devicetree,
	Boris Brezillon

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
 arch/arm/boot/dts/at91sam9261.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/at91sam9261.dtsi b/arch/arm/boot/dts/at91sam9261.dtsi
index 7119f1f..e52ae97 100644
--- a/arch/arm/boot/dts/at91sam9261.dtsi
+++ b/arch/arm/boot/dts/at91sam9261.dtsi
@@ -257,7 +257,7 @@
 			};
 
 			matrix: matrix@ffffee00 {
-				compatible = "atmel,at91sam9260-bus-matrix";
+				compatible = "atmel,at91sam9260-bus-matrix", "syscon";
 				reg = <0xffffee00 0x200>;
 			};
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 11/11] ARM: at91/dt: fix at91 udc compatible strings
  2014-12-03 11:31 [PATCH 00/11] usb: gadget: at91_udc: Rework for multi-platform support Boris Brezillon
                   ` (9 preceding siblings ...)
  2014-12-03 11:32 ` [PATCH 10/11] ARM: at91/dt: declare matrix node as a syscon device Boris Brezillon
@ 2014-12-03 11:32 ` Boris Brezillon
  10 siblings, 0 replies; 17+ messages in thread
From: Boris Brezillon @ 2014-12-03 11:32 UTC (permalink / raw)
  To: Nicolas Ferre, Jean-Christophe Plagniol-Villard,
	Alexandre Belloni, Andrew Victor, Felipe Balbi,
	Greg Kroah-Hartman, linux-usb
  Cc: Arnd Bergmann, linux-arm-kernel, linux-kernel, Rob Herring,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, devicetree,
	Boris Brezillon

The at91rm9200, at91sam9260, at91sam9261 and at91sam9263 SoCs have slightly
different UDC IPs.
Those differences were previously handled with cpu_is_at91xx macro which
are about to be dropped for multi-platform support, thus we need to
change compatible strings.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
 arch/arm/boot/dts/at91sam9260.dtsi | 2 +-
 arch/arm/boot/dts/at91sam9261.dtsi | 3 ++-
 arch/arm/boot/dts/at91sam9263.dtsi | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/arm/boot/dts/at91sam9260.dtsi b/arch/arm/boot/dts/at91sam9260.dtsi
index cb100b0..b43de88 100644
--- a/arch/arm/boot/dts/at91sam9260.dtsi
+++ b/arch/arm/boot/dts/at91sam9260.dtsi
@@ -848,7 +848,7 @@
 			};
 
 			usb1: gadget@fffa4000 {
-				compatible = "atmel,at91rm9200-udc";
+				compatible = "atmel,at91sam9260-udc";
 				reg = <0xfffa4000 0x4000>;
 				interrupts = <10 IRQ_TYPE_LEVEL_HIGH 2>;
 				clocks = <&udc_clk>, <&udpck>;
diff --git a/arch/arm/boot/dts/at91sam9261.dtsi b/arch/arm/boot/dts/at91sam9261.dtsi
index e52ae97..90f0b59 100644
--- a/arch/arm/boot/dts/at91sam9261.dtsi
+++ b/arch/arm/boot/dts/at91sam9261.dtsi
@@ -119,11 +119,12 @@
 			};
 
 			usb1: gadget@fffa4000 {
-				compatible = "atmel,at91rm9200-udc";
+				compatible = "atmel,at91sam9261-udc";
 				reg = <0xfffa4000 0x4000>;
 				interrupts = <10 IRQ_TYPE_LEVEL_HIGH 2>;
 				clocks = <&udc_clk>, <&udpck>;
 				clock-names = "pclk", "hclk";
+				atmel,matrix = <&matrix>;
 				status = "disabled";
 			};
 
diff --git a/arch/arm/boot/dts/at91sam9263.dtsi b/arch/arm/boot/dts/at91sam9263.dtsi
index 51416c7d..2c7ed05 100644
--- a/arch/arm/boot/dts/at91sam9263.dtsi
+++ b/arch/arm/boot/dts/at91sam9263.dtsi
@@ -817,7 +817,7 @@
 			};
 
 			usb1: gadget@fff78000 {
-				compatible = "atmel,at91rm9200-udc";
+				compatible = "atmel,at91sam9263-udc";
 				reg = <0xfff78000 0x4000>;
 				interrupts = <24 IRQ_TYPE_LEVEL_HIGH 2>;
 				clocks = <&udc_clk>, <&udpck>;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 05/11] usb: gadget: at91_udc: Remove non-DT handling code
  2014-12-03 11:32 ` [PATCH 05/11] usb: gadget: at91_udc: Remove non-DT handling code Boris Brezillon
@ 2015-01-12 21:39   ` Felipe Balbi
  2015-01-12 22:53     ` Alexandre Belloni
  0 siblings, 1 reply; 17+ messages in thread
From: Felipe Balbi @ 2015-01-12 21:39 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Nicolas Ferre, Jean-Christophe Plagniol-Villard,
	Alexandre Belloni, Andrew Victor, Felipe Balbi,
	Greg Kroah-Hartman, linux-usb, Arnd Bergmann, linux-arm-kernel,
	linux-kernel, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, devicetree

[-- Attachment #1: Type: text/plain, Size: 640 bytes --]

On Wed, Dec 03, 2014 at 12:32:04PM +0100, Boris Brezillon wrote:
> Since non-DT board support has been removed from the at91 architecture we
> can safely remove non-DT handling code.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>

doesn't apply cleanly:

checking file drivers/usb/gadget/udc/Kconfig
checking file drivers/usb/gadget/udc/at91_udc.c
Hunk #1 succeeded at 1710 (offset 13 lines).
Hunk #2 succeeded at 1722 (offset 13 lines).
Hunk #3 succeeded at 1958 (offset 13 lines).
Hunk #4 FAILED at 1960.
1 out of 4 hunks FAILED

please rebase on testing/next which I just pushed.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 05/11] usb: gadget: at91_udc: Remove non-DT handling code
  2015-01-12 21:39   ` Felipe Balbi
@ 2015-01-12 22:53     ` Alexandre Belloni
  2015-01-13 16:36       ` Felipe Balbi
  0 siblings, 1 reply; 17+ messages in thread
From: Alexandre Belloni @ 2015-01-12 22:53 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Boris Brezillon, Nicolas Ferre, Jean-Christophe Plagniol-Villard,
	Andrew Victor, Greg Kroah-Hartman, linux-usb, Arnd Bergmann,
	linux-arm-kernel, linux-kernel, Rob Herring, Pawel Moll,
	Mark Rutland, Ian Campbell, Kumar Gala, devicetree

Hi Felipe,

I've rebased that patch series but it depends on another one (the mfd:
syscon: part of "memory: add Atmel EBI (External Bus Interface) driver")
that is not taken yet so applying it now will break the build. I still
hope to get it merged for 3.20 and I'll resend it as soon as possible.


On 12/01/2015 at 15:39:05 -0600, Felipe Balbi wrote :
> On Wed, Dec 03, 2014 at 12:32:04PM +0100, Boris Brezillon wrote:
> > Since non-DT board support has been removed from the at91 architecture we
> > can safely remove non-DT handling code.
> > 
> > Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> 
> doesn't apply cleanly:
> 
> checking file drivers/usb/gadget/udc/Kconfig
> checking file drivers/usb/gadget/udc/at91_udc.c
> Hunk #1 succeeded at 1710 (offset 13 lines).
> Hunk #2 succeeded at 1722 (offset 13 lines).
> Hunk #3 succeeded at 1958 (offset 13 lines).
> Hunk #4 FAILED at 1960.
> 1 out of 4 hunks FAILED
> 
> please rebase on testing/next which I just pushed.
> 
> -- 
> balbi



-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 05/11] usb: gadget: at91_udc: Remove non-DT handling code
  2015-01-12 22:53     ` Alexandre Belloni
@ 2015-01-13 16:36       ` Felipe Balbi
  2015-01-13 18:05         ` Alexandre Belloni
  0 siblings, 1 reply; 17+ messages in thread
From: Felipe Balbi @ 2015-01-13 16:36 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Felipe Balbi, Boris Brezillon, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Andrew Victor,
	Greg Kroah-Hartman, linux-usb, Arnd Bergmann, linux-arm-kernel,
	linux-kernel, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, devicetree

[-- Attachment #1: Type: text/plain, Size: 579 bytes --]

Hi,

On Mon, Jan 12, 2015 at 11:53:30PM +0100, Alexandre Belloni wrote:
> Hi Felipe,
> 
> I've rebased that patch series but it depends on another one (the mfd:
> syscon: part of "memory: add Atmel EBI (External Bus Interface)
> driver") that is not taken yet so applying it now will break the
> build. I still hope to get it merged for 3.20 and I'll resend it as
> soon as possible.

In that case, we either take the entire series through MFD (including
the gadget patches) or we delay the gadget patches until all
dependencies have been sorted out.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 05/11] usb: gadget: at91_udc: Remove non-DT handling code
  2015-01-13 16:36       ` Felipe Balbi
@ 2015-01-13 18:05         ` Alexandre Belloni
  2015-01-13 18:35           ` Felipe Balbi
  0 siblings, 1 reply; 17+ messages in thread
From: Alexandre Belloni @ 2015-01-13 18:05 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Boris Brezillon, Nicolas Ferre, Jean-Christophe Plagniol-Villard,
	Andrew Victor, Greg Kroah-Hartman, linux-usb, Arnd Bergmann,
	linux-arm-kernel, linux-kernel, Rob Herring, Pawel Moll,
	Mark Rutland, Ian Campbell, Kumar Gala, devicetree

Hi,

On 13/01/2015 at 10:36:54 -0600, Felipe Balbi wrote :
> > I've rebased that patch series but it depends on another one (the mfd:
> > syscon: part of "memory: add Atmel EBI (External Bus Interface)
> > driver") that is not taken yet so applying it now will break the
> > build. I still hope to get it merged for 3.20 and I'll resend it as
> > soon as possible.
> 
> In that case, we either take the entire series through MFD (including
> the gadget patches) or we delay the gadget patches until all
> dependencies have been sorted out.

I would prefer not to miss 3.20, can I resend the patches now so you can
review and ack them? Then they could go through the mfd tree.

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 05/11] usb: gadget: at91_udc: Remove non-DT handling code
  2015-01-13 18:05         ` Alexandre Belloni
@ 2015-01-13 18:35           ` Felipe Balbi
  0 siblings, 0 replies; 17+ messages in thread
From: Felipe Balbi @ 2015-01-13 18:35 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Felipe Balbi, Boris Brezillon, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Andrew Victor,
	Greg Kroah-Hartman, linux-usb, Arnd Bergmann, linux-arm-kernel,
	linux-kernel, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, devicetree

[-- Attachment #1: Type: text/plain, Size: 822 bytes --]

On Tue, Jan 13, 2015 at 07:05:26PM +0100, Alexandre Belloni wrote:
> Hi,
> 
> On 13/01/2015 at 10:36:54 -0600, Felipe Balbi wrote :
> > > I've rebased that patch series but it depends on another one (the mfd:
> > > syscon: part of "memory: add Atmel EBI (External Bus Interface)
> > > driver") that is not taken yet so applying it now will break the
> > > build. I still hope to get it merged for 3.20 and I'll resend it as
> > > soon as possible.
> > 
> > In that case, we either take the entire series through MFD (including
> > the gadget patches) or we delay the gadget patches until all
> > dependencies have been sorted out.
> 
> I would prefer not to miss 3.20, can I resend the patches now so you can
> review and ack them? Then they could go through the mfd tree.

Sure, please do

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2015-01-13 18:36 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-03 11:31 [PATCH 00/11] usb: gadget: at91_udc: Rework for multi-platform support Boris Brezillon
2014-12-03 11:32 ` [PATCH 01/11] usb: gadget: at91_udc: Fix clock names Boris Brezillon
2014-12-03 11:32 ` [PATCH 02/11] usb: gadget: at91_udc: Drop uclk clock Boris Brezillon
2014-12-03 11:32 ` [PATCH 03/11] usb: gadget: at91_udc: Document DT clocks and clock-names property Boris Brezillon
2014-12-03 11:32 ` [PATCH 04/11] ARM: at91/dt: at91sam9261: fix clocks and clock-names in udc definition Boris Brezillon
2014-12-03 11:32 ` [PATCH 05/11] usb: gadget: at91_udc: Remove non-DT handling code Boris Brezillon
2015-01-12 21:39   ` Felipe Balbi
2015-01-12 22:53     ` Alexandre Belloni
2015-01-13 16:36       ` Felipe Balbi
2015-01-13 18:05         ` Alexandre Belloni
2015-01-13 18:35           ` Felipe Balbi
2014-12-03 11:32 ` [PATCH 06/11] usb: gadget: at91_udc: Simplify probe and remove functions Boris Brezillon
2014-12-03 11:32 ` [PATCH 07/11] usb: gadget: at91_udc: Rework for multi-platform kernel support Boris Brezillon
2014-12-03 11:32 ` [PATCH 08/11] usb: gadget: at91_udc: Update DT binding documentation Boris Brezillon
2014-12-03 11:32 ` [PATCH 09/11] usb: gadget: at91_udc: Allocate udc instance Boris Brezillon
2014-12-03 11:32 ` [PATCH 10/11] ARM: at91/dt: declare matrix node as a syscon device Boris Brezillon
2014-12-03 11:32 ` [PATCH 11/11] ARM: at91/dt: fix at91 udc compatible strings Boris Brezillon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).