六.代码
6.1 dtsi配置
&i2c2 {
status = "okay";
#address-cells = <1>;
#size-cells = <0>;
sprd: sn7326_key@58 {
compatible = "sprd,sn7326-key";
reg = <0x58>;
key-eint = <&ap_gpio 169 0>;
key-rst = <&ap_gpio 123 0>;
//key-led = <&ap_gpio 174 0>;
};
};
6.2 driver code
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/mm_types.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/gpio.h>
//#include <mach/mt_clkmgr.h>
#include <linux/timer.h>
#ifndef CONFIG_OF
#define CONFIG_OF
#endif
#ifdef CONFIG_OF
#include <linux/of.h>
#include <linux/of_irq.h>
#include <linux/of_address.h>
#include <linux/of_device.h>
#include <linux/regulator/consumer.h>
#include <linux/clk.h>
#include <linux/of_gpio.h>
#endif
//#include "upmu_common.h"
//#include <linux/hrtimer.h>
#include <linux/string.h>
#include <linux/vmalloc.h>
#include <linux/jiffies.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/input.h>
#include <linux/slab.h>
#include <linux/gpio.h>
#include <linux/sched.h>
#include <linux/kthread.h>
#include <linux/bitops.h>
#include <linux/kernel.h>
#include <linux/byteorder/generic.h>
#include <linux/interrupt.h>
#include <linux/time.h>
//#include <linux/hrtimer.h>
#include <linux/proc_fs.h>
#include <asm/uaccess.h>
#include <linux/types.h>
#include <linux/device.h>
#include <linux/workqueue.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/spinlock.h>
#ifdef CONFIG_COMPAT
#include <linux/compat.h>
#endif
#define KEY_DEV "sprd_sn7326"
//#define KEY_FULL
//1:enable log, 0: disable log
#define DEBUG_LOG 0
typedef unsigned char kal_uint8;
typedef unsigned short kal_uint16;
typedef unsigned int kal_uint32;
struct key_platform_data {
unsigned int key_gpio_irq;
unsigned int key_gpio_rst;
};
struct key_i2c_data {
unsigned long flags;
struct i2c_client *client;
struct key_platform_data *pdata;
struct hrtimer timer;
struct input_dev *input_dev;
};
static struct i2c_client *this_client;
static const struct i2c_device_id key_i2c_id[] = {
{"sprd_sn7326", 0}, {} };
static struct input_dev *key_input_dev;
struct sn7326_key_array {
unsigned char i2c_down_value;
unsigned char i2c_up_value;
unsigned int key_value;
};
static struct sn7326_key_array sn7326_array_uni[] = {
#ifndef KEY_FULL
{0x40, 0x00, KEY_F2}, //FN
{0x4C, 0x0C, KEY_F1}, //App
{0x49, 0x09, KEY_UP}, //Up
{0x52, 0x12, KEY_DOWN}, //Down
{0x43, 0x03, KEY_LEFT}, //Left
{0x4E, 0x0E, KEY_RIGHT}, //RIGHT
{0x65, 0x25, KEY_0}, //0
{0x75, 0x35, KEY_1}, //1
{0x68, 0x28, KEY_2}, //2
{0x5C, 0x1C, KEY_3}, //3
{0x71, 0x31, KEY_4}, //4
{0x6E, 0x2E, KEY_5}, //5
{0x5A, 0x1A, KEY_6}, //6
{0x73, 0x33, KEY_7}, //7
{0x6A, 0x2A, KEY_8}, //8
{0x58, 0x18, KEY_9}, //9
{0x6C, 0x2C, KEY_DOT}, //.
{0x61, 0x21, KEY_BACKSPACE},//del
{0x53, 0x13, KEY_MINUS}, //-
{0x55, 0x15, KEY_CAPSLOCK}, //Aa switch
{0x5E, 0x1E, KEY_F4}, //micro
#else
{0x40, 0x0, KEY_F2}, //FN:数字和符合切换
{0x45, 0x5, KEY_F1}, //APP:程序的关联快捷键
{0x49, 0x9, KEY_UP},
{0x52, 0x12, KEY_DOWN},
{0x46, 0x6, KEY_LEFT},
{0x4A, 0xA, KEY_RIGHT},
{0x44, 0x4, KEY_1},
{0x75, 0x35, KEY_2},
{0x42, 0x2, KEY_3},
{0x43, 0x3, KEY_4},
{0x41, 0x1, KEY_5},
{0x70, 0x30, KEY_6},
{0x68, 0x28, KEY_7},
{0x5C, 0x1C, KEY_8},
{0x53, 0x13, KEY_9},
{0x4C, 0xC, KEY_0},
{0x71, 0x31, KEY_Q},
{0x69, 0x29, KEY_E},
{0x59, 0x19, KEY_T},
{0x5B, 0x1B, KEY_U},
{0x48, 0x8, KEY_O},
{0x6D, 0x2D, KEY_W},
{0x61, 0x21, KEY_R},
{0x5A, 0x1A, KEY_Y},
{0x51, 0x11, KEY_I},
{0x4B, 0xB, KEY_P},
{0x72, 0x32, KEY_A},
{0x6A, 0x2A, KEY_S},
{0x65, 0x25, KEY_D