ipq806x: implement GPIO API

Add implementation of the GPIO API defined in src/include/gpiolib.h.
Also, clean up the GPIO driver, make it use pointers instead of
integers for register address.

This requires a touch in the SPI driver, where the CS GPIO is toggled
and in the board function where it enables USB interface.

BUG=chrome-os-partner:30489
TEST=tested with the following patches, observed proto0 properly read
     the board ID.

Original-Change-Id: I0962947c6bb32a854ca300752d259a48e9e7b4eb
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/210115
Original-Reviewed-by: David Hendricks <dhendrix@chromium.org>
(cherry picked from commit e951f735001509d135cc61530ed0eecb5fc31a85)
Signed-off-by: Marc Jones <marc.jones@se-eng.com>

Change-Id: I8a612dce000931835054086c1b02ebfc43dc57d2
Reviewed-on: http://review.coreboot.org/8718
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
This commit is contained in:
Vadim Bendebury 2014-07-25 17:34:42 -07:00 committed by Patrick Georgi
parent 9c9c336464
commit d36ef6a51d
5 changed files with 58 additions and 63 deletions

View File

@ -40,6 +40,7 @@ static void setup_usb(void)
#if !CONFIG_BOARD_VARIANT_AP148
gpio_tlmm_config_set(USB_ENABLE_GPIO, FUNC_SEL_GPIO,
GPIO_PULL_UP, GPIO_10MA, GPIO_ENABLE);
gpio_set_out_value(USB_ENABLE_GPIO, 1);
#endif
usb_clock_config();

View File

@ -50,20 +50,20 @@ static inline int gpio_not_valid(gpio_t gpio)
Function description: configure GPIO functinality
Arguments :
gpio_t gpio - Gpio number
unsigned int func - Functionality number
unsigned int pull - pull up/down, no pull range(0-3)
unsigned int drvstr - range (0 - 7)-> (2- 16)MA steps of 2
unsigned int enable - 1 - Disable, 2- Enable.
unsigned func - Functionality number
unsigned pull - pull up/down, no pull range(0-3)
unsigned drvstr - range (0 - 7)-> (2- 16)MA steps of 2
unsigned enable - 0 Disable, 1 - Enable.
Return : None
*******************************************************/
void gpio_tlmm_config_set(gpio_t gpio, unsigned int func,
unsigned int pull, unsigned int drvstr,
unsigned int enable)
void gpio_tlmm_config_set(gpio_t gpio, unsigned func,
unsigned pull, unsigned drvstr,
unsigned enable)
{
unsigned int val = 0;
unsigned val = 0;
if (gpio_not_valid(gpio))
return;
@ -72,33 +72,33 @@ void gpio_tlmm_config_set(gpio_t gpio, unsigned int func,
val |= (func & GPIO_CFG_FUNC_MASK) << GPIO_CFG_FUNC_SHIFT;
val |= (drvstr & GPIO_CFG_DRV_MASK) << GPIO_CFG_DRV_SHIFT;
val |= (enable & GPIO_CFG_OE_MASK) << GPIO_CFG_OE_SHIFT;
unsigned int *addr = (unsigned int *)GPIO_CONFIG_ADDR(gpio);
writel(val, addr);
writel(val, GPIO_CONFIG_ADDR(gpio));
}
/*******************************************************
Function description: Get GPIO configuration
Arguments :
gpio_t gpio - Gpio number
unsigned int *func - Functionality number
unsigned int *pull - pull up/down, no pull range(0-3)
unsigned int *drvstr - range (0 - 7)-> (2- 16)MA steps of 2
unsigned int *enable - 1 - Disable, 2- Enable.
unsigned *func - Functionality number
unsigned *pull - pull up/down, no pull range(0-3)
unsigned *drvstr - range (0 - 7)-> (2- 16)MA steps of 2
unsigned *enable - 0 - Disable, 1- Enable.
Return : None
*******************************************************/
void gpio_tlmm_config_get(gpio_t gpio, unsigned int *func,
unsigned int *pull, unsigned int *drvstr,
unsigned int *enable)
void gpio_tlmm_config_get(gpio_t gpio, unsigned *func,
unsigned *pull, unsigned *drvstr,
unsigned *enable)
{
unsigned int val;
unsigned val;
void *addr = GPIO_CONFIG_ADDR(gpio);
if (gpio_not_valid(gpio))
return;
unsigned int *addr = (unsigned int *)GPIO_CONFIG_ADDR(gpio);
val = readl(addr);
*pull = (val >> GPIO_CFG_PULL_SHIFT) & GPIO_CFG_PULL_MASK;
@ -107,53 +107,48 @@ void gpio_tlmm_config_get(gpio_t gpio, unsigned int *func,
*enable = (val >> GPIO_CFG_OE_SHIFT) & GPIO_CFG_OE_MASK;
}
/*******************************************************
Function description: configure GPIO IO functinality
Arguments :
gpio_t gpio - Gpio number
unsigned int out - Controls value of GPIO output
Return : None
*******************************************************/
void gpio_io_config_set(gpio_t gpio, unsigned int out)
{
unsigned int val;
if (gpio_not_valid(gpio))
return;
unsigned int *addr = (unsigned int *)GPIO_CONFIG_ADDR(gpio);
val = readl(addr);
if (out)
val |= (1 << GPIO_IO_OUT_SHIFT);
else
val &= (~(1 << GPIO_IO_OUT_SHIFT));
writel(val,addr);
}
/*******************************************************
Function description: get GPIO IO functinality details
Arguments :
gpio_t gpio - Gpio number
unsigned int *in - Value of GPIO input
unsigned int *out - Value of GPIO output
unsigned *in - Value of GPIO input
unsigned *out - Value of GPIO output
Return : None
*******************************************************/
void gpio_io_config_get(gpio_t gpio, unsigned int *in, unsigned int *out)
int gpio_get_in_value(gpio_t gpio)
{
unsigned int val;
if (gpio_not_valid(gpio))
return -1;
return (readl(GPIO_IN_OUT_ADDR(gpio)) >> GPIO_IO_IN_SHIFT) &
GPIO_IO_IN_MASK;
}
void gpio_set_out_value(gpio_t gpio, int value)
{
if (gpio_not_valid(gpio))
return;
unsigned int *addr = (unsigned int *)GPIO_CONFIG_ADDR(gpio);
val = readl(addr);
*in = (val >> GPIO_IO_IN_SHIFT) & GPIO_IO_IN_MASK;
*out = (val >> GPIO_IO_OUT_SHIFT) & GPIO_IO_OUT_MASK;
writel((value & 1) << GPIO_IO_OUT_SHIFT, GPIO_IN_OUT_ADDR(gpio));
}
void gpio_input_pulldown(gpio_t gpio)
{
gpio_tlmm_config_set(gpio, GPIO_FUNC_DISABLE,
GPIO_PULL_DOWN, GPIO_2MA, GPIO_DISABLE);
}
void gpio_input_pullup(gpio_t gpio)
{
gpio_tlmm_config_set(gpio, GPIO_FUNC_DISABLE,
GPIO_PULL_UP, GPIO_2MA, GPIO_DISABLE);
}
void gpio_input(gpio_t gpio)
{
gpio_tlmm_config_set(gpio, GPIO_FUNC_DISABLE,
GPIO_NO_PULL, GPIO_2MA, GPIO_DISABLE);
}

View File

@ -64,8 +64,8 @@
#define GPIO_16MA 7
/* GPIO TLMM: Status */
#define GPIO_ENABLE 0
#define GPIO_DISABLE 1
#define GPIO_DISABLE 0
#define GPIO_ENABLE 1
/* GPIO MAX Valid # */
#define GPIO_MAX_NUM 68
@ -99,7 +99,6 @@ void gpio_tlmm_config_get(gpio_t gpio, unsigned int *func,
unsigned int *enable);
void gpio_io_config_set(gpio_t gpio, unsigned int out);
void gpio_io_config_get(gpio_t gpio, unsigned int *in, unsigned int *out);
/* Keep this to maintain backwards compatibility with the vendor API. */
static inline void gpio_tlmm_config(unsigned int gpio, unsigned int func,

View File

@ -81,9 +81,9 @@
#define DGT_CLEAR DGT_REG(0x000C)
#define DGT_CLK_CTL DGT_REG(0x0010)
#define TLMM_BASE_ADDR 0x00800000
#define TLMM_BASE_ADDR ((char *)0x00800000)
#define GPIO_CONFIG_ADDR(x) (TLMM_BASE_ADDR + 0x1000 + (x)*0x10)
#define GPIO_IN_OUT_ADDR(x) (TLMM_BASE_ADDR + 0x1004 + (x)*0x10)
#define GPIO_IN_OUT_ADDR(x) (GPIO_CONFIG_ADDR(x) + 4)
/* Yes, this is not a typo... host2 is actually mapped before host1. */
#define USB_HOST2_XHCI_BASE 0x10000000

View File

@ -279,13 +279,13 @@ static int check_qup_clk_state(unsigned int core_num, int enable)
static void CS_change(int port_num, int cs_num, int enable)
{
unsigned int cs_gpio = cs_gpio_array[port_num][cs_num];
uint32_t addr = GPIO_IN_OUT_ADDR(cs_gpio);
void *addr = GPIO_IN_OUT_ADDR(cs_gpio);
uint32_t val = readl_i(addr);
val &= (~(1 << GPIO_OUTPUT));
if (!enable)
val |= (1 << GPIO_OUTPUT);
writel_i(val, addr);
writel(val, addr);
}
/*