linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: ryan@bluewatersys.com (Ryan Mallon)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH 13/23] at91: Make PWM device common
Date: Wed, 20 Apr 2011 13:10:17 +1200	[thread overview]
Message-ID: <1303261827-27730-15-git-send-email-ryan@bluewatersys.com> (raw)
In-Reply-To: <1303261827-27730-1-git-send-email-ryan@bluewatersys.com>

Replace the individual PWM code for each at91 variant with a single
implementation in devices.c

Signed-off-by: Ryan Mallon <ryan@bluewatersys.com>
---
 arch/arm/mach-at91/at91cap9_devices.c    |   56 +++++-------------------------
 arch/arm/mach-at91/at91sam9263_devices.c |   55 +++++------------------------
 arch/arm/mach-at91/at91sam9g45_devices.c |   55 +++++------------------------
 arch/arm/mach-at91/at91sam9rl_devices.c  |   55 +++++------------------------
 arch/arm/mach-at91/devices.c             |   55 +++++++++++++++++++++++++++++
 arch/arm/mach-at91/devices.h             |    7 ++++
 6 files changed, 98 insertions(+), 185 deletions(-)

diff --git a/arch/arm/mach-at91/at91cap9_devices.c b/arch/arm/mach-at91/at91cap9_devices.c
index 9aa7b40..d127f5b 100644
--- a/arch/arm/mach-at91/at91cap9_devices.c
+++ b/arch/arm/mach-at91/at91cap9_devices.c
@@ -302,56 +302,17 @@ static struct __initdata at91_dev_table_rtt device_rtt = {
  *  PWM
  * --------------------------------------------------------------------*/
 
-#if defined(CONFIG_ATMEL_PWM)
-static u32 pwm_mask;
-
-static struct resource pwm_resources[] = {
-	[0] = {
-		.start	= AT91CAP9_BASE_PWMC,
-		.end	= AT91CAP9_BASE_PWMC + SZ_16K - 1,
-		.flags	= IORESOURCE_MEM,
-	},
-	[1] = {
-		.start	= AT91CAP9_ID_PWMC,
-		.end	= AT91CAP9_ID_PWMC,
-		.flags	= IORESOURCE_IRQ,
+static struct __initdata at91_dev_table_pwm device_pwm = {
+	.mmio_base	= AT91CAP9_BASE_PWMC,
+	.irq		= AT91CAP9_ID_PWMC,
+	.pwm_pins	= {
+		{AT91_PIN_PB19, AT91_PIN_PERIPH_A, 1, 0, 0},
+		{AT91_PIN_PB8,  AT91_PIN_PERIPH_B, 1, 0, 0},
+		{AT91_PIN_PC29, AT91_PIN_PERIPH_B, 1, 0, 0},
+		{AT91_PIN_PA11, AT91_PIN_PERIPH_B, 1, 0, 0},
 	},
 };
 
-static struct platform_device at91cap9_pwm0_device = {
-	.name	= "atmel_pwm",
-	.id	= -1,
-	.dev	= {
-		.platform_data		= &pwm_mask,
-	},
-	.resource	= pwm_resources,
-	.num_resources	= ARRAY_SIZE(pwm_resources),
-};
-
-void __init at91_add_device_pwm(u32 mask)
-{
-	if (mask & (1 << AT91_PWM0))
-		at91_set_A_periph(AT91_PIN_PB19, 1);	/* enable PWM0 */
-
-	if (mask & (1 << AT91_PWM1))
-		at91_set_B_periph(AT91_PIN_PB8, 1);	/* enable PWM1 */
-
-	if (mask & (1 << AT91_PWM2))
-		at91_set_B_periph(AT91_PIN_PC29, 1);	/* enable PWM2 */
-
-	if (mask & (1 << AT91_PWM3))
-		at91_set_B_periph(AT91_PIN_PA11, 1);	/* enable PWM3 */
-
-	pwm_mask = mask;
-
-	platform_device_register(&at91cap9_pwm0_device);
-}
-#else
-void __init at91_add_device_pwm(u32 mask) {}
-#endif
-
-
-
 /* --------------------------------------------------------------------
  *  AC97
  * -------------------------------------------------------------------- */
@@ -679,6 +640,7 @@ static struct at91_device_table __initdata at91cap9_device_table = {
 	.uart[0]	= &device_uart0,
 	.uart[1]	= &device_uart1,
 	.uart[2]	= &device_uart2,
+	.pwm		= &device_pwm,
 };
 
 void __init at91cap9_init_devices(void)
diff --git a/arch/arm/mach-at91/at91sam9263_devices.c b/arch/arm/mach-at91/at91sam9263_devices.c
index e5f0164..1ffd044 100644
--- a/arch/arm/mach-at91/at91sam9263_devices.c
+++ b/arch/arm/mach-at91/at91sam9263_devices.c
@@ -536,55 +536,17 @@ static struct __initdata at91_dev_table_rtt device_rtt1 = {
  *  PWM
  * --------------------------------------------------------------------*/
 
-#if defined(CONFIG_ATMEL_PWM)
-static u32 pwm_mask;
-
-static struct resource pwm_resources[] = {
-	[0] = {
-		.start	= AT91SAM9263_BASE_PWMC,
-		.end	= AT91SAM9263_BASE_PWMC + SZ_16K - 1,
-		.flags	= IORESOURCE_MEM,
-	},
-	[1] = {
-		.start	= AT91SAM9263_ID_PWMC,
-		.end	= AT91SAM9263_ID_PWMC,
-		.flags	= IORESOURCE_IRQ,
+static struct __initdata at91_dev_table_pwm device_pwm = {
+	.mmio_base	= AT91SAM9263_BASE_PWMC,
+	.irq		= AT91SAM9263_ID_PWMC,
+	.pwm_pins	= {
+		{AT91_PIN_PB7,  AT91_PIN_PERIPH_B, 1, 0, 0},
+		{AT91_PIN_PB8,  AT91_PIN_PERIPH_B, 1, 0, 0},
+		{AT91_PIN_PC29, AT91_PIN_PERIPH_B, 1, 0, 0},
+		{AT91_PIN_PB29, AT91_PIN_PERIPH_B, 1, 0, 0},
 	},
 };
 
-static struct platform_device at91sam9263_pwm0_device = {
-	.name	= "atmel_pwm",
-	.id	= -1,
-	.dev	= {
-		.platform_data		= &pwm_mask,
-	},
-	.resource	= pwm_resources,
-	.num_resources	= ARRAY_SIZE(pwm_resources),
-};
-
-void __init at91_add_device_pwm(u32 mask)
-{
-	if (mask & (1 << AT91_PWM0))
-		at91_set_B_periph(AT91_PIN_PB7, 1);	/* enable PWM0 */
-
-	if (mask & (1 << AT91_PWM1))
-		at91_set_B_periph(AT91_PIN_PB8, 1);	/* enable PWM1 */
-
-	if (mask & (1 << AT91_PWM2))
-		at91_set_B_periph(AT91_PIN_PC29, 1);	/* enable PWM2 */
-
-	if (mask & (1 << AT91_PWM3))
-		at91_set_B_periph(AT91_PIN_PB29, 1);	/* enable PWM3 */
-
-	pwm_mask = mask;
-
-	platform_device_register(&at91sam9263_pwm0_device);
-}
-#else
-void __init at91_add_device_pwm(u32 mask) {}
-#endif
-
-
 /* --------------------------------------------------------------------
  *  SSC -- Synchronous Serial Controller
  * -------------------------------------------------------------------- */
@@ -787,6 +749,7 @@ static struct at91_device_table __initdata at91sam9263_device_table = {
 	.uart[0]	= &device_uart0,
 	.uart[1]	= &device_uart1,
 	.uart[2]	= &device_uart2,
+	.pwm		= &device_pwm,
 };
 
 void __init at91sam9263_init_devices(void)
diff --git a/arch/arm/mach-at91/at91sam9g45_devices.c b/arch/arm/mach-at91/at91sam9g45_devices.c
index c832917..0f11c56 100644
--- a/arch/arm/mach-at91/at91sam9g45_devices.c
+++ b/arch/arm/mach-at91/at91sam9g45_devices.c
@@ -569,55 +569,17 @@ static struct __initdata at91_dev_table_rtt device_rtt = {
  *  PWM
  * --------------------------------------------------------------------*/
 
-#if defined(CONFIG_ATMEL_PWM) || defined(CONFIG_ATMEL_PWM_MODULE)
-static u32 pwm_mask;
-
-static struct resource pwm_resources[] = {
-	[0] = {
-		.start	= AT91SAM9G45_BASE_PWMC,
-		.end	= AT91SAM9G45_BASE_PWMC + SZ_16K - 1,
-		.flags	= IORESOURCE_MEM,
-	},
-	[1] = {
-		.start	= AT91SAM9G45_ID_PWMC,
-		.end	= AT91SAM9G45_ID_PWMC,
-		.flags	= IORESOURCE_IRQ,
+static struct __initdata at91_dev_table_pwm device_pwm = {
+	.mmio_base	= AT91SAM9G45_BASE_PWMC,
+	.irq		= AT91SAM9G45_ID_PWMC,
+	.pwm_pins	= {
+		{AT91_PIN_PD24, AT91_PIN_PERIPH_B, 1, 0, 0},
+		{AT91_PIN_PD31, AT91_PIN_PERIPH_B, 1, 0, 0},
+		{AT91_PIN_PD26, AT91_PIN_PERIPH_B, 1, 0, 0},
+		{AT91_PIN_PD0,  AT91_PIN_PERIPH_B, 1, 0, 0},
 	},
 };
 
-static struct platform_device at91sam9g45_pwm0_device = {
-	.name	= "atmel_pwm",
-	.id	= -1,
-	.dev	= {
-		.platform_data		= &pwm_mask,
-	},
-	.resource	= pwm_resources,
-	.num_resources	= ARRAY_SIZE(pwm_resources),
-};
-
-void __init at91_add_device_pwm(u32 mask)
-{
-	if (mask & (1 << AT91_PWM0))
-		at91_set_B_periph(AT91_PIN_PD24, 1);	/* enable PWM0 */
-
-	if (mask & (1 << AT91_PWM1))
-		at91_set_B_periph(AT91_PIN_PD31, 1);	/* enable PWM1 */
-
-	if (mask & (1 << AT91_PWM2))
-		at91_set_B_periph(AT91_PIN_PD26, 1);	/* enable PWM2 */
-
-	if (mask & (1 << AT91_PWM3))
-		at91_set_B_periph(AT91_PIN_PD0, 1);	/* enable PWM3 */
-
-	pwm_mask = mask;
-
-	platform_device_register(&at91sam9g45_pwm0_device);
-}
-#else
-void __init at91_add_device_pwm(u32 mask) {}
-#endif
-
-
 /* --------------------------------------------------------------------
  *  SSC -- Synchronous Serial Controller
  * -------------------------------------------------------------------- */
@@ -836,6 +798,7 @@ static struct at91_device_table __initdata at91sam9g45_device_table = {
 	.uart[1]	= &device_uart1,
 	.uart[2]	= &device_uart2,
 	.uart[3]	= &device_uart3,
+	.pwm		= &device_pwm,
 };
 
 void __init at91sam9g45_init_devices(void)
diff --git a/arch/arm/mach-at91/at91sam9rl_devices.c b/arch/arm/mach-at91/at91sam9rl_devices.c
index e7a1fe1..7890d55 100644
--- a/arch/arm/mach-at91/at91sam9rl_devices.c
+++ b/arch/arm/mach-at91/at91sam9rl_devices.c
@@ -447,55 +447,17 @@ static struct __initdata at91_dev_table_rtt device_rtt = {
  *  PWM
  * --------------------------------------------------------------------*/
 
-#if defined(CONFIG_ATMEL_PWM)
-static u32 pwm_mask;
-
-static struct resource pwm_resources[] = {
-	[0] = {
-		.start	= AT91SAM9RL_BASE_PWMC,
-		.end	= AT91SAM9RL_BASE_PWMC + SZ_16K - 1,
-		.flags	= IORESOURCE_MEM,
-	},
-	[1] = {
-		.start	= AT91SAM9RL_ID_PWMC,
-		.end	= AT91SAM9RL_ID_PWMC,
-		.flags	= IORESOURCE_IRQ,
+static struct __initdata at91_dev_table_pwm device_pwm = {
+	.mmio_base	= AT91SAM9RL_BASE_PWMC,
+	.irq		= AT91SAM9RL_ID_PWMC,
+	.pwm_pins	= {
+		{AT91_PIN_PB8, AT91_PIN_PERIPH_B, 1, 0, 0},
+		{AT91_PIN_PB9, AT91_PIN_PERIPH_B, 1, 0, 0},
+		{AT91_PIN_PD5, AT91_PIN_PERIPH_B, 1, 0, 0},
+		{AT91_PIN_PD8, AT91_PIN_PERIPH_B, 1, 0, 0},
 	},
 };
 
-static struct platform_device at91sam9rl_pwm0_device = {
-	.name	= "atmel_pwm",
-	.id	= -1,
-	.dev	= {
-		.platform_data		= &pwm_mask,
-	},
-	.resource	= pwm_resources,
-	.num_resources	= ARRAY_SIZE(pwm_resources),
-};
-
-void __init at91_add_device_pwm(u32 mask)
-{
-	if (mask & (1 << AT91_PWM0))
-		at91_set_B_periph(AT91_PIN_PB8, 1);	/* enable PWM0 */
-
-	if (mask & (1 << AT91_PWM1))
-		at91_set_B_periph(AT91_PIN_PB9, 1);	/* enable PWM1 */
-
-	if (mask & (1 << AT91_PWM2))
-		at91_set_B_periph(AT91_PIN_PD5, 1);	/* enable PWM2 */
-
-	if (mask & (1 << AT91_PWM3))
-		at91_set_B_periph(AT91_PIN_PD8, 1);	/* enable PWM3 */
-
-	pwm_mask = mask;
-
-	platform_device_register(&at91sam9rl_pwm0_device);
-}
-#else
-void __init at91_add_device_pwm(u32 mask) {}
-#endif
-
-
 /* --------------------------------------------------------------------
  *  SSC -- Synchronous Serial Controller
  * -------------------------------------------------------------------- */
@@ -711,6 +673,7 @@ static struct at91_device_table __initdata at91sam9rl_device_table = {
 	.uart[1]	= &device_uart1,
 	.uart[2]	= &device_uart2,
 	.uart[3]	= &device_uart3,
+	.pwm		= &device_pwm,
 };
 
 void __init at91sam9rl_init_devices(void)
diff --git a/arch/arm/mach-at91/devices.c b/arch/arm/mach-at91/devices.c
index f94b27d..a4c29ed 100644
--- a/arch/arm/mach-at91/devices.c
+++ b/arch/arm/mach-at91/devices.c
@@ -1303,6 +1303,61 @@ void __init at91_set_serial_console(unsigned portnr) {}
 void __init at91_add_device_serial(void) {}
 #endif
 
+/* --------------------------------------------------------------------
+ *  PWM
+ * --------------------------------------------------------------------*/
+
+#if defined(CONFIG_ATMEL_PWM)
+static u32 pwm_mask;
+
+static struct resource pwm_resources[] = {
+	[0] = {
+		.end	= SZ_16K,
+		.flags	= IORESOURCE_MEM,
+	},
+	[1] = {
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+static struct platform_device at91_pwm_device = {
+	.name	= "atmel_pwm",
+	.id	= -1,
+	.dev	= {
+		.platform_data		= &pwm_mask,
+	},
+	.resource	= pwm_resources,
+	.num_resources	= ARRAY_SIZE(pwm_resources),
+};
+
+void __init at91_add_device_pwm(u32 mask)
+{
+	struct at91_dev_table_pwm *info = devices->pwm;
+
+	BUG_ON(!info);
+	init_resource_mem(&pwm_resources[0], info->mmio_base);
+	init_resource_irq(&pwm_resources[1], info->irq);
+
+	if (mask & (1 << AT91_PWM0))
+		at91_config_pins(&info->pwm_pins[0], 1); /* enable PWM0 */
+
+	if (mask & (1 << AT91_PWM1))
+		at91_config_pins(&info->pwm_pins[1], 1); /* enable PWM1 */
+
+	if (mask & (1 << AT91_PWM2))
+		at91_config_pins(&info->pwm_pins[2], 1); /* enable PWM2 */
+
+	if (mask & (1 << AT91_PWM3))
+		at91_config_pins(&info->pwm_pins[3], 1); /* enable PWM3 */
+
+	pwm_mask = mask;
+
+	platform_device_register(&at91_pwm_device);
+}
+#else
+void __init at91_add_device_pwm(u32 mask) {}
+#endif
+
 static int __init at91_add_standard_devices(void)
 {
 	at91_add_device_tc();
diff --git a/arch/arm/mach-at91/devices.h b/arch/arm/mach-at91/devices.h
index c535f58..52563be 100644
--- a/arch/arm/mach-at91/devices.h
+++ b/arch/arm/mach-at91/devices.h
@@ -122,6 +122,12 @@ struct at91_dev_table_uart {
 	struct at91_pin_config	dsr_pin;
 };
 
+struct at91_dev_table_pwm {
+	unsigned		mmio_base;
+	int			irq;
+	struct at91_pin_config	pwm_pins[4];
+};
+
 struct at91_device_table {
 	struct at91_dev_table_ethernet		*ethernet;
 	struct at91_dev_table_usb_ohci		*usbh_ohci;
@@ -135,6 +141,7 @@ struct at91_device_table {
 	struct at91_dev_table_rtt		*rtt[2];
 	struct at91_dev_table_uart		*dbgu;
 	struct at91_dev_table_uart		*uart[6];
+	struct at91_dev_table_pwm		*pwm;
 };
 
 extern void __init at91_init_devices(struct at91_device_table *device_table);
-- 
1.7.0.4

  parent reply	other threads:[~2011-04-20  1:10 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-20  1:10 [RFC PATCH 00/23] at91: Replace duplicate device initialisation code with common code Ryan Mallon
2011-04-20  1:10 ` [RFC PATCH 01/23] at91: Add common devices framework Ryan Mallon
2011-04-20  1:10 ` [RFC PATCH 02/23] at91: Make Ethernet device common Ryan Mallon
2011-04-20  2:10   ` H Hartley Sweeten
2011-04-20  2:33     ` Ryan Mallon
2011-04-20 18:23       ` H Hartley Sweeten
2011-04-20  8:36   ` Uwe Kleine-König
2011-04-20 10:34     ` Jean-Christophe PLAGNIOL-VILLARD
2011-04-20 11:07     ` Ryan Mallon
2011-04-20 20:41     ` Ryan Mallon
2011-04-20  1:10 ` [RFC PATCH 03/23] at91: Make USB OHCI/EHCI devices common Ryan Mallon
2011-04-20  1:10 ` [RFC PATCH 04/23] at91: Make UDC device common Ryan Mallon
2011-04-20  1:10 ` [PATCH 05/23] at91: Make MMC device (at91_mci) common Ryan Mallon
2011-04-20  1:12   ` Ryan Mallon
2011-04-20  1:10 ` [RFC PATCH 05/23] at91: Make MMC device common Ryan Mallon
2011-04-20  1:10 ` [RFC PATCH 06/23] at91: Make NAND " Ryan Mallon
2011-04-20  1:10 ` [RFC PATCH 07/23] at91: Make TWI " Ryan Mallon
2011-04-20  1:10 ` [RFC PATCH 08/23] at91: Make SPI " Ryan Mallon
2011-04-20  1:10 ` [RFC PATCH 09/23] at91: Make TCB " Ryan Mallon
2011-04-20  1:10 ` [RFC PATCH 10/23] at91: Make RTT " Ryan Mallon
2011-04-20  1:10 ` [RFC PATCH 11/23] at91: Make watchdog " Ryan Mallon
2011-04-20 17:10   ` H Hartley Sweeten
2011-04-20  1:10 ` Ryan Mallon [this message]
2011-04-20  1:10 ` [RFC PATCH 14/23] at91: Make SSC " Ryan Mallon
2011-04-20  1:10 ` [RFC PATCH 15/23] at91: Make AC97 " Ryan Mallon
2011-04-20  1:10 ` [RFC PATCH 16/23] at91: Make LCD controller " Ryan Mallon
2011-04-20  1:10 ` [RFC PATCH 17/23] at91: Make touchscreen " Ryan Mallon
2011-04-20  1:10 ` [RFC PATCH 18/23] at91: Make HDMAC " Ryan Mallon
2011-04-20  1:10 ` [RFC PATCH 19/23] at91: Make RTC " Ryan Mallon
2011-04-20  1:10 ` [RFC PATCH 20/23] at91: Make high speed USB gadget " Ryan Mallon
2011-04-20  1:10 ` [RFC PATCH 21/23] at91: Make compact flash " Ryan Mallon
2011-04-20  1:10 ` [RFC PATCH 22/23] at91: Move at91sam9263 CAN device to common devices Ryan Mallon
2011-04-20  1:10 ` [RFC PATCH 23/23] at91: Remove mAgic and ISI device code Ryan Mallon
2011-04-20  1:11 ` [RFC PATCH 12/23] at91: Make UART devices common Ryan Mallon
2011-04-20  3:47 ` [RFC PATCH 00/23] at91: Replace duplicate device initialisation code with common code Jean-Christophe PLAGNIOL-VILLARD
2011-04-20  3:58   ` Ryan Mallon
2011-04-20  4:03     ` Jean-Christophe PLAGNIOL-VILLARD
2011-04-20 17:14 ` H Hartley Sweeten
2011-04-20 21:07   ` Ryan Mallon
2011-04-21  0:56     ` Detlef Vollmann
2011-04-21  1:04       ` Ryan Mallon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1303261827-27730-15-git-send-email-ryan@bluewatersys.com \
    --to=ryan@bluewatersys.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).