1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Azoteq IQS7222A/B/C/D Capacitive Touch Controller
5 * Copyright (C) 2022 Jeff LaBundy <jeff@labundy.com>
8 #include <linux/bits.h>
9 #include <linux/delay.h>
10 #include <linux/device.h>
11 #include <linux/err.h>
12 #include <linux/gpio/consumer.h>
13 #include <linux/i2c.h>
14 #include <linux/input.h>
15 #include <linux/input/touchscreen.h>
16 #include <linux/interrupt.h>
17 #include <linux/kernel.h>
18 #include <linux/ktime.h>
19 #include <linux/mod_devicetable.h>
20 #include <linux/module.h>
21 #include <linux/property.h>
22 #include <linux/slab.h>
23 #include <linux/unaligned.h>
25 #define IQS7222_PROD_NUM 0x00
26 #define IQS7222_PROD_NUM_A 840
27 #define IQS7222_PROD_NUM_B 698
28 #define IQS7222_PROD_NUM_C 863
29 #define IQS7222_PROD_NUM_D 1046
31 #define IQS7222_SYS_STATUS 0x10
32 #define IQS7222_SYS_STATUS_RESET BIT(3)
33 #define IQS7222_SYS_STATUS_ATI_ERROR BIT(1)
34 #define IQS7222_SYS_STATUS_ATI_ACTIVE BIT(0)
36 #define IQS7222_CHAN_SETUP_0_REF_MODE_MASK GENMASK(15, 14)
37 #define IQS7222_CHAN_SETUP_0_REF_MODE_FOLLOW BIT(15)
38 #define IQS7222_CHAN_SETUP_0_REF_MODE_REF BIT(14)
39 #define IQS7222_CHAN_SETUP_0_CHAN_EN BIT(8)
41 #define IQS7222_SLDR_SETUP_0_CHAN_CNT_MASK GENMASK(2, 0)
42 #define IQS7222_SLDR_SETUP_2_RES_MASK GENMASK(15, 8)
43 #define IQS7222_SLDR_SETUP_2_RES_SHIFT 8
44 #define IQS7222_SLDR_SETUP_2_TOP_SPEED_MASK GENMASK(7, 0)
46 #define IQS7222_GPIO_SETUP_0_GPIO_EN BIT(0)
48 #define IQS7222_SYS_SETUP 0xD0
49 #define IQS7222_SYS_SETUP_INTF_MODE_MASK GENMASK(7, 6)
50 #define IQS7222_SYS_SETUP_INTF_MODE_TOUCH BIT(7)
51 #define IQS7222_SYS_SETUP_INTF_MODE_EVENT BIT(6)
52 #define IQS7222_SYS_SETUP_PWR_MODE_MASK GENMASK(5, 4)
53 #define IQS7222_SYS_SETUP_PWR_MODE_AUTO IQS7222_SYS_SETUP_PWR_MODE_MASK
54 #define IQS7222_SYS_SETUP_REDO_ATI BIT(2)
55 #define IQS7222_SYS_SETUP_ACK_RESET BIT(0)
57 #define IQS7222_EVENT_MASK_ATI BIT(12)
58 #define IQS7222_EVENT_MASK_SLDR BIT(10)
59 #define IQS7222_EVENT_MASK_TPAD IQS7222_EVENT_MASK_SLDR
60 #define IQS7222_EVENT_MASK_TOUCH BIT(1)
61 #define IQS7222_EVENT_MASK_PROX BIT(0)
63 #define IQS7222_COMMS_HOLD BIT(0)
64 #define IQS7222_COMMS_ERROR 0xEEEE
65 #define IQS7222_COMMS_RETRY_MS 50
66 #define IQS7222_COMMS_TIMEOUT_MS 100
67 #define IQS7222_RESET_TIMEOUT_MS 250
68 #define IQS7222_ATI_TIMEOUT_MS 2000
70 #define IQS7222_MAX_COLS_STAT 8
71 #define IQS7222_MAX_COLS_CYCLE 3
72 #define IQS7222_MAX_COLS_GLBL 3
73 #define IQS7222_MAX_COLS_BTN 3
74 #define IQS7222_MAX_COLS_CHAN 6
75 #define IQS7222_MAX_COLS_FILT 2
76 #define IQS7222_MAX_COLS_SLDR 11
77 #define IQS7222_MAX_COLS_TPAD 24
78 #define IQS7222_MAX_COLS_GPIO 3
79 #define IQS7222_MAX_COLS_SYS 13
81 #define IQS7222_MAX_CHAN 20
82 #define IQS7222_MAX_SLDR 2
84 #define IQS7222_NUM_RETRIES 5
85 #define IQS7222_REG_OFFSET 0x100
87 enum iqs7222_reg_key_id
{
90 IQS7222_REG_KEY_TOUCH
,
91 IQS7222_REG_KEY_DEBOUNCE
,
93 IQS7222_REG_KEY_TAP_LEGACY
,
94 IQS7222_REG_KEY_AXIAL
,
95 IQS7222_REG_KEY_AXIAL_LEGACY
,
96 IQS7222_REG_KEY_WHEEL
,
97 IQS7222_REG_KEY_NO_WHEEL
,
98 IQS7222_REG_KEY_RESERVED
101 enum iqs7222_reg_grp_id
{
102 IQS7222_REG_GRP_STAT
,
103 IQS7222_REG_GRP_FILT
,
104 IQS7222_REG_GRP_CYCLE
,
105 IQS7222_REG_GRP_GLBL
,
107 IQS7222_REG_GRP_CHAN
,
108 IQS7222_REG_GRP_SLDR
,
109 IQS7222_REG_GRP_TPAD
,
110 IQS7222_REG_GRP_GPIO
,
115 static const char * const iqs7222_reg_grp_names
[IQS7222_NUM_REG_GRPS
] = {
116 [IQS7222_REG_GRP_CYCLE
] = "cycle-%d",
117 [IQS7222_REG_GRP_CHAN
] = "channel-%d",
118 [IQS7222_REG_GRP_SLDR
] = "slider-%d",
119 [IQS7222_REG_GRP_TPAD
] = "trackpad",
120 [IQS7222_REG_GRP_GPIO
] = "gpio-%d",
123 static const unsigned int iqs7222_max_cols
[IQS7222_NUM_REG_GRPS
] = {
124 [IQS7222_REG_GRP_STAT
] = IQS7222_MAX_COLS_STAT
,
125 [IQS7222_REG_GRP_CYCLE
] = IQS7222_MAX_COLS_CYCLE
,
126 [IQS7222_REG_GRP_GLBL
] = IQS7222_MAX_COLS_GLBL
,
127 [IQS7222_REG_GRP_BTN
] = IQS7222_MAX_COLS_BTN
,
128 [IQS7222_REG_GRP_CHAN
] = IQS7222_MAX_COLS_CHAN
,
129 [IQS7222_REG_GRP_FILT
] = IQS7222_MAX_COLS_FILT
,
130 [IQS7222_REG_GRP_SLDR
] = IQS7222_MAX_COLS_SLDR
,
131 [IQS7222_REG_GRP_TPAD
] = IQS7222_MAX_COLS_TPAD
,
132 [IQS7222_REG_GRP_GPIO
] = IQS7222_MAX_COLS_GPIO
,
133 [IQS7222_REG_GRP_SYS
] = IQS7222_MAX_COLS_SYS
,
136 static const unsigned int iqs7222_gpio_links
[] = { 2, 5, 6, };
138 struct iqs7222_event_desc
{
145 enum iqs7222_reg_key_id reg_key
;
148 static const struct iqs7222_event_desc iqs7222_kp_events
[] = {
150 .name
= "event-prox",
151 .enable
= IQS7222_EVENT_MASK_PROX
,
152 .reg_key
= IQS7222_REG_KEY_PROX
,
155 .name
= "event-touch",
156 .enable
= IQS7222_EVENT_MASK_TOUCH
,
157 .reg_key
= IQS7222_REG_KEY_TOUCH
,
161 static const struct iqs7222_event_desc iqs7222_sl_events
[] = {
162 { .name
= "event-press", },
168 .reg_key
= IQS7222_REG_KEY_TAP
,
171 .name
= "event-swipe-pos",
172 .mask
= BIT(5) | BIT(1),
175 .reg_key
= IQS7222_REG_KEY_AXIAL
,
178 .name
= "event-swipe-neg",
179 .mask
= BIT(5) | BIT(1),
180 .val
= BIT(5) | BIT(1),
182 .reg_key
= IQS7222_REG_KEY_AXIAL
,
185 .name
= "event-flick-pos",
186 .mask
= BIT(5) | BIT(2),
189 .reg_key
= IQS7222_REG_KEY_AXIAL
,
192 .name
= "event-flick-neg",
193 .mask
= BIT(5) | BIT(2),
194 .val
= BIT(5) | BIT(2),
196 .reg_key
= IQS7222_REG_KEY_AXIAL
,
200 static const struct iqs7222_event_desc iqs7222_tp_events
[] = {
202 .name
= "event-press",
211 .reg_key
= IQS7222_REG_KEY_TAP
,
214 .name
= "event-swipe-x-pos",
216 .mask
= BIT(2) | BIT(1),
220 .reg_key
= IQS7222_REG_KEY_AXIAL
,
223 .name
= "event-swipe-y-pos",
225 .mask
= BIT(3) | BIT(1),
229 .reg_key
= IQS7222_REG_KEY_AXIAL
,
232 .name
= "event-swipe-x-neg",
234 .mask
= BIT(4) | BIT(1),
238 .reg_key
= IQS7222_REG_KEY_AXIAL
,
241 .name
= "event-swipe-y-neg",
243 .mask
= BIT(5) | BIT(1),
247 .reg_key
= IQS7222_REG_KEY_AXIAL
,
250 .name
= "event-flick-x-pos",
252 .mask
= BIT(2) | BIT(1),
253 .val
= BIT(2) | BIT(1),
256 .reg_key
= IQS7222_REG_KEY_AXIAL
,
259 .name
= "event-flick-y-pos",
261 .mask
= BIT(3) | BIT(1),
262 .val
= BIT(3) | BIT(1),
265 .reg_key
= IQS7222_REG_KEY_AXIAL
,
268 .name
= "event-flick-x-neg",
270 .mask
= BIT(4) | BIT(1),
271 .val
= BIT(4) | BIT(1),
274 .reg_key
= IQS7222_REG_KEY_AXIAL
,
277 .name
= "event-flick-y-neg",
279 .mask
= BIT(5) | BIT(1),
280 .val
= BIT(5) | BIT(1),
283 .reg_key
= IQS7222_REG_KEY_AXIAL
,
287 struct iqs7222_reg_grp_desc
{
293 struct iqs7222_dev_desc
{
304 struct iqs7222_reg_grp_desc reg_grps
[IQS7222_NUM_REG_GRPS
];
307 static const struct iqs7222_dev_desc iqs7222_devs
[] = {
309 .prod_num
= IQS7222_PROD_NUM_A
,
312 .sldr_res
= U8_MAX
* 16,
318 [IQS7222_REG_GRP_STAT
] = {
319 .base
= IQS7222_SYS_STATUS
,
323 [IQS7222_REG_GRP_CYCLE
] = {
328 [IQS7222_REG_GRP_GLBL
] = {
333 [IQS7222_REG_GRP_BTN
] = {
338 [IQS7222_REG_GRP_CHAN
] = {
343 [IQS7222_REG_GRP_FILT
] = {
348 [IQS7222_REG_GRP_SLDR
] = {
353 [IQS7222_REG_GRP_GPIO
] = {
358 [IQS7222_REG_GRP_SYS
] = {
359 .base
= IQS7222_SYS_SETUP
,
366 .prod_num
= IQS7222_PROD_NUM_A
,
369 .sldr_res
= U8_MAX
* 16,
374 .legacy_gesture
= true,
376 [IQS7222_REG_GRP_STAT
] = {
377 .base
= IQS7222_SYS_STATUS
,
381 [IQS7222_REG_GRP_CYCLE
] = {
386 [IQS7222_REG_GRP_GLBL
] = {
391 [IQS7222_REG_GRP_BTN
] = {
396 [IQS7222_REG_GRP_CHAN
] = {
401 [IQS7222_REG_GRP_FILT
] = {
406 [IQS7222_REG_GRP_SLDR
] = {
411 [IQS7222_REG_GRP_GPIO
] = {
416 [IQS7222_REG_GRP_SYS
] = {
417 .base
= IQS7222_SYS_SETUP
,
424 .prod_num
= IQS7222_PROD_NUM_B
,
430 [IQS7222_REG_GRP_STAT
] = {
431 .base
= IQS7222_SYS_STATUS
,
435 [IQS7222_REG_GRP_CYCLE
] = {
440 [IQS7222_REG_GRP_GLBL
] = {
445 [IQS7222_REG_GRP_BTN
] = {
450 [IQS7222_REG_GRP_CHAN
] = {
455 [IQS7222_REG_GRP_FILT
] = {
460 [IQS7222_REG_GRP_SYS
] = {
461 .base
= IQS7222_SYS_SETUP
,
468 .prod_num
= IQS7222_PROD_NUM_B
,
472 [IQS7222_REG_GRP_STAT
] = {
473 .base
= IQS7222_SYS_STATUS
,
477 [IQS7222_REG_GRP_CYCLE
] = {
482 [IQS7222_REG_GRP_GLBL
] = {
487 [IQS7222_REG_GRP_BTN
] = {
492 [IQS7222_REG_GRP_CHAN
] = {
497 [IQS7222_REG_GRP_FILT
] = {
502 [IQS7222_REG_GRP_SYS
] = {
503 .base
= IQS7222_SYS_SETUP
,
510 .prod_num
= IQS7222_PROD_NUM_C
,
515 .wheel_enable
= BIT(3),
519 [IQS7222_REG_GRP_STAT
] = {
520 .base
= IQS7222_SYS_STATUS
,
524 [IQS7222_REG_GRP_CYCLE
] = {
529 [IQS7222_REG_GRP_GLBL
] = {
534 [IQS7222_REG_GRP_BTN
] = {
539 [IQS7222_REG_GRP_CHAN
] = {
544 [IQS7222_REG_GRP_FILT
] = {
549 [IQS7222_REG_GRP_SLDR
] = {
554 [IQS7222_REG_GRP_GPIO
] = {
559 [IQS7222_REG_GRP_SYS
] = {
560 .base
= IQS7222_SYS_SETUP
,
567 .prod_num
= IQS7222_PROD_NUM_C
,
572 .wheel_enable
= BIT(3),
576 [IQS7222_REG_GRP_STAT
] = {
577 .base
= IQS7222_SYS_STATUS
,
581 [IQS7222_REG_GRP_CYCLE
] = {
586 [IQS7222_REG_GRP_GLBL
] = {
591 [IQS7222_REG_GRP_BTN
] = {
596 [IQS7222_REG_GRP_CHAN
] = {
601 [IQS7222_REG_GRP_FILT
] = {
606 [IQS7222_REG_GRP_SLDR
] = {
611 [IQS7222_REG_GRP_GPIO
] = {
616 [IQS7222_REG_GRP_SYS
] = {
617 .base
= IQS7222_SYS_SETUP
,
624 .prod_num
= IQS7222_PROD_NUM_D
,
632 [IQS7222_REG_GRP_STAT
] = {
633 .base
= IQS7222_SYS_STATUS
,
637 [IQS7222_REG_GRP_CYCLE
] = {
642 [IQS7222_REG_GRP_GLBL
] = {
647 [IQS7222_REG_GRP_BTN
] = {
652 [IQS7222_REG_GRP_CHAN
] = {
657 [IQS7222_REG_GRP_FILT
] = {
662 [IQS7222_REG_GRP_TPAD
] = {
667 [IQS7222_REG_GRP_GPIO
] = {
672 [IQS7222_REG_GRP_SYS
] = {
673 .base
= IQS7222_SYS_SETUP
,
680 .prod_num
= IQS7222_PROD_NUM_D
,
688 [IQS7222_REG_GRP_STAT
] = {
689 .base
= IQS7222_SYS_STATUS
,
693 [IQS7222_REG_GRP_CYCLE
] = {
698 [IQS7222_REG_GRP_GLBL
] = {
703 [IQS7222_REG_GRP_BTN
] = {
708 [IQS7222_REG_GRP_CHAN
] = {
713 [IQS7222_REG_GRP_FILT
] = {
718 [IQS7222_REG_GRP_TPAD
] = {
723 [IQS7222_REG_GRP_GPIO
] = {
728 [IQS7222_REG_GRP_SYS
] = {
729 .base
= IQS7222_SYS_SETUP
,
736 .prod_num
= IQS7222_PROD_NUM_D
,
744 [IQS7222_REG_GRP_STAT
] = {
745 .base
= IQS7222_SYS_STATUS
,
749 [IQS7222_REG_GRP_CYCLE
] = {
754 [IQS7222_REG_GRP_GLBL
] = {
759 [IQS7222_REG_GRP_BTN
] = {
764 [IQS7222_REG_GRP_CHAN
] = {
769 [IQS7222_REG_GRP_FILT
] = {
774 [IQS7222_REG_GRP_TPAD
] = {
779 [IQS7222_REG_GRP_GPIO
] = {
784 [IQS7222_REG_GRP_SYS
] = {
785 .base
= IQS7222_SYS_SETUP
,
793 struct iqs7222_prop_desc
{
795 enum iqs7222_reg_grp_id reg_grp
;
796 enum iqs7222_reg_key_id reg_key
;
807 static const struct iqs7222_prop_desc iqs7222_props
[] = {
809 .name
= "azoteq,conv-period",
810 .reg_grp
= IQS7222_REG_GRP_CYCLE
,
814 .label
= "conversion period",
817 .name
= "azoteq,conv-frac",
818 .reg_grp
= IQS7222_REG_GRP_CYCLE
,
822 .label
= "conversion frequency fractional divider",
825 .name
= "azoteq,rx-float-inactive",
826 .reg_grp
= IQS7222_REG_GRP_CYCLE
,
833 .name
= "azoteq,dead-time-enable",
834 .reg_grp
= IQS7222_REG_GRP_CYCLE
,
840 .name
= "azoteq,tx-freq-fosc",
841 .reg_grp
= IQS7222_REG_GRP_CYCLE
,
847 .name
= "azoteq,vbias-enable",
848 .reg_grp
= IQS7222_REG_GRP_CYCLE
,
854 .name
= "azoteq,sense-mode",
855 .reg_grp
= IQS7222_REG_GRP_CYCLE
,
860 .label
= "sensing mode",
863 .name
= "azoteq,iref-enable",
864 .reg_grp
= IQS7222_REG_GRP_CYCLE
,
870 .name
= "azoteq,iref-level",
871 .reg_grp
= IQS7222_REG_GRP_CYCLE
,
875 .label
= "current reference level",
878 .name
= "azoteq,iref-trim",
879 .reg_grp
= IQS7222_REG_GRP_CYCLE
,
883 .label
= "current reference trim",
886 .name
= "azoteq,max-counts",
887 .reg_grp
= IQS7222_REG_GRP_GLBL
,
891 .label
= "maximum counts",
894 .name
= "azoteq,auto-mode",
895 .reg_grp
= IQS7222_REG_GRP_GLBL
,
899 .label
= "number of conversions",
902 .name
= "azoteq,ati-frac-div-fine",
903 .reg_grp
= IQS7222_REG_GRP_GLBL
,
907 .label
= "ATI fine fractional divider",
910 .name
= "azoteq,ati-frac-div-coarse",
911 .reg_grp
= IQS7222_REG_GRP_GLBL
,
915 .label
= "ATI coarse fractional divider",
918 .name
= "azoteq,ati-comp-select",
919 .reg_grp
= IQS7222_REG_GRP_GLBL
,
923 .label
= "ATI compensation selection",
926 .name
= "azoteq,ati-band",
927 .reg_grp
= IQS7222_REG_GRP_CHAN
,
934 .name
= "azoteq,global-halt",
935 .reg_grp
= IQS7222_REG_GRP_CHAN
,
941 .name
= "azoteq,invert-enable",
942 .reg_grp
= IQS7222_REG_GRP_CHAN
,
948 .name
= "azoteq,dual-direction",
949 .reg_grp
= IQS7222_REG_GRP_CHAN
,
955 .name
= "azoteq,samp-cap-double",
956 .reg_grp
= IQS7222_REG_GRP_CHAN
,
962 .name
= "azoteq,vref-half",
963 .reg_grp
= IQS7222_REG_GRP_CHAN
,
969 .name
= "azoteq,proj-bias",
970 .reg_grp
= IQS7222_REG_GRP_CHAN
,
974 .label
= "projected bias current",
977 .name
= "azoteq,ati-target",
978 .reg_grp
= IQS7222_REG_GRP_CHAN
,
983 .label
= "ATI target",
986 .name
= "azoteq,ati-base",
987 .reg_grp
= IQS7222_REG_GRP_CHAN
,
995 .name
= "azoteq,ati-mode",
996 .reg_grp
= IQS7222_REG_GRP_CHAN
,
1001 .label
= "ATI mode",
1004 .name
= "azoteq,ati-frac-div-fine",
1005 .reg_grp
= IQS7222_REG_GRP_CHAN
,
1009 .label
= "ATI fine fractional divider",
1012 .name
= "azoteq,ati-frac-mult-coarse",
1013 .reg_grp
= IQS7222_REG_GRP_CHAN
,
1017 .label
= "ATI coarse fractional multiplier",
1020 .name
= "azoteq,ati-frac-div-coarse",
1021 .reg_grp
= IQS7222_REG_GRP_CHAN
,
1025 .label
= "ATI coarse fractional divider",
1028 .name
= "azoteq,ati-comp-div",
1029 .reg_grp
= IQS7222_REG_GRP_CHAN
,
1033 .label
= "ATI compensation divider",
1036 .name
= "azoteq,ati-comp-select",
1037 .reg_grp
= IQS7222_REG_GRP_CHAN
,
1041 .label
= "ATI compensation selection",
1044 .name
= "azoteq,debounce-exit",
1045 .reg_grp
= IQS7222_REG_GRP_BTN
,
1046 .reg_key
= IQS7222_REG_KEY_DEBOUNCE
,
1050 .label
= "debounce exit factor",
1053 .name
= "azoteq,debounce-enter",
1054 .reg_grp
= IQS7222_REG_GRP_BTN
,
1055 .reg_key
= IQS7222_REG_KEY_DEBOUNCE
,
1059 .label
= "debounce entrance factor",
1062 .name
= "azoteq,thresh",
1063 .reg_grp
= IQS7222_REG_GRP_BTN
,
1064 .reg_key
= IQS7222_REG_KEY_PROX
,
1069 .label
= "threshold",
1072 .name
= "azoteq,thresh",
1073 .reg_grp
= IQS7222_REG_GRP_BTN
,
1074 .reg_key
= IQS7222_REG_KEY_TOUCH
,
1078 .label
= "threshold",
1081 .name
= "azoteq,hyst",
1082 .reg_grp
= IQS7222_REG_GRP_BTN
,
1083 .reg_key
= IQS7222_REG_KEY_TOUCH
,
1087 .label
= "hysteresis",
1090 .name
= "azoteq,lta-beta-lp",
1091 .reg_grp
= IQS7222_REG_GRP_FILT
,
1095 .label
= "low-power mode long-term average beta",
1098 .name
= "azoteq,lta-beta-np",
1099 .reg_grp
= IQS7222_REG_GRP_FILT
,
1103 .label
= "normal-power mode long-term average beta",
1106 .name
= "azoteq,counts-beta-lp",
1107 .reg_grp
= IQS7222_REG_GRP_FILT
,
1111 .label
= "low-power mode counts beta",
1114 .name
= "azoteq,counts-beta-np",
1115 .reg_grp
= IQS7222_REG_GRP_FILT
,
1119 .label
= "normal-power mode counts beta",
1122 .name
= "azoteq,lta-fast-beta-lp",
1123 .reg_grp
= IQS7222_REG_GRP_FILT
,
1127 .label
= "low-power mode long-term average fast beta",
1130 .name
= "azoteq,lta-fast-beta-np",
1131 .reg_grp
= IQS7222_REG_GRP_FILT
,
1135 .label
= "normal-power mode long-term average fast beta",
1138 .name
= "azoteq,lower-cal",
1139 .reg_grp
= IQS7222_REG_GRP_SLDR
,
1143 .label
= "lower calibration",
1146 .name
= "azoteq,static-beta",
1147 .reg_grp
= IQS7222_REG_GRP_SLDR
,
1148 .reg_key
= IQS7222_REG_KEY_NO_WHEEL
,
1154 .name
= "azoteq,bottom-beta",
1155 .reg_grp
= IQS7222_REG_GRP_SLDR
,
1156 .reg_key
= IQS7222_REG_KEY_NO_WHEEL
,
1160 .label
= "bottom beta",
1163 .name
= "azoteq,static-beta",
1164 .reg_grp
= IQS7222_REG_GRP_SLDR
,
1165 .reg_key
= IQS7222_REG_KEY_WHEEL
,
1171 .name
= "azoteq,bottom-beta",
1172 .reg_grp
= IQS7222_REG_GRP_SLDR
,
1173 .reg_key
= IQS7222_REG_KEY_WHEEL
,
1177 .label
= "bottom beta",
1180 .name
= "azoteq,bottom-speed",
1181 .reg_grp
= IQS7222_REG_GRP_SLDR
,
1185 .label
= "bottom speed",
1188 .name
= "azoteq,upper-cal",
1189 .reg_grp
= IQS7222_REG_GRP_SLDR
,
1193 .label
= "upper calibration",
1196 .name
= "azoteq,gesture-max-ms",
1197 .reg_grp
= IQS7222_REG_GRP_SLDR
,
1198 .reg_key
= IQS7222_REG_KEY_TAP
,
1203 .label
= "maximum gesture time",
1206 .name
= "azoteq,gesture-max-ms",
1207 .reg_grp
= IQS7222_REG_GRP_SLDR
,
1208 .reg_key
= IQS7222_REG_KEY_TAP_LEGACY
,
1213 .label
= "maximum gesture time",
1216 .name
= "azoteq,gesture-min-ms",
1217 .reg_grp
= IQS7222_REG_GRP_SLDR
,
1218 .reg_key
= IQS7222_REG_KEY_TAP
,
1223 .label
= "minimum gesture time",
1226 .name
= "azoteq,gesture-min-ms",
1227 .reg_grp
= IQS7222_REG_GRP_SLDR
,
1228 .reg_key
= IQS7222_REG_KEY_TAP_LEGACY
,
1233 .label
= "minimum gesture time",
1236 .name
= "azoteq,gesture-dist",
1237 .reg_grp
= IQS7222_REG_GRP_SLDR
,
1238 .reg_key
= IQS7222_REG_KEY_AXIAL
,
1243 .label
= "gesture distance",
1246 .name
= "azoteq,gesture-dist",
1247 .reg_grp
= IQS7222_REG_GRP_SLDR
,
1248 .reg_key
= IQS7222_REG_KEY_AXIAL_LEGACY
,
1253 .label
= "gesture distance",
1256 .name
= "azoteq,gesture-max-ms",
1257 .reg_grp
= IQS7222_REG_GRP_SLDR
,
1258 .reg_key
= IQS7222_REG_KEY_AXIAL
,
1263 .label
= "maximum gesture time",
1266 .name
= "azoteq,gesture-max-ms",
1267 .reg_grp
= IQS7222_REG_GRP_SLDR
,
1268 .reg_key
= IQS7222_REG_KEY_AXIAL_LEGACY
,
1273 .label
= "maximum gesture time",
1276 .name
= "azoteq,num-rows",
1277 .reg_grp
= IQS7222_REG_GRP_TPAD
,
1283 .label
= "number of rows",
1286 .name
= "azoteq,num-cols",
1287 .reg_grp
= IQS7222_REG_GRP_TPAD
,
1293 .label
= "number of columns",
1296 .name
= "azoteq,lower-cal-y",
1297 .reg_grp
= IQS7222_REG_GRP_TPAD
,
1301 .label
= "lower vertical calibration",
1304 .name
= "azoteq,lower-cal-x",
1305 .reg_grp
= IQS7222_REG_GRP_TPAD
,
1309 .label
= "lower horizontal calibration",
1312 .name
= "azoteq,upper-cal-y",
1313 .reg_grp
= IQS7222_REG_GRP_TPAD
,
1317 .label
= "upper vertical calibration",
1320 .name
= "azoteq,upper-cal-x",
1321 .reg_grp
= IQS7222_REG_GRP_TPAD
,
1325 .label
= "upper horizontal calibration",
1328 .name
= "azoteq,top-speed",
1329 .reg_grp
= IQS7222_REG_GRP_TPAD
,
1334 .label
= "top speed",
1337 .name
= "azoteq,bottom-speed",
1338 .reg_grp
= IQS7222_REG_GRP_TPAD
,
1342 .label
= "bottom speed",
1345 .name
= "azoteq,gesture-min-ms",
1346 .reg_grp
= IQS7222_REG_GRP_TPAD
,
1347 .reg_key
= IQS7222_REG_KEY_TAP
,
1352 .label
= "minimum gesture time",
1355 .name
= "azoteq,gesture-max-ms",
1356 .reg_grp
= IQS7222_REG_GRP_TPAD
,
1357 .reg_key
= IQS7222_REG_KEY_AXIAL
,
1362 .label
= "maximum gesture time",
1365 .name
= "azoteq,gesture-max-ms",
1366 .reg_grp
= IQS7222_REG_GRP_TPAD
,
1367 .reg_key
= IQS7222_REG_KEY_TAP
,
1372 .label
= "maximum gesture time",
1375 .name
= "azoteq,gesture-dist",
1376 .reg_grp
= IQS7222_REG_GRP_TPAD
,
1377 .reg_key
= IQS7222_REG_KEY_TAP
,
1381 .label
= "gesture distance",
1384 .name
= "azoteq,gesture-dist",
1385 .reg_grp
= IQS7222_REG_GRP_TPAD
,
1386 .reg_key
= IQS7222_REG_KEY_AXIAL
,
1390 .label
= "gesture distance",
1393 .name
= "drive-open-drain",
1394 .reg_grp
= IQS7222_REG_GRP_GPIO
,
1400 .name
= "azoteq,timeout-ati-ms",
1401 .reg_grp
= IQS7222_REG_GRP_SYS
,
1406 .label
= "ATI error timeout",
1409 .name
= "azoteq,rate-ati-ms",
1410 .reg_grp
= IQS7222_REG_GRP_SYS
,
1414 .label
= "ATI report rate",
1417 .name
= "azoteq,timeout-np-ms",
1418 .reg_grp
= IQS7222_REG_GRP_SYS
,
1422 .label
= "normal-power mode timeout",
1425 .name
= "azoteq,rate-np-ms",
1426 .reg_grp
= IQS7222_REG_GRP_SYS
,
1431 .label
= "normal-power mode report rate",
1434 .name
= "azoteq,timeout-lp-ms",
1435 .reg_grp
= IQS7222_REG_GRP_SYS
,
1439 .label
= "low-power mode timeout",
1442 .name
= "azoteq,rate-lp-ms",
1443 .reg_grp
= IQS7222_REG_GRP_SYS
,
1448 .label
= "low-power mode report rate",
1451 .name
= "azoteq,timeout-ulp-ms",
1452 .reg_grp
= IQS7222_REG_GRP_SYS
,
1456 .label
= "ultra-low-power mode timeout",
1459 .name
= "azoteq,rate-ulp-ms",
1460 .reg_grp
= IQS7222_REG_GRP_SYS
,
1465 .label
= "ultra-low-power mode report rate",
1469 struct iqs7222_private
{
1470 const struct iqs7222_dev_desc
*dev_desc
;
1471 struct gpio_desc
*reset_gpio
;
1472 struct gpio_desc
*irq_gpio
;
1473 struct i2c_client
*client
;
1474 struct input_dev
*keypad
;
1475 struct touchscreen_properties prop
;
1476 unsigned int kp_type
[IQS7222_MAX_CHAN
][ARRAY_SIZE(iqs7222_kp_events
)];
1477 unsigned int kp_code
[IQS7222_MAX_CHAN
][ARRAY_SIZE(iqs7222_kp_events
)];
1478 unsigned int sl_code
[IQS7222_MAX_SLDR
][ARRAY_SIZE(iqs7222_sl_events
)];
1479 unsigned int sl_axis
[IQS7222_MAX_SLDR
];
1480 unsigned int tp_code
[ARRAY_SIZE(iqs7222_tp_events
)];
1481 u16 cycle_setup
[IQS7222_MAX_CHAN
/ 2][IQS7222_MAX_COLS_CYCLE
];
1482 u16 glbl_setup
[IQS7222_MAX_COLS_GLBL
];
1483 u16 btn_setup
[IQS7222_MAX_CHAN
][IQS7222_MAX_COLS_BTN
];
1484 u16 chan_setup
[IQS7222_MAX_CHAN
][IQS7222_MAX_COLS_CHAN
];
1485 u16 filt_setup
[IQS7222_MAX_COLS_FILT
];
1486 u16 sldr_setup
[IQS7222_MAX_SLDR
][IQS7222_MAX_COLS_SLDR
];
1487 u16 tpad_setup
[IQS7222_MAX_COLS_TPAD
];
1488 u16 gpio_setup
[ARRAY_SIZE(iqs7222_gpio_links
)][IQS7222_MAX_COLS_GPIO
];
1489 u16 sys_setup
[IQS7222_MAX_COLS_SYS
];
1492 static u16
*iqs7222_setup(struct iqs7222_private
*iqs7222
,
1493 enum iqs7222_reg_grp_id reg_grp
, int row
)
1496 case IQS7222_REG_GRP_CYCLE
:
1497 return iqs7222
->cycle_setup
[row
];
1499 case IQS7222_REG_GRP_GLBL
:
1500 return iqs7222
->glbl_setup
;
1502 case IQS7222_REG_GRP_BTN
:
1503 return iqs7222
->btn_setup
[row
];
1505 case IQS7222_REG_GRP_CHAN
:
1506 return iqs7222
->chan_setup
[row
];
1508 case IQS7222_REG_GRP_FILT
:
1509 return iqs7222
->filt_setup
;
1511 case IQS7222_REG_GRP_SLDR
:
1512 return iqs7222
->sldr_setup
[row
];
1514 case IQS7222_REG_GRP_TPAD
:
1515 return iqs7222
->tpad_setup
;
1517 case IQS7222_REG_GRP_GPIO
:
1518 return iqs7222
->gpio_setup
[row
];
1520 case IQS7222_REG_GRP_SYS
:
1521 return iqs7222
->sys_setup
;
1528 static int iqs7222_irq_poll(struct iqs7222_private
*iqs7222
, u16 timeout_ms
)
1530 ktime_t irq_timeout
= ktime_add_ms(ktime_get(), timeout_ms
);
1534 usleep_range(1000, 1100);
1536 ret
= gpiod_get_value_cansleep(iqs7222
->irq_gpio
);
1541 } while (ktime_compare(ktime_get(), irq_timeout
) < 0);
1546 static int iqs7222_hard_reset(struct iqs7222_private
*iqs7222
)
1548 struct i2c_client
*client
= iqs7222
->client
;
1551 if (!iqs7222
->reset_gpio
)
1554 gpiod_set_value_cansleep(iqs7222
->reset_gpio
, 1);
1555 usleep_range(1000, 1100);
1557 gpiod_set_value_cansleep(iqs7222
->reset_gpio
, 0);
1559 error
= iqs7222_irq_poll(iqs7222
, IQS7222_RESET_TIMEOUT_MS
);
1561 dev_err(&client
->dev
, "Failed to reset device: %d\n", error
);
1566 static int iqs7222_force_comms(struct iqs7222_private
*iqs7222
)
1568 u8 msg_buf
[] = { 0xFF, };
1572 * The device cannot communicate until it asserts its interrupt (RDY)
1573 * pin. Attempts to do so while RDY is deasserted return an ACK; how-
1574 * ever all write data is ignored, and all read data returns 0xEE.
1576 * Unsolicited communication must be preceded by a special force com-
1577 * munication command, after which the device eventually asserts its
1578 * RDY pin and agrees to communicate.
1580 * Regardless of whether communication is forced or the result of an
1581 * interrupt, the device automatically deasserts its RDY pin once it
1582 * detects an I2C stop condition, or a timeout expires.
1584 ret
= gpiod_get_value_cansleep(iqs7222
->irq_gpio
);
1590 ret
= i2c_master_send(iqs7222
->client
, msg_buf
, sizeof(msg_buf
));
1591 if (ret
< (int)sizeof(msg_buf
)) {
1596 * The datasheet states that the host must wait to retry any
1597 * failed attempt to communicate over I2C.
1599 msleep(IQS7222_COMMS_RETRY_MS
);
1603 return iqs7222_irq_poll(iqs7222
, IQS7222_COMMS_TIMEOUT_MS
);
1606 static int iqs7222_read_burst(struct iqs7222_private
*iqs7222
,
1607 u16 reg
, void *val
, u16 num_val
)
1609 u8 reg_buf
[sizeof(__be16
)];
1611 struct i2c_client
*client
= iqs7222
->client
;
1612 struct i2c_msg msg
[] = {
1614 .addr
= client
->addr
,
1616 .len
= reg
> U8_MAX
? sizeof(reg
) : sizeof(u8
),
1620 .addr
= client
->addr
,
1622 .len
= num_val
* sizeof(__le16
),
1628 put_unaligned_be16(reg
, reg_buf
);
1633 * The following loop protects against an edge case in which the RDY
1634 * pin is automatically deasserted just as the read is initiated. In
1635 * that case, the read must be retried using forced communication.
1637 for (i
= 0; i
< IQS7222_NUM_RETRIES
; i
++) {
1638 ret
= iqs7222_force_comms(iqs7222
);
1642 ret
= i2c_transfer(client
->adapter
, msg
, ARRAY_SIZE(msg
));
1643 if (ret
< (int)ARRAY_SIZE(msg
)) {
1647 msleep(IQS7222_COMMS_RETRY_MS
);
1651 if (get_unaligned_le16(msg
[1].buf
) == IQS7222_COMMS_ERROR
) {
1661 * The following delay ensures the device has deasserted the RDY pin
1662 * following the I2C stop condition.
1664 usleep_range(50, 100);
1667 dev_err(&client
->dev
,
1668 "Failed to read from address 0x%04X: %d\n", reg
, ret
);
1673 static int iqs7222_read_word(struct iqs7222_private
*iqs7222
, u16 reg
, u16
*val
)
1678 error
= iqs7222_read_burst(iqs7222
, reg
, &val_buf
, 1);
1682 *val
= le16_to_cpu(val_buf
);
1687 static int iqs7222_write_burst(struct iqs7222_private
*iqs7222
,
1688 u16 reg
, const void *val
, u16 num_val
)
1690 int reg_len
= reg
> U8_MAX
? sizeof(reg
) : sizeof(u8
);
1691 int val_len
= num_val
* sizeof(__le16
);
1692 int msg_len
= reg_len
+ val_len
;
1694 struct i2c_client
*client
= iqs7222
->client
;
1697 msg_buf
= kzalloc(msg_len
, GFP_KERNEL
);
1702 put_unaligned_be16(reg
, msg_buf
);
1706 memcpy(msg_buf
+ reg_len
, val
, val_len
);
1709 * The following loop protects against an edge case in which the RDY
1710 * pin is automatically asserted just before the force communication
1713 * In that case, the subsequent I2C stop condition tricks the device
1714 * into preemptively deasserting the RDY pin and the command must be
1717 for (i
= 0; i
< IQS7222_NUM_RETRIES
; i
++) {
1718 ret
= iqs7222_force_comms(iqs7222
);
1722 ret
= i2c_master_send(client
, msg_buf
, msg_len
);
1723 if (ret
< msg_len
) {
1727 msleep(IQS7222_COMMS_RETRY_MS
);
1737 usleep_range(50, 100);
1740 dev_err(&client
->dev
,
1741 "Failed to write to address 0x%04X: %d\n", reg
, ret
);
1746 static int iqs7222_write_word(struct iqs7222_private
*iqs7222
, u16 reg
, u16 val
)
1748 __le16 val_buf
= cpu_to_le16(val
);
1750 return iqs7222_write_burst(iqs7222
, reg
, &val_buf
, 1);
1753 static int iqs7222_ati_trigger(struct iqs7222_private
*iqs7222
)
1755 struct i2c_client
*client
= iqs7222
->client
;
1756 ktime_t ati_timeout
;
1762 * The reserved fields of the system setup register may have changed
1763 * as a result of other registers having been written. As such, read
1764 * the register's latest value to avoid unexpected behavior when the
1765 * register is written in the loop that follows.
1767 error
= iqs7222_read_word(iqs7222
, IQS7222_SYS_SETUP
, &sys_setup
);
1771 for (i
= 0; i
< IQS7222_NUM_RETRIES
; i
++) {
1773 * Trigger ATI from streaming and normal-power modes so that
1774 * the RDY pin continues to be asserted during ATI.
1776 error
= iqs7222_write_word(iqs7222
, IQS7222_SYS_SETUP
,
1778 IQS7222_SYS_SETUP_REDO_ATI
);
1782 ati_timeout
= ktime_add_ms(ktime_get(), IQS7222_ATI_TIMEOUT_MS
);
1785 error
= iqs7222_irq_poll(iqs7222
,
1786 IQS7222_COMMS_TIMEOUT_MS
);
1790 error
= iqs7222_read_word(iqs7222
, IQS7222_SYS_STATUS
,
1795 if (sys_status
& IQS7222_SYS_STATUS_RESET
)
1798 if (sys_status
& IQS7222_SYS_STATUS_ATI_ERROR
)
1801 if (sys_status
& IQS7222_SYS_STATUS_ATI_ACTIVE
)
1805 * Use stream-in-touch mode if either slider reports
1806 * absolute position.
1808 sys_setup
|= test_bit(EV_ABS
, iqs7222
->keypad
->evbit
)
1809 ? IQS7222_SYS_SETUP_INTF_MODE_TOUCH
1810 : IQS7222_SYS_SETUP_INTF_MODE_EVENT
;
1811 sys_setup
|= IQS7222_SYS_SETUP_PWR_MODE_AUTO
;
1813 return iqs7222_write_word(iqs7222
, IQS7222_SYS_SETUP
,
1815 } while (ktime_compare(ktime_get(), ati_timeout
) < 0);
1817 dev_err(&client
->dev
,
1818 "ATI attempt %d of %d failed with status 0x%02X, %s\n",
1819 i
+ 1, IQS7222_NUM_RETRIES
, (u8
)sys_status
,
1820 i
+ 1 < IQS7222_NUM_RETRIES
? "retrying" : "stopping");
1826 static int iqs7222_dev_init(struct iqs7222_private
*iqs7222
, int dir
)
1828 const struct iqs7222_dev_desc
*dev_desc
= iqs7222
->dev_desc
;
1829 int comms_offset
= dev_desc
->comms_offset
;
1833 * Acknowledge reset before writing any registers in case the device
1834 * suffers a spurious reset during initialization. Because this step
1835 * may change the reserved fields of the second filter beta register,
1836 * its cache must be updated.
1838 * Writing the second filter beta register, in turn, may clobber the
1839 * system status register. As such, the filter beta register pair is
1840 * written first to protect against this hazard.
1843 u16 reg
= dev_desc
->reg_grps
[IQS7222_REG_GRP_FILT
].base
+ 1;
1846 error
= iqs7222_write_word(iqs7222
, IQS7222_SYS_SETUP
,
1847 iqs7222
->sys_setup
[0] |
1848 IQS7222_SYS_SETUP_ACK_RESET
);
1852 error
= iqs7222_read_word(iqs7222
, reg
, &filt_setup
);
1856 iqs7222
->filt_setup
[1] &= GENMASK(7, 0);
1857 iqs7222
->filt_setup
[1] |= (filt_setup
& ~GENMASK(7, 0));
1861 * Take advantage of the stop-bit disable function, if available, to
1862 * save the trouble of having to reopen a communication window after
1863 * each burst read or write.
1868 error
= iqs7222_read_word(iqs7222
,
1869 IQS7222_SYS_SETUP
+ comms_offset
,
1874 error
= iqs7222_write_word(iqs7222
,
1875 IQS7222_SYS_SETUP
+ comms_offset
,
1876 comms_setup
| IQS7222_COMMS_HOLD
);
1881 for (i
= 0; i
< IQS7222_NUM_REG_GRPS
; i
++) {
1882 int num_row
= dev_desc
->reg_grps
[i
].num_row
;
1883 int num_col
= dev_desc
->reg_grps
[i
].num_col
;
1884 u16 reg
= dev_desc
->reg_grps
[i
].base
;
1891 val
= iqs7222_setup(iqs7222
, i
, 0);
1895 val_buf
= kcalloc(num_col
, sizeof(__le16
), GFP_KERNEL
);
1899 for (j
= 0; j
< num_row
; j
++) {
1902 error
= iqs7222_read_burst(iqs7222
, reg
,
1904 for (k
= 0; k
< num_col
; k
++)
1905 val
[k
] = le16_to_cpu(val_buf
[k
]);
1909 for (k
= 0; k
< num_col
; k
++)
1910 val_buf
[k
] = cpu_to_le16(val
[k
]);
1911 error
= iqs7222_write_burst(iqs7222
, reg
,
1922 reg
+= IQS7222_REG_OFFSET
;
1923 val
+= iqs7222_max_cols
[i
];
1935 error
= iqs7222_read_word(iqs7222
,
1936 IQS7222_SYS_SETUP
+ comms_offset
,
1941 error
= iqs7222_write_word(iqs7222
,
1942 IQS7222_SYS_SETUP
+ comms_offset
,
1943 comms_setup
& ~IQS7222_COMMS_HOLD
);
1949 iqs7222
->sys_setup
[0] &= ~IQS7222_SYS_SETUP_INTF_MODE_MASK
;
1950 iqs7222
->sys_setup
[0] &= ~IQS7222_SYS_SETUP_PWR_MODE_MASK
;
1954 return iqs7222_ati_trigger(iqs7222
);
1957 static int iqs7222_dev_info(struct iqs7222_private
*iqs7222
)
1959 struct i2c_client
*client
= iqs7222
->client
;
1960 bool prod_num_valid
= false;
1964 error
= iqs7222_read_burst(iqs7222
, IQS7222_PROD_NUM
, dev_id
,
1965 ARRAY_SIZE(dev_id
));
1969 for (i
= 0; i
< ARRAY_SIZE(iqs7222_devs
); i
++) {
1970 if (le16_to_cpu(dev_id
[0]) != iqs7222_devs
[i
].prod_num
)
1973 prod_num_valid
= true;
1975 if (le16_to_cpu(dev_id
[1]) < iqs7222_devs
[i
].fw_major
)
1978 if (le16_to_cpu(dev_id
[2]) < iqs7222_devs
[i
].fw_minor
)
1981 iqs7222
->dev_desc
= &iqs7222_devs
[i
];
1986 dev_err(&client
->dev
, "Unsupported firmware revision: %u.%u\n",
1987 le16_to_cpu(dev_id
[1]), le16_to_cpu(dev_id
[2]));
1989 dev_err(&client
->dev
, "Unrecognized product number: %u\n",
1990 le16_to_cpu(dev_id
[0]));
1995 static int iqs7222_gpio_select(struct iqs7222_private
*iqs7222
,
1996 struct fwnode_handle
*child_node
,
1997 int child_enable
, u16 child_link
)
1999 const struct iqs7222_dev_desc
*dev_desc
= iqs7222
->dev_desc
;
2000 struct i2c_client
*client
= iqs7222
->client
;
2001 int num_gpio
= dev_desc
->reg_grps
[IQS7222_REG_GRP_GPIO
].num_row
;
2002 int error
, count
, i
;
2003 unsigned int gpio_sel
[ARRAY_SIZE(iqs7222_gpio_links
)];
2008 if (!fwnode_property_present(child_node
, "azoteq,gpio-select"))
2011 count
= fwnode_property_count_u32(child_node
, "azoteq,gpio-select");
2012 if (count
> num_gpio
) {
2013 dev_err(&client
->dev
, "Invalid number of %s GPIOs\n",
2014 fwnode_get_name(child_node
));
2016 } else if (count
< 0) {
2017 dev_err(&client
->dev
, "Failed to count %s GPIOs: %d\n",
2018 fwnode_get_name(child_node
), count
);
2022 error
= fwnode_property_read_u32_array(child_node
,
2023 "azoteq,gpio-select",
2026 dev_err(&client
->dev
, "Failed to read %s GPIOs: %d\n",
2027 fwnode_get_name(child_node
), error
);
2031 for (i
= 0; i
< count
; i
++) {
2034 if (gpio_sel
[i
] >= num_gpio
) {
2035 dev_err(&client
->dev
, "Invalid %s GPIO: %u\n",
2036 fwnode_get_name(child_node
), gpio_sel
[i
]);
2040 gpio_setup
= iqs7222
->gpio_setup
[gpio_sel
[i
]];
2042 if (gpio_setup
[2] && child_link
!= gpio_setup
[2]) {
2043 dev_err(&client
->dev
,
2044 "Conflicting GPIO %u event types\n",
2049 gpio_setup
[0] |= IQS7222_GPIO_SETUP_0_GPIO_EN
;
2050 gpio_setup
[1] |= child_enable
;
2051 gpio_setup
[2] = child_link
;
2057 static int iqs7222_parse_props(struct iqs7222_private
*iqs7222
,
2058 struct fwnode_handle
*reg_grp_node
,
2060 enum iqs7222_reg_grp_id reg_grp
,
2061 enum iqs7222_reg_key_id reg_key
)
2063 u16
*setup
= iqs7222_setup(iqs7222
, reg_grp
, reg_grp_index
);
2064 struct i2c_client
*client
= iqs7222
->client
;
2070 for (i
= 0; i
< ARRAY_SIZE(iqs7222_props
); i
++) {
2071 const char *name
= iqs7222_props
[i
].name
;
2072 int reg_offset
= iqs7222_props
[i
].reg_offset
;
2073 int reg_shift
= iqs7222_props
[i
].reg_shift
;
2074 int reg_width
= iqs7222_props
[i
].reg_width
;
2075 int val_pitch
= iqs7222_props
[i
].val_pitch
? : 1;
2076 int val_min
= iqs7222_props
[i
].val_min
;
2077 int val_max
= iqs7222_props
[i
].val_max
;
2078 bool invert
= iqs7222_props
[i
].invert
;
2079 const char *label
= iqs7222_props
[i
].label
? : name
;
2083 if (iqs7222_props
[i
].reg_grp
!= reg_grp
||
2084 iqs7222_props
[i
].reg_key
!= reg_key
)
2088 * Boolean register fields are one bit wide; they are forcibly
2089 * reset to provide a means to undo changes by a bootloader if
2092 * Scalar fields, on the other hand, are left untouched unless
2093 * their corresponding properties are present.
2095 if (reg_width
== 1) {
2097 setup
[reg_offset
] |= BIT(reg_shift
);
2099 setup
[reg_offset
] &= ~BIT(reg_shift
);
2102 if (!fwnode_property_present(reg_grp_node
, name
))
2105 if (reg_width
== 1) {
2107 setup
[reg_offset
] &= ~BIT(reg_shift
);
2109 setup
[reg_offset
] |= BIT(reg_shift
);
2114 error
= fwnode_property_read_u32(reg_grp_node
, name
, &val
);
2116 dev_err(&client
->dev
, "Failed to read %s %s: %d\n",
2117 fwnode_get_name(reg_grp_node
), label
, error
);
2122 val_max
= GENMASK(reg_width
- 1, 0) * val_pitch
;
2124 if (val
< val_min
|| val
> val_max
) {
2125 dev_err(&client
->dev
, "Invalid %s %s: %u\n",
2126 fwnode_get_name(reg_grp_node
), label
, val
);
2130 setup
[reg_offset
] &= ~GENMASK(reg_shift
+ reg_width
- 1,
2132 setup
[reg_offset
] |= (val
/ val_pitch
<< reg_shift
);
2138 static int iqs7222_parse_event(struct iqs7222_private
*iqs7222
,
2139 struct fwnode_handle
*event_node
,
2141 enum iqs7222_reg_grp_id reg_grp
,
2142 enum iqs7222_reg_key_id reg_key
,
2143 u16 event_enable
, u16 event_link
,
2144 unsigned int *event_type
,
2145 unsigned int *event_code
)
2147 struct i2c_client
*client
= iqs7222
->client
;
2150 error
= iqs7222_parse_props(iqs7222
, event_node
, reg_grp_index
,
2155 error
= iqs7222_gpio_select(iqs7222
, event_node
, event_enable
,
2160 error
= fwnode_property_read_u32(event_node
, "linux,code", event_code
);
2161 if (error
== -EINVAL
) {
2164 dev_err(&client
->dev
, "Failed to read %s code: %d\n",
2165 fwnode_get_name(event_node
), error
);
2170 input_set_capability(iqs7222
->keypad
, EV_KEY
, *event_code
);
2174 error
= fwnode_property_read_u32(event_node
, "linux,input-type",
2176 if (error
== -EINVAL
) {
2177 *event_type
= EV_KEY
;
2179 dev_err(&client
->dev
, "Failed to read %s input type: %d\n",
2180 fwnode_get_name(event_node
), error
);
2182 } else if (*event_type
!= EV_KEY
&& *event_type
!= EV_SW
) {
2183 dev_err(&client
->dev
, "Invalid %s input type: %d\n",
2184 fwnode_get_name(event_node
), *event_type
);
2188 input_set_capability(iqs7222
->keypad
, *event_type
, *event_code
);
2193 static int iqs7222_parse_cycle(struct iqs7222_private
*iqs7222
,
2194 struct fwnode_handle
*cycle_node
, int cycle_index
)
2196 u16
*cycle_setup
= iqs7222
->cycle_setup
[cycle_index
];
2197 struct i2c_client
*client
= iqs7222
->client
;
2198 unsigned int pins
[9];
2199 int error
, count
, i
;
2202 * Each channel shares a cycle with one other channel; the mapping of
2203 * channels to cycles is fixed. Properties defined for a cycle impact
2204 * both channels tied to the cycle.
2206 * Unlike channels which are restricted to a select range of CRx pins
2207 * based on channel number, any cycle can claim any of the device's 9
2208 * CTx pins (CTx0-8).
2210 if (!fwnode_property_present(cycle_node
, "azoteq,tx-enable"))
2213 count
= fwnode_property_count_u32(cycle_node
, "azoteq,tx-enable");
2215 dev_err(&client
->dev
, "Failed to count %s CTx pins: %d\n",
2216 fwnode_get_name(cycle_node
), count
);
2218 } else if (count
> ARRAY_SIZE(pins
)) {
2219 dev_err(&client
->dev
, "Invalid number of %s CTx pins\n",
2220 fwnode_get_name(cycle_node
));
2224 error
= fwnode_property_read_u32_array(cycle_node
, "azoteq,tx-enable",
2227 dev_err(&client
->dev
, "Failed to read %s CTx pins: %d\n",
2228 fwnode_get_name(cycle_node
), error
);
2232 cycle_setup
[1] &= ~GENMASK(7 + ARRAY_SIZE(pins
) - 1, 7);
2234 for (i
= 0; i
< count
; i
++) {
2236 dev_err(&client
->dev
, "Invalid %s CTx pin: %u\n",
2237 fwnode_get_name(cycle_node
), pins
[i
]);
2241 cycle_setup
[1] |= BIT(pins
[i
] + 7);
2247 static int iqs7222_parse_chan(struct iqs7222_private
*iqs7222
,
2248 struct fwnode_handle
*chan_node
, int chan_index
)
2250 const struct iqs7222_dev_desc
*dev_desc
= iqs7222
->dev_desc
;
2251 struct i2c_client
*client
= iqs7222
->client
;
2252 int num_chan
= dev_desc
->reg_grps
[IQS7222_REG_GRP_CHAN
].num_row
;
2253 int ext_chan
= rounddown(num_chan
, 10);
2255 u16
*chan_setup
= iqs7222
->chan_setup
[chan_index
];
2256 u16
*sys_setup
= iqs7222
->sys_setup
;
2259 if (dev_desc
->allow_offset
&&
2260 fwnode_property_present(chan_node
, "azoteq,ulp-allow"))
2261 sys_setup
[dev_desc
->allow_offset
] &= ~BIT(chan_index
);
2263 chan_setup
[0] |= IQS7222_CHAN_SETUP_0_CHAN_EN
;
2266 * The reference channel function allows for differential measurements
2267 * and is only available in the case of IQS7222A or IQS7222C.
2269 if (dev_desc
->reg_grps
[IQS7222_REG_GRP_CHAN
].num_col
> 4 &&
2270 fwnode_property_present(chan_node
, "azoteq,ref-select")) {
2273 error
= fwnode_property_read_u32(chan_node
, "azoteq,ref-select",
2276 dev_err(&client
->dev
,
2277 "Failed to read %s reference channel: %d\n",
2278 fwnode_get_name(chan_node
), error
);
2282 if (val
>= ext_chan
) {
2283 dev_err(&client
->dev
,
2284 "Invalid %s reference channel: %u\n",
2285 fwnode_get_name(chan_node
), val
);
2289 ref_setup
= iqs7222
->chan_setup
[val
];
2292 * Configure the current channel as a follower of the selected
2293 * reference channel.
2295 chan_setup
[0] |= IQS7222_CHAN_SETUP_0_REF_MODE_FOLLOW
;
2296 chan_setup
[4] = val
* 42 + 1048;
2298 error
= fwnode_property_read_u32(chan_node
, "azoteq,ref-weight",
2301 if (val
> U16_MAX
) {
2302 dev_err(&client
->dev
,
2303 "Invalid %s reference weight: %u\n",
2304 fwnode_get_name(chan_node
), val
);
2308 chan_setup
[5] = val
;
2309 } else if (error
!= -EINVAL
) {
2310 dev_err(&client
->dev
,
2311 "Failed to read %s reference weight: %d\n",
2312 fwnode_get_name(chan_node
), error
);
2317 * Configure the selected channel as a reference channel which
2318 * serves the current channel.
2320 ref_setup
[0] |= IQS7222_CHAN_SETUP_0_REF_MODE_REF
;
2321 ref_setup
[5] |= BIT(chan_index
);
2323 ref_setup
[4] = dev_desc
->touch_link
;
2324 if (fwnode_property_present(chan_node
, "azoteq,use-prox"))
2326 } else if (dev_desc
->reg_grps
[IQS7222_REG_GRP_TPAD
].num_row
&&
2327 fwnode_property_present(chan_node
,
2328 "azoteq,counts-filt-enable")) {
2330 * In the case of IQS7222D, however, the reference mode field
2331 * is partially repurposed as a counts filter enable control.
2333 chan_setup
[0] |= IQS7222_CHAN_SETUP_0_REF_MODE_REF
;
2336 if (fwnode_property_present(chan_node
, "azoteq,rx-enable")) {
2338 * Each channel can claim up to 4 CRx pins. The first half of
2339 * the channels can use CRx0-3, while the second half can use
2342 unsigned int pins
[4];
2345 count
= fwnode_property_count_u32(chan_node
,
2346 "azoteq,rx-enable");
2348 dev_err(&client
->dev
,
2349 "Failed to count %s CRx pins: %d\n",
2350 fwnode_get_name(chan_node
), count
);
2352 } else if (count
> ARRAY_SIZE(pins
)) {
2353 dev_err(&client
->dev
,
2354 "Invalid number of %s CRx pins\n",
2355 fwnode_get_name(chan_node
));
2359 error
= fwnode_property_read_u32_array(chan_node
,
2363 dev_err(&client
->dev
,
2364 "Failed to read %s CRx pins: %d\n",
2365 fwnode_get_name(chan_node
), error
);
2369 chan_setup
[0] &= ~GENMASK(4 + ARRAY_SIZE(pins
) - 1, 4);
2371 for (i
= 0; i
< count
; i
++) {
2372 int min_crx
= chan_index
< ext_chan
/ 2 ? 0 : 4;
2374 if (pins
[i
] < min_crx
|| pins
[i
] > min_crx
+ 3) {
2375 dev_err(&client
->dev
,
2376 "Invalid %s CRx pin: %u\n",
2377 fwnode_get_name(chan_node
), pins
[i
]);
2381 chan_setup
[0] |= BIT(pins
[i
] + 4 - min_crx
);
2385 for (i
= 0; i
< ARRAY_SIZE(iqs7222_kp_events
); i
++) {
2386 const char *event_name
= iqs7222_kp_events
[i
].name
;
2387 u16 event_enable
= iqs7222_kp_events
[i
].enable
;
2389 struct fwnode_handle
*event_node
__free(fwnode_handle
) =
2390 fwnode_get_named_child_node(chan_node
, event_name
);
2394 error
= fwnode_property_read_u32(event_node
,
2395 "azoteq,timeout-press-ms",
2399 * The IQS7222B employs a global pair of press timeout
2400 * registers as opposed to channel-specific registers.
2402 u16
*setup
= dev_desc
->reg_grps
2403 [IQS7222_REG_GRP_BTN
].num_col
> 2 ?
2404 &iqs7222
->btn_setup
[chan_index
][2] :
2407 if (val
> U8_MAX
* 500) {
2408 dev_err(&client
->dev
,
2409 "Invalid %s press timeout: %u\n",
2410 fwnode_get_name(event_node
), val
);
2414 *setup
&= ~(U8_MAX
<< i
* 8);
2415 *setup
|= (val
/ 500 << i
* 8);
2416 } else if (error
!= -EINVAL
) {
2417 dev_err(&client
->dev
,
2418 "Failed to read %s press timeout: %d\n",
2419 fwnode_get_name(event_node
), error
);
2423 error
= iqs7222_parse_event(iqs7222
, event_node
, chan_index
,
2424 IQS7222_REG_GRP_BTN
,
2425 iqs7222_kp_events
[i
].reg_key
,
2427 dev_desc
->touch_link
- (i
? 0 : 2),
2428 &iqs7222
->kp_type
[chan_index
][i
],
2429 &iqs7222
->kp_code
[chan_index
][i
]);
2433 if (!dev_desc
->event_offset
)
2436 sys_setup
[dev_desc
->event_offset
] |= event_enable
;
2440 * The following call handles a special pair of properties that apply
2441 * to a channel node, but reside within the button (event) group.
2443 return iqs7222_parse_props(iqs7222
, chan_node
, chan_index
,
2444 IQS7222_REG_GRP_BTN
,
2445 IQS7222_REG_KEY_DEBOUNCE
);
2448 static int iqs7222_parse_sldr(struct iqs7222_private
*iqs7222
,
2449 struct fwnode_handle
*sldr_node
, int sldr_index
)
2451 const struct iqs7222_dev_desc
*dev_desc
= iqs7222
->dev_desc
;
2452 struct i2c_client
*client
= iqs7222
->client
;
2453 int num_chan
= dev_desc
->reg_grps
[IQS7222_REG_GRP_CHAN
].num_row
;
2454 int ext_chan
= rounddown(num_chan
, 10);
2455 int count
, error
, reg_offset
, i
;
2456 u16
*event_mask
= &iqs7222
->sys_setup
[dev_desc
->event_offset
];
2457 u16
*sldr_setup
= iqs7222
->sldr_setup
[sldr_index
];
2458 unsigned int chan_sel
[4], val
;
2461 * Each slider can be spread across 3 to 4 channels. It is possible to
2462 * select only 2 channels, but doing so prevents the slider from using
2463 * the specified resolution.
2465 count
= fwnode_property_count_u32(sldr_node
, "azoteq,channel-select");
2467 dev_err(&client
->dev
, "Failed to count %s channels: %d\n",
2468 fwnode_get_name(sldr_node
), count
);
2470 } else if (count
< 3 || count
> ARRAY_SIZE(chan_sel
)) {
2471 dev_err(&client
->dev
, "Invalid number of %s channels\n",
2472 fwnode_get_name(sldr_node
));
2476 error
= fwnode_property_read_u32_array(sldr_node
,
2477 "azoteq,channel-select",
2480 dev_err(&client
->dev
, "Failed to read %s channels: %d\n",
2481 fwnode_get_name(sldr_node
), error
);
2486 * Resolution and top speed, if small enough, are packed into a single
2487 * register. Otherwise, each occupies its own register and the rest of
2488 * the slider-related register addresses are offset by one.
2490 reg_offset
= dev_desc
->sldr_res
< U16_MAX
? 0 : 1;
2492 sldr_setup
[0] |= count
;
2493 sldr_setup
[3 + reg_offset
] &= ~GENMASK(ext_chan
- 1, 0);
2495 for (i
= 0; i
< ARRAY_SIZE(chan_sel
); i
++) {
2496 sldr_setup
[5 + reg_offset
+ i
] = 0;
2500 if (chan_sel
[i
] >= ext_chan
) {
2501 dev_err(&client
->dev
, "Invalid %s channel: %u\n",
2502 fwnode_get_name(sldr_node
), chan_sel
[i
]);
2507 * The following fields indicate which channels participate in
2508 * the slider, as well as each channel's relative placement.
2510 sldr_setup
[3 + reg_offset
] |= BIT(chan_sel
[i
]);
2511 sldr_setup
[5 + reg_offset
+ i
] = chan_sel
[i
] * 42 + 1080;
2514 sldr_setup
[4 + reg_offset
] = dev_desc
->touch_link
;
2515 if (fwnode_property_present(sldr_node
, "azoteq,use-prox"))
2516 sldr_setup
[4 + reg_offset
] -= 2;
2518 error
= fwnode_property_read_u32(sldr_node
, "azoteq,slider-size", &val
);
2520 if (val
> dev_desc
->sldr_res
) {
2521 dev_err(&client
->dev
, "Invalid %s size: %u\n",
2522 fwnode_get_name(sldr_node
), val
);
2527 sldr_setup
[3] = val
;
2529 sldr_setup
[2] &= ~IQS7222_SLDR_SETUP_2_RES_MASK
;
2530 sldr_setup
[2] |= (val
/ 16 <<
2531 IQS7222_SLDR_SETUP_2_RES_SHIFT
);
2533 } else if (error
!= -EINVAL
) {
2534 dev_err(&client
->dev
, "Failed to read %s size: %d\n",
2535 fwnode_get_name(sldr_node
), error
);
2539 if (!(reg_offset
? sldr_setup
[3]
2540 : sldr_setup
[2] & IQS7222_SLDR_SETUP_2_RES_MASK
)) {
2541 dev_err(&client
->dev
, "Undefined %s size\n",
2542 fwnode_get_name(sldr_node
));
2546 error
= fwnode_property_read_u32(sldr_node
, "azoteq,top-speed", &val
);
2548 if (val
> (reg_offset
? U16_MAX
: U8_MAX
* 4)) {
2549 dev_err(&client
->dev
, "Invalid %s top speed: %u\n",
2550 fwnode_get_name(sldr_node
), val
);
2555 sldr_setup
[2] = val
;
2557 sldr_setup
[2] &= ~IQS7222_SLDR_SETUP_2_TOP_SPEED_MASK
;
2558 sldr_setup
[2] |= (val
/ 4);
2560 } else if (error
!= -EINVAL
) {
2561 dev_err(&client
->dev
, "Failed to read %s top speed: %d\n",
2562 fwnode_get_name(sldr_node
), error
);
2566 error
= fwnode_property_read_u32(sldr_node
, "linux,axis", &val
);
2568 u16 sldr_max
= sldr_setup
[3] - 1;
2571 sldr_max
= sldr_setup
[2];
2573 sldr_max
&= IQS7222_SLDR_SETUP_2_RES_MASK
;
2574 sldr_max
>>= IQS7222_SLDR_SETUP_2_RES_SHIFT
;
2576 sldr_max
= sldr_max
* 16 - 1;
2579 input_set_abs_params(iqs7222
->keypad
, val
, 0, sldr_max
, 0, 0);
2580 iqs7222
->sl_axis
[sldr_index
] = val
;
2581 } else if (error
!= -EINVAL
) {
2582 dev_err(&client
->dev
, "Failed to read %s axis: %d\n",
2583 fwnode_get_name(sldr_node
), error
);
2587 if (dev_desc
->wheel_enable
) {
2588 sldr_setup
[0] &= ~dev_desc
->wheel_enable
;
2589 if (iqs7222
->sl_axis
[sldr_index
] == ABS_WHEEL
)
2590 sldr_setup
[0] |= dev_desc
->wheel_enable
;
2594 * The absence of a register offset makes it safe to assume the device
2595 * supports gestures, each of which is first disabled until explicitly
2599 for (i
= 0; i
< ARRAY_SIZE(iqs7222_sl_events
); i
++)
2600 sldr_setup
[9] &= ~iqs7222_sl_events
[i
].enable
;
2602 for (i
= 0; i
< ARRAY_SIZE(iqs7222_sl_events
); i
++) {
2603 const char *event_name
= iqs7222_sl_events
[i
].name
;
2604 enum iqs7222_reg_key_id reg_key
;
2606 struct fwnode_handle
*event_node
__free(fwnode_handle
) =
2607 fwnode_get_named_child_node(sldr_node
, event_name
);
2612 * Depending on the device, gestures are either offered using
2613 * one of two timing resolutions, or are not supported at all.
2616 reg_key
= IQS7222_REG_KEY_RESERVED
;
2617 else if (dev_desc
->legacy_gesture
&&
2618 iqs7222_sl_events
[i
].reg_key
== IQS7222_REG_KEY_TAP
)
2619 reg_key
= IQS7222_REG_KEY_TAP_LEGACY
;
2620 else if (dev_desc
->legacy_gesture
&&
2621 iqs7222_sl_events
[i
].reg_key
== IQS7222_REG_KEY_AXIAL
)
2622 reg_key
= IQS7222_REG_KEY_AXIAL_LEGACY
;
2624 reg_key
= iqs7222_sl_events
[i
].reg_key
;
2627 * The press/release event does not expose a direct GPIO link,
2628 * but one can be emulated by tying each of the participating
2629 * channels to the same GPIO.
2631 error
= iqs7222_parse_event(iqs7222
, event_node
, sldr_index
,
2632 IQS7222_REG_GRP_SLDR
, reg_key
,
2633 i
? iqs7222_sl_events
[i
].enable
2634 : sldr_setup
[3 + reg_offset
],
2635 i
? 1568 + sldr_index
* 30
2636 : sldr_setup
[4 + reg_offset
],
2638 &iqs7222
->sl_code
[sldr_index
][i
]);
2643 sldr_setup
[9] |= iqs7222_sl_events
[i
].enable
;
2645 if (!dev_desc
->event_offset
)
2649 * The press/release event is determined based on whether the
2650 * coordinate field reports 0xFFFF and solely relies on touch
2651 * or proximity interrupts to be unmasked.
2653 if (i
&& !reg_offset
)
2654 *event_mask
|= (IQS7222_EVENT_MASK_SLDR
<< sldr_index
);
2655 else if (sldr_setup
[4 + reg_offset
] == dev_desc
->touch_link
)
2656 *event_mask
|= IQS7222_EVENT_MASK_TOUCH
;
2658 *event_mask
|= IQS7222_EVENT_MASK_PROX
;
2662 * The following call handles a special pair of properties that shift
2663 * to make room for a wheel enable control in the case of IQS7222C.
2665 return iqs7222_parse_props(iqs7222
, sldr_node
, sldr_index
,
2666 IQS7222_REG_GRP_SLDR
,
2667 dev_desc
->wheel_enable
?
2668 IQS7222_REG_KEY_WHEEL
:
2669 IQS7222_REG_KEY_NO_WHEEL
);
2672 static int iqs7222_parse_tpad(struct iqs7222_private
*iqs7222
,
2673 struct fwnode_handle
*tpad_node
, int tpad_index
)
2675 const struct iqs7222_dev_desc
*dev_desc
= iqs7222
->dev_desc
;
2676 struct touchscreen_properties
*prop
= &iqs7222
->prop
;
2677 struct i2c_client
*client
= iqs7222
->client
;
2678 int num_chan
= dev_desc
->reg_grps
[IQS7222_REG_GRP_CHAN
].num_row
;
2679 int count
, error
, i
;
2680 u16
*event_mask
= &iqs7222
->sys_setup
[dev_desc
->event_offset
];
2681 u16
*tpad_setup
= iqs7222
->tpad_setup
;
2682 unsigned int chan_sel
[12];
2684 error
= iqs7222_parse_props(iqs7222
, tpad_node
, tpad_index
,
2685 IQS7222_REG_GRP_TPAD
,
2686 IQS7222_REG_KEY_NONE
);
2690 count
= fwnode_property_count_u32(tpad_node
, "azoteq,channel-select");
2692 dev_err(&client
->dev
, "Failed to count %s channels: %d\n",
2693 fwnode_get_name(tpad_node
), count
);
2695 } else if (!count
|| count
> ARRAY_SIZE(chan_sel
)) {
2696 dev_err(&client
->dev
, "Invalid number of %s channels\n",
2697 fwnode_get_name(tpad_node
));
2701 error
= fwnode_property_read_u32_array(tpad_node
,
2702 "azoteq,channel-select",
2705 dev_err(&client
->dev
, "Failed to read %s channels: %d\n",
2706 fwnode_get_name(tpad_node
), error
);
2710 tpad_setup
[6] &= ~GENMASK(num_chan
- 1, 0);
2712 for (i
= 0; i
< ARRAY_SIZE(chan_sel
); i
++) {
2713 tpad_setup
[8 + i
] = 0;
2714 if (i
>= count
|| chan_sel
[i
] == U8_MAX
)
2717 if (chan_sel
[i
] >= num_chan
) {
2718 dev_err(&client
->dev
, "Invalid %s channel: %u\n",
2719 fwnode_get_name(tpad_node
), chan_sel
[i
]);
2724 * The following fields indicate which channels participate in
2725 * the trackpad, as well as each channel's relative placement.
2727 tpad_setup
[6] |= BIT(chan_sel
[i
]);
2728 tpad_setup
[8 + i
] = chan_sel
[i
] * 34 + 1072;
2731 tpad_setup
[7] = dev_desc
->touch_link
;
2732 if (fwnode_property_present(tpad_node
, "azoteq,use-prox"))
2735 for (i
= 0; i
< ARRAY_SIZE(iqs7222_tp_events
); i
++)
2736 tpad_setup
[20] &= ~(iqs7222_tp_events
[i
].strict
|
2737 iqs7222_tp_events
[i
].enable
);
2739 for (i
= 0; i
< ARRAY_SIZE(iqs7222_tp_events
); i
++) {
2740 const char *event_name
= iqs7222_tp_events
[i
].name
;
2742 struct fwnode_handle
*event_node
__free(fwnode_handle
) =
2743 fwnode_get_named_child_node(tpad_node
, event_name
);
2747 if (fwnode_property_present(event_node
,
2748 "azoteq,gesture-angle-tighten"))
2749 tpad_setup
[20] |= iqs7222_tp_events
[i
].strict
;
2751 tpad_setup
[20] |= iqs7222_tp_events
[i
].enable
;
2753 error
= iqs7222_parse_event(iqs7222
, event_node
, tpad_index
,
2754 IQS7222_REG_GRP_TPAD
,
2755 iqs7222_tp_events
[i
].reg_key
,
2756 iqs7222_tp_events
[i
].link
, 1566,
2758 &iqs7222
->tp_code
[i
]);
2762 if (!dev_desc
->event_offset
)
2766 * The press/release event is determined based on whether the
2767 * coordinate fields report 0xFFFF and solely relies on touch
2768 * or proximity interrupts to be unmasked.
2771 *event_mask
|= IQS7222_EVENT_MASK_TPAD
;
2772 else if (tpad_setup
[7] == dev_desc
->touch_link
)
2773 *event_mask
|= IQS7222_EVENT_MASK_TOUCH
;
2775 *event_mask
|= IQS7222_EVENT_MASK_PROX
;
2778 if (!iqs7222
->tp_code
[0])
2781 input_set_abs_params(iqs7222
->keypad
, ABS_X
,
2782 0, (tpad_setup
[4] ? : 1) - 1, 0, 0);
2784 input_set_abs_params(iqs7222
->keypad
, ABS_Y
,
2785 0, (tpad_setup
[5] ? : 1) - 1, 0, 0);
2787 touchscreen_parse_properties(iqs7222
->keypad
, false, prop
);
2789 if (prop
->max_x
>= U16_MAX
|| prop
->max_y
>= U16_MAX
) {
2790 dev_err(&client
->dev
, "Invalid trackpad size: %u*%u\n",
2791 prop
->max_x
, prop
->max_y
);
2795 tpad_setup
[4] = prop
->max_x
+ 1;
2796 tpad_setup
[5] = prop
->max_y
+ 1;
2801 static int (*iqs7222_parse_extra
[IQS7222_NUM_REG_GRPS
])
2802 (struct iqs7222_private
*iqs7222
,
2803 struct fwnode_handle
*reg_grp_node
,
2804 int reg_grp_index
) = {
2805 [IQS7222_REG_GRP_CYCLE
] = iqs7222_parse_cycle
,
2806 [IQS7222_REG_GRP_CHAN
] = iqs7222_parse_chan
,
2807 [IQS7222_REG_GRP_SLDR
] = iqs7222_parse_sldr
,
2808 [IQS7222_REG_GRP_TPAD
] = iqs7222_parse_tpad
,
2811 static int iqs7222_parse_reg_grp(struct iqs7222_private
*iqs7222
,
2812 enum iqs7222_reg_grp_id reg_grp
,
2815 struct i2c_client
*client
= iqs7222
->client
;
2818 struct fwnode_handle
*reg_grp_node
__free(fwnode_handle
) = NULL
;
2819 if (iqs7222_reg_grp_names
[reg_grp
]) {
2820 char reg_grp_name
[16];
2822 snprintf(reg_grp_name
, sizeof(reg_grp_name
),
2823 iqs7222_reg_grp_names
[reg_grp
], reg_grp_index
);
2825 reg_grp_node
= device_get_named_child_node(&client
->dev
,
2828 reg_grp_node
= fwnode_handle_get(dev_fwnode(&client
->dev
));
2834 error
= iqs7222_parse_props(iqs7222
, reg_grp_node
, reg_grp_index
,
2835 reg_grp
, IQS7222_REG_KEY_NONE
);
2839 if (iqs7222_parse_extra
[reg_grp
]) {
2840 error
= iqs7222_parse_extra
[reg_grp
](iqs7222
, reg_grp_node
,
2849 static int iqs7222_parse_all(struct iqs7222_private
*iqs7222
)
2851 const struct iqs7222_dev_desc
*dev_desc
= iqs7222
->dev_desc
;
2852 const struct iqs7222_reg_grp_desc
*reg_grps
= dev_desc
->reg_grps
;
2853 u16
*sys_setup
= iqs7222
->sys_setup
;
2856 if (dev_desc
->allow_offset
)
2857 sys_setup
[dev_desc
->allow_offset
] = U16_MAX
;
2859 if (dev_desc
->event_offset
)
2860 sys_setup
[dev_desc
->event_offset
] = IQS7222_EVENT_MASK_ATI
;
2862 for (i
= 0; i
< reg_grps
[IQS7222_REG_GRP_GPIO
].num_row
; i
++) {
2863 u16
*gpio_setup
= iqs7222
->gpio_setup
[i
];
2865 gpio_setup
[0] &= ~IQS7222_GPIO_SETUP_0_GPIO_EN
;
2869 if (reg_grps
[IQS7222_REG_GRP_GPIO
].num_row
== 1)
2873 * The IQS7222C and IQS7222D expose multiple GPIO and must be
2874 * informed as to which GPIO this group represents.
2876 for (j
= 0; j
< ARRAY_SIZE(iqs7222_gpio_links
); j
++)
2877 gpio_setup
[0] &= ~BIT(iqs7222_gpio_links
[j
]);
2879 gpio_setup
[0] |= BIT(iqs7222_gpio_links
[i
]);
2882 for (i
= 0; i
< reg_grps
[IQS7222_REG_GRP_CHAN
].num_row
; i
++) {
2883 u16
*chan_setup
= iqs7222
->chan_setup
[i
];
2885 chan_setup
[0] &= ~IQS7222_CHAN_SETUP_0_REF_MODE_MASK
;
2886 chan_setup
[0] &= ~IQS7222_CHAN_SETUP_0_CHAN_EN
;
2891 for (i
= 0; i
< reg_grps
[IQS7222_REG_GRP_SLDR
].num_row
; i
++) {
2892 u16
*sldr_setup
= iqs7222
->sldr_setup
[i
];
2894 sldr_setup
[0] &= ~IQS7222_SLDR_SETUP_0_CHAN_CNT_MASK
;
2897 for (i
= 0; i
< IQS7222_NUM_REG_GRPS
; i
++) {
2898 for (j
= 0; j
< reg_grps
[i
].num_row
; j
++) {
2899 error
= iqs7222_parse_reg_grp(iqs7222
, i
, j
);
2908 static int iqs7222_report(struct iqs7222_private
*iqs7222
)
2910 const struct iqs7222_dev_desc
*dev_desc
= iqs7222
->dev_desc
;
2911 struct i2c_client
*client
= iqs7222
->client
;
2912 int num_chan
= dev_desc
->reg_grps
[IQS7222_REG_GRP_CHAN
].num_row
;
2913 int num_stat
= dev_desc
->reg_grps
[IQS7222_REG_GRP_STAT
].num_col
;
2915 __le16 status
[IQS7222_MAX_COLS_STAT
];
2917 error
= iqs7222_read_burst(iqs7222
, IQS7222_SYS_STATUS
, status
,
2922 if (le16_to_cpu(status
[0]) & IQS7222_SYS_STATUS_RESET
) {
2923 dev_err(&client
->dev
, "Unexpected device reset\n");
2924 return iqs7222_dev_init(iqs7222
, WRITE
);
2927 if (le16_to_cpu(status
[0]) & IQS7222_SYS_STATUS_ATI_ERROR
) {
2928 dev_err(&client
->dev
, "Unexpected ATI error\n");
2929 return iqs7222_ati_trigger(iqs7222
);
2932 if (le16_to_cpu(status
[0]) & IQS7222_SYS_STATUS_ATI_ACTIVE
)
2935 for (i
= 0; i
< num_chan
; i
++) {
2936 u16
*chan_setup
= iqs7222
->chan_setup
[i
];
2938 if (!(chan_setup
[0] & IQS7222_CHAN_SETUP_0_CHAN_EN
))
2941 for (j
= 0; j
< ARRAY_SIZE(iqs7222_kp_events
); j
++) {
2943 * Proximity state begins at offset 2 and spills into
2944 * offset 3 for devices with more than 16 channels.
2946 * Touch state begins at the first offset immediately
2947 * following proximity state.
2949 int k
= 2 + j
* (num_chan
> 16 ? 2 : 1);
2950 u16 state
= le16_to_cpu(status
[k
+ i
/ 16]);
2952 if (!iqs7222
->kp_type
[i
][j
])
2955 input_event(iqs7222
->keypad
,
2956 iqs7222
->kp_type
[i
][j
],
2957 iqs7222
->kp_code
[i
][j
],
2958 !!(state
& BIT(i
% 16)));
2962 for (i
= 0; i
< dev_desc
->reg_grps
[IQS7222_REG_GRP_SLDR
].num_row
; i
++) {
2963 u16
*sldr_setup
= iqs7222
->sldr_setup
[i
];
2964 u16 sldr_pos
= le16_to_cpu(status
[4 + i
]);
2965 u16 state
= le16_to_cpu(status
[6 + i
]);
2967 if (!(sldr_setup
[0] & IQS7222_SLDR_SETUP_0_CHAN_CNT_MASK
))
2970 if (sldr_pos
< dev_desc
->sldr_res
)
2971 input_report_abs(iqs7222
->keypad
, iqs7222
->sl_axis
[i
],
2974 input_report_key(iqs7222
->keypad
, iqs7222
->sl_code
[i
][0],
2975 sldr_pos
< dev_desc
->sldr_res
);
2978 * A maximum resolution indicates the device does not support
2979 * gestures, in which case the remaining fields are ignored.
2981 if (dev_desc
->sldr_res
== U16_MAX
)
2984 if (!(le16_to_cpu(status
[1]) & IQS7222_EVENT_MASK_SLDR
<< i
))
2988 * Skip the press/release event, as it does not have separate
2989 * status fields and is handled separately.
2991 for (j
= 1; j
< ARRAY_SIZE(iqs7222_sl_events
); j
++) {
2992 u16 mask
= iqs7222_sl_events
[j
].mask
;
2993 u16 val
= iqs7222_sl_events
[j
].val
;
2995 input_report_key(iqs7222
->keypad
,
2996 iqs7222
->sl_code
[i
][j
],
2997 (state
& mask
) == val
);
3000 input_sync(iqs7222
->keypad
);
3002 for (j
= 1; j
< ARRAY_SIZE(iqs7222_sl_events
); j
++)
3003 input_report_key(iqs7222
->keypad
,
3004 iqs7222
->sl_code
[i
][j
], 0);
3007 for (i
= 0; i
< dev_desc
->reg_grps
[IQS7222_REG_GRP_TPAD
].num_row
; i
++) {
3008 u16 tpad_pos_x
= le16_to_cpu(status
[4]);
3009 u16 tpad_pos_y
= le16_to_cpu(status
[5]);
3010 u16 state
= le16_to_cpu(status
[6]);
3012 input_report_key(iqs7222
->keypad
, iqs7222
->tp_code
[0],
3013 tpad_pos_x
< U16_MAX
);
3015 if (tpad_pos_x
< U16_MAX
)
3016 touchscreen_report_pos(iqs7222
->keypad
, &iqs7222
->prop
,
3017 tpad_pos_x
, tpad_pos_y
, false);
3019 if (!(le16_to_cpu(status
[1]) & IQS7222_EVENT_MASK_TPAD
))
3023 * Skip the press/release event, as it does not have separate
3024 * status fields and is handled separately.
3026 for (j
= 1; j
< ARRAY_SIZE(iqs7222_tp_events
); j
++) {
3027 u16 mask
= iqs7222_tp_events
[j
].mask
;
3028 u16 val
= iqs7222_tp_events
[j
].val
;
3030 input_report_key(iqs7222
->keypad
,
3031 iqs7222
->tp_code
[j
],
3032 (state
& mask
) == val
);
3035 input_sync(iqs7222
->keypad
);
3037 for (j
= 1; j
< ARRAY_SIZE(iqs7222_tp_events
); j
++)
3038 input_report_key(iqs7222
->keypad
,
3039 iqs7222
->tp_code
[j
], 0);
3042 input_sync(iqs7222
->keypad
);
3047 static irqreturn_t
iqs7222_irq(int irq
, void *context
)
3049 struct iqs7222_private
*iqs7222
= context
;
3051 return iqs7222_report(iqs7222
) ? IRQ_NONE
: IRQ_HANDLED
;
3054 static int iqs7222_probe(struct i2c_client
*client
)
3056 struct iqs7222_private
*iqs7222
;
3057 unsigned long irq_flags
;
3060 iqs7222
= devm_kzalloc(&client
->dev
, sizeof(*iqs7222
), GFP_KERNEL
);
3064 i2c_set_clientdata(client
, iqs7222
);
3065 iqs7222
->client
= client
;
3067 iqs7222
->keypad
= devm_input_allocate_device(&client
->dev
);
3068 if (!iqs7222
->keypad
)
3071 iqs7222
->keypad
->name
= client
->name
;
3072 iqs7222
->keypad
->id
.bustype
= BUS_I2C
;
3075 * The RDY pin behaves as an interrupt, but must also be polled ahead
3076 * of unsolicited I2C communication. As such, it is first opened as a
3077 * GPIO and then passed to gpiod_to_irq() to register the interrupt.
3079 iqs7222
->irq_gpio
= devm_gpiod_get(&client
->dev
, "irq", GPIOD_IN
);
3080 if (IS_ERR(iqs7222
->irq_gpio
)) {
3081 error
= PTR_ERR(iqs7222
->irq_gpio
);
3082 dev_err(&client
->dev
, "Failed to request IRQ GPIO: %d\n",
3087 iqs7222
->reset_gpio
= devm_gpiod_get_optional(&client
->dev
, "reset",
3089 if (IS_ERR(iqs7222
->reset_gpio
)) {
3090 error
= PTR_ERR(iqs7222
->reset_gpio
);
3091 dev_err(&client
->dev
, "Failed to request reset GPIO: %d\n",
3096 error
= iqs7222_hard_reset(iqs7222
);
3100 error
= iqs7222_dev_info(iqs7222
);
3104 error
= iqs7222_dev_init(iqs7222
, READ
);
3108 error
= iqs7222_parse_all(iqs7222
);
3112 error
= iqs7222_dev_init(iqs7222
, WRITE
);
3116 error
= iqs7222_report(iqs7222
);
3120 error
= input_register_device(iqs7222
->keypad
);
3122 dev_err(&client
->dev
, "Failed to register device: %d\n", error
);
3126 irq
= gpiod_to_irq(iqs7222
->irq_gpio
);
3130 irq_flags
= gpiod_is_active_low(iqs7222
->irq_gpio
) ? IRQF_TRIGGER_LOW
3131 : IRQF_TRIGGER_HIGH
;
3132 irq_flags
|= IRQF_ONESHOT
;
3134 error
= devm_request_threaded_irq(&client
->dev
, irq
, NULL
, iqs7222_irq
,
3135 irq_flags
, client
->name
, iqs7222
);
3137 dev_err(&client
->dev
, "Failed to request IRQ: %d\n", error
);
3142 static const struct of_device_id iqs7222_of_match
[] = {
3143 { .compatible
= "azoteq,iqs7222a" },
3144 { .compatible
= "azoteq,iqs7222b" },
3145 { .compatible
= "azoteq,iqs7222c" },
3146 { .compatible
= "azoteq,iqs7222d" },
3149 MODULE_DEVICE_TABLE(of
, iqs7222_of_match
);
3151 static struct i2c_driver iqs7222_i2c_driver
= {
3154 .of_match_table
= iqs7222_of_match
,
3156 .probe
= iqs7222_probe
,
3158 module_i2c_driver(iqs7222_i2c_driver
);
3160 MODULE_AUTHOR("Jeff LaBundy <jeff@labundy.com>");
3161 MODULE_DESCRIPTION("Azoteq IQS7222A/B/C/D Capacitive Touch Controller");
3162 MODULE_LICENSE("GPL");