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/bits.h>
13 #include <linux/completion.h>
14 #include <linux/delay.h>
15 #include <linux/device.h>
16 #include <linux/err.h>
17 #include <linux/i2c.h>
18 #include <linux/input.h>
19 #include <linux/interrupt.h>
20 #include <linux/kernel.h>
21 #include <linux/mod_devicetable.h>
22 #include <linux/module.h>
23 #include <linux/mutex.h>
24 #include <linux/property.h>
25 #include <linux/regmap.h>
26 #include <linux/slab.h>
28 #define IQS269_VER_INFO 0x00
29 #define IQS269_VER_INFO_PROD_NUM 0x4F
30 #define IQS269_VER_INFO_FW_NUM_2 0x03
31 #define IQS269_VER_INFO_FW_NUM_3 0x10
33 #define IQS269_SYS_FLAGS 0x02
34 #define IQS269_SYS_FLAGS_SHOW_RESET BIT(15)
35 #define IQS269_SYS_FLAGS_PWR_MODE_MASK GENMASK(12, 11)
36 #define IQS269_SYS_FLAGS_PWR_MODE_SHIFT 11
37 #define IQS269_SYS_FLAGS_IN_ATI BIT(10)
39 #define IQS269_CHx_COUNTS 0x08
41 #define IQS269_SLIDER_X 0x30
43 #define IQS269_CAL_DATA_A 0x35
44 #define IQS269_CAL_DATA_A_HALL_BIN_L_MASK GENMASK(15, 12)
45 #define IQS269_CAL_DATA_A_HALL_BIN_L_SHIFT 12
46 #define IQS269_CAL_DATA_A_HALL_BIN_R_MASK GENMASK(11, 8)
47 #define IQS269_CAL_DATA_A_HALL_BIN_R_SHIFT 8
49 #define IQS269_SYS_SETTINGS 0x80
50 #define IQS269_SYS_SETTINGS_CLK_DIV BIT(15)
51 #define IQS269_SYS_SETTINGS_ULP_AUTO BIT(14)
52 #define IQS269_SYS_SETTINGS_DIS_AUTO BIT(13)
53 #define IQS269_SYS_SETTINGS_PWR_MODE_MASK GENMASK(12, 11)
54 #define IQS269_SYS_SETTINGS_PWR_MODE_SHIFT 11
55 #define IQS269_SYS_SETTINGS_PWR_MODE_MAX 3
56 #define IQS269_SYS_SETTINGS_ULP_UPDATE_MASK GENMASK(10, 8)
57 #define IQS269_SYS_SETTINGS_ULP_UPDATE_SHIFT 8
58 #define IQS269_SYS_SETTINGS_ULP_UPDATE_MAX 7
59 #define IQS269_SYS_SETTINGS_SLIDER_SWIPE BIT(7)
60 #define IQS269_SYS_SETTINGS_RESEED_OFFSET BIT(6)
61 #define IQS269_SYS_SETTINGS_EVENT_MODE BIT(5)
62 #define IQS269_SYS_SETTINGS_EVENT_MODE_LP BIT(4)
63 #define IQS269_SYS_SETTINGS_REDO_ATI BIT(2)
64 #define IQS269_SYS_SETTINGS_ACK_RESET BIT(0)
66 #define IQS269_FILT_STR_LP_LTA_MASK GENMASK(7, 6)
67 #define IQS269_FILT_STR_LP_LTA_SHIFT 6
68 #define IQS269_FILT_STR_LP_CNT_MASK GENMASK(5, 4)
69 #define IQS269_FILT_STR_LP_CNT_SHIFT 4
70 #define IQS269_FILT_STR_NP_LTA_MASK GENMASK(3, 2)
71 #define IQS269_FILT_STR_NP_LTA_SHIFT 2
72 #define IQS269_FILT_STR_NP_CNT_MASK GENMASK(1, 0)
73 #define IQS269_FILT_STR_MAX 3
75 #define IQS269_EVENT_MASK_SYS BIT(6)
76 #define IQS269_EVENT_MASK_GESTURE BIT(3)
77 #define IQS269_EVENT_MASK_DEEP BIT(2)
78 #define IQS269_EVENT_MASK_TOUCH BIT(1)
79 #define IQS269_EVENT_MASK_PROX BIT(0)
81 #define IQS269_RATE_NP_MS_MAX 255
82 #define IQS269_RATE_LP_MS_MAX 255
83 #define IQS269_RATE_ULP_MS_MAX 4080
84 #define IQS269_TIMEOUT_PWR_MS_MAX 130560
85 #define IQS269_TIMEOUT_LTA_MS_MAX 130560
87 #define IQS269_MISC_A_ATI_BAND_DISABLE BIT(15)
88 #define IQS269_MISC_A_ATI_LP_ONLY BIT(14)
89 #define IQS269_MISC_A_ATI_BAND_TIGHTEN BIT(13)
90 #define IQS269_MISC_A_FILT_DISABLE BIT(12)
91 #define IQS269_MISC_A_GPIO3_SELECT_MASK GENMASK(10, 8)
92 #define IQS269_MISC_A_GPIO3_SELECT_SHIFT 8
93 #define IQS269_MISC_A_DUAL_DIR BIT(6)
94 #define IQS269_MISC_A_TX_FREQ_MASK GENMASK(5, 4)
95 #define IQS269_MISC_A_TX_FREQ_SHIFT 4
96 #define IQS269_MISC_A_TX_FREQ_MAX 3
97 #define IQS269_MISC_A_GLOBAL_CAP_SIZE BIT(0)
99 #define IQS269_MISC_B_RESEED_UI_SEL_MASK GENMASK(7, 6)
100 #define IQS269_MISC_B_RESEED_UI_SEL_SHIFT 6
101 #define IQS269_MISC_B_RESEED_UI_SEL_MAX 3
102 #define IQS269_MISC_B_TRACKING_UI_ENABLE BIT(4)
103 #define IQS269_MISC_B_FILT_STR_SLIDER GENMASK(1, 0)
105 #define IQS269_TOUCH_HOLD_SLIDER_SEL 0x89
106 #define IQS269_TOUCH_HOLD_DEFAULT 0x14
107 #define IQS269_TOUCH_HOLD_MS_MIN 256
108 #define IQS269_TOUCH_HOLD_MS_MAX 65280
110 #define IQS269_TIMEOUT_TAP_MS_MAX 4080
111 #define IQS269_TIMEOUT_SWIPE_MS_MAX 4080
112 #define IQS269_THRESH_SWIPE_MAX 255
114 #define IQS269_CHx_ENG_A_MEAS_CAP_SIZE BIT(15)
115 #define IQS269_CHx_ENG_A_RX_GND_INACTIVE BIT(13)
116 #define IQS269_CHx_ENG_A_LOCAL_CAP_SIZE BIT(12)
117 #define IQS269_CHx_ENG_A_ATI_MODE_MASK GENMASK(9, 8)
118 #define IQS269_CHx_ENG_A_ATI_MODE_SHIFT 8
119 #define IQS269_CHx_ENG_A_ATI_MODE_MAX 3
120 #define IQS269_CHx_ENG_A_INV_LOGIC BIT(7)
121 #define IQS269_CHx_ENG_A_PROJ_BIAS_MASK GENMASK(6, 5)
122 #define IQS269_CHx_ENG_A_PROJ_BIAS_SHIFT 5
123 #define IQS269_CHx_ENG_A_PROJ_BIAS_MAX 3
124 #define IQS269_CHx_ENG_A_SENSE_MODE_MASK GENMASK(3, 0)
125 #define IQS269_CHx_ENG_A_SENSE_MODE_MAX 15
127 #define IQS269_CHx_ENG_B_LOCAL_CAP_ENABLE BIT(13)
128 #define IQS269_CHx_ENG_B_SENSE_FREQ_MASK GENMASK(10, 9)
129 #define IQS269_CHx_ENG_B_SENSE_FREQ_SHIFT 9
130 #define IQS269_CHx_ENG_B_SENSE_FREQ_MAX 3
131 #define IQS269_CHx_ENG_B_STATIC_ENABLE BIT(8)
132 #define IQS269_CHx_ENG_B_ATI_BASE_MASK GENMASK(7, 6)
133 #define IQS269_CHx_ENG_B_ATI_BASE_75 0x00
134 #define IQS269_CHx_ENG_B_ATI_BASE_100 0x40
135 #define IQS269_CHx_ENG_B_ATI_BASE_150 0x80
136 #define IQS269_CHx_ENG_B_ATI_BASE_200 0xC0
137 #define IQS269_CHx_ENG_B_ATI_TARGET_MASK GENMASK(5, 0)
138 #define IQS269_CHx_ENG_B_ATI_TARGET_MAX 2016
140 #define IQS269_CHx_WEIGHT_MAX 255
141 #define IQS269_CHx_THRESH_MAX 255
142 #define IQS269_CHx_HYST_DEEP_MASK GENMASK(7, 4)
143 #define IQS269_CHx_HYST_DEEP_SHIFT 4
144 #define IQS269_CHx_HYST_TOUCH_MASK GENMASK(3, 0)
145 #define IQS269_CHx_HYST_MAX 15
147 #define IQS269_CHx_HALL_INACTIVE 6
148 #define IQS269_CHx_HALL_ACTIVE 7
150 #define IQS269_HALL_PAD_R BIT(0)
151 #define IQS269_HALL_PAD_L BIT(1)
152 #define IQS269_HALL_PAD_INV BIT(6)
154 #define IQS269_HALL_UI 0xF5
155 #define IQS269_HALL_UI_ENABLE BIT(15)
157 #define IQS269_MAX_REG 0xFF
159 #define IQS269_OTP_OPTION_DEFAULT 0x00
160 #define IQS269_OTP_OPTION_TWS 0xD0
161 #define IQS269_OTP_OPTION_HOLD BIT(7)
163 #define IQS269_NUM_CH 8
164 #define IQS269_NUM_SL 2
166 #define iqs269_irq_wait() usleep_range(200, 250)
168 enum iqs269_local_cap_size
{
169 IQS269_LOCAL_CAP_SIZE_0
,
170 IQS269_LOCAL_CAP_SIZE_GLOBAL_ONLY
,
171 IQS269_LOCAL_CAP_SIZE_GLOBAL_0pF5
,
174 enum iqs269_st_offs
{
177 IQS269_ST_OFFS_TOUCH
,
181 enum iqs269_th_offs
{
183 IQS269_TH_OFFS_TOUCH
,
187 enum iqs269_event_id
{
188 IQS269_EVENT_PROX_DN
,
189 IQS269_EVENT_PROX_UP
,
190 IQS269_EVENT_TOUCH_DN
,
191 IQS269_EVENT_TOUCH_UP
,
192 IQS269_EVENT_DEEP_DN
,
193 IQS269_EVENT_DEEP_UP
,
196 enum iqs269_slider_id
{
202 enum iqs269_gesture_id
{
205 IQS269_GESTURE_FLICK_POS
,
206 IQS269_GESTURE_FLICK_NEG
,
210 struct iqs269_switch_desc
{
215 struct iqs269_event_desc
{
217 enum iqs269_st_offs st_offs
;
218 enum iqs269_th_offs th_offs
;
223 static const struct iqs269_event_desc iqs269_events
[] = {
224 [IQS269_EVENT_PROX_DN
] = {
225 .name
= "event-prox",
226 .st_offs
= IQS269_ST_OFFS_PROX
,
227 .th_offs
= IQS269_TH_OFFS_PROX
,
228 .mask
= IQS269_EVENT_MASK_PROX
,
230 [IQS269_EVENT_PROX_UP
] = {
231 .name
= "event-prox-alt",
232 .st_offs
= IQS269_ST_OFFS_PROX
,
233 .th_offs
= IQS269_TH_OFFS_PROX
,
235 .mask
= IQS269_EVENT_MASK_PROX
,
237 [IQS269_EVENT_TOUCH_DN
] = {
238 .name
= "event-touch",
239 .st_offs
= IQS269_ST_OFFS_TOUCH
,
240 .th_offs
= IQS269_TH_OFFS_TOUCH
,
241 .mask
= IQS269_EVENT_MASK_TOUCH
,
243 [IQS269_EVENT_TOUCH_UP
] = {
244 .name
= "event-touch-alt",
245 .st_offs
= IQS269_ST_OFFS_TOUCH
,
246 .th_offs
= IQS269_TH_OFFS_TOUCH
,
248 .mask
= IQS269_EVENT_MASK_TOUCH
,
250 [IQS269_EVENT_DEEP_DN
] = {
251 .name
= "event-deep",
252 .st_offs
= IQS269_ST_OFFS_DEEP
,
253 .th_offs
= IQS269_TH_OFFS_DEEP
,
254 .mask
= IQS269_EVENT_MASK_DEEP
,
256 [IQS269_EVENT_DEEP_UP
] = {
257 .name
= "event-deep-alt",
258 .st_offs
= IQS269_ST_OFFS_DEEP
,
259 .th_offs
= IQS269_TH_OFFS_DEEP
,
261 .mask
= IQS269_EVENT_MASK_DEEP
,
265 struct iqs269_ver_info
{
272 struct iqs269_ch_reg
{
284 struct iqs269_sys_reg
{
300 u8 slider_select
[IQS269_NUM_SL
];
305 struct iqs269_ch_reg ch_reg
[IQS269_NUM_CH
];
308 struct iqs269_flags
{
315 struct iqs269_private
{
316 struct i2c_client
*client
;
317 struct regmap
*regmap
;
319 struct iqs269_switch_desc switches
[ARRAY_SIZE(iqs269_events
)];
320 struct iqs269_ver_info ver_info
;
321 struct iqs269_sys_reg sys_reg
;
322 struct completion ati_done
;
323 struct input_dev
*keypad
;
324 struct input_dev
*slider
[IQS269_NUM_SL
];
325 unsigned int keycode
[ARRAY_SIZE(iqs269_events
) * IQS269_NUM_CH
];
326 unsigned int sl_code
[IQS269_NUM_SL
][IQS269_NUM_GESTURES
];
327 unsigned int otp_option
;
333 static enum iqs269_slider_id
iqs269_slider_type(struct iqs269_private
*iqs269
,
339 * Slider 1 is unavailable if the touch-and-hold option is enabled via
340 * OTP. In that case, the channel selection register is repurposed for
341 * the touch-and-hold timer ceiling.
343 if (slider_num
&& (iqs269
->otp_option
& IQS269_OTP_OPTION_HOLD
))
344 return IQS269_SLIDER_NONE
;
346 if (!iqs269
->sys_reg
.slider_select
[slider_num
])
347 return IQS269_SLIDER_NONE
;
349 for (i
= 0; i
< IQS269_NUM_GESTURES
; i
++)
350 if (iqs269
->sl_code
[slider_num
][i
] != KEY_RESERVED
)
351 return IQS269_SLIDER_KEY
;
353 return IQS269_SLIDER_RAW
;
356 static int iqs269_ati_mode_set(struct iqs269_private
*iqs269
,
357 unsigned int ch_num
, unsigned int mode
)
359 struct iqs269_ch_reg
*ch_reg
= iqs269
->sys_reg
.ch_reg
;
362 if (ch_num
>= IQS269_NUM_CH
)
365 if (mode
> IQS269_CHx_ENG_A_ATI_MODE_MAX
)
368 guard(mutex
)(&iqs269
->lock
);
370 engine_a
= be16_to_cpu(ch_reg
[ch_num
].engine_a
);
372 engine_a
&= ~IQS269_CHx_ENG_A_ATI_MODE_MASK
;
373 engine_a
|= (mode
<< IQS269_CHx_ENG_A_ATI_MODE_SHIFT
);
375 ch_reg
[ch_num
].engine_a
= cpu_to_be16(engine_a
);
376 iqs269
->ati_current
= false;
381 static int iqs269_ati_mode_get(struct iqs269_private
*iqs269
,
382 unsigned int ch_num
, unsigned int *mode
)
384 struct iqs269_ch_reg
*ch_reg
= iqs269
->sys_reg
.ch_reg
;
387 if (ch_num
>= IQS269_NUM_CH
)
390 guard(mutex
)(&iqs269
->lock
);
392 engine_a
= be16_to_cpu(ch_reg
[ch_num
].engine_a
);
394 engine_a
&= IQS269_CHx_ENG_A_ATI_MODE_MASK
;
395 *mode
= (engine_a
>> IQS269_CHx_ENG_A_ATI_MODE_SHIFT
);
400 static int iqs269_ati_base_set(struct iqs269_private
*iqs269
,
401 unsigned int ch_num
, unsigned int base
)
403 struct iqs269_ch_reg
*ch_reg
= iqs269
->sys_reg
.ch_reg
;
406 if (ch_num
>= IQS269_NUM_CH
)
411 base
= IQS269_CHx_ENG_B_ATI_BASE_75
;
415 base
= IQS269_CHx_ENG_B_ATI_BASE_100
;
419 base
= IQS269_CHx_ENG_B_ATI_BASE_150
;
423 base
= IQS269_CHx_ENG_B_ATI_BASE_200
;
430 guard(mutex
)(&iqs269
->lock
);
432 engine_b
= be16_to_cpu(ch_reg
[ch_num
].engine_b
);
434 engine_b
&= ~IQS269_CHx_ENG_B_ATI_BASE_MASK
;
437 ch_reg
[ch_num
].engine_b
= cpu_to_be16(engine_b
);
438 iqs269
->ati_current
= false;
443 static int iqs269_ati_base_get(struct iqs269_private
*iqs269
,
444 unsigned int ch_num
, unsigned int *base
)
446 struct iqs269_ch_reg
*ch_reg
= iqs269
->sys_reg
.ch_reg
;
449 if (ch_num
>= IQS269_NUM_CH
)
452 guard(mutex
)(&iqs269
->lock
);
454 engine_b
= be16_to_cpu(ch_reg
[ch_num
].engine_b
);
456 switch (engine_b
& IQS269_CHx_ENG_B_ATI_BASE_MASK
) {
457 case IQS269_CHx_ENG_B_ATI_BASE_75
:
461 case IQS269_CHx_ENG_B_ATI_BASE_100
:
465 case IQS269_CHx_ENG_B_ATI_BASE_150
:
469 case IQS269_CHx_ENG_B_ATI_BASE_200
:
478 static int iqs269_ati_target_set(struct iqs269_private
*iqs269
,
479 unsigned int ch_num
, unsigned int target
)
481 struct iqs269_ch_reg
*ch_reg
= iqs269
->sys_reg
.ch_reg
;
484 if (ch_num
>= IQS269_NUM_CH
)
487 if (target
> IQS269_CHx_ENG_B_ATI_TARGET_MAX
)
490 guard(mutex
)(&iqs269
->lock
);
492 engine_b
= be16_to_cpu(ch_reg
[ch_num
].engine_b
);
494 engine_b
&= ~IQS269_CHx_ENG_B_ATI_TARGET_MASK
;
495 engine_b
|= target
/ 32;
497 ch_reg
[ch_num
].engine_b
= cpu_to_be16(engine_b
);
498 iqs269
->ati_current
= false;
503 static int iqs269_ati_target_get(struct iqs269_private
*iqs269
,
504 unsigned int ch_num
, unsigned int *target
)
506 struct iqs269_ch_reg
*ch_reg
= iqs269
->sys_reg
.ch_reg
;
509 if (ch_num
>= IQS269_NUM_CH
)
512 guard(mutex
)(&iqs269
->lock
);
514 engine_b
= be16_to_cpu(ch_reg
[ch_num
].engine_b
);
515 *target
= (engine_b
& IQS269_CHx_ENG_B_ATI_TARGET_MASK
) * 32;
520 static int iqs269_parse_mask(const struct fwnode_handle
*fwnode
,
521 const char *propname
, u8
*mask
)
523 unsigned int val
[IQS269_NUM_CH
];
526 count
= fwnode_property_count_u32(fwnode
, propname
);
530 if (count
> IQS269_NUM_CH
)
533 error
= fwnode_property_read_u32_array(fwnode
, propname
, val
, count
);
539 for (i
= 0; i
< count
; i
++) {
540 if (val
[i
] >= IQS269_NUM_CH
)
543 *mask
|= BIT(val
[i
]);
549 static int iqs269_parse_chan(struct iqs269_private
*iqs269
,
550 const struct fwnode_handle
*ch_node
)
552 struct i2c_client
*client
= iqs269
->client
;
553 struct iqs269_ch_reg
*ch_reg
;
554 u16 engine_a
, engine_b
;
555 unsigned int reg
, val
;
558 error
= fwnode_property_read_u32(ch_node
, "reg", ®
);
560 dev_err(&client
->dev
, "Failed to read channel number: %d\n",
563 } else if (reg
>= IQS269_NUM_CH
) {
564 dev_err(&client
->dev
, "Invalid channel number: %u\n", reg
);
568 iqs269
->sys_reg
.active
|= BIT(reg
);
569 if (!fwnode_property_present(ch_node
, "azoteq,reseed-disable"))
570 iqs269
->sys_reg
.reseed
|= BIT(reg
);
572 if (fwnode_property_present(ch_node
, "azoteq,blocking-enable"))
573 iqs269
->sys_reg
.blocking
|= BIT(reg
);
575 if (fwnode_property_present(ch_node
, "azoteq,slider0-select"))
576 iqs269
->sys_reg
.slider_select
[0] |= BIT(reg
);
578 if (fwnode_property_present(ch_node
, "azoteq,slider1-select") &&
579 !(iqs269
->otp_option
& IQS269_OTP_OPTION_HOLD
))
580 iqs269
->sys_reg
.slider_select
[1] |= BIT(reg
);
582 ch_reg
= &iqs269
->sys_reg
.ch_reg
[reg
];
584 error
= iqs269_parse_mask(ch_node
, "azoteq,rx-enable",
587 dev_err(&client
->dev
, "Invalid channel %u RX enable mask: %d\n",
592 error
= iqs269_parse_mask(ch_node
, "azoteq,tx-enable",
595 dev_err(&client
->dev
, "Invalid channel %u TX enable mask: %d\n",
600 engine_a
= be16_to_cpu(ch_reg
->engine_a
);
601 engine_b
= be16_to_cpu(ch_reg
->engine_b
);
603 engine_a
|= IQS269_CHx_ENG_A_MEAS_CAP_SIZE
;
604 if (fwnode_property_present(ch_node
, "azoteq,meas-cap-decrease"))
605 engine_a
&= ~IQS269_CHx_ENG_A_MEAS_CAP_SIZE
;
607 engine_a
|= IQS269_CHx_ENG_A_RX_GND_INACTIVE
;
608 if (fwnode_property_present(ch_node
, "azoteq,rx-float-inactive"))
609 engine_a
&= ~IQS269_CHx_ENG_A_RX_GND_INACTIVE
;
611 engine_a
&= ~IQS269_CHx_ENG_A_LOCAL_CAP_SIZE
;
612 engine_b
&= ~IQS269_CHx_ENG_B_LOCAL_CAP_ENABLE
;
613 if (!fwnode_property_read_u32(ch_node
, "azoteq,local-cap-size", &val
)) {
615 case IQS269_LOCAL_CAP_SIZE_0
:
618 case IQS269_LOCAL_CAP_SIZE_GLOBAL_0pF5
:
619 engine_a
|= IQS269_CHx_ENG_A_LOCAL_CAP_SIZE
;
622 case IQS269_LOCAL_CAP_SIZE_GLOBAL_ONLY
:
623 engine_b
|= IQS269_CHx_ENG_B_LOCAL_CAP_ENABLE
;
627 dev_err(&client
->dev
,
628 "Invalid channel %u local cap. size: %u\n", reg
,
634 engine_a
&= ~IQS269_CHx_ENG_A_INV_LOGIC
;
635 if (fwnode_property_present(ch_node
, "azoteq,invert-enable"))
636 engine_a
|= IQS269_CHx_ENG_A_INV_LOGIC
;
638 if (!fwnode_property_read_u32(ch_node
, "azoteq,proj-bias", &val
)) {
639 if (val
> IQS269_CHx_ENG_A_PROJ_BIAS_MAX
) {
640 dev_err(&client
->dev
,
641 "Invalid channel %u bias current: %u\n", reg
,
646 engine_a
&= ~IQS269_CHx_ENG_A_PROJ_BIAS_MASK
;
647 engine_a
|= (val
<< IQS269_CHx_ENG_A_PROJ_BIAS_SHIFT
);
650 if (!fwnode_property_read_u32(ch_node
, "azoteq,sense-mode", &val
)) {
651 if (val
> IQS269_CHx_ENG_A_SENSE_MODE_MAX
) {
652 dev_err(&client
->dev
,
653 "Invalid channel %u sensing mode: %u\n", reg
,
658 engine_a
&= ~IQS269_CHx_ENG_A_SENSE_MODE_MASK
;
662 if (!fwnode_property_read_u32(ch_node
, "azoteq,sense-freq", &val
)) {
663 if (val
> IQS269_CHx_ENG_B_SENSE_FREQ_MAX
) {
664 dev_err(&client
->dev
,
665 "Invalid channel %u sensing frequency: %u\n",
670 engine_b
&= ~IQS269_CHx_ENG_B_SENSE_FREQ_MASK
;
671 engine_b
|= (val
<< IQS269_CHx_ENG_B_SENSE_FREQ_SHIFT
);
674 engine_b
&= ~IQS269_CHx_ENG_B_STATIC_ENABLE
;
675 if (fwnode_property_present(ch_node
, "azoteq,static-enable"))
676 engine_b
|= IQS269_CHx_ENG_B_STATIC_ENABLE
;
678 ch_reg
->engine_a
= cpu_to_be16(engine_a
);
679 ch_reg
->engine_b
= cpu_to_be16(engine_b
);
681 if (!fwnode_property_read_u32(ch_node
, "azoteq,ati-mode", &val
)) {
682 error
= iqs269_ati_mode_set(iqs269
, reg
, val
);
684 dev_err(&client
->dev
,
685 "Invalid channel %u ATI mode: %u\n", reg
, val
);
690 if (!fwnode_property_read_u32(ch_node
, "azoteq,ati-base", &val
)) {
691 error
= iqs269_ati_base_set(iqs269
, reg
, val
);
693 dev_err(&client
->dev
,
694 "Invalid channel %u ATI base: %u\n", reg
, val
);
699 if (!fwnode_property_read_u32(ch_node
, "azoteq,ati-target", &val
)) {
700 error
= iqs269_ati_target_set(iqs269
, reg
, val
);
702 dev_err(&client
->dev
,
703 "Invalid channel %u ATI target: %u\n", reg
,
709 error
= iqs269_parse_mask(ch_node
, "azoteq,assoc-select",
710 &ch_reg
->assoc_select
);
712 dev_err(&client
->dev
, "Invalid channel %u association: %d\n",
717 if (!fwnode_property_read_u32(ch_node
, "azoteq,assoc-weight", &val
)) {
718 if (val
> IQS269_CHx_WEIGHT_MAX
) {
719 dev_err(&client
->dev
,
720 "Invalid channel %u associated weight: %u\n",
725 ch_reg
->assoc_weight
= val
;
728 for (i
= 0; i
< ARRAY_SIZE(iqs269_events
); i
++) {
729 struct fwnode_handle
*ev_node
__free(fwnode_handle
) =
730 fwnode_get_named_child_node(ch_node
,
731 iqs269_events
[i
].name
);
735 if (!fwnode_property_read_u32(ev_node
, "azoteq,thresh", &val
)) {
736 if (val
> IQS269_CHx_THRESH_MAX
) {
737 dev_err(&client
->dev
,
738 "Invalid channel %u threshold: %u\n",
743 ch_reg
->thresh
[iqs269_events
[i
].th_offs
] = val
;
746 if (!fwnode_property_read_u32(ev_node
, "azoteq,hyst", &val
)) {
747 u8
*hyst
= &ch_reg
->hyst
;
749 if (val
> IQS269_CHx_HYST_MAX
) {
750 dev_err(&client
->dev
,
751 "Invalid channel %u hysteresis: %u\n",
756 if (i
== IQS269_EVENT_DEEP_DN
||
757 i
== IQS269_EVENT_DEEP_UP
) {
758 *hyst
&= ~IQS269_CHx_HYST_DEEP_MASK
;
759 *hyst
|= (val
<< IQS269_CHx_HYST_DEEP_SHIFT
);
760 } else if (i
== IQS269_EVENT_TOUCH_DN
||
761 i
== IQS269_EVENT_TOUCH_UP
) {
762 *hyst
&= ~IQS269_CHx_HYST_TOUCH_MASK
;
767 error
= fwnode_property_read_u32(ev_node
, "linux,code", &val
);
768 if (error
== -EINVAL
) {
771 dev_err(&client
->dev
,
772 "Failed to read channel %u code: %d\n", reg
,
778 case IQS269_CHx_HALL_ACTIVE
:
779 if (iqs269
->hall_enable
) {
780 iqs269
->switches
[i
].code
= val
;
781 iqs269
->switches
[i
].enabled
= true;
785 case IQS269_CHx_HALL_INACTIVE
:
786 if (iqs269
->hall_enable
)
791 iqs269
->keycode
[i
* IQS269_NUM_CH
+ reg
] = val
;
794 iqs269
->sys_reg
.event_mask
&= ~iqs269_events
[i
].mask
;
800 static int iqs269_parse_prop(struct iqs269_private
*iqs269
)
802 struct iqs269_sys_reg
*sys_reg
= &iqs269
->sys_reg
;
803 struct i2c_client
*client
= iqs269
->client
;
804 u16 general
, misc_a
, misc_b
;
808 iqs269
->hall_enable
= device_property_present(&client
->dev
,
809 "azoteq,hall-enable");
811 error
= regmap_raw_read(iqs269
->regmap
, IQS269_SYS_SETTINGS
, sys_reg
,
816 if (!device_property_read_u32(&client
->dev
, "azoteq,filt-str-lp-lta",
818 if (val
> IQS269_FILT_STR_MAX
) {
819 dev_err(&client
->dev
, "Invalid filter strength: %u\n",
824 sys_reg
->filter
&= ~IQS269_FILT_STR_LP_LTA_MASK
;
825 sys_reg
->filter
|= (val
<< IQS269_FILT_STR_LP_LTA_SHIFT
);
828 if (!device_property_read_u32(&client
->dev
, "azoteq,filt-str-lp-cnt",
830 if (val
> IQS269_FILT_STR_MAX
) {
831 dev_err(&client
->dev
, "Invalid filter strength: %u\n",
836 sys_reg
->filter
&= ~IQS269_FILT_STR_LP_CNT_MASK
;
837 sys_reg
->filter
|= (val
<< IQS269_FILT_STR_LP_CNT_SHIFT
);
840 if (!device_property_read_u32(&client
->dev
, "azoteq,filt-str-np-lta",
842 if (val
> IQS269_FILT_STR_MAX
) {
843 dev_err(&client
->dev
, "Invalid filter strength: %u\n",
848 sys_reg
->filter
&= ~IQS269_FILT_STR_NP_LTA_MASK
;
849 sys_reg
->filter
|= (val
<< IQS269_FILT_STR_NP_LTA_SHIFT
);
852 if (!device_property_read_u32(&client
->dev
, "azoteq,filt-str-np-cnt",
854 if (val
> IQS269_FILT_STR_MAX
) {
855 dev_err(&client
->dev
, "Invalid filter strength: %u\n",
860 sys_reg
->filter
&= ~IQS269_FILT_STR_NP_CNT_MASK
;
861 sys_reg
->filter
|= val
;
864 if (!device_property_read_u32(&client
->dev
, "azoteq,rate-np-ms",
866 if (val
> IQS269_RATE_NP_MS_MAX
) {
867 dev_err(&client
->dev
, "Invalid report rate: %u\n", val
);
871 sys_reg
->rate_np
= val
;
874 if (!device_property_read_u32(&client
->dev
, "azoteq,rate-lp-ms",
876 if (val
> IQS269_RATE_LP_MS_MAX
) {
877 dev_err(&client
->dev
, "Invalid report rate: %u\n", val
);
881 sys_reg
->rate_lp
= val
;
884 if (!device_property_read_u32(&client
->dev
, "azoteq,rate-ulp-ms",
886 if (val
> IQS269_RATE_ULP_MS_MAX
) {
887 dev_err(&client
->dev
, "Invalid report rate: %u\n", val
);
891 sys_reg
->rate_ulp
= val
/ 16;
894 if (!device_property_read_u32(&client
->dev
, "azoteq,timeout-pwr-ms",
896 if (val
> IQS269_TIMEOUT_PWR_MS_MAX
) {
897 dev_err(&client
->dev
, "Invalid timeout: %u\n", val
);
901 sys_reg
->timeout_pwr
= val
/ 512;
904 if (!device_property_read_u32(&client
->dev
, "azoteq,timeout-lta-ms",
906 if (val
> IQS269_TIMEOUT_LTA_MS_MAX
) {
907 dev_err(&client
->dev
, "Invalid timeout: %u\n", val
);
911 sys_reg
->timeout_lta
= val
/ 512;
914 misc_a
= be16_to_cpu(sys_reg
->misc_a
);
915 misc_b
= be16_to_cpu(sys_reg
->misc_b
);
917 misc_a
&= ~IQS269_MISC_A_ATI_BAND_DISABLE
;
918 if (device_property_present(&client
->dev
, "azoteq,ati-band-disable"))
919 misc_a
|= IQS269_MISC_A_ATI_BAND_DISABLE
;
921 misc_a
&= ~IQS269_MISC_A_ATI_LP_ONLY
;
922 if (device_property_present(&client
->dev
, "azoteq,ati-lp-only"))
923 misc_a
|= IQS269_MISC_A_ATI_LP_ONLY
;
925 misc_a
&= ~IQS269_MISC_A_ATI_BAND_TIGHTEN
;
926 if (device_property_present(&client
->dev
, "azoteq,ati-band-tighten"))
927 misc_a
|= IQS269_MISC_A_ATI_BAND_TIGHTEN
;
929 misc_a
&= ~IQS269_MISC_A_FILT_DISABLE
;
930 if (device_property_present(&client
->dev
, "azoteq,filt-disable"))
931 misc_a
|= IQS269_MISC_A_FILT_DISABLE
;
933 if (!device_property_read_u32(&client
->dev
, "azoteq,gpio3-select",
935 if (val
>= IQS269_NUM_CH
) {
936 dev_err(&client
->dev
, "Invalid GPIO3 selection: %u\n",
941 misc_a
&= ~IQS269_MISC_A_GPIO3_SELECT_MASK
;
942 misc_a
|= (val
<< IQS269_MISC_A_GPIO3_SELECT_SHIFT
);
945 misc_a
&= ~IQS269_MISC_A_DUAL_DIR
;
946 if (device_property_present(&client
->dev
, "azoteq,dual-direction"))
947 misc_a
|= IQS269_MISC_A_DUAL_DIR
;
949 if (!device_property_read_u32(&client
->dev
, "azoteq,tx-freq", &val
)) {
950 if (val
> IQS269_MISC_A_TX_FREQ_MAX
) {
951 dev_err(&client
->dev
,
952 "Invalid excitation frequency: %u\n", val
);
956 misc_a
&= ~IQS269_MISC_A_TX_FREQ_MASK
;
957 misc_a
|= (val
<< IQS269_MISC_A_TX_FREQ_SHIFT
);
960 misc_a
&= ~IQS269_MISC_A_GLOBAL_CAP_SIZE
;
961 if (device_property_present(&client
->dev
, "azoteq,global-cap-increase"))
962 misc_a
|= IQS269_MISC_A_GLOBAL_CAP_SIZE
;
964 if (!device_property_read_u32(&client
->dev
, "azoteq,reseed-select",
966 if (val
> IQS269_MISC_B_RESEED_UI_SEL_MAX
) {
967 dev_err(&client
->dev
, "Invalid reseed selection: %u\n",
972 misc_b
&= ~IQS269_MISC_B_RESEED_UI_SEL_MASK
;
973 misc_b
|= (val
<< IQS269_MISC_B_RESEED_UI_SEL_SHIFT
);
976 misc_b
&= ~IQS269_MISC_B_TRACKING_UI_ENABLE
;
977 if (device_property_present(&client
->dev
, "azoteq,tracking-enable"))
978 misc_b
|= IQS269_MISC_B_TRACKING_UI_ENABLE
;
980 if (!device_property_read_u32(&client
->dev
, "azoteq,filt-str-slider",
982 if (val
> IQS269_FILT_STR_MAX
) {
983 dev_err(&client
->dev
, "Invalid filter strength: %u\n",
988 misc_b
&= ~IQS269_MISC_B_FILT_STR_SLIDER
;
992 sys_reg
->misc_a
= cpu_to_be16(misc_a
);
993 sys_reg
->misc_b
= cpu_to_be16(misc_b
);
998 sys_reg
->blocking
= 0;
1000 sys_reg
->slider_select
[0] = 0;
1003 * If configured via OTP to do so, the device asserts a pulse on the
1004 * GPIO4 pin for approximately 60 ms once a selected channel is held
1005 * in a state of touch for a configurable length of time.
1007 * In that case, the register used for slider 1 channel selection is
1008 * repurposed for the touch-and-hold timer ceiling.
1010 if (iqs269
->otp_option
& IQS269_OTP_OPTION_HOLD
) {
1011 if (!device_property_read_u32(&client
->dev
,
1012 "azoteq,touch-hold-ms", &val
)) {
1013 if (val
< IQS269_TOUCH_HOLD_MS_MIN
||
1014 val
> IQS269_TOUCH_HOLD_MS_MAX
) {
1015 dev_err(&client
->dev
,
1016 "Invalid touch-and-hold ceiling: %u\n",
1021 sys_reg
->slider_select
[1] = val
/ 256;
1022 } else if (iqs269
->ver_info
.fw_num
< IQS269_VER_INFO_FW_NUM_3
) {
1024 * The default touch-and-hold timer ceiling initially
1025 * read from early revisions of silicon is invalid if
1026 * the device experienced a soft reset between power-
1027 * on and the read operation.
1029 * To protect against this case, explicitly cache the
1030 * default value so that it is restored each time the
1031 * device is re-initialized.
1033 sys_reg
->slider_select
[1] = IQS269_TOUCH_HOLD_DEFAULT
;
1036 sys_reg
->slider_select
[1] = 0;
1039 sys_reg
->event_mask
= ~((u8
)IQS269_EVENT_MASK_SYS
);
1041 device_for_each_child_node_scoped(&client
->dev
, ch_node
) {
1042 error
= iqs269_parse_chan(iqs269
, ch_node
);
1048 * Volunteer all active channels to participate in ATI when REDO-ATI is
1049 * manually triggered.
1051 sys_reg
->redo_ati
= sys_reg
->active
;
1053 general
= be16_to_cpu(sys_reg
->general
);
1055 if (device_property_present(&client
->dev
, "azoteq,clk-div"))
1056 general
|= IQS269_SYS_SETTINGS_CLK_DIV
;
1059 * Configure the device to automatically switch between normal and low-
1060 * power modes as a function of sensing activity. Ultra-low-power mode,
1061 * if enabled, is reserved for suspend.
1063 general
&= ~IQS269_SYS_SETTINGS_ULP_AUTO
;
1064 general
&= ~IQS269_SYS_SETTINGS_DIS_AUTO
;
1065 general
&= ~IQS269_SYS_SETTINGS_PWR_MODE_MASK
;
1067 if (!device_property_read_u32(&client
->dev
, "azoteq,suspend-mode",
1069 if (val
> IQS269_SYS_SETTINGS_PWR_MODE_MAX
) {
1070 dev_err(&client
->dev
, "Invalid suspend mode: %u\n",
1075 general
|= (val
<< IQS269_SYS_SETTINGS_PWR_MODE_SHIFT
);
1078 if (!device_property_read_u32(&client
->dev
, "azoteq,ulp-update",
1080 if (val
> IQS269_SYS_SETTINGS_ULP_UPDATE_MAX
) {
1081 dev_err(&client
->dev
, "Invalid update rate: %u\n", val
);
1085 general
&= ~IQS269_SYS_SETTINGS_ULP_UPDATE_MASK
;
1086 general
|= (val
<< IQS269_SYS_SETTINGS_ULP_UPDATE_SHIFT
);
1089 if (device_property_present(&client
->dev
, "linux,keycodes")) {
1091 int count
= device_property_count_u32(&client
->dev
,
1093 if (count
> IQS269_NUM_GESTURES
* IQS269_NUM_SL
) {
1094 dev_err(&client
->dev
, "Too many keycodes present\n");
1096 } else if (count
< 0) {
1097 dev_err(&client
->dev
, "Failed to count keycodes: %d\n",
1102 error
= device_property_read_u32_array(&client
->dev
,
1104 *iqs269
->sl_code
, count
);
1106 dev_err(&client
->dev
, "Failed to read keycodes: %d\n",
1111 if (device_property_present(&client
->dev
,
1112 "azoteq,gesture-swipe"))
1113 general
|= IQS269_SYS_SETTINGS_SLIDER_SWIPE
;
1116 * Early revisions of silicon use a more granular step size for
1117 * tap and swipe gesture timeouts; scale them appropriately.
1119 if (iqs269
->ver_info
.fw_num
< IQS269_VER_INFO_FW_NUM_3
)
1122 if (!device_property_read_u32(&client
->dev
,
1123 "azoteq,timeout-tap-ms", &val
)) {
1124 if (val
> IQS269_TIMEOUT_TAP_MS_MAX
/ scale
) {
1125 dev_err(&client
->dev
, "Invalid timeout: %u\n",
1130 sys_reg
->timeout_tap
= val
/ (16 / scale
);
1133 if (!device_property_read_u32(&client
->dev
,
1134 "azoteq,timeout-swipe-ms",
1136 if (val
> IQS269_TIMEOUT_SWIPE_MS_MAX
/ scale
) {
1137 dev_err(&client
->dev
, "Invalid timeout: %u\n",
1142 sys_reg
->timeout_swipe
= val
/ (16 / scale
);
1145 if (!device_property_read_u32(&client
->dev
,
1146 "azoteq,thresh-swipe", &val
)) {
1147 if (val
> IQS269_THRESH_SWIPE_MAX
) {
1148 dev_err(&client
->dev
, "Invalid threshold: %u\n",
1153 sys_reg
->thresh_swipe
= val
;
1156 sys_reg
->event_mask
&= ~IQS269_EVENT_MASK_GESTURE
;
1159 general
&= ~IQS269_SYS_SETTINGS_RESEED_OFFSET
;
1160 if (device_property_present(&client
->dev
, "azoteq,reseed-offset"))
1161 general
|= IQS269_SYS_SETTINGS_RESEED_OFFSET
;
1163 general
|= IQS269_SYS_SETTINGS_EVENT_MODE
;
1166 * As per the datasheet, enable streaming during normal-power mode if
1167 * raw coordinates will be read from either slider. In that case, the
1168 * device returns to event mode during low-power mode.
1170 if (iqs269_slider_type(iqs269
, 0) == IQS269_SLIDER_RAW
||
1171 iqs269_slider_type(iqs269
, 1) == IQS269_SLIDER_RAW
)
1172 general
|= IQS269_SYS_SETTINGS_EVENT_MODE_LP
;
1174 general
|= IQS269_SYS_SETTINGS_REDO_ATI
;
1175 general
|= IQS269_SYS_SETTINGS_ACK_RESET
;
1177 sys_reg
->general
= cpu_to_be16(general
);
1182 static const struct reg_sequence iqs269_tws_init
[] = {
1183 { IQS269_TOUCH_HOLD_SLIDER_SEL
, IQS269_TOUCH_HOLD_DEFAULT
},
1188 static int iqs269_dev_init(struct iqs269_private
*iqs269
)
1192 guard(mutex
)(&iqs269
->lock
);
1195 * Early revisions of silicon require the following workaround in order
1196 * to restore any OTP-enabled functionality after a soft reset.
1198 if (iqs269
->otp_option
== IQS269_OTP_OPTION_TWS
&&
1199 iqs269
->ver_info
.fw_num
< IQS269_VER_INFO_FW_NUM_3
) {
1200 error
= regmap_multi_reg_write(iqs269
->regmap
, iqs269_tws_init
,
1201 ARRAY_SIZE(iqs269_tws_init
));
1206 error
= regmap_update_bits(iqs269
->regmap
, IQS269_HALL_UI
,
1207 IQS269_HALL_UI_ENABLE
,
1208 iqs269
->hall_enable
? ~0 : 0);
1212 error
= regmap_raw_write(iqs269
->regmap
, IQS269_SYS_SETTINGS
,
1213 &iqs269
->sys_reg
, sizeof(iqs269
->sys_reg
));
1218 * The following delay gives the device time to deassert its RDY output
1219 * so as to prevent an interrupt from being serviced prematurely.
1221 usleep_range(2000, 2100);
1223 iqs269
->ati_current
= true;
1228 static int iqs269_input_init(struct iqs269_private
*iqs269
)
1230 struct i2c_client
*client
= iqs269
->client
;
1231 unsigned int sw_code
, keycode
;
1234 iqs269
->keypad
= devm_input_allocate_device(&client
->dev
);
1235 if (!iqs269
->keypad
)
1238 iqs269
->keypad
->keycodemax
= ARRAY_SIZE(iqs269
->keycode
);
1239 iqs269
->keypad
->keycode
= iqs269
->keycode
;
1240 iqs269
->keypad
->keycodesize
= sizeof(*iqs269
->keycode
);
1242 iqs269
->keypad
->name
= "iqs269a_keypad";
1243 iqs269
->keypad
->id
.bustype
= BUS_I2C
;
1245 for (i
= 0; i
< ARRAY_SIZE(iqs269_events
); i
++) {
1246 sw_code
= iqs269
->switches
[i
].code
;
1248 for (j
= 0; j
< IQS269_NUM_CH
; j
++) {
1249 keycode
= iqs269
->keycode
[i
* IQS269_NUM_CH
+ j
];
1252 * Hall-effect sensing repurposes a pair of dedicated
1253 * channels, only one of which reports events.
1256 case IQS269_CHx_HALL_ACTIVE
:
1257 if (iqs269
->hall_enable
&&
1258 iqs269
->switches
[i
].enabled
)
1259 input_set_capability(iqs269
->keypad
,
1263 case IQS269_CHx_HALL_INACTIVE
:
1264 if (iqs269
->hall_enable
)
1269 if (keycode
!= KEY_RESERVED
)
1270 input_set_capability(iqs269
->keypad
,
1276 for (i
= 0; i
< IQS269_NUM_SL
; i
++) {
1277 if (iqs269_slider_type(iqs269
, i
) == IQS269_SLIDER_NONE
)
1280 iqs269
->slider
[i
] = devm_input_allocate_device(&client
->dev
);
1281 if (!iqs269
->slider
[i
])
1284 iqs269
->slider
[i
]->keycodemax
= ARRAY_SIZE(iqs269
->sl_code
[i
]);
1285 iqs269
->slider
[i
]->keycode
= iqs269
->sl_code
[i
];
1286 iqs269
->slider
[i
]->keycodesize
= sizeof(**iqs269
->sl_code
);
1288 iqs269
->slider
[i
]->name
= i
? "iqs269a_slider_1"
1289 : "iqs269a_slider_0";
1290 iqs269
->slider
[i
]->id
.bustype
= BUS_I2C
;
1292 for (j
= 0; j
< IQS269_NUM_GESTURES
; j
++)
1293 if (iqs269
->sl_code
[i
][j
] != KEY_RESERVED
)
1294 input_set_capability(iqs269
->slider
[i
], EV_KEY
,
1295 iqs269
->sl_code
[i
][j
]);
1298 * Present the slider as a narrow trackpad if one or more chan-
1299 * nels have been selected to participate, but no gestures have
1300 * been mapped to a keycode.
1302 if (iqs269_slider_type(iqs269
, i
) == IQS269_SLIDER_RAW
) {
1303 input_set_capability(iqs269
->slider
[i
],
1305 input_set_abs_params(iqs269
->slider
[i
],
1306 ABS_X
, 0, 255, 0, 0);
1309 error
= input_register_device(iqs269
->slider
[i
]);
1311 dev_err(&client
->dev
,
1312 "Failed to register slider %d: %d\n", i
, error
);
1320 static int iqs269_report(struct iqs269_private
*iqs269
)
1322 struct i2c_client
*client
= iqs269
->client
;
1323 struct iqs269_flags flags
;
1324 unsigned int sw_code
, keycode
;
1326 u8 slider_x
[IQS269_NUM_SL
];
1329 error
= regmap_raw_read(iqs269
->regmap
, IQS269_SYS_FLAGS
, &flags
,
1332 dev_err(&client
->dev
, "Failed to read device status: %d\n",
1338 * The device resets itself if its own watchdog bites, which can happen
1339 * in the event of an I2C communication error. In this case, the device
1340 * asserts a SHOW_RESET interrupt and all registers must be restored.
1342 if (be16_to_cpu(flags
.system
) & IQS269_SYS_FLAGS_SHOW_RESET
) {
1343 dev_err(&client
->dev
, "Unexpected device reset\n");
1345 error
= iqs269_dev_init(iqs269
);
1347 dev_err(&client
->dev
,
1348 "Failed to re-initialize device: %d\n", error
);
1353 if (be16_to_cpu(flags
.system
) & IQS269_SYS_FLAGS_IN_ATI
)
1356 if (iqs269_slider_type(iqs269
, 0) == IQS269_SLIDER_RAW
||
1357 iqs269_slider_type(iqs269
, 1) == IQS269_SLIDER_RAW
) {
1358 error
= regmap_raw_read(iqs269
->regmap
, IQS269_SLIDER_X
,
1359 slider_x
, sizeof(slider_x
));
1361 dev_err(&client
->dev
,
1362 "Failed to read slider position: %d\n", error
);
1367 for (i
= 0; i
< IQS269_NUM_SL
; i
++) {
1368 flags
.gesture
>>= (i
* IQS269_NUM_GESTURES
);
1370 switch (iqs269_slider_type(iqs269
, i
)) {
1371 case IQS269_SLIDER_NONE
:
1374 case IQS269_SLIDER_KEY
:
1375 for (j
= 0; j
< IQS269_NUM_GESTURES
; j
++)
1376 input_report_key(iqs269
->slider
[i
],
1377 iqs269
->sl_code
[i
][j
],
1378 flags
.gesture
& BIT(j
));
1380 if (!(flags
.gesture
& (BIT(IQS269_GESTURE_FLICK_NEG
) |
1381 BIT(IQS269_GESTURE_FLICK_POS
) |
1382 BIT(IQS269_GESTURE_TAP
))))
1385 input_sync(iqs269
->slider
[i
]);
1388 * Momentary gestures are followed by a complementary
1389 * release cycle so as to emulate a full keystroke.
1391 for (j
= 0; j
< IQS269_NUM_GESTURES
; j
++)
1392 if (j
!= IQS269_GESTURE_HOLD
)
1393 input_report_key(iqs269
->slider
[i
],
1394 iqs269
->sl_code
[i
][j
],
1398 case IQS269_SLIDER_RAW
:
1400 * The slider is considered to be in a state of touch
1401 * if any selected channels are in a state of touch.
1403 state
= flags
.states
[IQS269_ST_OFFS_TOUCH
];
1404 state
&= iqs269
->sys_reg
.slider_select
[i
];
1406 input_report_key(iqs269
->slider
[i
], BTN_TOUCH
, state
);
1409 input_report_abs(iqs269
->slider
[i
],
1410 ABS_X
, slider_x
[i
]);
1414 input_sync(iqs269
->slider
[i
]);
1417 for (i
= 0; i
< ARRAY_SIZE(iqs269_events
); i
++) {
1418 dir_mask
= flags
.states
[IQS269_ST_OFFS_DIR
];
1419 if (!iqs269_events
[i
].dir_up
)
1420 dir_mask
= ~dir_mask
;
1422 state
= flags
.states
[iqs269_events
[i
].st_offs
] & dir_mask
;
1424 sw_code
= iqs269
->switches
[i
].code
;
1426 for (j
= 0; j
< IQS269_NUM_CH
; j
++) {
1427 keycode
= iqs269
->keycode
[i
* IQS269_NUM_CH
+ j
];
1430 case IQS269_CHx_HALL_ACTIVE
:
1431 if (iqs269
->hall_enable
&&
1432 iqs269
->switches
[i
].enabled
)
1433 input_report_switch(iqs269
->keypad
,
1438 case IQS269_CHx_HALL_INACTIVE
:
1439 if (iqs269
->hall_enable
)
1444 input_report_key(iqs269
->keypad
, keycode
,
1450 input_sync(iqs269
->keypad
);
1453 * The following completion signals that ATI has finished, any initial
1454 * switch states have been reported and the keypad can be registered.
1456 complete_all(&iqs269
->ati_done
);
1461 static irqreturn_t
iqs269_irq(int irq
, void *context
)
1463 struct iqs269_private
*iqs269
= context
;
1465 if (iqs269_report(iqs269
))
1469 * The device does not deassert its interrupt (RDY) pin until shortly
1470 * after receiving an I2C stop condition; the following delay ensures
1471 * the interrupt handler does not return before this time.
1478 static ssize_t
counts_show(struct device
*dev
,
1479 struct device_attribute
*attr
, char *buf
)
1481 struct iqs269_private
*iqs269
= dev_get_drvdata(dev
);
1482 struct i2c_client
*client
= iqs269
->client
;
1486 if (!iqs269
->ati_current
|| iqs269
->hall_enable
)
1489 if (!completion_done(&iqs269
->ati_done
))
1493 * Unsolicited I2C communication prompts the device to assert its RDY
1494 * pin, so disable the interrupt line until the operation is finished
1495 * and RDY has been deasserted.
1497 disable_irq(client
->irq
);
1499 error
= regmap_raw_read(iqs269
->regmap
,
1500 IQS269_CHx_COUNTS
+ iqs269
->ch_num
* 2,
1501 &counts
, sizeof(counts
));
1504 enable_irq(client
->irq
);
1509 return sysfs_emit(buf
, "%u\n", le16_to_cpu(counts
));
1512 static ssize_t
hall_bin_show(struct device
*dev
,
1513 struct device_attribute
*attr
, char *buf
)
1515 struct iqs269_private
*iqs269
= dev_get_drvdata(dev
);
1516 struct iqs269_ch_reg
*ch_reg
= iqs269
->sys_reg
.ch_reg
;
1517 struct i2c_client
*client
= iqs269
->client
;
1521 disable_irq(client
->irq
);
1523 error
= regmap_read(iqs269
->regmap
, IQS269_CAL_DATA_A
, &val
);
1526 enable_irq(client
->irq
);
1531 switch (ch_reg
[IQS269_CHx_HALL_ACTIVE
].rx_enable
&
1532 ch_reg
[IQS269_CHx_HALL_INACTIVE
].rx_enable
) {
1533 case IQS269_HALL_PAD_R
:
1534 val
&= IQS269_CAL_DATA_A_HALL_BIN_R_MASK
;
1535 val
>>= IQS269_CAL_DATA_A_HALL_BIN_R_SHIFT
;
1538 case IQS269_HALL_PAD_L
:
1539 val
&= IQS269_CAL_DATA_A_HALL_BIN_L_MASK
;
1540 val
>>= IQS269_CAL_DATA_A_HALL_BIN_L_SHIFT
;
1547 return sysfs_emit(buf
, "%u\n", val
);
1550 static ssize_t
hall_enable_show(struct device
*dev
,
1551 struct device_attribute
*attr
, char *buf
)
1553 struct iqs269_private
*iqs269
= dev_get_drvdata(dev
);
1555 return sysfs_emit(buf
, "%u\n", iqs269
->hall_enable
);
1558 static ssize_t
hall_enable_store(struct device
*dev
,
1559 struct device_attribute
*attr
, const char *buf
,
1562 struct iqs269_private
*iqs269
= dev_get_drvdata(dev
);
1566 error
= kstrtouint(buf
, 10, &val
);
1570 guard(mutex
)(&iqs269
->lock
);
1572 iqs269
->hall_enable
= val
;
1573 iqs269
->ati_current
= false;
1578 static ssize_t
ch_number_show(struct device
*dev
,
1579 struct device_attribute
*attr
, char *buf
)
1581 struct iqs269_private
*iqs269
= dev_get_drvdata(dev
);
1583 return sysfs_emit(buf
, "%u\n", iqs269
->ch_num
);
1586 static ssize_t
ch_number_store(struct device
*dev
,
1587 struct device_attribute
*attr
, const char *buf
,
1590 struct iqs269_private
*iqs269
= dev_get_drvdata(dev
);
1594 error
= kstrtouint(buf
, 10, &val
);
1598 if (val
>= IQS269_NUM_CH
)
1601 iqs269
->ch_num
= val
;
1606 static ssize_t
rx_enable_show(struct device
*dev
,
1607 struct device_attribute
*attr
, char *buf
)
1609 struct iqs269_private
*iqs269
= dev_get_drvdata(dev
);
1610 struct iqs269_ch_reg
*ch_reg
= iqs269
->sys_reg
.ch_reg
;
1612 return sysfs_emit(buf
, "%u\n", ch_reg
[iqs269
->ch_num
].rx_enable
);
1615 static ssize_t
rx_enable_store(struct device
*dev
,
1616 struct device_attribute
*attr
, const char *buf
,
1619 struct iqs269_private
*iqs269
= dev_get_drvdata(dev
);
1620 struct iqs269_ch_reg
*ch_reg
= iqs269
->sys_reg
.ch_reg
;
1624 error
= kstrtouint(buf
, 10, &val
);
1631 guard(mutex
)(&iqs269
->lock
);
1633 ch_reg
[iqs269
->ch_num
].rx_enable
= val
;
1634 iqs269
->ati_current
= false;
1639 static ssize_t
ati_mode_show(struct device
*dev
,
1640 struct device_attribute
*attr
, char *buf
)
1642 struct iqs269_private
*iqs269
= dev_get_drvdata(dev
);
1646 error
= iqs269_ati_mode_get(iqs269
, iqs269
->ch_num
, &val
);
1650 return sysfs_emit(buf
, "%u\n", val
);
1653 static ssize_t
ati_mode_store(struct device
*dev
,
1654 struct device_attribute
*attr
, const char *buf
,
1657 struct iqs269_private
*iqs269
= dev_get_drvdata(dev
);
1661 error
= kstrtouint(buf
, 10, &val
);
1665 error
= iqs269_ati_mode_set(iqs269
, iqs269
->ch_num
, val
);
1672 static ssize_t
ati_base_show(struct device
*dev
,
1673 struct device_attribute
*attr
, char *buf
)
1675 struct iqs269_private
*iqs269
= dev_get_drvdata(dev
);
1679 error
= iqs269_ati_base_get(iqs269
, iqs269
->ch_num
, &val
);
1683 return sysfs_emit(buf
, "%u\n", val
);
1686 static ssize_t
ati_base_store(struct device
*dev
,
1687 struct device_attribute
*attr
, const char *buf
,
1690 struct iqs269_private
*iqs269
= dev_get_drvdata(dev
);
1694 error
= kstrtouint(buf
, 10, &val
);
1698 error
= iqs269_ati_base_set(iqs269
, iqs269
->ch_num
, val
);
1705 static ssize_t
ati_target_show(struct device
*dev
,
1706 struct device_attribute
*attr
, char *buf
)
1708 struct iqs269_private
*iqs269
= dev_get_drvdata(dev
);
1712 error
= iqs269_ati_target_get(iqs269
, iqs269
->ch_num
, &val
);
1716 return sysfs_emit(buf
, "%u\n", val
);
1719 static ssize_t
ati_target_store(struct device
*dev
,
1720 struct device_attribute
*attr
, const char *buf
,
1723 struct iqs269_private
*iqs269
= dev_get_drvdata(dev
);
1727 error
= kstrtouint(buf
, 10, &val
);
1731 error
= iqs269_ati_target_set(iqs269
, iqs269
->ch_num
, val
);
1738 static ssize_t
ati_trigger_show(struct device
*dev
,
1739 struct device_attribute
*attr
, char *buf
)
1741 struct iqs269_private
*iqs269
= dev_get_drvdata(dev
);
1743 return sysfs_emit(buf
, "%u\n",
1744 iqs269
->ati_current
&&
1745 completion_done(&iqs269
->ati_done
));
1748 static ssize_t
ati_trigger_store(struct device
*dev
,
1749 struct device_attribute
*attr
, const char *buf
,
1752 struct iqs269_private
*iqs269
= dev_get_drvdata(dev
);
1753 struct i2c_client
*client
= iqs269
->client
;
1757 error
= kstrtouint(buf
, 10, &val
);
1764 disable_irq(client
->irq
);
1765 reinit_completion(&iqs269
->ati_done
);
1767 error
= iqs269_dev_init(iqs269
);
1770 enable_irq(client
->irq
);
1775 if (!wait_for_completion_timeout(&iqs269
->ati_done
,
1776 msecs_to_jiffies(2000)))
1782 static DEVICE_ATTR_RO(counts
);
1783 static DEVICE_ATTR_RO(hall_bin
);
1784 static DEVICE_ATTR_RW(hall_enable
);
1785 static DEVICE_ATTR_RW(ch_number
);
1786 static DEVICE_ATTR_RW(rx_enable
);
1787 static DEVICE_ATTR_RW(ati_mode
);
1788 static DEVICE_ATTR_RW(ati_base
);
1789 static DEVICE_ATTR_RW(ati_target
);
1790 static DEVICE_ATTR_RW(ati_trigger
);
1792 static struct attribute
*iqs269_attrs
[] = {
1793 &dev_attr_counts
.attr
,
1794 &dev_attr_hall_bin
.attr
,
1795 &dev_attr_hall_enable
.attr
,
1796 &dev_attr_ch_number
.attr
,
1797 &dev_attr_rx_enable
.attr
,
1798 &dev_attr_ati_mode
.attr
,
1799 &dev_attr_ati_base
.attr
,
1800 &dev_attr_ati_target
.attr
,
1801 &dev_attr_ati_trigger
.attr
,
1804 ATTRIBUTE_GROUPS(iqs269
);
1806 static const struct regmap_config iqs269_regmap_config
= {
1809 .max_register
= IQS269_MAX_REG
,
1812 static int iqs269_probe(struct i2c_client
*client
)
1814 struct iqs269_private
*iqs269
;
1817 iqs269
= devm_kzalloc(&client
->dev
, sizeof(*iqs269
), GFP_KERNEL
);
1821 i2c_set_clientdata(client
, iqs269
);
1822 iqs269
->client
= client
;
1824 iqs269
->regmap
= devm_regmap_init_i2c(client
, &iqs269_regmap_config
);
1825 if (IS_ERR(iqs269
->regmap
)) {
1826 error
= PTR_ERR(iqs269
->regmap
);
1827 dev_err(&client
->dev
, "Failed to initialize register map: %d\n",
1832 mutex_init(&iqs269
->lock
);
1833 init_completion(&iqs269
->ati_done
);
1835 iqs269
->otp_option
= (uintptr_t)device_get_match_data(&client
->dev
);
1837 error
= regmap_raw_read(iqs269
->regmap
, IQS269_VER_INFO
,
1838 &iqs269
->ver_info
, sizeof(iqs269
->ver_info
));
1842 if (iqs269
->ver_info
.prod_num
!= IQS269_VER_INFO_PROD_NUM
) {
1843 dev_err(&client
->dev
, "Unrecognized product number: 0x%02X\n",
1844 iqs269
->ver_info
.prod_num
);
1848 error
= iqs269_parse_prop(iqs269
);
1852 error
= iqs269_dev_init(iqs269
);
1854 dev_err(&client
->dev
, "Failed to initialize device: %d\n",
1859 error
= iqs269_input_init(iqs269
);
1863 error
= devm_request_threaded_irq(&client
->dev
, client
->irq
,
1864 NULL
, iqs269_irq
, IRQF_ONESHOT
,
1865 client
->name
, iqs269
);
1867 dev_err(&client
->dev
, "Failed to request IRQ: %d\n", error
);
1871 if (!wait_for_completion_timeout(&iqs269
->ati_done
,
1872 msecs_to_jiffies(2000))) {
1873 dev_err(&client
->dev
, "Failed to complete ATI\n");
1878 * The keypad may include one or more switches and is not registered
1879 * until ATI is complete and the initial switch states are read.
1881 error
= input_register_device(iqs269
->keypad
);
1883 dev_err(&client
->dev
, "Failed to register keypad: %d\n", error
);
1890 static u16
iqs269_general_get(struct iqs269_private
*iqs269
)
1892 u16 general
= be16_to_cpu(iqs269
->sys_reg
.general
);
1894 general
&= ~IQS269_SYS_SETTINGS_REDO_ATI
;
1895 general
&= ~IQS269_SYS_SETTINGS_ACK_RESET
;
1897 return general
| IQS269_SYS_SETTINGS_DIS_AUTO
;
1900 static int iqs269_suspend(struct device
*dev
)
1902 struct iqs269_private
*iqs269
= dev_get_drvdata(dev
);
1903 struct i2c_client
*client
= iqs269
->client
;
1905 u16 general
= iqs269_general_get(iqs269
);
1907 if (!(general
& IQS269_SYS_SETTINGS_PWR_MODE_MASK
))
1910 disable_irq(client
->irq
);
1912 error
= regmap_write(iqs269
->regmap
, IQS269_SYS_SETTINGS
, general
);
1915 enable_irq(client
->irq
);
1920 static int iqs269_resume(struct device
*dev
)
1922 struct iqs269_private
*iqs269
= dev_get_drvdata(dev
);
1923 struct i2c_client
*client
= iqs269
->client
;
1925 u16 general
= iqs269_general_get(iqs269
);
1927 if (!(general
& IQS269_SYS_SETTINGS_PWR_MODE_MASK
))
1930 disable_irq(client
->irq
);
1932 error
= regmap_write(iqs269
->regmap
, IQS269_SYS_SETTINGS
,
1933 general
& ~IQS269_SYS_SETTINGS_PWR_MODE_MASK
);
1935 error
= regmap_write(iqs269
->regmap
, IQS269_SYS_SETTINGS
,
1936 general
& ~IQS269_SYS_SETTINGS_DIS_AUTO
);
1939 enable_irq(client
->irq
);
1944 static DEFINE_SIMPLE_DEV_PM_OPS(iqs269_pm
, iqs269_suspend
, iqs269_resume
);
1946 static const struct of_device_id iqs269_of_match
[] = {
1948 .compatible
= "azoteq,iqs269a",
1949 .data
= (void *)IQS269_OTP_OPTION_DEFAULT
,
1952 .compatible
= "azoteq,iqs269a-00",
1953 .data
= (void *)IQS269_OTP_OPTION_DEFAULT
,
1956 .compatible
= "azoteq,iqs269a-d0",
1957 .data
= (void *)IQS269_OTP_OPTION_TWS
,
1961 MODULE_DEVICE_TABLE(of
, iqs269_of_match
);
1963 static struct i2c_driver iqs269_i2c_driver
= {
1966 .dev_groups
= iqs269_groups
,
1967 .of_match_table
= iqs269_of_match
,
1968 .pm
= pm_sleep_ptr(&iqs269_pm
),
1970 .probe
= iqs269_probe
,
1972 module_i2c_driver(iqs269_i2c_driver
);
1974 MODULE_AUTHOR("Jeff LaBundy <jeff@labundy.com>");
1975 MODULE_DESCRIPTION("Azoteq IQS269A Capacitive Touch Controller");
1976 MODULE_LICENSE("GPL");