Commit 8f75bc33 authored by Damien Riegel's avatar Damien Riegel Committed by Dmitry Torokhov

Input: tca8418 - enable interrupt after it has been requested

Currently, enabling keypad interrupts is one of the first operations
done on the keypad, even before the interrupt is requested, so there is
a small time window where the keypad can fire interrupts but the driver
is not yet ready to handle them. It's fine for level interrupts because
they will be handled anyway, but not so much for edge ones.

This commit modifies and moves the function in charge of configuring the
keypad. Enabling interrupts is now the last thing done on the keypad,
and after the interrupt has been requested by the driver.

Writing to the config register was also used to determine if the device
was indeed present on the bus or not, this has been replaced by reading
the lock/event count register to keep the same functionality.
Signed-off-by: default avatarDamien Riegel <damien.riegel@savoirfairelinux.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent c9bfb2f0
...@@ -234,14 +234,7 @@ static irqreturn_t tca8418_irq_handler(int irq, void *dev_id) ...@@ -234,14 +234,7 @@ static irqreturn_t tca8418_irq_handler(int irq, void *dev_id)
static int tca8418_configure(struct tca8418_keypad *keypad_data, static int tca8418_configure(struct tca8418_keypad *keypad_data,
u32 rows, u32 cols) u32 rows, u32 cols)
{ {
int reg, error; int reg, error = 0;
/* Write config register, if this fails assume device not present */
error = tca8418_write_byte(keypad_data, REG_CFG,
CFG_INT_CFG | CFG_OVR_FLOW_IEN | CFG_KE_IEN);
if (error < 0)
return -ENODEV;
/* Assemble a mask for row and column registers */ /* Assemble a mask for row and column registers */
reg = ~(~0 << rows); reg = ~(~0 << rows);
...@@ -257,6 +250,12 @@ static int tca8418_configure(struct tca8418_keypad *keypad_data, ...@@ -257,6 +250,12 @@ static int tca8418_configure(struct tca8418_keypad *keypad_data,
error |= tca8418_write_byte(keypad_data, REG_DEBOUNCE_DIS2, reg >> 8); error |= tca8418_write_byte(keypad_data, REG_DEBOUNCE_DIS2, reg >> 8);
error |= tca8418_write_byte(keypad_data, REG_DEBOUNCE_DIS3, reg >> 16); error |= tca8418_write_byte(keypad_data, REG_DEBOUNCE_DIS3, reg >> 16);
if (error)
return error;
error = tca8418_write_byte(keypad_data, REG_CFG,
CFG_INT_CFG | CFG_OVR_FLOW_IEN | CFG_KE_IEN);
return error; return error;
} }
...@@ -268,6 +267,7 @@ static int tca8418_keypad_probe(struct i2c_client *client, ...@@ -268,6 +267,7 @@ static int tca8418_keypad_probe(struct i2c_client *client,
struct input_dev *input; struct input_dev *input;
u32 rows = 0, cols = 0; u32 rows = 0, cols = 0;
int error, row_shift, max_keys; int error, row_shift, max_keys;
u8 reg;
/* Check i2c driver capabilities */ /* Check i2c driver capabilities */
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE)) { if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE)) {
...@@ -301,10 +301,10 @@ static int tca8418_keypad_probe(struct i2c_client *client, ...@@ -301,10 +301,10 @@ static int tca8418_keypad_probe(struct i2c_client *client,
keypad_data->client = client; keypad_data->client = client;
keypad_data->row_shift = row_shift; keypad_data->row_shift = row_shift;
/* Initialize the chip or fail if chip isn't present */ /* Read key lock register, if this fails assume device not present */
error = tca8418_configure(keypad_data, rows, cols); error = tca8418_read_byte(keypad_data, REG_KEY_LCK_EC, &reg);
if (error < 0) if (error)
return error; return -ENODEV;
/* Configure input device */ /* Configure input device */
input = devm_input_allocate_device(dev); input = devm_input_allocate_device(dev);
...@@ -340,6 +340,11 @@ static int tca8418_keypad_probe(struct i2c_client *client, ...@@ -340,6 +340,11 @@ static int tca8418_keypad_probe(struct i2c_client *client,
return error; return error;
} }
/* Initialize the chip */
error = tca8418_configure(keypad_data, rows, cols);
if (error < 0)
return error;
error = input_register_device(input); error = input_register_device(input);
if (error) { if (error) {
dev_err(dev, "Unable to register input device, error: %d\n", dev_err(dev, "Unable to register input device, error: %d\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment