Re: [PATCH 4/4 v3] rtc: add rtc-driver for HID sensors of type time

2012-12-12 Thread Lars-Peter Clausen
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...
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 4/4 v3] rtc: add rtc-driver for HID sensors of type time

2012-12-12 Thread Alexander Holler

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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 4/4 v3] rtc: add rtc-driver for HID sensors of type time

2012-12-12 Thread Lars-Peter Clausen
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 

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 000..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(_state->lock_last_time, flags);
> + time_state->last_time = time_state->time_buf;
> + spin_unlock_irqrestore(_state->lock_last_time, flags);
> + complete(_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 = _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,
> + 

Re: [PATCH 4/4 v3] rtc: add rtc-driver for HID sensors of type time

2012-12-12 Thread Lars-Peter Clausen
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 hol...@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 000..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

 +

Re: [PATCH 4/4 v3] rtc: add rtc-driver for HID sensors of type time

2012-12-12 Thread Alexander Holler

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

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 4/4 v3] rtc: add rtc-driver for HID sensors of type time

2012-12-12 Thread Lars-Peter Clausen
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...
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 4/4 v3] rtc: add rtc-driver for HID sensors of type time

2012-12-11 Thread 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 
---
 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 000..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 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* 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(_state->lock_last_time, flags);
+   time_state->last_time = time_state->time_buf;
+   

[PATCH 4/4 v3] rtc: add rtc-driver for HID sensors of type time

2012-12-11 Thread 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 hol...@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 000..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);