Commit df5dade4 authored by Huacai Chen's avatar Huacai Chen Committed by Linus Walleij

MIPS: Cleanup Loongson-2F's gpio driver

This cleanup is prepare to move the driver to drivers/gpio. Custom
definitions of gpio_get_value()/gpio_set_value() are dropped.
Acked-by: default avatarRalf Baechle <ralf@linux-mips.org>
Signed-off-by: default avatarHuacai Chen <chenhc@lemote.com>
Reviewed-by: default avatarAlexandre Courbot <acourbot@nvidia.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent b8a51a2e
/* /*
* STLS2F GPIO Support * Loongson GPIO Support
* *
* Copyright (c) 2008 Richard Liu, STMicroelectronics <richard.liu@st.com> * Copyright (c) 2008 Richard Liu, STMicroelectronics <richard.liu@st.com>
* Copyright (c) 2008-2010 Arnaud Patard <apatard@mandriva.com> * Copyright (c) 2008-2010 Arnaud Patard <apatard@mandriva.com>
* Copyright (c) 2014 Huacai Chen <chenhc@lemote.com>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
...@@ -10,14 +11,14 @@ ...@@ -10,14 +11,14 @@
* (at your option) any later version. * (at your option) any later version.
*/ */
#ifndef __STLS2F_GPIO_H #ifndef __LOONGSON_GPIO_H
#define __STLS2F_GPIO_H #define __LOONGSON_GPIO_H
#include <asm-generic/gpio.h> #include <asm-generic/gpio.h>
extern void gpio_set_value(unsigned gpio, int value); #define gpio_get_value __gpio_get_value
extern int gpio_get_value(unsigned gpio); #define gpio_set_value __gpio_set_value
extern int gpio_cansleep(unsigned gpio); #define gpio_cansleep __gpio_cansleep
/* The chip can do interrupt /* The chip can do interrupt
* but it has not been tested and doc not clear * but it has not been tested and doc not clear
...@@ -32,4 +33,4 @@ static inline int irq_to_gpio(int gpio) ...@@ -32,4 +33,4 @@ static inline int irq_to_gpio(int gpio)
return -EINVAL; return -EINVAL;
} }
#endif /* __STLS2F_GPIO_H */ #endif /* __LOONGSON_GPIO_H */
...@@ -24,63 +24,11 @@ ...@@ -24,63 +24,11 @@
static DEFINE_SPINLOCK(gpio_lock); static DEFINE_SPINLOCK(gpio_lock);
int gpio_get_value(unsigned gpio)
{
u32 val;
u32 mask;
if (gpio >= STLS2F_N_GPIO)
return __gpio_get_value(gpio);
mask = 1 << (gpio + STLS2F_GPIO_IN_OFFSET);
spin_lock(&gpio_lock);
val = LOONGSON_GPIODATA;
spin_unlock(&gpio_lock);
return (val & mask) != 0;
}
EXPORT_SYMBOL(gpio_get_value);
void gpio_set_value(unsigned gpio, int state)
{
u32 val;
u32 mask;
if (gpio >= STLS2F_N_GPIO) {
__gpio_set_value(gpio, state);
return ;
}
mask = 1 << gpio;
spin_lock(&gpio_lock);
val = LOONGSON_GPIODATA;
if (state)
val |= mask;
else
val &= (~mask);
LOONGSON_GPIODATA = val;
spin_unlock(&gpio_lock);
}
EXPORT_SYMBOL(gpio_set_value);
int gpio_cansleep(unsigned gpio)
{
if (gpio < STLS2F_N_GPIO)
return 0;
else
return __gpio_cansleep(gpio);
}
EXPORT_SYMBOL(gpio_cansleep);
static int ls2f_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) static int ls2f_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
{ {
u32 temp; u32 temp;
u32 mask; u32 mask;
if (gpio >= STLS2F_N_GPIO)
return -EINVAL;
spin_lock(&gpio_lock); spin_lock(&gpio_lock);
mask = 1 << gpio; mask = 1 << gpio;
temp = LOONGSON_GPIOIE; temp = LOONGSON_GPIOIE;
...@@ -97,9 +45,6 @@ static int ls2f_gpio_direction_output(struct gpio_chip *chip, ...@@ -97,9 +45,6 @@ static int ls2f_gpio_direction_output(struct gpio_chip *chip,
u32 temp; u32 temp;
u32 mask; u32 mask;
if (gpio >= STLS2F_N_GPIO)
return -EINVAL;
gpio_set_value(gpio, level); gpio_set_value(gpio, level);
spin_lock(&gpio_lock); spin_lock(&gpio_lock);
mask = 1 << gpio; mask = 1 << gpio;
...@@ -113,13 +58,33 @@ static int ls2f_gpio_direction_output(struct gpio_chip *chip, ...@@ -113,13 +58,33 @@ static int ls2f_gpio_direction_output(struct gpio_chip *chip,
static int ls2f_gpio_get_value(struct gpio_chip *chip, unsigned gpio) static int ls2f_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
{ {
return gpio_get_value(gpio); u32 val;
u32 mask;
mask = 1 << (gpio + STLS2F_GPIO_IN_OFFSET);
spin_lock(&gpio_lock);
val = LOONGSON_GPIODATA;
spin_unlock(&gpio_lock);
return (val & mask) != 0;
} }
static void ls2f_gpio_set_value(struct gpio_chip *chip, static void ls2f_gpio_set_value(struct gpio_chip *chip,
unsigned gpio, int value) unsigned gpio, int value)
{ {
gpio_set_value(gpio, value); u32 val;
u32 mask;
mask = 1 << gpio;
spin_lock(&gpio_lock);
val = LOONGSON_GPIODATA;
if (value)
val |= mask;
else
val &= (~mask);
LOONGSON_GPIODATA = val;
spin_unlock(&gpio_lock);
} }
static struct gpio_chip ls2f_chip = { static struct gpio_chip ls2f_chip = {
...@@ -130,6 +95,7 @@ static struct gpio_chip ls2f_chip = { ...@@ -130,6 +95,7 @@ static struct gpio_chip ls2f_chip = {
.set = ls2f_gpio_set_value, .set = ls2f_gpio_set_value,
.base = 0, .base = 0,
.ngpio = STLS2F_N_GPIO, .ngpio = STLS2F_N_GPIO,
.can_sleep = false,
}; };
static int __init ls2f_gpio_setup(void) static int __init ls2f_gpio_setup(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment