Add Dts And Acpi Support

LKML Archive on lore.kernel.orghelp / color / mirror / Atom feed

* [PATCH v4 1/2] gpio: loongson: add dts and acpi support@ :59 Yinbo Zhu :59 ` [PATCH v4 2/2] dt-bindings: gpio: add loongson gpio Yinbo Zhu ` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Yinbo Zhu @ :59 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Rob Herring,
Krzysztof Kozlowski, WANG Xuerui, Jiaxun Yang,
Thomas Bogendoerfer, Juxin Gao, Bibo Mao, Yanteng Si, linux-gpio,
devicetree, linux-kernel, loongarch, linux-mips, Arnaud Patard,
Huacai Chen, Yinbo Zhu
Cc: Jianmin Lv, Hongchen Zhang, Liu Peibao
Latest Loongson platforms such as the Loongson-2 SoC series describe
GPIO device resources with DTS or ACPI. Add such support to the
existing platform device driver.
Signed-off-by: Jianmin Lv
Signed-off-by: Hongchen Zhang
Signed-off-by: Liu Peibao
Signed-off-by: Juxin Gao
Signed-off-by: Yinbo Zhu Change in v4:
1. Fixup name spelling about Signed-off-by.
2. Drop “series” here and everywhere else.
3. Fixup the copyright in driver.
4. Drop the “else” in loongson_gpio_request.
5. Use trinocular operation replace the related logic.
6. Remove lable judgement in context about “lgpio->chip.to_irq = loongson_gpio_to_irq”
7. Use dev_err replace pr_err in probe.
8. Make legacy platform_data should be left out of this patch.
9. Remove the mips config in gpio Kconfig.
Change in v3:
1. Move the gpio platform data struct from arch/ into include/linux/ platform_data/.
2. Replace platform_gpio_data with loongson_gpio_platform_data in .c.
3. Add maintainer in MAINTAINERS file for include/linux/platform_data/ gpio-loongson.h and gpio-loongson.c
Change in v2:
1. Fixup of_loongson_gpio_get_props and remove the parse logic about “loongson,conf_offset”, “loongson,out_offset”, “loongson,in_offset”, “loongson,gpio_base”, “loongson,support_irq” then kernel driver will initial them that depend compatible except “loongson,gpio_base”.
MAINTAINERS | 8 +
drivers/gpio/Kconfig | 6 +-
drivers/gpio/gpio-loongson.c | 403 ++++++++++++++++++++++++++++ files changed, 338 insertions(+), 79 deletions(-)
diff –git a/MAINTAINERS b/MAINTAINERS
index 5114db9c8f32..838b920efcef a/MAINTAINERS
+++ b/MAINTAINERS
@@ ,6 +12051,14 @@ S: Maintained
F: Documentation/devicetree/bindings/hwinfo/loongson,ls2k-chipid.yaml
F: drivers/soc/loongson/loongson2_guts.c
+LOONGSON GPIO DRIVER
+M: Huacai Chen
+M: Yinbo Zhu
+L: linux-
+S: Maintained
+F: drivers/gpio/gpio-loongson.c
+F: include/linux/platform_data/gpio-loongson.h
+
LSILOGIC MPT FUSION DRIVERS (FC/SAS/SPI)
M: Sathya Prakash
M: Sreekanth Reddy diff –git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index a01af ..b4423c058b1d a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -376,10 +376,10 @@ config GPIO_LOGICVC
programmable logic block.
config GPIO_LOONGSON
– bool “Loongson-2/3 GPIO support”
– depends on CPU_LOONGSON2EF || CPU_LOONGSON64
+ bool “Loongson series GPIO support”
+ depends on LOONGARCH || COMPILE_TEST
help
– Driver for GPIO functionality on Loongson-2F/3A/3B processors.
+ Driver for GPIO functionality on Loongson seires processors.
config GPIO_LPC18XX
tristate “NXP LPC18XX/43XX GPIO support”
diff –git a/drivers/gpio/gpio-loongson.c b/drivers/gpio/gpio-loongson.c
index a cc9..b9b191a541c a/drivers/gpio/gpio-loongson.c
+++ b/drivers/gpio/gpio-loongson.c
@@ -1,13 +1,11 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
+// SPDX-License-Identifier: GPL-2.0+
/*
– * Loongson-2F/3A/3B GPIO Support
+ * Loongson GPIO Support
*
– * Copyright (c) 2008 Richard Liu, STMicroelectronics
– * Copyright (c) Arnaud Patard
– * Copyright (c) 2013 Hongbing Hu
– * Copyright (c) 2014 Huacai Chen + * Copyright (C) 2022 Loongson Technology Corporation Limited
*/
+#include
#include
#include
#include
@@ -17,119 +15,372 @@
#include
#include
#include
-#include +#include
-#define STLS2F_N_GPIO 4
-#define STLS3A_N_GPIO 16
+#define LOONGSON_GPIO_IN(x) (x->base + x->in_offset)
+#define LOONGSON_GPIO_OUT(x) (x->base + x->out_offset)
+#define LOONGSON_GPIO_OEN(x) (x->base + x->conf_offset)
-#ifdef CONFIG_CPU_LOONGSON64
-#define LOONGSON_N_GPIO STLS3A_N_GPIO
-#else
-#define LOONGSON_N_GPIO STLS2F_N_GPIO
-#endif
+#define LOONGSON_GPIO_IN_BYTE(x, gpio) (x->base +\
+ x->in_offset + gpio)
+#define LOONGSON_GPIO_OUT_BYTE(x, gpio) (x->base +\
+ x->out_offset + gpio)
+#define LOONGSON_GPIO_OEN_BYTE(x, gpio) (x->base +\
+ x->conf_offset + gpio)
-/*
– * Offset into the register where we read lines, we write them from offset 0.
– * This offset is the only thing that stand between us and using
– * GPIO_GENERIC.
– */
-#define LOONGSON_GPIO_IN_OFFSET 16
+struct loongson_gpio_chip {
+ struct gpio_chip chip;
+ spinlock_t lock;
+ void __iomem *base;
+ int conf_offset;
+ int out_offset;
+ int in_offset;
+ u16 *gsi_idx_map;
+ u16 mapsize;
+};
-static DEFINE_SPINLOCK(gpio_lock);
+static int loongson_gpio_request(
+ struct gpio_chip *chip, unsigned int pin)
+{
+ if (pin >= chip->ngpio)
+ return -EINVAL;
+
+ return 0;
+}
-static int loongson_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
+static inline void __set_direction(struct loongson_gpio_chip *lgpio,
+ unsigned int pin, int input)

– u32 val;
+ u64 qval;
+ u8 bval;
+
+ if (!strcmp(lgpio->chip.label, “loongson,ls2k-gpio”))
+ !strncmp(lgpio->chip.label, “LOON0002”, 8)) {
+ bval = input ? 1 : 0;
+ writeb(bval, LOONGSON_GPIO_OEN_BYTE(lgpio, pin));
+ return;
+ }
– return !!(val & BIT(gpio + LOONGSON_GPIO_IN_OFFSET));
+ if (!strcmp(lgpio->chip.label, “loongson,platform-gpio”))
+ if (input)
+ LOONGSON_GPIOIE

-static void loongson_gpio_set_value(struct gpio_chip *chip,
– unsigned gpio, int value)
+static void __set_level(struct loongson_gpio_chip *lgpio, unsigned int pin,
+ int high)
= BIT(gpio);
– else
– val &= ~BIT(gpio);
– LOONGSON_GPIODATA = val;
– spin_unlock(&gpio_lock);
+ if (!strcmp(lgpio->chip.label, “loongson,ls2k-gpio”))
+ qval = readq(LOONGSON_GPIO_OUT(lgpio));
+ if (high)
+ qval
-static int loongson_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
+static int loongson_gpio_direction_input(
+ struct gpio_chip *chip, unsigned int pin)
= BIT(gpio);
– LOONGSON_GPIOIE = temp;
– spin_unlock(&gpio_lock);
+ spin_lock_irqsave(&lgpio->lock, flags);
+ __set_direction(lgpio, pin, 1);
+ spin_unlock_irqrestore(&lgpio->lock, flags);
return 0;

-static int loongson_gpio_direction_output(struct gpio_chip *chip,
– unsigned gpio, int level)
+static int loongson_gpio_direction_output(
+ struct gpio_chip *chip, unsigned int pin,
+ int value)
{
– u32 temp;
+ struct loongson_gpio_chip *lgpio =
+ container_of(chip, struct loongson_gpio_chip, chip);
+ unsigned long flags;
– loongson_gpio_set_value(chip, gpio, level);
– spin_lock(&gpio_lock);
– temp = LOONGSON_GPIOIE;
– temp &= ~BIT(gpio);
– LOONGSON_GPIOIE = temp;
– spin_unlock(&gpio_lock);
+ spin_lock_irqsave(&lgpio->lock, flags);
+ __set_level(lgpio, pin, value);
+ __set_direction(lgpio, pin, 0);
+ spin_unlock_irqrestore(&lgpio->lock, flags);
return 0;
}
+static int loongson_gpio_get(struct gpio_chip *chip, unsigned int pin)
+