]> rtime.felk.cvut.cz Git - hercules2020/nv-tegra/linux-4.4.git/commitdiff
staging: iio: light: provide sensor specs to user
authorSri Krishna chowdary <schowdary@nvidia.com>
Tue, 28 Jan 2014 06:49:02 +0000 (12:19 +0530)
committerAkhilesh Reddy Khumbum <akhumbum@nvidia.com>
Thu, 21 Apr 2016 23:43:08 +0000 (16:43 -0700)
Android HAL requires some specification details about a sensor.
Since, this information is device as well as board specific,
device tree is more appropriate to fill this information
rather than the sensor's driver.

The goal of this patch is two fold
1. add helpers to retrieve this data from device tree node
2. add helpers to share this information from device's platform data
to the user space through sysfs.

bug 1402172

Change-Id: I79b32a42d5e9234acf8f11788767162d9451bfd1
Signed-off-by: Sri Krishna chowdary <schowdary@nvidia.com>
Reviewed-on: http://git-master/r/359781
(cherry picked from commit 478f7e628df61da1aeac43e72e6f30545916468f)
Reviewed-on: http://git-master/r/350324
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Sachin Nikam <snikam@nvidia.com>
drivers/staging/iio/light/Kconfig
drivers/staging/iio/light/Makefile
drivers/staging/iio/light/ls_dt.c [new file with mode: 0644]
drivers/staging/iio/light/ls_sysfs.c [new file with mode: 0644]
include/linux/iio/light/ls_dt.h [new file with mode: 0644]
include/linux/iio/light/ls_sysfs.h [new file with mode: 0644]

index 8038ce11c376130fea4490282584c6a4a2e30871..57489807588d015d4b76f0a20aeb91edfb65306f 100644 (file)
@@ -50,4 +50,66 @@ config TSL2x7x
         tmd2672, tsl2772, tmd2772 devices.
         Provides iio_events and direct access via sysfs.
 
+config SENSORS_LTR558
+       tristate "LTR558 Ambient light and proximity sensor"
+       depends on I2C
+       default n
+       help
+         If you say yes here you get support for ambient light sensing and
+         proximity ir sensing from Lite On Technology LTR558.
+
+config SENSORS_MAX44005
+       tristate "MAX44005 ALS, RGB, temperature, IR, proximity Sensor"
+       depends on I2C
+       default n
+       help
+         If you say yes here you get support for ambient light, RGB, IR,
+         Proximity and temperature sensing from MAX44005.
+
+config SENSORS_STM8T143
+       tristate "STM8T143 proximity sensor"
+       default n
+       help
+         If you say yes here you get support for ST Microelectronics
+         STM8T143 sensor driver.
+         The STM8T143 sensor driver provices suport for proximity sensing.
+         Data from sensor is accessible via sysfs.
+
+config SENSORS_TCS3772
+       tristate "TCS3772 Ambient light, RGB and proximity Sensor"
+       depends on I2C
+       select REGMAP_I2C
+       default n
+       help
+         If you say yes here you get support for ambient light, RGB and
+         Proximity sensing from TCS3772.
+
+config SENSORS_CM3217
+       tristate "CM3217 Ambient light sensor"
+       depends on I2C
+       default n
+       help
+         Say Y here to enable the CM3217 Ambient Light Sensor.
+
+config LS_OF
+       tristate "Device Tree parsing for Light sensor specification details"
+       depends on OF
+       default n
+       help
+         Say Y for helpers to retrieve the sensor specification details like
+         vendor, power consumed, max range, resolution and integration.
+         This information is common to most Ambient light sensors as well as
+         proximity sensors. Hence, have common callbacks to retrive this
+         information from the respective device tree nodes.
+
+config LS_SYSFS
+       tristate "IIO registration for sensor meta data"
+       depends on LS_OF
+       default n
+       help
+         Say Y for to share sensor specification details to user space.
+         The information is retrieved from device platform data. If you are
+         using helpers from this file, make sure device's platform data
+         contains all the required information.
+
 endmenu
index 7ecc4518d340a346e93b07fc181fa2dc8d941240..a49e800ebb20dd2c537401e7ef997e76c8d271d3 100644 (file)
@@ -13,3 +13,5 @@ obj-$(CONFIG_SENSORS_TCS3772) += tcs3772.o
 obj-$(CONFIG_SENSORS_TSL2563)  += tsl2563.o
 obj-$(CONFIG_TSL2583)          += tsl2583.o
 obj-$(CONFIG_SENSORS_CM3217)   += cm3217.o
+obj-$(CONFIG_LS_SYSFS) += ls_sysfs.o
+obj-$(CONFIG_LS_OF)    += ls_dt.o
diff --git a/drivers/staging/iio/light/ls_dt.c b/drivers/staging/iio/light/ls_dt.c
new file mode 100644 (file)
index 0000000..bd800b9
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 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,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/iio/light/ls_sysfs.h>
+
+static const char *propname[NUM_PROP] = {
+       "vendor"
+};
+
+static const char *dt_chan_sysfs_lut[MAX_CHAN][MAX_CHAN_PROP] = {
+       {
+               "illuminance,max-range",
+               "illuminance,integration-time",
+               "illuminance,resolution",
+               "illuminance,power-consumed"
+       },
+       {
+               "proximity,max-range",
+               "proximity,integration-time",
+               "proximity,power-consumed"
+       }
+};
+
+/*
+ * 1. create instance of lightsensor_spec,
+ * 2. parse the DT node for the dev * and fill the lightsensor_spec
+ * 3. return the filled lightsensor_spec if success.
+ */
+struct lightsensor_spec *of_get_ls_spec(struct device *dev)
+{
+       const char *prop_value;
+       int i, j, ret;
+       struct lightsensor_spec *ls_spec;
+       bool is_empty = true;
+
+       if (!dev->of_node)
+               return NULL;
+
+       ls_spec = devm_kzalloc(dev,
+                               sizeof(struct lightsensor_spec), GFP_KERNEL);
+       if (!ls_spec)
+               return NULL;
+
+       /* fill values of dt properties in propname -> ls_spec->propname */
+       for (i = 0; i < NUM_PROP; i++) {
+               ret = of_property_read_string(dev->of_node, propname[i],
+                                               &prop_value);
+               if (!ret) {
+                       ls_spec->prop[i] = prop_value;
+                       is_empty = false;
+               }
+       }
+
+       /*
+        * fill values of dt properties in dt_chan_sysfs_lut to
+        * ls_spec->chan_prop
+        */
+       for (i = 0; i < MAX_CHAN; i++)
+               for (j = 0; j < MAX_CHAN_PROP; j++)
+                       if (dt_chan_sysfs_lut[i][j]) {
+                               ret = of_property_read_string(dev->of_node,
+                                       dt_chan_sysfs_lut[i][j], &prop_value);
+                               if (!ret) {
+                                       ls_spec->chan_prop[i][j] = prop_value;
+                                       is_empty = false;
+                               }
+                       }
+
+       if (is_empty) {
+               devm_kfree(dev, ls_spec);
+               ls_spec = NULL;
+       }
+
+       return ls_spec;
+}
diff --git a/drivers/staging/iio/light/ls_sysfs.c b/drivers/staging/iio/light/ls_sysfs.c
new file mode 100644 (file)
index 0000000..e36d02a
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 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,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/module.h>
+#include <linux/iio/light/ls_sysfs.h>
+
+static const char *propname[NUM_PROP] = {
+       "vendor"
+};
+
+/* look up table for light sensor's per channel sysfs */
+static const char *sysfs_ls_lut[MAX_CHAN][MAX_CHAN_PROP] = {
+       {
+               "in_illuminance_max_range",
+               "in_illuminance_integration_time",
+               "in_illuminance_resolution",
+               "in_illuminance_power_consumed"
+       },
+       {
+               "in_proximity_max_range",
+               "in_proximity_integration_time",
+               "in_proximity_power_consumed"
+       }
+};
+
+static const char *get_ls_spec_val(struct lightsensor_spec *ls_spec,
+                               const char *sysfs_name)
+{
+       int i, j;
+
+       if (sysfs_name == NULL)
+               return NULL;
+
+       if (!ls_spec)
+               return NULL;
+
+       for (i = 0; i < NUM_PROP; i++)
+               if (strstr(sysfs_name, propname[i]))
+                       return ls_spec->prop[i];
+
+       for (i = 0; i < MAX_CHAN; i++)
+               for (j = 0; j < MAX_CHAN_PROP; j++)
+                       if (sysfs_ls_lut[i][j] &&
+                               strstr(sysfs_name, sysfs_ls_lut[i][j]))
+                               return ls_spec->chan_prop[i][j];
+
+       return NULL;
+}
+
+void fill_ls_attrs(struct lightsensor_spec *ls_spec,
+                       struct attribute **attrs)
+{
+       struct attribute *attr;
+       struct device_attribute *dev_attr;
+       struct iio_const_attr *iio_const_attr;
+       int i;
+       const char *val;
+
+       if (!ls_spec || !attrs)
+               return;
+
+       for (i = 0, attr = attrs[i]; attr; attr = attrs[i++]) {
+               dev_attr = container_of(attr, struct device_attribute, attr);
+               iio_const_attr = to_iio_const_attr(dev_attr);
+               val = get_ls_spec_val(ls_spec, attr->name);
+               if (val)
+                       iio_const_attr->string = val;
+       }
+}
diff --git a/include/linux/iio/light/ls_dt.h b/include/linux/iio/light/ls_dt.h
new file mode 100644 (file)
index 0000000..20c4788
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 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,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __IIO_LS_DT_H__
+#define __IIO_LS_DT_H__
+
+#include <linux/iio/iio.h>
+
+struct lightsensor_spec;
+
+#ifdef CONFIG_LS_OF
+extern struct lightsensor_spec *of_get_ls_spec(struct device *);
+#else
+static inline struct lightsensor_spec *of_get_ls_spec(struct device *dev)
+{
+       return NULL;
+}
+#endif
+
+
+#endif
diff --git a/include/linux/iio/light/ls_sysfs.h b/include/linux/iio/light/ls_sysfs.h
new file mode 100644 (file)
index 0000000..909c762
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 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,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+
+#ifndef __IIO_LS_SYSFS_H__
+#define __IIO_LS_SYSFS_H__
+
+#define MAX_CHAN 2
+
+enum prop {
+       VENDOR,
+       NUM_PROP,
+};
+
+enum channel_prop {
+       MAX_RANGE,
+       INTEGRATION_TIME,
+       RESOLUTION,
+       POWER_CONSUMED,
+       MAX_CHAN_PROP,
+};
+
+struct lightsensor_spec {
+       const char *prop[NUM_PROP];
+       const char *chan_prop[MAX_CHAN][MAX_CHAN_PROP];
+};
+
+#ifdef CONFIG_LS_SYSFS
+extern void fill_ls_attrs(struct lightsensor_spec *, struct attribute **);
+#else
+void fill_ls_attrs(struct lightsensor_spec *meta, struct attribute **attrs)
+{
+}
+#endif
+
+#endif /* __IIO_LS_SYSFS_H__ */