From patchwork Thu Feb 6 01:03:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Praznik X-Patchwork-Id: 3592501 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E4BE69F392 for ; Thu, 6 Feb 2014 01:04:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 17E7120166 for ; Thu, 6 Feb 2014 01:04:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4323A20136 for ; Thu, 6 Feb 2014 01:04:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753169AbaBFBER (ORCPT ); Wed, 5 Feb 2014 20:04:17 -0500 Received: from cdptpa-omtalb.mail.rr.com ([75.180.132.120]:56652 "EHLO cdptpa-omtalb.mail.rr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753892AbaBFBEQ (ORCPT ); Wed, 5 Feb 2014 20:04:16 -0500 X-Authority-Analysis: v=2.0 cv=dq5Z+ic4 c=1 sm=0 a=N8gH7sxzIWrJto1iYJUVbg==:17 a=0DRqpTGj1rYA:10 a=05ChyHeVI94A:10 a=Cvmq5WjI5q8A:10 a=ayC55rCoAAAA:8 a=KGjhK52YXX0A:10 a=DF5aUo1Wt08A:10 a=LclIVfuN8fKNsHjzVTgA:9 a=N8gH7sxzIWrJto1iYJUVbg==:117 X-Cloudmark-Score: 0 X-Authenticated-User: X-Originating-IP: 24.29.232.96 Received: from [24.29.232.96] ([24.29.232.96:1133] helo=localhost.localdomain) by cdptpa-oedge03.mail.rr.com (envelope-from ) (ecelerity 2.2.3.46 r()) with ESMTP id 54/AF-21884-E8FD2F25; Thu, 06 Feb 2014 01:04:14 +0000 From: Frank Praznik To: linux-input@vger.kernel.org Cc: jkosina@suse.cz, dh.herrmann@gmail.com, Frank Praznik Subject: [PATCH v3 4/6] HID: sony: Add Dualshock 4 Bluetooth battery and touchpad parsing Date: Wed, 5 Feb 2014 20:03:47 -0500 Message-Id: <1391648629-3077-5-git-send-email-frank.praznik@oh.rr.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1391648629-3077-1-git-send-email-frank.praznik@oh.rr.com> References: <1391648629-3077-1-git-send-email-frank.praznik@oh.rr.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add Dualshock 4 battery and touchpad parsing for Bluetooth reports. Signed-off-by: Frank Praznik --- v2 adds more robust battery data parsing drivers/hid/hid-sony.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index 59cd9d7..4b8cb98 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -861,25 +861,34 @@ static void dualshock4_parse_report(struct sony_sc *sc, __u8 *rd, int size) struct hid_input, list); struct input_dev *input_dev = hidinput->input; unsigned long flags; - int n, offset = 35; + int n, offset; __u8 cable_state, battery_capacity, battery_charging; + /* Battery and touchpad data starts at byte 30 in the USB report and + * 32 in Bluetooth report. + */ + offset = (sc->quirks & DUALSHOCK4_CONTROLLER_USB) ? 30 : 32; + /* The lower 4 bits of byte 30 contain the battery level * and the 5th bit contains the USB cable state. */ - cable_state = (rd[30] >> 4) & 0x01; - battery_capacity = rd[30] & 0x0F; + cable_state = (rd[offset] >> 4) & 0x01; + battery_capacity = rd[offset] & 0x0F; - /* On USB the Dualshock 4 battery level goes from 0 to 11. - * A battery level of 11 means fully charged. + /* When a USB power source is connected the battery level ranges from + * 0 to 10, and when running on battery power it ranges from 0 to 9. + * A battery level above 10 when plugged in means charge completed. */ - if (cable_state && battery_capacity == 11) + if (!cable_state || battery_capacity > 10) battery_charging = 0; else battery_charging = 1; + if (!cable_state) + battery_capacity++; if (battery_capacity > 10) - battery_capacity--; + battery_capacity = 10; + battery_capacity *= 10; spin_lock_irqsave(&sc->lock, flags); @@ -888,7 +897,10 @@ static void dualshock4_parse_report(struct sony_sc *sc, __u8 *rd, int size) sc->battery_charging = battery_charging; spin_unlock_irqrestore(&sc->lock, flags); - /* The Dualshock 4 multi-touch trackpad data starts at offset 35 on USB. + offset += 5; + + /* The Dualshock 4 multi-touch trackpad data starts at offset 35 on USB + * and 37 on Bluetooth. * The first 7 bits of the first byte is a counter and bit 8 is a touch * indicator that is 0 when pressed and 1 when not pressed. * The next 3 bytes are two 12 bit touch coordinates, X and Y.