From patchwork Tue Mar 7 23:45:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roderick Colenbrander X-Patchwork-Id: 9609995 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 18F346046A for ; Tue, 7 Mar 2017 23:46:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 09FC928585 for ; Tue, 7 Mar 2017 23:46:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F10EF28535; Tue, 7 Mar 2017 23:46:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 912EA28535 for ; Tue, 7 Mar 2017 23:46:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933242AbdCGXqz (ORCPT ); Tue, 7 Mar 2017 18:46:55 -0500 Received: from mail-pg0-f41.google.com ([74.125.83.41]:35923 "EHLO mail-pg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933256AbdCGXqo (ORCPT ); Tue, 7 Mar 2017 18:46:44 -0500 Received: by mail-pg0-f41.google.com with SMTP id 187so5984490pgb.3 for ; Tue, 07 Mar 2017 15:45:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaikai-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sB3cQl8IsDrIqPZ6s1fSrNovLLkzSJDUSFuv7rP8NiA=; b=sl1q43TvedtFSKiv3iKc5AdDne+/vkrAs4hJG74wrDj/uKo6eS8RUodcmgIUu4si7N 4zZQW7YznjJujEcHRxUYZ74EndXle2UNVq6GEWLwaHX8V5scruo3q3d83DDMOR00xvtq yjqUJpOG3Cl7GGtMjXxKOLuV9Lknx7xhk4EKGHXJxEMoYJqe30zyu2hNdMS3cCSMfB26 6wzYjKIGC45UbBjMMH6fJ5yt/w8t6E/kyhDEdWNOh4y5D8qxpI1xlTwf6JbKRx0PjGJM /PanFtJfSJ2Pde12lr8Urb2VdGnArK45hW8bPofpozak2EVgv3t82ECcsib9o/9EwIxx Nfsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sB3cQl8IsDrIqPZ6s1fSrNovLLkzSJDUSFuv7rP8NiA=; b=HtBr14YfUo5PClFaRVszDFVDhKEDoug13jX63y9L+z/BGdVaxYanNIx4WBMtdPVPo2 zCMv3u3aeXrem3tkXVhU6iGN+DAc8H/rvthFf1Xr4kozZyNw6on3oyFcql8KAt0YTuIf tR9R4jTj656gXaRUSqx0CFoe57WFpOKSqZf9FuEl+MdkyHbfGtrnTbbiXVessjYukV1Y puiose4lPazdp5w7v7f98JO/tfzS/r8ixf4zXqK6IrqoYmnexXst7SMukJYKn9jSp0G9 P++Xbqh3ax5JUVf6KJXYI0NaNVjHHR4s+OCHCgl6g0Ic9VEnybdD5gn9/+G8DZA3HcCq z0Vw== X-Gm-Message-State: AMke39kbBCQFpwbJzdykWarM+DP2vxn0e6hMF8nn2MDwQH2hEmJoSiW+kfBNEkcy7duxhYfM X-Received: by 10.84.238.199 with SMTP id l7mr4106191pln.90.1488930317641; Tue, 07 Mar 2017 15:45:17 -0800 (PST) Received: from roderick.ad.gaikai.biz ([100.42.98.197]) by smtp.gmail.com with ESMTPSA id e7sm1890993pgp.2.2017.03.07.15.45.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Mar 2017 15:45:17 -0800 (PST) From: Roderick Colenbrander To: linux-input@vger.kernel.org Cc: Dmitry Torokhov , Jiri Kosina , Benjamin Tissoires , Simon Wood , Frank Praznik , Tim Bird , Roderick Colenbrander Subject: [PATCH v4 03/12] HID: sony: Report hardware timestamp for DS4 sensor values Date: Tue, 7 Mar 2017 15:45:02 -0800 Message-Id: <20170307234511.30380-4-roderick@gaikai.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170307234511.30380-1-roderick@gaikai.com> References: <20170307234511.30380-1-roderick@gaikai.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Roderick Colenbrander Report the hardware timestamp inside each HID report through MSC_TIMESTAMP for motion sensor values. Signed-off-by: Roderick Colenbrander --- drivers/hid/hid-sony.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index 1b933ef..d263e04 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -781,6 +781,7 @@ struct motion_output_report_02 { * additional +2. */ #define DS4_INPUT_REPORT_BUTTON_OFFSET 5 +#define DS4_INPUT_REPORT_TIMESTAMP_OFFSET 10 #define DS4_INPUT_REPORT_GYRO_X_OFFSET 13 #define DS4_INPUT_REPORT_BATTERY_OFFSET 30 #define DS4_INPUT_REPORT_TOUCHPAD_OFFSET 33 @@ -837,6 +838,11 @@ struct sony_sc { u8 led_delay_on[MAX_LEDS]; u8 led_delay_off[MAX_LEDS]; u8 led_count; + + bool timestamp_initialized; + u16 prev_timestamp; + unsigned int timestamp_us; + bool ds4_dongle_connected; /* DS4 calibration data */ struct ds4_calibration_data ds4_calib_data[6]; @@ -1031,6 +1037,7 @@ static void dualshock4_parse_report(struct sony_sc *sc, u8 *rd, int size) unsigned long flags; int n, m, offset, num_touch_data, max_touch_data; u8 cable_state, battery_capacity, battery_charging; + u16 timestamp; /* When using Bluetooth the header is 2 bytes longer, so skip these. */ int data_offset = (sc->quirks & DUALSHOCK4_CONTROLLER_USB) ? 0 : 2; @@ -1039,6 +1046,24 @@ static void dualshock4_parse_report(struct sony_sc *sc, u8 *rd, int size) offset = data_offset + DS4_INPUT_REPORT_BUTTON_OFFSET; input_report_key(sc->touchpad, BTN_LEFT, rd[offset+2] & 0x2); + /* Convert timestamp (in 5.33us unit) to timestamp_us */ + offset = data_offset + DS4_INPUT_REPORT_TIMESTAMP_OFFSET; + timestamp = get_unaligned_le16(&rd[offset]); + if (!sc->timestamp_initialized) { + sc->timestamp_us = ((unsigned int)timestamp * 16) / 3; + sc->timestamp_initialized = true; + } else { + u16 delta; + + if (sc->prev_timestamp > timestamp) + delta = (U16_MAX - sc->prev_timestamp + timestamp + 1); + else + delta = timestamp - sc->prev_timestamp; + sc->timestamp_us += (delta * 16) / 3; + } + sc->prev_timestamp = timestamp; + input_event(sc->sensor_dev, EV_MSC, MSC_TIMESTAMP, sc->timestamp_us); + offset = data_offset + DS4_INPUT_REPORT_GYRO_X_OFFSET; for (n = 0; n < 6; n++) { /* Store data in int for more precision during mult_frac. */ @@ -1385,6 +1410,8 @@ static int sony_register_sensors(struct sony_sc *sc) input_abs_set_res(sc->sensor_dev, ABS_RY, DS4_GYRO_RES_PER_DEG_S); input_abs_set_res(sc->sensor_dev, ABS_RZ, DS4_GYRO_RES_PER_DEG_S); + __set_bit(EV_MSC, sc->sensor_dev->evbit); + __set_bit(MSC_TIMESTAMP, sc->sensor_dev->mscbit); __set_bit(INPUT_PROP_ACCELEROMETER, sc->sensor_dev->propbit); ret = input_register_device(sc->sensor_dev);