1 // SPDX-License-Identifier: GPL-2.0+
3 * Azoteq IQS269A Capacitive Touch Controller
5 * Copyright (C) 2020 Jeff LaBundy <jeff@labundy.com>
7 * This driver registers up to 3 input devices: one representing capacitive or
8 * inductive keys as well as Hall-effect switches, and one for each of the two
9 * axial sliders presented by the device.
12 #include <linux/completion.h>
13 #include <linux/delay.h>
14 #include <linux/device.h>
15 #include <linux/err.h>
16 #include <linux/i2c.h>
17 #include <linux/input.h>
18 #include <linux/interrupt.h>
19 #include <linux/kernel.h>
20 #include <linux/mod_devicetable.h>
21 #include <linux/module.h>
22 #include <linux/mutex.h>
23 #include <linux/property.h>
24 #include <linux/regmap.h>
25 #include <linux/slab.h>
27 #define IQS269_VER_INFO 0x00
28 #define IQS269_VER_INFO_PROD_NUM 0x4F
30 #define IQS269_SYS_FLAGS 0x02
31 #define IQS269_SYS_FLAGS_SHOW_RESET BIT(15)
32 #define IQS269_SYS_FLAGS_PWR_MODE_MASK GENMASK(12, 11)
33 #define IQS269_SYS_FLAGS_PWR_MODE_SHIFT 11
34 #define IQS269_SYS_FLAGS_IN_ATI BIT(10)
36 #define IQS269_CHx_COUNTS 0x08
38 #define IQS269_SLIDER_X 0x30
40 #define IQS269_CAL_DATA_A 0x35
41 #define IQS269_CAL_DATA_A_HALL_BIN_L_MASK GENMASK(15, 12)
42 #define IQS269_CAL_DATA_A_HALL_BIN_L_SHIFT 12
43 #define IQS269_CAL_DATA_A_HALL_BIN_R_MASK GENMASK(11, 8)
44 #define IQS269_CAL_DATA_A_HALL_BIN_R_SHIFT 8
46 #define IQS269_SYS_SETTINGS 0x80
47 #define IQS269_SYS_SETTINGS_CLK_DIV BIT(15)
48 #define IQS269_SYS_SETTINGS_ULP_AUTO BIT(14)
49 #define IQS269_SYS_SETTINGS_DIS_AUTO BIT(13)
50 #define IQS269_SYS_SETTINGS_PWR_MODE_MASK GENMASK(12, 11)
51 #define IQS269_SYS_SETTINGS_PWR_MODE_SHIFT 11
52 #define IQS269_SYS_SETTINGS_PWR_MODE_MAX 3
53 #define IQS269_SYS_SETTINGS_ULP_UPDATE_MASK GENMASK(10, 8)
54 #define IQS269_SYS_SETTINGS_ULP_UPDATE_SHIFT 8
55 #define IQS269_SYS_SETTINGS_ULP_UPDATE_MAX 7
56 #define IQS269_SYS_SETTINGS_RESEED_OFFSET BIT(6)
57 #define IQS269_SYS_SETTINGS_EVENT_MODE BIT(5)
58 #define IQS269_SYS_SETTINGS_EVENT_MODE_LP BIT(4)
59 #define IQS269_SYS_SETTINGS_REDO_ATI BIT(2)
60 #define IQS269_SYS_SETTINGS_ACK_RESET BIT(0)
62 #define IQS269_FILT_STR_LP_LTA_MASK GENMASK(7, 6)
63 #define IQS269_FILT_STR_LP_LTA_SHIFT 6
64 #define IQS269_FILT_STR_LP_CNT_MASK GENMASK(5, 4)
65 #define IQS269_FILT_STR_LP_CNT_SHIFT 4
66 #define IQS269_FILT_STR_NP_LTA_MASK GENMASK(3, 2)
67 #define IQS269_FILT_STR_NP_LTA_SHIFT 2
68 #define IQS269_FILT_STR_NP_CNT_MASK GENMASK(1, 0)
69 #define IQS269_FILT_STR_MAX 3
71 #define IQS269_EVENT_MASK_SYS BIT(6)
72 #define IQS269_EVENT_MASK_DEEP BIT(2)
73 #define IQS269_EVENT_MASK_TOUCH BIT(1)
74 #define IQS269_EVENT_MASK_PROX BIT(0)
76 #define IQS269_RATE_NP_MS_MAX 255
77 #define IQS269_RATE_LP_MS_MAX 255
78 #define IQS269_RATE_ULP_MS_MAX 4080
79 #define IQS269_TIMEOUT_PWR_MS_MAX 130560
80 #define IQS269_TIMEOUT_LTA_MS_MAX 130560
82 #define IQS269_MISC_A_ATI_BAND_DISABLE BIT(15)
83 #define IQS269_MISC_A_ATI_LP_ONLY BIT(14)
84 #define IQS269_MISC_A_ATI_BAND_TIGHTEN BIT(13)
85 #define IQS269_MISC_A_FILT_DISABLE BIT(12)
86 #define IQS269_MISC_A_GPIO3_SELECT_MASK GENMASK(10, 8)
87 #define IQS269_MISC_A_GPIO3_SELECT_SHIFT 8
88 #define IQS269_MISC_A_DUAL_DIR BIT(6)
89 #define IQS269_MISC_A_TX_FREQ_MASK GENMASK(5, 4)
90 #define IQS269_MISC_A_TX_FREQ_SHIFT 4
91 #define IQS269_MISC_A_TX_FREQ_MAX 3
92 #define IQS269_MISC_A_GLOBAL_CAP_SIZE BIT(0)
94 #define IQS269_MISC_B_RESEED_UI_SEL_MASK GENMASK(7, 6)
95 #define IQS269_MISC_B_RESEED_UI_SEL_SHIFT 6
96 #define IQS269_MISC_B_RESEED_UI_SEL_MAX 3
97 #define IQS269_MISC_B_TRACKING_UI_ENABLE BIT(4)
98 #define IQS269_MISC_B_FILT_STR_SLIDER GENMASK(1, 0)
100 #define IQS269_CHx_ENG_A_MEAS_CAP_SIZE BIT(15)
101 #define IQS269_CHx_ENG_A_RX_GND_INACTIVE BIT(13)
102 #define IQS269_CHx_ENG_A_LOCAL_CAP_SIZE BIT(12)
103 #define IQS269_CHx_ENG_A_ATI_MODE_MASK GENMASK(9, 8)
104 #define IQS269_CHx_ENG_A_ATI_MODE_SHIFT 8
105 #define IQS269_CHx_ENG_A_ATI_MODE_MAX 3
106 #define IQS269_CHx_ENG_A_INV_LOGIC BIT(7)
107 #define IQS269_CHx_ENG_A_PROJ_BIAS_MASK GENMASK(6, 5)
108 #define IQS269_CHx_ENG_A_PROJ_BIAS_SHIFT 5
109 #define IQS269_CHx_ENG_A_PROJ_BIAS_MAX 3
110 #define IQS269_CHx_ENG_A_SENSE_MODE_MASK GENMASK(3, 0)
111 #define IQS269_CHx_ENG_A_SENSE_MODE_MAX 15
113 #define IQS269_CHx_ENG_B_LOCAL_CAP_ENABLE BIT(13)
114 #define IQS269_CHx_ENG_B_SENSE_FREQ_MASK GENMASK(10, 9)
115 #define IQS269_CHx_ENG_B_SENSE_FREQ_SHIFT 9
116 #define IQS269_CHx_ENG_B_SENSE_FREQ_MAX 3
117 #define IQS269_CHx_ENG_B_STATIC_ENABLE BIT(8)
118 #define IQS269_CHx_ENG_B_ATI_BASE_MASK GENMASK(7, 6)
119 #define IQS269_CHx_ENG_B_ATI_BASE_75 0x00
120 #define IQS269_CHx_ENG_B_ATI_BASE_100 0x40
121 #define IQS269_CHx_ENG_B_ATI_BASE_150 0x80
122 #define IQS269_CHx_ENG_B_ATI_BASE_200 0xC0
123 #define IQS269_CHx_ENG_B_ATI_TARGET_MASK GENMASK(5, 0)
124 #define IQS269_CHx_ENG_B_ATI_TARGET_MAX 2016
126 #define IQS269_CHx_WEIGHT_MAX 255
127 #define IQS269_CHx_THRESH_MAX 255
128 #define IQS269_CHx_HYST_DEEP_MASK GENMASK(7, 4)
129 #define IQS269_CHx_HYST_DEEP_SHIFT 4
130 #define IQS269_CHx_HYST_TOUCH_MASK GENMASK(3, 0)
131 #define IQS269_CHx_HYST_MAX 15
133 #define IQS269_CHx_HALL_INACTIVE 6
134 #define IQS269_CHx_HALL_ACTIVE 7
136 #define IQS269_HALL_PAD_R BIT(0)
137 #define IQS269_HALL_PAD_L BIT(1)
138 #define IQS269_HALL_PAD_INV BIT(6)
140 #define IQS269_HALL_UI 0xF5
141 #define IQS269_HALL_UI_ENABLE BIT(15)
143 #define IQS269_MAX_REG 0xFF
145 #define IQS269_NUM_CH 8
146 #define IQS269_NUM_SL 2
148 #define iqs269_irq_wait() usleep_range(200, 250)
150 enum iqs269_local_cap_size {
151 IQS269_LOCAL_CAP_SIZE_0,
152 IQS269_LOCAL_CAP_SIZE_GLOBAL_ONLY,
153 IQS269_LOCAL_CAP_SIZE_GLOBAL_0pF5,
156 enum iqs269_st_offs {
159 IQS269_ST_OFFS_TOUCH,
163 enum iqs269_th_offs {
165 IQS269_TH_OFFS_TOUCH,
169 enum iqs269_event_id {
170 IQS269_EVENT_PROX_DN,
171 IQS269_EVENT_PROX_UP,
172 IQS269_EVENT_TOUCH_DN,
173 IQS269_EVENT_TOUCH_UP,
174 IQS269_EVENT_DEEP_DN,
175 IQS269_EVENT_DEEP_UP,
178 struct iqs269_switch_desc {
183 struct iqs269_event_desc {
185 enum iqs269_st_offs st_offs;
186 enum iqs269_th_offs th_offs;
191 static const struct iqs269_event_desc iqs269_events[] = {
192 [IQS269_EVENT_PROX_DN] = {
193 .name = "event-prox",
194 .st_offs = IQS269_ST_OFFS_PROX,
195 .th_offs = IQS269_TH_OFFS_PROX,
196 .mask = IQS269_EVENT_MASK_PROX,
198 [IQS269_EVENT_PROX_UP] = {
199 .name = "event-prox-alt",
200 .st_offs = IQS269_ST_OFFS_PROX,
201 .th_offs = IQS269_TH_OFFS_PROX,
203 .mask = IQS269_EVENT_MASK_PROX,
205 [IQS269_EVENT_TOUCH_DN] = {
206 .name = "event-touch",
207 .st_offs = IQS269_ST_OFFS_TOUCH,
208 .th_offs = IQS269_TH_OFFS_TOUCH,
209 .mask = IQS269_EVENT_MASK_TOUCH,
211 [IQS269_EVENT_TOUCH_UP] = {
212 .name = "event-touch-alt",
213 .st_offs = IQS269_ST_OFFS_TOUCH,
214 .th_offs = IQS269_TH_OFFS_TOUCH,
216 .mask = IQS269_EVENT_MASK_TOUCH,
218 [IQS269_EVENT_DEEP_DN] = {
219 .name = "event-deep",
220 .st_offs = IQS269_ST_OFFS_DEEP,
221 .th_offs = IQS269_TH_OFFS_DEEP,
222 .mask = IQS269_EVENT_MASK_DEEP,
224 [IQS269_EVENT_DEEP_UP] = {
225 .name = "event-deep-alt",
226 .st_offs = IQS269_ST_OFFS_DEEP,
227 .th_offs = IQS269_TH_OFFS_DEEP,
229 .mask = IQS269_EVENT_MASK_DEEP,
233 struct iqs269_ver_info {
240 struct iqs269_ch_reg {
252 struct iqs269_sys_reg {
268 u8 slider_select[IQS269_NUM_SL];
273 struct iqs269_ch_reg ch_reg[IQS269_NUM_CH];
276 struct iqs269_flags {
283 struct iqs269_private {
284 struct i2c_client *client;
285 struct regmap *regmap;
287 struct iqs269_switch_desc switches[ARRAY_SIZE(iqs269_events)];
288 struct iqs269_sys_reg sys_reg;
289 struct completion ati_done;
290 struct input_dev *keypad;
291 struct input_dev *slider[IQS269_NUM_SL];
292 unsigned int keycode[ARRAY_SIZE(iqs269_events) * IQS269_NUM_CH];
298 static int iqs269_ati_mode_set(struct iqs269_private *iqs269,
299 unsigned int ch_num, unsigned int mode)
301 struct iqs269_ch_reg *ch_reg = iqs269->sys_reg.ch_reg;
304 if (ch_num >= IQS269_NUM_CH)
307 if (mode > IQS269_CHx_ENG_A_ATI_MODE_MAX)
310 mutex_lock(&iqs269->lock);
312 engine_a = be16_to_cpu(ch_reg[ch_num].engine_a);
314 engine_a &= ~IQS269_CHx_ENG_A_ATI_MODE_MASK;
315 engine_a |= (mode << IQS269_CHx_ENG_A_ATI_MODE_SHIFT);
317 ch_reg[ch_num].engine_a = cpu_to_be16(engine_a);
318 iqs269->ati_current = false;
320 mutex_unlock(&iqs269->lock);
325 static int iqs269_ati_mode_get(struct iqs269_private *iqs269,
326 unsigned int ch_num, unsigned int *mode)
328 struct iqs269_ch_reg *ch_reg = iqs269->sys_reg.ch_reg;
331 if (ch_num >= IQS269_NUM_CH)
334 mutex_lock(&iqs269->lock);
335 engine_a = be16_to_cpu(ch_reg[ch_num].engine_a);
336 mutex_unlock(&iqs269->lock);
338 engine_a &= IQS269_CHx_ENG_A_ATI_MODE_MASK;
339 *mode = (engine_a >> IQS269_CHx_ENG_A_ATI_MODE_SHIFT);
344 static int iqs269_ati_base_set(struct iqs269_private *iqs269,
345 unsigned int ch_num, unsigned int base)
347 struct iqs269_ch_reg *ch_reg = iqs269->sys_reg.ch_reg;
350 if (ch_num >= IQS269_NUM_CH)
355 base = IQS269_CHx_ENG_B_ATI_BASE_75;
359 base = IQS269_CHx_ENG_B_ATI_BASE_100;
363 base = IQS269_CHx_ENG_B_ATI_BASE_150;
367 base = IQS269_CHx_ENG_B_ATI_BASE_200;
374 mutex_lock(&iqs269->lock);
376 engine_b = be16_to_cpu(ch_reg[ch_num].engine_b);
378 engine_b &= ~IQS269_CHx_ENG_B_ATI_BASE_MASK;
381 ch_reg[ch_num].engine_b = cpu_to_be16(engine_b);
382 iqs269->ati_current = false;
384 mutex_unlock(&iqs269->lock);
389 static int iqs269_ati_base_get(struct iqs269_private *iqs269,
390 unsigned int ch_num, unsigned int *base)
392 struct iqs269_ch_reg *ch_reg = iqs269->sys_reg.ch_reg;
395 if (ch_num >= IQS269_NUM_CH)
398 mutex_lock(&iqs269->lock);
399 engine_b = be16_to_cpu(ch_reg[ch_num].engine_b);
400 mutex_unlock(&iqs269->lock);
402 switch (engine_b & IQS269_CHx_ENG_B_ATI_BASE_MASK) {
403 case IQS269_CHx_ENG_B_ATI_BASE_75:
407 case IQS269_CHx_ENG_B_ATI_BASE_100:
411 case IQS269_CHx_ENG_B_ATI_BASE_150:
415 case IQS269_CHx_ENG_B_ATI_BASE_200:
424 static int iqs269_ati_target_set(struct iqs269_private *iqs269,
425 unsigned int ch_num, unsigned int target)
427 struct iqs269_ch_reg *ch_reg = iqs269->sys_reg.ch_reg;
430 if (ch_num >= IQS269_NUM_CH)
433 if (target > IQS269_CHx_ENG_B_ATI_TARGET_MAX)
436 mutex_lock(&iqs269->lock);
438 engine_b = be16_to_cpu(ch_reg[ch_num].engine_b);
440 engine_b &= ~IQS269_CHx_ENG_B_ATI_TARGET_MASK;
441 engine_b |= target / 32;
443 ch_reg[ch_num].engine_b = cpu_to_be16(engine_b);
444 iqs269->ati_current = false;
446 mutex_unlock(&iqs269->lock);
451 static int iqs269_ati_target_get(struct iqs269_private *iqs269,
452 unsigned int ch_num, unsigned int *target)
454 struct iqs269_ch_reg *ch_reg = iqs269->sys_reg.ch_reg;
457 if (ch_num >= IQS269_NUM_CH)
460 mutex_lock(&iqs269->lock);
461 engine_b = be16_to_cpu(ch_reg[ch_num].engine_b);
462 mutex_unlock(&iqs269->lock);
464 *target = (engine_b & IQS269_CHx_ENG_B_ATI_TARGET_MASK) * 32;
469 static int iqs269_parse_mask(const struct fwnode_handle *fwnode,
470 const char *propname, u8 *mask)
472 unsigned int val[IQS269_NUM_CH];
475 count = fwnode_property_count_u32(fwnode, propname);
479 if (count > IQS269_NUM_CH)
482 error = fwnode_property_read_u32_array(fwnode, propname, val, count);
488 for (i = 0; i < count; i++) {
489 if (val[i] >= IQS269_NUM_CH)
492 *mask |= BIT(val[i]);
498 static int iqs269_parse_chan(struct iqs269_private *iqs269,
499 const struct fwnode_handle *ch_node)
501 struct i2c_client *client = iqs269->client;
502 struct fwnode_handle *ev_node;
503 struct iqs269_ch_reg *ch_reg;
504 u16 engine_a, engine_b;
505 unsigned int reg, val;
508 error = fwnode_property_read_u32(ch_node, "reg", ®);
510 dev_err(&client->dev, "Failed to read channel number: %d\n",
513 } else if (reg >= IQS269_NUM_CH) {
514 dev_err(&client->dev, "Invalid channel number: %u\n", reg);
518 iqs269->sys_reg.active |= BIT(reg);
519 if (!fwnode_property_present(ch_node, "azoteq,reseed-disable"))
520 iqs269->sys_reg.reseed |= BIT(reg);
522 if (fwnode_property_present(ch_node, "azoteq,blocking-enable"))
523 iqs269->sys_reg.blocking |= BIT(reg);
525 if (fwnode_property_present(ch_node, "azoteq,slider0-select"))
526 iqs269->sys_reg.slider_select[0] |= BIT(reg);
528 if (fwnode_property_present(ch_node, "azoteq,slider1-select"))
529 iqs269->sys_reg.slider_select[1] |= BIT(reg);
531 ch_reg = &iqs269->sys_reg.ch_reg[reg];
533 error = iqs269_parse_mask(ch_node, "azoteq,rx-enable",
536 dev_err(&client->dev, "Invalid channel %u RX enable mask: %d\n",
541 error = iqs269_parse_mask(ch_node, "azoteq,tx-enable",
544 dev_err(&client->dev, "Invalid channel %u TX enable mask: %d\n",
549 engine_a = be16_to_cpu(ch_reg->engine_a);
550 engine_b = be16_to_cpu(ch_reg->engine_b);
552 engine_a |= IQS269_CHx_ENG_A_MEAS_CAP_SIZE;
553 if (fwnode_property_present(ch_node, "azoteq,meas-cap-decrease"))
554 engine_a &= ~IQS269_CHx_ENG_A_MEAS_CAP_SIZE;
556 engine_a |= IQS269_CHx_ENG_A_RX_GND_INACTIVE;
557 if (fwnode_property_present(ch_node, "azoteq,rx-float-inactive"))
558 engine_a &= ~IQS269_CHx_ENG_A_RX_GND_INACTIVE;
560 engine_a &= ~IQS269_CHx_ENG_A_LOCAL_CAP_SIZE;
561 engine_b &= ~IQS269_CHx_ENG_B_LOCAL_CAP_ENABLE;
562 if (!fwnode_property_read_u32(ch_node, "azoteq,local-cap-size", &val)) {
564 case IQS269_LOCAL_CAP_SIZE_0:
567 case IQS269_LOCAL_CAP_SIZE_GLOBAL_0pF5:
568 engine_a |= IQS269_CHx_ENG_A_LOCAL_CAP_SIZE;
571 case IQS269_LOCAL_CAP_SIZE_GLOBAL_ONLY:
572 engine_b |= IQS269_CHx_ENG_B_LOCAL_CAP_ENABLE;
576 dev_err(&client->dev,
577 "Invalid channel %u local cap. size: %u\n", reg,
583 engine_a &= ~IQS269_CHx_ENG_A_INV_LOGIC;
584 if (fwnode_property_present(ch_node, "azoteq,invert-enable"))
585 engine_a |= IQS269_CHx_ENG_A_INV_LOGIC;
587 if (!fwnode_property_read_u32(ch_node, "azoteq,proj-bias", &val)) {
588 if (val > IQS269_CHx_ENG_A_PROJ_BIAS_MAX) {
589 dev_err(&client->dev,
590 "Invalid channel %u bias current: %u\n", reg,
595 engine_a &= ~IQS269_CHx_ENG_A_PROJ_BIAS_MASK;
596 engine_a |= (val << IQS269_CHx_ENG_A_PROJ_BIAS_SHIFT);
599 if (!fwnode_property_read_u32(ch_node, "azoteq,sense-mode", &val)) {
600 if (val > IQS269_CHx_ENG_A_SENSE_MODE_MAX) {
601 dev_err(&client->dev,
602 "Invalid channel %u sensing mode: %u\n", reg,
607 engine_a &= ~IQS269_CHx_ENG_A_SENSE_MODE_MASK;
611 if (!fwnode_property_read_u32(ch_node, "azoteq,sense-freq", &val)) {
612 if (val > IQS269_CHx_ENG_B_SENSE_FREQ_MAX) {
613 dev_err(&client->dev,
614 "Invalid channel %u sensing frequency: %u\n",
619 engine_b &= ~IQS269_CHx_ENG_B_SENSE_FREQ_MASK;
620 engine_b |= (val << IQS269_CHx_ENG_B_SENSE_FREQ_SHIFT);
623 engine_b &= ~IQS269_CHx_ENG_B_STATIC_ENABLE;
624 if (fwnode_property_present(ch_node, "azoteq,static-enable"))
625 engine_b |= IQS269_CHx_ENG_B_STATIC_ENABLE;
627 ch_reg->engine_a = cpu_to_be16(engine_a);
628 ch_reg->engine_b = cpu_to_be16(engine_b);
630 if (!fwnode_property_read_u32(ch_node, "azoteq,ati-mode", &val)) {
631 error = iqs269_ati_mode_set(iqs269, reg, val);
633 dev_err(&client->dev,
634 "Invalid channel %u ATI mode: %u\n", reg, val);
639 if (!fwnode_property_read_u32(ch_node, "azoteq,ati-base", &val)) {
640 error = iqs269_ati_base_set(iqs269, reg, val);
642 dev_err(&client->dev,
643 "Invalid channel %u ATI base: %u\n", reg, val);
648 if (!fwnode_property_read_u32(ch_node, "azoteq,ati-target", &val)) {
649 error = iqs269_ati_target_set(iqs269, reg, val);
651 dev_err(&client->dev,
652 "Invalid channel %u ATI target: %u\n", reg,
658 error = iqs269_parse_mask(ch_node, "azoteq,assoc-select",
659 &ch_reg->assoc_select);
661 dev_err(&client->dev, "Invalid channel %u association: %d\n",
666 if (!fwnode_property_read_u32(ch_node, "azoteq,assoc-weight", &val)) {
667 if (val > IQS269_CHx_WEIGHT_MAX) {
668 dev_err(&client->dev,
669 "Invalid channel %u associated weight: %u\n",
674 ch_reg->assoc_weight = val;
677 for (i = 0; i < ARRAY_SIZE(iqs269_events); i++) {
678 ev_node = fwnode_get_named_child_node(ch_node,
679 iqs269_events[i].name);
683 if (!fwnode_property_read_u32(ev_node, "azoteq,thresh", &val)) {
684 if (val > IQS269_CHx_THRESH_MAX) {
685 dev_err(&client->dev,
686 "Invalid channel %u threshold: %u\n",
688 fwnode_handle_put(ev_node);
692 ch_reg->thresh[iqs269_events[i].th_offs] = val;
695 if (!fwnode_property_read_u32(ev_node, "azoteq,hyst", &val)) {
696 u8 *hyst = &ch_reg->hyst;
698 if (val > IQS269_CHx_HYST_MAX) {
699 dev_err(&client->dev,
700 "Invalid channel %u hysteresis: %u\n",
702 fwnode_handle_put(ev_node);
706 if (i == IQS269_EVENT_DEEP_DN ||
707 i == IQS269_EVENT_DEEP_UP) {
708 *hyst &= ~IQS269_CHx_HYST_DEEP_MASK;
709 *hyst |= (val << IQS269_CHx_HYST_DEEP_SHIFT);
710 } else if (i == IQS269_EVENT_TOUCH_DN ||
711 i == IQS269_EVENT_TOUCH_UP) {
712 *hyst &= ~IQS269_CHx_HYST_TOUCH_MASK;
717 error = fwnode_property_read_u32(ev_node, "linux,code", &val);
718 fwnode_handle_put(ev_node);
719 if (error == -EINVAL) {
722 dev_err(&client->dev,
723 "Failed to read channel %u code: %d\n", reg,
729 case IQS269_CHx_HALL_ACTIVE:
730 if (iqs269->hall_enable) {
731 iqs269->switches[i].code = val;
732 iqs269->switches[i].enabled = true;
736 case IQS269_CHx_HALL_INACTIVE:
737 if (iqs269->hall_enable)
742 iqs269->keycode[i * IQS269_NUM_CH + reg] = val;
745 iqs269->sys_reg.event_mask &= ~iqs269_events[i].mask;
751 static int iqs269_parse_prop(struct iqs269_private *iqs269)
753 struct iqs269_sys_reg *sys_reg = &iqs269->sys_reg;
754 struct i2c_client *client = iqs269->client;
755 struct fwnode_handle *ch_node;
756 u16 general, misc_a, misc_b;
760 iqs269->hall_enable = device_property_present(&client->dev,
761 "azoteq,hall-enable");
763 error = regmap_raw_read(iqs269->regmap, IQS269_SYS_SETTINGS, sys_reg,
768 if (!device_property_read_u32(&client->dev, "azoteq,filt-str-lp-lta",
770 if (val > IQS269_FILT_STR_MAX) {
771 dev_err(&client->dev, "Invalid filter strength: %u\n",
776 sys_reg->filter &= ~IQS269_FILT_STR_LP_LTA_MASK;
777 sys_reg->filter |= (val << IQS269_FILT_STR_LP_LTA_SHIFT);
780 if (!device_property_read_u32(&client->dev, "azoteq,filt-str-lp-cnt",
782 if (val > IQS269_FILT_STR_MAX) {
783 dev_err(&client->dev, "Invalid filter strength: %u\n",
788 sys_reg->filter &= ~IQS269_FILT_STR_LP_CNT_MASK;
789 sys_reg->filter |= (val << IQS269_FILT_STR_LP_CNT_SHIFT);
792 if (!device_property_read_u32(&client->dev, "azoteq,filt-str-np-lta",
794 if (val > IQS269_FILT_STR_MAX) {
795 dev_err(&client->dev, "Invalid filter strength: %u\n",
800 sys_reg->filter &= ~IQS269_FILT_STR_NP_LTA_MASK;
801 sys_reg->filter |= (val << IQS269_FILT_STR_NP_LTA_SHIFT);
804 if (!device_property_read_u32(&client->dev, "azoteq,filt-str-np-cnt",
806 if (val > IQS269_FILT_STR_MAX) {
807 dev_err(&client->dev, "Invalid filter strength: %u\n",
812 sys_reg->filter &= ~IQS269_FILT_STR_NP_CNT_MASK;
813 sys_reg->filter |= val;
816 if (!device_property_read_u32(&client->dev, "azoteq,rate-np-ms",
818 if (val > IQS269_RATE_NP_MS_MAX) {
819 dev_err(&client->dev, "Invalid report rate: %u\n", val);
823 sys_reg->rate_np = val;
826 if (!device_property_read_u32(&client->dev, "azoteq,rate-lp-ms",
828 if (val > IQS269_RATE_LP_MS_MAX) {
829 dev_err(&client->dev, "Invalid report rate: %u\n", val);
833 sys_reg->rate_lp = val;
836 if (!device_property_read_u32(&client->dev, "azoteq,rate-ulp-ms",
838 if (val > IQS269_RATE_ULP_MS_MAX) {
839 dev_err(&client->dev, "Invalid report rate: %u\n", val);
843 sys_reg->rate_ulp = val / 16;
846 if (!device_property_read_u32(&client->dev, "azoteq,timeout-pwr-ms",
848 if (val > IQS269_TIMEOUT_PWR_MS_MAX) {
849 dev_err(&client->dev, "Invalid timeout: %u\n", val);
853 sys_reg->timeout_pwr = val / 512;
856 if (!device_property_read_u32(&client->dev, "azoteq,timeout-lta-ms",
858 if (val > IQS269_TIMEOUT_LTA_MS_MAX) {
859 dev_err(&client->dev, "Invalid timeout: %u\n", val);
863 sys_reg->timeout_lta = val / 512;
866 misc_a = be16_to_cpu(sys_reg->misc_a);
867 misc_b = be16_to_cpu(sys_reg->misc_b);
869 misc_a &= ~IQS269_MISC_A_ATI_BAND_DISABLE;
870 if (device_property_present(&client->dev, "azoteq,ati-band-disable"))
871 misc_a |= IQS269_MISC_A_ATI_BAND_DISABLE;
873 misc_a &= ~IQS269_MISC_A_ATI_LP_ONLY;
874 if (device_property_present(&client->dev, "azoteq,ati-lp-only"))
875 misc_a |= IQS269_MISC_A_ATI_LP_ONLY;
877 misc_a &= ~IQS269_MISC_A_ATI_BAND_TIGHTEN;
878 if (device_property_present(&client->dev, "azoteq,ati-band-tighten"))
879 misc_a |= IQS269_MISC_A_ATI_BAND_TIGHTEN;
881 misc_a &= ~IQS269_MISC_A_FILT_DISABLE;
882 if (device_property_present(&client->dev, "azoteq,filt-disable"))
883 misc_a |= IQS269_MISC_A_FILT_DISABLE;
885 if (!device_property_read_u32(&client->dev, "azoteq,gpio3-select",
887 if (val >= IQS269_NUM_CH) {
888 dev_err(&client->dev, "Invalid GPIO3 selection: %u\n",
893 misc_a &= ~IQS269_MISC_A_GPIO3_SELECT_MASK;
894 misc_a |= (val << IQS269_MISC_A_GPIO3_SELECT_SHIFT);
897 misc_a &= ~IQS269_MISC_A_DUAL_DIR;
898 if (device_property_present(&client->dev, "azoteq,dual-direction"))
899 misc_a |= IQS269_MISC_A_DUAL_DIR;
901 if (!device_property_read_u32(&client->dev, "azoteq,tx-freq", &val)) {
902 if (val > IQS269_MISC_A_TX_FREQ_MAX) {
903 dev_err(&client->dev,
904 "Invalid excitation frequency: %u\n", val);
908 misc_a &= ~IQS269_MISC_A_TX_FREQ_MASK;
909 misc_a |= (val << IQS269_MISC_A_TX_FREQ_SHIFT);
912 misc_a &= ~IQS269_MISC_A_GLOBAL_CAP_SIZE;
913 if (device_property_present(&client->dev, "azoteq,global-cap-increase"))
914 misc_a |= IQS269_MISC_A_GLOBAL_CAP_SIZE;
916 if (!device_property_read_u32(&client->dev, "azoteq,reseed-select",
918 if (val > IQS269_MISC_B_RESEED_UI_SEL_MAX) {
919 dev_err(&client->dev, "Invalid reseed selection: %u\n",
924 misc_b &= ~IQS269_MISC_B_RESEED_UI_SEL_MASK;
925 misc_b |= (val << IQS269_MISC_B_RESEED_UI_SEL_SHIFT);
928 misc_b &= ~IQS269_MISC_B_TRACKING_UI_ENABLE;
929 if (device_property_present(&client->dev, "azoteq,tracking-enable"))
930 misc_b |= IQS269_MISC_B_TRACKING_UI_ENABLE;
932 if (!device_property_read_u32(&client->dev, "azoteq,filt-str-slider",
934 if (val > IQS269_FILT_STR_MAX) {
935 dev_err(&client->dev, "Invalid filter strength: %u\n",
940 misc_b &= ~IQS269_MISC_B_FILT_STR_SLIDER;
944 sys_reg->misc_a = cpu_to_be16(misc_a);
945 sys_reg->misc_b = cpu_to_be16(misc_b);
950 sys_reg->blocking = 0;
952 sys_reg->slider_select[0] = 0;
953 sys_reg->slider_select[1] = 0;
955 sys_reg->event_mask = ~((u8)IQS269_EVENT_MASK_SYS);
957 device_for_each_child_node(&client->dev, ch_node) {
958 error = iqs269_parse_chan(iqs269, ch_node);
960 fwnode_handle_put(ch_node);
966 * Volunteer all active channels to participate in ATI when REDO-ATI is
967 * manually triggered.
969 sys_reg->redo_ati = sys_reg->active;
971 general = be16_to_cpu(sys_reg->general);
973 if (device_property_present(&client->dev, "azoteq,clk-div"))
974 general |= IQS269_SYS_SETTINGS_CLK_DIV;
977 * Configure the device to automatically switch between normal and low-
978 * power modes as a function of sensing activity. Ultra-low-power mode,
979 * if enabled, is reserved for suspend.
981 general &= ~IQS269_SYS_SETTINGS_ULP_AUTO;
982 general &= ~IQS269_SYS_SETTINGS_DIS_AUTO;
983 general &= ~IQS269_SYS_SETTINGS_PWR_MODE_MASK;
985 if (!device_property_read_u32(&client->dev, "azoteq,suspend-mode",
987 if (val > IQS269_SYS_SETTINGS_PWR_MODE_MAX) {
988 dev_err(&client->dev, "Invalid suspend mode: %u\n",
993 general |= (val << IQS269_SYS_SETTINGS_PWR_MODE_SHIFT);
996 if (!device_property_read_u32(&client->dev, "azoteq,ulp-update",
998 if (val > IQS269_SYS_SETTINGS_ULP_UPDATE_MAX) {
999 dev_err(&client->dev, "Invalid update rate: %u\n", val);
1003 general &= ~IQS269_SYS_SETTINGS_ULP_UPDATE_MASK;
1004 general |= (val << IQS269_SYS_SETTINGS_ULP_UPDATE_SHIFT);
1007 general &= ~IQS269_SYS_SETTINGS_RESEED_OFFSET;
1008 if (device_property_present(&client->dev, "azoteq,reseed-offset"))
1009 general |= IQS269_SYS_SETTINGS_RESEED_OFFSET;
1011 general |= IQS269_SYS_SETTINGS_EVENT_MODE;
1014 * As per the datasheet, enable streaming during normal-power mode if
1015 * either slider is in use. In that case, the device returns to event
1016 * mode during low-power mode.
1018 if (sys_reg->slider_select[0] || sys_reg->slider_select[1])
1019 general |= IQS269_SYS_SETTINGS_EVENT_MODE_LP;
1021 general |= IQS269_SYS_SETTINGS_REDO_ATI;
1022 general |= IQS269_SYS_SETTINGS_ACK_RESET;
1024 sys_reg->general = cpu_to_be16(general);
1029 static int iqs269_dev_init(struct iqs269_private *iqs269)
1033 mutex_lock(&iqs269->lock);
1035 error = regmap_update_bits(iqs269->regmap, IQS269_HALL_UI,
1036 IQS269_HALL_UI_ENABLE,
1037 iqs269->hall_enable ? ~0 : 0);
1041 error = regmap_raw_write(iqs269->regmap, IQS269_SYS_SETTINGS,
1042 &iqs269->sys_reg, sizeof(iqs269->sys_reg));
1047 * The following delay gives the device time to deassert its RDY output
1048 * so as to prevent an interrupt from being serviced prematurely.
1050 usleep_range(2000, 2100);
1052 iqs269->ati_current = true;
1055 mutex_unlock(&iqs269->lock);
1060 static int iqs269_input_init(struct iqs269_private *iqs269)
1062 struct i2c_client *client = iqs269->client;
1063 unsigned int sw_code, keycode;
1066 iqs269->keypad = devm_input_allocate_device(&client->dev);
1067 if (!iqs269->keypad)
1070 iqs269->keypad->keycodemax = ARRAY_SIZE(iqs269->keycode);
1071 iqs269->keypad->keycode = iqs269->keycode;
1072 iqs269->keypad->keycodesize = sizeof(*iqs269->keycode);
1074 iqs269->keypad->name = "iqs269a_keypad";
1075 iqs269->keypad->id.bustype = BUS_I2C;
1077 for (i = 0; i < ARRAY_SIZE(iqs269_events); i++) {
1078 sw_code = iqs269->switches[i].code;
1080 for (j = 0; j < IQS269_NUM_CH; j++) {
1081 keycode = iqs269->keycode[i * IQS269_NUM_CH + j];
1084 * Hall-effect sensing repurposes a pair of dedicated
1085 * channels, only one of which reports events.
1088 case IQS269_CHx_HALL_ACTIVE:
1089 if (iqs269->hall_enable &&
1090 iqs269->switches[i].enabled)
1091 input_set_capability(iqs269->keypad,
1095 case IQS269_CHx_HALL_INACTIVE:
1096 if (iqs269->hall_enable)
1101 if (keycode != KEY_RESERVED)
1102 input_set_capability(iqs269->keypad,
1108 for (i = 0; i < IQS269_NUM_SL; i++) {
1109 if (!iqs269->sys_reg.slider_select[i])
1112 iqs269->slider[i] = devm_input_allocate_device(&client->dev);
1113 if (!iqs269->slider[i])
1116 iqs269->slider[i]->name = i ? "iqs269a_slider_1"
1117 : "iqs269a_slider_0";
1118 iqs269->slider[i]->id.bustype = BUS_I2C;
1120 input_set_capability(iqs269->slider[i], EV_KEY, BTN_TOUCH);
1121 input_set_abs_params(iqs269->slider[i], ABS_X, 0, 255, 0, 0);
1123 error = input_register_device(iqs269->slider[i]);
1125 dev_err(&client->dev,
1126 "Failed to register slider %d: %d\n", i, error);
1134 static int iqs269_report(struct iqs269_private *iqs269)
1136 struct i2c_client *client = iqs269->client;
1137 struct iqs269_flags flags;
1138 unsigned int sw_code, keycode;
1140 u8 slider_x[IQS269_NUM_SL];
1143 error = regmap_raw_read(iqs269->regmap, IQS269_SYS_FLAGS, &flags,
1146 dev_err(&client->dev, "Failed to read device status: %d\n",
1152 * The device resets itself if its own watchdog bites, which can happen
1153 * in the event of an I2C communication error. In this case, the device
1154 * asserts a SHOW_RESET interrupt and all registers must be restored.
1156 if (be16_to_cpu(flags.system) & IQS269_SYS_FLAGS_SHOW_RESET) {
1157 dev_err(&client->dev, "Unexpected device reset\n");
1159 error = iqs269_dev_init(iqs269);
1161 dev_err(&client->dev,
1162 "Failed to re-initialize device: %d\n", error);
1167 if (be16_to_cpu(flags.system) & IQS269_SYS_FLAGS_IN_ATI)
1170 error = regmap_raw_read(iqs269->regmap, IQS269_SLIDER_X, slider_x,
1173 dev_err(&client->dev, "Failed to read slider position: %d\n",
1178 for (i = 0; i < IQS269_NUM_SL; i++) {
1179 if (!iqs269->sys_reg.slider_select[i])
1183 * Report BTN_TOUCH if any channel that participates in the
1184 * slider is in a state of touch.
1186 if (flags.states[IQS269_ST_OFFS_TOUCH] &
1187 iqs269->sys_reg.slider_select[i]) {
1188 input_report_key(iqs269->slider[i], BTN_TOUCH, 1);
1189 input_report_abs(iqs269->slider[i], ABS_X, slider_x[i]);
1191 input_report_key(iqs269->slider[i], BTN_TOUCH, 0);
1194 input_sync(iqs269->slider[i]);
1197 for (i = 0; i < ARRAY_SIZE(iqs269_events); i++) {
1198 dir_mask = flags.states[IQS269_ST_OFFS_DIR];
1199 if (!iqs269_events[i].dir_up)
1200 dir_mask = ~dir_mask;
1202 state = flags.states[iqs269_events[i].st_offs] & dir_mask;
1204 sw_code = iqs269->switches[i].code;
1206 for (j = 0; j < IQS269_NUM_CH; j++) {
1207 keycode = iqs269->keycode[i * IQS269_NUM_CH + j];
1210 case IQS269_CHx_HALL_ACTIVE:
1211 if (iqs269->hall_enable &&
1212 iqs269->switches[i].enabled)
1213 input_report_switch(iqs269->keypad,
1218 case IQS269_CHx_HALL_INACTIVE:
1219 if (iqs269->hall_enable)
1224 input_report_key(iqs269->keypad, keycode,
1230 input_sync(iqs269->keypad);
1233 * The following completion signals that ATI has finished, any initial
1234 * switch states have been reported and the keypad can be registered.
1236 complete_all(&iqs269->ati_done);
1241 static irqreturn_t iqs269_irq(int irq, void *context)
1243 struct iqs269_private *iqs269 = context;
1245 if (iqs269_report(iqs269))
1249 * The device does not deassert its interrupt (RDY) pin until shortly
1250 * after receiving an I2C stop condition; the following delay ensures
1251 * the interrupt handler does not return before this time.
1258 static ssize_t counts_show(struct device *dev,
1259 struct device_attribute *attr, char *buf)
1261 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1262 struct i2c_client *client = iqs269->client;
1266 if (!iqs269->ati_current || iqs269->hall_enable)
1269 if (!completion_done(&iqs269->ati_done))
1273 * Unsolicited I2C communication prompts the device to assert its RDY
1274 * pin, so disable the interrupt line until the operation is finished
1275 * and RDY has been deasserted.
1277 disable_irq(client->irq);
1279 error = regmap_raw_read(iqs269->regmap,
1280 IQS269_CHx_COUNTS + iqs269->ch_num * 2,
1281 &counts, sizeof(counts));
1284 enable_irq(client->irq);
1289 return scnprintf(buf, PAGE_SIZE, "%u\n", le16_to_cpu(counts));
1292 static ssize_t hall_bin_show(struct device *dev,
1293 struct device_attribute *attr, char *buf)
1295 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1296 struct iqs269_ch_reg *ch_reg = iqs269->sys_reg.ch_reg;
1297 struct i2c_client *client = iqs269->client;
1301 disable_irq(client->irq);
1303 error = regmap_read(iqs269->regmap, IQS269_CAL_DATA_A, &val);
1306 enable_irq(client->irq);
1311 switch (ch_reg[IQS269_CHx_HALL_ACTIVE].rx_enable &
1312 ch_reg[IQS269_CHx_HALL_INACTIVE].rx_enable) {
1313 case IQS269_HALL_PAD_R:
1314 val &= IQS269_CAL_DATA_A_HALL_BIN_R_MASK;
1315 val >>= IQS269_CAL_DATA_A_HALL_BIN_R_SHIFT;
1318 case IQS269_HALL_PAD_L:
1319 val &= IQS269_CAL_DATA_A_HALL_BIN_L_MASK;
1320 val >>= IQS269_CAL_DATA_A_HALL_BIN_L_SHIFT;
1327 return scnprintf(buf, PAGE_SIZE, "%u\n", val);
1330 static ssize_t hall_enable_show(struct device *dev,
1331 struct device_attribute *attr, char *buf)
1333 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1335 return scnprintf(buf, PAGE_SIZE, "%u\n", iqs269->hall_enable);
1338 static ssize_t hall_enable_store(struct device *dev,
1339 struct device_attribute *attr, const char *buf,
1342 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1346 error = kstrtouint(buf, 10, &val);
1350 mutex_lock(&iqs269->lock);
1352 iqs269->hall_enable = val;
1353 iqs269->ati_current = false;
1355 mutex_unlock(&iqs269->lock);
1360 static ssize_t ch_number_show(struct device *dev,
1361 struct device_attribute *attr, char *buf)
1363 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1365 return scnprintf(buf, PAGE_SIZE, "%u\n", iqs269->ch_num);
1368 static ssize_t ch_number_store(struct device *dev,
1369 struct device_attribute *attr, const char *buf,
1372 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1376 error = kstrtouint(buf, 10, &val);
1380 if (val >= IQS269_NUM_CH)
1383 iqs269->ch_num = val;
1388 static ssize_t rx_enable_show(struct device *dev,
1389 struct device_attribute *attr, char *buf)
1391 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1392 struct iqs269_ch_reg *ch_reg = iqs269->sys_reg.ch_reg;
1394 return scnprintf(buf, PAGE_SIZE, "%u\n",
1395 ch_reg[iqs269->ch_num].rx_enable);
1398 static ssize_t rx_enable_store(struct device *dev,
1399 struct device_attribute *attr, const char *buf,
1402 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1403 struct iqs269_ch_reg *ch_reg = iqs269->sys_reg.ch_reg;
1407 error = kstrtouint(buf, 10, &val);
1414 mutex_lock(&iqs269->lock);
1416 ch_reg[iqs269->ch_num].rx_enable = val;
1417 iqs269->ati_current = false;
1419 mutex_unlock(&iqs269->lock);
1424 static ssize_t ati_mode_show(struct device *dev,
1425 struct device_attribute *attr, char *buf)
1427 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1431 error = iqs269_ati_mode_get(iqs269, iqs269->ch_num, &val);
1435 return scnprintf(buf, PAGE_SIZE, "%u\n", val);
1438 static ssize_t ati_mode_store(struct device *dev,
1439 struct device_attribute *attr, const char *buf,
1442 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1446 error = kstrtouint(buf, 10, &val);
1450 error = iqs269_ati_mode_set(iqs269, iqs269->ch_num, val);
1457 static ssize_t ati_base_show(struct device *dev,
1458 struct device_attribute *attr, char *buf)
1460 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1464 error = iqs269_ati_base_get(iqs269, iqs269->ch_num, &val);
1468 return scnprintf(buf, PAGE_SIZE, "%u\n", val);
1471 static ssize_t ati_base_store(struct device *dev,
1472 struct device_attribute *attr, const char *buf,
1475 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1479 error = kstrtouint(buf, 10, &val);
1483 error = iqs269_ati_base_set(iqs269, iqs269->ch_num, val);
1490 static ssize_t ati_target_show(struct device *dev,
1491 struct device_attribute *attr, char *buf)
1493 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1497 error = iqs269_ati_target_get(iqs269, iqs269->ch_num, &val);
1501 return scnprintf(buf, PAGE_SIZE, "%u\n", val);
1504 static ssize_t ati_target_store(struct device *dev,
1505 struct device_attribute *attr, const char *buf,
1508 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1512 error = kstrtouint(buf, 10, &val);
1516 error = iqs269_ati_target_set(iqs269, iqs269->ch_num, val);
1523 static ssize_t ati_trigger_show(struct device *dev,
1524 struct device_attribute *attr, char *buf)
1526 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1528 return scnprintf(buf, PAGE_SIZE, "%u\n",
1529 iqs269->ati_current &&
1530 completion_done(&iqs269->ati_done));
1533 static ssize_t ati_trigger_store(struct device *dev,
1534 struct device_attribute *attr, const char *buf,
1537 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1538 struct i2c_client *client = iqs269->client;
1542 error = kstrtouint(buf, 10, &val);
1549 disable_irq(client->irq);
1550 reinit_completion(&iqs269->ati_done);
1552 error = iqs269_dev_init(iqs269);
1555 enable_irq(client->irq);
1560 if (!wait_for_completion_timeout(&iqs269->ati_done,
1561 msecs_to_jiffies(2000)))
1567 static DEVICE_ATTR_RO(counts);
1568 static DEVICE_ATTR_RO(hall_bin);
1569 static DEVICE_ATTR_RW(hall_enable);
1570 static DEVICE_ATTR_RW(ch_number);
1571 static DEVICE_ATTR_RW(rx_enable);
1572 static DEVICE_ATTR_RW(ati_mode);
1573 static DEVICE_ATTR_RW(ati_base);
1574 static DEVICE_ATTR_RW(ati_target);
1575 static DEVICE_ATTR_RW(ati_trigger);
1577 static struct attribute *iqs269_attrs[] = {
1578 &dev_attr_counts.attr,
1579 &dev_attr_hall_bin.attr,
1580 &dev_attr_hall_enable.attr,
1581 &dev_attr_ch_number.attr,
1582 &dev_attr_rx_enable.attr,
1583 &dev_attr_ati_mode.attr,
1584 &dev_attr_ati_base.attr,
1585 &dev_attr_ati_target.attr,
1586 &dev_attr_ati_trigger.attr,
1589 ATTRIBUTE_GROUPS(iqs269);
1591 static const struct regmap_config iqs269_regmap_config = {
1594 .max_register = IQS269_MAX_REG,
1597 static int iqs269_probe(struct i2c_client *client)
1599 struct iqs269_ver_info ver_info;
1600 struct iqs269_private *iqs269;
1603 iqs269 = devm_kzalloc(&client->dev, sizeof(*iqs269), GFP_KERNEL);
1607 i2c_set_clientdata(client, iqs269);
1608 iqs269->client = client;
1610 iqs269->regmap = devm_regmap_init_i2c(client, &iqs269_regmap_config);
1611 if (IS_ERR(iqs269->regmap)) {
1612 error = PTR_ERR(iqs269->regmap);
1613 dev_err(&client->dev, "Failed to initialize register map: %d\n",
1618 mutex_init(&iqs269->lock);
1619 init_completion(&iqs269->ati_done);
1621 error = regmap_raw_read(iqs269->regmap, IQS269_VER_INFO, &ver_info,
1626 if (ver_info.prod_num != IQS269_VER_INFO_PROD_NUM) {
1627 dev_err(&client->dev, "Unrecognized product number: 0x%02X\n",
1632 error = iqs269_parse_prop(iqs269);
1636 error = iqs269_dev_init(iqs269);
1638 dev_err(&client->dev, "Failed to initialize device: %d\n",
1643 error = iqs269_input_init(iqs269);
1647 error = devm_request_threaded_irq(&client->dev, client->irq,
1648 NULL, iqs269_irq, IRQF_ONESHOT,
1649 client->name, iqs269);
1651 dev_err(&client->dev, "Failed to request IRQ: %d\n", error);
1655 if (!wait_for_completion_timeout(&iqs269->ati_done,
1656 msecs_to_jiffies(2000))) {
1657 dev_err(&client->dev, "Failed to complete ATI\n");
1662 * The keypad may include one or more switches and is not registered
1663 * until ATI is complete and the initial switch states are read.
1665 error = input_register_device(iqs269->keypad);
1667 dev_err(&client->dev, "Failed to register keypad: %d\n", error);
1674 static u16 iqs269_general_get(struct iqs269_private *iqs269)
1676 u16 general = be16_to_cpu(iqs269->sys_reg.general);
1678 general &= ~IQS269_SYS_SETTINGS_REDO_ATI;
1679 general &= ~IQS269_SYS_SETTINGS_ACK_RESET;
1681 return general | IQS269_SYS_SETTINGS_DIS_AUTO;
1684 static int iqs269_suspend(struct device *dev)
1686 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1687 struct i2c_client *client = iqs269->client;
1689 u16 general = iqs269_general_get(iqs269);
1691 if (!(general & IQS269_SYS_SETTINGS_PWR_MODE_MASK))
1694 disable_irq(client->irq);
1696 error = regmap_write(iqs269->regmap, IQS269_SYS_SETTINGS, general);
1699 enable_irq(client->irq);
1704 static int iqs269_resume(struct device *dev)
1706 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1707 struct i2c_client *client = iqs269->client;
1709 u16 general = iqs269_general_get(iqs269);
1711 if (!(general & IQS269_SYS_SETTINGS_PWR_MODE_MASK))
1714 disable_irq(client->irq);
1716 error = regmap_write(iqs269->regmap, IQS269_SYS_SETTINGS,
1717 general & ~IQS269_SYS_SETTINGS_PWR_MODE_MASK);
1719 error = regmap_write(iqs269->regmap, IQS269_SYS_SETTINGS,
1720 general & ~IQS269_SYS_SETTINGS_DIS_AUTO);
1723 enable_irq(client->irq);
1728 static DEFINE_SIMPLE_DEV_PM_OPS(iqs269_pm, iqs269_suspend, iqs269_resume);
1730 static const struct of_device_id iqs269_of_match[] = {
1731 { .compatible = "azoteq,iqs269a" },
1734 MODULE_DEVICE_TABLE(of, iqs269_of_match);
1736 static struct i2c_driver iqs269_i2c_driver = {
1739 .dev_groups = iqs269_groups,
1740 .of_match_table = iqs269_of_match,
1741 .pm = pm_sleep_ptr(&iqs269_pm),
1743 .probe = iqs269_probe,
1745 module_i2c_driver(iqs269_i2c_driver);
1747 MODULE_AUTHOR("Jeff LaBundy <jeff@labundy.com>");
1748 MODULE_DESCRIPTION("Azoteq IQS269A Capacitive Touch Controller");
1749 MODULE_LICENSE("GPL");