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