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 * 1 Dec 1998 suurballe Created.
26 #include "IOCudaADBController.h"
27 #include "AppleCuda.h"
29 #define super IOADBController
30 OSDefineMetaClassAndStructors(IOCudaADBController
, IOADBController
)
32 // **********************************************************************************
35 // **********************************************************************************
36 bool IOCudaADBController::init ( OSDictionary
* properties
, AppleCuda
* driver
)
43 return super::init(properties
);
47 // **********************************************************************************
50 // **********************************************************************************
51 bool IOCudaADBController::start ( IOService
*nub
)
53 if( !super::start(nub
))
56 CudaDriver
->registerForADBInterrupts ( autopollHandler
, this );
61 // **********************************************************************************
64 // **********************************************************************************
65 IOReturn
IOCudaADBController::setAutoPollPeriod ( int microsecs
)
69 adb_init_request(&cmd
);
70 ADB_BUILD_CMD3(&cmd
, ADB_PACKET_PSEUDO
, ADB_PSEUDOCMD_SET_AUTO_RATE
,
71 ((microsecs
+ 999) / 1000));
73 return CudaDriver
->doSyncRequest(&cmd
);
77 // **********************************************************************************
80 // **********************************************************************************
81 IOReturn
IOCudaADBController::getAutoPollPeriod ( int * microsecs
)
87 adb_init_request(&cmd
);
88 ADB_BUILD_CMD2(&cmd
, ADB_PACKET_PSEUDO
, ADB_PSEUDOCMD_GET_AUTO_RATE
);
89 cmd
.a_reply
.a_buffer
= &data
;
90 cmd
.a_reply
.a_bcount
= sizeof(UInt8
);
92 err
= CudaDriver
->doSyncRequest(&cmd
);
94 if ( err
== kIOReturnSuccess
) {
95 *microsecs
= data
* 1000;
101 // **********************************************************************************
104 // **********************************************************************************
105 IOReturn
IOCudaADBController::setAutoPollList ( UInt16 activeAddressMask
)
109 adb_init_request(&cmd
);
110 ADB_BUILD_CMD2(&cmd
, ADB_PACKET_PSEUDO
, ADB_PSEUDOCMD_SET_DEVICE_LIST
)
112 cmd
.a_cmd
.a_buffer
= (UInt8
*) &activeAddressMask
;
113 cmd
.a_cmd
.a_bcount
= sizeof(UInt16
);
115 return CudaDriver
->doSyncRequest(&cmd
);
119 // **********************************************************************************
122 // **********************************************************************************
123 IOReturn
IOCudaADBController::getAutoPollList ( UInt16
* activeAddressMask
)
127 adb_init_request(&cmd
);
128 ADB_BUILD_CMD2(&cmd
, ADB_PACKET_PSEUDO
, ADB_PSEUDOCMD_GET_DEVICE_LIST
);
129 cmd
.a_reply
.a_buffer
= (UInt8
*) activeAddressMask
;
130 cmd
.a_reply
.a_bcount
= sizeof(UInt16
);
132 return CudaDriver
->doSyncRequest(&cmd
);
136 // **********************************************************************************
139 // **********************************************************************************
140 IOReturn
IOCudaADBController::setAutoPollEnable ( bool enable
)
144 adb_init_request(&cmd
);
145 ADB_BUILD_CMD3(&cmd
, ADB_PACKET_PSEUDO
, ADB_PSEUDOCMD_START_STOP_AUTO_POLL
, (enable
? 1 : 0));
147 return CudaDriver
->doSyncRequest(&cmd
);
151 // **********************************************************************************
154 // **********************************************************************************
155 IOReturn
IOCudaADBController::resetBus ( void )
159 adb_init_request(&cmd
);
160 ADB_BUILD_CMD2(&cmd
, ADB_PACKET_ADB
, ADB_ADBCMD_RESET_BUS
);
162 return CudaDriver
->doSyncRequest(&cmd
);
166 // **********************************************************************************
169 // **********************************************************************************
170 IOReturn
IOCudaADBController::flushDevice ( IOADBAddress address
)
174 adb_init_request(&cmd
);
175 ADB_BUILD_CMD2(&cmd
, ADB_PACKET_ADB
, (ADB_ADBCMD_FLUSH_ADB
| (address
<< 4)));
177 return CudaDriver
->doSyncRequest(&cmd
);
182 // **********************************************************************************
185 // **********************************************************************************
186 IOReturn
IOCudaADBController::readFromDevice (IOADBAddress address
, IOADBRegister adbRegister
,
187 UInt8
* data
, IOByteCount
* length
)
192 adb_init_request(&cmd
);
193 ADB_BUILD_CMD2(&cmd
, ADB_PACKET_ADB
,
194 (ADB_ADBCMD_READ_ADB
| (address
<< 4) | (adbRegister
& 3)));
196 cmd
.a_reply
.a_buffer
= data
;
197 cmd
.a_reply
.a_bcount
= *length
;
199 err
= CudaDriver
->doSyncRequest(&cmd
);
201 //IOLog("Read %d, Addr %x Reg %x = %04x\n", err, address, adbRegister, *((UInt16 *)data));
203 if( err
== ADB_RET_OK
) {
204 *length
= cmd
.a_reply
.a_bcount
;
214 // **********************************************************************************
217 // **********************************************************************************
218 IOReturn
IOCudaADBController::writeToDevice ( IOADBAddress address
, IOADBRegister adbRegister
,
219 UInt8
* data
, IOByteCount
* length
)
224 adb_init_request(&cmd
);
226 ADB_BUILD_CMD2(&cmd
, ADB_PACKET_ADB
,
227 (ADB_ADBCMD_WRITE_ADB
| (address
<< 4) | (adbRegister
& 3)));
228 cmd
.a_cmd
.a_buffer
= data
;
229 cmd
.a_cmd
.a_bcount
= *length
;
231 err
= CudaDriver
->doSyncRequest(&cmd
);
233 //IOLog("Write %d, Addr %x Reg %x = %04x\n", err, address, adbRegister, *((UInt16 *)data));
235 if( err
== ADB_RET_OK
) {
236 *length
= cmd
.a_reply
.a_bcount
;