1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Input driver for Microchip CAP11xx based capacitive touch sensors
4 *
5 * (c) 2014 Daniel Mack <linux@zonque.org>
6 */
7
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/interrupt.h>
11 #include <linux/input.h>
12 #include <linux/leds.h>
13 #include <linux/of.h>
14 #include <linux/regmap.h>
15 #include <linux/i2c.h>
16 #include <linux/gpio/consumer.h>
17 #include <linux/bitfield.h>
18
19 #define CAP11XX_REG_MAIN_CONTROL 0x00
20 #define CAP11XX_REG_MAIN_CONTROL_GAIN_SHIFT (6)
21 #define CAP11XX_REG_MAIN_CONTROL_GAIN_MASK (0xc0)
22 #define CAP11XX_REG_MAIN_CONTROL_DLSEEP BIT(4)
23 #define CAP11XX_REG_GENERAL_STATUS 0x02
24 #define CAP11XX_REG_SENSOR_INPUT 0x03
25 #define CAP11XX_REG_NOISE_FLAG_STATUS 0x0a
26 #define CAP11XX_REG_SENOR_DELTA(X) (0x10 + (X))
27 #define CAP11XX_REG_SENSITIVITY_CONTROL 0x1f
28 #define CAP11XX_REG_SENSITIVITY_CONTROL_DELTA_SENSE_MASK 0x70
29 #define CAP11XX_REG_CONFIG 0x20
30 #define CAP11XX_REG_SENSOR_ENABLE 0x21
31 #define CAP11XX_REG_SENSOR_CONFIG 0x22
32 #define CAP11XX_REG_SENSOR_CONFIG2 0x23
33 #define CAP11XX_REG_SAMPLING_CONFIG 0x24
34 #define CAP11XX_REG_CALIBRATION 0x26
35 #define CAP11XX_REG_INT_ENABLE 0x27
36 #define CAP11XX_REG_REPEAT_RATE 0x28
37 #define CAP11XX_REG_SIGNAL_GUARD_ENABLE 0x29
38 #define CAP11XX_REG_MT_CONFIG 0x2a
39 #define CAP11XX_REG_MT_PATTERN_CONFIG 0x2b
40 #define CAP11XX_REG_MT_PATTERN 0x2d
41 #define CAP11XX_REG_RECALIB_CONFIG 0x2f
42 #define CAP11XX_REG_SENSOR_THRESH(X) (0x30 + (X))
43 #define CAP11XX_REG_SENSOR_NOISE_THRESH 0x38
44 #define CAP11XX_REG_STANDBY_CHANNEL 0x40
45 #define CAP11XX_REG_STANDBY_CONFIG 0x41
46 #define CAP11XX_REG_STANDBY_SENSITIVITY 0x42
47 #define CAP11XX_REG_STANDBY_THRESH 0x43
48 #define CAP11XX_REG_CONFIG2 0x44
49 #define CAP11XX_REG_CONFIG2_ALT_POL BIT(6)
50 #define CAP11XX_REG_SENSOR_BASE_CNT(X) (0x50 + (X))
51 #define CAP11XX_REG_LED_POLARITY 0x73
52 #define CAP11XX_REG_LED_OUTPUT_CONTROL 0x74
53 #define CAP11XX_REG_CALIB_SENSITIVITY_CONFIG 0x80
54 #define CAP11XX_REG_CALIB_SENSITIVITY_CONFIG2 0x81
55
56 #define CAP11XX_REG_LED_DUTY_CYCLE_1 0x90
57 #define CAP11XX_REG_LED_DUTY_CYCLE_2 0x91
58 #define CAP11XX_REG_LED_DUTY_CYCLE_3 0x92
59 #define CAP11XX_REG_LED_DUTY_CYCLE_4 0x93
60
61 #define CAP11XX_REG_LED_DUTY_MIN_MASK (0x0f)
62 #define CAP11XX_REG_LED_DUTY_MIN_MASK_SHIFT (0)
63 #define CAP11XX_REG_LED_DUTY_MAX_MASK (0xf0)
64 #define CAP11XX_REG_LED_DUTY_MAX_MASK_SHIFT (4)
65 #define CAP11XX_REG_LED_DUTY_MAX_VALUE (15)
66
67 #define CAP11XX_REG_SENSOR_CALIB (0xb1 + (X))
68 #define CAP11XX_REG_SENSOR_CALIB_LSB1 0xb9
69 #define CAP11XX_REG_SENSOR_CALIB_LSB2 0xba
70 #define CAP11XX_REG_PRODUCT_ID 0xfd
71 #define CAP11XX_REG_MANUFACTURER_ID 0xfe
72 #define CAP11XX_REG_REVISION 0xff
73
74 #define CAP11XX_MANUFACTURER_ID 0x5d
75
76 #ifdef CONFIG_LEDS_CLASS
77 struct cap11xx_led {
78 struct cap11xx_priv *priv;
79 struct led_classdev cdev;
80 u32 reg;
81 };
82 #endif
83
84 struct cap11xx_priv {
85 struct regmap *regmap;
86 struct device *dev;
87 struct input_dev *idev;
88 const struct cap11xx_hw_model *model;
89
90 struct cap11xx_led *leds;
91 int num_leds;
92
93 /* config */
94 u8 analog_gain;
95 u8 sensitivity_delta_sense;
96 u8 signal_guard_inputs_mask;
97 u32 thresholds[8];
98 u32 calib_sensitivities[8];
99 u32 keycodes[];
100 };
101
102 struct cap11xx_hw_model {
103 u8 product_id;
104 unsigned int num_channels;
105 unsigned int num_leds;
106 bool has_gain;
107 bool has_irq_config;
108 bool has_sensitivity_control;
109 bool has_signal_guard;
110 };
111
112 static const struct reg_default cap11xx_reg_defaults[] = {
113 { CAP11XX_REG_MAIN_CONTROL, 0x00 },
114 { CAP11XX_REG_GENERAL_STATUS, 0x00 },
115 { CAP11XX_REG_SENSOR_INPUT, 0x00 },
116 { CAP11XX_REG_NOISE_FLAG_STATUS, 0x00 },
117 { CAP11XX_REG_SENSITIVITY_CONTROL, 0x2f },
118 { CAP11XX_REG_CONFIG, 0x20 },
119 { CAP11XX_REG_SENSOR_ENABLE, 0x3f },
120 { CAP11XX_REG_SENSOR_CONFIG, 0xa4 },
121 { CAP11XX_REG_SENSOR_CONFIG2, 0x07 },
122 { CAP11XX_REG_SAMPLING_CONFIG, 0x39 },
123 { CAP11XX_REG_CALIBRATION, 0x00 },
124 { CAP11XX_REG_INT_ENABLE, 0x3f },
125 { CAP11XX_REG_REPEAT_RATE, 0x3f },
126 { CAP11XX_REG_MT_CONFIG, 0x80 },
127 { CAP11XX_REG_MT_PATTERN_CONFIG, 0x00 },
128 { CAP11XX_REG_MT_PATTERN, 0x3f },
129 { CAP11XX_REG_RECALIB_CONFIG, 0x8a },
130 { CAP11XX_REG_SENSOR_THRESH(0), 0x40 },
131 { CAP11XX_REG_SENSOR_THRESH(1), 0x40 },
132 { CAP11XX_REG_SENSOR_THRESH(2), 0x40 },
133 { CAP11XX_REG_SENSOR_THRESH(3), 0x40 },
134 { CAP11XX_REG_SENSOR_THRESH(4), 0x40 },
135 { CAP11XX_REG_SENSOR_THRESH(5), 0x40 },
136 { CAP11XX_REG_SENSOR_NOISE_THRESH, 0x01 },
137 { CAP11XX_REG_STANDBY_CHANNEL, 0x00 },
138 { CAP11XX_REG_STANDBY_CONFIG, 0x39 },
139 { CAP11XX_REG_STANDBY_SENSITIVITY, 0x02 },
140 { CAP11XX_REG_STANDBY_THRESH, 0x40 },
141 { CAP11XX_REG_CONFIG2, 0x40 },
142 { CAP11XX_REG_LED_POLARITY, 0x00 },
143 { CAP11XX_REG_SENSOR_CALIB_LSB1, 0x00 },
144 { CAP11XX_REG_SENSOR_CALIB_LSB2, 0x00 },
145 };
146
cap11xx_volatile_reg(struct device * dev,unsigned int reg)147 static bool cap11xx_volatile_reg(struct device *dev, unsigned int reg)
148 {
149 switch (reg) {
150 case CAP11XX_REG_MAIN_CONTROL:
151 case CAP11XX_REG_SENSOR_INPUT:
152 case CAP11XX_REG_SENOR_DELTA(0):
153 case CAP11XX_REG_SENOR_DELTA(1):
154 case CAP11XX_REG_SENOR_DELTA(2):
155 case CAP11XX_REG_SENOR_DELTA(3):
156 case CAP11XX_REG_SENOR_DELTA(4):
157 case CAP11XX_REG_SENOR_DELTA(5):
158 return true;
159 }
160
161 return false;
162 }
163
164 static const struct regmap_config cap11xx_regmap_config = {
165 .reg_bits = 8,
166 .val_bits = 8,
167
168 .max_register = CAP11XX_REG_REVISION,
169 .reg_defaults = cap11xx_reg_defaults,
170
171 .num_reg_defaults = ARRAY_SIZE(cap11xx_reg_defaults),
172 .cache_type = REGCACHE_MAPLE,
173 .volatile_reg = cap11xx_volatile_reg,
174 };
175
cap11xx_write_calib_sens_config_1(struct cap11xx_priv * priv)176 static int cap11xx_write_calib_sens_config_1(struct cap11xx_priv *priv)
177 {
178 return regmap_write(priv->regmap,
179 CAP11XX_REG_CALIB_SENSITIVITY_CONFIG,
180 (priv->calib_sensitivities[3] << 6) |
181 (priv->calib_sensitivities[2] << 4) |
182 (priv->calib_sensitivities[1] << 2) |
183 priv->calib_sensitivities[0]);
184 }
185
cap11xx_write_calib_sens_config_2(struct cap11xx_priv * priv)186 static int cap11xx_write_calib_sens_config_2(struct cap11xx_priv *priv)
187 {
188 return regmap_write(priv->regmap,
189 CAP11XX_REG_CALIB_SENSITIVITY_CONFIG2,
190 (priv->calib_sensitivities[7] << 6) |
191 (priv->calib_sensitivities[6] << 4) |
192 (priv->calib_sensitivities[5] << 2) |
193 priv->calib_sensitivities[4]);
194 }
195
cap11xx_init_keys(struct cap11xx_priv * priv)196 static int cap11xx_init_keys(struct cap11xx_priv *priv)
197 {
198 struct device_node *node = priv->dev->of_node;
199 struct device *dev = priv->dev;
200 int i, error;
201 u32 u32_val;
202
203 if (!node) {
204 dev_err(dev, "Corresponding DT entry is not available\n");
205 return -ENODEV;
206 }
207
208 if (!of_property_read_u32(node, "microchip,sensor-gain", &u32_val)) {
209 if (!priv->model->has_gain) {
210 dev_warn(dev,
211 "This model doesn't support 'sensor-gain'\n");
212 } else if (is_power_of_2(u32_val) && u32_val <= 8) {
213 priv->analog_gain = (u8)ilog2(u32_val);
214
215 error = regmap_update_bits(priv->regmap,
216 CAP11XX_REG_MAIN_CONTROL,
217 CAP11XX_REG_MAIN_CONTROL_GAIN_MASK,
218 priv->analog_gain << CAP11XX_REG_MAIN_CONTROL_GAIN_SHIFT);
219 if (error)
220 return error;
221 } else {
222 dev_err(dev, "Invalid sensor-gain value %u\n", u32_val);
223 return -EINVAL;
224 }
225 }
226
227 if (of_property_read_bool(node, "microchip,irq-active-high")) {
228 if (priv->model->has_irq_config) {
229 error = regmap_update_bits(priv->regmap,
230 CAP11XX_REG_CONFIG2,
231 CAP11XX_REG_CONFIG2_ALT_POL,
232 0);
233 if (error)
234 return error;
235 } else {
236 dev_warn(dev,
237 "This model doesn't support 'irq-active-high'\n");
238 }
239 }
240
241 if (!of_property_read_u32(node, "microchip,sensitivity-delta-sense", &u32_val)) {
242 if (!is_power_of_2(u32_val) || u32_val > 128) {
243 dev_err(dev, "Invalid sensitivity-delta-sense value %u\n", u32_val);
244 return -EINVAL;
245 }
246
247 priv->sensitivity_delta_sense = (u8)ilog2(u32_val);
248 u32_val = ~(FIELD_PREP(CAP11XX_REG_SENSITIVITY_CONTROL_DELTA_SENSE_MASK,
249 priv->sensitivity_delta_sense));
250
251 error = regmap_update_bits(priv->regmap,
252 CAP11XX_REG_SENSITIVITY_CONTROL,
253 CAP11XX_REG_SENSITIVITY_CONTROL_DELTA_SENSE_MASK,
254 u32_val);
255 if (error)
256 return error;
257 }
258
259 if (!of_property_read_u32_array(node, "microchip,input-threshold",
260 priv->thresholds, priv->model->num_channels)) {
261 for (i = 0; i < priv->model->num_channels; i++) {
262 if (priv->thresholds[i] > 127) {
263 dev_err(dev, "Invalid input-threshold value %u\n",
264 priv->thresholds[i]);
265 return -EINVAL;
266 }
267
268 error = regmap_write(priv->regmap,
269 CAP11XX_REG_SENSOR_THRESH(i),
270 priv->thresholds[i]);
271 if (error)
272 return error;
273 }
274 }
275
276 if (!of_property_read_u32_array(node, "microchip,calib-sensitivity",
277 priv->calib_sensitivities,
278 priv->model->num_channels)) {
279 if (priv->model->has_sensitivity_control) {
280 for (i = 0; i < priv->model->num_channels; i++) {
281 if (!is_power_of_2(priv->calib_sensitivities[i]) ||
282 priv->calib_sensitivities[i] > 4) {
283 dev_err(dev, "Invalid calib-sensitivity value %u\n",
284 priv->calib_sensitivities[i]);
285 return -EINVAL;
286 }
287 priv->calib_sensitivities[i] = ilog2(priv->calib_sensitivities[i]);
288 }
289
290 error = cap11xx_write_calib_sens_config_1(priv);
291 if (error)
292 return error;
293
294 if (priv->model->num_channels > 4) {
295 error = cap11xx_write_calib_sens_config_2(priv);
296 if (error)
297 return error;
298 }
299 } else {
300 dev_warn(dev,
301 "This model doesn't support 'calib-sensitivity'\n");
302 }
303 }
304
305 for (i = 0; i < priv->model->num_channels; i++) {
306 if (!of_property_read_u32_index(node, "microchip,signal-guard",
307 i, &u32_val)) {
308 if (u32_val > 1)
309 return -EINVAL;
310 if (u32_val)
311 priv->signal_guard_inputs_mask |= 0x01 << i;
312 }
313 }
314
315 if (priv->signal_guard_inputs_mask) {
316 if (priv->model->has_signal_guard) {
317 error = regmap_write(priv->regmap,
318 CAP11XX_REG_SIGNAL_GUARD_ENABLE,
319 priv->signal_guard_inputs_mask);
320 if (error)
321 return error;
322 } else {
323 dev_warn(dev,
324 "This model doesn't support 'signal-guard'\n");
325 }
326 }
327
328 /* Provide some useful defaults */
329 for (i = 0; i < priv->model->num_channels; i++)
330 priv->keycodes[i] = KEY_A + i;
331
332 of_property_read_u32_array(node, "linux,keycodes",
333 priv->keycodes, priv->model->num_channels);
334
335 /* Disable autorepeat. The Linux input system has its own handling. */
336 error = regmap_write(priv->regmap, CAP11XX_REG_REPEAT_RATE, 0);
337 if (error)
338 return error;
339
340 return 0;
341 }
342
cap11xx_thread_func(int irq_num,void * data)343 static irqreturn_t cap11xx_thread_func(int irq_num, void *data)
344 {
345 struct cap11xx_priv *priv = data;
346 unsigned int status;
347 int ret, i;
348
349 /*
350 * Deassert interrupt. This needs to be done before reading the status
351 * registers, which will not carry valid values otherwise.
352 */
353 ret = regmap_update_bits(priv->regmap, CAP11XX_REG_MAIN_CONTROL, 1, 0);
354 if (ret < 0)
355 goto out;
356
357 ret = regmap_read(priv->regmap, CAP11XX_REG_SENSOR_INPUT, &status);
358 if (ret < 0)
359 goto out;
360
361 for (i = 0; i < priv->idev->keycodemax; i++)
362 input_report_key(priv->idev, priv->keycodes[i],
363 status & (1 << i));
364
365 input_sync(priv->idev);
366
367 out:
368 return IRQ_HANDLED;
369 }
370
cap11xx_set_sleep(struct cap11xx_priv * priv,bool sleep)371 static int cap11xx_set_sleep(struct cap11xx_priv *priv, bool sleep)
372 {
373 /*
374 * DLSEEP mode will turn off all LEDS, prevent this
375 */
376 if (IS_ENABLED(CONFIG_LEDS_CLASS) && priv->num_leds)
377 return 0;
378
379 return regmap_update_bits(priv->regmap, CAP11XX_REG_MAIN_CONTROL,
380 CAP11XX_REG_MAIN_CONTROL_DLSEEP,
381 sleep ? CAP11XX_REG_MAIN_CONTROL_DLSEEP : 0);
382 }
383
cap11xx_input_open(struct input_dev * idev)384 static int cap11xx_input_open(struct input_dev *idev)
385 {
386 struct cap11xx_priv *priv = input_get_drvdata(idev);
387
388 return cap11xx_set_sleep(priv, false);
389 }
390
cap11xx_input_close(struct input_dev * idev)391 static void cap11xx_input_close(struct input_dev *idev)
392 {
393 struct cap11xx_priv *priv = input_get_drvdata(idev);
394
395 cap11xx_set_sleep(priv, true);
396 }
397
398 #ifdef CONFIG_LEDS_CLASS
cap11xx_led_set(struct led_classdev * cdev,enum led_brightness value)399 static int cap11xx_led_set(struct led_classdev *cdev,
400 enum led_brightness value)
401 {
402 struct cap11xx_led *led = container_of(cdev, struct cap11xx_led, cdev);
403 struct cap11xx_priv *priv = led->priv;
404
405 /*
406 * All LEDs share the same duty cycle as this is a HW
407 * limitation. Brightness levels per LED are either
408 * 0 (OFF) and 1 (ON).
409 */
410 return regmap_update_bits(priv->regmap,
411 CAP11XX_REG_LED_OUTPUT_CONTROL,
412 BIT(led->reg),
413 value ? BIT(led->reg) : 0);
414 }
415
cap11xx_init_leds(struct device * dev,struct cap11xx_priv * priv,int num_leds)416 static int cap11xx_init_leds(struct device *dev,
417 struct cap11xx_priv *priv, int num_leds)
418 {
419 struct device_node *node = dev->of_node;
420 struct cap11xx_led *led;
421 int cnt = of_get_child_count(node);
422 int error;
423
424 if (!num_leds || !cnt)
425 return 0;
426
427 if (cnt > num_leds)
428 return -EINVAL;
429
430 led = devm_kcalloc(dev, cnt, sizeof(struct cap11xx_led), GFP_KERNEL);
431 if (!led)
432 return -ENOMEM;
433
434 priv->leds = led;
435
436 error = regmap_update_bits(priv->regmap,
437 CAP11XX_REG_LED_OUTPUT_CONTROL, 0xff, 0);
438 if (error)
439 return error;
440
441 error = regmap_update_bits(priv->regmap, CAP11XX_REG_LED_DUTY_CYCLE_4,
442 CAP11XX_REG_LED_DUTY_MAX_MASK,
443 CAP11XX_REG_LED_DUTY_MAX_VALUE <<
444 CAP11XX_REG_LED_DUTY_MAX_MASK_SHIFT);
445 if (error)
446 return error;
447
448 for_each_child_of_node_scoped(node, child) {
449 u32 reg;
450
451 led->cdev.name =
452 of_get_property(child, "label", NULL) ? : child->name;
453 led->cdev.default_trigger =
454 of_get_property(child, "linux,default-trigger", NULL);
455 led->cdev.flags = 0;
456 led->cdev.brightness_set_blocking = cap11xx_led_set;
457 led->cdev.max_brightness = 1;
458 led->cdev.brightness = LED_OFF;
459
460 error = of_property_read_u32(child, "reg", ®);
461 if (error != 0 || reg >= num_leds)
462 return -EINVAL;
463
464 led->reg = reg;
465 led->priv = priv;
466
467 error = devm_led_classdev_register(dev, &led->cdev);
468 if (error)
469 return error;
470
471 priv->num_leds++;
472 led++;
473 }
474
475 return 0;
476 }
477 #else
cap11xx_init_leds(struct device * dev,struct cap11xx_priv * priv,int num_leds)478 static int cap11xx_init_leds(struct device *dev,
479 struct cap11xx_priv *priv, int num_leds)
480 {
481 return 0;
482 }
483 #endif
484
cap11xx_i2c_probe(struct i2c_client * i2c_client)485 static int cap11xx_i2c_probe(struct i2c_client *i2c_client)
486 {
487 const struct i2c_device_id *id;
488 const struct cap11xx_hw_model *cap;
489 struct device *dev = &i2c_client->dev;
490 struct cap11xx_priv *priv;
491 int i, error;
492 unsigned int val, rev;
493
494 id = i2c_client_get_device_id(i2c_client);
495 cap = i2c_get_match_data(i2c_client);
496 if (!id || !cap || !cap->num_channels) {
497 dev_err(dev, "Invalid device configuration\n");
498 return -EINVAL;
499 }
500
501 priv = devm_kzalloc(dev,
502 struct_size(priv, keycodes, cap->num_channels),
503 GFP_KERNEL);
504 if (!priv)
505 return -ENOMEM;
506
507 priv->dev = dev;
508
509 priv->regmap = devm_regmap_init_i2c(i2c_client, &cap11xx_regmap_config);
510 if (IS_ERR(priv->regmap))
511 return PTR_ERR(priv->regmap);
512
513 error = regmap_read(priv->regmap, CAP11XX_REG_PRODUCT_ID, &val);
514 if (error)
515 return error;
516
517 if (val != cap->product_id) {
518 dev_err(dev, "Product ID: Got 0x%02x, expected 0x%02x\n",
519 val, cap->product_id);
520 return -ENXIO;
521 }
522
523 error = regmap_read(priv->regmap, CAP11XX_REG_MANUFACTURER_ID, &val);
524 if (error)
525 return error;
526
527 if (val != CAP11XX_MANUFACTURER_ID) {
528 dev_err(dev, "Manufacturer ID: Got 0x%02x, expected 0x%02x\n",
529 val, CAP11XX_MANUFACTURER_ID);
530 return -ENXIO;
531 }
532
533 error = regmap_read(priv->regmap, CAP11XX_REG_REVISION, &rev);
534 if (error < 0)
535 return error;
536
537 dev_info(dev, "CAP11XX detected, model %s, revision 0x%02x\n",
538 id->name, rev);
539
540 priv->model = cap;
541
542 dev_info(dev, "CAP11XX device detected, model %s, revision 0x%02x\n",
543 id->name, rev);
544
545 error = cap11xx_init_keys(priv);
546 if (error)
547 return error;
548
549 priv->idev = devm_input_allocate_device(dev);
550 if (!priv->idev)
551 return -ENOMEM;
552
553 priv->idev->name = "CAP11XX capacitive touch sensor";
554 priv->idev->id.bustype = BUS_I2C;
555 priv->idev->evbit[0] = BIT_MASK(EV_KEY);
556
557 if (of_property_read_bool(dev->of_node, "autorepeat"))
558 __set_bit(EV_REP, priv->idev->evbit);
559
560 for (i = 0; i < cap->num_channels; i++)
561 __set_bit(priv->keycodes[i], priv->idev->keybit);
562
563 __clear_bit(KEY_RESERVED, priv->idev->keybit);
564
565 priv->idev->keycode = priv->keycodes;
566 priv->idev->keycodesize = sizeof(priv->keycodes[0]);
567 priv->idev->keycodemax = cap->num_channels;
568
569 priv->idev->id.vendor = CAP11XX_MANUFACTURER_ID;
570 priv->idev->id.product = cap->product_id;
571 priv->idev->id.version = rev;
572
573 priv->idev->open = cap11xx_input_open;
574 priv->idev->close = cap11xx_input_close;
575
576 error = cap11xx_init_leds(dev, priv, cap->num_leds);
577 if (error)
578 return error;
579
580 input_set_drvdata(priv->idev, priv);
581
582 /*
583 * Put the device in deep sleep mode for now.
584 * ->open() will bring it back once the it is actually needed.
585 */
586 cap11xx_set_sleep(priv, true);
587
588 error = input_register_device(priv->idev);
589 if (error)
590 return error;
591
592 error = devm_request_threaded_irq(dev, i2c_client->irq,
593 NULL, cap11xx_thread_func,
594 IRQF_ONESHOT, dev_name(dev), priv);
595 if (error)
596 return error;
597
598 return 0;
599 }
600
601 static const struct cap11xx_hw_model cap1106_model = {
602 .product_id = 0x55, .num_channels = 6, .num_leds = 0,
603 .has_gain = true,
604 .has_irq_config = true,
605 };
606
607 static const struct cap11xx_hw_model cap1126_model = {
608 .product_id = 0x53, .num_channels = 6, .num_leds = 2,
609 .has_gain = true,
610 .has_irq_config = true,
611 };
612
613 static const struct cap11xx_hw_model cap1188_model = {
614 .product_id = 0x50, .num_channels = 8, .num_leds = 8,
615 .has_gain = true,
616 .has_irq_config = true,
617 };
618
619 static const struct cap11xx_hw_model cap1203_model = {
620 .product_id = 0x6d, .num_channels = 3, .num_leds = 0,
621 };
622
623 static const struct cap11xx_hw_model cap1206_model = {
624 .product_id = 0x67, .num_channels = 6, .num_leds = 0,
625 };
626
627 static const struct cap11xx_hw_model cap1293_model = {
628 .product_id = 0x6f, .num_channels = 3, .num_leds = 0,
629 .has_gain = true,
630 .has_sensitivity_control = true,
631 .has_signal_guard = true,
632 };
633
634 static const struct cap11xx_hw_model cap1298_model = {
635 .product_id = 0x71, .num_channels = 8, .num_leds = 0,
636 .has_gain = true,
637 .has_sensitivity_control = true,
638 .has_signal_guard = true,
639 };
640
641 static const struct of_device_id cap11xx_dt_ids[] = {
642 { .compatible = "microchip,cap1106", .data = &cap1106_model },
643 { .compatible = "microchip,cap1126", .data = &cap1126_model },
644 { .compatible = "microchip,cap1188", .data = &cap1188_model },
645 { .compatible = "microchip,cap1203", .data = &cap1203_model },
646 { .compatible = "microchip,cap1206", .data = &cap1206_model },
647 { .compatible = "microchip,cap1293", .data = &cap1293_model },
648 { .compatible = "microchip,cap1298", .data = &cap1298_model },
649 { }
650 };
651 MODULE_DEVICE_TABLE(of, cap11xx_dt_ids);
652
653 static const struct i2c_device_id cap11xx_i2c_ids[] = {
654 { "cap1106", (kernel_ulong_t)&cap1106_model },
655 { "cap1126", (kernel_ulong_t)&cap1126_model },
656 { "cap1188", (kernel_ulong_t)&cap1188_model },
657 { "cap1203", (kernel_ulong_t)&cap1203_model },
658 { "cap1206", (kernel_ulong_t)&cap1206_model },
659 { "cap1293", (kernel_ulong_t)&cap1293_model },
660 { "cap1298", (kernel_ulong_t)&cap1298_model },
661 { }
662 };
663 MODULE_DEVICE_TABLE(i2c, cap11xx_i2c_ids);
664
665 static struct i2c_driver cap11xx_i2c_driver = {
666 .driver = {
667 .name = "cap11xx",
668 .of_match_table = cap11xx_dt_ids,
669 },
670 .id_table = cap11xx_i2c_ids,
671 .probe = cap11xx_i2c_probe,
672 };
673
674 module_i2c_driver(cap11xx_i2c_driver);
675
676 MODULE_DESCRIPTION("Microchip CAP11XX driver");
677 MODULE_AUTHOR("Daniel Mack <linux@zonque.org>");
678 MODULE_LICENSE("GPL v2");
679