Having issue with gpio-keys not working. Testing gpio input with evtest.

Hi,

Either there is something wrong with both the Angstrom 3.0.17 kernel
and the Yocto 3.0.12 kernel or I'm not doing something right (probably
the latter).

I'll try to provide enough info so hopefully someone will spot where
the problem is.

I have several buttons hanging off the expansion connector. My fist
step was to setup the pinmux for the beagleboard user button and all
of my buttons. I also use a spidev device so I have McSPI 3
configured as well.

Here is my pinmux setting in board-omap3beagle.c:

#ifdef CONFIG_OMAP_MUX
static struct omap_board_mux board_mux[] __initdata = {
  // See TRM section 7.4.4 Pad Functional Multiplexing and Configuration
  OMAP3_MUX(SYS_BOOT5, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP), //
GPIO7 User Button
    OMAP3_MUX(SDMMC2_DAT7, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP),
     // Pin 3 GPIO 139
    OMAP3_MUX(UART2_CTS, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP),
     // Pin 4 GPIO 144
    OMAP3_MUX(SDMMC2_DAT6, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP),
     // Pin 5 GPIO 138
    OMAP3_MUX(UART2_TX, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP),
     // Pin 6 GPIO 146
    OMAP3_MUX(SDMMC2_DAT5, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP),
     // Pin 7 GPIO 137
    OMAP3_MUX(MCBSP3_FSX, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP),
     // Pin 8 GPIO 143
    OMAP3_MUX(SDMMC2_DAT4, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP),
     // Pin 9 GPIO 136
    OMAP3_MUX(UART2_RTS, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP),
     // Pin 10 GPIO 145
    OMAP3_MUX(SDMMC2_DAT3, OMAP_MUX_MODE1 | OMAP_PULL_UP |
OMAP_PULL_ENA), // Pin 11 McSPI3_CS0
    OMAP3_MUX(MCBSP1_DX, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP),
     // Pin 12 GPIO 158
    OMAP3_MUX(SDMMC2_DAT2, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP),
     // Pin 13 GPIO 134
    OMAP3_MUX(MCBSP1_CLKX, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP),
     // Pin 14 GPIO 162
    OMAP3_MUX(SDMMC2_DAT1, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP),
     // Pin 15 GPIO 133
    OMAP3_MUX(MCBSP1_FSX, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP),
     // Pin 16 GPIO 161
    OMAP3_MUX(SDMMC2_DAT0, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP),
     // Pin 17 GPIO 132
    OMAP3_MUX(MCBSP1_DR, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP),
     // Pin 18 GPIO 159
    OMAP3_MUX(SDMMC2_CMD, OMAP_MUX_MODE1),
     // Pin 19 McSPI3_SIMO
    OMAP3_MUX(MCBSP1_CLKR, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP),
     // Pin 20 GPIO 156
    OMAP3_MUX(SDMMC2_CLK, OMAP_MUX_MODE1 | OMAP_PIN_INPUT_PULLDOWN),
     // Pin 21 McSPI3_CLK
    OMAP3_MUX(MCBSP1_FSR, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP),
     // Pin 22 GPIO 157
    OMAP3_MUX(I2C2_SDA, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP),
     // Pin 23 GPIO 183
  { .reg_offset = OMAP_MUX_TERMINATOR },
};
#endif

Here is my gpio buttons setup:

static struct gpio_keys_button gpio_buttons[] = {
    {
        .code = BTN_EXTRA,
        .gpio = 7,
    .active_low = 1,
        .desc = "user",
    .type = EV_KEY,
        .wakeup = 1,
    },
  {
    .code = BTN_TRIGGER_HAPPY10,
    .gpio = 158,
        .active_low = 1,
    .desc = "10yd",
    .wakeup = 1,
        .type = EV_KEY,
        .debounce_interval = 20
  },
  {
    .code = BTN_TRIGGER_HAPPY15,
    .gpio = 134,
    .desc = "15yd",
    .wakeup = 1,
  },
  {
    .code = BTN_TRIGGER_HAPPY20,
    .gpio = 162,
    .desc = "20yd",
    .wakeup = 1,
  },
  {
    .code = BTN_TRIGGER_HAPPY25,
    .gpio = 133,
    .desc = "25yd",
    .wakeup = 1,
  },
  {
    .code = BTN_SELECT,
    .gpio = 161,
    .desc = "select",
    .wakeup = 1,
  },
  {
    .code = KEY_UP,
    .gpio = 132,
    .desc = "up",
    .wakeup = 1,
  },
  {
    .code = KEY_DOWN,
    .gpio = 159,
    .desc = "down",
    .wakeup = 1,
  },
  {
    .code = BTN_MODE,
    .gpio = 156,
    .desc = "mode",
    .wakeup = 1,
  },
  {
    .code = KEY_SAVE,
    .gpio = 157,
    .desc = "save",
    .wakeup = 1,
  },
  {
    .code = KEY_DIRECTION,
    .gpio = 183,
    .desc = "direction",
    .wakeup = 1,
    }
};

I'm not sure if I should have EV_KEY defined for all the buttons or
not and if I need wakeup or anything else setup (like active_low). I
figured I would focus first on getting the beagle user button working
first and then focus on getting the setup for the rest of my buttons
correct.

In my .config I've verified that all the kernel options that I "think"
I need to get this to work are all turned on. And I verified the
kernel running on the hardware is in fact configured the way I think
it is:

root@beagleboard:/dev# zcat /proc/config.gz | grep -i keyboard_gpio
# CONFIG_KEYBOARD_GPIO_POLLED is not set
CONFIG_KEYBOARD_GPIO=y

root@beagleboard:/dev# zcat /proc/config.gz | grep -i input_evdev
CONFIG_INPUT_EVDEV=y
CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV=y
CONFIG_USB_PWC_INPUT_EVDEV=y

Not sure what else is required. I can attach my entire .config if needed.

On the Angstrom 3.0.17 kernel, if I run evtest /dev/input/event0 I see:

root@beagleboard:/dev# evtest /dev/input/event0
Input driver version is 1.0.1
Input device ID: bus 0x0 vendor 0x0 product 0x0 version 0x0
Input device name: "twl4030_pwrbutton"
Supported events:
  Event type 0 (Sync)
  Event type 1 (Key)
    Event code 116 (Power)
Testing ... (interrupt to exit)

.... this output does not reflect the config of my buttons in
board-omap3beagle.c

Now if I run the same test using the Yocto 3.0.12 kernel I see:

root@beagleboard:~# evtest /dev/input/event0
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "gpio-keys"
Supported events:
  Event type 0 (Sync)
  Event type 1 (Key)
    Event code 103 (Up)
    Event code 108 (Down)
    Event code 153 (Direction)
    Event code 234 (?)
    Event code 276 (ExtraBtn)
    Event code 314 (BtnSelect)
    Event code 316 (BtnMode)
Testing ... (interrupt to exit)

... this at least reflects my button config which looks promising.

But ... in both cases I can press buttons and I see no events
displayed so I think I'm on the right track but am missing something.

Regards,

Brian

and other event interfaces?

Forgot to mention my hardware ... it is a beagleboard C3.

I've also tried running evtest with /dev/input/by-path/platform-gpio-keys-event.

On the Yocto 3.0.12 kernel I get the same result I described before.

On the Angstrom kernel I don't have a
/dev/input/by-path/platform-gpio-keys-event ... instead I see:
/dev/input/by-path/platform-omap_i2c.1-platform-twl4030_pwrbutton-event

I suspect this is because the console-image doesn't have the right udev rules.

Regards,

Brian

All I'm showing in /dev/input is:

root@beagleboard:/dev/input# ls
by-path event0 mice

by-path has:
root@beagleboard:/dev/input/by-path# ls
platform-omap_i2c.1-platform-twl4030_pwrbutton-event

Regards,

Brian

So your gpio-keys isn't getting registered

OK, udev rules doesn't appear to have anything to do with the
/dev/input/path-to differences I'm seeing. I thought the yocto
core-image-base image had some input rules that set this up but that
does not look like the case as I just checked it.

Regards,

Brian

Appears that way with the 3.0.17+ kernel. Looks like it is being
registered (but not working) on the yocto 3.0.12 kernel.

Regards,

Brian

Ah, I misspoke earlier. The yocto kernel I was trying wasn't 3.0.12
(edison) it was 3.0.14 from master.

Has anyone got gpio-keys/buttons to work with 3.0 kernel?

Regards,

Brian

I just tried with the angstrom/meta-ti 3.0.17 kernel on my beagleboard xM and evtest reports a buttonpress when I push the USER button

Can you send me your .config if you changed anything?

Did you change anything in board-omap3beagle for pinmux etc?

I just realized that I never tried it with just the user button … I added my other buttons too and now I’m thinking the problem is the kernel is probably being built with options (touchscreen lcd etc.) that conflict with some of the gpios I’m trying to use.

Regards,

Brian

No changes at all.

Thanks! That gave me some ideas as to where to look for my problem.

I see something strange regarding the debounce_interval.

I have my buttons working now. I think I may of had a .config
conflict. I turned some things off (LCD & touchscreen related) and
now /dev/input/event0 reflects my gpio-keys.

Problem I'm seeing is the comments in the code say the
debounce_interval is in milliseconds so I put in 20ms for all my
buttons. I have to hold the button down for 2 seconds for the button
press to register ... strange.

Regards,

Brian

A sample that shows the 2 seconds to detect state change:

Event: time 37.103938, -------------- Report Sync ------------
Event: time 49.602392, type 1 (Key), code 713 (?), value 1
Event: time 49.602392, -------------- Report Sync ------------
Event: time 52.141276, type 1 (Key), code 713 (?), value 0
Event: time 52.141276, -------------- Report Sync ------------

I held down my button and as soon and the event displayed on evtest I
released the button and the value going to zero was reflected about 2
seconds later. I was expecting 20ms.

I've stopped believing comments in kernelcode after the picoseconds vs Hertz confusion in the graphics drivers. Noone noticed it at vga resolutions where 33MHz works and maps to the actual pico seconds as well :slight_smile:

regards,

Koen

Latest update on my gpio-keys saga (which some may find entertaining
as I shot myself in the foot):

With Angstrom 3.0.17 from OECore, something is stepping on my pinmux
setup and I can't figure out what it is. I can't get gpio132, 133 and
134 configured right (I want them hight & be active low and they stay
low no matter what I do).

With 3.0.17, I tired to turn off some Wireless LAN settings in .config
but I discovered that if I go into make menuconfig and turn off
wireless support I get an error and the build fails.

So, at the very end of omap3_beagle_init I put in another call to
omap3_mux_init(board_mux, OMAP_PACKAGE_CBB); just for kicks. It still
didn't fix it. I also commented out calls to all things video as my
application has a 4x20 character screen ran by McSPI3.

I took what I learned so far and applied it back to the original Yocto
3.0.14 kernel I was working with and got all my buttons working!
Again, I commented out calls to display related stuff in beagle_init
and in the .config I turned off touchscreen and WiFi driver support.
Prior to doing this, the user button and gpio158 wouldn't work but did
after I trimmed the fat.

Man pinmux drives me crazy!

OK, those of you that are real sharp will notice in my first post
crying for help that I hosed myself up pretty good. I had the user
button, gpio7, setup with active_low flag set and this is wrong. It
is wired to be active high while all of my buttons on the expansion
connector are active low (adding to global warming I know but I didn't
wire it up that way) but I didn't have the active_low flag set. So, I
probably had things setup right as far as registering the buttons in
gpio-keys ... but I totally hosed the button settings up so that when
a button press happened ... nothing got triggered! The other problem
was the debounce set to what I thought was 20ms turned out being 2sec,
so it wasn't until I got really mad and just held a button down for a
long time that I noticed that one. Once I got rid of debounce I
started seeing some life.

I give up trying to figure out what in the Angstrom 3.0.17 kernel is
still messing with some of my gpio settings.

So, you can laugh and learn at my expense!

Regards,

Brian

are you using the TinCanTool expension board?
Did yo change the level shifter configuration?