linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Linus Walleij <linus.walleij@linaro.org>,
	 Bartosz Golaszewski <brgl@bgdev.pl>,
	Yinbo Zhu <zhuyinbo@loongson.cn>,
	 Hoan Tran <hoan@os.amperecomputing.com>,
	 Manivannan Sadhasivam <mani@kernel.org>,
	Yang Shen <shenyang39@huawei.com>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-arm-kernel@lists.infradead.org,
	linux-unisoc@lists.infradead.org,
	 Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: [PATCH RESEND 08/14] gpio: loongson-64bit: use new generic GPIO chip API
Date: Tue, 12 Aug 2025 14:12:50 +0200	[thread overview]
Message-ID: <20250812-gpio-mmio-gpio-conv-v1-8-aac41d656979@linaro.org> (raw)
In-Reply-To: <20250812-gpio-mmio-gpio-conv-v1-0-aac41d656979@linaro.org>

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Convert the driver to using the new generic GPIO chip interfaces from
linux/gpio/generic.h.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/gpio/gpio-loongson-64bit.c | 42 ++++++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 18 deletions(-)

diff --git a/drivers/gpio/gpio-loongson-64bit.c b/drivers/gpio/gpio-loongson-64bit.c
index 818c606fbc5149b2e4274f0776e558332700d916..482e64ba9b4209443c2f64ae7426b8fa9034011a 100644
--- a/drivers/gpio/gpio-loongson-64bit.c
+++ b/drivers/gpio/gpio-loongson-64bit.c
@@ -11,6 +11,7 @@
 #include <linux/spinlock.h>
 #include <linux/err.h>
 #include <linux/gpio/driver.h>
+#include <linux/gpio/generic.h>
 #include <linux/platform_device.h>
 #include <linux/bitops.h>
 #include <asm/types.h>
@@ -30,7 +31,7 @@ struct loongson_gpio_chip_data {
 };
 
 struct loongson_gpio_chip {
-	struct gpio_chip	chip;
+	struct gpio_generic_chip chip;
 	spinlock_t		lock;
 	void __iomem		*reg_base;
 	const struct loongson_gpio_chip_data *chip_data;
@@ -38,7 +39,8 @@ struct loongson_gpio_chip {
 
 static inline struct loongson_gpio_chip *to_loongson_gpio_chip(struct gpio_chip *chip)
 {
-	return container_of(chip, struct loongson_gpio_chip, chip);
+	return container_of(to_gpio_generic_chip(chip),
+			    struct loongson_gpio_chip, chip);
 }
 
 static inline void loongson_commit_direction(struct loongson_gpio_chip *lgpio, unsigned int pin,
@@ -138,36 +140,40 @@ static int loongson_gpio_to_irq(struct gpio_chip *chip, unsigned int offset)
 static int loongson_gpio_init(struct device *dev, struct loongson_gpio_chip *lgpio,
 			      void __iomem *reg_base)
 {
+	struct gpio_generic_chip_config config;
 	int ret;
 
 	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,
-				lgpio->reg_base + lgpio->chip_data->out_offset,
-				NULL, NULL,
-				lgpio->reg_base + lgpio->chip_data->conf_offset,
-				0);
+		config = (typeof(config)){
+			.dev = dev,
+			.sz = 8,
+			.dat = lgpio->reg_base + lgpio->chip_data->in_offset,
+			.set = lgpio->reg_base + lgpio->chip_data->out_offset,
+			.dirin = lgpio->reg_base + lgpio->chip_data->conf_offset,
+		};
+
+		ret = gpio_generic_chip_init(&lgpio->chip, &config);
 		if (ret) {
 			dev_err(dev, "unable to init generic GPIO\n");
 			return ret;
 		}
 	} else {
-		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.parent = dev;
+		lgpio->chip.gc.direction_input = loongson_gpio_direction_input;
+		lgpio->chip.gc.get = loongson_gpio_get;
+		lgpio->chip.gc.get_direction = loongson_gpio_get_direction;
+		lgpio->chip.gc.direction_output = loongson_gpio_direction_output;
+		lgpio->chip.gc.set = loongson_gpio_set;
+		lgpio->chip.gc.parent = dev;
 		spin_lock_init(&lgpio->lock);
 	}
 
-	lgpio->chip.label = lgpio->chip_data->label;
-	lgpio->chip.can_sleep = false;
+	lgpio->chip.gc.label = lgpio->chip_data->label;
+	lgpio->chip.gc.can_sleep = false;
 	if (lgpio->chip_data->inten_offset)
-		lgpio->chip.to_irq = loongson_gpio_to_irq;
+		lgpio->chip.gc.to_irq = loongson_gpio_to_irq;
 
-	return devm_gpiochip_add_data(dev, &lgpio->chip, lgpio);
+	return devm_gpiochip_add_data(dev, &lgpio->chip.gc, lgpio);
 }
 
 static int loongson_gpio_probe(struct platform_device *pdev)

-- 
2.48.1


  parent reply	other threads:[~2025-08-12 12:13 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-12 12:12 [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
2025-08-12 12:12 ` [PATCH RESEND 01/14] gpio: generic: provide to_gpio_generic_chip() Bartosz Golaszewski
2025-08-12 12:12 ` [PATCH RESEND 02/14] gpio: generic: provide helpers for reading and writing registers Bartosz Golaszewski
2025-08-12 12:12 ` [PATCH RESEND 03/14] gpio: hisi: use the BGPIOF_UNREADABLE_REG_DIR flag Bartosz Golaszewski
2025-08-12 12:12 ` [PATCH RESEND 04/14] gpio: ts4800: remove the unnecessary call to platform_set_drvdata() Bartosz Golaszewski
2025-08-12 12:12 ` [PATCH RESEND 05/14] gpio: ts4800: use generic device properties Bartosz Golaszewski
2025-08-12 12:12 ` [PATCH RESEND 06/14] gpio: ts4800: use dev_err_probe() Bartosz Golaszewski
2025-08-12 12:12 ` [PATCH RESEND 07/14] gpio: ts4800: use new generic GPIO chip API Bartosz Golaszewski
2025-08-12 12:12 ` Bartosz Golaszewski [this message]
2025-08-12 12:12 ` [PATCH RESEND 09/14] gpio: dwapb: " Bartosz Golaszewski
2025-08-12 12:12 ` [PATCH RESEND 10/14] gpio: amdpt: " Bartosz Golaszewski
2025-08-12 12:12 ` [PATCH RESEND 11/14] gpio: rda: " Bartosz Golaszewski
2025-08-12 12:12 ` [PATCH RESEND 12/14] gpio: grgpio: " Bartosz Golaszewski
2025-08-12 12:12 ` [PATCH RESEND 13/14] gpio: mpc8xxx: " Bartosz Golaszewski
2025-08-12 12:12 ` [PATCH RESEND 14/14] gpio: ge: " Bartosz Golaszewski
2025-08-12 12:14 ` [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
2025-08-19 11:18 ` Linus Walleij
  -- strict thread matches above, loose matches on Subject: below --
2025-08-25  9:48 Bartosz Golaszewski
2025-08-25  9:48 ` [PATCH RESEND 08/14] gpio: loongson-64bit: use new generic GPIO chip API Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250812-gpio-mmio-gpio-conv-v1-8-aac41d656979@linaro.org \
    --to=brgl@bgdev.pl \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=hoan@os.amperecomputing.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-unisoc@lists.infradead.org \
    --cc=mani@kernel.org \
    --cc=shenyang39@huawei.com \
    --cc=zhuyinbo@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).