2011-10-19 18:58:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2010 eXMeritus, A Boeing Company
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2011-10-19 18:58:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef POWERPC_ASM_MPC85XX_GPIO_H_
|
|
|
|
#define POWERPC_ASM_MPC85XX_GPIO_H_
|
|
|
|
|
|
|
|
# include <asm/immap_85xx.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following internal functions are an MPC85XX-specific GPIO API which
|
|
|
|
* allows setting and querying multiple GPIOs in a single operation.
|
|
|
|
*
|
|
|
|
* All of these look relatively large, but the arguments are almost always
|
|
|
|
* constants, so they compile down to just a few instructions and a
|
|
|
|
* memory-mapped IO operation or two.
|
|
|
|
*/
|
|
|
|
static inline void mpc85xx_gpio_set(unsigned int mask,
|
|
|
|
unsigned int dir, unsigned int val)
|
|
|
|
{
|
mpc85xx: Fix the offset of register address error
The offset of register address within GPIO module is just
CONFIG_SYS_MPC85xx_GPIO_ADDR. So, fix it. The following platforms
are confirmed: MPC8572, P1023, P1020, P1022, P2020, P4080,
P5020, P5040, T4240, B4860.
Signed-off-by: Tang Yuantian <Yuantian.Tang@freescale.com>
2013-10-17 02:47:33 +00:00
|
|
|
ccsr_gpio_t *gpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
|
2011-10-19 18:58:15 +00:00
|
|
|
|
|
|
|
/* First mask off the unwanted parts of "dir" and "val" */
|
|
|
|
dir &= mask;
|
|
|
|
val &= mask;
|
|
|
|
|
|
|
|
/* Now read in the values we're supposed to preserve */
|
|
|
|
dir |= (in_be32(&gpio->gpdir) & ~mask);
|
|
|
|
val |= (in_be32(&gpio->gpdat) & ~mask);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Poke the new output values first, then set the direction. This
|
|
|
|
* helps to avoid transient data when switching from input to output
|
|
|
|
* and vice versa.
|
|
|
|
*/
|
|
|
|
out_be32(&gpio->gpdat, val);
|
|
|
|
out_be32(&gpio->gpdir, dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mpc85xx_gpio_set_in(unsigned int gpios)
|
|
|
|
{
|
|
|
|
mpc85xx_gpio_set(gpios, 0x00000000, 0x00000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mpc85xx_gpio_set_low(unsigned int gpios)
|
|
|
|
{
|
|
|
|
mpc85xx_gpio_set(gpios, 0xFFFFFFFF, 0x00000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mpc85xx_gpio_set_high(unsigned int gpios)
|
|
|
|
{
|
|
|
|
mpc85xx_gpio_set(gpios, 0xFFFFFFFF, 0xFFFFFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int mpc85xx_gpio_get(unsigned int mask)
|
|
|
|
{
|
mpc85xx: Fix the offset of register address error
The offset of register address within GPIO module is just
CONFIG_SYS_MPC85xx_GPIO_ADDR. So, fix it. The following platforms
are confirmed: MPC8572, P1023, P1020, P1022, P2020, P4080,
P5020, P5040, T4240, B4860.
Signed-off-by: Tang Yuantian <Yuantian.Tang@freescale.com>
2013-10-17 02:47:33 +00:00
|
|
|
ccsr_gpio_t *gpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
|
2011-10-19 18:58:15 +00:00
|
|
|
|
|
|
|
/* Read the requested values */
|
|
|
|
return in_be32(&gpio->gpdat) & mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These implement the generic Linux GPIO API on top of the other functions
|
|
|
|
* in this header.
|
|
|
|
*/
|
|
|
|
static inline int gpio_request(unsigned gpio, const char *label)
|
|
|
|
{
|
|
|
|
/* Compatibility shim */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-28 17:59:50 +00:00
|
|
|
static inline int gpio_free(unsigned gpio)
|
2011-10-19 18:58:15 +00:00
|
|
|
{
|
|
|
|
/* Compatibility shim */
|
2015-04-28 17:59:50 +00:00
|
|
|
return 0;
|
2011-10-19 18:58:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int gpio_direction_input(unsigned gpio)
|
|
|
|
{
|
|
|
|
mpc85xx_gpio_set_in(1U << gpio);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int gpio_direction_output(unsigned gpio, int value)
|
|
|
|
{
|
2012-09-06 17:28:35 +00:00
|
|
|
if (value)
|
|
|
|
mpc85xx_gpio_set_high(1U << gpio);
|
|
|
|
else
|
|
|
|
mpc85xx_gpio_set_low(1U << gpio);
|
2011-10-19 18:58:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int gpio_get_value(unsigned gpio)
|
|
|
|
{
|
|
|
|
return !!mpc85xx_gpio_get(1U << gpio);
|
|
|
|
}
|
|
|
|
|
2015-04-28 17:59:50 +00:00
|
|
|
static inline int gpio_set_value(unsigned gpio, int value)
|
2011-10-19 18:58:15 +00:00
|
|
|
{
|
|
|
|
if (value)
|
|
|
|
mpc85xx_gpio_set_high(1U << gpio);
|
|
|
|
else
|
|
|
|
mpc85xx_gpio_set_low(1U << gpio);
|
2015-04-28 17:59:50 +00:00
|
|
|
return 0;
|
2011-10-19 18:58:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int gpio_is_valid(int gpio)
|
|
|
|
{
|
|
|
|
return (gpio >= 0) && (gpio < 32);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* not POWERPC_ASM_MPC85XX_GPIO_H_ */
|