Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Huacai Chen and committed by
Linus Walleij
cbfb3ea7 991ff4e3

+32 -20
+1
arch/mips/Kconfig
··· 1245 1245 select CPU_SUPPORTS_HUGEPAGES 1246 1246 select WEAK_ORDERING 1247 1247 select WEAK_REORDERING_BEYOND_LLSC 1248 + select ARCH_REQUIRE_GPIOLIB 1248 1249 help 1249 1250 The Loongson 3 processor implements the MIPS64R2 instruction 1250 1251 set with many extensions.
+1
arch/mips/configs/loongson3_defconfig
··· 243 243 CONFIG_RAW_DRIVER=m 244 244 CONFIG_I2C_CHARDEV=y 245 245 CONFIG_I2C_PIIX4=y 246 + CONFIG_GPIO_LOONGSON=y 246 247 CONFIG_SENSORS_LM75=m 247 248 CONFIG_SENSORS_LM93=m 248 249 CONFIG_SENSORS_W83627HF=m
+3 -3
drivers/gpio/Kconfig
··· 509 509 VHDL IP core library. 510 510 511 511 config GPIO_LOONGSON 512 - bool "Loongson-2 GPIO support" 513 - depends on CPU_LOONGSON2 512 + bool "Loongson-2/3 GPIO support" 513 + depends on CPU_LOONGSON2 || CPU_LOONGSON3 514 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 517 config GPIO_TB10X 518 518 bool
+27 -17
drivers/gpio/gpio-loongson.c
··· 1 1 /* 2 - * STLS2F GPIO Support 2 + * Loongson-2F/3A/3B GPIO Support 3 3 * 4 4 * Copyright (c) 2008 Richard Liu, STMicroelectronics <richard.liu@st.com> 5 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 9 * This program is free software; you can redistribute it and/or modify 8 10 * it under the terms of the GNU General Public License as published by ··· 22 20 #include <linux/gpio.h> 23 21 24 22 #define STLS2F_N_GPIO 4 25 - #define STLS2F_GPIO_IN_OFFSET 16 23 + #define STLS3A_N_GPIO 16 24 + 25 + #ifdef CONFIG_CPU_LOONGSON3 26 + #define LOONGSON_N_GPIO STLS3A_N_GPIO 27 + #else 28 + #define LOONGSON_N_GPIO STLS2F_N_GPIO 29 + #endif 30 + 31 + #define LOONGSON_GPIO_IN_OFFSET 16 26 32 27 33 static DEFINE_SPINLOCK(gpio_lock); 28 34 29 - static int ls2f_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) 35 + static int loongson_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) 30 36 { 31 37 u32 temp; 32 38 u32 mask; ··· 49 39 return 0; 50 40 } 51 41 52 - static int ls2f_gpio_direction_output(struct gpio_chip *chip, 42 + static int loongson_gpio_direction_output(struct gpio_chip *chip, 53 43 unsigned gpio, int level) 54 44 { 55 45 u32 temp; ··· 66 56 return 0; 67 57 } 68 58 69 - static int ls2f_gpio_get_value(struct gpio_chip *chip, unsigned gpio) 59 + static int loongson_gpio_get_value(struct gpio_chip *chip, unsigned gpio) 70 60 { 71 61 u32 val; 72 62 u32 mask; 73 63 74 - mask = 1 << (gpio + STLS2F_GPIO_IN_OFFSET); 64 + mask = 1 << (gpio + LOONGSON_GPIO_IN_OFFSET); 75 65 spin_lock(&gpio_lock); 76 66 val = LOONGSON_GPIODATA; 77 67 spin_unlock(&gpio_lock); ··· 79 69 return (val & mask) != 0; 80 70 } 81 71 82 - static void ls2f_gpio_set_value(struct gpio_chip *chip, 72 + static void loongson_gpio_set_value(struct gpio_chip *chip, 83 73 unsigned gpio, int value) 84 74 { 85 75 u32 val; ··· 97 87 spin_unlock(&gpio_lock); 98 88 } 99 89 100 - static struct gpio_chip ls2f_chip = { 101 - .label = "ls2f", 102 - .direction_input = ls2f_gpio_direction_input, 103 - .get = ls2f_gpio_get_value, 104 - .direction_output = ls2f_gpio_direction_output, 105 - .set = ls2f_gpio_set_value, 90 + static struct gpio_chip loongson_chip = { 91 + .label = "Loongson-gpio-chip", 92 + .direction_input = loongson_gpio_direction_input, 93 + .get = loongson_gpio_get_value, 94 + .direction_output = loongson_gpio_direction_output, 95 + .set = loongson_gpio_set_value, 106 96 .base = 0, 107 - .ngpio = STLS2F_N_GPIO, 97 + .ngpio = LOONGSON_N_GPIO, 108 98 .can_sleep = false, 109 99 }; 110 100 111 - static int __init ls2f_gpio_setup(void) 101 + static int __init loongson_gpio_setup(void) 112 102 { 113 - return gpiochip_add(&ls2f_chip); 103 + return gpiochip_add(&loongson_chip); 114 104 } 115 - arch_initcall(ls2f_gpio_setup); 105 + postcore_initcall(loongson_gpio_setup);