27 #include <linux/types.h>
28 #include <linux/module.h>
31 #include <linux/slab.h>
35 #include <linux/i2c.h>
36 #include <linux/input.h>
40 #define TCA8418_MAX_ROWS 8
41 #define TCA8418_MAX_COLS 10
45 #define REG_INT_STAT 0x02
46 #define REG_KEY_LCK_EC 0x03
47 #define REG_KEY_EVENT_A 0x04
48 #define REG_KEY_EVENT_B 0x05
49 #define REG_KEY_EVENT_C 0x06
50 #define REG_KEY_EVENT_D 0x07
51 #define REG_KEY_EVENT_E 0x08
52 #define REG_KEY_EVENT_F 0x09
53 #define REG_KEY_EVENT_G 0x0A
54 #define REG_KEY_EVENT_H 0x0B
55 #define REG_KEY_EVENT_I 0x0C
56 #define REG_KEY_EVENT_J 0x0D
57 #define REG_KP_LCK_TIMER 0x0E
58 #define REG_UNLOCK1 0x0F
59 #define REG_UNLOCK2 0x10
60 #define REG_GPIO_INT_STAT1 0x11
61 #define REG_GPIO_INT_STAT2 0x12
62 #define REG_GPIO_INT_STAT3 0x13
63 #define REG_GPIO_DAT_STAT1 0x14
64 #define REG_GPIO_DAT_STAT2 0x15
65 #define REG_GPIO_DAT_STAT3 0x16
66 #define REG_GPIO_DAT_OUT1 0x17
67 #define REG_GPIO_DAT_OUT2 0x18
68 #define REG_GPIO_DAT_OUT3 0x19
69 #define REG_GPIO_INT_EN1 0x1A
70 #define REG_GPIO_INT_EN2 0x1B
71 #define REG_GPIO_INT_EN3 0x1C
72 #define REG_KP_GPIO1 0x1D
73 #define REG_KP_GPIO2 0x1E
74 #define REG_KP_GPIO3 0x1F
75 #define REG_GPI_EM1 0x20
76 #define REG_GPI_EM2 0x21
77 #define REG_GPI_EM3 0x22
78 #define REG_GPIO_DIR1 0x23
79 #define REG_GPIO_DIR2 0x24
80 #define REG_GPIO_DIR3 0x25
81 #define REG_GPIO_INT_LVL1 0x26
82 #define REG_GPIO_INT_LVL2 0x27
83 #define REG_GPIO_INT_LVL3 0x28
84 #define REG_DEBOUNCE_DIS1 0x29
85 #define REG_DEBOUNCE_DIS2 0x2A
86 #define REG_DEBOUNCE_DIS3 0x2B
87 #define REG_GPIO_PULL1 0x2C
88 #define REG_GPIO_PULL2 0x2D
89 #define REG_GPIO_PULL3 0x2E
93 #define CFG_GPI_E_CFG BIT(6)
94 #define CFG_OVR_FLOW_M BIT(5)
95 #define CFG_INT_CFG BIT(4)
96 #define CFG_OVR_FLOW_IEN BIT(3)
97 #define CFG_K_LCK_IEN BIT(2)
98 #define CFG_GPI_IEN BIT(1)
99 #define CFG_KE_IEN BIT(0)
101 #define INT_STAT_CAD_INT BIT(4)
102 #define INT_STAT_OVR_FLOW_INT BIT(3)
103 #define INT_STAT_K_LCK_INT BIT(2)
104 #define INT_STAT_GPI_INT BIT(1)
105 #define INT_STAT_K_INT BIT(0)
108 #define KEY_LCK_EC_KEC 0x7
109 #define KEY_EVENT_CODE 0x7f
110 #define KEY_EVENT_VALUE 0x80
144 "%s failed, reg: %d, val: %d, error: %d\n",
145 __func__, reg, val, error);
163 "%s failed, reg: %d, error: %d\n",
164 __func__, reg, error);
173 static void tca8418_read_keypad(
struct tca8418_keypad *keypad_data)
182 while (error >= 0 && reg > 0) {
189 row = (col) ? row : row - 1;
194 input_report_key(keypad_data->
input,
195 keypad_data->
keymap[code], state);
203 "unable to read REG_KEY_EVENT_A\n");
205 input_sync(keypad_data->
input);
217 error = tca8418_read_byte(keypad_data,
REG_INT_STAT, ®);
220 "unable to read REG_INT_STAT\n");
228 tca8418_read_keypad(keypad_data);
233 error = tca8418_write_byte(keypad_data,
REG_INT_STAT, reg);
236 "unable to clear REG_INT_STAT\n");
249 error = tca8418_write_byte(keypad_data,
REG_CFG,
256 reg = ~(~0 << keypad_data->
rows);
257 reg += (~(~0 << keypad_data->
cols)) << 8;
261 error |= tca8418_write_byte(keypad_data,
REG_KP_GPIO1, reg);
262 error |= tca8418_write_byte(keypad_data,
REG_KP_GPIO2, reg >> 8);
263 error |= tca8418_write_byte(keypad_data,
REG_KP_GPIO3, reg >> 16);
277 client->
dev.platform_data;
279 struct input_dev *
input;
280 int error, row_shift, max_keys;
289 dev_err(&client->
dev,
"no keymap data defined\n");
305 dev_err(&client->
dev,
"%s adapter not supported\n",
310 row_shift = get_count_order(pdata->
cols);
311 max_keys = pdata->
rows << row_shift;
314 keypad_data = kzalloc(
sizeof(*keypad_data) +
325 error = tca8418_configure(keypad_data);
330 input = input_allocate_device();
337 input->name = client->
name;
338 input->dev.parent = &client->
dev;
341 input->id.vendor = 0x0001;
342 input->id.product = 0x001;
343 input->id.version = 0x0001;
347 keypad_data->
keymap, input);
349 dev_dbg(&client->
dev,
"Failed to build keymap\n");
357 input_set_drvdata(input, keypad_data);
364 client->
name, keypad_data);
367 "Unable to claim irq %d; error %d\n",
372 error = input_register_device(input);
375 "Unable to register input device, error: %d\n", error);
379 i2c_set_clientdata(client, keypad_data);
385 input_free_device(input);
397 input_unregister_device(keypad_data->
input);
405 static struct i2c_driver tca8418_keypad_driver = {
410 .probe = tca8418_keypad_probe,
412 .id_table = tca8418_id,
415 static int __init tca8418_keypad_init(
void)
417 return i2c_add_driver(&tca8418_keypad_driver);
421 static void __exit tca8418_keypad_exit(
void)