[ARM] MX1/MX2: simplify mxc_gpio_setup_multiple_pins
mxc_gpio_setup_multiple_pins used to take several ALLOC_MODE flags. Most of them are unused, so simplify the function by removing the flags. Also, instead of using a confusing MXC_GPIO_ALLOC_MODE_RELEASE flag in a function having alloc in its name, add a mxc_gpio_release_multiple_pins function. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
d1900d3a18
commit
7bd1822135
|
@ -68,15 +68,14 @@ static int mxc_uart0_pins[] = {
|
||||||
static int uart_mxc_port0_init(struct platform_device *pdev)
|
static int uart_mxc_port0_init(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
return mxc_gpio_setup_multiple_pins(mxc_uart0_pins,
|
return mxc_gpio_setup_multiple_pins(mxc_uart0_pins,
|
||||||
ARRAY_SIZE(mxc_uart0_pins),
|
ARRAY_SIZE(mxc_uart0_pins), "UART0");
|
||||||
MXC_GPIO_ALLOC_MODE_NORMAL, "UART0");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uart_mxc_port0_exit(struct platform_device *pdev)
|
static int uart_mxc_port0_exit(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
return mxc_gpio_setup_multiple_pins(mxc_uart0_pins,
|
mxc_gpio_release_multiple_pins(mxc_uart0_pins,
|
||||||
ARRAY_SIZE(mxc_uart0_pins),
|
ARRAY_SIZE(mxc_uart0_pins));
|
||||||
MXC_GPIO_ALLOC_MODE_RELEASE, "UART0");
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mxc_uart1_pins[] = {
|
static int mxc_uart1_pins[] = {
|
||||||
|
@ -89,15 +88,14 @@ static int mxc_uart1_pins[] = {
|
||||||
static int uart_mxc_port1_init(struct platform_device *pdev)
|
static int uart_mxc_port1_init(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
return mxc_gpio_setup_multiple_pins(mxc_uart1_pins,
|
return mxc_gpio_setup_multiple_pins(mxc_uart1_pins,
|
||||||
ARRAY_SIZE(mxc_uart1_pins),
|
ARRAY_SIZE(mxc_uart1_pins), "UART1");
|
||||||
MXC_GPIO_ALLOC_MODE_NORMAL, "UART1");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uart_mxc_port1_exit(struct platform_device *pdev)
|
static int uart_mxc_port1_exit(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
return mxc_gpio_setup_multiple_pins(mxc_uart1_pins,
|
mxc_gpio_setup_release_pins(mxc_uart1_pins,
|
||||||
ARRAY_SIZE(mxc_uart1_pins),
|
ARRAY_SIZE(mxc_uart1_pins));
|
||||||
MXC_GPIO_ALLOC_MODE_RELEASE, "UART1");
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mxc_uart2_pins[] = {
|
static int mxc_uart2_pins[] = {
|
||||||
|
@ -110,15 +108,14 @@ static int mxc_uart2_pins[] = {
|
||||||
static int uart_mxc_port2_init(struct platform_device *pdev)
|
static int uart_mxc_port2_init(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
return mxc_gpio_setup_multiple_pins(mxc_uart2_pins,
|
return mxc_gpio_setup_multiple_pins(mxc_uart2_pins,
|
||||||
ARRAY_SIZE(mxc_uart2_pins),
|
ARRAY_SIZE(mxc_uart2_pins), "UART2");
|
||||||
MXC_GPIO_ALLOC_MODE_NORMAL, "UART2");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uart_mxc_port2_exit(struct platform_device *pdev)
|
static int uart_mxc_port2_exit(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
return mxc_gpio_setup_multiple_pins(mxc_uart2_pins,
|
mxc_gpio_release_multiple_pins(mxc_uart2_pins,
|
||||||
ARRAY_SIZE(mxc_uart2_pins),
|
ARRAY_SIZE(mxc_uart2_pins));
|
||||||
MXC_GPIO_ALLOC_MODE_RELEASE, "UART2");
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mxc_uart3_pins[] = {
|
static int mxc_uart3_pins[] = {
|
||||||
|
@ -131,15 +128,13 @@ static int mxc_uart3_pins[] = {
|
||||||
static int uart_mxc_port3_init(struct platform_device *pdev)
|
static int uart_mxc_port3_init(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
return mxc_gpio_setup_multiple_pins(mxc_uart3_pins,
|
return mxc_gpio_setup_multiple_pins(mxc_uart3_pins,
|
||||||
ARRAY_SIZE(mxc_uart3_pins),
|
ARRAY_SIZE(mxc_uart3_pins), "UART3");
|
||||||
MXC_GPIO_ALLOC_MODE_NORMAL, "UART3");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uart_mxc_port3_exit(struct platform_device *pdev)
|
static int uart_mxc_port3_exit(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
return mxc_gpio_setup_multiple_pins(mxc_uart3_pins,
|
mxc_gpio_release_multiple_pins(mxc_uart3_pins,
|
||||||
ARRAY_SIZE(mxc_uart3_pins),
|
ARRAY_SIZE(mxc_uart3_pins));
|
||||||
MXC_GPIO_ALLOC_MODE_RELEASE, "UART3");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mxc_uart4_pins[] = {
|
static int mxc_uart4_pins[] = {
|
||||||
|
@ -152,15 +147,14 @@ static int mxc_uart4_pins[] = {
|
||||||
static int uart_mxc_port4_init(struct platform_device *pdev)
|
static int uart_mxc_port4_init(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
return mxc_gpio_setup_multiple_pins(mxc_uart4_pins,
|
return mxc_gpio_setup_multiple_pins(mxc_uart4_pins,
|
||||||
ARRAY_SIZE(mxc_uart4_pins),
|
ARRAY_SIZE(mxc_uart4_pins), "UART4");
|
||||||
MXC_GPIO_ALLOC_MODE_NORMAL, "UART4");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uart_mxc_port4_exit(struct platform_device *pdev)
|
static int uart_mxc_port4_exit(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
return mxc_gpio_setup_multiple_pins(mxc_uart4_pins,
|
mxc_gpio_release_multiple_pins(mxc_uart4_pins,
|
||||||
ARRAY_SIZE(mxc_uart4_pins),
|
ARRAY_SIZE(mxc_uart4_pins));
|
||||||
MXC_GPIO_ALLOC_MODE_RELEASE, "UART4");
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mxc_uart5_pins[] = {
|
static int mxc_uart5_pins[] = {
|
||||||
|
@ -173,15 +167,14 @@ static int mxc_uart5_pins[] = {
|
||||||
static int uart_mxc_port5_init(struct platform_device *pdev)
|
static int uart_mxc_port5_init(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
return mxc_gpio_setup_multiple_pins(mxc_uart5_pins,
|
return mxc_gpio_setup_multiple_pins(mxc_uart5_pins,
|
||||||
ARRAY_SIZE(mxc_uart5_pins),
|
ARRAY_SIZE(mxc_uart5_pins), "UART5");
|
||||||
MXC_GPIO_ALLOC_MODE_NORMAL, "UART5");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uart_mxc_port5_exit(struct platform_device *pdev)
|
static int uart_mxc_port5_exit(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
return mxc_gpio_setup_multiple_pins(mxc_uart5_pins,
|
mxc_gpio_release_multiple_pins(mxc_uart5_pins,
|
||||||
ARRAY_SIZE(mxc_uart5_pins),
|
ARRAY_SIZE(mxc_uart5_pins));
|
||||||
MXC_GPIO_ALLOC_MODE_RELEASE, "UART5");
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct platform_device *platform_devices[] __initdata = {
|
static struct platform_device *platform_devices[] __initdata = {
|
||||||
|
@ -212,15 +205,13 @@ static int mxc_fec_pins[] = {
|
||||||
static void gpio_fec_active(void)
|
static void gpio_fec_active(void)
|
||||||
{
|
{
|
||||||
mxc_gpio_setup_multiple_pins(mxc_fec_pins,
|
mxc_gpio_setup_multiple_pins(mxc_fec_pins,
|
||||||
ARRAY_SIZE(mxc_fec_pins),
|
ARRAY_SIZE(mxc_fec_pins), "FEC");
|
||||||
MXC_GPIO_ALLOC_MODE_NORMAL, "FEC");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gpio_fec_inactive(void)
|
static void gpio_fec_inactive(void)
|
||||||
{
|
{
|
||||||
mxc_gpio_setup_multiple_pins(mxc_fec_pins,
|
mxc_gpio_release_multiple_pins(mxc_fec_pins,
|
||||||
ARRAY_SIZE(mxc_fec_pins),
|
ARRAY_SIZE(mxc_fec_pins));
|
||||||
MXC_GPIO_ALLOC_MODE_RELEASE, "FEC");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct imxuart_platform_data uart_pdata[] = {
|
static struct imxuart_platform_data uart_pdata[] = {
|
||||||
|
|
|
@ -64,15 +64,14 @@ static int mxc_uart0_pins[] = {
|
||||||
static int uart_mxc_port0_init(struct platform_device *pdev)
|
static int uart_mxc_port0_init(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
return mxc_gpio_setup_multiple_pins(mxc_uart0_pins,
|
return mxc_gpio_setup_multiple_pins(mxc_uart0_pins,
|
||||||
ARRAY_SIZE(mxc_uart0_pins),
|
ARRAY_SIZE(mxc_uart0_pins), "UART0");
|
||||||
MXC_GPIO_ALLOC_MODE_NORMAL, "UART0");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uart_mxc_port0_exit(struct platform_device *pdev)
|
static int uart_mxc_port0_exit(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
return mxc_gpio_setup_multiple_pins(mxc_uart0_pins,
|
mxc_gpio_release_multiple_pins(mxc_uart0_pins,
|
||||||
ARRAY_SIZE(mxc_uart0_pins),
|
ARRAY_SIZE(mxc_uart0_pins));
|
||||||
MXC_GPIO_ALLOC_MODE_RELEASE, "UART0");
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mxc_uart1_pins[] = {
|
static int mxc_uart1_pins[] = {
|
||||||
|
@ -85,15 +84,14 @@ static int mxc_uart1_pins[] = {
|
||||||
static int uart_mxc_port1_init(struct platform_device *pdev)
|
static int uart_mxc_port1_init(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
return mxc_gpio_setup_multiple_pins(mxc_uart1_pins,
|
return mxc_gpio_setup_multiple_pins(mxc_uart1_pins,
|
||||||
ARRAY_SIZE(mxc_uart1_pins),
|
ARRAY_SIZE(mxc_uart1_pins), "UART1");
|
||||||
MXC_GPIO_ALLOC_MODE_NORMAL, "UART1");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uart_mxc_port1_exit(struct platform_device *pdev)
|
static int uart_mxc_port1_exit(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
return mxc_gpio_setup_multiple_pins(mxc_uart1_pins,
|
mxc_gpio_release_multiple_pins(mxc_uart1_pins,
|
||||||
ARRAY_SIZE(mxc_uart1_pins),
|
ARRAY_SIZE(mxc_uart1_pins));
|
||||||
MXC_GPIO_ALLOC_MODE_RELEASE, "UART1");
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mxc_uart2_pins[] = { PE10_PF_UART3_CTS,
|
static int mxc_uart2_pins[] = { PE10_PF_UART3_CTS,
|
||||||
|
@ -104,15 +102,14 @@ static int mxc_uart2_pins[] = { PE10_PF_UART3_CTS,
|
||||||
static int uart_mxc_port2_init(struct platform_device *pdev)
|
static int uart_mxc_port2_init(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
return mxc_gpio_setup_multiple_pins(mxc_uart2_pins,
|
return mxc_gpio_setup_multiple_pins(mxc_uart2_pins,
|
||||||
ARRAY_SIZE(mxc_uart2_pins),
|
ARRAY_SIZE(mxc_uart2_pins), "UART2");
|
||||||
MXC_GPIO_ALLOC_MODE_NORMAL, "UART2");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uart_mxc_port2_exit(struct platform_device *pdev)
|
static int uart_mxc_port2_exit(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
return mxc_gpio_setup_multiple_pins(mxc_uart2_pins,
|
mxc_gpio_release_multiple_pins(mxc_uart2_pins,
|
||||||
ARRAY_SIZE(mxc_uart2_pins),
|
ARRAY_SIZE(mxc_uart2_pins));
|
||||||
MXC_GPIO_ALLOC_MODE_RELEASE, "UART2");
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct imxuart_platform_data uart_pdata[] = {
|
static struct imxuart_platform_data uart_pdata[] = {
|
||||||
|
@ -155,15 +152,13 @@ static int mxc_fec_pins[] = {
|
||||||
static void gpio_fec_active(void)
|
static void gpio_fec_active(void)
|
||||||
{
|
{
|
||||||
mxc_gpio_setup_multiple_pins(mxc_fec_pins,
|
mxc_gpio_setup_multiple_pins(mxc_fec_pins,
|
||||||
ARRAY_SIZE(mxc_fec_pins),
|
ARRAY_SIZE(mxc_fec_pins), "FEC");
|
||||||
MXC_GPIO_ALLOC_MODE_NORMAL, "FEC");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gpio_fec_inactive(void)
|
static void gpio_fec_inactive(void)
|
||||||
{
|
{
|
||||||
mxc_gpio_setup_multiple_pins(mxc_fec_pins,
|
mxc_gpio_release_multiple_pins(mxc_fec_pins,
|
||||||
ARRAY_SIZE(mxc_fec_pins),
|
ARRAY_SIZE(mxc_fec_pins));
|
||||||
MXC_GPIO_ALLOC_MODE_RELEASE, "FEC");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct platform_device *platform_devices[] __initdata = {
|
static struct platform_device *platform_devices[] __initdata = {
|
||||||
|
|
|
@ -21,12 +21,6 @@
|
||||||
|
|
||||||
#include <linux/io.h>
|
#include <linux/io.h>
|
||||||
|
|
||||||
#define MXC_GPIO_ALLOC_MODE_NORMAL 0
|
|
||||||
#define MXC_GPIO_ALLOC_MODE_NO_ALLOC 1
|
|
||||||
#define MXC_GPIO_ALLOC_MODE_TRY_ALLOC 2
|
|
||||||
#define MXC_GPIO_ALLOC_MODE_ALLOC_ONLY 4
|
|
||||||
#define MXC_GPIO_ALLOC_MODE_RELEASE 8
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GPIO Module and I/O Multiplexer
|
* GPIO Module and I/O Multiplexer
|
||||||
* x = 0..3 for reg_A, reg_B, reg_C, reg_D
|
* x = 0..3 for reg_A, reg_B, reg_C, reg_D
|
||||||
|
@ -103,7 +97,8 @@
|
||||||
|
|
||||||
extern void mxc_gpio_mode(int gpio_mode);
|
extern void mxc_gpio_mode(int gpio_mode);
|
||||||
extern int mxc_gpio_setup_multiple_pins(const int *pin_list, unsigned count,
|
extern int mxc_gpio_setup_multiple_pins(const int *pin_list, unsigned count,
|
||||||
int alloc_mode, const char *label);
|
const char *label);
|
||||||
|
extern void mxc_gpio_release_multiple_pins(const int *pin_list, int count);
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
|
@ -110,12 +110,13 @@ void mxc_gpio_mode(int gpio_mode)
|
||||||
EXPORT_SYMBOL(mxc_gpio_mode);
|
EXPORT_SYMBOL(mxc_gpio_mode);
|
||||||
|
|
||||||
int mxc_gpio_setup_multiple_pins(const int *pin_list, unsigned count,
|
int mxc_gpio_setup_multiple_pins(const int *pin_list, unsigned count,
|
||||||
int alloc_mode, const char *label)
|
const char *label)
|
||||||
{
|
{
|
||||||
const int *p = pin_list;
|
const int *p = pin_list;
|
||||||
int i;
|
int i;
|
||||||
unsigned gpio;
|
unsigned gpio;
|
||||||
unsigned mode;
|
unsigned mode;
|
||||||
|
int ret = -EINVAL;
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
gpio = *p & (GPIO_PIN_MASK | GPIO_PORT_MASK);
|
gpio = *p & (GPIO_PIN_MASK | GPIO_PORT_MASK);
|
||||||
|
@ -124,33 +125,33 @@ int mxc_gpio_setup_multiple_pins(const int *pin_list, unsigned count,
|
||||||
if (gpio >= (GPIO_PORT_MAX + 1) * 32)
|
if (gpio >= (GPIO_PORT_MAX + 1) * 32)
|
||||||
goto setup_error;
|
goto setup_error;
|
||||||
|
|
||||||
if (alloc_mode & MXC_GPIO_ALLOC_MODE_RELEASE)
|
ret = gpio_request(gpio, label);
|
||||||
gpio_free(gpio);
|
if (ret)
|
||||||
else if (!(alloc_mode & MXC_GPIO_ALLOC_MODE_NO_ALLOC))
|
goto setup_error;
|
||||||
if (gpio_request(gpio, label)
|
|
||||||
&& !(alloc_mode & MXC_GPIO_ALLOC_MODE_TRY_ALLOC))
|
|
||||||
goto setup_error;
|
|
||||||
|
|
||||||
if (!(alloc_mode & (MXC_GPIO_ALLOC_MODE_ALLOC_ONLY |
|
mxc_gpio_mode(gpio | mode);
|
||||||
MXC_GPIO_ALLOC_MODE_RELEASE)))
|
|
||||||
mxc_gpio_mode(gpio | mode);
|
|
||||||
|
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
setup_error:
|
setup_error:
|
||||||
if (alloc_mode & (MXC_GPIO_ALLOC_MODE_NO_ALLOC |
|
mxc_gpio_release_multiple_pins(pin_list, i);
|
||||||
MXC_GPIO_ALLOC_MODE_TRY_ALLOC))
|
return ret;
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
while (p != pin_list) {
|
|
||||||
p--;
|
|
||||||
gpio = *p & (GPIO_PIN_MASK | GPIO_PORT_MASK);
|
|
||||||
gpio_free(gpio);
|
|
||||||
}
|
|
||||||
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(mxc_gpio_setup_multiple_pins);
|
EXPORT_SYMBOL(mxc_gpio_setup_multiple_pins);
|
||||||
|
|
||||||
|
void mxc_gpio_release_multiple_pins(const int *pin_list, int count)
|
||||||
|
{
|
||||||
|
const int *p = pin_list;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
|
unsigned gpio = *p & (GPIO_PIN_MASK | GPIO_PORT_MASK);
|
||||||
|
gpio_free(gpio);
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(mxc_gpio_release_multiple_pins);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue