From patchwork Fri Mar 6 19:47:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 5957571 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 04699BF440 for ; Fri, 6 Mar 2015 19:47:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 08B5C20263 for ; Fri, 6 Mar 2015 19:47:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0A7B32037E for ; Fri, 6 Mar 2015 19:47:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754617AbbCFTrx (ORCPT ); Fri, 6 Mar 2015 14:47:53 -0500 Received: from mail-pa0-f54.google.com ([209.85.220.54]:46102 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754647AbbCFTrw (ORCPT ); Fri, 6 Mar 2015 14:47:52 -0500 Received: by pabli10 with SMTP id li10so53964807pab.13 for ; Fri, 06 Mar 2015 11:47:52 -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=GpK7xcIC4ZlbfmYg0WBzyHBwzrl23dInXYQcWWld1Dw=; b=gK0C7MPu4fEIo1eFfhxT3IqRdQejMpRnhe98VuMOUiiO3UXqEpPjVmo/gDJ7QwkdAP q83DKE6oZd+COXYA2G3kMrCMhLtGlih2JnpkjDXW/9LHP5xpumZm8uQaDRf8TE8+0dp3 M5rZr8fTmyYJXsXKZaG2/gXCslBdUwXd/S2jR+xhm3jEcXvnHRzylf+MShDcOfEDo/Bb eLJjVp3bf9j4/FHCB/LV2daY0p33K17s0K1awrlz4hRK8U6KKIBLPrvQDDxDAdURLQbq L1hImlGxFzlPCXRunqh+kp4TJX5UtEpS2AQ5znHHPtvMoQHomUXwZXrEQaHRGA8iwIa2 +8Qw== X-Received: by 10.68.172.162 with SMTP id bd2mr28351319pbc.89.1425671272342; Fri, 06 Mar 2015 11:47:52 -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.50 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 Mar 2015 11:47:51 -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 2/7] HID: wacom: Centralize updating of wacom_wac battery status Date: Fri, 6 Mar 2015 11:47:32 -0800 Message-Id: <1425671264-4944-2-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 Has the 'wacom_notify_battery' function take on the job of detecting if updating the power supply is necessary to remove multiple nearly-identical 'if' blocks. Signed-off-by: Jason Gerecke --- drivers/hid/wacom.h | 7 ------ drivers/hid/wacom_wac.c | 57 +++++++++++++++++++++++++------------------------ 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/drivers/hid/wacom.h b/drivers/hid/wacom.h index 7db4328..b8344b1 100644 --- a/drivers/hid/wacom.h +++ b/drivers/hid/wacom.h @@ -129,13 +129,6 @@ static inline void wacom_schedule_work(struct wacom_wac *wacom_wac) schedule_work(&wacom->work); } -static inline void wacom_notify_battery(struct wacom_wac *wacom_wac) -{ - struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac); - - power_supply_changed(&wacom->battery); -} - extern const struct hid_device_id wacom_ids[]; void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len); diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index cb308c5..5d57fec 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -45,6 +45,24 @@ 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) +{ + 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->ps_connected != ps_connected; + + if (changed) { + wacom_wac->battery_capacity = bat_capacity; + wacom_wac->bat_charging = bat_charging; + wacom_wac->ps_connected = ps_connected; + + if (wacom->battery.dev) + power_supply_changed(&wacom->battery); + } +} + static int wacom_penpartner_irq(struct wacom_wac *wacom) { unsigned char *data = wacom->data; @@ -419,12 +437,8 @@ static int wacom_graphire_irq(struct wacom_wac *wacom) rw = (data[7] >> 2 & 0x07); battery_capacity = batcap_gr[rw]; ps_connected = rw == 7; - if ((wacom->battery_capacity != battery_capacity) || - (wacom->ps_connected != ps_connected)) { - wacom->battery_capacity = battery_capacity; - wacom->ps_connected = ps_connected; - wacom_notify_battery(wacom); - } + wacom_notify_battery(wacom, battery_capacity, ps_connected, + ps_connected); } exit: return retval; @@ -1014,15 +1028,8 @@ static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len) bat_charging = (power_raw & 0x08) ? 1 : 0; ps_connected = (power_raw & 0x10) ? 1 : 0; battery_capacity = batcap_i4[power_raw & 0x07]; - if ((wacom->battery_capacity != battery_capacity) || - (wacom->bat_charging != bat_charging) || - (wacom->ps_connected != ps_connected)) { - wacom->battery_capacity = battery_capacity; - wacom->bat_charging = bat_charging; - wacom->ps_connected = ps_connected; - wacom_notify_battery(wacom); - } - + wacom_notify_battery(wacom, battery_capacity, bat_charging, + ps_connected); break; default: dev_dbg(wacom->input->dev.parent, @@ -1910,7 +1917,7 @@ static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len) connected = data[1] & 0x01; if (connected) { - int pid, battery, ps_connected; + int pid, battery, ps_connected, charging; if ((wacom->shared->type == INTUOSHT) && wacom->shared->touch_input && @@ -1923,27 +1930,21 @@ static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len) pid = get_unaligned_be16(&data[6]); battery = (data[5] & 0x3f) * 100 / 31; ps_connected = !!(data[5] & 0x80); + charging = ps_connected && wacom->battery_capacity < 100; if (wacom->pid != pid) { wacom->pid = pid; wacom_schedule_work(wacom); } - if (wacom->shared->type && - (battery != wacom->battery_capacity || - ps_connected != wacom->ps_connected)) { - wacom->battery_capacity = battery; - wacom->ps_connected = ps_connected; - wacom->bat_charging = ps_connected && - wacom->battery_capacity < 100; - wacom_notify_battery(wacom); - } + if (wacom->shared->type) + wacom_notify_battery(wacom, battery, charging, + ps_connected); + } else if (wacom->pid != 0) { /* disconnected while previously connected */ wacom->pid = 0; wacom_schedule_work(wacom); - wacom->battery_capacity = 0; - wacom->bat_charging = 0; - wacom->ps_connected = 0; + wacom_notify_battery(wacom, 0, 0, 0); } return 0;