|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * The contents of this file constitute Original Code as defined in and ! 7: * are subject to the Apple Public Source License Version 1.1 (the ! 8: * "License"). You may not use this file except in compliance with the ! 9: * License. Please obtain a copy of the License at ! 10: * http://www.apple.com/publicsource and read it before using this file. ! 11: * ! 12: * This Original Code and all software distributed under the License are ! 13: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 14: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 15: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 16: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 17: * License for the specific language governing rights and limitations ! 18: * under the License. ! 19: * ! 20: * @APPLE_LICENSE_HEADER_END@ ! 21: */ ! 22: /* ! 23: * 12 Nov 1998 suurballe Created. ! 24: */ ! 25: ! 26: #include <IOKit/IOSyncer.h> ! 27: #include "IOPMUADBController.h" ! 28: #include "pmupriv.h" ! 29: ! 30: #define super IOADBController ! 31: OSDefineMetaClassAndStructors(IOPMUADBController, IOADBController) ! 32: ! 33: // ********************************************************************************** ! 34: // init ! 35: // ! 36: // ********************************************************************************** ! 37: bool IOPMUADBController::init ( OSDictionary * properties, ApplePMU * driver ) ! 38: { ! 39: PMUdriver = driver; ! 40: pollList = 0; ! 41: autopollOn = false; ! 42: ! 43: return super::init(properties); ! 44: } ! 45: ! 46: ! 47: // ********************************************************************************** ! 48: // start ! 49: // ! 50: // ********************************************************************************** ! 51: bool IOPMUADBController::start ( IOService * nub ) ! 52: { ! 53: if( !super::start(nub)) ! 54: return false; ! 55: ! 56: PMUdriver->registerForADBInterrupts ( autopollHandler, this ); ! 57: return true; ! 58: } ! 59: ! 60: ! 61: // ********************************************************************************** ! 62: // setAutoPollPeriod ! 63: // ! 64: // ********************************************************************************** ! 65: IOReturn IOPMUADBController::setAutoPollPeriod ( int ) ! 66: { ! 67: return kPMUNotSupported; ! 68: } ! 69: ! 70: ! 71: // ********************************************************************************** ! 72: // getAutoPollPeriod ! 73: // ! 74: // ********************************************************************************** ! 75: IOReturn IOPMUADBController::getAutoPollPeriod ( int * ) ! 76: { ! 77: return kPMUNotSupported; ! 78: } ! 79: ! 80: ! 81: // ********************************************************************************** ! 82: // setAutoPollList ! 83: // ! 84: // ********************************************************************************** ! 85: IOReturn IOPMUADBController::setAutoPollList ( UInt16 PollBitField ) ! 86: { ! 87: PMUrequest request; ! 88: ! 89: pollList = PollBitField; // remember the new poll list ! 90: ! 91: if ( autopollOn ) { ! 92: request.sync = IOSyncer::create(); ! 93: request.pmCommand = kPMUpMgrADB; // if PMU is currently autopolling, ! 94: request.pmFlag = false; // give it the new list ! 95: request.pmSLength1 = 4; ! 96: request.pmSBuffer2 = NULL; ! 97: request.pmSLength2 = 0; ! 98: request.pmRBuffer = NULL; ! 99: request.pmSBuffer1[0] = 0; ! 100: request.pmSBuffer1[1] = 0x86; ! 101: request.pmSBuffer1[2] = (UInt8)(PollBitField >> 8); ! 102: request.pmSBuffer1[3] = (UInt8)(PollBitField & 0xff); ! 103: ! 104: PMUdriver->enqueueCommand(&request); ! 105: request.sync->wait(); // wait till done ! 106: } ! 107: return kPMUNoError; ! 108: } ! 109: ! 110: ! 111: // ********************************************************************************** ! 112: // getAutoPollList ! 113: // ! 114: // ********************************************************************************** ! 115: IOReturn IOPMUADBController::getAutoPollList ( UInt16 * activeAddressMask ) ! 116: { ! 117: *activeAddressMask = pollList; ! 118: return kPMUNoError; ! 119: } ! 120: ! 121: ! 122: // ********************************************************************************** ! 123: // setAutoPollEnable ! 124: // ! 125: // ********************************************************************************** ! 126: IOReturn IOPMUADBController::setAutoPollEnable ( bool enable ) ! 127: { ! 128: PMUrequest request; ! 129: ! 130: if ( enable ) { // enabling autopoll ! 131: autopollOn = true; ! 132: request.sync = IOSyncer::create(); ! 133: request.pmCommand = kPMUpMgrADB; // give it the list we have ! 134: request.pmFlag = false; ! 135: request.pmSLength1 = 4; ! 136: request.pmSBuffer2 = NULL; ! 137: request.pmSLength2 = 0; ! 138: request.pmRBuffer = NULL; ! 139: request.pmSBuffer1[0] = 0; ! 140: request.pmSBuffer1[1] = 0x86; ! 141: request.pmSBuffer1[2] = (UInt8)(pollList >> 8); ! 142: request.pmSBuffer1[3] = (UInt8)(pollList & 0xff); ! 143: ! 144: PMUdriver->enqueueCommand(&request); ! 145: request.sync->wait(); // wait till done ! 146: return kPMUNoError; ! 147: } ! 148: else { // disabling autopoll ! 149: autopollOn = false; ! 150: request.sync = IOSyncer::create(); ! 151: request.pmCommand = kPMUpMgrADBoff; ! 152: request.pmFlag = false; ! 153: request.pmSLength1 = 0; ! 154: request.pmSBuffer2 = NULL; ! 155: request.pmSLength2 = 0; ! 156: request.pmRBuffer = NULL; ! 157: ! 158: PMUdriver->enqueueCommand(&request); ! 159: request.sync->wait(); // wait till done ! 160: ! 161: return kPMUNoError; ! 162: } ! 163: } ! 164: ! 165: ! 166: // ********************************************************************************** ! 167: // resetBus ! 168: // ! 169: // ********************************************************************************** ! 170: IOReturn IOPMUADBController::resetBus ( void ) ! 171: { ! 172: PMUrequest request; ! 173: ! 174: request.sync = IOSyncer::create(); ! 175: request.pmCommand = kPMUpMgrADB; ! 176: request.pmFlag = true; // this op solicits input from PGE ! 177: request.pmSLength1 = 3; ! 178: request.pmSBuffer2 = NULL; ! 179: request.pmSLength2 = 0; ! 180: request.pmRBuffer = NULL; ! 181: request.pmSBuffer1[0] = kPMUResetADBBus; ! 182: request.pmSBuffer1[1] = 0; ! 183: request.pmSBuffer1[2] = 0; ! 184: ! 185: PMUdriver->enqueueCommand(&request); ! 186: request.sync->wait(); // wait till done ! 187: ! 188: return kPMUNoError; ! 189: } ! 190: ! 191: ! 192: // ********************************************************************************** ! 193: // flushDevice ! 194: // ! 195: // ********************************************************************************** ! 196: IOReturn IOPMUADBController::flushDevice ( IOADBAddress address ) ! 197: { ! 198: PMUrequest request; ! 199: ! 200: request.sync = IOSyncer::create(); ! 201: request.pmCommand = kPMUpMgrADB; ! 202: request.pmFlag = true; ! 203: request.pmSLength1 = 3; ! 204: request.pmSBuffer2 = NULL; ! 205: request.pmSLength2 = 0; ! 206: request.pmRBuffer = NULL; ! 207: request.pmSBuffer1[0] = kPMUFlushADB | (address << kPMUADBAddressField); ! 208: if ( autopollOn ) { ! 209: request.pmSBuffer1[1] = 2; ! 210: } ! 211: else { ! 212: request.pmSBuffer1[1] = 0; ! 213: } ! 214: request.pmSBuffer1[2] = 0; ! 215: ! 216: PMUdriver->enqueueCommand(&request); ! 217: request.sync->wait(); // wait till done ! 218: ! 219: return kPMUNoError; ! 220: } ! 221: ! 222: ! 223: // ********************************************************************************** ! 224: // readFromDevice ! 225: // ! 226: // The length parameter is ignored on entry. It is set on exit to reflect ! 227: // the number of bytes read from the device. ! 228: // ********************************************************************************** ! 229: IOReturn IOPMUADBController::readFromDevice ( IOADBAddress address, IOADBRegister adbRegister, ! 230: UInt8 * data, IOByteCount * length ) ! 231: { ! 232: PMUrequest request; ! 233: UInt8 * source; ! 234: UInt8 * dest; ! 235: int copylength, i; ! 236: ! 237: if ( (length == NULL) || (data == NULL) ) { ! 238: return kPMUParameterError; ! 239: } ! 240: ! 241: request.sync = IOSyncer::create(); ! 242: request.pmCommand = kPMUpMgrADB; ! 243: request.pmFlag = true; // this op solicits input from PGE ! 244: request.pmSLength1 = 3; ! 245: request.pmSBuffer2 = NULL; ! 246: request.pmSLength2 = 0; ! 247: request.pmSBuffer1[0] = kPMUReadADB | (address << kPMUADBAddressField) | (adbRegister); ! 248: if ( autopollOn ) { ! 249: request.pmSBuffer1[1] = 2; ! 250: } ! 251: else { ! 252: request.pmSBuffer1[1] = 0; ! 253: } ! 254: request.pmSBuffer1[2] = 0; ! 255: ! 256: PMUdriver->enqueueCommand(&request); ! 257: request.sync->wait(); // wait till done ! 258: ! 259: *length = request.pmRLength; // set caller's length ! 260: ! 261: if (request.pmRLength == 0 ) { // nothing read; device isn't there ! 262: return ADB_RET_NOTPRESENT; ! 263: } ! 264: else { ! 265: source = request.pmRBuffer; // copy all but first two bytes of adb data ! 266: dest = data; ! 267: if ( *length > request.pmRLength ) { ! 268: copylength = request.pmRLength; ! 269: } ! 270: else { ! 271: copylength =*length; ! 272: } ! 273: for ( i = 0; i < copylength; i++ ) { ! 274: *dest++ = *source++; ! 275: } ! 276: return ADB_RET_OK; ! 277: } ! 278: } ! 279: ! 280: ! 281: // ********************************************************************************** ! 282: // writeToDevice ! 283: // ! 284: // ********************************************************************************** ! 285: IOReturn IOPMUADBController::writeToDevice ( IOADBAddress address, IOADBRegister adbRegister, ! 286: UInt8 * data, IOByteCount * length ) ! 287: { ! 288: PMUrequest request; ! 289: ! 290: if ( (* length == 0) || (data == NULL) || (* length > (MISC_LENGTH)) ) ! 291: { ! 292: return kPMUParameterError; ! 293: } ! 294: ! 295: request.sync = IOSyncer::create(); ! 296: request.pmCommand = kPMUpMgrADB; ! 297: request.pmFlag = true; // this op solicits input from PGE ! 298: request.pmSLength1 = 3; ! 299: request.pmSBuffer2 = data; ! 300: request.pmSLength2 = *length; ! 301: request.pmRBuffer = NULL; ! 302: request.pmSBuffer1[0] = kPMUWriteADB | (address << kPMUADBAddressField) | (adbRegister); ! 303: if ( autopollOn ) { ! 304: request.pmSBuffer1[1] = 2; ! 305: } ! 306: else { ! 307: request.pmSBuffer1[1] = 0; ! 308: } ! 309: request.pmSBuffer1[2] = *length; ! 310: ! 311: PMUdriver->enqueueCommand(&request); ! 312: request.sync->wait(); // wait till done ! 313: ! 314: return kPMUNoError; ! 315: } ! 316: ! 317:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.