Port the SB128 code to AROS.
[AROS.git] / workbench / devs / AHI / Drivers / SB128 / driver-init.c
blob52322de1d10f0e1acedc818df3077653b85e79cb
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 <exec/memory.h>
20 #include <proto/exec.h>
21 #include <proto/dos.h>
23 #include <devices/timer.h>
25 #define DEBUG 1
26 #include <aros/debug.h>
27 #define DebugPrintF bug
29 #include "library.h"
30 #include "version.h"
31 #include "misc.h"
32 #include "regs.h"
34 #include "pci_wrapper.h"
36 struct DosLibrary* DOSBase;
37 struct DriverBase* AHIsubBase;
38 struct Library* ExpansionBase = NULL;
40 struct VendorDevice
42 UWORD vendor;
43 UWORD device;
46 #define CARD_STRING "SB128"
47 #define MAX_DEVICE_VENDORS 512
49 struct VendorDevice *vendor_device_list = NULL;
50 static int vendor_device_list_size = 0;
52 /******************************************************************************
53 ** Custom driver init *********************************************************
54 ******************************************************************************/
56 BOOL
57 DriverInit( struct DriverBase* ahisubbase )
59 struct SB128Base* SB128Base = (struct SB128Base*) ahisubbase;
60 struct PCIDevice *dev;
61 int card_no, i;
62 struct List foundCards;
63 struct Node *devTmp;
65 bug("[SB128]: %s()\n", __PRETTY_FUNCTION__);
67 SB128Base->cards_found = 0;
68 SB128Base->driverdatas = 0;
69 AHIsubBase = ahisubbase;
71 DOSBase = OpenLibrary( DOSNAME, 37 );
73 if( DOSBase == NULL )
75 Req( "Unable to open 'dos.library' version 37.\n" );
76 return FALSE;
79 ExpansionBase = OpenLibrary( "expansion.library", 50 );
80 if( ExpansionBase == NULL )
82 Req( "Unable to open 'expansion.library' version 50.\n" );
83 return FALSE;
86 if (!ahi_pci_init(ahisubbase))
88 return FALSE;
91 /* Timer Device */
93 /* replymp = (struct MsgPort *) CreatePort(NULL, 0);
94 if (!replymp)
96 DebugPrintF("SB128: Couldn't create ReplyPort!\n");
97 return FALSE;
98 }*/
100 /*TimerIO = (struct timerequest *)CreateIORequest(replymp, sizeof(struct timerequest));
102 if (TimerIO == NULL)
104 DebugPrintF("Out of memory.\n");
105 return FALSE;
108 if (OpenDevice("timer.device", UNIT_MICROHZ, (struct IORequest *)TimerIO, 0) != 0)
110 DebugPrintF("Unable to open 'timer.device'.\n");
111 return FALSE;
113 else
114 TimerBase = (struct Device *)TimerIO->tr_node.io_Device;*/
116 InitSemaphore( &SB128Base->semaphore );
118 /*** Count cards ***********************************************************/
120 vendor_device_list = (struct VendorDevice *) AllocVec(sizeof(struct VendorDevice) * MAX_DEVICE_VENDORS, MEMF_PUBLIC | MEMF_CLEAR);
122 vendor_device_list[0].vendor = 0x1274;
123 vendor_device_list[0].device = 0x5000;
124 vendor_device_list_size++;
126 vendor_device_list[0].vendor = 0x1274;
127 vendor_device_list[0].device = 0x1371;
128 vendor_device_list_size++;
130 vendor_device_list[0].vendor = 0x1274;
131 vendor_device_list[0].device = 0x5880;
132 vendor_device_list_size++;
134 vendor_device_list[0].vendor = 0x1102;
135 vendor_device_list[0].device = 0x8938;
136 vendor_device_list_size++;
138 bug("vendor_device_list_size = %ld\n", vendor_device_list_size);
140 SB128Base->cards_found = 0;
141 dev = NULL;
143 for (i = 0; i < vendor_device_list_size; i++)
145 dev = ahi_pci_find_device(vendor_device_list[i].vendor, vendor_device_list[i].device, dev);
147 if (dev != NULL)
149 bug("[SB128] %s: Found SB128 #%d [%4x:%4x] pci obj @ 0x%p\n", __PRETTY_FUNCTION__, i, vendor_device_list[i].vendor, vendor_device_list[i].device, dev);
150 ++SB128Base->cards_found;
152 devTmp = AllocVec(sizeof(struct Node), MEMF_CLEAR);
153 devTmp->ln_Name = dev;
154 AddTail(&foundCards, devTmp);
158 // Fail if no hardware is present (prevents the audio modes from being added to
159 // the database if the driver cannot be used).
161 if(SB128Base->cards_found == 0 )
163 DebugPrintF("No SB128 found! :-(\n");
164 Req( "No card present.\n" );
165 return FALSE;
168 /*** CAMD ******************************************************************/
169 #if 0
170 InitSemaphore( &SB128Base->camd.Semaphore );
171 SB128Base->camd.Semaphore.ss_Link.ln_Pri = 0;
173 SB128Base->camd.Semaphore.ss_Link.ln_Name = Card_CAMD_SEMAPHORE;
174 AddSemaphore( &SB128Base->camd.Semaphore );
176 SB128Base->camd.Cards = SB128Base->cards_found;
177 SB128Base->camd.Version = VERSION;
178 SB128Base->camd.Revision = REVISION;
181 SB128Base->camd.OpenPortFunc.h_Entry = OpenCAMDPort;
182 SB128Base->camd.OpenPortFunc.h_SubEntry = NULL;
183 SB128Base->camd.OpenPortFunc.h_Data = NULL;
185 SB128Base->camd.ClosePortFunc.h_Entry = (HOOKFUNC) CloseCAMDPort;
186 SB128Base->camd.ClosePortFunc.h_SubEntry = NULL;
187 SB128Base->camd.ClosePortFunc.h_Data = NULL;
189 SB128Base->camd.ActivateXmitFunc.h_Entry = (HOOKFUNC) ActivateCAMDXmit;
190 SB128Base->camd.ActivateXmitFunc.h_SubEntry = NULL;
191 SB128Base->camd.ActivateXmitFunc.h_Data = NULL;
192 #endif
195 /*** Allocate and init all cards *******************************************/
197 SB128Base->driverdatas = AllocVec( sizeof( *SB128Base->driverdatas ) *
198 SB128Base->cards_found,
199 MEMF_PUBLIC );
201 if( SB128Base->driverdatas == NULL )
203 Req( "Out of memory." );
204 return FALSE;
207 card_no = 0;
209 struct Node *scratchNode;
210 ForeachNodeSafe(&foundCards, devTmp, scratchNode)
212 Remove(devTmp);
214 dev = devTmp->ln_Name;
215 bug("[SB128] %s: Prepairing card #%d pci obj @ 0x%p\n", __PRETTY_FUNCTION__, card_no, dev);
216 SB128Base->driverdatas[ card_no ] = AllocDriverData( dev, AHIsubBase );
218 FreeVec(devTmp);
219 ++card_no;
222 bug("[SB128] %s: Done.\n", __PRETTY_FUNCTION__);
225 return TRUE;
229 /******************************************************************************
230 ** Custom driver clean-up *****************************************************
231 ******************************************************************************/
233 VOID
234 DriverCleanup( struct DriverBase* AHIsubBase )
236 struct SB128Base* SB128Base = (struct SB128Base*) AHIsubBase;
237 int i;
238 #if 0
239 if( SB128Base->camd.Semaphore.ss_Link.ln_Name != NULL )
241 ObtainSemaphore( &SB128Base->camd.Semaphore );
242 RemSemaphore( &SB128Base->camd.Semaphore );
243 ReleaseSemaphore( &SB128Base->camd.Semaphore );
245 #endif
247 for( i = 0; i < SB128Base->cards_found; ++i )
249 if (SB128Base->driverdatas)
251 pci_outl( 0, SB128_SCON, SB128Base->driverdatas[i] );
252 FreeDriverData( SB128Base->driverdatas[ i ], AHIsubBase );
256 if (SB128Base->driverdatas)
257 FreeVec( SB128Base->driverdatas );
259 /*if (TimerIO)
261 CloseDevice((struct IORequest *)TimerIO);
262 DeleteIORequest((struct IORequest *)TimerIO);
265 /*if (replymp)
266 DeletePort(replymp);*/
268 ahi_pci_exit();
270 if (ExpansionBase)
271 CloseLibrary( (struct Library*) ExpansionBase );
273 if (UtilityBase)
274 CloseLibrary( (struct Library*) UtilityBase );
276 if (DOSBase)
277 CloseLibrary( (struct Library*) DOSBase );