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 01/23] at91: Add common devices framework
Date: Wed, 20 Apr 2011 13:10:04 +1200	[thread overview]
Message-ID: <1303261827-27730-2-git-send-email-ryan@bluewatersys.com> (raw)
In-Reply-To: <1303261827-27730-1-git-send-email-ryan@bluewatersys.com>

Each AT91 variant (AT91RM9200, AT91SAM9260, etc) currently has its own
devices file, which includes the MMIO address, interrupt
configuration, GPIO setup, etc for each device. This results in a large
amount of duplicated code.

This patch introduces a framework for adding shared devices for the
AT91 platform. The subsequent patches in this series replace the
multiple device setup implementations for each device with single
implementations in the new framework.

Signed-off-by: Ryan Mallon <ryan@bluewatersys.com>
---
 arch/arm/mach-at91/Makefile  |    2 +-
 arch/arm/mach-at91/devices.c |   70 ++++++++++++++++++++++++++++++++++++++++++
 arch/arm/mach-at91/devices.h |   36 +++++++++++++++++++++
 3 files changed, 107 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/mach-at91/devices.c
 create mode 100644 arch/arm/mach-at91/devices.h

diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile
index a83835e..14962f2 100644
--- a/arch/arm/mach-at91/Makefile
+++ b/arch/arm/mach-at91/Makefile
@@ -2,7 +2,7 @@
 # Makefile for the linux kernel.
 #
 
-obj-y		:= irq.o gpio.o
+obj-y		:= irq.o gpio.o devices.o
 obj-m		:=
 obj-n		:=
 obj-		:=
diff --git a/arch/arm/mach-at91/devices.c b/arch/arm/mach-at91/devices.c
new file mode 100644
index 0000000..653e0a9
--- /dev/null
+++ b/arch/arm/mach-at91/devices.c
@@ -0,0 +1,70 @@
+/*
+ * arch/arm/mach-at91/devices.c
+ *
+ *  Copyright (C) 2011 Bluewater Systems
+ *  Copyright (C) 2011 Ryan Mallon <ryan@bluewatersys.com>
+ * 
+ * Based on code from arch/arm/mach-at91/*_devices.c
+ *
+ * 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.
+ *
+ */
+
+#include <linux/platform_device.h>
+#include <linux/gpio.h>
+
+#include "devices.h"
+
+static __initdata struct at91_device_table *devices;
+
+static __init void at91_config_pins(struct at91_pin_config *pins, int nr_pins)
+{
+	int i;
+
+	for (i = 0; i < nr_pins; i++) {		
+		switch (pins[i].mode) {
+		case AT91_PIN_PERIPH_A:
+			at91_set_A_periph(pins[i].pin, pins[i].pullup);
+			break;
+
+		case AT91_PIN_PERIPH_B:
+			at91_set_B_periph(pins[i].pin, pins[i].pullup);
+			break;
+
+		default:
+			/* GPIO */
+			if (pins[i].direction == GPIOF_DIR_OUT)
+				at91_set_gpio_output(pins[i].pin,
+						     pins[i].value);
+			else
+				at91_set_gpio_input(pins[i].pin,
+						    pins[i].pullup);
+			break;
+		}
+	}
+}
+
+static inline void __init init_resource_mem(struct resource *res,
+					    unsigned mmio_base)
+{
+	BUG_ON(res->flags != IORESOURCE_MEM);
+	res->start = mmio_base;
+	res->end  += mmio_base - 1;
+}
+
+static inline void __init init_resource_irq(struct resource *res, int irq)
+{
+	if (irq) {
+		BUG_ON(res->flags != IORESOURCE_IRQ);
+		res->start = irq;
+		res->end   = irq;
+	}
+}
+
+void __init at91_init_devices(struct at91_device_table *device_table)
+{
+	devices = device_table;
+}
diff --git a/arch/arm/mach-at91/devices.h b/arch/arm/mach-at91/devices.h
new file mode 100644
index 0000000..738f736
--- /dev/null
+++ b/arch/arm/mach-at91/devices.h
@@ -0,0 +1,36 @@
+/*
+ * arch/arm/mach-at91/devices.h
+ *
+ *  Copyright (C) 2011 Bluewater Systems
+ *  Copyright (C) 2011 Ryan Mallon <ryan@bluewatersys.com>
+ *
+ * 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 _AT91_DEVICES_H
+#define _AT91_DEVICES_H
+
+enum {
+	AT91_PIN_PERIPH_A,
+	AT91_PIN_PERIPH_B,
+	AT91_PIN_GPIO,
+};
+
+struct at91_pin_config {
+	int pin;
+	int mode;
+	int pullup;
+	int direction;
+	int value;
+};
+
+struct at91_device_table {
+};
+
+extern void __init at91_init_devices(struct at91_device_table *device_table);
+
+#endif /* _AT91_DEVICES_H */
-- 
1.7.0.4

  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 ` Ryan Mallon [this message]
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 ` [RFC PATCH 13/23] at91: Make PWM " Ryan Mallon
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-2-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).