diff options
author | Huacai Chen <chenhc@lemote.com> | 2015-03-31 22:20:09 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2015-04-08 03:53:42 -0400 |
commit | cbfb3ea7f8c8da2e12d6d5aeca6d483de4297427 (patch) | |
tree | b77a0f746f2cf6f2a8ebc3b841d2a5e4f68e5257 | |
parent | 991ff4e3d71dcad184d18f9b1b241f3191601909 (diff) |
gpio: loongson: Add Loongson-3A/3B GPIO driver support
Improve Loongson-2's GPIO driver to support Loongson-3A/3B, and update
Loongson-3's default config file.
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>
-rw-r--r-- | arch/mips/Kconfig | 1 | ||||
-rw-r--r-- | arch/mips/configs/loongson3_defconfig | 1 | ||||
-rw-r--r-- | drivers/gpio/Kconfig | 6 | ||||
-rw-r--r-- | drivers/gpio/gpio-loongson.c | 44 |
4 files changed, 32 insertions, 20 deletions
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index c7a16904cd03..1ecd49945096 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig | |||
@@ -1245,6 +1245,7 @@ config CPU_LOONGSON3 | |||
1245 | select CPU_SUPPORTS_HUGEPAGES | 1245 | select CPU_SUPPORTS_HUGEPAGES |
1246 | select WEAK_ORDERING | 1246 | select WEAK_ORDERING |
1247 | select WEAK_REORDERING_BEYOND_LLSC | 1247 | select WEAK_REORDERING_BEYOND_LLSC |
1248 | select ARCH_REQUIRE_GPIOLIB | ||
1248 | help | 1249 | help |
1249 | The Loongson 3 processor implements the MIPS64R2 instruction | 1250 | The Loongson 3 processor implements the MIPS64R2 instruction |
1250 | set with many extensions. | 1251 | set with many extensions. |
diff --git a/arch/mips/configs/loongson3_defconfig b/arch/mips/configs/loongson3_defconfig index 7eabcd2031ea..c8442997477b 100644 --- a/arch/mips/configs/loongson3_defconfig +++ b/arch/mips/configs/loongson3_defconfig | |||
@@ -243,6 +243,7 @@ CONFIG_HW_RANDOM=y | |||
243 | CONFIG_RAW_DRIVER=m | 243 | CONFIG_RAW_DRIVER=m |
244 | CONFIG_I2C_CHARDEV=y | 244 | CONFIG_I2C_CHARDEV=y |
245 | CONFIG_I2C_PIIX4=y | 245 | CONFIG_I2C_PIIX4=y |
246 | CONFIG_GPIO_LOONGSON=y | ||
246 | CONFIG_SENSORS_LM75=m | 247 | CONFIG_SENSORS_LM75=m |
247 | CONFIG_SENSORS_LM93=m | 248 | CONFIG_SENSORS_LM93=m |
248 | CONFIG_SENSORS_W83627HF=m | 249 | CONFIG_SENSORS_W83627HF=m |
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 473511ff676a..41d91b6a5505 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig | |||
@@ -509,10 +509,10 @@ config GPIO_GRGPIO | |||
509 | VHDL IP core library. | 509 | VHDL IP core library. |
510 | 510 | ||
511 | config GPIO_LOONGSON | 511 | config GPIO_LOONGSON |
512 | bool "Loongson-2 GPIO support" | 512 | bool "Loongson-2/3 GPIO support" |
513 | depends on CPU_LOONGSON2 | 513 | depends on CPU_LOONGSON2 || CPU_LOONGSON3 |
514 | help | 514 | help |
515 | driver for GPIO functionality on Loongson-2F processors. | 515 | driver for GPIO functionality on Loongson-2F/3A/3B processors. |
516 | 516 | ||
517 | config GPIO_TB10X | 517 | config GPIO_TB10X |
518 | bool | 518 | bool |
diff --git a/drivers/gpio/gpio-loongson.c b/drivers/gpio/gpio-loongson.c index b4e69e0ed92b..ccc65a1aea88 100644 --- a/drivers/gpio/gpio-loongson.c +++ b/drivers/gpio/gpio-loongson.c | |||
@@ -1,8 +1,10 @@ | |||
1 | /* | 1 | /* |
2 | * STLS2F GPIO Support | 2 | * Loongson-2F/3A/3B 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) 2013 Hongbing Hu <huhb@lemote.com> | ||
7 | * Copyright (c) 2014 Huacai Chen <chenhc@lemote.com> | ||
6 | * | 8 | * |
7 | * This program is free software; you can redistribute it and/or modify | 9 | * 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 | 10 | * it under the terms of the GNU General Public License as published by |
@@ -20,11 +22,19 @@ | |||
20 | #include <linux/gpio.h> | 22 | #include <linux/gpio.h> |
21 | 23 | ||
22 | #define STLS2F_N_GPIO 4 | 24 | #define STLS2F_N_GPIO 4 |
23 | #define STLS2F_GPIO_IN_OFFSET 16 | 25 | #define STLS3A_N_GPIO 16 |
26 | |||
27 | #ifdef CONFIG_CPU_LOONGSON3 | ||
28 | #define LOONGSON_N_GPIO STLS3A_N_GPIO | ||
29 | #else | ||
30 | #define LOONGSON_N_GPIO STLS2F_N_GPIO | ||
31 | #endif | ||
32 | |||
33 | #define LOONGSON_GPIO_IN_OFFSET 16 | ||
24 | 34 | ||
25 | static DEFINE_SPINLOCK(gpio_lock); | 35 | static DEFINE_SPINLOCK(gpio_lock); |
26 | 36 | ||
27 | static int ls2f_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) | 37 | static int loongson_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) |
28 | { | 38 | { |
29 | u32 temp; | 39 | u32 temp; |
30 | u32 mask; | 40 | u32 mask; |
@@ -39,7 +49,7 @@ static int ls2f_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) | |||
39 | return 0; | 49 | return 0; |
40 | } | 50 | } |
41 | 51 | ||
42 | static int ls2f_gpio_direction_output(struct gpio_chip *chip, | 52 | static int loongson_gpio_direction_output(struct gpio_chip *chip, |
43 | unsigned gpio, int level) | 53 | unsigned gpio, int level) |
44 | { | 54 | { |
45 | u32 temp; | 55 | u32 temp; |
@@ -56,12 +66,12 @@ static int ls2f_gpio_direction_output(struct gpio_chip *chip, | |||
56 | return 0; | 66 | return 0; |
57 | } | 67 | } |
58 | 68 | ||
59 | static int ls2f_gpio_get_value(struct gpio_chip *chip, unsigned gpio) | 69 | static int loongson_gpio_get_value(struct gpio_chip *chip, unsigned gpio) |
60 | { | 70 | { |
61 | u32 val; | 71 | u32 val; |
62 | u32 mask; | 72 | u32 mask; |
63 | 73 | ||
64 | mask = 1 << (gpio + STLS2F_GPIO_IN_OFFSET); | 74 | mask = 1 << (gpio + LOONGSON_GPIO_IN_OFFSET); |
65 | spin_lock(&gpio_lock); | 75 | spin_lock(&gpio_lock); |
66 | val = LOONGSON_GPIODATA; | 76 | val = LOONGSON_GPIODATA; |
67 | spin_unlock(&gpio_lock); | 77 | spin_unlock(&gpio_lock); |
@@ -69,7 +79,7 @@ static int ls2f_gpio_get_value(struct gpio_chip *chip, unsigned gpio) | |||
69 | return (val & mask) != 0; | 79 | return (val & mask) != 0; |
70 | } | 80 | } |
71 | 81 | ||
72 | static void ls2f_gpio_set_value(struct gpio_chip *chip, | 82 | static void loongson_gpio_set_value(struct gpio_chip *chip, |
73 | unsigned gpio, int value) | 83 | unsigned gpio, int value) |
74 | { | 84 | { |
75 | u32 val; | 85 | u32 val; |
@@ -87,19 +97,19 @@ static void ls2f_gpio_set_value(struct gpio_chip *chip, | |||
87 | spin_unlock(&gpio_lock); | 97 | spin_unlock(&gpio_lock); |
88 | } | 98 | } |
89 | 99 | ||
90 | static struct gpio_chip ls2f_chip = { | 100 | static struct gpio_chip loongson_chip = { |
91 | .label = "ls2f", | 101 | .label = "Loongson-gpio-chip", |
92 | .direction_input = ls2f_gpio_direction_input, | 102 | .direction_input = loongson_gpio_direction_input, |
93 | .get = ls2f_gpio_get_value, | 103 | .get = loongson_gpio_get_value, |
94 | .direction_output = ls2f_gpio_direction_output, | 104 | .direction_output = loongson_gpio_direction_output, |
95 | .set = ls2f_gpio_set_value, | 105 | .set = loongson_gpio_set_value, |
96 | .base = 0, | 106 | .base = 0, |
97 | .ngpio = STLS2F_N_GPIO, | 107 | .ngpio = LOONGSON_N_GPIO, |
98 | .can_sleep = false, | 108 | .can_sleep = false, |
99 | }; | 109 | }; |
100 | 110 | ||
101 | static int __init ls2f_gpio_setup(void) | 111 | static int __init loongson_gpio_setup(void) |
102 | { | 112 | { |
103 | return gpiochip_add(&ls2f_chip); | 113 | return gpiochip_add(&loongson_chip); |
104 | } | 114 | } |
105 | arch_initcall(ls2f_gpio_setup); | 115 | postcore_initcall(loongson_gpio_setup); |