From: Alexander Holler <holler@ahsoftware.de>
To: linux-kernel@vger.kernel.org
Cc: rtc-linux@googlegroups.com,
Andrew Morton <akpm@linux-foundation.org>,
Alessandro Zummo <a.zummo@towertech.it>,
Lars-Peter Clausen <lars@metafoo.de>,
Jonathan Cameron <jic23@cam.ac.uk>, Jiri Kosina <jkosina@suse.cz>,
John Stultz <john.stultz@linaro.org>,
Alexander Holler <holler@ahsoftware.de>
Subject: [PATCH 4/4] rtc: rtc-hid-sensor-time: add support for milliseconds
Date: Sun, 5 May 2013 13:21:27 +0200 [thread overview]
Message-ID: <1367752887-2927-5-git-send-email-holler@ahsoftware.de> (raw)
In-Reply-To: <1367752887-2927-1-git-send-email-holler@ahsoftware.de>
If a device sends milliseconds too, the driver will use them if it sets
the system clock at startup (through module option hctosys).
Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
drivers/rtc/rtc-hid-sensor-time.c | 37 +++++++++++++++++++++++++++++++++----
include/linux/hid-sensor-ids.h | 1 +
2 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c
index db8503a..4aca12d 100644
--- a/drivers/rtc/rtc-hid-sensor-time.c
+++ b/drivers/rtc/rtc-hid-sensor-time.c
@@ -40,6 +40,7 @@ enum hid_time_channel {
CHANNEL_SCAN_INDEX_HOUR,
CHANNEL_SCAN_INDEX_MINUTE,
CHANNEL_SCAN_INDEX_SECOND,
+ CHANNEL_SCAN_INDEX_MILLISECOND, /* optional */
TIME_RTC_CHANNEL_MAX,
};
@@ -53,9 +54,11 @@ struct hid_time_state {
struct hid_sensor_common common_attributes;
struct hid_sensor_hub_attribute_info info[TIME_RTC_CHANNEL_MAX];
struct rtc_time last_time;
+ unsigned last_ms; /* == UINT_MAX to indicate ms aren't supported */
spinlock_t lock_last_time;
struct completion comp_last_time;
struct rtc_time time_buf;
+ unsigned ms_buf;
struct rtc_device *rtc;
struct hid_time_workts *workts;
};
@@ -67,16 +70,18 @@ static const u32 hid_time_addresses[TIME_RTC_CHANNEL_MAX] = {
HID_USAGE_SENSOR_TIME_HOUR,
HID_USAGE_SENSOR_TIME_MINUTE,
HID_USAGE_SENSOR_TIME_SECOND,
+ HID_USAGE_SENSOR_TIME_MILLISECOND, /* optional */
};
/* Channel names for verbose error messages */
static const char * const hid_time_channel_names[TIME_RTC_CHANNEL_MAX] = {
- "year", "month", "day", "hour", "minute", "second",
+ "year", "month", "day", "hour", "minute", "second", "millisecond",
};
static void hid_time_hctosys(struct hid_time_state *time_state)
{
struct timespec ts;
+ char msbuf[5];
int rc = rtc_valid_tm(&time_state->last_time);
if (rc) {
@@ -102,18 +107,25 @@ static void hid_time_hctosys(struct hid_time_state *time_state)
*/
return;
- ts.tv_nsec = NSEC_PER_SEC >> 1;
+ if (time_state->last_ms != UINT_MAX) {
+ ts.tv_nsec = time_state->last_ms * NSEC_PER_MSEC;
+ snprintf(msbuf, sizeof(msbuf), ":%03d", time_state->last_ms);
+ } else {
+ ts.tv_nsec = NSEC_PER_SEC >> 1;
+ *msbuf = 0;
+ }
rtc_tm_to_time(&time_state->last_time, &ts.tv_sec);
rc = do_settimeofday(&ts);
dev_info(time_state->rtc->dev.parent,
"hctosys: setting system clock to "
- "%d-%02d-%02d %02d:%02d:%02d UTC (%u)\n",
+ "%d-%02d-%02d %02d:%02d:%02d%s UTC (%u)\n",
time_state->last_time.tm_year + 1900,
time_state->last_time.tm_mon + 1,
time_state->last_time.tm_mday,
time_state->last_time.tm_hour,
time_state->last_time.tm_min,
time_state->last_time.tm_sec,
+ msbuf,
(unsigned int) ts.tv_sec);
}
@@ -126,6 +138,8 @@ static int hid_time_proc_event(struct hid_sensor_hub_device *hsdev,
spin_lock_irqsave(&time_state->lock_last_time, flags);
time_state->last_time = time_state->time_buf;
+ if (time_state->last_ms != UINT_MAX)
+ time_state->last_ms = time_state->ms_buf;
spin_unlock_irqrestore(&time_state->lock_last_time, flags);
complete(&time_state->comp_last_time);
if (unlikely(!hid_time_time_set_once && hid_time_hctosys_enabled)) {
@@ -188,6 +202,9 @@ static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev,
case HID_USAGE_SENSOR_TIME_SECOND:
time_buf->tm_sec = (int)hid_time_value(raw_len, raw_data);
break;
+ case HID_USAGE_SENSOR_TIME_MILLISECOND:
+ time_state->ms_buf = hid_time_value(raw_len, raw_data);
+ break;
default:
return -EINVAL;
}
@@ -214,12 +231,18 @@ static int hid_time_parse_report(struct platform_device *pdev,
{
int report_id, i;
- for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i)
+ /* Check if all required attributes are available */
+ for (i = 0; i < CHANNEL_SCAN_INDEX_MILLISECOND; ++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;
+ if (!sensor_hub_input_get_attribute_info(hsdev, HID_INPUT_REPORT,
+ usage_id, hid_time_addresses[i], &time_state->info[i])) {
+ dev_info(&pdev->dev, "milliseconds supported\n");
+ time_state->last_ms = 0;
+ }
/* Check the (needed) attributes for sanity */
report_id = time_state->info[0].report_id;
if (report_id < 0) {
@@ -227,6 +250,10 @@ static int hid_time_parse_report(struct platform_device *pdev,
return -EINVAL;
}
for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) {
+ if (time_state->info[i].attrib_id ==
+ HID_USAGE_SENSOR_TIME_MILLISECOND &&
+ time_state->last_ms == UINT_MAX)
+ continue;
if (time_state->info[i].report_id != report_id) {
dev_err(&pdev->dev,
"not all needed attributes inside the same report!\n");
@@ -319,6 +346,8 @@ static int hid_time_probe(struct platform_device *pdev)
if (time_state == NULL)
return -ENOMEM;
+ time_state->last_ms = UINT_MAX;
+
platform_set_drvdata(pdev, time_state);
spin_lock_init(&time_state->lock_last_time);
diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
index 6f24446..b519c47 100644
--- a/include/linux/hid-sensor-ids.h
+++ b/include/linux/hid-sensor-ids.h
@@ -74,6 +74,7 @@
#define HID_USAGE_SENSOR_TIME_HOUR 0x200525
#define HID_USAGE_SENSOR_TIME_MINUTE 0x200526
#define HID_USAGE_SENSOR_TIME_SECOND 0x200527
+#define HID_USAGE_SENSOR_TIME_MILLISECOND 0x200528
/* Units */
#define HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED 0x00
--
1.8.1.5
next prev parent reply other threads:[~2013-05-05 11:23 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-19 15:14 [PATCH 0/3] rtc: rtc-hid-sensor-time Alexander Holler
2013-04-19 15:14 ` [PATCH 1/3 RESEND] rtc: rtc-hid-sensor-time: allow full years (16bit) in HID reports Alexander Holler
2013-04-19 15:14 ` [PATCH 2/3] rtc: rtc-hid-sensor-time: allow 16 and 32 bit values for all attributes Alexander Holler
2013-04-19 15:14 ` [PATCH 3/3] rtc: rtc-hid-sensor-time; add option hctosys to set time at boot Alexander Holler
2013-04-22 23:38 ` Andrew Morton
2013-04-23 8:51 ` Alexander Holler
2013-04-23 10:08 ` Alexander Holler
2013-04-23 10:13 ` Alexander Holler
2013-04-23 10:17 ` Alexander Holler
2013-04-23 15:47 ` Alexander Holler
2013-04-24 21:14 ` Andrew Morton
2013-04-25 6:55 ` Alexander Holler
2013-05-05 11:21 ` [PATCH 0/4] rtc: rtc-hid-sensor-time: some changes Alexander Holler
2013-05-05 11:21 ` [PATCH 1/4] rtc: rtc-hid-sensor-time: allow full years (16bit) in HID reports Alexander Holler
2013-05-05 11:21 ` [PATCH 2/4] rtc: rtc-hid-sensor-time: allow 16 and 32 bit values for all attributes Alexander Holler
2013-05-05 11:21 ` [PATCH 3/4] rtc: rtc-hid-sensor-time: add option hctosys to set time at boot Alexander Holler
2013-05-21 21:42 ` Andrew Morton
2013-05-21 22:02 ` John Stultz
2013-05-21 23:15 ` Alexander Holler
2013-05-28 19:37 ` John Stultz
2013-05-29 4:42 ` Alexander Holler
2013-06-04 13:41 ` Alexander Holler
2013-06-05 17:15 ` [PATCH 0/3] RFC: timekeeping: rtc: change hctosys mechanism Alexander Holler
2013-06-05 17:15 ` [PATCH 1/3] RFC: timekeeping: introduce flag systime_was_set Alexander Holler
2013-06-05 17:15 ` [PATCH 2/3] RFC: timekeeping: rtc: Introduce new kernel parameter hctosys Alexander Holler
2013-06-05 17:15 ` [PATCH 3/3] RFC: timekeeping: rtc: remove CONFIG_RTC_HCTOSYS and RTC_HCTOSYS_DEVICE Alexander Holler
2013-06-06 10:51 ` [PATCH 0/3 v2] RFC: timekeeping: rtc: change hctosys mechanism Alexander Holler
2013-06-06 10:51 ` [PATCH 1/3 RESEND] RFC: timekeeping: introduce flag systime_was_set Alexander Holler
2013-06-06 10:51 ` [PATCH 2/3 v2] RFC: timekeeping: rtc: Introduce new kernel parameter hctosys Alexander Holler
2013-06-13 19:39 ` Alexander Holler
2013-06-14 16:52 ` [PATCH 0/9 v3] RFC: timekeeping: rtc: change hctosys mechanism Alexander Holler
2013-06-14 16:52 ` [PATCH 1/9 RESEND] rtc: rtc-hid-sensor-time: allow full years (16bit) in HID reports Alexander Holler
2013-06-14 16:52 ` [PATCH 2/9 RESEND] rtc: rtc-hid-sensor-time: allow 16 and 32 bit values for all attributes Alexander Holler
2013-06-14 16:52 ` [PATCH 3/9] rtc: rtc-hid-sensor-time: delay registering as rtc into a work Alexander Holler
2013-06-20 10:39 ` [PATCH 3/9 v2] " Alexander Holler
2013-06-26 19:55 ` Andrew Morton
2013-06-26 21:34 ` [rtc-linux] " Alexander Holler
2013-06-26 22:07 ` Greg KH
2013-06-26 23:51 ` Alexander Holler
2013-07-06 8:55 ` Alexander Holler
2013-07-06 18:21 ` Jiri Kosina
2013-07-07 7:35 ` Alexander Holler
2013-07-08 9:12 ` [PATCH 0/2] rtc: rtc-hid-sensor-time: enable HID input processing early Alexander Holler
2013-07-08 9:12 ` [PATCH 1/2] rtc: rtc-hid-sensor-time: improve error handling when rtc register fails Alexander Holler
2013-07-08 9:12 ` [PATCH 2/2] rtc: rtc-hid-sensor-time: enable HID input processing early Alexander Holler
2013-06-28 1:29 ` [rtc-linux] Re: [PATCH 3/9 v2] rtc: rtc-hid-sensor-time: delay registering as rtc into a work Alexander Holler
2013-06-14 16:52 ` [PATCH 4/9 RESEND] RFC: timekeeping: introduce flag systime_was_set Alexander Holler
2013-06-14 17:41 ` John Stultz
2013-06-14 18:05 ` [rtc-linux] " Alexander Holler
2013-06-14 18:28 ` John Stultz
2013-06-15 6:01 ` Alexander Holler
2013-06-17 18:10 ` John Stultz
2013-06-20 10:15 ` Alexander Holler
2013-06-20 17:27 ` John Stultz
2013-06-20 18:45 ` Alexander Holler
2013-06-20 19:28 ` John Stultz
2013-06-20 23:10 ` Alexander Holler
2013-06-14 16:52 ` [PATCH 5/9 v3] RFC: timekeeping: rtc: Introduce new kernel parameter hctosys Alexander Holler
2013-06-14 19:24 ` John Stultz
2013-06-14 16:52 ` [PATCH 6/9 v3] RFC: timekeeping: rtc: remove CONFIG_RTC_HCTOSYS and RTC_HCTOSYS_DEVICE Alexander Holler
2013-06-14 19:11 ` John Stultz
2013-06-22 8:00 ` Alexander Holler
2013-06-14 16:52 ` [PATCH 7/9] RFC: rtc: implement rtc_read_timeval() Alexander Holler
2013-06-14 17:23 ` John Stultz
2013-06-14 17:43 ` Alexander Holler
2013-06-14 19:18 ` John Stultz
2013-06-14 17:28 ` John Stultz
2013-06-14 16:52 ` [PATCH 8/9] RFC: rtc: hctosys: support rtc_read_timeval() for high precision clocks Alexander Holler
2013-06-14 19:20 ` John Stultz
2013-06-14 16:52 ` [PATCH 9/9] RFC: rtc: rtc-hid-sensor-time: add support for rtc_read_timeval() Alexander Holler
2013-06-14 17:27 ` [PATCH 0/9 v3] RFC: timekeeping: rtc: change hctosys mechanism John Stultz
2013-06-06 10:51 ` [PATCH 3/3 v2] RFC: timekeeping: rtc: remove CONFIG_RTC_HCTOSYS and RTC_HCTOSYS_DEVICE Alexander Holler
2013-06-04 9:38 ` [PATCH] rtc: rtc-hid-sensor-time: fix possible bug on driver_remove Alexander Holler
2013-06-08 8:56 ` Alexander Holler
2013-05-05 11:21 ` Alexander Holler [this message]
2013-04-20 23:46 ` [PATCH 0/3] rtc: rtc-hid-sensor-time Jiri Kosina
2013-04-21 6:38 ` Alexander Holler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1367752887-2927-5-git-send-email-holler@ahsoftware.de \
--to=holler@ahsoftware.de \
--cc=a.zummo@towertech.it \
--cc=akpm@linux-foundation.org \
--cc=jic23@cam.ac.uk \
--cc=jkosina@suse.cz \
--cc=john.stultz@linaro.org \
--cc=lars@metafoo.de \
--cc=linux-kernel@vger.kernel.org \
--cc=rtc-linux@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).