linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/12] Atmel matrix, SMC and UDC rework
@ 2015-01-14 16:21 Alexandre Belloni
  2015-01-14 16:21 ` [PATCH 01/12] mfd: syscon: Add atmel-matrix registers definition Alexandre Belloni
                   ` (12 more replies)
  0 siblings, 13 replies; 28+ messages in thread
From: Alexandre Belloni @ 2015-01-14 16:21 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Boris Brezillon, Alexandre Belloni, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

Hi Felipe,

The following series replace the previous series sent by Boris named:
 - [PATCH v5 00/11] memory: add Atmel EBI (External Bus Interface) driver
 - [PATCH 00/11] usb: gadget: at91_udc: Rework for multi-platform support

The patches I left out are less urgent and will be resent later, probably for
3.21.

Because of the dependancy between the syscon addition and the at91_udc series,
this can go through the AT91 tree if you giv your ack on the udc patches.

The first 4 patches introduce 2 syscon devices needed to configure the
matrix and SMC.
The following patches rework 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

Changes from the previous series:
 - rebased on 3.19-rc1

Boris Brezillon (12):
  mfd: syscon: Add atmel-matrix registers definition
  mfd: syscon: Add Atmel Matrix bus DT binding documentation
  mfd: syscon: Add atmel-smc registers definition
  mfd: syscon: Add Atmel SMC binding doc
  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
  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

 .../devicetree/bindings/mfd/atmel-matrix.txt       |  24 +
 .../devicetree/bindings/mfd/atmel-smc.txt          |  19 +
 .../devicetree/bindings/usb/atmel-usb.txt          |  10 +-
 drivers/usb/gadget/udc/Kconfig                     |   1 +
 drivers/usb/gadget/udc/at91_udc.c                  | 525 +++++++++++----------
 drivers/usb/gadget/udc/at91_udc.h                  |   9 +-
 include/linux/mfd/syscon/atmel-matrix.h            | 117 +++++
 include/linux/mfd/syscon/atmel-smc.h               | 173 +++++++
 8 files changed, 623 insertions(+), 255 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/atmel-matrix.txt
 create mode 100644 Documentation/devicetree/bindings/mfd/atmel-smc.txt
 create mode 100644 include/linux/mfd/syscon/atmel-matrix.h
 create mode 100644 include/linux/mfd/syscon/atmel-smc.h

-- 
2.1.0


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

* [PATCH 01/12] mfd: syscon: Add atmel-matrix registers definition
  2015-01-14 16:21 [PATCH 00/12] Atmel matrix, SMC and UDC rework Alexandre Belloni
@ 2015-01-14 16:21 ` Alexandre Belloni
  2015-01-18 12:52   ` Lee Jones
  2015-01-14 16:21 ` [PATCH 02/12] mfd: syscon: Add Atmel Matrix bus DT binding documentation Alexandre Belloni
                   ` (11 subsequent siblings)
  12 siblings, 1 reply; 28+ messages in thread
From: Alexandre Belloni @ 2015-01-14 16:21 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Boris Brezillon, Alexandre Belloni, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

From: Boris Brezillon <boris.brezillon@free-electrons.com>

AT91 SoCs have a memory range reserved for internal bus configuration.
Expose those registers so that drivers can make use of the matrix syscon
declared in at91 DTs.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: Lee Jones <lee.jones@linaro.org>
---
 include/linux/mfd/syscon/atmel-matrix.h | 117 ++++++++++++++++++++++++++++++++
 1 file changed, 117 insertions(+)
 create mode 100644 include/linux/mfd/syscon/atmel-matrix.h

diff --git a/include/linux/mfd/syscon/atmel-matrix.h b/include/linux/mfd/syscon/atmel-matrix.h
new file mode 100644
index 000000000000..8293c3e2a82a
--- /dev/null
+++ b/include/linux/mfd/syscon/atmel-matrix.h
@@ -0,0 +1,117 @@
+/*
+ *  Copyright (C) 2014 Atmel Corporation.
+ *
+ * Memory Controllers (MATRIX, EBI) - System peripherals registers.
+ *
+ * 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.
+ */
+
+#ifndef _LINUX_MFD_SYSCON_ATMEL_MATRIX_H
+#define _LINUX_MFD_SYSCON_ATMEL_MATRIX_H
+
+#define AT91SAM9260_MATRIX_MCFG			0x00
+#define AT91SAM9260_MATRIX_SCFG			0x40
+#define AT91SAM9260_MATRIX_PRS			0x80
+#define AT91SAM9260_MATRIX_MRCR			0x100
+#define AT91SAM9260_MATRIX_EBICSA		0x11c
+
+#define AT91SAM9261_MATRIX_MRCR			0x0
+#define AT91SAM9261_MATRIX_SCFG			0x4
+#define AT91SAM9261_MATRIX_TCR			0x24
+#define AT91SAM9261_MATRIX_EBICSA		0x30
+#define AT91SAM9261_MATRIX_USBPUCR		0x34
+
+#define AT91SAM9263_MATRIX_MCFG			0x00
+#define AT91SAM9263_MATRIX_SCFG			0x40
+#define AT91SAM9263_MATRIX_PRS			0x80
+#define AT91SAM9263_MATRIX_MRCR			0x100
+#define AT91SAM9263_MATRIX_TCR			0x114
+#define AT91SAM9263_MATRIX_EBI0CSA		0x120
+#define AT91SAM9263_MATRIX_EBI1CSA		0x124
+
+#define AT91SAM9RL_MATRIX_MCFG			0x00
+#define AT91SAM9RL_MATRIX_SCFG			0x40
+#define AT91SAM9RL_MATRIX_PRS			0x80
+#define AT91SAM9RL_MATRIX_MRCR			0x100
+#define AT91SAM9RL_MATRIX_TCR			0x114
+#define AT91SAM9RL_MATRIX_EBICSA		0x120
+
+#define AT91SAM9G45_MATRIX_MCFG			0x00
+#define AT91SAM9G45_MATRIX_SCFG			0x40
+#define AT91SAM9G45_MATRIX_PRS			0x80
+#define AT91SAM9G45_MATRIX_MRCR			0x100
+#define AT91SAM9G45_MATRIX_TCR			0x110
+#define AT91SAM9G45_MATRIX_DDRMPR		0x118
+#define AT91SAM9G45_MATRIX_EBICSA		0x128
+
+#define AT91SAM9N12_MATRIX_MCFG			0x00
+#define AT91SAM9N12_MATRIX_SCFG			0x40
+#define AT91SAM9N12_MATRIX_PRS			0x80
+#define AT91SAM9N12_MATRIX_MRCR			0x100
+#define AT91SAM9N12_MATRIX_EBICSA		0x118
+
+#define AT91SAM9X5_MATRIX_MCFG			0x00
+#define AT91SAM9X5_MATRIX_SCFG			0x40
+#define AT91SAM9X5_MATRIX_PRS			0x80
+#define AT91SAM9X5_MATRIX_MRCR			0x100
+#define AT91SAM9X5_MATRIX_EBICSA		0x120
+
+#define SAMA5D3_MATRIX_MCFG			0x00
+#define SAMA5D3_MATRIX_SCFG			0x40
+#define SAMA5D3_MATRIX_PRS			0x80
+#define SAMA5D3_MATRIX_MRCR			0x100
+
+#define AT91_MATRIX_MCFG(o, x)			((o) + ((x) * 0x4))
+#define AT91_MATRIX_ULBT			GENMASK(2, 0)
+#define AT91_MATRIX_ULBT_INFINITE		(0 << 0)
+#define AT91_MATRIX_ULBT_SINGLE			(1 << 0)
+#define AT91_MATRIX_ULBT_FOUR			(2 << 0)
+#define AT91_MATRIX_ULBT_EIGHT			(3 << 0)
+#define AT91_MATRIX_ULBT_SIXTEEN		(4 << 0)
+
+#define AT91_MATRIX_SCFG(o, x)			((o) + ((x) * 0x4))
+#define AT91_MATRIX_SLOT_CYCLE			GENMASK(7,  0)
+#define AT91_MATRIX_DEFMSTR_TYPE		GENMASK(17, 16)
+#define AT91_MATRIX_DEFMSTR_TYPE_NONE		(0 << 16)
+#define AT91_MATRIX_DEFMSTR_TYPE_LAST		(1 << 16)
+#define AT91_MATRIX_DEFMSTR_TYPE_FIXED		(2 << 16)
+#define AT91_MATRIX_FIXED_DEFMSTR		GENMASK(20, 18)
+#define AT91_MATRIX_ARBT			GENMASK(25, 24)
+#define AT91_MATRIX_ARBT_ROUND_ROBIN		(0 << 24)
+#define AT91_MATRIX_ARBT_FIXED_PRIORITY		(1 << 24)
+
+#define AT91_MATRIX_ITCM_SIZE			GENMASK(3, 0)
+#define AT91_MATRIX_ITCM_0			(0 << 0)
+#define AT91_MATRIX_ITCM_16			(5 << 0)
+#define AT91_MATRIX_ITCM_32			(6 << 0)
+#define AT91_MATRIX_ITCM_64			(7 << 0)
+#define	AT91_MATRIX_DTCM_SIZE			GENMASK(7, 4)
+#define	AT91_MATRIX_DTCM_0			(0 << 4)
+#define	AT91_MATRIX_DTCM_16			(5 << 4)
+#define AT91_MATRIX_DTCM_32			(6 << 4)
+#define AT91_MATRIX_DTCM_64			(7 << 4)
+
+#define AT91_MATRIX_PRAS(o, x)			((o) + ((x) * 0x8))
+#define AT91_MATRIX_PRBS(o, x)			((o) + ((x) * 0x8) + 0x4)
+#define AT91_MATRIX_MPR(x)			GENMASK(((x) * 0x4) + 1, ((x) * 0x4))
+
+#define AT91_MATRIX_RCB(x)			BIT(x)
+
+#define AT91_MATRIX_CSA(cs, val)		(val << (cs))
+#define AT91_MATRIX_DBPUC			BIT(8)
+#define AT91_MATRIX_DBPDC			BIT(9)
+#define AT91_MATRIX_VDDIOMSEL			BIT(16)
+#define AT91_MATRIX_VDDIOMSEL_1_8V		(0 << 16)
+#define AT91_MATRIX_VDDIOMSEL_3_3V		(1 << 16)
+#define AT91_MATRIX_EBI_IOSR			BIT(17)
+#define AT91_MATRIX_DDR_IOSR			BIT(18)
+#define AT91_MATRIX_NFD0_SELECT			BIT(24)
+#define AT91_MATRIX_DDR_MP_EN			BIT(25)
+#define AT91_MATRIX_EBI_NUM_CS			8
+
+#define AT91_MATRIX_USBPUCR_PUON		BIT(30)
+
+#endif /* _LINUX_MFD_SYSCON_ATMEL_MATRIX_H */
-- 
2.1.0


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

* [PATCH 02/12] mfd: syscon: Add Atmel Matrix bus DT binding documentation
  2015-01-14 16:21 [PATCH 00/12] Atmel matrix, SMC and UDC rework Alexandre Belloni
  2015-01-14 16:21 ` [PATCH 01/12] mfd: syscon: Add atmel-matrix registers definition Alexandre Belloni
@ 2015-01-14 16:21 ` Alexandre Belloni
  2015-01-18 12:53   ` Lee Jones
  2015-01-14 16:21 ` [PATCH 03/12] mfd: syscon: Add atmel-smc registers definition Alexandre Belloni
                   ` (10 subsequent siblings)
  12 siblings, 1 reply; 28+ messages in thread
From: Alexandre Belloni @ 2015-01-14 16:21 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Boris Brezillon, Alexandre Belloni, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

From: Boris Brezillon <boris.brezillon@free-electrons.com>

The Matrix registers are provided to configure internal bus behavior on
at91 SoCs.
Some registers might be accessed by several drivers (e.g. to configure
external memory bus timings), hence we declare this register set as a
syscon device.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: Lee Jones <lee.jones@linaro.org>
---
 .../devicetree/bindings/mfd/atmel-matrix.txt       | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/atmel-matrix.txt

diff --git a/Documentation/devicetree/bindings/mfd/atmel-matrix.txt b/Documentation/devicetree/bindings/mfd/atmel-matrix.txt
new file mode 100644
index 000000000000..e3ef50ca02a5
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/atmel-matrix.txt
@@ -0,0 +1,24 @@
+* Device tree bindings for Atmel Bus Matrix
+
+The Bus Matrix registers are used to configure Atmel SoCs internal bus
+behavior (master/slave priorities, undefined burst length type, ...)
+
+Required properties:
+- compatible:		Should be one of the following
+			"atmel,at91sam9260-matrix", "syscon"
+			"atmel,at91sam9261-matrix", "syscon"
+			"atmel,at91sam9263-matrix", "syscon"
+			"atmel,at91sam9rl-matrix", "syscon"
+			"atmel,at91sam9g45-matrix", "syscon"
+			"atmel,at91sam9n12-matrix", "syscon"
+			"atmel,at91sam9x5-matrix", "syscon"
+			"atmel,sama5d3-matrix", "syscon"
+- reg:			Contains offset/length value of the Bus Matrix
+			memory region.
+
+Example:
+
+matrix: matrix@ffffec00 {
+	compatible = "atmel,sama5d3-matrix", "syscon";
+	reg = <0xffffec00 0x200>;
+};
-- 
2.1.0


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

* [PATCH 03/12] mfd: syscon: Add atmel-smc registers definition
  2015-01-14 16:21 [PATCH 00/12] Atmel matrix, SMC and UDC rework Alexandre Belloni
  2015-01-14 16:21 ` [PATCH 01/12] mfd: syscon: Add atmel-matrix registers definition Alexandre Belloni
  2015-01-14 16:21 ` [PATCH 02/12] mfd: syscon: Add Atmel Matrix bus DT binding documentation Alexandre Belloni
@ 2015-01-14 16:21 ` Alexandre Belloni
  2015-01-18 12:53   ` Lee Jones
  2015-01-14 16:21 ` [PATCH 04/12] mfd: syscon: Add Atmel SMC binding doc Alexandre Belloni
                   ` (9 subsequent siblings)
  12 siblings, 1 reply; 28+ messages in thread
From: Alexandre Belloni @ 2015-01-14 16:21 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Boris Brezillon, Alexandre Belloni, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

From: Boris Brezillon <boris.brezillon@free-electrons.com>

Atmel AT91 SoCs have a memory range reserved for SMC (Static Memory
Controller) configuration.
Expose those registers so that drivers can make use of the smc syscon
declared in at91 DTs.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: Lee Jones <lee.jones@linaro.org>
---
 include/linux/mfd/syscon/atmel-smc.h | 173 +++++++++++++++++++++++++++++++++++
 1 file changed, 173 insertions(+)
 create mode 100644 include/linux/mfd/syscon/atmel-smc.h

diff --git a/include/linux/mfd/syscon/atmel-smc.h b/include/linux/mfd/syscon/atmel-smc.h
new file mode 100644
index 000000000000..be6ebe64eebe
--- /dev/null
+++ b/include/linux/mfd/syscon/atmel-smc.h
@@ -0,0 +1,173 @@
+/*
+ * Atmel SMC (Static Memory Controller) register offsets and bit definitions.
+ *
+ * Copyright (C) 2014 Atmel
+ * Copyright (C) 2014 Free Electrons
+ *
+ * Author: Boris Brezillon <boris.brezillon@free-electrons.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _LINUX_MFD_SYSCON_ATMEL_SMC_H_
+#define _LINUX_MFD_SYSCON_ATMEL_SMC_H_
+
+#include <linux/kernel.h>
+#include <linux/regmap.h>
+
+#define AT91SAM9_SMC_GENERIC		0x00
+#define AT91SAM9_SMC_GENERIC_BLK_SZ	0x10
+
+#define SAMA5_SMC_GENERIC		0x600
+#define SAMA5_SMC_GENERIC_BLK_SZ	0x14
+
+#define AT91SAM9_SMC_SETUP(o)		((o) + 0x00)
+#define AT91SAM9_SMC_NWESETUP(x)	(x)
+#define AT91SAM9_SMC_NCS_WRSETUP(x)	((x) << 8)
+#define AT91SAM9_SMC_NRDSETUP(x)	((x) << 16)
+#define AT91SAM9_SMC_NCS_NRDSETUP(x)	((x) << 24)
+
+#define AT91SAM9_SMC_PULSE(o)		((o) + 0x04)
+#define AT91SAM9_SMC_NWEPULSE(x)	(x)
+#define AT91SAM9_SMC_NCS_WRPULSE(x)	((x) << 8)
+#define AT91SAM9_SMC_NRDPULSE(x)	((x) << 16)
+#define AT91SAM9_SMC_NCS_NRDPULSE(x)	((x) << 24)
+
+#define AT91SAM9_SMC_CYCLE(o)		((o) + 0x08)
+#define AT91SAM9_SMC_NWECYCLE(x)	(x)
+#define AT91SAM9_SMC_NRDCYCLE(x)	((x) << 16)
+
+#define AT91SAM9_SMC_MODE(o)		((o) + 0x0c)
+#define SAMA5_SMC_MODE(o)		((o) + 0x10)
+#define AT91_SMC_READMODE		BIT(0)
+#define AT91_SMC_READMODE_NCS		(0 << 0)
+#define AT91_SMC_READMODE_NRD		(1 << 0)
+#define AT91_SMC_WRITEMODE		BIT(1)
+#define AT91_SMC_WRITEMODE_NCS		(0 << 1)
+#define AT91_SMC_WRITEMODE_NWE		(1 << 1)
+#define AT91_SMC_EXNWMODE		GENMASK(5, 4)
+#define AT91_SMC_EXNWMODE_DISABLE	(0 << 4)
+#define AT91_SMC_EXNWMODE_FROZEN	(2 << 4)
+#define AT91_SMC_EXNWMODE_READY		(3 << 4)
+#define AT91_SMC_BAT			BIT(8)
+#define AT91_SMC_BAT_SELECT		(0 << 8)
+#define AT91_SMC_BAT_WRITE		(1 << 8)
+#define AT91_SMC_DBW			GENMASK(13, 12)
+#define AT91_SMC_DBW_8			(0 << 12)
+#define AT91_SMC_DBW_16			(1 << 12)
+#define AT91_SMC_DBW_32			(2 << 12)
+#define AT91_SMC_TDF			GENMASK(19, 16)
+#define AT91_SMC_TDF_(x)		((((x) - 1) << 16) & AT91_SMC_TDF)
+#define AT91_SMC_TDF_MAX		16
+#define AT91_SMC_TDFMODE_OPTIMIZED	BIT(20)
+#define AT91_SMC_PMEN			BIT(24)
+#define AT91_SMC_PS			GENMASK(29, 28)
+#define AT91_SMC_PS_4			(0 << 28)
+#define AT91_SMC_PS_8			(1 << 28)
+#define AT91_SMC_PS_16			(2 << 28)
+#define AT91_SMC_PS_32			(3 << 28)
+
+
+/*
+ * This function converts a setup timing expressed in nanoseconds into an
+ * encoded value that can be written in the SMC_SETUP register.
+ *
+ * The following formula is described in atmel datasheets (section
+ * "SMC Setup Register"):
+ *
+ * setup length = (128* SETUP[5] + SETUP[4:0])
+ *
+ * where setup length is the timing expressed in cycles.
+ */
+static inline u32 at91sam9_smc_setup_ns_to_cycles(unsigned int clk_rate,
+						  u32 timing_ns)
+{
+	u32 clk_period = DIV_ROUND_UP(NSEC_PER_SEC, clk_rate);
+	u32 coded_cycles = 0;
+	u32 cycles;
+
+	cycles = DIV_ROUND_UP(timing_ns, clk_period);
+	if (cycles / 32) {
+		coded_cycles |= 1 << 5;
+		if (cycles < 128)
+			cycles = 0;
+	}
+
+	coded_cycles |= cycles % 32;
+
+	return coded_cycles;
+}
+
+/*
+ * This function converts a pulse timing expressed in nanoseconds into an
+ * encoded value that can be written in the SMC_PULSE register.
+ *
+ * The following formula is described in atmel datasheets (section
+ * "SMC Pulse Register"):
+ *
+ * pulse length = (256* PULSE[6] + PULSE[5:0])
+ *
+ * where pulse length is the timing expressed in cycles.
+ */
+static inline u32 at91sam9_smc_pulse_ns_to_cycles(unsigned int clk_rate,
+						  u32 timing_ns)
+{
+	u32 clk_period = DIV_ROUND_UP(NSEC_PER_SEC, clk_rate);
+	u32 coded_cycles = 0;
+	u32 cycles;
+
+	cycles = DIV_ROUND_UP(timing_ns, clk_period);
+	if (cycles / 64) {
+		coded_cycles |= 1 << 6;
+		if (cycles < 256)
+			cycles = 0;
+	}
+
+	coded_cycles |= cycles % 64;
+
+	return coded_cycles;
+}
+
+/*
+ * This function converts a cycle timing expressed in nanoseconds into an
+ * encoded value that can be written in the SMC_CYCLE register.
+ *
+ * The following formula is described in atmel datasheets (section
+ * "SMC Cycle Register"):
+ *
+ * cycle length = (CYCLE[8:7]*256 + CYCLE[6:0])
+ *
+ * where cycle length is the timing expressed in cycles.
+ */
+static inline u32 at91sam9_smc_cycle_ns_to_cycles(unsigned int clk_rate,
+						  u32 timing_ns)
+{
+	u32 clk_period = DIV_ROUND_UP(NSEC_PER_SEC, clk_rate);
+	u32 coded_cycles = 0;
+	u32 cycles;
+
+	cycles = DIV_ROUND_UP(timing_ns, clk_period);
+	if (cycles / 128) {
+		coded_cycles = cycles / 256;
+		cycles %= 256;
+		if (cycles >= 128) {
+			coded_cycles++;
+			cycles = 0;
+		}
+
+		if (coded_cycles > 0x3) {
+			coded_cycles = 0x3;
+			cycles = 0x7f;
+		}
+
+		coded_cycles <<= 7;
+	}
+
+	coded_cycles |= cycles % 128;
+
+	return coded_cycles;
+}
+
+#endif /* _LINUX_MFD_SYSCON_ATMEL_SMC_H_ */
-- 
2.1.0


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

* [PATCH 04/12] mfd: syscon: Add Atmel SMC binding doc
  2015-01-14 16:21 [PATCH 00/12] Atmel matrix, SMC and UDC rework Alexandre Belloni
                   ` (2 preceding siblings ...)
  2015-01-14 16:21 ` [PATCH 03/12] mfd: syscon: Add atmel-smc registers definition Alexandre Belloni
@ 2015-01-14 16:21 ` Alexandre Belloni
  2015-01-18 12:54   ` Lee Jones
  2015-01-14 16:21 ` [PATCH 05/12] usb: gadget: at91_udc: Fix clock names Alexandre Belloni
                   ` (8 subsequent siblings)
  12 siblings, 1 reply; 28+ messages in thread
From: Alexandre Belloni @ 2015-01-14 16:21 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Boris Brezillon, Alexandre Belloni, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

From: Boris Brezillon <boris.brezillon@free-electrons.com>

The SMC registers are used to configure Atmel EBI (External Bus Interface)
to interface with standard memory devices (NAND, NOR, SRAM or specialized
devices like FPGAs).

Declare this memory region as a syscon, so that different drivers can
configure the SMC interface (mostly timing configuration) according to
their need.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: Lee Jones <lee.jones@linaro.org>
---
 Documentation/devicetree/bindings/mfd/atmel-smc.txt | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/atmel-smc.txt

diff --git a/Documentation/devicetree/bindings/mfd/atmel-smc.txt b/Documentation/devicetree/bindings/mfd/atmel-smc.txt
new file mode 100644
index 000000000000..26eeed373934
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/atmel-smc.txt
@@ -0,0 +1,19 @@
+* Device tree bindings for Atmel SMC (Static Memory Controller)
+
+The SMC registers are used to configure Atmel EBI (External Bus Interface)
+to interface with standard memory devices (NAND, NOR, SRAM or specialized
+devices like FPGAs).
+
+Required properties:
+- compatible:		Should be one of the following
+			"atmel,at91sam9260-smc", "syscon"
+			"atmel,sama5d3-smc", "syscon"
+- reg:			Contains offset/length value of the SMC memory
+			region.
+
+Example:
+
+smc: smc@ffffc000 {
+	compatible = "atmel,sama5d3-smc", "syscon";
+	reg = <0xffffc000 0x1000>;
+};
-- 
2.1.0


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

* [PATCH 05/12] usb: gadget: at91_udc: Fix clock names
  2015-01-14 16:21 [PATCH 00/12] Atmel matrix, SMC and UDC rework Alexandre Belloni
                   ` (3 preceding siblings ...)
  2015-01-14 16:21 ` [PATCH 04/12] mfd: syscon: Add Atmel SMC binding doc Alexandre Belloni
@ 2015-01-14 16:21 ` Alexandre Belloni
  2015-01-14 17:37   ` Felipe Balbi
  2015-01-14 16:21 ` [PATCH 06/12] usb: gadget: at91_udc: Drop uclk clock Alexandre Belloni
                   ` (7 subsequent siblings)
  12 siblings, 1 reply; 28+ messages in thread
From: Alexandre Belloni @ 2015-01-14 16:21 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Boris Brezillon, Alexandre Belloni, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

From: Boris Brezillon <boris.brezillon@free-electrons.com>

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 c862656d18b8..9ff2f7e5c6a7 100644
--- a/drivers/usb/gadget/udc/at91_udc.c
+++ b/drivers/usb/gadget/udc/at91_udc.c
@@ -1779,8 +1779,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) ||
-- 
2.1.0


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

* [PATCH 06/12] usb: gadget: at91_udc: Drop uclk clock
  2015-01-14 16:21 [PATCH 00/12] Atmel matrix, SMC and UDC rework Alexandre Belloni
                   ` (4 preceding siblings ...)
  2015-01-14 16:21 ` [PATCH 05/12] usb: gadget: at91_udc: Fix clock names Alexandre Belloni
@ 2015-01-14 16:21 ` Alexandre Belloni
  2015-01-14 17:37   ` Felipe Balbi
  2015-01-14 16:21 ` [PATCH 07/12] usb: gadget: at91_udc: Document DT clocks and clock-names property Alexandre Belloni
                   ` (6 subsequent siblings)
  12 siblings, 1 reply; 28+ messages in thread
From: Alexandre Belloni @ 2015-01-14 16:21 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Boris Brezillon, Alexandre Belloni, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

From: Boris Brezillon <boris.brezillon@free-electrons.com>

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 9ff2f7e5c6a7..d33f2994b7c4 100644
--- a/drivers/usb/gadget/udc/at91_udc.c
+++ b/drivers/usb/gadget/udc/at91_udc.c
@@ -895,8 +895,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);
 }
@@ -909,8 +907,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);
 }
 
 /*
@@ -1781,25 +1777,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)
@@ -1873,12 +1861,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))
@@ -1924,15 +1907,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 017524663381..e647d1c2ada4 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;
-- 
2.1.0


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

* [PATCH 07/12] usb: gadget: at91_udc: Document DT clocks and clock-names property
  2015-01-14 16:21 [PATCH 00/12] Atmel matrix, SMC and UDC rework Alexandre Belloni
                   ` (5 preceding siblings ...)
  2015-01-14 16:21 ` [PATCH 06/12] usb: gadget: at91_udc: Drop uclk clock Alexandre Belloni
@ 2015-01-14 16:21 ` Alexandre Belloni
  2015-01-14 16:22 ` [PATCH 08/12] usb: gadget: at91_udc: Remove non-DT handling code Alexandre Belloni
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 28+ messages in thread
From: Alexandre Belloni @ 2015-01-14 16:21 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Boris Brezillon, Alexandre Belloni, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

From: Boris Brezillon <boris.brezillon@free-electrons.com>

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 bc2222ca3f2a..6007231e0adc 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
-- 
2.1.0


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

* [PATCH 08/12] usb: gadget: at91_udc: Remove non-DT handling code
  2015-01-14 16:21 [PATCH 00/12] Atmel matrix, SMC and UDC rework Alexandre Belloni
                   ` (6 preceding siblings ...)
  2015-01-14 16:21 ` [PATCH 07/12] usb: gadget: at91_udc: Document DT clocks and clock-names property Alexandre Belloni
@ 2015-01-14 16:22 ` Alexandre Belloni
  2015-01-14 17:38   ` Felipe Balbi
  2015-01-14 16:22 ` [PATCH 09/12] usb: gadget: at91_udc: Simplify probe and remove functions Alexandre Belloni
                   ` (4 subsequent siblings)
  12 siblings, 1 reply; 28+ messages in thread
From: Alexandre Belloni @ 2015-01-14 16:22 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Boris Brezillon, Alexandre Belloni, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

From: Boris Brezillon <boris.brezillon@free-electrons.com>

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 b8e213eb36cc..366e551aeff0 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 d33f2994b7c4..be7e16037ac4 100644
--- a/drivers/usb/gadget/udc/at91_udc.c
+++ b/drivers/usb/gadget/udc/at91_udc.c
@@ -1710,12 +1710,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;
@@ -1728,11 +1722,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);
@@ -1968,14 +1958,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),
@@ -1984,7 +1972,7 @@ static struct platform_driver at91_udc_driver = {
 	.resume		= at91udc_resume,
 	.driver		= {
 		.name	= (char *) driver_name,
-		.of_match_table	= of_match_ptr(at91_udc_dt_ids),
+		.of_match_table	= at91_udc_dt_ids,
 	},
 };
 
-- 
2.1.0


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

* [PATCH 09/12] usb: gadget: at91_udc: Simplify probe and remove functions
  2015-01-14 16:21 [PATCH 00/12] Atmel matrix, SMC and UDC rework Alexandre Belloni
                   ` (7 preceding siblings ...)
  2015-01-14 16:22 ` [PATCH 08/12] usb: gadget: at91_udc: Remove non-DT handling code Alexandre Belloni
@ 2015-01-14 16:22 ` Alexandre Belloni
  2015-01-14 17:38   ` Felipe Balbi
  2015-01-14 16:22 ` [PATCH 10/12] usb: gadget: at91_udc: Rework for multi-platform kernel support Alexandre Belloni
                   ` (3 subsequent siblings)
  12 siblings, 1 reply; 28+ messages in thread
From: Alexandre Belloni @ 2015-01-14 16:22 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Boris Brezillon, Alexandre Belloni, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

From: Boris Brezillon <boris.brezillon@free-electrons.com>

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 be7e16037ac4..4dba2c65dfd4 100644
--- a/drivers/usb/gadget/udc/at91_udc.c
+++ b/drivers/usb/gadget/udc/at91_udc.c
@@ -1710,15 +1710,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;
@@ -1731,13 +1722,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);
@@ -1756,32 +1747,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. */
@@ -1790,18 +1781,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);
 
 		/*
@@ -1818,12 +1812,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 {
@@ -1832,44 +1827,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");
@@ -1884,25 +1862,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;
 }
 
-- 
2.1.0


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

* [PATCH 10/12] usb: gadget: at91_udc: Rework for multi-platform kernel support
  2015-01-14 16:21 [PATCH 00/12] Atmel matrix, SMC and UDC rework Alexandre Belloni
                   ` (8 preceding siblings ...)
  2015-01-14 16:22 ` [PATCH 09/12] usb: gadget: at91_udc: Simplify probe and remove functions Alexandre Belloni
@ 2015-01-14 16:22 ` Alexandre Belloni
  2015-01-14 17:38   ` Felipe Balbi
  2015-01-14 16:22 ` [PATCH 11/12] usb: gadget: at91_udc: Update DT binding documentation Alexandre Belloni
                   ` (2 subsequent siblings)
  12 siblings, 1 reply; 28+ messages in thread
From: Alexandre Belloni @ 2015-01-14 16:22 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Boris Brezillon, Alexandre Belloni, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

From: Boris Brezillon <boris.brezillon@free-electrons.com>

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 4dba2c65dfd4..c0abb9bc76a9 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"
 
@@ -915,8 +908,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");
@@ -925,40 +916,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 */
@@ -1683,12 +1649,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,
+			   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;
@@ -1701,6 +1857,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)
@@ -1709,6 +1869,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;
@@ -1718,40 +1880,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 */
@@ -1920,13 +2061,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 e647d1c2ada4..4fc0daa6587f 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)
-- 
2.1.0


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

* [PATCH 11/12] usb: gadget: at91_udc: Update DT binding documentation
  2015-01-14 16:21 [PATCH 00/12] Atmel matrix, SMC and UDC rework Alexandre Belloni
                   ` (9 preceding siblings ...)
  2015-01-14 16:22 ` [PATCH 10/12] usb: gadget: at91_udc: Rework for multi-platform kernel support Alexandre Belloni
@ 2015-01-14 16:22 ` Alexandre Belloni
  2015-01-14 16:22 ` [PATCH 12/12] usb: gadget: at91_udc: Allocate udc instance Alexandre Belloni
  2015-01-15 13:30 ` [PATCH 00/12] Atmel matrix, SMC and UDC rework Nicolas Ferre
  12 siblings, 0 replies; 28+ messages in thread
From: Alexandre Belloni @ 2015-01-14 16:22 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Boris Brezillon, Alexandre Belloni, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

From: Boris Brezillon <boris.brezillon@free-electrons.com>

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 6007231e0adc..54a81219caae 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
-- 
2.1.0


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

* [PATCH 12/12] usb: gadget: at91_udc: Allocate udc instance
  2015-01-14 16:21 [PATCH 00/12] Atmel matrix, SMC and UDC rework Alexandre Belloni
                   ` (10 preceding siblings ...)
  2015-01-14 16:22 ` [PATCH 11/12] usb: gadget: at91_udc: Update DT binding documentation Alexandre Belloni
@ 2015-01-14 16:22 ` Alexandre Belloni
  2015-01-14 17:39   ` Felipe Balbi
  2015-01-15 13:30 ` [PATCH 00/12] Atmel matrix, SMC and UDC rework Nicolas Ferre
  12 siblings, 1 reply; 28+ messages in thread
From: Alexandre Belloni @ 2015-01-14 16:22 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Boris Brezillon, Alexandre Belloni, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

From: Boris Brezillon <boris.brezillon@free-electrons.com>

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 | 96 +++++++++++----------------------------
 1 file changed, 26 insertions(+), 70 deletions(-)

diff --git a/drivers/usb/gadget/udc/at91_udc.c b/drivers/usb/gadget/udc/at91_udc.c
index c0abb9bc76a9..6d285226ab94 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)
 
@@ -1497,74 +1505,6 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc)
 
 /*-------------------------------------------------------------------------*/
 
-static struct at91_udc controller = {
-	.gadget = {
-		.ops	= &at91_udc_ops,
-		.ep0	= &controller.ep[0].ep,
-		.name	= driver_name,
-	},
-	.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;
@@ -1872,15 +1812,31 @@ 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";
 
+	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);
-- 
2.1.0


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

* Re: [PATCH 05/12] usb: gadget: at91_udc: Fix clock names
  2015-01-14 16:21 ` [PATCH 05/12] usb: gadget: at91_udc: Fix clock names Alexandre Belloni
@ 2015-01-14 17:37   ` Felipe Balbi
  0 siblings, 0 replies; 28+ messages in thread
From: Felipe Balbi @ 2015-01-14 17:37 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Felipe Balbi, Boris Brezillon, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

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

On Wed, Jan 14, 2015 at 05:21:57PM +0100, Alexandre Belloni wrote:
> From: Boris Brezillon <boris.brezillon@free-electrons.com>
> 
> 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>

Acked-by: Felipe Balbi <balbi@ti.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 c862656d18b8..9ff2f7e5c6a7 100644
> --- a/drivers/usb/gadget/udc/at91_udc.c
> +++ b/drivers/usb/gadget/udc/at91_udc.c
> @@ -1779,8 +1779,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) ||
> -- 
> 2.1.0
> 

-- 
balbi

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

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

* Re: [PATCH 06/12] usb: gadget: at91_udc: Drop uclk clock
  2015-01-14 16:21 ` [PATCH 06/12] usb: gadget: at91_udc: Drop uclk clock Alexandre Belloni
@ 2015-01-14 17:37   ` Felipe Balbi
  0 siblings, 0 replies; 28+ messages in thread
From: Felipe Balbi @ 2015-01-14 17:37 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Felipe Balbi, Boris Brezillon, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

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

On Wed, Jan 14, 2015 at 05:21:58PM +0100, Alexandre Belloni wrote:
> From: Boris Brezillon <boris.brezillon@free-electrons.com>
> 
> 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>

Acked-by: Felipe Balbi <balbi@ti.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 9ff2f7e5c6a7..d33f2994b7c4 100644
> --- a/drivers/usb/gadget/udc/at91_udc.c
> +++ b/drivers/usb/gadget/udc/at91_udc.c
> @@ -895,8 +895,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);
>  }
> @@ -909,8 +907,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);
>  }
>  
>  /*
> @@ -1781,25 +1777,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)
> @@ -1873,12 +1861,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))
> @@ -1924,15 +1907,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 017524663381..e647d1c2ada4 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;
> -- 
> 2.1.0
> 

-- 
balbi

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

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

* Re: [PATCH 08/12] usb: gadget: at91_udc: Remove non-DT handling code
  2015-01-14 16:22 ` [PATCH 08/12] usb: gadget: at91_udc: Remove non-DT handling code Alexandre Belloni
@ 2015-01-14 17:38   ` Felipe Balbi
  2015-01-14 18:35     ` Alexandre Belloni
  0 siblings, 1 reply; 28+ messages in thread
From: Felipe Balbi @ 2015-01-14 17:38 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Felipe Balbi, Boris Brezillon, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

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

On Wed, Jan 14, 2015 at 05:22:00PM +0100, Alexandre Belloni wrote:
> From: Boris Brezillon <boris.brezillon@free-electrons.com>
> 
> 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 b8e213eb36cc..366e551aeff0 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

will this build with !OF builds ?

-- 
balbi

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

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

* Re: [PATCH 09/12] usb: gadget: at91_udc: Simplify probe and remove functions
  2015-01-14 16:22 ` [PATCH 09/12] usb: gadget: at91_udc: Simplify probe and remove functions Alexandre Belloni
@ 2015-01-14 17:38   ` Felipe Balbi
  0 siblings, 0 replies; 28+ messages in thread
From: Felipe Balbi @ 2015-01-14 17:38 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Felipe Balbi, Boris Brezillon, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

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

On Wed, Jan 14, 2015 at 05:22:01PM +0100, Alexandre Belloni wrote:
> From: Boris Brezillon <boris.brezillon@free-electrons.com>
> 
> Make use of devm_ functions to simplify probe and remove code.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>

Acked-by: Felipe Balbi <balbi@ti.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 be7e16037ac4..4dba2c65dfd4 100644
> --- a/drivers/usb/gadget/udc/at91_udc.c
> +++ b/drivers/usb/gadget/udc/at91_udc.c
> @@ -1710,15 +1710,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;
> @@ -1731,13 +1722,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);
> @@ -1756,32 +1747,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. */
> @@ -1790,18 +1781,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);
>  
>  		/*
> @@ -1818,12 +1812,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 {
> @@ -1832,44 +1827,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");
> @@ -1884,25 +1862,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;
>  }
>  
> -- 
> 2.1.0
> 

-- 
balbi

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

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

* Re: [PATCH 10/12] usb: gadget: at91_udc: Rework for multi-platform kernel support
  2015-01-14 16:22 ` [PATCH 10/12] usb: gadget: at91_udc: Rework for multi-platform kernel support Alexandre Belloni
@ 2015-01-14 17:38   ` Felipe Balbi
  0 siblings, 0 replies; 28+ messages in thread
From: Felipe Balbi @ 2015-01-14 17:38 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Felipe Balbi, Boris Brezillon, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

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

On Wed, Jan 14, 2015 at 05:22:02PM +0100, Alexandre Belloni wrote:
> From: Boris Brezillon <boris.brezillon@free-electrons.com>
> 
> 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>

Acked-by: Felipe Balbi <balbi@ti.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 4dba2c65dfd4..c0abb9bc76a9 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"
>  
> @@ -915,8 +908,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");
> @@ -925,40 +916,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 */
> @@ -1683,12 +1649,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,
> +			   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;
> @@ -1701,6 +1857,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)
> @@ -1709,6 +1869,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;
> @@ -1718,40 +1880,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 */
> @@ -1920,13 +2061,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 e647d1c2ada4..4fc0daa6587f 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)
> -- 
> 2.1.0
> 

-- 
balbi

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

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

* Re: [PATCH 12/12] usb: gadget: at91_udc: Allocate udc instance
  2015-01-14 16:22 ` [PATCH 12/12] usb: gadget: at91_udc: Allocate udc instance Alexandre Belloni
@ 2015-01-14 17:39   ` Felipe Balbi
  0 siblings, 0 replies; 28+ messages in thread
From: Felipe Balbi @ 2015-01-14 17:39 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Felipe Balbi, Boris Brezillon, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

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

On Wed, Jan 14, 2015 at 05:22:04PM +0100, Alexandre Belloni wrote:
> From: Boris Brezillon <boris.brezillon@free-electrons.com>
> 
> Allocate udc structure instead of relying on the statically declared
> object.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>

Acked-by: Felipe Balbi <balbi@ti.com>

> ---
>  drivers/usb/gadget/udc/at91_udc.c | 96 +++++++++++----------------------------
>  1 file changed, 26 insertions(+), 70 deletions(-)
> 
> diff --git a/drivers/usb/gadget/udc/at91_udc.c b/drivers/usb/gadget/udc/at91_udc.c
> index c0abb9bc76a9..6d285226ab94 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)
>  
> @@ -1497,74 +1505,6 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc)
>  
>  /*-------------------------------------------------------------------------*/
>  
> -static struct at91_udc controller = {
> -	.gadget = {
> -		.ops	= &at91_udc_ops,
> -		.ep0	= &controller.ep[0].ep,
> -		.name	= driver_name,
> -	},
> -	.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;
> @@ -1872,15 +1812,31 @@ 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";
>  
> +	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);
> -- 
> 2.1.0
> 

-- 
balbi

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

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

* Re: [PATCH 08/12] usb: gadget: at91_udc: Remove non-DT handling code
  2015-01-14 17:38   ` Felipe Balbi
@ 2015-01-14 18:35     ` Alexandre Belloni
  2015-01-14 18:39       ` Felipe Balbi
  0 siblings, 1 reply; 28+ messages in thread
From: Alexandre Belloni @ 2015-01-14 18:35 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Boris Brezillon, Nicolas Ferre, Jean-Christophe Plagniol-Villard,
	Arnd Bergmann, linux-usb, linux-kernel, linux-arm-kernel,
	Jean-Jacques Hiblot

On 14/01/2015 at 11:38:12 -0600, Felipe Balbi wrote :
> On Wed, Jan 14, 2015 at 05:22:00PM +0100, Alexandre Belloni wrote:
> > From: Boris Brezillon <boris.brezillon@free-electrons.com>
> > 
> > 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 b8e213eb36cc..366e551aeff0 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
> 
> will this build with !OF builds ?
> 

It should, I'll check but it doesn't matter because it depends on
ARCH_AT91 which selects OF.


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

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

* Re: [PATCH 08/12] usb: gadget: at91_udc: Remove non-DT handling code
  2015-01-14 18:35     ` Alexandre Belloni
@ 2015-01-14 18:39       ` Felipe Balbi
  0 siblings, 0 replies; 28+ messages in thread
From: Felipe Balbi @ 2015-01-14 18:39 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Felipe Balbi, Boris Brezillon, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

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

On Wed, Jan 14, 2015 at 07:35:16PM +0100, Alexandre Belloni wrote:
> On 14/01/2015 at 11:38:12 -0600, Felipe Balbi wrote :
> > On Wed, Jan 14, 2015 at 05:22:00PM +0100, Alexandre Belloni wrote:
> > > From: Boris Brezillon <boris.brezillon@free-electrons.com>
> > > 
> > > 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 b8e213eb36cc..366e551aeff0 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
> > 
> > will this build with !OF builds ?
> > 
> 
> It should, I'll check but it doesn't matter because it depends on
> ARCH_AT91 which selects OF.

Missed that line :-)

Acked-by: Felipe Balbi <balbi@ti.com>

-- 
balbi

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

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

* Re: [PATCH 00/12] Atmel matrix, SMC and UDC rework
  2015-01-14 16:21 [PATCH 00/12] Atmel matrix, SMC and UDC rework Alexandre Belloni
                   ` (11 preceding siblings ...)
  2015-01-14 16:22 ` [PATCH 12/12] usb: gadget: at91_udc: Allocate udc instance Alexandre Belloni
@ 2015-01-15 13:30 ` Nicolas Ferre
  12 siblings, 0 replies; 28+ messages in thread
From: Nicolas Ferre @ 2015-01-15 13:30 UTC (permalink / raw)
  To: Alexandre Belloni, Boris Brezillon
  Cc: Felipe Balbi, Jean-Christophe Plagniol-Villard, Arnd Bergmann,
	linux-usb, linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

Le 14/01/2015 17:21, Alexandre Belloni a écrit :
> Hi Felipe,
> 
> The following series replace the previous series sent by Boris named:
>  - [PATCH v5 00/11] memory: add Atmel EBI (External Bus Interface) driver
>  - [PATCH 00/11] usb: gadget: at91_udc: Rework for multi-platform support
> 
> The patches I left out are less urgent and will be resent later, probably for
> 3.21.
> 
> Because of the dependancy between the syscon addition and the at91_udc series,
> this can go through the AT91 tree if you giv your ack on the udc patches.
> 
> The first 4 patches introduce 2 syscon devices needed to configure the
> matrix and SMC.
> The following patches rework 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
> 
> Changes from the previous series:
>  - rebased on 3.19-rc1
>
> Boris Brezillon (12):
>   mfd: syscon: Add atmel-matrix registers definition
>   mfd: syscon: Add Atmel Matrix bus DT binding documentation
>   mfd: syscon: Add atmel-smc registers definition
>   mfd: syscon: Add Atmel SMC binding doc

I already acknowledged these 4 patches as part of another series.

>   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
>   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

I'm fine with all this:
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>

Great, I plan to add them all to the at91-3.20-drivers branch now.

Thanks, best regards.


>  .../devicetree/bindings/mfd/atmel-matrix.txt       |  24 +
>  .../devicetree/bindings/mfd/atmel-smc.txt          |  19 +
>  .../devicetree/bindings/usb/atmel-usb.txt          |  10 +-
>  drivers/usb/gadget/udc/Kconfig                     |   1 +
>  drivers/usb/gadget/udc/at91_udc.c                  | 525 +++++++++++----------
>  drivers/usb/gadget/udc/at91_udc.h                  |   9 +-
>  include/linux/mfd/syscon/atmel-matrix.h            | 117 +++++
>  include/linux/mfd/syscon/atmel-smc.h               | 173 +++++++
>  8 files changed, 623 insertions(+), 255 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/mfd/atmel-matrix.txt
>  create mode 100644 Documentation/devicetree/bindings/mfd/atmel-smc.txt
>  create mode 100644 include/linux/mfd/syscon/atmel-matrix.h
>  create mode 100644 include/linux/mfd/syscon/atmel-smc.h
> 


-- 
Nicolas Ferre

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

* Re: [PATCH 01/12] mfd: syscon: Add atmel-matrix registers definition
  2015-01-14 16:21 ` [PATCH 01/12] mfd: syscon: Add atmel-matrix registers definition Alexandre Belloni
@ 2015-01-18 12:52   ` Lee Jones
  2015-01-18 13:11     ` Boris Brezillon
  0 siblings, 1 reply; 28+ messages in thread
From: Lee Jones @ 2015-01-18 12:52 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Felipe Balbi, Boris Brezillon, Jean-Jacques Hiblot,
	Arnd Bergmann, linux-usb, Nicolas Ferre, linux-kernel,
	Jean-Christophe Plagniol-Villard, linux-arm-kernel

On Wed, 14 Jan 2015, Alexandre Belloni wrote:

> From: Boris Brezillon <boris.brezillon@free-electrons.com>
> 
> AT91 SoCs have a memory range reserved for internal bus configuration.
> Expose those registers so that drivers can make use of the matrix syscon
> declared in at91 DTs.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> Acked-by: Lee Jones <lee.jones@linaro.org>
> ---
>  include/linux/mfd/syscon/atmel-matrix.h | 117 ++++++++++++++++++++++++++++++++
>  1 file changed, 117 insertions(+)
>  create mode 100644 include/linux/mfd/syscon/atmel-matrix.h

Applied, thanks.

> diff --git a/include/linux/mfd/syscon/atmel-matrix.h b/include/linux/mfd/syscon/atmel-matrix.h
> new file mode 100644
> index 000000000000..8293c3e2a82a
> --- /dev/null
> +++ b/include/linux/mfd/syscon/atmel-matrix.h
> @@ -0,0 +1,117 @@
> +/*
> + *  Copyright (C) 2014 Atmel Corporation.
> + *
> + * Memory Controllers (MATRIX, EBI) - System peripherals registers.
> + *
> + * 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.
> + */
> +
> +#ifndef _LINUX_MFD_SYSCON_ATMEL_MATRIX_H
> +#define _LINUX_MFD_SYSCON_ATMEL_MATRIX_H
> +
> +#define AT91SAM9260_MATRIX_MCFG			0x00
> +#define AT91SAM9260_MATRIX_SCFG			0x40
> +#define AT91SAM9260_MATRIX_PRS			0x80
> +#define AT91SAM9260_MATRIX_MRCR			0x100
> +#define AT91SAM9260_MATRIX_EBICSA		0x11c
> +
> +#define AT91SAM9261_MATRIX_MRCR			0x0
> +#define AT91SAM9261_MATRIX_SCFG			0x4
> +#define AT91SAM9261_MATRIX_TCR			0x24
> +#define AT91SAM9261_MATRIX_EBICSA		0x30
> +#define AT91SAM9261_MATRIX_USBPUCR		0x34
> +
> +#define AT91SAM9263_MATRIX_MCFG			0x00
> +#define AT91SAM9263_MATRIX_SCFG			0x40
> +#define AT91SAM9263_MATRIX_PRS			0x80
> +#define AT91SAM9263_MATRIX_MRCR			0x100
> +#define AT91SAM9263_MATRIX_TCR			0x114
> +#define AT91SAM9263_MATRIX_EBI0CSA		0x120
> +#define AT91SAM9263_MATRIX_EBI1CSA		0x124
> +
> +#define AT91SAM9RL_MATRIX_MCFG			0x00
> +#define AT91SAM9RL_MATRIX_SCFG			0x40
> +#define AT91SAM9RL_MATRIX_PRS			0x80
> +#define AT91SAM9RL_MATRIX_MRCR			0x100
> +#define AT91SAM9RL_MATRIX_TCR			0x114
> +#define AT91SAM9RL_MATRIX_EBICSA		0x120
> +
> +#define AT91SAM9G45_MATRIX_MCFG			0x00
> +#define AT91SAM9G45_MATRIX_SCFG			0x40
> +#define AT91SAM9G45_MATRIX_PRS			0x80
> +#define AT91SAM9G45_MATRIX_MRCR			0x100
> +#define AT91SAM9G45_MATRIX_TCR			0x110
> +#define AT91SAM9G45_MATRIX_DDRMPR		0x118
> +#define AT91SAM9G45_MATRIX_EBICSA		0x128
> +
> +#define AT91SAM9N12_MATRIX_MCFG			0x00
> +#define AT91SAM9N12_MATRIX_SCFG			0x40
> +#define AT91SAM9N12_MATRIX_PRS			0x80
> +#define AT91SAM9N12_MATRIX_MRCR			0x100
> +#define AT91SAM9N12_MATRIX_EBICSA		0x118
> +
> +#define AT91SAM9X5_MATRIX_MCFG			0x00
> +#define AT91SAM9X5_MATRIX_SCFG			0x40
> +#define AT91SAM9X5_MATRIX_PRS			0x80
> +#define AT91SAM9X5_MATRIX_MRCR			0x100
> +#define AT91SAM9X5_MATRIX_EBICSA		0x120
> +
> +#define SAMA5D3_MATRIX_MCFG			0x00
> +#define SAMA5D3_MATRIX_SCFG			0x40
> +#define SAMA5D3_MATRIX_PRS			0x80
> +#define SAMA5D3_MATRIX_MRCR			0x100
> +
> +#define AT91_MATRIX_MCFG(o, x)			((o) + ((x) * 0x4))
> +#define AT91_MATRIX_ULBT			GENMASK(2, 0)
> +#define AT91_MATRIX_ULBT_INFINITE		(0 << 0)
> +#define AT91_MATRIX_ULBT_SINGLE			(1 << 0)
> +#define AT91_MATRIX_ULBT_FOUR			(2 << 0)
> +#define AT91_MATRIX_ULBT_EIGHT			(3 << 0)
> +#define AT91_MATRIX_ULBT_SIXTEEN		(4 << 0)
> +
> +#define AT91_MATRIX_SCFG(o, x)			((o) + ((x) * 0x4))
> +#define AT91_MATRIX_SLOT_CYCLE			GENMASK(7,  0)
> +#define AT91_MATRIX_DEFMSTR_TYPE		GENMASK(17, 16)
> +#define AT91_MATRIX_DEFMSTR_TYPE_NONE		(0 << 16)
> +#define AT91_MATRIX_DEFMSTR_TYPE_LAST		(1 << 16)
> +#define AT91_MATRIX_DEFMSTR_TYPE_FIXED		(2 << 16)
> +#define AT91_MATRIX_FIXED_DEFMSTR		GENMASK(20, 18)
> +#define AT91_MATRIX_ARBT			GENMASK(25, 24)
> +#define AT91_MATRIX_ARBT_ROUND_ROBIN		(0 << 24)
> +#define AT91_MATRIX_ARBT_FIXED_PRIORITY		(1 << 24)
> +
> +#define AT91_MATRIX_ITCM_SIZE			GENMASK(3, 0)
> +#define AT91_MATRIX_ITCM_0			(0 << 0)
> +#define AT91_MATRIX_ITCM_16			(5 << 0)
> +#define AT91_MATRIX_ITCM_32			(6 << 0)
> +#define AT91_MATRIX_ITCM_64			(7 << 0)
> +#define	AT91_MATRIX_DTCM_SIZE			GENMASK(7, 4)
> +#define	AT91_MATRIX_DTCM_0			(0 << 4)
> +#define	AT91_MATRIX_DTCM_16			(5 << 4)
> +#define AT91_MATRIX_DTCM_32			(6 << 4)
> +#define AT91_MATRIX_DTCM_64			(7 << 4)
> +
> +#define AT91_MATRIX_PRAS(o, x)			((o) + ((x) * 0x8))
> +#define AT91_MATRIX_PRBS(o, x)			((o) + ((x) * 0x8) + 0x4)
> +#define AT91_MATRIX_MPR(x)			GENMASK(((x) * 0x4) + 1, ((x) * 0x4))
> +
> +#define AT91_MATRIX_RCB(x)			BIT(x)
> +
> +#define AT91_MATRIX_CSA(cs, val)		(val << (cs))
> +#define AT91_MATRIX_DBPUC			BIT(8)
> +#define AT91_MATRIX_DBPDC			BIT(9)
> +#define AT91_MATRIX_VDDIOMSEL			BIT(16)
> +#define AT91_MATRIX_VDDIOMSEL_1_8V		(0 << 16)
> +#define AT91_MATRIX_VDDIOMSEL_3_3V		(1 << 16)
> +#define AT91_MATRIX_EBI_IOSR			BIT(17)
> +#define AT91_MATRIX_DDR_IOSR			BIT(18)
> +#define AT91_MATRIX_NFD0_SELECT			BIT(24)
> +#define AT91_MATRIX_DDR_MP_EN			BIT(25)
> +#define AT91_MATRIX_EBI_NUM_CS			8
> +
> +#define AT91_MATRIX_USBPUCR_PUON		BIT(30)
> +
> +#endif /* _LINUX_MFD_SYSCON_ATMEL_MATRIX_H */

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

* Re: [PATCH 02/12] mfd: syscon: Add Atmel Matrix bus DT binding documentation
  2015-01-14 16:21 ` [PATCH 02/12] mfd: syscon: Add Atmel Matrix bus DT binding documentation Alexandre Belloni
@ 2015-01-18 12:53   ` Lee Jones
  0 siblings, 0 replies; 28+ messages in thread
From: Lee Jones @ 2015-01-18 12:53 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Felipe Balbi, Boris Brezillon, Nicolas Ferre,
	Jean-Christophe Plagniol-Villard, Arnd Bergmann, linux-usb,
	linux-kernel, linux-arm-kernel, Jean-Jacques Hiblot

On Wed, 14 Jan 2015, Alexandre Belloni wrote:

> From: Boris Brezillon <boris.brezillon@free-electrons.com>
> 
> The Matrix registers are provided to configure internal bus behavior on
> at91 SoCs.
> Some registers might be accessed by several drivers (e.g. to configure
> external memory bus timings), hence we declare this register set as a
> syscon device.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> Acked-by: Lee Jones <lee.jones@linaro.org>
> ---
>  .../devicetree/bindings/mfd/atmel-matrix.txt       | 24 ++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/mfd/atmel-matrix.txt

Applied, thanks.
 
> diff --git a/Documentation/devicetree/bindings/mfd/atmel-matrix.txt b/Documentation/devicetree/bindings/mfd/atmel-matrix.txt
> new file mode 100644
> index 000000000000..e3ef50ca02a5
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mfd/atmel-matrix.txt
> @@ -0,0 +1,24 @@
> +* Device tree bindings for Atmel Bus Matrix
> +
> +The Bus Matrix registers are used to configure Atmel SoCs internal bus
> +behavior (master/slave priorities, undefined burst length type, ...)
> +
> +Required properties:
> +- compatible:		Should be one of the following
> +			"atmel,at91sam9260-matrix", "syscon"
> +			"atmel,at91sam9261-matrix", "syscon"
> +			"atmel,at91sam9263-matrix", "syscon"
> +			"atmel,at91sam9rl-matrix", "syscon"
> +			"atmel,at91sam9g45-matrix", "syscon"
> +			"atmel,at91sam9n12-matrix", "syscon"
> +			"atmel,at91sam9x5-matrix", "syscon"
> +			"atmel,sama5d3-matrix", "syscon"
> +- reg:			Contains offset/length value of the Bus Matrix
> +			memory region.
> +
> +Example:
> +
> +matrix: matrix@ffffec00 {
> +	compatible = "atmel,sama5d3-matrix", "syscon";
> +	reg = <0xffffec00 0x200>;
> +};

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

* Re: [PATCH 03/12] mfd: syscon: Add atmel-smc registers definition
  2015-01-14 16:21 ` [PATCH 03/12] mfd: syscon: Add atmel-smc registers definition Alexandre Belloni
@ 2015-01-18 12:53   ` Lee Jones
  0 siblings, 0 replies; 28+ messages in thread
From: Lee Jones @ 2015-01-18 12:53 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Felipe Balbi, Boris Brezillon, Jean-Jacques Hiblot,
	Arnd Bergmann, linux-usb, Nicolas Ferre, linux-kernel,
	Jean-Christophe Plagniol-Villard, linux-arm-kernel

On Wed, 14 Jan 2015, Alexandre Belloni wrote:

> From: Boris Brezillon <boris.brezillon@free-electrons.com>
> 
> Atmel AT91 SoCs have a memory range reserved for SMC (Static Memory
> Controller) configuration.
> Expose those registers so that drivers can make use of the smc syscon
> declared in at91 DTs.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> Acked-by: Lee Jones <lee.jones@linaro.org>
> ---
>  include/linux/mfd/syscon/atmel-smc.h | 173 +++++++++++++++++++++++++++++++++++
>  1 file changed, 173 insertions(+)
>  create mode 100644 include/linux/mfd/syscon/atmel-smc.h

Applied, thanks.
 
> diff --git a/include/linux/mfd/syscon/atmel-smc.h b/include/linux/mfd/syscon/atmel-smc.h
> new file mode 100644
> index 000000000000..be6ebe64eebe
> --- /dev/null
> +++ b/include/linux/mfd/syscon/atmel-smc.h
> @@ -0,0 +1,173 @@
> +/*
> + * Atmel SMC (Static Memory Controller) register offsets and bit definitions.
> + *
> + * Copyright (C) 2014 Atmel
> + * Copyright (C) 2014 Free Electrons
> + *
> + * Author: Boris Brezillon <boris.brezillon@free-electrons.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +#ifndef _LINUX_MFD_SYSCON_ATMEL_SMC_H_
> +#define _LINUX_MFD_SYSCON_ATMEL_SMC_H_
> +
> +#include <linux/kernel.h>
> +#include <linux/regmap.h>
> +
> +#define AT91SAM9_SMC_GENERIC		0x00
> +#define AT91SAM9_SMC_GENERIC_BLK_SZ	0x10
> +
> +#define SAMA5_SMC_GENERIC		0x600
> +#define SAMA5_SMC_GENERIC_BLK_SZ	0x14
> +
> +#define AT91SAM9_SMC_SETUP(o)		((o) + 0x00)
> +#define AT91SAM9_SMC_NWESETUP(x)	(x)
> +#define AT91SAM9_SMC_NCS_WRSETUP(x)	((x) << 8)
> +#define AT91SAM9_SMC_NRDSETUP(x)	((x) << 16)
> +#define AT91SAM9_SMC_NCS_NRDSETUP(x)	((x) << 24)
> +
> +#define AT91SAM9_SMC_PULSE(o)		((o) + 0x04)
> +#define AT91SAM9_SMC_NWEPULSE(x)	(x)
> +#define AT91SAM9_SMC_NCS_WRPULSE(x)	((x) << 8)
> +#define AT91SAM9_SMC_NRDPULSE(x)	((x) << 16)
> +#define AT91SAM9_SMC_NCS_NRDPULSE(x)	((x) << 24)
> +
> +#define AT91SAM9_SMC_CYCLE(o)		((o) + 0x08)
> +#define AT91SAM9_SMC_NWECYCLE(x)	(x)
> +#define AT91SAM9_SMC_NRDCYCLE(x)	((x) << 16)
> +
> +#define AT91SAM9_SMC_MODE(o)		((o) + 0x0c)
> +#define SAMA5_SMC_MODE(o)		((o) + 0x10)
> +#define AT91_SMC_READMODE		BIT(0)
> +#define AT91_SMC_READMODE_NCS		(0 << 0)
> +#define AT91_SMC_READMODE_NRD		(1 << 0)
> +#define AT91_SMC_WRITEMODE		BIT(1)
> +#define AT91_SMC_WRITEMODE_NCS		(0 << 1)
> +#define AT91_SMC_WRITEMODE_NWE		(1 << 1)
> +#define AT91_SMC_EXNWMODE		GENMASK(5, 4)
> +#define AT91_SMC_EXNWMODE_DISABLE	(0 << 4)
> +#define AT91_SMC_EXNWMODE_FROZEN	(2 << 4)
> +#define AT91_SMC_EXNWMODE_READY		(3 << 4)
> +#define AT91_SMC_BAT			BIT(8)
> +#define AT91_SMC_BAT_SELECT		(0 << 8)
> +#define AT91_SMC_BAT_WRITE		(1 << 8)
> +#define AT91_SMC_DBW			GENMASK(13, 12)
> +#define AT91_SMC_DBW_8			(0 << 12)
> +#define AT91_SMC_DBW_16			(1 << 12)
> +#define AT91_SMC_DBW_32			(2 << 12)
> +#define AT91_SMC_TDF			GENMASK(19, 16)
> +#define AT91_SMC_TDF_(x)		((((x) - 1) << 16) & AT91_SMC_TDF)
> +#define AT91_SMC_TDF_MAX		16
> +#define AT91_SMC_TDFMODE_OPTIMIZED	BIT(20)
> +#define AT91_SMC_PMEN			BIT(24)
> +#define AT91_SMC_PS			GENMASK(29, 28)
> +#define AT91_SMC_PS_4			(0 << 28)
> +#define AT91_SMC_PS_8			(1 << 28)
> +#define AT91_SMC_PS_16			(2 << 28)
> +#define AT91_SMC_PS_32			(3 << 28)
> +
> +
> +/*
> + * This function converts a setup timing expressed in nanoseconds into an
> + * encoded value that can be written in the SMC_SETUP register.
> + *
> + * The following formula is described in atmel datasheets (section
> + * "SMC Setup Register"):
> + *
> + * setup length = (128* SETUP[5] + SETUP[4:0])
> + *
> + * where setup length is the timing expressed in cycles.
> + */
> +static inline u32 at91sam9_smc_setup_ns_to_cycles(unsigned int clk_rate,
> +						  u32 timing_ns)
> +{
> +	u32 clk_period = DIV_ROUND_UP(NSEC_PER_SEC, clk_rate);
> +	u32 coded_cycles = 0;
> +	u32 cycles;
> +
> +	cycles = DIV_ROUND_UP(timing_ns, clk_period);
> +	if (cycles / 32) {
> +		coded_cycles |= 1 << 5;
> +		if (cycles < 128)
> +			cycles = 0;
> +	}
> +
> +	coded_cycles |= cycles % 32;
> +
> +	return coded_cycles;
> +}
> +
> +/*
> + * This function converts a pulse timing expressed in nanoseconds into an
> + * encoded value that can be written in the SMC_PULSE register.
> + *
> + * The following formula is described in atmel datasheets (section
> + * "SMC Pulse Register"):
> + *
> + * pulse length = (256* PULSE[6] + PULSE[5:0])
> + *
> + * where pulse length is the timing expressed in cycles.
> + */
> +static inline u32 at91sam9_smc_pulse_ns_to_cycles(unsigned int clk_rate,
> +						  u32 timing_ns)
> +{
> +	u32 clk_period = DIV_ROUND_UP(NSEC_PER_SEC, clk_rate);
> +	u32 coded_cycles = 0;
> +	u32 cycles;
> +
> +	cycles = DIV_ROUND_UP(timing_ns, clk_period);
> +	if (cycles / 64) {
> +		coded_cycles |= 1 << 6;
> +		if (cycles < 256)
> +			cycles = 0;
> +	}
> +
> +	coded_cycles |= cycles % 64;
> +
> +	return coded_cycles;
> +}
> +
> +/*
> + * This function converts a cycle timing expressed in nanoseconds into an
> + * encoded value that can be written in the SMC_CYCLE register.
> + *
> + * The following formula is described in atmel datasheets (section
> + * "SMC Cycle Register"):
> + *
> + * cycle length = (CYCLE[8:7]*256 + CYCLE[6:0])
> + *
> + * where cycle length is the timing expressed in cycles.
> + */
> +static inline u32 at91sam9_smc_cycle_ns_to_cycles(unsigned int clk_rate,
> +						  u32 timing_ns)
> +{
> +	u32 clk_period = DIV_ROUND_UP(NSEC_PER_SEC, clk_rate);
> +	u32 coded_cycles = 0;
> +	u32 cycles;
> +
> +	cycles = DIV_ROUND_UP(timing_ns, clk_period);
> +	if (cycles / 128) {
> +		coded_cycles = cycles / 256;
> +		cycles %= 256;
> +		if (cycles >= 128) {
> +			coded_cycles++;
> +			cycles = 0;
> +		}
> +
> +		if (coded_cycles > 0x3) {
> +			coded_cycles = 0x3;
> +			cycles = 0x7f;
> +		}
> +
> +		coded_cycles <<= 7;
> +	}
> +
> +	coded_cycles |= cycles % 128;
> +
> +	return coded_cycles;
> +}
> +
> +#endif /* _LINUX_MFD_SYSCON_ATMEL_SMC_H_ */

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

* Re: [PATCH 04/12] mfd: syscon: Add Atmel SMC binding doc
  2015-01-14 16:21 ` [PATCH 04/12] mfd: syscon: Add Atmel SMC binding doc Alexandre Belloni
@ 2015-01-18 12:54   ` Lee Jones
  0 siblings, 0 replies; 28+ messages in thread
From: Lee Jones @ 2015-01-18 12:54 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Felipe Balbi, Boris Brezillon, Jean-Jacques Hiblot,
	Arnd Bergmann, linux-usb, Nicolas Ferre, linux-kernel,
	Jean-Christophe Plagniol-Villard, linux-arm-kernel

On Wed, 14 Jan 2015, Alexandre Belloni wrote:

> From: Boris Brezillon <boris.brezillon@free-electrons.com>
> 
> The SMC registers are used to configure Atmel EBI (External Bus Interface)
> to interface with standard memory devices (NAND, NOR, SRAM or specialized
> devices like FPGAs).
> 
> Declare this memory region as a syscon, so that different drivers can
> configure the SMC interface (mostly timing configuration) according to
> their need.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> Acked-by: Lee Jones <lee.jones@linaro.org>
> ---
>  Documentation/devicetree/bindings/mfd/atmel-smc.txt | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/mfd/atmel-smc.txt

Applied, thanks.
 
> diff --git a/Documentation/devicetree/bindings/mfd/atmel-smc.txt b/Documentation/devicetree/bindings/mfd/atmel-smc.txt
> new file mode 100644
> index 000000000000..26eeed373934
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mfd/atmel-smc.txt
> @@ -0,0 +1,19 @@
> +* Device tree bindings for Atmel SMC (Static Memory Controller)
> +
> +The SMC registers are used to configure Atmel EBI (External Bus Interface)
> +to interface with standard memory devices (NAND, NOR, SRAM or specialized
> +devices like FPGAs).
> +
> +Required properties:
> +- compatible:		Should be one of the following
> +			"atmel,at91sam9260-smc", "syscon"
> +			"atmel,sama5d3-smc", "syscon"
> +- reg:			Contains offset/length value of the SMC memory
> +			region.
> +
> +Example:
> +
> +smc: smc@ffffc000 {
> +	compatible = "atmel,sama5d3-smc", "syscon";
> +	reg = <0xffffc000 0x1000>;
> +};

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

* Re: [PATCH 01/12] mfd: syscon: Add atmel-matrix registers definition
  2015-01-18 12:52   ` Lee Jones
@ 2015-01-18 13:11     ` Boris Brezillon
  2015-01-19  8:16       ` Lee Jones
  0 siblings, 1 reply; 28+ messages in thread
From: Boris Brezillon @ 2015-01-18 13:11 UTC (permalink / raw)
  To: Lee Jones
  Cc: Alexandre Belloni, Felipe Balbi, Jean-Jacques Hiblot,
	Arnd Bergmann, linux-usb, Nicolas Ferre, linux-kernel,
	Jean-Christophe Plagniol-Villard, linux-arm-kernel

Hi Lee,

On Sun, 18 Jan 2015 12:52:59 +0000
Lee Jones <lee.jones@linaro.org> wrote:

> On Wed, 14 Jan 2015, Alexandre Belloni wrote:
> 
> > From: Boris Brezillon <boris.brezillon@free-electrons.com>
> > 
> > AT91 SoCs have a memory range reserved for internal bus configuration.
> > Expose those registers so that drivers can make use of the matrix syscon
> > declared in at91 DTs.
> > 
> > Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> > Acked-by: Lee Jones <lee.jones@linaro.org>
> > ---
> >  include/linux/mfd/syscon/atmel-matrix.h | 117 ++++++++++++++++++++++++++++++++
> >  1 file changed, 117 insertions(+)
> >  create mode 100644 include/linux/mfd/syscon/atmel-matrix.h
> 
> Applied, thanks.

Actually Nicolas took all the patches in his tree and already sent a PR
to the arm-soc maintainers [1].

Best Regards,

Boris

[1]https://lkml.org/lkml/2015/1/15/542

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

* Re: [PATCH 01/12] mfd: syscon: Add atmel-matrix registers definition
  2015-01-18 13:11     ` Boris Brezillon
@ 2015-01-19  8:16       ` Lee Jones
  0 siblings, 0 replies; 28+ messages in thread
From: Lee Jones @ 2015-01-19  8:16 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Alexandre Belloni, Felipe Balbi, Jean-Jacques Hiblot,
	Arnd Bergmann, linux-usb, Nicolas Ferre, linux-kernel,
	Jean-Christophe Plagniol-Villard, linux-arm-kernel

On Sun, 18 Jan 2015, Boris Brezillon wrote:

> Hi Lee,
> 
> On Sun, 18 Jan 2015 12:52:59 +0000
> Lee Jones <lee.jones@linaro.org> wrote:
> 
> > On Wed, 14 Jan 2015, Alexandre Belloni wrote:
> > 
> > > From: Boris Brezillon <boris.brezillon@free-electrons.com>
> > > 
> > > AT91 SoCs have a memory range reserved for internal bus configuration.
> > > Expose those registers so that drivers can make use of the matrix syscon
> > > declared in at91 DTs.
> > > 
> > > Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> > > Acked-by: Lee Jones <lee.jones@linaro.org>
> > > ---
> > >  include/linux/mfd/syscon/atmel-matrix.h | 117 ++++++++++++++++++++++++++++++++
> > >  1 file changed, 117 insertions(+)
> > >  create mode 100644 include/linux/mfd/syscon/atmel-matrix.h
> > 
> > Applied, thanks.
> 
> Actually Nicolas took all the patches in his tree and already sent a PR
> to the arm-soc maintainers [1].
> 
> [1]https://lkml.org/lkml/2015/1/15/542

Very well.  All unapplied.

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

end of thread, other threads:[~2015-01-19  8:16 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-14 16:21 [PATCH 00/12] Atmel matrix, SMC and UDC rework Alexandre Belloni
2015-01-14 16:21 ` [PATCH 01/12] mfd: syscon: Add atmel-matrix registers definition Alexandre Belloni
2015-01-18 12:52   ` Lee Jones
2015-01-18 13:11     ` Boris Brezillon
2015-01-19  8:16       ` Lee Jones
2015-01-14 16:21 ` [PATCH 02/12] mfd: syscon: Add Atmel Matrix bus DT binding documentation Alexandre Belloni
2015-01-18 12:53   ` Lee Jones
2015-01-14 16:21 ` [PATCH 03/12] mfd: syscon: Add atmel-smc registers definition Alexandre Belloni
2015-01-18 12:53   ` Lee Jones
2015-01-14 16:21 ` [PATCH 04/12] mfd: syscon: Add Atmel SMC binding doc Alexandre Belloni
2015-01-18 12:54   ` Lee Jones
2015-01-14 16:21 ` [PATCH 05/12] usb: gadget: at91_udc: Fix clock names Alexandre Belloni
2015-01-14 17:37   ` Felipe Balbi
2015-01-14 16:21 ` [PATCH 06/12] usb: gadget: at91_udc: Drop uclk clock Alexandre Belloni
2015-01-14 17:37   ` Felipe Balbi
2015-01-14 16:21 ` [PATCH 07/12] usb: gadget: at91_udc: Document DT clocks and clock-names property Alexandre Belloni
2015-01-14 16:22 ` [PATCH 08/12] usb: gadget: at91_udc: Remove non-DT handling code Alexandre Belloni
2015-01-14 17:38   ` Felipe Balbi
2015-01-14 18:35     ` Alexandre Belloni
2015-01-14 18:39       ` Felipe Balbi
2015-01-14 16:22 ` [PATCH 09/12] usb: gadget: at91_udc: Simplify probe and remove functions Alexandre Belloni
2015-01-14 17:38   ` Felipe Balbi
2015-01-14 16:22 ` [PATCH 10/12] usb: gadget: at91_udc: Rework for multi-platform kernel support Alexandre Belloni
2015-01-14 17:38   ` Felipe Balbi
2015-01-14 16:22 ` [PATCH 11/12] usb: gadget: at91_udc: Update DT binding documentation Alexandre Belloni
2015-01-14 16:22 ` [PATCH 12/12] usb: gadget: at91_udc: Allocate udc instance Alexandre Belloni
2015-01-14 17:39   ` Felipe Balbi
2015-01-15 13:30 ` [PATCH 00/12] Atmel matrix, SMC and UDC rework Nicolas Ferre

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).