diff options
author | Huacai Chen <chenhc@lemote.com> | 2015-03-31 22:20:07 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2015-04-07 05:13:56 -0400 |
commit | df5dade4a7b29b003e000c5db5c35612e0b1019b (patch) | |
tree | 8feb005ff876ae9d1df0a74101bedb223f3f0b00 /arch/mips | |
parent | b8a51a2e8a9f8e24f8f155772168a7ca35ce7f75 (diff) |
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: Ralf Baechle <ralf@linux-mips.org>
Signed-off-by: Huacai Chen <chenhc@lemote.com>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'arch/mips')
-rw-r--r-- | arch/mips/include/asm/mach-loongson/gpio.h | 15 | ||||
-rw-r--r-- | arch/mips/loongson/common/gpio.c | 80 |
2 files changed, 31 insertions, 64 deletions
diff --git a/arch/mips/include/asm/mach-loongson/gpio.h b/arch/mips/include/asm/mach-loongson/gpio.h index 211a7b7138fe..b3b216904a9a 100644 --- a/arch/mips/include/asm/mach-loongson/gpio.h +++ b/arch/mips/include/asm/mach-loongson/gpio.h | |||
@@ -1,8 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * STLS2F GPIO Support | 2 | * Loongson GPIO Support |
3 | * | 3 | * |
4 | * Copyright (c) 2008 Richard Liu, STMicroelectronics <richard.liu@st.com> | 4 | * Copyright (c) 2008 Richard Liu, STMicroelectronics <richard.liu@st.com> |
5 | * Copyright (c) 2008-2010 Arnaud Patard <apatard@mandriva.com> | 5 | * Copyright (c) 2008-2010 Arnaud Patard <apatard@mandriva.com> |
6 | * Copyright (c) 2014 Huacai Chen <chenhc@lemote.com> | ||
6 | * | 7 | * |
7 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
@@ -10,14 +11,14 @@ | |||
10 | * (at your option) any later version. | 11 | * (at your option) any later version. |
11 | */ | 12 | */ |
12 | 13 | ||
13 | #ifndef __STLS2F_GPIO_H | 14 | #ifndef __LOONGSON_GPIO_H |
14 | #define __STLS2F_GPIO_H | 15 | #define __LOONGSON_GPIO_H |
15 | 16 | ||
16 | #include <asm-generic/gpio.h> | 17 | #include <asm-generic/gpio.h> |
17 | 18 | ||
18 | extern void gpio_set_value(unsigned gpio, int value); | 19 | #define gpio_get_value __gpio_get_value |
19 | extern int gpio_get_value(unsigned gpio); | 20 | #define gpio_set_value __gpio_set_value |
20 | extern int gpio_cansleep(unsigned gpio); | 21 | #define gpio_cansleep __gpio_cansleep |
21 | 22 | ||
22 | /* The chip can do interrupt | 23 | /* The chip can do interrupt |
23 | * but it has not been tested and doc not clear | 24 | * but it has not been tested and doc not clear |
@@ -32,4 +33,4 @@ static inline int irq_to_gpio(int gpio) | |||
32 | return -EINVAL; | 33 | return -EINVAL; |
33 | } | 34 | } |
34 | 35 | ||
35 | #endif /* __STLS2F_GPIO_H */ | 36 | #endif /* __LOONGSON_GPIO_H */ |
diff --git a/arch/mips/loongson/common/gpio.c b/arch/mips/loongson/common/gpio.c index 29dbaa253061..b4e69e0ed92b 100644 --- a/arch/mips/loongson/common/gpio.c +++ b/arch/mips/loongson/common/gpio.c | |||
@@ -24,63 +24,11 @@ | |||
24 | 24 | ||
25 | static DEFINE_SPINLOCK(gpio_lock); | 25 | static DEFINE_SPINLOCK(gpio_lock); |
26 | 26 | ||
27 | int gpio_get_value(unsigned gpio) | ||
28 | { | ||
29 | u32 val; | ||
30 | u32 mask; | ||
31 | |||
32 | if (gpio >= STLS2F_N_GPIO) | ||
33 | return __gpio_get_value(gpio); | ||
34 | |||
35 | mask = 1 << (gpio + STLS2F_GPIO_IN_OFFSET); | ||
36 | spin_lock(&gpio_lock); | ||
37 | val = LOONGSON_GPIODATA; | ||
38 | spin_unlock(&gpio_lock); | ||
39 | |||
40 | return (val & mask) != 0; | ||
41 | } | ||
42 | EXPORT_SYMBOL(gpio_get_value); | ||
43 | |||
44 | void gpio_set_value(unsigned gpio, int state) | ||
45 | { | ||
46 | u32 val; | ||
47 | u32 mask; | ||
48 | |||
49 | if (gpio >= STLS2F_N_GPIO) { | ||
50 | __gpio_set_value(gpio, state); | ||
51 | return ; | ||
52 | } | ||
53 | |||
54 | mask = 1 << gpio; | ||
55 | |||
56 | spin_lock(&gpio_lock); | ||
57 | val = LOONGSON_GPIODATA; | ||
58 | if (state) | ||
59 | val |= mask; | ||
60 | else | ||
61 | val &= (~mask); | ||
62 | LOONGSON_GPIODATA = val; | ||
63 | spin_unlock(&gpio_lock); | ||
64 | } | ||
65 | EXPORT_SYMBOL(gpio_set_value); | ||
66 | |||
67 | int gpio_cansleep(unsigned gpio) | ||
68 | { | ||
69 | if (gpio < STLS2F_N_GPIO) | ||
70 | return 0; | ||
71 | else | ||
72 | return __gpio_cansleep(gpio); | ||
73 | } | ||
74 | EXPORT_SYMBOL(gpio_cansleep); | ||
75 | |||
76 | static int ls2f_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) | 27 | static int ls2f_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) |
77 | { | 28 | { |
78 | u32 temp; | 29 | u32 temp; |
79 | u32 mask; | 30 | u32 mask; |
80 | 31 | ||
81 | if (gpio >= STLS2F_N_GPIO) | ||
82 | return -EINVAL; | ||
83 | |||
84 | spin_lock(&gpio_lock); | 32 | spin_lock(&gpio_lock); |
85 | mask = 1 << gpio; | 33 | mask = 1 << gpio; |
86 | temp = LOONGSON_GPIOIE; | 34 | temp = LOONGSON_GPIOIE; |
@@ -97,9 +45,6 @@ static int ls2f_gpio_direction_output(struct gpio_chip *chip, | |||
97 | u32 temp; | 45 | u32 temp; |
98 | u32 mask; | 46 | u32 mask; |
99 | 47 | ||
100 | if (gpio >= STLS2F_N_GPIO) | ||
101 | return -EINVAL; | ||
102 | |||
103 | gpio_set_value(gpio, level); | 48 | gpio_set_value(gpio, level); |
104 | spin_lock(&gpio_lock); | 49 | spin_lock(&gpio_lock); |
105 | mask = 1 << gpio; | 50 | mask = 1 << gpio; |
@@ -113,13 +58,33 @@ static int ls2f_gpio_direction_output(struct gpio_chip *chip, | |||
113 | 58 | ||
114 | static int ls2f_gpio_get_value(struct gpio_chip *chip, unsigned gpio) | 59 | static int ls2f_gpio_get_value(struct gpio_chip *chip, unsigned gpio) |
115 | { | 60 | { |
116 | return gpio_get_value(gpio); | 61 | u32 val; |
62 | u32 mask; | ||
63 | |||
64 | mask = 1 << (gpio + STLS2F_GPIO_IN_OFFSET); | ||
65 | spin_lock(&gpio_lock); | ||
66 | val = LOONGSON_GPIODATA; | ||
67 | spin_unlock(&gpio_lock); | ||
68 | |||
69 | return (val & mask) != 0; | ||
117 | } | 70 | } |
118 | 71 | ||
119 | static void ls2f_gpio_set_value(struct gpio_chip *chip, | 72 | static void ls2f_gpio_set_value(struct gpio_chip *chip, |
120 | unsigned gpio, int value) | 73 | unsigned gpio, int value) |
121 | { | 74 | { |
122 | gpio_set_value(gpio, value); | 75 | u32 val; |
76 | u32 mask; | ||
77 | |||
78 | mask = 1 << gpio; | ||
79 | |||
80 | spin_lock(&gpio_lock); | ||
81 | val = LOONGSON_GPIODATA; | ||
82 | if (value) | ||
83 | val |= mask; | ||
84 | else | ||
85 | val &= (~mask); | ||
86 | LOONGSON_GPIODATA = val; | ||
87 | spin_unlock(&gpio_lock); | ||
123 | } | 88 | } |
124 | 89 | ||
125 | static struct gpio_chip ls2f_chip = { | 90 | static struct gpio_chip ls2f_chip = { |
@@ -130,6 +95,7 @@ static struct gpio_chip ls2f_chip = { | |||
130 | .set = ls2f_gpio_set_value, | 95 | .set = ls2f_gpio_set_value, |
131 | .base = 0, | 96 | .base = 0, |
132 | .ngpio = STLS2F_N_GPIO, | 97 | .ngpio = STLS2F_N_GPIO, |
98 | .can_sleep = false, | ||
133 | }; | 99 | }; |
134 | 100 | ||
135 | static int __init ls2f_gpio_setup(void) | 101 | static int __init ls2f_gpio_setup(void) |