]> git.saurik.com Git - apple/xnu.git/blob - iokit/Drivers/platform/drvApplePMU/IOPMUADBController.h
697967eff44da66d6f6f4c7aaa2e24172a7b706b
[apple/xnu.git] / iokit / Drivers / platform / drvApplePMU / IOPMUADBController.h
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/adb/IOADBController.h>
27 #include <IOKit/IODeviceTreeSupport.h>
28 #include <IOKit/IOPlatformExpert.h>
29 #include <IOKit/IOSyncer.h>
30
31 class IOPMUADBController : public IOADBController
32 {
33 OSDeclareDefaultStructors(IOPMUADBController)
34
35 private:
36 enum {
37 kPMUNoError = 0,
38 kPMUInitError = 1, // PMU failed to initialize
39 kPMUParameterError = 2, // Bad parameters
40 kPMUNotSupported = 3, // PMU don't do that (Cuda does, though)
41 kPMUIOError = 4 // Nonspecific I/O failure
42 };
43
44 enum {
45 kPMUpMgrADB = 0x20, // send ADB command
46 kPMUpMgrADBoff = 0x21, // turn ADB auto-poll off
47 kPMUreadADB = 0x28, // Apple Desktop Bus
48 kPMUpMgrADBInt = 0x2F, // get ADB interrupt data (Portable only)
49 };
50
51 enum {
52 kPMUADBAddressField = 4
53 };
54
55 enum {
56 kPMUResetADBBus = 0x00,
57 kPMUFlushADB = 0x01,
58 kPMUWriteADB = 0x08,
59 kPMUReadADB = 0x0C,
60 kPMURWMaskADB = 0x0C
61 };
62
63 enum { // when kPMUADBint is set
64 kPMUADBint = 0x10,
65 kPMUenvironmentInt = 0x40, // Environment changed (clamshell)
66 kPMUwaitinglsc = 0x01, // waiting to listen to charger
67 kPMUautoSRQpolling = 0x02, // auto/SRQ polling is enabled
68 kPMUautopoll = 0x04 // input is autopoll data
69 };
70
71 // We need this to callPlatformFunction when sending to sendMiscCommand
72 typedef struct SendMiscCommandParameterBlock {
73 int command;
74 IOByteCount sLength;
75 UInt8 *sBuffer;
76 IOByteCount *rLength;
77 UInt8 *rBuffer;
78 } SendMiscCommandParameterBlock;
79 typedef SendMiscCommandParameterBlock *SendMiscCommandParameterBlockPtr;
80
81 // Local data:
82 IOService *PMUdriver;
83 UInt32 pollList; // ADB autopoll device bitmap
84 bool autopollOn; // TRUE: PMU is autopolling
85 bool clamshellOpen; // Normally TRUE
86
87 UInt32 dataLen; // data len as result of an interrupt
88 UInt8 dataBuffer[256]; // data as result of an interrupt
89 IOSyncer *waitingForData; // syncronizer for reads and writes.
90
91 // Local interrupt handlers:
92 static void handleADBInterrupt(IOService *client, UInt8 matchingMask, UInt32 length, UInt8 *buffer);
93
94 // This lock protects the access to the common varialbes of this object:
95 IOLock *requestMutexLock;
96
97 // A simpler way to interface with the pmu SendMiscCommand
98 IOReturn localSendMiscCommand(int command, IOByteCount sLength, UInt8 *sBuffer);
99
100 public:
101 IOService *probe( IOService * nub, SInt32 * score );
102 bool start ( IOService * );
103 void free ();
104 IOReturn setAutoPollPeriod ( int microseconds );
105 IOReturn getAutoPollPeriod ( int * microseconds );
106 IOReturn setAutoPollList ( UInt16 activeAddressMask );
107 IOReturn getAutoPollList ( UInt16 * activeAddressMask );
108 IOReturn setAutoPollEnable ( bool enable );
109 IOReturn resetBus ( void );
110 IOReturn cancelAllIO ( void );
111 IOReturn flushDevice ( IOADBAddress address );
112 IOReturn readFromDevice ( IOADBAddress address, IOADBRegister adbRegister, UInt8 * data, IOByteCount * length );
113 IOReturn writeToDevice ( IOADBAddress address, IOADBRegister adbRegister, UInt8 * data, IOByteCount * length );
114 };