qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v1 00/15] android-console: Add console power command
@ 2014-11-12  0:25 Greg Bellows
  2014-11-12  0:25 ` [Qemu-devel] [PATCH v1 01/15] android-console: Fix goldfish audio misnaming Greg Bellows
                   ` (15 more replies)
  0 siblings, 16 replies; 21+ messages in thread
From: Greg Bellows @ 2014-11-12  0:25 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, christoffer.dall, alex.bennee; +Cc: Greg Bellows

This patchset includes 3 changes:
- Fixes to the existing Android emulator console.
- Restructure the emulator console redir help output
- Add support for the emulator console power command

Greg Bellows (15):
  android-console: Fix goldfish audio misnaming
  android-console: Unify available commands output
  android-console: Remove extra redir help message
  android-console: Consolidate redir help text
  android-console: Add console base power command
  android-console: Add missing hw_has_battery prop
  android-console: Init the battery ID state field
  android-console: Add header for battery externs
  android-console: Add GF battery prop print func
  android-console: Add GF battery property getter
  android-console: Add power ac command
  android-console: Add power status command
  android-console: Add power present command
  android-console: Add power health command
  android-console: Add power capacity command

 android-commands.h                 |  53 ++++++++
 android-console.c                  | 254 ++++++++++++++++++++++++++++++++-----
 android-console.h                  |   8 ++
 hw/misc/goldfish_battery.c         | 122 ++++++++++++++++--
 include/hw/misc/goldfish_battery.h |  74 +++++++++++
 monitor.c                          |  16 ++-
 6 files changed, 484 insertions(+), 43 deletions(-)
 create mode 100644 include/hw/misc/goldfish_battery.h

--
1.8.3.2

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v1 01/15] android-console: Fix goldfish audio misnaming
  2014-11-12  0:25 [Qemu-devel] [PATCH v1 00/15] android-console: Add console power command Greg Bellows
@ 2014-11-12  0:25 ` 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
                   ` (14 subsequent siblings)
  15 siblings, 1 reply; 21+ messages in thread
From: Greg Bellows @ 2014-11-12  0:25 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, christoffer.dall, alex.bennee; +Cc: Greg Bellows

Replaced goldfish_audio misnaming to goldfish_battery where appropriate in
goldfish_battery.c

Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
---
 hw/misc/goldfish_battery.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/hw/misc/goldfish_battery.c b/hw/misc/goldfish_battery.c
index 03847d6..89fd05d 100644
--- a/hw/misc/goldfish_battery.c
+++ b/hw/misc/goldfish_battery.c
@@ -121,7 +121,7 @@ static void goldfish_battery_write(void *opaque, hwaddr offset, uint64_t val,
             break;
 
         default:
-            error_report ("goldfish_audio_write: Bad offset " TARGET_FMT_plx,
+            error_report("goldfish_battery_write: Bad offset " TARGET_FMT_plx,
                     offset);
     }
 }
@@ -161,16 +161,16 @@ static void goldfish_battery_class_init(ObjectClass *klass, void *data)
     dc->desc = "goldfish battery";
 }
 
-static const TypeInfo goldfish_audio_info = {
+static const TypeInfo goldfish_battery_info = {
     .name          = TYPE_GOLDFISH_BATTERY,
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(struct goldfish_battery_state),
     .class_init    = goldfish_battery_class_init,
 };
 
-static void goldfish_audio_register(void)
+static void goldfish_battery_register(void)
 {
-    type_register_static(&goldfish_audio_info);
+    type_register_static(&goldfish_battery_info);
 }
 
-type_init(goldfish_audio_register);
+type_init(goldfish_battery_register);
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v1 02/15] android-console: Unify available commands output
  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-12  0:25 ` Greg Bellows
  2014-11-12  0:25 ` [Qemu-devel] [PATCH v1 03/15] android-console: Remove extra redir help message Greg Bellows
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 21+ messages in thread
From: Greg Bellows @ 2014-11-12  0:25 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, christoffer.dall, alex.bennee; +Cc: Greg Bellows

Moved the "available commands" print output to the top level help command
handler to avoid repitition across all commands with sub-commands.  Adjusted
the redir command handler to no longer print out available commands.
Adjusted "OK" message to be shared by all cases to avoid duplicates.

Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
---
 android-console.c | 20 +++++---------------
 monitor.c         | 16 ++++++++++++----
 2 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/android-console.c b/android-console.c
index c2e41da..be573b5 100644
--- a/android-console.c
+++ b/android-console.c
@@ -242,8 +242,7 @@ void android_console_redir_remove(Monitor *mon, const QDict *qdict)
 
 static const char *redir_list_help =
     "list current port redirections. "
-    "use 'redir add' and 'redir del' to add and remove them\n"
-    "OK\n";
+    "use 'redir add' and 'redir del' to add and remove them\n";
 
 static const char *redir_add_help =
     "add a new port redirection, arguments must be:\n"
@@ -258,15 +257,13 @@ static const char *redir_add_help =
     "\n"
     "as an example, 'redir  tcp:5000:6000' will allow any packets sent to\n"
     "the host's TCP port 5000 to be routed to TCP port 6000 of the "
-    "emulated device\n"
-    "OK\n";
+    "emulated device\n";
 
 static const char *redir_del_help =
     "remove a port redirecion that was created with 'redir add', "
-    "arguments must be:\n\n"
+    "arguments must be:\n"
     "  redir  del <protocol>:<host-port>\n\n"
-    "see the 'help redir add' for the meaning of <protocol> and <host-port>\n"
-    "OK\n";
+    "see the 'help redir add' for the meaning of <protocol> and <host-port>\n";
 
 void android_console_redir(Monitor *mon, const QDict *qdict)
 {
@@ -291,12 +288,5 @@ void android_console_redir(Monitor *mon, const QDict *qdict)
                    "PORT redirection from the host to the device\n"
                    "as an example, 'redir  tcp:5000:6000' will route "
                    "any packet sent to the host's TCP port 5000\n"
-                   "to TCP port 6000 of the emulated device\n"
-                   "\n"
-                   "available sub-commands:\n"
-                   "    list             list current redirections\n"
-                   "    add              add new redirection\n"
-                   "    del              remove existing redirection\n"
-                   "\n%s\n",
-                   helptext ? "OK" : "KO: missing sub-command");
+                   "to TCP port 6000 of the emulated device\n");
 }
diff --git a/monitor.c b/monitor.c
index f071878..4222b7a 100644
--- a/monitor.c
+++ b/monitor.c
@@ -943,7 +943,7 @@ static void do_help_cmd(Monitor *mon, const QDict *qdict)
 static void android_console_help(Monitor *mon, const QDict *qdict)
 {
     const char *name = qdict_get_try_str(qdict, "helptext");
-    const mon_cmd_t *cmd;
+    const mon_cmd_t *cmd, *subcmd;
     const mon_cmd_t *cmds = mon->cmd_table;
     char *args[MAX_ARGS];
     int nb_args = 0;
@@ -957,7 +957,7 @@ static void android_console_help(Monitor *mon, const QDict *qdict)
             monitor_printf(mon, "    %-15s  %s\n", cmd->name, cmd->help);
         }
         monitor_printf(mon,
-                       "\ntry 'help <command>' for command-specific help\n");
+                       "\ntry 'help <command>' for command-specific help\nOK\n");
         return;
     }
 
@@ -1000,15 +1000,23 @@ static void android_console_help(Monitor *mon, const QDict *qdict)
                 parent_cmd->mhandler.cmd(mon, qdict);
             } else if (cmd->sub_table) {
                 cmd->mhandler.cmd(mon, qdict);
+                monitor_printf(mon, "\navailable sub-commands:\n");
+                for (subcmd = cmd->sub_table; subcmd->name; subcmd++) {
+                    monitor_printf(mon, "    %-15s  %s\n",
+                                    subcmd->name, subcmd->help);
+                }
+                monitor_printf(mon, "\n");
             } else {
-                monitor_printf(mon, "%s\nOK\n", cmd->help);
+                monitor_printf(mon, "%s\n", cmd->help);
             }
-            return;
+            break;
         }
 
         parent_cmd = cmd;
         cmds = cmd->sub_table;
     }
+
+    monitor_printf(mon, "OK\n");
 }
 
 static void do_trace_event_set_state(Monitor *mon, const QDict *qdict)
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v1 03/15] android-console: Remove extra redir help message
  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-12  0:25 ` [Qemu-devel] [PATCH v1 02/15] android-console: Unify available commands output Greg Bellows
@ 2014-11-12  0:25 ` Greg Bellows
  2014-11-12  0:25 ` [Qemu-devel] [PATCH v1 04/15] android-console: Consolidate redir help text Greg Bellows
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 21+ messages in thread
From: Greg Bellows @ 2014-11-12  0:25 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, christoffer.dall, alex.bennee; +Cc: Greg Bellows

Removed an extraneous message in the redir command help.  The message is not
part of the standard Android emulator output.

Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
---
 android-console.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/android-console.c b/android-console.c
index be573b5..2de4a0c 100644
--- a/android-console.c
+++ b/android-console.c
@@ -270,8 +270,6 @@ void android_console_redir(Monitor *mon, const QDict *qdict)
     /* This only gets called for bad subcommands and help requests */
     const char *helptext = qdict_get_try_str(qdict, "helptext");
 
-    monitor_printf(mon, "help text %s\n", helptext ? helptext : "(null)");
-
     if (helptext) {
         if (strstr(helptext, "add")) {
             monitor_printf(mon, "%s", redir_add_help);
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v1 04/15] android-console: Consolidate redir help text
  2014-11-12  0:25 [Qemu-devel] [PATCH v1 00/15] android-console: Add console power command Greg Bellows
                   ` (2 preceding siblings ...)
  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 ` Greg Bellows
  2014-11-12  0:25 ` [Qemu-devel] [PATCH v1 05/15] android-console: Add console base power command Greg Bellows
                   ` (11 subsequent siblings)
  15 siblings, 0 replies; 21+ messages in thread
From: Greg Bellows @ 2014-11-12  0:25 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, christoffer.dall, alex.bennee; +Cc: Greg Bellows

Consolidated the Android emulator console help text for the redir command to
make the hndler functions more readable.  This establishes the pattern to be
used for each command added in the future.

Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
---
 android-console.c | 50 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 30 insertions(+), 20 deletions(-)

diff --git a/android-console.c b/android-console.c
index 2de4a0c..0be5949 100644
--- a/android-console.c
+++ b/android-console.c
@@ -240,11 +240,24 @@ void android_console_redir_remove(Monitor *mon, const QDict *qdict)
 }
 #endif
 
-static const char *redir_list_help =
-    "list current port redirections. "
-    "use 'redir add' and 'redir del' to add and remove them\n";
-
-static const char *redir_add_help =
+enum {
+    CMD_REDIR,
+    CMD_REDIR_LIST,
+    CMD_REDIR_ADD,
+    CMD_REDIR_DEL,
+};
+
+static const char *redir_help[] = {
+    /* CMD_REDIR */
+    "allows you to add, list and remove UDP and/or PORT redirection "
+    "from the host to the device\n"
+    "as an example, 'redir  tcp:5000:6000' will route any packet sent "
+    "to the host's TCP port 5000\n"
+    "to TCP port 6000 of the emulated device",
+    /* CMD_REDIR_LIST */
+    "list current port redirections. use 'redir add' and 'redir del' to add "
+    "and remove them",
+    /* CMD_REDIR_ADD */
     "add a new port redirection, arguments must be:\n"
     "\n"
     "  redir add <protocol>:<host-port>:<guest-port>\n"
@@ -257,34 +270,31 @@ static const char *redir_add_help =
     "\n"
     "as an example, 'redir  tcp:5000:6000' will allow any packets sent to\n"
     "the host's TCP port 5000 to be routed to TCP port 6000 of the "
-    "emulated device\n";
-
-static const char *redir_del_help =
+    "emulated device",
+    /* CMD_REDIR_DEL */
     "remove a port redirecion that was created with 'redir add', "
     "arguments must be:\n"
     "  redir  del <protocol>:<host-port>\n\n"
-    "see the 'help redir add' for the meaning of <protocol> and <host-port>\n";
+    "see the 'help redir add' for the meaning of <protocol> and <host-port>",
+};
 
 void android_console_redir(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_REDIR;
+
     if (helptext) {
         if (strstr(helptext, "add")) {
-            monitor_printf(mon, "%s", redir_add_help);
-            return;
+            cmd = CMD_REDIR_ADD;
         } else if (strstr(helptext, "del")) {
-            monitor_printf(mon, "%s", redir_del_help);
-            return;
+            cmd = CMD_REDIR_DEL;
         } else if (strstr(helptext, "list")) {
-            monitor_printf(mon, "%s", redir_list_help);
-            return;
+            cmd = CMD_REDIR_LIST;
         }
     }
-    monitor_printf(mon, "allows you to add, list and remove and/or "
-                   "PORT redirection from the host to the device\n"
-                   "as an example, 'redir  tcp:5000:6000' will route "
-                   "any packet sent to the host's TCP port 5000\n"
-                   "to TCP port 6000 of the emulated device\n");
+    monitor_printf(mon, "%s\n", redir_help[cmd]);
 }
+
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v1 05/15] android-console: Add console base power command
  2014-11-12  0:25 [Qemu-devel] [PATCH v1 00/15] android-console: Add console power command Greg Bellows
                   ` (3 preceding siblings ...)
  2014-11-12  0:25 ` [Qemu-devel] [PATCH v1 04/15] android-console: Consolidate redir help text Greg Bellows
@ 2014-11-12  0:25 ` Greg Bellows
  2014-11-12  0:25 ` [Qemu-devel] [PATCH v1 06/15] android-console: Add missing hw_has_battery prop Greg Bellows
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 21+ messages in thread
From: Greg Bellows @ 2014-11-12  0:25 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, christoffer.dall, alex.bennee; +Cc: Greg Bellows

Added the base Android emulator console power command and infrastructure for
adding sub-commands.

Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
---
 android-commands.h | 11 +++++++++++
 android-console.c  | 16 ++++++++++++++++
 android-console.h  |  2 ++
 3 files changed, 29 insertions(+)

diff --git a/android-commands.h b/android-commands.h
index 1bfd15d..29c8769 100644
--- a/android-commands.h
+++ b/android-commands.h
@@ -25,6 +25,10 @@ static mon_cmd_t android_redir_cmds[] = {
     { NULL, NULL, },
 };
 
+static mon_cmd_t android_power_cmds[] = {
+    { NULL, NULL, },
+};
+
 static mon_cmd_t android_cmds[] = {
     {
         .name = "help|h|?",
@@ -55,5 +59,12 @@ static mon_cmd_t android_cmds[] = {
         .mhandler.cmd = android_console_redir,
         .sub_table = android_redir_cmds,
     },
+    {   .name = "power",
+        .args_type = "item:s?",
+        .params = "",
+        .help = "power related commands",
+        .mhandler.cmd = android_console_power,
+        .sub_table = android_power_cmds,
+    },
     { NULL, NULL, },
 };
diff --git a/android-console.c b/android-console.c
index 0be5949..c08c607 100644
--- a/android-console.c
+++ b/android-console.c
@@ -298,3 +298,19 @@ void android_console_redir(Monitor *mon, const QDict *qdict)
     monitor_printf(mon, "%s\n", redir_help[cmd]);
 }
 
+enum {
+    CMD_POWER,
+};
+
+static const char *power_help[] = {
+        /* CMD_POWER */
+        "allows to change battery and AC power status",
+};
+
+void android_console_power(Monitor *mon, const QDict *qdict)
+{
+    /* Default to the first entry which is the parent help message */
+    int cmd = CMD_POWER;
+
+    monitor_printf(mon, "%s\n", power_help[cmd]);
+}
diff --git a/android-console.h b/android-console.h
index 2786b64..ba936be 100644
--- a/android-console.h
+++ b/android-console.h
@@ -28,6 +28,8 @@ 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(Monitor *mon, const QDict *qdict);
+
 void android_monitor_print_error(Monitor *mon, const char *fmt, ...);
 
 #endif
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v1 06/15] android-console: Add missing hw_has_battery prop
  2014-11-12  0:25 [Qemu-devel] [PATCH v1 00/15] android-console: Add console power command Greg Bellows
                   ` (4 preceding siblings ...)
  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 ` 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
                   ` (9 subsequent siblings)
  15 siblings, 1 reply; 21+ messages in thread
From: Greg Bellows @ 2014-11-12  0:25 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, christoffer.dall, alex.bennee; +Cc: Greg Bellows

Added the missing hw_has_battery property to the Goldfish batter state.  This
property indicates whether the device has a battery and controls whether some
power commands are available.

In the Android emulator this property is acquired from the AVD for the device.
For now, this is wired as always enabled.

Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
---
 hw/misc/goldfish_battery.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/hw/misc/goldfish_battery.c b/hw/misc/goldfish_battery.c
index 89fd05d..a0bc379 100644
--- a/hw/misc/goldfish_battery.c
+++ b/hw/misc/goldfish_battery.c
@@ -52,6 +52,7 @@ struct goldfish_battery_state {
     uint32_t health;
     uint32_t present;
     uint32_t capacity;
+    uint32_t hw_has_battery;;
 };
 
 /* update this each time you update the battery_state struct */
@@ -70,6 +71,7 @@ static const VMStateDescription goldfish_battery_vmsd = {
         VMSTATE_UINT32(health, struct goldfish_battery_state),
         VMSTATE_UINT32(present, struct goldfish_battery_state),
         VMSTATE_UINT32(capacity, struct goldfish_battery_state),
+        VMSTATE_UINT32(hw_has_battery, struct goldfish_battery_state),
         VMSTATE_END_OF_LIST()
     }
 };
@@ -146,6 +148,11 @@ static void goldfish_battery_realize(DeviceState *dev, Error **errp)
 
     // default values for the battery
     s->ac_online = 1;
+    /* TODO: The Android Emulator gets this attribute from the AVD
+     *       hw-config-defs.h.  For now we hard-code the value to match the
+     *       other values.
+     */
+    s->hw_has_battery = 1;
     s->status = POWER_SUPPLY_STATUS_CHARGING;
     s->health = POWER_SUPPLY_HEALTH_GOOD;
     s->present = 1;     // battery is present
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v1 07/15] android-console: Init the battery ID state field
  2014-11-12  0:25 [Qemu-devel] [PATCH v1 00/15] android-console: Add console power command Greg Bellows
                   ` (5 preceding siblings ...)
  2014-11-12  0:25 ` [Qemu-devel] [PATCH v1 06/15] android-console: Add missing hw_has_battery prop Greg Bellows
@ 2014-11-12  0:25 ` 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
                   ` (8 subsequent siblings)
  15 siblings, 1 reply; 21+ messages in thread
From: Greg Bellows @ 2014-11-12  0:25 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, christoffer.dall, alex.bennee; +Cc: Greg Bellows

Adds initialization of the battery ID field so that it is discoverable by name
(ID) when needed by power commands.

Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
---
 hw/misc/goldfish_battery.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/misc/goldfish_battery.c b/hw/misc/goldfish_battery.c
index a0bc379..11a2561 100644
--- a/hw/misc/goldfish_battery.c
+++ b/hw/misc/goldfish_battery.c
@@ -141,6 +141,11 @@ static void goldfish_battery_realize(DeviceState *dev, Error **errp)
     SysBusDevice *sbdev = SYS_BUS_DEVICE(dev);
     struct goldfish_battery_state *s = GOLDFISH_BATTERY(dev);
 
+    /* Initialize the device ID so the battery can be looked up during monitor
+     * commands.
+     */
+    dev->id = strdup("goldfish_battery");
+
     memory_region_init_io(&s->iomem, OBJECT(s), &goldfish_battery_iomem_ops, s,
             "goldfish_battery", 0x1000);
     sysbus_init_mmio(sbdev, &s->iomem);
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v1 08/15] android-console: Add header for battery externs
  2014-11-12  0:25 [Qemu-devel] [PATCH v1 00/15] android-console: Add console power command Greg Bellows
                   ` (6 preceding siblings ...)
  2014-11-12  0:25 ` [Qemu-devel] [PATCH v1 07/15] android-console: Init the battery ID state field Greg Bellows
@ 2014-11-12  0:25 ` Greg Bellows
  2014-11-12  0:25 ` [Qemu-devel] [PATCH v1 09/15] android-console: Add GF battery prop print func Greg Bellows
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 21+ messages in thread
From: Greg Bellows @ 2014-11-12  0:25 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, christoffer.dall, alex.bennee; +Cc: Greg Bellows

Added goldfish_battery.h to share power and battery constants and externs
between the Goldfish battery code and the Android console code.

Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
---
 hw/misc/goldfish_battery.c         |  4 +--
 include/hw/misc/goldfish_battery.h | 71 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 3 deletions(-)
 create mode 100644 include/hw/misc/goldfish_battery.h

diff --git a/hw/misc/goldfish_battery.c b/hw/misc/goldfish_battery.c
index 11a2561..c956eb2 100644
--- a/hw/misc/goldfish_battery.c
+++ b/hw/misc/goldfish_battery.c
@@ -12,6 +12,7 @@
 #include "hw/hw.h"
 #include "hw/sysbus.h"
 #include "qemu/error-report.h"
+#include "hw/misc/goldfish_battery.h"
 
 enum {
 	/* status register */
@@ -30,9 +31,6 @@ enum {
 	BATTERY_INT_MASK        = BATTERY_STATUS_CHANGED | AC_STATUS_CHANGED,
 };
 
-const uint32_t POWER_SUPPLY_STATUS_CHARGING = 1;
-const uint32_t POWER_SUPPLY_HEALTH_GOOD = 1;
-
 #define TYPE_GOLDFISH_BATTERY "goldfish_battery"
 #define GOLDFISH_BATTERY(obj) OBJECT_CHECK(struct goldfish_battery_state, (obj), TYPE_GOLDFISH_BATTERY)
 
diff --git a/include/hw/misc/goldfish_battery.h b/include/hw/misc/goldfish_battery.h
new file mode 100644
index 0000000..85a9f2f
--- /dev/null
+++ b/include/hw/misc/goldfish_battery.h
@@ -0,0 +1,71 @@
+/* Copyright (C) 2007-2013 The Android Open Source Project
+**
+** This software is licensed under the terms of the GNU General Public
+** License version 2, as published by the Free Software Foundation, and
+** may be copied, distributed, and modified under those terms.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+*/
+#ifndef _HW_GOLDFISH_BATTERY_H
+#define _HW_GOLDFISH_BATTERY_H
+
+enum {
+    POWER_SUPPLY_STATUS_UNKNOWN = 0,
+    POWER_SUPPLY_STATUS_CHARGING,
+    POWER_SUPPLY_STATUS_DISCHARGING,
+    POWER_SUPPLY_STATUS_NOT_CHARGING,
+    POWER_SUPPLY_STATUS_FULL,
+};
+
+enum {
+    POWER_SUPPLY_HEALTH_UNKNOWN = 0,
+    POWER_SUPPLY_HEALTH_GOOD,
+    POWER_SUPPLY_HEALTH_OVERHEAT,
+    POWER_SUPPLY_HEALTH_DEAD,
+    POWER_SUPPLY_HEALTH_OVERVOLTAGE,
+    POWER_SUPPLY_HEALTH_UNSPEC_FAILURE,
+};
+
+
+enum power_supply_property {
+    /* Properties of type `int' */
+    POWER_SUPPLY_PROP_STATUS = 0,
+    POWER_SUPPLY_PROP_HEALTH,
+    POWER_SUPPLY_PROP_PRESENT,
+    POWER_SUPPLY_PROP_ONLINE,
+    POWER_SUPPLY_PROP_TECHNOLOGY,
+    POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
+    POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
+    POWER_SUPPLY_PROP_VOLTAGE_NOW,
+    POWER_SUPPLY_PROP_VOLTAGE_AVG,
+    POWER_SUPPLY_PROP_CURRENT_NOW,
+    POWER_SUPPLY_PROP_CURRENT_AVG,
+    POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
+    POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN,
+    POWER_SUPPLY_PROP_CHARGE_FULL,
+    POWER_SUPPLY_PROP_CHARGE_EMPTY,
+    POWER_SUPPLY_PROP_CHARGE_NOW,
+    POWER_SUPPLY_PROP_CHARGE_AVG,
+    POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
+    POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN,
+    POWER_SUPPLY_PROP_ENERGY_FULL,
+    POWER_SUPPLY_PROP_ENERGY_EMPTY,
+    POWER_SUPPLY_PROP_ENERGY_NOW,
+    POWER_SUPPLY_PROP_ENERGY_AVG,
+    POWER_SUPPLY_PROP_CAPACITY, /* in percents! */
+    POWER_SUPPLY_PROP_CAPACITY_LEVEL,
+    POWER_SUPPLY_PROP_TEMP,
+    POWER_SUPPLY_PROP_TEMP_AMBIENT,
+    POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
+    POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
+    POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
+    POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
+    /* Properties of type `const char *' */
+    POWER_SUPPLY_PROP_MODEL_NAME,
+    POWER_SUPPLY_PROP_MANUFACTURER,
+};
+
+#endif /* _HW_GOLDFISH_BATTERY_H */
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v1 09/15] android-console: Add GF battery prop print func
  2014-11-12  0:25 [Qemu-devel] [PATCH v1 00/15] android-console: Add console power command Greg Bellows
                   ` (7 preceding siblings ...)
  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 ` Greg Bellows
  2014-11-12  0:25 ` [Qemu-devel] [PATCH v1 10/15] android-console: Add GF battery property getter Greg Bellows
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 21+ messages in thread
From: Greg Bellows @ 2014-11-12  0:25 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, christoffer.dall, alex.bennee; +Cc: Greg Bellows

Add a function for printing out the Goldfish battery properties to the android
console.

Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
---
 hw/misc/goldfish_battery.c         | 54 ++++++++++++++++++++++++++++++++++++++
 include/hw/misc/goldfish_battery.h |  2 ++
 2 files changed, 56 insertions(+)

diff --git a/hw/misc/goldfish_battery.c b/hw/misc/goldfish_battery.c
index c956eb2..c7c9d98 100644
--- a/hw/misc/goldfish_battery.c
+++ b/hw/misc/goldfish_battery.c
@@ -12,6 +12,7 @@
 #include "hw/hw.h"
 #include "hw/sysbus.h"
 #include "qemu/error-report.h"
+#include "monitor/monitor.h"
 #include "hw/misc/goldfish_battery.h"

 enum {
@@ -74,6 +75,59 @@ static const VMStateDescription goldfish_battery_vmsd = {
     }
 };

+void goldfish_battery_display(Monitor *mon)
+{
+    DeviceState *dev = qdev_find_recursive(sysbus_get_default(),
+                                           TYPE_GOLDFISH_BATTERY);
+    struct goldfish_battery_state *s = GOLDFISH_BATTERY(dev);
+    const char *value;
+
+    monitor_printf(mon, "AC: %s\n", (s->ac_online) ? "online" : "offline");
+
+    switch (s->status) {
+    case POWER_SUPPLY_STATUS_CHARGING:
+        value = "Charging";
+        break;
+    case POWER_SUPPLY_STATUS_DISCHARGING:
+        value = "Discharging";
+        break;
+    case POWER_SUPPLY_STATUS_NOT_CHARGING:
+        value = "Not charging";
+        break;
+    case POWER_SUPPLY_STATUS_FULL:
+        value = "Full";
+        break;
+    default:
+        value = "Unknown";
+    }
+    monitor_printf(mon, "status: %s\n", value);
+
+    switch (s->health) {
+    case POWER_SUPPLY_HEALTH_GOOD:
+        value = "Good";
+        break;
+    case POWER_SUPPLY_HEALTH_OVERHEAT:
+        value = "Overhead";
+        break;
+    case POWER_SUPPLY_HEALTH_DEAD:
+        value = "Dead";
+        break;
+    case POWER_SUPPLY_HEALTH_OVERVOLTAGE:
+        value = "Overvoltage";
+        break;
+    case POWER_SUPPLY_HEALTH_UNSPEC_FAILURE:
+        value = "Unspecified failure";
+        break;
+    default:
+        value = "Unknown";
+    }
+    monitor_printf(mon, "health: %s\n", value);
+
+    monitor_printf(mon, "present: %s\n", (s->present) ? "true" : "false");
+
+    monitor_printf(mon, "capacity: %d\n", s->capacity);
+}
+
 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 85a9f2f..f497538 100644
--- a/include/hw/misc/goldfish_battery.h
+++ b/include/hw/misc/goldfish_battery.h
@@ -68,4 +68,6 @@ enum power_supply_property {
     POWER_SUPPLY_PROP_MANUFACTURER,
 };

+extern void goldfish_battery_display(Monitor *mon);
+
 #endif /* _HW_GOLDFISH_BATTERY_H */
--
1.8.3.2

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v1 10/15] android-console: Add GF battery property getter
  2014-11-12  0:25 [Qemu-devel] [PATCH v1 00/15] android-console: Add console power command Greg Bellows
                   ` (8 preceding siblings ...)
  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
  2014-11-12  0:25 ` [Qemu-devel] [PATCH v1 11/15] android-console: Add power ac command Greg Bellows
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 21+ messages in thread
From: Greg Bellows @ 2014-11-12  0:25 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, christoffer.dall, alex.bennee; +Cc: Greg Bellows

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

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v1 11/15] android-console: Add power ac command
  2014-11-12  0:25 [Qemu-devel] [PATCH v1 00/15] android-console: Add console power command Greg Bellows
                   ` (9 preceding siblings ...)
  2014-11-12  0:25 ` [Qemu-devel] [PATCH v1 10/15] android-console: Add GF battery property getter Greg Bellows
@ 2014-11-12  0:25 ` Greg Bellows
  2014-11-12  0:26 ` [Qemu-devel] [PATCH v1 12/15] android-console: Add power status command Greg Bellows
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 21+ messages in thread
From: Greg Bellows @ 2014-11-12  0:25 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, christoffer.dall, alex.bennee; +Cc: Greg Bellows

Add the Android emulator console "power ac" along with the associated help
messages.  The "ac" command allows the power supply state of the device to be
manipulated.

Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
---
 android-commands.h |  7 +++++++
 android-console.c  | 23 +++++++++++++++++++++++
 android-console.h  |  1 +
 3 files changed, 31 insertions(+)

diff --git a/android-commands.h b/android-commands.h
index 8bf856d..674e259 100644
--- a/android-commands.h
+++ b/android-commands.h
@@ -33,6 +33,13 @@ static mon_cmd_t android_power_cmds[] = {
         .help = "display battery and charger state",
         .mhandler.cmd = android_console_power_display,
     },
+    {
+        .name = "ac",
+        .args_type = "arg:s?",
+        .params = "",
+        .help = "set AC charging state",
+        .mhandler.cmd = android_console_power_ac,
+    },
     { NULL, NULL, },
 };
 
diff --git a/android-console.c b/android-console.c
index faaeeaf..dbcc993 100644
--- a/android-console.c
+++ b/android-console.c
@@ -306,9 +306,28 @@ void android_console_power_display(Monitor *mon, const QDict *qdict)
     monitor_printf(mon, "OK\n");
 }
 
+void android_console_power_ac(Monitor *mon, const QDict *qdict)
+{
+    const char *arg = qdict_get_try_str(qdict, "arg");
+
+    if (arg) {
+        if (strcasecmp(arg, "on") == 0) {
+            goldfish_battery_set_prop(1, POWER_SUPPLY_PROP_ONLINE, 1);
+            return;
+        }
+        if (strcasecmp(arg, "off") == 0) {
+            goldfish_battery_set_prop(1, POWER_SUPPLY_PROP_ONLINE, 0);
+            return;
+        }
+    }
+
+    monitor_printf(mon, "KO: Usage: \"ac on\" or \"ac off\"\n");
+}
+
 enum {
     CMD_POWER,
     CMD_POWER_DISPLAY,
+    CMD_POWER_AC,
 };
 
 static const char *power_help[] = {
@@ -316,6 +335,8 @@ static const char *power_help[] = {
         "allows to change battery and AC power status",
         /* CMD_POWER_DISPLAY */
         "display battery and charger state",
+        /* CMD_POWER_AC */
+        "'ac on|off' allows you to set the AC charging state to on or off",
 };
 
 void android_console_power(Monitor *mon, const QDict *qdict)
@@ -329,6 +350,8 @@ void android_console_power(Monitor *mon, const QDict *qdict)
     if (helptext) {
         if (strstr(helptext, "display")) {
             cmd = CMD_POWER_DISPLAY;
+        } else if (strstr(helptext, "ac")) {
+            cmd = CMD_POWER_AC;
         }
     }
 
diff --git a/android-console.h b/android-console.h
index 44ff11b..458f44c 100644
--- a/android-console.h
+++ b/android-console.h
@@ -29,6 +29,7 @@ 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_ac(Monitor *mon, const QDict *qdict);
 void android_console_power(Monitor *mon, const QDict *qdict);
 
 void android_monitor_print_error(Monitor *mon, const char *fmt, ...);
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v1 12/15] android-console: Add power status command
  2014-11-12  0:25 [Qemu-devel] [PATCH v1 00/15] android-console: Add console power command Greg Bellows
                   ` (10 preceding siblings ...)
  2014-11-12  0:25 ` [Qemu-devel] [PATCH v1 11/15] android-console: Add power ac command Greg Bellows
@ 2014-11-12  0:26 ` Greg Bellows
  2014-11-12  0:26 ` [Qemu-devel] [PATCH v1 13/15] android-console: Add power present command Greg Bellows
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 21+ messages in thread
From: Greg Bellows @ 2014-11-12  0:26 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, christoffer.dall, alex.bennee; +Cc: Greg Bellows

Add the Android emulator console "power status" command and associated help
messages.  The "status" command allows the battery status of the device to be
manipulated.

Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
---
 android-commands.h |  7 +++++++
 android-console.c  | 39 +++++++++++++++++++++++++++++++++++++++
 android-console.h  |  1 +
 3 files changed, 47 insertions(+)

diff --git a/android-commands.h b/android-commands.h
index 674e259..53f89b1 100644
--- a/android-commands.h
+++ b/android-commands.h
@@ -40,6 +40,13 @@ static mon_cmd_t android_power_cmds[] = {
         .help = "set AC charging state",
         .mhandler.cmd = android_console_power_ac,
     },
+    {
+        .name = "status",
+        .args_type = "arg:s?",
+        .params = "",
+        .help = "set battery status",
+        .mhandler.cmd = android_console_power_status,
+    },
     { NULL, NULL, },
 };
 
diff --git a/android-console.c b/android-console.c
index dbcc993..04a1971 100644
--- a/android-console.c
+++ b/android-console.c
@@ -324,10 +324,44 @@ void android_console_power_ac(Monitor *mon, const QDict *qdict)
     monitor_printf(mon, "KO: Usage: \"ac on\" or \"ac off\"\n");
 }
 
+void android_console_power_status(Monitor *mon, const QDict *qdict)
+{
+    const char *arg = qdict_get_try_str(qdict, "arg");
+
+    if (arg) {
+        if (strcasecmp(arg, "unknown") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_STATUS,
+                                      POWER_SUPPLY_STATUS_UNKNOWN);
+            return;
+        } else if (strcasecmp(arg, "charging") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_STATUS,
+                                      POWER_SUPPLY_STATUS_CHARGING);
+            return;
+        } else if (strcasecmp(arg, "discharging") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_STATUS,
+                                      POWER_SUPPLY_STATUS_DISCHARGING);
+            return;
+        } else if (strcasecmp(arg, "not-charging") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_STATUS,
+                                      POWER_SUPPLY_STATUS_NOT_CHARGING);
+            return;
+        } else if (strcasecmp(arg, "full") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_STATUS,
+                                      POWER_SUPPLY_STATUS_FULL);
+            return;
+        }
+    }
+
+    monitor_printf(mon, "KO: Usage: \"status unknown|charging|"
+                   "discharging|not-charging|full\"\n");
+}
+
+
 enum {
     CMD_POWER,
     CMD_POWER_DISPLAY,
     CMD_POWER_AC,
+    CMD_POWER_STATUS,
 };
 
 static const char *power_help[] = {
@@ -337,6 +371,9 @@ static const char *power_help[] = {
         "display battery and charger state",
         /* CMD_POWER_AC */
         "'ac on|off' allows you to set the AC charging state to on or off",
+        /* CMD_POWER_STATUS */
+        "'status unknown|charging|discharging|not-charging|full' allows you "
+        "to set battery status",
 };
 
 void android_console_power(Monitor *mon, const QDict *qdict)
@@ -352,6 +389,8 @@ void android_console_power(Monitor *mon, const QDict *qdict)
             cmd = CMD_POWER_DISPLAY;
         } else if (strstr(helptext, "ac")) {
             cmd = CMD_POWER_AC;
+        } else if (strstr(helptext, "status")) {
+            cmd = CMD_POWER_STATUS;
         }
     }
 
diff --git a/android-console.h b/android-console.h
index 458f44c..184ae69 100644
--- a/android-console.h
+++ b/android-console.h
@@ -30,6 +30,7 @@ void android_console_redir_del(Monitor *mon, const QDict *qdict);
 
 void android_console_power_display(Monitor *mon, const QDict *qdict);
 void android_console_power_ac(Monitor *mon, const QDict *qdict);
+void android_console_power_status(Monitor *mon, const QDict *qdict);
 void android_console_power(Monitor *mon, const QDict *qdict);
 
 void android_monitor_print_error(Monitor *mon, const char *fmt, ...);
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v1 13/15] android-console: Add power present command
  2014-11-12  0:25 [Qemu-devel] [PATCH v1 00/15] android-console: Add console power command Greg Bellows
                   ` (11 preceding siblings ...)
  2014-11-12  0:26 ` [Qemu-devel] [PATCH v1 12/15] android-console: Add power status command Greg Bellows
@ 2014-11-12  0:26 ` Greg Bellows
  2014-11-12  0:26 ` [Qemu-devel] [PATCH v1 14/15] android-console: Add power health command Greg Bellows
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 21+ messages in thread
From: Greg Bellows @ 2014-11-12  0:26 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, christoffer.dall, alex.bennee; +Cc: Greg Bellows

Add the Android emulator console "power present" command and associated help
messages.  The "present" command allows the battery presence in the device to be
manipulated.

Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
---
 android-commands.h |  7 +++++++
 android-console.c  | 23 +++++++++++++++++++++++
 android-console.h  |  1 +
 3 files changed, 31 insertions(+)

diff --git a/android-commands.h b/android-commands.h
index 53f89b1..3adef55 100644
--- a/android-commands.h
+++ b/android-commands.h
@@ -47,6 +47,13 @@ static mon_cmd_t android_power_cmds[] = {
         .help = "set battery status",
         .mhandler.cmd = android_console_power_status,
     },
+    {
+        .name = "present",
+        .args_type = "arg:s?",
+        .params = "",
+        .help = "set battery present state",
+        .mhandler.cmd = android_console_power_present,
+    },
     { NULL, NULL, },
 };
 
diff --git a/android-console.c b/android-console.c
index 04a1971..b08519d 100644
--- a/android-console.c
+++ b/android-console.c
@@ -356,12 +356,30 @@ void android_console_power_status(Monitor *mon, const QDict *qdict)
                    "discharging|not-charging|full\"\n");
 }
 
+void android_console_power_present(Monitor *mon, const QDict *qdict)
+{
+    const char *arg = qdict_get_try_str(qdict, "arg");
+
+    if (arg) {
+        if (strcasecmp(arg, "true") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_PRESENT, 1);
+            return;
+        }
+        if (strcasecmp(arg, "false") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_PRESENT, 0);
+            return;
+        }
+    }
+
+    monitor_printf(mon, "KO: Usage: \"present true\" or \"present false\"\n");
+}
 
 enum {
     CMD_POWER,
     CMD_POWER_DISPLAY,
     CMD_POWER_AC,
     CMD_POWER_STATUS,
+    CMD_POWER_PRESENT,
 };
 
 static const char *power_help[] = {
@@ -374,6 +392,9 @@ static const char *power_help[] = {
         /* CMD_POWER_STATUS */
         "'status unknown|charging|discharging|not-charging|full' allows you "
         "to set battery status",
+        /* CMD_POWER_PRESENT */
+        "'present true|false' allows you to set battery present state to true "
+        "or false",
 };
 
 void android_console_power(Monitor *mon, const QDict *qdict)
@@ -391,6 +412,8 @@ void android_console_power(Monitor *mon, const QDict *qdict)
             cmd = CMD_POWER_AC;
         } else if (strstr(helptext, "status")) {
             cmd = CMD_POWER_STATUS;
+        } else if (strstr(helptext, "present")) {
+            cmd = CMD_POWER_PRESENT;
         }
     }
 
diff --git a/android-console.h b/android-console.h
index 184ae69..c7c7c86 100644
--- a/android-console.h
+++ b/android-console.h
@@ -31,6 +31,7 @@ void android_console_redir_del(Monitor *mon, const QDict *qdict);
 void android_console_power_display(Monitor *mon, const QDict *qdict);
 void android_console_power_ac(Monitor *mon, const QDict *qdict);
 void android_console_power_status(Monitor *mon, const QDict *qdict);
+void android_console_power_present(Monitor *mon, const QDict *qdict);
 void android_console_power(Monitor *mon, const QDict *qdict);
 
 void android_monitor_print_error(Monitor *mon, const char *fmt, ...);
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v1 14/15] android-console: Add power health command
  2014-11-12  0:25 [Qemu-devel] [PATCH v1 00/15] android-console: Add console power command Greg Bellows
                   ` (12 preceding siblings ...)
  2014-11-12  0:26 ` [Qemu-devel] [PATCH v1 13/15] android-console: Add power present command Greg Bellows
@ 2014-11-12  0:26 ` Greg Bellows
  2014-11-12  0:26 ` [Qemu-devel] [PATCH v1 15/15] android-console: Add power capacity command Greg Bellows
  2014-11-12 13:39 ` [Qemu-devel] [PATCH v1 00/15] android-console: Add console power command Greg Bellows
  15 siblings, 0 replies; 21+ messages in thread
From: Greg Bellows @ 2014-11-12  0:26 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, christoffer.dall, alex.bennee; +Cc: Greg Bellows

Add the Android emulator console "power health" command and associated help
messages.  The "health" command allows the battery health of the device to be
manipulated.

Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
---
 android-commands.h |  7 +++++++
 android-console.c  | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 android-console.h  |  1 +
 3 files changed, 55 insertions(+)

diff --git a/android-commands.h b/android-commands.h
index 3adef55..bb3f783 100644
--- a/android-commands.h
+++ b/android-commands.h
@@ -54,6 +54,13 @@ static mon_cmd_t android_power_cmds[] = {
         .help = "set battery present state",
         .mhandler.cmd = android_console_power_present,
     },
+    {
+        .name = "health",
+        .args_type = "arg:s?",
+        .params = "",
+        .help = "set battery health state",
+        .mhandler.cmd = android_console_power_health,
+    },
     { NULL, NULL, },
 };
 
diff --git a/android-console.c b/android-console.c
index b08519d..0a4fc1d 100644
--- a/android-console.c
+++ b/android-console.c
@@ -374,12 +374,54 @@ void android_console_power_present(Monitor *mon, const QDict *qdict)
     monitor_printf(mon, "KO: Usage: \"present true\" or \"present false\"\n");
 }
 
+void android_console_power_health(Monitor *mon, const QDict *qdict)
+{
+    const char *arg = qdict_get_try_str(qdict, "arg");
+
+    if (arg) {
+        if (strcasecmp(arg, "unknown") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_HEALTH,
+                                      POWER_SUPPLY_HEALTH_UNKNOWN);
+            return;
+        }
+        if (strcasecmp(arg, "good") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_HEALTH,
+                                      POWER_SUPPLY_HEALTH_GOOD);
+            return;
+        }
+        if (strcasecmp(arg, "overheat") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_HEALTH,
+                                      POWER_SUPPLY_HEALTH_OVERHEAT);
+            return;
+        }
+        if (strcasecmp(arg, "dead") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_HEALTH,
+                                      POWER_SUPPLY_HEALTH_DEAD);
+            return;
+        }
+        if (strcasecmp(arg, "overvoltage") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_HEALTH,
+                                      POWER_SUPPLY_HEALTH_OVERVOLTAGE);
+            return;
+        }
+        if (strcasecmp(arg, "failure") == 0) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_HEALTH,
+                                      POWER_SUPPLY_HEALTH_UNSPEC_FAILURE);
+            return;
+        }
+    }
+
+    monitor_printf(mon, "KO: Usage: \"health unknown|good|overheat|"
+                   "dead|overvoltage|failure\"\n");
+}
+
 enum {
     CMD_POWER,
     CMD_POWER_DISPLAY,
     CMD_POWER_AC,
     CMD_POWER_STATUS,
     CMD_POWER_PRESENT,
+    CMD_POWER_HEALTH,
 };
 
 static const char *power_help[] = {
@@ -395,6 +437,9 @@ static const char *power_help[] = {
         /* CMD_POWER_PRESENT */
         "'present true|false' allows you to set battery present state to true "
         "or false",
+        /* CMD_POWER_HEALTH */
+        "'health unknown|good|overheat|dead|overvoltage|failure' allows you "
+        "to set battery health state",
 };
 
 void android_console_power(Monitor *mon, const QDict *qdict)
@@ -414,6 +459,8 @@ void android_console_power(Monitor *mon, const QDict *qdict)
             cmd = CMD_POWER_STATUS;
         } else if (strstr(helptext, "present")) {
             cmd = CMD_POWER_PRESENT;
+        } else if (strstr(helptext, "health")) {
+            cmd = CMD_POWER_HEALTH;
         }
     }
 
diff --git a/android-console.h b/android-console.h
index c7c7c86..aea671f 100644
--- a/android-console.h
+++ b/android-console.h
@@ -32,6 +32,7 @@ void android_console_power_display(Monitor *mon, const QDict *qdict);
 void android_console_power_ac(Monitor *mon, const QDict *qdict);
 void android_console_power_status(Monitor *mon, const QDict *qdict);
 void android_console_power_present(Monitor *mon, const QDict *qdict);
+void android_console_power_health(Monitor *mon, const QDict *qdict);
 void android_console_power(Monitor *mon, const QDict *qdict);
 
 void android_monitor_print_error(Monitor *mon, const char *fmt, ...);
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v1 15/15] android-console: Add power capacity command
  2014-11-12  0:25 [Qemu-devel] [PATCH v1 00/15] android-console: Add console power command Greg Bellows
                   ` (13 preceding siblings ...)
  2014-11-12  0:26 ` [Qemu-devel] [PATCH v1 14/15] android-console: Add power health command Greg Bellows
@ 2014-11-12  0:26 ` 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
  15 siblings, 1 reply; 21+ messages in thread
From: Greg Bellows @ 2014-11-12  0:26 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, christoffer.dall, alex.bennee; +Cc: Greg Bellows

Add the Android emulator console "power capacity" command along associated help
messages.  The "capacity" command allows the battery capacity of the device to
be manipulated.

Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
---
 android-commands.h |  7 +++++++
 android-console.c  | 26 ++++++++++++++++++++++++++
 android-console.h  |  1 +
 3 files changed, 34 insertions(+)

diff --git a/android-commands.h b/android-commands.h
index bb3f783..62b181b 100644
--- a/android-commands.h
+++ b/android-commands.h
@@ -61,6 +61,13 @@ static mon_cmd_t android_power_cmds[] = {
         .help = "set battery health state",
         .mhandler.cmd = android_console_power_health,
     },
+    {
+        .name = "capacity",
+        .args_type = "arg:s?",
+        .params = "",
+        .help = "set battery capacity state",
+        .mhandler.cmd = android_console_power_capacity,
+    },
     { NULL, NULL, },
 };
 
diff --git a/android-console.c b/android-console.c
index 0a4fc1d..e24a87c 100644
--- a/android-console.c
+++ b/android-console.c
@@ -415,6 +415,23 @@ void android_console_power_health(Monitor *mon, const QDict *qdict)
                    "dead|overvoltage|failure\"\n");
 }
 
+void android_console_power_capacity(Monitor *mon, const QDict *qdict)
+{
+    const char *arg = qdict_get_try_str(qdict, "arg");
+
+   if (arg) {
+        int capacity;
+
+        if (sscanf(arg, "%d", &capacity) == 1 &&
+            capacity >= 0 && capacity <= 100) {
+            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_CAPACITY, capacity);
+            return;
+        }
+    }
+
+    monitor_printf(mon, "KO: Usage: \"capacity <percentage>\"\n");
+ }
+
 enum {
     CMD_POWER,
     CMD_POWER_DISPLAY,
@@ -422,6 +439,7 @@ enum {
     CMD_POWER_STATUS,
     CMD_POWER_PRESENT,
     CMD_POWER_HEALTH,
+    CMD_POWER_CAPACITY,
 };
 
 static const char *power_help[] = {
@@ -440,6 +458,9 @@ static const char *power_help[] = {
         /* CMD_POWER_HEALTH */
         "'health unknown|good|overheat|dead|overvoltage|failure' allows you "
         "to set battery health state",
+        /* CMD_POWER_CAPACITY */
+        "'capacity <percentage>' allows you to set battery capacity to a "
+        "value 0 - 100",
 };
 
 void android_console_power(Monitor *mon, const QDict *qdict)
@@ -450,9 +471,14 @@ void android_console_power(Monitor *mon, const QDict *qdict)
     /* Default to the first entry which is the parent help message */
     int cmd = CMD_POWER;
 
+    /* In the below command name parsing, "capacity" has to precede "ac"
+     * otherwise we will hit on "ac" first.
+     */
     if (helptext) {
         if (strstr(helptext, "display")) {
             cmd = CMD_POWER_DISPLAY;
+        } else if (strstr(helptext, "capacity")) {
+            cmd = CMD_POWER_CAPACITY;
         } else if (strstr(helptext, "ac")) {
             cmd = CMD_POWER_AC;
         } else if (strstr(helptext, "status")) {
diff --git a/android-console.h b/android-console.h
index aea671f..8801600 100644
--- a/android-console.h
+++ b/android-console.h
@@ -33,6 +33,7 @@ void android_console_power_ac(Monitor *mon, const QDict *qdict);
 void android_console_power_status(Monitor *mon, const QDict *qdict);
 void android_console_power_present(Monitor *mon, const QDict *qdict);
 void android_console_power_health(Monitor *mon, const QDict *qdict);
+void android_console_power_capacity(Monitor *mon, const QDict *qdict);
 void android_console_power(Monitor *mon, const QDict *qdict);
 
 void android_monitor_print_error(Monitor *mon, const char *fmt, ...);
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [PATCH v1 00/15] android-console: Add console power command
  2014-11-12  0:25 [Qemu-devel] [PATCH v1 00/15] android-console: Add console power command Greg Bellows
                   ` (14 preceding siblings ...)
  2014-11-12  0:26 ` [Qemu-devel] [PATCH v1 15/15] android-console: Add power capacity command Greg Bellows
@ 2014-11-12 13:39 ` Greg Bellows
  15 siblings, 0 replies; 21+ messages in thread
From: Greg Bellows @ 2014-11-12 13:39 UTC (permalink / raw)
  To: QEMU Developers, Peter Maydell, Christoffer Dall,
	Alex Bennée
  Cc: Greg Bellows

[-- Attachment #1: Type: text/plain, Size: 1790 bytes --]

Please disregard this patch review as it went to a broader audience than
intended.

If there is interest in this work then please let me know and I will be
happy to point you to a Linaro git repository that can be monitored for
future updates.

Regards,

Greg

On 11 November 2014 18:25, Greg Bellows <greg.bellows@linaro.org> wrote:

> This patchset includes 3 changes:
> - Fixes to the existing Android emulator console.
> - Restructure the emulator console redir help output
> - Add support for the emulator console power command
>
> Greg Bellows (15):
>   android-console: Fix goldfish audio misnaming
>   android-console: Unify available commands output
>   android-console: Remove extra redir help message
>   android-console: Consolidate redir help text
>   android-console: Add console base power command
>   android-console: Add missing hw_has_battery prop
>   android-console: Init the battery ID state field
>   android-console: Add header for battery externs
>   android-console: Add GF battery prop print func
>   android-console: Add GF battery property getter
>   android-console: Add power ac command
>   android-console: Add power status command
>   android-console: Add power present command
>   android-console: Add power health command
>   android-console: Add power capacity command
>
>  android-commands.h                 |  53 ++++++++
>  android-console.c                  | 254
> ++++++++++++++++++++++++++++++++-----
>  android-console.h                  |   8 ++
>  hw/misc/goldfish_battery.c         | 122 ++++++++++++++++--
>  include/hw/misc/goldfish_battery.h |  74 +++++++++++
>  monitor.c                          |  16 ++-
>  6 files changed, 484 insertions(+), 43 deletions(-)
>  create mode 100644 include/hw/misc/goldfish_battery.h
>
> --
> 1.8.3.2
>
>

[-- Attachment #2: Type: text/html, Size: 2338 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [PATCH v1 01/15] android-console: Fix goldfish audio misnaming
  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
  0 siblings, 0 replies; 21+ messages in thread
From: Alex Bennée @ 2014-11-13 10:01 UTC (permalink / raw)
  To: Greg Bellows; +Cc: peter.maydell, qemu-devel, christoffer.dall


Greg Bellows <greg.bellows@linaro.org> writes:

> Replaced goldfish_audio misnaming to goldfish_battery where appropriate in
> goldfish_battery.c

Ahh good 'ole copy pasta bugs ;-)

This will probably be worth squash merging when we clean-up the tree.

>
> Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
> ---
>  hw/misc/goldfish_battery.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/hw/misc/goldfish_battery.c b/hw/misc/goldfish_battery.c
> index 03847d6..89fd05d 100644
> --- a/hw/misc/goldfish_battery.c
> +++ b/hw/misc/goldfish_battery.c
> @@ -121,7 +121,7 @@ static void goldfish_battery_write(void *opaque, hwaddr offset, uint64_t val,
>              break;
>  
>          default:
> -            error_report ("goldfish_audio_write: Bad offset " TARGET_FMT_plx,
> +            error_report("goldfish_battery_write: Bad offset " TARGET_FMT_plx,
>                      offset);
>      }
>  }
> @@ -161,16 +161,16 @@ static void goldfish_battery_class_init(ObjectClass *klass, void *data)
>      dc->desc = "goldfish battery";
>  }
>  
> -static const TypeInfo goldfish_audio_info = {
> +static const TypeInfo goldfish_battery_info = {
>      .name          = TYPE_GOLDFISH_BATTERY,
>      .parent        = TYPE_SYS_BUS_DEVICE,
>      .instance_size = sizeof(struct goldfish_battery_state),
>      .class_init    = goldfish_battery_class_init,
>  };
>  
> -static void goldfish_audio_register(void)
> +static void goldfish_battery_register(void)
>  {
> -    type_register_static(&goldfish_audio_info);
> +    type_register_static(&goldfish_battery_info);
>  }
>  
> -type_init(goldfish_audio_register);
> +type_init(goldfish_battery_register);

-- 
Alex Bennée

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [PATCH v1 06/15] android-console: Add missing hw_has_battery prop
  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
  0 siblings, 0 replies; 21+ messages in thread
From: Alex Bennée @ 2014-11-13 10:03 UTC (permalink / raw)
  To: Greg Bellows; +Cc: peter.maydell, qemu-devel, christoffer.dall


Greg Bellows <greg.bellows@linaro.org> writes:

> Added the missing hw_has_battery property to the Goldfish batter state.  This
> property indicates whether the device has a battery and controls whether some
> power commands are available.
>
> In the Android emulator this property is acquired from the AVD for the device.
> For now, this is wired as always enabled.
>
> Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
> ---
>  hw/misc/goldfish_battery.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/hw/misc/goldfish_battery.c b/hw/misc/goldfish_battery.c
> index 89fd05d..a0bc379 100644
> --- a/hw/misc/goldfish_battery.c
> +++ b/hw/misc/goldfish_battery.c
> @@ -52,6 +52,7 @@ struct goldfish_battery_state {
>      uint32_t health;
>      uint32_t present;
>      uint32_t capacity;
> +    uint32_t hw_has_battery;;

Double semi-colon

>  };
>  
>  /* update this each time you update the battery_state struct */
> @@ -70,6 +71,7 @@ static const VMStateDescription goldfish_battery_vmsd = {
>          VMSTATE_UINT32(health, struct goldfish_battery_state),
>          VMSTATE_UINT32(present, struct goldfish_battery_state),
>          VMSTATE_UINT32(capacity, struct goldfish_battery_state),
> +        VMSTATE_UINT32(hw_has_battery, struct goldfish_battery_state),
>          VMSTATE_END_OF_LIST()
>      }
>  };
> @@ -146,6 +148,11 @@ static void goldfish_battery_realize(DeviceState *dev, Error **errp)
>  
>      // default values for the battery
>      s->ac_online = 1;
> +    /* TODO: The Android Emulator gets this attribute from the AVD
> +     *       hw-config-defs.h.  For now we hard-code the value to match the
> +     *       other values.
> +     */
> +    s->hw_has_battery = 1;
>      s->status = POWER_SUPPLY_STATUS_CHARGING;
>      s->health = POWER_SUPPLY_HEALTH_GOOD;
>      s->present = 1;     // battery is present

-- 
Alex Bennée

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [PATCH v1 07/15] android-console: Init the battery ID state field
  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
  0 siblings, 0 replies; 21+ messages in thread
From: Alex Bennée @ 2014-11-13 10:05 UTC (permalink / raw)
  To: Greg Bellows; +Cc: peter.maydell, qemu-devel, christoffer.dall


Greg Bellows <greg.bellows@linaro.org> writes:

> Adds initialization of the battery ID field so that it is discoverable by name
> (ID) when needed by power commands.
>
> Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
> ---
>  hw/misc/goldfish_battery.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/hw/misc/goldfish_battery.c b/hw/misc/goldfish_battery.c
> index a0bc379..11a2561 100644
> --- a/hw/misc/goldfish_battery.c
> +++ b/hw/misc/goldfish_battery.c
> @@ -141,6 +141,11 @@ static void goldfish_battery_realize(DeviceState *dev, Error **errp)
>      SysBusDevice *sbdev = SYS_BUS_DEVICE(dev);
>      struct goldfish_battery_state *s = GOLDFISH_BATTERY(dev);
>  
> +    /* Initialize the device ID so the battery can be looked up during monitor
> +     * commands.
> +     */
> +    dev->id = strdup("goldfish_battery");
> +

We should probably use g_strdup() here.

>      memory_region_init_io(&s->iomem, OBJECT(s), &goldfish_battery_iomem_ops, s,
>              "goldfish_battery", 0x1000);
>      sysbus_init_mmio(sbdev, &s->iomem);

-- 
Alex Bennée

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [PATCH v1 15/15] android-console: Add power capacity command
  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
  0 siblings, 0 replies; 21+ messages in thread
From: Alex Bennée @ 2014-11-13 10:17 UTC (permalink / raw)
  To: Greg Bellows; +Cc: peter.maydell, qemu-devel, christoffer.dall


Greg Bellows <greg.bellows@linaro.org> writes:

> Add the Android emulator console "power capacity" command along associated help
> messages.  The "capacity" command allows the battery capacity of the device to
> be manipulated.
>
> Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
> ---
>  android-commands.h |  7 +++++++
>  android-console.c  | 26 ++++++++++++++++++++++++++
>  android-console.h  |  1 +
>  3 files changed, 34 insertions(+)
>
<snip>
>  
> +void android_console_power_capacity(Monitor *mon, const QDict *qdict)
> +{
> +    const char *arg = qdict_get_try_str(qdict, "arg");
> +
> +   if (arg) {
> +        int capacity;
> +
> +        if (sscanf(arg, "%d", &capacity) == 1 &&
> +            capacity >= 0 && capacity <= 100) {
> +            goldfish_battery_set_prop(0, POWER_SUPPLY_PROP_CAPACITY, capacity);
> +            return;
> +        }

Has the formatting of const/if (arg) gone off there?

-- 
Alex Bennée

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2014-11-13 10:18 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [Qemu-devel] [PATCH v1 10/15] android-console: Add GF battery property getter Greg Bellows
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

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).