From patchwork Wed Nov 12 00:25:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Bellows X-Patchwork-Id: 40629 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f69.google.com (mail-ee0-f69.google.com [74.125.83.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9CAD1205DF for ; Wed, 12 Nov 2014 00:34:01 +0000 (UTC) Received: by mail-ee0-f69.google.com with SMTP id c41sf7460362eek.0 for ; Tue, 11 Nov 2014 16:34:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=G662y5+8N6YjcDNLDhA5JTWwmIcKli4r9keBpyJs8do=; b=g33JnMnjzl6hc+hZ6yj3mXYkAZ2gKChySlMhog7RV/nhY1ftjkYIfk3AlYCmupFLh5 e9v5FI+zyeWuxhIvO4+UFCCejw5ubsbFDRkhWBN50zf9NUiS14jzYOj/9zEZHiGSYZNl Js8S3UB+jRpREavIxN8cstJ3DO+YZHn5/oUz4Q3Uk60RLz4i+/GTOZ6rtidXB65A/uzG cV/aOx3BfVZbWiswQCMI6/mLEz9khUkJ8WW5x+3PiukHzmFa5t1oNNiwELXTXWkYPS71 g9jqrXXIsgM8/93mQufW57YkgHs+J8Tl7KgtsHVsI+795ZnV/RS1AA56EKM8vmDDrG+n dlyw== X-Gm-Message-State: ALoCoQkPFAiVN4o8unfjsIa/eoknOyQgbr741C5UiwJC/vxIl0Jjz2dd3EXsiVOk9sqbR3oP2ux0 X-Received: by 10.180.219.40 with SMTP id pl8mr5927113wic.3.1415752440916; Tue, 11 Nov 2014 16:34:00 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.23.130 with SMTP id m2ls236322laf.63.gmail; Tue, 11 Nov 2014 16:34:00 -0800 (PST) X-Received: by 10.152.18.166 with SMTP id x6mr38451076lad.18.1415752440472; Tue, 11 Nov 2014 16:34:00 -0800 (PST) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com. [209.85.217.177]) by mx.google.com with ESMTPS id s2si33249905lag.22.2014.11.11.16.34.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Nov 2014 16:34:00 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) client-ip=209.85.217.177; Received: by mail-lb0-f177.google.com with SMTP id z12so1744198lbi.22 for ; Tue, 11 Nov 2014 16:34:00 -0800 (PST) X-Received: by 10.152.120.199 with SMTP id le7mr38415830lab.67.1415752440380; Tue, 11 Nov 2014 16:34:00 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp347606lbc; Tue, 11 Nov 2014 16:33:59 -0800 (PST) X-Received: by 10.229.252.201 with SMTP id mx9mr51894329qcb.4.1415752438806; Tue, 11 Nov 2014 16:33:58 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id y20si39214960qay.99.2014.11.11.16.33.58 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 11 Nov 2014 16:33:58 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:51613 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XoLsj-00060i-Ap for patch@linaro.org; Tue, 11 Nov 2014 19:33:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38053) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XoLla-00029x-V6 for qemu-devel@nongnu.org; Tue, 11 Nov 2014 19:26:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XoLlS-0000Gl-2C for qemu-devel@nongnu.org; Tue, 11 Nov 2014 19:26:34 -0500 Received: from mail-ob0-f174.google.com ([209.85.214.174]:60230) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XoLlR-0000Fs-S4 for qemu-devel@nongnu.org; Tue, 11 Nov 2014 19:26:25 -0500 Received: by mail-ob0-f174.google.com with SMTP id uz6so8342939obc.33 for ; Tue, 11 Nov 2014 16:26:25 -0800 (PST) X-Received: by 10.202.7.21 with SMTP id 21mr33211302oih.6.1415751985452; Tue, 11 Nov 2014 16:26:25 -0800 (PST) Received: from gbellows-linaro.bellowshome.net (99-179-1-128.lightspeed.austtx.sbcglobal.net. [99.179.1.128]) by mx.google.com with ESMTPSA id d3sm6239765obs.18.2014.11.11.16.26.24 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Nov 2014 16:26:25 -0800 (PST) From: Greg Bellows To: qemu-devel@nongnu.org, peter.maydell@linaro.org, christoffer.dall@linaro.org, alex.bennee@linaro.org Date: Tue, 11 Nov 2014 18:25:58 -0600 Message-Id: <1415751963-4081-11-git-send-email-greg.bellows@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1415751963-4081-1-git-send-email-greg.bellows@linaro.org> References: <1415751963-4081-1-git-send-email-greg.bellows@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.214.174 Cc: Greg Bellows Subject: [Qemu-devel] [PATCH v1 10/15] android-console: Add GF battery property getter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: greg.bellows@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Add a function for acquiring each of the goldfish battery properties. Signed-off-by: Greg Bellows --- android-commands.h | 7 +++++++ android-console.c | 20 ++++++++++++++++++ android-console.h | 1 + hw/misc/goldfish_battery.c | 42 ++++++++++++++++++++++++++++++++++++++ include/hw/misc/goldfish_battery.h | 1 + 5 files changed, 71 insertions(+) diff --git a/android-commands.h b/android-commands.h index 29c8769..8bf856d 100644 --- a/android-commands.h +++ b/android-commands.h @@ -26,6 +26,13 @@ static mon_cmd_t android_redir_cmds[] = { }; static mon_cmd_t android_power_cmds[] = { + { + .name = "display", + .args_type = "", + .params = "", + .help = "display battery and charger state", + .mhandler.cmd = android_console_power_display, + }, { NULL, NULL, }, }; diff --git a/android-console.c b/android-console.c index c08c607..faaeeaf 100644 --- a/android-console.c +++ b/android-console.c @@ -21,6 +21,7 @@ #include "net/slirp.h" #include "slirp/libslirp.h" #include "qmp-commands.h" +#include "hw/misc/goldfish_battery.h" typedef struct { int is_udp; @@ -298,19 +299,38 @@ void android_console_redir(Monitor *mon, const QDict *qdict) monitor_printf(mon, "%s\n", redir_help[cmd]); } +void android_console_power_display(Monitor *mon, const QDict *qdict) +{ + goldfish_battery_display(mon); + + monitor_printf(mon, "OK\n"); +} + enum { CMD_POWER, + CMD_POWER_DISPLAY, }; static const char *power_help[] = { /* CMD_POWER */ "allows to change battery and AC power status", + /* CMD_POWER_DISPLAY */ + "display battery and charger state", }; void android_console_power(Monitor *mon, const QDict *qdict) { + /* This only gets called for bad subcommands and help requests */ + const char *helptext = qdict_get_try_str(qdict, "helptext"); + /* Default to the first entry which is the parent help message */ int cmd = CMD_POWER; + if (helptext) { + if (strstr(helptext, "display")) { + cmd = CMD_POWER_DISPLAY; + } + } + monitor_printf(mon, "%s\n", power_help[cmd]); } diff --git a/android-console.h b/android-console.h index ba936be..44ff11b 100644 --- a/android-console.h +++ b/android-console.h @@ -28,6 +28,7 @@ void android_console_redir_list(Monitor *mon, const QDict *qdict); void android_console_redir_add(Monitor *mon, const QDict *qdict); void android_console_redir_del(Monitor *mon, const QDict *qdict); +void android_console_power_display(Monitor *mon, const QDict *qdict); void android_console_power(Monitor *mon, const QDict *qdict); void android_monitor_print_error(Monitor *mon, const char *fmt, ...); diff --git a/hw/misc/goldfish_battery.c b/hw/misc/goldfish_battery.c index c7c9d98..557bf7a 100644 --- a/hw/misc/goldfish_battery.c +++ b/hw/misc/goldfish_battery.c @@ -128,6 +128,48 @@ void goldfish_battery_display(Monitor *mon) monitor_printf(mon, "capacity: %d\n", s->capacity); } +void goldfish_battery_set_prop(int ac, int property, int value) +{ + DeviceState *dev = qdev_find_recursive(sysbus_get_default(), + TYPE_GOLDFISH_BATTERY); + struct goldfish_battery_state *battery_state = GOLDFISH_BATTERY(dev); + int new_status = (ac ? AC_STATUS_CHANGED : BATTERY_STATUS_CHANGED); + + if (!battery_state || !battery_state->hw_has_battery) { + return; + } + + if (ac) { + switch (property) { + case POWER_SUPPLY_PROP_ONLINE: + battery_state->ac_online = value; + break; + } + } else { + switch (property) { + case POWER_SUPPLY_PROP_STATUS: + battery_state->status = value; + break; + case POWER_SUPPLY_PROP_HEALTH: + battery_state->health = value; + break; + case POWER_SUPPLY_PROP_PRESENT: + battery_state->present = value; + break; + case POWER_SUPPLY_PROP_CAPACITY: + battery_state->capacity = value; + break; + } + } + + if (new_status != battery_state->int_status) { + battery_state->int_status |= new_status; + qemu_set_irq(battery_state->irq, + (battery_state->int_status & + battery_state->int_enable)); + } +} + static uint64_t goldfish_battery_read(void *opaque, hwaddr offset, unsigned size) { uint64_t ret; diff --git a/include/hw/misc/goldfish_battery.h b/include/hw/misc/goldfish_battery.h index f497538..2d02a38 100644 --- a/include/hw/misc/goldfish_battery.h +++ b/include/hw/misc/goldfish_battery.h @@ -69,5 +69,6 @@ enum power_supply_property { }; extern void goldfish_battery_display(Monitor *mon); +void goldfish_battery_set_prop(int ac, int property, int value); #endif /* _HW_GOLDFISH_BATTERY_H */