From patchwork Fri Mar 6 19:47:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 5957591 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AF4E19F380 for ; Fri, 6 Mar 2015 19:47:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D933B20263 for ; Fri, 6 Mar 2015 19:47:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 06EDE2034E for ; Fri, 6 Mar 2015 19:47:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754647AbbCFTr5 (ORCPT ); Fri, 6 Mar 2015 14:47:57 -0500 Received: from mail-pd0-f171.google.com ([209.85.192.171]:37955 "EHLO mail-pd0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755190AbbCFTr4 (ORCPT ); Fri, 6 Mar 2015 14:47:56 -0500 Received: by pdbfl12 with SMTP id fl12so46295152pdb.5 for ; Fri, 06 Mar 2015 11:47:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YIYc0T+/bRN6dMzpZYrF4X7my5RlS6Iy69AATUiV6ec=; b=jmOA2vzfVqUaVohgv0UAyr4oAg1hb+GuTMEHFaetoXLEQvuh9ugBUqdsALQT48h85v H3dtGTDBMiu3RENQg1RaO82JScTp7o1iYmrQuFTZvVgNB0HoFIDhdEFeeGri6WBZfyRC wAxsb9AuRzjjhAA9AftGtSoO21Hc8i4iIFoPgXqJulTPrFOl8btefb6hp4I1Ifd8Ql5C fGU4AjI1MAeIvuu7dnj/6e6pgk1uZZanPxjUDcqcY63BUR0LQDAcBoW1t5jrRC+QGg55 sWtU97hSnx34NYTp4H6E7tBmyJ8jkA3LOFD5D+9PAKBDJ06Mqc1OJO0U7BkfGEX/Xm6a nW3w== X-Received: by 10.68.253.161 with SMTP id ab1mr28454820pbd.25.1425671276446; Fri, 06 Mar 2015 11:47:56 -0800 (PST) Received: from wacom-arch2.localdomain ([67.51.163.2]) by mx.google.com with ESMTPSA id gf2sm2367452pbc.60.2015.03.06.11.47.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 Mar 2015 11:47:54 -0800 (PST) From: Jason Gerecke To: jkosina@suse.cz, linux-input@vger.kernel.org Cc: pinglinux@gmail.com, benjamin.tissoires@redhat.com, Jason Gerecke Subject: [PATCH 4/7] HID: wacom: Provide battery charge state to system over USB if available Date: Fri, 6 Mar 2015 11:47:34 -0800 Message-Id: <1425671264-4944-4-git-send-email-killertofu@gmail.com> X-Mailer: git-send-email 2.3.0 In-Reply-To: <1425671264-4944-1-git-send-email-killertofu@gmail.com> References: <1425671264-4944-1-git-send-email-killertofu@gmail.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=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_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 If a wireless adapter (which contains the charging circuitry) is detected as being attached to the tablet then create a new battery interface and update its status as data is reported. Also destroy the battery if the adapter goes away. Signed-off-by: Jason Gerecke --- drivers/hid/wacom_wac.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 5d57fec..f1e53f1 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -1952,6 +1952,7 @@ static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len) static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len) { + struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac); struct wacom_features *features = &wacom_wac->features; unsigned char *data = wacom_wac->data; @@ -1965,6 +1966,30 @@ static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len) SW_MUTE_DEVICE, data[8] & 0x40); input_sync(wacom_wac->shared->touch_input); } + + if (data[9] & 0x02) { /* wireless module is attached */ + int battery = (data[8] & 0x3f) * 100 / 31; + bool ps_connected = !!(data[8] & 0x80); + bool charging = ps_connected && + wacom_wac->battery_capacity < 100; + + wacom_notify_battery(wacom_wac, battery, charging, + ps_connected); + + if (!wacom->battery.dev && + !(features->quirks & WACOM_QUIRK_BATTERY)) { + features->quirks |= WACOM_QUIRK_BATTERY; + INIT_WORK(&wacom->work, wacom_battery_work); + wacom_schedule_work(wacom_wac); + } + } + else if ((features->quirks & WACOM_QUIRK_BATTERY) && + wacom->battery.dev) { + features->quirks &= ~WACOM_QUIRK_BATTERY; + INIT_WORK(&wacom->work, wacom_battery_work); + wacom_schedule_work(wacom_wac); + wacom_notify_battery(wacom_wac, 0, 0, 0); + } return 0; }