1 // SPDX-License-Identifier: GPL-2.0+
3 * Azoteq IQS626A Capacitive Touch Controller
5 * Copyright (C) 2020 Jeff LaBundy <jeff@labundy.com>
7 * This driver registers up to 2 input devices: one representing capacitive or
8 * inductive keys as well as Hall-effect switches, and one for a trackpad that
9 * can express various gestures.
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/input/touchscreen.h>
20 #include <linux/interrupt.h>
21 #include <linux/kernel.h>
22 #include <linux/mod_devicetable.h>
23 #include <linux/module.h>
24 #include <linux/property.h>
25 #include <linux/regmap.h>
26 #include <linux/slab.h>
28 #define IQS626_VER_INFO 0x00
29 #define IQS626_VER_INFO_PROD_NUM 0x51
31 #define IQS626_SYS_FLAGS 0x02
32 #define IQS626_SYS_FLAGS_SHOW_RESET BIT(15)
33 #define IQS626_SYS_FLAGS_IN_ATI BIT(12)
34 #define IQS626_SYS_FLAGS_PWR_MODE_MASK GENMASK(9, 8)
35 #define IQS626_SYS_FLAGS_PWR_MODE_SHIFT 8
37 #define IQS626_HALL_OUTPUT 0x23
39 #define IQS626_SYS_SETTINGS 0x80
40 #define IQS626_SYS_SETTINGS_CLK_DIV BIT(15)
41 #define IQS626_SYS_SETTINGS_ULP_AUTO BIT(14)
42 #define IQS626_SYS_SETTINGS_DIS_AUTO BIT(13)
43 #define IQS626_SYS_SETTINGS_PWR_MODE_MASK GENMASK(12, 11)
44 #define IQS626_SYS_SETTINGS_PWR_MODE_SHIFT 11
45 #define IQS626_SYS_SETTINGS_PWR_MODE_MAX 3
46 #define IQS626_SYS_SETTINGS_ULP_UPDATE_MASK GENMASK(10, 8)
47 #define IQS626_SYS_SETTINGS_ULP_UPDATE_SHIFT 8
48 #define IQS626_SYS_SETTINGS_ULP_UPDATE_MAX 7
49 #define IQS626_SYS_SETTINGS_EVENT_MODE BIT(5)
50 #define IQS626_SYS_SETTINGS_EVENT_MODE_LP BIT(4)
51 #define IQS626_SYS_SETTINGS_REDO_ATI BIT(2)
52 #define IQS626_SYS_SETTINGS_ACK_RESET BIT(0)
54 #define IQS626_MISC_A_ATI_BAND_DISABLE BIT(7)
55 #define IQS626_MISC_A_TPx_LTA_UPDATE_MASK GENMASK(6, 4)
56 #define IQS626_MISC_A_TPx_LTA_UPDATE_SHIFT 4
57 #define IQS626_MISC_A_TPx_LTA_UPDATE_MAX 7
58 #define IQS626_MISC_A_ATI_LP_ONLY BIT(3)
59 #define IQS626_MISC_A_GPIO3_SELECT_MASK GENMASK(2, 0)
60 #define IQS626_MISC_A_GPIO3_SELECT_MAX 7
62 #define IQS626_EVENT_MASK_SYS BIT(6)
63 #define IQS626_EVENT_MASK_GESTURE BIT(3)
64 #define IQS626_EVENT_MASK_DEEP BIT(2)
65 #define IQS626_EVENT_MASK_TOUCH BIT(1)
66 #define IQS626_EVENT_MASK_PROX BIT(0)
68 #define IQS626_RATE_NP_MS_MAX 255
69 #define IQS626_RATE_LP_MS_MAX 255
70 #define IQS626_RATE_ULP_MS_MAX 4080
71 #define IQS626_TIMEOUT_PWR_MS_MAX 130560
72 #define IQS626_TIMEOUT_LTA_MS_MAX 130560
74 #define IQS626_MISC_B_RESEED_UI_SEL_MASK GENMASK(7, 6)
75 #define IQS626_MISC_B_RESEED_UI_SEL_SHIFT 6
76 #define IQS626_MISC_B_RESEED_UI_SEL_MAX 3
77 #define IQS626_MISC_B_THRESH_EXTEND BIT(5)
78 #define IQS626_MISC_B_TRACKING_UI_ENABLE BIT(4)
79 #define IQS626_MISC_B_TPx_SWIPE BIT(3)
80 #define IQS626_MISC_B_RESEED_OFFSET BIT(2)
81 #define IQS626_MISC_B_FILT_STR_TPx GENMASK(1, 0)
83 #define IQS626_THRESH_SWIPE_MAX 255
84 #define IQS626_TIMEOUT_TAP_MS_MAX 4080
85 #define IQS626_TIMEOUT_SWIPE_MS_MAX 4080
87 #define IQS626_CHx_ENG_0_MEAS_CAP_SIZE BIT(7)
88 #define IQS626_CHx_ENG_0_RX_TERM_VSS BIT(5)
89 #define IQS626_CHx_ENG_0_LINEARIZE BIT(4)
90 #define IQS626_CHx_ENG_0_DUAL_DIR BIT(3)
91 #define IQS626_CHx_ENG_0_FILT_DISABLE BIT(2)
92 #define IQS626_CHx_ENG_0_ATI_MODE_MASK GENMASK(1, 0)
93 #define IQS626_CHx_ENG_0_ATI_MODE_MAX 3
95 #define IQS626_CHx_ENG_1_CCT_HIGH_1 BIT(7)
96 #define IQS626_CHx_ENG_1_CCT_HIGH_0 BIT(6)
97 #define IQS626_CHx_ENG_1_PROJ_BIAS_MASK GENMASK(5, 4)
98 #define IQS626_CHx_ENG_1_PROJ_BIAS_SHIFT 4
99 #define IQS626_CHx_ENG_1_PROJ_BIAS_MAX 3
100 #define IQS626_CHx_ENG_1_CCT_ENABLE BIT(3)
101 #define IQS626_CHx_ENG_1_SENSE_FREQ_MASK GENMASK(2, 1)
102 #define IQS626_CHx_ENG_1_SENSE_FREQ_SHIFT 1
103 #define IQS626_CHx_ENG_1_SENSE_FREQ_MAX 3
104 #define IQS626_CHx_ENG_1_ATI_BAND_TIGHTEN BIT(0)
106 #define IQS626_CHx_ENG_2_LOCAL_CAP_MASK GENMASK(7, 6)
107 #define IQS626_CHx_ENG_2_LOCAL_CAP_SHIFT 6
108 #define IQS626_CHx_ENG_2_LOCAL_CAP_MAX 3
109 #define IQS626_CHx_ENG_2_LOCAL_CAP_ENABLE BIT(5)
110 #define IQS626_CHx_ENG_2_SENSE_MODE_MASK GENMASK(3, 0)
111 #define IQS626_CHx_ENG_2_SENSE_MODE_MAX 15
113 #define IQS626_CHx_ENG_3_TX_FREQ_MASK GENMASK(5, 4)
114 #define IQS626_CHx_ENG_3_TX_FREQ_SHIFT 4
115 #define IQS626_CHx_ENG_3_TX_FREQ_MAX 3
116 #define IQS626_CHx_ENG_3_INV_LOGIC BIT(0)
118 #define IQS626_CHx_ENG_4_RX_TERM_VREG BIT(6)
119 #define IQS626_CHx_ENG_4_CCT_LOW_1 BIT(5)
120 #define IQS626_CHx_ENG_4_CCT_LOW_0 BIT(4)
121 #define IQS626_CHx_ENG_4_COMP_DISABLE BIT(1)
122 #define IQS626_CHx_ENG_4_STATIC_ENABLE BIT(0)
124 #define IQS626_TPx_ATI_BASE_MIN 45
125 #define IQS626_TPx_ATI_BASE_MAX 300
126 #define IQS626_CHx_ATI_BASE_MASK GENMASK(7, 6)
127 #define IQS626_CHx_ATI_BASE_75 0x00
128 #define IQS626_CHx_ATI_BASE_100 0x40
129 #define IQS626_CHx_ATI_BASE_150 0x80
130 #define IQS626_CHx_ATI_BASE_200 0xC0
131 #define IQS626_CHx_ATI_TARGET_MASK GENMASK(5, 0)
132 #define IQS626_CHx_ATI_TARGET_MAX 2016
134 #define IQS626_CHx_THRESH_MAX 255
135 #define IQS626_CHx_HYST_DEEP_MASK GENMASK(7, 4)
136 #define IQS626_CHx_HYST_DEEP_SHIFT 4
137 #define IQS626_CHx_HYST_TOUCH_MASK GENMASK(3, 0)
138 #define IQS626_CHx_HYST_MAX 15
140 #define IQS626_FILT_STR_NP_TPx_MASK GENMASK(7, 6)
141 #define IQS626_FILT_STR_NP_TPx_SHIFT 6
142 #define IQS626_FILT_STR_LP_TPx_MASK GENMASK(5, 4)
143 #define IQS626_FILT_STR_LP_TPx_SHIFT 4
145 #define IQS626_FILT_STR_NP_CNT_MASK GENMASK(7, 6)
146 #define IQS626_FILT_STR_NP_CNT_SHIFT 6
147 #define IQS626_FILT_STR_LP_CNT_MASK GENMASK(5, 4)
148 #define IQS626_FILT_STR_LP_CNT_SHIFT 4
149 #define IQS626_FILT_STR_NP_LTA_MASK GENMASK(3, 2)
150 #define IQS626_FILT_STR_NP_LTA_SHIFT 2
151 #define IQS626_FILT_STR_LP_LTA_MASK GENMASK(1, 0)
152 #define IQS626_FILT_STR_MAX 3
154 #define IQS626_ULP_PROJ_ENABLE BIT(4)
155 #define IQS626_GEN_WEIGHT_MAX 255
157 #define IQS626_MAX_REG 0xFF
159 #define IQS626_NUM_CH_TP_3 9
160 #define IQS626_NUM_CH_TP_2 6
161 #define IQS626_NUM_CH_GEN 3
162 #define IQS626_NUM_CRx_TX 8
164 #define IQS626_PWR_MODE_POLL_SLEEP_US 50000
165 #define IQS626_PWR_MODE_POLL_TIMEOUT_US 500000
167 #define iqs626_irq_wait() usleep_range(350, 400)
179 enum iqs626_rx_inactive
{
180 IQS626_RX_INACTIVE_VSS
,
181 IQS626_RX_INACTIVE_FLOAT
,
182 IQS626_RX_INACTIVE_VREG
,
185 enum iqs626_st_offs
{
188 IQS626_ST_OFFS_TOUCH
,
192 enum iqs626_th_offs
{
194 IQS626_TH_OFFS_TOUCH
,
198 enum iqs626_event_id
{
199 IQS626_EVENT_PROX_DN
,
200 IQS626_EVENT_PROX_UP
,
201 IQS626_EVENT_TOUCH_DN
,
202 IQS626_EVENT_TOUCH_UP
,
203 IQS626_EVENT_DEEP_DN
,
204 IQS626_EVENT_DEEP_UP
,
207 enum iqs626_gesture_id
{
208 IQS626_GESTURE_FLICK_X_POS
,
209 IQS626_GESTURE_FLICK_X_NEG
,
210 IQS626_GESTURE_FLICK_Y_POS
,
211 IQS626_GESTURE_FLICK_Y_NEG
,
217 struct iqs626_event_desc
{
219 enum iqs626_st_offs st_offs
;
220 enum iqs626_th_offs th_offs
;
225 static const struct iqs626_event_desc iqs626_events
[] = {
226 [IQS626_EVENT_PROX_DN
] = {
227 .name
= "event-prox",
228 .st_offs
= IQS626_ST_OFFS_PROX
,
229 .th_offs
= IQS626_TH_OFFS_PROX
,
230 .mask
= IQS626_EVENT_MASK_PROX
,
232 [IQS626_EVENT_PROX_UP
] = {
233 .name
= "event-prox-alt",
234 .st_offs
= IQS626_ST_OFFS_PROX
,
235 .th_offs
= IQS626_TH_OFFS_PROX
,
237 .mask
= IQS626_EVENT_MASK_PROX
,
239 [IQS626_EVENT_TOUCH_DN
] = {
240 .name
= "event-touch",
241 .st_offs
= IQS626_ST_OFFS_TOUCH
,
242 .th_offs
= IQS626_TH_OFFS_TOUCH
,
243 .mask
= IQS626_EVENT_MASK_TOUCH
,
245 [IQS626_EVENT_TOUCH_UP
] = {
246 .name
= "event-touch-alt",
247 .st_offs
= IQS626_ST_OFFS_TOUCH
,
248 .th_offs
= IQS626_TH_OFFS_TOUCH
,
250 .mask
= IQS626_EVENT_MASK_TOUCH
,
252 [IQS626_EVENT_DEEP_DN
] = {
253 .name
= "event-deep",
254 .st_offs
= IQS626_ST_OFFS_DEEP
,
255 .th_offs
= IQS626_TH_OFFS_DEEP
,
256 .mask
= IQS626_EVENT_MASK_DEEP
,
258 [IQS626_EVENT_DEEP_UP
] = {
259 .name
= "event-deep-alt",
260 .st_offs
= IQS626_ST_OFFS_DEEP
,
261 .th_offs
= IQS626_TH_OFFS_DEEP
,
263 .mask
= IQS626_EVENT_MASK_DEEP
,
267 struct iqs626_ver_info
{
274 struct iqs626_flags
{
287 struct iqs626_ch_reg_ulp
{
299 struct iqs626_ch_reg_tp
{
305 struct iqs626_tp_grp_reg
{
309 struct iqs626_ch_reg_tp ch_reg_tp
[IQS626_NUM_CH_TP_3
];
312 struct iqs626_ch_reg_gen
{
326 struct iqs626_ch_reg_hall
{
334 struct iqs626_sys_reg
{
352 struct iqs626_ch_reg_ulp ch_reg_ulp
;
353 struct iqs626_tp_grp_reg tp_grp_reg
;
354 struct iqs626_ch_reg_gen ch_reg_gen
[IQS626_NUM_CH_GEN
];
355 struct iqs626_ch_reg_hall ch_reg_hall
;
358 struct iqs626_channel_desc
{
362 bool events
[ARRAY_SIZE(iqs626_events
)];
365 static const struct iqs626_channel_desc iqs626_channels
[] = {
366 [IQS626_CH_ULP_0
] = {
371 [IQS626_EVENT_PROX_DN
] = true,
372 [IQS626_EVENT_PROX_UP
] = true,
373 [IQS626_EVENT_TOUCH_DN
] = true,
374 [IQS626_EVENT_TOUCH_UP
] = true,
378 .name
= "trackpad-3x2",
379 .num_ch
= IQS626_NUM_CH_TP_2
,
382 [IQS626_EVENT_TOUCH_DN
] = true,
386 .name
= "trackpad-3x3",
387 .num_ch
= IQS626_NUM_CH_TP_3
,
388 .active
= BIT(2) | BIT(1),
390 [IQS626_EVENT_TOUCH_DN
] = true,
393 [IQS626_CH_GEN_0
] = {
398 [IQS626_EVENT_PROX_DN
] = true,
399 [IQS626_EVENT_PROX_UP
] = true,
400 [IQS626_EVENT_TOUCH_DN
] = true,
401 [IQS626_EVENT_TOUCH_UP
] = true,
402 [IQS626_EVENT_DEEP_DN
] = true,
403 [IQS626_EVENT_DEEP_UP
] = true,
406 [IQS626_CH_GEN_1
] = {
411 [IQS626_EVENT_PROX_DN
] = true,
412 [IQS626_EVENT_PROX_UP
] = true,
413 [IQS626_EVENT_TOUCH_DN
] = true,
414 [IQS626_EVENT_TOUCH_UP
] = true,
415 [IQS626_EVENT_DEEP_DN
] = true,
416 [IQS626_EVENT_DEEP_UP
] = true,
419 [IQS626_CH_GEN_2
] = {
424 [IQS626_EVENT_PROX_DN
] = true,
425 [IQS626_EVENT_PROX_UP
] = true,
426 [IQS626_EVENT_TOUCH_DN
] = true,
427 [IQS626_EVENT_TOUCH_UP
] = true,
428 [IQS626_EVENT_DEEP_DN
] = true,
429 [IQS626_EVENT_DEEP_UP
] = true,
437 [IQS626_EVENT_TOUCH_DN
] = true,
438 [IQS626_EVENT_TOUCH_UP
] = true,
443 struct iqs626_private
{
444 struct i2c_client
*client
;
445 struct regmap
*regmap
;
446 struct iqs626_sys_reg sys_reg
;
447 struct completion ati_done
;
448 struct input_dev
*keypad
;
449 struct input_dev
*trackpad
;
450 struct touchscreen_properties prop
;
451 unsigned int kp_type
[ARRAY_SIZE(iqs626_channels
)]
452 [ARRAY_SIZE(iqs626_events
)];
453 unsigned int kp_code
[ARRAY_SIZE(iqs626_channels
)]
454 [ARRAY_SIZE(iqs626_events
)];
455 unsigned int tp_code
[IQS626_NUM_GESTURES
];
456 unsigned int suspend_mode
;
459 static noinline_for_stack
int
460 iqs626_parse_events(struct iqs626_private
*iqs626
,
461 struct fwnode_handle
*ch_node
, enum iqs626_ch_id ch_id
)
463 struct iqs626_sys_reg
*sys_reg
= &iqs626
->sys_reg
;
464 struct i2c_client
*client
= iqs626
->client
;
471 case IQS626_CH_ULP_0
:
472 thresh
= sys_reg
->ch_reg_ulp
.thresh
;
473 hyst
= &sys_reg
->ch_reg_ulp
.hyst
;
478 thresh
= &sys_reg
->tp_grp_reg
.ch_reg_tp
[0].thresh
;
479 hyst
= &sys_reg
->tp_grp_reg
.hyst
;
482 case IQS626_CH_GEN_0
:
483 case IQS626_CH_GEN_1
:
484 case IQS626_CH_GEN_2
:
485 i
= ch_id
- IQS626_CH_GEN_0
;
486 thresh
= sys_reg
->ch_reg_gen
[i
].thresh
;
487 hyst
= &sys_reg
->ch_reg_gen
[i
].hyst
;
491 thresh
= &sys_reg
->ch_reg_hall
.thresh
;
492 hyst
= &sys_reg
->ch_reg_hall
.hyst
;
499 for (i
= 0; i
< ARRAY_SIZE(iqs626_events
); i
++) {
500 if (!iqs626_channels
[ch_id
].events
[i
])
503 struct fwnode_handle
*ev_node
__free(fwnode_handle
) = NULL
;
504 if (ch_id
== IQS626_CH_TP_2
|| ch_id
== IQS626_CH_TP_3
) {
506 * Trackpad touch events are simply described under the
507 * trackpad child node.
509 ev_node
= fwnode_handle_get(ch_node
);
511 ev_name
= iqs626_events
[i
].name
;
512 ev_node
= fwnode_get_named_child_node(ch_node
, ev_name
);
516 if (!fwnode_property_read_u32(ev_node
, "linux,code",
518 iqs626
->kp_code
[ch_id
][i
] = val
;
520 if (fwnode_property_read_u32(ev_node
,
523 if (ch_id
== IQS626_CH_HALL
)
529 if (val
!= EV_KEY
&& val
!= EV_SW
) {
530 dev_err(&client
->dev
,
531 "Invalid input type: %u\n",
536 iqs626
->kp_type
[ch_id
][i
] = val
;
538 sys_reg
->event_mask
&= ~iqs626_events
[i
].mask
;
542 if (!fwnode_property_read_u32(ev_node
, "azoteq,hyst", &val
)) {
543 if (val
> IQS626_CHx_HYST_MAX
) {
544 dev_err(&client
->dev
,
545 "Invalid %s channel hysteresis: %u\n",
546 fwnode_get_name(ch_node
), val
);
550 if (i
== IQS626_EVENT_DEEP_DN
||
551 i
== IQS626_EVENT_DEEP_UP
) {
552 *hyst
&= ~IQS626_CHx_HYST_DEEP_MASK
;
553 *hyst
|= (val
<< IQS626_CHx_HYST_DEEP_SHIFT
);
554 } else if (i
== IQS626_EVENT_TOUCH_DN
||
555 i
== IQS626_EVENT_TOUCH_UP
) {
556 *hyst
&= ~IQS626_CHx_HYST_TOUCH_MASK
;
561 if (ch_id
!= IQS626_CH_TP_2
&& ch_id
!= IQS626_CH_TP_3
&&
562 !fwnode_property_read_u32(ev_node
, "azoteq,thresh", &val
)) {
563 if (val
> IQS626_CHx_THRESH_MAX
) {
564 dev_err(&client
->dev
,
565 "Invalid %s channel threshold: %u\n",
566 fwnode_get_name(ch_node
), val
);
570 if (ch_id
== IQS626_CH_HALL
)
573 *(thresh
+ iqs626_events
[i
].th_offs
) = val
;
580 static noinline_for_stack
int
581 iqs626_parse_ati_target(struct iqs626_private
*iqs626
,
582 struct fwnode_handle
*ch_node
, enum iqs626_ch_id ch_id
)
584 struct iqs626_sys_reg
*sys_reg
= &iqs626
->sys_reg
;
585 struct i2c_client
*client
= iqs626
->client
;
591 case IQS626_CH_ULP_0
:
592 ati_target
= &sys_reg
->ch_reg_ulp
.ati_target
;
597 ati_target
= &sys_reg
->tp_grp_reg
.ati_target
;
600 case IQS626_CH_GEN_0
:
601 case IQS626_CH_GEN_1
:
602 case IQS626_CH_GEN_2
:
603 i
= ch_id
- IQS626_CH_GEN_0
;
604 ati_target
= &sys_reg
->ch_reg_gen
[i
].ati_target
;
608 ati_target
= &sys_reg
->ch_reg_hall
.ati_target
;
615 if (!fwnode_property_read_u32(ch_node
, "azoteq,ati-target", &val
)) {
616 if (val
> IQS626_CHx_ATI_TARGET_MAX
) {
617 dev_err(&client
->dev
,
618 "Invalid %s channel ATI target: %u\n",
619 fwnode_get_name(ch_node
), val
);
623 *ati_target
&= ~IQS626_CHx_ATI_TARGET_MASK
;
624 *ati_target
|= (val
/ 32);
627 if (ch_id
!= IQS626_CH_TP_2
&& ch_id
!= IQS626_CH_TP_3
&&
628 !fwnode_property_read_u32(ch_node
, "azoteq,ati-base", &val
)) {
631 val
= IQS626_CHx_ATI_BASE_75
;
635 val
= IQS626_CHx_ATI_BASE_100
;
639 val
= IQS626_CHx_ATI_BASE_150
;
643 val
= IQS626_CHx_ATI_BASE_200
;
647 dev_err(&client
->dev
,
648 "Invalid %s channel ATI base: %u\n",
649 fwnode_get_name(ch_node
), val
);
653 *ati_target
&= ~IQS626_CHx_ATI_BASE_MASK
;
660 static int iqs626_parse_pins(struct iqs626_private
*iqs626
,
661 struct fwnode_handle
*ch_node
,
662 const char *propname
, u8
*enable
)
664 struct i2c_client
*client
= iqs626
->client
;
665 unsigned int val
[IQS626_NUM_CRx_TX
];
668 if (!fwnode_property_present(ch_node
, propname
))
671 count
= fwnode_property_count_u32(ch_node
, propname
);
672 if (count
> IQS626_NUM_CRx_TX
) {
673 dev_err(&client
->dev
,
674 "Too many %s channel CRX/TX pins present\n",
675 fwnode_get_name(ch_node
));
677 } else if (count
< 0) {
678 dev_err(&client
->dev
,
679 "Failed to count %s channel CRX/TX pins: %d\n",
680 fwnode_get_name(ch_node
), count
);
684 error
= fwnode_property_read_u32_array(ch_node
, propname
, val
, count
);
686 dev_err(&client
->dev
,
687 "Failed to read %s channel CRX/TX pins: %d\n",
688 fwnode_get_name(ch_node
), error
);
694 for (i
= 0; i
< count
; i
++) {
695 if (val
[i
] >= IQS626_NUM_CRx_TX
) {
696 dev_err(&client
->dev
,
697 "Invalid %s channel CRX/TX pin: %u\n",
698 fwnode_get_name(ch_node
), val
[i
]);
702 *enable
|= BIT(val
[i
]);
708 static int iqs626_parse_trackpad(struct iqs626_private
*iqs626
,
709 struct fwnode_handle
*ch_node
,
710 enum iqs626_ch_id ch_id
)
712 struct iqs626_sys_reg
*sys_reg
= &iqs626
->sys_reg
;
713 struct i2c_client
*client
= iqs626
->client
;
714 u8
*hyst
= &sys_reg
->tp_grp_reg
.hyst
;
718 if (!fwnode_property_read_u32(ch_node
, "azoteq,lta-update", &val
)) {
719 if (val
> IQS626_MISC_A_TPx_LTA_UPDATE_MAX
) {
720 dev_err(&client
->dev
,
721 "Invalid %s channel update rate: %u\n",
722 fwnode_get_name(ch_node
), val
);
726 sys_reg
->misc_a
&= ~IQS626_MISC_A_TPx_LTA_UPDATE_MASK
;
727 sys_reg
->misc_a
|= (val
<< IQS626_MISC_A_TPx_LTA_UPDATE_SHIFT
);
730 if (!fwnode_property_read_u32(ch_node
, "azoteq,filt-str-trackpad",
732 if (val
> IQS626_FILT_STR_MAX
) {
733 dev_err(&client
->dev
,
734 "Invalid %s channel filter strength: %u\n",
735 fwnode_get_name(ch_node
), val
);
739 sys_reg
->misc_b
&= ~IQS626_MISC_B_FILT_STR_TPx
;
740 sys_reg
->misc_b
|= val
;
743 if (!fwnode_property_read_u32(ch_node
, "azoteq,filt-str-np-cnt",
745 if (val
> IQS626_FILT_STR_MAX
) {
746 dev_err(&client
->dev
,
747 "Invalid %s channel filter strength: %u\n",
748 fwnode_get_name(ch_node
), val
);
752 *hyst
&= ~IQS626_FILT_STR_NP_TPx_MASK
;
753 *hyst
|= (val
<< IQS626_FILT_STR_NP_TPx_SHIFT
);
756 if (!fwnode_property_read_u32(ch_node
, "azoteq,filt-str-lp-cnt",
758 if (val
> IQS626_FILT_STR_MAX
) {
759 dev_err(&client
->dev
,
760 "Invalid %s channel filter strength: %u\n",
761 fwnode_get_name(ch_node
), val
);
765 *hyst
&= ~IQS626_FILT_STR_LP_TPx_MASK
;
766 *hyst
|= (val
<< IQS626_FILT_STR_LP_TPx_SHIFT
);
769 for (i
= 0; i
< iqs626_channels
[ch_id
].num_ch
; i
++) {
770 u8
*ati_base
= &sys_reg
->tp_grp_reg
.ch_reg_tp
[i
].ati_base
;
771 u8
*thresh
= &sys_reg
->tp_grp_reg
.ch_reg_tp
[i
].thresh
;
774 snprintf(tc_name
, sizeof(tc_name
), "channel-%d", i
);
776 struct fwnode_handle
*tc_node
__free(fwnode_handle
) =
777 fwnode_get_named_child_node(ch_node
, tc_name
);
781 if (!fwnode_property_read_u32(tc_node
, "azoteq,ati-base",
783 if (val
< IQS626_TPx_ATI_BASE_MIN
||
784 val
> IQS626_TPx_ATI_BASE_MAX
) {
785 dev_err(&client
->dev
,
786 "Invalid %s %s ATI base: %u\n",
787 fwnode_get_name(ch_node
), tc_name
, val
);
791 *ati_base
= val
- IQS626_TPx_ATI_BASE_MIN
;
794 if (!fwnode_property_read_u32(tc_node
, "azoteq,thresh",
796 if (val
> IQS626_CHx_THRESH_MAX
) {
797 dev_err(&client
->dev
,
798 "Invalid %s %s threshold: %u\n",
799 fwnode_get_name(ch_node
), tc_name
, val
);
807 if (!fwnode_property_present(ch_node
, "linux,keycodes"))
810 count
= fwnode_property_count_u32(ch_node
, "linux,keycodes");
811 if (count
> IQS626_NUM_GESTURES
) {
812 dev_err(&client
->dev
, "Too many keycodes present\n");
814 } else if (count
< 0) {
815 dev_err(&client
->dev
, "Failed to count keycodes: %d\n", count
);
819 error
= fwnode_property_read_u32_array(ch_node
, "linux,keycodes",
820 iqs626
->tp_code
, count
);
822 dev_err(&client
->dev
, "Failed to read keycodes: %d\n", error
);
826 sys_reg
->misc_b
&= ~IQS626_MISC_B_TPx_SWIPE
;
827 if (fwnode_property_present(ch_node
, "azoteq,gesture-swipe"))
828 sys_reg
->misc_b
|= IQS626_MISC_B_TPx_SWIPE
;
830 if (!fwnode_property_read_u32(ch_node
, "azoteq,timeout-tap-ms",
832 if (val
> IQS626_TIMEOUT_TAP_MS_MAX
) {
833 dev_err(&client
->dev
,
834 "Invalid %s channel timeout: %u\n",
835 fwnode_get_name(ch_node
), val
);
839 sys_reg
->timeout_tap
= val
/ 16;
842 if (!fwnode_property_read_u32(ch_node
, "azoteq,timeout-swipe-ms",
844 if (val
> IQS626_TIMEOUT_SWIPE_MS_MAX
) {
845 dev_err(&client
->dev
,
846 "Invalid %s channel timeout: %u\n",
847 fwnode_get_name(ch_node
), val
);
851 sys_reg
->timeout_swipe
= val
/ 16;
854 if (!fwnode_property_read_u32(ch_node
, "azoteq,thresh-swipe",
856 if (val
> IQS626_THRESH_SWIPE_MAX
) {
857 dev_err(&client
->dev
,
858 "Invalid %s channel threshold: %u\n",
859 fwnode_get_name(ch_node
), val
);
863 sys_reg
->thresh_swipe
= val
;
866 sys_reg
->event_mask
&= ~IQS626_EVENT_MASK_GESTURE
;
871 static noinline_for_stack
int
872 iqs626_parse_channel(struct iqs626_private
*iqs626
,
873 struct fwnode_handle
*ch_node
, enum iqs626_ch_id ch_id
)
875 struct iqs626_sys_reg
*sys_reg
= &iqs626
->sys_reg
;
876 struct i2c_client
*client
= iqs626
->client
;
877 u8
*engine
, *filter
, *rx_enable
, *tx_enable
;
878 u8
*assoc_select
, *assoc_weight
;
883 case IQS626_CH_ULP_0
:
884 engine
= sys_reg
->ch_reg_ulp
.engine
;
889 engine
= sys_reg
->tp_grp_reg
.engine
;
892 case IQS626_CH_GEN_0
:
893 case IQS626_CH_GEN_1
:
894 case IQS626_CH_GEN_2
:
895 i
= ch_id
- IQS626_CH_GEN_0
;
896 engine
= sys_reg
->ch_reg_gen
[i
].engine
;
900 engine
= &sys_reg
->ch_reg_hall
.engine
;
907 error
= iqs626_parse_ati_target(iqs626
, ch_node
, ch_id
);
911 error
= iqs626_parse_events(iqs626
, ch_node
, ch_id
);
915 if (!fwnode_property_present(ch_node
, "azoteq,ati-exclude"))
916 sys_reg
->redo_ati
|= iqs626_channels
[ch_id
].active
;
918 if (!fwnode_property_present(ch_node
, "azoteq,reseed-disable"))
919 sys_reg
->reseed
|= iqs626_channels
[ch_id
].active
;
921 *engine
|= IQS626_CHx_ENG_0_MEAS_CAP_SIZE
;
922 if (fwnode_property_present(ch_node
, "azoteq,meas-cap-decrease"))
923 *engine
&= ~IQS626_CHx_ENG_0_MEAS_CAP_SIZE
;
925 *engine
|= IQS626_CHx_ENG_0_RX_TERM_VSS
;
926 if (!fwnode_property_read_u32(ch_node
, "azoteq,rx-inactive", &val
)) {
928 case IQS626_RX_INACTIVE_VSS
:
931 case IQS626_RX_INACTIVE_FLOAT
:
932 *engine
&= ~IQS626_CHx_ENG_0_RX_TERM_VSS
;
933 if (ch_id
== IQS626_CH_GEN_0
||
934 ch_id
== IQS626_CH_GEN_1
||
935 ch_id
== IQS626_CH_GEN_2
)
936 *(engine
+ 4) &= ~IQS626_CHx_ENG_4_RX_TERM_VREG
;
939 case IQS626_RX_INACTIVE_VREG
:
940 if (ch_id
== IQS626_CH_GEN_0
||
941 ch_id
== IQS626_CH_GEN_1
||
942 ch_id
== IQS626_CH_GEN_2
) {
943 *engine
&= ~IQS626_CHx_ENG_0_RX_TERM_VSS
;
944 *(engine
+ 4) |= IQS626_CHx_ENG_4_RX_TERM_VREG
;
950 dev_err(&client
->dev
,
951 "Invalid %s channel CRX pin termination: %u\n",
952 fwnode_get_name(ch_node
), val
);
957 *engine
&= ~IQS626_CHx_ENG_0_LINEARIZE
;
958 if (fwnode_property_present(ch_node
, "azoteq,linearize"))
959 *engine
|= IQS626_CHx_ENG_0_LINEARIZE
;
961 *engine
&= ~IQS626_CHx_ENG_0_DUAL_DIR
;
962 if (fwnode_property_present(ch_node
, "azoteq,dual-direction"))
963 *engine
|= IQS626_CHx_ENG_0_DUAL_DIR
;
965 *engine
&= ~IQS626_CHx_ENG_0_FILT_DISABLE
;
966 if (fwnode_property_present(ch_node
, "azoteq,filt-disable"))
967 *engine
|= IQS626_CHx_ENG_0_FILT_DISABLE
;
969 if (!fwnode_property_read_u32(ch_node
, "azoteq,ati-mode", &val
)) {
970 if (val
> IQS626_CHx_ENG_0_ATI_MODE_MAX
) {
971 dev_err(&client
->dev
,
972 "Invalid %s channel ATI mode: %u\n",
973 fwnode_get_name(ch_node
), val
);
977 *engine
&= ~IQS626_CHx_ENG_0_ATI_MODE_MASK
;
981 if (ch_id
== IQS626_CH_HALL
)
984 *(engine
+ 1) &= ~IQS626_CHx_ENG_1_CCT_ENABLE
;
985 if (!fwnode_property_read_u32(ch_node
, "azoteq,cct-increase",
987 unsigned int orig_val
= val
--;
990 * In the case of the generic channels, the charge cycle time
991 * field doubles in size and straddles two separate registers.
993 if (ch_id
== IQS626_CH_GEN_0
||
994 ch_id
== IQS626_CH_GEN_1
||
995 ch_id
== IQS626_CH_GEN_2
) {
996 *(engine
+ 4) &= ~IQS626_CHx_ENG_4_CCT_LOW_1
;
998 *(engine
+ 4) |= IQS626_CHx_ENG_4_CCT_LOW_1
;
1000 *(engine
+ 4) &= ~IQS626_CHx_ENG_4_CCT_LOW_0
;
1002 *(engine
+ 4) |= IQS626_CHx_ENG_4_CCT_LOW_0
;
1007 if (val
& ~GENMASK(1, 0)) {
1008 dev_err(&client
->dev
,
1009 "Invalid %s channel charge cycle time: %u\n",
1010 fwnode_get_name(ch_node
), orig_val
);
1014 *(engine
+ 1) &= ~IQS626_CHx_ENG_1_CCT_HIGH_1
;
1016 *(engine
+ 1) |= IQS626_CHx_ENG_1_CCT_HIGH_1
;
1018 *(engine
+ 1) &= ~IQS626_CHx_ENG_1_CCT_HIGH_0
;
1020 *(engine
+ 1) |= IQS626_CHx_ENG_1_CCT_HIGH_0
;
1022 *(engine
+ 1) |= IQS626_CHx_ENG_1_CCT_ENABLE
;
1025 if (!fwnode_property_read_u32(ch_node
, "azoteq,proj-bias", &val
)) {
1026 if (val
> IQS626_CHx_ENG_1_PROJ_BIAS_MAX
) {
1027 dev_err(&client
->dev
,
1028 "Invalid %s channel bias current: %u\n",
1029 fwnode_get_name(ch_node
), val
);
1033 *(engine
+ 1) &= ~IQS626_CHx_ENG_1_PROJ_BIAS_MASK
;
1034 *(engine
+ 1) |= (val
<< IQS626_CHx_ENG_1_PROJ_BIAS_SHIFT
);
1037 if (!fwnode_property_read_u32(ch_node
, "azoteq,sense-freq", &val
)) {
1038 if (val
> IQS626_CHx_ENG_1_SENSE_FREQ_MAX
) {
1039 dev_err(&client
->dev
,
1040 "Invalid %s channel sensing frequency: %u\n",
1041 fwnode_get_name(ch_node
), val
);
1045 *(engine
+ 1) &= ~IQS626_CHx_ENG_1_SENSE_FREQ_MASK
;
1046 *(engine
+ 1) |= (val
<< IQS626_CHx_ENG_1_SENSE_FREQ_SHIFT
);
1049 *(engine
+ 1) &= ~IQS626_CHx_ENG_1_ATI_BAND_TIGHTEN
;
1050 if (fwnode_property_present(ch_node
, "azoteq,ati-band-tighten"))
1051 *(engine
+ 1) |= IQS626_CHx_ENG_1_ATI_BAND_TIGHTEN
;
1053 if (ch_id
== IQS626_CH_TP_2
|| ch_id
== IQS626_CH_TP_3
)
1054 return iqs626_parse_trackpad(iqs626
, ch_node
, ch_id
);
1056 if (ch_id
== IQS626_CH_ULP_0
) {
1057 sys_reg
->ch_reg_ulp
.hyst
&= ~IQS626_ULP_PROJ_ENABLE
;
1058 if (fwnode_property_present(ch_node
, "azoteq,proj-enable"))
1059 sys_reg
->ch_reg_ulp
.hyst
|= IQS626_ULP_PROJ_ENABLE
;
1061 filter
= &sys_reg
->ch_reg_ulp
.filter
;
1063 rx_enable
= &sys_reg
->ch_reg_ulp
.rx_enable
;
1064 tx_enable
= &sys_reg
->ch_reg_ulp
.tx_enable
;
1066 i
= ch_id
- IQS626_CH_GEN_0
;
1067 filter
= &sys_reg
->ch_reg_gen
[i
].filter
;
1069 rx_enable
= &sys_reg
->ch_reg_gen
[i
].rx_enable
;
1070 tx_enable
= &sys_reg
->ch_reg_gen
[i
].tx_enable
;
1073 if (!fwnode_property_read_u32(ch_node
, "azoteq,filt-str-np-cnt",
1075 if (val
> IQS626_FILT_STR_MAX
) {
1076 dev_err(&client
->dev
,
1077 "Invalid %s channel filter strength: %u\n",
1078 fwnode_get_name(ch_node
), val
);
1082 *filter
&= ~IQS626_FILT_STR_NP_CNT_MASK
;
1083 *filter
|= (val
<< IQS626_FILT_STR_NP_CNT_SHIFT
);
1086 if (!fwnode_property_read_u32(ch_node
, "azoteq,filt-str-lp-cnt",
1088 if (val
> IQS626_FILT_STR_MAX
) {
1089 dev_err(&client
->dev
,
1090 "Invalid %s channel filter strength: %u\n",
1091 fwnode_get_name(ch_node
), val
);
1095 *filter
&= ~IQS626_FILT_STR_LP_CNT_MASK
;
1096 *filter
|= (val
<< IQS626_FILT_STR_LP_CNT_SHIFT
);
1099 if (!fwnode_property_read_u32(ch_node
, "azoteq,filt-str-np-lta",
1101 if (val
> IQS626_FILT_STR_MAX
) {
1102 dev_err(&client
->dev
,
1103 "Invalid %s channel filter strength: %u\n",
1104 fwnode_get_name(ch_node
), val
);
1108 *filter
&= ~IQS626_FILT_STR_NP_LTA_MASK
;
1109 *filter
|= (val
<< IQS626_FILT_STR_NP_LTA_SHIFT
);
1112 if (!fwnode_property_read_u32(ch_node
, "azoteq,filt-str-lp-lta",
1114 if (val
> IQS626_FILT_STR_MAX
) {
1115 dev_err(&client
->dev
,
1116 "Invalid %s channel filter strength: %u\n",
1117 fwnode_get_name(ch_node
), val
);
1121 *filter
&= ~IQS626_FILT_STR_LP_LTA_MASK
;
1125 error
= iqs626_parse_pins(iqs626
, ch_node
, "azoteq,rx-enable",
1130 error
= iqs626_parse_pins(iqs626
, ch_node
, "azoteq,tx-enable",
1135 if (ch_id
== IQS626_CH_ULP_0
)
1138 *(engine
+ 2) &= ~IQS626_CHx_ENG_2_LOCAL_CAP_ENABLE
;
1139 if (!fwnode_property_read_u32(ch_node
, "azoteq,local-cap-size",
1141 unsigned int orig_val
= val
--;
1143 if (val
> IQS626_CHx_ENG_2_LOCAL_CAP_MAX
) {
1144 dev_err(&client
->dev
,
1145 "Invalid %s channel local cap. size: %u\n",
1146 fwnode_get_name(ch_node
), orig_val
);
1150 *(engine
+ 2) &= ~IQS626_CHx_ENG_2_LOCAL_CAP_MASK
;
1151 *(engine
+ 2) |= (val
<< IQS626_CHx_ENG_2_LOCAL_CAP_SHIFT
);
1153 *(engine
+ 2) |= IQS626_CHx_ENG_2_LOCAL_CAP_ENABLE
;
1156 if (!fwnode_property_read_u32(ch_node
, "azoteq,sense-mode", &val
)) {
1157 if (val
> IQS626_CHx_ENG_2_SENSE_MODE_MAX
) {
1158 dev_err(&client
->dev
,
1159 "Invalid %s channel sensing mode: %u\n",
1160 fwnode_get_name(ch_node
), val
);
1164 *(engine
+ 2) &= ~IQS626_CHx_ENG_2_SENSE_MODE_MASK
;
1165 *(engine
+ 2) |= val
;
1168 if (!fwnode_property_read_u32(ch_node
, "azoteq,tx-freq", &val
)) {
1169 if (val
> IQS626_CHx_ENG_3_TX_FREQ_MAX
) {
1170 dev_err(&client
->dev
,
1171 "Invalid %s channel excitation frequency: %u\n",
1172 fwnode_get_name(ch_node
), val
);
1176 *(engine
+ 3) &= ~IQS626_CHx_ENG_3_TX_FREQ_MASK
;
1177 *(engine
+ 3) |= (val
<< IQS626_CHx_ENG_3_TX_FREQ_SHIFT
);
1180 *(engine
+ 3) &= ~IQS626_CHx_ENG_3_INV_LOGIC
;
1181 if (fwnode_property_present(ch_node
, "azoteq,invert-enable"))
1182 *(engine
+ 3) |= IQS626_CHx_ENG_3_INV_LOGIC
;
1184 *(engine
+ 4) &= ~IQS626_CHx_ENG_4_COMP_DISABLE
;
1185 if (fwnode_property_present(ch_node
, "azoteq,comp-disable"))
1186 *(engine
+ 4) |= IQS626_CHx_ENG_4_COMP_DISABLE
;
1188 *(engine
+ 4) &= ~IQS626_CHx_ENG_4_STATIC_ENABLE
;
1189 if (fwnode_property_present(ch_node
, "azoteq,static-enable"))
1190 *(engine
+ 4) |= IQS626_CHx_ENG_4_STATIC_ENABLE
;
1192 i
= ch_id
- IQS626_CH_GEN_0
;
1193 assoc_select
= &sys_reg
->ch_reg_gen
[i
].assoc_select
;
1194 assoc_weight
= &sys_reg
->ch_reg_gen
[i
].assoc_weight
;
1197 if (!fwnode_property_present(ch_node
, "azoteq,assoc-select"))
1200 for (i
= 0; i
< ARRAY_SIZE(iqs626_channels
); i
++) {
1201 if (fwnode_property_match_string(ch_node
, "azoteq,assoc-select",
1202 iqs626_channels
[i
].name
) < 0)
1205 *assoc_select
|= iqs626_channels
[i
].active
;
1208 if (fwnode_property_read_u32(ch_node
, "azoteq,assoc-weight", &val
))
1211 if (val
> IQS626_GEN_WEIGHT_MAX
) {
1212 dev_err(&client
->dev
,
1213 "Invalid %s channel associated weight: %u\n",
1214 fwnode_get_name(ch_node
), val
);
1218 *assoc_weight
= val
;
1223 static int iqs626_parse_prop(struct iqs626_private
*iqs626
)
1225 struct iqs626_sys_reg
*sys_reg
= &iqs626
->sys_reg
;
1226 struct i2c_client
*client
= iqs626
->client
;
1231 if (!device_property_read_u32(&client
->dev
, "azoteq,suspend-mode",
1233 if (val
> IQS626_SYS_SETTINGS_PWR_MODE_MAX
) {
1234 dev_err(&client
->dev
, "Invalid suspend mode: %u\n",
1239 iqs626
->suspend_mode
= val
;
1242 error
= regmap_raw_read(iqs626
->regmap
, IQS626_SYS_SETTINGS
, sys_reg
,
1247 general
= be16_to_cpu(sys_reg
->general
);
1248 general
&= IQS626_SYS_SETTINGS_ULP_UPDATE_MASK
;
1250 if (device_property_present(&client
->dev
, "azoteq,clk-div"))
1251 general
|= IQS626_SYS_SETTINGS_CLK_DIV
;
1253 if (device_property_present(&client
->dev
, "azoteq,ulp-enable"))
1254 general
|= IQS626_SYS_SETTINGS_ULP_AUTO
;
1256 if (!device_property_read_u32(&client
->dev
, "azoteq,ulp-update",
1258 if (val
> IQS626_SYS_SETTINGS_ULP_UPDATE_MAX
) {
1259 dev_err(&client
->dev
, "Invalid update rate: %u\n", val
);
1263 general
&= ~IQS626_SYS_SETTINGS_ULP_UPDATE_MASK
;
1264 general
|= (val
<< IQS626_SYS_SETTINGS_ULP_UPDATE_SHIFT
);
1267 sys_reg
->misc_a
&= ~IQS626_MISC_A_ATI_BAND_DISABLE
;
1268 if (device_property_present(&client
->dev
, "azoteq,ati-band-disable"))
1269 sys_reg
->misc_a
|= IQS626_MISC_A_ATI_BAND_DISABLE
;
1271 sys_reg
->misc_a
&= ~IQS626_MISC_A_ATI_LP_ONLY
;
1272 if (device_property_present(&client
->dev
, "azoteq,ati-lp-only"))
1273 sys_reg
->misc_a
|= IQS626_MISC_A_ATI_LP_ONLY
;
1275 if (!device_property_read_u32(&client
->dev
, "azoteq,gpio3-select",
1277 if (val
> IQS626_MISC_A_GPIO3_SELECT_MAX
) {
1278 dev_err(&client
->dev
, "Invalid GPIO3 selection: %u\n",
1283 sys_reg
->misc_a
&= ~IQS626_MISC_A_GPIO3_SELECT_MASK
;
1284 sys_reg
->misc_a
|= val
;
1287 if (!device_property_read_u32(&client
->dev
, "azoteq,reseed-select",
1289 if (val
> IQS626_MISC_B_RESEED_UI_SEL_MAX
) {
1290 dev_err(&client
->dev
, "Invalid reseed selection: %u\n",
1295 sys_reg
->misc_b
&= ~IQS626_MISC_B_RESEED_UI_SEL_MASK
;
1296 sys_reg
->misc_b
|= (val
<< IQS626_MISC_B_RESEED_UI_SEL_SHIFT
);
1299 sys_reg
->misc_b
&= ~IQS626_MISC_B_THRESH_EXTEND
;
1300 if (device_property_present(&client
->dev
, "azoteq,thresh-extend"))
1301 sys_reg
->misc_b
|= IQS626_MISC_B_THRESH_EXTEND
;
1303 sys_reg
->misc_b
&= ~IQS626_MISC_B_TRACKING_UI_ENABLE
;
1304 if (device_property_present(&client
->dev
, "azoteq,tracking-enable"))
1305 sys_reg
->misc_b
|= IQS626_MISC_B_TRACKING_UI_ENABLE
;
1307 sys_reg
->misc_b
&= ~IQS626_MISC_B_RESEED_OFFSET
;
1308 if (device_property_present(&client
->dev
, "azoteq,reseed-offset"))
1309 sys_reg
->misc_b
|= IQS626_MISC_B_RESEED_OFFSET
;
1311 if (!device_property_read_u32(&client
->dev
, "azoteq,rate-np-ms",
1313 if (val
> IQS626_RATE_NP_MS_MAX
) {
1314 dev_err(&client
->dev
, "Invalid report rate: %u\n", val
);
1318 sys_reg
->rate_np
= val
;
1321 if (!device_property_read_u32(&client
->dev
, "azoteq,rate-lp-ms",
1323 if (val
> IQS626_RATE_LP_MS_MAX
) {
1324 dev_err(&client
->dev
, "Invalid report rate: %u\n", val
);
1328 sys_reg
->rate_lp
= val
;
1331 if (!device_property_read_u32(&client
->dev
, "azoteq,rate-ulp-ms",
1333 if (val
> IQS626_RATE_ULP_MS_MAX
) {
1334 dev_err(&client
->dev
, "Invalid report rate: %u\n", val
);
1338 sys_reg
->rate_ulp
= val
/ 16;
1341 if (!device_property_read_u32(&client
->dev
, "azoteq,timeout-pwr-ms",
1343 if (val
> IQS626_TIMEOUT_PWR_MS_MAX
) {
1344 dev_err(&client
->dev
, "Invalid timeout: %u\n", val
);
1348 sys_reg
->timeout_pwr
= val
/ 512;
1351 if (!device_property_read_u32(&client
->dev
, "azoteq,timeout-lta-ms",
1353 if (val
> IQS626_TIMEOUT_LTA_MS_MAX
) {
1354 dev_err(&client
->dev
, "Invalid timeout: %u\n", val
);
1358 sys_reg
->timeout_lta
= val
/ 512;
1361 sys_reg
->event_mask
= ~((u8
)IQS626_EVENT_MASK_SYS
);
1362 sys_reg
->redo_ati
= 0;
1364 sys_reg
->reseed
= 0;
1365 sys_reg
->active
= 0;
1367 for (i
= 0; i
< ARRAY_SIZE(iqs626_channels
); i
++) {
1368 struct fwnode_handle
*ch_node
__free(fwnode_handle
) =
1369 device_get_named_child_node(&client
->dev
,
1370 iqs626_channels
[i
].name
);
1374 error
= iqs626_parse_channel(iqs626
, ch_node
, i
);
1378 sys_reg
->active
|= iqs626_channels
[i
].active
;
1381 general
|= IQS626_SYS_SETTINGS_EVENT_MODE
;
1384 * Enable streaming during normal-power mode if the trackpad is used to
1385 * report raw coordinates instead of gestures. In that case, the device
1386 * returns to event mode during low-power mode.
1388 if (sys_reg
->active
& iqs626_channels
[IQS626_CH_TP_2
].active
&&
1389 sys_reg
->event_mask
& IQS626_EVENT_MASK_GESTURE
)
1390 general
|= IQS626_SYS_SETTINGS_EVENT_MODE_LP
;
1392 general
|= IQS626_SYS_SETTINGS_REDO_ATI
;
1393 general
|= IQS626_SYS_SETTINGS_ACK_RESET
;
1395 sys_reg
->general
= cpu_to_be16(general
);
1397 error
= regmap_raw_write(iqs626
->regmap
, IQS626_SYS_SETTINGS
,
1398 &iqs626
->sys_reg
, sizeof(iqs626
->sys_reg
));
1407 static int iqs626_input_init(struct iqs626_private
*iqs626
)
1409 struct iqs626_sys_reg
*sys_reg
= &iqs626
->sys_reg
;
1410 struct i2c_client
*client
= iqs626
->client
;
1413 iqs626
->keypad
= devm_input_allocate_device(&client
->dev
);
1414 if (!iqs626
->keypad
)
1417 iqs626
->keypad
->keycodemax
= ARRAY_SIZE(iqs626
->kp_code
);
1418 iqs626
->keypad
->keycode
= iqs626
->kp_code
;
1419 iqs626
->keypad
->keycodesize
= sizeof(**iqs626
->kp_code
);
1421 iqs626
->keypad
->name
= "iqs626a_keypad";
1422 iqs626
->keypad
->id
.bustype
= BUS_I2C
;
1424 for (i
= 0; i
< ARRAY_SIZE(iqs626_channels
); i
++) {
1425 if (!(sys_reg
->active
& iqs626_channels
[i
].active
))
1428 for (j
= 0; j
< ARRAY_SIZE(iqs626_events
); j
++) {
1429 if (!iqs626
->kp_type
[i
][j
])
1432 input_set_capability(iqs626
->keypad
,
1433 iqs626
->kp_type
[i
][j
],
1434 iqs626
->kp_code
[i
][j
]);
1438 if (!(sys_reg
->active
& iqs626_channels
[IQS626_CH_TP_2
].active
))
1441 iqs626
->trackpad
= devm_input_allocate_device(&client
->dev
);
1442 if (!iqs626
->trackpad
)
1445 iqs626
->trackpad
->keycodemax
= ARRAY_SIZE(iqs626
->tp_code
);
1446 iqs626
->trackpad
->keycode
= iqs626
->tp_code
;
1447 iqs626
->trackpad
->keycodesize
= sizeof(*iqs626
->tp_code
);
1449 iqs626
->trackpad
->name
= "iqs626a_trackpad";
1450 iqs626
->trackpad
->id
.bustype
= BUS_I2C
;
1453 * Present the trackpad as a traditional pointing device if no gestures
1454 * have been mapped to a keycode.
1456 if (sys_reg
->event_mask
& IQS626_EVENT_MASK_GESTURE
) {
1457 u8 tp_mask
= iqs626_channels
[IQS626_CH_TP_3
].active
;
1459 input_set_capability(iqs626
->trackpad
, EV_KEY
, BTN_TOUCH
);
1460 input_set_abs_params(iqs626
->trackpad
, ABS_Y
, 0, 255, 0, 0);
1462 if ((sys_reg
->active
& tp_mask
) == tp_mask
)
1463 input_set_abs_params(iqs626
->trackpad
,
1464 ABS_X
, 0, 255, 0, 0);
1466 input_set_abs_params(iqs626
->trackpad
,
1467 ABS_X
, 0, 128, 0, 0);
1469 touchscreen_parse_properties(iqs626
->trackpad
, false,
1472 for (i
= 0; i
< IQS626_NUM_GESTURES
; i
++)
1473 if (iqs626
->tp_code
[i
] != KEY_RESERVED
)
1474 input_set_capability(iqs626
->trackpad
, EV_KEY
,
1475 iqs626
->tp_code
[i
]);
1478 error
= input_register_device(iqs626
->trackpad
);
1480 dev_err(&client
->dev
, "Failed to register trackpad: %d\n",
1486 static int iqs626_report(struct iqs626_private
*iqs626
)
1488 struct iqs626_sys_reg
*sys_reg
= &iqs626
->sys_reg
;
1489 struct i2c_client
*client
= iqs626
->client
;
1490 struct iqs626_flags flags
;
1494 u8
*dir_mask
= &flags
.states
[IQS626_ST_OFFS_DIR
];
1496 error
= regmap_raw_read(iqs626
->regmap
, IQS626_SYS_FLAGS
, &flags
,
1499 dev_err(&client
->dev
, "Failed to read device status: %d\n",
1505 * The device resets itself if its own watchdog bites, which can happen
1506 * in the event of an I2C communication error. In this case, the device
1507 * asserts a SHOW_RESET interrupt and all registers must be restored.
1509 if (be16_to_cpu(flags
.system
) & IQS626_SYS_FLAGS_SHOW_RESET
) {
1510 dev_err(&client
->dev
, "Unexpected device reset\n");
1512 error
= regmap_raw_write(iqs626
->regmap
, IQS626_SYS_SETTINGS
,
1513 sys_reg
, sizeof(*sys_reg
));
1515 dev_err(&client
->dev
,
1516 "Failed to re-initialize device: %d\n", error
);
1521 if (be16_to_cpu(flags
.system
) & IQS626_SYS_FLAGS_IN_ATI
)
1525 * Unlike the ULP or generic channels, the Hall channel does not have a
1526 * direction flag. Instead, the direction (i.e. magnet polarity) can be
1527 * derived based on the sign of the 2's complement differential output.
1529 if (sys_reg
->active
& iqs626_channels
[IQS626_CH_HALL
].active
) {
1530 error
= regmap_raw_read(iqs626
->regmap
, IQS626_HALL_OUTPUT
,
1531 &hall_output
, sizeof(hall_output
));
1533 dev_err(&client
->dev
,
1534 "Failed to read Hall output: %d\n", error
);
1538 *dir_mask
&= ~iqs626_channels
[IQS626_CH_HALL
].active
;
1539 if (le16_to_cpu(hall_output
) < 0x8000)
1540 *dir_mask
|= iqs626_channels
[IQS626_CH_HALL
].active
;
1543 for (i
= 0; i
< ARRAY_SIZE(iqs626_channels
); i
++) {
1544 if (!(sys_reg
->active
& iqs626_channels
[i
].active
))
1547 for (j
= 0; j
< ARRAY_SIZE(iqs626_events
); j
++) {
1548 if (!iqs626
->kp_type
[i
][j
])
1551 state
= flags
.states
[iqs626_events
[j
].st_offs
];
1552 state
&= iqs626_events
[j
].dir_up
? *dir_mask
1554 state
&= iqs626_channels
[i
].active
;
1556 input_event(iqs626
->keypad
, iqs626
->kp_type
[i
][j
],
1557 iqs626
->kp_code
[i
][j
], !!state
);
1561 input_sync(iqs626
->keypad
);
1564 * The following completion signals that ATI has finished, any initial
1565 * switch states have been reported and the keypad can be registered.
1567 complete_all(&iqs626
->ati_done
);
1569 if (!(sys_reg
->active
& iqs626_channels
[IQS626_CH_TP_2
].active
))
1572 if (sys_reg
->event_mask
& IQS626_EVENT_MASK_GESTURE
) {
1573 state
= flags
.states
[IQS626_ST_OFFS_TOUCH
];
1574 state
&= iqs626_channels
[IQS626_CH_TP_2
].active
;
1576 input_report_key(iqs626
->trackpad
, BTN_TOUCH
, state
);
1579 touchscreen_report_pos(iqs626
->trackpad
, &iqs626
->prop
,
1581 flags
.trackpad_y
, false);
1583 for (i
= 0; i
< IQS626_NUM_GESTURES
; i
++)
1584 input_report_key(iqs626
->trackpad
, iqs626
->tp_code
[i
],
1585 flags
.gesture
& BIT(i
));
1587 if (flags
.gesture
& GENMASK(IQS626_GESTURE_TAP
, 0)) {
1588 input_sync(iqs626
->trackpad
);
1591 * Momentary gestures are followed by a complementary
1592 * release cycle so as to emulate a full keystroke.
1594 for (i
= 0; i
< IQS626_GESTURE_HOLD
; i
++)
1595 input_report_key(iqs626
->trackpad
,
1596 iqs626
->tp_code
[i
], 0);
1600 input_sync(iqs626
->trackpad
);
1605 static irqreturn_t
iqs626_irq(int irq
, void *context
)
1607 struct iqs626_private
*iqs626
= context
;
1609 if (iqs626_report(iqs626
))
1613 * The device does not deassert its interrupt (RDY) pin until shortly
1614 * after receiving an I2C stop condition; the following delay ensures
1615 * the interrupt handler does not return before this time.
1622 static const struct regmap_config iqs626_regmap_config
= {
1625 .max_register
= IQS626_MAX_REG
,
1628 static int iqs626_probe(struct i2c_client
*client
)
1630 struct iqs626_ver_info ver_info
;
1631 struct iqs626_private
*iqs626
;
1634 iqs626
= devm_kzalloc(&client
->dev
, sizeof(*iqs626
), GFP_KERNEL
);
1638 i2c_set_clientdata(client
, iqs626
);
1639 iqs626
->client
= client
;
1641 iqs626
->regmap
= devm_regmap_init_i2c(client
, &iqs626_regmap_config
);
1642 if (IS_ERR(iqs626
->regmap
)) {
1643 error
= PTR_ERR(iqs626
->regmap
);
1644 dev_err(&client
->dev
, "Failed to initialize register map: %d\n",
1649 init_completion(&iqs626
->ati_done
);
1651 error
= regmap_raw_read(iqs626
->regmap
, IQS626_VER_INFO
, &ver_info
,
1656 if (ver_info
.prod_num
!= IQS626_VER_INFO_PROD_NUM
) {
1657 dev_err(&client
->dev
, "Unrecognized product number: 0x%02X\n",
1662 error
= iqs626_parse_prop(iqs626
);
1666 error
= iqs626_input_init(iqs626
);
1670 error
= devm_request_threaded_irq(&client
->dev
, client
->irq
,
1671 NULL
, iqs626_irq
, IRQF_ONESHOT
,
1672 client
->name
, iqs626
);
1674 dev_err(&client
->dev
, "Failed to request IRQ: %d\n", error
);
1678 if (!wait_for_completion_timeout(&iqs626
->ati_done
,
1679 msecs_to_jiffies(2000))) {
1680 dev_err(&client
->dev
, "Failed to complete ATI\n");
1685 * The keypad may include one or more switches and is not registered
1686 * until ATI is complete and the initial switch states are read.
1688 error
= input_register_device(iqs626
->keypad
);
1690 dev_err(&client
->dev
, "Failed to register keypad: %d\n", error
);
1695 static int iqs626_suspend(struct device
*dev
)
1697 struct iqs626_private
*iqs626
= dev_get_drvdata(dev
);
1698 struct i2c_client
*client
= iqs626
->client
;
1702 if (!iqs626
->suspend_mode
)
1705 disable_irq(client
->irq
);
1708 * Automatic power mode switching must be disabled before the device is
1709 * forced into any particular power mode. In this case, the device will
1710 * transition into normal-power mode.
1712 error
= regmap_update_bits(iqs626
->regmap
, IQS626_SYS_SETTINGS
,
1713 IQS626_SYS_SETTINGS_DIS_AUTO
, ~0);
1718 * The following check ensures the device has completed its transition
1719 * into normal-power mode before a manual mode switch is performed.
1721 error
= regmap_read_poll_timeout(iqs626
->regmap
, IQS626_SYS_FLAGS
, val
,
1722 !(val
& IQS626_SYS_FLAGS_PWR_MODE_MASK
),
1723 IQS626_PWR_MODE_POLL_SLEEP_US
,
1724 IQS626_PWR_MODE_POLL_TIMEOUT_US
);
1728 error
= regmap_update_bits(iqs626
->regmap
, IQS626_SYS_SETTINGS
,
1729 IQS626_SYS_SETTINGS_PWR_MODE_MASK
,
1730 iqs626
->suspend_mode
<<
1731 IQS626_SYS_SETTINGS_PWR_MODE_SHIFT
);
1736 * This last check ensures the device has completed its transition into
1737 * the desired power mode to prevent any spurious interrupts from being
1738 * triggered after iqs626_suspend has already returned.
1740 error
= regmap_read_poll_timeout(iqs626
->regmap
, IQS626_SYS_FLAGS
, val
,
1741 (val
& IQS626_SYS_FLAGS_PWR_MODE_MASK
)
1742 == (iqs626
->suspend_mode
<<
1743 IQS626_SYS_FLAGS_PWR_MODE_SHIFT
),
1744 IQS626_PWR_MODE_POLL_SLEEP_US
,
1745 IQS626_PWR_MODE_POLL_TIMEOUT_US
);
1749 enable_irq(client
->irq
);
1754 static int iqs626_resume(struct device
*dev
)
1756 struct iqs626_private
*iqs626
= dev_get_drvdata(dev
);
1757 struct i2c_client
*client
= iqs626
->client
;
1761 if (!iqs626
->suspend_mode
)
1764 disable_irq(client
->irq
);
1766 error
= regmap_update_bits(iqs626
->regmap
, IQS626_SYS_SETTINGS
,
1767 IQS626_SYS_SETTINGS_PWR_MODE_MASK
, 0);
1772 * This check ensures the device has returned to normal-power mode
1773 * before automatic power mode switching is re-enabled.
1775 error
= regmap_read_poll_timeout(iqs626
->regmap
, IQS626_SYS_FLAGS
, val
,
1776 !(val
& IQS626_SYS_FLAGS_PWR_MODE_MASK
),
1777 IQS626_PWR_MODE_POLL_SLEEP_US
,
1778 IQS626_PWR_MODE_POLL_TIMEOUT_US
);
1782 error
= regmap_update_bits(iqs626
->regmap
, IQS626_SYS_SETTINGS
,
1783 IQS626_SYS_SETTINGS_DIS_AUTO
, 0);
1788 * This step reports any events that may have been "swallowed" as a
1789 * result of polling PWR_MODE (which automatically acknowledges any
1790 * pending interrupts).
1792 error
= iqs626_report(iqs626
);
1796 enable_irq(client
->irq
);
1801 static DEFINE_SIMPLE_DEV_PM_OPS(iqs626_pm
, iqs626_suspend
, iqs626_resume
);
1803 static const struct of_device_id iqs626_of_match
[] = {
1804 { .compatible
= "azoteq,iqs626a" },
1807 MODULE_DEVICE_TABLE(of
, iqs626_of_match
);
1809 static struct i2c_driver iqs626_i2c_driver
= {
1812 .of_match_table
= iqs626_of_match
,
1813 .pm
= pm_sleep_ptr(&iqs626_pm
),
1815 .probe
= iqs626_probe
,
1817 module_i2c_driver(iqs626_i2c_driver
);
1819 MODULE_AUTHOR("Jeff LaBundy <jeff@labundy.com>");
1820 MODULE_DESCRIPTION("Azoteq IQS626A Capacitive Touch Controller");
1821 MODULE_LICENSE("GPL");