diff mbox series

[v2,03/10] gpio: raspberrypi-exp: Release firmware handle on unbind

Message ID 20201022155858.20867-4-nsaenzjulienne@suse.de (mailing list archive)
State Superseded
Headers show
Series Raspberry Pi PoE HAT fan support | expand

Commit Message

Nicolas Saenz Julienne Oct. 22, 2020, 3:58 p.m. UTC
Upon unbinding the device make sure we release RPi's firmware interface.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
---
 drivers/gpio/gpio-raspberrypi-exp.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

Comments

Bartosz Golaszewski Oct. 26, 2020, 2:40 p.m. UTC | #1
On Thu, Oct 22, 2020 at 5:59 PM Nicolas Saenz Julienne
<nsaenzjulienne@suse.de> wrote:
>
> Upon unbinding the device make sure we release RPi's firmware interface.
>
> Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> ---
>  drivers/gpio/gpio-raspberrypi-exp.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpio-raspberrypi-exp.c b/drivers/gpio/gpio-raspberrypi-exp.c
> index bb100e0124e6..c008336e1131 100644
> --- a/drivers/gpio/gpio-raspberrypi-exp.c
> +++ b/drivers/gpio/gpio-raspberrypi-exp.c
> @@ -231,8 +231,19 @@ static int rpi_exp_gpio_probe(struct platform_device *pdev)
>         rpi_gpio->gc.get = rpi_exp_gpio_get;
>         rpi_gpio->gc.set = rpi_exp_gpio_set;
>         rpi_gpio->gc.can_sleep = true;
> +       platform_set_drvdata(pdev, rpi_gpio);
>
> -       return devm_gpiochip_add_data(dev, &rpi_gpio->gc, rpi_gpio);
> +       return gpiochip_add_data(&rpi_gpio->gc, rpi_gpio);
> +}
> +
> +static int rpi_exp_gpio_remove(struct platform_device *pdev)
> +{
> +       struct rpi_exp_gpio *rpi_gpio = platform_get_drvdata(pdev);
> +
> +       gpiochip_remove(&rpi_gpio->gc);
> +       rpi_firmware_put(rpi_gpio->fw);
> +
> +       return 0;
>  }
>
>  static const struct of_device_id rpi_exp_gpio_ids[] = {
> @@ -247,6 +258,7 @@ static struct platform_driver rpi_exp_gpio_driver = {
>                 .of_match_table = of_match_ptr(rpi_exp_gpio_ids),
>         },
>         .probe  = rpi_exp_gpio_probe,
> +       .remove = rpi_exp_gpio_remove,
>  };
>  module_platform_driver(rpi_exp_gpio_driver);
>
> --
> 2.28.0
>

Why not introduce devm_rpi_firmware_get()? That would allow you to
keep the driver elegant without re-adding remove().

Bartosz
Nicolas Saenz Julienne Oct. 26, 2020, 2:42 p.m. UTC | #2
On Mon, 2020-10-26 at 15:40 +0100, Bartosz Golaszewski wrote:
> On Thu, Oct 22, 2020 at 5:59 PM Nicolas Saenz Julienne
> <nsaenzjulienne@suse.de> wrote:
> > Upon unbinding the device make sure we release RPi's firmware interface.
> > 
> > Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> > ---
> >  drivers/gpio/gpio-raspberrypi-exp.c | 14 +++++++++++++-
> >  1 file changed, 13 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/gpio/gpio-raspberrypi-exp.c b/drivers/gpio/gpio-raspberrypi-exp.c
> > index bb100e0124e6..c008336e1131 100644
> > --- a/drivers/gpio/gpio-raspberrypi-exp.c
> > +++ b/drivers/gpio/gpio-raspberrypi-exp.c
> > @@ -231,8 +231,19 @@ static int rpi_exp_gpio_probe(struct platform_device *pdev)
> >         rpi_gpio->gc.get = rpi_exp_gpio_get;
> >         rpi_gpio->gc.set = rpi_exp_gpio_set;
> >         rpi_gpio->gc.can_sleep = true;
> > +       platform_set_drvdata(pdev, rpi_gpio);
> > 
> > -       return devm_gpiochip_add_data(dev, &rpi_gpio->gc, rpi_gpio);
> > +       return gpiochip_add_data(&rpi_gpio->gc, rpi_gpio);
> > +}
> > +
> > +static int rpi_exp_gpio_remove(struct platform_device *pdev)
> > +{
> > +       struct rpi_exp_gpio *rpi_gpio = platform_get_drvdata(pdev);
> > +
> > +       gpiochip_remove(&rpi_gpio->gc);
> > +       rpi_firmware_put(rpi_gpio->fw);
> > +
> > +       return 0;
> >  }
> > 
> >  static const struct of_device_id rpi_exp_gpio_ids[] = {
> > @@ -247,6 +258,7 @@ static struct platform_driver rpi_exp_gpio_driver = {
> >                 .of_match_table = of_match_ptr(rpi_exp_gpio_ids),
> >         },
> >         .probe  = rpi_exp_gpio_probe,
> > +       .remove = rpi_exp_gpio_remove,
> >  };
> >  module_platform_driver(rpi_exp_gpio_driver);
> > 
> > --
> > 2.28.0
> > 
> 
> Why not introduce devm_rpi_firmware_get()? That would allow you to
> keep the driver elegant without re-adding remove().

I like the idea, I'll look into it.

Thanks,
Nicolas
Bartosz Golaszewski Oct. 26, 2020, 2:45 p.m. UTC | #3
On Mon, Oct 26, 2020 at 3:42 PM Nicolas Saenz Julienne
<nsaenzjulienne@suse.de> wrote:
>
> On Mon, 2020-10-26 at 15:40 +0100, Bartosz Golaszewski wrote:
> > On Thu, Oct 22, 2020 at 5:59 PM Nicolas Saenz Julienne
> > <nsaenzjulienne@suse.de> wrote:
> > > Upon unbinding the device make sure we release RPi's firmware interface.
> > >
> > > Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> > > ---
> > >  drivers/gpio/gpio-raspberrypi-exp.c | 14 +++++++++++++-
> > >  1 file changed, 13 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/gpio/gpio-raspberrypi-exp.c b/drivers/gpio/gpio-raspberrypi-exp.c
> > > index bb100e0124e6..c008336e1131 100644
> > > --- a/drivers/gpio/gpio-raspberrypi-exp.c
> > > +++ b/drivers/gpio/gpio-raspberrypi-exp.c
> > > @@ -231,8 +231,19 @@ static int rpi_exp_gpio_probe(struct platform_device *pdev)
> > >         rpi_gpio->gc.get = rpi_exp_gpio_get;
> > >         rpi_gpio->gc.set = rpi_exp_gpio_set;
> > >         rpi_gpio->gc.can_sleep = true;
> > > +       platform_set_drvdata(pdev, rpi_gpio);
> > >
> > > -       return devm_gpiochip_add_data(dev, &rpi_gpio->gc, rpi_gpio);
> > > +       return gpiochip_add_data(&rpi_gpio->gc, rpi_gpio);
> > > +}
> > > +
> > > +static int rpi_exp_gpio_remove(struct platform_device *pdev)
> > > +{
> > > +       struct rpi_exp_gpio *rpi_gpio = platform_get_drvdata(pdev);
> > > +
> > > +       gpiochip_remove(&rpi_gpio->gc);
> > > +       rpi_firmware_put(rpi_gpio->fw);
> > > +
> > > +       return 0;
> > >  }
> > >
> > >  static const struct of_device_id rpi_exp_gpio_ids[] = {
> > > @@ -247,6 +258,7 @@ static struct platform_driver rpi_exp_gpio_driver = {
> > >                 .of_match_table = of_match_ptr(rpi_exp_gpio_ids),
> > >         },
> > >         .probe  = rpi_exp_gpio_probe,
> > > +       .remove = rpi_exp_gpio_remove,
> > >  };
> > >  module_platform_driver(rpi_exp_gpio_driver);
> > >
> > > --
> > > 2.28.0
> > >
> >
> > Why not introduce devm_rpi_firmware_get()? That would allow you to
> > keep the driver elegant without re-adding remove().
>
> I like the idea, I'll look into it.
>
> Thanks,
> Nicolas
>

If you can't do it for some reason, then even using devm_add_action() is fine.

Bartosz
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-raspberrypi-exp.c b/drivers/gpio/gpio-raspberrypi-exp.c
index bb100e0124e6..c008336e1131 100644
--- a/drivers/gpio/gpio-raspberrypi-exp.c
+++ b/drivers/gpio/gpio-raspberrypi-exp.c
@@ -231,8 +231,19 @@  static int rpi_exp_gpio_probe(struct platform_device *pdev)
 	rpi_gpio->gc.get = rpi_exp_gpio_get;
 	rpi_gpio->gc.set = rpi_exp_gpio_set;
 	rpi_gpio->gc.can_sleep = true;
+	platform_set_drvdata(pdev, rpi_gpio);
 
-	return devm_gpiochip_add_data(dev, &rpi_gpio->gc, rpi_gpio);
+	return gpiochip_add_data(&rpi_gpio->gc, rpi_gpio);
+}
+
+static int rpi_exp_gpio_remove(struct platform_device *pdev)
+{
+	struct rpi_exp_gpio *rpi_gpio = platform_get_drvdata(pdev);
+
+	gpiochip_remove(&rpi_gpio->gc);
+	rpi_firmware_put(rpi_gpio->fw);
+
+	return 0;
 }
 
 static const struct of_device_id rpi_exp_gpio_ids[] = {
@@ -247,6 +258,7 @@  static struct platform_driver rpi_exp_gpio_driver = {
 		.of_match_table	= of_match_ptr(rpi_exp_gpio_ids),
 	},
 	.probe	= rpi_exp_gpio_probe,
+	.remove = rpi_exp_gpio_remove,
 };
 module_platform_driver(rpi_exp_gpio_driver);