]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
43866e37 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
43866e37 A |
8 | * This file contains Original Code and/or Modifications of Original Code |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
43866e37 A |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* | |
26 | * 12 Nov 1998 suurballe Created. | |
27 | */ | |
28 | ||
29 | #include <IOKit/adb/IOADBController.h> | |
30 | #include <IOKit/IODeviceTreeSupport.h> | |
31 | #include <IOKit/IOPlatformExpert.h> | |
32 | #include <IOKit/IOSyncer.h> | |
33 | ||
34 | class IOPMUADBController : public IOADBController | |
35 | { | |
36 | OSDeclareDefaultStructors(IOPMUADBController) | |
37 | ||
38 | private: | |
39 | enum { | |
40 | kPMUNoError = 0, | |
41 | kPMUInitError = 1, // PMU failed to initialize | |
42 | kPMUParameterError = 2, // Bad parameters | |
43 | kPMUNotSupported = 3, // PMU don't do that (Cuda does, though) | |
44 | kPMUIOError = 4 // Nonspecific I/O failure | |
45 | }; | |
46 | ||
47 | enum { | |
48 | kPMUpMgrADB = 0x20, // send ADB command | |
49 | kPMUpMgrADBoff = 0x21, // turn ADB auto-poll off | |
50 | kPMUreadADB = 0x28, // Apple Desktop Bus | |
51 | kPMUpMgrADBInt = 0x2F, // get ADB interrupt data (Portable only) | |
52 | }; | |
53 | ||
54 | enum { | |
55 | kPMUADBAddressField = 4 | |
56 | }; | |
57 | ||
58 | enum { | |
59 | kPMUResetADBBus = 0x00, | |
60 | kPMUFlushADB = 0x01, | |
61 | kPMUWriteADB = 0x08, | |
62 | kPMUReadADB = 0x0C, | |
63 | kPMURWMaskADB = 0x0C | |
64 | }; | |
65 | ||
66 | enum { // when kPMUADBint is set | |
67 | kPMUADBint = 0x10, | |
9bccf70c | 68 | kPMUenvironmentInt = 0x40, // Environment changed (clamshell) |
1c79356b A |
69 | kPMUwaitinglsc = 0x01, // waiting to listen to charger |
70 | kPMUautoSRQpolling = 0x02, // auto/SRQ polling is enabled | |
71 | kPMUautopoll = 0x04 // input is autopoll data | |
72 | }; | |
73 | ||
74 | // We need this to callPlatformFunction when sending to sendMiscCommand | |
75 | typedef struct SendMiscCommandParameterBlock { | |
76 | int command; | |
77 | IOByteCount sLength; | |
78 | UInt8 *sBuffer; | |
79 | IOByteCount *rLength; | |
80 | UInt8 *rBuffer; | |
81 | } SendMiscCommandParameterBlock; | |
82 | typedef SendMiscCommandParameterBlock *SendMiscCommandParameterBlockPtr; | |
83 | ||
84 | // Local data: | |
85 | IOService *PMUdriver; | |
86 | UInt32 pollList; // ADB autopoll device bitmap | |
87 | bool autopollOn; // TRUE: PMU is autopolling | |
9bccf70c | 88 | bool clamshellOpen; // Normally TRUE |
1c79356b A |
89 | |
90 | UInt32 dataLen; // data len as result of an interrupt | |
91 | UInt8 dataBuffer[256]; // data as result of an interrupt | |
92 | IOSyncer *waitingForData; // syncronizer for reads and writes. | |
93 | ||
94 | // Local interrupt handlers: | |
95 | static void handleADBInterrupt(IOService *client, UInt8 matchingMask, UInt32 length, UInt8 *buffer); | |
96 | ||
97 | // This lock protects the access to the common varialbes of this object: | |
98 | IOLock *requestMutexLock; | |
99 | ||
100 | // A simpler way to interface with the pmu SendMiscCommand | |
0b4e3aa0 | 101 | IOReturn localSendMiscCommand(int command, IOByteCount sLength, UInt8 *sBuffer); |
1c79356b A |
102 | |
103 | public: | |
104 | IOService *probe( IOService * nub, SInt32 * score ); | |
105 | bool start ( IOService * ); | |
106 | void free (); | |
107 | IOReturn setAutoPollPeriod ( int microseconds ); | |
108 | IOReturn getAutoPollPeriod ( int * microseconds ); | |
109 | IOReturn setAutoPollList ( UInt16 activeAddressMask ); | |
110 | IOReturn getAutoPollList ( UInt16 * activeAddressMask ); | |
111 | IOReturn setAutoPollEnable ( bool enable ); | |
112 | IOReturn resetBus ( void ); | |
0b4e3aa0 | 113 | IOReturn cancelAllIO ( void ); |
1c79356b A |
114 | IOReturn flushDevice ( IOADBAddress address ); |
115 | IOReturn readFromDevice ( IOADBAddress address, IOADBRegister adbRegister, UInt8 * data, IOByteCount * length ); | |
116 | IOReturn writeToDevice ( IOADBAddress address, IOADBRegister adbRegister, UInt8 * data, IOByteCount * length ); | |
117 | }; |