Skip to content

Commit 78b5e0b

Browse files
committed
Check both PS2 and SMBus power states
1 parent 83868f0 commit 78b5e0b

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

VoodooRMI/Transports/SMBus/RMISMBus.cpp

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ bool RMISMBus::start(IOService *provider)
5858
IOService *ps2 = OSDynamicCast(IOService, device_nub->getProperty("PS/2 Parent"));
5959
if (ps2) {
6060
(void) ps2->registerInterestedDriver(this);
61-
} else {
62-
PMinit();
63-
device_nub->joinPMtree(this);
64-
registerPowerDriver(this, RMIPowerStates, 2);
61+
ps2PowerDriver = true;
6562
}
6663

64+
// Receive power notifications for sleep/wake
65+
PMinit();
66+
device_nub->joinPMtree(this);
67+
registerPowerDriver(this, RMIPowerStates, 2);
68+
6769
setProperty(RMIBusSupported, kOSBooleanTrue);
6870
registerService(kIOServiceAsynchronous);
6971
return true;
@@ -279,9 +281,36 @@ IOReturn RMISMBus::setPowerState(unsigned long whichState, IOService* whatDevice
279281
if (whatDevice != this)
280282
return kIOPMAckImplied;
281283

282-
if (whichState == RMI_POWER_OFF) {
283-
messageClient(kIOMessageRMI4Sleep, bus);
284+
IOLogInfo("Received SMBus Power State Change: 0x%lx", whichState);
285+
smbusAwake = whichState == RMI_POWER_ON;
286+
return processPowerState(whichState);
287+
}
288+
289+
IOReturn RMISMBus::powerStateDidChangeTo(IOPMPowerFlags capabilities, unsigned long stateNumber, IOService *whatDevice) {
290+
unsigned long newState;
291+
292+
IOLogInfo("Received PS2 Power State Change: 0x%lx", capabilities);
293+
ps2Awake = capabilities & kIOPMDeviceUsable;
294+
if (capabilities & kIOPMDeviceUsable) {
295+
newState = RMI_POWER_ON;
284296
} else {
297+
newState = RMI_POWER_OFF;
298+
}
299+
300+
return processPowerState(newState);
301+
}
302+
303+
IOReturn RMISMBus::processPowerState(unsigned long whichState) {
304+
if (ps2PowerDriver && ps2Awake != smbusAwake) {
305+
IOLogDebug("PS2 Power State (%b) != SMB Power State (%b) - Waiting!",
306+
ps2Awake, smbusAwake);
307+
return kIOPMAckImplied;
308+
}
309+
310+
if (whichState == RMI_POWER_OFF && vrmiAwake) {
311+
messageClient(kIOMessageRMI4Sleep, bus);
312+
vrmiAwake = false;
313+
} else if (whichState == RMI_POWER_ON && !vrmiAwake) {
285314
// Put trackpad in SMBus mode again
286315
int retval = reset();
287316
if (retval < 0) {
@@ -295,21 +324,11 @@ IOReturn RMISMBus::setPowerState(unsigned long whichState, IOService* whatDevice
295324
IOLogError("Failed to resume trackpad!");
296325
return kIOPMAckImplied;
297326
}
298-
}
299-
300-
return kIOPMAckImplied;
301-
}
302-
303-
IOReturn RMISMBus::powerStateDidChangeTo(IOPMPowerFlags capabilities, unsigned long stateNumber, IOService *whatDevice) {
304-
unsigned long newState;
305-
IOLogInfo("Received PS2 Power State Change: 0x%lx", capabilities);
306-
if (capabilities & kIOPMDeviceUsable) {
307-
newState = RMI_POWER_ON;
308-
} else {
309-
newState = RMI_POWER_OFF;
327+
328+
vrmiAwake = true;
310329
}
311330

312-
return setPowerState(newState, this);
331+
return kIOPMAckImplied;
313332
}
314333

315334
OSDictionary *RMISMBus::createConfig() {

VoodooRMI/Transports/SMBus/RMISMBus.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ class RMISMBus : public RMITransport {
5151
struct mapping_table_entry mapping_table[RMI_SMB2_MAP_SIZE];
5252
UInt8 table_index {0};
5353

54+
bool ps2PowerDriver {false};
55+
bool ps2Awake {true};
56+
bool smbusAwake {true};
57+
bool vrmiAwake {true};
58+
5459
bool rmiStart();
60+
IOReturn processPowerState(unsigned long whichState);
5561
int rmi_smb_get_version();
5662
int rmi_smb_get_command_code(UInt16 rmiaddr, int bytecount,
5763
bool isread, UInt8 *commandcode);

0 commit comments

Comments
 (0)