X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/1c79356b52d46aa6b508fb032f5ae709b1f2897b..43866e378188c25dd1e2208016ab3cbeb086ae6c:/iokit/Drivers/platform/drvApplePMU/IOPMUADBController.cpp diff --git a/iokit/Drivers/platform/drvApplePMU/IOPMUADBController.cpp b/iokit/Drivers/platform/drvApplePMU/IOPMUADBController.cpp index 5f8896351..f71f313da 100644 --- a/iokit/Drivers/platform/drvApplePMU/IOPMUADBController.cpp +++ b/iokit/Drivers/platform/drvApplePMU/IOPMUADBController.cpp @@ -3,19 +3,22 @@ * * @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@ */ @@ -23,6 +26,7 @@ * 12 Nov 1998 suurballe Created. */ +#include #include #include "IOPMUADBController.h" @@ -69,7 +73,7 @@ bool IOPMUADBController::start ( IOService * nub ) 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 @@ -83,6 +87,8 @@ bool IOPMUADBController::start ( IOService * nub ) 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)) @@ -105,20 +111,22 @@ void IOPMUADBController::free ( ) // 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", @@ -142,18 +150,52 @@ IOReturn IOPMUADBController::localSendMiscCommand(int command, IOByteCount sLeng // ********************************************************************************** // 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); @@ -162,6 +204,21 @@ IOPMUADBController::handleADBInterrupt(IOService *client, UInt8 interruptMask, U } } + +// ********************************************************************************** +// cancelAllIO +// +// ********************************************************************************** +IOReturn IOPMUADBController::cancelAllIO ( void ) +{ + if (waitingForData != NULL) { + dataLen = 0; // read fails with error, write fails quietly + waitingForData->signal(); + } + return kPMUNoError; +} + + // ********************************************************************************** // setAutoPollPeriod // @@ -197,8 +254,8 @@ IOReturn IOPMUADBController::setAutoPollList ( UInt16 PollBitField ) 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; } @@ -223,17 +280,24 @@ IOReturn IOPMUADBController::setAutoPollEnable ( bool enable ) { 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; @@ -250,20 +314,25 @@ IOReturn IOPMUADBController::resetBus ( void ) 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; } @@ -285,7 +354,7 @@ IOReturn IOPMUADBController::flushDevice ( IOADBAddress address ) // 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; @@ -321,7 +390,7 @@ IOReturn IOPMUADBController::readFromDevice ( IOADBAddress address, IOADBRegiste // 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; @@ -370,7 +439,7 @@ IOReturn IOPMUADBController::writeToDevice ( IOADBAddress address, IOADBRegister // 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;