From patchwork Fri Apr 5 10:58:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Holler X-Patchwork-Id: 234110 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-wi0-x238.google.com (mail-wi0-x238.google.com [IPv6:2a00:1450:400c:c05::238]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 8270B2C00B1 for ; Fri, 5 Apr 2013 21:58:26 +1100 (EST) Received: by mail-wi0-f184.google.com with SMTP id cb5sf140318wib.21 for ; Fri, 05 Apr 2013 03:58:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=x-received:mime-version:x-beenthere:x-received:received-spf :x-spam-checker-version:x-spam-level:x-spam-status:from:to:cc :subject:date:message-id:x-mailer:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=3xXlRjJTON8Eje94woXRWiawydfmi0ln0H1Va31YJWc=; b=jcavduVM0BXAGCEEU9yDAUIckfzkpTSG2XDJ50zzxHlnk2mRWKQN7akB5I028dXOub MFhvnGtZtAlLKVcbWyA4RMGcF02hjaxXK20cmgLA+qQUrZ6q/OuzbOezU2Ri+X6D7HHu xPHyA5kIuQvm0BuexJ6kvPxdcaC3nGqmcg/Z9doin2y7CFebRRmwOR131LwQcHKE7iDC wZK7bRvtnLeCcTP2xaUOBrCeN2CMh1ZQ4WFkRI641RexHOCUfLARDJmqGoktnVO8Yv5i mn4326gOATL9FTXAggNrIhFCKN14+BTwackNdsRAGfyNQhBlTmUSvx6G6oY+bFq2hTGU ajeg== X-Received: by 10.180.208.19 with SMTP id ma19mr134811wic.21.1365159502019; Fri, 05 Apr 2013 03:58:22 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.180.189.38 with SMTP id gf6ls154575wic.47.gmail; Fri, 05 Apr 2013 03:58:20 -0700 (PDT) X-Received: by 10.204.247.132 with SMTP id mc4mr1000559bkb.2.1365159500892; Fri, 05 Apr 2013 03:58:20 -0700 (PDT) Received: from mail.ahsoftware.de (h1446028.stratoserver.net. [85.214.92.142]) by gmr-mx.google.com with ESMTP id u1si1524006bkv.1.2013.04.05.03.58.20; Fri, 05 Apr 2013 03:58:20 -0700 (PDT) Received-SPF: neutral (google.com: 85.214.92.142 is neither permitted nor denied by best guess record for domain of holler@ahsoftware.de) client-ip=85.214.92.142; Received: by mail.ahsoftware.de (Postfix, from userid 65534) id 6E38E888020; Fri, 5 Apr 2013 12:58:20 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.ahsoftware.de X-Spam-Level: X-Spam-Status: No, score=-101.0 required=5.0 tests=ALL_TRUSTED, USER_IN_WHITELIST autolearn=disabled version=3.3.1 Received: from eiche.ahsoftware (p57B20119.dip0.t-ipconnect.de [87.178.1.25]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.ahsoftware.de (Postfix) with ESMTPSA id D4951888020 for ; Fri, 5 Apr 2013 12:58:19 +0200 (CEST) Received: by eiche.ahsoftware (Postfix, from userid 65534) id E81227FC01; Fri, 5 Apr 2013 12:58:18 +0200 (CEST) Received: from krabat.ahsoftware (unknown [192.168.207.2]) by eiche.ahsoftware (Postfix) with ESMTP id 676F27F9E9; Fri, 5 Apr 2013 10:58:14 +0000 (UTC) From: Alexander Holler To: linux-kernel@vger.kernel.org Cc: rtc-linux@googlegroups.com, Alessandro Zummo , Alexander Holler Subject: [rtc-linux] [PATCH] rtc: rtc-hid-sensor-time: allow full years (16bit) in HID reports Date: Fri, 5 Apr 2013 12:58:10 +0200 Message-Id: <1365159490-9327-1-git-send-email-holler@ahsoftware.de> X-Mailer: git-send-email 1.8.1.4 X-Original-Sender: holler@ahsoftware.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 85.214.92.142 is neither permitted nor denied by best guess record for domain of holler@ahsoftware.de) smtp.mail=holler@ahsoftware.de Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , The draft for HID-sensors (HUTRR39) currently doesn't define the range for the attribute year. Asking one of the authors revealed that full years (e.g. 2013 instead of just 13) were meant. So we now allow both, 8 bit and 16 bit values for the attribute year and assuming full years when the value is 16 bits wide. We will still support 8 bit values until the specification gets final (and maybe defines a way to set the time too). Signed-off-by: Alexander Holler --- drivers/rtc/rtc-hid-sensor-time.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c index 31c5728..f3ef38a 100644 --- a/drivers/rtc/rtc-hid-sensor-time.c +++ b/drivers/rtc/rtc-hid-sensor-time.c @@ -85,10 +85,13 @@ static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev, 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; + if (raw_len == 1) { + time_buf->tm_year = *(u8 *)raw_data; + if (time_buf->tm_year < 70) + /* assume we are in 1970...2069 */ + time_buf->tm_year += 100; + } else + time_buf->tm_year = *(u16 *)raw_data-1900; break; case HID_USAGE_SENSOR_TIME_MONTH: /* sensor sending the month as 1-12, we need 0-11 */ @@ -151,11 +154,27 @@ static int hid_time_parse_report(struct platform_device *pdev, return -EINVAL; } if (time_state->info[i].size != 1) { - dev_err(&pdev->dev, - "attribute '%s' not 8 bits wide!\n", + /* + * The draft for HID-sensors (HUTRR39) currently + * doesn't define the range for the year attribute. + * Therefor we support both 8 bit (0-99) and 16 bit + * (full) as size for the year. + */ + if (time_state->info[i].attrib_id != + HID_USAGE_SENSOR_TIME_YEAR) { + dev_err(&pdev->dev, + "attribute '%s' not 8 bits wide!\n", hid_time_attrib_name( time_state->info[i].attrib_id)); - return -EINVAL; + return -EINVAL; + } + if (time_state->info[i].size != 2) { + dev_err(&pdev->dev, + "attribute '%s' not 8 or 16 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 &&