All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/2] gpio: loongson: add more gpio chip support
@ 2023-08-29 12:35 Yinbo Zhu
  2023-08-29 12:35 ` [PATCH v5 1/2] gpio: dt-bindings: add more loongson " Yinbo Zhu
  2023-08-29 12:35 ` [PATCH v5 2/2] gpio: loongson: add more " Yinbo Zhu
  0 siblings, 2 replies; 6+ messages in thread
From: Yinbo Zhu @ 2023-08-29 12:35 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-gpio, devicetree,
	linux-kernel
  Cc: Jianmin Lv, wanghongliang, loongson-kernel, Yinbo Zhu

This patch was to add loongson 2k0500, 2k2000 and 3a5000 gpio chip
driver support.

Change in v5:
		1. Use boolean initializer for lgpio->chip.can_sleep.
		2. Remove the code that about io width gain from ngpios.
		3. Fixup the ls7a-gpio and ls2k-gpio items in yaml file.
		4. Add the reviewed-by information for dt-bindings patch.
		5. Add some comments in loongson_gpio_to_irq.
Change in v4:
		1. Reword the title and commit log information.
		2. Remove the offset parse in DT and add it in of_device_id and
		   acpi_device_id's data field.
		3. Add more gpio chip dt-bindings support in yaml file.
Change in v3:
		1. Reword the dt-bindings patch commit log information.
		2. Add "loongson,ls2k1000-gpio" compatible.
Change in v2:
		1. Reword the patch commit log information.
		2. Add some GPIO register offset description in yaml.

Yinbo Zhu (2):
  gpio: dt-bindings: add more loongson gpio chip support
  gpio: loongson: add more gpio chip support

 .../bindings/gpio/loongson,ls-gpio.yaml       |  21 ++-
 drivers/gpio/gpio-loongson-64bit.c            | 125 ++++++++++++++++--
 2 files changed, 130 insertions(+), 16 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v5 1/2] gpio: dt-bindings: add more loongson gpio chip support
  2023-08-29 12:35 [PATCH v5 0/2] gpio: loongson: add more gpio chip support Yinbo Zhu
@ 2023-08-29 12:35 ` Yinbo Zhu
  2023-08-29 12:35 ` [PATCH v5 2/2] gpio: loongson: add more " Yinbo Zhu
  1 sibling, 0 replies; 6+ messages in thread
From: Yinbo Zhu @ 2023-08-29 12:35 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-gpio, devicetree,
	linux-kernel
  Cc: Jianmin Lv, wanghongliang, loongson-kernel, Yinbo Zhu, Conor Dooley

This patch was to add loongson 2k0500, 2k2000 and 3a5000 gpio chip
dt-bindings support in yaml file.

Signed-off-by: Yinbo Zhu <zhuyinbo@loongson.cn>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Conor Dooley <conor.dooley@microchip.com>
---
 .../bindings/gpio/loongson,ls-gpio.yaml       | 21 +++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/gpio/loongson,ls-gpio.yaml b/Documentation/devicetree/bindings/gpio/loongson,ls-gpio.yaml
index fb86e8ce6349..cf3b1b270aa8 100644
--- a/Documentation/devicetree/bindings/gpio/loongson,ls-gpio.yaml
+++ b/Documentation/devicetree/bindings/gpio/loongson,ls-gpio.yaml
@@ -11,9 +11,22 @@ maintainers:
 
 properties:
   compatible:
-    enum:
-      - loongson,ls2k-gpio
-      - loongson,ls7a-gpio
+    oneOf:
+      - enum:
+          - loongson,ls2k-gpio
+          - loongson,ls2k0500-gpio0
+          - loongson,ls2k0500-gpio1
+          - loongson,ls2k2000-gpio0
+          - loongson,ls2k2000-gpio1
+          - loongson,ls2k2000-gpio2
+          - loongson,ls3a5000-gpio
+          - loongson,ls7a-gpio
+      - items:
+          - const: loongson,ls2k1000-gpio
+          - const: loongson,ls2k-gpio
+      - items:
+          - const: loongson,ls7a1000-gpio
+          - const: loongson,ls7a-gpio
 
   reg:
     maxItems: 1
@@ -49,7 +62,7 @@ examples:
     #include <dt-bindings/interrupt-controller/irq.h>
 
     gpio0: gpio@1fe00500 {
-      compatible = "loongson,ls2k-gpio";
+      compatible = "loongson,ls2k1000-gpio", "loongson,ls2k-gpio";
       reg = <0x1fe00500 0x38>;
       ngpios = <64>;
       #gpio-cells = <2>;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v5 2/2] gpio: loongson: add more gpio chip support
  2023-08-29 12:35 [PATCH v5 0/2] gpio: loongson: add more gpio chip support Yinbo Zhu
  2023-08-29 12:35 ` [PATCH v5 1/2] gpio: dt-bindings: add more loongson " Yinbo Zhu
@ 2023-08-29 12:35 ` Yinbo Zhu
  2023-09-12  7:06   ` Linus Walleij
  2023-09-12  9:02   ` Bartosz Golaszewski
  1 sibling, 2 replies; 6+ messages in thread
From: Yinbo Zhu @ 2023-08-29 12:35 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-gpio, devicetree,
	linux-kernel
  Cc: Jianmin Lv, wanghongliang, loongson-kernel, Yinbo Zhu

This patch was to add loongson 2k0500, 2k2000 and 3a5000 gpio chip
driver support.

Signed-off-by: Yinbo Zhu <zhuyinbo@loongson.cn>
---
 drivers/gpio/gpio-loongson-64bit.c | 125 ++++++++++++++++++++++++++---
 1 file changed, 113 insertions(+), 12 deletions(-)

diff --git a/drivers/gpio/gpio-loongson-64bit.c b/drivers/gpio/gpio-loongson-64bit.c
index 06213bbfabdd..2608f7eeba3b 100644
--- a/drivers/gpio/gpio-loongson-64bit.c
+++ b/drivers/gpio/gpio-loongson-64bit.c
@@ -23,9 +23,10 @@ enum loongson_gpio_mode {
 struct loongson_gpio_chip_data {
 	const char		*label;
 	enum loongson_gpio_mode	mode;
-	unsigned int		conf_offset;
-	unsigned int		out_offset;
-	unsigned int		in_offset;
+	u32			conf_offset;
+	u32			out_offset;
+	u32			in_offset;
+	u32			inten_offset;
 };
 
 struct loongson_gpio_chip {
@@ -117,19 +118,29 @@ static void loongson_gpio_set(struct gpio_chip *chip, unsigned int pin, int valu
 
 static int loongson_gpio_to_irq(struct gpio_chip *chip, unsigned int offset)
 {
+	unsigned int u;
 	struct platform_device *pdev = to_platform_device(chip->parent);
+	struct loongson_gpio_chip *lgpio = to_loongson_gpio_chip(chip);
+
+	if (lgpio->chip_data->mode == BIT_CTRL_MODE) {
+		/* Get the register index from offset then multiply by bytes per register */
+		u = readl(lgpio->reg_base + lgpio->chip_data->inten_offset + (offset / 32) * 4);
+		u |= BIT(offset % 32);
+		writel(u, lgpio->reg_base + lgpio->chip_data->inten_offset + (offset / 32) * 4);
+	} else {
+		writeb(1, lgpio->reg_base + lgpio->chip_data->inten_offset + offset);
+	}
 
 	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)
+			      void __iomem *reg_base)
 {
 	int ret;
 	u32 ngpios;
 
 	lgpio->reg_base = reg_base;
-
 	if (lgpio->chip_data->mode == BIT_CTRL_MODE) {
 		ret = bgpio_init(&lgpio->chip, dev, 8,
 				lgpio->reg_base + lgpio->chip_data->in_offset,
@@ -148,15 +159,15 @@ static int loongson_gpio_init(struct device *dev, struct loongson_gpio_chip *lgp
 		lgpio->chip.direction_output = loongson_gpio_direction_output;
 		lgpio->chip.set = loongson_gpio_set;
 		lgpio->chip.parent = dev;
+		device_property_read_u32(dev, "ngpios", &ngpios);
+		lgpio->chip.ngpio = ngpios;
 		spin_lock_init(&lgpio->lock);
 	}
 
-	device_property_read_u32(dev, "ngpios", &ngpios);
-
-	lgpio->chip.can_sleep = 0;
-	lgpio->chip.ngpio = ngpios;
 	lgpio->chip.label = lgpio->chip_data->label;
-	lgpio->chip.to_irq = loongson_gpio_to_irq;
+	lgpio->chip.can_sleep = false;
+	if (lgpio->chip_data->inten_offset)
+		lgpio->chip.to_irq = loongson_gpio_to_irq;
 
 	return devm_gpiochip_add_data(dev, &lgpio->chip, lgpio);
 }
@@ -165,7 +176,6 @@ 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);
@@ -178,7 +188,7 @@ static int loongson_gpio_probe(struct platform_device *pdev)
 	if (IS_ERR(reg_base))
 		return PTR_ERR(reg_base);
 
-	return loongson_gpio_init(dev, lgpio, np, reg_base);
+	return loongson_gpio_init(dev, lgpio, reg_base);
 }
 
 static const struct loongson_gpio_chip_data loongson_gpio_ls2k_data = {
@@ -187,6 +197,57 @@ static const struct loongson_gpio_chip_data loongson_gpio_ls2k_data = {
 	.conf_offset = 0x0,
 	.in_offset = 0x20,
 	.out_offset = 0x10,
+	.inten_offset = 0x30,
+};
+
+static const struct loongson_gpio_chip_data loongson_gpio_ls2k0500_data0 = {
+	.label = "ls2k0500_gpio",
+	.mode = BIT_CTRL_MODE,
+	.conf_offset = 0x0,
+	.in_offset = 0x8,
+	.out_offset = 0x10,
+	.inten_offset = 0xb0,
+};
+
+static const struct loongson_gpio_chip_data loongson_gpio_ls2k0500_data1 = {
+	.label = "ls2k0500_gpio",
+	.mode = BIT_CTRL_MODE,
+	.conf_offset = 0x0,
+	.in_offset = 0x8,
+	.out_offset = 0x10,
+	.inten_offset = 0x98,
+};
+
+static const struct loongson_gpio_chip_data loongson_gpio_ls2k2000_data0 = {
+	.label = "ls2k2000_gpio",
+	.mode = BIT_CTRL_MODE,
+	.conf_offset = 0x0,
+	.in_offset = 0xc,
+	.out_offset = 0x8,
+};
+
+static const struct loongson_gpio_chip_data loongson_gpio_ls2k2000_data1 = {
+	.label = "ls2k2000_gpio",
+	.mode = BIT_CTRL_MODE,
+	.conf_offset = 0x0,
+	.in_offset = 0x20,
+	.out_offset = 0x10,
+};
+
+static const struct loongson_gpio_chip_data loongson_gpio_ls2k2000_data2 = {
+	.label = "ls2k2000_gpio",
+	.mode = BIT_CTRL_MODE,
+	.conf_offset = 0x84,
+	.in_offset = 0x88,
+	.out_offset = 0x80,
+};
+
+static const struct loongson_gpio_chip_data loongson_gpio_ls3a5000_data = {
+	.label = "ls3a5000_gpio",
+	.mode = BIT_CTRL_MODE,
+	.conf_offset = 0x0,
+	.in_offset = 0xc,
+	.out_offset = 0x8,
 };
 
 static const struct loongson_gpio_chip_data loongson_gpio_ls7a_data = {
@@ -202,6 +263,30 @@ static const struct of_device_id loongson_gpio_of_match[] = {
 		.compatible = "loongson,ls2k-gpio",
 		.data = &loongson_gpio_ls2k_data,
 	},
+	{
+		.compatible = "loongson,ls2k0500-gpio0",
+		.data = &loongson_gpio_ls2k0500_data0,
+	},
+	{
+		.compatible = "loongson,ls2k0500-gpio1",
+		.data = &loongson_gpio_ls2k0500_data1,
+	},
+	{
+		.compatible = "loongson,ls2k2000-gpio0",
+		.data = &loongson_gpio_ls2k2000_data0,
+	},
+	{
+		.compatible = "loongson,ls2k2000-gpio1",
+		.data = &loongson_gpio_ls2k2000_data1,
+	},
+	{
+		.compatible = "loongson,ls2k2000-gpio2",
+		.data = &loongson_gpio_ls2k2000_data2,
+	},
+	{
+		.compatible = "loongson,ls3a5000-gpio",
+		.data = &loongson_gpio_ls3a5000_data,
+	},
 	{
 		.compatible = "loongson,ls7a-gpio",
 		.data = &loongson_gpio_ls7a_data,
@@ -215,6 +300,22 @@ static const struct acpi_device_id loongson_gpio_acpi_match[] = {
 		.id = "LOON0002",
 		.driver_data = (kernel_ulong_t)&loongson_gpio_ls7a_data,
 	},
+	{
+		.id = "LOON0007",
+		.driver_data = (kernel_ulong_t)&loongson_gpio_ls3a5000_data,
+	},
+	{
+		.id = "LOON000A",
+		.driver_data = (kernel_ulong_t)&loongson_gpio_ls2k2000_data0,
+	},
+	{
+		.id = "LOON000B",
+		.driver_data = (kernel_ulong_t)&loongson_gpio_ls2k2000_data1,
+	},
+	{
+		.id = "LOON000C",
+		.driver_data = (kernel_ulong_t)&loongson_gpio_ls2k2000_data2,
+	},
 	{}
 };
 MODULE_DEVICE_TABLE(acpi, loongson_gpio_acpi_match);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v5 2/2] gpio: loongson: add more gpio chip support
  2023-08-29 12:35 ` [PATCH v5 2/2] gpio: loongson: add more " Yinbo Zhu
@ 2023-09-12  7:06   ` Linus Walleij
  2023-09-12  9:02   ` Bartosz Golaszewski
  1 sibling, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2023-09-12  7:06 UTC (permalink / raw)
  To: Yinbo Zhu
  Cc: Bartosz Golaszewski, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, linux-gpio, devicetree, linux-kernel, Jianmin Lv,
	wanghongliang, loongson-kernel

On Tue, Aug 29, 2023 at 2:35 PM Yinbo Zhu <zhuyinbo@loongson.cn> wrote:

> This patch was to add loongson 2k0500, 2k2000 and 3a5000 gpio chip
> driver support.
>
> Signed-off-by: Yinbo Zhu <zhuyinbo@loongson.cn>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v5 2/2] gpio: loongson: add more gpio chip support
  2023-08-29 12:35 ` [PATCH v5 2/2] gpio: loongson: add more " Yinbo Zhu
  2023-09-12  7:06   ` Linus Walleij
@ 2023-09-12  9:02   ` Bartosz Golaszewski
  2023-09-12 10:11     ` Yinbo Zhu
  1 sibling, 1 reply; 6+ messages in thread
From: Bartosz Golaszewski @ 2023-09-12  9:02 UTC (permalink / raw)
  To: Yinbo Zhu
  Cc: Linus Walleij, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	linux-gpio, devicetree, linux-kernel, Jianmin Lv, wanghongliang,
	loongson-kernel

On Tue, Aug 29, 2023 at 2:35 PM Yinbo Zhu <zhuyinbo@loongson.cn> wrote:
>
> This patch was to add loongson 2k0500, 2k2000 and 3a5000 gpio chip
> driver support.
>
> Signed-off-by: Yinbo Zhu <zhuyinbo@loongson.cn>
> ---
>  drivers/gpio/gpio-loongson-64bit.c | 125 ++++++++++++++++++++++++++---
>  1 file changed, 113 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/gpio/gpio-loongson-64bit.c b/drivers/gpio/gpio-loongson-64bit.c
> index 06213bbfabdd..2608f7eeba3b 100644
> --- a/drivers/gpio/gpio-loongson-64bit.c
> +++ b/drivers/gpio/gpio-loongson-64bit.c
> @@ -23,9 +23,10 @@ enum loongson_gpio_mode {
>  struct loongson_gpio_chip_data {
>         const char              *label;
>         enum loongson_gpio_mode mode;
> -       unsigned int            conf_offset;
> -       unsigned int            out_offset;
> -       unsigned int            in_offset;
> +       u32                     conf_offset;
> +       u32                     out_offset;
> +       u32                     in_offset;
> +       u32                     inten_offset;

Why are you doing this? If this change is needed, it warrants at least
a mention in the commit message.

Bart

>  };
>
>  struct loongson_gpio_chip {
> @@ -117,19 +118,29 @@ static void loongson_gpio_set(struct gpio_chip *chip, unsigned int pin, int valu
>
>  static int loongson_gpio_to_irq(struct gpio_chip *chip, unsigned int offset)
>  {
> +       unsigned int u;
>         struct platform_device *pdev = to_platform_device(chip->parent);
> +       struct loongson_gpio_chip *lgpio = to_loongson_gpio_chip(chip);
> +
> +       if (lgpio->chip_data->mode == BIT_CTRL_MODE) {
> +               /* Get the register index from offset then multiply by bytes per register */
> +               u = readl(lgpio->reg_base + lgpio->chip_data->inten_offset + (offset / 32) * 4);
> +               u |= BIT(offset % 32);
> +               writel(u, lgpio->reg_base + lgpio->chip_data->inten_offset + (offset / 32) * 4);
> +       } else {
> +               writeb(1, lgpio->reg_base + lgpio->chip_data->inten_offset + offset);
> +       }
>
>         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)
> +                             void __iomem *reg_base)
>  {
>         int ret;
>         u32 ngpios;
>
>         lgpio->reg_base = reg_base;
> -
>         if (lgpio->chip_data->mode == BIT_CTRL_MODE) {
>                 ret = bgpio_init(&lgpio->chip, dev, 8,
>                                 lgpio->reg_base + lgpio->chip_data->in_offset,
> @@ -148,15 +159,15 @@ static int loongson_gpio_init(struct device *dev, struct loongson_gpio_chip *lgp
>                 lgpio->chip.direction_output = loongson_gpio_direction_output;
>                 lgpio->chip.set = loongson_gpio_set;
>                 lgpio->chip.parent = dev;
> +               device_property_read_u32(dev, "ngpios", &ngpios);
> +               lgpio->chip.ngpio = ngpios;
>                 spin_lock_init(&lgpio->lock);
>         }
>
> -       device_property_read_u32(dev, "ngpios", &ngpios);
> -
> -       lgpio->chip.can_sleep = 0;
> -       lgpio->chip.ngpio = ngpios;
>         lgpio->chip.label = lgpio->chip_data->label;
> -       lgpio->chip.to_irq = loongson_gpio_to_irq;
> +       lgpio->chip.can_sleep = false;
> +       if (lgpio->chip_data->inten_offset)
> +               lgpio->chip.to_irq = loongson_gpio_to_irq;
>
>         return devm_gpiochip_add_data(dev, &lgpio->chip, lgpio);
>  }
> @@ -165,7 +176,6 @@ 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);
> @@ -178,7 +188,7 @@ static int loongson_gpio_probe(struct platform_device *pdev)
>         if (IS_ERR(reg_base))
>                 return PTR_ERR(reg_base);
>
> -       return loongson_gpio_init(dev, lgpio, np, reg_base);
> +       return loongson_gpio_init(dev, lgpio, reg_base);
>  }
>
>  static const struct loongson_gpio_chip_data loongson_gpio_ls2k_data = {
> @@ -187,6 +197,57 @@ static const struct loongson_gpio_chip_data loongson_gpio_ls2k_data = {
>         .conf_offset = 0x0,
>         .in_offset = 0x20,
>         .out_offset = 0x10,
> +       .inten_offset = 0x30,
> +};
> +
> +static const struct loongson_gpio_chip_data loongson_gpio_ls2k0500_data0 = {
> +       .label = "ls2k0500_gpio",
> +       .mode = BIT_CTRL_MODE,
> +       .conf_offset = 0x0,
> +       .in_offset = 0x8,
> +       .out_offset = 0x10,
> +       .inten_offset = 0xb0,
> +};
> +
> +static const struct loongson_gpio_chip_data loongson_gpio_ls2k0500_data1 = {
> +       .label = "ls2k0500_gpio",
> +       .mode = BIT_CTRL_MODE,
> +       .conf_offset = 0x0,
> +       .in_offset = 0x8,
> +       .out_offset = 0x10,
> +       .inten_offset = 0x98,
> +};
> +
> +static const struct loongson_gpio_chip_data loongson_gpio_ls2k2000_data0 = {
> +       .label = "ls2k2000_gpio",
> +       .mode = BIT_CTRL_MODE,
> +       .conf_offset = 0x0,
> +       .in_offset = 0xc,
> +       .out_offset = 0x8,
> +};
> +
> +static const struct loongson_gpio_chip_data loongson_gpio_ls2k2000_data1 = {
> +       .label = "ls2k2000_gpio",
> +       .mode = BIT_CTRL_MODE,
> +       .conf_offset = 0x0,
> +       .in_offset = 0x20,
> +       .out_offset = 0x10,
> +};
> +
> +static const struct loongson_gpio_chip_data loongson_gpio_ls2k2000_data2 = {
> +       .label = "ls2k2000_gpio",
> +       .mode = BIT_CTRL_MODE,
> +       .conf_offset = 0x84,
> +       .in_offset = 0x88,
> +       .out_offset = 0x80,
> +};
> +
> +static const struct loongson_gpio_chip_data loongson_gpio_ls3a5000_data = {
> +       .label = "ls3a5000_gpio",
> +       .mode = BIT_CTRL_MODE,
> +       .conf_offset = 0x0,
> +       .in_offset = 0xc,
> +       .out_offset = 0x8,
>  };
>
>  static const struct loongson_gpio_chip_data loongson_gpio_ls7a_data = {
> @@ -202,6 +263,30 @@ static const struct of_device_id loongson_gpio_of_match[] = {
>                 .compatible = "loongson,ls2k-gpio",
>                 .data = &loongson_gpio_ls2k_data,
>         },
> +       {
> +               .compatible = "loongson,ls2k0500-gpio0",
> +               .data = &loongson_gpio_ls2k0500_data0,
> +       },
> +       {
> +               .compatible = "loongson,ls2k0500-gpio1",
> +               .data = &loongson_gpio_ls2k0500_data1,
> +       },
> +       {
> +               .compatible = "loongson,ls2k2000-gpio0",
> +               .data = &loongson_gpio_ls2k2000_data0,
> +       },
> +       {
> +               .compatible = "loongson,ls2k2000-gpio1",
> +               .data = &loongson_gpio_ls2k2000_data1,
> +       },
> +       {
> +               .compatible = "loongson,ls2k2000-gpio2",
> +               .data = &loongson_gpio_ls2k2000_data2,
> +       },
> +       {
> +               .compatible = "loongson,ls3a5000-gpio",
> +               .data = &loongson_gpio_ls3a5000_data,
> +       },
>         {
>                 .compatible = "loongson,ls7a-gpio",
>                 .data = &loongson_gpio_ls7a_data,
> @@ -215,6 +300,22 @@ static const struct acpi_device_id loongson_gpio_acpi_match[] = {
>                 .id = "LOON0002",
>                 .driver_data = (kernel_ulong_t)&loongson_gpio_ls7a_data,
>         },
> +       {
> +               .id = "LOON0007",
> +               .driver_data = (kernel_ulong_t)&loongson_gpio_ls3a5000_data,
> +       },
> +       {
> +               .id = "LOON000A",
> +               .driver_data = (kernel_ulong_t)&loongson_gpio_ls2k2000_data0,
> +       },
> +       {
> +               .id = "LOON000B",
> +               .driver_data = (kernel_ulong_t)&loongson_gpio_ls2k2000_data1,
> +       },
> +       {
> +               .id = "LOON000C",
> +               .driver_data = (kernel_ulong_t)&loongson_gpio_ls2k2000_data2,
> +       },
>         {}
>  };
>  MODULE_DEVICE_TABLE(acpi, loongson_gpio_acpi_match);
> --
> 2.20.1
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v5 2/2] gpio: loongson: add more gpio chip support
  2023-09-12  9:02   ` Bartosz Golaszewski
@ 2023-09-12 10:11     ` Yinbo Zhu
  0 siblings, 0 replies; 6+ messages in thread
From: Yinbo Zhu @ 2023-09-12 10:11 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Linus Walleij, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	linux-gpio, devicetree, linux-kernel, Jianmin Lv, wanghongliang,
	loongson-kernel, zhuyinbo



在 2023/9/12 下午5:02, Bartosz Golaszewski 写道:
> On Tue, Aug 29, 2023 at 2:35 PM Yinbo Zhu <zhuyinbo@loongson.cn> wrote:
>>
>> This patch was to add loongson 2k0500, 2k2000 and 3a5000 gpio chip
>> driver support.
>>
>> Signed-off-by: Yinbo Zhu <zhuyinbo@loongson.cn>
>> ---
>>   drivers/gpio/gpio-loongson-64bit.c | 125 ++++++++++++++++++++++++++---
>>   1 file changed, 113 insertions(+), 12 deletions(-)
>>
>> diff --git a/drivers/gpio/gpio-loongson-64bit.c b/drivers/gpio/gpio-loongson-64bit.c
>> index 06213bbfabdd..2608f7eeba3b 100644
>> --- a/drivers/gpio/gpio-loongson-64bit.c
>> +++ b/drivers/gpio/gpio-loongson-64bit.c
>> @@ -23,9 +23,10 @@ enum loongson_gpio_mode {
>>   struct loongson_gpio_chip_data {
>>          const char              *label;
>>          enum loongson_gpio_mode mode;
>> -       unsigned int            conf_offset;
>> -       unsigned int            out_offset;
>> -       unsigned int            in_offset;
>> +       u32                     conf_offset;
>> +       u32                     out_offset;
>> +       u32                     in_offset;
>> +       u32                     inten_offset;
> 
> Why are you doing this? If this change is needed, it warrants at least
> a mention in the commit message.


Hi Bart,

These changes include add "inten_offset" and use use "u32" replaced
"unsigned int", which type change was due to v3 has following code,

but, in v5 gpio patch, no following code, so no need type change.

104 +       if (device_property_read_u32(dev, 
"loongson,gpio-conf-offset", (u32 *)&d->conf_offset)
105 +           || device_property_read_u32(dev, 
"loongson,gpio-in-offset", (u32 *)&d->in_offset)
106 +           || device_property_read_u32(dev, 
"loongson,gpio-out-offset", (u32 *)&d->out_offset)
107 +           || device_property_read_u32(dev, 
"loongson,gpio-ctrl-mode", (u32 *)&d->mode))


I will add following change in v6.

--- a/drivers/gpio/gpio-loongson-64bit.c
+++ b/drivers/gpio/gpio-loongson-64bit.c
@@ -26,6 +26,7 @@ struct loongson_gpio_chip_data {
         unsigned int            conf_offset;
         unsigned int            out_offset;
         unsigned int            in_offset;
+       unsigned int            inten_offset;
  };


Change the commit log to the following:

This patch was to add loongson 2k0500, 2k2000 and 3a5000 gpio chip
driver support and define inten_offset attribute to enable gpio chip
interrupt.

Thanks,
Yinbo

> 
>>   };
>>
>>   struct loongson_gpio_chip {
>> @@ -117,19 +118,29 @@ static void loongson_gpio_set(struct gpio_chip *chip, unsigned int pin, int valu
>>
>>   static int loongson_gpio_to_irq(struct gpio_chip *chip, unsigned int offset)
>>   {
>> +       unsigned int u;
>>          struct platform_device *pdev = to_platform_device(chip->parent);
>> +       struct loongson_gpio_chip *lgpio = to_loongson_gpio_chip(chip);
>> +
>> +       if (lgpio->chip_data->mode == BIT_CTRL_MODE) {
>> +               /* Get the register index from offset then multiply by bytes per register */
>> +               u = readl(lgpio->reg_base + lgpio->chip_data->inten_offset + (offset / 32) * 4);
>> +               u |= BIT(offset % 32);
>> +               writel(u, lgpio->reg_base + lgpio->chip_data->inten_offset + (offset / 32) * 4);
>> +       } else {
>> +               writeb(1, lgpio->reg_base + lgpio->chip_data->inten_offset + offset);
>> +       }
>>
>>          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)
>> +                             void __iomem *reg_base)
>>   {
>>          int ret;
>>          u32 ngpios;
>>
>>          lgpio->reg_base = reg_base;
>> -
>>          if (lgpio->chip_data->mode == BIT_CTRL_MODE) {
>>                  ret = bgpio_init(&lgpio->chip, dev, 8,
>>                                  lgpio->reg_base + lgpio->chip_data->in_offset,
>> @@ -148,15 +159,15 @@ static int loongson_gpio_init(struct device *dev, struct loongson_gpio_chip *lgp
>>                  lgpio->chip.direction_output = loongson_gpio_direction_output;
>>                  lgpio->chip.set = loongson_gpio_set;
>>                  lgpio->chip.parent = dev;
>> +               device_property_read_u32(dev, "ngpios", &ngpios);
>> +               lgpio->chip.ngpio = ngpios;
>>                  spin_lock_init(&lgpio->lock);
>>          }
>>
>> -       device_property_read_u32(dev, "ngpios", &ngpios);
>> -
>> -       lgpio->chip.can_sleep = 0;
>> -       lgpio->chip.ngpio = ngpios;
>>          lgpio->chip.label = lgpio->chip_data->label;
>> -       lgpio->chip.to_irq = loongson_gpio_to_irq;
>> +       lgpio->chip.can_sleep = false;
>> +       if (lgpio->chip_data->inten_offset)
>> +               lgpio->chip.to_irq = loongson_gpio_to_irq;
>>
>>          return devm_gpiochip_add_data(dev, &lgpio->chip, lgpio);
>>   }
>> @@ -165,7 +176,6 @@ 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);
>> @@ -178,7 +188,7 @@ static int loongson_gpio_probe(struct platform_device *pdev)
>>          if (IS_ERR(reg_base))
>>                  return PTR_ERR(reg_base);
>>
>> -       return loongson_gpio_init(dev, lgpio, np, reg_base);
>> +       return loongson_gpio_init(dev, lgpio, reg_base);
>>   }
>>
>>   static const struct loongson_gpio_chip_data loongson_gpio_ls2k_data = {
>> @@ -187,6 +197,57 @@ static const struct loongson_gpio_chip_data loongson_gpio_ls2k_data = {
>>          .conf_offset = 0x0,
>>          .in_offset = 0x20,
>>          .out_offset = 0x10,
>> +       .inten_offset = 0x30,
>> +};
>> +
>> +static const struct loongson_gpio_chip_data loongson_gpio_ls2k0500_data0 = {
>> +       .label = "ls2k0500_gpio",
>> +       .mode = BIT_CTRL_MODE,
>> +       .conf_offset = 0x0,
>> +       .in_offset = 0x8,
>> +       .out_offset = 0x10,
>> +       .inten_offset = 0xb0,
>> +};
>> +
>> +static const struct loongson_gpio_chip_data loongson_gpio_ls2k0500_data1 = {
>> +       .label = "ls2k0500_gpio",
>> +       .mode = BIT_CTRL_MODE,
>> +       .conf_offset = 0x0,
>> +       .in_offset = 0x8,
>> +       .out_offset = 0x10,
>> +       .inten_offset = 0x98,
>> +};
>> +
>> +static const struct loongson_gpio_chip_data loongson_gpio_ls2k2000_data0 = {
>> +       .label = "ls2k2000_gpio",
>> +       .mode = BIT_CTRL_MODE,
>> +       .conf_offset = 0x0,
>> +       .in_offset = 0xc,
>> +       .out_offset = 0x8,
>> +};
>> +
>> +static const struct loongson_gpio_chip_data loongson_gpio_ls2k2000_data1 = {
>> +       .label = "ls2k2000_gpio",
>> +       .mode = BIT_CTRL_MODE,
>> +       .conf_offset = 0x0,
>> +       .in_offset = 0x20,
>> +       .out_offset = 0x10,
>> +};
>> +
>> +static const struct loongson_gpio_chip_data loongson_gpio_ls2k2000_data2 = {
>> +       .label = "ls2k2000_gpio",
>> +       .mode = BIT_CTRL_MODE,
>> +       .conf_offset = 0x84,
>> +       .in_offset = 0x88,
>> +       .out_offset = 0x80,
>> +};
>> +
>> +static const struct loongson_gpio_chip_data loongson_gpio_ls3a5000_data = {
>> +       .label = "ls3a5000_gpio",
>> +       .mode = BIT_CTRL_MODE,
>> +       .conf_offset = 0x0,
>> +       .in_offset = 0xc,
>> +       .out_offset = 0x8,
>>   };
>>
>>   static const struct loongson_gpio_chip_data loongson_gpio_ls7a_data = {
>> @@ -202,6 +263,30 @@ static const struct of_device_id loongson_gpio_of_match[] = {
>>                  .compatible = "loongson,ls2k-gpio",
>>                  .data = &loongson_gpio_ls2k_data,
>>          },
>> +       {
>> +               .compatible = "loongson,ls2k0500-gpio0",
>> +               .data = &loongson_gpio_ls2k0500_data0,
>> +       },
>> +       {
>> +               .compatible = "loongson,ls2k0500-gpio1",
>> +               .data = &loongson_gpio_ls2k0500_data1,
>> +       },
>> +       {
>> +               .compatible = "loongson,ls2k2000-gpio0",
>> +               .data = &loongson_gpio_ls2k2000_data0,
>> +       },
>> +       {
>> +               .compatible = "loongson,ls2k2000-gpio1",
>> +               .data = &loongson_gpio_ls2k2000_data1,
>> +       },
>> +       {
>> +               .compatible = "loongson,ls2k2000-gpio2",
>> +               .data = &loongson_gpio_ls2k2000_data2,
>> +       },
>> +       {
>> +               .compatible = "loongson,ls3a5000-gpio",
>> +               .data = &loongson_gpio_ls3a5000_data,
>> +       },
>>          {
>>                  .compatible = "loongson,ls7a-gpio",
>>                  .data = &loongson_gpio_ls7a_data,
>> @@ -215,6 +300,22 @@ static const struct acpi_device_id loongson_gpio_acpi_match[] = {
>>                  .id = "LOON0002",
>>                  .driver_data = (kernel_ulong_t)&loongson_gpio_ls7a_data,
>>          },
>> +       {
>> +               .id = "LOON0007",
>> +               .driver_data = (kernel_ulong_t)&loongson_gpio_ls3a5000_data,
>> +       },
>> +       {
>> +               .id = "LOON000A",
>> +               .driver_data = (kernel_ulong_t)&loongson_gpio_ls2k2000_data0,
>> +       },
>> +       {
>> +               .id = "LOON000B",
>> +               .driver_data = (kernel_ulong_t)&loongson_gpio_ls2k2000_data1,
>> +       },
>> +       {
>> +               .id = "LOON000C",
>> +               .driver_data = (kernel_ulong_t)&loongson_gpio_ls2k2000_data2,
>> +       },
>>          {}
>>   };
>>   MODULE_DEVICE_TABLE(acpi, loongson_gpio_acpi_match);
>> --
>> 2.20.1
>>


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-09-12 10:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-29 12:35 [PATCH v5 0/2] gpio: loongson: add more gpio chip support Yinbo Zhu
2023-08-29 12:35 ` [PATCH v5 1/2] gpio: dt-bindings: add more loongson " Yinbo Zhu
2023-08-29 12:35 ` [PATCH v5 2/2] gpio: loongson: add more " Yinbo Zhu
2023-09-12  7:06   ` Linus Walleij
2023-09-12  9:02   ` Bartosz Golaszewski
2023-09-12 10:11     ` 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.