summaryrefslogtreecommitdiff
path: root/drivers/iio/light
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-01-19 10:40:44 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-01-19 10:40:44 +0100
commit4463c3e72dd3058eda8b3d806f1f186c5ddad232 (patch)
tree3ffd9e46a059023b4579c716248eb8628a3ea578 /drivers/iio/light
parent1fac9c5a6c2ad7096a9521e2c637cf0b28ee597b (diff)
parente30eca0e69cb888125b081c96ca761e958fcb5b4 (diff)
Merge tag 'iio-for-4.11a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next
Jonathan writes: First round of new device support, features and cleanups for IIO in the 4.11 cycle. It's shaping to be another fairly busy cycle. Lots more on the way! New device support * ads7950 - new driver supporting ads7950, ads7951, ads7952, ads7953, ads7954, ads7955, ads7956, ads7957, ads7958, ads7959, ads7960, and ads7961 ADCs. * cm3605 - New driver for this light sensor and proximity sensor which is an analog part with some additional digital controls. * hx711 - New driver. Core new stuff * Gravity sensor type. This is a processed datastream in which the device will try to work out which way is down. * Split the buffer.h file into two parts. One provides the interface to 'use' a buffer, the second provides the internals of the buffer functionality as needed by implementations of buffers. - Move documentation inline so as to allow use of private: tag when generating documentation. - Add some utility functions for the few things that are directly done with the buffers. - Stop exporting functions that no-one uses outside of the core code. - Push docs down by the code in the c file where they should have always been. - Fix typo in kernel-doc for buffer. - push down some includes that were previously happening implicitly. - stop enabling the timestamp of the dummy device. Features and cleanups * ad5592r - ACPI support * ad5593r -ACPI support. * ad5933 - Fix a false comment about size of a particular register. * ad7150 - replace S_IRUGO | S_IWUSR with 0644. I'm not that keen on these patches in general, but as it was nicely presented I took this one anyway. As a general rule will only take these as part of a larger driver cleanup. - don't eat an error but rather reutnr it in the write_event_config callback. * ad7606 - replace non standard range attibute with _scale * ade7753 - use usleep_range for short sleeps * ade7754 - use usleep_range for short sleeps * ade7758 - use usleep_range for short sleeps * ade7759 - use usleep_range for short sleeps * ade7854 - use usleep_range for short sleeps * adis16201 - fix description * adis16203 - fix description - fix copyright year * adis16209 - fix description * adt7316 - Add braces to arms of if else statement (for consistency) - Alignment fixes. * axp288 - Fix up an issue with accidental overwrites of data. * bmi160 - add deivce tables for i2c and spi to support correctly identifying the full dt name (including manufacturer). - device tree binding. * bmp280 - use usleep_range for short sleeps. * cm3232 - return error from cm3232_reg_init rather than eating it if the last write fails. * dummy driver - remove a semicolor found at end of a function defintition. * exynos-adc - use usleep_range for short sleeps. * hid-sensor (accel) - Add timestamp support. The hardware can provide timestamps so lets support them. If not fall back to timestamps estimated in kernel. * hid-sensor (light) - Add a duplicate ID for the light channels so as to keep existing interface whilst also using the more standard IIO interface. * hts221 - acpi probing * imx25-gcq - Add a macro call to allow this driver to be automatically loaded. * isl29028 - reorganise code to avoid deep nesting of if statements. - move chip test and default regs into a function suitable or sharing with power management code. - tidy up some code alignment. * lidar-lite-v3 - introduce compatible strings that make it clear Garmin have consideral friends. * mma8452 - avoid returning signed value when unsigned is appropriate * spmi-vadc - Update function for generic voltage conversion to take into account that different channels on this device should be handled differently. - Rework code to allow per channel voltage scaling and support the standard options for this hardware. - Fixup three minor issues with the above patches for this part. These all effect test builds rather than the native builds for the part, but good to clean them up anyway. * st_sensors - support device matching from the ACPI DST tables. - acpi based probing for accelerometers - acpi based probing for pressure sensors - Allow pressure sensors to read negative values. - Export sampling frequency for lps25h and lps331ap. - Add support for the old DT bindings from the period when these deivces were often supported through windows. Docs fixup: * typo in sysfs-bus-iio
Diffstat (limited to 'drivers/iio/light')
-rw-r--r--drivers/iio/light/Kconfig10
-rw-r--r--drivers/iio/light/Makefile1
-rw-r--r--drivers/iio/light/cm3232.c2
-rw-r--r--drivers/iio/light/cm3605.c330
-rw-r--r--drivers/iio/light/hid-sensor-als.c24
5 files changed, 363 insertions, 4 deletions
diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
index 298ea5081a96..5f731ead9d46 100644
--- a/drivers/iio/light/Kconfig
+++ b/drivers/iio/light/Kconfig
@@ -115,6 +115,16 @@ config CM3323
To compile this driver as a module, choose M here: the module will
be called cm3323.
+config CM3605
+ tristate "Capella CM3605 ambient light and proximity sensor"
+ depends on OF
+ help
+ Say Y here if you want to build a driver for Capella CM3605
+ ambient light and short range proximity sensor.
+
+ To compile this driver as a module, choose M here: the module will
+ be called cm3605.
+
config CM36651
depends on I2C
tristate "CM36651 driver"
diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile
index 4de520036e6e..c13a2399e6df 100644
--- a/drivers/iio/light/Makefile
+++ b/drivers/iio/light/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_BH1780) += bh1780.o
obj-$(CONFIG_CM32181) += cm32181.o
obj-$(CONFIG_CM3232) += cm3232.o
obj-$(CONFIG_CM3323) += cm3323.o
+obj-$(CONFIG_CM3605) += cm3605.o
obj-$(CONFIG_CM36651) += cm36651.o
obj-$(CONFIG_GP2AP020A00F) += gp2ap020a00f.o
obj-$(CONFIG_HID_SENSOR_ALS) += hid-sensor-als.o
diff --git a/drivers/iio/light/cm3232.c b/drivers/iio/light/cm3232.c
index fe89b6823217..263e97235ea0 100644
--- a/drivers/iio/light/cm3232.c
+++ b/drivers/iio/light/cm3232.c
@@ -119,7 +119,7 @@ static int cm3232_reg_init(struct cm3232_chip *chip)
if (ret < 0)
dev_err(&chip->client->dev, "Error writing reg_cmd\n");
- return 0;
+ return ret;
}
/**
diff --git a/drivers/iio/light/cm3605.c b/drivers/iio/light/cm3605.c
new file mode 100644
index 000000000000..2d96543db1ef
--- /dev/null
+++ b/drivers/iio/light/cm3605.c
@@ -0,0 +1,330 @@
+/*
+ * CM3605 Ambient Light and Proximity Sensor
+ *
+ * Copyright (C) 2016 Linaro Ltd.
+ * Author: Linus Walleij <linus.walleij@linaro.org>
+ *
+ * This hardware was found in the very first Nexus One handset from Google/HTC
+ * and an early endavour into mobile light and proximity sensors.
+ */
+
+#include <linux/module.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+#include <linux/iio/events.h>
+#include <linux/iio/consumer.h> /* To get our ADC channel */
+#include <linux/iio/types.h> /* To deal with our ADC channel */
+#include <linux/init.h>
+#include <linux/leds.h>
+#include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/regulator/consumer.h>
+#include <linux/gpio/consumer.h>
+#include <linux/interrupt.h>
+#include <linux/math64.h>
+#include <linux/pm.h>
+
+#define CM3605_PROX_CHANNEL 0
+#define CM3605_ALS_CHANNEL 1
+#define CM3605_AOUT_TYP_MAX_MV 1550
+/* It should not go above 1.650V according to the data sheet */
+#define CM3605_AOUT_MAX_MV 1650
+
+/**
+ * struct cm3605 - CM3605 state
+ * @dev: pointer to parent device
+ * @vdd: regulator controlling VDD
+ * @aset: sleep enable GPIO, high = sleep
+ * @aout: IIO ADC channel to convert the AOUT signal
+ * @als_max: maximum LUX detection (depends on RSET)
+ * @dir: proximity direction: start as FALLING
+ * @led: trigger for the infrared LED used by the proximity sensor
+ */
+struct cm3605 {
+ struct device *dev;
+ struct regulator *vdd;
+ struct gpio_desc *aset;
+ struct iio_channel *aout;
+ s32 als_max;
+ enum iio_event_direction dir;
+ struct led_trigger *led;
+};
+
+static irqreturn_t cm3605_prox_irq(int irq, void *d)
+{
+ struct iio_dev *indio_dev = d;
+ struct cm3605 *cm3605 = iio_priv(indio_dev);
+ u64 ev;
+
+ ev = IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, CM3605_PROX_CHANNEL,
+ IIO_EV_TYPE_THRESH, cm3605->dir);
+ iio_push_event(indio_dev, ev, iio_get_time_ns(indio_dev));
+
+ /* Invert the edge for each event */
+ if (cm3605->dir == IIO_EV_DIR_RISING)
+ cm3605->dir = IIO_EV_DIR_FALLING;
+ else
+ cm3605->dir = IIO_EV_DIR_RISING;
+
+ return IRQ_HANDLED;
+}
+
+static int cm3605_get_lux(struct cm3605 *cm3605)
+{
+ int ret, res;
+ s64 lux;
+
+ ret = iio_read_channel_processed(cm3605->aout, &res);
+ if (ret < 0)
+ return ret;
+
+ dev_dbg(cm3605->dev, "read %d mV from ADC\n", res);
+
+ /*
+ * AOUT has an offset of ~30mV then linear at dark
+ * then goes from 2.54 up to 650 LUX yielding 1.55V
+ * (1550 mV) so scale the returned value to this interval
+ * using simple linear interpolation.
+ */
+ if (res < 30)
+ return 0;
+ if (res > CM3605_AOUT_MAX_MV)
+ dev_err(cm3605->dev, "device out of range\n");
+
+ /* Remove bias */
+ lux = res - 30;
+
+ /* Linear interpolation between 0 and ALS typ max */
+ lux *= cm3605->als_max;
+ lux = div64_s64(lux, CM3605_AOUT_TYP_MAX_MV);
+
+ return lux;
+}
+
+static int cm3605_read_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int *val, int *val2, long mask)
+{
+ struct cm3605 *cm3605 = iio_priv(indio_dev);
+ int ret;
+
+ switch (mask) {
+ case IIO_CHAN_INFO_RAW:
+ switch (chan->type) {
+ case IIO_LIGHT:
+ ret = cm3605_get_lux(cm3605);
+ if (ret < 0)
+ return ret;
+ *val = ret;
+ return IIO_VAL_INT;
+ default:
+ return -EINVAL;
+ }
+ default:
+ return -EINVAL;
+ }
+}
+
+static const struct iio_info cm3605_info = {
+ .driver_module = THIS_MODULE,
+ .read_raw = cm3605_read_raw,
+};
+
+static const struct iio_event_spec cm3605_events[] = {
+ {
+ .type = IIO_EV_TYPE_THRESH,
+ .dir = IIO_EV_DIR_EITHER,
+ .mask_separate = BIT(IIO_EV_INFO_ENABLE),
+ },
+};
+
+static const struct iio_chan_spec cm3605_channels[] = {
+ {
+ .type = IIO_PROXIMITY,
+ .event_spec = cm3605_events,
+ .num_event_specs = ARRAY_SIZE(cm3605_events),
+ },
+ {
+ .type = IIO_LIGHT,
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+ .channel = CM3605_ALS_CHANNEL,
+ },
+};
+
+static int cm3605_probe(struct platform_device *pdev)
+{
+ struct cm3605 *cm3605;
+ struct iio_dev *indio_dev;
+ struct device *dev = &pdev->dev;
+ struct device_node *np = dev->of_node;
+ enum iio_chan_type ch_type;
+ u32 rset;
+ int ret;
+
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*cm3605));
+ if (!indio_dev)
+ return -ENOMEM;
+ platform_set_drvdata(pdev, indio_dev);
+
+ cm3605 = iio_priv(indio_dev);
+ cm3605->dev = dev;
+ cm3605->dir = IIO_EV_DIR_FALLING;
+
+ ret = of_property_read_u32(np, "capella,aset-resistance-ohms", &rset);
+ if (ret) {
+ dev_info(dev, "no RSET specified, assuming 100K\n");
+ rset = 100000;
+ }
+ switch (rset) {
+ case 50000:
+ cm3605->als_max = 650;
+ break;
+ case 100000:
+ cm3605->als_max = 300;
+ break;
+ case 300000:
+ cm3605->als_max = 100;
+ break;
+ case 600000:
+ cm3605->als_max = 50;
+ break;
+ default:
+ dev_info(dev, "non-standard resistance\n");
+ return -EINVAL;
+ }
+
+ cm3605->aout = devm_iio_channel_get(dev, "aout");
+ if (IS_ERR(cm3605->aout)) {
+ if (PTR_ERR(cm3605->aout) == -ENODEV) {
+ dev_err(dev, "no ADC, deferring...\n");
+ return -EPROBE_DEFER;
+ }
+ dev_err(dev, "failed to get AOUT ADC channel\n");
+ return PTR_ERR(cm3605->aout);
+ }
+ ret = iio_get_channel_type(cm3605->aout, &ch_type);
+ if (ret < 0)
+ return ret;
+ if (ch_type != IIO_VOLTAGE) {
+ dev_err(dev, "wrong type of IIO channel specified for AOUT\n");
+ return -EINVAL;
+ }
+
+ cm3605->vdd = devm_regulator_get(dev, "vdd");
+ if (IS_ERR(cm3605->vdd)) {
+ dev_err(dev, "failed to get VDD regulator\n");
+ return PTR_ERR(cm3605->vdd);
+ }
+ ret = regulator_enable(cm3605->vdd);
+ if (ret) {
+ dev_err(dev, "failed to enable VDD regulator\n");
+ return ret;
+ }
+
+ cm3605->aset = devm_gpiod_get(dev, "aset", GPIOD_OUT_HIGH);
+ if (IS_ERR(cm3605->aset)) {
+ dev_err(dev, "no ASET GPIO\n");
+ ret = PTR_ERR(cm3605->aset);
+ goto out_disable_vdd;
+ }
+
+ ret = devm_request_threaded_irq(dev, platform_get_irq(pdev, 0),
+ cm3605_prox_irq, NULL, 0, "cm3605", indio_dev);
+ if (ret) {
+ dev_err(dev, "unable to request IRQ\n");
+ goto out_disable_aset;
+ }
+
+ /* Just name the trigger the same as the driver */
+ led_trigger_register_simple("cm3605", &cm3605->led);
+ led_trigger_event(cm3605->led, LED_FULL);
+
+ indio_dev->dev.parent = dev;
+ indio_dev->info = &cm3605_info;
+ indio_dev->name = "cm3605";
+ indio_dev->channels = cm3605_channels;
+ indio_dev->num_channels = ARRAY_SIZE(cm3605_channels);
+ indio_dev->modes = INDIO_DIRECT_MODE;
+
+ ret = iio_device_register(indio_dev);
+ if (ret)
+ goto out_remove_trigger;
+ dev_info(dev, "Capella Microsystems CM3605 enabled range 0..%d LUX\n",
+ cm3605->als_max);
+
+ return 0;
+
+out_remove_trigger:
+ led_trigger_event(cm3605->led, LED_OFF);
+ led_trigger_unregister_simple(cm3605->led);
+out_disable_aset:
+ gpiod_set_value_cansleep(cm3605->aset, 0);
+out_disable_vdd:
+ regulator_disable(cm3605->vdd);
+ return ret;
+}
+
+static int cm3605_remove(struct platform_device *pdev)
+{
+ struct iio_dev *indio_dev = platform_get_drvdata(pdev);
+ struct cm3605 *cm3605 = iio_priv(indio_dev);
+
+ led_trigger_event(cm3605->led, LED_OFF);
+ led_trigger_unregister_simple(cm3605->led);
+ gpiod_set_value_cansleep(cm3605->aset, 0);
+ iio_device_unregister(indio_dev);
+ regulator_disable(cm3605->vdd);
+
+ return 0;
+}
+
+static int cm3605_pm_suspend(struct device *dev)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct cm3605 *cm3605 = iio_priv(indio_dev);
+
+ led_trigger_event(cm3605->led, LED_OFF);
+ regulator_disable(cm3605->vdd);
+
+ return 0;
+}
+
+static int cm3605_pm_resume(struct device *dev)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct cm3605 *cm3605 = iio_priv(indio_dev);
+ int ret;
+
+ ret = regulator_enable(cm3605->vdd);
+ if (ret)
+ dev_err(dev, "failed to enable regulator in resume path\n");
+ led_trigger_event(cm3605->led, LED_FULL);
+
+ return 0;
+}
+
+static const struct dev_pm_ops cm3605_dev_pm_ops = {
+ SET_SYSTEM_SLEEP_PM_OPS(cm3605_pm_suspend,
+ cm3605_pm_resume)
+};
+
+static const struct of_device_id cm3605_of_match[] = {
+ {.compatible = "capella,cm3605"},
+ { },
+};
+MODULE_DEVICE_TABLE(of, cm3605_of_match);
+
+static struct platform_driver cm3605_driver = {
+ .driver = {
+ .name = "cm3605",
+ .of_match_table = cm3605_of_match,
+ .pm = &cm3605_dev_pm_ops,
+ },
+ .probe = cm3605_probe,
+ .remove = cm3605_remove,
+};
+module_platform_driver(cm3605_driver);
+
+MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
+MODULE_DESCRIPTION("CM3605 ambient light and proximity sensor driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
index 8bb1f90ecd51..059d964772c7 100644
--- a/drivers/iio/light/hid-sensor-als.c
+++ b/drivers/iio/light/hid-sensor-als.c
@@ -31,13 +31,17 @@
#include <linux/iio/triggered_buffer.h>
#include "../common/hid-sensors/hid-sensor-trigger.h"
-#define CHANNEL_SCAN_INDEX_ILLUM 0
+enum {
+ CHANNEL_SCAN_INDEX_INTENSITY = 0,
+ CHANNEL_SCAN_INDEX_ILLUM = 1,
+ CHANNEL_SCAN_INDEX_MAX
+};
struct als_state {
struct hid_sensor_hub_callbacks callbacks;
struct hid_sensor_common common_attributes;
struct hid_sensor_hub_attribute_info als_illum;
- u32 illum;
+ u32 illum[CHANNEL_SCAN_INDEX_MAX];
int scale_pre_decml;
int scale_post_decml;
int scale_precision;
@@ -55,6 +59,15 @@ static const struct iio_chan_spec als_channels[] = {
BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_SAMP_FREQ) |
BIT(IIO_CHAN_INFO_HYSTERESIS),
+ .scan_index = CHANNEL_SCAN_INDEX_INTENSITY,
+ },
+ {
+ .type = IIO_LIGHT,
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
+ BIT(IIO_CHAN_INFO_SCALE) |
+ BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+ BIT(IIO_CHAN_INFO_HYSTERESIS),
.scan_index = CHANNEL_SCAN_INDEX_ILLUM,
}
};
@@ -86,6 +99,7 @@ static int als_read_raw(struct iio_dev *indio_dev,
switch (mask) {
case 0:
switch (chan->scan_index) {
+ case CHANNEL_SCAN_INDEX_INTENSITY:
case CHANNEL_SCAN_INDEX_ILLUM:
report_id = als_state->als_illum.report_id;
address =
@@ -202,10 +216,12 @@ static int als_capture_sample(struct hid_sensor_hub_device *hsdev,
struct iio_dev *indio_dev = platform_get_drvdata(priv);
struct als_state *als_state = iio_priv(indio_dev);
int ret = -EINVAL;
+ u32 sample_data = *(u32 *)raw_data;
switch (usage_id) {
case HID_USAGE_SENSOR_LIGHT_ILLUM:
- als_state->illum = *(u32 *)raw_data;
+ als_state->illum[CHANNEL_SCAN_INDEX_INTENSITY] = sample_data;
+ als_state->illum[CHANNEL_SCAN_INDEX_ILLUM] = sample_data;
ret = 0;
break;
default:
@@ -230,6 +246,8 @@ static int als_parse_report(struct platform_device *pdev,
&st->als_illum);
if (ret < 0)
return ret;
+ als_adjust_channel_bit_mask(channels, CHANNEL_SCAN_INDEX_INTENSITY,
+ st->als_illum.size);
als_adjust_channel_bit_mask(channels, CHANNEL_SCAN_INDEX_ILLUM,
st->als_illum.size);