All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2 2.6.40 0/3] ARM: simpad: Add support for GPIO attached hardware
@ 2011-04-18 13:00 Jochen Friedrich
  2011-04-18 13:00 ` [PATCHv2 2.6.40 1/3] ARM:simpad: Add ucb1x00 GPIO definitions and register GPIO Jochen Friedrich
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Jochen Friedrich @ 2011-04-18 13:00 UTC (permalink / raw)
  To: linux-arm-kernel

This series enables GPIO API on UCB1x00 and implements the GPIO
API on the CS3 latch. The third patch finally registers platform
devices for the GPIO attached LED, buttons and I2C bus.

v2: In response to the Linus rant, remove the ARM specific LED
    support for simpad hardware instead of supporting it
    alternatively to the generic LED code.

ARM: simpad: Add ucb1x00 GPIO definitions and register GPIO
ARM: simpad: Cleanup CS3 accessors and add GPIO API
ARM: simpad: add GPIO based device definitions

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

* [PATCHv2 2.6.40 1/3] ARM:simpad: Add ucb1x00 GPIO definitions and register GPIO
  2011-04-18 13:00 [PATCHv2 2.6.40 0/3] ARM: simpad: Add support for GPIO attached hardware Jochen Friedrich
@ 2011-04-18 13:00 ` Jochen Friedrich
  2011-04-18 13:00 ` [PATCHv2 2.6.40 2/3] ARM:simpad: Cleanup CS3 accessors Jochen Friedrich
  2011-04-18 13:00 ` [PATCHv2 2.6.40 3/3] ARM:simpad: add GPIO based device definitions Jochen Friedrich
  2 siblings, 0 replies; 12+ messages in thread
From: Jochen Friedrich @ 2011-04-18 13:00 UTC (permalink / raw)
  To: linux-arm-kernel

Add ucb1x00 GPIO definitions to simpad.h and add gpio_base
to ucb1x00 platform device so the pins are available using
the GPIO API.

Signed-off-by: Jochen Friedrich <jochen@scram.de>
---
 arch/arm/mach-sa1100/include/mach/simpad.h |   13 +++++++++++++
 arch/arm/mach-sa1100/simpad.c              |    1 +
 2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-sa1100/include/mach/simpad.h b/arch/arm/mach-sa1100/include/mach/simpad.h
index 9296c45..231550d 100644
--- a/arch/arm/mach-sa1100/include/mach/simpad.h
+++ b/arch/arm/mach-sa1100/include/mach/simpad.h
@@ -48,6 +48,19 @@
 #define GPIO_SMART_CARD		GPIO_GPIO10
 #define IRQ_GPIO_SMARD_CARD	IRQ_GPIO10
 
+/*--- ucb1x00 GPIO ---*/
+#define SIMPAD_UCB1X00_GPIO_BASE	(GPIO_MAX + 1)
+#define SIMPAD_UCB1X00_GPIO_PROG1	(SIMPAD_UCB1X00_GPIO_BASE)
+#define SIMPAD_UCB1X00_GPIO_PROG2	(SIMPAD_UCB1X00_GPIO_BASE + 1)
+#define SIMPAD_UCB1X00_GPIO_UP		(SIMPAD_UCB1X00_GPIO_BASE + 2)
+#define SIMPAD_UCB1X00_GPIO_DOWN	(SIMPAD_UCB1X00_GPIO_BASE + 3)
+#define SIMPAD_UCB1X00_GPIO_LEFT	(SIMPAD_UCB1X00_GPIO_BASE + 4)
+#define SIMPAD_UCB1X00_GPIO_RIGHT	(SIMPAD_UCB1X00_GPIO_BASE + 5)
+#define SIMPAD_UCB1X00_GPIO_6		(SIMPAD_UCB1X00_GPIO_BASE + 6)
+#define SIMPAD_UCB1X00_GPIO_7		(SIMPAD_UCB1X00_GPIO_BASE + 7)
+#define SIMPAD_UCB1X00_GPIO_HEADSET	(SIMPAD_UCB1X00_GPIO_BASE + 8)
+#define SIMPAD_UCB1X00_GPIO_SPEAKER	(SIMPAD_UCB1X00_GPIO_BASE + 9)
+
 // CS3 Latch is write only, a shadow is necessary
 
 #define CS3BUSTYPE unsigned volatile long
diff --git a/arch/arm/mach-sa1100/simpad.c b/arch/arm/mach-sa1100/simpad.c
index cfb7607..718b802 100644
--- a/arch/arm/mach-sa1100/simpad.c
+++ b/arch/arm/mach-sa1100/simpad.c
@@ -132,6 +132,7 @@ static struct resource simpad_flash_resources [] = {
 static struct mcp_plat_data simpad_mcp_data = {
 	.mccr0		= MCCR0_ADM,
 	.sclk_rate	= 11981000,
+	.gpio_base	= SIMPAD_UCB1X00_GPIO_BASE,
 };
 
 
-- 
1.7.4.1

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

* [PATCHv2 2.6.40 2/3] ARM:simpad: Cleanup CS3 accessors.
  2011-04-18 13:00 [PATCHv2 2.6.40 0/3] ARM: simpad: Add support for GPIO attached hardware Jochen Friedrich
  2011-04-18 13:00 ` [PATCHv2 2.6.40 1/3] ARM:simpad: Add ucb1x00 GPIO definitions and register GPIO Jochen Friedrich
@ 2011-04-18 13:00 ` Jochen Friedrich
  2011-04-18 13:47   ` Jamie Iles
  2011-04-18 13:00 ` [PATCHv2 2.6.40 3/3] ARM:simpad: add GPIO based device definitions Jochen Friedrich
  2 siblings, 1 reply; 12+ messages in thread
From: Jochen Friedrich @ 2011-04-18 13:00 UTC (permalink / raw)
  To: linux-arm-kernel

- prepend CS3 accessors by simpad_ to indicate they
  are specific to simpad devices.
- use spinlock to protect shadow register.
- implement 8 read-only pins.
- use readl/writel macros so barriers are used where
  necessary.
- register CS3 as GPIO controller with 24 pins
  (16 output only and 8 input only).

Signed-off-by: Jochen Friedrich <jochen@scram.de>
---
 arch/arm/mach-sa1100/include/mach/simpad.h |   81 ++++++++++++++------
 arch/arm/mach-sa1100/leds-simpad.c         |    7 +-
 arch/arm/mach-sa1100/simpad.c              |  115 ++++++++++++++++++++++------
 drivers/pcmcia/sa1100_simpad.c             |   30 +++----
 4 files changed, 165 insertions(+), 68 deletions(-)

diff --git a/arch/arm/mach-sa1100/include/mach/simpad.h b/arch/arm/mach-sa1100/include/mach/simpad.h
index 231550d..db28118 100644
--- a/arch/arm/mach-sa1100/include/mach/simpad.h
+++ b/arch/arm/mach-sa1100/include/mach/simpad.h
@@ -61,32 +61,67 @@
 #define SIMPAD_UCB1X00_GPIO_HEADSET	(SIMPAD_UCB1X00_GPIO_BASE + 8)
 #define SIMPAD_UCB1X00_GPIO_SPEAKER	(SIMPAD_UCB1X00_GPIO_BASE + 9)
 
-// CS3 Latch is write only, a shadow is necessary
+/*--- CS3 Latch ---*/
+#define SIMPAD_CS3_GPIO_BASE		(GPIO_MAX + 11)
+#define SIMPAD_CS3_VCC_5V_EN		(SIMPAD_CS3_GPIO_BASE)
+#define SIMPAD_CS3_VCC_3V_EN		(SIMPAD_CS3_GPIO_BASE + 1)
+#define SIMPAD_CS3_EN1			(SIMPAD_CS3_GPIO_BASE + 2)
+#define SIMPAD_CS3_EN0			(SIMPAD_CS3_GPIO_BASE + 3)
+#define SIMPAD_CS3_DISPLAY_ON		(SIMPAD_CS3_GPIO_BASE + 4)
+#define SIMPAD_CS3_PCMCIA_BUFF_DIS	(SIMPAD_CS3_GPIO_BASE + 5)
+#define SIMPAD_CS3_MQ_RESET		(SIMPAD_CS3_GPIO_BASE + 6)
+#define SIMPAD_CS3_PCMCIA_RESET		(SIMPAD_CS3_GPIO_BASE + 7)
+#define SIMPAD_CS3_DECT_POWER_ON	(SIMPAD_CS3_GPIO_BASE + 8)
+#define SIMPAD_CS3_IRDA_SD		(SIMPAD_CS3_GPIO_BASE + 9)
+#define SIMPAD_CS3_RS232_ON		(SIMPAD_CS3_GPIO_BASE + 10)
+#define SIMPAD_CS3_SD_MEDIAQ		(SIMPAD_CS3_GPIO_BASE + 11)
+#define SIMPAD_CS3_LED2_ON		(SIMPAD_CS3_GPIO_BASE + 12)
+#define SIMPAD_CS3_IRDA_MODE		(SIMPAD_CS3_GPIO_BASE + 13)
+#define SIMPAD_CS3_ENABLE_5V		(SIMPAD_CS3_GPIO_BASE + 14)
+#define SIMPAD_CS3_RESET_SIMCARD	(SIMPAD_CS3_GPIO_BASE + 15)
+
+#define SIMPAD_CS3_PCMCIA_BVD1		(SIMPAD_CS3_GPIO_BASE + 16)
+#define SIMPAD_CS3_PCMCIA_BVD2		(SIMPAD_CS3_GPIO_BASE + 17)
+#define SIMPAD_CS3_PCMCIA_VS1		(SIMPAD_CS3_GPIO_BASE + 18)
+#define SIMPAD_CS3_PCMCIA_VS2		(SIMPAD_CS3_GPIO_BASE + 19)
+#define SIMPAD_CS3_LOCK_IND		(SIMPAD_CS3_GPIO_BASE + 20)
+#define SIMPAD_CS3_CHARGING_STATE	(SIMPAD_CS3_GPIO_BASE + 21)
+#define SIMPAD_CS3_PCMCIA_SHORT		(SIMPAD_CS3_GPIO_BASE + 22)
+#define SIMPAD_CS3_GPIO_23		(SIMPAD_CS3_GPIO_BASE + 23)
 
-#define CS3BUSTYPE unsigned volatile long
 #define CS3_BASE        0xf1000000
 
-#define VCC_5V_EN       0x0001 // For 5V PCMCIA
-#define VCC_3V_EN       0x0002 // FOR 3.3V PCMCIA
-#define EN1             0x0004 // This is only for EPROM's
-#define EN0             0x0008 // Both should be enable for 3.3V or 5V
-#define DISPLAY_ON      0x0010
-#define PCMCIA_BUFF_DIS 0x0020
-#define MQ_RESET        0x0040
-#define PCMCIA_RESET    0x0080
-#define DECT_POWER_ON   0x0100
-#define IRDA_SD         0x0200 // Shutdown for powersave
-#define RS232_ON        0x0400
-#define SD_MEDIAQ       0x0800 // Shutdown for powersave
-#define LED2_ON         0x1000
-#define IRDA_MODE       0x2000 // Fast/Slow IrDA mode
-#define ENABLE_5V       0x4000 // Enable 5V circuit
-#define RESET_SIMCARD   0x8000
-
-#define RS232_ENABLE    0x0440
-#define PCMCIAMASK      0x402f
-
-
+long simpad_get_cs3_ro(void);
+long simpad_get_cs3_shadow(void);
+void simpad_set_cs3_bit(int value);
+void simpad_clear_cs3_bit(int value);
+
+#define VCC_5V_EN	0x0001 /* For 5V PCMCIA */
+#define VCC_3V_EN	0x0002 /* FOR 3.3V PCMCIA */
+#define EN1		0x0004 /* This is only for EPROM's */
+#define EN0		0x0008 /* Both should be enable for 3.3V or 5V */
+#define DISPLAY_ON	0x0010
+#define PCMCIA_BUFF_DIS	0x0020
+#define MQ_RESET	0x0040
+#define PCMCIA_RESET	0x0080
+#define DECT_POWER_ON	0x0100
+#define IRDA_SD		0x0200 /* Shutdown for powersave */
+#define RS232_ON	0x0400
+#define SD_MEDIAQ	0x0800 /* Shutdown for powersave */
+#define LED2_ON		0x1000
+#define IRDA_MODE	0x2000 /* Fast/Slow IrDA mode */
+#define ENABLE_5V	0x4000 /* Enable 5V circuit */
+#define RESET_SIMCARD	0x8000
+
+#define PCMCIA_BVD1	0x01
+#define PCMCIA_BVD2	0x02
+#define PCMCIA_VS1	0x04
+#define PCMCIA_VS2	0x08
+#define LOCK_IND	0x10
+#define CHARGING_STATE	0x20
+#define PCMCIA_SHORT	0x40
+
+/*--- Battery ---*/
 struct simpad_battery {
 	unsigned char ac_status;	/* line connected yes/no */
 	unsigned char status;		/* battery loading yes/no */
diff --git a/arch/arm/mach-sa1100/leds-simpad.c b/arch/arm/mach-sa1100/leds-simpad.c
index d50f4ee..d25784c 100644
--- a/arch/arm/mach-sa1100/leds-simpad.c
+++ b/arch/arm/mach-sa1100/leds-simpad.c
@@ -22,9 +22,6 @@ static unsigned int hw_led_state;
 #define	LED_GREEN	(1)
 #define	LED_MASK	(1)
 
-extern void set_cs3_bit(int value);
-extern void clear_cs3_bit(int value);     
-
 void simpad_leds_event(led_event_t evt)
 {
 	switch (evt)
@@ -93,8 +90,8 @@ void simpad_leds_event(led_event_t evt)
 	}
 
 	if  (led_state & LED_STATE_ENABLED)
-		set_cs3_bit(LED2_ON);
+		simpad_set_cs3_bit(LED2_ON);
 	else 
-	        clear_cs3_bit(LED2_ON);
+		simpad_clear_cs3_bit(LED2_ON);
 }
 
diff --git a/arch/arm/mach-sa1100/simpad.c b/arch/arm/mach-sa1100/simpad.c
index 718b802..ec6e381 100644
--- a/arch/arm/mach-sa1100/simpad.c
+++ b/arch/arm/mach-sa1100/simpad.c
@@ -13,6 +13,7 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
 #include <linux/io.h>
+#include <linux/gpio.h>
 
 #include <asm/irq.h>
 #include <mach/hardware.h>
@@ -31,32 +32,85 @@
 
 #include "generic.h"
 
-long cs3_shadow;
+/*
+ * CS3 support
+ */
+
+static long cs3_shadow;
+static spinlock_t cs3_lock;
+static struct gpio_chip cs3_gpio;
+
+long simpad_get_cs3_ro(void)
+{
+	return readl(CS3_BASE);
+}
+EXPORT_SYMBOL(simpad_get_cs3_ro);
 
-long get_cs3_shadow(void)
+long simpad_get_cs3_shadow(void)
 {
 	return cs3_shadow;
 }
+EXPORT_SYMBOL(simpad_get_cs3_shadow);
 
-void set_cs3(long value)
+static void __simpad_write_cs3(void)
 {
-	*(CS3BUSTYPE *)(CS3_BASE) = cs3_shadow = value;
+	writel(cs3_shadow, CS3_BASE);
 }
 
-void set_cs3_bit(int value)
+void simpad_set_cs3_bit(int value)
 {
+	unsigned long flags;
+
+	spin_lock_irqsave(&cs3_lock, flags);
 	cs3_shadow |= value;
-	*(CS3BUSTYPE *)(CS3_BASE) = cs3_shadow;
+	__simpad_write_cs3();
+	spin_unlock_irqrestore(&cs3_lock, flags);
 }
+EXPORT_SYMBOL(simpad_set_cs3_bit);
 
-void clear_cs3_bit(int value)
+void simpad_clear_cs3_bit(int value)
 {
+	unsigned long flags;
+
+	spin_lock_irqsave(&cs3_lock, flags);
 	cs3_shadow &= ~value;
-	*(CS3BUSTYPE *)(CS3_BASE) = cs3_shadow;
+	__simpad_write_cs3();
+	spin_unlock_irqrestore(&cs3_lock, flags);
 }
+EXPORT_SYMBOL(simpad_clear_cs3_bit);
+
+static void cs3_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
+{
+	if (offset > 15)
+		return;
+	if (value)
+		simpad_set_cs3_bit(1 << offset);
+	else
+		simpad_clear_cs3_bit(1 << offset);
+};
 
-EXPORT_SYMBOL(set_cs3_bit);
-EXPORT_SYMBOL(clear_cs3_bit);
+static int cs3_gpio_get(struct gpio_chip *chip, unsigned offset)
+{
+	if (offset > 15)
+		return simpad_get_cs3_ro() & (1 << (offset - 16));
+	return simpad_get_cs3_shadow() & (1 << offset);
+};
+
+static int cs3_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
+{
+	if (offset > 15)
+		return 0;
+	return -EINVAL;
+};
+
+static int cs3_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
+	int value)
+{
+	if (offset > 15)
+		return -EINVAL;
+	cs3_gpio_set(chip, offset, value);
+	return 0;
+};
 
 static struct map_desc simpad_io_desc[] __initdata = {
 	{	/* MQ200 */
@@ -64,9 +118,9 @@ static struct map_desc simpad_io_desc[] __initdata = {
 		.pfn		= __phys_to_pfn(0x4b800000),
 		.length		= 0x00800000,
 		.type		= MT_DEVICE
-	}, {	/* Paules CS3, write only */
-		.virtual	=  0xf1000000,
-		.pfn		= __phys_to_pfn(0x18000000),
+	}, {	/* Simpad CS3 */
+		.virtual	= CS3_BASE,
+		.pfn		= __phys_to_pfn(SA1100_CS3_PHYS),
 		.length		= 0x00100000,
 		.type		= MT_DEVICE
 	},
@@ -78,12 +132,12 @@ static void simpad_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
 	if (port->mapbase == (u_int)&Ser1UTCR0) {
 		if (state)
 		{
-			clear_cs3_bit(RS232_ON);
-			clear_cs3_bit(DECT_POWER_ON);
+			simpad_clear_cs3_bit(RS232_ON);
+			simpad_clear_cs3_bit(DECT_POWER_ON);
 		}else
 		{
-			set_cs3_bit(RS232_ON);
-			set_cs3_bit(DECT_POWER_ON);
+			simpad_set_cs3_bit(RS232_ON);
+			simpad_set_cs3_bit(DECT_POWER_ON);
 		}
 	}
 }
@@ -143,9 +197,10 @@ static void __init simpad_map_io(void)
 
 	iotable_init(simpad_io_desc, ARRAY_SIZE(simpad_io_desc));
 
-	set_cs3_bit (EN1 | EN0 | LED2_ON | DISPLAY_ON | RS232_ON |
-		      ENABLE_5V | RESET_SIMCARD | DECT_POWER_ON);
-
+	/* Initialize CS3 */
+	cs3_shadow = (EN1 | EN0 | LED2_ON | DISPLAY_ON |
+		RS232_ON | ENABLE_5V | RESET_SIMCARD | DECT_POWER_ON);
+	__simpad_write_cs3(); /* Spinlocks not yet initialized */
 
         sa1100_register_uart_fns(&simpad_port_fns);
 	sa1100_register_uart(0, 3);  /* serial interface */
@@ -171,12 +226,13 @@ static void __init simpad_map_io(void)
 
 static void simpad_power_off(void)
 {
-	local_irq_disable(); // was cli
-	set_cs3(0x800);        /* only SD_MEDIAQ */
+	local_irq_disable(); /* was cli */
+	cs3_shadow = SD_MEDIAQ;
+	__simpad_write_cs3(); /* Bypass spinlock here */
 
 	/* disable internal oscillator, float CS lines */
 	PCFR = (PCFR_OPDE | PCFR_FP | PCFR_FS);
-	/* enable wake-up on GPIO0 (Assabet...) */
+	/* enable wake-up on GPIO0 */
 	PWER = GFER = GRER = 1;
 	/*
 	 * set scratchpad to zero, just in case it is used as a
@@ -212,6 +268,19 @@ static int __init simpad_init(void)
 {
 	int ret;
 
+	spin_lock_init(&cs3_lock);
+
+	cs3_gpio.label = "simpad_cs3";
+	cs3_gpio.base = SIMPAD_CS3_GPIO_BASE;
+	cs3_gpio.ngpio = 24;
+	cs3_gpio.set = cs3_gpio_set;
+	cs3_gpio.get = cs3_gpio_get;
+	cs3_gpio.direction_input = cs3_gpio_direction_input;
+	cs3_gpio.direction_output = cs3_gpio_direction_output;
+	ret = gpiochip_add(&cs3_gpio);
+	if (ret)
+		printk(KERN_WARNING "simpad: Unable to register cs3 GPIO device");
+
 	pm_power_off = simpad_power_off;
 
 	sa11x0_register_mtd(&simpad_flash_data, simpad_flash_resources,
diff --git a/drivers/pcmcia/sa1100_simpad.c b/drivers/pcmcia/sa1100_simpad.c
index c998f7a..540320d 100644
--- a/drivers/pcmcia/sa1100_simpad.c
+++ b/drivers/pcmcia/sa1100_simpad.c
@@ -15,10 +15,6 @@
 #include <mach/simpad.h>
 #include "sa1100_generic.h"
  
-extern long get_cs3_shadow(void);
-extern void set_cs3_bit(int value); 
-extern void clear_cs3_bit(int value);
-
 static struct pcmcia_irqs irqs[] = {
 	{ 1, IRQ_GPIO_CF_CD, "CF_CD" },
 };
@@ -26,7 +22,7 @@ static struct pcmcia_irqs irqs[] = {
 static int simpad_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
 {
 
-	clear_cs3_bit(VCC_3V_EN|VCC_5V_EN|EN0|EN1);
+	simpad_clear_cs3_bit(VCC_3V_EN|VCC_5V_EN|EN0|EN1);
 
 	skt->socket.pci_irq = IRQ_GPIO_CF_IRQ;
 
@@ -38,8 +34,8 @@ static void simpad_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
 	soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
 
 	/* Disable CF bus: */
-	//set_cs3_bit(PCMCIA_BUFF_DIS);
-	clear_cs3_bit(PCMCIA_RESET);       
+	/*simpad_set_cs3_bit(PCMCIA_BUFF_DIS);*/
+	simpad_clear_cs3_bit(PCMCIA_RESET);
 }
 
 static void
@@ -47,15 +43,15 @@ simpad_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
 			   struct pcmcia_state *state)
 {
 	unsigned long levels = GPLR;
-	long cs3reg = get_cs3_shadow();
+	long cs3reg = simpad_get_cs3_shadow();
 
 	state->detect=((levels & GPIO_CF_CD)==0)?1:0;
 	state->ready=(levels & GPIO_CF_IRQ)?1:0;
 	state->bvd1=1; /* Not available on Simpad. */
 	state->bvd2=1; /* Not available on Simpad. */
 	state->wrprot=0; /* Not available on Simpad. */
-  
-	if((cs3reg & 0x0c) == 0x0c) {
+
+	if ((cs3reg & 0x0c) == 0x0c) {
 		state->vs_3v=0;
 		state->vs_Xv=0;
 	} else {
@@ -75,23 +71,23 @@ simpad_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
 	/* Murphy: see table of MIC2562a-1 */
 	switch (state->Vcc) {
 	case 0:
-		clear_cs3_bit(VCC_3V_EN|VCC_5V_EN|EN0|EN1);
+		simpad_clear_cs3_bit(VCC_3V_EN|VCC_5V_EN|EN0|EN1);
 		break;
 
 	case 33:  
-		clear_cs3_bit(VCC_3V_EN|EN1);
-		set_cs3_bit(VCC_5V_EN|EN0);
+		simpad_clear_cs3_bit(VCC_3V_EN|EN1);
+		simpad_set_cs3_bit(VCC_5V_EN|EN0);
 		break;
 
 	case 50:
-		clear_cs3_bit(VCC_5V_EN|EN1);
-		set_cs3_bit(VCC_3V_EN|EN0);
+		simpad_clear_cs3_bit(VCC_5V_EN|EN1);
+		simpad_set_cs3_bit(VCC_3V_EN|EN0);
 		break;
 
 	default:
 		printk(KERN_ERR "%s(): unrecognized Vcc %u\n",
 			__func__, state->Vcc);
-		clear_cs3_bit(VCC_3V_EN|VCC_5V_EN|EN0|EN1);
+		simpad_clear_cs3_bit(VCC_3V_EN|VCC_5V_EN|EN0|EN1);
 		local_irq_restore(flags);
 		return -1;
 	}
@@ -110,7 +106,7 @@ static void simpad_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
 static void simpad_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
 {
 	soc_pcmcia_disable_irqs(skt, irqs, ARRAY_SIZE(irqs));
-	set_cs3_bit(PCMCIA_RESET);
+	simpad_set_cs3_bit(PCMCIA_RESET);
 }
 
 static struct pcmcia_low_level simpad_pcmcia_ops = { 
-- 
1.7.4.1

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

* [PATCHv2 2.6.40 3/3] ARM:simpad: add GPIO based device definitions.
  2011-04-18 13:00 [PATCHv2 2.6.40 0/3] ARM: simpad: Add support for GPIO attached hardware Jochen Friedrich
  2011-04-18 13:00 ` [PATCHv2 2.6.40 1/3] ARM:simpad: Add ucb1x00 GPIO definitions and register GPIO Jochen Friedrich
  2011-04-18 13:00 ` [PATCHv2 2.6.40 2/3] ARM:simpad: Cleanup CS3 accessors Jochen Friedrich
@ 2011-04-18 13:00 ` Jochen Friedrich
  2011-04-19 13:52   ` Dmitry Artamonow
  2 siblings, 1 reply; 12+ messages in thread
From: Jochen Friedrich @ 2011-04-18 13:00 UTC (permalink / raw)
  To: linux-arm-kernel

Register LED, keyboard, polled keyboard and I2C platform
devices based on GPIOs.

V2: Remove the legacy ARM LED code for simpad devices.

Signed-off-by: Jochen Friedrich <jochen@scram.de>
---
 arch/arm/mach-sa1100/Makefile      |    1 -
 arch/arm/mach-sa1100/leds-simpad.c |   97 ------------------------------------
 arch/arm/mach-sa1100/simpad.c      |   95 ++++++++++++++++++++++++++++++++++-
 3 files changed, 94 insertions(+), 99 deletions(-)
 delete mode 100644 arch/arm/mach-sa1100/leds-simpad.c

diff --git a/arch/arm/mach-sa1100/Makefile b/arch/arm/mach-sa1100/Makefile
index 41252d2..0063178 100644
--- a/arch/arm/mach-sa1100/Makefile
+++ b/arch/arm/mach-sa1100/Makefile
@@ -45,7 +45,6 @@ obj-$(CONFIG_SA1100_PLEB)		+= pleb.o
 obj-$(CONFIG_SA1100_SHANNON)		+= shannon.o
 
 obj-$(CONFIG_SA1100_SIMPAD)		+= simpad.o
-led-$(CONFIG_SA1100_SIMPAD)		+= leds-simpad.o
 
 # LEDs support
 obj-$(CONFIG_LEDS) += $(led-y)
diff --git a/arch/arm/mach-sa1100/leds-simpad.c b/arch/arm/mach-sa1100/leds-simpad.c
deleted file mode 100644
index d25784c..0000000
--- a/arch/arm/mach-sa1100/leds-simpad.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * linux/arch/arm/mach-sa1100/leds-simpad.c
- *
- * Author: Juergen Messerer <juergen.messerer@siemens.ch>
- */
-#include <linux/init.h>
-
-#include <mach/hardware.h>
-#include <asm/leds.h>
-#include <asm/system.h>
-#include <mach/simpad.h>
-
-#include "leds.h"
-
-
-#define LED_STATE_ENABLED	1
-#define LED_STATE_CLAIMED	2
-
-static unsigned int led_state;
-static unsigned int hw_led_state;
-
-#define	LED_GREEN	(1)
-#define	LED_MASK	(1)
-
-void simpad_leds_event(led_event_t evt)
-{
-	switch (evt)
-	{
-	case led_start:
-	        hw_led_state = LED_GREEN;
-		led_state = LED_STATE_ENABLED;
-		break;
-
-	case led_stop:
-		led_state &= ~LED_STATE_ENABLED;
-		break;
-
-	case led_claim:
-		led_state |= LED_STATE_CLAIMED;
-		hw_led_state = LED_GREEN;
-		break;
-
-	case led_release:
-		led_state &= ~LED_STATE_CLAIMED;
-		hw_led_state = LED_GREEN;
-		break;
-
-#ifdef CONFIG_LEDS_TIMER
-	case led_timer:
-		if (!(led_state & LED_STATE_CLAIMED))
-			hw_led_state ^= LED_GREEN;
-		break;
-#endif
-
-#ifdef CONFIG_LEDS_CPU
-	case led_idle_start:
-		break;
-
-	case led_idle_end:
-		break;
-#endif
-
-	case led_halted:
-		break;
-
-	case led_green_on:
-		if (led_state & LED_STATE_CLAIMED)
-			hw_led_state |= LED_GREEN;
-		break;
-
-	case led_green_off:
-		if (led_state & LED_STATE_CLAIMED)
-			hw_led_state &= ~LED_GREEN;
-		break;
-
-	case led_amber_on:
-		break;
-
-	case led_amber_off:
-		break;
-
-	case led_red_on:
-		break;
-
-	case led_red_off:
-		break;
-
-	default:
-		break;
-	}
-
-	if  (led_state & LED_STATE_ENABLED)
-		simpad_set_cs3_bit(LED2_ON);
-	else 
-		simpad_clear_cs3_bit(LED2_ON);
-}
-
diff --git a/arch/arm/mach-sa1100/simpad.c b/arch/arm/mach-sa1100/simpad.c
index ec6e381..cf3a68a 100644
--- a/arch/arm/mach-sa1100/simpad.c
+++ b/arch/arm/mach-sa1100/simpad.c
@@ -29,6 +29,10 @@
 
 #include <linux/serial_core.h>
 #include <linux/ioport.h>
+#include <linux/input.h>
+#include <linux/gpio_keys.h>
+#include <linux/leds.h>
+#include <linux/i2c-gpio.h>
 
 #include "generic.h"
 
@@ -249,6 +253,91 @@ static void simpad_power_off(void)
 
 }
 
+/*
+ * gpio_keys
+*/
+
+static struct gpio_keys_button simpad_button_table[] = {
+	{ KEY_POWER, IRQ_GPIO_POWER_BUTTON, 1, "power button" },
+};
+
+static struct gpio_keys_platform_data simpad_keys_data = {
+	.buttons = simpad_button_table,
+	.nbuttons = ARRAY_SIZE(simpad_button_table),
+};
+
+static struct platform_device simpad_keys = {
+	.name = "gpio-keys",
+	.dev = {
+		.platform_data = &simpad_keys_data,
+	},
+};
+
+static struct gpio_keys_button simpad_polled_button_table[] = {
+	{ KEY_PROG1, SIMPAD_UCB1X00_GPIO_PROG1, 1, "prog1 button" },
+	{ KEY_PROG2, SIMPAD_UCB1X00_GPIO_PROG2, 1, "prog2 button" },
+	{ KEY_UP,    SIMPAD_UCB1X00_GPIO_UP,    1, "up button" },
+	{ KEY_DOWN,  SIMPAD_UCB1X00_GPIO_DOWN,  1, "down button" },
+	{ KEY_LEFT,  SIMPAD_UCB1X00_GPIO_LEFT,  1, "left button" },
+	{ KEY_RIGHT, SIMPAD_UCB1X00_GPIO_RIGHT, 1, "right button" },
+};
+
+static struct gpio_keys_platform_data simpad_polled_keys_data = {
+	.buttons = simpad_polled_button_table,
+	.nbuttons = ARRAY_SIZE(simpad_polled_button_table),
+	.poll_interval = 50,
+};
+
+static struct platform_device simpad_polled_keys = {
+	.name = "gpio-keys-polled",
+	.dev = {
+		.platform_data = &simpad_polled_keys_data,
+	},
+};
+
+/*
+ * GPIO LEDs
+ */
+
+static struct gpio_led simpad_leds[] = {
+	{
+		.name = "power",
+		.gpio = SIMPAD_CS3_LED2_ON,
+		.active_low = 0,
+		.default_trigger = "default-on",
+	},
+};
+
+static struct gpio_led_platform_data simpad_led_data = {
+	.num_leds = 1,
+	.leds = simpad_leds,
+};
+
+static struct platform_device simpad_gpio_leds = {
+	.name = "leds-gpio",
+	.id = 0,
+	.dev = {
+		.platform_data = &simpad_led_data,
+	},
+};
+
+/*
+ * i2c
+ */
+static struct i2c_gpio_platform_data simpad_i2c_data = {
+	.sda_pin = GPIO_GPIO21,
+	.scl_pin = GPIO_GPIO25,
+	.udelay = 10,
+	.timeout = HZ,
+};
+
+static struct platform_device simpad_i2c = {
+	.name = "i2c-gpio",
+	.id = 0,
+	.dev = {
+		.platform_data = &simpad_i2c_data,
+	},
+};
 
 /*
  * MediaQ Video Device
@@ -259,7 +348,11 @@ static struct platform_device simpad_mq200fb = {
 };
 
 static struct platform_device *devices[] __initdata = {
-	&simpad_mq200fb
+	&simpad_keys,
+	&simpad_polled_keys,
+	&simpad_mq200fb,
+	&simpad_gpio_leds,
+	&simpad_i2c,
 };
 
 
-- 
1.7.4.1

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

* [PATCHv2 2.6.40 2/3] ARM:simpad: Cleanup CS3 accessors.
  2011-04-18 13:00 ` [PATCHv2 2.6.40 2/3] ARM:simpad: Cleanup CS3 accessors Jochen Friedrich
@ 2011-04-18 13:47   ` Jamie Iles
  2011-04-18 14:35     ` Jochen Friedrich
  0 siblings, 1 reply; 12+ messages in thread
From: Jamie Iles @ 2011-04-18 13:47 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Jochen,

On Mon, Apr 18, 2011 at 03:00:35PM +0200, Jochen Friedrich wrote:
> - prepend CS3 accessors by simpad_ to indicate they
>   are specific to simpad devices.
> - use spinlock to protect shadow register.
> - implement 8 read-only pins.
> - use readl/writel macros so barriers are used where
>   necessary.
> - register CS3 as GPIO controller with 24 pins
>   (16 output only and 8 input only).

I think the basic-mmio-gpio driver (drivers/gpio/basic_mmio_gpio.c) 
should cover the GPIO controller portion of this (including the 
shadowing etc).  This may need a few other bits (simpad_uart_pm(), 
simpad_map_io() etc) converting over to use the GPIO API though.

Jamie

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

* [PATCHv2 2.6.40 2/3] ARM:simpad: Cleanup CS3 accessors.
  2011-04-18 13:47   ` Jamie Iles
@ 2011-04-18 14:35     ` Jochen Friedrich
  2011-04-18 14:46       ` Henning Heinold
  2011-04-18 16:49       ` Jamie Iles
  0 siblings, 2 replies; 12+ messages in thread
From: Jochen Friedrich @ 2011-04-18 14:35 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Jamie,

>> - register CS3 as GPIO controller with 24 pins
>>    (16 output only and 8 input only).
>
> I think the basic-mmio-gpio driver (drivers/gpio/basic_mmio_gpio.c)
> should cover the GPIO controller portion of this (including the
> shadowing etc).

I'll have a look at this. Last time I checked, a single virtual address
for a wite-only/read-only register pair was not supported, but this
might have changed.

 > This may need a few other bits (simpad_uart_pm(),
> simpad_map_io() etc) converting over to use the GPIO API though.

Yes. In particular the UART and PCMCIA stuff needs to be converted.
OTOH, this would make some board specific stuff obsolete and would
help to reduce the arch/arm/* mess some more ;-).

Unfortunately, my Simpad doesn't have a PCMCIA slot, so it's hard
for me to test this.

Thanks,
Jochen

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

* [PATCHv2 2.6.40 2/3] ARM:simpad: Cleanup CS3 accessors.
  2011-04-18 14:35     ` Jochen Friedrich
@ 2011-04-18 14:46       ` Henning Heinold
  2011-04-18 16:49       ` Jamie Iles
  1 sibling, 0 replies; 12+ messages in thread
From: Henning Heinold @ 2011-04-18 14:46 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Apr 18, 2011 at 04:35:26PM +0200, Jochen Friedrich wrote:
> Unfortunately, my Simpad doesn't have a PCMCIA slot, so it's hard
> for me to test this.
>
> Thanks,
> Jochen

Hi Jochen,

I have a simpad with pcmcia slot so I could test it.

Bye Henning

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

* [PATCHv2 2.6.40 2/3] ARM:simpad: Cleanup CS3 accessors.
  2011-04-18 14:35     ` Jochen Friedrich
  2011-04-18 14:46       ` Henning Heinold
@ 2011-04-18 16:49       ` Jamie Iles
  2011-04-18 18:02         ` Jochen Friedrich
  1 sibling, 1 reply; 12+ messages in thread
From: Jamie Iles @ 2011-04-18 16:49 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Apr 18, 2011 at 04:35:26PM +0200, Jochen Friedrich wrote:
> Hi Jamie,
> 
> >>- register CS3 as GPIO controller with 24 pins
> >>   (16 output only and 8 input only).
> >
> >I think the basic-mmio-gpio driver (drivers/gpio/basic_mmio_gpio.c)
> >should cover the GPIO controller portion of this (including the
> >shadowing etc).
> 
> I'll have a look at this. Last time I checked, a single virtual address
> for a wite-only/read-only register pair was not supported, but this
> might have changed.

You should just be able to specify a single resource named "dat" and 
you'll be good to go.  The current driver in mainline detects the number 
of GPIO's based on the register width (so it would detect 32 GPIO's in 
your case), but I have some patches posted on lkml that allow this to be 
overridden.  These patches also add support for direction registers 
which it looks like you may need.

Jamie

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

* [PATCHv2 2.6.40 2/3] ARM:simpad: Cleanup CS3 accessors.
  2011-04-18 16:49       ` Jamie Iles
@ 2011-04-18 18:02         ` Jochen Friedrich
  2011-04-19  9:09           ` Jamie Iles
  0 siblings, 1 reply; 12+ messages in thread
From: Jochen Friedrich @ 2011-04-18 18:02 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Jamie,

>> I'll have a look at this. Last time I checked, a single virtual address
>> for a wite-only/read-only register pair was not supported, but this
>> might have changed.
>
> You should just be able to specify a single resource named "dat" and
> you'll be good to go.

Not really. The "CS3" register on the simpad device is a 16bit register
which hat 16 write-only pins and 8 independent read-only pins (no 
direction register, at all). It is implemented using 3 TTL logic chips.
More information about this strange stuff can be found at:
http://opensimpad.org/index.php/Wiring#CS3_latch

I'm not sure if handling such a corner-case in the generic driver makes
sense. However, i'm convinced that moving away from the simpad specific
API to the GPIO API and removing all the platform specific UART and
PCMCIA glue code by a generic GPIO one does make sense, in particular
as the FDT has a nice way to assign GPIO functions to other subsystems.

Thanks,
Jochen

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

* [PATCHv2 2.6.40 2/3] ARM:simpad: Cleanup CS3 accessors.
  2011-04-18 18:02         ` Jochen Friedrich
@ 2011-04-19  9:09           ` Jamie Iles
  0 siblings, 0 replies; 12+ messages in thread
From: Jamie Iles @ 2011-04-19  9:09 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Apr 18, 2011 at 08:02:05PM +0200, Jochen Friedrich wrote:
> Hi Jamie,
> 
> >>I'll have a look at this. Last time I checked, a single virtual address
> >>for a wite-only/read-only register pair was not supported, but this
> >>might have changed.
> >
> >You should just be able to specify a single resource named "dat" and
> >you'll be good to go.
> 
> Not really. The "CS3" register on the simpad device is a 16bit register
> which hat 16 write-only pins and 8 independent read-only pins (no
> direction register, at all). It is implemented using 3 TTL logic
> chips.

Ahh, I misread that bit.

> More information about this strange stuff can be found at:
> http://opensimpad.org/index.php/Wiring#CS3_latch
> 
> I'm not sure if handling such a corner-case in the generic driver makes
> sense.

I think I agree with you - it's more like two gpio_chip's using a single 
register and I would guess that it isn't too common a scenario.

Jamie

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

* [PATCHv2 2.6.40 3/3] ARM:simpad: add GPIO based device definitions.
  2011-04-18 13:00 ` [PATCHv2 2.6.40 3/3] ARM:simpad: add GPIO based device definitions Jochen Friedrich
@ 2011-04-19 13:52   ` Dmitry Artamonow
  2011-04-19 14:46     ` Jochen Friedrich
  0 siblings, 1 reply; 12+ messages in thread
From: Dmitry Artamonow @ 2011-04-19 13:52 UTC (permalink / raw)
  To: linux-arm-kernel

On 15:00 Mon 18 Apr     , Jochen Friedrich wrote:
> Register LED, keyboard, polled keyboard and I2C platform
> devices based on GPIOs.
> 
> V2: Remove the legacy ARM LED code for simpad devices.

Yeah, that looks like a good move! IMO, legacy ARM leds code should go
away, as we have now proper generic LED subsystem, and the sooner we
convert all legacy users to leds-class drivers, the better.

> Signed-off-by: Jochen Friedrich <jochen@scram.de>
> ---
>  arch/arm/mach-sa1100/Makefile      |    1 -
>  arch/arm/mach-sa1100/leds-simpad.c |   97 ------------------------------------
>  arch/arm/mach-sa1100/simpad.c      |   95 ++++++++++++++++++++++++++++++++++-
>  3 files changed, 94 insertions(+), 99 deletions(-)
>  delete mode 100644 arch/arm/mach-sa1100/leds-simpad.c

But, while removing leds-simpad.c, it seems you forgot to update both
Makefile and corresponding entries in leds.[ch], so I suspect it will
break build with CONFIG_LEDS=y.

And, while you're at it, it's probably a good idea to move all these LED
changes into separate patch, and not to mix them with gpio-keys/i2c/etc
devices registration.

-- 
Best regards,
Dmitry "MAD" Artamonow

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

* [PATCHv2 2.6.40 3/3] ARM:simpad: add GPIO based device definitions.
  2011-04-19 13:52   ` Dmitry Artamonow
@ 2011-04-19 14:46     ` Jochen Friedrich
  0 siblings, 0 replies; 12+ messages in thread
From: Jochen Friedrich @ 2011-04-19 14:46 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Dmitry,

>>   arch/arm/mach-sa1100/Makefile      |    1 -
>>   arch/arm/mach-sa1100/leds-simpad.c |   97 ------------------------------------
>>   arch/arm/mach-sa1100/simpad.c      |   95 ++++++++++++++++++++++++++++++++++-
>>   3 files changed, 94 insertions(+), 99 deletions(-)
>>   delete mode 100644 arch/arm/mach-sa1100/leds-simpad.c
>
> But, while removing leds-simpad.c, it seems you forgot to update both
> Makefile and corresponding entries in leds.[ch], so I suspect it will
> break build with CONFIG_LEDS=y.

Thanks for the review. I'll update my patch.

> And, while you're at it, it's probably a good idea to move all these LED
> changes into separate patch, and not to mix them with gpio-keys/i2c/etc
> devices registration.

I'll seperate the LED stuff from the rest of the patch.

Thanks,
Jochen

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

end of thread, other threads:[~2011-04-19 14:46 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-18 13:00 [PATCHv2 2.6.40 0/3] ARM: simpad: Add support for GPIO attached hardware Jochen Friedrich
2011-04-18 13:00 ` [PATCHv2 2.6.40 1/3] ARM:simpad: Add ucb1x00 GPIO definitions and register GPIO Jochen Friedrich
2011-04-18 13:00 ` [PATCHv2 2.6.40 2/3] ARM:simpad: Cleanup CS3 accessors Jochen Friedrich
2011-04-18 13:47   ` Jamie Iles
2011-04-18 14:35     ` Jochen Friedrich
2011-04-18 14:46       ` Henning Heinold
2011-04-18 16:49       ` Jamie Iles
2011-04-18 18:02         ` Jochen Friedrich
2011-04-19  9:09           ` Jamie Iles
2011-04-18 13:00 ` [PATCHv2 2.6.40 3/3] ARM:simpad: add GPIO based device definitions Jochen Friedrich
2011-04-19 13:52   ` Dmitry Artamonow
2011-04-19 14:46     ` Jochen Friedrich

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.