bcmring: add gpio support
Subsystems (2)
PATCH 1/1 bcmring: add gpio support
add gpio.c and gpio_irq.c
Signed-off-by Leo Hao Chen <[email protected]>
--- arch/arm/mach-bcmring/gpio.c | 291 +++++++++++++++++++++++++++++ arch/arm/mach-bcmring/gpio_irq.c | 381 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 672 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-bcmring/gpio.c create mode 100644 arch/arm/mach-bcmring/gpio_irq.c
arch/arm/mach-bcmring/gpio.c new file +291 -0
@@ -0,0 +1,291 @@ +/***************************************************************************** +* Copyright 2004 - 2008 Broadcom Corporation. All rights reserved. +* +* Unless you and Broadcom execute a separate written software license +* agreement governing use of this software, this software is licensed to you +* under the terms of the GNU General Public License version 2, available at +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL"). +* +* Notwithstanding the above, under no circumstances may you combine this +* software in any way with any other Broadcom software provided under a +* license other than the GPL, without Broadcom's express prior written +* consent. +*****************************************************************************/ + +/**************************************************************************** +* +* gpio.c +* +* PURPOSE: +* +* This file implements the GPIO chips required to support the onchip +* gpio pins, as per gpiolib +* +*****************************************************************************/ + +/* ---- Include Files ---------------------------------------------------- */ + +#include <linux/types.h> +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/seq_file.h> +#include <linux/irq.h> +#include <linux/gpio.h> + +#include <mach/gpio_defs.h> +#include <mach/csp/gpiomux.h> +#include <mach/csp/chipcHw_inline.h> + +/* ---- Public Variables ------------------------------------------------- */ + +/* ---- Private Constants and Types -------------------------------------- */ + +typedef struct { +struct gpio_chip chip; +volatile GPIOHW_REG_t *reg; + +}bcmring_gpio_chip ; + +/* ---- Private Function Prototypes -------------------------------------- */ + +/* ---- Private Variables ------------------------------------------------ */ + +/* ---- Functions -------------------------------------------------------- */ + +/**************************************************************************** +* +* Called whenever gpio_request is called. This will force the pin to be +* a GPIO pin. If you want it to be something else, then gpiomux_request +* should be called instead. +* +*****************************************************************************/ + +static int gpio_bcmring_request (struct gpio_chip *chip,unsigned offset) +{ +unsigned gpio; +bcmring_gpio_chip *bcmring_chip = +container_of (chip, bcmring_gpio_chip, chip); + + gpio = bcmring_chip->chip.base + offset; + +/* +* Ensure that the pin is actually configured as a GPIO. If it isn't then +* that means that somebody called chipcHW_setGpioPinFunction directly +* which is a no-no. +*/ + +if (chipcHw_getGpioPinFunction (gpio) != chipcHw_GPIO_FUNCTION_GPIO) { +printk (KERN_ERR +"%s: Error - gpio %d not configured as a GPIO pin\n" , + __FUNCTION__, gpio); +return -EBUSY ; + } + +return 0 ; + +}/* gpio_bcmring_request */ + +/**************************************************************************** +* +* Configure a GPIO pin as an input pin +* +*****************************************************************************/ + +static int gpio_bcmring_direction_input (struct gpio_chip *chip,unsigned offset) +{ +bcmring_gpio_chip *bcmring_chip = +container_of (chip, bcmring_gpio_chip, chip); + +GpioHwReg_SetDirInput (bcmring_chip->reg, offset); + +return 0 ; + +}/* gpio_bcmring_direction_input */ + +/**************************************************************************** +* +* Configure a GPIO pin as an output pin and sets its initial value. +* +*****************************************************************************/ + +static int gpio_bcmring_direction_output (struct gpio_chip *chip, +unsigned offset,int value) +{ +bcmring_gpio_chip *bcmring_chip = +container_of (chip, bcmring_gpio_chip, chip); + +GpioHwReg_SetValDirOutput (bcmring_chip->reg, offset, value); + +return 0 ; + +}/* gpio_bcmring_direction_output */ + +/**************************************************************************** +* +* Retrieve the value of a GPIO pin. Note that this returns zero or the raw +* value. +* +*****************************************************************************/ + +static int gpio_bcmring_get (struct gpio_chip *chip,unsigned offset) +{ +bcmring_gpio_chip *bcmring_chip = +container_of (chip, bcmring_gpio_chip, chip); +int val; + + val =GpioHwReg_GetVal (bcmring_chip->reg, offset); + +return val; + +}/* gpio_bcmring_get */ + +/**************************************************************************** +* +* Set the value of a GPIO pin +* +*****************************************************************************/ + +static void gpio_bcmring_set (struct gpio_chip *chip,unsigned offset,int value) +{ +bcmring_gpio_chip *bcmring_chip = +container_of (chip, bcmring_gpio_chip, chip); + +GpioHwReg_SetVal (bcmring_chip->reg, offset, value); + +}/* gpio_bcmring_set */ + +/**************************************************************************** +* +* gpiolib chip description +* +*****************************************************************************/ + +/* +* Note: If you need to add a field, like a register base, then create a new +* structure which includes the gpio_chip as the first element and has +* the custom fields after. See asm-arm/arch-pxa/gpio.c for an example. +*/ + +static bcmring_gpio_chip gpio_bcmring_chip[] = { + [0 ] = { + .reg =gpioRegP (0 ), + .chip = { + .label ="bcmring-low" , + .request = gpio_bcmring_request, + .direction_input = gpio_bcmring_direction_input, + .direction_output = gpio_bcmring_direction_output, + .get = gpio_bcmring_get, + .set = gpio_bcmring_set, + .base =0 , + .ngpio =GPIOHW_NUM_PINS_LOWER_BLOCK , + }, + }, + [1 ] = { + .reg =gpioRegP (1 ), + .chip = { + .label ="bcmring-high" , + .request = gpio_bcmring_request, + .direction_input = gpio_bcmring_direction_input, + .direction_output = gpio_bcmring_direction_output, + .get = gpio_bcmring_get, + .set = gpio_bcmring_set, + .base =GPIOHW_NUM_PINS_LOWER_BLOCK , + .ngpio =GPIOHW_NUM_PINS_HIGHER_BLOCK , + }, + }, +}; + +/****************************************************************************/ +/** +* @brief mux_isRequested +* +* Find out if a gpio pin has already been requested in the gpiolib sense. +* +* @return +* none +*/ +/****************************************************************************/ +static const char *mux_isRequested (gpio_defs_e pin) +{ +int i; + +/* +* For now, convert pin number to chip and offset. Later, convert this +* into a gpiomux register/chip array structure. Since this is typically +* init time code, it may not be worth worrying about for this one case. +*/ +for (i =0 ; i <ARRAY_LEN (gpio_bcmring_chip); i++) { +struct gpio_chip *chipp = &gpio_bcmring_chip[i].chip; +int base = chipp->base; +if ((pin >= base) && (pin < base + chipp->ngpio)) { +return gpiochip_is_requested (chipp, pin - base); + } + } +return NULL ; + +}/* mux_isRequested */ + +/****************************************************************************/ +/** +* @brief mux_request +* +* Request a pin from gpiolib. +* +*/ +/****************************************************************************/ +static int mux_request (gpio_defs_e pin,const char *label) +{ +return gpio_request (pin, label); + +}/* mux_request */ + +/****************************************************************************/ +/** +* @brief mux_free +* +* Free a pin from gpiolib. +* +*/ +/****************************************************************************/ +static void mux_free (gpio_defs_e pin) +{ +return gpio_free (pin); + +}/* mux_free */ + +/**************************************************************************** +* +* brcm_init_gpio +* +* Sets up gpiolib so that it's aware of how to manipulate our GPIOs +* +*****************************************************************************/ + +void __init brcm_init_gpio (void ) +{ +gpiomux_init_t initstruct; + +gpiochip_add (&gpio_bcmring_chip[0 ].chip); +gpiochip_add (&gpio_bcmring_chip[1 ].chip); + +/* Initialize callbacks for gpiomux function calls into gpiolib */ + initstruct.request_gpio = mux_request; + initstruct.free_gpio = mux_free; + initstruct.is_requested = mux_isRequested; +gpiomux_Init (&initstruct); + +/* +* gpiomux_Init skips pins 14 and 15 (which makes sense when gpiomux_Init +* is called from within the bootloaders. +* +* However, from this point forward in the code, gpiolib "owns" the pins. So +* if you want these pins to be UART1, then you should call gpiomux_request +* after this so that the pins gets reserved inside gpiolib. +*/ + +chipcHw_setGpioPinFunction (GPIO14_UART1_TXD , + chipcHw_GPIO_FUNCTION_GPIO); +chipcHw_setGpioPinFunction (GPIO15_UART1_RXD , + chipcHw_GPIO_FUNCTION_GPIO); + +}/* brcm_init_gpio */
arch/arm/mach-bcmring/gpio_irq.c new file +381 -0
381 lines not on this page · raw message
Signature · 3 lines
1.6.0.6 Leo Chen