gpio: Add gpio alias support
PATCH 1/1 gpio: Add gpio alias support
From: Haibo Chen <[email protected]>
This patch allow setting gpio device id via device tree alias.
--- drivers/gpio/gpiolib.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/gpio/gpiolib.c +16 -6
@@ -495,7 +495,7 @@ static void gpiodevice_release(struct device *dev)list_del (&gdev->list);spin_unlock_irqrestore (&gpio_lock, flags); -ida_free (&gpio_ida, gdev->id); +ida_simple_remove (&gpio_ida, gdev->id);kfree_const (gdev->label);kfree (gdev->descs);kfree (gdev);
@@ -594,6 +594,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,unsigned long flags;int base = gc->base;unsigned int i; +int alias_id, first_dynamic;int ret =0 ;u32 ngpios;
@@ -623,11 +624,20 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,*/ gdev->dev.fwnode =dev_fwnode (&gdev->dev) ?: fwnode; - gdev->id =ida_alloc (&gpio_ida,GFP_KERNEL ); -if (gdev->id <0 ) { - ret = gdev->id; - goto err_free_gdev; + alias_id =of_alias_get_id (gdev->dev.of_node,"gpio" ); +if (alias_id <0 ) { + first_dynamic =of_alias_get_highest_id ("gpio" ); +if (first_dynamic <0 ) + first_dynamic =0 ; +else + first_dynamic++; + alias_id =ida_simple_get (&gpio_ida, first_dynamic,0 ,GFP_KERNEL ); +if (alias_id <0 ) { + ret = alias_id; + goto err_free_gdev; + } } + gdev->id = alias_id; ret =dev_set_name (&gdev->dev,GPIOCHIP_NAME "%d" , gdev->id);if (ret)
@@ -821,7 +831,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, err_free_dev_name:kfree (dev_name (&gdev->dev)); err_free_ida: -ida_free (&gpio_ida, gdev->id); +ida_simple_remove (&gpio_ida, gdev->id); err_free_gdev:/* failures here can mean systems won't boot... */ if (ret != -EPROBE_DEFER ) {
Signature · 1 line
2.25.1
Quoted 4 lines · On Mon, Mar 21, 2022 at 11:22 AM <[email protected]> wrote:
From: Haibo Chen <[email protected]>
This patch allow setting gpio device id via device tree alias.
allows
But read the Submitting Patches document about imperative mode.
Moreover, this commit message is quite bad. Please, read [1] for making your commit messages meaningful and useful.
[1]: https://cbea.ms/git-commit/
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 15 lines
-----Original Message-----
From: Andy Shevchenko [mailto:[email protected]]
Sent: 2022年3月22日 0:41
To: Bough Chen <[email protected]>
Cc: Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; open list:GPIO SUBSYSTEM <[email protected]>; Linux Kernel Mailing List <[email protected]>; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] gpio: Add gpio alias supportQuoted 3 lines · On Mon, Mar 21, 2022 at 11:22 AM <[email protected]> wrote:
From: Haibo Chen <[email protected]>
Quoted 7 lines
Quoted 1 line
This patch allow setting gpio device id via device tree alias.
allows
But read the Submitting Patches document about imperative mode.
Moreover, this commit message is quite bad. Please, read [1] for making
your
Quoted 1 line
commit messages meaningful and useful.
Thanks for your suggestion, I will add some info to explain why I involve this change,
and the benefit of this patch.
Best Regards
Haibo Chen
Quoted 13 lines
[1]:
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcbea.m
s%2Fgit-commit%2F&data=04%7C01%7Chaibo.chen%40nxp.com%7C365 e24600aee43b3310508da0b59c5b3%7C686ea1d3bc2b4c6fa92cd99c5c301635 %7C0%7C0%7C637834777437333289%7CUnknown%7CTWFpbGZsb3d8eyJWIj oiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C30 00&sdata=JuJrBC1M079h5%2Bpc3i10eVqpL%2BXJLd4rt%2BjSPeIys4U%3 D&reserved=0--
With Best Regards,
Andy Shevchenko