9
9
* axial sliders presented by the device.
10
10
*/
11
11
12
+ #include <linux/completion.h>
12
13
#include <linux/delay.h>
13
14
#include <linux/device.h>
14
15
#include <linux/err.h>
144
145
#define IQS269_NUM_CH 8
145
146
#define IQS269_NUM_SL 2
146
147
147
- #define IQS269_ATI_POLL_SLEEP_US (iqs269->delay_mult * 10000)
148
- #define IQS269_ATI_POLL_TIMEOUT_US (iqs269->delay_mult * 500000)
149
- #define IQS269_ATI_STABLE_DELAY_MS (iqs269->delay_mult * 150)
150
-
151
148
#define iqs269_irq_wait () usleep_range(200, 250)
152
149
153
150
enum iqs269_local_cap_size {
@@ -289,10 +286,10 @@ struct iqs269_private {
289
286
struct mutex lock ;
290
287
struct iqs269_switch_desc switches [ARRAY_SIZE (iqs269_events )];
291
288
struct iqs269_sys_reg sys_reg ;
289
+ struct completion ati_done ;
292
290
struct input_dev * keypad ;
293
291
struct input_dev * slider [IQS269_NUM_SL ];
294
292
unsigned int keycode [ARRAY_SIZE (iqs269_events ) * IQS269_NUM_CH ];
295
- unsigned int delay_mult ;
296
293
unsigned int ch_num ;
297
294
bool hall_enable ;
298
295
bool ati_current ;
@@ -973,13 +970,8 @@ static int iqs269_parse_prop(struct iqs269_private *iqs269)
973
970
974
971
general = be16_to_cpu (sys_reg -> general );
975
972
976
- if (device_property_present (& client -> dev , "azoteq,clk-div" )) {
973
+ if (device_property_present (& client -> dev , "azoteq,clk-div" ))
977
974
general |= IQS269_SYS_SETTINGS_CLK_DIV ;
978
- iqs269 -> delay_mult = 4 ;
979
- } else {
980
- general &= ~IQS269_SYS_SETTINGS_CLK_DIV ;
981
- iqs269 -> delay_mult = 1 ;
982
- }
983
975
984
976
/*
985
977
* Configure the device to automatically switch between normal and low-
@@ -1036,7 +1028,6 @@ static int iqs269_parse_prop(struct iqs269_private *iqs269)
1036
1028
1037
1029
static int iqs269_dev_init (struct iqs269_private * iqs269 )
1038
1030
{
1039
- unsigned int val ;
1040
1031
int error ;
1041
1032
1042
1033
mutex_lock (& iqs269 -> lock );
@@ -1052,14 +1043,12 @@ static int iqs269_dev_init(struct iqs269_private *iqs269)
1052
1043
if (error )
1053
1044
goto err_mutex ;
1054
1045
1055
- error = regmap_read_poll_timeout (iqs269 -> regmap , IQS269_SYS_FLAGS , val ,
1056
- !(val & IQS269_SYS_FLAGS_IN_ATI ),
1057
- IQS269_ATI_POLL_SLEEP_US ,
1058
- IQS269_ATI_POLL_TIMEOUT_US );
1059
- if (error )
1060
- goto err_mutex ;
1046
+ /*
1047
+ * The following delay gives the device time to deassert its RDY output
1048
+ * so as to prevent an interrupt from being serviced prematurely.
1049
+ */
1050
+ usleep_range (2000 , 2100 );
1061
1051
1062
- msleep (IQS269_ATI_STABLE_DELAY_MS );
1063
1052
iqs269 -> ati_current = true;
1064
1053
1065
1054
err_mutex :
@@ -1071,10 +1060,8 @@ static int iqs269_dev_init(struct iqs269_private *iqs269)
1071
1060
static int iqs269_input_init (struct iqs269_private * iqs269 )
1072
1061
{
1073
1062
struct i2c_client * client = iqs269 -> client ;
1074
- struct iqs269_flags flags ;
1075
1063
unsigned int sw_code , keycode ;
1076
1064
int error , i , j ;
1077
- u8 dir_mask , state ;
1078
1065
1079
1066
iqs269 -> keypad = devm_input_allocate_device (& client -> dev );
1080
1067
if (!iqs269 -> keypad )
@@ -1087,23 +1074,7 @@ static int iqs269_input_init(struct iqs269_private *iqs269)
1087
1074
iqs269 -> keypad -> name = "iqs269a_keypad" ;
1088
1075
iqs269 -> keypad -> id .bustype = BUS_I2C ;
1089
1076
1090
- if (iqs269 -> hall_enable ) {
1091
- error = regmap_raw_read (iqs269 -> regmap , IQS269_SYS_FLAGS ,
1092
- & flags , sizeof (flags ));
1093
- if (error ) {
1094
- dev_err (& client -> dev ,
1095
- "Failed to read initial status: %d\n" , error );
1096
- return error ;
1097
- }
1098
- }
1099
-
1100
1077
for (i = 0 ; i < ARRAY_SIZE (iqs269_events ); i ++ ) {
1101
- dir_mask = flags .states [IQS269_ST_OFFS_DIR ];
1102
- if (!iqs269_events [i ].dir_up )
1103
- dir_mask = ~dir_mask ;
1104
-
1105
- state = flags .states [iqs269_events [i ].st_offs ] & dir_mask ;
1106
-
1107
1078
sw_code = iqs269 -> switches [i ].code ;
1108
1079
1109
1080
for (j = 0 ; j < IQS269_NUM_CH ; j ++ ) {
@@ -1116,13 +1087,9 @@ static int iqs269_input_init(struct iqs269_private *iqs269)
1116
1087
switch (j ) {
1117
1088
case IQS269_CHx_HALL_ACTIVE :
1118
1089
if (iqs269 -> hall_enable &&
1119
- iqs269 -> switches [i ].enabled ) {
1090
+ iqs269 -> switches [i ].enabled )
1120
1091
input_set_capability (iqs269 -> keypad ,
1121
1092
EV_SW , sw_code );
1122
- input_report_switch (iqs269 -> keypad ,
1123
- sw_code ,
1124
- state & BIT (j ));
1125
- }
1126
1093
fallthrough ;
1127
1094
1128
1095
case IQS269_CHx_HALL_INACTIVE :
@@ -1138,14 +1105,6 @@ static int iqs269_input_init(struct iqs269_private *iqs269)
1138
1105
}
1139
1106
}
1140
1107
1141
- input_sync (iqs269 -> keypad );
1142
-
1143
- error = input_register_device (iqs269 -> keypad );
1144
- if (error ) {
1145
- dev_err (& client -> dev , "Failed to register keypad: %d\n" , error );
1146
- return error ;
1147
- }
1148
-
1149
1108
for (i = 0 ; i < IQS269_NUM_SL ; i ++ ) {
1150
1109
if (!iqs269 -> sys_reg .slider_select [i ])
1151
1110
continue ;
@@ -1205,6 +1164,9 @@ static int iqs269_report(struct iqs269_private *iqs269)
1205
1164
return error ;
1206
1165
}
1207
1166
1167
+ if (be16_to_cpu (flags .system ) & IQS269_SYS_FLAGS_IN_ATI )
1168
+ return 0 ;
1169
+
1208
1170
error = regmap_raw_read (iqs269 -> regmap , IQS269_SLIDER_X , slider_x ,
1209
1171
sizeof (slider_x ));
1210
1172
if (error ) {
@@ -1267,6 +1229,12 @@ static int iqs269_report(struct iqs269_private *iqs269)
1267
1229
1268
1230
input_sync (iqs269 -> keypad );
1269
1231
1232
+ /*
1233
+ * The following completion signals that ATI has finished, any initial
1234
+ * switch states have been reported and the keypad can be registered.
1235
+ */
1236
+ complete_all (& iqs269 -> ati_done );
1237
+
1270
1238
return 0 ;
1271
1239
}
1272
1240
@@ -1298,6 +1266,9 @@ static ssize_t counts_show(struct device *dev,
1298
1266
if (!iqs269 -> ati_current || iqs269 -> hall_enable )
1299
1267
return - EPERM ;
1300
1268
1269
+ if (!completion_done (& iqs269 -> ati_done ))
1270
+ return - EBUSY ;
1271
+
1301
1272
/*
1302
1273
* Unsolicited I2C communication prompts the device to assert its RDY
1303
1274
* pin, so disable the interrupt line until the operation is finished
@@ -1554,7 +1525,9 @@ static ssize_t ati_trigger_show(struct device *dev,
1554
1525
{
1555
1526
struct iqs269_private * iqs269 = dev_get_drvdata (dev );
1556
1527
1557
- return scnprintf (buf , PAGE_SIZE , "%u\n" , iqs269 -> ati_current );
1528
+ return scnprintf (buf , PAGE_SIZE , "%u\n" ,
1529
+ iqs269 -> ati_current &&
1530
+ completion_done (& iqs269 -> ati_done ));
1558
1531
}
1559
1532
1560
1533
static ssize_t ati_trigger_store (struct device * dev ,
@@ -1574,6 +1547,7 @@ static ssize_t ati_trigger_store(struct device *dev,
1574
1547
return count ;
1575
1548
1576
1549
disable_irq (client -> irq );
1550
+ reinit_completion (& iqs269 -> ati_done );
1577
1551
1578
1552
error = iqs269_dev_init (iqs269 );
1579
1553
@@ -1583,6 +1557,10 @@ static ssize_t ati_trigger_store(struct device *dev,
1583
1557
if (error )
1584
1558
return error ;
1585
1559
1560
+ if (!wait_for_completion_timeout (& iqs269 -> ati_done ,
1561
+ msecs_to_jiffies (2000 )))
1562
+ return - ETIMEDOUT ;
1563
+
1586
1564
return count ;
1587
1565
}
1588
1566
@@ -1641,6 +1619,7 @@ static int iqs269_probe(struct i2c_client *client)
1641
1619
}
1642
1620
1643
1621
mutex_init (& iqs269 -> lock );
1622
+ init_completion (& iqs269 -> ati_done );
1644
1623
1645
1624
error = regmap_raw_read (iqs269 -> regmap , IQS269_VER_INFO , & ver_info ,
1646
1625
sizeof (ver_info ));
@@ -1676,6 +1655,22 @@ static int iqs269_probe(struct i2c_client *client)
1676
1655
return error ;
1677
1656
}
1678
1657
1658
+ if (!wait_for_completion_timeout (& iqs269 -> ati_done ,
1659
+ msecs_to_jiffies (2000 ))) {
1660
+ dev_err (& client -> dev , "Failed to complete ATI\n" );
1661
+ return - ETIMEDOUT ;
1662
+ }
1663
+
1664
+ /*
1665
+ * The keypad may include one or more switches and is not registered
1666
+ * until ATI is complete and the initial switch states are read.
1667
+ */
1668
+ error = input_register_device (iqs269 -> keypad );
1669
+ if (error ) {
1670
+ dev_err (& client -> dev , "Failed to register keypad: %d\n" , error );
1671
+ return error ;
1672
+ }
1673
+
1679
1674
error = devm_device_add_group (& client -> dev , & iqs269_attr_group );
1680
1675
if (error )
1681
1676
dev_err (& client -> dev , "Failed to add attributes: %d\n" , error );
0 commit comments