From b2a09da8cd1aded496ab6b196fc016ed735016d5 Mon Sep 17 00:00:00 2001 From: Gordon Willem Klok Date: Mon, 12 Feb 2007 21:01:12 +0000 Subject: Add cuda_fileserver_mode() and pmu_fileserver_mode() that enable the wake on AC loss feature of the power management IC. Make this the default behaviour when booting OpenBSD from now on. This will only affect machines that have the power suddenly cut, Performing a shutdown requesting power down will clear this mode and its then possible to remove the power cord, and plug it back in without the machine comming back on automatically. Tested by myself, drahn ok kettenis, drahn. --- sys/arch/macppc/dev/adb.c | 34 ++++++++++++++++++++++++++++++---- sys/arch/macppc/dev/pm_direct.c | 24 ++++++++++++++++++++++-- sys/arch/macppc/dev/pm_direct.h | 11 ++++++++++- 3 files changed, 62 insertions(+), 7 deletions(-) (limited to 'sys/arch/macppc') diff --git a/sys/arch/macppc/dev/adb.c b/sys/arch/macppc/dev/adb.c index cfc5bd8ca7b..3dc6552ff39 100644 --- a/sys/arch/macppc/dev/adb.c +++ b/sys/arch/macppc/dev/adb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: adb.c,v 1.19 2006/03/07 20:00:18 miod Exp $ */ +/* $OpenBSD: adb.c,v 1.20 2007/02/12 21:01:11 gwk Exp $ */ /* $NetBSD: adb.c,v 1.6 1999/08/16 06:28:09 tsubai Exp $ */ /* $NetBSD: adb_direct.c,v 1.14 2000/06/08 22:10:45 tsubai Exp $ */ @@ -278,6 +278,7 @@ void setsoftadb(void); int adb_intr(void *arg); void adb_cuda_autopoll(void); +void adb_cuda_fileserver_mode(void); #ifdef ADB_DEBUG /* @@ -1524,7 +1525,7 @@ adb_poweroff(void) case ADB_HW_CUDA: output[0] = 0x02; /* 2 byte message */ output[1] = 0x01; /* to pram/rtc/soft-power device */ - output[2] = 0x0a; /* set date/time */ + output[2] = 0x0a; /* set poweroff */ result = send_adb_cuda((u_char *)output, (u_char *)0, (void *)0, (void *)0, (int)0); if (result != 0) /* exit if not sent */ @@ -1555,17 +1556,37 @@ adb_cuda_autopoll() u_char output[16]; output[0] = 0x03; /* 3-byte message */ - output[1] = 0x01; /* to pram/rtc device */ + output[1] = 0x01; /* to pram/rtc/soft-power device */ output[2] = 0x01; /* cuda autopoll */ output[3] = 0x01; result = send_adb_cuda(output, output, adb_op_comprout, - (void *)&flag, 0); + (void *)&flag, 0); if (result != 0) /* exit if not sent */ return; while (flag == 0); /* wait for result */ } +void +adb_cuda_fileserver_mode() +{ + volatile int flag = 0; + int result; + u_char output[16]; + + output[0] = 0x03; /* 3-byte message */ + output[1] = 0x01; /* to pram/rtc device/soft-power device */ + output[2] = 0x13; /* cuda file server mode */ + output[3] = 0x01; /* True */ + + result = send_adb_cuda(output, output, adb_op_comprout, + (void *)&flag, 0); + if (result != 0) + return; + + while (flag == 0); +} + void adb_restart() { @@ -1716,4 +1737,9 @@ adbattach(struct device *parent, struct device *self, void *aux) config_found(self, &nca, NULL); } } + + if (adbHardware == ADB_HW_CUDA) + adb_cuda_fileserver_mode(); + if (adbHardware == ADB_HW_PMU) + pmu_fileserver_mode(); } diff --git a/sys/arch/macppc/dev/pm_direct.c b/sys/arch/macppc/dev/pm_direct.c index f683585261e..21dadafacd3 100644 --- a/sys/arch/macppc/dev/pm_direct.c +++ b/sys/arch/macppc/dev/pm_direct.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pm_direct.c,v 1.20 2006/03/07 20:00:18 miod Exp $ */ +/* $OpenBSD: pm_direct.c,v 1.21 2007/02/12 21:01:11 gwk Exp $ */ /* $NetBSD: pm_direct.c,v 1.9 2000/06/08 22:10:46 tsubai Exp $ */ /* @@ -558,7 +558,7 @@ pm_adb_op(u_char *buffer, void *compRout, void *data, int command) s = splhigh(); write_via_reg(VIA1, vIER, 0x10); - adbBuffer = buffer; + adbBuffer = buffer; adbCompRout = compRout; adbCompData = data; @@ -837,3 +837,23 @@ pm_battery_info(int battery, struct pmu_battery_info *info) return 1; } + +void +pmu_fileserver_mode() +{ + PMData p; + + p.command = PMU_POWER_EVENTS; + p.num_data = 1; + p.s_buf = p.r_buf = p.data; + p.data[0] = PMU_PWR_GET_POWERUP_EVENTS; + pmgrop(&p); + + p.command = PMU_POWER_EVENTS; + p.num_data = 3; + p.s_buf = p.r_buf = p.data; + p.data[1] = p.data[0]; /* result from the get */ + p.data[0] = PMU_PWR_SET_POWERUP_EVENTS; + p.data[2] |= PMU_WAKE_AC_LOSS; + pmgrop(&p); +} diff --git a/sys/arch/macppc/dev/pm_direct.h b/sys/arch/macppc/dev/pm_direct.h index 41d7a57628c..8213ffe9a0c 100644 --- a/sys/arch/macppc/dev/pm_direct.h +++ b/sys/arch/macppc/dev/pm_direct.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pm_direct.h,v 1.9 2005/12/22 22:55:25 miod Exp $ */ +/* $OpenBSD: pm_direct.h,v 1.10 2007/02/12 21:01:11 gwk Exp $ */ /* $NetBSD: pm_direct.h,v 1.5 1999/07/12 15:54:55 tsubai Exp $ */ /* @@ -68,6 +68,7 @@ struct pmu_battery_info int pm_battery_info(int, struct pmu_battery_info *); void pm_eject_pcmcia(int); +void pmu_fileserver_mode(void); /* PMU commands */ #define PMU_RESET_ADB 0x00 /* Reset ADB */ @@ -127,6 +128,14 @@ enum { PMU_PWR_CLR_WAKEUP_EVENTS = 0x05, }; +/* PMU WAKE ON EVENTS */ + +#define PMU_WAKE_KEYB 0x01 +#define PMU_WAKE_AC_LOSS 0x02 +#define PMU_WAKE_AC_CHG 0x04 +#define PMU_WAKE_LID 0x08 +#define PMU_WAKE_RING 0x10 + /* PMU Power Information */ #define PMU_PWR_AC_PRESENT (1 << 0) -- cgit v1.2.3