#define ISL_ALS_I2C_ADDR 0x44
#define TAOS_ALS_I2C_ADDR 0x29
+#define MAX_I2C_DEVICE_DEFERRALS 5
+
static struct i2c_client *als;
static struct i2c_client *tp;
static struct i2c_client *ts;
I2C_ADAPTER_DESIGNWARE_1,
};
+enum i2c_peripheral_state {
+ UNPROBED = 0,
+ PROBED,
+ TIMEDOUT,
+};
+
struct i2c_peripheral {
int (*add)(enum i2c_adapter_type type);
enum i2c_adapter_type type;
+ enum i2c_peripheral_state state;
+ int tries;
};
#define MAX_I2C_PERIPHERALS 3
/* add the i2c device */
client = i2c_new_probed_device(adapter, info, addrs, NULL);
if (!client)
- pr_err("%s failed to register device %d-%02x\n",
- __func__, bus, info->addr);
+ pr_notice("%s failed to register device %d-%02x\n",
+ __func__, bus, info->addr);
else
pr_debug("%s added i2c device %d-%02x\n",
__func__, bus, info->addr);
if (i2c_dev->add == NULL)
break;
- /* Add the device. Set -EPROBE_DEFER on any failure */
- if (i2c_dev->add(i2c_dev->type))
+ if (i2c_dev->state == TIMEDOUT || i2c_dev->state == PROBED)
+ continue;
+
+ /*
+ * Check that the i2c adapter is present.
+ * -EPROBE_DEFER if missing as the adapter may appear much
+ * later.
+ */
+ if (find_i2c_adapter_num(i2c_dev->type) == -ENODEV) {
ret = -EPROBE_DEFER;
+ continue;
+ }
+
+ /* Add the device. */
+ if (i2c_dev->add(i2c_dev->type) == -EAGAIN) {
+ /*
+ * Set -EPROBE_DEFER a limited num of times
+ * if device is not successfully added.
+ */
+ if (++i2c_dev->tries < MAX_I2C_DEVICE_DEFERRALS) {
+ ret = -EPROBE_DEFER;
+ } else {
+ /* Ran out of tries. */
+ pr_notice("%s: Ran out of tries for device.\n",
+ __func__);
+ i2c_dev->state = TIMEDOUT;
+ }
+ } else {
+ i2c_dev->state = PROBED;
+ }
}
return ret;