Alchemy GPIO rewrite v7
cover Alchemy GPIO rewrite v7
Rewrite Alchemy GPIO support to be compatible with the Linux GPIO framework, both with and without gpiolib. For a list of reasons, see blurb in patch #2.
Patches #3-#5 replace a few open-coded GPIO accesses in the board files with calls to the new gpio functions.
Tested on DB1200 and a custom Au1200 platform.
History:
v7 - fix config variable evaluation bug in alchemy/Makefile
renamed gpio-au1000.c to gpiolib-au1000.c because it's only supposed
to be built when gpiolib is used.
lots of build- and bugfixes in patches #3, #5
v6 - renamed gpio.[ch] to gpio-au1000.[ch], since this code only affects
pre-Au1300 chips. Should make integration of Au1300 GPIO a bit easier.
v5 - fix gpio1 bug in inlined gpio_get_value()
v4 - GPIO2 shared interrupt management, styling.
v3 - fixed thinko in alchemy_gpio2_set_value (16->32 bit)
v2 - added gpio_to_irq and irq_to_gpio, some renaming.
Manuel Lauss (5):
Alchemy: remove unused au1000_gpio.h header
Alchemy: rewrite GPIO support.
Alchemy: mtx-1: use linux gpio api.
Alchemy: xxs1500: use linux gpio api.
Alchemy: devboards: convert to gpio calls.
arch/mips/Makefile | 5 +- arch/mips/alchemy/Kconfig | 19 +- arch/mips/alchemy/common/Makefile | 9 +- arch/mips/alchemy/common/gpio.c | 201 ------- arch/mips/alchemy/common/gpiolib-au1000.c | 130 +++++ arch/mips/alchemy/common/reset.c | 5 +- arch/mips/alchemy/devboards/db1x00/board_setup.c | 12 +- arch/mips/alchemy/devboards/pb1000/board_setup.c | 10 +- arch/mips/alchemy/devboards/pb1100/board_setup.c | 3 +- arch/mips/alchemy/devboards/pb1500/board_setup.c | 10 +- arch/mips/alchemy/devboards/pm.c | 3 +- arch/mips/alchemy/mtx-1/board_setup.c | 24 +- arch/mips/alchemy/xxs1500/board_setup.c | 21 +- arch/mips/include/asm/mach-au1x00/au1000_gpio.h | 56 -- arch/mips/include/asm/mach-au1x00/gpio-au1000.h | 604 ++++++++++++++++++++++ arch/mips/include/asm/mach-au1x00/gpio.h | 35 +- 16 files changed, 821 insertions(+), 326 deletions(-) delete mode 100644 arch/mips/alchemy/common/gpio.c create mode 100644 arch/mips/alchemy/common/gpiolib-au1000.c delete mode 100644 arch/mips/include/asm/mach-au1x00/au1000_gpio.h create mode 100644 arch/mips/include/asm/mach-au1x00/gpio-au1000.h
PATCH 1/5 Alchemy: remove unused au1000_gpio.h header
--- arch/mips/include/asm/mach-au1x00/au1000_gpio.h | 56 ----------------------- 1 files changed, 0 insertions(+), 56 deletions(-) delete mode 100644 arch/mips/include/asm/mach-au1x00/au1000_gpio.h
arch/mips/include/asm/mach-au1x00/au1000_gpio.h deleted +0 -56
@@ -1,56 +0,0 @@ -/* -* FILE NAME au1000_gpio.h -* -* BRIEF MODULE DESCRIPTION -* API to Alchemy Au1xx0 GPIO device. -* -* Author: MontaVista Software, Inc. <[email protected]> -* Steve Longerbeam -* -* Copyright 2001, 2008 MontaVista Software Inc. -* -* 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. -* -* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN -* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF -* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -* You should have received a copy of the GNU General Public License along -* with this program; if not, write to the Free Software Foundation, Inc., -* 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#ifndef __AU1000_GPIO_H -#define __AU1000_GPIO_H - -#include <linux/ioctl.h> - -#define AU1000GPIO_IOC_MAGIC 'A' - -#define AU1000GPIO_IN _IOR(AU1000GPIO_IOC_MAGIC, 0, int) -#define AU1000GPIO_SET _IOW(AU1000GPIO_IOC_MAGIC, 1, int) -#define AU1000GPIO_CLEAR _IOW(AU1000GPIO_IOC_MAGIC, 2, int) -#define AU1000GPIO_OUT _IOW(AU1000GPIO_IOC_MAGIC, 3, int) -#define AU1000GPIO_TRISTATE _IOW(AU1000GPIO_IOC_MAGIC, 4, int) -#define AU1000GPIO_AVAIL_MASK _IOR(AU1000GPIO_IOC_MAGIC, 5, int) - -#ifdef __KERNEL__ -extern u32 get_au1000_avail_gpio_mask (void ); -extern int au1000gpio_tristate (u32 data); -extern int au1000gpio_in (u32 *data); -extern int au1000gpio_set (u32 data); -extern int au1000gpio_clear (u32 data); -extern int au1000gpio_out (u32 data); -#endif - -#endif
Signature · 1 line
1.6.3.1
PATCH 2/5 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.
--- arch/mips/Makefile | 5 +- arch/mips/alchemy/Kconfig | 19 +- arch/mips/alchemy/common/Makefile | 9 +- arch/mips/alchemy/common/gpio.c | 201 -------- arch/mips/alchemy/common/gpiolib-au1000.c | 130 +++++ arch/mips/include/asm/mach-au1x00/gpio-au1000.h | 604 +++++++++++++++++++++++ arch/mips/include/asm/mach-au1x00/gpio.h | 35 +-- 7 files changed, 770 insertions(+), 233 deletions(-) delete mode 100644 arch/mips/alchemy/common/gpio.c create mode 100644 arch/mips/alchemy/common/gpiolib-au1000.c create mode 100644 arch/mips/include/asm/mach-au1x00/gpio-au1000.h
arch/mips/Makefile +4 -1
@@ -184,7 +184,6 @@ load-$(CONFIG_MACH_JAZZ) += 0xffffffff80080000 # Common Alchemy Au1x00 stuff # 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
@@ -282,6 +281,10 @@ load-$(CONFIG_MIPS_MTX1) += 0xffffffff80100000 libs-$(CONFIG_MIPS_XXS1500) += arch/mips/alchemy/xxs1500/ 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 #
arch/mips/alchemy/Kconfig +18 -1
@@ -1,3 +1,14 @@ +# 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 prompt "Machine type" depends on MACH_ALCHEMY
@@ -108,22 +119,27 @@ endchoice config SOC_AU1000 bool select SOC_AU1X00 + select ALCHEMY_GPIO_AU1000 config SOC_AU1100 bool select SOC_AU1X00 + select ALCHEMY_GPIO_AU1000 config SOC_AU1500 bool select SOC_AU1X00 + select ALCHEMY_GPIO_AU1000 config SOC_AU1550 bool select SOC_AU1X00 + select ALCHEMY_GPIO_AU1000 config SOC_AU1200 bool select SOC_AU1X00 + select ALCHEMY_GPIO_AU1000 config SOC_AU1X00 bool
@@ -134,4 +150,5 @@ config SOC_AU1X00 select SYS_HAS_CPU_MIPS32_R1 select SYS_SUPPORTS_32BIT_KERNEL select SYS_SUPPORTS_APM_EMULATION - select ARCH_REQUIRE_GPIOLIB + select GENERIC_GPIO + select ARCH_WANT_OPTIONAL_GPIOLIB
arch/mips/alchemy/common/Makefile +8 -1
@@ -7,7 +7,14 @@ obj-y += prom.o irq.o puts.o time.o reset.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
arch/mips/alchemy/common/gpio.c deleted +0 -201
201 lines not on this page · raw message
arch/mips/alchemy/common/gpiolib-au1000.c new file +130 -0
130 lines not on this page · raw message
arch/mips/include/asm/mach-au1x00/gpio-au1000.h new file +604 -0
604 lines not on this page · raw message
arch/mips/include/asm/mach-au1x00/gpio.h +6 -29
@@ -1,33 +1,10 @@ -#ifndef _AU1XXX_GPIO_H_ -#define _AU1XXX_GPIO_H_ +#ifndef _ALCHEMY_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 */ -#define AU1000_GPIO1_TRI_OUT 0x0100 -#define AU1000_GPIO1_OUT 0x0108 -#define AU1000_GPIO1_ST 0x0110 -#define AU1000_GPIO1_CLR 0x010C +#endif -/* GPIO bank 2 offsets */ -#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_ */ +#endif /* _ALCHEMY_GPIO_H_ */
Signature · 1 line
1.6.3.1
PATCH 3/5 Alchemy: mtx-1: use linux gpio api.
Replace a few GPIO register accesses in the board init code with calls to the gpio api.
--- arch/mips/alchemy/mtx-1/board_setup.c | 24 +++++++++++++----------- 1 files changed, 13 insertions(+), 11 deletions(-)
arch/mips/alchemy/mtx-1/board_setup.c +13 -11
@@ -28,6 +28,7 @@* 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include <linux/gpio.h> #include <linux/init.h> #include <asm/mach-au1x00/au1000.h>
@@ -55,10 +56,11 @@ void __init board_setup(void) }#endif +alchemy_gpio2_enable (); +#if defined(CONFIG_USB_OHCI_HCD ) || defined(CONFIG_USB_OHCI_HCD_MODULE )/* Enable USB power switch */ -au_writel (au_readl (GPIO2_DIR ) |0x10 ,GPIO2_DIR ); -au_writel (0x100000 ,GPIO2_OUTPUT ); +alchemy_gpio_direction_output (204 ,0 );#endif /* defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) */ #ifdef CONFIG_PCI
@@ -74,14 +76,14 @@ void __init board_setup(void)/* Initialize GPIO */ au_writel (0xFFFFFFFF ,SYS_TRIOUTCLR ); -au_writel (0x00000001 ,SYS_OUTPUTCLR );/* set M66EN (PCI 66MHz) to OFF */ -au_writel (0x00000008 ,SYS_OUTPUTSET );/* set PCI CLKRUN# to OFF */ -au_writel (0x00000002 ,SYS_OUTPUTSET );/* set EXT_IO3 ON */ -au_writel (0x00000020 ,SYS_OUTPUTCLR );/* set eth PHY TX_ER to OFF */ +alchemy_gpio_direction_output (0 ,0 );/* set M66EN (PCI 66MHz) to OFF */ +alchemy_gpio_direction_output (3 ,1 );/* set PCI CLKRUN# to OFF */ +alchemy_gpio_direction_output (1 ,1 );/* set EXT_IO3 ON */ +alchemy_gpio_direction_output (5 ,0 );/* set eth PHY TX_ER to OFF */ /* Enable LED and set it to green */ -au_writel (au_readl (GPIO2_DIR ) |0x1800 ,GPIO2_DIR ); -au_writel (0x18000800 ,GPIO2_OUTPUT ); +alchemy_gpio_direction_output (211 ,1 );/* green on */ +alchemy_gpio_direction_output (212 ,0 );/* red off */ board_pci_idsel = mtx1_pci_idsel;
@@ -101,10 +103,10 @@ mtx1_pci_idsel(unsigned int devsel, int assert)if (assert && devsel !=0 )/* Suppress signal to Cardbus */ -au_writel (0x00000002 ,SYS_OUTPUTCLR );/* set EXT_IO3 OFF */ +gpio_set_value (1 ,0 );/* set EXT_IO3 OFF */ else -au_writel (0x00000002 ,SYS_OUTPUTSET );/* set EXT_IO3 ON */ +gpio_set_value (1 ,1 );/* set EXT_IO3 ON */ +au_sync_udelay (1 );return 1 ; } -
Signature · 1 line
1.6.3.1
PATCH 4/5 Alchemy: xxs1500: use linux gpio api.
Replace a few GPIO register accesses in the board init code with calls to the gpio api.
--- arch/mips/alchemy/xxs1500/board_setup.c | 21 ++++++++++++--------- 1 files changed, 12 insertions(+), 9 deletions(-)
arch/mips/alchemy/xxs1500/board_setup.c +12 -9
@@ -23,6 +23,7 @@* 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include <linux/gpio.h> #include <linux/init.h> #include <linux/delay.h>
@@ -50,6 +51,9 @@ void __init board_setup(void) }#endif +alchemy_gpio1_input_enable (); +alchemy_gpio2_enable (); +/* Set multiple use pins (UART3/GPIO) to UART (it's used as UART too) */ pin_func =au_readl (SYS_PINFUNC ) & ~SYS_PF_UR3 ; pin_func |=SYS_PF_UR3 ;
@@ -65,20 +69,19 @@ void __init board_setup(void)au_writel (0x01 ,UART3_ADDR +UART_MCR );/* UART_MCR_DTR is 0x01??? */ #ifdef CONFIG_PCMCIA_XXS1500 -/* Setup PCMCIA signals */ -au_writel (0 ,SYS_PININPUTEN ); -/* GPIO 0, 1, and 4 are inputs */ -au_writel (1 | (1 <<1 ) | (1 <<4 ),SYS_TRIOUTCLR ); +alchemy_gpio_direction_input (0 ); +alchemy_gpio_direction_input (1 ); +alchemy_gpio_direction_input (4 ); -/* Enable GPIO2 if not already enabled */ -au_writel (1 ,GPIO2_ENABLE );/* GPIO2 208/9/10/11 are inputs */ -au_writel ((1 <<8 ) | (1 <<9 ) | (1 <<10 ) | (1 <<11 ),GPIO2_DIR ); +alchemy_gpio_direction_input (208 ); +alchemy_gpio_direction_input (209 ); +alchemy_gpio_direction_input (210 ); +alchemy_gpio_direction_input (211 );/* Turn off power */ -au_writel ((au_readl (GPIO2_PINSTATE ) & ~(1 <<14 )) | (1 <<30 ), -GPIO2_OUTPUT ); +alchemy_gpio_direction_output (214 ,0 );#endif #ifdef CONFIG_PCI
Signature · 1 line
1.6.3.1
PATCH 5/5 Alchemy: devboards: convert to gpio calls.
Replace a few open-coded GPIO register accesses with gpio calls.
--- arch/mips/alchemy/common/reset.c | 5 +++-- arch/mips/alchemy/devboards/db1x00/board_setup.c | 12 ++++++------ arch/mips/alchemy/devboards/pb1000/board_setup.c | 10 +++++++--- arch/mips/alchemy/devboards/pb1100/board_setup.c | 3 ++- arch/mips/alchemy/devboards/pb1500/board_setup.c | 10 ++++++---- arch/mips/alchemy/devboards/pm.c | 3 ++- 6 files changed, 26 insertions(+), 17 deletions(-)
arch/mips/alchemy/common/reset.c +3 -2
@@ -27,8 +27,9 @@* 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <asm/cacheflush.h> +#include <linux/gpio.h> +#include <asm/cacheflush.h> #include <asm/mach-au1x00/au1000.h> void au1000_restart (char *command)
@@ -161,7 +162,7 @@ void au1000_halt(void)#else printk (KERN_NOTICE "\n** You can safely turn off the power\n" );#ifdef CONFIG_MIPS_MIRAGE -au_writel ((1 <<26 ) | (1 <<10 ),GPIO2_OUTPUT ); +gpio_direction_output (210 ,1 );#endif #ifdef CONFIG_MIPS_DB1200 au_writew (au_readw (0xB980001C ) | (1 <<14 ),0xB980001C );
arch/mips/alchemy/devboards/db1x00/board_setup.c +6 -6
@@ -27,6 +27,7 @@* 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include <linux/gpio.h> #include <linux/init.h> #include <asm/mach-au1x00/au1000.h>
@@ -94,12 +95,12 @@ void __init board_setup(void)#endif bcsr->pcmcia =0x0000 ;/* turn off PCMCIA power */ -#ifdef CONFIG_MIPS_MIRAGE /* Enable GPIO[31:0] inputs */ -au_writel (0 ,SYS_PININPUTEN ); +alchemy_gpio1_input_enable (); -/* GPIO[20] is output, tristate the other input primary GPIOs */ -au_writel (~(1 <<20 ),SYS_TRIOUTCLR ); +#ifdef CONFIG_MIPS_MIRAGE +/* GPIO[20] is output */ +alchemy_gpio_direction_output (20 ,0 );/* Set GPIO[210:208] instead of SSI_0 */ pin_func =au_readl (SYS_PINFUNC ) |SYS_PF_S0 ;
@@ -118,8 +119,7 @@ void __init board_setup(void)* Enable speaker amplifier. This should * be part of the audio driver. */ -au_writel (au_readl (GPIO2_DIR ) |0x200 ,GPIO2_DIR ); -au_writel (0x02000200 ,GPIO2_OUTPUT ); +alchemy_gpio_direction_output (209 ,1 );#endif au_sync ();
arch/mips/alchemy/devboards/pb1000/board_setup.c +7 -3
@@ -24,6 +24,7 @@*/ #include <linux/delay.h> +#include <linux/gpio.h> #include <linux/init.h> #include <linux/interrupt.h> #include <asm/mach-au1x00/au1000.h>
@@ -130,8 +131,11 @@ void __init board_setup(void) pin_func |=SYS_PF_USB ;au_writel (pin_func,SYS_PINFUNC ); -au_writel (0x2800 ,SYS_TRIOUTCLR ); -au_writel (0x0030 ,SYS_OUTPUTCLR ); + +alchemy_gpio_direction_input (11 ); +alchemy_gpio_direction_input (13 ); +alchemy_gpio_direction_output (4 ,0 ); +alchemy_gpio_direction_output (5 ,0 );#endif /* defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) */ /* Make GPIO 15 an input (for interrupt line) */
@@ -140,7 +144,7 @@ void __init board_setup(void) pin_func |=SYS_PF_I2S ;au_writel (pin_func,SYS_PINFUNC ); -au_writel (0x8000 ,SYS_TRIOUTCLR ); +alchemy_gpio_direction_input (15 ); static_cfg0 =au_readl (MEM_STCFG0 ) & ~0xc00 ;au_writel (static_cfg0,MEM_STCFG0 );
arch/mips/alchemy/devboards/pb1100/board_setup.c +2 -1
@@ -23,6 +23,7 @@* 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include <linux/gpio.h> #include <linux/init.h> #include <linux/delay.h> #include <linux/interrupt.h>
@@ -88,7 +89,7 @@ void __init board_setup(void)/* Set AUX clock to 12 MHz * 8 = 96 MHz */ au_writel (8 ,SYS_AUXPLL ); -au_writel (0 ,SYS_PININPUTEN ); +alchemy_gpio1_input_enable ();udelay (100 );#if defined(CONFIG_USB_OHCI_HCD ) || defined(CONFIG_USB_OHCI_HCD_MODULE )
arch/mips/alchemy/devboards/pb1500/board_setup.c +6 -4
@@ -23,8 +23,9 @@* 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <linux/init.h> #include <linux/delay.h> +#include <linux/gpio.h> +#include <linux/init.h> #include <linux/interrupt.h> #include <asm/mach-au1x00/au1000.h>
@@ -90,11 +91,12 @@ void __init board_setup(void)au_writel (0 ,SYS_PINSTATERD );udelay (100 ); -#if defined(CONFIG_USB_OHCI_HCD ) || defined(CONFIG_USB_OHCI_HCD_MODULE ) -/* GPIO201 is input for PCMCIA card detect */ /* GPIO203 is input for PCMCIA interrupt request */ -au_writel (au_readl (GPIO2_DIR ) & ~((1 <<1 ) | (1 <<3 )),GPIO2_DIR ); +alchemy_gpio_direction_input (201 ); +alchemy_gpio_direction_input (203 ); + +#if defined(CONFIG_USB_OHCI_HCD ) || defined(CONFIG_USB_OHCI_HCD_MODULE )/* Zero and disable FREQ2 */ sys_freqctrl =au_readl (SYS_FREQCTRL0 );
arch/mips/alchemy/devboards/pm.c +2 -1
@@ -9,6 +9,7 @@#include <linux/suspend.h> #include <linux/sysfs.h> #include <asm/mach-au1x00/au1000.h> +#include <asm/mach-au1x00/gpio.h> /* * Generic suspend userspace interface for Alchemy development boards.
@@ -26,7 +27,7 @@ static unsigned long db1x_pm_last_wakesrc;static int db1x_pm_enter (suspend_state_t state) {/* enable GPIO based wakeup */ -au_writel (1 ,SYS_PININPUTEN ); +alchemy_gpio1_input_enable ();/* clear and setup wake cause and source */ au_writel (0 ,SYS_WAKEMSK );
Signature · 1 line
1.6.3.1
On Sat, Jun 06, 2009 at 02:09:53PM +0200, Manuel Lauss wrote:
Thanks, queued. Looking much better than earlier versions but there still are many magic numbers being used in the code.
Ralf
Quoted 2 lines · Ralf Baechle
Thanks, queued. Looking much better than earlier versions but there still are many magic numbers being used in the code.
Thanks!
Does the below patch address your concerns?
---
From: Manuel Lauss <[email protected]>
Subject: [PATCH] Alchemy: gpio: document magic numbers.
--- arch/mips/include/asm/mach-au1x00/au1000.h | 3 +++ arch/mips/include/asm/mach-au1x00/gpio-au1000.h | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-)
arch/mips/include/asm/mach-au1x00/au1000.h +3 -0
@@ -1550,6 +1550,9 @@ enum soc_au1200_ints {#define GPIO2_INTENABLE (GPIO2_BASE + 0x10)#define GPIO2_ENABLE (GPIO2_BASE + 0x14) +#define GPIO2_ENABLE_RESET (1 << 1)/* reset peripheral */ +#define GPIO2_ENABLE_CLK (1 << 0)/* clock enable */ +/* Power Management */ #define SYS_SCRATCH0 0xB1900018#define SYS_SCRATCH1 0xB190001C
arch/mips/include/asm/mach-au1x00/gpio-au1000.h +9 -4
@@ -275,10 +275,15 @@ static inline void __alchemy_gpio2_mod_dir(int gpio, int to_out)au_sync (); } +/* GPIO2_OUTPUT expects the levels of output pins in bits 0-15; +* bits 16-31 indicate whether the level change should be carried out +* for a particular pin. +*/ static inline void alchemy_gpio2_set_value (int gpio,int v) {unsigned long mask; - mask = ((v) ?0x00010001 :0x00010000 ) << (gpio -ALCHEMY_GPIO2_BASE ); + mask = (1 <<16 ) | (v ?1 :0 );/* set up en | value */ + mask <<= gpio -ALCHEMY_GPIO2_BASE ;au_writel (mask,GPIO2_OUTPUT );au_sync (); }
@@ -420,9 +425,9 @@ static inline void alchemy_gpio2_disable_int(int gpio2)*/ static inline void alchemy_gpio2_enable (void ) { -au_writel (3 ,GPIO2_ENABLE );/* reset, clock enabled */ +au_writel (GPIO2_ENABLE_RESET |GPIO2_ENABLE_CLK ,GPIO2_ENABLE );au_sync (); -au_writel (1 ,GPIO2_ENABLE );/* clock enabled */ +au_writel (GPIO2_ENABLE_CLK ,GPIO2_ENABLE );au_sync (); }
@@ -433,7 +438,7 @@ static inline void alchemy_gpio2_enable(void)*/ static inline void alchemy_gpio2_disable (void ) { -au_writel (2 ,GPIO2_ENABLE );/* reset, clock disabled */ +au_writel (GPIO2_ENABLE_RESET ,GPIO2_ENABLE );au_sync (); }
Signature · 1 line
1.6.3.1