linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] iio: HID sensor time (as RTC)
@ 2012-12-09 12:21 Alexander Holler
  2012-12-09 12:21 ` [PATCH 1/3] iio: hid-sensors: respect CONFIG_IIO_TRIGGER Alexander Holler
                   ` (2 more replies)
  0 siblings, 3 replies; 66+ messages in thread
From: Alexander Holler @ 2012-12-09 12:21 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-iio, Jonathan Cameron, rtc-linux, Alessandro Zummo,
	srinivas pandruvada

Hello,

the following 3 patches are neccessary to add a driver for
(USB) HID sensors of type time (using hid-sensor-hub).

The driver implements a RTC, so the time will be available like from
any other RTC.

Regards,

Alexander


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

* [PATCH 1/3] iio: hid-sensors: respect CONFIG_IIO_TRIGGER
  2012-12-09 12:21 [PATCH 0/3] iio: HID sensor time (as RTC) Alexander Holler
@ 2012-12-09 12:21 ` Alexander Holler
  2012-12-09 12:21 ` [PATCH 2/3] iio: Add Usage IDs for HID time sensors Alexander Holler
  2012-12-09 12:21 ` [PATCH 3/3] iio: add rtc-driver for HID sensors of type time Alexander Holler
  2 siblings, 0 replies; 66+ messages in thread
From: Alexander Holler @ 2012-12-09 12:21 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-iio, Jonathan Cameron, rtc-linux, Alessandro Zummo,
	srinivas pandruvada, Alexander Holler

Not much to say, without that change, hid-sensor-trigger will be
always compiled if HID_SENSOR_IIO_COMMON is selected which fails if
CONFIG_IIO_TRIGGER is not set because CONFIG_IIO_CONSUMERS_PER_TRIGGER
will not be defined.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 drivers/iio/accel/Kconfig               |    1 +
 drivers/iio/common/hid-sensors/Makefile |    3 ++-
 drivers/iio/gyro/Kconfig                |    1 +
 drivers/iio/light/Kconfig               |    1 +
 drivers/iio/magnetometer/Kconfig        |    1 +
 5 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index b2510c4..b84b806 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -8,6 +8,7 @@ config HID_SENSOR_ACCEL_3D
 	select IIO_BUFFER
 	select IIO_TRIGGERED_BUFFER
 	select HID_SENSOR_IIO_COMMON
+	select HID_SENSOR_IIO_TRIGGER
 	tristate "HID Acelerometers 3D"
 	help
 	  Say yes here to build support for the HID SENSOR
diff --git a/drivers/iio/common/hid-sensors/Makefile b/drivers/iio/common/hid-sensors/Makefile
index 1f463e0..22e7c5a 100644
--- a/drivers/iio/common/hid-sensors/Makefile
+++ b/drivers/iio/common/hid-sensors/Makefile
@@ -3,4 +3,5 @@
 #
 
 obj-$(CONFIG_HID_SENSOR_IIO_COMMON) += hid-sensor-iio-common.o
-hid-sensor-iio-common-y := hid-sensor-attributes.o hid-sensor-trigger.o
+obj-$(CONFIG_HID_SENSOR_IIO_TRIGGER) += hid-sensor-trigger.o
+hid-sensor-iio-common-y := hid-sensor-attributes.o
diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig
index 21e27e2..bc9daff 100644
--- a/drivers/iio/gyro/Kconfig
+++ b/drivers/iio/gyro/Kconfig
@@ -8,6 +8,7 @@ config HID_SENSOR_GYRO_3D
 	select IIO_BUFFER
 	select IIO_TRIGGERED_BUFFER
 	select HID_SENSOR_IIO_COMMON
+	select HID_SENSOR_IIO_TRIGGER
 	tristate "HID Gyroscope 3D"
 	help
 	  Say yes here to build support for the HID SENSOR
diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
index 1763c9b..dbf80ab 100644
--- a/drivers/iio/light/Kconfig
+++ b/drivers/iio/light/Kconfig
@@ -47,6 +47,7 @@ config HID_SENSOR_ALS
 	select IIO_BUFFER
 	select IIO_TRIGGERED_BUFFER
 	select HID_SENSOR_IIO_COMMON
+	select HID_SENSOR_IIO_TRIGGER
 	tristate "HID ALS"
 	help
 	  Say yes here to build support for the HID SENSOR
diff --git a/drivers/iio/magnetometer/Kconfig b/drivers/iio/magnetometer/Kconfig
index c1f0cdd..ff11d68 100644
--- a/drivers/iio/magnetometer/Kconfig
+++ b/drivers/iio/magnetometer/Kconfig
@@ -8,6 +8,7 @@ config HID_SENSOR_MAGNETOMETER_3D
 	select IIO_BUFFER
 	select IIO_TRIGGERED_BUFFER
 	select HID_SENSOR_IIO_COMMON
+	select HID_SENSOR_IIO_TRIGGER
 	tristate "HID Magenetometer 3D"
 	help
 	  Say yes here to build support for the HID SENSOR
-- 
1.7.8.6


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

* [PATCH 2/3] iio: Add Usage IDs for HID time sensors.
  2012-12-09 12:21 [PATCH 0/3] iio: HID sensor time (as RTC) Alexander Holler
  2012-12-09 12:21 ` [PATCH 1/3] iio: hid-sensors: respect CONFIG_IIO_TRIGGER Alexander Holler
@ 2012-12-09 12:21 ` Alexander Holler
  2012-12-09 12:21 ` [PATCH 3/3] iio: add rtc-driver for HID sensors of type time Alexander Holler
  2 siblings, 0 replies; 66+ messages in thread
From: Alexander Holler @ 2012-12-09 12:21 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-iio, Jonathan Cameron, rtc-linux, Alessandro Zummo,
	srinivas pandruvada, Alexander Holler

These are Usage IDs for the attributes year, month, day,
hour, minute and second, needed to read HID time sensors.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 include/linux/hid-sensor-ids.h |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
index 55f2773..6f24446 100644
--- a/include/linux/hid-sensor-ids.h
+++ b/include/linux/hid-sensor-ids.h
@@ -66,6 +66,15 @@
 #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Y_AXIS		0x200486
 #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Z_AXIS		0x200487
 
+/* Time (2000a0) */
+#define HID_USAGE_SENSOR_TIME					0x2000a0
+#define HID_USAGE_SENSOR_TIME_YEAR				0x200521
+#define HID_USAGE_SENSOR_TIME_MONTH				0x200522
+#define HID_USAGE_SENSOR_TIME_DAY				0x200523
+#define HID_USAGE_SENSOR_TIME_HOUR				0x200525
+#define HID_USAGE_SENSOR_TIME_MINUTE				0x200526
+#define HID_USAGE_SENSOR_TIME_SECOND				0x200527
+
 /* Units */
 #define HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED			0x00
 #define HID_USAGE_SENSOR_UNITS_LUX				0x01
-- 
1.7.8.6


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

* [PATCH 3/3] iio: add rtc-driver for HID sensors of type time
  2012-12-09 12:21 [PATCH 0/3] iio: HID sensor time (as RTC) Alexander Holler
  2012-12-09 12:21 ` [PATCH 1/3] iio: hid-sensors: respect CONFIG_IIO_TRIGGER Alexander Holler
  2012-12-09 12:21 ` [PATCH 2/3] iio: Add Usage IDs for HID time sensors Alexander Holler
@ 2012-12-09 12:21 ` Alexander Holler
  2012-12-09 12:55   ` Lars-Peter Clausen
  2 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-09 12:21 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-iio, Jonathan Cameron, rtc-linux, Alessandro Zummo,
	srinivas pandruvada, Alexander Holler

This driver makes the time from HID sensors (hubs) which are offering
such available like any other RTC does.

Currently the time can only be read. Setting the time must be done
through sending a report, which currently isn't supported by
hid-sensor-hub.

It is necessary that all values like year, month etc, are send as
8bit values (1 byte each) and all of them in 1 report. Also the
spec HUTRR39b doesn't define the range of the year field, we
tread it as 0 - 99 because that's what most RTCs I know about are
offering.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 drivers/iio/Kconfig                |    1 +
 drivers/iio/Makefile               |    1 +
 drivers/iio/time/Kconfig           |   14 ++
 drivers/iio/time/Makefile          |    5 +
 drivers/iio/time/hid-sensor-time.c |  397 ++++++++++++++++++++++++++++++++++++
 5 files changed, 418 insertions(+), 0 deletions(-)
 create mode 100644 drivers/iio/time/Kconfig
 create mode 100644 drivers/iio/time/Makefile
 create mode 100644 drivers/iio/time/hid-sensor-time.c

diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
index fc937ac..78fa3ff 100644
--- a/drivers/iio/Kconfig
+++ b/drivers/iio/Kconfig
@@ -63,5 +63,6 @@ source "drivers/iio/dac/Kconfig"
 source "drivers/iio/common/Kconfig"
 source "drivers/iio/gyro/Kconfig"
 source "drivers/iio/magnetometer/Kconfig"
+source "drivers/iio/time/Kconfig"
 
 endif # IIO
diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
index 761f2b6..6a6da31 100644
--- a/drivers/iio/Makefile
+++ b/drivers/iio/Makefile
@@ -19,3 +19,4 @@ obj-y += dac/
 obj-y += common/
 obj-y += gyro/
 obj-y += magnetometer/
+obj-y += time/
diff --git a/drivers/iio/time/Kconfig b/drivers/iio/time/Kconfig
new file mode 100644
index 0000000..0ca4682
--- /dev/null
+++ b/drivers/iio/time/Kconfig
@@ -0,0 +1,14 @@
+#
+# Time sensors
+#
+menu "Time sensors"
+
+config HID_SENSOR_TIME
+	depends on HID_SENSOR_HUB
+	select HID_SENSOR_IIO_COMMON
+	tristate "HID Time"
+	help
+	  Say yes here to build support for the HID SENSOR Time.
+	  This drivers makes such sensors available as RTCs.
+
+endmenu
diff --git a/drivers/iio/time/Makefile b/drivers/iio/time/Makefile
new file mode 100644
index 0000000..705fe0d
--- /dev/null
+++ b/drivers/iio/time/Makefile
@@ -0,0 +1,5 @@
+#
+# Makefile for industrial I/O Time sensor driver
+#
+
+obj-$(CONFIG_HID_SENSOR_TIME) += hid-sensor-time.o
diff --git a/drivers/iio/time/hid-sensor-time.c b/drivers/iio/time/hid-sensor-time.c
new file mode 100644
index 0000000..a5993d6
--- /dev/null
+++ b/drivers/iio/time/hid-sensor-time.c
@@ -0,0 +1,397 @@
+/*
+ * HID Sensor Time Driver
+ * Copyright (c) 2012, Alexander Holler.
+ *
+ * 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 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/module.h>
+#include <linux/hid-sensor-hub.h>
+#include <linux/iio/iio.h>
+#include <linux/rtc.h>
+#include "../common/hid-sensors/hid-sensor-attributes.h"
+
+/* Format: HID-SENSOR-usage_id_in_hex */
+/* Usage ID from spec for Time: 0x2000A0 */
+#define DRIVER_NAME "HID-SENSOR-2000a0" /* must be lowercase */
+
+enum hid_time_channel {
+	CHANNEL_SCAN_INDEX_YEAR,
+	CHANNEL_SCAN_INDEX_MONTH,
+	CHANNEL_SCAN_INDEX_DAY,
+	CHANNEL_SCAN_INDEX_HOUR,
+	CHANNEL_SCAN_INDEX_MINUTE,
+	CHANNEL_SCAN_INDEX_SECOND,
+	TIME_RTC_CHANNEL_MAX,
+};
+
+struct hid_time_state {
+	struct hid_sensor_hub_callbacks callbacks;
+	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_hub_attribute_info info[TIME_RTC_CHANNEL_MAX];
+	struct rtc_time last_time;
+	spinlock_t lock_last_time;
+	struct completion comp_last_time;
+	struct rtc_time time_buf;
+	struct rtc_device *rtc;
+};
+
+static const u32 hid_time_addresses[TIME_RTC_CHANNEL_MAX] = {
+	HID_USAGE_SENSOR_TIME_YEAR,
+	HID_USAGE_SENSOR_TIME_MONTH,
+	HID_USAGE_SENSOR_TIME_DAY,
+	HID_USAGE_SENSOR_TIME_HOUR,
+	HID_USAGE_SENSOR_TIME_MINUTE,
+	HID_USAGE_SENSOR_TIME_SECOND,
+};
+
+/* Channel definitions */
+static const struct iio_chan_spec hid_time_channels[TIME_RTC_CHANNEL_MAX] = {
+	{
+		.info_mask = IIO_CHAN_INFO_RAW,
+		.scan_index = CHANNEL_SCAN_INDEX_YEAR,
+		.extend_name = "year",
+	}, {
+		.info_mask = IIO_CHAN_INFO_RAW,
+		.scan_index = CHANNEL_SCAN_INDEX_MONTH,
+		.extend_name = "month",
+	}, {
+		.info_mask = IIO_CHAN_INFO_RAW,
+		.scan_index = CHANNEL_SCAN_INDEX_DAY,
+		.extend_name = "day",
+	}, {
+		.info_mask = IIO_CHAN_INFO_RAW,
+		.scan_index = CHANNEL_SCAN_INDEX_HOUR,
+		.extend_name = "hour",
+	}, {
+		.info_mask = IIO_CHAN_INFO_RAW,
+		.scan_index = CHANNEL_SCAN_INDEX_MINUTE,
+		.extend_name = "minute",
+	}, {
+		.info_mask = IIO_CHAN_INFO_RAW,
+		.scan_index = CHANNEL_SCAN_INDEX_SECOND,
+		.extend_name = "second",
+	}
+};
+
+/* Adjust channel real bits based on report descriptor */
+static void hid_time_adjust_channel_bit_mask(struct iio_chan_spec *channels,
+						int channel, int size)
+{
+	channels[channel].scan_type.sign = 'u';
+	/* Real storage bits will change based on the report desc. */
+	channels[channel].scan_type.realbits = size * 8;
+	/* Maximum size of a sample to capture is u8 */
+	channels[channel].scan_type.storagebits = sizeof(u8) * 8;
+}
+
+static int hid_time_read_raw(struct iio_dev *indio_dev,
+			      struct iio_chan_spec const *chan,
+			      int *val, int *val2,
+			      long mask)
+{
+	struct hid_time_state *time_state = iio_priv(indio_dev);
+	int report_id;
+	u32 address;
+
+	*val = 0;
+	*val2 = 0;
+	if(mask)
+		return -EINVAL;
+	report_id = time_state->info[chan->scan_index].report_id;
+	address = hid_time_addresses[chan->scan_index];
+	if (report_id >= 0) {
+		*val = sensor_hub_input_attr_get_raw_value(
+			time_state->common_attributes.hsdev,
+			HID_USAGE_SENSOR_TIME, address, report_id);
+		return IIO_VAL_INT;
+	}
+	*val = 0;
+	return -EINVAL;
+}
+
+/* Callback handler to send event after all samples are received and captured */
+static int hid_time_proc_event(struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id, void *priv)
+{
+	unsigned long flags;
+	struct iio_dev *indio_dev = platform_get_drvdata(priv);
+	struct hid_time_state *time_state = iio_priv(indio_dev);
+
+	spin_lock_irqsave(&time_state->lock_last_time, flags);
+	time_state->last_time = time_state->time_buf;
+	spin_unlock_irqrestore(&time_state->lock_last_time, flags);
+	complete(&time_state->comp_last_time);
+	return 0;
+}
+
+static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id, size_t raw_len,
+				char *raw_data, void *priv)
+{
+	struct iio_dev *indio_dev = platform_get_drvdata(priv);
+	struct hid_time_state *time_state = iio_priv(indio_dev);
+	struct rtc_time *time_buf = &time_state->time_buf;
+
+	switch (usage_id) {
+	case HID_USAGE_SENSOR_TIME_YEAR:
+		time_buf->tm_year = *(u8 *)raw_data;
+		if (time_buf->tm_year < 70)
+			/* assume we are in 1970...2069 */
+			time_buf->tm_year += 100;
+		break;
+	case HID_USAGE_SENSOR_TIME_MONTH:
+		time_buf->tm_mon = --*(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_DAY:
+		time_buf->tm_mday = *(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_HOUR:
+		time_buf->tm_hour = *(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_MINUTE:
+		time_buf->tm_min = *(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_SECOND:
+		time_buf->tm_sec = *(u8 *)raw_data;
+		break;
+	default:
+		return -EINVAL;
+	}
+	return 0;
+}
+
+static int hid_time_parse_report(struct platform_device *pdev,
+				struct hid_sensor_hub_device *hsdev,
+				struct iio_chan_spec *channels,
+				unsigned usage_id, struct hid_time_state *st)
+{
+	int ret, i=0;
+
+	for (; i < TIME_RTC_CHANNEL_MAX; ++i) {
+		ret = sensor_hub_input_get_attribute_info(hsdev,
+				HID_INPUT_REPORT, usage_id,
+				hid_time_addresses[i], &st->info[i]);
+		if (ret < 0)
+			return ret;
+		hid_time_adjust_channel_bit_mask(channels, i,
+				st->info[i].size);
+	}
+
+	return ret;
+}
+
+static int hid_rtc_read_time(struct device *dev,
+	struct rtc_time *tm)
+{
+	int val;
+	unsigned long flags;
+	struct iio_dev *indio_dev =
+		platform_get_drvdata(to_platform_device(dev));
+	struct hid_time_state *time_state = iio_priv(indio_dev);
+
+	init_completion(&time_state->comp_last_time);
+	/* start a read */
+	if (hid_time_read_raw(indio_dev,
+			&hid_time_channels[0], &val, &val, 0) == -EINVAL) {
+		dev_err(dev, "unable to read time!\n");
+		return -EIO;
+	}
+	/* wait for all values (event) */
+	wait_for_completion_interruptible_timeout(&time_state->comp_last_time,
+							HZ*6);
+	spin_lock_irqsave(&time_state->lock_last_time, flags);
+	*tm = time_state->last_time;
+	spin_unlock_irqrestore(&time_state->lock_last_time, flags);
+
+	return 0;
+}
+
+/* small helper, haven't found any other way */
+static const char *attrib_name(u32 attrib_id)
+{
+	unsigned i=0;
+	static const char unknown[] = "unknown";
+
+	for(; i< TIME_RTC_CHANNEL_MAX; ++i) {
+		if(hid_time_addresses[i] == attrib_id)
+			return hid_time_channels[i].extend_name;
+	}
+	return unknown; /* should never happen */
+}
+
+static const struct iio_info hid_time_info = {
+	.driver_module = THIS_MODULE,
+	.read_raw = &hid_time_read_raw,
+};
+
+static const struct rtc_class_ops rtc_ops = {
+	.read_time = hid_rtc_read_time,
+};
+
+static int __devinit hid_time_probe(struct platform_device *pdev)
+{
+	int temp, ret = 0;
+	static char *name = "hid_time";
+	struct hid_time_state *time_state;
+	struct iio_chan_spec *channels;
+	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct iio_dev *indio_dev = iio_device_alloc(sizeof(struct hid_time_state));
+
+	if (indio_dev == NULL) {
+		ret = -ENOMEM;
+		goto error_ret;
+	}
+	platform_set_drvdata(pdev, indio_dev);
+
+	time_state = iio_priv(indio_dev);
+	time_state->common_attributes.hsdev = hsdev;
+	time_state->common_attributes.pdev = pdev;
+
+	ret = hid_sensor_parse_common_attributes(hsdev,
+				HID_USAGE_SENSOR_TIME,
+				&time_state->common_attributes);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to setup common attributes!\n");
+		goto error_free_dev;
+	}
+
+	channels = kmemdup(hid_time_channels,
+					sizeof(hid_time_channels),
+					GFP_KERNEL);
+	if (!channels) {
+		dev_err(&pdev->dev, "failed to duplicate channels!\n");
+		goto error_free_dev;
+	}
+
+	ret = hid_time_parse_report(pdev, hsdev, channels,
+				HID_USAGE_SENSOR_TIME, time_state);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to setup attributes!\n");
+		goto error_free_dev_mem;
+	}
+
+	/* Check the attributes we need for sanity */
+	temp = time_state->info[ret].report_id;
+	if (temp<0) {
+		dev_err(&pdev->dev, "bad report ID!\n");
+		goto error_free_dev_mem;
+	}
+	for (ret = 0; ret< TIME_RTC_CHANNEL_MAX; ++ret) {
+		if (time_state->info[ret].report_id != temp) {
+			dev_err(&pdev->dev,
+				"not all needed attributes inside the same report!\n");
+			goto error_free_dev_mem;
+		}
+		if (time_state->info[ret].size != 1) {
+			dev_err(&pdev->dev,
+				"attribute '%s' not 8 bits wide!\n",
+				attrib_name(time_state->info[ret].attrib_id));
+			goto error_free_dev_mem;
+		}
+		if (time_state->info[ret].units !=
+				HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED &&
+				/* allow attribute seconds with unit seconds */
+				!(time_state->info[ret].attrib_id ==
+				HID_USAGE_SENSOR_TIME_SECOND &&
+				time_state->info[ret].units ==
+				HID_USAGE_SENSOR_UNITS_SECOND)) {
+			dev_err(&pdev->dev,
+				"attribute '%s' hasn't a unit of type 'none'!\n",
+				attrib_name(time_state->info[ret].attrib_id));
+			goto error_free_dev_mem;
+		}
+		if (time_state->info[ret].unit_expo) {
+			dev_err(&pdev->dev,
+				"attribute '%s' hasn't a unit exponent of 1!\n",
+				attrib_name(time_state->info[ret].attrib_id));
+			goto error_free_dev_mem;
+		}
+	}
+
+	indio_dev->channels = channels;
+	indio_dev->num_channels = ARRAY_SIZE(hid_time_channels);
+	indio_dev->dev.parent = &pdev->dev;
+	indio_dev->info = &hid_time_info;
+	indio_dev->name = name;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+
+	ret = iio_device_register(indio_dev);
+	if (ret) {
+		dev_err(&pdev->dev, "device register failed!\n");
+		goto error_free_dev_mem;
+	}
+
+	time_state->callbacks.send_event = hid_time_proc_event;
+	time_state->callbacks.capture_sample = hid_time_capture_sample;
+	time_state->callbacks.pdev = pdev;
+	ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_TIME,
+					&time_state->callbacks);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "register callback failed!\n");
+		goto error_iio_unreg;
+	}
+
+	time_state->rtc = rtc_device_register("hid-sensor-time",
+				&pdev->dev, &rtc_ops, THIS_MODULE);
+
+	if (IS_ERR(time_state->rtc)) {
+		ret = PTR_ERR(time_state->rtc);
+		dev_err(&pdev->dev, "rtc device register failed!\n");
+		goto error_iio_unreg;
+	}
+
+	return ret;
+
+error_iio_unreg:
+	iio_device_unregister(indio_dev);
+error_free_dev_mem:
+	kfree(indio_dev->channels);
+error_free_dev:
+	iio_device_free(indio_dev);
+error_ret:
+	return ret;
+}
+
+static int __devinit hid_time_remove(struct platform_device *pdev)
+{
+	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
+	struct hid_time_state *time_state = iio_priv(indio_dev);
+
+	if (!IS_ERR(time_state->rtc))
+		rtc_device_unregister(time_state->rtc);
+	sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
+	iio_device_unregister(indio_dev);
+	kfree(indio_dev->channels);
+	iio_device_free(indio_dev);
+
+	return 0;
+}
+
+static struct platform_driver hid_time_platform_driver = {
+	.driver = {
+		.name	= DRIVER_NAME,
+		.owner	= THIS_MODULE,
+	},
+	.probe		= hid_time_probe,
+	.remove		= hid_time_remove,
+};
+module_platform_driver(hid_time_platform_driver);
+
+MODULE_DESCRIPTION("HID Sensor Time");
+MODULE_AUTHOR("Alexander Holler <holler@ahsoftware.de>");
+MODULE_LICENSE("GPL");
-- 
1.7.8.6


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

* Re: [PATCH 3/3] iio: add rtc-driver for HID sensors of type time
  2012-12-09 12:21 ` [PATCH 3/3] iio: add rtc-driver for HID sensors of type time Alexander Holler
@ 2012-12-09 12:55   ` Lars-Peter Clausen
  2012-12-09 16:40     ` Alexander Holler
  0 siblings, 1 reply; 66+ messages in thread
From: Lars-Peter Clausen @ 2012-12-09 12:55 UTC (permalink / raw)
  To: Alexander Holler
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada

On 12/09/2012 01:21 PM, Alexander Holler wrote:
> This driver makes the time from HID sensors (hubs) which are offering
> such available like any other RTC does.
> 
> Currently the time can only be read. Setting the time must be done
> through sending a report, which currently isn't supported by
> hid-sensor-hub.
> 
> It is necessary that all values like year, month etc, are send as
> 8bit values (1 byte each) and all of them in 1 report. Also the
> spec HUTRR39b doesn't define the range of the year field, we
> tread it as 0 - 99 because that's what most RTCs I know about are
> offering.

I don't think we should register a IIO device for this. Just an RTC device
should be fully sufficient.

> 
> Signed-off-by: Alexander Holler <holler@ahsoftware.de>
> ---
>  drivers/iio/Kconfig                |    1 +
>  drivers/iio/Makefile               |    1 +
>  drivers/iio/time/Kconfig           |   14 ++
>  drivers/iio/time/Makefile          |    5 +
>  drivers/iio/time/hid-sensor-time.c |  397 ++++++++++++++++++++++++++++++++++++
>  5 files changed, 418 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/iio/time/Kconfig
>  create mode 100644 drivers/iio/time/Makefile
>  create mode 100644 drivers/iio/time/hid-sensor-time.c
> 
> diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
> index fc937ac..78fa3ff 100644
> --- a/drivers/iio/Kconfig
> +++ b/drivers/iio/Kconfig
> @@ -63,5 +63,6 @@ source "drivers/iio/dac/Kconfig"
>  source "drivers/iio/common/Kconfig"
>  source "drivers/iio/gyro/Kconfig"
>  source "drivers/iio/magnetometer/Kconfig"
> +source "drivers/iio/time/Kconfig"
>  
>  endif # IIO
> diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
> index 761f2b6..6a6da31 100644
> --- a/drivers/iio/Makefile
> +++ b/drivers/iio/Makefile
> @@ -19,3 +19,4 @@ obj-y += dac/
>  obj-y += common/
>  obj-y += gyro/
>  obj-y += magnetometer/
> +obj-y += time/
> diff --git a/drivers/iio/time/Kconfig b/drivers/iio/time/Kconfig
> new file mode 100644
> index 0000000..0ca4682
> --- /dev/null
> +++ b/drivers/iio/time/Kconfig
> @@ -0,0 +1,14 @@
> +#
> +# Time sensors
> +#
> +menu "Time sensors"
> +
> +config HID_SENSOR_TIME
> +	depends on HID_SENSOR_HUB
> +	select HID_SENSOR_IIO_COMMON
> +	tristate "HID Time"
> +	help
> +	  Say yes here to build support for the HID SENSOR Time.
> +	  This drivers makes such sensors available as RTCs.
> +
> +endmenu
> diff --git a/drivers/iio/time/Makefile b/drivers/iio/time/Makefile
> new file mode 100644
> index 0000000..705fe0d
> --- /dev/null
> +++ b/drivers/iio/time/Makefile
> @@ -0,0 +1,5 @@
> +#
> +# Makefile for industrial I/O Time sensor driver
> +#
> +
> +obj-$(CONFIG_HID_SENSOR_TIME) += hid-sensor-time.o
> diff --git a/drivers/iio/time/hid-sensor-time.c b/drivers/iio/time/hid-sensor-time.c
> new file mode 100644
> index 0000000..a5993d6
> --- /dev/null
> +++ b/drivers/iio/time/hid-sensor-time.c
> @@ -0,0 +1,397 @@
> +/*
> + * HID Sensor Time Driver
> + * Copyright (c) 2012, Alexander Holler.
> + *
> + * 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 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, write to the Free Software Foundation, Inc.,
> + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
> + *
> + */
> +#include <linux/device.h>
> +#include <linux/platform_device.h>
> +#include <linux/module.h>
> +#include <linux/hid-sensor-hub.h>
> +#include <linux/iio/iio.h>
> +#include <linux/rtc.h>
> +#include "../common/hid-sensors/hid-sensor-attributes.h"
> +
> +/* Format: HID-SENSOR-usage_id_in_hex */
> +/* Usage ID from spec for Time: 0x2000A0 */
> +#define DRIVER_NAME "HID-SENSOR-2000a0" /* must be lowercase */
> +
> +enum hid_time_channel {
> +	CHANNEL_SCAN_INDEX_YEAR,
> +	CHANNEL_SCAN_INDEX_MONTH,
> +	CHANNEL_SCAN_INDEX_DAY,
> +	CHANNEL_SCAN_INDEX_HOUR,
> +	CHANNEL_SCAN_INDEX_MINUTE,
> +	CHANNEL_SCAN_INDEX_SECOND,
> +	TIME_RTC_CHANNEL_MAX,
> +};
> +
> +struct hid_time_state {
> +	struct hid_sensor_hub_callbacks callbacks;
> +	struct hid_sensor_iio_common common_attributes;
> +	struct hid_sensor_hub_attribute_info info[TIME_RTC_CHANNEL_MAX];
> +	struct rtc_time last_time;
> +	spinlock_t lock_last_time;
> +	struct completion comp_last_time;
> +	struct rtc_time time_buf;
> +	struct rtc_device *rtc;
> +};
> +
> +static const u32 hid_time_addresses[TIME_RTC_CHANNEL_MAX] = {
> +	HID_USAGE_SENSOR_TIME_YEAR,
> +	HID_USAGE_SENSOR_TIME_MONTH,
> +	HID_USAGE_SENSOR_TIME_DAY,
> +	HID_USAGE_SENSOR_TIME_HOUR,
> +	HID_USAGE_SENSOR_TIME_MINUTE,
> +	HID_USAGE_SENSOR_TIME_SECOND,
> +};
> +
> +/* Channel definitions */
> +static const struct iio_chan_spec hid_time_channels[TIME_RTC_CHANNEL_MAX] = {
> +	{
> +		.info_mask = IIO_CHAN_INFO_RAW,
> +		.scan_index = CHANNEL_SCAN_INDEX_YEAR,
> +		.extend_name = "year",
> +	}, {
> +		.info_mask = IIO_CHAN_INFO_RAW,
> +		.scan_index = CHANNEL_SCAN_INDEX_MONTH,
> +		.extend_name = "month",
> +	}, {
> +		.info_mask = IIO_CHAN_INFO_RAW,
> +		.scan_index = CHANNEL_SCAN_INDEX_DAY,
> +		.extend_name = "day",
> +	}, {
> +		.info_mask = IIO_CHAN_INFO_RAW,
> +		.scan_index = CHANNEL_SCAN_INDEX_HOUR,
> +		.extend_name = "hour",
> +	}, {
> +		.info_mask = IIO_CHAN_INFO_RAW,
> +		.scan_index = CHANNEL_SCAN_INDEX_MINUTE,
> +		.extend_name = "minute",
> +	}, {
> +		.info_mask = IIO_CHAN_INFO_RAW,
> +		.scan_index = CHANNEL_SCAN_INDEX_SECOND,
> +		.extend_name = "second",
> +	}
> +};
> +
> +/* Adjust channel real bits based on report descriptor */
> +static void hid_time_adjust_channel_bit_mask(struct iio_chan_spec *channels,
> +						int channel, int size)
> +{
> +	channels[channel].scan_type.sign = 'u';
> +	/* Real storage bits will change based on the report desc. */
> +	channels[channel].scan_type.realbits = size * 8;
> +	/* Maximum size of a sample to capture is u8 */
> +	channels[channel].scan_type.storagebits = sizeof(u8) * 8;
> +}
> +
> +static int hid_time_read_raw(struct iio_dev *indio_dev,
> +			      struct iio_chan_spec const *chan,
> +			      int *val, int *val2,
> +			      long mask)
> +{
> +	struct hid_time_state *time_state = iio_priv(indio_dev);
> +	int report_id;
> +	u32 address;
> +
> +	*val = 0;
> +	*val2 = 0;
> +	if(mask)
> +		return -EINVAL;
> +	report_id = time_state->info[chan->scan_index].report_id;
> +	address = hid_time_addresses[chan->scan_index];
> +	if (report_id >= 0) {
> +		*val = sensor_hub_input_attr_get_raw_value(
> +			time_state->common_attributes.hsdev,
> +			HID_USAGE_SENSOR_TIME, address, report_id);
> +		return IIO_VAL_INT;
> +	}
> +	*val = 0;
> +	return -EINVAL;
> +}
> +
> +/* Callback handler to send event after all samples are received and captured */
> +static int hid_time_proc_event(struct hid_sensor_hub_device *hsdev,
> +				unsigned usage_id, void *priv)
> +{
> +	unsigned long flags;
> +	struct iio_dev *indio_dev = platform_get_drvdata(priv);
> +	struct hid_time_state *time_state = iio_priv(indio_dev);
> +
> +	spin_lock_irqsave(&time_state->lock_last_time, flags);
> +	time_state->last_time = time_state->time_buf;
> +	spin_unlock_irqrestore(&time_state->lock_last_time, flags);
> +	complete(&time_state->comp_last_time);
> +	return 0;
> +}
> +
> +static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev,
> +				unsigned usage_id, size_t raw_len,
> +				char *raw_data, void *priv)
> +{
> +	struct iio_dev *indio_dev = platform_get_drvdata(priv);
> +	struct hid_time_state *time_state = iio_priv(indio_dev);
> +	struct rtc_time *time_buf = &time_state->time_buf;
> +
> +	switch (usage_id) {
> +	case HID_USAGE_SENSOR_TIME_YEAR:
> +		time_buf->tm_year = *(u8 *)raw_data;
> +		if (time_buf->tm_year < 70)
> +			/* assume we are in 1970...2069 */
> +			time_buf->tm_year += 100;
> +		break;
> +	case HID_USAGE_SENSOR_TIME_MONTH:
> +		time_buf->tm_mon = --*(u8 *)raw_data;
> +		break;
> +	case HID_USAGE_SENSOR_TIME_DAY:
> +		time_buf->tm_mday = *(u8 *)raw_data;
> +		break;
> +	case HID_USAGE_SENSOR_TIME_HOUR:
> +		time_buf->tm_hour = *(u8 *)raw_data;
> +		break;
> +	case HID_USAGE_SENSOR_TIME_MINUTE:
> +		time_buf->tm_min = *(u8 *)raw_data;
> +		break;
> +	case HID_USAGE_SENSOR_TIME_SECOND:
> +		time_buf->tm_sec = *(u8 *)raw_data;
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +	return 0;
> +}
> +
> +static int hid_time_parse_report(struct platform_device *pdev,
> +				struct hid_sensor_hub_device *hsdev,
> +				struct iio_chan_spec *channels,
> +				unsigned usage_id, struct hid_time_state *st)
> +{
> +	int ret, i=0;
> +
> +	for (; i < TIME_RTC_CHANNEL_MAX; ++i) {
> +		ret = sensor_hub_input_get_attribute_info(hsdev,
> +				HID_INPUT_REPORT, usage_id,
> +				hid_time_addresses[i], &st->info[i]);
> +		if (ret < 0)
> +			return ret;
> +		hid_time_adjust_channel_bit_mask(channels, i,
> +				st->info[i].size);
> +	}
> +
> +	return ret;
> +}
> +
> +static int hid_rtc_read_time(struct device *dev,
> +	struct rtc_time *tm)
> +{
> +	int val;
> +	unsigned long flags;
> +	struct iio_dev *indio_dev =
> +		platform_get_drvdata(to_platform_device(dev));
> +	struct hid_time_state *time_state = iio_priv(indio_dev);
> +
> +	init_completion(&time_state->comp_last_time);
> +	/* start a read */
> +	if (hid_time_read_raw(indio_dev,
> +			&hid_time_channels[0], &val, &val, 0) == -EINVAL) {
> +		dev_err(dev, "unable to read time!\n");
> +		return -EIO;
> +	}
> +	/* wait for all values (event) */
> +	wait_for_completion_interruptible_timeout(&time_state->comp_last_time,
> +							HZ*6);
> +	spin_lock_irqsave(&time_state->lock_last_time, flags);
> +	*tm = time_state->last_time;
> +	spin_unlock_irqrestore(&time_state->lock_last_time, flags);
> +
> +	return 0;
> +}
> +
> +/* small helper, haven't found any other way */
> +static const char *attrib_name(u32 attrib_id)
> +{
> +	unsigned i=0;
> +	static const char unknown[] = "unknown";
> +
> +	for(; i< TIME_RTC_CHANNEL_MAX; ++i) {
> +		if(hid_time_addresses[i] == attrib_id)
> +			return hid_time_channels[i].extend_name;
> +	}
> +	return unknown; /* should never happen */
> +}
> +
> +static const struct iio_info hid_time_info = {
> +	.driver_module = THIS_MODULE,
> +	.read_raw = &hid_time_read_raw,
> +};
> +
> +static const struct rtc_class_ops rtc_ops = {
> +	.read_time = hid_rtc_read_time,
> +};
> +
> +static int __devinit hid_time_probe(struct platform_device *pdev)
> +{
> +	int temp, ret = 0;
> +	static char *name = "hid_time";
> +	struct hid_time_state *time_state;
> +	struct iio_chan_spec *channels;
> +	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
> +	struct iio_dev *indio_dev = iio_device_alloc(sizeof(struct hid_time_state));
> +
> +	if (indio_dev == NULL) {
> +		ret = -ENOMEM;
> +		goto error_ret;
> +	}
> +	platform_set_drvdata(pdev, indio_dev);
> +
> +	time_state = iio_priv(indio_dev);
> +	time_state->common_attributes.hsdev = hsdev;
> +	time_state->common_attributes.pdev = pdev;
> +
> +	ret = hid_sensor_parse_common_attributes(hsdev,
> +				HID_USAGE_SENSOR_TIME,
> +				&time_state->common_attributes);
> +	if (ret) {
> +		dev_err(&pdev->dev, "failed to setup common attributes!\n");
> +		goto error_free_dev;
> +	}
> +
> +	channels = kmemdup(hid_time_channels,
> +					sizeof(hid_time_channels),
> +					GFP_KERNEL);
> +	if (!channels) {
> +		dev_err(&pdev->dev, "failed to duplicate channels!\n");
> +		goto error_free_dev;
> +	}
> +
> +	ret = hid_time_parse_report(pdev, hsdev, channels,
> +				HID_USAGE_SENSOR_TIME, time_state);
> +	if (ret) {
> +		dev_err(&pdev->dev, "failed to setup attributes!\n");
> +		goto error_free_dev_mem;
> +	}
> +
> +	/* Check the attributes we need for sanity */
> +	temp = time_state->info[ret].report_id;
> +	if (temp<0) {
> +		dev_err(&pdev->dev, "bad report ID!\n");
> +		goto error_free_dev_mem;
> +	}
> +	for (ret = 0; ret< TIME_RTC_CHANNEL_MAX; ++ret) {
> +		if (time_state->info[ret].report_id != temp) {
> +			dev_err(&pdev->dev,
> +				"not all needed attributes inside the same report!\n");
> +			goto error_free_dev_mem;
> +		}
> +		if (time_state->info[ret].size != 1) {
> +			dev_err(&pdev->dev,
> +				"attribute '%s' not 8 bits wide!\n",
> +				attrib_name(time_state->info[ret].attrib_id));
> +			goto error_free_dev_mem;
> +		}
> +		if (time_state->info[ret].units !=
> +				HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED &&
> +				/* allow attribute seconds with unit seconds */
> +				!(time_state->info[ret].attrib_id ==
> +				HID_USAGE_SENSOR_TIME_SECOND &&
> +				time_state->info[ret].units ==
> +				HID_USAGE_SENSOR_UNITS_SECOND)) {
> +			dev_err(&pdev->dev,
> +				"attribute '%s' hasn't a unit of type 'none'!\n",
> +				attrib_name(time_state->info[ret].attrib_id));
> +			goto error_free_dev_mem;
> +		}
> +		if (time_state->info[ret].unit_expo) {
> +			dev_err(&pdev->dev,
> +				"attribute '%s' hasn't a unit exponent of 1!\n",
> +				attrib_name(time_state->info[ret].attrib_id));
> +			goto error_free_dev_mem;
> +		}
> +	}
> +
> +	indio_dev->channels = channels;
> +	indio_dev->num_channels = ARRAY_SIZE(hid_time_channels);
> +	indio_dev->dev.parent = &pdev->dev;
> +	indio_dev->info = &hid_time_info;
> +	indio_dev->name = name;
> +	indio_dev->modes = INDIO_DIRECT_MODE;
> +
> +	ret = iio_device_register(indio_dev);
> +	if (ret) {
> +		dev_err(&pdev->dev, "device register failed!\n");
> +		goto error_free_dev_mem;
> +	}
> +
> +	time_state->callbacks.send_event = hid_time_proc_event;
> +	time_state->callbacks.capture_sample = hid_time_capture_sample;
> +	time_state->callbacks.pdev = pdev;
> +	ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_TIME,
> +					&time_state->callbacks);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "register callback failed!\n");
> +		goto error_iio_unreg;
> +	}
> +
> +	time_state->rtc = rtc_device_register("hid-sensor-time",
> +				&pdev->dev, &rtc_ops, THIS_MODULE);
> +
> +	if (IS_ERR(time_state->rtc)) {
> +		ret = PTR_ERR(time_state->rtc);
> +		dev_err(&pdev->dev, "rtc device register failed!\n");
> +		goto error_iio_unreg;
> +	}
> +
> +	return ret;
> +
> +error_iio_unreg:
> +	iio_device_unregister(indio_dev);
> +error_free_dev_mem:
> +	kfree(indio_dev->channels);
> +error_free_dev:
> +	iio_device_free(indio_dev);
> +error_ret:
> +	return ret;
> +}
> +
> +static int __devinit hid_time_remove(struct platform_device *pdev)
> +{
> +	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
> +	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
> +	struct hid_time_state *time_state = iio_priv(indio_dev);
> +
> +	if (!IS_ERR(time_state->rtc))
> +		rtc_device_unregister(time_state->rtc);
> +	sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
> +	iio_device_unregister(indio_dev);
> +	kfree(indio_dev->channels);
> +	iio_device_free(indio_dev);
> +
> +	return 0;
> +}
> +
> +static struct platform_driver hid_time_platform_driver = {
> +	.driver = {
> +		.name	= DRIVER_NAME,
> +		.owner	= THIS_MODULE,
> +	},
> +	.probe		= hid_time_probe,
> +	.remove		= hid_time_remove,
> +};
> +module_platform_driver(hid_time_platform_driver);
> +
> +MODULE_DESCRIPTION("HID Sensor Time");
> +MODULE_AUTHOR("Alexander Holler <holler@ahsoftware.de>");
> +MODULE_LICENSE("GPL");


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

* Re: [PATCH 3/3] iio: add rtc-driver for HID sensors of type time
  2012-12-09 12:55   ` Lars-Peter Clausen
@ 2012-12-09 16:40     ` Alexander Holler
  2012-12-09 18:16       ` Alexander Holler
  0 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-09 16:40 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada

Am 09.12.2012 13:55, schrieb Lars-Peter Clausen:
> On 12/09/2012 01:21 PM, Alexander Holler wrote:
>> This driver makes the time from HID sensors (hubs) which are offering
>> such available like any other RTC does.
>>
>> Currently the time can only be read. Setting the time must be done
>> through sending a report, which currently isn't supported by
>> hid-sensor-hub.
>>
>> It is necessary that all values like year, month etc, are send as
>> 8bit values (1 byte each) and all of them in 1 report. Also the
>> spec HUTRR39b doesn't define the range of the year field, we
>> tread it as 0 - 99 because that's what most RTCs I know about are
>> offering.
>
> I don't think we should register a IIO device for this. Just an RTC device
> should be fully sufficient.
>

You would have to implement all the used services hid-sensor-hub offers 
in the rtc-driver again.

Regards,

Alexander


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

* Re: [PATCH 3/3] iio: add rtc-driver for HID sensors of type time
  2012-12-09 16:40     ` Alexander Holler
@ 2012-12-09 18:16       ` Alexander Holler
  2012-12-09 19:20         ` Lars-Peter Clausen
  0 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-09 18:16 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada

Am 09.12.2012 17:40, schrieb Alexander Holler:
> Am 09.12.2012 13:55, schrieb Lars-Peter Clausen:
>> On 12/09/2012 01:21 PM, Alexander Holler wrote:
>>> This driver makes the time from HID sensors (hubs) which are offering
>>> such available like any other RTC does.
>>>
>>> Currently the time can only be read. Setting the time must be done
>>> through sending a report, which currently isn't supported by
>>> hid-sensor-hub.
>>>
>>> It is necessary that all values like year, month etc, are send as
>>> 8bit values (1 byte each) and all of them in 1 report. Also the
>>> spec HUTRR39b doesn't define the range of the year field, we
>>> tread it as 0 - 99 because that's what most RTCs I know about are
>>> offering.
>>
>> I don't think we should register a IIO device for this. Just an RTC
>> device
>> should be fully sufficient.
>>
>
> You would have to implement all the used services hid-sensor-hub offers
> in the rtc-driver again.

Besides that, time is part of the spec for HID sensors, which makes 
sense. Making that available as a RTC to read/set the time is imho the 
best to way support that. If you want a driver which doesn't use the HID 
sensor hub framework (or iio), you would either have to define your own 
standard or make sure it is interoperable with the HID sensor hub 
framework, which might not be trivial.

Regards,

Alexander

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

* Re: [PATCH 3/3] iio: add rtc-driver for HID sensors of type time
  2012-12-09 18:16       ` Alexander Holler
@ 2012-12-09 19:20         ` Lars-Peter Clausen
  2012-12-10 13:12           ` Alexander Holler
  0 siblings, 1 reply; 66+ messages in thread
From: Lars-Peter Clausen @ 2012-12-09 19:20 UTC (permalink / raw)
  To: Alexander Holler
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada

On 12/09/2012 07:16 PM, Alexander Holler wrote:
> Am 09.12.2012 17:40, schrieb Alexander Holler:
>> Am 09.12.2012 13:55, schrieb Lars-Peter Clausen:
>>> On 12/09/2012 01:21 PM, Alexander Holler wrote:
>>>> This driver makes the time from HID sensors (hubs) which are offering
>>>> such available like any other RTC does.
>>>>
>>>> Currently the time can only be read. Setting the time must be done
>>>> through sending a report, which currently isn't supported by
>>>> hid-sensor-hub.
>>>>
>>>> It is necessary that all values like year, month etc, are send as
>>>> 8bit values (1 byte each) and all of them in 1 report. Also the
>>>> spec HUTRR39b doesn't define the range of the year field, we
>>>> tread it as 0 - 99 because that's what most RTCs I know about are
>>>> offering.
>>>
>>> I don't think we should register a IIO device for this. Just an RTC
>>> device
>>> should be fully sufficient.
>>>
>>
>> You would have to implement all the used services hid-sensor-hub offers
>> in the rtc-driver again.
> 
> Besides that, time is part of the spec for HID sensors, which makes
> sense. Making that available as a RTC to read/set the time is imho the
> best to way support that. If you want a driver which doesn't use the HID
> sensor hub framework (or iio), you would either have to define your own
> standard or make sure it is interoperable with the HID sensor hub
> framework, which might not be trivial.

I agree with what you wrote above. It just doesn't make sense to register a IIO
device for a RTC type device. Just rip out all the IIO related bits from the
driver and it will be fine.

- Lars


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

* Re: [PATCH 3/3] iio: add rtc-driver for HID sensors of type time
  2012-12-09 19:20         ` Lars-Peter Clausen
@ 2012-12-10 13:12           ` Alexander Holler
  2012-12-10 14:51             ` [PATCH 3/3 v2] " Alexander Holler
  0 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-10 13:12 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada

Am 09.12.2012 20:20, schrieb Lars-Peter Clausen:

> I agree with what you wrote above. It just doesn't make sense to register a IIO
> device for a RTC type device. Just rip out all the IIO related bits from the
> driver and it will be fine.

Ah, I misunderstood you. Yes, you are right. As I already have removed 
the buffer, trigger and the exposure of attributes in sysfs (the driver 
started as a copy from one of the other hid sensor drivers), the IIO 
device itself doesn't make sense anymore.

I will remove it.

Regards,

Alexander


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

* [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time
  2012-12-10 13:12           ` Alexander Holler
@ 2012-12-10 14:51             ` Alexander Holler
  2012-12-10 17:05               ` Lars-Peter Clausen
  0 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-10 14:51 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-iio, Jonathan Cameron, rtc-linux, Alessandro Zummo,
	srinivas pandruvada, Alexander Holler

This driver makes the time from HID sensors (hubs) which are offering
such available like any other RTC does.

Currently the time can only be read. Setting the time must be done
through sending a report, which currently isn't supported by
hid-sensor-hub.

It is necessary that all values like year, month etc, are send as
8bit values (1 byte each) and all of them in 1 report. Also the
spec HUTRR39b doesn't define the range of the year field, we
tread it as 0 - 99 because that's what most RTCs I know about are
offering.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 drivers/iio/Kconfig                |    1 +
 drivers/iio/Makefile               |    1 +
 drivers/iio/time/Kconfig           |   14 ++
 drivers/iio/time/Makefile          |    5 +
 drivers/iio/time/hid-sensor-time.c |  346 ++++++++++++++++++++++++++++++++++++
 5 files changed, 367 insertions(+), 0 deletions(-)
 create mode 100644 drivers/iio/time/Kconfig
 create mode 100644 drivers/iio/time/Makefile
 create mode 100644 drivers/iio/time/hid-sensor-time.c

diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
index fc937ac..78fa3ff 100644
--- a/drivers/iio/Kconfig
+++ b/drivers/iio/Kconfig
@@ -63,5 +63,6 @@ source "drivers/iio/dac/Kconfig"
 source "drivers/iio/common/Kconfig"
 source "drivers/iio/gyro/Kconfig"
 source "drivers/iio/magnetometer/Kconfig"
+source "drivers/iio/time/Kconfig"
 
 endif # IIO
diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
index 761f2b6..6a6da31 100644
--- a/drivers/iio/Makefile
+++ b/drivers/iio/Makefile
@@ -19,3 +19,4 @@ obj-y += dac/
 obj-y += common/
 obj-y += gyro/
 obj-y += magnetometer/
+obj-y += time/
diff --git a/drivers/iio/time/Kconfig b/drivers/iio/time/Kconfig
new file mode 100644
index 0000000..0ca4682
--- /dev/null
+++ b/drivers/iio/time/Kconfig
@@ -0,0 +1,14 @@
+#
+# Time sensors
+#
+menu "Time sensors"
+
+config HID_SENSOR_TIME
+	depends on HID_SENSOR_HUB
+	select HID_SENSOR_IIO_COMMON
+	tristate "HID Time"
+	help
+	  Say yes here to build support for the HID SENSOR Time.
+	  This drivers makes such sensors available as RTCs.
+
+endmenu
diff --git a/drivers/iio/time/Makefile b/drivers/iio/time/Makefile
new file mode 100644
index 0000000..705fe0d
--- /dev/null
+++ b/drivers/iio/time/Makefile
@@ -0,0 +1,5 @@
+#
+# Makefile for industrial I/O Time sensor driver
+#
+
+obj-$(CONFIG_HID_SENSOR_TIME) += hid-sensor-time.o
diff --git a/drivers/iio/time/hid-sensor-time.c b/drivers/iio/time/hid-sensor-time.c
new file mode 100644
index 0000000..556bac9
--- /dev/null
+++ b/drivers/iio/time/hid-sensor-time.c
@@ -0,0 +1,346 @@
+/*
+ * HID Sensor Time Driver
+ * Copyright (c) 2012, Alexander Holler.
+ *
+ * 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 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/module.h>
+#include <linux/hid-sensor-hub.h>
+#include <linux/iio/iio.h>
+#include <linux/rtc.h>
+#include "../common/hid-sensors/hid-sensor-attributes.h"
+
+/* Format: HID-SENSOR-usage_id_in_hex */
+/* Usage ID from spec for Time: 0x2000A0 */
+#define DRIVER_NAME "HID-SENSOR-2000a0" /* must be lowercase */
+
+enum hid_time_channel {
+	CHANNEL_SCAN_INDEX_YEAR,
+	CHANNEL_SCAN_INDEX_MONTH,
+	CHANNEL_SCAN_INDEX_DAY,
+	CHANNEL_SCAN_INDEX_HOUR,
+	CHANNEL_SCAN_INDEX_MINUTE,
+	CHANNEL_SCAN_INDEX_SECOND,
+	TIME_RTC_CHANNEL_MAX,
+};
+
+struct hid_time_state {
+	struct hid_sensor_hub_callbacks callbacks;
+	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_hub_attribute_info info[TIME_RTC_CHANNEL_MAX];
+	struct rtc_time last_time;
+	spinlock_t lock_last_time;
+	struct completion comp_last_time;
+	struct rtc_time time_buf;
+	struct rtc_device *rtc;
+};
+
+static const u32 hid_time_addresses[TIME_RTC_CHANNEL_MAX] = {
+	HID_USAGE_SENSOR_TIME_YEAR,
+	HID_USAGE_SENSOR_TIME_MONTH,
+	HID_USAGE_SENSOR_TIME_DAY,
+	HID_USAGE_SENSOR_TIME_HOUR,
+	HID_USAGE_SENSOR_TIME_MINUTE,
+	HID_USAGE_SENSOR_TIME_SECOND,
+};
+
+/* Channel definitions */
+static const struct iio_chan_spec hid_time_channels[TIME_RTC_CHANNEL_MAX] = {
+	{
+		.info_mask = IIO_CHAN_INFO_RAW,
+		.scan_index = CHANNEL_SCAN_INDEX_YEAR,
+		.extend_name = "year",
+	}, {
+		.info_mask = IIO_CHAN_INFO_RAW,
+		.scan_index = CHANNEL_SCAN_INDEX_MONTH,
+		.extend_name = "month",
+	}, {
+		.info_mask = IIO_CHAN_INFO_RAW,
+		.scan_index = CHANNEL_SCAN_INDEX_DAY,
+		.extend_name = "day",
+	}, {
+		.info_mask = IIO_CHAN_INFO_RAW,
+		.scan_index = CHANNEL_SCAN_INDEX_HOUR,
+		.extend_name = "hour",
+	}, {
+		.info_mask = IIO_CHAN_INFO_RAW,
+		.scan_index = CHANNEL_SCAN_INDEX_MINUTE,
+		.extend_name = "minute",
+	}, {
+		.info_mask = IIO_CHAN_INFO_RAW,
+		.scan_index = CHANNEL_SCAN_INDEX_SECOND,
+		.extend_name = "second",
+	}
+};
+
+static int hid_time_read_raw(struct hid_time_state *time_state,
+			      struct iio_chan_spec const *chan,
+			      int *val, int *val2,
+			      long mask)
+{
+	int report_id;
+	u32 address;
+
+	*val = 0;
+	*val2 = 0;
+	if (mask)
+		return -EINVAL;
+	report_id = time_state->info[chan->scan_index].report_id;
+	address = hid_time_addresses[chan->scan_index];
+	if (report_id >= 0) {
+		*val = sensor_hub_input_attr_get_raw_value(
+			time_state->common_attributes.hsdev,
+			HID_USAGE_SENSOR_TIME, address, report_id);
+		return IIO_VAL_INT;
+	}
+	*val = 0;
+	return -EINVAL;
+}
+
+/* Callback handler to send event after all samples are received and captured */
+static int hid_time_proc_event(struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id, void *priv)
+{
+	unsigned long flags;
+	struct hid_time_state *time_state = platform_get_drvdata(priv);
+
+	spin_lock_irqsave(&time_state->lock_last_time, flags);
+	time_state->last_time = time_state->time_buf;
+	spin_unlock_irqrestore(&time_state->lock_last_time, flags);
+	complete(&time_state->comp_last_time);
+	return 0;
+}
+
+static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id, size_t raw_len,
+				char *raw_data, void *priv)
+{
+	struct hid_time_state *time_state = platform_get_drvdata(priv);
+	struct rtc_time *time_buf = &time_state->time_buf;
+
+	switch (usage_id) {
+	case HID_USAGE_SENSOR_TIME_YEAR:
+		time_buf->tm_year = *(u8 *)raw_data;
+		if (time_buf->tm_year < 70)
+			/* assume we are in 1970...2069 */
+			time_buf->tm_year += 100;
+		break;
+	case HID_USAGE_SENSOR_TIME_MONTH:
+		time_buf->tm_mon = --*(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_DAY:
+		time_buf->tm_mday = *(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_HOUR:
+		time_buf->tm_hour = *(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_MINUTE:
+		time_buf->tm_min = *(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_SECOND:
+		time_buf->tm_sec = *(u8 *)raw_data;
+		break;
+	default:
+		return -EINVAL;
+	}
+	return 0;
+}
+
+/* small helper, haven't found any other way */
+static const char *attrib_name(u32 attrib_id)
+{
+	unsigned i = 0;
+	static const char unknown[] = "unknown";
+
+	for (; i < TIME_RTC_CHANNEL_MAX; ++i) {
+		if (hid_time_addresses[i] == attrib_id)
+			return hid_time_channels[i].extend_name;
+	}
+	return unknown; /* should never happen */
+}
+
+static int hid_time_parse_report(struct platform_device *pdev,
+				struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id,
+				struct hid_time_state *time_state)
+{
+	int ret, i = 0;
+
+	for (; i < TIME_RTC_CHANNEL_MAX; ++i) {
+		ret = sensor_hub_input_get_attribute_info(hsdev,
+				HID_INPUT_REPORT, usage_id,
+				hid_time_addresses[i], &time_state->info[i]);
+		if (ret < 0)
+			return ret;
+	}
+	/* Check the (needed) attributes for sanity */
+	ret = time_state->info[0].report_id; /* use ret as temp. */
+	if (ret < 0) {
+		dev_err(&pdev->dev, "bad report ID!\n");
+		return -EINVAL;
+	}
+	for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) {
+		if (time_state->info[i].report_id != ret) {
+			dev_err(&pdev->dev,
+				"not all needed attributes inside the same report!\n");
+			return -EINVAL;
+		}
+		if (time_state->info[i].size != 1) {
+			dev_err(&pdev->dev,
+				"attribute '%s' not 8 bits wide!\n",
+				attrib_name(time_state->info[i].attrib_id));
+			return -EINVAL;
+		}
+		if (time_state->info[i].units !=
+				HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED &&
+				/* allow attribute seconds with unit seconds */
+				!(time_state->info[i].attrib_id ==
+				HID_USAGE_SENSOR_TIME_SECOND &&
+				time_state->info[i].units ==
+				HID_USAGE_SENSOR_UNITS_SECOND)) {
+			dev_err(&pdev->dev,
+				"attribute '%s' hasn't a unit of type 'none'!\n",
+				attrib_name(time_state->info[i].attrib_id));
+			return -EINVAL;
+		}
+		if (time_state->info[i].unit_expo) {
+			dev_err(&pdev->dev,
+				"attribute '%s' hasn't a unit exponent of 1!\n",
+				attrib_name(time_state->info[i].attrib_id));
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+static int hid_rtc_read_time(struct device *dev,
+	struct rtc_time *tm)
+{
+	int val;
+	unsigned long flags;
+	struct hid_time_state *time_state =
+		platform_get_drvdata(to_platform_device(dev));
+
+	init_completion(&time_state->comp_last_time);
+	/* start a read */
+	if (hid_time_read_raw(time_state,
+			&hid_time_channels[0], &val, &val, 0) == -EINVAL) {
+		dev_err(dev, "unable to read time!\n");
+		return -EIO;
+	}
+	/* wait for all values (event) */
+	wait_for_completion_interruptible_timeout(&time_state->comp_last_time,
+							HZ*6);
+	spin_lock_irqsave(&time_state->lock_last_time, flags);
+	*tm = time_state->last_time;
+	spin_unlock_irqrestore(&time_state->lock_last_time, flags);
+
+	return 0;
+}
+
+static const struct rtc_class_ops rtc_ops = {
+	.read_time = hid_rtc_read_time,
+};
+
+static int __devinit hid_time_probe(struct platform_device *pdev)
+{
+	int ret = 0;
+	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct hid_time_state *time_state =
+		kzalloc(sizeof(struct hid_time_state), GFP_KERNEL);
+
+	if (time_state == NULL) {
+		ret = -ENOMEM;
+		goto error_ret;
+	}
+
+	platform_set_drvdata(pdev, time_state);
+
+	time_state->common_attributes.hsdev = hsdev;
+	time_state->common_attributes.pdev = pdev;
+
+	ret = hid_sensor_parse_common_attributes(hsdev,
+				HID_USAGE_SENSOR_TIME,
+				&time_state->common_attributes);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to setup common attributes!\n");
+		goto error_free_drvdata;
+	}
+
+	ret = hid_time_parse_report(pdev, hsdev, /*channels,*/
+				HID_USAGE_SENSOR_TIME, time_state);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to setup attributes!\n");
+		goto error_free_drvdata;
+	}
+
+	time_state->callbacks.send_event = hid_time_proc_event;
+	time_state->callbacks.capture_sample = hid_time_capture_sample;
+	time_state->callbacks.pdev = pdev;
+	ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_TIME,
+					&time_state->callbacks);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "register callback failed!\n");
+		goto error_free_drvdata;
+	}
+
+	time_state->rtc = rtc_device_register("hid-sensor-time",
+				&pdev->dev, &rtc_ops, THIS_MODULE);
+
+	if (IS_ERR(time_state->rtc)) {
+		ret = PTR_ERR(time_state->rtc);
+		dev_err(&pdev->dev, "rtc device register failed!\n");
+		goto error_free_drvdata;
+	}
+
+	return ret;
+
+error_free_drvdata:
+	platform_set_drvdata(pdev, NULL);
+	kfree(time_state);
+error_ret:
+	return ret;
+}
+
+static int __devinit hid_time_remove(struct platform_device *pdev)
+{
+	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct hid_time_state *time_state = platform_get_drvdata(pdev);
+
+	if (!IS_ERR(time_state->rtc))
+		rtc_device_unregister(time_state->rtc);
+	sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
+	platform_set_drvdata(pdev, NULL);
+	kfree(time_state);
+
+	return 0;
+}
+
+static struct platform_driver hid_time_platform_driver = {
+	.driver = {
+		.name	= DRIVER_NAME,
+		.owner	= THIS_MODULE,
+	},
+	.probe		= hid_time_probe,
+	.remove		= hid_time_remove,
+};
+module_platform_driver(hid_time_platform_driver);
+
+MODULE_DESCRIPTION("HID Sensor Time");
+MODULE_AUTHOR("Alexander Holler <holler@ahsoftware.de>");
+MODULE_LICENSE("GPL");
-- 
1.7.8.6


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

* Re: [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time
  2012-12-10 14:51             ` [PATCH 3/3 v2] " Alexander Holler
@ 2012-12-10 17:05               ` Lars-Peter Clausen
  2012-12-10 19:45                 ` Alexander Holler
  2012-12-10 22:20                 ` Alexander Holler
  0 siblings, 2 replies; 66+ messages in thread
From: Lars-Peter Clausen @ 2012-12-10 17:05 UTC (permalink / raw)
  To: Alexander Holler
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada

On 12/10/2012 03:51 PM, Alexander Holler wrote:
> This driver makes the time from HID sensors (hubs) which are offering
> such available like any other RTC does.
> 
> Currently the time can only be read. Setting the time must be done
> through sending a report, which currently isn't supported by
> hid-sensor-hub.
> 
> It is necessary that all values like year, month etc, are send as
> 8bit values (1 byte each) and all of them in 1 report. Also the
> spec HUTRR39b doesn't define the range of the year field, we
> tread it as 0 - 99 because that's what most RTCs I know about are
> offering.
> 
> Signed-off-by: Alexander Holler <holler@ahsoftware.de>

Looks pretty good now. But there are still some IIO remnants which should be
removed as well. Also the driver should move to drivers/rtc/ since, well,
it's a rtc driver not a IIO driver.

> diff --git a/drivers/iio/time/hid-sensor-time.c b/drivers/iio/time/hid-sensor-time.c
> new file mode 100644
> index 0000000..556bac9
> --- /dev/null
> +++ b/drivers/iio/time/hid-sensor-time.c
> @@ -0,0 +1,346 @@
[...]
> +
> +/* Channel definitions */
> +static const struct iio_chan_spec hid_time_channels[TIME_RTC_CHANNEL_MAX] = {
> +	{
> +		.info_mask = IIO_CHAN_INFO_RAW,
> +		.scan_index = CHANNEL_SCAN_INDEX_YEAR,
> +		.extend_name = "year",
> +	}, {
> +		.info_mask = IIO_CHAN_INFO_RAW,
> +		.scan_index = CHANNEL_SCAN_INDEX_MONTH,
> +		.extend_name = "month",
> +	}, {
> +		.info_mask = IIO_CHAN_INFO_RAW,
> +		.scan_index = CHANNEL_SCAN_INDEX_DAY,
> +		.extend_name = "day",
> +	}, {
> +		.info_mask = IIO_CHAN_INFO_RAW,
> +		.scan_index = CHANNEL_SCAN_INDEX_HOUR,
> +		.extend_name = "hour",
> +	}, {
> +		.info_mask = IIO_CHAN_INFO_RAW,
> +		.scan_index = CHANNEL_SCAN_INDEX_MINUTE,
> +		.extend_name = "minute",
> +	}, {
> +		.info_mask = IIO_CHAN_INFO_RAW,
> +		.scan_index = CHANNEL_SCAN_INDEX_SECOND,
> +		.extend_name = "second",
> +	}
> +};

The channel spec is semi unused. You use it to lookup the scan index and the
name, but that could easily be implemented without the channel spec.
Especially considering that the scan index lookup is only ever done for
channel 0, which will always return CHANNEL_SCAN_INDEX_YEAR.

> +
> +static int hid_time_read_raw(struct hid_time_state *time_state,
> +			      struct iio_chan_spec const *chan,
> +			      int *val, int *val2,
> +			      long mask)
> +{
> +	int report_id;
> +	u32 address;
> +
> +	*val = 0;
> +	*val2 = 0;
> +	if (mask)
> +		return -EINVAL;
> +	report_id = time_state->info[chan->scan_index].report_id;
> +	address = hid_time_addresses[chan->scan_index];
> +	if (report_id >= 0) {
> +		*val = sensor_hub_input_attr_get_raw_value(
> +			time_state->common_attributes.hsdev,
> +			HID_USAGE_SENSOR_TIME, address, report_id);

Just directly call sensor_hub_input_attr_get_raw_value in hid_rtc_read_time
instead of wrapping it here.

> +		return IIO_VAL_INT;
> +	}
> +	*val = 0;
> +	return -EINVAL;
> +}
> +

[...]

Are the entries in info ordered in the same way as the addresses in
hid_time_addresses? If yes you could just use a lookup-table like

static const char * const hid_time_attrib_names[] = {
	"second",
	...
};

and just use 'i' to look them up.

> +static const char *attrib_name(u32 attrib_id)
> +{
> +	unsigned i = 0;
> +	static const char unknown[] = "unknown";
> +
> +	for (; i < TIME_RTC_CHANNEL_MAX; ++i) {
> +		if (hid_time_addresses[i] == attrib_id)
> +			return hid_time_channels[i].extend_name;
> +	}
> +	return unknown; /* should never happen */
> +}
> +
> +static int hid_time_parse_report(struct platform_device *pdev,
> +				struct hid_sensor_hub_device *hsdev,
> +				unsigned usage_id,
> +				struct hid_time_state *time_state)
> +{
> +	int ret, i = 0;
> +
> +	for (; i < TIME_RTC_CHANNEL_MAX; ++i) {

I'd put the i = 0 in the for header.

> +		ret = sensor_hub_input_get_attribute_info(hsdev,
> +				HID_INPUT_REPORT, usage_id,
> +				hid_time_addresses[i], &time_state->info[i]);
> +		if (ret < 0)
> +			return ret;
> +	}
> +	/* Check the (needed) attributes for sanity */
> +	ret = time_state->info[0].report_id; /* use ret as temp. */

maybe name it report_id instead of ret

> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "bad report ID!\n");
> +		return -EINVAL;
> +	}
> +	for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) {
> +		if (time_state->info[i].report_id != ret) {
> +			dev_err(&pdev->dev,
> +				"not all needed attributes inside the same report!\n");
> +			return -EINVAL;
> +		}
[...]
> +	}
> +
> +	return 0;
> +}
> +
> +static int hid_rtc_read_time(struct device *dev,
> +	struct rtc_time *tm)
> +{
> +	int val;
> +	unsigned long flags;
> +	struct hid_time_state *time_state =
> +		platform_get_drvdata(to_platform_device(dev));
> +
> +	init_completion(&time_state->comp_last_time);

This needs to be INIT_COMPLETION. init_completion must be called exactly
once on a completion, which should be from inside probe() in this case.

> +	/* start a read */
> +	if (hid_time_read_raw(time_state,
> +			&hid_time_channels[0], &val, &val, 0) == -EINVAL) {
> +		dev_err(dev, "unable to read time!\n");
> +		return -EIO;
> +	}
> +	/* wait for all values (event) */
> +	wait_for_completion_interruptible_timeout(&time_state->comp_last_time,
> +							HZ*6);

You should check the return value in case either a timeout happens or the
sleep is interrupted.

> +	spin_lock_irqsave(&time_state->lock_last_time, flags);
> +	*tm = time_state->last_time;
> +	spin_unlock_irqrestore(&time_state->lock_last_time, flags);
> +
> +	return 0;
> +}
> +
> +static const struct rtc_class_ops rtc_ops = {
> +	.read_time = hid_rtc_read_time,
> +};
> +
> +static int __devinit hid_time_probe(struct platform_device *pdev)

__devinit is going away, it shouldn't be used anymore in new drivers.

> +{
> +	int ret = 0;
> +	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
> +	struct hid_time_state *time_state =
> +		kzalloc(sizeof(struct hid_time_state), GFP_KERNEL);

You could use devm_kzalloc here. By doing so you don't have to take care of
freeing it again since it will be auto-freed once the device is removed.

> +
> +	if (time_state == NULL) {
> +		ret = -ENOMEM;
> +		goto error_ret;
> +	}
> +
> +	platform_set_drvdata(pdev, time_state);
> +
> +	time_state->common_attributes.hsdev = hsdev;
> +	time_state->common_attributes.pdev = pdev;
> +
> +	ret = hid_sensor_parse_common_attributes(hsdev,
> +				HID_USAGE_SENSOR_TIME,
> +				&time_state->common_attributes);
> +	if (ret) {
> +		dev_err(&pdev->dev, "failed to setup common attributes!\n");
> +		goto error_free_drvdata;
> +	}
> +
> +	ret = hid_time_parse_report(pdev, hsdev, /*channels,*/

remove the commented out code

> +				HID_USAGE_SENSOR_TIME, time_state);
> +	if (ret) {
> +		dev_err(&pdev->dev, "failed to setup attributes!\n");
> +		goto error_free_drvdata;
> +	}
> +
> +	time_state->callbacks.send_event = hid_time_proc_event;
> +	time_state->callbacks.capture_sample = hid_time_capture_sample;
> +	time_state->callbacks.pdev = pdev;
> +	ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_TIME,
> +					&time_state->callbacks);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "register callback failed!\n");
> +		goto error_free_drvdata;
> +	}
> +
> +	time_state->rtc = rtc_device_register("hid-sensor-time",
> +				&pdev->dev, &rtc_ops, THIS_MODULE);

Since the driver does not do much if the rtc device could not be registered
I think it should be ok to fail probe in case registering the rtc device fails.

> +
> +	if (IS_ERR(time_state->rtc)) {
> +		ret = PTR_ERR(time_state->rtc);
> +		dev_err(&pdev->dev, "rtc device register failed!\n");
> +		goto error_free_drvdata;
> +	}
> +
> +	return ret;
> +
> +error_free_drvdata:
> +	platform_set_drvdata(pdev, NULL);

Setting the platform data to NULL should not be necessary. Some drivers do
this but it's kind of the result of cargo-cult-coding.

> +	kfree(time_state);
> +error_ret:
> +	return ret;
> +}
> +
> +static int __devinit hid_time_remove(struct platform_device *pdev)
> +{
> +	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
> +	struct hid_time_state *time_state = platform_get_drvdata(pdev);
> +
> +	if (!IS_ERR(time_state->rtc))
> +		rtc_device_unregister(time_state->rtc);
> +	sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
> +	platform_set_drvdata(pdev, NULL);

Same here.

> +	kfree(time_state);
> +
> +	return 0;
> +}
> +
[...]

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

* Re: [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time
  2012-12-10 17:05               ` Lars-Peter Clausen
@ 2012-12-10 19:45                 ` Alexander Holler
  2012-12-10 20:22                   ` Lars-Peter Clausen
  2012-12-10 22:20                 ` Alexander Holler
  1 sibling, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-10 19:45 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada

Am 10.12.2012 18:05, schrieb Lars-Peter Clausen:

> Looks pretty good now. But there are still some IIO remnants which should be
> removed as well. Also the driver should move to drivers/rtc/ since, well,
> it's a rtc driver not a IIO driver.

I think it still should be stick to iio, because that is where all HID
sensors currently are found and where the user would expect to find such
a driver.

>> +/* Channel definitions */
>> +static const struct iio_chan_spec hid_time_channels[TIME_RTC_CHANNEL_MAX] = {

And that is imho the last remaining iio-stuff. If necessary I can remove
it too.

Regards,

Alexander

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

* Re: [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time
  2012-12-10 19:45                 ` Alexander Holler
@ 2012-12-10 20:22                   ` Lars-Peter Clausen
  2012-12-10 21:26                     ` Alexander Holler
  0 siblings, 1 reply; 66+ messages in thread
From: Lars-Peter Clausen @ 2012-12-10 20:22 UTC (permalink / raw)
  To: Alexander Holler
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada

On 12/10/2012 08:45 PM, Alexander Holler wrote:
> Am 10.12.2012 18:05, schrieb Lars-Peter Clausen:
> 
>> Looks pretty good now. But there are still some IIO remnants which should be
>> removed as well. Also the driver should move to drivers/rtc/ since, well,
>> it's a rtc driver not a IIO driver.
> 
> I think it still should be stick to iio, because that is where all HID
> sensors currently are found and where the user would expect to find such
> a driver.

That's because all the current IIO sensor drivers fall in the IIO domain. This
one clearly is a RTC driver, so it belongs in drivers/rtc/

> 
>>> +/* Channel definitions */
>>> +static const struct iio_chan_spec hid_time_channels[TIME_RTC_CHANNEL_MAX] = {
> 
> And that is imho the last remaining iio-stuff. If necessary I can remove
> it too.

That and the remaining bits of the read_raw callback.

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

* Re: [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time
  2012-12-10 20:22                   ` Lars-Peter Clausen
@ 2012-12-10 21:26                     ` Alexander Holler
  2012-12-10 21:39                       ` Lars-Peter Clausen
  0 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-10 21:26 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada

Am 10.12.2012 21:22, schrieb Lars-Peter Clausen:
> On 12/10/2012 08:45 PM, Alexander Holler wrote:
>> Am 10.12.2012 18:05, schrieb Lars-Peter Clausen:
>>
>>> Looks pretty good now. But there are still some IIO remnants which should be
>>> removed as well. Also the driver should move to drivers/rtc/ since, well,
>>> it's a rtc driver not a IIO driver.
>>
>> I think it still should be stick to iio, because that is where all HID
>> sensors currently are found and where the user would expect to find such
>> a driver.
> 
> That's because all the current IIO sensor drivers fall in the IIO domain. This
> one clearly is a RTC driver, so it belongs in drivers/rtc/

Where nobody will find it if he searches for drivers for his HID sensor.
I still see it as HID sensor driver and not a rtc-driver.
But ...

> 
>>
>>>> +/* Channel definitions */
>>>> +static const struct iio_chan_spec hid_time_channels[TIME_RTC_CHANNEL_MAX] = {
>>
>> And that is imho the last remaining iio-stuff. If necessary I can remove
>> it too.
> 
> That and the remaining bits of the read_raw callback.

Ok. I will make a v3.

Alexander

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

* Re: [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time
  2012-12-10 21:26                     ` Alexander Holler
@ 2012-12-10 21:39                       ` Lars-Peter Clausen
  2012-12-10 21:42                         ` Jonathan Cameron
  0 siblings, 1 reply; 66+ messages in thread
From: Lars-Peter Clausen @ 2012-12-10 21:39 UTC (permalink / raw)
  To: Alexander Holler
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada

On 12/10/2012 10:26 PM, Alexander Holler wrote:
> Am 10.12.2012 21:22, schrieb Lars-Peter Clausen:
>> On 12/10/2012 08:45 PM, Alexander Holler wrote:
>>> Am 10.12.2012 18:05, schrieb Lars-Peter Clausen:
>>>
>>>> Looks pretty good now. But there are still some IIO remnants which should be
>>>> removed as well. Also the driver should move to drivers/rtc/ since, well,
>>>> it's a rtc driver not a IIO driver.
>>>
>>> I think it still should be stick to iio, because that is where all HID
>>> sensors currently are found and where the user would expect to find such
>>> a driver.
>>
>> That's because all the current IIO sensor drivers fall in the IIO domain. This
>> one clearly is a RTC driver, so it belongs in drivers/rtc/
> 
> Where nobody will find it if he searches for drivers for his HID sensor.
> I still see it as HID sensor driver and not a rtc-driver.
> But ...

I can understand your position, but drivers are usually grouped by function not
by topology. If there is a proper Kconfig help text people should hopefully be
find it.

> 
>>
>>>
>>>>> +/* Channel definitions */
>>>>> +static const struct iio_chan_spec hid_time_channels[TIME_RTC_CHANNEL_MAX] = {
>>>
>>> And that is imho the last remaining iio-stuff. If necessary I can remove
>>> it too.
>>
>> That and the remaining bits of the read_raw callback.
> 
> Ok. I will make a v3.
> 

Btw. have you seen the other comments I had inline in my response to your v2?

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

* Re: [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time
  2012-12-10 21:39                       ` Lars-Peter Clausen
@ 2012-12-10 21:42                         ` Jonathan Cameron
  2012-12-10 22:50                           ` Alexander Holler
  0 siblings, 1 reply; 66+ messages in thread
From: Jonathan Cameron @ 2012-12-10 21:42 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Alexander Holler, linux-kernel, linux-iio, Jonathan Cameron,
	rtc-linux, Alessandro Zummo, srinivas pandruvada

On 12/10/2012 09:39 PM, Lars-Peter Clausen wrote:
> On 12/10/2012 10:26 PM, Alexander Holler wrote:
>> Am 10.12.2012 21:22, schrieb Lars-Peter Clausen:
>>> On 12/10/2012 08:45 PM, Alexander Holler wrote:
>>>> Am 10.12.2012 18:05, schrieb Lars-Peter Clausen:
>>>>
>>>>> Looks pretty good now. But there are still some IIO remnants which should be
>>>>> removed as well. Also the driver should move to drivers/rtc/ since, well,
>>>>> it's a rtc driver not a IIO driver.
>>>>
>>>> I think it still should be stick to iio, because that is where all HID
>>>> sensors currently are found and where the user would expect to find such
>>>> a driver.
>>>
>>> That's because all the current IIO sensor drivers fall in the IIO domain. This
>>> one clearly is a RTC driver, so it belongs in drivers/rtc/
>>
>> Where nobody will find it if he searches for drivers for his HID sensor.
>> I still see it as HID sensor driver and not a rtc-driver.
>> But ...
> 
> I can understand your position, but drivers are usually grouped by function not
> by topology. If there is a proper Kconfig help text people should hopefully be
> find it.
Seconded on this. If it is a pure rtc driver then it definitely belongs in
drivers/rtc.  Now there might have been ways of doing this as a consumer / provider
with the provider being in IIO and the consumer in rtc, but that sounds like
it is over compicating things, at least for now.

> 
>>
>>>
>>>>
>>>>>> +/* Channel definitions */
>>>>>> +static const struct iio_chan_spec hid_time_channels[TIME_RTC_CHANNEL_MAX] = {
>>>>
>>>> And that is imho the last remaining iio-stuff. If necessary I can remove
>>>> it too.
>>>
>>> That and the remaining bits of the read_raw callback.
>>
>> Ok. I will make a v3.
>>
> 
> Btw. have you seen the other comments I had inline in my response to your v2?
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

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

* Re: [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time
  2012-12-10 17:05               ` Lars-Peter Clausen
  2012-12-10 19:45                 ` Alexander Holler
@ 2012-12-10 22:20                 ` Alexander Holler
  2012-12-10 22:36                   ` Lars-Peter Clausen
  1 sibling, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-10 22:20 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada

Am 10.12.2012 18:05, schrieb Lars-Peter Clausen:
> On 12/10/2012 03:51 PM, Alexander Holler wrote:

> The channel spec is semi unused. You use it to lookup the scan index and the
> name, but that could easily be implemented without the channel spec.
> Especially considering that the scan index lookup is only ever done for
> channel 0, which will always return CHANNEL_SCAN_INDEX_YEAR.

Thats what I had in mind for v3.

> Are the entries in info ordered in the same way as the addresses in
> hid_time_addresses? If yes you could just use a lookup-table like
>
> static const char * const hid_time_attrib_names[] = {
> 	"second",
> 	...
> };
>
> and just use 'i' to look them up.

Again, what I had in mind for v3. It would have been better I wouldn't 
have used one of the existing drivers as template and afterwards 
removing tons of stuff. ;)

>> +	init_completion(&time_state->comp_last_time);
>
> This needs to be INIT_COMPLETION. init_completion must be called exactly
> once on a completion, which should be from inside probe() in this case.

Ah, so I've misread http://lwn.net/Articles/23993/ . I've read it as 
init_completion() is usable multiple times (I had the impression 
INIT_COMPLETION got replaced by init_completion().

>> +	/* wait for all values (event) */
>> +	wait_for_completion_interruptible_timeout(&time_state->comp_last_time,
>> +							HZ*6);
>
> You should check the return value in case either a timeout happens or the
> sleep is interrupted.

Yes, I already wanted to do it, but it seems I've forgotten it.

>> +	struct hid_time_state *time_state =
>> +		kzalloc(sizeof(struct hid_time_state), GFP_KERNEL);
>
> You could use devm_kzalloc here. By doing so you don't have to take care of
> freeing it again since it will be auto-freed once the device is removed.

Thanks. I already searched such and wondered why such didn't exist. Just 
to clarify, if I use devm_kzalloc, I don't have to free time_state here

>> +error_free_drvdata:
>> +	platform_set_drvdata(pdev, NULL);
>
> Setting the platform data to NULL should not be necessary. Some drivers do
> this but it's kind of the result of cargo-cult-coding.
>
>> +	kfree(time_state);
>> +error_ret:
>> +	return ret;
>> +}
>> +
>> +static int __devinit hid_time_remove(struct platform_device *pdev)
>> +{
>> +	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
>> +	struct hid_time_state *time_state = platform_get_drvdata(pdev);
>> +
>> +	if (!IS_ERR(time_state->rtc))
>> +		rtc_device_unregister(time_state->rtc);
>> +	sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
>> +	platform_set_drvdata(pdev, NULL);
>

and here?

> Same here.
>
>> +	kfree(time_state);
>> +
>> +	return 0;
>> +}
>> +
> [...]

Regards,

Alexander

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

* Re: [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time
  2012-12-10 22:20                 ` Alexander Holler
@ 2012-12-10 22:36                   ` Lars-Peter Clausen
  2012-12-11  0:01                     ` Alexander Holler
  0 siblings, 1 reply; 66+ messages in thread
From: Lars-Peter Clausen @ 2012-12-10 22:36 UTC (permalink / raw)
  To: Alexander Holler
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada

On 12/10/2012 11:20 PM, Alexander Holler wrote:
> [...]
>>> +    init_completion(&time_state->comp_last_time);
>>
>> This needs to be INIT_COMPLETION. init_completion must be called exactly
>> once on a completion, which should be from inside probe() in this case.
> 
> Ah, so I've misread http://lwn.net/Articles/23993/ . I've read it as
> init_completion() is usable multiple times (I had the impression
> INIT_COMPLETION got replaced by init_completion().
> 

Well, I've been exaggerating a bit, you can call it multiple times, but you
need to make sure that the completion is not in use at the same time, since
init_completion will completely reinitialize the struct and if it is in use at
the same time you'll get undefined behavior. So it is a good rule of thumb to
just use it once in probe(). INIT_COMPLETION on the other hand will just clear
the done flag, so you know that between your call to INIT_COMPLETION and when
wait_for_completion returns successfully your event has occurred at least once.

>>> +    /* wait for all values (event) */
>>> +   
>>> wait_for_completion_interruptible_timeout(&time_state->comp_last_time,
>>> +                            HZ*6);
>>
>> You should check the return value in case either a timeout happens or the
>> sleep is interrupted.
> 
> Yes, I already wanted to do it, but it seems I've forgotten it.
> 
>>> +    struct hid_time_state *time_state =
>>> +        kzalloc(sizeof(struct hid_time_state), GFP_KERNEL);
>>
>> You could use devm_kzalloc here. By doing so you don't have to take
>> care of
>> freeing it again since it will be auto-freed once the device is removed.
> 
> Thanks. I already searched such and wondered why such didn't exist. Just
> to clarify, if I use devm_kzalloc, I don't have to free time_state here
> 
>>> +error_free_drvdata:
>>> +    platform_set_drvdata(pdev, NULL);
>>
>> Setting the platform data to NULL should not be necessary. Some
>> drivers do
>> this but it's kind of the result of cargo-cult-coding.
>>
>>> +    kfree(time_state);
>>> +error_ret:
>>> +    return ret;
>>> +}
>>> +
>>> +static int __devinit hid_time_remove(struct platform_device *pdev)
>>> +{
>>> +    struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
>>> +    struct hid_time_state *time_state = platform_get_drvdata(pdev);
>>> +
>>> +    if (!IS_ERR(time_state->rtc))
>>> +        rtc_device_unregister(time_state->rtc);
>>> +    sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
>>> +    platform_set_drvdata(pdev, NULL);
>>
> 
> and here?
> 

yes.


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

* Re: [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time
  2012-12-10 21:42                         ` Jonathan Cameron
@ 2012-12-10 22:50                           ` Alexander Holler
  2012-12-11  9:31                             ` Jonathan Cameron
  0 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-10 22:50 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Lars-Peter Clausen, linux-kernel, linux-iio, Jonathan Cameron,
	rtc-linux, Alessandro Zummo, srinivas pandruvada

Am 10.12.2012 22:42, schrieb Jonathan Cameron:
> On 12/10/2012 09:39 PM, Lars-Peter Clausen wrote:
>> On 12/10/2012 10:26 PM, Alexander Holler wrote:
>>> Am 10.12.2012 21:22, schrieb Lars-Peter Clausen:
>>>> On 12/10/2012 08:45 PM, Alexander Holler wrote:
>>>>> Am 10.12.2012 18:05, schrieb Lars-Peter Clausen:
>>>>>
>>>>>> Looks pretty good now. But there are still some IIO remnants which should be
>>>>>> removed as well. Also the driver should move to drivers/rtc/ since, well,
>>>>>> it's a rtc driver not a IIO driver.
>>>>>
>>>>> I think it still should be stick to iio, because that is where all HID
>>>>> sensors currently are found and where the user would expect to find such
>>>>> a driver.
>>>>
>>>> That's because all the current IIO sensor drivers fall in the IIO domain. This
>>>> one clearly is a RTC driver, so it belongs in drivers/rtc/
>>>
>>> Where nobody will find it if he searches for drivers for his HID sensor.
>>> I still see it as HID sensor driver and not a rtc-driver.
>>> But ...
>>
>> I can understand your position, but drivers are usually grouped by function not
>> by topology. If there is a proper Kconfig help text people should hopefully be
>> find it.
> Seconded on this. If it is a pure rtc driver then it definitely belongs in
> drivers/rtc.  Now there might have been ways of doing this as a consumer / provider
> with the provider being in IIO and the consumer in rtc, but that sounds like
> it is over compicating things, at least for now.

Personally I just want to use it to have HID-USB_RTCs. ;)

But in case of HID sensor hubs, the main usage of that driver will be to 
set the time of such hubs (something I still have to make patches for), 
and not to read it. So if you think as an HID sensor user, it should 
belong to iio or wherever those sensor will finally end up (I think they 
should end up in HID and should be usable by bluetooth devices too), but 
if you creatively misuse the standard to get a driver for USB-RTCs, as I 
want, then rtc is the correct place. ;)

Because I don't want to do a v4:

the driver has an

#include "../common/hid-sensors/hid-sensor-attributes.h"

so moving it to drivers/rtc/ will make that even more ugly.

Suggestions? I don't really care and as I'm currently at the order 
receiving end ;) I would change it to whatever the maintainers are 
wanting. Maybe moving that header to include/linux or even integrating 
it into include/linux/hid-sensor-hubs.h makes sense.

Regards,

Alexander

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

* Re: [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time
  2012-12-10 22:36                   ` Lars-Peter Clausen
@ 2012-12-11  0:01                     ` Alexander Holler
  2012-12-11 10:35                       ` Alan Cox
  0 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-11  0:01 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada

Am 10.12.2012 23:36, schrieb Lars-Peter Clausen:
> Well, I've been exaggerating a bit, you can call it multiple times, but you

Thanks a lot for the explanation(s).

>>>> +error_free_drvdata:
>>>> +    platform_set_drvdata(pdev, NULL);
>>>
>>> Setting the platform data to NULL should not be necessary. Some
>>> drivers do
>>> this but it's kind of the result of cargo-cult-coding.
>>>
>>>> +    kfree(time_state);

Btw. I wouldn't call that cargo-cult-coding. It's more defensive 
programming as people might not be sure, if there is something around 
which still might access the platform data at that point. Ok, there 
would be a need for a mutex or similiar if that really could happen, but 
I wouldn't call such practices cargo-cult. ;)

Regards,

Alexander


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

* Re: [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time
  2012-12-10 22:50                           ` Alexander Holler
@ 2012-12-11  9:31                             ` Jonathan Cameron
  2012-12-11  9:40                               ` Lars-Peter Clausen
  0 siblings, 1 reply; 66+ messages in thread
From: Jonathan Cameron @ 2012-12-11  9:31 UTC (permalink / raw)
  To: Alexander Holler
  Cc: Jonathan Cameron, Lars-Peter Clausen, linux-kernel, linux-iio,
	Jonathan Cameron, rtc-linux, Alessandro Zummo,
	srinivas pandruvada

On 10/12/12 22:50, Alexander Holler wrote:
> Am 10.12.2012 22:42, schrieb Jonathan Cameron:
>> On 12/10/2012 09:39 PM, Lars-Peter Clausen wrote:
>>> On 12/10/2012 10:26 PM, Alexander Holler wrote:
>>>> Am 10.12.2012 21:22, schrieb Lars-Peter Clausen:
>>>>> On 12/10/2012 08:45 PM, Alexander Holler wrote:
>>>>>> Am 10.12.2012 18:05, schrieb Lars-Peter Clausen:
>>>>>>
>>>>>>> Looks pretty good now. But there are still some IIO remnants
>>>>>>> which should be
>>>>>>> removed as well. Also the driver should move to drivers/rtc/
>>>>>>> since, well,
>>>>>>> it's a rtc driver not a IIO driver.
>>>>>>
>>>>>> I think it still should be stick to iio, because that is where all
>>>>>> HID
>>>>>> sensors currently are found and where the user would expect to
>>>>>> find such
>>>>>> a driver.
>>>>>
>>>>> That's because all the current IIO sensor drivers fall in the IIO
>>>>> domain. This
>>>>> one clearly is a RTC driver, so it belongs in drivers/rtc/
>>>>
>>>> Where nobody will find it if he searches for drivers for his HID
>>>> sensor.
>>>> I still see it as HID sensor driver and not a rtc-driver.
>>>> But ...
>>>
>>> I can understand your position, but drivers are usually grouped by
>>> function not
>>> by topology. If there is a proper Kconfig help text people should
>>> hopefully be
>>> find it.
>> Seconded on this. If it is a pure rtc driver then it definitely
>> belongs in
>> drivers/rtc.  Now there might have been ways of doing this as a
>> consumer / provider
>> with the provider being in IIO and the consumer in rtc, but that
>> sounds like
>> it is over compicating things, at least for now.
>
> Personally I just want to use it to have HID-USB_RTCs. ;)
>
> But in case of HID sensor hubs, the main usage of that driver will be to
> set the time of such hubs (something I still have to make patches for),
> and not to read it. So if you think as an HID sensor user, it should
> belong to iio or wherever those sensor will finally end up (I think they
> should end up in HID and should be usable by bluetooth devices too), but
> if you creatively misuse the standard to get a driver for USB-RTCs, as I
> want, then rtc is the correct place. ;)
I did wonder what you were up to ;)
>
> Because I don't want to do a v4:
>
> the driver has an
>
> #include "../common/hid-sensors/hid-sensor-attributes.h"
>
> so moving it to drivers/rtc/ will make that even more ugly.
>

> Suggestions? I don't really care and as I'm currently at the order
> receiving end ;) I would change it to whatever the maintainers are
> wanting. Maybe moving that header to include/linux or even integrating
> it into include/linux/hid-sensor-hubs.h makes sense.
Yes, move the header or merge into existing one as makes sense.
I'm not pulling this driver into the IIO tree (unless for some
reason Alessandro wants me to and I can't think why he would...).

>
> Regards,
>
> Alexander


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

* Re: [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time
  2012-12-11  9:31                             ` Jonathan Cameron
@ 2012-12-11  9:40                               ` Lars-Peter Clausen
  2012-12-11 12:39                                 ` Alexander Holler
  2012-12-16 22:15                                 ` [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time Alessandro Zummo
  0 siblings, 2 replies; 66+ messages in thread
From: Lars-Peter Clausen @ 2012-12-11  9:40 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Alexander Holler, Jonathan Cameron, linux-kernel, linux-iio,
	Jonathan Cameron, rtc-linux, Alessandro Zummo,
	srinivas pandruvada

On 12/11/2012 10:31 AM, Jonathan Cameron wrote:
> On 10/12/12 22:50, Alexander Holler wrote:
>> Am 10.12.2012 22:42, schrieb Jonathan Cameron:
>>> On 12/10/2012 09:39 PM, Lars-Peter Clausen wrote:
>>>> On 12/10/2012 10:26 PM, Alexander Holler wrote:
>>>>> Am 10.12.2012 21:22, schrieb Lars-Peter Clausen:
>>>>>> On 12/10/2012 08:45 PM, Alexander Holler wrote:
>>>>>>> Am 10.12.2012 18:05, schrieb Lars-Peter Clausen:
>>>>>>>
>>>>>>>> Looks pretty good now. But there are still some IIO remnants
>>>>>>>> which should be
>>>>>>>> removed as well. Also the driver should move to drivers/rtc/
>>>>>>>> since, well,
>>>>>>>> it's a rtc driver not a IIO driver.
>>>>>>>
>>>>>>> I think it still should be stick to iio, because that is where all
>>>>>>> HID
>>>>>>> sensors currently are found and where the user would expect to
>>>>>>> find such
>>>>>>> a driver.
>>>>>>
>>>>>> That's because all the current IIO sensor drivers fall in the IIO
>>>>>> domain. This
>>>>>> one clearly is a RTC driver, so it belongs in drivers/rtc/
>>>>>
>>>>> Where nobody will find it if he searches for drivers for his HID
>>>>> sensor.
>>>>> I still see it as HID sensor driver and not a rtc-driver.
>>>>> But ...
>>>>
>>>> I can understand your position, but drivers are usually grouped by
>>>> function not
>>>> by topology. If there is a proper Kconfig help text people should
>>>> hopefully be
>>>> find it.
>>> Seconded on this. If it is a pure rtc driver then it definitely
>>> belongs in
>>> drivers/rtc.  Now there might have been ways of doing this as a
>>> consumer / provider
>>> with the provider being in IIO and the consumer in rtc, but that
>>> sounds like
>>> it is over compicating things, at least for now.
>>
>> Personally I just want to use it to have HID-USB_RTCs. ;)
>>
>> But in case of HID sensor hubs, the main usage of that driver will be to
>> set the time of such hubs (something I still have to make patches for),
>> and not to read it. So if you think as an HID sensor user, it should
>> belong to iio or wherever those sensor will finally end up (I think they
>> should end up in HID and should be usable by bluetooth devices too), but
>> if you creatively misuse the standard to get a driver for USB-RTCs, as I
>> want, then rtc is the correct place. ;)
> I did wonder what you were up to ;)
>>
>> Because I don't want to do a v4:
>>
>> the driver has an
>>
>> #include "../common/hid-sensors/hid-sensor-attributes.h"
>>
>> so moving it to drivers/rtc/ will make that even more ugly.
>>
> 
>> Suggestions? I don't really care and as I'm currently at the order
>> receiving end ;) I would change it to whatever the maintainers are
>> wanting. Maybe moving that header to include/linux or even integrating
>> it into include/linux/hid-sensor-hubs.h makes sense.
> Yes, move the header or merge into existing one as makes sense.
> I'm not pulling this driver into the IIO tree (unless for some
> reason Alessandro wants me to and I can't think why he would...).
> 

Alessandro has been pretty quiet for quite some time now. Luckily Andrew
Morton usually picks up the stuff for orphaned subsystems. So put him on Cc
for v4.

- Lars

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

* Re: [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time
  2012-12-11  0:01                     ` Alexander Holler
@ 2012-12-11 10:35                       ` Alan Cox
  0 siblings, 0 replies; 66+ messages in thread
From: Alan Cox @ 2012-12-11 10:35 UTC (permalink / raw)
  To: Alexander Holler
  Cc: Lars-Peter Clausen, linux-kernel, linux-iio, Jonathan Cameron,
	rtc-linux, Alessandro Zummo, srinivas pandruvada

On Tue, 11 Dec 2012 01:01:29 +0100
Alexander Holler <holler@ahsoftware.de> wrote:

> Am 10.12.2012 23:36, schrieb Lars-Peter Clausen:
> > Well, I've been exaggerating a bit, you can call it multiple times, but you
> 
> Thanks a lot for the explanation(s).
> 
> >>>> +error_free_drvdata:
> >>>> +    platform_set_drvdata(pdev, NULL);
> >>>
> >>> Setting the platform data to NULL should not be necessary. Some
> >>> drivers do
> >>> this but it's kind of the result of cargo-cult-coding.
> >>>
> >>>> +    kfree(time_state);
> 
> Btw. I wouldn't call that cargo-cult-coding. It's more defensive 
> programming as people might not be sure, if there is something around 
> which still might access the platform data at that point. Ok, there 
> would be a need for a mutex or similiar if that really could happen, but 
> I wouldn't call such practices cargo-cult. ;)

Agreed - pointer NULLing catches a lot of mistakes during teardown where
timers or interrupts running in parallel get missed.

Alan

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

* Re: [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time
  2012-12-11  9:40                               ` Lars-Peter Clausen
@ 2012-12-11 12:39                                 ` Alexander Holler
  2012-12-11 13:54                                   ` Jonathan Cameron
  2012-12-16 22:15                                 ` [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time Alessandro Zummo
  1 sibling, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-11 12:39 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Jonathan Cameron, Jonathan Cameron, linux-kernel, linux-iio,
	Jonathan Cameron, rtc-linux, Alessandro Zummo,
	srinivas pandruvada

Am 11.12.2012 10:40, schrieb Lars-Peter Clausen:

>> Yes, move the header or merge into existing one as makes sense.
>> I'm not pulling this driver into the IIO tree (unless for some
>> reason Alessandro wants me to and I can't think why he would...).
>>
>
> Alessandro has been pretty quiet for quite some time now. Luckily Andrew
> Morton usually picks up the stuff for orphaned subsystems. So put him on Cc
> for v4.

Will do it. Thanks a lot for your review.

I willl post the whole series (4 patches including the merge of 
hid-sensor-attributes.h) again, when I've finished v3 of the driver 
(hopefully this evening), marking some patches as RESEND. So 3 out of 
those 4 patches will be for iio (as hid-sensor-hub is part of it), and 
the last one, the rtc driver itself, will be for the rtc subsystem. I 
don't know if they have to be pulled by different maintainers. ;)

Regards,

Alexander

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

* Re: [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time
  2012-12-11 12:39                                 ` Alexander Holler
@ 2012-12-11 13:54                                   ` Jonathan Cameron
  2012-12-11 18:21                                     ` [PATCH 1/4 v2] iio: hid-sensors: respect CONFIG_IIO_TRIGGER Alexander Holler
  0 siblings, 1 reply; 66+ messages in thread
From: Jonathan Cameron @ 2012-12-11 13:54 UTC (permalink / raw)
  To: Alexander Holler
  Cc: Lars-Peter Clausen, Jonathan Cameron, linux-kernel, linux-iio,
	Jonathan Cameron, rtc-linux, Alessandro Zummo,
	srinivas pandruvada

On 11/12/12 12:39, Alexander Holler wrote:
> Am 11.12.2012 10:40, schrieb Lars-Peter Clausen:
>
>>> Yes, move the header or merge into existing one as makes sense.
>>> I'm not pulling this driver into the IIO tree (unless for some
>>> reason Alessandro wants me to and I can't think why he would...).
>>>
>>
>> Alessandro has been pretty quiet for quite some time now. Luckily Andrew
>> Morton usually picks up the stuff for orphaned subsystems. So put him
>> on Cc
>> for v4.
>
> Will do it. Thanks a lot for your review.
>
> I willl post the whole series (4 patches including the merge of
> hid-sensor-attributes.h) again, when I've finished v3 of the driver
> (hopefully this evening), marking some patches as RESEND. So 3 out of
> those 4 patches will be for iio (as hid-sensor-hub is part of it), and
> the last one, the rtc driver itself, will be for the rtc subsystem. I
> don't know if they have to be pulled by different maintainers. ;)
>
> Regards,
>
> Alexander
We'll see what Andrew says.  We can take the lot through IIO
(doubt Greg will mind) as long as we have the correct acks to do so
(or at least statements of not caring ;)


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

* [PATCH 1/4 v2] iio: hid-sensors: respect CONFIG_IIO_TRIGGER
  2012-12-11 13:54                                   ` Jonathan Cameron
@ 2012-12-11 18:21                                     ` Alexander Holler
  2012-12-11 18:21                                       ` [PATCH 2/4 RESEND] iio: Add Usage IDs for HID time sensors Alexander Holler
                                                         ` (3 more replies)
  0 siblings, 4 replies; 66+ messages in thread
From: Alexander Holler @ 2012-12-11 18:21 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-iio, Jonathan Cameron, Lars-Peter Clausen, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton,
	Alexander Holler

Not much to say, without that change, hid-sensor-trigger will be
always compiled if HID_SENSOR_IIO_COMMON is selected which fails if
CONFIG_IIO_TRIGGER is not set because CONFIG_IIO_CONSUMERS_PER_TRIGGER
will not be defined.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 drivers/iio/accel/Kconfig               |    1 +
 drivers/iio/common/hid-sensors/Kconfig  |   13 ++++++++++++-
 drivers/iio/common/hid-sensors/Makefile |    3 ++-
 drivers/iio/gyro/Kconfig                |    1 +
 drivers/iio/light/Kconfig               |    1 +
 drivers/iio/magnetometer/Kconfig        |    1 +
 6 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index b2510c4..b84b806 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -8,6 +8,7 @@ config HID_SENSOR_ACCEL_3D
 	select IIO_BUFFER
 	select IIO_TRIGGERED_BUFFER
 	select HID_SENSOR_IIO_COMMON
+	select HID_SENSOR_IIO_TRIGGER
 	tristate "HID Acelerometers 3D"
 	help
 	  Say yes here to build support for the HID SENSOR
diff --git a/drivers/iio/common/hid-sensors/Kconfig b/drivers/iio/common/hid-sensors/Kconfig
index 8e63d81..e294f31 100644
--- a/drivers/iio/common/hid-sensors/Kconfig
+++ b/drivers/iio/common/hid-sensors/Kconfig
@@ -6,7 +6,7 @@ menu "Hid Sensor IIO Common"
 config HID_SENSOR_IIO_COMMON
 	tristate "Common modules for all HID Sensor IIO drivers"
 	depends on HID_SENSOR_HUB
-	select IIO_TRIGGER if IIO_BUFFER
+	select HID_SENSOR_IIO_TRIGGER if IIO_BUFFER
 	help
 	  Say yes here to build support for HID sensor to use
 	  HID sensor common processing for attributes and IIO triggers.
@@ -14,6 +14,17 @@ config HID_SENSOR_IIO_COMMON
 	  HID sensor drivers, this module contains processing for those
 	  attributes.
 
+config HID_SENSOR_IIO_TRIGGER
+	tristate "Common module (trigger) for all HID Sensor IIO drivers"
+	depends on HID_SENSOR_HUB && HID_SENSOR_IIO_COMMON
+	select IIO_TRIGGER
+	help
+	  Say yes here to build trigger support for HID sensors.
+	  Triggers will be send if all requested attributes were read.
+
+	  If this driver is compiled as a module, it will be named
+	  hid-sensor-trigger.
+
 config HID_SENSOR_ENUM_BASE_QUIRKS
 	tristate "ENUM base quirks for HID Sensor IIO drivers"
 	depends on HID_SENSOR_IIO_COMMON
diff --git a/drivers/iio/common/hid-sensors/Makefile b/drivers/iio/common/hid-sensors/Makefile
index 1f463e0..22e7c5a 100644
--- a/drivers/iio/common/hid-sensors/Makefile
+++ b/drivers/iio/common/hid-sensors/Makefile
@@ -3,4 +3,5 @@
 #
 
 obj-$(CONFIG_HID_SENSOR_IIO_COMMON) += hid-sensor-iio-common.o
-hid-sensor-iio-common-y := hid-sensor-attributes.o hid-sensor-trigger.o
+obj-$(CONFIG_HID_SENSOR_IIO_TRIGGER) += hid-sensor-trigger.o
+hid-sensor-iio-common-y := hid-sensor-attributes.o
diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig
index 21e27e2..bc9daff 100644
--- a/drivers/iio/gyro/Kconfig
+++ b/drivers/iio/gyro/Kconfig
@@ -8,6 +8,7 @@ config HID_SENSOR_GYRO_3D
 	select IIO_BUFFER
 	select IIO_TRIGGERED_BUFFER
 	select HID_SENSOR_IIO_COMMON
+	select HID_SENSOR_IIO_TRIGGER
 	tristate "HID Gyroscope 3D"
 	help
 	  Say yes here to build support for the HID SENSOR
diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
index 1763c9b..dbf80ab 100644
--- a/drivers/iio/light/Kconfig
+++ b/drivers/iio/light/Kconfig
@@ -47,6 +47,7 @@ config HID_SENSOR_ALS
 	select IIO_BUFFER
 	select IIO_TRIGGERED_BUFFER
 	select HID_SENSOR_IIO_COMMON
+	select HID_SENSOR_IIO_TRIGGER
 	tristate "HID ALS"
 	help
 	  Say yes here to build support for the HID SENSOR
diff --git a/drivers/iio/magnetometer/Kconfig b/drivers/iio/magnetometer/Kconfig
index c1f0cdd..ff11d68 100644
--- a/drivers/iio/magnetometer/Kconfig
+++ b/drivers/iio/magnetometer/Kconfig
@@ -8,6 +8,7 @@ config HID_SENSOR_MAGNETOMETER_3D
 	select IIO_BUFFER
 	select IIO_TRIGGERED_BUFFER
 	select HID_SENSOR_IIO_COMMON
+	select HID_SENSOR_IIO_TRIGGER
 	tristate "HID Magenetometer 3D"
 	help
 	  Say yes here to build support for the HID SENSOR
-- 
1.7.8.6


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

* [PATCH 2/4 RESEND] iio: Add Usage IDs for HID time sensors.
  2012-12-11 18:21                                     ` [PATCH 1/4 v2] iio: hid-sensors: respect CONFIG_IIO_TRIGGER Alexander Holler
@ 2012-12-11 18:21                                       ` Alexander Holler
  2012-12-15 11:06                                         ` Jonathan Cameron
  2012-12-11 18:21                                       ` [PATCH 3/4] iio: merge hid-sensor-attributes.h into hid-sensor-hub.h Alexander Holler
                                                         ` (2 subsequent siblings)
  3 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-11 18:21 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-iio, Jonathan Cameron, Lars-Peter Clausen, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton,
	Alexander Holler

These are Usage IDs for the attributes year, month, day,
hour, minute and second, needed to read HID time sensors.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 include/linux/hid-sensor-ids.h |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
index ca8d7e9..3754ea9 100644
--- a/include/linux/hid-sensor-ids.h
+++ b/include/linux/hid-sensor-ids.h
@@ -67,6 +67,15 @@
 #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Y_AXIS		0x200486
 #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Z_AXIS		0x200487
 
+/* Time (2000a0) */
+#define HID_USAGE_SENSOR_TIME					0x2000a0
+#define HID_USAGE_SENSOR_TIME_YEAR				0x200521
+#define HID_USAGE_SENSOR_TIME_MONTH				0x200522
+#define HID_USAGE_SENSOR_TIME_DAY				0x200523
+#define HID_USAGE_SENSOR_TIME_HOUR				0x200525
+#define HID_USAGE_SENSOR_TIME_MINUTE				0x200526
+#define HID_USAGE_SENSOR_TIME_SECOND				0x200527
+
 /* Units */
 #define HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED			0x00
 #define HID_USAGE_SENSOR_UNITS_LUX				0x01
-- 
1.7.8.6


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

* [PATCH 3/4] iio: merge hid-sensor-attributes.h into hid-sensor-hub.h
  2012-12-11 18:21                                     ` [PATCH 1/4 v2] iio: hid-sensors: respect CONFIG_IIO_TRIGGER Alexander Holler
  2012-12-11 18:21                                       ` [PATCH 2/4 RESEND] iio: Add Usage IDs for HID time sensors Alexander Holler
@ 2012-12-11 18:21                                       ` Alexander Holler
  2012-12-12 15:45                                         ` Pandruvada, Srinivas
  2012-12-11 18:21                                       ` [PATCH 4/4 v3] rtc: add rtc-driver for HID sensors of type time Alexander Holler
  2012-12-15 10:54                                       ` [PATCH 1/4 v2] iio: hid-sensors: respect CONFIG_IIO_TRIGGER Jonathan Cameron
  3 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-11 18:21 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-iio, Jonathan Cameron, Lars-Peter Clausen, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton,
	Alexander Holler

The stuff in hid-sensor-attributes.h is needed by every piece which
uses hid-sensor-hub and merging it into hid-sensor-hub.h makes it accessible
from outside the iio subdirectory.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 drivers/iio/accel/hid-sensor-accel-3d.c            |    1 -
 .../iio/common/hid-sensors/hid-sensor-attributes.c |    1 -
 .../iio/common/hid-sensors/hid-sensor-attributes.h |   57 --------------------
 .../iio/common/hid-sensors/hid-sensor-trigger.c    |    1 -
 drivers/iio/gyro/hid-sensor-gyro-3d.c              |    1 -
 drivers/iio/light/hid-sensor-als.c                 |    1 -
 drivers/iio/magnetometer/hid-sensor-magn-3d.c      |    1 -
 include/linux/hid-sensor-hub.h                     |   38 +++++++++++++
 8 files changed, 38 insertions(+), 63 deletions(-)
 delete mode 100644 drivers/iio/common/hid-sensors/hid-sensor-attributes.h

diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
index 314a405..72371aa 100644
--- a/drivers/iio/accel/hid-sensor-accel-3d.c
+++ b/drivers/iio/accel/hid-sensor-accel-3d.c
@@ -28,7 +28,6 @@
 #include <linux/iio/buffer.h>
 #include <linux/iio/trigger_consumer.h>
 #include <linux/iio/triggered_buffer.h>
-#include "../common/hid-sensors/hid-sensor-attributes.h"
 #include "../common/hid-sensors/hid-sensor-trigger.h"
 
 /*Format: HID-SENSOR-usage_id_in_hex*/
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index 7537495..5873f16 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -25,7 +25,6 @@
 #include <linux/hid-sensor-hub.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
-#include "hid-sensor-attributes.h"
 
 static int pow_10(unsigned power)
 {
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.h b/drivers/iio/common/hid-sensors/hid-sensor-attributes.h
deleted file mode 100644
index a4676a0..0000000
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * HID Sensors Driver
- * Copyright (c) 2012, Intel Corporation.
- *
- * 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 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, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-#ifndef _HID_SENSORS_ATTRIBUTES_H
-#define _HID_SENSORS_ATTRIBUTES_H
-
-/* Common hid sensor iio structure */
-struct hid_sensor_iio_common {
-	struct hid_sensor_hub_device *hsdev;
-	struct platform_device *pdev;
-	unsigned usage_id;
-	bool data_ready;
-	struct hid_sensor_hub_attribute_info poll;
-	struct hid_sensor_hub_attribute_info report_state;
-	struct hid_sensor_hub_attribute_info power_state;
-	struct hid_sensor_hub_attribute_info sensitivity;
-};
-
-/*Convert from hid unit expo to regular exponent*/
-static inline int hid_sensor_convert_exponent(int unit_expo)
-{
-	if (unit_expo < 0x08)
-		return unit_expo;
-	else if (unit_expo <= 0x0f)
-		return -(0x0f-unit_expo+1);
-	else
-		return 0;
-}
-
-int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
-					u32 usage_id,
-					struct hid_sensor_iio_common *st);
-int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
-					int val1, int val2);
-int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
-					int *val1, int *val2);
-int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
-					int val1, int val2);
-int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
-					int *val1, int *val2);
-
-#endif
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
index d4b790d..b097b68 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
@@ -26,7 +26,6 @@
 #include <linux/iio/iio.h>
 #include <linux/iio/trigger.h>
 #include <linux/iio/sysfs.h>
-#include "hid-sensor-attributes.h"
 #include "hid-sensor-trigger.h"
 
 static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
index 4c56ada..b98cd70 100644
--- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
+++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
@@ -28,7 +28,6 @@
 #include <linux/iio/buffer.h>
 #include <linux/iio/trigger_consumer.h>
 #include <linux/iio/triggered_buffer.h>
-#include "../common/hid-sensors/hid-sensor-attributes.h"
 #include "../common/hid-sensors/hid-sensor-trigger.h"
 
 /*Format: HID-SENSOR-usage_id_in_hex*/
diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
index 96e3691..9610989 100644
--- a/drivers/iio/light/hid-sensor-als.c
+++ b/drivers/iio/light/hid-sensor-als.c
@@ -28,7 +28,6 @@
 #include <linux/iio/buffer.h>
 #include <linux/iio/trigger_consumer.h>
 #include <linux/iio/triggered_buffer.h>
-#include "../common/hid-sensors/hid-sensor-attributes.h"
 #include "../common/hid-sensors/hid-sensor-trigger.h"
 
 /*Format: HID-SENSOR-usage_id_in_hex*/
diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
index c4f0d27..4957430 100644
--- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
+++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
@@ -28,7 +28,6 @@
 #include <linux/iio/buffer.h>
 #include <linux/iio/trigger_consumer.h>
 #include <linux/iio/triggered_buffer.h>
-#include "../common/hid-sensors/hid-sensor-attributes.h"
 #include "../common/hid-sensors/hid-sensor-trigger.h"
 
 /*Format: HID-SENSOR-usage_id_in_hex*/
diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
index 0aa5f4c..e6265f9 100644
--- a/include/linux/hid-sensor-hub.h
+++ b/include/linux/hid-sensor-hub.h
@@ -157,4 +157,42 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
 */
 int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
 			u32 field_index, s32 *value);
+
+/* hid-sensor-attributes */
+
+/* Common hid sensor iio structure */
+struct hid_sensor_iio_common {
+	struct hid_sensor_hub_device *hsdev;
+	struct platform_device *pdev;
+	unsigned usage_id;
+	bool data_ready;
+	struct hid_sensor_hub_attribute_info poll;
+	struct hid_sensor_hub_attribute_info report_state;
+	struct hid_sensor_hub_attribute_info power_state;
+	struct hid_sensor_hub_attribute_info sensitivity;
+};
+
+/*Convert from hid unit expo to regular exponent*/
+static inline int hid_sensor_convert_exponent(int unit_expo)
+{
+	if (unit_expo < 0x08)
+		return unit_expo;
+	else if (unit_expo <= 0x0f)
+		return -(0x0f-unit_expo+1);
+	else
+		return 0;
+}
+
+int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
+					u32 usage_id,
+					struct hid_sensor_iio_common *st);
+int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
+					int val1, int val2);
+int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
+					int *val1, int *val2);
+int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
+					int val1, int val2);
+int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
+					int *val1, int *val2);
+
 #endif
-- 
1.7.8.6


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

* [PATCH 4/4 v3] rtc: add rtc-driver for HID sensors of type time
  2012-12-11 18:21                                     ` [PATCH 1/4 v2] iio: hid-sensors: respect CONFIG_IIO_TRIGGER Alexander Holler
  2012-12-11 18:21                                       ` [PATCH 2/4 RESEND] iio: Add Usage IDs for HID time sensors Alexander Holler
  2012-12-11 18:21                                       ` [PATCH 3/4] iio: merge hid-sensor-attributes.h into hid-sensor-hub.h Alexander Holler
@ 2012-12-11 18:21                                       ` Alexander Holler
  2012-12-12  9:51                                         ` Lars-Peter Clausen
  2012-12-15 10:54                                       ` [PATCH 1/4 v2] iio: hid-sensors: respect CONFIG_IIO_TRIGGER Jonathan Cameron
  3 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-11 18:21 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-iio, Jonathan Cameron, Lars-Peter Clausen, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton,
	Alexander Holler

This driver makes the time from HID sensors (hubs) which are offering
such available like any other RTC does.

Currently the time can only be read. Setting the time must be done
through sending a report, which currently isn't supported by
hid-sensor-hub. (I've planned to submit patches.)

It is necessary that all values like year, month etc, are send as
8bit values (1 byte each) and all of them in 1 report. Also the
spec HUTRR39b doesn't define the range of the year field, we
tread it as 0 - 99 because that's what most RTCs I know about are
offering.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 drivers/rtc/Kconfig               |   16 ++
 drivers/rtc/Makefile              |    1 +
 drivers/rtc/rtc-hid-sensor-time.c |  284 +++++++++++++++++++++++++++++++++++++
 3 files changed, 301 insertions(+), 0 deletions(-)
 create mode 100644 drivers/rtc/rtc-hid-sensor-time.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 19c03ab..7c7b33e 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1144,4 +1144,20 @@ config RTC_DRV_SNVS
 	   This driver can also be built as a module, if so, the module
 	   will be called "rtc-snvs".
 
+comment "HID Sensor RTC drivers"
+
+config RTC_DRV_HID_SENSOR_TIME
+	tristate "HID Sensor Time"
+	depends on USB_HID
+	select IIO
+	select HID_SENSOR_HUB
+	select HID_SENSOR_IIO_COMMON
+	help
+	  Say yes here to build support for the HID Sensors of type Time.
+	  This drivers makes such sensors available as RTCs.
+
+          If this driver is compiled as a module, it will be named
+          rtc-hid-sensor-time.
+
+
 endif # RTC_CLASS
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 56297f0..9d1658a 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_RTC_DRV_EM3027)	+= rtc-em3027.o
 obj-$(CONFIG_RTC_DRV_EP93XX)	+= rtc-ep93xx.o
 obj-$(CONFIG_RTC_DRV_FM3130)	+= rtc-fm3130.o
 obj-$(CONFIG_RTC_DRV_GENERIC)	+= rtc-generic.o
+obj-$(CONFIG_RTC_DRV_HID_SENSOR_TIME) += rtc-hid-sensor-time.o
 obj-$(CONFIG_RTC_DRV_IMXDI)	+= rtc-imxdi.o
 obj-$(CONFIG_RTC_DRV_ISL1208)	+= rtc-isl1208.o
 obj-$(CONFIG_RTC_DRV_ISL12022)	+= rtc-isl12022.o
diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c
new file mode 100644
index 0000000..42b7ba1
--- /dev/null
+++ b/drivers/rtc/rtc-hid-sensor-time.c
@@ -0,0 +1,284 @@
+/*
+ * HID Sensor Time Driver
+ * Copyright (c) 2012, Alexander Holler.
+ *
+ * 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 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/module.h>
+#include <linux/hid-sensor-hub.h>
+#include <linux/iio/iio.h>
+#include <linux/rtc.h>
+
+/* Format: HID-SENSOR-usage_id_in_hex */
+/* Usage ID from spec for Time: 0x2000A0 */
+#define DRIVER_NAME "HID-SENSOR-2000a0" /* must be lowercase */
+
+enum hid_time_channel {
+	CHANNEL_SCAN_INDEX_YEAR,
+	CHANNEL_SCAN_INDEX_MONTH,
+	CHANNEL_SCAN_INDEX_DAY,
+	CHANNEL_SCAN_INDEX_HOUR,
+	CHANNEL_SCAN_INDEX_MINUTE,
+	CHANNEL_SCAN_INDEX_SECOND,
+	TIME_RTC_CHANNEL_MAX,
+};
+
+struct hid_time_state {
+	struct hid_sensor_hub_callbacks callbacks;
+	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_hub_attribute_info info[TIME_RTC_CHANNEL_MAX];
+	struct rtc_time last_time;
+	spinlock_t lock_last_time;
+	struct completion comp_last_time;
+	struct rtc_time time_buf;
+	struct rtc_device *rtc;
+};
+
+static const u32 hid_time_addresses[TIME_RTC_CHANNEL_MAX] = {
+	HID_USAGE_SENSOR_TIME_YEAR,
+	HID_USAGE_SENSOR_TIME_MONTH,
+	HID_USAGE_SENSOR_TIME_DAY,
+	HID_USAGE_SENSOR_TIME_HOUR,
+	HID_USAGE_SENSOR_TIME_MINUTE,
+	HID_USAGE_SENSOR_TIME_SECOND,
+};
+
+/* Channel names for verbose error messages */
+static const char *hid_time_channel_names[TIME_RTC_CHANNEL_MAX] = {
+	"year", "month", "day", "hour", "minute", "second",
+};
+
+/* Callback handler to send event after all samples are received and captured */
+static int hid_time_proc_event(struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id, void *priv)
+{
+	unsigned long flags;
+	struct hid_time_state *time_state = platform_get_drvdata(priv);
+
+	spin_lock_irqsave(&time_state->lock_last_time, flags);
+	time_state->last_time = time_state->time_buf;
+	spin_unlock_irqrestore(&time_state->lock_last_time, flags);
+	complete(&time_state->comp_last_time);
+	return 0;
+}
+
+static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id, size_t raw_len,
+				char *raw_data, void *priv)
+{
+	struct hid_time_state *time_state = platform_get_drvdata(priv);
+	struct rtc_time *time_buf = &time_state->time_buf;
+
+	switch (usage_id) {
+	case HID_USAGE_SENSOR_TIME_YEAR:
+		time_buf->tm_year = *(u8 *)raw_data;
+		if (time_buf->tm_year < 70)
+			/* assume we are in 1970...2069 */
+			time_buf->tm_year += 100;
+		break;
+	case HID_USAGE_SENSOR_TIME_MONTH:
+		time_buf->tm_mon = --*(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_DAY:
+		time_buf->tm_mday = *(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_HOUR:
+		time_buf->tm_hour = *(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_MINUTE:
+		time_buf->tm_min = *(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_SECOND:
+		time_buf->tm_sec = *(u8 *)raw_data;
+		break;
+	default:
+		return -EINVAL;
+	}
+	return 0;
+}
+
+/* small helper, haven't found any other way */
+static const char *attrib_name(u32 attrib_id)
+{
+	unsigned i = 0;
+	static const char unknown[] = "unknown";
+
+	for (; i < TIME_RTC_CHANNEL_MAX; ++i) {
+		if (hid_time_addresses[i] == attrib_id)
+			return hid_time_channel_names[i];
+	}
+	return unknown; /* should never happen */
+}
+
+static int hid_time_parse_report(struct platform_device *pdev,
+				struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id,
+				struct hid_time_state *time_state)
+{
+	int ret, i = 0;
+
+	for (; i < TIME_RTC_CHANNEL_MAX; ++i) {
+		ret = sensor_hub_input_get_attribute_info(hsdev,
+				HID_INPUT_REPORT, usage_id,
+				hid_time_addresses[i], &time_state->info[i]);
+		if (ret < 0)
+			return ret;
+	}
+	/* Check the (needed) attributes for sanity */
+	ret = time_state->info[0].report_id; /* use ret as temp. */
+	if (ret < 0) {
+		dev_err(&pdev->dev, "bad report ID!\n");
+		return -EINVAL;
+	}
+	for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) {
+		if (time_state->info[i].report_id != ret) {
+			dev_err(&pdev->dev,
+				"not all needed attributes inside the same report!\n");
+			return -EINVAL;
+		}
+		if (time_state->info[i].size != 1) {
+			dev_err(&pdev->dev,
+				"attribute '%s' not 8 bits wide!\n",
+				attrib_name(time_state->info[i].attrib_id));
+			return -EINVAL;
+		}
+		if (time_state->info[i].units !=
+				HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED &&
+				/* allow attribute seconds with unit seconds */
+				!(time_state->info[i].attrib_id ==
+				HID_USAGE_SENSOR_TIME_SECOND &&
+				time_state->info[i].units ==
+				HID_USAGE_SENSOR_UNITS_SECOND)) {
+			dev_err(&pdev->dev,
+				"attribute '%s' hasn't a unit of type 'none'!\n",
+				attrib_name(time_state->info[i].attrib_id));
+			return -EINVAL;
+		}
+		if (time_state->info[i].unit_expo) {
+			dev_err(&pdev->dev,
+				"attribute '%s' hasn't a unit exponent of 1!\n",
+				attrib_name(time_state->info[i].attrib_id));
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+static int hid_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	unsigned long flags;
+	struct hid_time_state *time_state =
+		platform_get_drvdata(to_platform_device(dev));
+
+	INIT_COMPLETION(time_state->comp_last_time);
+	/* get a report with all values through requesting one value */
+	sensor_hub_input_attr_get_raw_value(time_state->common_attributes.hsdev,
+			HID_USAGE_SENSOR_TIME, hid_time_addresses[0],
+			time_state->info[0].report_id);
+	/* wait for all values (event) */
+	if (!wait_for_completion_interruptible_timeout(
+			&time_state->comp_last_time, HZ*6))
+		return -EIO;
+	spin_lock_irqsave(&time_state->lock_last_time, flags);
+	*tm = time_state->last_time;
+	spin_unlock_irqrestore(&time_state->lock_last_time, flags);
+
+	return 0;
+}
+
+static const struct rtc_class_ops rtc_ops = {
+	.read_time = hid_rtc_read_time,
+};
+
+static int __devinit hid_time_probe(struct platform_device *pdev)
+{
+	int ret = 0;
+	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct hid_time_state *time_state = devm_kzalloc(&pdev->dev,
+		sizeof(struct hid_time_state), GFP_KERNEL);
+
+	if (time_state == NULL)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, time_state);
+
+	init_completion(&time_state->comp_last_time);
+	time_state->common_attributes.hsdev = hsdev;
+	time_state->common_attributes.pdev = pdev;
+
+	ret = hid_sensor_parse_common_attributes(hsdev,
+				HID_USAGE_SENSOR_TIME,
+				&time_state->common_attributes);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to setup common attributes!\n");
+		return ret;
+	}
+
+	ret = hid_time_parse_report(pdev, hsdev, HID_USAGE_SENSOR_TIME,
+					time_state);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to setup attributes!\n");
+		return ret;
+	}
+
+	time_state->callbacks.send_event = hid_time_proc_event;
+	time_state->callbacks.capture_sample = hid_time_capture_sample;
+	time_state->callbacks.pdev = pdev;
+	ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_TIME,
+					&time_state->callbacks);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "register callback failed!\n");
+		return ret;
+	}
+
+	time_state->rtc = rtc_device_register("hid-sensor-time",
+				&pdev->dev, &rtc_ops, THIS_MODULE);
+
+	if (IS_ERR(time_state->rtc)) {
+		dev_err(&pdev->dev, "rtc device register failed!\n");
+		return PTR_ERR(time_state->rtc);
+	}
+
+	return ret;
+}
+
+static int __devinit hid_time_remove(struct platform_device *pdev)
+{
+	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct hid_time_state *time_state = platform_get_drvdata(pdev);
+
+	if (!IS_ERR(time_state->rtc))
+		rtc_device_unregister(time_state->rtc);
+	sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
+
+	return 0;
+}
+
+static struct platform_driver hid_time_platform_driver = {
+	.driver = {
+		.name	= DRIVER_NAME,
+		.owner	= THIS_MODULE,
+	},
+	.probe		= hid_time_probe,
+	.remove		= hid_time_remove,
+};
+module_platform_driver(hid_time_platform_driver);
+
+MODULE_DESCRIPTION("HID Sensor Time");
+MODULE_AUTHOR("Alexander Holler <holler@ahsoftware.de>");
+MODULE_LICENSE("GPL");
-- 
1.7.8.6


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

* Re: [PATCH 4/4 v3] rtc: add rtc-driver for HID sensors of type time
  2012-12-11 18:21                                       ` [PATCH 4/4 v3] rtc: add rtc-driver for HID sensors of type time Alexander Holler
@ 2012-12-12  9:51                                         ` Lars-Peter Clausen
  2012-12-12 10:14                                           ` Alexander Holler
  0 siblings, 1 reply; 66+ messages in thread
From: Lars-Peter Clausen @ 2012-12-12  9:51 UTC (permalink / raw)
  To: Alexander Holler
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton

On 12/11/2012 07:21 PM, Alexander Holler wrote:
> This driver makes the time from HID sensors (hubs) which are offering
> such available like any other RTC does.
> 
> Currently the time can only be read. Setting the time must be done
> through sending a report, which currently isn't supported by
> hid-sensor-hub. (I've planned to submit patches.)
> 
> It is necessary that all values like year, month etc, are send as
> 8bit values (1 byte each) and all of them in 1 report. Also the
> spec HUTRR39b doesn't define the range of the year field, we
> tread it as 0 - 99 because that's what most RTCs I know about are
> offering.
> 
> Signed-off-by: Alexander Holler <holler@ahsoftware.de>

Looks good, but as I wrote during the last review the __devinits need to go.
A few other suggerstions online

> ---
>  drivers/rtc/Kconfig               |   16 ++
>  drivers/rtc/Makefile              |    1 +
>  drivers/rtc/rtc-hid-sensor-time.c |  284 +++++++++++++++++++++++++++++++++++++
>  3 files changed, 301 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/rtc/rtc-hid-sensor-time.c
> 
> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
> index 19c03ab..7c7b33e 100644
> --- a/drivers/rtc/Kconfig
> +++ b/drivers/rtc/Kconfig
> @@ -1144,4 +1144,20 @@ config RTC_DRV_SNVS
>  	   This driver can also be built as a module, if so, the module
>  	   will be called "rtc-snvs".
>  
> +comment "HID Sensor RTC drivers"
> +
> +config RTC_DRV_HID_SENSOR_TIME
> +	tristate "HID Sensor Time"
> +	depends on USB_HID
> +	select IIO
> +	select HID_SENSOR_HUB
> +	select HID_SENSOR_IIO_COMMON
> +	help
> +	  Say yes here to build support for the HID Sensors of type Time.
> +	  This drivers makes such sensors available as RTCs.
> +
> +          If this driver is compiled as a module, it will be named
> +          rtc-hid-sensor-time.

The help text should be indented using one tab followed by two spaces

> +
> +
>  endif # RTC_CLASS
[...]
> diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c
> new file mode 100644
> index 0000000..42b7ba1
> --- /dev/null
> +++ b/drivers/rtc/rtc-hid-sensor-time.c
> @@ -0,0 +1,284 @@
[...]
> +
> +/* Channel names for verbose error messages */
> +static const char *hid_time_channel_names[TIME_RTC_CHANNEL_MAX] = {

const char * const

> +	"year", "month", "day", "hour", "minute", "second",
> +};
> +
> +/* Callback handler to send event after all samples are received and captured */
> +static int hid_time_proc_event(struct hid_sensor_hub_device *hsdev,
> +				unsigned usage_id, void *priv)
> +{
> +	unsigned long flags;
> +	struct hid_time_state *time_state = platform_get_drvdata(priv);
> +
> +	spin_lock_irqsave(&time_state->lock_last_time, flags);
> +	time_state->last_time = time_state->time_buf;
> +	spin_unlock_irqrestore(&time_state->lock_last_time, flags);
> +	complete(&time_state->comp_last_time);
> +	return 0;
> +}
> +
> +static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev,
> +				unsigned usage_id, size_t raw_len,
> +				char *raw_data, void *priv)
> +{
> +	struct hid_time_state *time_state = platform_get_drvdata(priv);
> +	struct rtc_time *time_buf = &time_state->time_buf;
> +
> +	switch (usage_id) {
> +	case HID_USAGE_SENSOR_TIME_YEAR:
> +		time_buf->tm_year = *(u8 *)raw_data;
> +		if (time_buf->tm_year < 70)
> +			/* assume we are in 1970...2069 */
> +			time_buf->tm_year += 100;
> +		break;
> +	case HID_USAGE_SENSOR_TIME_MONTH:
> +		time_buf->tm_mon = --*(u8 *)raw_data;

What's up with the double minus?

> +		break;
> +	case HID_USAGE_SENSOR_TIME_DAY:
> +		time_buf->tm_mday = *(u8 *)raw_data;
> +		break;
> +	case HID_USAGE_SENSOR_TIME_HOUR:
> +		time_buf->tm_hour = *(u8 *)raw_data;
> +		break;
> +	case HID_USAGE_SENSOR_TIME_MINUTE:
> +		time_buf->tm_min = *(u8 *)raw_data;
> +		break;
> +	case HID_USAGE_SENSOR_TIME_SECOND:
> +		time_buf->tm_sec = *(u8 *)raw_data;
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +	return 0;
> +}
> +
> +/* small helper, haven't found any other way */
> +static const char *attrib_name(u32 attrib_id)
> +{
> +	unsigned i = 0;
> +	static const char unknown[] = "unknown";
> +
> +	for (; i < TIME_RTC_CHANNEL_MAX; ++i) {

I would put the i = 0 in the for header.

> +		if (hid_time_addresses[i] == attrib_id)
> +			return hid_time_channel_names[i];
> +	}
> +	return unknown; /* should never happen */
> +}
> +
> +static int hid_time_parse_report(struct platform_device *pdev,
> +				struct hid_sensor_hub_device *hsdev,
> +				unsigned usage_id,
> +				struct hid_time_state *time_state)
> +{
> +	int ret, i = 0;
> +
> +	for (; i < TIME_RTC_CHANNEL_MAX; ++i) {

Same here

> +		ret = sensor_hub_input_get_attribute_info(hsdev,
> +				HID_INPUT_REPORT, usage_id,
> +				hid_time_addresses[i], &time_state->info[i]);
> +		if (ret < 0)
> +			return ret;
> +	}
> +	/* Check the (needed) attributes for sanity */
> +	ret = time_state->info[0].report_id; /* use ret as temp. */

As I said last time, report_id instead of ret may be a better name for the
variable

> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "bad report ID!\n");
> +		return -EINVAL;
> +	}
> +	for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) {
> +		if (time_state->info[i].report_id != ret) {
> +			dev_err(&pdev->dev,
> +				"not all needed attributes inside the same report!\n");
> +			return -EINVAL;
> +		}
[...]
> +	}
> +
> +	return 0;
> +}
> +
[...]
> +
> +static int __devinit hid_time_remove(struct platform_device *pdev)
> +{
> +	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
> +	struct hid_time_state *time_state = platform_get_drvdata(pdev);
> +
> +	if (!IS_ERR(time_state->rtc))

This will never be false, so you can just run unregister unconditionally

> +		rtc_device_unregister(time_state->rtc);
> +	sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
> +
> +	return 0;
> +}


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

* Re: [PATCH 4/4 v3] rtc: add rtc-driver for HID sensors of type time
  2012-12-12  9:51                                         ` Lars-Peter Clausen
@ 2012-12-12 10:14                                           ` Alexander Holler
  2012-12-12 10:18                                             ` Lars-Peter Clausen
  2012-12-12 11:11                                             ` [PATCH 4/4 v4] " Alexander Holler
  0 siblings, 2 replies; 66+ messages in thread
From: Alexander Holler @ 2012-12-12 10:14 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton

Am 12.12.2012 10:51, schrieb Lars-Peter Clausen:

> Looks good, but as I wrote during the last review the __devinits need to go.
> A few other suggerstions online

Oh, have forgotten it. Ok, will make a v4, changing the other few things 
too.

>> +	case HID_USAGE_SENSOR_TIME_MONTH:
>> +		time_buf->tm_mon = --*(u8 *)raw_data;

Time sensors are sending the month in the range 1-12, not 0-11.

Regards,

Alexander


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

* Re: [PATCH 4/4 v3] rtc: add rtc-driver for HID sensors of type time
  2012-12-12 10:14                                           ` Alexander Holler
@ 2012-12-12 10:18                                             ` Lars-Peter Clausen
  2012-12-12 11:11                                             ` [PATCH 4/4 v4] " Alexander Holler
  1 sibling, 0 replies; 66+ messages in thread
From: Lars-Peter Clausen @ 2012-12-12 10:18 UTC (permalink / raw)
  To: Alexander Holler
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton

On 12/12/2012 11:14 AM, Alexander Holler wrote:
> Am 12.12.2012 10:51, schrieb Lars-Peter Clausen:
> 
>> Looks good, but as I wrote during the last review the __devinits need to go.
>> A few other suggerstions online
> 
> Oh, have forgotten it. Ok, will make a v4, changing the other few things too.
> 
>>> +    case HID_USAGE_SENSOR_TIME_MONTH:
>>> +        time_buf->tm_mon = --*(u8 *)raw_data;
> 
> Time sensors are sending the month in the range 1-12, not 0-11.
> 
Ah, sorry, I guess hadn't had enough coffee yet, I read this as -(-(*(u8
*)raw_data))) and was a bit confused...

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

* [PATCH 4/4 v4] rtc: add rtc-driver for HID sensors of type time
  2012-12-12 10:14                                           ` Alexander Holler
  2012-12-12 10:18                                             ` Lars-Peter Clausen
@ 2012-12-12 11:11                                             ` Alexander Holler
  2012-12-14  9:42                                               ` Lars-Peter Clausen
  1 sibling, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-12 11:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-iio, Jonathan Cameron, Lars-Peter Clausen, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton,
	Alexander Holler

This driver makes the time from HID sensors (hubs) which are offering
such available like any other RTC does.

Currently the time can only be read. Setting the time must be done
through sending a report, which currently isn't supported by
hid-sensor-hub. (I've planned to submit patches.)

It is necessary that all values like year, month etc, are send as
8bit values (1 byte each) and all of them in 1 report. Also the
spec HUTRR39b doesn't define the range of the year field, we
tread it as 0 - 99 because that's what most RTCs I know about are
offering.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 drivers/rtc/Kconfig               |   16 ++
 drivers/rtc/Makefile              |    1 +
 drivers/rtc/rtc-hid-sensor-time.c |  283 +++++++++++++++++++++++++++++++++++++
 3 files changed, 300 insertions(+), 0 deletions(-)
 create mode 100644 drivers/rtc/rtc-hid-sensor-time.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 19c03ab..e0d29b5 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1144,4 +1144,20 @@ config RTC_DRV_SNVS
 	   This driver can also be built as a module, if so, the module
 	   will be called "rtc-snvs".
 
+comment "HID Sensor RTC drivers"
+
+config RTC_DRV_HID_SENSOR_TIME
+	tristate "HID Sensor Time"
+	depends on USB_HID
+	select IIO
+	select HID_SENSOR_HUB
+	select HID_SENSOR_IIO_COMMON
+	help
+	  Say yes here to build support for the HID Sensors of type Time.
+	  This drivers makes such sensors available as RTCs.
+
+	  If this driver is compiled as a module, it will be named
+	  rtc-hid-sensor-time.
+
+
 endif # RTC_CLASS
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 56297f0..9d1658a 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_RTC_DRV_EM3027)	+= rtc-em3027.o
 obj-$(CONFIG_RTC_DRV_EP93XX)	+= rtc-ep93xx.o
 obj-$(CONFIG_RTC_DRV_FM3130)	+= rtc-fm3130.o
 obj-$(CONFIG_RTC_DRV_GENERIC)	+= rtc-generic.o
+obj-$(CONFIG_RTC_DRV_HID_SENSOR_TIME) += rtc-hid-sensor-time.o
 obj-$(CONFIG_RTC_DRV_IMXDI)	+= rtc-imxdi.o
 obj-$(CONFIG_RTC_DRV_ISL1208)	+= rtc-isl1208.o
 obj-$(CONFIG_RTC_DRV_ISL12022)	+= rtc-isl12022.o
diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c
new file mode 100644
index 0000000..41bc011
--- /dev/null
+++ b/drivers/rtc/rtc-hid-sensor-time.c
@@ -0,0 +1,283 @@
+/*
+ * HID Sensor Time Driver
+ * Copyright (c) 2012, Alexander Holler.
+ *
+ * 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 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/module.h>
+#include <linux/hid-sensor-hub.h>
+#include <linux/iio/iio.h>
+#include <linux/rtc.h>
+
+/* Format: HID-SENSOR-usage_id_in_hex */
+/* Usage ID from spec for Time: 0x2000A0 */
+#define DRIVER_NAME "HID-SENSOR-2000a0" /* must be lowercase */
+
+enum hid_time_channel {
+	CHANNEL_SCAN_INDEX_YEAR,
+	CHANNEL_SCAN_INDEX_MONTH,
+	CHANNEL_SCAN_INDEX_DAY,
+	CHANNEL_SCAN_INDEX_HOUR,
+	CHANNEL_SCAN_INDEX_MINUTE,
+	CHANNEL_SCAN_INDEX_SECOND,
+	TIME_RTC_CHANNEL_MAX,
+};
+
+struct hid_time_state {
+	struct hid_sensor_hub_callbacks callbacks;
+	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_hub_attribute_info info[TIME_RTC_CHANNEL_MAX];
+	struct rtc_time last_time;
+	spinlock_t lock_last_time;
+	struct completion comp_last_time;
+	struct rtc_time time_buf;
+	struct rtc_device *rtc;
+};
+
+static const u32 hid_time_addresses[TIME_RTC_CHANNEL_MAX] = {
+	HID_USAGE_SENSOR_TIME_YEAR,
+	HID_USAGE_SENSOR_TIME_MONTH,
+	HID_USAGE_SENSOR_TIME_DAY,
+	HID_USAGE_SENSOR_TIME_HOUR,
+	HID_USAGE_SENSOR_TIME_MINUTE,
+	HID_USAGE_SENSOR_TIME_SECOND,
+};
+
+/* Channel names for verbose error messages */
+static const char * const hid_time_channel_names[TIME_RTC_CHANNEL_MAX] = {
+	"year", "month", "day", "hour", "minute", "second",
+};
+
+/* Callback handler to send event after all samples are received and captured */
+static int hid_time_proc_event(struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id, void *priv)
+{
+	unsigned long flags;
+	struct hid_time_state *time_state = platform_get_drvdata(priv);
+
+	spin_lock_irqsave(&time_state->lock_last_time, flags);
+	time_state->last_time = time_state->time_buf;
+	spin_unlock_irqrestore(&time_state->lock_last_time, flags);
+	complete(&time_state->comp_last_time);
+	return 0;
+}
+
+static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id, size_t raw_len,
+				char *raw_data, void *priv)
+{
+	struct hid_time_state *time_state = platform_get_drvdata(priv);
+	struct rtc_time *time_buf = &time_state->time_buf;
+
+	switch (usage_id) {
+	case HID_USAGE_SENSOR_TIME_YEAR:
+		time_buf->tm_year = *(u8 *)raw_data;
+		if (time_buf->tm_year < 70)
+			/* assume we are in 1970...2069 */
+			time_buf->tm_year += 100;
+		break;
+	case HID_USAGE_SENSOR_TIME_MONTH:
+		/* sensor sending the month as 1-12, we need 0-11 */
+		time_buf->tm_mon = *(u8 *)raw_data-1;
+		break;
+	case HID_USAGE_SENSOR_TIME_DAY:
+		time_buf->tm_mday = *(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_HOUR:
+		time_buf->tm_hour = *(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_MINUTE:
+		time_buf->tm_min = *(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_SECOND:
+		time_buf->tm_sec = *(u8 *)raw_data;
+		break;
+	default:
+		return -EINVAL;
+	}
+	return 0;
+}
+
+/* small helper, haven't found any other way */
+static const char *attrib_name(u32 attrib_id)
+{
+	static const char unknown[] = "unknown";
+	unsigned i;
+
+	for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) {
+		if (hid_time_addresses[i] == attrib_id)
+			return hid_time_channel_names[i];
+	}
+	return unknown; /* should never happen */
+}
+
+static int hid_time_parse_report(struct platform_device *pdev,
+				struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id,
+				struct hid_time_state *time_state)
+{
+	int report_id, i;
+
+	for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i)
+		if (sensor_hub_input_get_attribute_info(hsdev,
+				HID_INPUT_REPORT, usage_id,
+				hid_time_addresses[i],
+				&time_state->info[i]) < 0)
+			return -EINVAL;
+	/* Check the (needed) attributes for sanity */
+	report_id = time_state->info[0].report_id;
+	if (report_id < 0) {
+		dev_err(&pdev->dev, "bad report ID!\n");
+		return -EINVAL;
+	}
+	for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) {
+		if (time_state->info[i].report_id != report_id) {
+			dev_err(&pdev->dev,
+				"not all needed attributes inside the same report!\n");
+			return -EINVAL;
+		}
+		if (time_state->info[i].size != 1) {
+			dev_err(&pdev->dev,
+				"attribute '%s' not 8 bits wide!\n",
+				attrib_name(time_state->info[i].attrib_id));
+			return -EINVAL;
+		}
+		if (time_state->info[i].units !=
+				HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED &&
+				/* allow attribute seconds with unit seconds */
+				!(time_state->info[i].attrib_id ==
+				HID_USAGE_SENSOR_TIME_SECOND &&
+				time_state->info[i].units ==
+				HID_USAGE_SENSOR_UNITS_SECOND)) {
+			dev_err(&pdev->dev,
+				"attribute '%s' hasn't a unit of type 'none'!\n",
+				attrib_name(time_state->info[i].attrib_id));
+			return -EINVAL;
+		}
+		if (time_state->info[i].unit_expo) {
+			dev_err(&pdev->dev,
+				"attribute '%s' hasn't a unit exponent of 1!\n",
+				attrib_name(time_state->info[i].attrib_id));
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+static int hid_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	unsigned long flags;
+	struct hid_time_state *time_state =
+		platform_get_drvdata(to_platform_device(dev));
+
+	INIT_COMPLETION(time_state->comp_last_time);
+	/* get a report with all values through requesting one value */
+	sensor_hub_input_attr_get_raw_value(time_state->common_attributes.hsdev,
+			HID_USAGE_SENSOR_TIME, hid_time_addresses[0],
+			time_state->info[0].report_id);
+	/* wait for all values (event) */
+	if (!wait_for_completion_interruptible_timeout(
+			&time_state->comp_last_time, HZ*6))
+		return -EIO;
+	spin_lock_irqsave(&time_state->lock_last_time, flags);
+	*tm = time_state->last_time;
+	spin_unlock_irqrestore(&time_state->lock_last_time, flags);
+
+	return 0;
+}
+
+static const struct rtc_class_ops rtc_ops = {
+	.read_time = hid_rtc_read_time,
+};
+
+static int hid_time_probe(struct platform_device *pdev)
+{
+	int ret = 0;
+	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct hid_time_state *time_state = devm_kzalloc(&pdev->dev,
+		sizeof(struct hid_time_state), GFP_KERNEL);
+
+	if (time_state == NULL)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, time_state);
+
+	init_completion(&time_state->comp_last_time);
+	time_state->common_attributes.hsdev = hsdev;
+	time_state->common_attributes.pdev = pdev;
+
+	ret = hid_sensor_parse_common_attributes(hsdev,
+				HID_USAGE_SENSOR_TIME,
+				&time_state->common_attributes);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to setup common attributes!\n");
+		return ret;
+	}
+
+	ret = hid_time_parse_report(pdev, hsdev, HID_USAGE_SENSOR_TIME,
+					time_state);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to setup attributes!\n");
+		return ret;
+	}
+
+	time_state->callbacks.send_event = hid_time_proc_event;
+	time_state->callbacks.capture_sample = hid_time_capture_sample;
+	time_state->callbacks.pdev = pdev;
+	ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_TIME,
+					&time_state->callbacks);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "register callback failed!\n");
+		return ret;
+	}
+
+	time_state->rtc = rtc_device_register("hid-sensor-time",
+				&pdev->dev, &rtc_ops, THIS_MODULE);
+
+	if (IS_ERR(time_state->rtc)) {
+		dev_err(&pdev->dev, "rtc device register failed!\n");
+		return PTR_ERR(time_state->rtc);
+	}
+
+	return ret;
+}
+
+static int __devinit hid_time_remove(struct platform_device *pdev)
+{
+	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct hid_time_state *time_state = platform_get_drvdata(pdev);
+
+	rtc_device_unregister(time_state->rtc);
+	sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
+
+	return 0;
+}
+
+static struct platform_driver hid_time_platform_driver = {
+	.driver = {
+		.name	= DRIVER_NAME,
+		.owner	= THIS_MODULE,
+	},
+	.probe		= hid_time_probe,
+	.remove		= hid_time_remove,
+};
+module_platform_driver(hid_time_platform_driver);
+
+MODULE_DESCRIPTION("HID Sensor Time");
+MODULE_AUTHOR("Alexander Holler <holler@ahsoftware.de>");
+MODULE_LICENSE("GPL");
-- 
1.7.8.6


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

* RE: [PATCH 3/4] iio: merge hid-sensor-attributes.h into hid-sensor-hub.h
  2012-12-11 18:21                                       ` [PATCH 3/4] iio: merge hid-sensor-attributes.h into hid-sensor-hub.h Alexander Holler
@ 2012-12-12 15:45                                         ` Pandruvada, Srinivas
  2012-12-12 20:10                                           ` Alexander Holler
  0 siblings, 1 reply; 66+ messages in thread
From: Pandruvada, Srinivas @ 2012-12-12 15:45 UTC (permalink / raw)
  To: Alexander Holler, linux-kernel
  Cc: linux-iio, Jonathan Cameron, Lars-Peter Clausen, rtc-linux,
	Alessandro Zummo, Andrew Morton


One minor comment.

-----Original Message-----
From: Alexander Holler [mailto:holler@ahsoftware.de] 
Sent: Tuesday, December 11, 2012 10:22 AM
To: linux-kernel@vger.kernel.org
Cc: linux-iio@vger.kernel.org; Jonathan Cameron; Lars-Peter Clausen; rtc-linux@googlegroups.com; Alessandro Zummo; Pandruvada, Srinivas; Andrew Morton; Alexander Holler
Subject: [PATCH 3/4] iio: merge hid-sensor-attributes.h into hid-sensor-hub.h

The stuff in hid-sensor-attributes.h is needed by every piece which uses hid-sensor-hub and merging it into hid-sensor-hub.h makes it accessible from outside the iio subdirectory.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 drivers/iio/accel/hid-sensor-accel-3d.c            |    1 -
 .../iio/common/hid-sensors/hid-sensor-attributes.c |    1 -
 .../iio/common/hid-sensors/hid-sensor-attributes.h |   57 --------------------
 .../iio/common/hid-sensors/hid-sensor-trigger.c    |    1 -
 drivers/iio/gyro/hid-sensor-gyro-3d.c              |    1 -
 drivers/iio/light/hid-sensor-als.c                 |    1 -
 drivers/iio/magnetometer/hid-sensor-magn-3d.c      |    1 -
 include/linux/hid-sensor-hub.h                     |   38 +++++++++++++
 8 files changed, 38 insertions(+), 63 deletions(-)  delete mode 100644 drivers/iio/common/hid-sensors/hid-sensor-attributes.h

diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
index 314a405..72371aa 100644
--- a/drivers/iio/accel/hid-sensor-accel-3d.c
+++ b/drivers/iio/accel/hid-sensor-accel-3d.c
@@ -28,7 +28,6 @@
 #include <linux/iio/buffer.h>
 #include <linux/iio/trigger_consumer.h>  #include <linux/iio/triggered_buffer.h> -#include "../common/hid-sensors/hid-sensor-attributes.h"
 #include "../common/hid-sensors/hid-sensor-trigger.h"
 
 /*Format: HID-SENSOR-usage_id_in_hex*/
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index 7537495..5873f16 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -25,7 +25,6 @@
 #include <linux/hid-sensor-hub.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
-#include "hid-sensor-attributes.h"
 
 static int pow_10(unsigned power)
 {
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.h b/drivers/iio/common/hid-sensors/hid-sensor-attributes.h
deleted file mode 100644
index a4676a0..0000000
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * HID Sensors Driver
- * Copyright (c) 2012, Intel Corporation.
- *
- * 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 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, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-#ifndef _HID_SENSORS_ATTRIBUTES_H
-#define _HID_SENSORS_ATTRIBUTES_H
-
-/* Common hid sensor iio structure */
-struct hid_sensor_iio_common {
-	struct hid_sensor_hub_device *hsdev;
-	struct platform_device *pdev;
-	unsigned usage_id;
-	bool data_ready;
-	struct hid_sensor_hub_attribute_info poll;
-	struct hid_sensor_hub_attribute_info report_state;
-	struct hid_sensor_hub_attribute_info power_state;
-	struct hid_sensor_hub_attribute_info sensitivity;
-};
-/*Convert from hid unit expo to regular exponent*/ -static inline int hid_sensor_convert_exponent(int unit_expo) -{
-	if (unit_expo < 0x08)
-		return unit_expo;
-	else if (unit_expo <= 0x0f)
-		return -(0x0f-unit_expo+1);
-	else
-		return 0;
-}
-
-int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
-					u32 usage_id,
-					struct hid_sensor_iio_common *st);
-int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
-					int val1, int val2);
-int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
-					int *val1, int *val2);
-int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
-					int val1, int val2);
-int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
-					int *val1, int *val2);
-
-#endif
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
index d4b790d..b097b68 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
@@ -26,7 +26,6 @@
 #include <linux/iio/iio.h>
 #include <linux/iio/trigger.h>
 #include <linux/iio/sysfs.h>
-#include "hid-sensor-attributes.h"
 #include "hid-sensor-trigger.h"
 
 static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
index 4c56ada..b98cd70 100644
--- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
+++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
@@ -28,7 +28,6 @@
 #include <linux/iio/buffer.h>
 #include <linux/iio/trigger_consumer.h>  #include <linux/iio/triggered_buffer.h> -#include "../common/hid-sensors/hid-sensor-attributes.h"
 #include "../common/hid-sensors/hid-sensor-trigger.h"
 
 /*Format: HID-SENSOR-usage_id_in_hex*/
diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
index 96e3691..9610989 100644
--- a/drivers/iio/light/hid-sensor-als.c
+++ b/drivers/iio/light/hid-sensor-als.c
@@ -28,7 +28,6 @@
 #include <linux/iio/buffer.h>
 #include <linux/iio/trigger_consumer.h>  #include <linux/iio/triggered_buffer.h> -#include "../common/hid-sensors/hid-sensor-attributes.h"
 #include "../common/hid-sensors/hid-sensor-trigger.h"
 
 /*Format: HID-SENSOR-usage_id_in_hex*/
diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
index c4f0d27..4957430 100644
--- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
+++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
@@ -28,7 +28,6 @@
 #include <linux/iio/buffer.h>
 #include <linux/iio/trigger_consumer.h>  #include <linux/iio/triggered_buffer.h> -#include "../common/hid-sensors/hid-sensor-attributes.h"
 #include "../common/hid-sensors/hid-sensor-trigger.h"
 
 /*Format: HID-SENSOR-usage_id_in_hex*/
diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h index 0aa5f4c..e6265f9 100644
--- a/include/linux/hid-sensor-hub.h
+++ b/include/linux/hid-sensor-hub.h
@@ -157,4 +157,42 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,  */  int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
 			u32 field_index, s32 *value);
+
+/* hid-sensor-attributes */
+
+/* Common hid sensor iio structure */
+struct hid_sensor_iio_common {
+	struct hid_sensor_hub_device *hsdev;
+	struct platform_device *pdev;
+	unsigned usage_id;
+	bool data_ready;
+	struct hid_sensor_hub_attribute_info poll;
+	struct hid_sensor_hub_attribute_info report_state;
+	struct hid_sensor_hub_attribute_info power_state;
+	struct hid_sensor_hub_attribute_info sensitivity; };

<Since it is not common to iio only, we should also remove iio in the structure name. >

+/*Convert from hid unit expo to regular exponent*/ static inline int 
+hid_sensor_convert_exponent(int unit_expo) {
+	if (unit_expo < 0x08)
+		return unit_expo;
+	else if (unit_expo <= 0x0f)
+		return -(0x0f-unit_expo+1);
+	else
+		return 0;
+}
+
+int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
+					u32 usage_id,
+					struct hid_sensor_iio_common *st); int 
+hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
+					int val1, int val2);
+int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
+					int *val1, int *val2);
+int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
+					int val1, int val2);
+int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
+					int *val1, int *val2);
+
 #endif
--
1.7.8.6


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

* Re: [PATCH 3/4] iio: merge hid-sensor-attributes.h into hid-sensor-hub.h
  2012-12-12 15:45                                         ` Pandruvada, Srinivas
@ 2012-12-12 20:10                                           ` Alexander Holler
  2012-12-12 20:28                                             ` [PATCHi 5/4] hid: iio: rename struct hid_sensor_iio_common to hid_sensor_common Alexander Holler
  0 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-12 20:10 UTC (permalink / raw)
  To: Pandruvada, Srinivas
  Cc: linux-kernel, linux-iio, Jonathan Cameron, Lars-Peter Clausen,
	rtc-linux, Alessandro Zummo, Andrew Morton

Am 12.12.2012 16:45, schrieb Pandruvada, Srinivas:
>
> One minor comment.

> +/* hid-sensor-attributes */
> +
> +/* Common hid sensor iio structure */
> +struct hid_sensor_iio_common {
> +	struct hid_sensor_hub_device *hsdev;
> +	struct platform_device *pdev;
> +	unsigned usage_id;
> +	bool data_ready;
> +	struct hid_sensor_hub_attribute_info poll;
> +	struct hid_sensor_hub_attribute_info report_state;
> +	struct hid_sensor_hub_attribute_info power_state;
> +	struct hid_sensor_hub_attribute_info sensitivity; };
>
> <Since it is not common to iio only, we should also remove iio in the structure name. >
>

Ok, I play the patch-monkey and will send a patch 5/4.

Alexander

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

* [PATCHi 5/4] hid: iio: rename struct hid_sensor_iio_common to hid_sensor_common
  2012-12-12 20:10                                           ` Alexander Holler
@ 2012-12-12 20:28                                             ` Alexander Holler
  2012-12-12 21:04                                               ` Pandruvada, Srinivas
  0 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-12 20:28 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-iio, Jonathan Cameron, Lars-Peter Clausen, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton,
	Alexander Holler

The structure with common attributes for hid-sensors isn't specific
to the iio-subsystem, so rename it to hid_sensor_common.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@intel.com>

---
 drivers/iio/accel/hid-sensor-accel-3d.c            |    2 +-
 .../iio/common/hid-sensors/hid-sensor-attributes.c |   10 +++++-----
 .../iio/common/hid-sensors/hid-sensor-trigger.c    |    4 ++--
 .../iio/common/hid-sensors/hid-sensor-trigger.h    |    2 +-
 drivers/iio/gyro/hid-sensor-gyro-3d.c              |    2 +-
 drivers/iio/light/hid-sensor-als.c                 |    2 +-
 drivers/iio/magnetometer/hid-sensor-magn-3d.c      |    2 +-
 drivers/rtc/rtc-hid-sensor-time.c                  |    2 +-
 include/linux/hid-sensor-hub.h                     |   12 ++++++------
 9 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
index 72371aa..2133da8 100644
--- a/drivers/iio/accel/hid-sensor-accel-3d.c
+++ b/drivers/iio/accel/hid-sensor-accel-3d.c
@@ -43,7 +43,7 @@ enum accel_3d_channel {
 
 struct accel_3d_state {
 	struct hid_sensor_hub_callbacks callbacks;
-	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info accel[ACCEL_3D_CHANNEL_MAX];
 	u32 accel_val[ACCEL_3D_CHANNEL_MAX];
 };
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index 5873f16..75b5473 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -113,7 +113,7 @@ static u32 convert_to_vtf_format(int size, int exp, int val1, int val2)
 	return value;
 }
 
-int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
+int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
 				int *val1, int *val2)
 {
 	s32 value;
@@ -140,7 +140,7 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
 }
 EXPORT_SYMBOL(hid_sensor_read_samp_freq_value);
 
-int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
+int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
 				int val1, int val2)
 {
 	s32 value;
@@ -168,7 +168,7 @@ int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
 }
 EXPORT_SYMBOL(hid_sensor_write_samp_freq_value);
 
-int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
+int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
 				int *val1, int *val2)
 {
 	s32 value;
@@ -190,7 +190,7 @@ int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
 }
 EXPORT_SYMBOL(hid_sensor_read_raw_hyst_value);
 
-int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
+int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
 					int val1, int val2)
 {
 	s32 value;
@@ -211,7 +211,7 @@ EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
 
 int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 					u32 usage_id,
-					struct hid_sensor_iio_common *st)
+					struct hid_sensor_common *st)
 {
 
 	sensor_hub_input_get_attribute_info(hsdev,
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
index b097b68..58fc108 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
@@ -31,7 +31,7 @@
 static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
 						bool state)
 {
-	struct hid_sensor_iio_common *st = trig->private_data;
+	struct hid_sensor_common *st = trig->private_data;
 	int state_val;
 
 	state_val = state ? 1 : 0;
@@ -65,7 +65,7 @@ static const struct iio_trigger_ops hid_sensor_trigger_ops = {
 };
 
 int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
-				struct hid_sensor_iio_common *attrb)
+				struct hid_sensor_common *attrb)
 {
 	int ret;
 	struct iio_trigger *trig;
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
index fd98297..9a87314 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
@@ -20,7 +20,7 @@
 #define _HID_SENSOR_TRIGGER_H
 
 int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
-				struct hid_sensor_iio_common *attrb);
+				struct hid_sensor_common *attrb);
 void hid_sensor_remove_trigger(struct iio_dev *indio_dev);
 
 #endif
diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
index b98cd70..85330ad 100644
--- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
+++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
@@ -43,7 +43,7 @@ enum gyro_3d_channel {
 
 struct gyro_3d_state {
 	struct hid_sensor_hub_callbacks callbacks;
-	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info gyro[GYRO_3D_CHANNEL_MAX];
 	u32 gyro_val[GYRO_3D_CHANNEL_MAX];
 };
diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
index 9610989..051b88c 100644
--- a/drivers/iio/light/hid-sensor-als.c
+++ b/drivers/iio/light/hid-sensor-als.c
@@ -38,7 +38,7 @@
 
 struct als_state {
 	struct hid_sensor_hub_callbacks callbacks;
-	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info als_illum;
 	u32 illum;
 };
diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
index 4957430..5c59044 100644
--- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
+++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
@@ -43,7 +43,7 @@ enum magn_3d_channel {
 
 struct magn_3d_state {
 	struct hid_sensor_hub_callbacks callbacks;
-	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info magn[MAGN_3D_CHANNEL_MAX];
 	u32 magn_val[MAGN_3D_CHANNEL_MAX];
 };
diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c
index 41bc011..8050c5d 100644
--- a/drivers/rtc/rtc-hid-sensor-time.c
+++ b/drivers/rtc/rtc-hid-sensor-time.c
@@ -39,7 +39,7 @@ enum hid_time_channel {
 
 struct hid_time_state {
 	struct hid_sensor_hub_callbacks callbacks;
-	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info info[TIME_RTC_CHANNEL_MAX];
 	struct rtc_time last_time;
 	spinlock_t lock_last_time;
diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
index e6265f9..ecefb73 100644
--- a/include/linux/hid-sensor-hub.h
+++ b/include/linux/hid-sensor-hub.h
@@ -161,7 +161,7 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
 /* hid-sensor-attributes */
 
 /* Common hid sensor iio structure */
-struct hid_sensor_iio_common {
+struct hid_sensor_common {
 	struct hid_sensor_hub_device *hsdev;
 	struct platform_device *pdev;
 	unsigned usage_id;
@@ -185,14 +185,14 @@ static inline int hid_sensor_convert_exponent(int unit_expo)
 
 int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 					u32 usage_id,
-					struct hid_sensor_iio_common *st);
-int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
+					struct hid_sensor_common *st);
+int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
 					int val1, int val2);
-int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
+int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
 					int *val1, int *val2);
-int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
+int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
 					int val1, int val2);
-int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
+int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
 					int *val1, int *val2);
 
 #endif
-- 
1.7.8.6


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

* RE: [PATCHi 5/4] hid: iio: rename struct hid_sensor_iio_common to hid_sensor_common
  2012-12-12 20:28                                             ` [PATCHi 5/4] hid: iio: rename struct hid_sensor_iio_common to hid_sensor_common Alexander Holler
@ 2012-12-12 21:04                                               ` Pandruvada, Srinivas
  0 siblings, 0 replies; 66+ messages in thread
From: Pandruvada, Srinivas @ 2012-12-12 21:04 UTC (permalink / raw)
  To: Alexander Holler, linux-kernel
  Cc: linux-iio, Jonathan Cameron, Lars-Peter Clausen, rtc-linux,
	Alessandro Zummo, Andrew Morton

Looks good.

-----Original Message-----
From: Alexander Holler [mailto:holler@ahsoftware.de] 
Sent: Wednesday, December 12, 2012 12:28 PM
To: linux-kernel@vger.kernel.org
Cc: linux-iio@vger.kernel.org; Jonathan Cameron; Lars-Peter Clausen; rtc-linux@googlegroups.com; Alessandro Zummo; Pandruvada, Srinivas; Andrew Morton; Alexander Holler
Subject: [PATCHi 5/4] hid: iio: rename struct hid_sensor_iio_common to hid_sensor_common

The structure with common attributes for hid-sensors isn't specific to the iio-subsystem, so rename it to hid_sensor_common.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@intel.com>

---
 drivers/iio/accel/hid-sensor-accel-3d.c            |    2 +-
 .../iio/common/hid-sensors/hid-sensor-attributes.c |   10 +++++-----
 .../iio/common/hid-sensors/hid-sensor-trigger.c    |    4 ++--
 .../iio/common/hid-sensors/hid-sensor-trigger.h    |    2 +-
 drivers/iio/gyro/hid-sensor-gyro-3d.c              |    2 +-
 drivers/iio/light/hid-sensor-als.c                 |    2 +-
 drivers/iio/magnetometer/hid-sensor-magn-3d.c      |    2 +-
 drivers/rtc/rtc-hid-sensor-time.c                  |    2 +-
 include/linux/hid-sensor-hub.h                     |   12 ++++++------
 9 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
index 72371aa..2133da8 100644
--- a/drivers/iio/accel/hid-sensor-accel-3d.c
+++ b/drivers/iio/accel/hid-sensor-accel-3d.c
@@ -43,7 +43,7 @@ enum accel_3d_channel {
 
 struct accel_3d_state {
 	struct hid_sensor_hub_callbacks callbacks;
-	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info accel[ACCEL_3D_CHANNEL_MAX];
 	u32 accel_val[ACCEL_3D_CHANNEL_MAX];
 };
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index 5873f16..75b5473 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -113,7 +113,7 @@ static u32 convert_to_vtf_format(int size, int exp, int val1, int val2)
 	return value;
 }
 
-int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
+int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
 				int *val1, int *val2)
 {
 	s32 value;
@@ -140,7 +140,7 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,  }  EXPORT_SYMBOL(hid_sensor_read_samp_freq_value);
 
-int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
+int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
 				int val1, int val2)
 {
 	s32 value;
@@ -168,7 +168,7 @@ int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,  }  EXPORT_SYMBOL(hid_sensor_write_samp_freq_value);
 
-int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
+int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
 				int *val1, int *val2)
 {
 	s32 value;
@@ -190,7 +190,7 @@ int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,  }  EXPORT_SYMBOL(hid_sensor_read_raw_hyst_value);
 
-int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
+int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
 					int val1, int val2)
 {
 	s32 value;
@@ -211,7 +211,7 @@ EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
 
 int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 					u32 usage_id,
-					struct hid_sensor_iio_common *st)
+					struct hid_sensor_common *st)
 {
 
 	sensor_hub_input_get_attribute_info(hsdev,
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
index b097b68..58fc108 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
@@ -31,7 +31,7 @@
 static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
 						bool state)
 {
-	struct hid_sensor_iio_common *st = trig->private_data;
+	struct hid_sensor_common *st = trig->private_data;
 	int state_val;
 
 	state_val = state ? 1 : 0;
@@ -65,7 +65,7 @@ static const struct iio_trigger_ops hid_sensor_trigger_ops = {  };
 
 int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
-				struct hid_sensor_iio_common *attrb)
+				struct hid_sensor_common *attrb)
 {
 	int ret;
 	struct iio_trigger *trig;
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
index fd98297..9a87314 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
@@ -20,7 +20,7 @@
 #define _HID_SENSOR_TRIGGER_H
 
 int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
-				struct hid_sensor_iio_common *attrb);
+				struct hid_sensor_common *attrb);
 void hid_sensor_remove_trigger(struct iio_dev *indio_dev);
 
 #endif
diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
index b98cd70..85330ad 100644
--- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
+++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
@@ -43,7 +43,7 @@ enum gyro_3d_channel {
 
 struct gyro_3d_state {
 	struct hid_sensor_hub_callbacks callbacks;
-	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info gyro[GYRO_3D_CHANNEL_MAX];
 	u32 gyro_val[GYRO_3D_CHANNEL_MAX];
 };
diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
index 9610989..051b88c 100644
--- a/drivers/iio/light/hid-sensor-als.c
+++ b/drivers/iio/light/hid-sensor-als.c
@@ -38,7 +38,7 @@
 
 struct als_state {
 	struct hid_sensor_hub_callbacks callbacks;
-	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info als_illum;
 	u32 illum;
 };
diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
index 4957430..5c59044 100644
--- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
+++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
@@ -43,7 +43,7 @@ enum magn_3d_channel {
 
 struct magn_3d_state {
 	struct hid_sensor_hub_callbacks callbacks;
-	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info magn[MAGN_3D_CHANNEL_MAX];
 	u32 magn_val[MAGN_3D_CHANNEL_MAX];
 };
diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c
index 41bc011..8050c5d 100644
--- a/drivers/rtc/rtc-hid-sensor-time.c
+++ b/drivers/rtc/rtc-hid-sensor-time.c
@@ -39,7 +39,7 @@ enum hid_time_channel {
 
 struct hid_time_state {
 	struct hid_sensor_hub_callbacks callbacks;
-	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info info[TIME_RTC_CHANNEL_MAX];
 	struct rtc_time last_time;
 	spinlock_t lock_last_time;
diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h index e6265f9..ecefb73 100644
--- a/include/linux/hid-sensor-hub.h
+++ b/include/linux/hid-sensor-hub.h
@@ -161,7 +161,7 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
 /* hid-sensor-attributes */
 
 /* Common hid sensor iio structure */
-struct hid_sensor_iio_common {
+struct hid_sensor_common {
 	struct hid_sensor_hub_device *hsdev;
 	struct platform_device *pdev;
 	unsigned usage_id;
@@ -185,14 +185,14 @@ static inline int hid_sensor_convert_exponent(int unit_expo)
 
 int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 					u32 usage_id,
-					struct hid_sensor_iio_common *st);
-int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
+					struct hid_sensor_common *st);
+int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
 					int val1, int val2);
-int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
+int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
 					int *val1, int *val2);
-int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
+int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
 					int val1, int val2);
-int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
+int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
 					int *val1, int *val2);
 
 #endif
--
1.7.8.6


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

* Re: [PATCH 4/4 v4] rtc: add rtc-driver for HID sensors of type time
  2012-12-12 11:11                                             ` [PATCH 4/4 v4] " Alexander Holler
@ 2012-12-14  9:42                                               ` Lars-Peter Clausen
  2012-12-14 13:08                                                 ` Alexander Holler
  0 siblings, 1 reply; 66+ messages in thread
From: Lars-Peter Clausen @ 2012-12-14  9:42 UTC (permalink / raw)
  To: Alexander Holler
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton

On 12/12/2012 12:11 PM, Alexander Holler wrote:
> This driver makes the time from HID sensors (hubs) which are offering
> such available like any other RTC does.
> 
> Currently the time can only be read. Setting the time must be done
> through sending a report, which currently isn't supported by
> hid-sensor-hub. (I've planned to submit patches.)
> 
> It is necessary that all values like year, month etc, are send as
> 8bit values (1 byte each) and all of them in 1 report. Also the
> spec HUTRR39b doesn't define the range of the year field, we
> tread it as 0 - 99 because that's what most RTCs I know about are
> offering.
> 
> Signed-off-by: Alexander Holler <holler@ahsoftware.de>

Hi,

sorry for the delay. There is still the __devinit in front of
hid_time_remove left.

And another thing I've overlooked before:
wait_for_completion_interruptible_timeout can either return a positive
number when the completion was completed, 0 in case of an timeout, or a
negative error code in case it was interrupted. You need to handle all
three. E.g. something like this.

ret = wait_for_completion_interruptible_timeout(...)
if (ret == 0)
	return -EIO;
if (ret < 0)
	return ret


Otherwise it looks fine now. Maybe add a prefix to attrib_name() to avoid
potential clashes with the global namespace. E.g. hid_time_attrib_name()
Same goes for rtc_ops, hid_time_rtc_ops would be a better name.

- Lars

> ---
>  drivers/rtc/Kconfig               |   16 ++
>  drivers/rtc/Makefile              |    1 +
>  drivers/rtc/rtc-hid-sensor-time.c |  283 +++++++++++++++++++++++++++++++++++++
>  3 files changed, 300 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/rtc/rtc-hid-sensor-time.c
> 
> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
> index 19c03ab..e0d29b5 100644
> --- a/drivers/rtc/Kconfig
> +++ b/drivers/rtc/Kconfig
> @@ -1144,4 +1144,20 @@ config RTC_DRV_SNVS
>  	   This driver can also be built as a module, if so, the module
>  	   will be called "rtc-snvs".
>  
> +comment "HID Sensor RTC drivers"
> +
> +config RTC_DRV_HID_SENSOR_TIME
> +	tristate "HID Sensor Time"
> +	depends on USB_HID
> +	select IIO
> +	select HID_SENSOR_HUB
> +	select HID_SENSOR_IIO_COMMON
> +	help
> +	  Say yes here to build support for the HID Sensors of type Time.
> +	  This drivers makes such sensors available as RTCs.
> +
> +	  If this driver is compiled as a module, it will be named
> +	  rtc-hid-sensor-time.
> +
> +
>  endif # RTC_CLASS
> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
> index 56297f0..9d1658a 100644
> --- a/drivers/rtc/Makefile
> +++ b/drivers/rtc/Makefile
> @@ -51,6 +51,7 @@ obj-$(CONFIG_RTC_DRV_EM3027)	+= rtc-em3027.o
>  obj-$(CONFIG_RTC_DRV_EP93XX)	+= rtc-ep93xx.o
>  obj-$(CONFIG_RTC_DRV_FM3130)	+= rtc-fm3130.o
>  obj-$(CONFIG_RTC_DRV_GENERIC)	+= rtc-generic.o
> +obj-$(CONFIG_RTC_DRV_HID_SENSOR_TIME) += rtc-hid-sensor-time.o
>  obj-$(CONFIG_RTC_DRV_IMXDI)	+= rtc-imxdi.o
>  obj-$(CONFIG_RTC_DRV_ISL1208)	+= rtc-isl1208.o
>  obj-$(CONFIG_RTC_DRV_ISL12022)	+= rtc-isl12022.o
> diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c
> new file mode 100644
> index 0000000..41bc011
> --- /dev/null
> +++ b/drivers/rtc/rtc-hid-sensor-time.c
> @@ -0,0 +1,283 @@
> +/*
> + * HID Sensor Time Driver
> + * Copyright (c) 2012, Alexander Holler.
> + *
> + * 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 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, write to the Free Software Foundation, Inc.,
> + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
> + *
> + */
> +#include <linux/device.h>
> +#include <linux/platform_device.h>
> +#include <linux/module.h>
> +#include <linux/hid-sensor-hub.h>
> +#include <linux/iio/iio.h>
> +#include <linux/rtc.h>
> +
> +/* Format: HID-SENSOR-usage_id_in_hex */
> +/* Usage ID from spec for Time: 0x2000A0 */
> +#define DRIVER_NAME "HID-SENSOR-2000a0" /* must be lowercase */
> +
> +enum hid_time_channel {
> +	CHANNEL_SCAN_INDEX_YEAR,
> +	CHANNEL_SCAN_INDEX_MONTH,
> +	CHANNEL_SCAN_INDEX_DAY,
> +	CHANNEL_SCAN_INDEX_HOUR,
> +	CHANNEL_SCAN_INDEX_MINUTE,
> +	CHANNEL_SCAN_INDEX_SECOND,
> +	TIME_RTC_CHANNEL_MAX,
> +};
> +
> +struct hid_time_state {
> +	struct hid_sensor_hub_callbacks callbacks;
> +	struct hid_sensor_iio_common common_attributes;
> +	struct hid_sensor_hub_attribute_info info[TIME_RTC_CHANNEL_MAX];
> +	struct rtc_time last_time;
> +	spinlock_t lock_last_time;
> +	struct completion comp_last_time;
> +	struct rtc_time time_buf;
> +	struct rtc_device *rtc;
> +};
> +
> +static const u32 hid_time_addresses[TIME_RTC_CHANNEL_MAX] = {
> +	HID_USAGE_SENSOR_TIME_YEAR,
> +	HID_USAGE_SENSOR_TIME_MONTH,
> +	HID_USAGE_SENSOR_TIME_DAY,
> +	HID_USAGE_SENSOR_TIME_HOUR,
> +	HID_USAGE_SENSOR_TIME_MINUTE,
> +	HID_USAGE_SENSOR_TIME_SECOND,
> +};
> +
> +/* Channel names for verbose error messages */
> +static const char * const hid_time_channel_names[TIME_RTC_CHANNEL_MAX] = {
> +	"year", "month", "day", "hour", "minute", "second",
> +};
> +
> +/* Callback handler to send event after all samples are received and captured */
> +static int hid_time_proc_event(struct hid_sensor_hub_device *hsdev,
> +				unsigned usage_id, void *priv)
> +{
> +	unsigned long flags;
> +	struct hid_time_state *time_state = platform_get_drvdata(priv);
> +
> +	spin_lock_irqsave(&time_state->lock_last_time, flags);
> +	time_state->last_time = time_state->time_buf;
> +	spin_unlock_irqrestore(&time_state->lock_last_time, flags);
> +	complete(&time_state->comp_last_time);
> +	return 0;
> +}
> +
> +static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev,
> +				unsigned usage_id, size_t raw_len,
> +				char *raw_data, void *priv)
> +{
> +	struct hid_time_state *time_state = platform_get_drvdata(priv);
> +	struct rtc_time *time_buf = &time_state->time_buf;
> +
> +	switch (usage_id) {
> +	case HID_USAGE_SENSOR_TIME_YEAR:
> +		time_buf->tm_year = *(u8 *)raw_data;
> +		if (time_buf->tm_year < 70)
> +			/* assume we are in 1970...2069 */
> +			time_buf->tm_year += 100;
> +		break;
> +	case HID_USAGE_SENSOR_TIME_MONTH:
> +		/* sensor sending the month as 1-12, we need 0-11 */
> +		time_buf->tm_mon = *(u8 *)raw_data-1;
> +		break;
> +	case HID_USAGE_SENSOR_TIME_DAY:
> +		time_buf->tm_mday = *(u8 *)raw_data;
> +		break;
> +	case HID_USAGE_SENSOR_TIME_HOUR:
> +		time_buf->tm_hour = *(u8 *)raw_data;
> +		break;
> +	case HID_USAGE_SENSOR_TIME_MINUTE:
> +		time_buf->tm_min = *(u8 *)raw_data;
> +		break;
> +	case HID_USAGE_SENSOR_TIME_SECOND:
> +		time_buf->tm_sec = *(u8 *)raw_data;
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +	return 0;
> +}
> +
> +/* small helper, haven't found any other way */
> +static const char *attrib_name(u32 attrib_id)
> +{
> +	static const char unknown[] = "unknown";
> +	unsigned i;
> +
> +	for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) {
> +		if (hid_time_addresses[i] == attrib_id)
> +			return hid_time_channel_names[i];
> +	}
> +	return unknown; /* should never happen */
> +}
> +
> +static int hid_time_parse_report(struct platform_device *pdev,
> +				struct hid_sensor_hub_device *hsdev,
> +				unsigned usage_id,
> +				struct hid_time_state *time_state)
> +{
> +	int report_id, i;
> +
> +	for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i)
> +		if (sensor_hub_input_get_attribute_info(hsdev,
> +				HID_INPUT_REPORT, usage_id,
> +				hid_time_addresses[i],
> +				&time_state->info[i]) < 0)
> +			return -EINVAL;
> +	/* Check the (needed) attributes for sanity */
> +	report_id = time_state->info[0].report_id;
> +	if (report_id < 0) {
> +		dev_err(&pdev->dev, "bad report ID!\n");
> +		return -EINVAL;
> +	}
> +	for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) {
> +		if (time_state->info[i].report_id != report_id) {
> +			dev_err(&pdev->dev,
> +				"not all needed attributes inside the same report!\n");
> +			return -EINVAL;
> +		}
> +		if (time_state->info[i].size != 1) {
> +			dev_err(&pdev->dev,
> +				"attribute '%s' not 8 bits wide!\n",
> +				attrib_name(time_state->info[i].attrib_id));
> +			return -EINVAL;
> +		}
> +		if (time_state->info[i].units !=
> +				HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED &&
> +				/* allow attribute seconds with unit seconds */
> +				!(time_state->info[i].attrib_id ==
> +				HID_USAGE_SENSOR_TIME_SECOND &&
> +				time_state->info[i].units ==
> +				HID_USAGE_SENSOR_UNITS_SECOND)) {
> +			dev_err(&pdev->dev,
> +				"attribute '%s' hasn't a unit of type 'none'!\n",
> +				attrib_name(time_state->info[i].attrib_id));
> +			return -EINVAL;
> +		}
> +		if (time_state->info[i].unit_expo) {
> +			dev_err(&pdev->dev,
> +				"attribute '%s' hasn't a unit exponent of 1!\n",
> +				attrib_name(time_state->info[i].attrib_id));
> +			return -EINVAL;
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +static int hid_rtc_read_time(struct device *dev, struct rtc_time *tm)
> +{
> +	unsigned long flags;
> +	struct hid_time_state *time_state =
> +		platform_get_drvdata(to_platform_device(dev));
> +
> +	INIT_COMPLETION(time_state->comp_last_time);
> +	/* get a report with all values through requesting one value */
> +	sensor_hub_input_attr_get_raw_value(time_state->common_attributes.hsdev,
> +			HID_USAGE_SENSOR_TIME, hid_time_addresses[0],
> +			time_state->info[0].report_id);
> +	/* wait for all values (event) */
> +	if (!wait_for_completion_interruptible_timeout(
> +			&time_state->comp_last_time, HZ*6))
> +		return -EIO;
> +	spin_lock_irqsave(&time_state->lock_last_time, flags);
> +	*tm = time_state->last_time;
> +	spin_unlock_irqrestore(&time_state->lock_last_time, flags);
> +
> +	return 0;
> +}
> +
> +static const struct rtc_class_ops rtc_ops = {
> +	.read_time = hid_rtc_read_time,
> +};
> +
> +static int hid_time_probe(struct platform_device *pdev)
> +{
> +	int ret = 0;
> +	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
> +	struct hid_time_state *time_state = devm_kzalloc(&pdev->dev,
> +		sizeof(struct hid_time_state), GFP_KERNEL);
> +
> +	if (time_state == NULL)
> +		return -ENOMEM;
> +
> +	platform_set_drvdata(pdev, time_state);
> +
> +	init_completion(&time_state->comp_last_time);
> +	time_state->common_attributes.hsdev = hsdev;
> +	time_state->common_attributes.pdev = pdev;
> +
> +	ret = hid_sensor_parse_common_attributes(hsdev,
> +				HID_USAGE_SENSOR_TIME,
> +				&time_state->common_attributes);
> +	if (ret) {
> +		dev_err(&pdev->dev, "failed to setup common attributes!\n");
> +		return ret;
> +	}
> +
> +	ret = hid_time_parse_report(pdev, hsdev, HID_USAGE_SENSOR_TIME,
> +					time_state);
> +	if (ret) {
> +		dev_err(&pdev->dev, "failed to setup attributes!\n");
> +		return ret;
> +	}
> +
> +	time_state->callbacks.send_event = hid_time_proc_event;
> +	time_state->callbacks.capture_sample = hid_time_capture_sample;
> +	time_state->callbacks.pdev = pdev;
> +	ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_TIME,
> +					&time_state->callbacks);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "register callback failed!\n");
> +		return ret;
> +	}
> +
> +	time_state->rtc = rtc_device_register("hid-sensor-time",
> +				&pdev->dev, &rtc_ops, THIS_MODULE);
> +
> +	if (IS_ERR(time_state->rtc)) {
> +		dev_err(&pdev->dev, "rtc device register failed!\n");
> +		return PTR_ERR(time_state->rtc);
> +	}
> +
> +	return ret;
> +}
> +
> +static int __devinit hid_time_remove(struct platform_device *pdev)
> +{
> +	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
> +	struct hid_time_state *time_state = platform_get_drvdata(pdev);
> +
> +	rtc_device_unregister(time_state->rtc);
> +	sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
> +
> +	return 0;
> +}
> +
> +static struct platform_driver hid_time_platform_driver = {
> +	.driver = {
> +		.name	= DRIVER_NAME,
> +		.owner	= THIS_MODULE,
> +	},
> +	.probe		= hid_time_probe,
> +	.remove		= hid_time_remove,
> +};
> +module_platform_driver(hid_time_platform_driver);
> +
> +MODULE_DESCRIPTION("HID Sensor Time");
> +MODULE_AUTHOR("Alexander Holler <holler@ahsoftware.de>");
> +MODULE_LICENSE("GPL");


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

* Re: [PATCH 4/4 v4] rtc: add rtc-driver for HID sensors of type time
  2012-12-14  9:42                                               ` Lars-Peter Clausen
@ 2012-12-14 13:08                                                 ` Alexander Holler
  2012-12-14 14:15                                                   ` Alexander Holler
  0 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-14 13:08 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton

Am 14.12.2012 10:42, schrieb Lars-Peter Clausen:
> On 12/12/2012 12:11 PM, Alexander Holler wrote:
>> This driver makes the time from HID sensors (hubs) which are offering
>> such available like any other RTC does.
>>
>> Currently the time can only be read. Setting the time must be done
>> through sending a report, which currently isn't supported by
>> hid-sensor-hub. (I've planned to submit patches.)
>>
>> It is necessary that all values like year, month etc, are send as
>> 8bit values (1 byte each) and all of them in 1 report. Also the
>> spec HUTRR39b doesn't define the range of the year field, we
>> tread it as 0 - 99 because that's what most RTCs I know about are
>> offering.
>>
>> Signed-off-by: Alexander Holler <holler@ahsoftware.de>
>
> Hi,
>
> sorry for the delay. There is still the __devinit in front of
> hid_time_remove left.
>
> And another thing I've overlooked before:
> wait_for_completion_interruptible_timeout can either return a positive
> number when the completion was completed, 0 in case of an timeout, or a
> negative error code in case it was interrupted. You need to handle all
> three. E.g. something like this.
>
> ret = wait_for_completion_interruptible_timeout(...)
> if (ret == 0)
> 	return -EIO;
> if (ret < 0)
> 	return ret
>

Hmpf, the only working approach to use some in kernel functions really 
is to the read source yourself and don't trust anything else. :/

And that ping-ping is stressing my patience, I think I will write a rfc 
to introduce (at least allow) maintainer-patches.

Will make a v5.

Regards,

Alexander

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

* Re: [PATCH 4/4 v4] rtc: add rtc-driver for HID sensors of type time
  2012-12-14 13:08                                                 ` Alexander Holler
@ 2012-12-14 14:15                                                   ` Alexander Holler
  2012-12-14 14:29                                                     ` Alexander Holler
  0 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-14 14:15 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton

Am 14.12.2012 14:08, schrieb Alexander Holler:
> Am 14.12.2012 10:42, schrieb Lars-Peter Clausen:

>> And another thing I've overlooked before:
>> wait_for_completion_interruptible_timeout can either return a positive
>> number when the completion was completed, 0 in case of an timeout, or a
>> negative error code in case it was interrupted. You need to handle all
>> three. E.g. something like this.
>>
>> ret = wait_for_completion_interruptible_timeout(...)
>> if (ret == 0)
>>     return -EIO;
>> if (ret < 0)
>>     return ret
>>
>
> Hmpf, the only working approach to use some in kernel functions really
> is to the read source yourself and don't trust anything else. :/

Anyway, my approach doesn't work as it introduces a race condition:


/* get a report with all values through requesting one value */
sensor_hub_input_attr_get_raw_value(...)

/* race if this task goes to slepp and the values were
received before it could call the below wait...

/* wait for all values (event) */
if (!wait_for_completion_interruptible_timeout(...))


I'll have to look for a mechanism how to avoid that. So v5 might need 
some time.


Regards,

Alexander


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

* Re: [PATCH 4/4 v4] rtc: add rtc-driver for HID sensors of type time
  2012-12-14 14:15                                                   ` Alexander Holler
@ 2012-12-14 14:29                                                     ` Alexander Holler
  2012-12-14 14:34                                                       ` Lars-Peter Clausen
  0 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-14 14:29 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton

Am 14.12.2012 15:15, schrieb Alexander Holler:
> Am 14.12.2012 14:08, schrieb Alexander Holler:
>> Am 14.12.2012 10:42, schrieb Lars-Peter Clausen:
>
>>> And another thing I've overlooked before:
>>> wait_for_completion_interruptible_timeout can either return a positive
>>> number when the completion was completed, 0 in case of an timeout, or a
>>> negative error code in case it was interrupted. You need to handle all
>>> three. E.g. something like this.
>>>
>>> ret = wait_for_completion_interruptible_timeout(...)
>>> if (ret == 0)
>>>     return -EIO;
>>> if (ret < 0)
>>>     return ret
>>>
>>
>> Hmpf, the only working approach to use some in kernel functions really
>> is to the read source yourself and don't trust anything else. :/
>
> Anyway, my approach doesn't work as it introduces a race condition:
>
>
> /* get a report with all values through requesting one value */
> sensor_hub_input_attr_get_raw_value(...)
>
> /* race if this task goes to slepp and the values were
> received before it could call the below wait...
>
> /* wait for all values (event) */
> if (!wait_for_completion_interruptible_timeout(...))
>
>
> I'll have to look for a mechanism how to avoid that. So v5 might need
> some time.

Sorry for the noise. That INIT_COMPLETION() before the sensor...() does 
exactly that. So it's enough if I handle the different return situations 
of wait_for...().

I will just use if(wait...()<=0) return -EIO.

Regards,

Alexander

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

* Re: [PATCH 4/4 v4] rtc: add rtc-driver for HID sensors of type time
  2012-12-14 14:29                                                     ` Alexander Holler
@ 2012-12-14 14:34                                                       ` Lars-Peter Clausen
  2012-12-14 15:24                                                         ` Alexander Holler
  0 siblings, 1 reply; 66+ messages in thread
From: Lars-Peter Clausen @ 2012-12-14 14:34 UTC (permalink / raw)
  To: Alexander Holler
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton

On 12/14/2012 03:29 PM, Alexander Holler wrote:
> Am 14.12.2012 15:15, schrieb Alexander Holler:
>> Am 14.12.2012 14:08, schrieb Alexander Holler:
>>> Am 14.12.2012 10:42, schrieb Lars-Peter Clausen:
>>
>>>> And another thing I've overlooked before:
>>>> wait_for_completion_interruptible_timeout can either return a positive
>>>> number when the completion was completed, 0 in case of an timeout, or a
>>>> negative error code in case it was interrupted. You need to handle all
>>>> three. E.g. something like this.
>>>>
>>>> ret = wait_for_completion_interruptible_timeout(...)
>>>> if (ret == 0)
>>>>     return -EIO;
>>>> if (ret < 0)
>>>>     return ret
>>>>
>>>
>>> Hmpf, the only working approach to use some in kernel functions really
>>> is to the read source yourself and don't trust anything else. :/
>>
>> Anyway, my approach doesn't work as it introduces a race condition:
>>
>>
>> /* get a report with all values through requesting one value */
>> sensor_hub_input_attr_get_raw_value(...)
>>
>> /* race if this task goes to slepp and the values were
>> received before it could call the below wait...
>>
>> /* wait for all values (event) */
>> if (!wait_for_completion_interruptible_timeout(...))
>>
>>
>> I'll have to look for a mechanism how to avoid that. So v5 might need
>> some time.
> 
> Sorry for the noise. That INIT_COMPLETION() before the sensor...() does
> exactly that. So it's enough if I handle the different return situations of
> wait_for...().
> 
> I will just use if(wait...()<=0) return -EIO.
> 

No, that's wrong. You should really return the error code returned by
wait_for_completion_interruptible_timeout(). This will make sure that
userspace restarts the syscall if necessary.

- Lars

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

* Re: [PATCH 4/4 v4] rtc: add rtc-driver for HID sensors of type time
  2012-12-14 14:34                                                       ` Lars-Peter Clausen
@ 2012-12-14 15:24                                                         ` Alexander Holler
  2012-12-14 16:33                                                           ` Lars-Peter Clausen
  0 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-14 15:24 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton

Am 14.12.2012 15:34, schrieb Lars-Peter Clausen:
> On 12/14/2012 03:29 PM, Alexander Holler wrote:
>> Am 14.12.2012 15:15, schrieb Alexander Holler:
>>> Am 14.12.2012 14:08, schrieb Alexander Holler:
>>>> Am 14.12.2012 10:42, schrieb Lars-Peter Clausen:
>>>
>>>>> And another thing I've overlooked before:
>>>>> wait_for_completion_interruptible_timeout can either return a positive
>>>>> number when the completion was completed, 0 in case of an timeout, or a
>>>>> negative error code in case it was interrupted. You need to handle all
>>>>> three. E.g. something like this.
>>>>>
>>>>> ret = wait_for_completion_interruptible_timeout(...)
>>>>> if (ret == 0)
>>>>>     return -EIO;
>>>>> if (ret < 0)
>>>>>     return ret
>>>>>
>>>>
>>>> Hmpf, the only working approach to use some in kernel functions really
>>>> is to the read source yourself and don't trust anything else. :/
>>>
>>> Anyway, my approach doesn't work as it introduces a race condition:
>>>
>>>
>>> /* get a report with all values through requesting one value */
>>> sensor_hub_input_attr_get_raw_value(...)
>>>
>>> /* race if this task goes to slepp and the values were
>>> received before it could call the below wait...
>>>
>>> /* wait for all values (event) */
>>> if (!wait_for_completion_interruptible_timeout(...))
>>>
>>>
>>> I'll have to look for a mechanism how to avoid that. So v5 might need
>>> some time.
>>
>> Sorry for the noise. That INIT_COMPLETION() before the sensor...() does
>> exactly that. So it's enough if I handle the different return situations of
>> wait_for...().
>>
>> I will just use if(wait...()<=0) return -EIO.
>>
> 
> No, that's wrong. You should really return the error code returned by
> wait_for_completion_interruptible_timeout(). This will make sure that
> userspace restarts the syscall if necessary.

Sorry for my ignorance, but which reasons for interruption do exist
which doesn't kill the userspace too? The error number -ESYSRESTART
doesn't offer a hint.

Alexander

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

* Re: [PATCH 4/4 v4] rtc: add rtc-driver for HID sensors of type time
  2012-12-14 15:24                                                         ` Alexander Holler
@ 2012-12-14 16:33                                                           ` Lars-Peter Clausen
  2012-12-14 21:24                                                             ` Alexander Holler
  0 siblings, 1 reply; 66+ messages in thread
From: Lars-Peter Clausen @ 2012-12-14 16:33 UTC (permalink / raw)
  To: Alexander Holler
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton

On 12/14/2012 04:24 PM, Alexander Holler wrote:
> Am 14.12.2012 15:34, schrieb Lars-Peter Clausen:
>> On 12/14/2012 03:29 PM, Alexander Holler wrote:
>>> Am 14.12.2012 15:15, schrieb Alexander Holler:
>>>> Am 14.12.2012 14:08, schrieb Alexander Holler:
>>>>> Am 14.12.2012 10:42, schrieb Lars-Peter Clausen:
>>>>
>>>>>> And another thing I've overlooked before:
>>>>>> wait_for_completion_interruptible_timeout can either return a positive
>>>>>> number when the completion was completed, 0 in case of an timeout, or a
>>>>>> negative error code in case it was interrupted. You need to handle all
>>>>>> three. E.g. something like this.
>>>>>>
>>>>>> ret = wait_for_completion_interruptible_timeout(...)
>>>>>> if (ret == 0)
>>>>>>     return -EIO;
>>>>>> if (ret < 0)
>>>>>>     return ret
>>>>>>
>>>>>
>>>>> Hmpf, the only working approach to use some in kernel functions really
>>>>> is to the read source yourself and don't trust anything else. :/
>>>>
>>>> Anyway, my approach doesn't work as it introduces a race condition:
>>>>
>>>>
>>>> /* get a report with all values through requesting one value */
>>>> sensor_hub_input_attr_get_raw_value(...)
>>>>
>>>> /* race if this task goes to slepp and the values were
>>>> received before it could call the below wait...
>>>>
>>>> /* wait for all values (event) */
>>>> if (!wait_for_completion_interruptible_timeout(...))
>>>>
>>>>
>>>> I'll have to look for a mechanism how to avoid that. So v5 might need
>>>> some time.
>>>
>>> Sorry for the noise. That INIT_COMPLETION() before the sensor...() does
>>> exactly that. So it's enough if I handle the different return situations of
>>> wait_for...().
>>>
>>> I will just use if(wait...()<=0) return -EIO.
>>>
>>
>> No, that's wrong. You should really return the error code returned by
>> wait_for_completion_interruptible_timeout(). This will make sure that
>> userspace restarts the syscall if necessary.
> 
> Sorry for my ignorance, but which reasons for interruption do exist
> which doesn't kill the userspace too? The error number -ESYSRESTART
> doesn't offer a hint.


Well I'm not an expert on this either, but as far as I know any signal the
process is listening on can cause an interruption. Most signals won't kill
the process though. More on the whole restart stuff:
http://lwn.net/Articles/528935/

- Lars


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

* Re: [PATCH 4/4 v4] rtc: add rtc-driver for HID sensors of type time
  2012-12-14 16:33                                                           ` Lars-Peter Clausen
@ 2012-12-14 21:24                                                             ` Alexander Holler
  2012-12-14 22:02                                                               ` [PATCH 4/4 v5] " Alexander Holler
  0 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-14 21:24 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton

Am 14.12.2012 17:33, schrieb Lars-Peter Clausen:
> On 12/14/2012 04:24 PM, Alexander Holler wrote:
>> Am 14.12.2012 15:34, schrieb Lars-Peter Clausen:
>>> On 12/14/2012 03:29 PM, Alexander Holler wrote:
>>>> Am 14.12.2012 15:15, schrieb Alexander Holler:
>>>>> Am 14.12.2012 14:08, schrieb Alexander Holler:
>>>>>> Am 14.12.2012 10:42, schrieb Lars-Peter Clausen:
>>>>>
>>>>>>> And another thing I've overlooked before:
>>>>>>> wait_for_completion_interruptible_timeout can either return a positive
>>>>>>> number when the completion was completed, 0 in case of an timeout, or a
>>>>>>> negative error code in case it was interrupted. You need to handle all
>>>>>>> three. E.g. something like this.
>>>>>>>
>>>>>>> ret = wait_for_completion_interruptible_timeout(...)
>>>>>>> if (ret == 0)
>>>>>>>      return -EIO;
>>>>>>> if (ret < 0)
>>>>>>>      return ret
>>>>>>>
>>>>>>
>>>>>> Hmpf, the only working approach to use some in kernel functions really
>>>>>> is to the read source yourself and don't trust anything else. :/
>>>>>
>>>>> Anyway, my approach doesn't work as it introduces a race condition:
>>>>>
>>>>>
>>>>> /* get a report with all values through requesting one value */
>>>>> sensor_hub_input_attr_get_raw_value(...)
>>>>>
>>>>> /* race if this task goes to slepp and the values were
>>>>> received before it could call the below wait...
>>>>>
>>>>> /* wait for all values (event) */
>>>>> if (!wait_for_completion_interruptible_timeout(...))
>>>>>
>>>>>
>>>>> I'll have to look for a mechanism how to avoid that. So v5 might need
>>>>> some time.
>>>>
>>>> Sorry for the noise. That INIT_COMPLETION() before the sensor...() does
>>>> exactly that. So it's enough if I handle the different return situations of
>>>> wait_for...().
>>>>
>>>> I will just use if(wait...()<=0) return -EIO.
>>>>
>>>
>>> No, that's wrong. You should really return the error code returned by
>>> wait_for_completion_interruptible_timeout(). This will make sure that
>>> userspace restarts the syscall if necessary.
>>
>> Sorry for my ignorance, but which reasons for interruption do exist
>> which doesn't kill the userspace too? The error number -ESYSRESTART
>> doesn't offer a hint.
>
>
> Well I'm not an expert on this either, but as far as I know any signal the
> process is listening on can cause an interruption. Most signals won't kill
> the process though. More on the whole restart stuff:
> http://lwn.net/Articles/528935/

I've come to the conclusion that using 
wait_for_completion_interruptible_timeout() isn't what should be used 
here and will switch to wait_for_completion_killable_timeout(). Here are 
my reasons:

1. I don't think any caller of rtc_ops.read_time will be prepared to 
handle -ESYSRESTART.

2. Someone wants the time. Beeing interruptible seems to mean the 
process might be interrupted by signal processing with an unknown long 
duration which could decrease the accuracy even below the desired one 
second (which doesn't look unlikely, signal processing in userspace is 
unpredictable and (mis)used for all kind of stuff).

3. I've primarily used it to be friendly in means of killable, but 
didn't know that ..._killable() does exist. ;)

Btw., here is a imho good and especially short introduction about the 
task states along with some pointers to more comprehensive resources:
http://www.ibm.com/developerworks/linux/library/l-task-killable/

v5 of that patch will follow. Hopefully the last one necessary.

Regards,

Alexander

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

* [PATCH 4/4 v5] rtc: add rtc-driver for HID sensors of type time
  2012-12-14 21:24                                                             ` Alexander Holler
@ 2012-12-14 22:02                                                               ` Alexander Holler
  0 siblings, 0 replies; 66+ messages in thread
From: Alexander Holler @ 2012-12-14 22:02 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-iio, Jonathan Cameron, Lars-Peter Clausen, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton,
	Alexander Holler

This driver makes the time from HID sensors (hubs) which are offering
such available like any other RTC does.

It is necessary that all values like year, month etc, are send as
8bit values (1 byte each) and all of them in 1 report. Also the
spec HUTRR39b doesn't define the range of the year field, we
tread it as 0 - 99 because that's what most RTCs I know about are
offering.

Currently the time can only be read. Setting the time must be done
through sending a report (or a feature). The spec currently doesn't
define how and I'm not sure if I just should define something by myself.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 drivers/rtc/Kconfig               |   16 ++
 drivers/rtc/Makefile              |    1 +
 drivers/rtc/rtc-hid-sensor-time.c |  291 +++++++++++++++++++++++++++++++++++++
 3 files changed, 308 insertions(+), 0 deletions(-)
 create mode 100644 drivers/rtc/rtc-hid-sensor-time.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 19c03ab..e0d29b5 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1144,4 +1144,20 @@ config RTC_DRV_SNVS
 	   This driver can also be built as a module, if so, the module
 	   will be called "rtc-snvs".
 
+comment "HID Sensor RTC drivers"
+
+config RTC_DRV_HID_SENSOR_TIME
+	tristate "HID Sensor Time"
+	depends on USB_HID
+	select IIO
+	select HID_SENSOR_HUB
+	select HID_SENSOR_IIO_COMMON
+	help
+	  Say yes here to build support for the HID Sensors of type Time.
+	  This drivers makes such sensors available as RTCs.
+
+	  If this driver is compiled as a module, it will be named
+	  rtc-hid-sensor-time.
+
+
 endif # RTC_CLASS
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 56297f0..9d1658a 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_RTC_DRV_EM3027)	+= rtc-em3027.o
 obj-$(CONFIG_RTC_DRV_EP93XX)	+= rtc-ep93xx.o
 obj-$(CONFIG_RTC_DRV_FM3130)	+= rtc-fm3130.o
 obj-$(CONFIG_RTC_DRV_GENERIC)	+= rtc-generic.o
+obj-$(CONFIG_RTC_DRV_HID_SENSOR_TIME) += rtc-hid-sensor-time.o
 obj-$(CONFIG_RTC_DRV_IMXDI)	+= rtc-imxdi.o
 obj-$(CONFIG_RTC_DRV_ISL1208)	+= rtc-isl1208.o
 obj-$(CONFIG_RTC_DRV_ISL12022)	+= rtc-isl12022.o
diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c
new file mode 100644
index 0000000..25cac6e
--- /dev/null
+++ b/drivers/rtc/rtc-hid-sensor-time.c
@@ -0,0 +1,291 @@
+/*
+ * HID Sensor Time Driver
+ * Copyright (c) 2012, Alexander Holler.
+ *
+ * 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 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/module.h>
+#include <linux/hid-sensor-hub.h>
+#include <linux/iio/iio.h>
+#include <linux/rtc.h>
+
+/* Format: HID-SENSOR-usage_id_in_hex */
+/* Usage ID from spec for Time: 0x2000A0 */
+#define DRIVER_NAME "HID-SENSOR-2000a0" /* must be lowercase */
+
+enum hid_time_channel {
+	CHANNEL_SCAN_INDEX_YEAR,
+	CHANNEL_SCAN_INDEX_MONTH,
+	CHANNEL_SCAN_INDEX_DAY,
+	CHANNEL_SCAN_INDEX_HOUR,
+	CHANNEL_SCAN_INDEX_MINUTE,
+	CHANNEL_SCAN_INDEX_SECOND,
+	TIME_RTC_CHANNEL_MAX,
+};
+
+struct hid_time_state {
+	struct hid_sensor_hub_callbacks callbacks;
+	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_hub_attribute_info info[TIME_RTC_CHANNEL_MAX];
+	struct rtc_time last_time;
+	spinlock_t lock_last_time;
+	struct completion comp_last_time;
+	struct rtc_time time_buf;
+	struct rtc_device *rtc;
+};
+
+static const u32 hid_time_addresses[TIME_RTC_CHANNEL_MAX] = {
+	HID_USAGE_SENSOR_TIME_YEAR,
+	HID_USAGE_SENSOR_TIME_MONTH,
+	HID_USAGE_SENSOR_TIME_DAY,
+	HID_USAGE_SENSOR_TIME_HOUR,
+	HID_USAGE_SENSOR_TIME_MINUTE,
+	HID_USAGE_SENSOR_TIME_SECOND,
+};
+
+/* Channel names for verbose error messages */
+static const char * const hid_time_channel_names[TIME_RTC_CHANNEL_MAX] = {
+	"year", "month", "day", "hour", "minute", "second",
+};
+
+/* Callback handler to send event after all samples are received and captured */
+static int hid_time_proc_event(struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id, void *priv)
+{
+	unsigned long flags;
+	struct hid_time_state *time_state = platform_get_drvdata(priv);
+
+	spin_lock_irqsave(&time_state->lock_last_time, flags);
+	time_state->last_time = time_state->time_buf;
+	spin_unlock_irqrestore(&time_state->lock_last_time, flags);
+	complete(&time_state->comp_last_time);
+	return 0;
+}
+
+static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id, size_t raw_len,
+				char *raw_data, void *priv)
+{
+	struct hid_time_state *time_state = platform_get_drvdata(priv);
+	struct rtc_time *time_buf = &time_state->time_buf;
+
+	switch (usage_id) {
+	case HID_USAGE_SENSOR_TIME_YEAR:
+		time_buf->tm_year = *(u8 *)raw_data;
+		if (time_buf->tm_year < 70)
+			/* assume we are in 1970...2069 */
+			time_buf->tm_year += 100;
+		break;
+	case HID_USAGE_SENSOR_TIME_MONTH:
+		/* sensor sending the month as 1-12, we need 0-11 */
+		time_buf->tm_mon = *(u8 *)raw_data-1;
+		break;
+	case HID_USAGE_SENSOR_TIME_DAY:
+		time_buf->tm_mday = *(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_HOUR:
+		time_buf->tm_hour = *(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_MINUTE:
+		time_buf->tm_min = *(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_SECOND:
+		time_buf->tm_sec = *(u8 *)raw_data;
+		break;
+	default:
+		return -EINVAL;
+	}
+	return 0;
+}
+
+/* small helper, haven't found any other way */
+static const char *hid_time_attrib_name(u32 attrib_id)
+{
+	static const char unknown[] = "unknown";
+	unsigned i;
+
+	for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) {
+		if (hid_time_addresses[i] == attrib_id)
+			return hid_time_channel_names[i];
+	}
+	return unknown; /* should never happen */
+}
+
+static int hid_time_parse_report(struct platform_device *pdev,
+				struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id,
+				struct hid_time_state *time_state)
+{
+	int report_id, i;
+
+	for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i)
+		if (sensor_hub_input_get_attribute_info(hsdev,
+				HID_INPUT_REPORT, usage_id,
+				hid_time_addresses[i],
+				&time_state->info[i]) < 0)
+			return -EINVAL;
+	/* Check the (needed) attributes for sanity */
+	report_id = time_state->info[0].report_id;
+	if (report_id < 0) {
+		dev_err(&pdev->dev, "bad report ID!\n");
+		return -EINVAL;
+	}
+	for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) {
+		if (time_state->info[i].report_id != report_id) {
+			dev_err(&pdev->dev,
+				"not all needed attributes inside the same report!\n");
+			return -EINVAL;
+		}
+		if (time_state->info[i].size != 1) {
+			dev_err(&pdev->dev,
+				"attribute '%s' not 8 bits wide!\n",
+				hid_time_attrib_name(
+					time_state->info[i].attrib_id));
+			return -EINVAL;
+		}
+		if (time_state->info[i].units !=
+				HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED &&
+				/* allow attribute seconds with unit seconds */
+				!(time_state->info[i].attrib_id ==
+				HID_USAGE_SENSOR_TIME_SECOND &&
+				time_state->info[i].units ==
+				HID_USAGE_SENSOR_UNITS_SECOND)) {
+			dev_err(&pdev->dev,
+				"attribute '%s' hasn't a unit of type 'none'!\n",
+				hid_time_attrib_name(
+					time_state->info[i].attrib_id));
+			return -EINVAL;
+		}
+		if (time_state->info[i].unit_expo) {
+			dev_err(&pdev->dev,
+				"attribute '%s' hasn't a unit exponent of 1!\n",
+				hid_time_attrib_name(
+					time_state->info[i].attrib_id));
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+static int hid_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	unsigned long flags;
+	struct hid_time_state *time_state =
+		platform_get_drvdata(to_platform_device(dev));
+	int ret;
+
+	INIT_COMPLETION(time_state->comp_last_time);
+	/* get a report with all values through requesting one value */
+	sensor_hub_input_attr_get_raw_value(time_state->common_attributes.hsdev,
+			HID_USAGE_SENSOR_TIME, hid_time_addresses[0],
+			time_state->info[0].report_id);
+	/* wait for all values (event) */
+	ret = wait_for_completion_killable_timeout(
+			&time_state->comp_last_time, HZ*6);
+	if (ret > 0) {
+		/* no error */
+		spin_lock_irqsave(&time_state->lock_last_time, flags);
+		*tm = time_state->last_time;
+		spin_unlock_irqrestore(&time_state->lock_last_time, flags);
+		return 0;
+	}
+	if (!ret)
+		return -EIO; /* timeouted */
+	return ret; /* killed (-ERESTARTSYS) */
+}
+
+static const struct rtc_class_ops hid_time_rtc_ops = {
+	.read_time = hid_rtc_read_time,
+};
+
+static int hid_time_probe(struct platform_device *pdev)
+{
+	int ret = 0;
+	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct hid_time_state *time_state = devm_kzalloc(&pdev->dev,
+		sizeof(struct hid_time_state), GFP_KERNEL);
+
+	if (time_state == NULL)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, time_state);
+
+	init_completion(&time_state->comp_last_time);
+	time_state->common_attributes.hsdev = hsdev;
+	time_state->common_attributes.pdev = pdev;
+
+	ret = hid_sensor_parse_common_attributes(hsdev,
+				HID_USAGE_SENSOR_TIME,
+				&time_state->common_attributes);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to setup common attributes!\n");
+		return ret;
+	}
+
+	ret = hid_time_parse_report(pdev, hsdev, HID_USAGE_SENSOR_TIME,
+					time_state);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to setup attributes!\n");
+		return ret;
+	}
+
+	time_state->callbacks.send_event = hid_time_proc_event;
+	time_state->callbacks.capture_sample = hid_time_capture_sample;
+	time_state->callbacks.pdev = pdev;
+	ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_TIME,
+					&time_state->callbacks);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "register callback failed!\n");
+		return ret;
+	}
+
+	time_state->rtc = rtc_device_register("hid-sensor-time",
+				&pdev->dev, &hid_time_rtc_ops, THIS_MODULE);
+
+	if (IS_ERR(time_state->rtc)) {
+		dev_err(&pdev->dev, "rtc device register failed!\n");
+		return PTR_ERR(time_state->rtc);
+	}
+
+	return ret;
+}
+
+static int hid_time_remove(struct platform_device *pdev)
+{
+	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct hid_time_state *time_state = platform_get_drvdata(pdev);
+
+	rtc_device_unregister(time_state->rtc);
+	sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
+
+	return 0;
+}
+
+static struct platform_driver hid_time_platform_driver = {
+	.driver = {
+		.name	= DRIVER_NAME,
+		.owner	= THIS_MODULE,
+	},
+	.probe		= hid_time_probe,
+	.remove		= hid_time_remove,
+};
+module_platform_driver(hid_time_platform_driver);
+
+MODULE_DESCRIPTION("HID Sensor Time");
+MODULE_AUTHOR("Alexander Holler <holler@ahsoftware.de>");
+MODULE_LICENSE("GPL");
-- 
1.7.8.6


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

* Re: [PATCH 1/4 v2] iio: hid-sensors: respect CONFIG_IIO_TRIGGER
  2012-12-11 18:21                                     ` [PATCH 1/4 v2] iio: hid-sensors: respect CONFIG_IIO_TRIGGER Alexander Holler
                                                         ` (2 preceding siblings ...)
  2012-12-11 18:21                                       ` [PATCH 4/4 v3] rtc: add rtc-driver for HID sensors of type time Alexander Holler
@ 2012-12-15 10:54                                       ` Jonathan Cameron
  2012-12-15 12:37                                         ` Alexander Holler
  3 siblings, 1 reply; 66+ messages in thread
From: Jonathan Cameron @ 2012-12-15 10:54 UTC (permalink / raw)
  To: Alexander Holler
  Cc: linux-kernel, linux-iio, Jonathan Cameron, Lars-Peter Clausen,
	rtc-linux, Alessandro Zummo, srinivas pandruvada, Andrew Morton

On 12/11/2012 06:21 PM, Alexander Holler wrote:
> Not much to say, without that change, hid-sensor-trigger will be
> always compiled if HID_SENSOR_IIO_COMMON is selected which fails if
> CONFIG_IIO_TRIGGER is not set because CONFIG_IIO_CONSUMERS_PER_TRIGGER
> will not be defined.
> 
> Signed-off-by: Alexander Holler <holler@ahsoftware.de>

Not sure what tree this was against as it is needs some fixing up for
staging-next and currently mainline.  Ah well fixed up and added to togreg
branch of

git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git

Please check I haven't messed it up.
> ---
>  drivers/iio/accel/Kconfig               |    1 +
>  drivers/iio/common/hid-sensors/Kconfig  |   13 ++++++++++++-
>  drivers/iio/common/hid-sensors/Makefile |    3 ++-
>  drivers/iio/gyro/Kconfig                |    1 +
>  drivers/iio/light/Kconfig               |    1 +
>  drivers/iio/magnetometer/Kconfig        |    1 +
>  6 files changed, 18 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
> index b2510c4..b84b806 100644
> --- a/drivers/iio/accel/Kconfig
> +++ b/drivers/iio/accel/Kconfig
> @@ -8,6 +8,7 @@ config HID_SENSOR_ACCEL_3D
>  	select IIO_BUFFER
>  	select IIO_TRIGGERED_BUFFER
>  	select HID_SENSOR_IIO_COMMON
> +	select HID_SENSOR_IIO_TRIGGER
>  	tristate "HID Acelerometers 3D"
>  	help
>  	  Say yes here to build support for the HID SENSOR
> diff --git a/drivers/iio/common/hid-sensors/Kconfig b/drivers/iio/common/hid-sensors/Kconfig
> index 8e63d81..e294f31 100644
> --- a/drivers/iio/common/hid-sensors/Kconfig
> +++ b/drivers/iio/common/hid-sensors/Kconfig
> @@ -6,7 +6,7 @@ menu "Hid Sensor IIO Common"
>  config HID_SENSOR_IIO_COMMON
>  	tristate "Common modules for all HID Sensor IIO drivers"
>  	depends on HID_SENSOR_HUB
> -	select IIO_TRIGGER if IIO_BUFFER
> +	select HID_SENSOR_IIO_TRIGGER if IIO_BUFFER
>  	help
>  	  Say yes here to build support for HID sensor to use
>  	  HID sensor common processing for attributes and IIO triggers.
> @@ -14,6 +14,17 @@ config HID_SENSOR_IIO_COMMON
>  	  HID sensor drivers, this module contains processing for those
>  	  attributes.
>  
> +config HID_SENSOR_IIO_TRIGGER
> +	tristate "Common module (trigger) for all HID Sensor IIO drivers"
> +	depends on HID_SENSOR_HUB && HID_SENSOR_IIO_COMMON
> +	select IIO_TRIGGER
> +	help
> +	  Say yes here to build trigger support for HID sensors.
> +	  Triggers will be send if all requested attributes were read.
> +
> +	  If this driver is compiled as a module, it will be named
> +	  hid-sensor-trigger.
> +
>  config HID_SENSOR_ENUM_BASE_QUIRKS
>  	tristate "ENUM base quirks for HID Sensor IIO drivers"
>  	depends on HID_SENSOR_IIO_COMMON
> diff --git a/drivers/iio/common/hid-sensors/Makefile b/drivers/iio/common/hid-sensors/Makefile
> index 1f463e0..22e7c5a 100644
> --- a/drivers/iio/common/hid-sensors/Makefile
> +++ b/drivers/iio/common/hid-sensors/Makefile
> @@ -3,4 +3,5 @@
>  #
>  
>  obj-$(CONFIG_HID_SENSOR_IIO_COMMON) += hid-sensor-iio-common.o
> -hid-sensor-iio-common-y := hid-sensor-attributes.o hid-sensor-trigger.o
> +obj-$(CONFIG_HID_SENSOR_IIO_TRIGGER) += hid-sensor-trigger.o
> +hid-sensor-iio-common-y := hid-sensor-attributes.o
> diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig
> index 21e27e2..bc9daff 100644
> --- a/drivers/iio/gyro/Kconfig
> +++ b/drivers/iio/gyro/Kconfig
> @@ -8,6 +8,7 @@ config HID_SENSOR_GYRO_3D
>  	select IIO_BUFFER
>  	select IIO_TRIGGERED_BUFFER
>  	select HID_SENSOR_IIO_COMMON
> +	select HID_SENSOR_IIO_TRIGGER
>  	tristate "HID Gyroscope 3D"
>  	help
>  	  Say yes here to build support for the HID SENSOR
> diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
> index 1763c9b..dbf80ab 100644
> --- a/drivers/iio/light/Kconfig
> +++ b/drivers/iio/light/Kconfig
> @@ -47,6 +47,7 @@ config HID_SENSOR_ALS
>  	select IIO_BUFFER
>  	select IIO_TRIGGERED_BUFFER
>  	select HID_SENSOR_IIO_COMMON
> +	select HID_SENSOR_IIO_TRIGGER
>  	tristate "HID ALS"
>  	help
>  	  Say yes here to build support for the HID SENSOR
> diff --git a/drivers/iio/magnetometer/Kconfig b/drivers/iio/magnetometer/Kconfig
> index c1f0cdd..ff11d68 100644
> --- a/drivers/iio/magnetometer/Kconfig
> +++ b/drivers/iio/magnetometer/Kconfig
> @@ -8,6 +8,7 @@ config HID_SENSOR_MAGNETOMETER_3D
>  	select IIO_BUFFER
>  	select IIO_TRIGGERED_BUFFER
>  	select HID_SENSOR_IIO_COMMON
> +	select HID_SENSOR_IIO_TRIGGER
>  	tristate "HID Magenetometer 3D"
>  	help
>  	  Say yes here to build support for the HID SENSOR
> 

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

* Re: [PATCH 2/4 RESEND] iio: Add Usage IDs for HID time sensors.
  2012-12-11 18:21                                       ` [PATCH 2/4 RESEND] iio: Add Usage IDs for HID time sensors Alexander Holler
@ 2012-12-15 11:06                                         ` Jonathan Cameron
  2012-12-15 12:41                                           ` Alexander Holler
  0 siblings, 1 reply; 66+ messages in thread
From: Jonathan Cameron @ 2012-12-15 11:06 UTC (permalink / raw)
  To: Alexander Holler
  Cc: linux-kernel, linux-iio, Lars-Peter Clausen, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton,
	Jiri Kosina

On 12/11/2012 06:21 PM, Alexander Holler wrote:
> These are Usage IDs for the attributes year, month, day,
> hour, minute and second, needed to read HID time sensors.
> 
> Signed-off-by: Alexander Holler <holler@ahsoftware.de>
This has gotten very messy to follow.  Could you resend the
patches (without the first) with Jiri cc'd as well
(as some of this is in his domain as HID maintainer).

Given this makes quite a few changes in IIO drivers I'm happy
to take the lot through the IIO tree but to do that I would
like a go ahead from Jiri + either Andrew or Alessandro
(for rtc side of things).

Alexander, you need to be careful with multi subsystem patches
like these to ensure everyone relevant is in the cc list.


> ---
>  include/linux/hid-sensor-ids.h |    9 +++++++++
>  1 files changed, 9 insertions(+), 0 deletions(-)
> 
> diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
> index ca8d7e9..3754ea9 100644
> --- a/include/linux/hid-sensor-ids.h
> +++ b/include/linux/hid-sensor-ids.h
> @@ -67,6 +67,15 @@
>  #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Y_AXIS		0x200486
>  #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Z_AXIS		0x200487
>  
> +/* Time (2000a0) */
> +#define HID_USAGE_SENSOR_TIME					0x2000a0
> +#define HID_USAGE_SENSOR_TIME_YEAR				0x200521
> +#define HID_USAGE_SENSOR_TIME_MONTH				0x200522
> +#define HID_USAGE_SENSOR_TIME_DAY				0x200523
> +#define HID_USAGE_SENSOR_TIME_HOUR				0x200525
> +#define HID_USAGE_SENSOR_TIME_MINUTE				0x200526
> +#define HID_USAGE_SENSOR_TIME_SECOND				0x200527
> +
>  /* Units */
>  #define HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED			0x00
>  #define HID_USAGE_SENSOR_UNITS_LUX				0x01
> 

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

* Re: [PATCH 1/4 v2] iio: hid-sensors: respect CONFIG_IIO_TRIGGER
  2012-12-15 10:54                                       ` [PATCH 1/4 v2] iio: hid-sensors: respect CONFIG_IIO_TRIGGER Jonathan Cameron
@ 2012-12-15 12:37                                         ` Alexander Holler
  0 siblings, 0 replies; 66+ messages in thread
From: Alexander Holler @ 2012-12-15 12:37 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: linux-kernel, linux-iio, Jonathan Cameron, Lars-Peter Clausen,
	rtc-linux, Alessandro Zummo, srinivas pandruvada, Andrew Morton

Am 15.12.2012 11:54, schrieb Jonathan Cameron:
> On 12/11/2012 06:21 PM, Alexander Holler wrote:
>> Not much to say, without that change, hid-sensor-trigger will be
>> always compiled if HID_SENSOR_IIO_COMMON is selected which fails if
>> CONFIG_IIO_TRIGGER is not set because CONFIG_IIO_CONSUMERS_PER_TRIGGER
>> will not be defined.
>>
>> Signed-off-by: Alexander Holler <holler@ahsoftware.de>
>
> Not sure what tree this was against as it is needs some fixing up for
> staging-next and currently mainline.  Ah well fixed up and added to togreg
> branch of

Should have been 3.7(-rcN).

>
> git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git
>
> Please check I haven't messed it up.

Still looks like what I have here.

Thanks,

Alexander


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

* Re: [PATCH 2/4 RESEND] iio: Add Usage IDs for HID time sensors.
  2012-12-15 11:06                                         ` Jonathan Cameron
@ 2012-12-15 12:41                                           ` Alexander Holler
  2012-12-15 12:45                                             ` [PATCH 1/4 " Alexander Holler
  0 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-15 12:41 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: linux-kernel, linux-iio, Lars-Peter Clausen, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton,
	Jiri Kosina

Am 15.12.2012 12:06, schrieb Jonathan Cameron:
> On 12/11/2012 06:21 PM, Alexander Holler wrote:
>> These are Usage IDs for the attributes year, month, day,
>> hour, minute and second, needed to read HID time sensors.
>>
>> Signed-off-by: Alexander Holler <holler@ahsoftware.de>
> This has gotten very messy to follow.  Could you resend the

I aggree. The workflow (ping-pong until a patch is almost perfect, 
without typos and style glitches and makes the maintainers eyes happy) 
is horrible and requires quite a lot goodwill and patience on every 
side. Not the stuff people like to do on a voluntarily basis.

So thanks to everyone who still follows.

The whole series (now 5 patches) follows. I mark all of them as RESEND 
to indicate that no changes were done since I've send them the last time.

> patches (without the first) with Jiri cc'd as well
> (as some of this is in his domain as HID maintainer).

Sorry, almost the whole series (5-1 = 4) follows. ;)

>
> Given this makes quite a few changes in IIO drivers I'm happy
> to take the lot through the IIO tree but to do that I would
> like a go ahead from Jiri + either Andrew or Alessandro
> (for rtc side of things).

Thanks again.

Alexander


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

* [PATCH 1/4 RESEND] iio: Add Usage IDs for HID time sensors.
  2012-12-15 12:41                                           ` Alexander Holler
@ 2012-12-15 12:45                                             ` Alexander Holler
  2012-12-15 12:45                                               ` [PATCH 2/4 RESEND] iio: merge hid-sensor-attributes.h into hid-sensor-hub.h Alexander Holler
                                                                 ` (3 more replies)
  0 siblings, 4 replies; 66+ messages in thread
From: Alexander Holler @ 2012-12-15 12:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-iio, Jonathan Cameron, Lars-Peter Clausen, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton,
	Jiri Kosina, Alexander Holler

These are Usage IDs for the attributes year, month, day,
hour, minute and second, needed to read HID time sensors.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 include/linux/hid-sensor-ids.h |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
index ca8d7e9..3754ea9 100644
--- a/include/linux/hid-sensor-ids.h
+++ b/include/linux/hid-sensor-ids.h
@@ -67,6 +67,15 @@
 #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Y_AXIS		0x200486
 #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Z_AXIS		0x200487
 
+/* Time (2000a0) */
+#define HID_USAGE_SENSOR_TIME					0x2000a0
+#define HID_USAGE_SENSOR_TIME_YEAR				0x200521
+#define HID_USAGE_SENSOR_TIME_MONTH				0x200522
+#define HID_USAGE_SENSOR_TIME_DAY				0x200523
+#define HID_USAGE_SENSOR_TIME_HOUR				0x200525
+#define HID_USAGE_SENSOR_TIME_MINUTE				0x200526
+#define HID_USAGE_SENSOR_TIME_SECOND				0x200527
+
 /* Units */
 #define HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED			0x00
 #define HID_USAGE_SENSOR_UNITS_LUX				0x01
-- 
1.7.8.6


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

* [PATCH 2/4 RESEND] iio: merge hid-sensor-attributes.h into hid-sensor-hub.h
  2012-12-15 12:45                                             ` [PATCH 1/4 " Alexander Holler
@ 2012-12-15 12:45                                               ` Alexander Holler
  2013-01-03  9:41                                                 ` Jiri Kosina
  2012-12-15 12:45                                               ` [PATCH 3/4 v5 RESEND] rtc: add rtc-driver for HID sensors of type time Alexander Holler
                                                                 ` (2 subsequent siblings)
  3 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-15 12:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-iio, Jonathan Cameron, Lars-Peter Clausen, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton,
	Jiri Kosina, Alexander Holler

The stuff in hid-sensor-attributes.h is needed by every piece which
uses hid-sensor-hub and merging it into hid-sensor-hub.h makes it accessible
from outside the iio subdirectory.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 drivers/iio/accel/hid-sensor-accel-3d.c            |    1 -
 .../iio/common/hid-sensors/hid-sensor-attributes.c |    1 -
 .../iio/common/hid-sensors/hid-sensor-attributes.h |   57 --------------------
 .../iio/common/hid-sensors/hid-sensor-trigger.c    |    1 -
 drivers/iio/gyro/hid-sensor-gyro-3d.c              |    1 -
 drivers/iio/light/hid-sensor-als.c                 |    1 -
 drivers/iio/magnetometer/hid-sensor-magn-3d.c      |    1 -
 include/linux/hid-sensor-hub.h                     |   38 +++++++++++++
 8 files changed, 38 insertions(+), 63 deletions(-)
 delete mode 100644 drivers/iio/common/hid-sensors/hid-sensor-attributes.h

diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
index 314a405..72371aa 100644
--- a/drivers/iio/accel/hid-sensor-accel-3d.c
+++ b/drivers/iio/accel/hid-sensor-accel-3d.c
@@ -28,7 +28,6 @@
 #include <linux/iio/buffer.h>
 #include <linux/iio/trigger_consumer.h>
 #include <linux/iio/triggered_buffer.h>
-#include "../common/hid-sensors/hid-sensor-attributes.h"
 #include "../common/hid-sensors/hid-sensor-trigger.h"
 
 /*Format: HID-SENSOR-usage_id_in_hex*/
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index 7537495..5873f16 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -25,7 +25,6 @@
 #include <linux/hid-sensor-hub.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
-#include "hid-sensor-attributes.h"
 
 static int pow_10(unsigned power)
 {
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.h b/drivers/iio/common/hid-sensors/hid-sensor-attributes.h
deleted file mode 100644
index a4676a0..0000000
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * HID Sensors Driver
- * Copyright (c) 2012, Intel Corporation.
- *
- * 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 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, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-#ifndef _HID_SENSORS_ATTRIBUTES_H
-#define _HID_SENSORS_ATTRIBUTES_H
-
-/* Common hid sensor iio structure */
-struct hid_sensor_iio_common {
-	struct hid_sensor_hub_device *hsdev;
-	struct platform_device *pdev;
-	unsigned usage_id;
-	bool data_ready;
-	struct hid_sensor_hub_attribute_info poll;
-	struct hid_sensor_hub_attribute_info report_state;
-	struct hid_sensor_hub_attribute_info power_state;
-	struct hid_sensor_hub_attribute_info sensitivity;
-};
-
-/*Convert from hid unit expo to regular exponent*/
-static inline int hid_sensor_convert_exponent(int unit_expo)
-{
-	if (unit_expo < 0x08)
-		return unit_expo;
-	else if (unit_expo <= 0x0f)
-		return -(0x0f-unit_expo+1);
-	else
-		return 0;
-}
-
-int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
-					u32 usage_id,
-					struct hid_sensor_iio_common *st);
-int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
-					int val1, int val2);
-int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
-					int *val1, int *val2);
-int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
-					int val1, int val2);
-int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
-					int *val1, int *val2);
-
-#endif
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
index d4b790d..b097b68 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
@@ -26,7 +26,6 @@
 #include <linux/iio/iio.h>
 #include <linux/iio/trigger.h>
 #include <linux/iio/sysfs.h>
-#include "hid-sensor-attributes.h"
 #include "hid-sensor-trigger.h"
 
 static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
index 4c56ada..b98cd70 100644
--- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
+++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
@@ -28,7 +28,6 @@
 #include <linux/iio/buffer.h>
 #include <linux/iio/trigger_consumer.h>
 #include <linux/iio/triggered_buffer.h>
-#include "../common/hid-sensors/hid-sensor-attributes.h"
 #include "../common/hid-sensors/hid-sensor-trigger.h"
 
 /*Format: HID-SENSOR-usage_id_in_hex*/
diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
index 96e3691..9610989 100644
--- a/drivers/iio/light/hid-sensor-als.c
+++ b/drivers/iio/light/hid-sensor-als.c
@@ -28,7 +28,6 @@
 #include <linux/iio/buffer.h>
 #include <linux/iio/trigger_consumer.h>
 #include <linux/iio/triggered_buffer.h>
-#include "../common/hid-sensors/hid-sensor-attributes.h"
 #include "../common/hid-sensors/hid-sensor-trigger.h"
 
 /*Format: HID-SENSOR-usage_id_in_hex*/
diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
index c4f0d27..4957430 100644
--- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
+++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
@@ -28,7 +28,6 @@
 #include <linux/iio/buffer.h>
 #include <linux/iio/trigger_consumer.h>
 #include <linux/iio/triggered_buffer.h>
-#include "../common/hid-sensors/hid-sensor-attributes.h"
 #include "../common/hid-sensors/hid-sensor-trigger.h"
 
 /*Format: HID-SENSOR-usage_id_in_hex*/
diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
index 0aa5f4c..e6265f9 100644
--- a/include/linux/hid-sensor-hub.h
+++ b/include/linux/hid-sensor-hub.h
@@ -157,4 +157,42 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
 */
 int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
 			u32 field_index, s32 *value);
+
+/* hid-sensor-attributes */
+
+/* Common hid sensor iio structure */
+struct hid_sensor_iio_common {
+	struct hid_sensor_hub_device *hsdev;
+	struct platform_device *pdev;
+	unsigned usage_id;
+	bool data_ready;
+	struct hid_sensor_hub_attribute_info poll;
+	struct hid_sensor_hub_attribute_info report_state;
+	struct hid_sensor_hub_attribute_info power_state;
+	struct hid_sensor_hub_attribute_info sensitivity;
+};
+
+/*Convert from hid unit expo to regular exponent*/
+static inline int hid_sensor_convert_exponent(int unit_expo)
+{
+	if (unit_expo < 0x08)
+		return unit_expo;
+	else if (unit_expo <= 0x0f)
+		return -(0x0f-unit_expo+1);
+	else
+		return 0;
+}
+
+int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
+					u32 usage_id,
+					struct hid_sensor_iio_common *st);
+int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
+					int val1, int val2);
+int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
+					int *val1, int *val2);
+int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
+					int val1, int val2);
+int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
+					int *val1, int *val2);
+
 #endif
-- 
1.7.8.6


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

* [PATCH 3/4 v5 RESEND] rtc: add rtc-driver for HID sensors of type time
  2012-12-15 12:45                                             ` [PATCH 1/4 " Alexander Holler
  2012-12-15 12:45                                               ` [PATCH 2/4 RESEND] iio: merge hid-sensor-attributes.h into hid-sensor-hub.h Alexander Holler
@ 2012-12-15 12:45                                               ` Alexander Holler
  2013-01-03 22:39                                                 ` Andrew Morton
  2012-12-15 12:45                                               ` [PATCH 4/4 RESEND] hid: iio: rename struct hid_sensor_iio_common to hid_sensor_common Alexander Holler
  2013-01-03  9:40                                               ` [PATCH 1/4 RESEND] iio: Add Usage IDs for HID time sensors Jiri Kosina
  3 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-15 12:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-iio, Jonathan Cameron, Lars-Peter Clausen, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton,
	Jiri Kosina, Alexander Holler

This driver makes the time from HID sensors (hubs) which are offering
such available like any other RTC does.

It is necessary that all values like year, month etc, are send as
8bit values (1 byte each) and all of them in 1 report. Also the
spec HUTRR39b doesn't define the range of the year field, we
tread it as 0 - 99 because that's what most RTCs I know about are
offering.

Currently the time can only be read. Setting the time must be done
through sending a report (or a feature). The spec currently doesn't
define how and I'm not sure if I just should define something by myself.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 drivers/rtc/Kconfig               |   16 ++
 drivers/rtc/Makefile              |    1 +
 drivers/rtc/rtc-hid-sensor-time.c |  291 +++++++++++++++++++++++++++++++++++++
 3 files changed, 308 insertions(+), 0 deletions(-)
 create mode 100644 drivers/rtc/rtc-hid-sensor-time.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 19c03ab..e0d29b5 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1144,4 +1144,20 @@ config RTC_DRV_SNVS
 	   This driver can also be built as a module, if so, the module
 	   will be called "rtc-snvs".
 
+comment "HID Sensor RTC drivers"
+
+config RTC_DRV_HID_SENSOR_TIME
+	tristate "HID Sensor Time"
+	depends on USB_HID
+	select IIO
+	select HID_SENSOR_HUB
+	select HID_SENSOR_IIO_COMMON
+	help
+	  Say yes here to build support for the HID Sensors of type Time.
+	  This drivers makes such sensors available as RTCs.
+
+	  If this driver is compiled as a module, it will be named
+	  rtc-hid-sensor-time.
+
+
 endif # RTC_CLASS
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 56297f0..9d1658a 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_RTC_DRV_EM3027)	+= rtc-em3027.o
 obj-$(CONFIG_RTC_DRV_EP93XX)	+= rtc-ep93xx.o
 obj-$(CONFIG_RTC_DRV_FM3130)	+= rtc-fm3130.o
 obj-$(CONFIG_RTC_DRV_GENERIC)	+= rtc-generic.o
+obj-$(CONFIG_RTC_DRV_HID_SENSOR_TIME) += rtc-hid-sensor-time.o
 obj-$(CONFIG_RTC_DRV_IMXDI)	+= rtc-imxdi.o
 obj-$(CONFIG_RTC_DRV_ISL1208)	+= rtc-isl1208.o
 obj-$(CONFIG_RTC_DRV_ISL12022)	+= rtc-isl12022.o
diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c
new file mode 100644
index 0000000..25cac6e
--- /dev/null
+++ b/drivers/rtc/rtc-hid-sensor-time.c
@@ -0,0 +1,291 @@
+/*
+ * HID Sensor Time Driver
+ * Copyright (c) 2012, Alexander Holler.
+ *
+ * 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 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/module.h>
+#include <linux/hid-sensor-hub.h>
+#include <linux/iio/iio.h>
+#include <linux/rtc.h>
+
+/* Format: HID-SENSOR-usage_id_in_hex */
+/* Usage ID from spec for Time: 0x2000A0 */
+#define DRIVER_NAME "HID-SENSOR-2000a0" /* must be lowercase */
+
+enum hid_time_channel {
+	CHANNEL_SCAN_INDEX_YEAR,
+	CHANNEL_SCAN_INDEX_MONTH,
+	CHANNEL_SCAN_INDEX_DAY,
+	CHANNEL_SCAN_INDEX_HOUR,
+	CHANNEL_SCAN_INDEX_MINUTE,
+	CHANNEL_SCAN_INDEX_SECOND,
+	TIME_RTC_CHANNEL_MAX,
+};
+
+struct hid_time_state {
+	struct hid_sensor_hub_callbacks callbacks;
+	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_hub_attribute_info info[TIME_RTC_CHANNEL_MAX];
+	struct rtc_time last_time;
+	spinlock_t lock_last_time;
+	struct completion comp_last_time;
+	struct rtc_time time_buf;
+	struct rtc_device *rtc;
+};
+
+static const u32 hid_time_addresses[TIME_RTC_CHANNEL_MAX] = {
+	HID_USAGE_SENSOR_TIME_YEAR,
+	HID_USAGE_SENSOR_TIME_MONTH,
+	HID_USAGE_SENSOR_TIME_DAY,
+	HID_USAGE_SENSOR_TIME_HOUR,
+	HID_USAGE_SENSOR_TIME_MINUTE,
+	HID_USAGE_SENSOR_TIME_SECOND,
+};
+
+/* Channel names for verbose error messages */
+static const char * const hid_time_channel_names[TIME_RTC_CHANNEL_MAX] = {
+	"year", "month", "day", "hour", "minute", "second",
+};
+
+/* Callback handler to send event after all samples are received and captured */
+static int hid_time_proc_event(struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id, void *priv)
+{
+	unsigned long flags;
+	struct hid_time_state *time_state = platform_get_drvdata(priv);
+
+	spin_lock_irqsave(&time_state->lock_last_time, flags);
+	time_state->last_time = time_state->time_buf;
+	spin_unlock_irqrestore(&time_state->lock_last_time, flags);
+	complete(&time_state->comp_last_time);
+	return 0;
+}
+
+static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id, size_t raw_len,
+				char *raw_data, void *priv)
+{
+	struct hid_time_state *time_state = platform_get_drvdata(priv);
+	struct rtc_time *time_buf = &time_state->time_buf;
+
+	switch (usage_id) {
+	case HID_USAGE_SENSOR_TIME_YEAR:
+		time_buf->tm_year = *(u8 *)raw_data;
+		if (time_buf->tm_year < 70)
+			/* assume we are in 1970...2069 */
+			time_buf->tm_year += 100;
+		break;
+	case HID_USAGE_SENSOR_TIME_MONTH:
+		/* sensor sending the month as 1-12, we need 0-11 */
+		time_buf->tm_mon = *(u8 *)raw_data-1;
+		break;
+	case HID_USAGE_SENSOR_TIME_DAY:
+		time_buf->tm_mday = *(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_HOUR:
+		time_buf->tm_hour = *(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_MINUTE:
+		time_buf->tm_min = *(u8 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_TIME_SECOND:
+		time_buf->tm_sec = *(u8 *)raw_data;
+		break;
+	default:
+		return -EINVAL;
+	}
+	return 0;
+}
+
+/* small helper, haven't found any other way */
+static const char *hid_time_attrib_name(u32 attrib_id)
+{
+	static const char unknown[] = "unknown";
+	unsigned i;
+
+	for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) {
+		if (hid_time_addresses[i] == attrib_id)
+			return hid_time_channel_names[i];
+	}
+	return unknown; /* should never happen */
+}
+
+static int hid_time_parse_report(struct platform_device *pdev,
+				struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id,
+				struct hid_time_state *time_state)
+{
+	int report_id, i;
+
+	for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i)
+		if (sensor_hub_input_get_attribute_info(hsdev,
+				HID_INPUT_REPORT, usage_id,
+				hid_time_addresses[i],
+				&time_state->info[i]) < 0)
+			return -EINVAL;
+	/* Check the (needed) attributes for sanity */
+	report_id = time_state->info[0].report_id;
+	if (report_id < 0) {
+		dev_err(&pdev->dev, "bad report ID!\n");
+		return -EINVAL;
+	}
+	for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) {
+		if (time_state->info[i].report_id != report_id) {
+			dev_err(&pdev->dev,
+				"not all needed attributes inside the same report!\n");
+			return -EINVAL;
+		}
+		if (time_state->info[i].size != 1) {
+			dev_err(&pdev->dev,
+				"attribute '%s' not 8 bits wide!\n",
+				hid_time_attrib_name(
+					time_state->info[i].attrib_id));
+			return -EINVAL;
+		}
+		if (time_state->info[i].units !=
+				HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED &&
+				/* allow attribute seconds with unit seconds */
+				!(time_state->info[i].attrib_id ==
+				HID_USAGE_SENSOR_TIME_SECOND &&
+				time_state->info[i].units ==
+				HID_USAGE_SENSOR_UNITS_SECOND)) {
+			dev_err(&pdev->dev,
+				"attribute '%s' hasn't a unit of type 'none'!\n",
+				hid_time_attrib_name(
+					time_state->info[i].attrib_id));
+			return -EINVAL;
+		}
+		if (time_state->info[i].unit_expo) {
+			dev_err(&pdev->dev,
+				"attribute '%s' hasn't a unit exponent of 1!\n",
+				hid_time_attrib_name(
+					time_state->info[i].attrib_id));
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+static int hid_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	unsigned long flags;
+	struct hid_time_state *time_state =
+		platform_get_drvdata(to_platform_device(dev));
+	int ret;
+
+	INIT_COMPLETION(time_state->comp_last_time);
+	/* get a report with all values through requesting one value */
+	sensor_hub_input_attr_get_raw_value(time_state->common_attributes.hsdev,
+			HID_USAGE_SENSOR_TIME, hid_time_addresses[0],
+			time_state->info[0].report_id);
+	/* wait for all values (event) */
+	ret = wait_for_completion_killable_timeout(
+			&time_state->comp_last_time, HZ*6);
+	if (ret > 0) {
+		/* no error */
+		spin_lock_irqsave(&time_state->lock_last_time, flags);
+		*tm = time_state->last_time;
+		spin_unlock_irqrestore(&time_state->lock_last_time, flags);
+		return 0;
+	}
+	if (!ret)
+		return -EIO; /* timeouted */
+	return ret; /* killed (-ERESTARTSYS) */
+}
+
+static const struct rtc_class_ops hid_time_rtc_ops = {
+	.read_time = hid_rtc_read_time,
+};
+
+static int hid_time_probe(struct platform_device *pdev)
+{
+	int ret = 0;
+	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct hid_time_state *time_state = devm_kzalloc(&pdev->dev,
+		sizeof(struct hid_time_state), GFP_KERNEL);
+
+	if (time_state == NULL)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, time_state);
+
+	init_completion(&time_state->comp_last_time);
+	time_state->common_attributes.hsdev = hsdev;
+	time_state->common_attributes.pdev = pdev;
+
+	ret = hid_sensor_parse_common_attributes(hsdev,
+				HID_USAGE_SENSOR_TIME,
+				&time_state->common_attributes);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to setup common attributes!\n");
+		return ret;
+	}
+
+	ret = hid_time_parse_report(pdev, hsdev, HID_USAGE_SENSOR_TIME,
+					time_state);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to setup attributes!\n");
+		return ret;
+	}
+
+	time_state->callbacks.send_event = hid_time_proc_event;
+	time_state->callbacks.capture_sample = hid_time_capture_sample;
+	time_state->callbacks.pdev = pdev;
+	ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_TIME,
+					&time_state->callbacks);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "register callback failed!\n");
+		return ret;
+	}
+
+	time_state->rtc = rtc_device_register("hid-sensor-time",
+				&pdev->dev, &hid_time_rtc_ops, THIS_MODULE);
+
+	if (IS_ERR(time_state->rtc)) {
+		dev_err(&pdev->dev, "rtc device register failed!\n");
+		return PTR_ERR(time_state->rtc);
+	}
+
+	return ret;
+}
+
+static int hid_time_remove(struct platform_device *pdev)
+{
+	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct hid_time_state *time_state = platform_get_drvdata(pdev);
+
+	rtc_device_unregister(time_state->rtc);
+	sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
+
+	return 0;
+}
+
+static struct platform_driver hid_time_platform_driver = {
+	.driver = {
+		.name	= DRIVER_NAME,
+		.owner	= THIS_MODULE,
+	},
+	.probe		= hid_time_probe,
+	.remove		= hid_time_remove,
+};
+module_platform_driver(hid_time_platform_driver);
+
+MODULE_DESCRIPTION("HID Sensor Time");
+MODULE_AUTHOR("Alexander Holler <holler@ahsoftware.de>");
+MODULE_LICENSE("GPL");
-- 
1.7.8.6


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

* [PATCH 4/4 RESEND] hid: iio: rename struct hid_sensor_iio_common to hid_sensor_common
  2012-12-15 12:45                                             ` [PATCH 1/4 " Alexander Holler
  2012-12-15 12:45                                               ` [PATCH 2/4 RESEND] iio: merge hid-sensor-attributes.h into hid-sensor-hub.h Alexander Holler
  2012-12-15 12:45                                               ` [PATCH 3/4 v5 RESEND] rtc: add rtc-driver for HID sensors of type time Alexander Holler
@ 2012-12-15 12:45                                               ` Alexander Holler
  2013-01-03  9:42                                                 ` Jiri Kosina
  2013-01-03  9:40                                               ` [PATCH 1/4 RESEND] iio: Add Usage IDs for HID time sensors Jiri Kosina
  3 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2012-12-15 12:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-iio, Jonathan Cameron, Lars-Peter Clausen, rtc-linux,
	Alessandro Zummo, srinivas pandruvada, Andrew Morton,
	Jiri Kosina, Alexander Holler

The structure with common attributes for hid-sensors isn't specific
to the iio-subsystem, so rename it to hid_sensor_common.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 drivers/iio/accel/hid-sensor-accel-3d.c            |    2 +-
 .../iio/common/hid-sensors/hid-sensor-attributes.c |   10 +++++-----
 .../iio/common/hid-sensors/hid-sensor-trigger.c    |    4 ++--
 .../iio/common/hid-sensors/hid-sensor-trigger.h    |    2 +-
 drivers/iio/gyro/hid-sensor-gyro-3d.c              |    2 +-
 drivers/iio/light/hid-sensor-als.c                 |    2 +-
 drivers/iio/magnetometer/hid-sensor-magn-3d.c      |    2 +-
 drivers/rtc/rtc-hid-sensor-time.c                  |    2 +-
 include/linux/hid-sensor-hub.h                     |   12 ++++++------
 9 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
index 72371aa..2133da8 100644
--- a/drivers/iio/accel/hid-sensor-accel-3d.c
+++ b/drivers/iio/accel/hid-sensor-accel-3d.c
@@ -43,7 +43,7 @@ enum accel_3d_channel {
 
 struct accel_3d_state {
 	struct hid_sensor_hub_callbacks callbacks;
-	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info accel[ACCEL_3D_CHANNEL_MAX];
 	u32 accel_val[ACCEL_3D_CHANNEL_MAX];
 };
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index 5873f16..75b5473 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -113,7 +113,7 @@ static u32 convert_to_vtf_format(int size, int exp, int val1, int val2)
 	return value;
 }
 
-int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
+int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
 				int *val1, int *val2)
 {
 	s32 value;
@@ -140,7 +140,7 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
 }
 EXPORT_SYMBOL(hid_sensor_read_samp_freq_value);
 
-int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
+int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
 				int val1, int val2)
 {
 	s32 value;
@@ -168,7 +168,7 @@ int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
 }
 EXPORT_SYMBOL(hid_sensor_write_samp_freq_value);
 
-int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
+int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
 				int *val1, int *val2)
 {
 	s32 value;
@@ -190,7 +190,7 @@ int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
 }
 EXPORT_SYMBOL(hid_sensor_read_raw_hyst_value);
 
-int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
+int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
 					int val1, int val2)
 {
 	s32 value;
@@ -211,7 +211,7 @@ EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
 
 int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 					u32 usage_id,
-					struct hid_sensor_iio_common *st)
+					struct hid_sensor_common *st)
 {
 
 	sensor_hub_input_get_attribute_info(hsdev,
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
index b097b68..58fc108 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
@@ -31,7 +31,7 @@
 static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
 						bool state)
 {
-	struct hid_sensor_iio_common *st = trig->private_data;
+	struct hid_sensor_common *st = trig->private_data;
 	int state_val;
 
 	state_val = state ? 1 : 0;
@@ -65,7 +65,7 @@ static const struct iio_trigger_ops hid_sensor_trigger_ops = {
 };
 
 int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
-				struct hid_sensor_iio_common *attrb)
+				struct hid_sensor_common *attrb)
 {
 	int ret;
 	struct iio_trigger *trig;
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
index fd98297..9a87314 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
@@ -20,7 +20,7 @@
 #define _HID_SENSOR_TRIGGER_H
 
 int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
-				struct hid_sensor_iio_common *attrb);
+				struct hid_sensor_common *attrb);
 void hid_sensor_remove_trigger(struct iio_dev *indio_dev);
 
 #endif
diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
index b98cd70..85330ad 100644
--- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
+++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
@@ -43,7 +43,7 @@ enum gyro_3d_channel {
 
 struct gyro_3d_state {
 	struct hid_sensor_hub_callbacks callbacks;
-	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info gyro[GYRO_3D_CHANNEL_MAX];
 	u32 gyro_val[GYRO_3D_CHANNEL_MAX];
 };
diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
index 9610989..051b88c 100644
--- a/drivers/iio/light/hid-sensor-als.c
+++ b/drivers/iio/light/hid-sensor-als.c
@@ -38,7 +38,7 @@
 
 struct als_state {
 	struct hid_sensor_hub_callbacks callbacks;
-	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info als_illum;
 	u32 illum;
 };
diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
index 4957430..5c59044 100644
--- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
+++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
@@ -43,7 +43,7 @@ enum magn_3d_channel {
 
 struct magn_3d_state {
 	struct hid_sensor_hub_callbacks callbacks;
-	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info magn[MAGN_3D_CHANNEL_MAX];
 	u32 magn_val[MAGN_3D_CHANNEL_MAX];
 };
diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c
index 25cac6e..0438c9e 100644
--- a/drivers/rtc/rtc-hid-sensor-time.c
+++ b/drivers/rtc/rtc-hid-sensor-time.c
@@ -39,7 +39,7 @@ enum hid_time_channel {
 
 struct hid_time_state {
 	struct hid_sensor_hub_callbacks callbacks;
-	struct hid_sensor_iio_common common_attributes;
+	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info info[TIME_RTC_CHANNEL_MAX];
 	struct rtc_time last_time;
 	spinlock_t lock_last_time;
diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
index e6265f9..ecefb73 100644
--- a/include/linux/hid-sensor-hub.h
+++ b/include/linux/hid-sensor-hub.h
@@ -161,7 +161,7 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
 /* hid-sensor-attributes */
 
 /* Common hid sensor iio structure */
-struct hid_sensor_iio_common {
+struct hid_sensor_common {
 	struct hid_sensor_hub_device *hsdev;
 	struct platform_device *pdev;
 	unsigned usage_id;
@@ -185,14 +185,14 @@ static inline int hid_sensor_convert_exponent(int unit_expo)
 
 int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 					u32 usage_id,
-					struct hid_sensor_iio_common *st);
-int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
+					struct hid_sensor_common *st);
+int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
 					int val1, int val2);
-int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
+int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
 					int *val1, int *val2);
-int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
+int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
 					int val1, int val2);
-int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
+int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
 					int *val1, int *val2);
 
 #endif
-- 
1.7.8.6


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

* Re: [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time
  2012-12-11  9:40                               ` Lars-Peter Clausen
  2012-12-11 12:39                                 ` Alexander Holler
@ 2012-12-16 22:15                                 ` Alessandro Zummo
  2012-12-17  7:38                                   ` Alexander Holler
  1 sibling, 1 reply; 66+ messages in thread
From: Alessandro Zummo @ 2012-12-16 22:15 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Jonathan Cameron, Alexander Holler, Jonathan Cameron,
	linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	srinivas pandruvada

On Tue, 11 Dec 2012 10:40:01 +0100
Lars-Peter Clausen <lars@metafoo.de> wrote:
  
> > Yes, move the header or merge into existing one as makes sense.
> > I'm not pulling this driver into the IIO tree (unless for some
> > reason Alessandro wants me to and I can't think why he would...).
> >   
> 
> Alessandro has been pretty quiet for quite some time now. Luckily Andrew
> Morton usually picks up the stuff for orphaned subsystems. So put him on Cc
> for v4.

 Still reading e-mails ;) Andrew monitors the rtc mailing list and picks up
 the patches that do not need to go in any arch's main tree, which is the suggested
 way as, with modern chipsets, the RTCs shares hw with many other drivers.
 

-- 

 Best regards,

 Alessandro Zummo,
  Tower Technologies - Torino, Italy

  http://www.towertech.it


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

* Re: [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time
  2012-12-16 22:15                                 ` [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time Alessandro Zummo
@ 2012-12-17  7:38                                   ` Alexander Holler
  0 siblings, 0 replies; 66+ messages in thread
From: Alexander Holler @ 2012-12-17  7:38 UTC (permalink / raw)
  To: Alessandro Zummo
  Cc: Lars-Peter Clausen, Jonathan Cameron, Jonathan Cameron,
	linux-kernel, linux-iio, Jonathan Cameron, rtc-linux,
	srinivas pandruvada

Am 16.12.2012 23:15, schrieb Alessandro Zummo:
> On Tue, 11 Dec 2012 10:40:01 +0100
> Lars-Peter Clausen <lars@metafoo.de> wrote:
>
>>> Yes, move the header or merge into existing one as makes sense.
>>> I'm not pulling this driver into the IIO tree (unless for some
>>> reason Alessandro wants me to and I can't think why he would...).
>>>
>>
>> Alessandro has been pretty quiet for quite some time now. Luckily Andrew
>> Morton usually picks up the stuff for orphaned subsystems. So put him on Cc
>> for v4.
>
>   Still reading e-mails ;) Andrew monitors the rtc mailing list and picks up
>   the patches that do not need to go in any arch's main tree, which is the suggested
>   way as, with modern chipsets, the RTCs shares hw with many other drivers.

Reading just the latest patch (v5) might be faster. ;)

It basically doesn't do much. On call of read_time() a so called report 
with the time values (year, month, ...) is requested from the device, 
rtc_time is filled with them, done.

Regards,

Alexander

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

* Re: [PATCH 1/4 RESEND] iio: Add Usage IDs for HID time sensors.
  2012-12-15 12:45                                             ` [PATCH 1/4 " Alexander Holler
                                                                 ` (2 preceding siblings ...)
  2012-12-15 12:45                                               ` [PATCH 4/4 RESEND] hid: iio: rename struct hid_sensor_iio_common to hid_sensor_common Alexander Holler
@ 2013-01-03  9:40                                               ` Jiri Kosina
  2013-01-06 11:51                                                 ` Jonathan Cameron
  3 siblings, 1 reply; 66+ messages in thread
From: Jiri Kosina @ 2013-01-03  9:40 UTC (permalink / raw)
  To: Alexander Holler
  Cc: linux-kernel, linux-iio, Jonathan Cameron, Lars-Peter Clausen,
	rtc-linux, Alessandro Zummo, srinivas pandruvada, Andrew Morton

On Sat, 15 Dec 2012, Alexander Holler wrote:

> These are Usage IDs for the attributes year, month, day,
> hour, minute and second, needed to read HID time sensors.
> 
> Signed-off-by: Alexander Holler <holler@ahsoftware.de>

Signed-off-by: Jiri Kosina <jkosina@suse.cz>

> ---
>  include/linux/hid-sensor-ids.h |    9 +++++++++
>  1 files changed, 9 insertions(+), 0 deletions(-)
> 
> diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
> index ca8d7e9..3754ea9 100644
> --- a/include/linux/hid-sensor-ids.h
> +++ b/include/linux/hid-sensor-ids.h
> @@ -67,6 +67,15 @@
>  #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Y_AXIS		0x200486
>  #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Z_AXIS		0x200487
>  
> +/* Time (2000a0) */
> +#define HID_USAGE_SENSOR_TIME					0x2000a0
> +#define HID_USAGE_SENSOR_TIME_YEAR				0x200521
> +#define HID_USAGE_SENSOR_TIME_MONTH				0x200522
> +#define HID_USAGE_SENSOR_TIME_DAY				0x200523
> +#define HID_USAGE_SENSOR_TIME_HOUR				0x200525
> +#define HID_USAGE_SENSOR_TIME_MINUTE				0x200526
> +#define HID_USAGE_SENSOR_TIME_SECOND				0x200527
> +
>  /* Units */
>  #define HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED			0x00
>  #define HID_USAGE_SENSOR_UNITS_LUX				0x01
> -- 
> 1.7.8.6
> 

-- 
Jiri Kosina
SUSE Labs

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

* Re: [PATCH 2/4 RESEND] iio: merge hid-sensor-attributes.h into hid-sensor-hub.h
  2012-12-15 12:45                                               ` [PATCH 2/4 RESEND] iio: merge hid-sensor-attributes.h into hid-sensor-hub.h Alexander Holler
@ 2013-01-03  9:41                                                 ` Jiri Kosina
  2013-01-06 11:50                                                   ` Jonathan Cameron
  0 siblings, 1 reply; 66+ messages in thread
From: Jiri Kosina @ 2013-01-03  9:41 UTC (permalink / raw)
  To: Alexander Holler
  Cc: linux-kernel, linux-iio, Jonathan Cameron, Lars-Peter Clausen,
	rtc-linux, Alessandro Zummo, srinivas pandruvada, Andrew Morton

On Sat, 15 Dec 2012, Alexander Holler wrote:

> The stuff in hid-sensor-attributes.h is needed by every piece which
> uses hid-sensor-hub and merging it into hid-sensor-hub.h makes it accessible
> from outside the iio subdirectory.
> 
> Signed-off-by: Alexander Holler <holler@ahsoftware.de>

Acked-by: Jiri Kosina <jkosina@suse.cz>

> ---
>  drivers/iio/accel/hid-sensor-accel-3d.c            |    1 -
>  .../iio/common/hid-sensors/hid-sensor-attributes.c |    1 -
>  .../iio/common/hid-sensors/hid-sensor-attributes.h |   57 --------------------
>  .../iio/common/hid-sensors/hid-sensor-trigger.c    |    1 -
>  drivers/iio/gyro/hid-sensor-gyro-3d.c              |    1 -
>  drivers/iio/light/hid-sensor-als.c                 |    1 -
>  drivers/iio/magnetometer/hid-sensor-magn-3d.c      |    1 -
>  include/linux/hid-sensor-hub.h                     |   38 +++++++++++++
>  8 files changed, 38 insertions(+), 63 deletions(-)
>  delete mode 100644 drivers/iio/common/hid-sensors/hid-sensor-attributes.h
> 
> diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
> index 314a405..72371aa 100644
> --- a/drivers/iio/accel/hid-sensor-accel-3d.c
> +++ b/drivers/iio/accel/hid-sensor-accel-3d.c
> @@ -28,7 +28,6 @@
>  #include <linux/iio/buffer.h>
>  #include <linux/iio/trigger_consumer.h>
>  #include <linux/iio/triggered_buffer.h>
> -#include "../common/hid-sensors/hid-sensor-attributes.h"
>  #include "../common/hid-sensors/hid-sensor-trigger.h"
>  
>  /*Format: HID-SENSOR-usage_id_in_hex*/
> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> index 7537495..5873f16 100644
> --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> @@ -25,7 +25,6 @@
>  #include <linux/hid-sensor-hub.h>
>  #include <linux/iio/iio.h>
>  #include <linux/iio/sysfs.h>
> -#include "hid-sensor-attributes.h"
>  
>  static int pow_10(unsigned power)
>  {
> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.h b/drivers/iio/common/hid-sensors/hid-sensor-attributes.h
> deleted file mode 100644
> index a4676a0..0000000
> --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.h
> +++ /dev/null
> @@ -1,57 +0,0 @@
> -/*
> - * HID Sensors Driver
> - * Copyright (c) 2012, Intel Corporation.
> - *
> - * 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 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, write to the Free Software Foundation, Inc.,
> - * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
> - *
> - */
> -#ifndef _HID_SENSORS_ATTRIBUTES_H
> -#define _HID_SENSORS_ATTRIBUTES_H
> -
> -/* Common hid sensor iio structure */
> -struct hid_sensor_iio_common {
> -	struct hid_sensor_hub_device *hsdev;
> -	struct platform_device *pdev;
> -	unsigned usage_id;
> -	bool data_ready;
> -	struct hid_sensor_hub_attribute_info poll;
> -	struct hid_sensor_hub_attribute_info report_state;
> -	struct hid_sensor_hub_attribute_info power_state;
> -	struct hid_sensor_hub_attribute_info sensitivity;
> -};
> -
> -/*Convert from hid unit expo to regular exponent*/
> -static inline int hid_sensor_convert_exponent(int unit_expo)
> -{
> -	if (unit_expo < 0x08)
> -		return unit_expo;
> -	else if (unit_expo <= 0x0f)
> -		return -(0x0f-unit_expo+1);
> -	else
> -		return 0;
> -}
> -
> -int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
> -					u32 usage_id,
> -					struct hid_sensor_iio_common *st);
> -int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
> -					int val1, int val2);
> -int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
> -					int *val1, int *val2);
> -int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
> -					int val1, int val2);
> -int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
> -					int *val1, int *val2);
> -
> -#endif
> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> index d4b790d..b097b68 100644
> --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> @@ -26,7 +26,6 @@
>  #include <linux/iio/iio.h>
>  #include <linux/iio/trigger.h>
>  #include <linux/iio/sysfs.h>
> -#include "hid-sensor-attributes.h"
>  #include "hid-sensor-trigger.h"
>  
>  static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
> diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
> index 4c56ada..b98cd70 100644
> --- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
> +++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
> @@ -28,7 +28,6 @@
>  #include <linux/iio/buffer.h>
>  #include <linux/iio/trigger_consumer.h>
>  #include <linux/iio/triggered_buffer.h>
> -#include "../common/hid-sensors/hid-sensor-attributes.h"
>  #include "../common/hid-sensors/hid-sensor-trigger.h"
>  
>  /*Format: HID-SENSOR-usage_id_in_hex*/
> diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
> index 96e3691..9610989 100644
> --- a/drivers/iio/light/hid-sensor-als.c
> +++ b/drivers/iio/light/hid-sensor-als.c
> @@ -28,7 +28,6 @@
>  #include <linux/iio/buffer.h>
>  #include <linux/iio/trigger_consumer.h>
>  #include <linux/iio/triggered_buffer.h>
> -#include "../common/hid-sensors/hid-sensor-attributes.h"
>  #include "../common/hid-sensors/hid-sensor-trigger.h"
>  
>  /*Format: HID-SENSOR-usage_id_in_hex*/
> diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
> index c4f0d27..4957430 100644
> --- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
> +++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
> @@ -28,7 +28,6 @@
>  #include <linux/iio/buffer.h>
>  #include <linux/iio/trigger_consumer.h>
>  #include <linux/iio/triggered_buffer.h>
> -#include "../common/hid-sensors/hid-sensor-attributes.h"
>  #include "../common/hid-sensors/hid-sensor-trigger.h"
>  
>  /*Format: HID-SENSOR-usage_id_in_hex*/
> diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
> index 0aa5f4c..e6265f9 100644
> --- a/include/linux/hid-sensor-hub.h
> +++ b/include/linux/hid-sensor-hub.h
> @@ -157,4 +157,42 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
>  */
>  int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
>  			u32 field_index, s32 *value);
> +
> +/* hid-sensor-attributes */
> +
> +/* Common hid sensor iio structure */
> +struct hid_sensor_iio_common {
> +	struct hid_sensor_hub_device *hsdev;
> +	struct platform_device *pdev;
> +	unsigned usage_id;
> +	bool data_ready;
> +	struct hid_sensor_hub_attribute_info poll;
> +	struct hid_sensor_hub_attribute_info report_state;
> +	struct hid_sensor_hub_attribute_info power_state;
> +	struct hid_sensor_hub_attribute_info sensitivity;
> +};
> +
> +/*Convert from hid unit expo to regular exponent*/
> +static inline int hid_sensor_convert_exponent(int unit_expo)
> +{
> +	if (unit_expo < 0x08)
> +		return unit_expo;
> +	else if (unit_expo <= 0x0f)
> +		return -(0x0f-unit_expo+1);
> +	else
> +		return 0;
> +}
> +
> +int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
> +					u32 usage_id,
> +					struct hid_sensor_iio_common *st);
> +int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
> +					int val1, int val2);
> +int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
> +					int *val1, int *val2);
> +int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
> +					int val1, int val2);
> +int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
> +					int *val1, int *val2);
> +
>  #endif
> -- 
> 1.7.8.6
> 

-- 
Jiri Kosina
SUSE Labs

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

* Re: [PATCH 4/4 RESEND] hid: iio: rename struct hid_sensor_iio_common to hid_sensor_common
  2012-12-15 12:45                                               ` [PATCH 4/4 RESEND] hid: iio: rename struct hid_sensor_iio_common to hid_sensor_common Alexander Holler
@ 2013-01-03  9:42                                                 ` Jiri Kosina
  2013-01-06 11:50                                                   ` Jonathan Cameron
  0 siblings, 1 reply; 66+ messages in thread
From: Jiri Kosina @ 2013-01-03  9:42 UTC (permalink / raw)
  To: Alexander Holler
  Cc: linux-kernel, linux-iio, Jonathan Cameron, Lars-Peter Clausen,
	rtc-linux, Alessandro Zummo, srinivas pandruvada, Andrew Morton

On Sat, 15 Dec 2012, Alexander Holler wrote:

> The structure with common attributes for hid-sensors isn't specific
> to the iio-subsystem, so rename it to hid_sensor_common.
> 
> Signed-off-by: Alexander Holler <holler@ahsoftware.de>

Acked-by: Jiri Kosina <jkosina@suse.cz>

> ---
>  drivers/iio/accel/hid-sensor-accel-3d.c            |    2 +-
>  .../iio/common/hid-sensors/hid-sensor-attributes.c |   10 +++++-----
>  .../iio/common/hid-sensors/hid-sensor-trigger.c    |    4 ++--
>  .../iio/common/hid-sensors/hid-sensor-trigger.h    |    2 +-
>  drivers/iio/gyro/hid-sensor-gyro-3d.c              |    2 +-
>  drivers/iio/light/hid-sensor-als.c                 |    2 +-
>  drivers/iio/magnetometer/hid-sensor-magn-3d.c      |    2 +-
>  drivers/rtc/rtc-hid-sensor-time.c                  |    2 +-
>  include/linux/hid-sensor-hub.h                     |   12 ++++++------
>  9 files changed, 19 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
> index 72371aa..2133da8 100644
> --- a/drivers/iio/accel/hid-sensor-accel-3d.c
> +++ b/drivers/iio/accel/hid-sensor-accel-3d.c
> @@ -43,7 +43,7 @@ enum accel_3d_channel {
>  
>  struct accel_3d_state {
>  	struct hid_sensor_hub_callbacks callbacks;
> -	struct hid_sensor_iio_common common_attributes;
> +	struct hid_sensor_common common_attributes;
>  	struct hid_sensor_hub_attribute_info accel[ACCEL_3D_CHANNEL_MAX];
>  	u32 accel_val[ACCEL_3D_CHANNEL_MAX];
>  };
> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> index 5873f16..75b5473 100644
> --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> @@ -113,7 +113,7 @@ static u32 convert_to_vtf_format(int size, int exp, int val1, int val2)
>  	return value;
>  }
>  
> -int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
> +int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
>  				int *val1, int *val2)
>  {
>  	s32 value;
> @@ -140,7 +140,7 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
>  }
>  EXPORT_SYMBOL(hid_sensor_read_samp_freq_value);
>  
> -int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
> +int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
>  				int val1, int val2)
>  {
>  	s32 value;
> @@ -168,7 +168,7 @@ int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
>  }
>  EXPORT_SYMBOL(hid_sensor_write_samp_freq_value);
>  
> -int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
> +int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
>  				int *val1, int *val2)
>  {
>  	s32 value;
> @@ -190,7 +190,7 @@ int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
>  }
>  EXPORT_SYMBOL(hid_sensor_read_raw_hyst_value);
>  
> -int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
> +int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
>  					int val1, int val2)
>  {
>  	s32 value;
> @@ -211,7 +211,7 @@ EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
>  
>  int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
>  					u32 usage_id,
> -					struct hid_sensor_iio_common *st)
> +					struct hid_sensor_common *st)
>  {
>  
>  	sensor_hub_input_get_attribute_info(hsdev,
> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> index b097b68..58fc108 100644
> --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> @@ -31,7 +31,7 @@
>  static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
>  						bool state)
>  {
> -	struct hid_sensor_iio_common *st = trig->private_data;
> +	struct hid_sensor_common *st = trig->private_data;
>  	int state_val;
>  
>  	state_val = state ? 1 : 0;
> @@ -65,7 +65,7 @@ static const struct iio_trigger_ops hid_sensor_trigger_ops = {
>  };
>  
>  int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
> -				struct hid_sensor_iio_common *attrb)
> +				struct hid_sensor_common *attrb)
>  {
>  	int ret;
>  	struct iio_trigger *trig;
> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
> index fd98297..9a87314 100644
> --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
> +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
> @@ -20,7 +20,7 @@
>  #define _HID_SENSOR_TRIGGER_H
>  
>  int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
> -				struct hid_sensor_iio_common *attrb);
> +				struct hid_sensor_common *attrb);
>  void hid_sensor_remove_trigger(struct iio_dev *indio_dev);
>  
>  #endif
> diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
> index b98cd70..85330ad 100644
> --- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
> +++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
> @@ -43,7 +43,7 @@ enum gyro_3d_channel {
>  
>  struct gyro_3d_state {
>  	struct hid_sensor_hub_callbacks callbacks;
> -	struct hid_sensor_iio_common common_attributes;
> +	struct hid_sensor_common common_attributes;
>  	struct hid_sensor_hub_attribute_info gyro[GYRO_3D_CHANNEL_MAX];
>  	u32 gyro_val[GYRO_3D_CHANNEL_MAX];
>  };
> diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
> index 9610989..051b88c 100644
> --- a/drivers/iio/light/hid-sensor-als.c
> +++ b/drivers/iio/light/hid-sensor-als.c
> @@ -38,7 +38,7 @@
>  
>  struct als_state {
>  	struct hid_sensor_hub_callbacks callbacks;
> -	struct hid_sensor_iio_common common_attributes;
> +	struct hid_sensor_common common_attributes;
>  	struct hid_sensor_hub_attribute_info als_illum;
>  	u32 illum;
>  };
> diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
> index 4957430..5c59044 100644
> --- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
> +++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
> @@ -43,7 +43,7 @@ enum magn_3d_channel {
>  
>  struct magn_3d_state {
>  	struct hid_sensor_hub_callbacks callbacks;
> -	struct hid_sensor_iio_common common_attributes;
> +	struct hid_sensor_common common_attributes;
>  	struct hid_sensor_hub_attribute_info magn[MAGN_3D_CHANNEL_MAX];
>  	u32 magn_val[MAGN_3D_CHANNEL_MAX];
>  };
> diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c
> index 25cac6e..0438c9e 100644
> --- a/drivers/rtc/rtc-hid-sensor-time.c
> +++ b/drivers/rtc/rtc-hid-sensor-time.c
> @@ -39,7 +39,7 @@ enum hid_time_channel {
>  
>  struct hid_time_state {
>  	struct hid_sensor_hub_callbacks callbacks;
> -	struct hid_sensor_iio_common common_attributes;
> +	struct hid_sensor_common common_attributes;
>  	struct hid_sensor_hub_attribute_info info[TIME_RTC_CHANNEL_MAX];
>  	struct rtc_time last_time;
>  	spinlock_t lock_last_time;
> diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
> index e6265f9..ecefb73 100644
> --- a/include/linux/hid-sensor-hub.h
> +++ b/include/linux/hid-sensor-hub.h
> @@ -161,7 +161,7 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
>  /* hid-sensor-attributes */
>  
>  /* Common hid sensor iio structure */
> -struct hid_sensor_iio_common {
> +struct hid_sensor_common {
>  	struct hid_sensor_hub_device *hsdev;
>  	struct platform_device *pdev;
>  	unsigned usage_id;
> @@ -185,14 +185,14 @@ static inline int hid_sensor_convert_exponent(int unit_expo)
>  
>  int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
>  					u32 usage_id,
> -					struct hid_sensor_iio_common *st);
> -int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
> +					struct hid_sensor_common *st);
> +int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
>  					int val1, int val2);
> -int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
> +int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
>  					int *val1, int *val2);
> -int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
> +int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
>  					int val1, int val2);
> -int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
> +int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
>  					int *val1, int *val2);
>  
>  #endif
> -- 
> 1.7.8.6
> 

-- 
Jiri Kosina
SUSE Labs

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

* Re: [PATCH 3/4 v5 RESEND] rtc: add rtc-driver for HID sensors of type time
  2012-12-15 12:45                                               ` [PATCH 3/4 v5 RESEND] rtc: add rtc-driver for HID sensors of type time Alexander Holler
@ 2013-01-03 22:39                                                 ` Andrew Morton
  2013-01-04  9:18                                                   ` Jiri Kosina
  0 siblings, 1 reply; 66+ messages in thread
From: Andrew Morton @ 2013-01-03 22:39 UTC (permalink / raw)
  To: Alexander Holler
  Cc: linux-kernel, linux-iio, Jonathan Cameron, Lars-Peter Clausen,
	rtc-linux, Alessandro Zummo, srinivas pandruvada, Jiri Kosina

On Sat, 15 Dec 2012 13:45:36 +0100
Alexander Holler <holler@ahsoftware.de> wrote:

> This driver makes the time from HID sensors (hubs) which are offering
> such available like any other RTC does.
> 
> It is necessary that all values like year, month etc, are send as
> 8bit values (1 byte each) and all of them in 1 report. Also the
> spec HUTRR39b doesn't define the range of the year field, we
> tread it as 0 - 99 because that's what most RTCs I know about are
> offering.
> 
> Currently the time can only be read. Setting the time must be done
> through sending a report (or a feature). The spec currently doesn't
> define how and I'm not sure if I just should define something by myself.
> 

Looks OK to me.  It sounds like Jonathan will be merging these patches
when he's happy with them - please do proceed that way.


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

* Re: [PATCH 3/4 v5 RESEND] rtc: add rtc-driver for HID sensors of type time
  2013-01-03 22:39                                                 ` Andrew Morton
@ 2013-01-04  9:18                                                   ` Jiri Kosina
  2013-01-04 13:10                                                     ` Alexander Holler
  0 siblings, 1 reply; 66+ messages in thread
From: Jiri Kosina @ 2013-01-04  9:18 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Alexander Holler, linux-kernel, linux-iio, Jonathan Cameron,
	Lars-Peter Clausen, rtc-linux, Alessandro Zummo,
	srinivas pandruvada

On Thu, 3 Jan 2013, Andrew Morton wrote:

> > This driver makes the time from HID sensors (hubs) which are offering
> > such available like any other RTC does.
> > 
> > It is necessary that all values like year, month etc, are send as
> > 8bit values (1 byte each) and all of them in 1 report. Also the
> > spec HUTRR39b doesn't define the range of the year field, we
> > tread it as 0 - 99 because that's what most RTCs I know about are
> > offering.
> > 
> > Currently the time can only be read. Setting the time must be done
> > through sending a report (or a feature). The spec currently doesn't
> > define how and I'm not sure if I just should define something by myself.
> > 
> 
> Looks OK to me.  It sounds like Jonathan will be merging these patches
> when he's happy with them - please do proceed that way.

Yes, fine by me as well -- that's why I have provided by explicit Acks to 
those.

Jonathan, are you taking those, please?

-- 
Jiri Kosina
SUSE Labs

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

* Re: [PATCH 3/4 v5 RESEND] rtc: add rtc-driver for HID sensors of type time
  2013-01-04  9:18                                                   ` Jiri Kosina
@ 2013-01-04 13:10                                                     ` Alexander Holler
  2013-01-06 11:50                                                       ` Jonathan Cameron
  0 siblings, 1 reply; 66+ messages in thread
From: Alexander Holler @ 2013-01-04 13:10 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: Andrew Morton, linux-kernel, linux-iio, Jonathan Cameron,
	Lars-Peter Clausen, rtc-linux, Alessandro Zummo,
	srinivas pandruvada

Am 04.01.2013 10:18, schrieb Jiri Kosina:
> On Thu, 3 Jan 2013, Andrew Morton wrote:
>
>>> This driver makes the time from HID sensors (hubs) which are offering
>>> such available like any other RTC does.

>> Looks OK to me.  It sounds like Jonathan will be merging these patches
>> when he's happy with them - please do proceed that way.
>
> Yes, fine by me as well -- that's why I have provided by explicit Acks to
> those.
>
> Jonathan, are you taking those, please?

Thanks to all.

Btw. if someone wants to build such a pluggable HID-USB-RTC using an AVR 
(Arduino Leonardo, or an ATtiny with v-usb), feel free to contact me. I 
have some working sources around and will write a website with "exact 
steps" ;) if I find the time. Currently the stuff is still in ugly 
state, but if someone needs a starting point (e.g. for the HID 
descriptors), it is already usable.

Regards,

Alexander

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

* Re: [PATCH 4/4 RESEND] hid: iio: rename struct hid_sensor_iio_common to hid_sensor_common
  2013-01-03  9:42                                                 ` Jiri Kosina
@ 2013-01-06 11:50                                                   ` Jonathan Cameron
  0 siblings, 0 replies; 66+ messages in thread
From: Jonathan Cameron @ 2013-01-06 11:50 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: Alexander Holler, linux-kernel, linux-iio, Jonathan Cameron,
	Lars-Peter Clausen, rtc-linux, Alessandro Zummo,
	srinivas pandruvada, Andrew Morton

On 01/03/2013 09:42 AM, Jiri Kosina wrote:
> On Sat, 15 Dec 2012, Alexander Holler wrote:
> 
>> The structure with common attributes for hid-sensors isn't specific
>> to the iio-subsystem, so rename it to hid_sensor_common.
>>
>> Signed-off-by: Alexander Holler <holler@ahsoftware.de>
> 
> Acked-by: Jiri Kosina <jkosina@suse.cz>
Added to togreg branch of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git

Thanks,

> 
>> ---
>>  drivers/iio/accel/hid-sensor-accel-3d.c            |    2 +-
>>  .../iio/common/hid-sensors/hid-sensor-attributes.c |   10 +++++-----
>>  .../iio/common/hid-sensors/hid-sensor-trigger.c    |    4 ++--
>>  .../iio/common/hid-sensors/hid-sensor-trigger.h    |    2 +-
>>  drivers/iio/gyro/hid-sensor-gyro-3d.c              |    2 +-
>>  drivers/iio/light/hid-sensor-als.c                 |    2 +-
>>  drivers/iio/magnetometer/hid-sensor-magn-3d.c      |    2 +-
>>  drivers/rtc/rtc-hid-sensor-time.c                  |    2 +-
>>  include/linux/hid-sensor-hub.h                     |   12 ++++++------
>>  9 files changed, 19 insertions(+), 19 deletions(-)
>>
>> diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
>> index 72371aa..2133da8 100644
>> --- a/drivers/iio/accel/hid-sensor-accel-3d.c
>> +++ b/drivers/iio/accel/hid-sensor-accel-3d.c
>> @@ -43,7 +43,7 @@ enum accel_3d_channel {
>>  
>>  struct accel_3d_state {
>>  	struct hid_sensor_hub_callbacks callbacks;
>> -	struct hid_sensor_iio_common common_attributes;
>> +	struct hid_sensor_common common_attributes;
>>  	struct hid_sensor_hub_attribute_info accel[ACCEL_3D_CHANNEL_MAX];
>>  	u32 accel_val[ACCEL_3D_CHANNEL_MAX];
>>  };
>> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>> index 5873f16..75b5473 100644
>> --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>> +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>> @@ -113,7 +113,7 @@ static u32 convert_to_vtf_format(int size, int exp, int val1, int val2)
>>  	return value;
>>  }
>>  
>> -int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
>> +int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
>>  				int *val1, int *val2)
>>  {
>>  	s32 value;
>> @@ -140,7 +140,7 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
>>  }
>>  EXPORT_SYMBOL(hid_sensor_read_samp_freq_value);
>>  
>> -int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
>> +int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
>>  				int val1, int val2)
>>  {
>>  	s32 value;
>> @@ -168,7 +168,7 @@ int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
>>  }
>>  EXPORT_SYMBOL(hid_sensor_write_samp_freq_value);
>>  
>> -int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
>> +int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
>>  				int *val1, int *val2)
>>  {
>>  	s32 value;
>> @@ -190,7 +190,7 @@ int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
>>  }
>>  EXPORT_SYMBOL(hid_sensor_read_raw_hyst_value);
>>  
>> -int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
>> +int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
>>  					int val1, int val2)
>>  {
>>  	s32 value;
>> @@ -211,7 +211,7 @@ EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
>>  
>>  int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
>>  					u32 usage_id,
>> -					struct hid_sensor_iio_common *st)
>> +					struct hid_sensor_common *st)
>>  {
>>  
>>  	sensor_hub_input_get_attribute_info(hsdev,
>> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
>> index b097b68..58fc108 100644
>> --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
>> +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
>> @@ -31,7 +31,7 @@
>>  static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
>>  						bool state)
>>  {
>> -	struct hid_sensor_iio_common *st = trig->private_data;
>> +	struct hid_sensor_common *st = trig->private_data;
>>  	int state_val;
>>  
>>  	state_val = state ? 1 : 0;
>> @@ -65,7 +65,7 @@ static const struct iio_trigger_ops hid_sensor_trigger_ops = {
>>  };
>>  
>>  int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
>> -				struct hid_sensor_iio_common *attrb)
>> +				struct hid_sensor_common *attrb)
>>  {
>>  	int ret;
>>  	struct iio_trigger *trig;
>> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
>> index fd98297..9a87314 100644
>> --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
>> +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
>> @@ -20,7 +20,7 @@
>>  #define _HID_SENSOR_TRIGGER_H
>>  
>>  int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
>> -				struct hid_sensor_iio_common *attrb);
>> +				struct hid_sensor_common *attrb);
>>  void hid_sensor_remove_trigger(struct iio_dev *indio_dev);
>>  
>>  #endif
>> diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
>> index b98cd70..85330ad 100644
>> --- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
>> +++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
>> @@ -43,7 +43,7 @@ enum gyro_3d_channel {
>>  
>>  struct gyro_3d_state {
>>  	struct hid_sensor_hub_callbacks callbacks;
>> -	struct hid_sensor_iio_common common_attributes;
>> +	struct hid_sensor_common common_attributes;
>>  	struct hid_sensor_hub_attribute_info gyro[GYRO_3D_CHANNEL_MAX];
>>  	u32 gyro_val[GYRO_3D_CHANNEL_MAX];
>>  };
>> diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
>> index 9610989..051b88c 100644
>> --- a/drivers/iio/light/hid-sensor-als.c
>> +++ b/drivers/iio/light/hid-sensor-als.c
>> @@ -38,7 +38,7 @@
>>  
>>  struct als_state {
>>  	struct hid_sensor_hub_callbacks callbacks;
>> -	struct hid_sensor_iio_common common_attributes;
>> +	struct hid_sensor_common common_attributes;
>>  	struct hid_sensor_hub_attribute_info als_illum;
>>  	u32 illum;
>>  };
>> diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
>> index 4957430..5c59044 100644
>> --- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
>> +++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
>> @@ -43,7 +43,7 @@ enum magn_3d_channel {
>>  
>>  struct magn_3d_state {
>>  	struct hid_sensor_hub_callbacks callbacks;
>> -	struct hid_sensor_iio_common common_attributes;
>> +	struct hid_sensor_common common_attributes;
>>  	struct hid_sensor_hub_attribute_info magn[MAGN_3D_CHANNEL_MAX];
>>  	u32 magn_val[MAGN_3D_CHANNEL_MAX];
>>  };
>> diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c
>> index 25cac6e..0438c9e 100644
>> --- a/drivers/rtc/rtc-hid-sensor-time.c
>> +++ b/drivers/rtc/rtc-hid-sensor-time.c
>> @@ -39,7 +39,7 @@ enum hid_time_channel {
>>  
>>  struct hid_time_state {
>>  	struct hid_sensor_hub_callbacks callbacks;
>> -	struct hid_sensor_iio_common common_attributes;
>> +	struct hid_sensor_common common_attributes;
>>  	struct hid_sensor_hub_attribute_info info[TIME_RTC_CHANNEL_MAX];
>>  	struct rtc_time last_time;
>>  	spinlock_t lock_last_time;
>> diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
>> index e6265f9..ecefb73 100644
>> --- a/include/linux/hid-sensor-hub.h
>> +++ b/include/linux/hid-sensor-hub.h
>> @@ -161,7 +161,7 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
>>  /* hid-sensor-attributes */
>>  
>>  /* Common hid sensor iio structure */
>> -struct hid_sensor_iio_common {
>> +struct hid_sensor_common {
>>  	struct hid_sensor_hub_device *hsdev;
>>  	struct platform_device *pdev;
>>  	unsigned usage_id;
>> @@ -185,14 +185,14 @@ static inline int hid_sensor_convert_exponent(int unit_expo)
>>  
>>  int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
>>  					u32 usage_id,
>> -					struct hid_sensor_iio_common *st);
>> -int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
>> +					struct hid_sensor_common *st);
>> +int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
>>  					int val1, int val2);
>> -int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
>> +int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
>>  					int *val1, int *val2);
>> -int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
>> +int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
>>  					int val1, int val2);
>> -int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
>> +int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
>>  					int *val1, int *val2);
>>  
>>  #endif
>> -- 
>> 1.7.8.6
>>
> 

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

* Re: [PATCH 3/4 v5 RESEND] rtc: add rtc-driver for HID sensors of type time
  2013-01-04 13:10                                                     ` Alexander Holler
@ 2013-01-06 11:50                                                       ` Jonathan Cameron
  0 siblings, 0 replies; 66+ messages in thread
From: Jonathan Cameron @ 2013-01-06 11:50 UTC (permalink / raw)
  To: Alexander Holler
  Cc: Jiri Kosina, Andrew Morton, linux-kernel, linux-iio,
	Jonathan Cameron, Lars-Peter Clausen, rtc-linux,
	Alessandro Zummo, srinivas pandruvada

On 01/04/2013 01:10 PM, Alexander Holler wrote:
> Am 04.01.2013 10:18, schrieb Jiri Kosina:
>> On Thu, 3 Jan 2013, Andrew Morton wrote:
>>
>>>> This driver makes the time from HID sensors (hubs) which are offering
>>>> such available like any other RTC does.
> 
>>> Looks OK to me.  It sounds like Jonathan will be merging these patches
>>> when he's happy with them - please do proceed that way.
>>
>> Yes, fine by me as well -- that's why I have provided by explicit Acks to
>> those.
>>
>> Jonathan, are you taking those, please?
> 
Added to togreg branch of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git

Thanks all,

> Thanks to all.
> 
> Btw. if someone wants to build such a pluggable HID-USB-RTC using an AVR (Arduino Leonardo, or an ATtiny with v-usb),
> feel free to contact me. I have some working sources around and will write a website with "exact steps" ;) if I find the
> time. Currently the stuff is still in ugly state, but if someone needs a starting point (e.g. for the HID descriptors),
> it is already usable.
> 
> Regards,
> 
> Alexander
> -- 
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 2/4 RESEND] iio: merge hid-sensor-attributes.h into hid-sensor-hub.h
  2013-01-03  9:41                                                 ` Jiri Kosina
@ 2013-01-06 11:50                                                   ` Jonathan Cameron
  0 siblings, 0 replies; 66+ messages in thread
From: Jonathan Cameron @ 2013-01-06 11:50 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: Alexander Holler, linux-kernel, linux-iio, Jonathan Cameron,
	Lars-Peter Clausen, rtc-linux, Alessandro Zummo,
	srinivas pandruvada, Andrew Morton

On 01/03/2013 09:41 AM, Jiri Kosina wrote:
> On Sat, 15 Dec 2012, Alexander Holler wrote:
> 
>> The stuff in hid-sensor-attributes.h is needed by every piece which
>> uses hid-sensor-hub and merging it into hid-sensor-hub.h makes it accessible
>> from outside the iio subdirectory.
>>
>> Signed-off-by: Alexander Holler <holler@ahsoftware.de>
> 
> Acked-by: Jiri Kosina <jkosina@suse.cz>
Added to togreg branch of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git

Thanks,

> 
>> ---
>>  drivers/iio/accel/hid-sensor-accel-3d.c            |    1 -
>>  .../iio/common/hid-sensors/hid-sensor-attributes.c |    1 -
>>  .../iio/common/hid-sensors/hid-sensor-attributes.h |   57 --------------------
>>  .../iio/common/hid-sensors/hid-sensor-trigger.c    |    1 -
>>  drivers/iio/gyro/hid-sensor-gyro-3d.c              |    1 -
>>  drivers/iio/light/hid-sensor-als.c                 |    1 -
>>  drivers/iio/magnetometer/hid-sensor-magn-3d.c      |    1 -
>>  include/linux/hid-sensor-hub.h                     |   38 +++++++++++++
>>  8 files changed, 38 insertions(+), 63 deletions(-)
>>  delete mode 100644 drivers/iio/common/hid-sensors/hid-sensor-attributes.h
>>
>> diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
>> index 314a405..72371aa 100644
>> --- a/drivers/iio/accel/hid-sensor-accel-3d.c
>> +++ b/drivers/iio/accel/hid-sensor-accel-3d.c
>> @@ -28,7 +28,6 @@
>>  #include <linux/iio/buffer.h>
>>  #include <linux/iio/trigger_consumer.h>
>>  #include <linux/iio/triggered_buffer.h>
>> -#include "../common/hid-sensors/hid-sensor-attributes.h"
>>  #include "../common/hid-sensors/hid-sensor-trigger.h"
>>  
>>  /*Format: HID-SENSOR-usage_id_in_hex*/
>> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>> index 7537495..5873f16 100644
>> --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>> +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>> @@ -25,7 +25,6 @@
>>  #include <linux/hid-sensor-hub.h>
>>  #include <linux/iio/iio.h>
>>  #include <linux/iio/sysfs.h>
>> -#include "hid-sensor-attributes.h"
>>  
>>  static int pow_10(unsigned power)
>>  {
>> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.h b/drivers/iio/common/hid-sensors/hid-sensor-attributes.h
>> deleted file mode 100644
>> index a4676a0..0000000
>> --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.h
>> +++ /dev/null
>> @@ -1,57 +0,0 @@
>> -/*
>> - * HID Sensors Driver
>> - * Copyright (c) 2012, Intel Corporation.
>> - *
>> - * 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 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, write to the Free Software Foundation, Inc.,
>> - * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
>> - *
>> - */
>> -#ifndef _HID_SENSORS_ATTRIBUTES_H
>> -#define _HID_SENSORS_ATTRIBUTES_H
>> -
>> -/* Common hid sensor iio structure */
>> -struct hid_sensor_iio_common {
>> -	struct hid_sensor_hub_device *hsdev;
>> -	struct platform_device *pdev;
>> -	unsigned usage_id;
>> -	bool data_ready;
>> -	struct hid_sensor_hub_attribute_info poll;
>> -	struct hid_sensor_hub_attribute_info report_state;
>> -	struct hid_sensor_hub_attribute_info power_state;
>> -	struct hid_sensor_hub_attribute_info sensitivity;
>> -};
>> -
>> -/*Convert from hid unit expo to regular exponent*/
>> -static inline int hid_sensor_convert_exponent(int unit_expo)
>> -{
>> -	if (unit_expo < 0x08)
>> -		return unit_expo;
>> -	else if (unit_expo <= 0x0f)
>> -		return -(0x0f-unit_expo+1);
>> -	else
>> -		return 0;
>> -}
>> -
>> -int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
>> -					u32 usage_id,
>> -					struct hid_sensor_iio_common *st);
>> -int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
>> -					int val1, int val2);
>> -int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
>> -					int *val1, int *val2);
>> -int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
>> -					int val1, int val2);
>> -int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
>> -					int *val1, int *val2);
>> -
>> -#endif
>> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
>> index d4b790d..b097b68 100644
>> --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
>> +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
>> @@ -26,7 +26,6 @@
>>  #include <linux/iio/iio.h>
>>  #include <linux/iio/trigger.h>
>>  #include <linux/iio/sysfs.h>
>> -#include "hid-sensor-attributes.h"
>>  #include "hid-sensor-trigger.h"
>>  
>>  static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
>> diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
>> index 4c56ada..b98cd70 100644
>> --- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
>> +++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
>> @@ -28,7 +28,6 @@
>>  #include <linux/iio/buffer.h>
>>  #include <linux/iio/trigger_consumer.h>
>>  #include <linux/iio/triggered_buffer.h>
>> -#include "../common/hid-sensors/hid-sensor-attributes.h"
>>  #include "../common/hid-sensors/hid-sensor-trigger.h"
>>  
>>  /*Format: HID-SENSOR-usage_id_in_hex*/
>> diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
>> index 96e3691..9610989 100644
>> --- a/drivers/iio/light/hid-sensor-als.c
>> +++ b/drivers/iio/light/hid-sensor-als.c
>> @@ -28,7 +28,6 @@
>>  #include <linux/iio/buffer.h>
>>  #include <linux/iio/trigger_consumer.h>
>>  #include <linux/iio/triggered_buffer.h>
>> -#include "../common/hid-sensors/hid-sensor-attributes.h"
>>  #include "../common/hid-sensors/hid-sensor-trigger.h"
>>  
>>  /*Format: HID-SENSOR-usage_id_in_hex*/
>> diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
>> index c4f0d27..4957430 100644
>> --- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
>> +++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
>> @@ -28,7 +28,6 @@
>>  #include <linux/iio/buffer.h>
>>  #include <linux/iio/trigger_consumer.h>
>>  #include <linux/iio/triggered_buffer.h>
>> -#include "../common/hid-sensors/hid-sensor-attributes.h"
>>  #include "../common/hid-sensors/hid-sensor-trigger.h"
>>  
>>  /*Format: HID-SENSOR-usage_id_in_hex*/
>> diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
>> index 0aa5f4c..e6265f9 100644
>> --- a/include/linux/hid-sensor-hub.h
>> +++ b/include/linux/hid-sensor-hub.h
>> @@ -157,4 +157,42 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
>>  */
>>  int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
>>  			u32 field_index, s32 *value);
>> +
>> +/* hid-sensor-attributes */
>> +
>> +/* Common hid sensor iio structure */
>> +struct hid_sensor_iio_common {
>> +	struct hid_sensor_hub_device *hsdev;
>> +	struct platform_device *pdev;
>> +	unsigned usage_id;
>> +	bool data_ready;
>> +	struct hid_sensor_hub_attribute_info poll;
>> +	struct hid_sensor_hub_attribute_info report_state;
>> +	struct hid_sensor_hub_attribute_info power_state;
>> +	struct hid_sensor_hub_attribute_info sensitivity;
>> +};
>> +
>> +/*Convert from hid unit expo to regular exponent*/
>> +static inline int hid_sensor_convert_exponent(int unit_expo)
>> +{
>> +	if (unit_expo < 0x08)
>> +		return unit_expo;
>> +	else if (unit_expo <= 0x0f)
>> +		return -(0x0f-unit_expo+1);
>> +	else
>> +		return 0;
>> +}
>> +
>> +int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
>> +					u32 usage_id,
>> +					struct hid_sensor_iio_common *st);
>> +int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
>> +					int val1, int val2);
>> +int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
>> +					int *val1, int *val2);
>> +int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
>> +					int val1, int val2);
>> +int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
>> +					int *val1, int *val2);
>> +
>>  #endif
>> -- 
>> 1.7.8.6
>>
> 

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

* Re: [PATCH 1/4 RESEND] iio: Add Usage IDs for HID time sensors.
  2013-01-03  9:40                                               ` [PATCH 1/4 RESEND] iio: Add Usage IDs for HID time sensors Jiri Kosina
@ 2013-01-06 11:51                                                 ` Jonathan Cameron
  0 siblings, 0 replies; 66+ messages in thread
From: Jonathan Cameron @ 2013-01-06 11:51 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: Alexander Holler, linux-kernel, linux-iio, Jonathan Cameron,
	Lars-Peter Clausen, rtc-linux, Alessandro Zummo,
	srinivas pandruvada, Andrew Morton

On 01/03/2013 09:40 AM, Jiri Kosina wrote:
> On Sat, 15 Dec 2012, Alexander Holler wrote:
> 
>> These are Usage IDs for the attributes year, month, day,
>> hour, minute and second, needed to read HID time sensors.
>>
>> Signed-off-by: Alexander Holler <holler@ahsoftware.de>
> 
> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Added to togreg branch of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git

Thanks,

> 
>> ---
>>  include/linux/hid-sensor-ids.h |    9 +++++++++
>>  1 files changed, 9 insertions(+), 0 deletions(-)
>>
>> diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
>> index ca8d7e9..3754ea9 100644
>> --- a/include/linux/hid-sensor-ids.h
>> +++ b/include/linux/hid-sensor-ids.h
>> @@ -67,6 +67,15 @@
>>  #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Y_AXIS		0x200486
>>  #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Z_AXIS		0x200487
>>  
>> +/* Time (2000a0) */
>> +#define HID_USAGE_SENSOR_TIME					0x2000a0
>> +#define HID_USAGE_SENSOR_TIME_YEAR				0x200521
>> +#define HID_USAGE_SENSOR_TIME_MONTH				0x200522
>> +#define HID_USAGE_SENSOR_TIME_DAY				0x200523
>> +#define HID_USAGE_SENSOR_TIME_HOUR				0x200525
>> +#define HID_USAGE_SENSOR_TIME_MINUTE				0x200526
>> +#define HID_USAGE_SENSOR_TIME_SECOND				0x200527
>> +
>>  /* Units */
>>  #define HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED			0x00
>>  #define HID_USAGE_SENSOR_UNITS_LUX				0x01
>> -- 
>> 1.7.8.6
>>
> 

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

end of thread, other threads:[~2013-01-06 11:51 UTC | newest]

Thread overview: 66+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-09 12:21 [PATCH 0/3] iio: HID sensor time (as RTC) Alexander Holler
2012-12-09 12:21 ` [PATCH 1/3] iio: hid-sensors: respect CONFIG_IIO_TRIGGER Alexander Holler
2012-12-09 12:21 ` [PATCH 2/3] iio: Add Usage IDs for HID time sensors Alexander Holler
2012-12-09 12:21 ` [PATCH 3/3] iio: add rtc-driver for HID sensors of type time Alexander Holler
2012-12-09 12:55   ` Lars-Peter Clausen
2012-12-09 16:40     ` Alexander Holler
2012-12-09 18:16       ` Alexander Holler
2012-12-09 19:20         ` Lars-Peter Clausen
2012-12-10 13:12           ` Alexander Holler
2012-12-10 14:51             ` [PATCH 3/3 v2] " Alexander Holler
2012-12-10 17:05               ` Lars-Peter Clausen
2012-12-10 19:45                 ` Alexander Holler
2012-12-10 20:22                   ` Lars-Peter Clausen
2012-12-10 21:26                     ` Alexander Holler
2012-12-10 21:39                       ` Lars-Peter Clausen
2012-12-10 21:42                         ` Jonathan Cameron
2012-12-10 22:50                           ` Alexander Holler
2012-12-11  9:31                             ` Jonathan Cameron
2012-12-11  9:40                               ` Lars-Peter Clausen
2012-12-11 12:39                                 ` Alexander Holler
2012-12-11 13:54                                   ` Jonathan Cameron
2012-12-11 18:21                                     ` [PATCH 1/4 v2] iio: hid-sensors: respect CONFIG_IIO_TRIGGER Alexander Holler
2012-12-11 18:21                                       ` [PATCH 2/4 RESEND] iio: Add Usage IDs for HID time sensors Alexander Holler
2012-12-15 11:06                                         ` Jonathan Cameron
2012-12-15 12:41                                           ` Alexander Holler
2012-12-15 12:45                                             ` [PATCH 1/4 " Alexander Holler
2012-12-15 12:45                                               ` [PATCH 2/4 RESEND] iio: merge hid-sensor-attributes.h into hid-sensor-hub.h Alexander Holler
2013-01-03  9:41                                                 ` Jiri Kosina
2013-01-06 11:50                                                   ` Jonathan Cameron
2012-12-15 12:45                                               ` [PATCH 3/4 v5 RESEND] rtc: add rtc-driver for HID sensors of type time Alexander Holler
2013-01-03 22:39                                                 ` Andrew Morton
2013-01-04  9:18                                                   ` Jiri Kosina
2013-01-04 13:10                                                     ` Alexander Holler
2013-01-06 11:50                                                       ` Jonathan Cameron
2012-12-15 12:45                                               ` [PATCH 4/4 RESEND] hid: iio: rename struct hid_sensor_iio_common to hid_sensor_common Alexander Holler
2013-01-03  9:42                                                 ` Jiri Kosina
2013-01-06 11:50                                                   ` Jonathan Cameron
2013-01-03  9:40                                               ` [PATCH 1/4 RESEND] iio: Add Usage IDs for HID time sensors Jiri Kosina
2013-01-06 11:51                                                 ` Jonathan Cameron
2012-12-11 18:21                                       ` [PATCH 3/4] iio: merge hid-sensor-attributes.h into hid-sensor-hub.h Alexander Holler
2012-12-12 15:45                                         ` Pandruvada, Srinivas
2012-12-12 20:10                                           ` Alexander Holler
2012-12-12 20:28                                             ` [PATCHi 5/4] hid: iio: rename struct hid_sensor_iio_common to hid_sensor_common Alexander Holler
2012-12-12 21:04                                               ` Pandruvada, Srinivas
2012-12-11 18:21                                       ` [PATCH 4/4 v3] rtc: add rtc-driver for HID sensors of type time Alexander Holler
2012-12-12  9:51                                         ` Lars-Peter Clausen
2012-12-12 10:14                                           ` Alexander Holler
2012-12-12 10:18                                             ` Lars-Peter Clausen
2012-12-12 11:11                                             ` [PATCH 4/4 v4] " Alexander Holler
2012-12-14  9:42                                               ` Lars-Peter Clausen
2012-12-14 13:08                                                 ` Alexander Holler
2012-12-14 14:15                                                   ` Alexander Holler
2012-12-14 14:29                                                     ` Alexander Holler
2012-12-14 14:34                                                       ` Lars-Peter Clausen
2012-12-14 15:24                                                         ` Alexander Holler
2012-12-14 16:33                                                           ` Lars-Peter Clausen
2012-12-14 21:24                                                             ` Alexander Holler
2012-12-14 22:02                                                               ` [PATCH 4/4 v5] " Alexander Holler
2012-12-15 10:54                                       ` [PATCH 1/4 v2] iio: hid-sensors: respect CONFIG_IIO_TRIGGER Jonathan Cameron
2012-12-15 12:37                                         ` Alexander Holler
2012-12-16 22:15                                 ` [PATCH 3/3 v2] iio: add rtc-driver for HID sensors of type time Alessandro Zummo
2012-12-17  7:38                                   ` Alexander Holler
2012-12-10 22:20                 ` Alexander Holler
2012-12-10 22:36                   ` Lars-Peter Clausen
2012-12-11  0:01                     ` Alexander Holler
2012-12-11 10:35                       ` Alan Cox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).