This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

GPIO 96 AM335x

I'm developing a linux driver and I have tried allocate gpio 96 with gpio_request. I have received -16 error and in user space I can see that gpio is allocated by another driver:

GPIOs 96-127, gpio:
 gpio-96  ([auto]              ) in  hi
 gpio-105 (WDT                 ) out hi
 gpio-114 (mmc_wp              ) in  lo

And the gpio is labeled with [auto]. What auto means in this case? How can I find which driver is using that resource?

Thanks a lot,

Leonardo

  • Hi Leonardo,

    Which AM335x board are you using? The GP EVM, the Starter Kit or the BeagleBone?

    Best regards,
    Miroslav

  • Hi Leonardo,

    Please take a look at the gpiolib.c file: http://lxr.free-electrons.com/source/drivers/gpio/gpiolib.c
    The [auto] label means that the GPIO pin has been autorequested. I quote:

    /* Warn when drivers omit gpio_request() calls -- legal but ill-advised
     * when setting direction, and otherwise illegal.  Until board setup code
     * and drivers use explicit requests everywhere (which won't happen when
     * those calls have no teeth) we can't avoid autorequesting.  This nag
     * message should motivate switching to explicit requests... so should
     * the weaker cleanup after faults, compared to gpio_request().
     *
     * NOTE: the autorequest mechanism is going away; at this point it's
     * only "legal" in the sense that (old) code using it won't break yet,
     * but instead only triggers a WARN() stack dump.
     */
    static int gpio_ensure_requested(struct gpio_desc *desc, unsigned offset)
    {
        const struct gpio_chip *chip = desc->chip;
        const int gpio = chip->base + offset;

        /* Debug prints */
        if (gpio == 96) {
            printk(KERN_ALERT "**********\n");
            dump_stack();
            printk(KERN_ALERT "**********\n");
        }

        if (WARN(test_and_set_bit(FLAG_REQUESTED, &desc->flags) == 0,
                "autorequest GPIO-%d\n", gpio)) {
            if (!try_module_get(chip->owner)) {
                pr_err("GPIO-%d: module can't be gotten \n", gpio);
                clear_bit(FLAG_REQUESTED, &desc->flags);
                /* lose */
                return -EIO;
            }
            desc_set_label(desc, "[auto]");
            /* caller must chip->request() w/o spinlock */
            if (chip->request)
                return 1;
        }
        return 0;
    }

    You can try and dump the stack inside the gpio_ensure_requested() function. Something like this:

    if (gpio == 96) {
            printk(KERN_ALERT "**********\n");
            dump_stack();
            printk(KERN_ALERT "**********\n");
    }

    Then recompile the kernel. This will dump the call stack and you can check which module is using GPIO #96.

    Best regards,
    Miroslav