]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
[POWERPC] Celleb: Support for Power/Reset buttons
authorIshizaki Kou <kou.ishizaki@toshiba.co.jp>
Tue, 2 Oct 2007 08:21:21 +0000 (18:21 +1000)
committerPaul Mackerras <paulus@samba.org>
Wed, 3 Oct 2007 03:25:28 +0000 (13:25 +1000)
This supports Power/Reset buttons on Beat on Celleb.

On Beat, we have an event from Beat if Power button or Reset button
is pressed. This patch catches the event and convert it to a signal
to INIT process by calling ctrl_alt_del() function.

/sbin/inittab have no entry to turn the machine power off so we have
to detect if power button is pressed or not internally in our driver.
This idea is taken from PS3's event handling subsystem.

Signed-off-by: Kou Ishizaki <Kou.Ishizaki@toshiba.co.jp>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Paul Mackerras <paulus@samba.org>
arch/powerpc/platforms/celleb/beat.c

index ced6f68c7b0beac2d3944796a7c7027fe835c61b..93ebb7d85120fe7172f83c67e717410b61f92fdd 100644 (file)
 #include <linux/init.h>
 #include <linux/err.h>
 #include <linux/rtc.h>
+#include <linux/interrupt.h>
+#include <linux/irqreturn.h>
+#include <linux/reboot.h>
 
 #include <asm/hvconsole.h>
 #include <asm/time.h>
+#include <asm/machdep.h>
+#include <asm/firmware.h>
 
 #include "beat_wrapper.h"
 #include "beat.h"
+#include "interrupt.h"
+
+static int beat_pm_poweroff_flag;
 
 void beat_restart(char *cmd)
 {
-       beat_shutdown_logical_partition(1);
+       beat_shutdown_logical_partition(!beat_pm_poweroff_flag);
 }
 
 void beat_power_off(void)
@@ -170,6 +178,90 @@ void beat_kexec_cpu_down(int crash, int secondary)
 }
 #endif
 
+static irqreturn_t beat_power_event(int virq, void *arg)
+{
+       printk(KERN_DEBUG "Beat: power button pressed\n");
+       beat_pm_poweroff_flag = 1;
+       ctrl_alt_del();
+       return IRQ_HANDLED;
+}
+
+static irqreturn_t beat_reset_event(int virq, void *arg)
+{
+       printk(KERN_DEBUG "Beat: reset button pressed\n");
+       beat_pm_poweroff_flag = 0;
+       ctrl_alt_del();
+       return IRQ_HANDLED;
+}
+
+static struct beat_event_list {
+       const char *typecode;
+       irq_handler_t handler;
+       unsigned int virq;
+} beat_event_list[] = {
+       { "power", beat_power_event, 0 },
+       { "reset", beat_reset_event, 0 },
+};
+
+static int __init beat_register_event(void)
+{
+       u64 path[4], data[2];
+       int rc, i;
+       unsigned int virq;
+
+       for (i = 0; i < ARRAY_SIZE(beat_event_list); i++) {
+               struct beat_event_list *ev = &beat_event_list[i];
+
+               if (beat_construct_event_receive_port(data) != 0) {
+                       printk(KERN_ERR "Beat: "
+                              "cannot construct event receive port for %s\n",
+                              ev->typecode);
+                       return -EINVAL;
+               }
+
+               virq = irq_create_mapping(NULL, data[0]);
+               if (virq == NO_IRQ) {
+                       printk(KERN_ERR "Beat: failed to get virtual IRQ"
+                              " for event receive port for %s\n",
+                              ev->typecode);
+                       beat_destruct_event_receive_port(data[0]);
+                       return -EIO;
+               }
+               ev->virq = virq;
+
+               rc = request_irq(virq, ev->handler, IRQF_DISABLED,
+                                     ev->typecode, NULL);
+               if (rc != 0) {
+                       printk(KERN_ERR "Beat: failed to request virtual IRQ"
+                              " for event receive port for %s\n",
+                              ev->typecode);
+                       beat_destruct_event_receive_port(data[0]);
+                       return rc;
+               }
+
+               path[0] = 0x1000000065780000ul; /* 1,ex */
+               path[1] = 0x627574746f6e0000ul; /* button */
+               path[2] = 0;
+               strncpy((char *)&path[2], ev->typecode, 8);
+               path[3] = 0;
+               data[1] = 0;
+
+               beat_create_repository_node(path, data);
+       }
+       return 0;
+}
+
+static int __init beat_event_init(void)
+{
+       if (!firmware_has_feature(FW_FEATURE_BEAT))
+               return -EINVAL;
+
+       beat_pm_poweroff_flag = 0;
+       return beat_register_event();
+}
+
+device_initcall(beat_event_init);
+
 EXPORT_SYMBOL(beat_get_term_char);
 EXPORT_SYMBOL(beat_put_term_char);
 EXPORT_SYMBOL(beat_halt_code);