Commit 51e02b02 authored by Manuel Lauss's avatar Manuel Lauss Committed by Ralf Baechle

MIPS: Alchemy: Rewrite GPIO support.

The current in-kernel Alchemy GPIO support is far too inflexible for
all my use cases.  To address this, the following changes are made:

* create generic functions which deal with manipulating the on-chip
  GPIO1/2 blocks.  Such functions are universally useful.
* Macros for GPIO2 shared interrupt management and block control.
* support for both built-in CONFIG_GPIOLIB and fast, inlined GPIO macros.

  If CONFIG_GPIOLIB is not enabled, provide linux gpio framework
  compatibility by directly inlining the GPIO1/2 functions.  GPIO access
  is limited to on-chip ones and they can be accessed as documented in
  the datasheets (GPIO0-31 and 200-215).

  If CONFIG_GPIOLIB is selected, two (2) gpio_chip-s, one for GPIO1 and
  one for GPIO2, are registered.  GPIOs can still be accessed by using
  the numberspace established in the databooks.

  However this is not yet flexible enough for my uses:  My Alchemy
  systems have a documented "external" gpio interface (fixed, different
  numberspace) and can support a variety of baseboards, some of which
  are equipped with I2C gpio expanders.  I want to be able to provide
  the default 16 GPIOs of the CPU board numbered as 0..15 and also
  support gpio expanders, if present, starting as gpio16.

  To achieve this, a new Kconfig symbol for Alchemy is introduced,
  CONFIG_ALCHEMY_GPIO_INDIRECT, which boards can enable to signal
  that they don't want the Alchemy numberspace exposed to the outside
  world, but instead want to provide their own.  Boards are now respon-
  sible for providing the linux gpio interface glue code (either in a
  custom gpio.h header (in board include directory) or with gpio_chips).

  To make the board-specific inlined gpio functions work, the MIPS
  Makefile must be changed so that the mach-au1x00/gpio.h header is
  included _after_ the board headers, by moving the inclusion of
  the mach-au1x00/ to the end of the header list.

  See arch/mips/include/asm/mach-au1x00/gpio.h for more info.
Signed-off-by: default avatarManuel Lauss <manuel.lauss@gmail.com>
Acked-by: default avatarFlorian Fainelli <florian@openwrt.org>
Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
parent eeb09e65
...@@ -183,7 +183,6 @@ load-$(CONFIG_MACH_JAZZ) += 0xffffffff80080000 ...@@ -183,7 +183,6 @@ load-$(CONFIG_MACH_JAZZ) += 0xffffffff80080000
# Common Alchemy Au1x00 stuff # Common Alchemy Au1x00 stuff
# #
core-$(CONFIG_SOC_AU1X00) += arch/mips/alchemy/common/ core-$(CONFIG_SOC_AU1X00) += arch/mips/alchemy/common/
cflags-$(CONFIG_SOC_AU1X00) += -I$(srctree)/arch/mips/include/asm/mach-au1x00
# #
# AMD Alchemy Pb1000 eval board # AMD Alchemy Pb1000 eval board
...@@ -281,6 +280,10 @@ load-$(CONFIG_MIPS_MTX1) += 0xffffffff80100000 ...@@ -281,6 +280,10 @@ load-$(CONFIG_MIPS_MTX1) += 0xffffffff80100000
libs-$(CONFIG_MIPS_XXS1500) += arch/mips/alchemy/xxs1500/ libs-$(CONFIG_MIPS_XXS1500) += arch/mips/alchemy/xxs1500/
load-$(CONFIG_MIPS_XXS1500) += 0xffffffff80100000 load-$(CONFIG_MIPS_XXS1500) += 0xffffffff80100000
# must be last for Alchemy systems for GPIO to work properly
cflags-$(CONFIG_SOC_AU1X00) += -I$(srctree)/arch/mips/include/asm/mach-au1x00
# #
# Cobalt Server # Cobalt Server
# #
......
# au1000-style gpio
config ALCHEMY_GPIO_AU1000
bool
# select this in your board config if you don't want to use the gpio
# namespace as documented in the manuals. In this case however you need
# to create the necessary gpio_* functions in your board code/headers!
# see arch/mips/include/asm/mach-au1x00/gpio.h for more information.
config ALCHEMY_GPIO_INDIRECT
def_bool n
choice choice
prompt "Machine type" prompt "Machine type"
depends on MACH_ALCHEMY depends on MACH_ALCHEMY
...@@ -108,22 +119,27 @@ endchoice ...@@ -108,22 +119,27 @@ endchoice
config SOC_AU1000 config SOC_AU1000
bool bool
select SOC_AU1X00 select SOC_AU1X00
select ALCHEMY_GPIO_AU1000
config SOC_AU1100 config SOC_AU1100
bool bool
select SOC_AU1X00 select SOC_AU1X00
select ALCHEMY_GPIO_AU1000
config SOC_AU1500 config SOC_AU1500
bool bool
select SOC_AU1X00 select SOC_AU1X00
select ALCHEMY_GPIO_AU1000
config SOC_AU1550 config SOC_AU1550
bool bool
select SOC_AU1X00 select SOC_AU1X00
select ALCHEMY_GPIO_AU1000
config SOC_AU1200 config SOC_AU1200
bool bool
select SOC_AU1X00 select SOC_AU1X00
select ALCHEMY_GPIO_AU1000
config SOC_AU1X00 config SOC_AU1X00
bool bool
...@@ -134,4 +150,5 @@ config SOC_AU1X00 ...@@ -134,4 +150,5 @@ config SOC_AU1X00
select SYS_HAS_CPU_MIPS32_R1 select SYS_HAS_CPU_MIPS32_R1
select SYS_SUPPORTS_32BIT_KERNEL select SYS_SUPPORTS_32BIT_KERNEL
select SYS_SUPPORTS_APM_EMULATION select SYS_SUPPORTS_APM_EMULATION
select ARCH_REQUIRE_GPIOLIB select GENERIC_GPIO
select ARCH_WANT_OPTIONAL_GPIOLIB
...@@ -7,7 +7,14 @@ ...@@ -7,7 +7,14 @@
obj-y += prom.o irq.o puts.o time.o reset.o \ obj-y += prom.o irq.o puts.o time.o reset.o \
clocks.o platform.o power.o setup.o \ clocks.o platform.o power.o setup.o \
sleeper.o dma.o dbdma.o gpio.o sleeper.o dma.o dbdma.o
# optional gpiolib support
ifeq ($(CONFIG_ALCHEMY_GPIO_INDIRECT),)
ifeq ($(CONFIG_GPIOLIB),y)
obj-$(CONFIG_ALCHEMY_GPIO_AU1000) += gpiolib-au1000.o
endif
endif
obj-$(CONFIG_PCI) += pci.o obj-$(CONFIG_PCI) += pci.o
......
/* /*
* Copyright (C) 2007-2009, OpenWrt.org, Florian Fainelli <florian@openwrt.org> * Copyright (C) 2007-2009, OpenWrt.org, Florian Fainelli <florian@openwrt.org>
* Architecture specific GPIO support * GPIOLIB support for Au1000, Au1500, Au1100, Au1550 and Au12x0.
* *
* This program is free software; you can redistribute it and/or modify it * 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 * under the terms of the GNU General Public License as published by the
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
* 675 Mass Ave, Cambridge, MA 02139, USA. * 675 Mass Ave, Cambridge, MA 02139, USA.
* *
* Notes : * Notes :
* au1000 SoC have only one GPIO line : GPIO1 * au1000 SoC have only one GPIO block : GPIO1
* others have a second one : GPIO2 * Au1100, Au15x0, Au12x0 have a second one : GPIO2
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>
...@@ -34,168 +34,97 @@ ...@@ -34,168 +34,97 @@
#include <linux/gpio.h> #include <linux/gpio.h>
#include <asm/mach-au1x00/au1000.h> #include <asm/mach-au1x00/au1000.h>
#include <asm/gpio.h> #include <asm/mach-au1x00/gpio.h>
struct au1000_gpio_chip {
struct gpio_chip chip;
void __iomem *regbase;
};
#if !defined(CONFIG_SOC_AU1000) #if !defined(CONFIG_SOC_AU1000)
static int au1000_gpio2_get(struct gpio_chip *chip, unsigned offset) static int gpio2_get(struct gpio_chip *chip, unsigned offset)
{ {
u32 mask = 1 << offset; return alchemy_gpio2_get_value(offset + ALCHEMY_GPIO2_BASE);
struct au1000_gpio_chip *gpch;
gpch = container_of(chip, struct au1000_gpio_chip, chip);
return readl(gpch->regbase + AU1000_GPIO2_ST) & mask;
} }
static void au1000_gpio2_set(struct gpio_chip *chip, static void gpio2_set(struct gpio_chip *chip, unsigned offset, int value)
unsigned offset, int value)
{ {
u32 mask = ((GPIO2_OUT_EN_MASK << offset) | (!!value << offset)); alchemy_gpio2_set_value(offset + ALCHEMY_GPIO2_BASE, value);
struct au1000_gpio_chip *gpch;
unsigned long flags;
gpch = container_of(chip, struct au1000_gpio_chip, chip);
local_irq_save(flags);
writel(mask, gpch->regbase + AU1000_GPIO2_OUT);
local_irq_restore(flags);
} }
static int au1000_gpio2_direction_input(struct gpio_chip *chip, unsigned offset) static int gpio2_direction_input(struct gpio_chip *chip, unsigned offset)
{ {
u32 mask = 1 << offset; return alchemy_gpio2_direction_input(offset + ALCHEMY_GPIO2_BASE);
u32 tmp;
struct au1000_gpio_chip *gpch;
unsigned long flags;
gpch = container_of(chip, struct au1000_gpio_chip, chip);
local_irq_save(flags);
tmp = readl(gpch->regbase + AU1000_GPIO2_DIR);
tmp &= ~mask;
writel(tmp, gpch->regbase + AU1000_GPIO2_DIR);
local_irq_restore(flags);
return 0;
} }
static int au1000_gpio2_direction_output(struct gpio_chip *chip, static int gpio2_direction_output(struct gpio_chip *chip, unsigned offset,
unsigned offset, int value) int value)
{ {
u32 mask = 1 << offset; return alchemy_gpio2_direction_output(offset + ALCHEMY_GPIO2_BASE,
u32 out_mask = ((GPIO2_OUT_EN_MASK << offset) | (!!value << offset)); value);
u32 tmp; }
struct au1000_gpio_chip *gpch;
unsigned long flags;
gpch = container_of(chip, struct au1000_gpio_chip, chip);
local_irq_save(flags);
tmp = readl(gpch->regbase + AU1000_GPIO2_DIR);
tmp |= mask;
writel(tmp, gpch->regbase + AU1000_GPIO2_DIR);
writel(out_mask, gpch->regbase + AU1000_GPIO2_OUT);
local_irq_restore(flags);
return 0; static int gpio2_to_irq(struct gpio_chip *chip, unsigned offset)
{
return alchemy_gpio2_to_irq(offset + ALCHEMY_GPIO2_BASE);
} }
#endif /* !defined(CONFIG_SOC_AU1000) */ #endif /* !defined(CONFIG_SOC_AU1000) */
static int au1000_gpio1_get(struct gpio_chip *chip, unsigned offset) static int gpio1_get(struct gpio_chip *chip, unsigned offset)
{ {
u32 mask = 1 << offset; return alchemy_gpio1_get_value(offset + ALCHEMY_GPIO1_BASE);
struct au1000_gpio_chip *gpch;
gpch = container_of(chip, struct au1000_gpio_chip, chip);
return readl(gpch->regbase + AU1000_GPIO1_ST) & mask;
} }
static void au1000_gpio1_set(struct gpio_chip *chip, static void gpio1_set(struct gpio_chip *chip,
unsigned offset, int value) unsigned offset, int value)
{ {
u32 mask = 1 << offset; alchemy_gpio1_set_value(offset + ALCHEMY_GPIO1_BASE, value);
u32 reg_offset;
struct au1000_gpio_chip *gpch;
unsigned long flags;
gpch = container_of(chip, struct au1000_gpio_chip, chip);
if (value)
reg_offset = AU1000_GPIO1_OUT;
else
reg_offset = AU1000_GPIO1_CLR;
local_irq_save(flags);
writel(mask, gpch->regbase + reg_offset);
local_irq_restore(flags);
} }
static int au1000_gpio1_direction_input(struct gpio_chip *chip, unsigned offset) static int gpio1_direction_input(struct gpio_chip *chip, unsigned offset)
{ {
u32 mask = 1 << offset; return alchemy_gpio1_direction_input(offset + ALCHEMY_GPIO1_BASE);
struct au1000_gpio_chip *gpch;
gpch = container_of(chip, struct au1000_gpio_chip, chip);
writel(mask, gpch->regbase + AU1000_GPIO1_ST);
return 0;
} }
static int au1000_gpio1_direction_output(struct gpio_chip *chip, static int gpio1_direction_output(struct gpio_chip *chip,
unsigned offset, int value) unsigned offset, int value)
{ {
u32 mask = 1 << offset; return alchemy_gpio1_direction_output(offset + ALCHEMY_GPIO1_BASE,
struct au1000_gpio_chip *gpch; value);
}
gpch = container_of(chip, struct au1000_gpio_chip, chip);
writel(mask, gpch->regbase + AU1000_GPIO1_TRI_OUT);
au1000_gpio1_set(chip, offset, value);
return 0; static int gpio1_to_irq(struct gpio_chip *chip, unsigned offset)
{
return alchemy_gpio1_to_irq(offset + ALCHEMY_GPIO1_BASE);
} }
struct au1000_gpio_chip au1000_gpio_chip[] = { struct gpio_chip alchemy_gpio_chip[] = {
[0] = { [0] = {
.regbase = (void __iomem *)SYS_BASE, .label = "alchemy-gpio1",
.chip = { .direction_input = gpio1_direction_input,
.label = "au1000-gpio1", .direction_output = gpio1_direction_output,
.direction_input = au1000_gpio1_direction_input, .get = gpio1_get,
.direction_output = au1000_gpio1_direction_output, .set = gpio1_set,
.get = au1000_gpio1_get, .to_irq = gpio1_to_irq,
.set = au1000_gpio1_set, .base = ALCHEMY_GPIO1_BASE,
.base = 0, .ngpio = ALCHEMY_GPIO1_NUM,
.ngpio = 32,
},
}, },
#if !defined(CONFIG_SOC_AU1000) #if !defined(CONFIG_SOC_AU1000)
[1] = { [1] = {
.regbase = (void __iomem *)GPIO2_BASE, .label = "alchemy-gpio2",
.chip = { .direction_input = gpio2_direction_input,
.label = "au1000-gpio2", .direction_output = gpio2_direction_output,
.direction_input = au1000_gpio2_direction_input, .get = gpio2_get,
.direction_output = au1000_gpio2_direction_output, .set = gpio2_set,
.get = au1000_gpio2_get, .to_irq = gpio2_to_irq,
.set = au1000_gpio2_set, .base = ALCHEMY_GPIO2_BASE,
.base = AU1XXX_GPIO_BASE, .ngpio = ALCHEMY_GPIO2_NUM,
.ngpio = 32,
},
}, },
#endif #endif
}; };
static int __init au1000_gpio_init(void) static int __init alchemy_gpiolib_init(void)
{ {
gpiochip_add(&au1000_gpio_chip[0].chip); gpiochip_add(&alchemy_gpio_chip[0]);
#if !defined(CONFIG_SOC_AU1000) #if !defined(CONFIG_SOC_AU1000)
gpiochip_add(&au1000_gpio_chip[1].chip); gpiochip_add(&alchemy_gpio_chip[1]);
#endif #endif
return 0; return 0;
} }
arch_initcall(au1000_gpio_init); arch_initcall(alchemy_gpiolib_init);
This diff is collapsed.
#ifndef _AU1XXX_GPIO_H_ #ifndef _ALCHEMY_GPIO_H_
#define _AU1XXX_GPIO_H_ #define _ALCHEMY_GPIO_H_
#include <linux/types.h> #if defined(CONFIG_ALCHEMY_GPIO_AU1000)
#define AU1XXX_GPIO_BASE 200 #include <asm/mach-au1x00/gpio-au1000.h>
/* GPIO bank 1 offsets */ #endif
#define AU1000_GPIO1_TRI_OUT 0x0100
#define AU1000_GPIO1_OUT 0x0108
#define AU1000_GPIO1_ST 0x0110
#define AU1000_GPIO1_CLR 0x010C
/* GPIO bank 2 offsets */ #endif /* _ALCHEMY_GPIO_H_ */
#define AU1000_GPIO2_DIR 0x00
#define AU1000_GPIO2_RSVD 0x04
#define AU1000_GPIO2_OUT 0x08
#define AU1000_GPIO2_ST 0x0C
#define AU1000_GPIO2_INT 0x10
#define AU1000_GPIO2_EN 0x14
#define GPIO2_OUT_EN_MASK 0x00010000
#define gpio_to_irq(gpio) NULL
#define gpio_get_value __gpio_get_value
#define gpio_set_value __gpio_set_value
#define gpio_cansleep __gpio_cansleep
#include <asm-generic/gpio.h>
#endif /* _AU1XXX_GPIO_H_ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment