|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: #import <mach/std_types.h>
26: #import <kernserv/ns_timer.h>
27: #import <driverkit/IODirectDevice.h>
28:
29:
30: typedef volatile unsigned char *VIAAddress; // This is an address on the bus
31:
32: // **********************************************************************************
33: //
34: // VIA definitions
35: //
36: // **********************************************************************************
37:
38: enum { // port B
39: // M2 uses VIA2
40: M2Req = 2, // Power manager handshake request
41: M2Ack = 1, // Power manager handshake acknowledge
42: // Hooper uses VIA1
43: HooperReq = 4, // request
44: HooperAck = 3 // acknowledge
45: };
46:
47: enum { // IFR/IER
48: ifCA2 = 0, // CA2 interrupt
49: ifCA1 = 1, // CA1 interrupt
50: ifSR = 2, // SR shift register done
51: ifCB2 = 3, // CB2 interrupt
52: ifCB1 = 4, // CB1 interrupt
53: ifT2 = 5, // T2 timer2 interrupt
54: ifT1 = 6, // T1 timer1 interrupt
55: ifIRQ = 7 // any interrupt
56: };
57:
58: // **********************************************************************************
59: // bits in response to kPMUReadInt command
60: // **********************************************************************************
61:
62: enum {
63: kPMUMD0Int = 0x01, // interrupt type 0 (machine-specific)
64: kPMUMD1Int = 0x02, // interrupt type 1 (machine-specific)
65: kPMUMD2Int = 0x04, // interrupt type 2 (machine-specific)
66: kPMUbrightnessInt = 0x08, // brightness button has been pressed, value changed
67: kPMUADBint = 0x10, // ADB
68: kPMUbattInt = 0x20, // battery
69: kPMUenvironmentInt = 0x40, // environment
70: kPMUoneSecInt = 0x80 // one second interrupt
71: };
72:
73: enum { // when kPMUADBint is set
74: kPMUautopoll = 0x04 // input is autopoll data
75: };
76:
77: // **********************************************************************************
78: // states of the ISR
79: // **********************************************************************************
80:
81: enum {
82: kPMUidle,
83: kPMUxmtLen,
84: kPMUxmtData,
85: kPMUreadLen_cmd,
86: kPMUrcvLen_cmd,
87: kPMUreadData,
88: kPMUrcvData_cmd,
89: kPMUdone,
90: kPMUreadLen_int,
91: kPMUrcvLen_int,
92: kPMUrcvData_int
93: };
94:
95:
96: enum {
97: kPMUADBAddressField = 4
98: };
99:
100: enum {
101: kPMUResetADBBus = 0x00,
102: kPMUFlushADB = 0x01,
103: kPMUWriteADB = 0x08,
104: kPMUReadADB = 0x0C,
105: kPMURWMaskADB = 0x0C
106: };
107:
108: #define MISC_LENGTH 8
109:
110: struct PMURequest {
111: struct PMUmachMessage * next;
112: struct PMUmachMessage * prev;
113: UInt32 pmCommand;
114: UInt32 pmSLength1;
115: UInt8 * pmSBuffer2;
116: UInt32 pmSLength2;
117: UInt8 * pmRBuffer;
118: Boolean pmFlag;
119: pmCallback_func pmCallback;
120: id pmId;
121: UInt32 pmRefNum;
122: UInt8 pmSBuffer1[MISC_LENGTH];
123: };
124:
125: typedef struct PMURequest PMURequest;
126:
127: struct PMUmachMessage {
128: msg_header_t msgHeader;
129: msg_type_t msgType;
130: PMURequest msgBody;
131: };
132:
133: typedef struct PMUmachMessage PMUmachMessage;
134:
135:
136: @interface ApplePMU : IODirectDevice <ADBservice, RTCservice, NVRAMservice, PowerService>
137: {
138: VIAAddress VIA1_shift; // pointers to VIA registers
139: VIAAddress VIA1_auxillaryControl;
140: VIAAddress VIA1_interruptFlag;
141: VIAAddress VIA1_interruptEnable;
142: VIAAddress VIA2_dataB;
143: UInt8 PMreq; // req bit
144: UInt8 PMack; // ack bit
145: UInt8 savedPGEintEn;
146: UInt8 savedSRintEn;
147: pmADBinput_func ADBclient; // Input handler in ADB client
148: id ADBid; // id of ADB client
149: pmCallback_func RTCclient; // Tick handler in RTC client
150: id RTCid; // id of RTC client
151: pmCallback_func PWRclient; // Button handler in Power Management client
152: id PWRid; // id of Power Management client
153: Boolean debugging; // TRUE to avoid COP timeout during debugging
154: PMURequest * clientRequest;
155: PMUmachMessage localMachMessage;
156: UInt8 firstChar;
157: UInt32 charCountS1;
158: UInt32 charCountS2;
159: UInt8 * dataPointer1;
160: UInt8 * dataPointer2;
161: UInt8 * dataPointer;
162: SInt32 charCountR;
163: SInt32 charCountR2;
164: UInt32 PGE_ISR_state;
165: UInt8 receivedByte;
166: UInt8 interruptState[12];
167: PMUmachMessage * queueHead; // our command queue
168: PMUmachMessage * queueTail;
169: port_t port; // our interrupt port
170: UInt32 pollList; // ADB autopoll device bitmap
171: Boolean autopollOn; // TRUE: PMU is autopolling
172: Boolean adb_reading; // TRUE: we have a register read outstanding
173: pmCallback_func who_to_call; // ADB client's callback for solicited input
174: id theirId; // ADB client's id for input callback
175: UInt32 theirRefNum; // ADB client's refnum for input callback
176: ns_time_t adb_read_timeout; // timeout on read to absent adb device
177: Boolean PMU_int_pending; // TRUE: PMU has requested service
178: }
179:
180:
181: + (Boolean)probe : (IODeviceDescription *)deviceDescription; // initialize the PMU driver
182:
183: - initFromDeviceDescription : (IODeviceDescription *)deviceDescription;
184:
185: - free; // shut the driver down
186:
187: - (void)interruptOccurred;
188:
189: - (void)interruptOccurredAt:(int)localInterrupt;
190:
191: - (void)timeoutOccurred;
192:
193: - (void)receiveMsg;
194:
195:
196:
197: // ADB protocol
198: - (void)registerForADBAutopoll :(pmADBinput_func)inputHandler
199: :(id)caller;
200:
201: - (PMUStatus)ADBWrite :(UInt32)DevAddr
202: :(UInt32)DevReg
203: :(UInt32)ByteCount
204: :(UInt8*)Buffer
205: :(UInt32)RefNum
206: :(id)Id
207: :(pmCallback_func)Callback;
208:
209: - (PMUStatus)ADBRead :(UInt32)DevAddr
210: :(UInt32)DevReg
211: :(UInt32)RefNum
212: :(id)Id
213: :(pmCallback_func)Callback;
214:
215: - (PMUStatus)ADBReset :(UInt32)Refnum
216: :(id)Id
217: :(pmCallback_func)Callback;
218:
219: - (PMUStatus)ADBFlush :(UInt32)DevAddr
220: :(UInt32)RefNum
221: :(id)Id
222: :(pmCallback_func)Callback;
223:
224: - (PMUStatus)ADBSetPollList :(UInt32)PollBitField
225: :(UInt32)RefNum
226: :(id)Id
227: :(pmCallback_func)Callback;
228:
229: - (PMUStatus)ADBPollDisable :(UInt32)RefNum
230: :(id)Id
231: :(pmCallback_func)Callback;
232:
233: - (PMUStatus)ADBPollEnable :(UInt32)RefNum
234: :(id)Id
235: :(pmCallback_func)Callback;
236:
237: - (PMUStatus)ADBSetPollRate :(UInt32)newRate
238: :(UInt32)RefNum
239: :(id)Id
240: :(pmCallback_func)Callback;
241:
242: - (PMUStatus)ADBGetPollRate :(UInt32 *)currentRate
243: :(UInt32)RefNum
244: :(id)Id
245: :(pmCallback_func)Callback;
246:
247: - (PMUStatus)ADBSetAlternateKeyboard :(UInt32)DevAddr
248: :(UInt32)RefNum
249: :(id)Id
250: :(pmCallback_func)Callback;
251:
252: - (void)poll_device;
253:
254:
255: // RTC protocol
256: - (void)registerForClockTicks :(pmCallback_func)tickHandler
257: :(id)caller;
258:
259: - (PMUStatus)setRealTimeClock :(UInt8 *)newTime
260: :(UInt32)RefNum
261: :(id)Id
262: :(pmCallback_func)Callback;
263:
264: - (PMUStatus)getRealTimeClock :(UInt8 *)currentTime
265: :(UInt32)RefNum
266: :(id)Id
267: :(pmCallback_func)Callback;
268:
269:
270: // NVRAM protocol
271: - (PMUStatus) readNVRAM :(UInt32)Offset
272: :(UInt32)Length
273: :(UInt8 *)Buffer
274: :(UInt32)RefNum
275: :(id)Id
276: :(pmCallback_func)Callback;
277:
278: - (PMUStatus) writeNVRAM:(UInt32)Offset
279: :(UInt32)Length
280: :(UInt8 *)Buffer
281: :(UInt32)RefNum
282: :(id)Id
283: :(pmCallback_func)Callback;
284:
285:
286: // Power Management protocol
287: - (void)registerForPowerInterrupts :(pmCallback_func)buttonHandler
288: :(id)caller;
289:
290:
291: // Misc protocol
292: - (PMUStatus)sendMiscCommand :(UInt32)Command
293: :(UInt32)SLength
294: :(UInt8 *)SBuffer
295: :(UInt8 *)RBuffer
296: :(UInt32)RefNum
297: :(id)Id
298: :(pmCallback_func)Callback;
299:
300:
301:
302:
303: // private methods
304:
305: - (void)ADBinput:(UInt32)theLength:(UInt8 *)theInput;
306:
307: - (void)StartPMUTransmission:(PMURequest *)plugInMessage;
308:
309: - (void)SendPMUByte:(UInt8)theByte;
310:
311: - (void)ReadPMUByte:(UInt8*)theByte;
312:
313: - (Boolean)WaitForAckLo;
314:
315: - (Boolean)WaitForAckHi;
316:
317: - (UInt8)GetPMUInterruptState;
318:
319: - (void)RestorePMUInterrupt:(UInt8)savedPGEintEn;
320:
321: - (void)DisablePMUInterrupt;
322:
323: - (void)EnablePMUInterrupt;
324:
325: - (void)AcknowledgePMUInterrupt;
326:
327: - (UInt8)GetSRInterruptState;
328:
329: - (void)RestoreSRInterrupt:(UInt8)savedSRintEn;
330:
331: - (void)DisableSRInterrupt;
332:
333: - (void)EnableSRInterrupt;
334:
335: - (void)CheckRequestQueue;
336:
337: @end
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.