struct isl29018_chip {
struct i2c_client *client;
struct mutex lock;
+ unsigned int lux_scale;
unsigned int range;
unsigned int adc_bit;
int prox_scheme;
if (lux_data < 0)
return lux_data;
- *lux = (lux_data * chip->range) >> chip->adc_bit;
+ *lux = (lux_data * chip->range * chip->lux_scale) >> chip->adc_bit;
return 0;
}
}
/* Sysfs interface */
+/* lux_scale */
+static ssize_t show_lux_scale(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct isl29018_chip *chip = indio_dev->dev_data;
+
+ return sprintf(buf, "%d\n", chip->lux_scale);
+}
+
+static ssize_t store_lux_scale(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct isl29018_chip *chip = indio_dev->dev_data;
+ unsigned long lval;
+
+ lval = simple_strtoul(buf, NULL, 10);
+ if (lval == 0)
+ return -EINVAL;
+
+ mutex_lock(&chip->lock);
+ chip->lux_scale = lval;
+ mutex_unlock(&chip->lock);
+
+ return count;
+}
+
/* range */
static ssize_t show_range(struct device *dev,
struct device_attribute *attr, char *buf)
show_prox_infrared_supression,
store_prox_infrared_supression, 0);
static IIO_DEVICE_ATTR(illuminance0_input, S_IRUGO, show_lux, NULL, 0);
+static IIO_DEVICE_ATTR(illuminance0_calibscale, S_IRUGO | S_IWUSR,
+ show_lux_scale, store_lux_scale, 0);
static IIO_DEVICE_ATTR(intensity_infrared_raw, S_IRUGO, show_ir, NULL, 0);
static IIO_DEVICE_ATTR(proximity_raw, S_IRUGO, show_proxim_ir, NULL, 0);
ISL29018_CONST_ATTR(adc_resolution_available),
ISL29018_DEV_ATTR(proximity_on_chip_ambient_infrared_supression),
ISL29018_DEV_ATTR(illuminance0_input),
+ ISL29018_DEV_ATTR(illuminance0_calibscale),
ISL29018_DEV_ATTR(intensity_infrared_raw),
ISL29018_DEV_ATTR(proximity_raw),
NULL
mutex_init(&chip->lock);
+ chip->lux_scale = 1;
chip->range = 1000;
chip->adc_bit = 16;