]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.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)
committerSachin Nikam <snikam@nvidia.com>
Mon, 10 Feb 2014 08:35:11 +0000 (00:35 -0800)
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 5fa41e08be29c89ffd034bf5a1694b8789c789f2..c8c61cee5579adaace061aa87288d713124b92ac 100644 (file)
@@ -102,4 +102,25 @@ config SENSORS_CM3217
        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 90114e55a2f437908512583a5abff0621a3c3f1a..d0244a5fb0ca1cf2826ee1b07adcdbf741bbe9c8 100644 (file)
@@ -18,3 +18,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__ */