Import SB128-v5.24 to main branch
[AROS.git] / workbench / devs / AHI / Drivers / SB128 / driver-init.c
blob2dc2cf99707f848007321aa75943e57423e0c9ed
1 /*
3 The contents of this file are subject to the AROS Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
4 http://www.aros.org/license.html
6 Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
7 ANY KIND, either express or implied. See the License for the specific language governing rights and
8 limitations under the License.
10 The Original Code is (C) Copyright 2004-2011 Ross Vumbaca.
12 The Initial Developer of the Original Code is Ross Vumbaca.
14 All Rights Reserved.
18 #include <config.h>
20 #include <exec/memory.h>
22 #undef __USE_INLINE__
23 #include <proto/expansion.h>
25 #include <proto/exec.h>
26 #include <proto/dos.h>
28 #include <devices/timer.h>
30 #include "library_card.h"
31 #include "version.h"
32 #include "misc.h"
33 #include "regs.h"
34 #include "DriverData.h"
37 struct Library* SysBase;
38 struct Library* DOSBase;
39 struct DriverBase* AHIsubBase;
41 struct Library* ExpansionBase = NULL;
42 struct ExpansionIFace* IExpansion = NULL;
43 struct UtilityIFace* IUtility = NULL;
44 struct AHIsubIFace* IAHIsub = NULL;
45 struct MMUIFace* IMMU = NULL;
46 struct PCIIFace* IPCI = NULL;
48 #define CARD_STRING "SB128"
51 /******************************************************************************
52 ** Custom driver init *********************************************************
53 ******************************************************************************/
55 BOOL
56 DriverInit( struct DriverBase* ahisubbase )
58 struct CardBase* CardBase = (struct CardBase*) ahisubbase;
59 struct PCIDevice *dev;
60 int card_no;
62 UWORD cards[] =
64 0x1274, 0x5000,
65 0x1274, 0x1371,
66 0x1274, 0x5880,
67 0x1102, 0x8938,
68 PCI_ANY_ID, PCI_ANY_ID
71 CardBase->cards_found = 0;
72 CardBase->driverdatas = 0;
73 AHIsubBase = ahisubbase;
75 DOSBase = IExec->OpenLibrary( DOSNAME, 37 );
77 if( DOSBase == NULL )
79 Req( "Unable to open 'dos.library' version 37.\n" );
80 return FALSE;
83 if ((IDOS = (struct DOSIFace *) IExec->GetInterface((struct Library *) DOSBase, "main", 1, NULL)) == NULL)
85 Req("Couldn't open IDOS interface!\n");
86 return FALSE;
89 ExpansionBase = IExec->OpenLibrary( "expansion.library", 50 );
90 if( ExpansionBase == NULL )
92 Req( "Unable to open 'expansion.library' version 50.\n" );
93 return FALSE;
95 if ((IExpansion = (struct ExpansionIFace *) IExec->GetInterface((struct Library *) ExpansionBase, "main", 1, NULL)) == NULL)
97 Req("Couldn't open IExpansion interface!\n");
98 return FALSE;
101 if ((IPCI = (struct PCIIFace *) IExec->GetInterface((struct Library *) ExpansionBase, "pci", 1, NULL)) == NULL)
103 Req("Couldn't open IPCI interface!\n");
104 return FALSE;
107 if ((IAHIsub = (struct AHIsubIFace *) IExec->GetInterface((struct Library *) AHIsubBase, "main", 1, NULL)) == NULL)
109 Req("Couldn't open IAHIsub interface!\n");
110 return FALSE;
113 if ((IUtility = (struct UtilityIFace *) IExec->GetInterface((struct Library *) UtilityBase, "main", 1, NULL)) == NULL)
115 Req("Couldn't open IUtility interface!\n");
116 return FALSE;
119 if ((IMMU = (struct MMUIFace *) IExec->GetInterface((struct Library *) SysBase, "mmu", 1, NULL)) == NULL)
121 Req("Couldn't open IMMU interface!\n");
122 return FALSE;
125 /* Timer Device */
127 /* replymp = (struct MsgPort *) IExec->CreatePort(NULL, 0);
128 if (!replymp)
130 IExec->DebugPrintF("SB128: Couldn't create ReplyPort!\n");
131 return FALSE;
134 /*TimerIO = (struct timerequest *)IExec->CreateIORequest(replymp, sizeof(struct timerequest));
136 if (TimerIO == NULL)
138 IExec->DebugPrintF("Out of memory.\n");
139 return FALSE;
142 if (IExec->OpenDevice("timer.device", UNIT_MICROHZ, (struct IORequest *)TimerIO, 0) != 0)
144 IExec->DebugPrintF("Unable to open 'timer.device'.\n");
145 return FALSE;
147 else
148 TimerBase = (struct Device *)TimerIO->tr_node.io_Device;*/
150 IExec->InitSemaphore( &CardBase->semaphore );
153 /*** Count cards ***********************************************************/
155 dev = NULL;
157 if ( (dev = IPCI->FindDeviceTags( FDT_CandidateList, cards,
158 TAG_DONE ) ) != NULL )
160 ++CardBase->cards_found;
161 IExec->DebugPrintF("%s found! :-)\n", CARD_STRING);
164 /* Fail if no hardware is present (prevents the audio modes from being added to
165 the database if the driver cannot be used). */
167 if( CardBase->cards_found == 0 )
169 IExec->DebugPrintF("No %s found! :-(\n", CARD_STRING);
170 Req( "No card present.\n" );
171 return FALSE;
174 /*** CAMD ******************************************************************/
175 #if 0
176 IExec->InitSemaphore( &CardBase->camd.Semaphore );
177 CardBase->camd.Semaphore.ss_Link.ln_Pri = 0;
179 CardBase->camd.Semaphore.ss_Link.ln_Name = Card_CAMD_SEMAPHORE;
180 IExec->AddSemaphore( &CardBase->camd.Semaphore );
182 CardBase->camd.Cards = CardBase->cards_found;
183 CardBase->camd.Version = VERSION;
184 CardBase->camd.Revision = REVISION;
187 CardBase->camd.OpenPortFunc.h_Entry = OpenCAMDPort;
188 CardBase->camd.OpenPortFunc.h_SubEntry = NULL;
189 CardBase->camd.OpenPortFunc.h_Data = NULL;
191 CardBase->camd.ClosePortFunc.h_Entry = (HOOKFUNC) CloseCAMDPort;
192 CardBase->camd.ClosePortFunc.h_SubEntry = NULL;
193 CardBase->camd.ClosePortFunc.h_Data = NULL;
195 CardBase->camd.ActivateXmitFunc.h_Entry = (HOOKFUNC) ActivateCAMDXmit;
196 CardBase->camd.ActivateXmitFunc.h_SubEntry = NULL;
197 CardBase->camd.ActivateXmitFunc.h_Data = NULL;
198 #endif
201 /*** Allocate and init all cards *******************************************/
203 CardBase->driverdatas = IExec->AllocVec( sizeof( *CardBase->driverdatas ) *
204 CardBase->cards_found,
205 MEMF_PUBLIC );
207 if( CardBase->driverdatas == NULL )
209 Req( "Out of memory." );
210 return FALSE;
213 card_no = 0;
215 if( ( dev = IPCI->FindDeviceTags( FDT_CandidateList, cards,
216 TAG_DONE ) ) != NULL )
218 CardBase->driverdatas[ card_no ] = AllocDriverData( dev, AHIsubBase );
219 ++card_no;
222 return TRUE;
226 /******************************************************************************
227 ** Custom driver clean-up *****************************************************
228 ******************************************************************************/
230 VOID
231 DriverCleanup( struct DriverBase* AHIsubBase )
233 struct CardBase* CardBase = (struct CardBase*) AHIsubBase;
234 int i;
235 #if 0
236 if( CardBase->camd.Semaphore.ss_Link.ln_Name != NULL )
238 IExec->ObtainSemaphore( &CardBase->camd.Semaphore );
239 IExec->RemSemaphore( &CardBase->camd.Semaphore );
240 IExec->ReleaseSemaphore( &CardBase->camd.Semaphore );
242 #endif
244 for( i = 0; i < CardBase->cards_found; ++i )
246 if (CardBase->driverdatas)
248 CardBase->driverdatas[ i ]->pci_dev->OutLong(CardBase->driverdatas[ i ]->iobase + SB128_SCON, 0);
249 FreeDriverData( CardBase->driverdatas[ i ], AHIsubBase );
253 if (CardBase->driverdatas)
254 IExec->FreeVec( CardBase->driverdatas );
256 /*if (TimerIO)
258 IExec->CloseDevice((struct IORequest *)TimerIO);
259 IExec->DeleteIORequest((struct IORequest *)TimerIO);
262 /*if (replymp)
263 IExec->DeletePort(replymp);*/
265 if (IMMU)
266 IExec->DropInterface( (struct Interface *) IMMU);
268 if (IUtility)
269 IExec->DropInterface( (struct Interface *) IUtility);
271 if (IExpansion)
272 IExec->DropInterface( (struct Interface *) IExpansion);
274 if (IPCI)
275 IExec->DropInterface( (struct Interface *) IPCI);
277 if (IAHIsub)
278 IExec->DropInterface( (struct Interface *) IAHIsub);
280 if (IDOS)
281 IExec->DropInterface( (struct Interface *) IDOS);
283 if (ExpansionBase)
284 IExec->CloseLibrary( (struct Library*) ExpansionBase );
286 if (UtilityBase)
287 IExec->CloseLibrary( (struct Library*) UtilityBase );
289 if (DOSBase)
290 IExec->CloseLibrary( (struct Library*) DOSBase );