15 #include <linux/module.h>
17 #include <linux/input.h>
18 #include <linux/i2c.h>
19 #include <linux/slab.h>
21 #include <linux/bitops.h>
26 #define ELE_TOUCH_STATUS_0_ADDR 0x0
27 #define ELE_TOUCH_STATUS_1_ADDR 0X1
28 #define MHD_RISING_ADDR 0x2b
29 #define NHD_RISING_ADDR 0x2c
30 #define NCL_RISING_ADDR 0x2d
31 #define FDL_RISING_ADDR 0x2e
32 #define MHD_FALLING_ADDR 0x2f
33 #define NHD_FALLING_ADDR 0x30
34 #define NCL_FALLING_ADDR 0x31
35 #define FDL_FALLING_ADDR 0x32
36 #define ELE0_TOUCH_THRESHOLD_ADDR 0x41
37 #define ELE0_RELEASE_THRESHOLD_ADDR 0x42
38 #define AFE_CONF_ADDR 0x5c
39 #define FILTER_CONF_ADDR 0x5d
45 #define ELECTRODE_CONF_ADDR 0x5e
46 #define ELECTRODE_CONF_QUICK_CHARGE 0x80
47 #define AUTO_CONFIG_CTRL_ADDR 0x7b
48 #define AUTO_CONFIG_USL_ADDR 0x7d
49 #define AUTO_CONFIG_LSL_ADDR 0x7e
50 #define AUTO_CONFIG_TL_ADDR 0x7f
53 #define TOUCH_THRESHOLD 0x08
54 #define RELEASE_THRESHOLD 0x05
56 #define TOUCH_STATUS_MASK 0xfff
58 #define MPR121_MAX_KEY_COUNT 12
91 unsigned int key_num, key_val, pressed;
96 dev_err(&client->
dev,
"i2c read error [%d]\n", reg);
103 dev_err(&client->
dev,
"i2c read error [%d]\n", reg);
110 pressed = reg & (1 <<
key_num);
116 input_report_key(input, key_val, pressed);
119 dev_dbg(&client->
dev,
"key %d %d %s\n", key_num, key_val,
120 pressed ?
"pressed" :
"released");
131 unsigned char usl, lsl, tl, eleconf;
147 for (i = 0; i <
ARRAY_SIZE(init_reg_table); i++) {
148 reg = &init_reg_table[
i];
160 vdd = pdata->
vdd_uv / 1000;
161 usl = ((vdd - 700) * 256) / vdd;
162 lsl = (usl * 65) / 100;
163 tl = (usl * 90) / 100;
184 dev_err(&client->
dev,
"i2c write error: %d\n", ret);
193 struct input_dev *input_dev;
198 dev_err(&client->
dev,
"no platform data defined\n");
203 dev_err(&client->
dev,
"missing keymap data\n");
208 dev_err(&client->
dev,
"too many keys defined\n");
213 dev_err(&client->
dev,
"irq number should not be zero\n");
218 input_dev = input_allocate_device();
219 if (!mpr121 || !input_dev) {
220 dev_err(&client->
dev,
"Failed to allocate memory\n");
229 input_dev->name =
"Freescale MPR121 Touchkey";
230 input_dev->id.bustype =
BUS_I2C;
231 input_dev->dev.parent = &client->
dev;
234 input_dev->keycode = mpr121->
keycodes;
235 input_dev->keycodesize =
sizeof(mpr121->
keycodes[0]);
236 input_dev->keycodemax = mpr121->
keycount;
239 input_set_capability(input_dev,
EV_KEY, pdata->
keymap[i]);
243 error = mpr121_phys_init(pdata, mpr121, client);
245 dev_err(&client->
dev,
"Failed to init register\n");
250 mpr_touchkey_interrupt,
252 client->
dev.driver->name, mpr121);
254 dev_err(&client->
dev,
"Failed to register interrupt\n");
258 error = input_register_device(input_dev);
262 i2c_set_clientdata(client, mpr121);
270 input_free_device(input_dev);
280 input_unregister_device(mpr121->
input_dev);
286 #ifdef CONFIG_PM_SLEEP
287 static int mpr_suspend(
struct device *
dev)
291 if (device_may_wakeup(&client->
dev))
292 enable_irq_wake(client->
irq);
299 static int mpr_resume(
struct device *dev)
304 if (device_may_wakeup(&client->
dev))
305 disable_irq_wake(client->
irq);
317 {
"mpr121_touchkey", 0 },
322 static struct i2c_driver mpr_touchkey_driver = {
326 .pm = &mpr121_touchkey_pm_ops,
328 .id_table = mpr121_id,
329 .probe = mpr_touchkey_probe,