linux/arch/x86/platform/intel-mid/device_libs/platform_gpio_keys.c
<<
>>
Prefs
   1/*
   2 * platform_gpio_keys.c: gpio_keys platform data initialization file
   3 *
   4 * (C) Copyright 2013 Intel Corporation
   5 * Author: Sathyanarayanan Kuppuswamy <sathyanarayanan.kuppuswamy@intel.com>
   6 *
   7 * This program is free software; you can redistribute it and/or
   8 * modify it under the terms of the GNU General Public License
   9 * as published by the Free Software Foundation; version 2
  10 * of the License.
  11 */
  12
  13#include <linux/input.h>
  14#include <linux/init.h>
  15#include <linux/kernel.h>
  16#include <linux/gpio.h>
  17#include <linux/gpio_keys.h>
  18#include <linux/platform_device.h>
  19#include <asm/intel-mid.h>
  20
  21#define DEVICE_NAME "gpio-keys"
  22
  23/*
  24 * we will search these buttons in SFI GPIO table (by name)
  25 * and register them dynamically. Please add all possible
  26 * buttons here, we will shrink them if no GPIO found.
  27 */
  28static struct gpio_keys_button gpio_button[] = {
  29        {KEY_POWER,             -1, 1, "power_btn",     EV_KEY, 0, 3000},
  30        {KEY_PROG1,             -1, 1, "prog_btn1",     EV_KEY, 0, 20},
  31        {KEY_PROG2,             -1, 1, "prog_btn2",     EV_KEY, 0, 20},
  32        {SW_LID,                -1, 1, "lid_switch",    EV_SW,  0, 20},
  33        {KEY_VOLUMEUP,          -1, 1, "vol_up",        EV_KEY, 0, 20},
  34        {KEY_VOLUMEDOWN,        -1, 1, "vol_down",      EV_KEY, 0, 20},
  35        {KEY_MUTE,              -1, 1, "mute_enable",   EV_KEY, 0, 20},
  36        {KEY_VOLUMEUP,          -1, 1, "volume_up",     EV_KEY, 0, 20},
  37        {KEY_VOLUMEDOWN,        -1, 1, "volume_down",   EV_KEY, 0, 20},
  38        {KEY_CAMERA,            -1, 1, "camera_full",   EV_KEY, 0, 20},
  39        {KEY_CAMERA_FOCUS,      -1, 1, "camera_half",   EV_KEY, 0, 20},
  40        {SW_KEYPAD_SLIDE,       -1, 1, "MagSw1",        EV_SW,  0, 20},
  41        {SW_KEYPAD_SLIDE,       -1, 1, "MagSw2",        EV_SW,  0, 20},
  42};
  43
  44static struct gpio_keys_platform_data gpio_keys = {
  45        .buttons        = gpio_button,
  46        .rep            = 1,
  47        .nbuttons       = -1, /* will fill it after search */
  48};
  49
  50static struct platform_device pb_device = {
  51        .name           = DEVICE_NAME,
  52        .id             = -1,
  53        .dev            = {
  54                .platform_data  = &gpio_keys,
  55        },
  56};
  57
  58/*
  59 * Shrink the non-existent buttons, register the gpio button
  60 * device if there is some
  61 */
  62static int __init pb_keys_init(void)
  63{
  64        struct gpio_keys_button *gb = gpio_button;
  65        int i, good = 0;
  66
  67        for (i = 0; i < ARRAY_SIZE(gpio_button); i++) {
  68                gb[i].gpio = get_gpio_by_name(gb[i].desc);
  69                pr_debug("info[%2d]: name = %s, gpio = %d\n", i, gb[i].desc,
  70                                        gb[i].gpio);
  71                if (gb[i].gpio < 0)
  72                        continue;
  73
  74                if (i != good)
  75                        gb[good] = gb[i];
  76                good++;
  77        }
  78
  79        if (good) {
  80                gpio_keys.nbuttons = good;
  81                return platform_device_register(&pb_device);
  82        }
  83        return 0;
  84}
  85late_initcall(pb_keys_init);
  86