};
static const struct tsl2x7x_settings tsl2x7x_default_settings = {
- .als_time = 255, /* 2.73 ms */
+ .als_time = 255, /* 2.72 / 2.73 ms */
.als_gain = 0,
- .prox_time = 255, /* 2.73 ms */
+ .prox_time = 255, /* 2.72 / 2.73 ms */
.prox_gain = 0,
.wait_time = 255,
.als_prox_config = 0,
8
};
+static const int tsl2x7x_int_time_avail[][6] = {
+ [tsl2571] = { 0, 2720, 0, 2720, 0, 696000 },
+ [tsl2671] = { 0, 2720, 0, 2720, 0, 696000 },
+ [tmd2671] = { 0, 2720, 0, 2720, 0, 696000 },
+ [tsl2771] = { 0, 2720, 0, 2720, 0, 696000 },
+ [tmd2771] = { 0, 2720, 0, 2720, 0, 696000 },
+ [tsl2572] = { 0, 2730, 0, 2730, 0, 699000 },
+ [tsl2672] = { 0, 2730, 0, 2730, 0, 699000 },
+ [tmd2672] = { 0, 2730, 0, 2730, 0, 699000 },
+ [tsl2772] = { 0, 2730, 0, 2730, 0, 699000 },
+ [tmd2772] = { 0, 2730, 0, 2730, 0, 699000 },
+};
+
+static int tsl2x7x_int_calibscale_avail[] = { 1, 8, 16, 120 };
+
+static int tsl2x7x_prox_calibscale_avail[] = { 1, 2, 4, 8 };
+
/* Channel variations */
enum {
ALS,
/* set chip time scaling and saturation */
als_count = 256 - chip->settings.als_time;
- als_time_us = als_count * 2720;
+ als_time_us = als_count * tsl2x7x_int_time_avail[chip->id][3];
chip->als_saturation = als_count * 768; /* 75% of full scale */
chip->als_gain_time_scale = als_time_us *
tsl2x7x_als_gain[chip->settings.als_gain];
return tsl2x7x_invoke_change(indio_dev);
}
-static IIO_CONST_ATTR(in_intensity0_calibscale_available, "1 8 16 120");
+static int tsl2x7x_read_avail(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ const int **vals, int *type, int *length,
+ long mask)
+{
+ struct tsl2X7X_chip *chip = iio_priv(indio_dev);
-static IIO_CONST_ATTR(in_proximity0_calibscale_available, "1 2 4 8");
+ switch (mask) {
+ case IIO_CHAN_INFO_CALIBSCALE:
+ if (chan->type == IIO_INTENSITY) {
+ *length = ARRAY_SIZE(tsl2x7x_int_calibscale_avail);
+ *vals = tsl2x7x_int_calibscale_avail;
+ } else {
+ *length = ARRAY_SIZE(tsl2x7x_prox_calibscale_avail);
+ *vals = tsl2x7x_prox_calibscale_avail;
+ }
+ *type = IIO_VAL_INT;
+ return IIO_AVAIL_LIST;
+ case IIO_CHAN_INFO_INT_TIME:
+ *length = ARRAY_SIZE(tsl2x7x_int_time_avail[chip->id]);
+ *vals = tsl2x7x_int_time_avail[chip->id];
+ *type = IIO_VAL_INT_PLUS_MICRO;
+ return IIO_AVAIL_RANGE;
+ }
-static IIO_CONST_ATTR(in_intensity0_integration_time_available,
- ".00272 - .696");
+ return -EINVAL;
+}
static ssize_t in_illuminance0_target_input_show(struct device *dev,
struct device_attribute *attr,
return IIO_VAL_INT;
case IIO_CHAN_INFO_INT_TIME:
*val = 0;
- *val2 = (256 - chip->settings.als_time) * 2720;
+ *val2 = (256 - chip->settings.als_time) *
+ tsl2x7x_int_time_avail[chip->id][3];
return IIO_VAL_INT_PLUS_MICRO;
default:
return -EINVAL;
chip->settings.als_gain_trim = val;
break;
case IIO_CHAN_INFO_INT_TIME:
- chip->settings.als_time = 256 - (val2 / 2720);
+ chip->settings.als_time = 256 -
+ (val2 / tsl2x7x_int_time_avail[chip->id][3]);
break;
default:
return -EINVAL;
}
static struct attribute *tsl2x7x_ALS_device_attrs[] = {
- &iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
- &iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
&dev_attr_in_illuminance0_target_input.attr,
&dev_attr_in_illuminance0_calibrate.attr,
&dev_attr_in_illuminance0_lux_table.attr,
};
static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = {
- &iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
- &iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
&dev_attr_in_illuminance0_target_input.attr,
&dev_attr_in_illuminance0_calibrate.attr,
&dev_attr_in_illuminance0_lux_table.attr,
static struct attribute *tsl2x7x_PRX2_device_attrs[] = {
&dev_attr_in_proximity0_calibrate.attr,
- &iio_const_attr_in_proximity0_calibscale_available.dev_attr.attr,
NULL
};
static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = {
- &iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
- &iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
&dev_attr_in_illuminance0_target_input.attr,
&dev_attr_in_illuminance0_calibrate.attr,
&dev_attr_in_illuminance0_lux_table.attr,
&dev_attr_in_proximity0_calibrate.attr,
- &iio_const_attr_in_proximity0_calibscale_available.dev_attr.attr,
NULL
};
{ \
.attrs = &tsl2X7X_device_attr_group_tbl[type], \
.read_raw = &tsl2x7x_read_raw, \
+ .read_avail = &tsl2x7x_read_avail, \
.write_raw = &tsl2x7x_write_raw, \
.read_event_value = &tsl2x7x_read_event_value, \
.write_event_value = &tsl2x7x_write_event_value, \
BIT(IIO_CHAN_INFO_INT_TIME) |
BIT(IIO_CHAN_INFO_CALIBSCALE) |
BIT(IIO_CHAN_INFO_CALIBBIAS),
+ .info_mask_separate_available =
+ BIT(IIO_CHAN_INFO_INT_TIME) |
+ BIT(IIO_CHAN_INFO_CALIBSCALE),
.event_spec = tsl2x7x_events,
.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
}, {
BIT(IIO_CHAN_INFO_INT_TIME) |
BIT(IIO_CHAN_INFO_CALIBSCALE) |
BIT(IIO_CHAN_INFO_CALIBBIAS),
+ .info_mask_separate_available =
+ BIT(IIO_CHAN_INFO_INT_TIME) |
+ BIT(IIO_CHAN_INFO_CALIBSCALE),
}, {
.type = IIO_INTENSITY,
.indexed = 1,
BIT(IIO_CHAN_INFO_INT_TIME) |
BIT(IIO_CHAN_INFO_CALIBSCALE) |
BIT(IIO_CHAN_INFO_CALIBBIAS),
+ .info_mask_separate_available =
+ BIT(IIO_CHAN_INFO_INT_TIME) |
+ BIT(IIO_CHAN_INFO_CALIBSCALE),
.event_spec = tsl2x7x_events,
.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
}, {
BIT(IIO_CHAN_INFO_INT_TIME) |
BIT(IIO_CHAN_INFO_CALIBSCALE) |
BIT(IIO_CHAN_INFO_CALIBBIAS),
+ .info_mask_separate_available =
+ BIT(IIO_CHAN_INFO_INT_TIME) |
+ BIT(IIO_CHAN_INFO_CALIBSCALE),
}, {
.type = IIO_INTENSITY,
.indexed = 1,
.channel = 0,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_CALIBSCALE),
+ .info_mask_separate_available =
+ BIT(IIO_CHAN_INFO_CALIBSCALE),
.event_spec = tsl2x7x_events,
.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
},
.channel = 0,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_CALIBSCALE),
+ .info_mask_separate_available =
+ BIT(IIO_CHAN_INFO_CALIBSCALE),
},
},
.chan_table_elements = 1,
BIT(IIO_CHAN_INFO_INT_TIME) |
BIT(IIO_CHAN_INFO_CALIBSCALE) |
BIT(IIO_CHAN_INFO_CALIBBIAS),
+ .info_mask_separate_available =
+ BIT(IIO_CHAN_INFO_INT_TIME) |
+ BIT(IIO_CHAN_INFO_CALIBSCALE),
.event_spec = tsl2x7x_events,
.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
}, {
.channel = 0,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_CALIBSCALE),
+ .info_mask_separate_available =
+ BIT(IIO_CHAN_INFO_CALIBSCALE),
.event_spec = tsl2x7x_events,
.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
},
BIT(IIO_CHAN_INFO_INT_TIME) |
BIT(IIO_CHAN_INFO_CALIBSCALE) |
BIT(IIO_CHAN_INFO_CALIBBIAS),
+ .info_mask_separate_available =
+ BIT(IIO_CHAN_INFO_INT_TIME) |
+ BIT(IIO_CHAN_INFO_CALIBSCALE),
}, {
.type = IIO_INTENSITY,
.indexed = 1,
.channel = 0,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_CALIBSCALE),
+ .info_mask_separate_available =
+ BIT(IIO_CHAN_INFO_CALIBSCALE),
},
},
.chan_table_elements = 4,