--- pmud-0.10.orig/Batmon +++ pmud-0.10/Batmon @@ -19,9 +19,11 @@ # global c bgcolor +global font +set font {Helvetica 9} proc thermometer {tx0 ty0 scale max} { - global c tscale titem txitem + global c tscale titem txitem font set y0 [expr {$ty0 + $scale * $max}] $c create line $tx0 $ty0 $tx0 $y0 -width 9 -capstyle round -fill black $c create oval [expr $tx0-7] $y0 [expr $tx0+7] [expr $y0+14] \ @@ -31,15 +33,15 @@ for {set t 0} {$t <= $max} {incr t 10} { set y [expr {$y0 - $scale * $t}] .c create text [expr $tx0+10] $y -text $t -anchor w \ - -font -Adobe-Helvetica-Bold-R-Normal--*-100-*-*-*-*-*-* + -font $font } set txitem [.c create text [expr $tx0+1] [expr $y0+20] -anchor n] } proc smallabel {x y text} { - global c + global c font $c create text $x $y -anchor nw -text $text \ - -font -Adobe-Helvetica-Bold-R-Normal--*-100-*-*-*-*-*-* + -font $font } proc settherm {val} { @@ -60,9 +62,10 @@ set bscale$id $scale set boff$id $off for {set v $min} {$v <= $max} {incr v $tick} { + global font set y [expr {$yb - $scale * ($v - $off)}] .c create text [expr $x0+12] $y -text $v -anchor w \ - -font -Adobe-Helvetica-Bold-R-Normal--*-100-*-*-*-*-*-* + -font $font } set bxitem$id [.c create text [expr $x0+2] [expr $yb+8] -anchor n] set bmax$id $max --- pmud-0.10.orig/Makefile +++ pmud-0.10/Makefile @@ -39,7 +39,7 @@ $(CC) $(CFLAGS) -o fblevel fblevel.c xmouse: xmouse.c - $(CC) $(CLAGS) -o xmouse xmouse.c -L/usr/X11R6/lib -lX11 + $(CC) $(CLAGS) -o xmouse xmouse.c -lX11 tcp.o: tcp.c tcp.h $(CC) $(CFLAGS) -c tcp.c @@ -49,7 +49,7 @@ install -c snooze /sbin install -c wakebay /sbin install -c fblevel /sbin - install -c xmouse /usr/X11R6/bin + install -c xmouse /usr/bin install -c Batmon /usr/bin install -c -D pwrctl /etc/power/pwrctl cp pmud.rc /etc/rc.d/init.d/pmud --- pmud-0.10.orig/contrib/trackpad.c +++ pmud-0.10/contrib/trackpad.c @@ -7,6 +7,8 @@ * * 3/17/99 - Minor Fix: usage display used to leave /dev/adb open * + * 10/12/99 - addition of 'show' option to aid in pmud debugging + * * Pieces from mousehack, from numerous contributors... * */ @@ -102,7 +104,8 @@ mode_notap, mode_tap, mode_drag, - mode_lock + mode_lock, + mode_show }; @@ -117,33 +120,66 @@ printf("setting mode: %d\n", mode); #endif - buf[0] = ADB_PACKET; - buf[1] = ADB_WRITEREG(id, 2); - buf[2] = (mode < mode_tap) ? 0x19 : 0x99; - buf[3] = (mode < mode_drag) ? 0x14 : 0x94; - buf[4] = 0x19; - buf[5] = (mode < mode_lock) ? 0xb2 : 0xff; - buf[6] = 0xb2; - buf[7] = 0x8a; - buf[8] = 0x1b; - buf[9] = 0x50; - send(buf, 10); - listen(buf); + if (mode == mode_show) { + int n; - set_program_mode(id, 0); - - { - int i, n; - - for(i=0; i<4; i++) - { - printf("READREG(%d, %d) ", id, i); + printf("READREG(%d, %d) ", id, 2); buf[0] = ADB_PACKET; - buf[1] = ADB_READREG(id, i); + buf[1] = ADB_READREG(id, 2); send(buf, 2); - n = listen(buf+1); - } + n = listen(buf); +#ifdef DEBUG + printf("(reply %d bytes): ",n); + if (n >= 0) { + int ii; + for (ii=0; ii < n; ii++) + printf("0x%02x ",buf[ii]); + } + printf("\n"); +#endif + printf("trackpad settings %stap %sdrag %slock\n", + buf[1] == 0x99 ? "" : "no", + buf[2] == 0x94 ? "" : "no", + buf[4] == 0xff ? "" : "no" + ); + } else { + buf[0] = ADB_PACKET; + buf[1] = ADB_WRITEREG(id, 2); + buf[2] = (mode < mode_tap) ? 0x19 : 0x99; + buf[3] = (mode < mode_drag) ? 0x14 : 0x94; + buf[4] = 0x19; + buf[5] = (mode < mode_lock) ? 0xb2 : 0xff; + buf[6] = 0xb2; + buf[7] = 0x8a; + buf[8] = 0x1b; + buf[9] = 0x50; + send(buf, 10); + listen(buf); + +#ifdef DEBUG + { + int i, n; + + for(i=0; i<4; i++) + { + printf("READREG(%d, %d) ", id, i); + buf[0] = ADB_PACKET; + buf[1] = ADB_READREG(id, i); + send(buf, 2); + n = listen(buf+1); + printf("(reply %d bytes): ",n); + if (n >= 0) { + int ii; + for (ii=1; ii <= n; ii++) + printf("0x%02x ",buf[ii]); + } + printf("\n"); + } + } +#endif } + set_program_mode(id, 0); + } int @@ -189,6 +225,8 @@ mode = mode_drag; else if (strcmp(argv[1], "lock") == 0) mode = mode_lock; + else if (strcmp(argv[1], "show") == 0) + mode = mode_show; } if (mode == mode_invalid) { --- pmud-0.10.orig/debian/README.Debian +++ pmud-0.10/debian/README.Debian @@ -0,0 +1,41 @@ +pmud was debianized in May 2000 based on the pmud-0.6.1 release by Stephan +Leemburg . + +Not Debian related bugs, as well as feature requests should be reported to +the pmud bug mailing list. + +Notable differences from the LinuxPPC (basically RedHat) version: + +- the pmud config file is located in /etc/default not /etc/sysconfig. + /var/lock/subsystem is not used on Debian. + +- the non-essential utilities have been moved to a separate pmud-utils + package - this includes Batmon, fblevel and the xmouse program (save + and restore X11 mouse settings) which wasn't included before. + +pmud startup options are customized by editing /etc/default/power. For a +list of options, see the pmud(8) man page. + +A supplementary pwrctl script for local customization has been provided in +/usr/share/doc/pmud/examples/pwrctl-local. Common usage: run trackpad notap +after wakeup to restore the pesky trackpad to a sane setting (this is being +taken care of by pmud internally now!), or adjust the screen backlight level +according to power source and battery level. +Copy this script to /etc/power and customize according to your preferences. +This local script will never be overwritten by upgrades (nor removed on +package removal). /etc/power/pwrctl may be replaced by a new version on +occasion so be sure to make any changes to /etc/power/pwrctl-local only! + +apmd compatibility support has been added in the 0.6 release but is not +mentioned in the documentation yet. So here's the scoop: + +apmd support is enabled by the -a flag to pmud (in /etc/defaults/power) and +results in status information being logged to the /etc/power/apm fifo every +second. To use this feature, you'll need a patched version of any applet +or program that uses the apmd interface (these would usually look at +/proc/apm and we can't really fake that from user space). A GKrellM plugin +is available at http://www.execpc.com/~jpgarcia. +Recent kernels should have APM emulation built in so /proc/apm should be +used where possible. + + Michael Schmitz --- pmud-0.10.orig/debian/changelog +++ pmud-0.10/debian/changelog @@ -0,0 +1,258 @@ +pmud (0.10-14ubuntu1) vivid; urgency=medium + + * Merge from Debian unstable. Remaining changes: + - pmud.c: Fix call to open() when passing O_CREATE, it needs file mode. + + -- Logan Rosen Tue, 10 Feb 2015 21:03:11 +0000 + +pmud (0.10-14) unstable; urgency=low + + * Properly add LSB header to initscript to support dependency based init. + (not correctly fixed in 0.10-13) + Closes: #680447. + + * Remove postinst code to check for udev support. All current systems now + have udev support so the check is obsolete. + + -- Michael Schmitz Fri, 23 Jan 2015 11:52:34 +1200 + +pmud (0.10-13ubuntu1) raring; urgency=low + + * Merge from Debian unstable (LP: #1077853). Remaining changes: + - pmud.c: Fix call to open() when passing O_CREATE, it needs file mode. + + -- Logan Rosen Tue, 19 Mar 2013 16:40:33 -0400 + +pmud (0.10-13) unstable; urgency=low + + * Add LSB header to initscript to support dependency based init + Closes: #680447. + + -- Michael Schmitz Sat, 14 Jul 2012 12:44:12 +1200 + +pmud (0.10-12ubuntu1) precise; urgency=low + + * pmud.c: Fix call to open() when passing O_CREATE, it needs file mode. + + -- Ben Collins Sun, 22 Jan 2012 22:27:44 +0000 + +pmud (0.10-12) unstable; urgency=low + + * Fix error in low voltage threshold default (patch by Paul Collins + ). + Closes: #574422. + * Fix lintian warnings WRT mknod use in postinst. + + -- Michael Schmitz Sat, 17 Apr 2010 11:44:13 +1200 + +pmud (0.10-11) unstable; urgency=low + + * New feature: use low voltage threshold for sleep. + + -- Michael Schmitz Tue, 06 Aug 2009 20:20:57 +1200 + +pmud (0.10-10) unstable; urgency=low + + * Incorporate #363476 NMU. + + -- Michael Schmitz Tue, 30 Jun 2006 15:55:40 +0100 + +pmud (0.10-9) unstable; urgency=low + + * Build-depend on libx11-dev after xlibs-dev split. + Closes: #347026. + + * Add man pages for apm and wakebay. + Closes: #311190. + + -- Michael Schmitz Mon, 9 Jan 2006 18:04:40 +0100 + +pmud (0.10-8) unstable; urgency=low + + * Add option to ignore lid open events. Thanks to Colin Leroy for alerting + me to the corresponding /proc/pmu option. + + -- Michael Schmitz Tue, 23 Nov 2004 10:36:28 +0100 + +pmud (0.10-7) unstable; urgency=low + + * Add suspend-to-disk support for machines with no kernel sleep support. + Experimental, requires sysfs and swsusp patches to work. + + * Don't remove /etc/power on purge since pbbuttonsd might need it. + Closes: #272106. + + * Execute scripts in /etc/power/event.d to support generic power + management interface. This isn't quite what the bug submitter asked, but + close enough, and should take care of long standing wishlist items as + well. Closes: #263344,#164875. + + * Use invoke-rc.d if available. Closes: #273918. + + -- Michael Schmitz Tue, 26 Oct 2004 14:33:34 +0200 + +pmud (0.10-6) unstable; urgency=low + + * Move update-rc.d remove to postrm purge step (spotted by Colin Watson + ). Closes: #228219. + + * Add 'restart/force-reload' option to rc script (patch by Michael Shields + ). Closes: #230609. + + * Add 'nobeep' option to shut off beep on sleep/wakeup. Patch by Graham + Wilson . Closes: #229478. + + * Should be fixed IN -5 but forgot to close: display blanks/unblanks/blanks + again on iBook (reported by Michael Shields , compare + #205896). Closes: #185370. + + * Display shutdown on lid close with -k apparently fixed by -5 changes in + backlight handling: Closes: #150623. + + -- Michael Schmitz Thu, 12 Feb 2004 17:07:11 +0100 + +pmud (0.10-5) unstable; urgency=low + + * Stop pmud tweaking the backlight, recent kernels should cope now. + Closes: #205896. + + * Document '-o' flag in usage and man page. Closes: #221288. + + -- Michael Schmitz Thu, 15 Jan 2004 16:00:10 +0200 + +pmud (0.10-4) unstable; urgency=low + + * Add postinst code to create /dev/apm_bios (or have devfsd register + the devices) to enable the kernel APM emulation for XFree86 (should + really be in the XFree86 or kernel image postinst). Adding a Depends: on + powermgmt-base seems unnecessary (maybe XFree86 should do that, and use + apm_available). + Closes: #167009. + + -- Michael Schmitz Fri, 24 Jan 2003 14:47:51 +0200 + +pmud (0.10-3) unstable; urgency=low + + * Fix fcntl syscall syntax problem resulting in pmud crashing with 2.5 + kernels (patch by Paul Mackerras) + Closes: #167836. + + -- Michael Schmitz Tue, 05 Nov 2002 09:52:55 +0200 + +pmud (0.10-2) unstable; urgency=low + + * Removed on_ac_power which is in powermgmt-base, add Recommends: + powermgmt-base instead (reported by Jens Schmalzing). + Closes: #150622. + + * Add debhelper build-depends (reported by Junichi Uekawa). + Closes: #139651. + + * Unlink (stale) pmud socket special file before socket (stale socket file + resulted in pmud failing to start up after crash; reported by no-idea-who + && fixed upstream in the meantime). + + * Fix 'AC powerstatus forced on lid open' bug (reported by Michel Lanners) + Closes: #145922. + + * Fix log message grammar typo (reported by Mark Brown). + Closes: #126615. + + -- Michael Schmitz Tue, 07 May 2002 12:20:25 +0200 + +pmud (0.10-1) unstable; urgency=low + + * New upstream release; applied various patches from 0.7/0.8 not yet propagated + upstream. + + * Upstream changes include Unix domain socket support (for pmud only). + Closes: #122866. + Forked processes get stdin/stderr/stdout redirected to the bit bucket. + Closes: #123375. + + -- Michael Schmitz Tue, 18 Dec 2001 14:20:25 +0200 + +pmud (0.8-1) unstable; urgency=low + + * New upstream release; source now at http://sourceforge.net/projects/apmud/ + Applied various patches from 0.7 not yet propagated upstream. + + * Batmon font patch (Rusty Russell ). Closes: #111830. + + -- Michael Schmitz Fri, 07 Dec 2001 16:14:25 +0200 + +pmud (0.7-6) unstable; urgency=low + + * Conditionalize Core99 pwrctl section to shut down instead of sleep only + if kernel version is below 2.4.8. + + * Fix broken wall usage in pwrctl. Closes: 112123 + + -- Michael Schmitz Thu, 13 Sep 2001 13:31:23 +0200 + +pmud (0.7-5) unstable; urgency=low + + * Add conflicts on apmd for as long as it takes to convince the PTB + that apmd makes no sense whatsoever on powerpc. + + * Big package split: separate non-essential tools off into extra + pmud-utils package (#79905). + + * Add sample powerfail script for use by init on SIGPWR in examples + - untested (#79904). + + * Change Core99 pwrctl section once again as these machines appear to + be almost supported by the kernel now. + + Closes #79904, #79905 + + -- Michael Schmitz Fri, 25 May 2001 15:48:12 +0200 + +pmud (0.7-4) unstable; urgency=low + + * fixed broken pwrctl script (Pismo section), do a shutdown now. + Closes: #81103 + + * added devfs support code for /dev/pmu (Thanks to Chad Miller for the + patch). + Closes: #89928 + + -- Michael Schmitz Sun, 18 Mar 2001 20:57:14 +0200 + +pmud (0.7-3) unstable; urgency=low + + * fixed missing dependency (hdparm). + + -- Michael Schmitz Thu, 19 Oct 2000 23:32:31 +0200 + +pmud (0.7-2) unstable; urgency=low + + * Bugfix: trackpad status save/restore mangled the trackpad state (reply + buffer pointer off by one). Added 'show' option to trackpad tool. + Closes: #74527 + + -- Michael Schmitz Mon, 12 Oct 2000 20:14:19 +0200 + +pmud (0.7-1) unstable; urgency=low + + * New upstream release, adding wakebay support and trackpad status + save/restore. + + -- Michael Schmitz Mon, 09 Oct 2000 13:43:19 +0200 + +pmud (0.6-2) unstable; urgency=low + + * Added 3400 PMU APM patch from Joseph Garcia + + * Fixed handling of -f option (patch by Jens Schmalzing ). Closes #69591 + + * Added -a and -s options to man page (Jens Schmalzing ). Closes #69587 + + -- Michael Schmitz Mon, 21 Aug 2000 22:02:19 +0100 + +pmud (0.6-1) unstable; urgency=low + + * Initial Release. (built from LinuxPPC pmud-0.6 by Stephan Leemburg ) + + -- Michael Schmitz Mon, 23 May 2000 23:58:07 +0100 + --- pmud-0.10.orig/debian/compat +++ pmud-0.10/debian/compat @@ -0,0 +1 @@ +7 --- pmud-0.10.orig/debian/conffiles +++ pmud-0.10/debian/conffiles @@ -0,0 +1,4 @@ +/etc/init.d/pmud +/etc/power/pwrctl +/etc/default/power +/etc/devfs/conf.d/pmud --- pmud-0.10.orig/debian/control +++ pmud-0.10/debian/control @@ -0,0 +1,33 @@ +Source: pmud +Section: admin +Priority: optional +Build-Depends: debhelper, libx11-dev +Maintainer: Ubuntu Developers +XSBC-Original-Maintainer: Michael Schmitz +Standards-Version: 3.8.0 + +Package: pmud +Architecture: powerpc +Depends: hdparm, ${shlibs:Depends} +Recommends: powermgmt-base, powerpc-utils +Conflicts: apmd +Description: Apple PowerBook power management daemon + pmud is a daemon which periodically polls the PMU + (power manager) and performs functions such as enabling + or disabling devices appropriately when the power source + changes, or putting the computer into sleep mode when the + remaining battery power drops below a critical threshold. + Additional tools include a sleep command and a tool for + waking up media bay devices to work around a CD-ROM wakeup + bug in old kernels. + +Package: pmud-utils +Architecture: powerpc +Depends: pmud (>= 0.7-5), wish, ${shlibs:Depends} +Description: Apple PowerBook power management daemon utils + pmud is a daemon which periodically polls the PMU + (power manager) and performs various housekeeping functions + depending on the power status. + This package contains additional tools including a battery + status monitor and a tool to preserve X mouse settings + across sleep. --- pmud-0.10.orig/debian/copyright +++ pmud-0.10/debian/copyright @@ -0,0 +1,20 @@ +The pmud package was debianized by Michael Schmitz + on Mon, 22 May 2000 23:53:00 +0800 + +The source distribution was downloaded from http://www3.jvc.nl/linuxppc/ + +Copyright notice: + +Copyright 2000 Stephan Leemburg + +At present this supports the PB2400/3400/3500, +the 1999 G3 Powerbooks (aka "Lombard"), and the previous +generation of G3 Powerbooks (aka "Wallstreet"). + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version +2 of the License, or (at your option) any later version. + +pmud is a system daemon, which is usefull only for Apple Macintosh +Powerbooks. --- pmud-0.10.orig/debian/debhelper.log +++ pmud-0.10/debian/debhelper.log @@ -0,0 +1,18 @@ +dh_installdirs +dh_installdocs +dh_installexamples +dh_installmenu +dh_installcron +dh_installmanpages +dh_installinfo +dh_installchangelogs +dh_link +dh_strip +dh_compress +dh_fixperms +dh_installdeb +dh_shlibdeps +dh_gencontrol +dh_md5sums +dh_builddeb +dh_builddeb --- pmud-0.10.orig/debian/devfs.pmud +++ pmud-0.10/debian/devfs.pmud @@ -0,0 +1,2 @@ +REGISTER ^misc/pmu$ PERMISSIONS root.root 0600 +REGISTER ^misc/apm_bios$ PERMISSIONS root.root 0660 --- pmud-0.10.orig/debian/pmud-utils.manpages +++ pmud-0.10/debian/pmud-utils.manpages @@ -0,0 +1 @@ +xmouse.8 --- pmud-0.10.orig/debian/pmud.manpages +++ pmud-0.10/debian/pmud.manpages @@ -0,0 +1 @@ +pmud.8 --- pmud-0.10.orig/debian/postinst +++ pmud-0.10/debian/postinst @@ -0,0 +1,35 @@ +#! /bin/sh +set -e + +update-rc.d pmud defaults 40 60 + +#DEBHELPER# + +if [ "$1" = "configure" ]; then + if ! grep -q "PowerBook" /proc/cpuinfo ; then + cat <= 2.7) +misc:Depends= --- pmud-0.10.orig/on_ac_power +++ pmud-0.10/on_ac_power @@ -0,0 +1,64 @@ +#!/usr/bin/perl + +# on_ac_power v 0.2 +# Sunday 29 July 2001 +# +# on_ac_power utility replacement for PowerMac architecture +# exits with 0 if on AC power, with 1 if on batteries +# if on battery, outputs the percentage of battery left +# +# extension : if the -b or --battery switches are on, it outputs the battery +# status not depending on the AC status +# +# original version in the apmd distribution +# by Bastien Nocera , 2001 +# licensed under the GNU General Public License + +#If file doesn't exist, assume we're on mains power +open(FILE, "/proc/pmu/info") || exit 0; + +$matched = 0; +$ret_val = 0; + +while (($line = ) && ($matched == 0)) { + chop $line; + if ($line =~ m/^AC\ Power/) { + $matched = 1; + if ($line =~ m/1$/) { + # on AC + $ret_val = 0; + } else { + # on battery + $ret_val = 1; + } + } +} +close (FILE); + +# on battery or "-b" or "--battery" ? +# we need to ouput the percentage of battery left +$arg = $ARGV[0]; + +if (($ret_val == 0) && !($arg =~ "-b") && !($arg =~ "--battery")) { + exit $ret_val; +} + +open(FILE, "/proc/pmu/battery_0") || + die ("No such file: /proc/pmu/battery_0"); + +while ($line = ) { + chop $line; + if ($line =~ m/^charge/) { + @tmp = split(" ", $line); + $charge = @tmp[2]; + } + if ($line =~ m/^max_charge/) { + @tmp = split(" ", $line); + $max_charge = @tmp[2]; + } +} + +print int($charge/$max_charge*100)."\n"; +close (FILE); + +exit $ret_val; --- pmud-0.10.orig/pmud.8 +++ pmud-0.10/pmud.8 @@ -5,6 +5,7 @@ .\" as published by the Free Software Foundation; either version .\" 2 of the License, or (at your option) any later version. .\" +.TH PMUD 8 "January 23, 2015" .\" $Log: pmud.8,v $ .\" Revision 1.1.1.1 2001/12/07 11:31:44 sleemburg .\" Initial CVS import of the unreleased pmud-0.8 to apmud (new project name @@ -36,7 +37,7 @@ left to continue. .Sh SYNOPSIS .Nm pmud -.Op Fl dhsvkK +.Op Fl BdhsvkK .Op Fl f Ar facility .Op Fl l Ar seconds .Op Fl m Ar seconds @@ -52,6 +53,8 @@ is closed, after which the machine is put to sleep. The options are as follows: .Bl -tag -width Ds +.It Fl B +Do not beep when going to sleep or waking up. .It Fl d Enable debugging; this disables pmud of backgrounding. .It Fl f Ar facility @@ -82,6 +85,8 @@ signal. The default is 15 seconds. .It Fl n Do not detach. Whit this option the daemon will not become a background process. +.It Fl o +Do not save/restore backlight settings when sleeping (use for offb displays). .It Fl p Ar port Specifies the .Ar port @@ -97,6 +102,14 @@ address. .It Fl v Print the current RCS version Id of +.Nm Pmud +.It Fl V Ar voltage +Use +.Nm voltage +as critical low condition to drain a battery beyond a false +time left treshold sometimes observed with aging batteries. +Needs -l 0 to prevent early sleep or shutdown +due to low time left. .El .Sh POWERSIGNALS When @@ -170,4 +183,4 @@ .Xr init(8), .Xr hdparm(8), .Xr snooze(8) -.Xr /usr/doc/pmud*/* +.Xr /usr/share/doc/pmud*/* --- pmud-0.10.orig/pmud.c +++ pmud-0.10/pmud.c @@ -115,6 +115,9 @@ #define FLG_NOLID (1<<7) #define FLG_NOACLID (1<<8) #define FLG_NOTCP (1<<9) +#define FLG_NOBEEP (1<<10) +#define FLG_SUSPEND (1<<11) +#define FLG_NOLIDOPEN (1<<12) #define TPS_TAP (1<<0) #define TPS_DRAG (1<<1) @@ -156,6 +159,7 @@ int adb_fd; int apm_fd; int fb0_fd; +int susp_fd; int pmu_version; int powermode; /* 0 for battery, 1 for AC */ int powerlevel = -1; /* current power level setting */ @@ -164,6 +168,7 @@ int critical_time; /* # seconds of critically low power */ int critical_left = CRITICAL_TIMELEFT; /* # seconds of power left */ int critical_margin = CRITICAL_TIME; +int critical_voltage = CRITICAL_VOLT; struct sockstate *all_sockets; struct timeval pmu_poll_time; char *apmfile = APM_FILE; @@ -214,7 +219,8 @@ { struct timeval now, tleft; unsigned tms; - int s, len, fl; + int s, len, fl, err; + unsigned long can_sleep; struct sockaddr *sa; struct sockaddr_in sin; struct sockaddr_un sun; @@ -229,13 +235,18 @@ {"critical-left", 1, 0, 'l'}, {"critical-margin", 1, 0, 'm'}, {"nolid", 0, 0, 'k'}, - {"noaclid", 0, 0, 'k'}, + {"noaclid", 0, 0, 'K'}, + {"nolidopen", 0, 0, 'L'}, {"nodetach", 0, 0, 'n'}, + {"nooffb", 0, 0, 'o'}, + {"nobeep", 0, 0, 'B'}, {"port", 1, 0, 'p'}, {"sigpower", 0, 0, 's'}, {"shutdown", 0, 0, 'S'}, + {"suspend", 0, 0, 'D'}, {"af_unix", 0, 0, 'u'}, {"version", 0, 0, 'v'}, + {"voltage", 1, 0, 'V'}, {0, 0, 0, 0} }; int opt; @@ -251,7 +262,7 @@ p = p ? p + 1 : *av; - while((opt=getopt_long(ac,av, "a::df:hKkl:m:nop:sSuv", options,0))!=EOF) + while((opt=getopt_long(ac,av, "a::BdDf:hKkLl:m:nop:sSuvV:", options,0))!=EOF) switch(opt) { case 'a': @@ -260,6 +271,9 @@ apmfile = optarg; break; + case 'B': + flags |= FLG_NOBEEP; + break; case 'd': flags |= (FLG_DEBUG|FLG_NODETACH); syslog_options |= LOG_PERROR; @@ -293,6 +307,9 @@ case 'k': flags |= FLG_NOLID; break; + case 'L': + flags |= FLG_NOLIDOPEN; + break; case 'l': critical_left = atoi(optarg); break; @@ -314,12 +331,18 @@ case 'S': flags |= FLG_SHUTDOWN|FLG_SIGPWR; break; + case 'D': + flags |= FLG_SUSPEND; + break; case 'u': flags |= FLG_NOTCP; break; case 'v': printf("%s\n", rcsid); return 0; + case 'V': + critical_voltage = atoi(optarg); + break; case 'h': default : @@ -360,16 +383,28 @@ chk(pmu_fd < 0, "Couldn't open " PMU_FILE " or " PMU_DEVFS_FILE); - chk(fcntl(pmu_fd, F_GETFL, &fl) < 0, "fcntl(F_GETFL)"); + chk((fl = fcntl(pmu_fd, F_GETFL)) < 0, "fcntl(F_GETFL)"); fl |= O_NONBLOCK; - chk(fcntl(pmu_fd, F_SETFL, &fl) < 0, "fcntl(F_SETFL)"); + chk(fcntl(pmu_fd, F_SETFL, fl) < 0, "fcntl(F_SETFL)"); add_fd(pmu_fd, POLLIN, pmu_intr, NULL); fb0_fd = open(FB0_FILE, O_RDONLY); chk(fb0_fd < 0, "Couldn't open " FB0_FILE); + /* preliminary suspend-to-disk support */ + if(flags&FLG_SUSPEND) + { + susp_fd = open(SUSP_FILE, O_RDONLY); + if (susp_fd < 0) + { + syslog(LOG_ERR, "No suspend-to-disk support, using shutdown as fallback!\n"); + flags |= FLG_SIGPWR; + flags &= ~FLG_SUSPEND; + } else + close(susp_fd); + } if(!(flags&FLG_NOTCP)) { @@ -391,6 +426,8 @@ sun.sun_family = AF_UNIX; strcpy(sun.sun_path, SOCKET_FILE); + unlink(SOCKET_FILE); + chk(fchmod(s, 0600) < 0, "Couldn't change socket mode"); len = sizeof(sun); @@ -408,6 +445,31 @@ if(!get_pmu_version()) bye(EXIT_FAILURE, "incorrect PMU version"); + if(pmu_version >= PMU_VERSION_KEYLARGO) { + can_sleep = 0; + err = ioctl(pmu_fd, PMU_IOC_CAN_SLEEP, &can_sleep); + if (err) { + syslog(LOG_DEBUG, "Could not query kernel for sleep support! Setting the system to sleep may fail or hang."); + } else { + if (can_sleep == 0) { + if (flags&FLG_SUSPEND) { + syslog(LOG_DEBUG, "No sleep support on this hardware, using suspend-to-disk as requested!"); + // flags |= FLG_SUSPEND; + } else { + syslog(LOG_DEBUG, "No sleep support on this hardware, exiting!"); + close(adb_fd); + close(pmu_fd); + bye(EXIT_FAILURE, "missing sleep support"); + } + } + } + } + + if (flags&FLG_NOLIDOPEN) { + /* prevent lid open from waking the machine */ + system ("echo lid_wakeup=0 > /proc/pmu/options"); + } + if(flags&FLG_APM) { #if 0 @@ -447,7 +509,7 @@ syslog(LOG_DEBUG, "powerlevels from %s: %d %d", POWER_FILE, powerlevels[0], - powerlevels[0] + powerlevels[1] ); if(powerlevels[0] < 1 || powerlevels[0] > 3) @@ -508,9 +570,9 @@ if(!lid_closed) { fbon(1); - run_program(POWERLEVEL_SCRIPT, + run_program(POWERLEVEL_SCRIPT, "lid-opened", - ac ? "ac" : "battery" + powermode ? "ac" : "battery" ); } } @@ -621,8 +683,10 @@ printf("usage: %s [args]\n\n" "\twhere [args] is:\n\n" "\t-a [] : emulate an apm file in \n" + "\t-B : don't beep on sleep or wakeup.\n" "\t-d : enable debugging text; this flag implicitly\n" "\t sets the -n flag to prevent backgrounding.\n" + "\t-D : use suspend-to-disk in place of sleep\n" "\t-f : use for syslogd(8) messages.\n" "\t-h : this text.\n" "\t-k : do not detect lid close\n" @@ -634,6 +698,8 @@ "\t order to enable sleeping|shutdown.\n" "\t-n : do not detach. With this option the daemon\n" "\t will not become a background process.\n" + "\t-o : do not save/restore backlight settings \n" + "\t (use with offb framebuffer driver).\n" "\t-p : listen on for requestes.\n" "\t-s : send SIGPWR to init(8) on low power level;\n" "\t this does not put the machine to sleep as\n" @@ -642,9 +708,11 @@ "\t-S : same as -s, but also send SIGPWR on every\n" "\t sleep request or closing of the lid\n" "\t-u : communicate through a AF_UNIX socket;\n" - "\t-v : print the version string of %s.\n\n" + "\t-v : print the version string of %s.\n" + "\t-V : the battery voltage considered critical.\n\n" "\tfor the following flags, you can also use long-flags\n\n" "\t-a [] : --apm []\n" + "\t-B : --nobeep\n" "\t-d : --debug\n" "\t-f : --facility \n" "\t-h : --help\n" @@ -724,7 +792,7 @@ "G3 Wallstreet", // 10 "1999 G3 Lombard", // 11 "iBook/G3 Pismo/G4 Titanium", // 12 - "Wow, later than an Titanium! ;-)" // > 12 + "Wow, later than a Titanium! ;-)" // > 12 }; #define max_version (sizeof(version)/sizeof(char*)) static char env[16]; @@ -859,13 +927,14 @@ signed short batt[5], batt1, batt2; unsigned char par; int i, j; - int charge, current; + int charge, current, voltage1, voltage2; char *p = status; *p++ = 'S'; pwr = 0; charge = current = 0; batt1 = batt2 = 0; + voltage1 = voltage2 = 0; for (i = 0; i < 2; ++i) { @@ -906,6 +975,11 @@ * charging battery? */ charging = batt[0] & 0x02; + + /* + * battery voltage + */ + voltage1 = batt[4]; } else { @@ -917,6 +991,11 @@ * charging battery? */ charging |= batt[0] & 0x02; + + /* + * battery voltage + */ + voltage2 = batt[4]; } apm.battery_percentage = batt1 * 100; apm.battery_percentage /= batt2 ? batt2 : 1; @@ -929,6 +1008,8 @@ if (current < 0) timeleft = charge * 3552 / -current; + vb = ((voltage1 > voltage2) ? voltage1 : voltage2); + } /* apm pseudo info */ @@ -1007,7 +1088,7 @@ if(flags&FLG_DEBUG) syslog(LOG_DEBUG, "timeleft = %d", timeleft); - if (!pwr && timeleft >= 0 && timeleft < critical_left) + if (!pwr && ((timeleft >= 0 && timeleft < critical_left) || vb < critical_voltage)) { apm.battery_status = 2; /* critical */ @@ -1194,10 +1275,10 @@ struct sockstate *ss; fe = accept(fd, NULL, 0); - chk(fcntl(fe, F_GETFL, &fl) < 0, "fcntl(F_GETFL)"); + chk((fl = fcntl(fe, F_GETFL)) < 0, "fcntl(F_GETFL)"); fl |= O_NONBLOCK; - chk(fcntl(fe, F_SETFL, &fl) < 0, "fcntl(F_SETFL)"); + chk(fcntl(fe, F_SETFL, fl) < 0, "fcntl(F_SETFL)"); ss = malloc(sizeof(*ss)); if (ss == 0) @@ -1385,7 +1466,8 @@ if(id >= 0) ts = get_trackpad_settings(adb_fd, id); - beep(BEEP_TIME, BEEP_OK); + if (!(flags & FLG_NOBEEP)) + beep(BEEP_TIME, BEEP_OK); if(flags&FLG_DEBUG) syslog(LOG_DEBUG, "calling sync()"); @@ -1395,12 +1477,18 @@ syslog(LOG_INFO, "going to sleep"); - if (ioctl(pmu_fd, PMU_IOC_SLEEP, 0) < 0) - syslog(LOG_ALERT, "cannot put system to sleep! (%m)"); - else - syslog(LOG_INFO, "system awake again"); + if (flags&FLG_SUSPEND) { + /* suspend here */ + system ("echo -n disk > /sys/power/state"); + } else { + if (ioctl(pmu_fd, PMU_IOC_SLEEP, 0) < 0) + syslog(LOG_ALERT, "cannot put system to sleep! (%m)"); + else + syslog(LOG_INFO, "system awake again"); + } - beep(BEEP_TIME, BEEP_OK); + if (!(flags & FLG_NOBEEP)) + beep(BEEP_TIME, BEEP_OK); if(id >= 0) set_trackpad_settings(adb_fd, id, ts); @@ -1487,7 +1575,7 @@ static int do_sigpower(char level) { - int fd = open(POWERSTATUS_FILE, O_RDWR|O_TRUNC|O_CREAT); + int fd = open(POWERSTATUS_FILE, O_RDWR|O_TRUNC|O_CREAT, 0644); if(fd < 0) { syslog(LOG_ALERT, "open of %s failed (%m) reverting to sleep", @@ -1788,7 +1876,7 @@ static void fbon(int on) { - ioctl(fb0_fd, FBIOBLANK, !on); + // ioctl(fb0_fd, FBIOBLANK, !on); } static void beep(unsigned int ms, unsigned int freq) --- pmud-0.10.orig/pmud.h +++ pmud-0.10/pmud.h @@ -38,6 +38,7 @@ #define PMU_DEVFS_FILE "/dev/misc/pmu" #define ADB_FILE "/dev/adb" #define FB0_FILE "/dev/fb0" +#define SUSP_FILE "/sys/power/disk" #define POWERDIR "/etc/power" #define POWERLEVEL_SCRIPT POWERDIR "/pwrctl" #define POWER_FILE POWERDIR "/levels" @@ -80,6 +81,10 @@ #define CRITICAL_TIME 15 +/* take immediate action once voltage drops this low */ + +#define CRITICAL_VOLT 10000 + #define BEEP_TIME 150 #define BEEP_OK 1000 #define BEEP_WARN 2000 --- pmud-0.10.orig/pmud.rc +++ pmud-0.10/pmud.rc @@ -3,16 +3,26 @@ # pmud Power Manager daemon for Apple powerbooks # # chkconfig: 2345 40 60 -# description: pmud is a daemon which periodically polls the PMU \ -# (power manager) and performs functions such as enabling \ -# or disabling devices appropriately when the power source \ -# changes. +# +### BEGIN INIT INFO +# Provides: pmud +# Required-Start: $syslog $network $local_fs +# Required-Stop: $syslog $network $local_fs +# Default-Start: 2 3 4 5 +# Default-Stop: S 0 1 6 +# Short-Description: handle special hotkeys of Apple computers +# Description: pmud is a daemon which periodically polls the PMU +# (power manager) of an Apple PowerBook, and performs functions +# such as enabling or disabling devices appropriately when the +# power source changes. +### END INIT INFO +# # processname: pmud # config: /etc/powerlevels # pidfile: /var/run/pmud.pid # Source function library. -. /etc/rc.d/init.d/functions +. /lib/lsb/init-functions # Source power daemon options [ -f /etc/sysconfig/power ] && . /etc/sysconfig/power --- pmud-0.10.orig/pmud.rc.debian +++ pmud-0.10/pmud.rc.debian @@ -0,0 +1,99 @@ +#! /bin/sh +# +# pmud Power Manager daemon for Apple powerbooks +# +# chkconfig: 2345 40 60 +# description: pmud is a daemon which periodically polls the PMU \ +# (power manager) and performs functions such as enabling \ +# or disabling devices appropriately when the power source \ +# changes. +# processname: pmud +# config: /etc/power/levels +# pidfile: /var/run/pmud.pid + +### BEGIN INIT INFO +# Provides: pmud +# Required-Start: $syslog $network $local_fs +# Required-Stop: $syslog $network $local_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: handle power management of Apple computers +# Description: pmud is a daemon which periodically polls the PMU +# (power manager) of an Apple PowerBook, and performs functions +# such as enabling or disabling devices appropriately when the +# power source changes. +### END INIT INFO + +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin +DAEMON=/sbin/pmud +NAME=pmud +PIDFILE=/var/run/$NAME.pid +DESC="Power Management Unit" + +status() { + # Test syntax. + if [ $# = 0 ] ; then + echo "Usage: status {program}" + return 1 + fi + + # First try "pidof" + pid=`pidof $1` + if [ "$pid" != "" ] ; then + echo "$1 (pid $pid) is running..." + return 0 + else + pid=`ps ax | awk 'BEGIN { prog=ARGV[1]; ARGC=1 } + { if ((prog == $5) || (("(" prog ")") == $5) || + (("[" prog "]") == $5) || + ((prog ":") == $5)) { print $1 ; exit 0 } }' $1` + if [ "$pid" != "" ] ; then + echo "$1 (pid $pid) is running..." + return 0 + fi + fi + + # Next try "/var/run/*.pid" files + if [ -f /var/run/$1.pid ] ; then + pid=`head -1 /var/run/$1.pid` + if [ "$pid" != "" ] ; then + echo "$1 dead but pid file exists" + return 1 + fi + fi + echo "$1 not running" + return 2 +} + +# Source power daemon options +[ -f /etc/default/power ] && . /etc/default/power + +test -f $DAEMON || exit 0 + +# See how we were called. +case "$1" in + start) + echo -n "Starting $NAME: " + start-stop-daemon --start --quiet --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- $PMUD_FLAGS + #echo "$NAME." + ;; + stop) + echo -n "Stopping $NAME: " + start-stop-daemon --stop --quiet --exec $DAEMON + [ -f $PIDFILE ] && rm -f $PIDFILE + echo "$NAME." + ;; + restart|force-reload) + $0 stop + sleep 1 + $0 start + ;; + status) + status pmud + ;; + *) + echo "Usage: pmud {start|stop|status}" + exit 1 +esac + +exit 0 --- pmud-0.10.orig/power.conf +++ pmud-0.10/power.conf @@ -1,25 +1,41 @@ # ----------------------------------------------------------------------------- # Specify the pmud start flags here, you can use the following flags: # ----------------------------------------------------------------------------- +# -a : enable apmd compatibility mode (fifo /etc/power/apm) +# -B : do not beep on sleep or wakeup # -d : enable debugging text; this flag implicitly # sets the -n flag to prevent backgrounding. +# -D : use suspend-to-disk in place of sleep. # -f : use for syslogd(8) messages. # -h : this text. +# -k : do not detect lid close +# -K : do not detect lid close when on AC # -l : the numbers of power left which # is considered to be a critical low level. +# -L : do not detect lid open for wakeup # -m : the number of a critical low (see # the -l flag) power level has to endure in # order to enable sleeping|shutdown. # -n : do not detach. With this option the daemon # will not become a background process. +# -o : don't save/restore backlight settings (for offb displays) # -p : listen on for requestes. # -s : send SIGPWR to init(8) on low power level; # this does not put the machine to sleep as # another SIGPWR needs to be send to init(8) # when power is restored. +# -S : same as -s, but also send SIGPWR on every +# sleep request or closing of the lid +# -u : communicate through a AF_UNIX socket. # -v : print the version string of pmud. +# -V : use as critically low condition (together with +# -l 0 to force draining the battery beyond the usual low +# threshold - useful on old batteries!). # # see also pmud(8) +# +# Enclose the flags in double quotes as shown below. Otherwise, only the +# first one is passed to pmud! # ----------------------------------------------------------------------------- -PMUD_FLAGS= +PMUD_FLAGS="-a" --- pmud-0.10.orig/powerfail +++ pmud-0.10/powerfail @@ -0,0 +1,123 @@ +#! /bin/sh +# +# powerfail This script is run when the UPS tells the system the power has +# gone. Tell everybody and start the shutdown based on the failure +# type. This script will also being run when the power comes up +# again. +# +# Version: /etc/init.d/powerfail (v1.1) +# +# Author: Tom Webster +# Modified-By: Brian White +# + + + +failtime=+5 # shutdown delay from initial power failure +btrytime=now # shutdown delay from low-battery warning + +failmsg="LINE POWER FAILURE -- SWITCHED TO BATTERY BACKUP" +btrymsg="BACKUP BATTERY LOW -- EMERGENCY SHUTDOWN" +cablmsg="BAD UPS CABLE -- SYSTEM MAY BE UNRELIABLE" +othrmsg="LINE POWER FAILURE -- SHUTTING DOWN SYSTEM" +okaymsg="LINE POWER RESTORED -- RESUMING NORMAL OPERATION" + + + +# Set the path. +PATH=/sbin:/etc:/bin:/usr/bin + +# Set location of upsstatus file +statpath="/etc/upsstatus" + +# Set location of file containing PID of running shutdowns +spidpath="/var/run/shutdown.pid" + + + +# See what happened. +case "$1" in + + start) + # Called with a powerfail event, check to see if a shutdown is running + if [ -f $spidpath ] + then + # Shutdown is running, kill it to process the new event + shutdown -c >/dev/null 2>&1 + fi + + # Get power problem and act on it + if [ -r $statpath ] + then + stats=`head -1 $statpath` + case "$stats" in + FAIL) # Power is down + shutdown -h $failtime "$failmsg" & + # switch off backlight, and force disks to spin down. + # fblevel in pmud-utils now! + fblevel 0 + [ "`cat /proc/ide/hde/model`" != "(none)" ] && hdparm -f -S 1 -Y /dev/hde + hdparm -f -S 1 -Y /dev/hda + ;; + SCRAM) # Battery is low + shutdown -h $btrytime "$btrymsg" & + fblevel 0 + [ "`cat /proc/ide/hde/model`" != "(none)" ] && hdparm -f -S 1 -Y /dev/hde + hdparm -f -S 1 -Y /dev/hda + ;; + CABLE) # Possible bad cable + echo "$cablmsg" | wall + ;; + *) # Unknown message, assume power is down + shutdown -h $btrytime "$othrmsg" & + fblevel 0 + [ "`cat /proc/ide/hde/model`" != "(none)" ] && hdparm -f -S 1 -Y /dev/hde + hdparm -f -S 1 -Y /dev/hda + ;; + esac + + else + # powerfail called, and upsstatus dosen't exist. + # Assume user is using powerd, and shutdown. + shutdown -h $failtime "$othrmsg" & + fblevel 0 + [ "`cat /proc/ide/hde/model`" != "(none)" ] && hdparm -f -S 1 -Y /dev/hde + hdparm -f -S 1 -Y /dev/hda + fi + ;; + + + now) + # Called with a powerfail event, check to see if a shutdown is running + if [ -f $spidpath ] + then + # Shutdown is running, kill it to process the new event + shutdown -c >/dev/null 2>&1 + fi + + # Power is going down _now_ + shutdown -h $btrytime "$btrymsg" & + ;; + + + stop) + # switch backlight back on + fblevel 12 + # Ok, power is good again. Say so on the console. + if [ -f $spidpath ] + then + # Only cancel if shutdown is running (system boot will call this) + shutdown -c "$okaymsg" + fi + ;; + + + *) + echo "Usage: /etc/init.d/powerfail {start|now|stop}" >&2 + exit 1 + ;; + +esac + + +exit 0 --- pmud-0.10.orig/pwrctl +++ pmud-0.10/pwrctl @@ -32,6 +32,29 @@ # You can edit this file, but it's better to edit /etc/power/pwrctl-local # as that file will not be overwritten on upgrades. # ----------------------------------------------------------------------------- +# Debian add-on: support (sort of) for Core99 machines (Pismo,...). The +# Pismo can't sleep right now so it will wake again immediately. We spin +# down the disk on sleep, turn off backlight power and ignore the wakeup. +# +# While things are stabilizing, these commands could be used to put the system +# into absolute minimum power mode. You can use commands of this sort in +# /etc/init.d/powerfail if needs be (sample powerfail script is in +# /usr/share/doc/sysvinit/examples/). +# fblevel 0 +# [ "`cat /proc/ide/hde/model`" != "(none)" ] && hdparm -f -S 1 -Y /dev/hde +# hdparm -f -S 1 -Y /dev/hda +# Use this to switch the display back on if the powerfail status is called +# off: +# fblevel 12 +# +# 01/09/13: Recent 2.4 kernel versions support sleep properly, by all +# accounts. So shut down only if kernel version is insufficient. +# Sample code to deal with broken airport drivers moved to pwrctl-local +# (courtesy Tom Rini). +# +# 04/02/12: moved fblevel tool to powerpc-utils. Recommend that package in +# our dependencies. +# # $Log: pwrctl,v $ # Revision 1.1.1.1 2001/12/07 11:31:53 sleemburg # Initial CVS import of the unreleased pmud-0.8 to apmud (new project name @@ -57,14 +80,15 @@ # ----------------------------------------------------------------------------- logger=/usr/bin/logger localfun=/etc/power/pwrctl-local +fundir=/etc/power/event.d function do_warn() { local msg="Low battery, system will go down..." ( - /usr/X11R6/bin/xmessage -center -timeout 15 "$msg" || \ - /usr/bin/wall "$msg" + /usr/bin/X11/xmessage -center -timeout 15 "$msg" || \ + echo "$msg" | /usr/bin/wall ) & } @@ -73,20 +97,21 @@ case "$1" in minimum) # min power, set disk to spin down after 1 minute - hdparm -p -S 12 /dev/hda + [ -f /sbin/hdparm ] && hdparm -p -S 12 /dev/hda ;; medium) - hdparm -p -S 12 /dev/hda + # medium power, set disk to spin down after 2.5 minutes + [ -f /sbin/hdparm ] && hdparm -p -S 30 /dev/hda ;; maximum) case "$2" in ac) # on mains, do not spin down - hdparm -p -S 0 /dev/hda + [ -f /sbin/hdparm ] && hdparm -p -S 0 /dev/hda ;; *) - # on battery, set disk to spin down after 5 minute - hdparm -p -S 60 /dev/hda + # on battery, set disk to spin down after 5 minutes + [ -f /sbin/hdparm ] && hdparm -p -S 60 /dev/hda ;; esac ;; @@ -122,6 +147,67 @@ esac } +#------------------------------------------------------------------------------ +# This is largely a no-op on iBook or Pismo, as we don't know how to handle +# the sleep functions yet (with old kernel versions). Instead, we shut down +# on the spot unless the kernel version is a known good one. +#------------------------------------------------------------------------------ + +function pwrctl_Core99() +{ + case "$1" in + minimum) + # min power, set disk to spin down after 1 minute + [ -f /sbin/hdparm ] && hdparm -p -S 12 /dev/hda + ;; + medium) + # medium power, set disk to spin down after 2.5 minutes + [ -f /sbin/hdparm ] && hdparm -p -S 30 /dev/hda + ;; + maximum) + case "$2" in + ac) + # on mains, do not spin down + [ -f /sbin/hdparm ] && hdparm -p -S 0 /dev/hda + ;; + *) + # on battery, set disk to spin down after 5 minutes + [ -f /sbin/hdparm ] && hdparm -p -S 60 /dev/hda + ;; + esac + ;; + warning) + do_warn + ;; + lid-closed) + ;; + lid-opened) + ;; + sleep) + # We may end up here if someone closed the lid ... + # SIGPWR can be sent to init anyway with -s option, do the only + # safe thing for now: shut the hell down on 2.2 kernels, or anything + # below a known safe 2.4 version. + KVER=`uname -r` + case "$KVER" in + 2.2.*|2.3.*|2.4.[1-7]|2.4.[1-7]-*) + $logger -p daemon.error -t pwrctl "$0: insufficient kernel verison - sleep function not implemented, shutting down!" + echo "Kernel does not support sleep, shutting down!" | /usr/bin/wall + /sbin/shutdown -h now + ;; + *) + ;; + esac + ;; + wakeup) + # maybe force wakeup of media bay devices? + ;; + *) + $logger -p daemon.error -t pwrctl "$0: invalid arg $1" + ;; + esac +} + # ----------------------------------------------------------------------------- # On the 3400, for minimum power, we put the CPU into nap mode # (rather than doze mode) when it is idle. This reduces power @@ -135,14 +221,14 @@ case "$1" in minimum) ifconfig eth0 down - hdparm -d0 -S 12 /dev/hda - hdparm -d0 /dev/hdc + [ -f /sbin/hdparm ] && hdparm -d0 -S 12 /dev/hda + [ "`cat /proc/ide/hdc/model`" != "(none)" ] && [ -f /sbin/hdparm ] && hdparm -d0 /dev/hdc echo 1 >/proc/sys/kernel/powersave-nap ;; medium) echo 0 >/proc/sys/kernel/powersave-nap - hdparm -d1 -p -S 12 /dev/hda - hdparm -d1 /dev/hdc + [ -f /sbin/hdparm ] && hdparm -d1 -p -S 30 /dev/hda + [ "`cat /proc/ide/hdc/model`" != "(none)" ] && [ -f /sbin/hdparm ] && hdparm -d1 /dev/hdc ifconfig eth0 up ;; maximum) @@ -150,14 +236,14 @@ case "$2" in ac) # on mains, do not spin down - hdparm -d1 -p -S 0 /dev/hda + [ -f /sbin/hdparm ] && hdparm -d1 -p -S 0 /dev/hda ;; *) - # on battery, set disk to spin down after 5 minute - hdparm -d1 -p -S 60 /dev/hda + # on battery, set disk to spin down after 5 minutes + [ -f /sbin/hdparm ] && hdparm -d1 -p -S 60 /dev/hda ;; esac - hdparm -d1 /dev/hdc + [ "`cat /proc/ide/hdc/model`" != "(none)" ] && [ -f /sbin/hdparm ] && hdparm -d1 /dev/hdc ifconfig eth0 up ;; warning) @@ -198,9 +284,37 @@ esac } +for fun in $fundir/* ; do + [ -x $fun ] && { + case $1 in + sleep) + $logger -p daemon.info -t pwrctl "calling $fun suspend $2" + $fun suspend $2 + ;; + wakeup) + $logger -p daemon.info -t pwrctl "calling $fun resume $2" + $fun resume $2 + ;; + minimum) + $logger -p daemon.info -t pwrctl "calling $fun powersave $2" + $fun powersave $2 + ;; + medium) + $logger -p daemon.info -t pwrctl "calling $fun custom $2" + $fun custom $2 + ;; + maximum) + $logger -p daemon.info -t pwrctl "calling $fun performance $2" + $fun performance $2 + ;; + esac + } +done + case "$PMUVERSION" in -9) pwrctl_3400 $1 $2 ;; -1[012]) pwrctl_G3 $1 $2 ;; +9) pwrctl_3400 $1 $2 ;; +10|11) pwrctl_G3 $1 $2 ;; +12) pwrctl_Core99 $1 $2 ;; *) $logger -p daemon.error -t pwrctl "no function for PMU $PMUVERSION" ;; --- pmud-0.10.orig/pwrctl-local +++ pmud-0.10/pwrctl-local @@ -20,8 +20,18 @@ # battery # # -# This script can be invoked by pwrctl when it is named /etc/power/pwrctl-local # and is executable. Pwrctl is called by pmud on a power event. If this +# This script can be invoked by pwrctl when it is named /etc/power/pwrctl-local +# and is executable. Pwrctl is called by pmud on a power event. If this # script returns the value 1, then pwrctl will skip it's main body +# +# Example usage: use ifdown -a on sleep (and ifup -a on wakeup) to +# automagically renew DHCP leases. Similar use of iwconfig down/up might be +# required for Wavelan users with older versions of the kernel. +# +# Other examples: store/restore function keys settings (Debian users need +# powerpc-utils >= 1.1.3-8 for this) , tweak backlight settings depending on +# power mode, etc. ... +# # ----------------------------------------------------------------------------- # $Log: pwrctl-local,v $ # Revision 1.1.1.1 2001/12/07 11:31:48 sleemburg @@ -63,9 +73,23 @@ ;; sleep) $logger -p daemon.info -t pwrctl-local "sleep $2" + # Currently the airport driver isn't happy with sleep, so we + # must remove it + if [ "`lsmod | grep airport 2>/dev/null`" ]; then + AIRPORT=`cat /proc/net/wireless | grep eth | sed 's/^ //' | cut -d : -f 1` + ifdown $AIRPORT + echo $AIRPORT > /var/run/airport-device + sync + rmmod -a && rmmod -a + fi ;; wakeup) - $logger -p daemon.info -t pwrctl-local "sleep $2" + $logger -p daemon.info -t pwrctl-local "wakeup $2" + # restore airport config + [ -f /var/tmp/airport ] && { + ifup `cat /var/run/airport-device` + rm /var/tmp/airport-device + } ;; *) $logger -p daemon.error -t pwrctl-local "invalid arg $1 $2" --- pmud-0.10.orig/snooze.8 +++ pmud-0.10/snooze.8 @@ -21,13 +21,17 @@ .Dt SNOOZE 8 .Os "LinuxPPC pmud" .Sh NAME -.Nm snooze +.Nm snooze,apm .Nd will put an Apple Macintosh Powerbook into sleep. .Sh SYNOPSIS .Nm snooze .Op Fl hv .Op Fl f .Op Fl p Ar port +.Nm apm +.Op Fl hv +.Op Fl f +.Op Fl p Ar port .Sh DESCRIPTION .Nm Snooze is a program, which is usefull only for Apple Macintosh Powerbooks. @@ -49,6 +53,11 @@ you will not get the benefits of all the facilities that .Nm pmud has to offer. +.Nm apm +(/usr/bin/apm) is provided as a symbolic link to +.Nm snooze +for limited apmd compatibility to use by ia32 centric scripts from other +packages. .Sh BUGS AND CHANGE REQUESTS Please email your bug reports or change requests to \fB\fP. .Sh FILES --- pmud-0.10.orig/wakebay.8 +++ pmud-0.10/wakebay.8 @@ -0,0 +1,31 @@ +.\" Copyright (c) 2000 Stephan Leemburg +.\" +.Dd November 18, 2005 +.Dt WAKEBAY 8 +.Os "LinuxPPC pmud" +.Sh NAME +.Nm wakebay +.Nd will wake up Apple PowerBook Mediabay devices +.Sh SYNOPSIS +.Nm wakebay +.Op Ar /dev/ +.Sh DESCRIPTION +.Nm wakebay +is a program, which is useful only for Apple Macintosh Powerbooks. +On invocation, it will wake up the specified Mediabay device that was +powered down by sleep. +Waking up the device involves sending an IOCTL to the device to force it +to check for a media change, thus revalidating the device info. Newer +kernels do this internally so +.Nm wakebay +should only be needed on old kernel versions. +.Sh BUGS AND CHANGE REQUESTS +Please email your bug reports or change requests to \fB\fP. +.Sh FILES +.nf +/dev/ +.fi +.Sh AUTHORS +Joseph Palani Garcia +.Sh SEE ALSO +.Xr pmud(8)