]> git.saurik.com Git - apple/xnu.git/blob - iokit/Drivers/platform/drvAppleCuda/IOCudaADBController.cpp
677bdfc801d8f6a8c2c19f2760055a209336b8a5
[apple/xnu.git] / iokit / Drivers / platform / drvAppleCuda / IOCudaADBController.cpp
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 * 1 Dec 1998 suurballe Created.
24 */
25
26 #include "IOCudaADBController.h"
27 #include "AppleCuda.h"
28
29 #define super IOADBController
30 OSDefineMetaClassAndStructors(IOCudaADBController, IOADBController)
31
32 // **********************************************************************************
33 // init
34 //
35 // **********************************************************************************
36 bool IOCudaADBController::init ( OSDictionary * properties, AppleCuda * driver )
37 {
38
39 CudaDriver = driver;
40 pollList = 0;
41 autopollOn = false;
42
43 return super::init(properties);
44 }
45
46
47 // **********************************************************************************
48 // start
49 //
50 // **********************************************************************************
51 bool IOCudaADBController::start ( IOService *nub )
52 {
53 if( !super::start(nub))
54 return false;
55
56 CudaDriver->registerForADBInterrupts ( autopollHandler, this );
57 return true;
58 }
59
60
61 // **********************************************************************************
62 // setAutoPollPeriod
63 //
64 // **********************************************************************************
65 IOReturn IOCudaADBController::setAutoPollPeriod ( int microsecs )
66 {
67 cuda_request_t cmd;
68
69 adb_init_request(&cmd);
70 ADB_BUILD_CMD3(&cmd, ADB_PACKET_PSEUDO, ADB_PSEUDOCMD_SET_AUTO_RATE,
71 ((microsecs + 999) / 1000));
72
73 return CudaDriver->doSyncRequest(&cmd);
74 }
75
76
77 // **********************************************************************************
78 // getAutoPollPeriod
79 //
80 // **********************************************************************************
81 IOReturn IOCudaADBController::getAutoPollPeriod ( int * microsecs )
82 {
83 IOReturn err;
84 cuda_request_t cmd;
85 UInt8 data;
86
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);
91
92 err = CudaDriver->doSyncRequest(&cmd);
93
94 if ( err == kIOReturnSuccess ) {
95 *microsecs = data * 1000;
96 }
97 return err;
98 }
99
100
101 // **********************************************************************************
102 // getAutoPollPeriod
103 //
104 // **********************************************************************************
105 IOReturn IOCudaADBController::setAutoPollList ( UInt16 activeAddressMask )
106 {
107 cuda_request_t cmd;
108
109 adb_init_request(&cmd);
110 ADB_BUILD_CMD2(&cmd, ADB_PACKET_PSEUDO, ADB_PSEUDOCMD_SET_DEVICE_LIST)
111
112 cmd.a_cmd.a_buffer = (UInt8 *) &activeAddressMask;
113 cmd.a_cmd.a_bcount = sizeof(UInt16);
114
115 return CudaDriver->doSyncRequest(&cmd);
116 }
117
118
119 // **********************************************************************************
120 // getAutoPollList
121 //
122 // **********************************************************************************
123 IOReturn IOCudaADBController::getAutoPollList ( UInt16 * activeAddressMask )
124 {
125 cuda_request_t cmd;
126
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);
131
132 return CudaDriver->doSyncRequest(&cmd);
133 }
134
135
136 // **********************************************************************************
137 // setAutoPollEnable
138 //
139 // **********************************************************************************
140 IOReturn IOCudaADBController::setAutoPollEnable ( bool enable )
141 {
142 cuda_request_t cmd;
143
144 adb_init_request(&cmd);
145 ADB_BUILD_CMD3(&cmd, ADB_PACKET_PSEUDO, ADB_PSEUDOCMD_START_STOP_AUTO_POLL, (enable ? 1 : 0));
146
147 return CudaDriver->doSyncRequest(&cmd);
148 }
149
150
151 // **********************************************************************************
152 // resetBus
153 //
154 // **********************************************************************************
155 IOReturn IOCudaADBController::resetBus ( void )
156 {
157 cuda_request_t cmd;
158
159 adb_init_request(&cmd);
160 ADB_BUILD_CMD2(&cmd, ADB_PACKET_ADB, ADB_ADBCMD_RESET_BUS );
161
162 return CudaDriver->doSyncRequest(&cmd);
163 }
164
165
166 // **********************************************************************************
167 // flushDevice
168 //
169 // **********************************************************************************
170 IOReturn IOCudaADBController::flushDevice ( IOADBAddress address )
171 {
172 cuda_request_t cmd;
173
174 adb_init_request(&cmd);
175 ADB_BUILD_CMD2(&cmd, ADB_PACKET_ADB, (ADB_ADBCMD_FLUSH_ADB | (address << 4)));
176
177 return CudaDriver->doSyncRequest(&cmd);
178 }
179
180
181
182 // **********************************************************************************
183 // readFromDevice
184 //
185 // **********************************************************************************
186 IOReturn IOCudaADBController::readFromDevice (IOADBAddress address, IOADBRegister adbRegister,
187 UInt8 * data, IOByteCount * length )
188 {
189 IOReturn err;
190 cuda_request_t cmd;
191
192 adb_init_request(&cmd);
193 ADB_BUILD_CMD2(&cmd, ADB_PACKET_ADB,
194 (ADB_ADBCMD_READ_ADB | (address << 4) | (adbRegister & 3)));
195
196 cmd.a_reply.a_buffer = data;
197 cmd.a_reply.a_bcount = *length;
198
199 err = CudaDriver->doSyncRequest(&cmd);
200
201 //IOLog("Read %d, Addr %x Reg %x = %04x\n", err, address, adbRegister, *((UInt16 *)data));
202
203 if( err == ADB_RET_OK ) {
204 *length = cmd.a_reply.a_bcount;
205 }
206 else {
207 *length = 0;
208 }
209
210 return err;
211 }
212
213
214 // **********************************************************************************
215 // writeToDevice
216 //
217 // **********************************************************************************
218 IOReturn IOCudaADBController::writeToDevice ( IOADBAddress address, IOADBRegister adbRegister,
219 UInt8 * data, IOByteCount * length )
220 {
221 IOReturn err;
222 cuda_request_t cmd;
223
224 adb_init_request(&cmd);
225
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;
230
231 err = CudaDriver->doSyncRequest(&cmd);
232
233 //IOLog("Write %d, Addr %x Reg %x = %04x\n", err, address, adbRegister, *((UInt16 *)data));
234
235 if( err == ADB_RET_OK ) {
236 *length = cmd.a_reply.a_bcount;
237 }
238 else {
239 *length = 0;
240 }
241 return err;
242 }
243