* [PATCH v2] gpio: set device type for GPIO chips
@ 2024-02-05 10:08 Bartosz Golaszewski
2024-02-07 13:50 ` Greg KH
2024-02-08 9:38 ` Bartosz Golaszewski
0 siblings, 2 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2024-02-05 10:08 UTC (permalink / raw)
To: Linus Walleij, Ricardo B . Marliere
Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
It's useful to have the device type information for those sub-devices
that are actually GPIO chips registered with GPIOLIB. While at it: use
the device type struct to setup the release callback which is the
preferred way to use the device API.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
v1-> v2:
- make struct device_type constant
drivers/gpio/gpiolib.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index d52b340562ce..caec861cfa5d 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -663,6 +663,11 @@ static void gpiodev_release(struct device *dev)
kfree(gdev);
}
+static const struct device_type gpio_dev_type = {
+ .name = "gpio_chip",
+ .release = gpiodev_release,
+};
+
#ifdef CONFIG_GPIO_CDEV
#define gcdev_register(gdev, devt) gpiolib_cdev_register((gdev), (devt))
#define gcdev_unregister(gdev) gpiolib_cdev_unregister((gdev))
@@ -680,6 +685,8 @@ static int gpiochip_setup_dev(struct gpio_device *gdev)
struct fwnode_handle *fwnode = dev_fwnode(&gdev->dev);
int ret;
+ device_initialize(&gdev->dev);
+
/*
* If fwnode doesn't belong to another device, it's safe to clear its
* initialized flag.
@@ -691,9 +698,6 @@ static int gpiochip_setup_dev(struct gpio_device *gdev)
if (ret)
return ret;
- /* From this point, the .release() function cleans up gpio_device */
- gdev->dev.release = gpiodev_release;
-
ret = gpiochip_sysfs_register(gdev);
if (ret)
goto err_remove_device;
@@ -825,6 +829,8 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
gdev = kzalloc(sizeof(*gdev), GFP_KERNEL);
if (!gdev)
return -ENOMEM;
+
+ gdev->dev.type = &gpio_dev_type;
gdev->dev.bus = &gpio_bus_type;
gdev->dev.parent = gc->parent;
gdev->chip = gc;
@@ -851,7 +857,6 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
if (ret)
goto err_free_ida;
- device_initialize(&gdev->dev);
if (gc->parent && gc->parent->driver)
gdev->owner = gc->parent->driver->owner;
else if (gc->owner)
--
2.40.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] gpio: set device type for GPIO chips
2024-02-05 10:08 [PATCH v2] gpio: set device type for GPIO chips Bartosz Golaszewski
@ 2024-02-07 13:50 ` Greg KH
2024-02-08 9:38 ` Bartosz Golaszewski
1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2024-02-07 13:50 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linus Walleij, Ricardo B . Marliere, linux-gpio, linux-kernel,
Bartosz Golaszewski
On Mon, Feb 05, 2024 at 11:08:11AM +0100, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> It's useful to have the device type information for those sub-devices
> that are actually GPIO chips registered with GPIOLIB. While at it: use
> the device type struct to setup the release callback which is the
> preferred way to use the device API.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] gpio: set device type for GPIO chips
2024-02-05 10:08 [PATCH v2] gpio: set device type for GPIO chips Bartosz Golaszewski
2024-02-07 13:50 ` Greg KH
@ 2024-02-08 9:38 ` Bartosz Golaszewski
1 sibling, 0 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2024-02-08 9:38 UTC (permalink / raw)
To: Linus Walleij, Ricardo B . Marliere
Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
On Mon, Feb 5, 2024 at 11:08 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> It's useful to have the device type information for those sub-devices
> that are actually GPIO chips registered with GPIOLIB. While at it: use
> the device type struct to setup the release callback which is the
> preferred way to use the device API.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---
Patch applied.
Bart
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-02-08 9:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-05 10:08 [PATCH v2] gpio: set device type for GPIO chips Bartosz Golaszewski
2024-02-07 13:50 ` Greg KH
2024-02-08 9:38 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox