ALSPRX2
};
+static int tsl2x7x_clear_interrupts(struct tsl2X7X_chip *chip, int reg)
+{
+ int ret;
+
+ ret = i2c_smbus_write_byte(chip->client,
+ TSL2X7X_CMD_REG | TSL2X7X_CMD_SPL_FN | reg);
+ if (ret < 0)
+ dev_err(&chip->client->dev,
+ "%s: failed to clear interrupt status %x: %d\n",
+ __func__, reg, ret);
+
+ return ret;
+}
+
/**
* tsl2x7x_get_lux() - Reads and calculates current lux value.
* @indio_dev: pointer to IIO device
buf[i] = ret;
}
- /* clear any existing interrupt status */
- ret = i2c_smbus_write_byte(chip->client,
- TSL2X7X_CMD_REG |
- TSL2X7X_CMD_SPL_FN |
- TSL2X7X_CMD_ALS_INT_CLR);
- if (ret < 0) {
- dev_err(&chip->client->dev,
- "i2c_write_command failed - err = %d\n", ret);
- goto out_unlock; /* have no data, so return failure */
- }
+ ret = tsl2x7x_clear_interrupts(chip, TSL2X7X_CMD_ALS_INT_CLR);
+ if (ret < 0)
+ goto out_unlock;
/* extract ALS/lux data */
ch0 = le16_to_cpup((const __le16 *)&buf[0]);
"%s: failed in tsl2x7x_IOCTL_INT_SET.\n",
__func__);
- /* Clear out any initial interrupts */
- ret = i2c_smbus_write_byte(chip->client,
- TSL2X7X_CMD_REG |
- TSL2X7X_CMD_SPL_FN |
- TSL2X7X_CMD_PROXALS_INT_CLR);
- if (ret < 0) {
- dev_err(&chip->client->dev,
- "%s: Failed to clear Int status\n",
- __func__);
- return ret;
- }
+ ret = tsl2x7x_clear_interrupts(chip,
+ TSL2X7X_CMD_PROXALS_INT_CLR);
+ if (ret < 0)
+ return ret;
}
return ret;
IIO_EV_DIR_EITHER),
timestamp);
}
- /* Clear interrupt now that we have handled it. */
- ret = i2c_smbus_write_byte(chip->client,
- TSL2X7X_CMD_REG | TSL2X7X_CMD_SPL_FN |
- TSL2X7X_CMD_PROXALS_INT_CLR);
+
+ ret = tsl2x7x_clear_interrupts(chip, TSL2X7X_CMD_PROXALS_INT_CLR);
if (ret < 0)
- dev_err(&chip->client->dev,
- "Failed to clear irq from event handler. err = %d\n",
- ret);
+ return ret;
return IRQ_HANDLED;
}