2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1997-1998 Apple Computer, Inc.
28 * sdouglas 22 Oct 97 - first checked in.
29 * sdouglas 23 Jul 98 - start IOKit
30 * suurballe 17 Nov 98 - ported to C++
34 #include <IOKit/IOLib.h>
36 #include "AppleADBDisplay.h"
39 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
41 #define super IODisplay
42 OSDefineMetaClassAndStructors( AppleADBDisplay
, IODisplay
)
44 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
46 IOReturn
AppleADBDisplay::findADBDisplayInfoForType( UInt16 deviceType
)
53 sprintf( stringBuf
, "adb%dWiggle", deviceType
);
54 if( (off
= OSDynamicCast( OSNumber
, getProperty( stringBuf
))))
55 wiggleLADAddr
= off
->unsigned32BitValue();
57 wiggleLADAddr
= kWiggleLADAddr
;
59 sprintf( stringBuf
, "adb%dModes", deviceType
);
60 key
= OSDynamicCast( OSString
, getProperty( stringBuf
));
62 if( key
&& (data
= OSDynamicCast( OSData
, getProperty( key
)))) {
63 modeList
= (UInt32
*) data
->getBytesNoCopy();
64 numModes
= data
->getLength() / sizeof( UInt32
);
67 return(kIOReturnSuccess
);
73 IOReturn
AppleADBDisplay::getConnectFlagsForDisplayMode(
74 IODisplayModeID mode
, UInt32
* flags
)
77 IODisplayConnect
* connect
;
78 IOFramebuffer
* framebuffer
;
80 IOTimingInformation info
;
84 connect
= getConnection();
86 framebuffer
= connect
->getFramebuffer();
87 assert( framebuffer
);
89 err
= framebuffer
->getTimingInfoForDisplayMode( mode
, &info
);
91 if( kIOReturnSuccess
== err
) {
92 for( timingNum
= 0; timingNum
< numModes
; timingNum
++ ) {
93 if( info
.appleTimingID
== modeList
[ timingNum
] ) {
95 ? ( kDisplayModeValidFlag
| kDisplayModeSafeFlag
)
96 : ( kDisplayModeValidFlag
| kDisplayModeSafeFlag
97 | kDisplayModeDefaultFlag
);
106 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
108 IOReturn
AppleADBDisplay::doConnect( void )
115 while ( retries
-- ) {
117 value
= 0x6000 | (adbDevice
->address() << 8);
118 length
= sizeof( value
);
119 err
= adbDevice
->writeRegister( 3, (UInt8
*) &value
, &length
);
125 length
= sizeof( value
);
126 err
= adbDevice
->readRegister( 3, (UInt8
*) &value
, &length
);
130 if( (value
& 0xf000) == 0x6000 )
133 err
= kIOReturnNotAttached
;
137 kprintf("%s: %d\n", __FUNCTION__
, err
);
142 static void autoPollHandler( IOService
* self
, UInt8 adbCommand
,
143 IOByteCount length
, UInt8
* data
)
145 ((AppleADBDisplay
*)self
)->packet( adbCommand
, length
, data
);
148 void AppleADBDisplay::packet( UInt8 adbCommand
,
149 IOByteCount length
, UInt8
* data
)
151 if( length
&& (*data
== waitAckValue
) )
155 IOReturn
AppleADBDisplay::writeWithAcknowledge( UInt8 regNum
,
156 UInt16 data
, UInt8 ackValue
)
159 enum { kTimeoutMS
= 400 };
163 waitAckValue
= ackValue
;
165 length
= sizeof(data
);
166 err
= adbDevice
->writeRegister( regNum
, (UInt8
*) &data
, &length
);
169 timeout
= kTimeoutMS
/ 50;
170 while( waitAckValue
&& timeout
-- )
181 IOReturn
AppleADBDisplay::setLogicalRegister( UInt16 address
, UInt16 data
)
184 UInt32 reconnects
= 3;
186 while( err
&& reconnects
-- ) {
187 err
= writeWithAcknowledge( kADBReg1
, address
, kReg2DataRdy
);
188 if( err
== kIOReturnSuccess
)
189 err
= writeWithAcknowledge( kADBReg2
, data
, kReg2DataAck
);
197 kprintf( "%s: %x, %d\n", __FUNCTION__
, address
, err
);
202 IOReturn
AppleADBDisplay::getLogicalRegister( UInt16 address
, UInt16
* data
)
205 UInt32 reconnects
= 3;
209 while ( err
&& reconnects
--) {
210 err
= writeWithAcknowledge( kADBReg1
, address
, kReg2DataRdy
);
211 if( err
== kIOReturnSuccess
) {
212 length
= sizeof( value
);
213 err
= adbDevice
->readRegister( 2, (UInt8
*)&value
, &length
);
214 *data
= value
& 0xff; // actually only 8 bits
222 kprintf( "%s: %x=%x, %d\n", __FUNCTION__
, address
, *data
, err
);
227 void AppleADBDisplay::setWiggle( bool active
)
229 setLogicalRegister( wiggleLADAddr
, (active
? 1 : 0));
232 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
234 bool AppleADBDisplay::start( IOService
* nub
)
237 UInt16 data
, deviceType
;
239 if( !super::start( nub
))
242 if( OSDynamicCast( IODisplayConnect
, nub
))
245 assert( OSDynamicCast( IOADBDevice
, nub
));
246 adbDevice
= (IOADBDevice
*) nub
;
248 if( !adbDevice
->seizeForClient( this, &autoPollHandler
) ) {
249 IOLog("%s: sieze failed\n", getName());
258 err
= setLogicalRegister( 0xff, 0xff);
262 err
= getLogicalRegister( 0xff, &data
);
266 err
= getLogicalRegister( 0xff, &deviceType
);
270 kprintf("%s: found AVType %d\n",
271 adbDevice
->getName(), deviceType
);
273 err
= findADBDisplayInfoForType( deviceType
);
277 avDisplayID
= deviceType
;
285 adbDevice
->releaseFromClient( this );
290 bool AppleADBDisplay::tryAttach( IODisplayConnect
* connect
)
293 bool attached
= false;
294 UInt32 sense
, extSense
;
295 IOFramebuffer
* framebuffer
;
302 kESCSixStandard
= 0x2B,
307 framebuffer
= connect
->getFramebuffer();
308 fbConnect
= connect
->getConnection();
309 assert( framebuffer
);
311 if( kIOReturnSuccess
!= framebuffer
->getAttributeForConnection(
313 kConnectionSupportsAppleSense
, NULL
))
316 err
= framebuffer
->getAppleSense( fbConnect
,
317 &senseType
, &sense
, &extSense
, 0 );
320 if( (sense
!= kRSCSix
) || (extSense
!= kESCSixStandard
) ) // straight-6
324 err
= framebuffer
->getAppleSense( fbConnect
,
325 &senseType
, &sense
, &extSense
, 0 );
329 if( (sense
!= kRSCFour
) || (extSense
!= kESCFourNTSC
) ) // straight-4
332 kprintf( "%s: attached to %s\n",
333 adbDevice
->getName(), framebuffer
->getName() );
343 IOService
* AppleADBDisplay::probe( IOService
* nub
, SInt32
* score
)
345 IODisplayConnect
* connect
;
347 // both ADB device & display connections come here!
350 if( OSDynamicCast( IOADBDevice
, nub
))
353 if( (connect
= OSDynamicCast( IODisplayConnect
, nub
))
354 && tryAttach( connect
))
362 return( super::probe( nub
, score
));