Skip to content

Commit 57a1592

Browse files
jwrdegoedejic23
authored andcommitted
iio: accel: mxc4005: Interrupt handling fixes
There are 2 issues with interrupt handling in the mxc4005 driver: 1. mxc4005_set_trigger_state() writes MXC4005_REG_INT_MASK1_BIT_DRDYE (0x01) to INT_MASK1 to enable the interrupt, but to disable the interrupt it writes ~MXC4005_REG_INT_MASK1_BIT_DRDYE which is 0xfe, so it enables all other interrupt sources in the INT_SRC1 register. On the MXC4005 this is not an issue because only bit 0 of the register is used. On the MXC6655 OTOH this is a problem since bit7 is used as TC (Temperature Compensation) disable bit and writing 1 to this disables Temperature Compensation which should only be done when running self-tests on the chip. Write 0 instead of ~MXC4005_REG_INT_MASK1_BIT_DRDYE to disable the interrupts to fix this. 2. The datasheets for the MXC4005 / MXC6655 do not state what the reset value for the INT_MASK0 and INT_MASK1 registers is and since these are write only we also cannot learn this from the hw. Presumably the reset value for both is all 0, which means all interrupts disabled. Explicitly set both registers to 0 from mxc4005_chip_init() to ensure both masks are actually set to 0. Fixes: 79846e3 ("iio: accel: mxc4005: add support for mxc6655") Signed-off-by: Hans de Goede <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 89384a2 commit 57a1592

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

drivers/iio/accel/mxc4005.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@
2727
#define MXC4005_REG_ZOUT_UPPER 0x07
2828
#define MXC4005_REG_ZOUT_LOWER 0x08
2929

30+
#define MXC4005_REG_INT_MASK0 0x0A
31+
3032
#define MXC4005_REG_INT_MASK1 0x0B
3133
#define MXC4005_REG_INT_MASK1_BIT_DRDYE 0x01
3234

35+
#define MXC4005_REG_INT_CLR0 0x00
36+
3337
#define MXC4005_REG_INT_CLR1 0x01
3438
#define MXC4005_REG_INT_CLR1_BIT_DRDYC 0x01
3539

@@ -113,7 +117,9 @@ static bool mxc4005_is_readable_reg(struct device *dev, unsigned int reg)
113117
static bool mxc4005_is_writeable_reg(struct device *dev, unsigned int reg)
114118
{
115119
switch (reg) {
120+
case MXC4005_REG_INT_CLR0:
116121
case MXC4005_REG_INT_CLR1:
122+
case MXC4005_REG_INT_MASK0:
117123
case MXC4005_REG_INT_MASK1:
118124
case MXC4005_REG_CONTROL:
119125
return true;
@@ -330,17 +336,13 @@ static int mxc4005_set_trigger_state(struct iio_trigger *trig,
330336
{
331337
struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
332338
struct mxc4005_data *data = iio_priv(indio_dev);
339+
unsigned int val;
333340
int ret;
334341

335342
mutex_lock(&data->mutex);
336-
if (state) {
337-
ret = regmap_write(data->regmap, MXC4005_REG_INT_MASK1,
338-
MXC4005_REG_INT_MASK1_BIT_DRDYE);
339-
} else {
340-
ret = regmap_write(data->regmap, MXC4005_REG_INT_MASK1,
341-
~MXC4005_REG_INT_MASK1_BIT_DRDYE);
342-
}
343343

344+
val = state ? MXC4005_REG_INT_MASK1_BIT_DRDYE : 0;
345+
ret = regmap_write(data->regmap, MXC4005_REG_INT_MASK1, val);
344346
if (ret < 0) {
345347
mutex_unlock(&data->mutex);
346348
dev_err(data->dev, "failed to update reg_int_mask1");
@@ -382,6 +384,14 @@ static int mxc4005_chip_init(struct mxc4005_data *data)
382384

383385
dev_dbg(data->dev, "MXC4005 chip id %02x\n", reg);
384386

387+
ret = regmap_write(data->regmap, MXC4005_REG_INT_MASK0, 0);
388+
if (ret < 0)
389+
return dev_err_probe(data->dev, ret, "writing INT_MASK0\n");
390+
391+
ret = regmap_write(data->regmap, MXC4005_REG_INT_MASK1, 0);
392+
if (ret < 0)
393+
return dev_err_probe(data->dev, ret, "writing INT_MASK1\n");
394+
385395
return 0;
386396
}
387397

0 commit comments

Comments
 (0)