Skip to contentSkip to conversation

MusicPal: Add specific -hold-button option

PATCH In review Jan Kiszka 2 participants 3 messages May 20, 2008 – May 21, 2008

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 3/3 MusicPal: Add specific -hold-button option

[ adapted to new QEMUOptionSet abstraction ]

MusicPal's U-Boot is able to start in a special mode (firmware recovery) in case one of the control buttons is pressed during power-up. As with QEMU, there is no chance to achieve this by hand (except for artificially delaying the power-up with sleep()), this patch adds a MusicPal-specific command line option -hold-button. The option takes button codes and simulates those buttons as pressed on power-up.

---
 hw/musicpal.c |   55 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 48 insertions(+), 7 deletions(-)
hw/musicpal.c +48 -7
Index: b/hw/musicpal.c
===================================================================
@@ -62,6 +62,7 @@ static uint32_t gpio_in_state = 0xffffff
 static uint32_t gpio_isr;
 static uint32_t gpio_out_state;
 static ram_addr_t sram_off;
+static int powerup_hold_button;
 
 /* Address conversion helpers */
 static void *target2host_addr(uint32_t addr)
@@ -1344,6 +1345,12 @@ static void musicpal_key_event(void *opa
     uint32_t event = 0;
     static int kbd_extended;
 
+    if (powerup_hold_button) {
+        powerup_hold_button = 0;
+        gpio_in_state |= MP_GPIO_BTN_FAVORITS | MP_GPIO_BTN_VOLUME |
+                         MP_GPIO_BTN_NAVIGATION | MP_GPIO_BTN_MENU;
+    }
+
     if (keycode == KEYCODE_EXTENDED) {
         kbd_extended = 1;
         return;
@@ -1491,12 +1498,6 @@ static void musicpal_init(ram_addr_t ram
 
     qemu_add_kbd_event_handler(musicpal_key_event, pic[MP_GPIO_IRQ]);
 
-    /*
-     * Wait a bit to catch menu button during U-Boot start-up
-     * (to trigger emergency update).
-     */
-    sleep(1);
-
     mv88w8618_eth_init(&nd_table[0], MP_ETH_BASE, pic[MP_ETH_IRQ]);
 
     mixer_i2c = musicpal_audio_init(MP_AUDIO_BASE, pic[MP_AUDIO_IRQ]);
@@ -1508,9 +1509,49 @@ static void musicpal_init(ram_addr_t ram
     arm_load_kernel(env, &musicpal_binfo);
 }
 
+static void musicpal_parse_options(int index, const char *optarg)
+{
+    switch (*optarg) {
+    case 'f':
+        gpio_in_state &= ~MP_GPIO_BTN_FAVORITS;
+        break;
+    case 'm':
+        gpio_in_state &= ~MP_GPIO_BTN_MENU;
+        break;
+    case 'n':
+        gpio_in_state &= ~MP_GPIO_BTN_NAVIGATION;
+        break;
+    case 'v':
+        gpio_in_state &= ~MP_GPIO_BTN_VOLUME;
+        break;
+    default:
+        fprintf(stderr, "Invalid button specified: %c\n", *optarg);
+        exit(1);
+    }
+    powerup_hold_button = 1;
+}
+
+static const QEMUOption musicpal_options[] = {
+    { "hold-button", HAS_ARG, 0 },
+    { NULL }
+};
+
+static QEMUOptionSet musicpal_option_set = {
+    .options = musicpal_options,
+    .help_string =
+        "MusicPal specific options:\n"
+        "-hold-button [f][m][n][v]\n"
+        "                Hold favorits (f), menu (m), navigation (n), or volume(v)\n"
+        "                button on power-up to trigger special services. The button\n"
+        "                is released on next keystroke.\n"
+        "\n",
+    .parse_handler = musicpal_parse_options
+};
+
 QEMUMachine musicpal_machine = {
     "musicpal",
     "Marvell 88w8618 / MusicPal (ARM926EJ-S)",
     musicpal_init,
-    MP_RAM_DEFAULT_SIZE + MP_SRAM_SIZE + MP_FLASH_SIZE_MAX + RAMSIZE_FIXED
+    MP_RAM_DEFAULT_SIZE + MP_SRAM_SIZE + MP_FLASH_SIZE_MAX + RAMSIZE_FIXED,
+    &musicpal_option_set
 };
#1 lore raw
Quoted 6 lines

MusicPal's U-Boot is able to start in a special mode (firmware recovery) in case one of the control buttons is pressed during power-up. As with QEMU, there is no chance to achieve this by hand (except for artificially delaying the power-up with sleep()), this patch adds a MusicPal-specific command line option -hold-button. The option takes button codes and simulates those buttons as pressed on power-up.

There's no reason why this should be limited to the musicpal. Better would be to implement it in the input layer and have to work with all machines.

Paul

author
#2 lore raw
Quoted 9 lines · Paul Brook
Quoted 6 lines

MusicPal's U-Boot is able to start in a special mode (firmware recovery) in case one of the control buttons is pressed during power-up. As with QEMU, there is no chance to achieve this by hand (except for artificially delaying the power-up with sleep()), this patch adds a MusicPal-specific command line option -hold-button. The option takes button codes and simulates those buttons as pressed on power-up.

There's no reason why this should be limited to the musicpal. Better would be to implement it in the input layer and have to work with all machines.

Hmm... hard to argue against. Will look into this.

But I hope this doesn't make the other two patches in this serious obsolete in your eyes. I would still like to see them go in, at least the first one (until there is an in-tree use case for the second one).

Jan