9 #include <linux/module.h>
11 #include <linux/input.h>
13 #include <linux/i2c.h>
14 #include <linux/slab.h>
17 #define DRV_NAME "pcf8574_keypad"
19 static const unsigned char pcf8574_kp_btncode[] = {
48 static short read_state(
struct kp_data *
lp)
50 unsigned char x,
y,
a,
b;
58 for (a = 0; x > 0; a++)
60 for (b = 0; y > 0; b++)
63 return ((a - 1) * 4) + b;
69 unsigned char nextstate = read_state(lp);
73 unsigned short keycode = key_down ?
76 input_report_key(lp->
idev, keycode, key_down);
88 struct input_dev *
idev;
100 idev = input_allocate_device();
102 dev_err(&client->
dev,
"Can't allocate input device\n");
112 idev->keycodesize =
sizeof(lp->
btncode[0]);
115 for (i = 0; i <
ARRAY_SIZE(pcf8574_kp_btncode); i++) {
123 idev->name = lp->
name;
124 idev->phys = lp->
phys;
126 idev->id.vendor = 0x0001;
127 idev->id.product = 0x0001;
128 idev->id.version = 0x0100;
137 goto fail_free_device;
140 ret = input_register_device(idev);
142 dev_err(&client->
dev,
"input_register_device() failed\n");
146 i2c_set_clientdata(client, lp);
152 input_free_device(idev);
161 struct kp_data *lp = i2c_get_clientdata(client);
165 input_unregister_device(lp->
idev);
190 static const struct dev_pm_ops pcf8574_kp_pm_ops = {
196 # define pcf8574_kp_resume NULL
197 # define pcf8574_kp_suspend NULL
206 static struct i2c_driver pcf8574_kp_driver = {
211 .pm = &pcf8574_kp_pm_ops,
214 .probe = pcf8574_kp_probe,
216 .id_table = pcf8574_kp_id,