* [PATCH v6 1/2] gpio: loongson: add gpio driver support
@ 2022-11-23 8:04 Yinbo Zhu
2022-11-23 8:04 ` [PATCH v6 2/2] dt-bindings: gpio: add loongson gpio Yinbo Zhu
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Yinbo Zhu @ 2022-11-23 8:04 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
The Loongson platforms GPIO controller contains 60 GPIO pins in total,
4 of which are dedicated GPIO pins, and the remaining 56 are reused
with other functions. Each GPIO can set input/output and has the
interrupt capability.
This driver added support for Loongson GPIO controller and support to
use DTS or ACPI to descibe GPIO device resources.
Signed-off-by: Jianmin Lv <lvjianmin@loongson.cn>
Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
Signed-off-by: Liu Peibao <liupeibao@loongson.cn>
Signed-off-by: Juxin Gao <gaojuxin@loongson.cn>
Signed-off-by: Yinbo Zhu <zhuyinbo@loongson.cn>
---
Change in v6:
1. Remove the bit mode keep byte mode in all function except
loongson_gpio_init.
2. Use bgpio_init replace bit mode.
3. Implement the function loongson_gpio_get_direction for byte mode.
4. Set ngpios after call bgpio_init.
5. Use gpio-loongson-64bit.c as driver filename.
6. Ignore that loongson legacy drvier and remove the patch about
"gpio: loongson2ef: move driver to original location".
Change in v5:
1. Move legacy gpio driver to proper location.
2. Remove the "gpio_base".
3. Add of_device_id and acpi_device_id data field for platform
data.
4. Remove the ACPI_PTR().
5. Remove the gpio label judgement logic and use mode instead.
6. Drop platform_loongson_gpio_get_props.
7. Using devres for all resource.
8. Remove the loongson_gpio_remove.
9. Remove the unmatched print information.
10. Remove the loongson_gpio_exit.
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 | 6 +
drivers/gpio/Kconfig | 11 +
drivers/gpio/Makefile | 1 +
drivers/gpio/gpio-loongson-64bit.c | 315 +++++++++++++++++++++++++++++
4 files changed, 333 insertions(+)
create mode 100644 drivers/gpio/gpio-loongson-64bit.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 5114db9c8f32..2854da69cabb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12051,6 +12051,12 @@ S: Maintained
F: Documentation/devicetree/bindings/hwinfo/loongson,ls2k-chipid.yaml
F: drivers/soc/loongson/loongson2_guts.c
+LOONGSON GPIO DRIVER
+M: Yinbo Zhu <zhuyinbo@loongson.cn>
+L: linux-gpio@vger.kernel.org
+S: Maintained
+F: drivers/gpio/gpio-loongson-64bit.c
+
LSILOGIC MPT FUSION DRIVERS (FC/SAS/SPI)
M: Sathya Prakash <sathya.prakash@broadcom.com>
M: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index a01af1180616..840e8a80af2b 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -381,6 +381,17 @@ config GPIO_LOONGSON
help
Driver for GPIO functionality on Loongson-2F/3A/3B processors.
+config GPIO_LOONGSON_64BIT
+ tristate "Loongson 64 bit GPIO support"
+ depends on LOONGARCH || COMPILE_TEST
+ select GPIO_GENERIC
+ help
+ Say yes here to support the GPIO functionality of a number of
+ Loongson series of chips. The Loongson GPIO controller supports
+ up to 60 GPIOS in total, 4 of which are dedicated GPIO pins, and
+ the remaining 56 are reused with other functions, with edge or
+ level triggered interrupts.
+
config GPIO_LPC18XX
tristate "NXP LPC18XX/43XX GPIO support"
default y if ARCH_LPC18XX
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 29e3beb6548c..fc832484cc77 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -78,6 +78,7 @@ obj-$(CONFIG_GPIO_KEMPLD) += gpio-kempld.o
obj-$(CONFIG_GPIO_LOGICVC) += gpio-logicvc.o
obj-$(CONFIG_GPIO_LOONGSON1) += gpio-loongson1.o
obj-$(CONFIG_GPIO_LOONGSON) += gpio-loongson.o
+obj-$(CONFIG_GPIO_LOONGSON_64BIT) += gpio-loongson-64bit.o
obj-$(CONFIG_GPIO_LP3943) += gpio-lp3943.o
obj-$(CONFIG_GPIO_LP873X) += gpio-lp873x.o
obj-$(CONFIG_GPIO_LP87565) += gpio-lp87565.o
diff --git a/drivers/gpio/gpio-loongson-64bit.c b/drivers/gpio/gpio-loongson-64bit.c
new file mode 100644
index 000000000000..e0528a8768a0
--- /dev/null
+++ b/drivers/gpio/gpio-loongson-64bit.c
@@ -0,0 +1,315 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Loongson GPIO Support
+ *
+ * Copyright (C) 2022 Loongson Technology Corporation Limited
+ */
+
+#include <linux/acpi.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/spinlock.h>
+#include <linux/err.h>
+#include <linux/gpio/driver.h>
+#include <linux/platform_device.h>
+#include <linux/bitops.h>
+#include <asm/types.h>
+
+#define LOONGSON_GPIO_IN(x) (x->reg_base +\
+ x->p_data->in_offset)
+#define LOONGSON_GPIO_OUT(x) (x->reg_base +\
+ x->p_data->out_offset)
+#define LOONGSON_GPIO_OEN(x) (x->reg_base +\
+ x->p_data->conf_offset)
+#define LOONGSON_GPIO_IN_BYTE(x, gpio) (x->reg_base +\
+ x->p_data->in_offset + gpio)
+#define LOONGSON_GPIO_OUT_BYTE(x, gpio) (x->reg_base +\
+ x->p_data->out_offset + gpio)
+#define LOONGSON_GPIO_OEN_BYTE(x, gpio) (x->reg_base +\
+ x->p_data->conf_offset + gpio)
+
+enum loongson_gpio_mode {
+ BIT_CTRL_MODE,
+ BYTE_CTRL_MODE,
+};
+
+struct loongson_gpio_platform_data {
+ const char *label;
+ enum loongson_gpio_mode mode;
+ int conf_offset;
+ int out_offset;
+ int in_offset;
+};
+
+struct loongson_gpio_chip {
+ struct gpio_chip chip;
+ spinlock_t lock;
+ void __iomem *reg_base;
+ u16 *gsi_idx_map;
+ u16 mapsize;
+ const struct loongson_gpio_platform_data *p_data;
+};
+
+static int loongson_gpio_request(
+ struct gpio_chip *chip, unsigned int pin)
+{
+ if (pin >= chip->ngpio)
+ return -EINVAL;
+
+ return 0;
+}
+
+static inline void __set_direction(struct loongson_gpio_chip *lgpio,
+ unsigned int pin, int input)
+{
+ u8 bval;
+
+ bval = input ? 1 : 0;
+ writeb(bval, LOONGSON_GPIO_OEN_BYTE(lgpio, pin));
+}
+
+static void __set_level(struct loongson_gpio_chip *lgpio, unsigned int pin,
+ int high)
+{
+ u8 bval;
+
+ bval = high ? 1 : 0;
+ writeb(bval, LOONGSON_GPIO_OUT_BYTE(lgpio, pin));
+}
+
+static int loongson_gpio_direction_input(
+ struct gpio_chip *chip, unsigned int pin)
+{
+ unsigned long flags;
+ struct loongson_gpio_chip *lgpio =
+ container_of(chip, struct loongson_gpio_chip, chip);
+
+ 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 int pin,
+ int value)
+{
+ struct loongson_gpio_chip *lgpio =
+ container_of(chip, struct loongson_gpio_chip, chip);
+ unsigned long flags;
+
+ 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)
+{
+ u8 bval;
+ int val;
+
+ struct loongson_gpio_chip *lgpio =
+ container_of(chip, struct loongson_gpio_chip, chip);
+
+ bval = readb(LOONGSON_GPIO_IN_BYTE(lgpio, pin));
+ val = bval & 1;
+
+ return val;
+}
+
+static int loongson_gpio_get_direction(
+ struct gpio_chip *chip, unsigned int pin)
+{
+ u8 bval;
+ int val;
+
+ struct loongson_gpio_chip *lgpio =
+ container_of(chip, struct loongson_gpio_chip, chip);
+
+ bval = readb(LOONGSON_GPIO_OEN_BYTE(lgpio, pin));
+ val = bval & 1;
+
+ return val;
+}
+
+static void loongson_gpio_set(struct gpio_chip *chip, unsigned int pin,
+ int value)
+{
+ unsigned long flags;
+ struct loongson_gpio_chip *lgpio =
+ container_of(chip, struct loongson_gpio_chip, chip);
+
+ spin_lock_irqsave(&lgpio->lock, flags);
+ __set_level(lgpio, pin, value);
+ spin_unlock_irqrestore(&lgpio->lock, flags);
+}
+
+static int loongson_gpio_to_irq(
+ struct gpio_chip *chip, unsigned int offset)
+{
+ struct platform_device *pdev =
+ container_of(chip->parent, struct platform_device, dev);
+ struct loongson_gpio_chip *lgpio =
+ container_of(chip, struct loongson_gpio_chip, chip);
+
+ if (offset >= chip->ngpio)
+ return -EINVAL;
+
+ if ((lgpio->gsi_idx_map != NULL) && (offset < lgpio->mapsize))
+ offset = lgpio->gsi_idx_map[offset];
+ else
+ return -EINVAL;
+
+ return platform_get_irq(pdev, offset);
+}
+
+static int loongson_gpio_init(
+ struct device *dev, struct loongson_gpio_chip *lgpio,
+ struct device_node *np, void __iomem *reg_base)
+{
+ int ret;
+ u32 ngpios = lgpio->chip.ngpio;
+
+ lgpio->reg_base = reg_base;
+
+ if (lgpio->p_data->mode == BIT_CTRL_MODE) {
+ ret = bgpio_init(&lgpio->chip, dev, 8,
+ LOONGSON_GPIO_IN(lgpio),
+ LOONGSON_GPIO_OUT(lgpio), 0,
+ LOONGSON_GPIO_OEN(lgpio), NULL, 0);
+ if (ret) {
+ dev_err(dev, "unable to init generic GPIO\n");
+ return ret;
+ }
+ lgpio->chip.ngpio = ngpios;
+ lgpio->chip.base = 0;
+ } else {
+ lgpio->chip.request = loongson_gpio_request;
+ lgpio->chip.direction_input = loongson_gpio_direction_input;
+ lgpio->chip.get = loongson_gpio_get;
+ lgpio->chip.get_direction = loongson_gpio_get_direction;
+ lgpio->chip.direction_output = loongson_gpio_direction_output;
+ lgpio->chip.set = loongson_gpio_set;
+ lgpio->chip.can_sleep = 0;
+ lgpio->chip.of_node = np;
+ lgpio->chip.parent = dev;
+ spin_lock_init(&lgpio->lock);
+ }
+
+ lgpio->chip.label = lgpio->p_data->label;
+
+ lgpio->chip.to_irq = loongson_gpio_to_irq;
+
+ devm_gpiochip_add_data(dev, &lgpio->chip, lgpio);
+
+ return 0;
+}
+
+static void loongson_gpio_get_props(struct platform_device *pdev,
+ struct loongson_gpio_chip *lgpio)
+{
+ int rval;
+ u32 ngpios;
+ struct device *dev = &pdev->dev;
+
+ device_property_read_u32(dev, "ngpios", &ngpios);
+ lgpio->chip.ngpio = ngpios;
+
+ rval = device_property_read_u16_array(dev, "gsi_idx_map", NULL, 0);
+ if (rval > 0) {
+ lgpio->gsi_idx_map =
+ devm_kmalloc_array(dev, rval, sizeof(*lgpio->gsi_idx_map),
+ GFP_KERNEL);
+ if (lgpio->gsi_idx_map) {
+ lgpio->mapsize = rval;
+ device_property_read_u16_array(dev, "gsi_idx_map",
+ lgpio->gsi_idx_map, lgpio->mapsize);
+ }
+ }
+}
+
+static int loongson_gpio_probe(struct platform_device *pdev)
+{
+ void __iomem *reg_base;
+ struct loongson_gpio_chip *lgpio;
+ struct device_node *np = pdev->dev.of_node;
+ struct device *dev = &pdev->dev;
+
+ lgpio = devm_kzalloc(dev, sizeof(*lgpio), GFP_KERNEL);
+ if (!lgpio)
+ return -ENOMEM;
+
+ loongson_gpio_get_props(pdev, lgpio);
+
+ lgpio->p_data = device_get_match_data(&pdev->dev);
+
+ reg_base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(reg_base))
+ return PTR_ERR(reg_base);
+
+ loongson_gpio_init(dev, lgpio, np, reg_base);
+
+ return 0;
+}
+
+static const struct loongson_gpio_platform_data loongson_gpio_pdata0 = {
+ .label = "ls2k_gpio",
+ .mode = BIT_CTRL_MODE,
+ .conf_offset = 0x0,
+ .in_offset = 0x10,
+ .out_offset = 0x20,
+};
+
+static const struct loongson_gpio_platform_data loongson_gpio_pdata1 = {
+ .label = "ls7a_gpio",
+ .mode = BYTE_CTRL_MODE,
+ .conf_offset = 0x800,
+ .in_offset = 0x900,
+ .out_offset = 0xa00,
+};
+
+static const struct of_device_id loongson_gpio_of_match[] = {
+ {
+ .compatible = "loongson,ls2k-gpio",
+ .data = &loongson_gpio_pdata0,
+ },
+ {
+ .compatible = "loongson,ls7a-gpio",
+ .data = &loongson_gpio_pdata1,
+ },
+ {}
+};
+MODULE_DEVICE_TABLE(of, loongson_gpio_of_match);
+
+static const struct acpi_device_id loongson_gpio_acpi_match[] = {
+ {
+ .id = "LOON0002",
+ .driver_data = (kernel_ulong_t)&loongson_gpio_pdata1,
+ },
+ {}
+};
+MODULE_DEVICE_TABLE(acpi, loongson_gpio_acpi_match);
+
+static struct platform_driver loongson_gpio_driver = {
+ .driver = {
+ .name = "loongson-gpio",
+ .owner = THIS_MODULE,
+ .of_match_table = loongson_gpio_of_match,
+ .acpi_match_table = loongson_gpio_acpi_match,
+ },
+ .probe = loongson_gpio_probe,
+};
+
+static int __init loongson_gpio_setup(void)
+{
+ return platform_driver_register(&loongson_gpio_driver);
+}
+postcore_initcall(loongson_gpio_setup);
+
+MODULE_DESCRIPTION("Loongson gpio driver");
+MODULE_LICENSE("GPL");
--
2.31.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v6 2/2] dt-bindings: gpio: add loongson gpio
2022-11-23 8:04 [PATCH v6 1/2] gpio: loongson: add gpio driver support Yinbo Zhu
@ 2022-11-23 8:04 ` Yinbo Zhu
2022-11-23 10:25 ` [PATCH v6 1/2] gpio: loongson: add gpio driver support Bartosz Golaszewski
2022-11-23 22:14 ` Linus Walleij
2 siblings, 0 replies; 5+ messages in thread
From: Yinbo Zhu @ 2022-11-23 8:04 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: Krzysztof Kozlowski
Add the Loongson platform gpio binding with DT schema format using
json-schema.
Signed-off-by: Yinbo Zhu <zhuyinbo@loongson.cn>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
Change in v6:
1. NO change, but other patch in this series of patches set has
change.
Change in v5:
1. NO change, but other patch in this series of patches set has
change.
Change in v4:
1. Remove the string "series".
2. Add the reviewed-by information.
Change in v3:
1. Separate some changes of MAINTAINERS file and enter the first patch.
Change in v2:
1. Drop "loongson,gpio_base" and "gpio-ranges" will cover it.
1. Drop "loongson,conf_offset", "loongson,out_offset", "loongson,in_offset",
"loongson,support_irq" and kernel driver will initial them that depend
compatible in kernel.
3. Fixup maintainer for this driver.
.../bindings/gpio/loongson,ls-gpio.yaml | 126 ++++++++++++++++++
MAINTAINERS | 1 +
2 files changed, 127 insertions(+)
create mode 100644 Documentation/devicetree/bindings/gpio/loongson,ls-gpio.yaml
diff --git a/Documentation/devicetree/bindings/gpio/loongson,ls-gpio.yaml b/Documentation/devicetree/bindings/gpio/loongson,ls-gpio.yaml
new file mode 100644
index 000000000000..fb86e8ce6349
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/loongson,ls-gpio.yaml
@@ -0,0 +1,126 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/gpio/loongson,ls-gpio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Loongson GPIO controller.
+
+maintainers:
+ - Yinbo Zhu <zhuyinbo@loongson.cn>
+
+properties:
+ compatible:
+ enum:
+ - loongson,ls2k-gpio
+ - loongson,ls7a-gpio
+
+ reg:
+ maxItems: 1
+
+ ngpios:
+ minimum: 1
+ maximum: 64
+
+ "#gpio-cells":
+ const: 2
+
+ gpio-controller: true
+
+ gpio-ranges: true
+
+ interrupts:
+ minItems: 1
+ maxItems: 64
+
+required:
+ - compatible
+ - reg
+ - ngpios
+ - "#gpio-cells"
+ - gpio-controller
+ - gpio-ranges
+ - interrupts
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/interrupt-controller/irq.h>
+
+ gpio0: gpio@1fe00500 {
+ compatible = "loongson,ls2k-gpio";
+ reg = <0x1fe00500 0x38>;
+ ngpios = <64>;
+ #gpio-cells = <2>;
+ gpio-controller;
+ gpio-ranges = <&pctrl 0 0 15>,
+ <&pctrl 16 16 15>,
+ <&pctrl 32 32 10>,
+ <&pctrl 44 44 20>;
+ interrupt-parent = <&liointc1>;
+ interrupts = <28 IRQ_TYPE_LEVEL_LOW>,
+ <29 IRQ_TYPE_LEVEL_LOW>,
+ <30 IRQ_TYPE_LEVEL_LOW>,
+ <30 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <26 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <>,
+ <>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>,
+ <27 IRQ_TYPE_LEVEL_LOW>;
+ };
diff --git a/MAINTAINERS b/MAINTAINERS
index 2854da69cabb..b8a02a60973d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12055,6 +12055,7 @@ LOONGSON GPIO DRIVER
M: Yinbo Zhu <zhuyinbo@loongson.cn>
L: linux-gpio@vger.kernel.org
S: Maintained
+F: Documentation/devicetree/bindings/gpio/loongson,ls-gpio.yaml
F: drivers/gpio/gpio-loongson-64bit.c
LSILOGIC MPT FUSION DRIVERS (FC/SAS/SPI)
--
2.31.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v6 1/2] gpio: loongson: add gpio driver support
2022-11-23 8:04 [PATCH v6 1/2] gpio: loongson: add gpio driver support Yinbo Zhu
2022-11-23 8:04 ` [PATCH v6 2/2] dt-bindings: gpio: add loongson gpio Yinbo Zhu
@ 2022-11-23 10:25 ` Bartosz Golaszewski
2022-11-23 22:14 ` Linus Walleij
2 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2022-11-23 10:25 UTC (permalink / raw)
To: Yinbo Zhu
Cc: Linus Walleij, 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, Jianmin Lv,
Hongchen Zhang, Liu Peibao
On Wed, Nov 23, 2022 at 9:04 AM Yinbo Zhu <zhuyinbo@loongson.cn> wrote:
>
> The Loongson platforms GPIO controller contains 60 GPIO pins in total,
> 4 of which are dedicated GPIO pins, and the remaining 56 are reused
> with other functions. Each GPIO can set input/output and has the
> interrupt capability.
>
> This driver added support for Loongson GPIO controller and support to
> use DTS or ACPI to descibe GPIO device resources.
>
> Signed-off-by: Jianmin Lv <lvjianmin@loongson.cn>
> Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
> Signed-off-by: Liu Peibao <liupeibao@loongson.cn>
> Signed-off-by: Juxin Gao <gaojuxin@loongson.cn>
> Signed-off-by: Yinbo Zhu <zhuyinbo@loongson.cn>
> ---
> Change in v6:
> 1. Remove the bit mode keep byte mode in all function except
> loongson_gpio_init.
> 2. Use bgpio_init replace bit mode.
> 3. Implement the function loongson_gpio_get_direction for byte mode.
> 4. Set ngpios after call bgpio_init.
> 5. Use gpio-loongson-64bit.c as driver filename.
> 6. Ignore that loongson legacy drvier and remove the patch about
> "gpio: loongson2ef: move driver to original location".
> Change in v5:
> 1. Move legacy gpio driver to proper location.
> 2. Remove the "gpio_base".
> 3. Add of_device_id and acpi_device_id data field for platform
> data.
> 4. Remove the ACPI_PTR().
> 5. Remove the gpio label judgement logic and use mode instead.
> 6. Drop platform_loongson_gpio_get_props.
> 7. Using devres for all resource.
> 8. Remove the loongson_gpio_remove.
> 9. Remove the unmatched print information.
> 10. Remove the loongson_gpio_exit.
> 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 | 6 +
> drivers/gpio/Kconfig | 11 +
> drivers/gpio/Makefile | 1 +
> drivers/gpio/gpio-loongson-64bit.c | 315 +++++++++++++++++++++++++++++
> 4 files changed, 333 insertions(+)
> create mode 100644 drivers/gpio/gpio-loongson-64bit.c
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 5114db9c8f32..2854da69cabb 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -12051,6 +12051,12 @@ S: Maintained
> F: Documentation/devicetree/bindings/hwinfo/loongson,ls2k-chipid.yaml
> F: drivers/soc/loongson/loongson2_guts.c
>
> +LOONGSON GPIO DRIVER
> +M: Yinbo Zhu <zhuyinbo@loongson.cn>
> +L: linux-gpio@vger.kernel.org
> +S: Maintained
> +F: drivers/gpio/gpio-loongson-64bit.c
> +
> LSILOGIC MPT FUSION DRIVERS (FC/SAS/SPI)
> M: Sathya Prakash <sathya.prakash@broadcom.com>
> M: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> index a01af1180616..840e8a80af2b 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -381,6 +381,17 @@ config GPIO_LOONGSON
> help
> Driver for GPIO functionality on Loongson-2F/3A/3B processors.
>
> +config GPIO_LOONGSON_64BIT
> + tristate "Loongson 64 bit GPIO support"
> + depends on LOONGARCH || COMPILE_TEST
> + select GPIO_GENERIC
> + help
> + Say yes here to support the GPIO functionality of a number of
> + Loongson series of chips. The Loongson GPIO controller supports
> + up to 60 GPIOS in total, 4 of which are dedicated GPIO pins, and
> + the remaining 56 are reused with other functions, with edge or
> + level triggered interrupts.
> +
> config GPIO_LPC18XX
> tristate "NXP LPC18XX/43XX GPIO support"
> default y if ARCH_LPC18XX
> diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
> index 29e3beb6548c..fc832484cc77 100644
> --- a/drivers/gpio/Makefile
> +++ b/drivers/gpio/Makefile
> @@ -78,6 +78,7 @@ obj-$(CONFIG_GPIO_KEMPLD) += gpio-kempld.o
> obj-$(CONFIG_GPIO_LOGICVC) += gpio-logicvc.o
> obj-$(CONFIG_GPIO_LOONGSON1) += gpio-loongson1.o
> obj-$(CONFIG_GPIO_LOONGSON) += gpio-loongson.o
> +obj-$(CONFIG_GPIO_LOONGSON_64BIT) += gpio-loongson-64bit.o
> obj-$(CONFIG_GPIO_LP3943) += gpio-lp3943.o
> obj-$(CONFIG_GPIO_LP873X) += gpio-lp873x.o
> obj-$(CONFIG_GPIO_LP87565) += gpio-lp87565.o
> diff --git a/drivers/gpio/gpio-loongson-64bit.c b/drivers/gpio/gpio-loongson-64bit.c
> new file mode 100644
> index 000000000000..e0528a8768a0
> --- /dev/null
> +++ b/drivers/gpio/gpio-loongson-64bit.c
> @@ -0,0 +1,315 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Loongson GPIO Support
> + *
> + * Copyright (C) 2022 Loongson Technology Corporation Limited
> + */
> +
> +#include <linux/acpi.h>
> +#include <linux/kernel.h>
> +#include <linux/init.h>
> +#include <linux/module.h>
> +#include <linux/spinlock.h>
> +#include <linux/err.h>
> +#include <linux/gpio/driver.h>
> +#include <linux/platform_device.h>
> +#include <linux/bitops.h>
> +#include <asm/types.h>
> +
> +#define LOONGSON_GPIO_IN(x) (x->reg_base +\
> + x->p_data->in_offset)
> +#define LOONGSON_GPIO_OUT(x) (x->reg_base +\
> + x->p_data->out_offset)
> +#define LOONGSON_GPIO_OEN(x) (x->reg_base +\
> + x->p_data->conf_offset)
> +#define LOONGSON_GPIO_IN_BYTE(x, gpio) (x->reg_base +\
> + x->p_data->in_offset + gpio)
> +#define LOONGSON_GPIO_OUT_BYTE(x, gpio) (x->reg_base +\
> + x->p_data->out_offset + gpio)
> +#define LOONGSON_GPIO_OEN_BYTE(x, gpio) (x->reg_base +\
> + x->p_data->conf_offset + gpio)
> +
> +enum loongson_gpio_mode {
> + BIT_CTRL_MODE,
> + BYTE_CTRL_MODE,
> +};
> +
> +struct loongson_gpio_platform_data {
> + const char *label;
> + enum loongson_gpio_mode mode;
> + int conf_offset;
> + int out_offset;
> + int in_offset;
> +};
Calling this platform_data is confusing as platform data is typically
used for structures associated with device instances, not device
types. There is no hard convention but normally it would be called
chip_data.
> +
> +struct loongson_gpio_chip {
> + struct gpio_chip chip;
> + spinlock_t lock;
> + void __iomem *reg_base;
> + u16 *gsi_idx_map;
> + u16 mapsize;
> + const struct loongson_gpio_platform_data *p_data;
> +};
> +
> +static int loongson_gpio_request(
> + struct gpio_chip *chip, unsigned int pin)
> +{
> + if (pin >= chip->ngpio)
> + return -EINVAL;
> +
> + return 0;
> +}
> +
> +static inline void __set_direction(struct loongson_gpio_chip *lgpio,
> + unsigned int pin, int input)
> +{
> + u8 bval;
> +
> + bval = input ? 1 : 0;
> + writeb(bval, LOONGSON_GPIO_OEN_BYTE(lgpio, pin));
> +}
> +
> +static void __set_level(struct loongson_gpio_chip *lgpio, unsigned int pin,
> + int high)
> +{
> + u8 bval;
> +
> + bval = high ? 1 : 0;
> + writeb(bval, LOONGSON_GPIO_OUT_BYTE(lgpio, pin));
> +}
> +
> +static int loongson_gpio_direction_input(
> + struct gpio_chip *chip, unsigned int pin)
> +{
> + unsigned long flags;
> + struct loongson_gpio_chip *lgpio =
> + container_of(chip, struct loongson_gpio_chip, chip);
> +
> + 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 int pin,
> + int value)
> +{
> + struct loongson_gpio_chip *lgpio =
> + container_of(chip, struct loongson_gpio_chip, chip);
> + unsigned long flags;
> +
> + 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)
> +{
> + u8 bval;
> + int val;
> +
> + struct loongson_gpio_chip *lgpio =
> + container_of(chip, struct loongson_gpio_chip, chip);
> +
> + bval = readb(LOONGSON_GPIO_IN_BYTE(lgpio, pin));
> + val = bval & 1;
> +
> + return val;
> +}
> +
> +static int loongson_gpio_get_direction(
> + struct gpio_chip *chip, unsigned int pin)
> +{
> + u8 bval;
> + int val;
> +
> + struct loongson_gpio_chip *lgpio =
> + container_of(chip, struct loongson_gpio_chip, chip);
> +
> + bval = readb(LOONGSON_GPIO_OEN_BYTE(lgpio, pin));
> + val = bval & 1;
> +
> + return val;
> +}
> +
> +static void loongson_gpio_set(struct gpio_chip *chip, unsigned int pin,
> + int value)
> +{
> + unsigned long flags;
> + struct loongson_gpio_chip *lgpio =
> + container_of(chip, struct loongson_gpio_chip, chip);
> +
> + spin_lock_irqsave(&lgpio->lock, flags);
> + __set_level(lgpio, pin, value);
> + spin_unlock_irqrestore(&lgpio->lock, flags);
> +}
> +
> +static int loongson_gpio_to_irq(
> + struct gpio_chip *chip, unsigned int offset)
> +{
> + struct platform_device *pdev =
> + container_of(chip->parent, struct platform_device, dev);
> + struct loongson_gpio_chip *lgpio =
> + container_of(chip, struct loongson_gpio_chip, chip);
> +
> + if (offset >= chip->ngpio)
> + return -EINVAL;
> +
> + if ((lgpio->gsi_idx_map != NULL) && (offset < lgpio->mapsize))
> + offset = lgpio->gsi_idx_map[offset];
> + else
> + return -EINVAL;
> +
> + return platform_get_irq(pdev, offset);
> +}
> +
> +static int loongson_gpio_init(
> + struct device *dev, struct loongson_gpio_chip *lgpio,
> + struct device_node *np, void __iomem *reg_base)
> +{
> + int ret;
> + u32 ngpios = lgpio->chip.ngpio;
> +
> + lgpio->reg_base = reg_base;
> +
> + if (lgpio->p_data->mode == BIT_CTRL_MODE) {
> + ret = bgpio_init(&lgpio->chip, dev, 8,
> + LOONGSON_GPIO_IN(lgpio),
> + LOONGSON_GPIO_OUT(lgpio), 0,
> + LOONGSON_GPIO_OEN(lgpio), NULL, 0);
> + if (ret) {
> + dev_err(dev, "unable to init generic GPIO\n");
> + return ret;
> + }
> + lgpio->chip.ngpio = ngpios;
> + lgpio->chip.base = 0;
> + } else {
> + lgpio->chip.request = loongson_gpio_request;
> + lgpio->chip.direction_input = loongson_gpio_direction_input;
> + lgpio->chip.get = loongson_gpio_get;
> + lgpio->chip.get_direction = loongson_gpio_get_direction;
> + lgpio->chip.direction_output = loongson_gpio_direction_output;
> + lgpio->chip.set = loongson_gpio_set;
> + lgpio->chip.can_sleep = 0;
> + lgpio->chip.of_node = np;
> + lgpio->chip.parent = dev;
> + spin_lock_init(&lgpio->lock);
> + }
> +
> + lgpio->chip.label = lgpio->p_data->label;
> +
> + lgpio->chip.to_irq = loongson_gpio_to_irq;
> +
> + devm_gpiochip_add_data(dev, &lgpio->chip, lgpio);
> +
> + return 0;
You can return the above function directly.
> +}
> +
> +static void loongson_gpio_get_props(struct platform_device *pdev,
> + struct loongson_gpio_chip *lgpio)
> +{
> + int rval;
> + u32 ngpios;
> + struct device *dev = &pdev->dev;
> +
> + device_property_read_u32(dev, "ngpios", &ngpios);
> + lgpio->chip.ngpio = ngpios;
> +
> + rval = device_property_read_u16_array(dev, "gsi_idx_map", NULL, 0);
> + if (rval > 0) {
> + lgpio->gsi_idx_map =
> + devm_kmalloc_array(dev, rval, sizeof(*lgpio->gsi_idx_map),
> + GFP_KERNEL);
> + if (lgpio->gsi_idx_map) {
> + lgpio->mapsize = rval;
> + device_property_read_u16_array(dev, "gsi_idx_map",
> + lgpio->gsi_idx_map, lgpio->mapsize);
> + }
> + }
> +}
> +
> +static int loongson_gpio_probe(struct platform_device *pdev)
> +{
> + void __iomem *reg_base;
> + struct loongson_gpio_chip *lgpio;
> + struct device_node *np = pdev->dev.of_node;
> + struct device *dev = &pdev->dev;
> +
> + lgpio = devm_kzalloc(dev, sizeof(*lgpio), GFP_KERNEL);
> + if (!lgpio)
> + return -ENOMEM;
> +
> + loongson_gpio_get_props(pdev, lgpio);
> +
> + lgpio->p_data = device_get_match_data(&pdev->dev);
> +
> + reg_base = devm_platform_ioremap_resource(pdev, 0);
> + if (IS_ERR(reg_base))
> + return PTR_ERR(reg_base);
> +
> + loongson_gpio_init(dev, lgpio, np, reg_base);
> +
> + return 0;
> +}
> +
> +static const struct loongson_gpio_platform_data loongson_gpio_pdata0 = {
> + .label = "ls2k_gpio",
> + .mode = BIT_CTRL_MODE,
> + .conf_offset = 0x0,
> + .in_offset = 0x10,
> + .out_offset = 0x20,
> +};
> +
> +static const struct loongson_gpio_platform_data loongson_gpio_pdata1 = {
> + .label = "ls7a_gpio",
> + .mode = BYTE_CTRL_MODE,
> + .conf_offset = 0x800,
> + .in_offset = 0x900,
> + .out_offset = 0xa00,
> +};
> +
> +static const struct of_device_id loongson_gpio_of_match[] = {
> + {
> + .compatible = "loongson,ls2k-gpio",
> + .data = &loongson_gpio_pdata0,
> + },
> + {
> + .compatible = "loongson,ls7a-gpio",
> + .data = &loongson_gpio_pdata1,
> + },
> + {}
> +};
> +MODULE_DEVICE_TABLE(of, loongson_gpio_of_match);
> +
> +static const struct acpi_device_id loongson_gpio_acpi_match[] = {
> + {
> + .id = "LOON0002",
> + .driver_data = (kernel_ulong_t)&loongson_gpio_pdata1,
> + },
> + {}
> +};
> +MODULE_DEVICE_TABLE(acpi, loongson_gpio_acpi_match);
> +
> +static struct platform_driver loongson_gpio_driver = {
> + .driver = {
> + .name = "loongson-gpio",
> + .owner = THIS_MODULE,
> + .of_match_table = loongson_gpio_of_match,
> + .acpi_match_table = loongson_gpio_acpi_match,
> + },
> + .probe = loongson_gpio_probe,
> +};
> +
> +static int __init loongson_gpio_setup(void)
> +{
> + return platform_driver_register(&loongson_gpio_driver);
> +}
> +postcore_initcall(loongson_gpio_setup);
> +
> +MODULE_DESCRIPTION("Loongson gpio driver");
> +MODULE_LICENSE("GPL");
> --
> 2.31.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v6 1/2] gpio: loongson: add gpio driver support
2022-11-23 8:04 [PATCH v6 1/2] gpio: loongson: add gpio driver support Yinbo Zhu
2022-11-23 8:04 ` [PATCH v6 2/2] dt-bindings: gpio: add loongson gpio Yinbo Zhu
2022-11-23 10:25 ` [PATCH v6 1/2] gpio: loongson: add gpio driver support Bartosz Golaszewski
@ 2022-11-23 22:14 ` Linus Walleij
2022-11-28 6:25 ` Yinbo Zhu
2 siblings, 1 reply; 5+ messages in thread
From: Linus Walleij @ 2022-11-23 22:14 UTC (permalink / raw)
To: Yinbo Zhu
Cc: 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, Jianmin Lv,
Hongchen Zhang, Liu Peibao
On Wed, Nov 23, 2022 at 9:04 AM Yinbo Zhu <zhuyinbo@loongson.cn> wrote:
> The Loongson platforms GPIO controller contains 60 GPIO pins in total,
> 4 of which are dedicated GPIO pins, and the remaining 56 are reused
> with other functions. Each GPIO can set input/output and has the
> interrupt capability.
>
> This driver added support for Loongson GPIO controller and support to
> use DTS or ACPI to descibe GPIO device resources.
>
> Signed-off-by: Jianmin Lv <lvjianmin@loongson.cn>
> Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
> Signed-off-by: Liu Peibao <liupeibao@loongson.cn>
> Signed-off-by: Juxin Gao <gaojuxin@loongson.cn>
> Signed-off-by: Yinbo Zhu <zhuyinbo@loongson.cn>
> ---
> Change in v6:
This is way better :)
I guess you notice how the driver gets smaller and smaller.
This is a good sign!
> +static int loongson_gpio_request(
> + struct gpio_chip *chip, unsigned int pin)
> +{
> + if (pin >= chip->ngpio)
> + return -EINVAL;
> +
> + return 0;
> +}
Drop this altogether as discussed in my other reply.
> +static inline void __set_direction(struct loongson_gpio_chip *lgpio,
> + unsigned int pin, int input)
> +static void __set_level(struct loongson_gpio_chip *lgpio, unsigned int pin,
> + int high)
I missed this before. Also the use of __underscore for inner functions
is a bad habit IMO (because __underscore is also used for compiler
primitives such as __init which is confusing) The signature of these
functions is too generic. Name them loongson_commit_direction() or
loongson_commit_level() or something.
> +static int loongson_gpio_get_direction(
> + struct gpio_chip *chip, unsigned int pin)
thanks for implementing this!
> + if (lgpio->p_data->mode == BIT_CTRL_MODE) {
> + ret = bgpio_init(&lgpio->chip, dev, 8,
> + LOONGSON_GPIO_IN(lgpio),
> + LOONGSON_GPIO_OUT(lgpio), 0,
> + LOONGSON_GPIO_OEN(lgpio), NULL, 0);
> + if (ret) {
> + dev_err(dev, "unable to init generic GPIO\n");
> + return ret;
> + }
> + lgpio->chip.ngpio = ngpios;
Neat!
> + lgpio->chip.base = 0;
Drop this. It is good that the base is unpredictable so
people don't start to rely on it. (drivers/gpio/TODO)
> + rval = device_property_read_u16_array(dev, "gsi_idx_map", NULL, 0);
But this gsi_idx_map is missing from your device tree bindings,
is it not?
Or what am I missing here? Sorry I might overlook something...
> +static int loongson_gpio_probe(struct platform_device *pdev)
> +{
> + void __iomem *reg_base;
> + struct loongson_gpio_chip *lgpio;
> + struct device_node *np = pdev->dev.of_node;
> + struct device *dev = &pdev->dev;
> +
> + lgpio = devm_kzalloc(dev, sizeof(*lgpio), GFP_KERNEL);
> + if (!lgpio)
> + return -ENOMEM;
> +
> + loongson_gpio_get_props(pdev, lgpio);
> +
> + lgpio->p_data = device_get_match_data(&pdev->dev);
lgpio->p_data = device_get_match_data(dev);
> +static int __init loongson_gpio_setup(void)
> +{
> + return platform_driver_register(&loongson_gpio_driver);
> +}
> +postcore_initcall(loongson_gpio_setup);
Why does this have to be postcore_initcall()?
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v6 1/2] gpio: loongson: add gpio driver support
2022-11-23 22:14 ` Linus Walleij
@ 2022-11-28 6:25 ` Yinbo Zhu
0 siblings, 0 replies; 5+ messages in thread
From: Yinbo Zhu @ 2022-11-28 6:25 UTC (permalink / raw)
To: Linus Walleij
Cc: 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, Jianmin Lv,
Hongchen Zhang, Liu Peibao
在 2022/11/24 6:14, Linus Walleij 写道:
> On Wed, Nov 23, 2022 at 9:04 AM Yinbo Zhu <zhuyinbo@loongson.cn> wrote:
>
>> The Loongson platforms GPIO controller contains 60 GPIO pins in total,
>> 4 of which are dedicated GPIO pins, and the remaining 56 are reused
>> with other functions. Each GPIO can set input/output and has the
>> interrupt capability.
>>
>> This driver added support for Loongson GPIO controller and support to
>> use DTS or ACPI to descibe GPIO device resources.
>>
>> Signed-off-by: Jianmin Lv <lvjianmin@loongson.cn>
>> Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
>> Signed-off-by: Liu Peibao <liupeibao@loongson.cn>
>> Signed-off-by: Juxin Gao <gaojuxin@loongson.cn>
>> Signed-off-by: Yinbo Zhu <zhuyinbo@loongson.cn>
>> ---
>> Change in v6:
> This is way better :)
>
> I guess you notice how the driver gets smaller and smaller.
> This is a good sign!
It's thanks to your advice!
>> +static int loongson_gpio_request(
>> + struct gpio_chip *chip, unsigned int pin)
>> +{
>> + if (pin >= chip->ngpio)
>> + return -EINVAL;
>> +
>> + return 0;
>> +}
> Drop this altogether as discussed in my other reply.
okay , I got it.
>
>> +static inline void __set_direction(struct loongson_gpio_chip *lgpio,
>> + unsigned int pin, int input)
>> +static void __set_level(struct loongson_gpio_chip *lgpio, unsigned int pin,
>> + int high)
> I missed this before. Also the use of __underscore for inner functions
> is a bad habit IMO (because __underscore is also used for compiler
> primitives such as __init which is confusing) The signature of these
> functions is too generic. Name them loongson_commit_direction() or
> loongson_commit_level() or something.
okay , I got it.
>
>> +static int loongson_gpio_get_direction(
>> + struct gpio_chip *chip, unsigned int pin)
> thanks for implementing this!
>
>> + if (lgpio->p_data->mode == BIT_CTRL_MODE) {
>> + ret = bgpio_init(&lgpio->chip, dev, 8,
>> + LOONGSON_GPIO_IN(lgpio),
>> + LOONGSON_GPIO_OUT(lgpio), 0,
>> + LOONGSON_GPIO_OEN(lgpio), NULL, 0);
>> + if (ret) {
>> + dev_err(dev, "unable to init generic GPIO\n");
>> + return ret;
>> + }
>> + lgpio->chip.ngpio = ngpios;
> Neat!
>
>> + lgpio->chip.base = 0;
> Drop this. It is good that the base is unpredictable so
> people don't start to rely on it. (drivers/gpio/TODO)
okay, I got it.
>
>> + rval = device_property_read_u16_array(dev, "gsi_idx_map", NULL, 0);
> But this gsi_idx_map is missing from your device tree bindings,
> is it not?
>
> Or what am I missing here? Sorry I might overlook something...
gsi_idx_map is for acpi, the dts doesn't use it, and acpi should be
follow dts,
so remove it.
>
>> +static int loongson_gpio_probe(struct platform_device *pdev)
>> +{
>> + void __iomem *reg_base;
>> + struct loongson_gpio_chip *lgpio;
>> + struct device_node *np = pdev->dev.of_node;
>> + struct device *dev = &pdev->dev;
>> +
>> + lgpio = devm_kzalloc(dev, sizeof(*lgpio), GFP_KERNEL);
>> + if (!lgpio)
>> + return -ENOMEM;
>> +
>> + loongson_gpio_get_props(pdev, lgpio);
>> +
>> + lgpio->p_data = device_get_match_data(&pdev->dev);
> lgpio->p_data = device_get_match_data(dev);
>
>
>> +static int __init loongson_gpio_setup(void)
>> +{
>> + return platform_driver_register(&loongson_gpio_driver);
>> +}
>> +postcore_initcall(loongson_gpio_setup);
> Why does this have to be postcore_initcall()?
it was refer other gpio driver. other perpherial driver will use gpio,
the gpio driver
should be loaded as early as possible,so use postcore_initcall();
>
> Yours,
> Linus Walleij
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-11-28 6:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-23 8:04 [PATCH v6 1/2] gpio: loongson: add gpio driver support Yinbo Zhu
2022-11-23 8:04 ` [PATCH v6 2/2] dt-bindings: gpio: add loongson gpio Yinbo Zhu
2022-11-23 10:25 ` [PATCH v6 1/2] gpio: loongson: add gpio driver support Bartosz Golaszewski
2022-11-23 22:14 ` Linus Walleij
2022-11-28 6:25 ` Yinbo Zhu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.