diff options
author | Sri Krishna chowdary <schowdary@nvidia.com> | 2014-02-19 19:00:13 +0530 |
---|---|---|
committer | Sachin Nikam <snikam@nvidia.com> | 2014-03-03 01:27:36 -0800 |
commit | dd8d439a09c0bf12e31c8a6cbd47b2df238bd087 (patch) | |
tree | c8c7a2b5f5b08c3618af090c6f6bcf3818323796 | |
parent | 5a2fc3db0734e778b8e460cb4a001eca0b5d1b63 (diff) |
staging: iio: light: max44005: configure gain
- Add support to configure gain from dt
- Also get als_resolution from dt
- Add als_resolution sysfs
- Add dt bindings for max44005
Bug 1462476
Change-Id: I58f05a0971cf063ab14f4cd331b30e537cf989a5
Signed-off-by: Sri Krishna chowdary <schowdary@nvidia.com>
Reviewed-on: http://git-master/r/369337
(cherry picked from commit 0928174f846de5e6ffce0dee31c3a538ea8fadfe)
Reviewed-on: http://git-master/r/374281
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Sachin Nikam <snikam@nvidia.com>
-rw-r--r-- | Documentation/devicetree/bindings/staging/iio/light/max44006-als.txt | 20 | ||||
-rw-r--r-- | drivers/staging/iio/light/max44005.c | 43 |
2 files changed, 61 insertions, 2 deletions
diff --git a/Documentation/devicetree/bindings/staging/iio/light/max44006-als.txt b/Documentation/devicetree/bindings/staging/iio/light/max44006-als.txt new file mode 100644 index 000000000000..8eef8f3208f7 --- /dev/null +++ b/Documentation/devicetree/bindings/staging/iio/light/max44006-als.txt @@ -0,0 +1,20 @@ +* MAX44006 ambient light sensor + +Required properties: +- compatible: must be "maxim,max44006" +- reg: i2c address of the device. It should be 0x44. +- vcc-supply: regulator supply for the chip + +Optional propertied: +- maxim,gain: integer value specifying the gain factor per lsb. +- maxim,als-resolution: conversion factor from sensor raw units to lux. + +Example: + + max44006@44 { + compatible = "maxim,max44006"; + reg = <0x44>; + vcc-supply = <&palmas_smps8>; + maxim,gain = <1>; + maxim,als-resolution = "0.75"; + }; diff --git a/drivers/staging/iio/light/max44005.c b/drivers/staging/iio/light/max44005.c index 68e527a32ec5..91fff947f90c 100644 --- a/drivers/staging/iio/light/max44005.c +++ b/drivers/staging/iio/light/max44005.c @@ -4,7 +4,7 @@ * IIO Light driver for monitoring ambient light intensity in lux and proximity * ir. * - * Copyright (c) 2013 - 2014, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2013-2014, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -107,6 +107,9 @@ struct max44005_chip { bool is_standby; int shutdown_complete; + + u32 gain; + const char *als_resolution; }; static int max44005_read(struct max44005_chip *chip, int *rval, u8 reg_addr, @@ -340,7 +343,7 @@ static ssize_t amb_clear_enable(struct device *dev, if (!max44005_power(chip, true)) goto fail; - if (max44005_write(chip, AMB_PGA_256x, AMB_CONF_REG_ADDR)) + if (max44005_write(chip, chip->gain, AMB_CONF_REG_ADDR)) goto fail; if (!PROXIMITY_ENABLED && @@ -434,6 +437,18 @@ fail: } /* amb LED end */ + +/* amb LED begin */ +static ssize_t show_resolution(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct max44005_chip *chip = iio_priv(indio_dev); + if (chip->als_resolution) + return sprintf(buf, chip->als_resolution); + return sprintf(buf, "1.75"); +} + static IIO_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, 0); static IIO_DEVICE_ATTR(amb_clear, S_IRUGO | S_IWUSR, show_amb_clear_value, amb_clear_enable, 0); @@ -447,6 +462,8 @@ static IIO_DEVICE_ATTR(ir, S_IRUGO, show_ir_value, NULL, 0); static IIO_DEVICE_ATTR(proximity, S_IRUGO | S_IWUSR, show_prox_value, prox_enable, 0); +static IIO_DEVICE_ATTR(als_resolution, S_IRUGO | S_IWUSR, show_resolution, + NULL , 0); /* sysfs attr */ static struct attribute *max44005_iio_attr[] = { @@ -457,6 +474,7 @@ static struct attribute *max44005_iio_attr[] = { &iio_dev_attr_green.dev_attr.attr, &iio_dev_attr_blue.dev_attr.attr, &iio_dev_attr_ir.dev_attr.attr, + &iio_dev_attr_als_resolution.dev_attr.attr, NULL }; @@ -497,6 +515,15 @@ static int max44005_probe(struct i2c_client *client, struct iio_dev *indio_dev; struct max44005_chip *chip; int err; + const char *prop_value = NULL; + u32 gain = 0; + + if (client->dev.of_node) { + of_property_read_u32(client->dev.of_node, + "maxim,gain", &gain); + err = of_property_read_string(client->dev.of_node, + "maxim,als-resolution", &prop_value); + } indio_dev = iio_device_alloc(sizeof(struct max44005_chip)); if (indio_dev == NULL) { @@ -546,6 +573,18 @@ static int max44005_probe(struct i2c_client *client, } finish: + switch (gain) { + case AMB_PGA_1x: + case AMB_PGA_4x: + case AMB_PGA_16x: + case AMB_PGA_256x: + break; + default: + gain = AMB_PGA_256x; + }; + chip->gain = gain; + chip->als_resolution = prop_value; + mutex_lock(&chip->lock); max44005_power(chip, false); mutex_unlock(&chip->lock); |