mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] iio: light: al3320a: support illuminance0_input function
@ 2016-06-03 10:00 Rocky Hsiao
  2016-06-03 10:36 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Rocky Hsiao @ 2016-06-03 10:00 UTC (permalink / raw)
  To: linux-iio
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald, Rocky Hsiao, linux-kernel, John Huang,
	Thomas Lin

Add few functions to show lux.

Signed-off-by: Rocky Hsiao <rocky.hsiao@dyna-image.com>
---
 drivers/iio/light/al3320a.c | 50 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 48 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/light/al3320a.c b/drivers/iio/light/al3320a.c
index 6aac651..f32b5d1 100644
--- a/drivers/iio/light/al3320a.c
+++ b/drivers/iio/light/al3320a.c
@@ -11,6 +11,13 @@
  *
  * TODO: interrupt support, thresholds
  *
+ * last change: 2016/06/03
+ *
+ * change list:
+ * - add few function to supprt illuminance0_input
+ *
+ * editor: Rocky Hsiao <rocky.hsiao@dyna-image>
+ *
  */
 
 #include <linux/module.h>
@@ -72,9 +79,47 @@ static const struct iio_chan_spec al3320a_channels[] = {
 	}
 };
 
+static int al3320a_get_adc_value(struct al3320a_data *data)
+{
+	int val;
+
+	val = i2c_smbus_read_word_data(data->client, AL3320A_REG_DATA_LOW);
+
+	return val;
+}
+
+static int al3320a_get_lux(struct al3320a_data *data)
+{
+	int ret;
+	long ret64;
+
+	ret = al3320a_get_adc_value(data);
+	ret64 = ret;
+	ret64 = (ret64 * 32000) / 1000000;
+	ret = ret64;
+
+	return  ret;
+}
+
+static ssize_t al3320a_lux_show(struct device *dev,
+		struct device_attribute *attr,
+		char *buf)
+{
+	struct al3320a_data *data = iio_priv(dev_to_iio_dev(dev));
+	int val;
+
+	val = al3320a_get_lux(data);
+
+	return sprintf(buf, "%d\n", val);
+}
+
+static IIO_DEVICE_ATTR(illuminance0_input, S_IRUGO,
+		al3320a_lux_show, NULL, 0);
+
 static IIO_CONST_ATTR(in_illuminance_scale_available, AL3320A_SCALE_AVAILABLE);
 
 static struct attribute *al3320a_attributes[] = {
+	&iio_dev_attr_illuminance0_input.dev_attr.attr,
 	&iio_const_attr_in_illuminance_scale_available.dev_attr.attr,
 	NULL,
 };
@@ -125,8 +170,8 @@ static int al3320a_read_raw(struct iio_dev *indio_dev,
 		 * - low byte of output is stored at AL3320A_REG_DATA_LOW
 		 * - high byte of output is stored at AL3320A_REG_DATA_LOW + 1
 		 */
-		ret = i2c_smbus_read_word_data(data->client,
-					       AL3320A_REG_DATA_LOW);
+		ret = al3320a_get_adc_value(data);
+
 		if (ret < 0)
 			return ret;
 		*val = ret;
@@ -201,6 +246,7 @@ static int al3320a_probe(struct i2c_client *client,
 		dev_err(&client->dev, "al3320a chip init failed\n");
 		return ret;
 	}
+
 	return devm_iio_device_register(&client->dev, indio_dev);
 }
 
-- 
2.1.2

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-06-03 10:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-03 10:00 [PATCH 1/2] iio: light: al3320a: support illuminance0_input function Rocky Hsiao
2016-06-03 10:36 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®