[Letux-kernel] GPIOs and driver removal

Andreas Kemnade andreas at kemnade.info
Wed Nov 21 08:11:33 CET 2018


On Tue, 20 Nov 2018 17:56:28 +0100
"H. Nikolaus Schaller" <hns at goldelico.com> wrote:

> Hi,
> 
> > Am 20.11.2018 um 17:14 schrieb Andreas Kemnade <andreas at kemnade.info>:
> > 
> > Hi,
> > 
> > On Tue, 20 Nov 2018 09:56:46 +0100
> > "H. Nikolaus Schaller" <hns at goldelico.com> wrote:
> >   
> >> Hi,
> >> 
> >> This is IMHO the cleanest way.
> >>   
> > At least the easiest way.
> >   
> >>> Is the gpio behavior really sane? Shouldn't gpios generally be declared as
> >>> input, output or both (and not only the inputenable in the pinmux).
> >>> Lots of strange things.    
> >> 
> >> This is special for omap. Usually one would expect that a gpio is always
> >> input and you declare it to be an output.
> >> 
> >> But on OMAP you can only enable the input by pinmux.
> >> 
> >> The reason seems to be that pinmux and gpio-controller are quite independent
> >> functions.
> >>   
> > Yes, and here I am talking about gpio-controller function only and how it
> > handled by kernel. 
> > So who is turning that on/off gpio into an input at driver removal? And why?  
> 
> Ah, now I get it...
> 
> If you remove a driver that has set it to output it is magically turned into an input?
> 
> Before devm there was besides gpio_direction_output a gpio_free which probably was to
> be called explicitly in the remove function. This should be shrink-wrapped into the
> devm_gpio(d) now which might have changed the default behaviour on removal...
> 
We have in drivers/gpio/gpio-omap.c:

static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
{
        struct gpio_bank *bank = gpiochip_get_data(chip);
        unsigned long flags;

        raw_spin_lock_irqsave(&bank->lock, flags);
        bank->mod_usage &= ~(BIT(offset));
        if (!LINE_USED(bank->irq_usage, offset)) {
                omap_set_gpio_direction(bank, offset, 1);
                omap_clear_gpio_debounce(bank, offset);
        }
        omap_disable_gpio_module(bank, offset);
        raw_spin_unlock_irqrestore(&bank->lock, flags);

        pm_runtime_put(chip->parent);
}

So at least that behavior should be kept in mind when playing around with rmmod.

Regards,
Andreas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.goldelico.com/pipermail/letux-kernel/attachments/20181121/002e3ccd/attachment.asc>


More information about the Letux-kernel mailing list