hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/input/keyboard/mpr121_touchkey.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Touchkey driver for Freescale MPR121 Controllor
34 *
....@@ -5,11 +6,6 @@
56 * Author: Zhang Jiejing <jiejing.zhang@freescale.com>
67 *
78 * 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
- *
139 */
1410
1511 #include <linux/bitops.h>
....@@ -57,6 +53,9 @@
5753 #define TOUCH_STATUS_MASK 0xfff
5854 /* MPR121 has 12 keys */
5955 #define MPR121_MAX_KEY_COUNT 12
56
+
57
+#define MPR121_MIN_POLL_INTERVAL 10
58
+#define MPR121_MAX_POLL_INTERVAL 200
6059
6160 struct mpr121_touchkey {
6261 struct i2c_client *client;
....@@ -119,11 +118,11 @@
119118 return vdd_supply;
120119 }
121120
122
-static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id)
121
+static void mpr_touchkey_report(struct input_dev *dev)
123122 {
124
- struct mpr121_touchkey *mpr121 = dev_id;
125
- struct i2c_client *client = mpr121->client;
123
+ struct mpr121_touchkey *mpr121 = input_get_drvdata(dev);
126124 struct input_dev *input = mpr121->input_dev;
125
+ struct i2c_client *client = mpr121->client;
127126 unsigned long bit_changed;
128127 unsigned int key_num;
129128 int reg;
....@@ -131,14 +130,14 @@
131130 reg = i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_1_ADDR);
132131 if (reg < 0) {
133132 dev_err(&client->dev, "i2c read error [%d]\n", reg);
134
- goto out;
133
+ return;
135134 }
136135
137136 reg <<= 8;
138137 reg |= i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_0_ADDR);
139138 if (reg < 0) {
140139 dev_err(&client->dev, "i2c read error [%d]\n", reg);
141
- goto out;
140
+ return;
142141 }
143142
144143 reg &= TOUCH_STATUS_MASK;
....@@ -159,8 +158,14 @@
159158
160159 }
161160 input_sync(input);
161
+}
162162
163
-out:
163
+static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id)
164
+{
165
+ struct mpr121_touchkey *mpr121 = dev_id;
166
+
167
+ mpr_touchkey_report(mpr121->input_dev);
168
+
164169 return IRQ_HANDLED;
165170 }
166171
....@@ -233,13 +238,9 @@
233238 int vdd_uv;
234239 struct mpr121_touchkey *mpr121;
235240 struct input_dev *input_dev;
241
+ u32 poll_interval = 0;
236242 int error;
237243 int i;
238
-
239
- if (!client->irq) {
240
- dev_err(dev, "irq number should not be zero\n");
241
- return -EINVAL;
242
- }
243244
244245 vdd_supply = mpr121_vdd_supply_init(dev);
245246 if (IS_ERR(vdd_supply))
....@@ -257,8 +258,7 @@
257258
258259 mpr121->client = client;
259260 mpr121->input_dev = input_dev;
260
- mpr121->keycount = device_property_read_u32_array(dev, "linux,keycodes",
261
- NULL, 0);
261
+ mpr121->keycount = device_property_count_u32(dev, "linux,keycodes");
262262 if (mpr121->keycount > MPR121_MAX_KEY_COUNT) {
263263 dev_err(dev, "too many keys defined (%d)\n", mpr121->keycount);
264264 return -EINVAL;
....@@ -279,6 +279,7 @@
279279 if (device_property_read_bool(dev, "autorepeat"))
280280 __set_bit(EV_REP, input_dev->evbit);
281281 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
282
+ input_set_drvdata(input_dev, mpr121);
282283
283284 input_dev->keycode = mpr121->keycodes;
284285 input_dev->keycodesize = sizeof(mpr121->keycodes[0]);
....@@ -293,13 +294,40 @@
293294 return error;
294295 }
295296
296
- error = devm_request_threaded_irq(dev, client->irq, NULL,
297
- mpr_touchkey_interrupt,
298
- IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
299
- dev->driver->name, mpr121);
300
- if (error) {
301
- dev_err(dev, "Failed to register interrupt\n");
302
- return error;
297
+ device_property_read_u32(dev, "poll-interval", &poll_interval);
298
+
299
+ if (client->irq) {
300
+ error = devm_request_threaded_irq(dev, client->irq, NULL,
301
+ mpr_touchkey_interrupt,
302
+ IRQF_TRIGGER_FALLING |
303
+ IRQF_ONESHOT,
304
+ dev->driver->name, mpr121);
305
+ if (error) {
306
+ dev_err(dev, "Failed to register interrupt\n");
307
+ return error;
308
+ }
309
+ } else if (poll_interval) {
310
+ if (poll_interval < MPR121_MIN_POLL_INTERVAL)
311
+ return -EINVAL;
312
+
313
+ if (poll_interval > MPR121_MAX_POLL_INTERVAL)
314
+ return -EINVAL;
315
+
316
+ error = input_setup_polling(input_dev, mpr_touchkey_report);
317
+ if (error) {
318
+ dev_err(dev, "Failed to setup polling\n");
319
+ return error;
320
+ }
321
+
322
+ input_set_poll_interval(input_dev, poll_interval);
323
+ input_set_min_poll_interval(input_dev,
324
+ MPR121_MIN_POLL_INTERVAL);
325
+ input_set_max_poll_interval(input_dev,
326
+ MPR121_MAX_POLL_INTERVAL);
327
+ } else {
328
+ dev_err(dev,
329
+ "invalid IRQ number and polling not configured\n");
330
+ return -EINVAL;
303331 }
304332
305333 error = input_register_device(input_dev);