From: Greg Bellows <greg.bellows@linaro.org>
To: qemu-devel@nongnu.org, peter.maydell@linaro.org,
christoffer.dall@linaro.org, alex.bennee@linaro.org
Cc: Greg Bellows <greg.bellows@linaro.org>
Subject: [Qemu-devel] [PATCH v1 10/15] android-console: Add GF battery property getter
Date: Tue, 11 Nov 2014 18:25:58 -0600 [thread overview]
Message-ID: <1415751963-4081-11-git-send-email-greg.bellows@linaro.org> (raw)
In-Reply-To: <1415751963-4081-1-git-send-email-greg.bellows@linaro.org>
Add a function for acquiring each of the goldfish battery properties.
Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
---
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 */
--
1.8.3.2
next prev parent reply other threads:[~2014-11-12 0:26 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-12 0:25 [Qemu-devel] [PATCH v1 00/15] android-console: Add console power command Greg Bellows
2014-11-12 0:25 ` [Qemu-devel] [PATCH v1 01/15] android-console: Fix goldfish audio misnaming Greg Bellows
2014-11-13 10:01 ` Alex Bennée
2014-11-12 0:25 ` [Qemu-devel] [PATCH v1 02/15] android-console: Unify available commands output Greg Bellows
2014-11-12 0:25 ` [Qemu-devel] [PATCH v1 03/15] android-console: Remove extra redir help message Greg Bellows
2014-11-12 0:25 ` [Qemu-devel] [PATCH v1 04/15] android-console: Consolidate redir help text Greg Bellows
2014-11-12 0:25 ` [Qemu-devel] [PATCH v1 05/15] android-console: Add console base power command Greg Bellows
2014-11-12 0:25 ` [Qemu-devel] [PATCH v1 06/15] android-console: Add missing hw_has_battery prop Greg Bellows
2014-11-13 10:03 ` Alex Bennée
2014-11-12 0:25 ` [Qemu-devel] [PATCH v1 07/15] android-console: Init the battery ID state field Greg Bellows
2014-11-13 10:05 ` Alex Bennée
2014-11-12 0:25 ` [Qemu-devel] [PATCH v1 08/15] android-console: Add header for battery externs Greg Bellows
2014-11-12 0:25 ` [Qemu-devel] [PATCH v1 09/15] android-console: Add GF battery prop print func Greg Bellows
2014-11-12 0:25 ` Greg Bellows [this message]
2014-11-12 0:25 ` [Qemu-devel] [PATCH v1 11/15] android-console: Add power ac command Greg Bellows
2014-11-12 0:26 ` [Qemu-devel] [PATCH v1 12/15] android-console: Add power status command Greg Bellows
2014-11-12 0:26 ` [Qemu-devel] [PATCH v1 13/15] android-console: Add power present command Greg Bellows
2014-11-12 0:26 ` [Qemu-devel] [PATCH v1 14/15] android-console: Add power health command Greg Bellows
2014-11-12 0:26 ` [Qemu-devel] [PATCH v1 15/15] android-console: Add power capacity command Greg Bellows
2014-11-13 10:17 ` Alex Bennée
2014-11-12 13:39 ` [Qemu-devel] [PATCH v1 00/15] android-console: Add console power command Greg Bellows
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1415751963-4081-11-git-send-email-greg.bellows@linaro.org \
--to=greg.bellows@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=christoffer.dall@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).