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 is not working from Linux

Hi all,

I am trying to control user LEDs of AM335x starter kit. I know that these are gpio 36,37,38 ans 39.

I am able to control gpio LED from uboot using gpio command and is working fine . But after booting linux ,this is not seems to be working  . I tried to turn on and off LED using sysfs interface . There is no error messages when I doing this. Also LED status is not changing . Please find following log for my activity .

root@EVM:/sys/class/gpio# echo 36 > export
root@EVM:/sys/class/gpio# echo 38 > export
root@EVM:/sys/class/gpio# echo 37 > export
root@EVM:/sys/class/gpio# echo 39 > export
root@EVM:/sys/class/gpio#  cat /sys/class/gpio/gpio36/direction
in
root@EVM:/sys/class/gpio# echo out > gpio36/direction
root@EVM:/sys/class/gpio#  cat /sys/class/gpio/gpio36/direction
out
root@EVM:/sys/class/gpio# echo 1 > gpio36/value
root@EVM:/sys/class/gpio#
root@EVM:/sys/class/gpio# echo 0 > gpio36/value
root@EVM:/sys/class/gpio# echo 1 > gpio36/value
root@EVM:/sys/class/gpio# echo out > gpio37/direction
root@EVM:/sys/class/gpio# echo out > gpio38/direction
root@EVM:/sys/class/gpio# echo out > gpio39/direction
root@EVM:/sys/class/gpio# echo 1 > gpio38/value
root@EVM:/sys/class/gpio# echo 0 > gpio38/value
root@EVM:/sys/class/gpio# echo 1 > gpio38/value
root@EVM:/sys/class/gpio# echo 1 > gpio39/value
root@EVM:/sys/class/gpio# echo 37 > unexport
root@EVM:/sys/class/gpio# ls /sys/kernel/debug
bdi             gpio            mmc0            regmap          ubi
bonding         hid             pinctrl         regulator       ubifs
clk             kprobes         pm_debug        sleep_time      usb
extfrag         memblock        pwm             suspend_stats   wakeup_sources
root@EVM:/sys/class/gpio# cat /sys/kernel/debug/gpio
export      gpio38/     gpiochip0/  gpiochip64/ unexport
gpio36/     gpio39/     gpiochip32/ gpiochip96/
root@EVM:/sys/class/gpio# cat /sys/kernel/debug/gpio
GPIOs 0-31, gpio:
 gpio-6   (mmc_cd              ) in  lo

GPIOs 32-63, gpio:
 gpio-36  (sysfs               ) out hi
 gpio-38  (sysfs               ) out hi
 gpio-39  (sysfs               ) out hi

GPIOs 64-95, gpio:

GPIOs 96-127, gpio:
root@EVM:/sys/class/gpio#
root@EVM:/sys/class/gpio#
 

is there any additional setting needs to be done ?

Thanks and regards

Gokul CG

  • Have you set the pinmux correctly in the kernel? Which Linux version are you using?

  • hi ,

    I am using Linux 3.12.10-ti2013.12.01 ,shipped along with SDK7.0 . In kernel means in the dts file right ? I didn't explicitly configured that pins as gpio since its default state is gpio .

    Thanks and regards
    Gokul CG
  • These GPIOs are pinmuxed with GPMC_AD[7:4] and may be changed from their default state either by ROM code (depending on SYSBOOT combination) or u-boot.

  • Hi Biser,

    Thanks.
    Now this is working using sysfs interface .
    But when I use kernel module with generic gpio functions like , gpio_set_value( param.gpio, param.value ); as in "svn.hylands.org/.../user-gpio-drv.c" this is not working. Now i have tow components, a kernel module and user space application to call ioctl .


    Thanks and regards
    Gokul CG
  • Hi Gokul,

    To call ioctl from user space you have to make a gpio's as driver. It's good to read:
    people.ee.ethz.ch/.../kernel_user_space_howto.html
    how this is made. There is a examples. Also the ioctl numbers you can read from:
    /Documentation/ioctl/ioctl-number.txt

    BR
    Ivan
  • Hi ,

    Thanks for your support .

    Now  I have two problems ,

    1) I had set one I/O pin to HIGH from uboot . When Linux starts booting its going to LOW state . The same pin is not used for any other functionality and not present in dtb file . I assume the state of IO pin should persist if we not doing explicitly from Linux.

    2) I am using following sequence of API for controlling GPIO .
        gpio_request(36, "");
        gpio_direction_output(36,1);
        mdelay(15);
        gpio_set_value(36,1);
        gpio_free(36);
    A soon as I call   gpio_free(36); , I/O state of PIN going to LOW .

    I Linux kernel , /driver/gpio/gpio-omap.c file free function declared as follows .

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

        spin_lock_irqsave(&bank->lock, flags);
        bank->mod_usage &= ~(1 << offset);
        _disable_gpio_module(bank, offset);
        _reset_gpio(bank, bank->chip.base + offset);
        spin_unlock_irqrestore(&bank->lock, flags);

        /*
         * If this is the last gpio to be freed in the bank,
         * disable the bank module.
         */
        if (!BANK_USED(bank))
            pm_runtime_put(bank->dev);
    }

    is this is the desired behavior.  ?

    Thanks and regards
    Gokul CG