|
|
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: * 18 June 1998
24: * Start IOKit version.
25: */
26:
27: #include "AppleADBKeyboard.h"
28: #include <IOKit/hidsystem/IOHIDTypes.h>
29: #include <IOKit/IOLib.h>
30:
31: #define super IOHIKeyboard
32: OSDefineMetaClassAndStructors(AppleADBKeyboard,IOHIKeyboard)
33:
34:
35: static void new_kbd_data ( IOService * us, UInt8 adbCommand, IOByteCount length, UInt8 * data );
36: static void asyncFunc ( thread_call_param_t, thread_call_param_t );
37:
38:
39: // **********************************************************************************
40: // start
41: //
42: // **********************************************************************************
43: bool AppleADBKeyboard::start ( IOService * theNub )
44: {
45: if( !super::start(theNub))
46: return false;
47:
48: adbDevice = (IOADBDevice *)theNub;
49: if( !adbDevice->seizeForClient(this, new_kbd_data) ) {
50: IOLog("%s: Seize failed\n", getName());
51: return false;
52: }
53:
54: setAlphaLockFeedback(false);
55:
56: clock_interval_to_absolutetime_interval( 4, kSecondScale, &rebootTime);
57: clock_interval_to_absolutetime_interval( 1, kSecondScale, &debuggerTime);
58:
59: return true;
60: }
61:
62:
63: // **********************************************************************************
64: // interfaceID
65: //
66: // **********************************************************************************
67: UInt32 AppleADBKeyboard::interfaceID ( void )
68: {
69: return NX_EVS_DEVICE_INTERFACE_ADB;
70: }
71:
72:
73: // **********************************************************************************
74: // deviceType
75: //
76: // **********************************************************************************
77: UInt32 AppleADBKeyboard::deviceType ( void )
78: {
79: return adbDevice->handlerID();
80: }
81:
82:
83: // **********************************************************************************
84: // setAlphaLockFeedback
85: // This is usually called on a call-out thread after the caps-lock key is pressed.
86: // ADB operations to PMU are synchronous, and this is must not be done
87: // on the call-out thread since that is the PMU driver workloop thread, and
88: // it will block itself.
89: //
90: // Therefore, we schedule the ADB write to disconnect the call-out thread
91: // and the one that initiates the ADB write.
92: //
93: // **********************************************************************************
94: void AppleADBKeyboard::setAlphaLockFeedback ( bool to )
95: {
96: turnLEDon = to;
97:
98: thread_call_func(asyncFunc, (thread_call_param_t)this, true);
99: }
100:
101:
102:
103:
104: // **********************************************************************************
105: // asyncFunc
106: //
107: // Called asynchronously to turn on/off the capslock LED
108: //
109: // **********************************************************************************
110: static void asyncFunc ( thread_call_param_t self, thread_call_param_t )
111: {
112:
113: UInt16 value;
114: IOByteCount length = sizeof( UInt16);
115:
116: value = (((AppleADBKeyboard*)self)->turnLEDon ?
117: 0 : ADBKS_LED_CAPSLOCK) | ADBKS_LED_NUMLOCK | ADBKS_LED_SCROLLLOCK;
118:
119: ((AppleADBKeyboard*)self)->adbDevice->writeRegister(2, (UInt8 *)&value, &length);
120: }
121:
122:
123: // **********************************************************************************
124: // new_kbd_data
125: //
126: // **********************************************************************************
127: static void new_kbd_data ( IOService * us, UInt8 adbCommand, IOByteCount length, UInt8 * data )
128: {
129: ((AppleADBKeyboard *)us)->packet(data,length,adbCommand);
130: }
131:
132: // **********************************************************************************
133: // dispatchKeyboardEvent
134: //
135: // **********************************************************************************
136: extern "C" {
137: void Debugger( const char * );
138: void boot(int paniced, int howto, char * command);
139: #define RB_HALT 0x08 /* don't reboot, just halt */
140: }
141:
142: static void AppleADBKeyboardReboot( thread_call_param_t arg, thread_call_param_t )
143: {
144: boot( 0, (int) arg, 0 );
145: }
146:
147: void AppleADBKeyboard::dispatchKeyboardEvent(unsigned int keyCode,
148: /* direction */ bool goingDown,
149: /* timeStamp */ AbsoluteTime time)
150: {
151: if( !goingDown && programmerKey) {
152: programmerKey = false;
153: EVK_KEYUP( ADBK_CONTROL, _keyState);
154: SUB_ABSOLUTETIME( &time, &programmerKeyTime );
155: if( CMP_ABSOLUTETIME( &time, &rebootTime) >= 0) {
156:
157: thread_call_func( AppleADBKeyboardReboot,
158: (void *) RB_HALT, true );
159: } else if( CMP_ABSOLUTETIME( &time, &debuggerTime) >= 0) {
160: Debugger("Programmer Key");
161: }
162:
163: } else if( (keyCode == ADBK_POWER)
164: && (EVK_IS_KEYDOWN( ADBK_CONTROL, _keyState))) {
165:
166: if( !programmerKey) {
167: programmerKey = true;
168: programmerKeyTime = time;
169: }
170: return;
171: }
172:
173: super::dispatchKeyboardEvent( keyCode, goingDown, time );
174: }
175:
176: // **********************************************************************************
177: // packet
178: //
179: // **********************************************************************************
180: IOReturn AppleADBKeyboard::packet (UInt8 * data, IOByteCount, UInt8 adbCommand )
181: {
182: unsigned int keycode1, keycode2;
183: bool down;
184: AbsoluteTime now;
185:
186: keycode1 = *data;
187: down = ((keycode1 & 0x80) == 0);
188: keycode1 &= 0x7f;
189: if(keycode1 == 0x7e) keycode1 = ADBK_POWER;
190: clock_get_uptime(&now);
191:
192: dispatchKeyboardEvent(keycode1,down,now);
193:
194: keycode2 = *(data + 1);
195: if( keycode2 != 0xff ) {
196: down = ((keycode2 & 0x80) == 0);
197: keycode2 &= 0x7f;
198: if( keycode2 == 0x7e) keycode2 = ADBK_POWER;
199: if( (keycode1 != ADBK_POWER) || (keycode2 != ADBK_POWER))
200: dispatchKeyboardEvent(keycode2,down,now);
201: }
202:
203: return kIOReturnSuccess;
204: }
205:
206:
207: // **********************************************************************************
208: // maxKeyCodes
209: //
210: // **********************************************************************************
211: UInt32 AppleADBKeyboard::maxKeyCodes ( void )
212: {
213: return 0x80;
214: }
215:
216:
217: // **********************************************************************************
218: // defaultKeymapOfLength
219: //
220: // **********************************************************************************
221: const unsigned char * AppleADBKeyboard::defaultKeymapOfLength (UInt32 * length )
222: {
223: static const unsigned char appleUSAKeyMap[] = {
224: 0x00,0x00,0x07,
225: 0x00,0x01,0x39,
226: 0x01,0x02,0x38,0x7b,
227: 0x02,0x02,0x36,0x7d,0x03,0x02,0x3a,0x7c,0x04,
228: 0x01,0x37,0x05,0x15,0x52,0x41,0x4c,0x53,0x54,0x55,0x45,0x58,0x57,0x56,0x5b,0x5c,
229: 0x43,0x4b,0x51,0x3b,0x3d,0x3e,0x3c,0x4e,0x59,0x06,0x01,0x72,0x7b,0x0d,0x00,0x61,
230: 0x00,0x41,0x00,0x01,0x00,0x01,0x00,0xca,0x00,0xc7,0x00,0x01,0x00,0x01,0x0d,0x00,
231: 0x73,0x00,0x53,0x00,0x13,0x00,0x13,0x00,0xfb,0x00,0xa7,0x00,0x13,0x00,0x13,0x0d,
232: 0x00,0x64,0x00,0x44,0x00,0x04,0x00,0x04,0x01,0x44,0x01,0xb6,0x00,0x04,0x00,0x04,
233: 0x0d,0x00,0x66,0x00,0x46,0x00,0x06,0x00,0x06,0x00,0xa6,0x01,0xac,0x00,0x06,0x00,
234: 0x06,0x0d,0x00,0x68,0x00,0x48,0x00,0x08,0x00,0x08,0x00,0xe3,0x00,0xeb,0x00,0x00,
235: 0x18,0x00,0x0d,0x00,0x67,0x00,0x47,0x00,0x07,0x00,0x07,0x00,0xf1,0x00,0xe1,0x00,
236: 0x07,0x00,0x07,0x0d,0x00,0x7a,0x00,0x5a,0x00,0x1a,0x00,0x1a,0x00,0xcf,0x01,0x57,
237: 0x00,0x1a,0x00,0x1a,0x0d,0x00,0x78,0x00,0x58,0x00,0x18,0x00,0x18,0x01,0xb4,0x01,
238: 0xce,0x00,0x18,0x00,0x18,0x0d,0x00,0x63,0x00,0x43,0x00,0x03,0x00,0x03,0x01,0xe3,
239: 0x01,0xd3,0x00,0x03,0x00,0x03,0x0d,0x00,0x76,0x00,0x56,0x00,0x16,0x00,0x16,0x01,
240: 0xd6,0x01,0xe0,0x00,0x16,0x00,0x16,0x02,0x00,0x3c,0x00,0x3e,0x0d,0x00,0x62,0x00,
241: 0x42,0x00,0x02,0x00,0x02,0x01,0xe5,0x01,0xf2,0x00,0x02,0x00,0x02,0x0d,0x00,0x71,
242: 0x00,0x51,0x00,0x11,0x00,0x11,0x00,0xfa,0x00,0xea,0x00,0x11,0x00,0x11,0x0d,0x00,
243: 0x77,0x00,0x57,0x00,0x17,0x00,0x17,0x01,0xc8,0x01,0xc7,0x00,0x17,0x00,0x17,0x0d,
244: 0x00,0x65,0x00,0x45,0x00,0x05,0x00,0x05,0x00,0xc2,0x00,0xc5,0x00,0x05,0x00,0x05,
245: 0x0d,0x00,0x72,0x00,0x52,0x00,0x12,0x00,0x12,0x01,0xe2,0x01,0xd2,0x00,0x12,0x00,
246: 0x12,0x0d,0x00,0x79,0x00,0x59,0x00,0x19,0x00,0x19,0x00,0xa5,0x01,0xdb,0x00,0x19,
247: 0x00,0x19,0x0d,0x00,0x74,0x00,0x54,0x00,0x14,0x00,0x14,0x01,0xe4,0x01,0xd4,0x00,
248: 0x14,0x00,0x14,0x0a,0x00,0x31,0x00,0x21,0x01,0xad,0x00,0xa1,0x0e,0x00,0x32,0x00,
249: 0x40,0x00,0x32,0x00,0x00,0x00,0xb2,0x00,0xb3,0x00,0x00,0x00,0x00,0x0a,0x00,0x33,
250: 0x00,0x23,0x00,0xa3,0x01,0xba,0x0a,0x00,0x34,0x00,0x24,0x00,0xa2,0x00,0xa8,0x0e,
251: 0x00,0x36,0x00,0x5e,0x00,0x36,0x00,0x1e,0x00,0xb6,0x00,0xc3,0x00,0x1e,0x00,0x1e,
252: 0x0a,0x00,0x35,0x00,0x25,0x01,0xa5,0x00,0xbd,0x0a,0x00,0x3d,0x00,0x2b,0x01,0xb9,
253: 0x01,0xb1,0x0a,0x00,0x39,0x00,0x28,0x00,0xac,0x00,0xab,0x0a,0x00,0x37,0x00,0x26,
254: 0x01,0xb0,0x01,0xab,0x0e,0x00,0x2d,0x00,0x5f,0x00,0x1f,0x00,0x1f,0x00,0xb1,0x00,
255: 0xd0,0x00,0x1f,0x00,0x1f,0x0a,0x00,0x38,0x00,0x2a,0x00,0xb7,0x00,0xb4,0x0a,0x00,
256: 0x30,0x00,0x29,0x00,0xad,0x00,0xbb,0x0e,0x00,0x5d,0x00,0x7d,0x00,0x1d,0x00,0x1d,
257: 0x00,0x27,0x00,0xba,0x00,0x1d,0x00,0x1d,0x0d,0x00,0x6f,0x00,0x4f,0x00,0x0f,0x00,
258: 0x0f,0x00,0xf9,0x00,0xe9,0x00,0x0f,0x00,0x0f,0x0d,0x00,0x75,0x00,0x55,0x00,0x15,
259: 0x00,0x15,0x00,0xc8,0x00,0xcd,0x00,0x15,0x00,0x15,0x0e,0x00,0x5b,0x00,0x7b,0x00,
260: 0x1b,0x00,0x1b,0x00,0x60,0x00,0xaa,0x00,0x1b,0x00,0x1b,0x0d,0x00,0x69,0x00,0x49,
261: 0x00,0x09,0x00,0x09,0x00,0xc1,0x00,0xf5,0x00,0x09,0x00,0x09,0x0d,0x00,0x70,0x00,
262: 0x50,0x00,0x10,0x00,0x10,0x01,0x70,0x01,0x50,0x00,0x10,0x00,0x10,0x10,0x00,0x0d,
263: 0x00,0x03,0x0d,0x00,0x6c,0x00,0x4c,0x00,0x0c,0x00,0x0c,0x00,0xf8,0x00,0xe8,0x00,
264: 0x0c,0x00,0x0c,0x0d,0x00,0x6a,0x00,0x4a,0x00,0x0a,0x00,0x0a,0x00,0xc6,0x00,0xae,
265: 0x00,0x0a,0x00,0x0a,0x0a,0x00,0x27,0x00,0x22,0x00,0xa9,0x01,0xae,0x0d,0x00,0x6b,
266: 0x00,0x4b,0x00,0x0b,0x00,0x0b,0x00,0xce,0x00,0xaf,0x00,0x0b,0x00,0x0b,0x0a,0x00,
267: 0x3b,0x00,0x3a,0x01,0xb2,0x01,0xa2,0x0e,0x00,0x5c,0x00,0x7c,0x00,0x1c,0x00,0x1c,
268: 0x00,0xe3,0x00,0xeb,0x00,0x1c,0x00,0x1c,0x0a,0x00,0x2c,0x00,0x3c,0x00,0xcb,0x01,
269: 0xa3,0x0a,0x00,0x2f,0x00,0x3f,0x01,0xb8,0x00,0xbf,0x0d,0x00,0x6e,0x00,0x4e,0x00,
270: 0x0e,0x00,0x0e,0x00,0xc4,0x01,0xaf,0x00,0x0e,0x00,0x0e,0x0d,0x00,0x6d,0x00,0x4d,
271: 0x00,0x0d,0x00,0x0d,0x01,0x6d,0x01,0xd8,0x00,0x0d,0x00,0x0d,0x0a,0x00,0x2e,0x00,
272: 0x3e,0x00,0xbc,0x01,0xb3,0x02,0x00,0x09,0x00,0x19,0x0c,0x00,0x20,0x00,0x00,0x00,
273: 0x80,0x00,0x00,0x0a,0x00,0x60,0x00,0x7e,0x00,0x60,0x01,0xbb,0x02,0x00,0x7f,0x00,
274: 0x08,0xff,0x02,0x00,0x1b,0x00,0x7e,0xff,0xff,0xff,0xff,0xff,0x00,0x01,0xac,0x00,
275: 0x01,0xae,0x00,0x01,0xaf,0x00,0x01,0xad,0xff,0xff,0x00,0x00,0x2e,0xff,0x00,0x00,
276: 0x2a,0xff,0x00,0x00,0x2b,0xff,0x00,0x00,0x1b,0xff,0xff,0xff,0x0e,0x00,0x2f,0x00,
277: 0x5c,0x00,0x2f,0x00,0x1c,0x00,0x2f,0x00,0x5c,0x00,0x00,0x0a,0x00,0x00,0x00,0x0d, //XX03
278: 0xff,0x00,0x00,0x2d,0xff,0xff,0x0e,0x00,0x3d,0x00,0x7c,0x00,0x3d,0x00,0x1c,0x00,
279: 0x3d,0x00,0x7c,0x00,0x00,0x18,0x46,0x00,0x00,0x30,0x00,0x00,0x31,0x00,0x00,0x32,
280: 0x00,0x00,0x33,0x00,0x00,0x34,0x00,0x00,0x35,0x00,0x00,0x36,0x00,0x00,0x37,0xff,
281: 0x00,0x00,0x38,0x00,0x00,0x39,0xff,0xff,0xff,0x00,0xfe,0x24,0x00,0xfe,0x25,0x00,
282: 0xfe,0x26,0x00,0xfe,0x22,0x00,0xfe,0x27,0x00,0xfe,0x28,0xff,0x00,0xfe,0x2a,0xff,
283: 0x00,0xfe,0x32,0xff,0x00,0xfe,0x33,0xff,0x00,0xfe,0x29,0xff,0x00,0xfe,0x2b,0xff,
284: 0x00,0xfe,0x34,0xff,0x00,0xfe,0x2e,0x00,0xfe,0x30,0x00,0xfe,0x2d,0x00,0xfe,0x23,
285: 0x00,0xfe,0x2f,0x00,0xfe,0x21,0x00,0xfe,0x31,0x00,0xfe,0x20,0x0f,0x02,0xff,0x04,
286: 0x00,0x31,0x02,0xff,0x04,0x00,0x32,0x02,0xff,0x04,0x00,0x33,0x02,0xff,0x04,0x00,
287: 0x34,0x02,0xff,0x04,0x00,0x35,0x02,0xff,0x04,0x00,0x36,0x02,0xff,0x04,0x00,0x37,
288: 0x02,0xff,0x04,0x00,0x38,0x02,0xff,0x04,0x00,0x39,0x02,0xff,0x04,0x00,0x30,0x02,
289: 0xff,0x04,0x00,0x2d,0x02,0xff,0x04,0x00,0x3d,0x02,0xff,0x04,0x00,0x70,0x02,0xff,
290: 0x04,0x00,0x5d,0x02,0xff,0x04,0x00,0x5b,0x04,0x05,0x72,0x06,0x7f,0x07,
291: 0x3e,0x08,0x3d
292: };
293:
294: *length = sizeof(appleUSAKeyMap);
295: return appleUSAKeyMap;
296: }
297:
298:
299:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.