|
|
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:
26:
27: /*********
28:
29: usbcmd.m
30: This is a preliminary driver for the CMD PCI USB card on my
31: PowerSurge 8500.
32:
33: Common USB terms: TD is Transfer Descriptor, ED is Endpoint Descriptor.
34: * Naga Pappireddi 12-17-98 Radar bug# 2293217 Cleanup of code in GetErrataBits function to read the registry properties
35: * this cleanup took care of LED problem on Yosemite
36:
37: *********/
38:
39:
40: #import <kern/clock.h>
41: #import <machdep/ppc/interrupts.h>
42: #import <kernserv/prototypes.h>
43: #import <kernserv/clock_timer.h>
44: #import <kernserv/ns_timer.h>
45: #import <sys/time.h>
46: #import <sys/callout.h>
47: #import <machdep/ppc/proc_reg.h>
48: #import <driverkit/generalFuncs.h>
49: #import <driverkit/kernelDriver.h>
50: #import <driverkit/interruptMsg.h>
51: #import <driverkit/ppc/IODBDMA.h> //for ReadSwap32() only
52: #import <driverkit/align.h> //for IOAlign() only
53: #import "usbcmd.h"
54:
55: extern id ApplePMUId; //in adb.m (remove this when adb becomes an indirect driver)(q8q)
56: extern id usb_UIM_object; //in bsd/dev/ppc/EventSrcPCKeyboard.m
57: extern unsigned int usb_kbd_vendor_id, usb_kbd_product_id; //in uslExpert.c
58:
59: int OHCIUIMInitialize(unsigned long ioBase);
60: void pollRootHubSim(void);
61: IOThreadFunc usb_thread(void *);
62: void IOSync(void)
63: {
64: eieio();
65: }
66: extern OHCIUIMDataPtr pOHCIUIMData;
67: extern void kprintf(const char *, ...);
68: extern void bcopy(void *, void *, int);
69: extern void usb_intr(int intr, void *ssp, void *dev);
70: #define printf usb_donone
71: #define kprintf usb_donone
72: void usb_donone(char *x,...);
73:
74:
75: //OSStatus OHCIUIMInterruptHandler (InterruptSetMember member, void *refCon, UInt32 interruptCount);
76: extern int kdp_flag;
77: int usb_port_configured[2] = {0,0};
78:
79: IOPropertyTable *usb_propTable;
80: IOPCIDevice *devUsb;
81: AppleUSBCMD *selfUsb;
82: int cmd_pci_errata; //global needed to fix errata for Caps Lock LED support
83:
84: unsigned int
85: usb_swap_word(unsigned int input)
86: {
87: int lo, hi;
88:
89: lo = 0x00ff & input;
90: lo = lo << 8;
91: hi = input >> 8;
92: return (hi | lo);
93: }
94:
95: void enable_intr()
96: {
97: [selfUsb enableAllInterrupts];
98: }
99:
100: void ReadConfigVal(UInt32 ctl, UInt32 *val)
101: {
102: [devUsb configReadLong:ctl value:val];
103: }
104:
105: void WriteConfigVal(UInt32 ctl, UInt32 val)
106: {
107: [devUsb configWriteLong:ctl value:val];
108: }
109:
110: @implementation AppleUSBCMD
111:
112: // **********************************************************************************
113: // probe
114: //
115: //
116: //
117: // **********************************************************************************
118: + (Boolean) probe : deviceDescription
119: {
120: id dev;
121: //kdp_flag=2;
122: kprintf("usb probe\n");
123: usb_propTable = [deviceDescription propertyTable]; /* For use with RegistryPropertyGet */
124:
125: if ( (dev = [ self alloc ]) == nil ) {
126: return NO;
127: }
128:
129: if ([dev initFromDeviceDescription:deviceDescription] == nil) {
130: return NO;
131: }
132:
133: usb_UIM_object = dev;
134:
135: kprintf("naga:Successful probe of USB\n");
136: return YES;
137: }
138:
139:
140: // **********************************************************************************
141: // initFromDeviceDescription
142: //
143: //
144: //- initFromDeviceDescription:(IODeviceDescription *)deviceDescription
145: //- initFromDeviceDescription:(IOPCIDevice *)deviceDescription
146: //
147: // **********************************************************************************
148: - initFromDeviceDescription:(IODeviceDescription *) devDesc
149: {
150: IORange * ioRange;
151: int numRanges;
152: int irq;
153: unsigned long PCICommandReg;
154: IOPCIDevice *deviceDescription = (IOPCIDevice *)devDesc;
155: char *tbuf;
156:
157:
158: devUsb = (IOPCIDevice *)devDesc;
159: selfUsb=self;
160: if ( [super initFromDeviceDescription:deviceDescription] == nil )
161: {
162: [self free];
163: return nil;
164: }
165:
166: [self setDeviceKind:"USB-CMD Subsystem"];
167: [self setLocation:NULL];
168: [self setName:"USBCMD"];
169:
170: tbuf = [devDesc nodeName];
171: //CMD card is "pci1095,670"
172: cmd_pci_errata = 0;
173: if (!strcmp(tbuf, "pci1095,670")) //if match Open Firmware string
174: {
175: cmd_pci_errata = 1;
176: }
177:
178:
179: ioRange = [deviceDescription memoryRangeList];
180: //ioRange->start is 0x80800000 for my PCI USB card
181: kprintf("USB Start of mem is %x\n", ioRange->start);
182:
183: numRanges = [deviceDescription numMemoryRanges];
184: kprintf("USB numRanges is %d\n", numRanges);
185: // This causes crash [self isPCIPresent];
186:
187: if (numRanges < 1 )
188: {
189: IOLog( "USB-CMD: Incorrect deviceDescription - 1\n\r");
190: return nil;
191: }
192: ioBase = 0;
193: [self mapMemoryRange: 0 to:(vm_address_t *)&ioBase findSpace:YES cache:IO_CacheOff];
194: kprintf("USB ioBase is %x\n", ioBase); //Should be 3519000 on PowerSurge (Heathrow)
195:
196: /*
197: * BUS MASTER, MEM I/O Space, MEM WR & INV
198: */
199:
200: [deviceDescription configWriteLong:0x04 value:0x16];
201: #ifdef OMIT
202: [deviceDescription configReadLong:0x04 value:&PCICommandReg];
203: PCICommandReg |= (4 | 1); // Master & Memory
204: PCICommandReg &= ~2; // Not I/O
205: [deviceDescription configWriteLong:0x04 value:PCICommandReg];
206: #endif
207:
208: OHCIUIMInitialize( ioBase);
209: USBServicesInitialise(nil);
210:
211: if ([self startIOThread] != IO_R_SUCCESS)
212: {
213: [self free];
214: kprintf("USB thread error \n");
215: return nil;
216: }
217: port = IOConvertPort([self interruptPort],IO_KernelIOTask,IO_Kernel);
218: kprintf("USB port is %x\n", port);
219: [self registerDevice];
220: irq = [devDesc interrupt];
221: {
222: IOThread tid;
223: tid = IOForkThread(usb_thread, (void *)0);
224: }
225: return self;
226: }
227:
228: // **********************************************************************************
229: // free
230: //
231: //
232: //
233: // **********************************************************************************
234: - free
235: {
236: return [ super free ];
237: }
238:
239:
240:
241: - (void)interruptOccurred
242: {
243: void dump_regs(UInt32 *);
244: extern int usb_iodone;
245: void wait_usbio();
246: void print_usbDesc();
247: OHCIUIMInterruptHandler (0, NULL , 0);
248: [self enableAllInterrupts];
249: }
250:
251:
252: //New method added 12/22/98 by A.W. to support international USB keyboards
253: //NOTE: ADB keyboard keymaps are in /System/Library/Keyboards/*.keyboard
254: // Apple Extended Keyboard, North American version has ID of 16+2 = 18
255: - (unsigned int) getADBKeyboardID
256: {
257: //kprintf("USB: in usbcmd.m, vendor is %x, product is %x\n", usb_kbd_vendor_id, usb_kbd_product_id);
258:
259: if (usb_kbd_vendor_id == 0x05ac) //Apple Corp. vendor ID
260: {
261: switch (usb_kbd_product_id)
262: {
263: case 0x0201: //North American iMac keyboard
264: return 18;
265: case 0x0203: //38=Japanese. 34 is adjustable JIS
266: return 34;
267: case 0x0202: //Arabic
268: return 21; //21 is Apple ISO Extended Keyboard
269: default:
270: return 18;
271: }
272: }
273:
274: if (usb_kbd_vendor_id == 0x045e) //Microsoft ID
275: {
276: if (usb_kbd_product_id == 0x000b) //Natural USB+PS/2 keyboard
277: return 18;
278: }
279: //By default return Apple Extended ADB Keyboard ID
280: return 18;
281: }
282:
283:
284: @end
285:
286: IOThreadFunc usb_thread(void *ignore)
287: {
288: extern void Get_Config_Info(void);
289: extern void usbAddBus(void);
290: extern char ports_connected[2];
291: extern USBIdleTask(void);
292:
293: kprintf("Usb Thread Started\n");
294: usbAddBus();
295: kprintf("*************** usbAddBus complete\n");
296: for(;;)
297: {
298: USBIdleTask();
299:
300: IOSleep(1); // Milliseconds
301: }
302: }
303: /* Moved this function from ohciuim.c to here
304: * Naga Pappireddi 12-17-98 Radar bug# 2293217 Cleanup of code in GetErrataBits function to read the registry properties
305: * this cleanup took care of LED problem on Yosemite
306: */
307:
308: OSStatus RegistryPropertyGet(const RegEntryID *entryID, const RegPropertyName *propertyName, void *propertyValue, RegPropertyValueSize *propertySize)
309: {
310: void *prop_value;
311:
312: prop_value = (void *)propertyValue;
313: [usb_propTable getProperty:propertyName flags:0 value:(void **) &prop_value length:propertySize];
314:
315: return 0;
316: }
317:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.