From patchwork Wed Mar 11 17:25:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 5987911 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2E5A2BF90F for ; Wed, 11 Mar 2015 17:26:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 26C1020379 for ; Wed, 11 Mar 2015 17:26:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8069420375 for ; Wed, 11 Mar 2015 17:26:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752738AbbCKRZ7 (ORCPT ); Wed, 11 Mar 2015 13:25:59 -0400 Received: from mail-pd0-f170.google.com ([209.85.192.170]:38439 "EHLO mail-pd0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752717AbbCKRZ6 (ORCPT ); Wed, 11 Mar 2015 13:25:58 -0400 Received: by pdbfl12 with SMTP id fl12so12767190pdb.5 for ; Wed, 11 Mar 2015 10:25:57 -0700 (PDT) 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=QCrF67yM3AsKmZ7BPmsNsugyzRo4QRTD0506MCqJ51Y=; b=gU3ke2BSZ6E3G4+k4KTcnTmT6it+E+nFj8WP61giDodqjLYtTJade5GmN9CKd3QoEt IVDfTjhpcRzFeaUn9VAizMkCwm0u+QmQR0IPmg8LWiR61pM/bkrQ/6gx/UKJnS6nQAIy +9nuHdpwYq/eRBfU+ZXKW3pwajGU1FIjVGlwGos5s9oqOigaePE5aw51UO73yCfNUdRf wbxycBtmfhyiUoKyCh7BDRSSw00b5ie5FSY5MvIEcr0dNToEY4QMu/abz9DQke6540sg hdeCl6ISdfBRixLPhgKNox6Hq55Hl8I77k+iT4dKHR7UE2wSUt07WApBbXTn8YSkZmbQ NBnQ== X-Received: by 10.70.43.72 with SMTP id u8mr59215046pdl.107.1426094757228; Wed, 11 Mar 2015 10:25:57 -0700 (PDT) Received: from wacom-arch2.localdomain ([67.51.163.2]) by mx.google.com with ESMTPSA id t5sm6978763pde.51.2015.03.11.10.25.55 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Mar 2015 10:25:55 -0700 (PDT) From: Jason Gerecke To: jkosina@suse.cz, linux-input@vger.kernel.org Cc: pinglinux@gmail.com, benjamin.tissoires@redhat.com, Jason Gerecke Subject: [PATCH v2 7/7] HID: wacom: Add battery presence indicator to wireless tablets Date: Wed, 11 Mar 2015 10:25:41 -0700 Message-Id: <1426094741-15270-1-git-send-email-killertofu@gmail.com> X-Mailer: git-send-email 2.3.2 In-Reply-To: <1425671264-4944-14-git-send-email-killertofu@gmail.com> References: <1425671264-4944-14-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 Declares the POWER_SUPPLY_PROP_PRESENT property to provide userspace with a way to determine if the battery on a wireless tablet is plugged in. Although current wireless tablets do not explicitly report this information, it can be inferred from other state information. In particular, a battery is assumed to be present if any of the following are true: a non-zero battery level reported, the battery is reported as charging, or the tablet is operating wirelessly. Note: The last condition above may not strictly hold for the Graphire Wireless (it charges from a DC barrel jack instead of a USB port), but I do not know what is reported in the no-battery condition. Signed-off-by: Jason Gerecke --- drivers/hid/wacom_sys.c | 4 ++++ drivers/hid/wacom_wac.c | 16 ++++++++++------ drivers/hid/wacom_wac.h | 1 + 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 955ce7c..ab7bf84 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -945,6 +945,7 @@ static void wacom_destroy_leds(struct wacom *wacom) } static enum power_supply_property wacom_battery_props[] = { + POWER_SUPPLY_PROP_PRESENT, POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_SCOPE, POWER_SUPPLY_PROP_CAPACITY @@ -964,6 +965,9 @@ static int wacom_battery_get_property(struct power_supply *psy, int ret = 0; switch (psp) { + case POWER_SUPPLY_PROP_PRESENT: + val->intval = wacom->wacom_wac.bat_connected; + break; case POWER_SUPPLY_PROP_SCOPE: val->intval = POWER_SUPPLY_SCOPE_DEVICE; break; diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 57faf5b..9262622 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -46,16 +46,19 @@ static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 }; static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 }; static void wacom_notify_battery(struct wacom_wac *wacom_wac, - int bat_capacity, bool bat_charging, bool ps_connected) + int bat_capacity, bool bat_charging, bool bat_connected, + bool ps_connected) { struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac); bool changed = wacom_wac->battery_capacity != bat_capacity || wacom_wac->bat_charging != bat_charging || + wacom_wac->bat_connected != bat_connected || wacom_wac->ps_connected != ps_connected; if (changed) { wacom_wac->battery_capacity = bat_capacity; wacom_wac->bat_charging = bat_charging; + wacom_wac->bat_connected = bat_connected; wacom_wac->ps_connected = ps_connected; if (wacom->battery.dev) @@ -438,7 +441,7 @@ static int wacom_graphire_irq(struct wacom_wac *wacom) battery_capacity = batcap_gr[rw]; ps_connected = rw == 7; wacom_notify_battery(wacom, battery_capacity, ps_connected, - ps_connected); + 1, ps_connected); } exit: return retval; @@ -1029,6 +1032,7 @@ static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len) ps_connected = (power_raw & 0x10) ? 1 : 0; battery_capacity = batcap_i4[power_raw & 0x07]; wacom_notify_battery(wacom, battery_capacity, bat_charging, + battery_capacity || bat_charging, ps_connected); break; default: @@ -1936,13 +1940,13 @@ static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len) } if (wacom->shared->type) - wacom_notify_battery(wacom, battery, charging, 0); + wacom_notify_battery(wacom, battery, charging, 1, 0); } else if (wacom->pid != 0) { /* disconnected while previously connected */ wacom->pid = 0; wacom_schedule_work(wacom); - wacom_notify_battery(wacom, 0, 0, 0); + wacom_notify_battery(wacom, 0, 0, 0, 0); } return 0; @@ -1970,7 +1974,7 @@ static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len) bool charging = !!(data[8] & 0x80); wacom_notify_battery(wacom_wac, battery, charging, - 1); + battery || charging, 1); if (!wacom->battery.dev && !(features->quirks & WACOM_QUIRK_BATTERY)) { @@ -1984,7 +1988,7 @@ static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len) 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); + wacom_notify_battery(wacom_wac, 0, 0, 0, 0); } return 0; } diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h index ee6a545..f3daf7b 100644 --- a/drivers/hid/wacom_wac.h +++ b/drivers/hid/wacom_wac.h @@ -213,6 +213,7 @@ struct wacom_wac { int battery_capacity; int num_contacts_left; int bat_charging; + int bat_connected; int ps_connected; u8 bt_features; u8 bt_high_speed;