1/* 2 * platform_gpio_keys.c: gpio_keys platform data initilization 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_CAMERA, -1, 1, "camera_full", EV_KEY, 0, 20}, 36 {KEY_CAMERA_FOCUS, -1, 1, "camera_half", EV_KEY, 0, 20}, 37 {SW_KEYPAD_SLIDE, -1, 1, "MagSw1", EV_SW, 0, 20}, 38 {SW_KEYPAD_SLIDE, -1, 1, "MagSw2", EV_SW, 0, 20}, 39}; 40 41static struct gpio_keys_platform_data gpio_keys = { 42 .buttons = gpio_button, 43 .rep = 1, 44 .nbuttons = -1, /* will fill it after search */ 45}; 46 47static struct platform_device pb_device = { 48 .name = DEVICE_NAME, 49 .id = -1, 50 .dev = { 51 .platform_data = &gpio_keys, 52 }, 53}; 54 55/* 56 * Shrink the non-existent buttons, register the gpio button 57 * device if there is some 58 */ 59static int __init pb_keys_init(void) 60{ 61 struct gpio_keys_button *gb = gpio_button; 62 int i, num, good = 0; 63 64 num = sizeof(gpio_button) / sizeof(struct gpio_keys_button); 65 for (i = 0; i < num; i++) { 66 gb[i].gpio = get_gpio_by_name(gb[i].desc); 67 pr_debug("info[%2d]: name = %s, gpio = %d\n", i, gb[i].desc, 68 gb[i].gpio); 69 if (gb[i].gpio < 0) 70 continue; 71 72 if (i != good) 73 gb[good] = gb[i]; 74 good++; 75 } 76 77 if (good) { 78 gpio_keys.nbuttons = good; 79 return platform_device_register(&pb_device); 80 } 81 return 0; 82} 83late_initcall(pb_keys_init); 84