4 Original author: Michael Roßberg
6 Rewritten by: Joshua Wise
8 Description: Ambien is a kernel extension to disable sleep-on-clamshell.
10 Ambien is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 Ambien is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with Ambien; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <IOKit/IOLib.h>
27 #include <IOKit/pwr_mgt/RootDomain.h>
28 #include <IOKit/pwr_mgt/IOPM.h>
30 #define super IOService
32 OSDefineMetaClassAndStructors(Ambien, IOService);
34 bool Ambien::init(OSDictionary* properties)
36 IOLog("Ambien.kext for Mac OS X Leopard, by Joshua Wise\n");
39 if (super::init(properties) == false) {
40 IOLog("Ambien::init: super::init failed\n");
47 bool Ambien::start(IOService* provider)
49 static IOPMPowerState states[] =
51 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
52 {1, kIOPMDeviceUsable, kIOPMPowerOn, kIOPMPowerOn, 0, 0, 0, 0, 0, 0, 0, 0}
55 if (!super::start(provider)) {
56 IOLog("Ambien::start: super::start failed\n");
61 provider->joinPMtree(this);
62 if (registerPowerDriver(this, states, 2) != IOPMNoErr)
64 IOLog("Ambien::start: registerPowerDriver returned error -- uh-oh!\n");
71 void Ambien::stop(IOService* provider)
80 super::stop(provider);
81 IOLog("Ambien: your sleep schedule is back to you!\n");
84 IOReturn Ambien::setPowerState(unsigned long which, IOService *dev)
88 IOLog("Ambien::setPowerState: system going to sleep\n");
90 IOLog("Ambien::setPowerState: system is awake\n");
93 return kIOPMAckImplied;
102 IOWorkLoop* Ambien::getWorkLoop()
105 _workLoop = IOWorkLoop::workLoop();
110 IOReturn Ambien::message(UInt32 type, IOService *provider, void *arg)
112 unsigned int argi = (unsigned int)(unsigned long)/* screw off, it's a bitmask, not a pointer */arg;
114 if (type == kIOPMMessageClamshellStateChange)
116 IOPMrootDomain *root = NULL;
118 IOLog("Ambien::message: kIOPMMessageClamshellStateChange: lid is %s, sleep bit is %d (arg %08x)\n",
119 (argi & kClamshellStateBit) ? "closed" : "open",
120 !!(argi & kClamshellSleepBit), argi);
122 root = getPMRootDomain();
125 IOLog("Ambien::message: failed to get PM root?\n");
128 root->receivePowerNotification((argi & kClamshellStateBit) ? kIOPMPreventSleep : kIOPMAllowSleep);
130 IOLog("Ambien::message: unknown type %08x (so I won't worry about it)\n", (unsigned int)type);
131 return super::message(type, provider, arg);