Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Input: iqs269a - do not poll during ATI

After initial start-up, the driver triggers ATI (calibration) with
the newly loaded register configuration in place. Next, the driver
polls a register field to ensure ATI completed in a timely fashion
and that the device is ready to sense.

However, communicating with the device over I2C while ATI is under-
way may induce noise in the device and cause ATI to fail. As such,
the vendor recommends not to poll the device during ATI.

To solve this problem, let the device naturally signal to the host
that ATI is complete by way of an interrupt. A completion prevents
the device from successfully probing until this happens.

As an added benefit, initial switch states are now reported in the
interrupt handler at the same time ATI status is checked. As such,
duplicate code that reports initial switch states has been removed
from iqs269_input_init().

The former logic that scaled ATI timeout and filter settling delay
is not carried forward with the new implementation, as it produces
overly conservative delays at the lower clock rate.

Rather, a single timeout that covers both clock rates is used. The
filter settling delay does not happen to be necessary and has been
removed as well.

Fixes: 04e49867fad1 ("Input: add support for Azoteq IQS269A")
Signed-off-by: Jeff LaBundy <jeff@labundy.com>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Link: https://lore.kernel.org/r/Y7RtB2T7AF9rYMjK@nixie71
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Jeff LaBundy and committed by
Dmitry Torokhov
b08134eb 18ab69c8

+46 -51
+46 -51
drivers/input/misc/iqs269a.c
··· 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 143 145 144 #define IQS269_NUM_CH 8 146 145 #define IQS269_NUM_SL 2 147 - 148 - #define IQS269_ATI_POLL_SLEEP_US (iqs269->delay_mult * 10000) 149 - #define IQS269_ATI_POLL_TIMEOUT_US (iqs269->delay_mult * 500000) 150 - #define IQS269_ATI_STABLE_DELAY_MS (iqs269->delay_mult * 150) 151 146 152 147 #define iqs269_irq_wait() usleep_range(200, 250) 153 148 ··· 286 289 struct mutex lock; 287 290 struct iqs269_switch_desc switches[ARRAY_SIZE(iqs269_events)]; 288 291 struct iqs269_sys_reg sys_reg; 292 + struct completion ati_done; 289 293 struct input_dev *keypad; 290 294 struct input_dev *slider[IQS269_NUM_SL]; 291 295 unsigned int keycode[ARRAY_SIZE(iqs269_events) * IQS269_NUM_CH]; 292 - unsigned int delay_mult; 293 296 unsigned int ch_num; 294 297 bool hall_enable; 295 298 bool ati_current; ··· 970 973 971 974 general = be16_to_cpu(sys_reg->general); 972 975 973 - if (device_property_present(&client->dev, "azoteq,clk-div")) { 976 + if (device_property_present(&client->dev, "azoteq,clk-div")) 974 977 general |= IQS269_SYS_SETTINGS_CLK_DIV; 975 - iqs269->delay_mult = 4; 976 - } else { 977 - general &= ~IQS269_SYS_SETTINGS_CLK_DIV; 978 - iqs269->delay_mult = 1; 979 - } 980 978 981 979 /* 982 980 * Configure the device to automatically switch between normal and low- ··· 1028 1036 1029 1037 static int iqs269_dev_init(struct iqs269_private *iqs269) 1030 1038 { 1031 - unsigned int val; 1032 1039 int error; 1033 1040 1034 1041 mutex_lock(&iqs269->lock); ··· 1043 1052 if (error) 1044 1053 goto err_mutex; 1045 1054 1046 - error = regmap_read_poll_timeout(iqs269->regmap, IQS269_SYS_FLAGS, val, 1047 - !(val & IQS269_SYS_FLAGS_IN_ATI), 1048 - IQS269_ATI_POLL_SLEEP_US, 1049 - IQS269_ATI_POLL_TIMEOUT_US); 1050 - if (error) 1051 - goto err_mutex; 1055 + /* 1056 + * The following delay gives the device time to deassert its RDY output 1057 + * so as to prevent an interrupt from being serviced prematurely. 1058 + */ 1059 + usleep_range(2000, 2100); 1052 1060 1053 - msleep(IQS269_ATI_STABLE_DELAY_MS); 1054 1061 iqs269->ati_current = true; 1055 1062 1056 1063 err_mutex: ··· 1060 1071 static int iqs269_input_init(struct iqs269_private *iqs269) 1061 1072 { 1062 1073 struct i2c_client *client = iqs269->client; 1063 - struct iqs269_flags flags; 1064 1074 unsigned int sw_code, keycode; 1065 1075 int error, i, j; 1066 - u8 dir_mask, state; 1067 1076 1068 1077 iqs269->keypad = devm_input_allocate_device(&client->dev); 1069 1078 if (!iqs269->keypad) ··· 1074 1087 iqs269->keypad->name = "iqs269a_keypad"; 1075 1088 iqs269->keypad->id.bustype = BUS_I2C; 1076 1089 1077 - if (iqs269->hall_enable) { 1078 - error = regmap_raw_read(iqs269->regmap, IQS269_SYS_FLAGS, 1079 - &flags, sizeof(flags)); 1080 - if (error) { 1081 - dev_err(&client->dev, 1082 - "Failed to read initial status: %d\n", error); 1083 - return error; 1084 - } 1085 - } 1086 - 1087 1090 for (i = 0; i < ARRAY_SIZE(iqs269_events); i++) { 1088 - dir_mask = flags.states[IQS269_ST_OFFS_DIR]; 1089 - if (!iqs269_events[i].dir_up) 1090 - dir_mask = ~dir_mask; 1091 - 1092 - state = flags.states[iqs269_events[i].st_offs] & dir_mask; 1093 - 1094 1091 sw_code = iqs269->switches[i].code; 1095 1092 1096 1093 for (j = 0; j < IQS269_NUM_CH; j++) { ··· 1087 1116 switch (j) { 1088 1117 case IQS269_CHx_HALL_ACTIVE: 1089 1118 if (iqs269->hall_enable && 1090 - iqs269->switches[i].enabled) { 1119 + iqs269->switches[i].enabled) 1091 1120 input_set_capability(iqs269->keypad, 1092 1121 EV_SW, sw_code); 1093 - input_report_switch(iqs269->keypad, 1094 - sw_code, 1095 - state & BIT(j)); 1096 - } 1097 1122 fallthrough; 1098 1123 1099 1124 case IQS269_CHx_HALL_INACTIVE: ··· 1103 1136 EV_KEY, keycode); 1104 1137 } 1105 1138 } 1106 - } 1107 - 1108 - input_sync(iqs269->keypad); 1109 - 1110 - error = input_register_device(iqs269->keypad); 1111 - if (error) { 1112 - dev_err(&client->dev, "Failed to register keypad: %d\n", error); 1113 - return error; 1114 1139 } 1115 1140 1116 1141 for (i = 0; i < IQS269_NUM_SL; i++) { ··· 1163 1204 1164 1205 return error; 1165 1206 } 1207 + 1208 + if (be16_to_cpu(flags.system) & IQS269_SYS_FLAGS_IN_ATI) 1209 + return 0; 1166 1210 1167 1211 error = regmap_raw_read(iqs269->regmap, IQS269_SLIDER_X, slider_x, 1168 1212 sizeof(slider_x)); ··· 1229 1267 1230 1268 input_sync(iqs269->keypad); 1231 1269 1270 + /* 1271 + * The following completion signals that ATI has finished, any initial 1272 + * switch states have been reported and the keypad can be registered. 1273 + */ 1274 + complete_all(&iqs269->ati_done); 1275 + 1232 1276 return 0; 1233 1277 } 1234 1278 ··· 1265 1297 1266 1298 if (!iqs269->ati_current || iqs269->hall_enable) 1267 1299 return -EPERM; 1300 + 1301 + if (!completion_done(&iqs269->ati_done)) 1302 + return -EBUSY; 1268 1303 1269 1304 /* 1270 1305 * Unsolicited I2C communication prompts the device to assert its RDY ··· 1525 1554 { 1526 1555 struct iqs269_private *iqs269 = dev_get_drvdata(dev); 1527 1556 1528 - return scnprintf(buf, PAGE_SIZE, "%u\n", iqs269->ati_current); 1557 + return scnprintf(buf, PAGE_SIZE, "%u\n", 1558 + iqs269->ati_current && 1559 + completion_done(&iqs269->ati_done)); 1529 1560 } 1530 1561 1531 1562 static ssize_t ati_trigger_store(struct device *dev, ··· 1547 1574 return count; 1548 1575 1549 1576 disable_irq(client->irq); 1577 + reinit_completion(&iqs269->ati_done); 1550 1578 1551 1579 error = iqs269_dev_init(iqs269); 1552 1580 ··· 1556 1582 1557 1583 if (error) 1558 1584 return error; 1585 + 1586 + if (!wait_for_completion_timeout(&iqs269->ati_done, 1587 + msecs_to_jiffies(2000))) 1588 + return -ETIMEDOUT; 1559 1589 1560 1590 return count; 1561 1591 } ··· 1619 1641 } 1620 1642 1621 1643 mutex_init(&iqs269->lock); 1644 + init_completion(&iqs269->ati_done); 1622 1645 1623 1646 error = regmap_raw_read(iqs269->regmap, IQS269_VER_INFO, &ver_info, 1624 1647 sizeof(ver_info)); ··· 1652 1673 client->name, iqs269); 1653 1674 if (error) { 1654 1675 dev_err(&client->dev, "Failed to request IRQ: %d\n", error); 1676 + return error; 1677 + } 1678 + 1679 + if (!wait_for_completion_timeout(&iqs269->ati_done, 1680 + msecs_to_jiffies(2000))) { 1681 + dev_err(&client->dev, "Failed to complete ATI\n"); 1682 + return -ETIMEDOUT; 1683 + } 1684 + 1685 + /* 1686 + * The keypad may include one or more switches and is not registered 1687 + * until ATI is complete and the initial switch states are read. 1688 + */ 1689 + error = input_register_device(iqs269->keypad); 1690 + if (error) { 1691 + dev_err(&client->dev, "Failed to register keypad: %d\n", error); 1655 1692 return error; 1656 1693 } 1657 1694