13 #include <linux/types.h>
14 #include <linux/module.h>
17 #include <linux/slab.h>
21 #include <linux/i2c.h>
22 #include <linux/input.h>
25 #define TCA6416_INPUT 0
26 #define TCA6416_OUTPUT 1
27 #define TCA6416_INVERT 2
28 #define TCA6416_DIRECTION 3
31 {
"tca6416-keys", 16, },
32 {
"tca6408-keys", 8, },
66 "%s failed, reg: %d, val: %d, error: %d\n",
67 __func__, reg, val, error);
82 dev_err(&chip->
client->dev,
"%s failed, reg: %d, error: %d\n",
83 __func__, reg, retval);
107 for (i = 0, pin_index = 0; i < 16; i++) {
108 if (val & (1 << i)) {
111 int state = ((reg_val & (1 <<
i)) ? 1 : 0)
130 tca6416_keys_scan(chip);
140 tca6416_keys_scan(chip);
144 static int tca6416_keys_open(
struct input_dev *
dev)
149 tca6416_keys_scan(chip);
159 static void tca6416_keys_close(
struct input_dev *dev)
205 struct input_dev *
input;
211 dev_err(&client->
dev,
"%s adapter not supported\n",
216 pdata = client->
dev.platform_data;
225 input = input_allocate_device();
226 if (!chip || !input) {
233 chip->
io_size =
id->driver_data;
239 input->phys =
"tca6416-keys/input0";
240 input->name = client->
name;
241 input->dev.parent = &client->
dev;
243 input->open = tca6416_keys_open;
244 input->close = tca6416_keys_close;
247 input->id.vendor = 0x0001;
248 input->id.product = 0x0001;
249 input->id.version = 0x0100;
255 for (i = 0; i < pdata->
nbuttons; i++) {
260 input_set_capability(input, type, pdata->
buttons[i].code);
263 input_set_drvdata(input, chip);
269 error = tca6416_setup_registers(chip);
283 "tca6416-keypad", chip);
286 "Unable to claim irq %d; error %d\n",
293 error = input_register_device(input);
296 "Unable to register input device, error: %d\n", error);
300 i2c_set_clientdata(client, chip);
311 input_free_device(input);
325 input_unregister_device(chip->
input);
331 #ifdef CONFIG_PM_SLEEP
332 static int tca6416_keypad_suspend(
struct device *dev)
337 if (device_may_wakeup(dev))
338 enable_irq_wake(chip->
irqnum);
343 static int tca6416_keypad_resume(
struct device *dev)
348 if (device_may_wakeup(dev))
349 disable_irq_wake(chip->
irqnum);
356 tca6416_keypad_suspend, tca6416_keypad_resume);
358 static struct i2c_driver tca6416_keypad_driver = {
360 .name =
"tca6416-keypad",
361 .pm = &tca6416_keypad_dev_pm_ops,
363 .probe = tca6416_keypad_probe,
365 .id_table = tca6416_id,
368 static int __init tca6416_keypad_init(
void)
370 return i2c_add_driver(&tca6416_keypad_driver);
375 static void __exit tca6416_keypad_exit(
void)