1 // SPDX-License-Identifier: GPL-2.0+
3 * Azoteq IQS269A Capacitive Touch Controller
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/delay.h>
13 #include <linux/device.h>
14 #include <linux/err.h>
15 #include <linux/i2c.h>
16 #include <linux/input.h>
17 #include <linux/interrupt.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/mutex.h>
21 #include <linux/of_device.h>
22 #include <linux/property.h>
23 #include <linux/regmap.h>
24 #include <linux/slab.h>
26 #define IQS269_VER_INFO 0x00
27 #define IQS269_VER_INFO_PROD_NUM 0x4F
29 #define IQS269_SYS_FLAGS 0x02
30 #define IQS269_SYS_FLAGS_SHOW_RESET BIT(15)
31 #define IQS269_SYS_FLAGS_PWR_MODE_MASK GENMASK(12, 11)
32 #define IQS269_SYS_FLAGS_PWR_MODE_SHIFT 11
33 #define IQS269_SYS_FLAGS_IN_ATI BIT(10)
35 #define IQS269_CHx_COUNTS 0x08
37 #define IQS269_SLIDER_X 0x30
39 #define IQS269_CAL_DATA_A 0x35
40 #define IQS269_CAL_DATA_A_HALL_BIN_L_MASK GENMASK(15, 12)
41 #define IQS269_CAL_DATA_A_HALL_BIN_L_SHIFT 12
42 #define IQS269_CAL_DATA_A_HALL_BIN_R_MASK GENMASK(11, 8)
43 #define IQS269_CAL_DATA_A_HALL_BIN_R_SHIFT 8
45 #define IQS269_SYS_SETTINGS 0x80
46 #define IQS269_SYS_SETTINGS_CLK_DIV BIT(15)
47 #define IQS269_SYS_SETTINGS_ULP_AUTO BIT(14)
48 #define IQS269_SYS_SETTINGS_DIS_AUTO BIT(13)
49 #define IQS269_SYS_SETTINGS_PWR_MODE_MASK GENMASK(12, 11)
50 #define IQS269_SYS_SETTINGS_PWR_MODE_SHIFT 11
51 #define IQS269_SYS_SETTINGS_PWR_MODE_MAX 3
52 #define IQS269_SYS_SETTINGS_ULP_UPDATE_MASK GENMASK(10, 8)
53 #define IQS269_SYS_SETTINGS_ULP_UPDATE_SHIFT 8
54 #define IQS269_SYS_SETTINGS_ULP_UPDATE_MAX 7
55 #define IQS269_SYS_SETTINGS_RESEED_OFFSET BIT(6)
56 #define IQS269_SYS_SETTINGS_EVENT_MODE BIT(5)
57 #define IQS269_SYS_SETTINGS_EVENT_MODE_LP BIT(4)
58 #define IQS269_SYS_SETTINGS_REDO_ATI BIT(2)
59 #define IQS269_SYS_SETTINGS_ACK_RESET BIT(0)
61 #define IQS269_FILT_STR_LP_LTA_MASK GENMASK(7, 6)
62 #define IQS269_FILT_STR_LP_LTA_SHIFT 6
63 #define IQS269_FILT_STR_LP_CNT_MASK GENMASK(5, 4)
64 #define IQS269_FILT_STR_LP_CNT_SHIFT 4
65 #define IQS269_FILT_STR_NP_LTA_MASK GENMASK(3, 2)
66 #define IQS269_FILT_STR_NP_LTA_SHIFT 2
67 #define IQS269_FILT_STR_NP_CNT_MASK GENMASK(1, 0)
68 #define IQS269_FILT_STR_MAX 3
70 #define IQS269_EVENT_MASK_SYS BIT(6)
71 #define IQS269_EVENT_MASK_DEEP BIT(2)
72 #define IQS269_EVENT_MASK_TOUCH BIT(1)
73 #define IQS269_EVENT_MASK_PROX BIT(0)
75 #define IQS269_RATE_NP_MS_MAX 255
76 #define IQS269_RATE_LP_MS_MAX 255
77 #define IQS269_RATE_ULP_MS_MAX 4080
78 #define IQS269_TIMEOUT_PWR_MS_MAX 130560
79 #define IQS269_TIMEOUT_LTA_MS_MAX 130560
81 #define IQS269_MISC_A_ATI_BAND_DISABLE BIT(15)
82 #define IQS269_MISC_A_ATI_LP_ONLY BIT(14)
83 #define IQS269_MISC_A_ATI_BAND_TIGHTEN BIT(13)
84 #define IQS269_MISC_A_FILT_DISABLE BIT(12)
85 #define IQS269_MISC_A_GPIO3_SELECT_MASK GENMASK(10, 8)
86 #define IQS269_MISC_A_GPIO3_SELECT_SHIFT 8
87 #define IQS269_MISC_A_DUAL_DIR BIT(6)
88 #define IQS269_MISC_A_TX_FREQ_MASK GENMASK(5, 4)
89 #define IQS269_MISC_A_TX_FREQ_SHIFT 4
90 #define IQS269_MISC_A_TX_FREQ_MAX 3
91 #define IQS269_MISC_A_GLOBAL_CAP_SIZE BIT(0)
93 #define IQS269_MISC_B_RESEED_UI_SEL_MASK GENMASK(7, 6)
94 #define IQS269_MISC_B_RESEED_UI_SEL_SHIFT 6
95 #define IQS269_MISC_B_RESEED_UI_SEL_MAX 3
96 #define IQS269_MISC_B_TRACKING_UI_ENABLE BIT(4)
97 #define IQS269_MISC_B_FILT_STR_SLIDER GENMASK(1, 0)
99 #define IQS269_CHx_SETTINGS 0x8C
101 #define IQS269_CHx_ENG_A_MEAS_CAP_SIZE BIT(15)
102 #define IQS269_CHx_ENG_A_RX_GND_INACTIVE BIT(13)
103 #define IQS269_CHx_ENG_A_LOCAL_CAP_SIZE BIT(12)
104 #define IQS269_CHx_ENG_A_ATI_MODE_MASK GENMASK(9, 8)
105 #define IQS269_CHx_ENG_A_ATI_MODE_SHIFT 8
106 #define IQS269_CHx_ENG_A_ATI_MODE_MAX 3
107 #define IQS269_CHx_ENG_A_INV_LOGIC BIT(7)
108 #define IQS269_CHx_ENG_A_PROJ_BIAS_MASK GENMASK(6, 5)
109 #define IQS269_CHx_ENG_A_PROJ_BIAS_SHIFT 5
110 #define IQS269_CHx_ENG_A_PROJ_BIAS_MAX 3
111 #define IQS269_CHx_ENG_A_SENSE_MODE_MASK GENMASK(3, 0)
112 #define IQS269_CHx_ENG_A_SENSE_MODE_MAX 15
114 #define IQS269_CHx_ENG_B_LOCAL_CAP_ENABLE BIT(13)
115 #define IQS269_CHx_ENG_B_SENSE_FREQ_MASK GENMASK(10, 9)
116 #define IQS269_CHx_ENG_B_SENSE_FREQ_SHIFT 9
117 #define IQS269_CHx_ENG_B_SENSE_FREQ_MAX 3
118 #define IQS269_CHx_ENG_B_STATIC_ENABLE BIT(8)
119 #define IQS269_CHx_ENG_B_ATI_BASE_MASK GENMASK(7, 6)
120 #define IQS269_CHx_ENG_B_ATI_BASE_75 0x00
121 #define IQS269_CHx_ENG_B_ATI_BASE_100 0x40
122 #define IQS269_CHx_ENG_B_ATI_BASE_150 0x80
123 #define IQS269_CHx_ENG_B_ATI_BASE_200 0xC0
124 #define IQS269_CHx_ENG_B_ATI_TARGET_MASK GENMASK(5, 0)
125 #define IQS269_CHx_ENG_B_ATI_TARGET_MAX 2016
127 #define IQS269_CHx_WEIGHT_MAX 255
128 #define IQS269_CHx_THRESH_MAX 255
129 #define IQS269_CHx_HYST_DEEP_MASK GENMASK(7, 4)
130 #define IQS269_CHx_HYST_DEEP_SHIFT 4
131 #define IQS269_CHx_HYST_TOUCH_MASK GENMASK(3, 0)
132 #define IQS269_CHx_HYST_MAX 15
134 #define IQS269_CHx_HALL_INACTIVE 6
135 #define IQS269_CHx_HALL_ACTIVE 7
137 #define IQS269_HALL_PAD_R BIT(0)
138 #define IQS269_HALL_PAD_L BIT(1)
139 #define IQS269_HALL_PAD_INV BIT(6)
141 #define IQS269_HALL_UI 0xF5
142 #define IQS269_HALL_UI_ENABLE BIT(15)
144 #define IQS269_MAX_REG 0xFF
146 #define IQS269_NUM_CH 8
147 #define IQS269_NUM_SL 2
149 #define IQS269_ATI_POLL_SLEEP_US (iqs269->delay_mult * 10000)
150 #define IQS269_ATI_POLL_TIMEOUT_US (iqs269->delay_mult * 500000)
151 #define IQS269_ATI_STABLE_DELAY_MS (iqs269->delay_mult * 150)
153 #define IQS269_PWR_MODE_POLL_SLEEP_US IQS269_ATI_POLL_SLEEP_US
154 #define IQS269_PWR_MODE_POLL_TIMEOUT_US IQS269_ATI_POLL_TIMEOUT_US
156 #define iqs269_irq_wait() usleep_range(100, 150)
158 enum iqs269_local_cap_size {
159 IQS269_LOCAL_CAP_SIZE_0,
160 IQS269_LOCAL_CAP_SIZE_GLOBAL_ONLY,
161 IQS269_LOCAL_CAP_SIZE_GLOBAL_0pF5,
164 enum iqs269_st_offs {
167 IQS269_ST_OFFS_TOUCH,
171 enum iqs269_th_offs {
173 IQS269_TH_OFFS_TOUCH,
177 enum iqs269_event_id {
178 IQS269_EVENT_PROX_DN,
179 IQS269_EVENT_PROX_UP,
180 IQS269_EVENT_TOUCH_DN,
181 IQS269_EVENT_TOUCH_UP,
182 IQS269_EVENT_DEEP_DN,
183 IQS269_EVENT_DEEP_UP,
186 struct iqs269_switch_desc {
191 struct iqs269_event_desc {
193 enum iqs269_st_offs st_offs;
194 enum iqs269_th_offs th_offs;
199 static const struct iqs269_event_desc iqs269_events[] = {
200 [IQS269_EVENT_PROX_DN] = {
201 .name = "event-prox",
202 .st_offs = IQS269_ST_OFFS_PROX,
203 .th_offs = IQS269_TH_OFFS_PROX,
204 .mask = IQS269_EVENT_MASK_PROX,
206 [IQS269_EVENT_PROX_UP] = {
207 .name = "event-prox-alt",
208 .st_offs = IQS269_ST_OFFS_PROX,
209 .th_offs = IQS269_TH_OFFS_PROX,
211 .mask = IQS269_EVENT_MASK_PROX,
213 [IQS269_EVENT_TOUCH_DN] = {
214 .name = "event-touch",
215 .st_offs = IQS269_ST_OFFS_TOUCH,
216 .th_offs = IQS269_TH_OFFS_TOUCH,
217 .mask = IQS269_EVENT_MASK_TOUCH,
219 [IQS269_EVENT_TOUCH_UP] = {
220 .name = "event-touch-alt",
221 .st_offs = IQS269_ST_OFFS_TOUCH,
222 .th_offs = IQS269_TH_OFFS_TOUCH,
224 .mask = IQS269_EVENT_MASK_TOUCH,
226 [IQS269_EVENT_DEEP_DN] = {
227 .name = "event-deep",
228 .st_offs = IQS269_ST_OFFS_DEEP,
229 .th_offs = IQS269_TH_OFFS_DEEP,
230 .mask = IQS269_EVENT_MASK_DEEP,
232 [IQS269_EVENT_DEEP_UP] = {
233 .name = "event-deep-alt",
234 .st_offs = IQS269_ST_OFFS_DEEP,
235 .th_offs = IQS269_TH_OFFS_DEEP,
237 .mask = IQS269_EVENT_MASK_DEEP,
241 struct iqs269_ver_info {
248 struct iqs269_sys_reg {
264 u8 slider_select[IQS269_NUM_SL];
271 struct iqs269_ch_reg {
283 struct iqs269_flags {
290 struct iqs269_private {
291 struct i2c_client *client;
292 struct regmap *regmap;
294 struct iqs269_switch_desc switches[ARRAY_SIZE(iqs269_events)];
295 struct iqs269_ch_reg ch_reg[IQS269_NUM_CH];
296 struct iqs269_sys_reg sys_reg;
297 struct input_dev *keypad;
298 struct input_dev *slider[IQS269_NUM_SL];
299 unsigned int keycode[ARRAY_SIZE(iqs269_events) * IQS269_NUM_CH];
300 unsigned int suspend_mode;
301 unsigned int delay_mult;
307 static int iqs269_ati_mode_set(struct iqs269_private *iqs269,
308 unsigned int ch_num, unsigned int mode)
312 if (ch_num >= IQS269_NUM_CH)
315 if (mode > IQS269_CHx_ENG_A_ATI_MODE_MAX)
318 mutex_lock(&iqs269->lock);
320 engine_a = be16_to_cpu(iqs269->ch_reg[ch_num].engine_a);
322 engine_a &= ~IQS269_CHx_ENG_A_ATI_MODE_MASK;
323 engine_a |= (mode << IQS269_CHx_ENG_A_ATI_MODE_SHIFT);
325 iqs269->ch_reg[ch_num].engine_a = cpu_to_be16(engine_a);
326 iqs269->ati_current = false;
328 mutex_unlock(&iqs269->lock);
333 static int iqs269_ati_mode_get(struct iqs269_private *iqs269,
334 unsigned int ch_num, unsigned int *mode)
338 if (ch_num >= IQS269_NUM_CH)
341 mutex_lock(&iqs269->lock);
342 engine_a = be16_to_cpu(iqs269->ch_reg[ch_num].engine_a);
343 mutex_unlock(&iqs269->lock);
345 engine_a &= IQS269_CHx_ENG_A_ATI_MODE_MASK;
346 *mode = (engine_a >> IQS269_CHx_ENG_A_ATI_MODE_SHIFT);
351 static int iqs269_ati_base_set(struct iqs269_private *iqs269,
352 unsigned int ch_num, unsigned int base)
356 if (ch_num >= IQS269_NUM_CH)
361 base = IQS269_CHx_ENG_B_ATI_BASE_75;
365 base = IQS269_CHx_ENG_B_ATI_BASE_100;
369 base = IQS269_CHx_ENG_B_ATI_BASE_150;
373 base = IQS269_CHx_ENG_B_ATI_BASE_200;
380 mutex_lock(&iqs269->lock);
382 engine_b = be16_to_cpu(iqs269->ch_reg[ch_num].engine_b);
384 engine_b &= ~IQS269_CHx_ENG_B_ATI_BASE_MASK;
387 iqs269->ch_reg[ch_num].engine_b = cpu_to_be16(engine_b);
388 iqs269->ati_current = false;
390 mutex_unlock(&iqs269->lock);
395 static int iqs269_ati_base_get(struct iqs269_private *iqs269,
396 unsigned int ch_num, unsigned int *base)
400 if (ch_num >= IQS269_NUM_CH)
403 mutex_lock(&iqs269->lock);
404 engine_b = be16_to_cpu(iqs269->ch_reg[ch_num].engine_b);
405 mutex_unlock(&iqs269->lock);
407 switch (engine_b & IQS269_CHx_ENG_B_ATI_BASE_MASK) {
408 case IQS269_CHx_ENG_B_ATI_BASE_75:
412 case IQS269_CHx_ENG_B_ATI_BASE_100:
416 case IQS269_CHx_ENG_B_ATI_BASE_150:
420 case IQS269_CHx_ENG_B_ATI_BASE_200:
429 static int iqs269_ati_target_set(struct iqs269_private *iqs269,
430 unsigned int ch_num, unsigned int target)
434 if (ch_num >= IQS269_NUM_CH)
437 if (target > IQS269_CHx_ENG_B_ATI_TARGET_MAX)
440 mutex_lock(&iqs269->lock);
442 engine_b = be16_to_cpu(iqs269->ch_reg[ch_num].engine_b);
444 engine_b &= ~IQS269_CHx_ENG_B_ATI_TARGET_MASK;
445 engine_b |= target / 32;
447 iqs269->ch_reg[ch_num].engine_b = cpu_to_be16(engine_b);
448 iqs269->ati_current = false;
450 mutex_unlock(&iqs269->lock);
455 static int iqs269_ati_target_get(struct iqs269_private *iqs269,
456 unsigned int ch_num, unsigned int *target)
460 if (ch_num >= IQS269_NUM_CH)
463 mutex_lock(&iqs269->lock);
464 engine_b = be16_to_cpu(iqs269->ch_reg[ch_num].engine_b);
465 mutex_unlock(&iqs269->lock);
467 *target = (engine_b & IQS269_CHx_ENG_B_ATI_TARGET_MASK) * 32;
472 static int iqs269_parse_mask(const struct fwnode_handle *fwnode,
473 const char *propname, u8 *mask)
475 unsigned int val[IQS269_NUM_CH];
478 count = fwnode_property_count_u32(fwnode, propname);
482 if (count > IQS269_NUM_CH)
485 error = fwnode_property_read_u32_array(fwnode, propname, val, count);
491 for (i = 0; i < count; i++) {
492 if (val[i] >= IQS269_NUM_CH)
495 *mask |= BIT(val[i]);
501 static int iqs269_parse_chan(struct iqs269_private *iqs269,
502 const struct fwnode_handle *ch_node)
504 struct i2c_client *client = iqs269->client;
505 struct fwnode_handle *ev_node;
506 struct iqs269_ch_reg *ch_reg;
507 u16 engine_a, engine_b;
508 unsigned int reg, val;
511 error = fwnode_property_read_u32(ch_node, "reg", ®);
513 dev_err(&client->dev, "Failed to read channel number: %d\n",
516 } else if (reg >= IQS269_NUM_CH) {
517 dev_err(&client->dev, "Invalid channel number: %u\n", reg);
521 iqs269->sys_reg.active |= BIT(reg);
522 if (!fwnode_property_present(ch_node, "azoteq,reseed-disable"))
523 iqs269->sys_reg.reseed |= BIT(reg);
525 if (fwnode_property_present(ch_node, "azoteq,blocking-enable"))
526 iqs269->sys_reg.blocking |= BIT(reg);
528 if (fwnode_property_present(ch_node, "azoteq,slider0-select"))
529 iqs269->sys_reg.slider_select[0] |= BIT(reg);
531 if (fwnode_property_present(ch_node, "azoteq,slider1-select"))
532 iqs269->sys_reg.slider_select[1] |= BIT(reg);
534 ch_reg = &iqs269->ch_reg[reg];
536 error = regmap_raw_read(iqs269->regmap,
537 IQS269_CHx_SETTINGS + reg * sizeof(*ch_reg) / 2,
538 ch_reg, sizeof(*ch_reg));
542 error = iqs269_parse_mask(ch_node, "azoteq,rx-enable",
545 dev_err(&client->dev, "Invalid channel %u RX enable mask: %d\n",
550 error = iqs269_parse_mask(ch_node, "azoteq,tx-enable",
553 dev_err(&client->dev, "Invalid channel %u TX enable mask: %d\n",
558 engine_a = be16_to_cpu(ch_reg->engine_a);
559 engine_b = be16_to_cpu(ch_reg->engine_b);
561 engine_a |= IQS269_CHx_ENG_A_MEAS_CAP_SIZE;
562 if (fwnode_property_present(ch_node, "azoteq,meas-cap-decrease"))
563 engine_a &= ~IQS269_CHx_ENG_A_MEAS_CAP_SIZE;
565 engine_a |= IQS269_CHx_ENG_A_RX_GND_INACTIVE;
566 if (fwnode_property_present(ch_node, "azoteq,rx-float-inactive"))
567 engine_a &= ~IQS269_CHx_ENG_A_RX_GND_INACTIVE;
569 engine_a &= ~IQS269_CHx_ENG_A_LOCAL_CAP_SIZE;
570 engine_b &= ~IQS269_CHx_ENG_B_LOCAL_CAP_ENABLE;
571 if (!fwnode_property_read_u32(ch_node, "azoteq,local-cap-size", &val)) {
573 case IQS269_LOCAL_CAP_SIZE_0:
576 case IQS269_LOCAL_CAP_SIZE_GLOBAL_0pF5:
577 engine_a |= IQS269_CHx_ENG_A_LOCAL_CAP_SIZE;
580 case IQS269_LOCAL_CAP_SIZE_GLOBAL_ONLY:
581 engine_b |= IQS269_CHx_ENG_B_LOCAL_CAP_ENABLE;
585 dev_err(&client->dev,
586 "Invalid channel %u local cap. size: %u\n", reg,
592 engine_a &= ~IQS269_CHx_ENG_A_INV_LOGIC;
593 if (fwnode_property_present(ch_node, "azoteq,invert-enable"))
594 engine_a |= IQS269_CHx_ENG_A_INV_LOGIC;
596 if (!fwnode_property_read_u32(ch_node, "azoteq,proj-bias", &val)) {
597 if (val > IQS269_CHx_ENG_A_PROJ_BIAS_MAX) {
598 dev_err(&client->dev,
599 "Invalid channel %u bias current: %u\n", reg,
604 engine_a &= ~IQS269_CHx_ENG_A_PROJ_BIAS_MASK;
605 engine_a |= (val << IQS269_CHx_ENG_A_PROJ_BIAS_SHIFT);
608 if (!fwnode_property_read_u32(ch_node, "azoteq,sense-mode", &val)) {
609 if (val > IQS269_CHx_ENG_A_SENSE_MODE_MAX) {
610 dev_err(&client->dev,
611 "Invalid channel %u sensing mode: %u\n", reg,
616 engine_a &= ~IQS269_CHx_ENG_A_SENSE_MODE_MASK;
620 if (!fwnode_property_read_u32(ch_node, "azoteq,sense-freq", &val)) {
621 if (val > IQS269_CHx_ENG_B_SENSE_FREQ_MAX) {
622 dev_err(&client->dev,
623 "Invalid channel %u sensing frequency: %u\n",
628 engine_b &= ~IQS269_CHx_ENG_B_SENSE_FREQ_MASK;
629 engine_b |= (val << IQS269_CHx_ENG_B_SENSE_FREQ_SHIFT);
632 engine_b &= ~IQS269_CHx_ENG_B_STATIC_ENABLE;
633 if (fwnode_property_present(ch_node, "azoteq,static-enable"))
634 engine_b |= IQS269_CHx_ENG_B_STATIC_ENABLE;
636 ch_reg->engine_a = cpu_to_be16(engine_a);
637 ch_reg->engine_b = cpu_to_be16(engine_b);
639 if (!fwnode_property_read_u32(ch_node, "azoteq,ati-mode", &val)) {
640 error = iqs269_ati_mode_set(iqs269, reg, val);
642 dev_err(&client->dev,
643 "Invalid channel %u ATI mode: %u\n", reg, val);
648 if (!fwnode_property_read_u32(ch_node, "azoteq,ati-base", &val)) {
649 error = iqs269_ati_base_set(iqs269, reg, val);
651 dev_err(&client->dev,
652 "Invalid channel %u ATI base: %u\n", reg, val);
657 if (!fwnode_property_read_u32(ch_node, "azoteq,ati-target", &val)) {
658 error = iqs269_ati_target_set(iqs269, reg, val);
660 dev_err(&client->dev,
661 "Invalid channel %u ATI target: %u\n", reg,
667 error = iqs269_parse_mask(ch_node, "azoteq,assoc-select",
668 &ch_reg->assoc_select);
670 dev_err(&client->dev, "Invalid channel %u association: %d\n",
675 if (!fwnode_property_read_u32(ch_node, "azoteq,assoc-weight", &val)) {
676 if (val > IQS269_CHx_WEIGHT_MAX) {
677 dev_err(&client->dev,
678 "Invalid channel %u associated weight: %u\n",
683 ch_reg->assoc_weight = val;
686 for (i = 0; i < ARRAY_SIZE(iqs269_events); i++) {
687 ev_node = fwnode_get_named_child_node(ch_node,
688 iqs269_events[i].name);
692 if (!fwnode_property_read_u32(ev_node, "azoteq,thresh", &val)) {
693 if (val > IQS269_CHx_THRESH_MAX) {
694 dev_err(&client->dev,
695 "Invalid channel %u threshold: %u\n",
700 ch_reg->thresh[iqs269_events[i].th_offs] = val;
703 if (!fwnode_property_read_u32(ev_node, "azoteq,hyst", &val)) {
704 u8 *hyst = &ch_reg->hyst;
706 if (val > IQS269_CHx_HYST_MAX) {
707 dev_err(&client->dev,
708 "Invalid channel %u hysteresis: %u\n",
713 if (i == IQS269_EVENT_DEEP_DN ||
714 i == IQS269_EVENT_DEEP_UP) {
715 *hyst &= ~IQS269_CHx_HYST_DEEP_MASK;
716 *hyst |= (val << IQS269_CHx_HYST_DEEP_SHIFT);
717 } else if (i == IQS269_EVENT_TOUCH_DN ||
718 i == IQS269_EVENT_TOUCH_UP) {
719 *hyst &= ~IQS269_CHx_HYST_TOUCH_MASK;
724 if (fwnode_property_read_u32(ev_node, "linux,code", &val))
728 case IQS269_CHx_HALL_ACTIVE:
729 if (iqs269->hall_enable) {
730 iqs269->switches[i].code = val;
731 iqs269->switches[i].enabled = true;
735 case IQS269_CHx_HALL_INACTIVE:
736 if (iqs269->hall_enable)
741 iqs269->keycode[i * IQS269_NUM_CH + reg] = val;
744 iqs269->sys_reg.event_mask &= ~iqs269_events[i].mask;
750 static int iqs269_parse_prop(struct iqs269_private *iqs269)
752 struct iqs269_sys_reg *sys_reg = &iqs269->sys_reg;
753 struct i2c_client *client = iqs269->client;
754 struct fwnode_handle *ch_node;
755 u16 general, misc_a, misc_b;
759 iqs269->hall_enable = device_property_present(&client->dev,
760 "azoteq,hall-enable");
762 if (!device_property_read_u32(&client->dev, "azoteq,suspend-mode",
764 if (val > IQS269_SYS_SETTINGS_PWR_MODE_MAX) {
765 dev_err(&client->dev, "Invalid suspend mode: %u\n",
770 iqs269->suspend_mode = val;
773 error = regmap_raw_read(iqs269->regmap, IQS269_SYS_SETTINGS, sys_reg,
778 if (!device_property_read_u32(&client->dev, "azoteq,filt-str-lp-lta",
780 if (val > IQS269_FILT_STR_MAX) {
781 dev_err(&client->dev, "Invalid filter strength: %u\n",
786 sys_reg->filter &= ~IQS269_FILT_STR_LP_LTA_MASK;
787 sys_reg->filter |= (val << IQS269_FILT_STR_LP_LTA_SHIFT);
790 if (!device_property_read_u32(&client->dev, "azoteq,filt-str-lp-cnt",
792 if (val > IQS269_FILT_STR_MAX) {
793 dev_err(&client->dev, "Invalid filter strength: %u\n",
798 sys_reg->filter &= ~IQS269_FILT_STR_LP_CNT_MASK;
799 sys_reg->filter |= (val << IQS269_FILT_STR_LP_CNT_SHIFT);
802 if (!device_property_read_u32(&client->dev, "azoteq,filt-str-np-lta",
804 if (val > IQS269_FILT_STR_MAX) {
805 dev_err(&client->dev, "Invalid filter strength: %u\n",
810 sys_reg->filter &= ~IQS269_FILT_STR_NP_LTA_MASK;
811 sys_reg->filter |= (val << IQS269_FILT_STR_NP_LTA_SHIFT);
814 if (!device_property_read_u32(&client->dev, "azoteq,filt-str-np-cnt",
816 if (val > IQS269_FILT_STR_MAX) {
817 dev_err(&client->dev, "Invalid filter strength: %u\n",
822 sys_reg->filter &= ~IQS269_FILT_STR_NP_CNT_MASK;
823 sys_reg->filter |= val;
826 if (!device_property_read_u32(&client->dev, "azoteq,rate-np-ms",
828 if (val > IQS269_RATE_NP_MS_MAX) {
829 dev_err(&client->dev, "Invalid report rate: %u\n", val);
833 sys_reg->rate_np = val;
836 if (!device_property_read_u32(&client->dev, "azoteq,rate-lp-ms",
838 if (val > IQS269_RATE_LP_MS_MAX) {
839 dev_err(&client->dev, "Invalid report rate: %u\n", val);
843 sys_reg->rate_lp = val;
846 if (!device_property_read_u32(&client->dev, "azoteq,rate-ulp-ms",
848 if (val > IQS269_RATE_ULP_MS_MAX) {
849 dev_err(&client->dev, "Invalid report rate: %u\n", val);
853 sys_reg->rate_ulp = val / 16;
856 if (!device_property_read_u32(&client->dev, "azoteq,timeout-pwr-ms",
858 if (val > IQS269_TIMEOUT_PWR_MS_MAX) {
859 dev_err(&client->dev, "Invalid timeout: %u\n", val);
863 sys_reg->timeout_pwr = val / 512;
866 if (!device_property_read_u32(&client->dev, "azoteq,timeout-lta-ms",
868 if (val > IQS269_TIMEOUT_LTA_MS_MAX) {
869 dev_err(&client->dev, "Invalid timeout: %u\n", val);
873 sys_reg->timeout_lta = val / 512;
876 misc_a = be16_to_cpu(sys_reg->misc_a);
877 misc_b = be16_to_cpu(sys_reg->misc_b);
879 misc_a &= ~IQS269_MISC_A_ATI_BAND_DISABLE;
880 if (device_property_present(&client->dev, "azoteq,ati-band-disable"))
881 misc_a |= IQS269_MISC_A_ATI_BAND_DISABLE;
883 misc_a &= ~IQS269_MISC_A_ATI_LP_ONLY;
884 if (device_property_present(&client->dev, "azoteq,ati-lp-only"))
885 misc_a |= IQS269_MISC_A_ATI_LP_ONLY;
887 misc_a &= ~IQS269_MISC_A_ATI_BAND_TIGHTEN;
888 if (device_property_present(&client->dev, "azoteq,ati-band-tighten"))
889 misc_a |= IQS269_MISC_A_ATI_BAND_TIGHTEN;
891 misc_a &= ~IQS269_MISC_A_FILT_DISABLE;
892 if (device_property_present(&client->dev, "azoteq,filt-disable"))
893 misc_a |= IQS269_MISC_A_FILT_DISABLE;
895 if (!device_property_read_u32(&client->dev, "azoteq,gpio3-select",
897 if (val >= IQS269_NUM_CH) {
898 dev_err(&client->dev, "Invalid GPIO3 selection: %u\n",
903 misc_a &= ~IQS269_MISC_A_GPIO3_SELECT_MASK;
904 misc_a |= (val << IQS269_MISC_A_GPIO3_SELECT_SHIFT);
907 misc_a &= ~IQS269_MISC_A_DUAL_DIR;
908 if (device_property_present(&client->dev, "azoteq,dual-direction"))
909 misc_a |= IQS269_MISC_A_DUAL_DIR;
911 if (!device_property_read_u32(&client->dev, "azoteq,tx-freq", &val)) {
912 if (val > IQS269_MISC_A_TX_FREQ_MAX) {
913 dev_err(&client->dev,
914 "Invalid excitation frequency: %u\n", val);
918 misc_a &= ~IQS269_MISC_A_TX_FREQ_MASK;
919 misc_a |= (val << IQS269_MISC_A_TX_FREQ_SHIFT);
922 misc_a &= ~IQS269_MISC_A_GLOBAL_CAP_SIZE;
923 if (device_property_present(&client->dev, "azoteq,global-cap-increase"))
924 misc_a |= IQS269_MISC_A_GLOBAL_CAP_SIZE;
926 if (!device_property_read_u32(&client->dev, "azoteq,reseed-select",
928 if (val > IQS269_MISC_B_RESEED_UI_SEL_MAX) {
929 dev_err(&client->dev, "Invalid reseed selection: %u\n",
934 misc_b &= ~IQS269_MISC_B_RESEED_UI_SEL_MASK;
935 misc_b |= (val << IQS269_MISC_B_RESEED_UI_SEL_SHIFT);
938 misc_b &= ~IQS269_MISC_B_TRACKING_UI_ENABLE;
939 if (device_property_present(&client->dev, "azoteq,tracking-enable"))
940 misc_b |= IQS269_MISC_B_TRACKING_UI_ENABLE;
942 if (!device_property_read_u32(&client->dev, "azoteq,filt-str-slider",
944 if (val > IQS269_FILT_STR_MAX) {
945 dev_err(&client->dev, "Invalid filter strength: %u\n",
950 misc_b &= ~IQS269_MISC_B_FILT_STR_SLIDER;
954 sys_reg->misc_a = cpu_to_be16(misc_a);
955 sys_reg->misc_b = cpu_to_be16(misc_b);
960 sys_reg->blocking = 0;
962 sys_reg->slider_select[0] = 0;
963 sys_reg->slider_select[1] = 0;
965 sys_reg->event_mask = ~((u8)IQS269_EVENT_MASK_SYS);
967 device_for_each_child_node(&client->dev, ch_node) {
968 error = iqs269_parse_chan(iqs269, ch_node);
970 fwnode_handle_put(ch_node);
976 * Volunteer all active channels to participate in ATI when REDO-ATI is
977 * manually triggered.
979 sys_reg->redo_ati = sys_reg->active;
981 general = be16_to_cpu(sys_reg->general);
983 if (device_property_present(&client->dev, "azoteq,clk-div")) {
984 general |= IQS269_SYS_SETTINGS_CLK_DIV;
985 iqs269->delay_mult = 4;
987 general &= ~IQS269_SYS_SETTINGS_CLK_DIV;
988 iqs269->delay_mult = 1;
992 * Configure the device to automatically switch between normal and low-
993 * power modes as a function of sensing activity. Ultra-low-power mode,
994 * if enabled, is reserved for suspend.
996 general &= ~IQS269_SYS_SETTINGS_ULP_AUTO;
997 general &= ~IQS269_SYS_SETTINGS_DIS_AUTO;
998 general &= ~IQS269_SYS_SETTINGS_PWR_MODE_MASK;
1000 if (!device_property_read_u32(&client->dev, "azoteq,ulp-update",
1002 if (val > IQS269_SYS_SETTINGS_ULP_UPDATE_MAX) {
1003 dev_err(&client->dev, "Invalid update rate: %u\n", val);
1007 general &= ~IQS269_SYS_SETTINGS_ULP_UPDATE_MASK;
1008 general |= (val << IQS269_SYS_SETTINGS_ULP_UPDATE_SHIFT);
1011 general &= ~IQS269_SYS_SETTINGS_RESEED_OFFSET;
1012 if (device_property_present(&client->dev, "azoteq,reseed-offset"))
1013 general |= IQS269_SYS_SETTINGS_RESEED_OFFSET;
1015 general |= IQS269_SYS_SETTINGS_EVENT_MODE;
1018 * As per the datasheet, enable streaming during normal-power mode if
1019 * either slider is in use. In that case, the device returns to event
1020 * mode during low-power mode.
1022 if (sys_reg->slider_select[0] || sys_reg->slider_select[1])
1023 general |= IQS269_SYS_SETTINGS_EVENT_MODE_LP;
1025 general |= IQS269_SYS_SETTINGS_REDO_ATI;
1026 general |= IQS269_SYS_SETTINGS_ACK_RESET;
1028 sys_reg->general = cpu_to_be16(general);
1033 static int iqs269_dev_init(struct iqs269_private *iqs269)
1035 struct iqs269_sys_reg *sys_reg = &iqs269->sys_reg;
1036 struct iqs269_ch_reg *ch_reg;
1040 mutex_lock(&iqs269->lock);
1042 error = regmap_update_bits(iqs269->regmap, IQS269_HALL_UI,
1043 IQS269_HALL_UI_ENABLE,
1044 iqs269->hall_enable ? ~0 : 0);
1048 for (i = 0; i < IQS269_NUM_CH; i++) {
1049 if (!(sys_reg->active & BIT(i)))
1052 ch_reg = &iqs269->ch_reg[i];
1054 error = regmap_raw_write(iqs269->regmap,
1055 IQS269_CHx_SETTINGS + i *
1056 sizeof(*ch_reg) / 2, ch_reg,
1063 * The REDO-ATI and ATI channel selection fields must be written in the
1064 * same block write, so every field between registers 0x80 through 0x8B
1065 * (inclusive) must be written as well.
1067 error = regmap_raw_write(iqs269->regmap, IQS269_SYS_SETTINGS, sys_reg,
1072 error = regmap_read_poll_timeout(iqs269->regmap, IQS269_SYS_FLAGS, val,
1073 !(val & IQS269_SYS_FLAGS_IN_ATI),
1074 IQS269_ATI_POLL_SLEEP_US,
1075 IQS269_ATI_POLL_TIMEOUT_US);
1079 msleep(IQS269_ATI_STABLE_DELAY_MS);
1080 iqs269->ati_current = true;
1083 mutex_unlock(&iqs269->lock);
1088 static int iqs269_input_init(struct iqs269_private *iqs269)
1090 struct i2c_client *client = iqs269->client;
1091 struct iqs269_flags flags;
1092 unsigned int sw_code, keycode;
1096 iqs269->keypad = devm_input_allocate_device(&client->dev);
1097 if (!iqs269->keypad)
1100 iqs269->keypad->keycodemax = ARRAY_SIZE(iqs269->keycode);
1101 iqs269->keypad->keycode = iqs269->keycode;
1102 iqs269->keypad->keycodesize = sizeof(*iqs269->keycode);
1104 iqs269->keypad->name = "iqs269a_keypad";
1105 iqs269->keypad->id.bustype = BUS_I2C;
1107 if (iqs269->hall_enable) {
1108 error = regmap_raw_read(iqs269->regmap, IQS269_SYS_FLAGS,
1109 &flags, sizeof(flags));
1111 dev_err(&client->dev,
1112 "Failed to read initial status: %d\n", error);
1117 for (i = 0; i < ARRAY_SIZE(iqs269_events); i++) {
1118 dir_mask = flags.states[IQS269_ST_OFFS_DIR];
1119 if (!iqs269_events[i].dir_up)
1120 dir_mask = ~dir_mask;
1122 state = flags.states[iqs269_events[i].st_offs] & dir_mask;
1124 sw_code = iqs269->switches[i].code;
1126 for (j = 0; j < IQS269_NUM_CH; j++) {
1127 keycode = iqs269->keycode[i * IQS269_NUM_CH + j];
1130 * Hall-effect sensing repurposes a pair of dedicated
1131 * channels, only one of which reports events.
1134 case IQS269_CHx_HALL_ACTIVE:
1135 if (iqs269->hall_enable &&
1136 iqs269->switches[i].enabled) {
1137 input_set_capability(iqs269->keypad,
1139 input_report_switch(iqs269->keypad,
1145 case IQS269_CHx_HALL_INACTIVE:
1146 if (iqs269->hall_enable)
1151 if (keycode != KEY_RESERVED)
1152 input_set_capability(iqs269->keypad,
1158 input_sync(iqs269->keypad);
1160 error = input_register_device(iqs269->keypad);
1162 dev_err(&client->dev, "Failed to register keypad: %d\n", error);
1166 for (i = 0; i < IQS269_NUM_SL; i++) {
1167 if (!iqs269->sys_reg.slider_select[i])
1170 iqs269->slider[i] = devm_input_allocate_device(&client->dev);
1171 if (!iqs269->slider[i])
1174 iqs269->slider[i]->name = i ? "iqs269a_slider_1"
1175 : "iqs269a_slider_0";
1176 iqs269->slider[i]->id.bustype = BUS_I2C;
1178 input_set_capability(iqs269->slider[i], EV_KEY, BTN_TOUCH);
1179 input_set_abs_params(iqs269->slider[i], ABS_X, 0, 255, 0, 0);
1181 error = input_register_device(iqs269->slider[i]);
1183 dev_err(&client->dev,
1184 "Failed to register slider %d: %d\n", i, error);
1192 static int iqs269_report(struct iqs269_private *iqs269)
1194 struct i2c_client *client = iqs269->client;
1195 struct iqs269_flags flags;
1196 unsigned int sw_code, keycode;
1198 u8 slider_x[IQS269_NUM_SL];
1201 error = regmap_raw_read(iqs269->regmap, IQS269_SYS_FLAGS, &flags,
1204 dev_err(&client->dev, "Failed to read device status: %d\n",
1210 * The device resets itself if its own watchdog bites, which can happen
1211 * in the event of an I2C communication error. In this case, the device
1212 * asserts a SHOW_RESET interrupt and all registers must be restored.
1214 if (be16_to_cpu(flags.system) & IQS269_SYS_FLAGS_SHOW_RESET) {
1215 dev_err(&client->dev, "Unexpected device reset\n");
1217 error = iqs269_dev_init(iqs269);
1219 dev_err(&client->dev,
1220 "Failed to re-initialize device: %d\n", error);
1225 error = regmap_raw_read(iqs269->regmap, IQS269_SLIDER_X, slider_x,
1228 dev_err(&client->dev, "Failed to read slider position: %d\n",
1233 for (i = 0; i < IQS269_NUM_SL; i++) {
1234 if (!iqs269->sys_reg.slider_select[i])
1238 * Report BTN_TOUCH if any channel that participates in the
1239 * slider is in a state of touch.
1241 if (flags.states[IQS269_ST_OFFS_TOUCH] &
1242 iqs269->sys_reg.slider_select[i]) {
1243 input_report_key(iqs269->slider[i], BTN_TOUCH, 1);
1244 input_report_abs(iqs269->slider[i], ABS_X, slider_x[i]);
1246 input_report_key(iqs269->slider[i], BTN_TOUCH, 0);
1249 input_sync(iqs269->slider[i]);
1252 for (i = 0; i < ARRAY_SIZE(iqs269_events); i++) {
1253 dir_mask = flags.states[IQS269_ST_OFFS_DIR];
1254 if (!iqs269_events[i].dir_up)
1255 dir_mask = ~dir_mask;
1257 state = flags.states[iqs269_events[i].st_offs] & dir_mask;
1259 sw_code = iqs269->switches[i].code;
1261 for (j = 0; j < IQS269_NUM_CH; j++) {
1262 keycode = iqs269->keycode[i * IQS269_NUM_CH + j];
1265 case IQS269_CHx_HALL_ACTIVE:
1266 if (iqs269->hall_enable &&
1267 iqs269->switches[i].enabled)
1268 input_report_switch(iqs269->keypad,
1273 case IQS269_CHx_HALL_INACTIVE:
1274 if (iqs269->hall_enable)
1279 input_report_key(iqs269->keypad, keycode,
1285 input_sync(iqs269->keypad);
1290 static irqreturn_t iqs269_irq(int irq, void *context)
1292 struct iqs269_private *iqs269 = context;
1294 if (iqs269_report(iqs269))
1298 * The device does not deassert its interrupt (RDY) pin until shortly
1299 * after receiving an I2C stop condition; the following delay ensures
1300 * the interrupt handler does not return before this time.
1307 static ssize_t counts_show(struct device *dev,
1308 struct device_attribute *attr, char *buf)
1310 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1311 struct i2c_client *client = iqs269->client;
1315 if (!iqs269->ati_current || iqs269->hall_enable)
1319 * Unsolicited I2C communication prompts the device to assert its RDY
1320 * pin, so disable the interrupt line until the operation is finished
1321 * and RDY has been deasserted.
1323 disable_irq(client->irq);
1325 error = regmap_raw_read(iqs269->regmap,
1326 IQS269_CHx_COUNTS + iqs269->ch_num * 2,
1327 &counts, sizeof(counts));
1330 enable_irq(client->irq);
1335 return scnprintf(buf, PAGE_SIZE, "%u\n", le16_to_cpu(counts));
1338 static ssize_t hall_bin_show(struct device *dev,
1339 struct device_attribute *attr, char *buf)
1341 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1342 struct i2c_client *client = iqs269->client;
1346 disable_irq(client->irq);
1348 error = regmap_read(iqs269->regmap, IQS269_CAL_DATA_A, &val);
1351 enable_irq(client->irq);
1356 switch (iqs269->ch_reg[IQS269_CHx_HALL_ACTIVE].rx_enable &
1357 iqs269->ch_reg[IQS269_CHx_HALL_INACTIVE].rx_enable) {
1358 case IQS269_HALL_PAD_R:
1359 val &= IQS269_CAL_DATA_A_HALL_BIN_R_MASK;
1360 val >>= IQS269_CAL_DATA_A_HALL_BIN_R_SHIFT;
1363 case IQS269_HALL_PAD_L:
1364 val &= IQS269_CAL_DATA_A_HALL_BIN_L_MASK;
1365 val >>= IQS269_CAL_DATA_A_HALL_BIN_L_SHIFT;
1372 return scnprintf(buf, PAGE_SIZE, "%u\n", val);
1375 static ssize_t hall_enable_show(struct device *dev,
1376 struct device_attribute *attr, char *buf)
1378 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1380 return scnprintf(buf, PAGE_SIZE, "%u\n", iqs269->hall_enable);
1383 static ssize_t hall_enable_store(struct device *dev,
1384 struct device_attribute *attr, const char *buf,
1387 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1391 error = kstrtouint(buf, 10, &val);
1395 mutex_lock(&iqs269->lock);
1397 iqs269->hall_enable = val;
1398 iqs269->ati_current = false;
1400 mutex_unlock(&iqs269->lock);
1405 static ssize_t ch_number_show(struct device *dev,
1406 struct device_attribute *attr, char *buf)
1408 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1410 return scnprintf(buf, PAGE_SIZE, "%u\n", iqs269->ch_num);
1413 static ssize_t ch_number_store(struct device *dev,
1414 struct device_attribute *attr, const char *buf,
1417 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1421 error = kstrtouint(buf, 10, &val);
1425 if (val >= IQS269_NUM_CH)
1428 iqs269->ch_num = val;
1433 static ssize_t rx_enable_show(struct device *dev,
1434 struct device_attribute *attr, char *buf)
1436 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1438 return scnprintf(buf, PAGE_SIZE, "%u\n",
1439 iqs269->ch_reg[iqs269->ch_num].rx_enable);
1442 static ssize_t rx_enable_store(struct device *dev,
1443 struct device_attribute *attr, const char *buf,
1446 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1450 error = kstrtouint(buf, 10, &val);
1457 mutex_lock(&iqs269->lock);
1459 iqs269->ch_reg[iqs269->ch_num].rx_enable = val;
1460 iqs269->ati_current = false;
1462 mutex_unlock(&iqs269->lock);
1467 static ssize_t ati_mode_show(struct device *dev,
1468 struct device_attribute *attr, char *buf)
1470 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1474 error = iqs269_ati_mode_get(iqs269, iqs269->ch_num, &val);
1478 return scnprintf(buf, PAGE_SIZE, "%u\n", val);
1481 static ssize_t ati_mode_store(struct device *dev,
1482 struct device_attribute *attr, const char *buf,
1485 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1489 error = kstrtouint(buf, 10, &val);
1493 error = iqs269_ati_mode_set(iqs269, iqs269->ch_num, val);
1500 static ssize_t ati_base_show(struct device *dev,
1501 struct device_attribute *attr, char *buf)
1503 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1507 error = iqs269_ati_base_get(iqs269, iqs269->ch_num, &val);
1511 return scnprintf(buf, PAGE_SIZE, "%u\n", val);
1514 static ssize_t ati_base_store(struct device *dev,
1515 struct device_attribute *attr, const char *buf,
1518 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1522 error = kstrtouint(buf, 10, &val);
1526 error = iqs269_ati_base_set(iqs269, iqs269->ch_num, val);
1533 static ssize_t ati_target_show(struct device *dev,
1534 struct device_attribute *attr, char *buf)
1536 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1540 error = iqs269_ati_target_get(iqs269, iqs269->ch_num, &val);
1544 return scnprintf(buf, PAGE_SIZE, "%u\n", val);
1547 static ssize_t ati_target_store(struct device *dev,
1548 struct device_attribute *attr, const char *buf,
1551 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1555 error = kstrtouint(buf, 10, &val);
1559 error = iqs269_ati_target_set(iqs269, iqs269->ch_num, val);
1566 static ssize_t ati_trigger_show(struct device *dev,
1567 struct device_attribute *attr, char *buf)
1569 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1571 return scnprintf(buf, PAGE_SIZE, "%u\n", iqs269->ati_current);
1574 static ssize_t ati_trigger_store(struct device *dev,
1575 struct device_attribute *attr, const char *buf,
1578 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1579 struct i2c_client *client = iqs269->client;
1583 error = kstrtouint(buf, 10, &val);
1590 disable_irq(client->irq);
1592 error = iqs269_dev_init(iqs269);
1595 enable_irq(client->irq);
1603 static DEVICE_ATTR_RO(counts);
1604 static DEVICE_ATTR_RO(hall_bin);
1605 static DEVICE_ATTR_RW(hall_enable);
1606 static DEVICE_ATTR_RW(ch_number);
1607 static DEVICE_ATTR_RW(rx_enable);
1608 static DEVICE_ATTR_RW(ati_mode);
1609 static DEVICE_ATTR_RW(ati_base);
1610 static DEVICE_ATTR_RW(ati_target);
1611 static DEVICE_ATTR_RW(ati_trigger);
1613 static struct attribute *iqs269_attrs[] = {
1614 &dev_attr_counts.attr,
1615 &dev_attr_hall_bin.attr,
1616 &dev_attr_hall_enable.attr,
1617 &dev_attr_ch_number.attr,
1618 &dev_attr_rx_enable.attr,
1619 &dev_attr_ati_mode.attr,
1620 &dev_attr_ati_base.attr,
1621 &dev_attr_ati_target.attr,
1622 &dev_attr_ati_trigger.attr,
1626 static const struct attribute_group iqs269_attr_group = {
1627 .attrs = iqs269_attrs,
1630 static const struct regmap_config iqs269_regmap_config = {
1633 .max_register = IQS269_MAX_REG,
1636 static int iqs269_probe(struct i2c_client *client)
1638 struct iqs269_ver_info ver_info;
1639 struct iqs269_private *iqs269;
1642 iqs269 = devm_kzalloc(&client->dev, sizeof(*iqs269), GFP_KERNEL);
1646 i2c_set_clientdata(client, iqs269);
1647 iqs269->client = client;
1649 iqs269->regmap = devm_regmap_init_i2c(client, &iqs269_regmap_config);
1650 if (IS_ERR(iqs269->regmap)) {
1651 error = PTR_ERR(iqs269->regmap);
1652 dev_err(&client->dev, "Failed to initialize register map: %d\n",
1657 mutex_init(&iqs269->lock);
1659 error = regmap_raw_read(iqs269->regmap, IQS269_VER_INFO, &ver_info,
1664 if (ver_info.prod_num != IQS269_VER_INFO_PROD_NUM) {
1665 dev_err(&client->dev, "Unrecognized product number: 0x%02X\n",
1670 error = iqs269_parse_prop(iqs269);
1674 error = iqs269_dev_init(iqs269);
1676 dev_err(&client->dev, "Failed to initialize device: %d\n",
1681 error = iqs269_input_init(iqs269);
1685 error = devm_request_threaded_irq(&client->dev, client->irq,
1686 NULL, iqs269_irq, IRQF_ONESHOT,
1687 client->name, iqs269);
1689 dev_err(&client->dev, "Failed to request IRQ: %d\n", error);
1693 error = devm_device_add_group(&client->dev, &iqs269_attr_group);
1695 dev_err(&client->dev, "Failed to add attributes: %d\n", error);
1700 static int __maybe_unused iqs269_suspend(struct device *dev)
1702 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1703 struct i2c_client *client = iqs269->client;
1707 if (!iqs269->suspend_mode)
1710 disable_irq(client->irq);
1713 * Automatic power mode switching must be disabled before the device is
1714 * forced into any particular power mode. In this case, the device will
1715 * transition into normal-power mode.
1717 error = regmap_update_bits(iqs269->regmap, IQS269_SYS_SETTINGS,
1718 IQS269_SYS_SETTINGS_DIS_AUTO, ~0);
1723 * The following check ensures the device has completed its transition
1724 * into normal-power mode before a manual mode switch is performed.
1726 error = regmap_read_poll_timeout(iqs269->regmap, IQS269_SYS_FLAGS, val,
1727 !(val & IQS269_SYS_FLAGS_PWR_MODE_MASK),
1728 IQS269_PWR_MODE_POLL_SLEEP_US,
1729 IQS269_PWR_MODE_POLL_TIMEOUT_US);
1733 error = regmap_update_bits(iqs269->regmap, IQS269_SYS_SETTINGS,
1734 IQS269_SYS_SETTINGS_PWR_MODE_MASK,
1735 iqs269->suspend_mode <<
1736 IQS269_SYS_SETTINGS_PWR_MODE_SHIFT);
1741 * This last check ensures the device has completed its transition into
1742 * the desired power mode to prevent any spurious interrupts from being
1743 * triggered after iqs269_suspend has already returned.
1745 error = regmap_read_poll_timeout(iqs269->regmap, IQS269_SYS_FLAGS, val,
1746 (val & IQS269_SYS_FLAGS_PWR_MODE_MASK)
1747 == (iqs269->suspend_mode <<
1748 IQS269_SYS_FLAGS_PWR_MODE_SHIFT),
1749 IQS269_PWR_MODE_POLL_SLEEP_US,
1750 IQS269_PWR_MODE_POLL_TIMEOUT_US);
1754 enable_irq(client->irq);
1759 static int __maybe_unused iqs269_resume(struct device *dev)
1761 struct iqs269_private *iqs269 = dev_get_drvdata(dev);
1762 struct i2c_client *client = iqs269->client;
1766 if (!iqs269->suspend_mode)
1769 disable_irq(client->irq);
1771 error = regmap_update_bits(iqs269->regmap, IQS269_SYS_SETTINGS,
1772 IQS269_SYS_SETTINGS_PWR_MODE_MASK, 0);
1777 * This check ensures the device has returned to normal-power mode
1778 * before automatic power mode switching is re-enabled.
1780 error = regmap_read_poll_timeout(iqs269->regmap, IQS269_SYS_FLAGS, val,
1781 !(val & IQS269_SYS_FLAGS_PWR_MODE_MASK),
1782 IQS269_PWR_MODE_POLL_SLEEP_US,
1783 IQS269_PWR_MODE_POLL_TIMEOUT_US);
1787 error = regmap_update_bits(iqs269->regmap, IQS269_SYS_SETTINGS,
1788 IQS269_SYS_SETTINGS_DIS_AUTO, 0);
1793 * This step reports any events that may have been "swallowed" as a
1794 * result of polling PWR_MODE (which automatically acknowledges any
1795 * pending interrupts).
1797 error = iqs269_report(iqs269);
1801 enable_irq(client->irq);
1806 static SIMPLE_DEV_PM_OPS(iqs269_pm, iqs269_suspend, iqs269_resume);
1808 static const struct of_device_id iqs269_of_match[] = {
1809 { .compatible = "azoteq,iqs269a" },
1812 MODULE_DEVICE_TABLE(of, iqs269_of_match);
1814 static struct i2c_driver iqs269_i2c_driver = {
1817 .of_match_table = iqs269_of_match,
1820 .probe_new = iqs269_probe,
1822 module_i2c_driver(iqs269_i2c_driver);
1825 MODULE_DESCRIPTION("Azoteq IQS269A Capacitive Touch Controller");
1826 MODULE_LICENSE("GPL");