Loading...
1/*
2 * Touchkey driver for Freescale MPR121 Controllor
3 *
4 * Copyright (C) 2011 Freescale Semiconductor, Inc.
5 * Author: Zhang Jiejing <jiejing.zhang@freescale.com>
6 *
7 * Based on mcs_touchkey.c
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 */
14
15#include <linux/module.h>
16#include <linux/input.h>
17#include <linux/i2c.h>
18#include <linux/slab.h>
19#include <linux/delay.h>
20#include <linux/bitops.h>
21#include <linux/interrupt.h>
22#include <linux/i2c/mpr121_touchkey.h>
23
24/* Register definitions */
25#define ELE_TOUCH_STATUS_0_ADDR 0x0
26#define ELE_TOUCH_STATUS_1_ADDR 0X1
27#define MHD_RISING_ADDR 0x2b
28#define NHD_RISING_ADDR 0x2c
29#define NCL_RISING_ADDR 0x2d
30#define FDL_RISING_ADDR 0x2e
31#define MHD_FALLING_ADDR 0x2f
32#define NHD_FALLING_ADDR 0x30
33#define NCL_FALLING_ADDR 0x31
34#define FDL_FALLING_ADDR 0x32
35#define ELE0_TOUCH_THRESHOLD_ADDR 0x41
36#define ELE0_RELEASE_THRESHOLD_ADDR 0x42
37#define AFE_CONF_ADDR 0x5c
38#define FILTER_CONF_ADDR 0x5d
39
40/*
41 * ELECTRODE_CONF_ADDR: This register configures the number of
42 * enabled capacitance sensing inputs and its run/suspend mode.
43 */
44#define ELECTRODE_CONF_ADDR 0x5e
45#define ELECTRODE_CONF_QUICK_CHARGE 0x80
46#define AUTO_CONFIG_CTRL_ADDR 0x7b
47#define AUTO_CONFIG_USL_ADDR 0x7d
48#define AUTO_CONFIG_LSL_ADDR 0x7e
49#define AUTO_CONFIG_TL_ADDR 0x7f
50
51/* Threshold of touch/release trigger */
52#define TOUCH_THRESHOLD 0x08
53#define RELEASE_THRESHOLD 0x05
54/* Masks for touch and release triggers */
55#define TOUCH_STATUS_MASK 0xfff
56/* MPR121 has 12 keys */
57#define MPR121_MAX_KEY_COUNT 12
58
59struct mpr121_touchkey {
60 struct i2c_client *client;
61 struct input_dev *input_dev;
62 unsigned int key_val;
63 unsigned int statusbits;
64 unsigned int keycount;
65 u16 keycodes[MPR121_MAX_KEY_COUNT];
66};
67
68struct mpr121_init_register {
69 int addr;
70 u8 val;
71};
72
73static const struct mpr121_init_register init_reg_table[] = {
74 { MHD_RISING_ADDR, 0x1 },
75 { NHD_RISING_ADDR, 0x1 },
76 { MHD_FALLING_ADDR, 0x1 },
77 { NHD_FALLING_ADDR, 0x1 },
78 { NCL_FALLING_ADDR, 0xff },
79 { FDL_FALLING_ADDR, 0x02 },
80 { FILTER_CONF_ADDR, 0x04 },
81 { AFE_CONF_ADDR, 0x0b },
82 { AUTO_CONFIG_CTRL_ADDR, 0x0b },
83};
84
85static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id)
86{
87 struct mpr121_touchkey *mpr121 = dev_id;
88 struct i2c_client *client = mpr121->client;
89 struct input_dev *input = mpr121->input_dev;
90 unsigned int key_num, key_val, pressed;
91 int reg;
92
93 reg = i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_1_ADDR);
94 if (reg < 0) {
95 dev_err(&client->dev, "i2c read error [%d]\n", reg);
96 goto out;
97 }
98
99 reg <<= 8;
100 reg |= i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_0_ADDR);
101 if (reg < 0) {
102 dev_err(&client->dev, "i2c read error [%d]\n", reg);
103 goto out;
104 }
105
106 reg &= TOUCH_STATUS_MASK;
107 /* use old press bit to figure out which bit changed */
108 key_num = ffs(reg ^ mpr121->statusbits) - 1;
109 pressed = reg & (1 << key_num);
110 mpr121->statusbits = reg;
111
112 key_val = mpr121->keycodes[key_num];
113
114 input_event(input, EV_MSC, MSC_SCAN, key_num);
115 input_report_key(input, key_val, pressed);
116 input_sync(input);
117
118 dev_dbg(&client->dev, "key %d %d %s\n", key_num, key_val,
119 pressed ? "pressed" : "released");
120
121out:
122 return IRQ_HANDLED;
123}
124
125static int mpr121_phys_init(const struct mpr121_platform_data *pdata,
126 struct mpr121_touchkey *mpr121,
127 struct i2c_client *client)
128{
129 const struct mpr121_init_register *reg;
130 unsigned char usl, lsl, tl, eleconf;
131 int i, t, vdd, ret;
132
133 /* Set up touch/release threshold for ele0-ele11 */
134 for (i = 0; i <= MPR121_MAX_KEY_COUNT; i++) {
135 t = ELE0_TOUCH_THRESHOLD_ADDR + (i * 2);
136 ret = i2c_smbus_write_byte_data(client, t, TOUCH_THRESHOLD);
137 if (ret < 0)
138 goto err_i2c_write;
139 ret = i2c_smbus_write_byte_data(client, t + 1,
140 RELEASE_THRESHOLD);
141 if (ret < 0)
142 goto err_i2c_write;
143 }
144
145 /* Set up init register */
146 for (i = 0; i < ARRAY_SIZE(init_reg_table); i++) {
147 reg = &init_reg_table[i];
148 ret = i2c_smbus_write_byte_data(client, reg->addr, reg->val);
149 if (ret < 0)
150 goto err_i2c_write;
151 }
152
153
154 /*
155 * Capacitance on sensing input varies and needs to be compensated.
156 * The internal MPR121-auto-configuration can do this if it's
157 * registers are set properly (based on pdata->vdd_uv).
158 */
159 vdd = pdata->vdd_uv / 1000;
160 usl = ((vdd - 700) * 256) / vdd;
161 lsl = (usl * 65) / 100;
162 tl = (usl * 90) / 100;
163 ret = i2c_smbus_write_byte_data(client, AUTO_CONFIG_USL_ADDR, usl);
164 ret |= i2c_smbus_write_byte_data(client, AUTO_CONFIG_LSL_ADDR, lsl);
165 ret |= i2c_smbus_write_byte_data(client, AUTO_CONFIG_TL_ADDR, tl);
166
167 /*
168 * Quick charge bit will let the capacitive charge to ready
169 * state quickly, or the buttons may not function after system
170 * boot.
171 */
172 eleconf = mpr121->keycount | ELECTRODE_CONF_QUICK_CHARGE;
173 ret |= i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR,
174 eleconf);
175 if (ret != 0)
176 goto err_i2c_write;
177
178 dev_dbg(&client->dev, "set up with %x keys.\n", mpr121->keycount);
179
180 return 0;
181
182err_i2c_write:
183 dev_err(&client->dev, "i2c write error: %d\n", ret);
184 return ret;
185}
186
187static int mpr_touchkey_probe(struct i2c_client *client,
188 const struct i2c_device_id *id)
189{
190 const struct mpr121_platform_data *pdata =
191 dev_get_platdata(&client->dev);
192 struct mpr121_touchkey *mpr121;
193 struct input_dev *input_dev;
194 int error;
195 int i;
196
197 if (!pdata) {
198 dev_err(&client->dev, "no platform data defined\n");
199 return -EINVAL;
200 }
201
202 if (!pdata->keymap || !pdata->keymap_size) {
203 dev_err(&client->dev, "missing keymap data\n");
204 return -EINVAL;
205 }
206
207 if (pdata->keymap_size > MPR121_MAX_KEY_COUNT) {
208 dev_err(&client->dev, "too many keys defined\n");
209 return -EINVAL;
210 }
211
212 if (!client->irq) {
213 dev_err(&client->dev, "irq number should not be zero\n");
214 return -EINVAL;
215 }
216
217 mpr121 = kzalloc(sizeof(struct mpr121_touchkey), GFP_KERNEL);
218 input_dev = input_allocate_device();
219 if (!mpr121 || !input_dev) {
220 dev_err(&client->dev, "Failed to allocate memory\n");
221 error = -ENOMEM;
222 goto err_free_mem;
223 }
224
225 mpr121->client = client;
226 mpr121->input_dev = input_dev;
227 mpr121->keycount = pdata->keymap_size;
228
229 input_dev->name = "Freescale MPR121 Touchkey";
230 input_dev->id.bustype = BUS_I2C;
231 input_dev->dev.parent = &client->dev;
232 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
233
234 input_dev->keycode = mpr121->keycodes;
235 input_dev->keycodesize = sizeof(mpr121->keycodes[0]);
236 input_dev->keycodemax = mpr121->keycount;
237
238 for (i = 0; i < pdata->keymap_size; i++) {
239 input_set_capability(input_dev, EV_KEY, pdata->keymap[i]);
240 mpr121->keycodes[i] = pdata->keymap[i];
241 }
242
243 error = mpr121_phys_init(pdata, mpr121, client);
244 if (error) {
245 dev_err(&client->dev, "Failed to init register\n");
246 goto err_free_mem;
247 }
248
249 error = request_threaded_irq(client->irq, NULL,
250 mpr_touchkey_interrupt,
251 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
252 client->dev.driver->name, mpr121);
253 if (error) {
254 dev_err(&client->dev, "Failed to register interrupt\n");
255 goto err_free_mem;
256 }
257
258 error = input_register_device(input_dev);
259 if (error)
260 goto err_free_irq;
261
262 i2c_set_clientdata(client, mpr121);
263 device_init_wakeup(&client->dev, pdata->wakeup);
264
265 return 0;
266
267err_free_irq:
268 free_irq(client->irq, mpr121);
269err_free_mem:
270 input_free_device(input_dev);
271 kfree(mpr121);
272 return error;
273}
274
275static int mpr_touchkey_remove(struct i2c_client *client)
276{
277 struct mpr121_touchkey *mpr121 = i2c_get_clientdata(client);
278
279 free_irq(client->irq, mpr121);
280 input_unregister_device(mpr121->input_dev);
281 kfree(mpr121);
282
283 return 0;
284}
285
286#ifdef CONFIG_PM_SLEEP
287static int mpr_suspend(struct device *dev)
288{
289 struct i2c_client *client = to_i2c_client(dev);
290
291 if (device_may_wakeup(&client->dev))
292 enable_irq_wake(client->irq);
293
294 i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR, 0x00);
295
296 return 0;
297}
298
299static int mpr_resume(struct device *dev)
300{
301 struct i2c_client *client = to_i2c_client(dev);
302 struct mpr121_touchkey *mpr121 = i2c_get_clientdata(client);
303
304 if (device_may_wakeup(&client->dev))
305 disable_irq_wake(client->irq);
306
307 i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR,
308 mpr121->keycount);
309
310 return 0;
311}
312#endif
313
314static SIMPLE_DEV_PM_OPS(mpr121_touchkey_pm_ops, mpr_suspend, mpr_resume);
315
316static const struct i2c_device_id mpr121_id[] = {
317 { "mpr121_touchkey", 0 },
318 { }
319};
320MODULE_DEVICE_TABLE(i2c, mpr121_id);
321
322static struct i2c_driver mpr_touchkey_driver = {
323 .driver = {
324 .name = "mpr121",
325 .owner = THIS_MODULE,
326 .pm = &mpr121_touchkey_pm_ops,
327 },
328 .id_table = mpr121_id,
329 .probe = mpr_touchkey_probe,
330 .remove = mpr_touchkey_remove,
331};
332
333module_i2c_driver(mpr_touchkey_driver);
334
335MODULE_LICENSE("GPL");
336MODULE_AUTHOR("Zhang Jiejing <jiejing.zhang@freescale.com>");
337MODULE_DESCRIPTION("Touch Key driver for Freescale MPR121 Chip");
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Touchkey driver for Freescale MPR121 Controllor
4 *
5 * Copyright (C) 2011 Freescale Semiconductor, Inc.
6 * Author: Zhang Jiejing <jiejing.zhang@freescale.com>
7 *
8 * Based on mcs_touchkey.c
9 */
10
11#include <linux/bitops.h>
12#include <linux/delay.h>
13#include <linux/i2c.h>
14#include <linux/input.h>
15#include <linux/interrupt.h>
16#include <linux/module.h>
17#include <linux/of.h>
18#include <linux/property.h>
19#include <linux/regulator/consumer.h>
20#include <linux/slab.h>
21
22/* Register definitions */
23#define ELE_TOUCH_STATUS_0_ADDR 0x0
24#define ELE_TOUCH_STATUS_1_ADDR 0X1
25#define MHD_RISING_ADDR 0x2b
26#define NHD_RISING_ADDR 0x2c
27#define NCL_RISING_ADDR 0x2d
28#define FDL_RISING_ADDR 0x2e
29#define MHD_FALLING_ADDR 0x2f
30#define NHD_FALLING_ADDR 0x30
31#define NCL_FALLING_ADDR 0x31
32#define FDL_FALLING_ADDR 0x32
33#define ELE0_TOUCH_THRESHOLD_ADDR 0x41
34#define ELE0_RELEASE_THRESHOLD_ADDR 0x42
35#define AFE_CONF_ADDR 0x5c
36#define FILTER_CONF_ADDR 0x5d
37
38/*
39 * ELECTRODE_CONF_ADDR: This register configures the number of
40 * enabled capacitance sensing inputs and its run/suspend mode.
41 */
42#define ELECTRODE_CONF_ADDR 0x5e
43#define ELECTRODE_CONF_QUICK_CHARGE 0x80
44#define AUTO_CONFIG_CTRL_ADDR 0x7b
45#define AUTO_CONFIG_USL_ADDR 0x7d
46#define AUTO_CONFIG_LSL_ADDR 0x7e
47#define AUTO_CONFIG_TL_ADDR 0x7f
48
49/* Threshold of touch/release trigger */
50#define TOUCH_THRESHOLD 0x08
51#define RELEASE_THRESHOLD 0x05
52/* Masks for touch and release triggers */
53#define TOUCH_STATUS_MASK 0xfff
54/* MPR121 has 12 keys */
55#define MPR121_MAX_KEY_COUNT 12
56
57struct mpr121_touchkey {
58 struct i2c_client *client;
59 struct input_dev *input_dev;
60 unsigned int statusbits;
61 unsigned int keycount;
62 u32 keycodes[MPR121_MAX_KEY_COUNT];
63};
64
65struct mpr121_init_register {
66 int addr;
67 u8 val;
68};
69
70static const struct mpr121_init_register init_reg_table[] = {
71 { MHD_RISING_ADDR, 0x1 },
72 { NHD_RISING_ADDR, 0x1 },
73 { MHD_FALLING_ADDR, 0x1 },
74 { NHD_FALLING_ADDR, 0x1 },
75 { NCL_FALLING_ADDR, 0xff },
76 { FDL_FALLING_ADDR, 0x02 },
77 { FILTER_CONF_ADDR, 0x04 },
78 { AFE_CONF_ADDR, 0x0b },
79 { AUTO_CONFIG_CTRL_ADDR, 0x0b },
80};
81
82static void mpr121_vdd_supply_disable(void *data)
83{
84 struct regulator *vdd_supply = data;
85
86 regulator_disable(vdd_supply);
87}
88
89static struct regulator *mpr121_vdd_supply_init(struct device *dev)
90{
91 struct regulator *vdd_supply;
92 int err;
93
94 vdd_supply = devm_regulator_get(dev, "vdd");
95 if (IS_ERR(vdd_supply)) {
96 dev_err(dev, "failed to get vdd regulator: %ld\n",
97 PTR_ERR(vdd_supply));
98 return vdd_supply;
99 }
100
101 err = regulator_enable(vdd_supply);
102 if (err) {
103 dev_err(dev, "failed to enable vdd regulator: %d\n", err);
104 return ERR_PTR(err);
105 }
106
107 err = devm_add_action(dev, mpr121_vdd_supply_disable, vdd_supply);
108 if (err) {
109 regulator_disable(vdd_supply);
110 dev_err(dev, "failed to add disable regulator action: %d\n",
111 err);
112 return ERR_PTR(err);
113 }
114
115 return vdd_supply;
116}
117
118static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id)
119{
120 struct mpr121_touchkey *mpr121 = dev_id;
121 struct i2c_client *client = mpr121->client;
122 struct input_dev *input = mpr121->input_dev;
123 unsigned long bit_changed;
124 unsigned int key_num;
125 int reg;
126
127 reg = i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_1_ADDR);
128 if (reg < 0) {
129 dev_err(&client->dev, "i2c read error [%d]\n", reg);
130 goto out;
131 }
132
133 reg <<= 8;
134 reg |= i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_0_ADDR);
135 if (reg < 0) {
136 dev_err(&client->dev, "i2c read error [%d]\n", reg);
137 goto out;
138 }
139
140 reg &= TOUCH_STATUS_MASK;
141 /* use old press bit to figure out which bit changed */
142 bit_changed = reg ^ mpr121->statusbits;
143 mpr121->statusbits = reg;
144 for_each_set_bit(key_num, &bit_changed, mpr121->keycount) {
145 unsigned int key_val, pressed;
146
147 pressed = reg & BIT(key_num);
148 key_val = mpr121->keycodes[key_num];
149
150 input_event(input, EV_MSC, MSC_SCAN, key_num);
151 input_report_key(input, key_val, pressed);
152
153 dev_dbg(&client->dev, "key %d %d %s\n", key_num, key_val,
154 pressed ? "pressed" : "released");
155
156 }
157 input_sync(input);
158
159out:
160 return IRQ_HANDLED;
161}
162
163static int mpr121_phys_init(struct mpr121_touchkey *mpr121,
164 struct i2c_client *client, int vdd_uv)
165{
166 const struct mpr121_init_register *reg;
167 unsigned char usl, lsl, tl, eleconf;
168 int i, t, vdd, ret;
169
170 /* Set up touch/release threshold for ele0-ele11 */
171 for (i = 0; i <= MPR121_MAX_KEY_COUNT; i++) {
172 t = ELE0_TOUCH_THRESHOLD_ADDR + (i * 2);
173 ret = i2c_smbus_write_byte_data(client, t, TOUCH_THRESHOLD);
174 if (ret < 0)
175 goto err_i2c_write;
176 ret = i2c_smbus_write_byte_data(client, t + 1,
177 RELEASE_THRESHOLD);
178 if (ret < 0)
179 goto err_i2c_write;
180 }
181
182 /* Set up init register */
183 for (i = 0; i < ARRAY_SIZE(init_reg_table); i++) {
184 reg = &init_reg_table[i];
185 ret = i2c_smbus_write_byte_data(client, reg->addr, reg->val);
186 if (ret < 0)
187 goto err_i2c_write;
188 }
189
190
191 /*
192 * Capacitance on sensing input varies and needs to be compensated.
193 * The internal MPR121-auto-configuration can do this if it's
194 * registers are set properly (based on vdd_uv).
195 */
196 vdd = vdd_uv / 1000;
197 usl = ((vdd - 700) * 256) / vdd;
198 lsl = (usl * 65) / 100;
199 tl = (usl * 90) / 100;
200 ret = i2c_smbus_write_byte_data(client, AUTO_CONFIG_USL_ADDR, usl);
201 ret |= i2c_smbus_write_byte_data(client, AUTO_CONFIG_LSL_ADDR, lsl);
202 ret |= i2c_smbus_write_byte_data(client, AUTO_CONFIG_TL_ADDR, tl);
203
204 /*
205 * Quick charge bit will let the capacitive charge to ready
206 * state quickly, or the buttons may not function after system
207 * boot.
208 */
209 eleconf = mpr121->keycount | ELECTRODE_CONF_QUICK_CHARGE;
210 ret |= i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR,
211 eleconf);
212 if (ret != 0)
213 goto err_i2c_write;
214
215 dev_dbg(&client->dev, "set up with %x keys.\n", mpr121->keycount);
216
217 return 0;
218
219err_i2c_write:
220 dev_err(&client->dev, "i2c write error: %d\n", ret);
221 return ret;
222}
223
224static int mpr_touchkey_probe(struct i2c_client *client,
225 const struct i2c_device_id *id)
226{
227 struct device *dev = &client->dev;
228 struct regulator *vdd_supply;
229 int vdd_uv;
230 struct mpr121_touchkey *mpr121;
231 struct input_dev *input_dev;
232 int error;
233 int i;
234
235 if (!client->irq) {
236 dev_err(dev, "irq number should not be zero\n");
237 return -EINVAL;
238 }
239
240 vdd_supply = mpr121_vdd_supply_init(dev);
241 if (IS_ERR(vdd_supply))
242 return PTR_ERR(vdd_supply);
243
244 vdd_uv = regulator_get_voltage(vdd_supply);
245
246 mpr121 = devm_kzalloc(dev, sizeof(*mpr121), GFP_KERNEL);
247 if (!mpr121)
248 return -ENOMEM;
249
250 input_dev = devm_input_allocate_device(dev);
251 if (!input_dev)
252 return -ENOMEM;
253
254 mpr121->client = client;
255 mpr121->input_dev = input_dev;
256 mpr121->keycount = device_property_count_u32(dev, "linux,keycodes");
257 if (mpr121->keycount > MPR121_MAX_KEY_COUNT) {
258 dev_err(dev, "too many keys defined (%d)\n", mpr121->keycount);
259 return -EINVAL;
260 }
261
262 error = device_property_read_u32_array(dev, "linux,keycodes",
263 mpr121->keycodes,
264 mpr121->keycount);
265 if (error) {
266 dev_err(dev,
267 "failed to read linux,keycode property: %d\n", error);
268 return error;
269 }
270
271 input_dev->name = "Freescale MPR121 Touchkey";
272 input_dev->id.bustype = BUS_I2C;
273 input_dev->dev.parent = dev;
274 if (device_property_read_bool(dev, "autorepeat"))
275 __set_bit(EV_REP, input_dev->evbit);
276 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
277
278 input_dev->keycode = mpr121->keycodes;
279 input_dev->keycodesize = sizeof(mpr121->keycodes[0]);
280 input_dev->keycodemax = mpr121->keycount;
281
282 for (i = 0; i < mpr121->keycount; i++)
283 input_set_capability(input_dev, EV_KEY, mpr121->keycodes[i]);
284
285 error = mpr121_phys_init(mpr121, client, vdd_uv);
286 if (error) {
287 dev_err(dev, "Failed to init register\n");
288 return error;
289 }
290
291 error = devm_request_threaded_irq(dev, client->irq, NULL,
292 mpr_touchkey_interrupt,
293 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
294 dev->driver->name, mpr121);
295 if (error) {
296 dev_err(dev, "Failed to register interrupt\n");
297 return error;
298 }
299
300 error = input_register_device(input_dev);
301 if (error)
302 return error;
303
304 i2c_set_clientdata(client, mpr121);
305 device_init_wakeup(dev,
306 device_property_read_bool(dev, "wakeup-source"));
307
308 return 0;
309}
310
311static int __maybe_unused mpr_suspend(struct device *dev)
312{
313 struct i2c_client *client = to_i2c_client(dev);
314
315 if (device_may_wakeup(&client->dev))
316 enable_irq_wake(client->irq);
317
318 i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR, 0x00);
319
320 return 0;
321}
322
323static int __maybe_unused mpr_resume(struct device *dev)
324{
325 struct i2c_client *client = to_i2c_client(dev);
326 struct mpr121_touchkey *mpr121 = i2c_get_clientdata(client);
327
328 if (device_may_wakeup(&client->dev))
329 disable_irq_wake(client->irq);
330
331 i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR,
332 mpr121->keycount);
333
334 return 0;
335}
336
337static SIMPLE_DEV_PM_OPS(mpr121_touchkey_pm_ops, mpr_suspend, mpr_resume);
338
339static const struct i2c_device_id mpr121_id[] = {
340 { "mpr121_touchkey", 0 },
341 { }
342};
343MODULE_DEVICE_TABLE(i2c, mpr121_id);
344
345#ifdef CONFIG_OF
346static const struct of_device_id mpr121_touchkey_dt_match_table[] = {
347 { .compatible = "fsl,mpr121-touchkey" },
348 { },
349};
350MODULE_DEVICE_TABLE(of, mpr121_touchkey_dt_match_table);
351#endif
352
353static struct i2c_driver mpr_touchkey_driver = {
354 .driver = {
355 .name = "mpr121",
356 .pm = &mpr121_touchkey_pm_ops,
357 .of_match_table = of_match_ptr(mpr121_touchkey_dt_match_table),
358 },
359 .id_table = mpr121_id,
360 .probe = mpr_touchkey_probe,
361};
362
363module_i2c_driver(mpr_touchkey_driver);
364
365MODULE_LICENSE("GPL");
366MODULE_AUTHOR("Zhang Jiejing <jiejing.zhang@freescale.com>");
367MODULE_DESCRIPTION("Touch Key driver for Freescale MPR121 Chip");