*
* @APPLE_LICENSE_HEADER_START@
*
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License"). You may not use this file except in compliance with the
- * License. Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
*
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
* 12 Nov 1998 suurballe Created.
*/
+#include <IOKit/pwr_mgt/IOPM.h>
#include <IOKit/IOSyncer.h>
#include "IOPMUADBController.h"
waitingForData = NULL;
// Registers for the two interrupts that needs to handle:
- if (PMUdriver->callPlatformFunction("registerForPMUInterrupts", true, (void*)kPMUADBint, (void*)handleADBInterrupt, (void*)this, NULL) != kIOReturnSuccess) {
+ if (PMUdriver->callPlatformFunction("registerForPMUInterrupts", true, (void*) (kPMUADBint | kPMUenvironmentInt), (void*)handleADBInterrupt, (void*)this, NULL) != kIOReturnSuccess) {
#ifdef VERBOSE_LOGS_ON
IOLog("IOPMUADBController::start registerForPMUInterrupts kPMUADBint fails\n");
#endif // VERBOSE_LOGS_ON
if (!requestMutexLock)
return false;
+ clamshellOpen = true;
+
// This happens last (while the most common place is the begin) because
// trhe superclass may need the services of the functions above.
if( !super::start(nub))
// And removes the interrupt handler:
if (PMUdriver != NULL)
- PMUdriver->callPlatformFunction("deRegisterClient", true, (void*)this, (void*)kPMUADBint, NULL, NULL);
+ PMUdriver->callPlatformFunction("deRegisterClient", true, (void*)this, (void*)(kPMUADBint | kPMUenvironmentInt), NULL, NULL);
}
// **********************************************************************************
// localSendMiscCommand
//
// **********************************************************************************
-IOReturn IOPMUADBController::localSendMiscCommand(int command, IOByteCount sLength, UInt8 *sBuffer, IOByteCount *rLength, UInt8 *rBuffer)
+IOReturn IOPMUADBController::localSendMiscCommand(int command, IOByteCount sLength, UInt8 *sBuffer)
{
IOReturn returnValue = kIOReturnError;
-
+ IOByteCount rLength = 1;
+ UInt8 rBuffer;
+
// The poupose of this method is to free us from the pain to create a parameter block each time
// we wish to talk to the pmu:
- SendMiscCommandParameterBlock prmBlock = {command, sLength, sBuffer, rLength, rBuffer};
+ SendMiscCommandParameterBlock prmBlock = {command, sLength, sBuffer, &rLength, &rBuffer};
#ifdef VERBOSE_LOGS_ON
IOLog("ApplePMUInterface::localSendMiscCommand 0x%02x %d 0x%08lx 0x%08lx 0x%08lx\n",
// **********************************************************************************
// this is the interrupt handler for all ADB interrupts:
-//
+// A.W. Added code to check for clamshell status, and block all ADB traffic except
+// for POWER key scan code from default ADB keyboard or devices that connect
+// to that keyboard power button.
// **********************************************************************************
/* static */ void
IOPMUADBController::handleADBInterrupt(IOService *client, UInt8 interruptMask, UInt32 length, UInt8 *buffer)
{
- if (interruptMask & kPMUautopoll)
- autopollHandler(client, buffer[0], length - 1, buffer + 1); // yes, call adb input handler
- else {
- IOPMUADBController *myThis = OSDynamicCast(IOPMUADBController, client);
+ IOPMUADBController *myThis = OSDynamicCast(IOPMUADBController, client);
- if ((myThis != NULL) && (myThis->waitingForData != NULL)) {
+ // Check if we are the right client for this interrupt:
+ if (myThis == NULL)
+ return;
+
+ if (interruptMask & kPMUenvironmentInt)
+ {
+ if (buffer)
+ {
+ if (*buffer & kClamshellClosedEventMask)
+ myThis->clamshellOpen = false;
+ else
+ myThis->clamshellOpen = true;
+ }
+ if ( !(interruptMask & kPMUautopoll))
+ {
+ return; //Nothing left to do
+ }
+ }
+ if ((interruptMask & kPMUautopoll) && (myThis->autopollOn))
+ {
+ if (myThis->clamshellOpen)
+ {
+ autopollHandler(client, buffer[0], length - 1, buffer + 1); // yes, call adb input handler
+ }
+ else if ( (buffer[0] == 0x2c) && (buffer[1] == 0x7f) && (buffer[2] == 0x7f))
+ {
+ autopollHandler(client, buffer[0], length - 1, buffer + 1); // POWER down
+ }
+ else if ( (buffer[0] == 0x2c) && (buffer[1] == 0xff) && (buffer[2] == 0xff))
+ {
+ autopollHandler(client, buffer[0], length - 1, buffer + 1); // POWER up
+ }
+
+ }
+ else {
+ if (myThis->waitingForData != NULL) {
// Complets the adb transaction
myThis->dataLen = length - 1;
bcopy(buffer + 1, myThis->dataBuffer, myThis->dataLen);
}
}
+
+// **********************************************************************************
+// cancelAllIO
+//
+// **********************************************************************************
+IOReturn IOPMUADBController::cancelAllIO ( void )
+{
+ if (waitingForData != NULL) {
+ dataLen = 0; // read fails with error, write fails quietly
+ waitingForData->signal();
+ }
+ return kPMUNoError;
+}
+
+
// **********************************************************************************
// setAutoPollPeriod
//
oBuffer[1] = 0x86; // adb Command op.
oBuffer[2] = (UInt8)(PollBitField >> 8); // ??
oBuffer[3] = (UInt8)(PollBitField & 0xff); // ??
-
- localSendMiscCommand (kPMUpMgrADB, 4, oBuffer, NULL, NULL);
+
+ localSendMiscCommand (kPMUpMgrADB, 4, oBuffer);
}
return kPMUNoError;
}
{
UInt8 oBuffer[4];
+ autopollOn = enable;
+
if ( enable ) { // enabling autopoll
oBuffer[0] = 0;
oBuffer[1] = 0x86;
oBuffer[2] = (UInt8)(pollList >> 8);
oBuffer[3] = (UInt8)(pollList & 0xff);
- localSendMiscCommand (kPMUpMgrADB, 4, oBuffer, NULL,NULL);
- autopollOn = true;
+ localSendMiscCommand (kPMUpMgrADB, 4, oBuffer);
}
else { // disabling autopoll;
- localSendMiscCommand (kPMUpMgrADBoff, 0, NULL, NULL, NULL);
+ /* Waits one second for the trackpads to be up (this is needed only in old machines)
+ This is placed here because this is the fist call at wake. */
+ if (IODTMatchNubWithKeys(getPlatform()->getProvider(), "'PowerBook1,1'") ||
+ IODTMatchNubWithKeys(getPlatform()->getProvider(), "'AAPL,PowerBook1998'"))
+ IOSleep(1500);
+
+ localSendMiscCommand (kPMUpMgrADBoff, 0, NULL);
}
return kPMUNoError;
IOLockLock(requestMutexLock);
UInt8 oBuffer[4];
-
+
oBuffer[0] = kPMUResetADBBus;
oBuffer[1] = 0;
oBuffer[2] = 0;
// Reset bus needs to wait for the interrupt to terminate the transaction:
waitingForData = IOSyncer::create();
- localSendMiscCommand (kPMUpMgrADB, 3, oBuffer, NULL, NULL);
+ localSendMiscCommand (kPMUpMgrADB, 3, oBuffer);
waitingForData->wait(); // wait till done
waitingForData = 0;
if (requestMutexLock != NULL)
IOLockUnlock(requestMutexLock);
-
+
+ /* Waits one second for the trackpads to be up (this is needed only in old machines) */
+ if (IODTMatchNubWithKeys(getPlatform()->getProvider(), "'PowerBook1,1'") ||
+ IODTMatchNubWithKeys(getPlatform()->getProvider(), "'AAPL,PowerBook1998'"))
+ IOSleep(1500);
+
return kPMUNoError;
}
// flush device needs to wait for the interrupt to terminate the transaction
waitingForData = IOSyncer::create();
- localSendMiscCommand (kPMUpMgrADB, 3, oBuffer, NULL, NULL);
+ localSendMiscCommand (kPMUpMgrADB, 3, oBuffer);
waitingForData->wait(); // wait till done
waitingForData = 0;
// read from device needs to wait for the interrupt to terminate the transaction
// and to obtain the data from the device.
waitingForData = IOSyncer::create();
- localSendMiscCommand (kPMUpMgrADB, 3, oBuffer, NULL, NULL);
+ localSendMiscCommand (kPMUpMgrADB, 3, oBuffer);
waitingForData->wait(); // wait till done
waitingForData = 0;
// write to the device needs to wait for the interrupt to terminate the transaction
waitingForData = IOSyncer::create();
- localSendMiscCommand (kPMUpMgrADB, 3 + *length, oBuffer, NULL, NULL);
+ localSendMiscCommand (kPMUpMgrADB, 3 + *length, oBuffer);
waitingForData->wait();
waitingForData = 0;