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