Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / AHI / Drivers / CMI8738 / driver-init.c
blob7533bb80efbe99b7bf772683cb26583c515f57b0
1 /*
2 The contents of this file are subject to the AROS Public License Version 1.1 (the "License");
3 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
5 Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
6 ANY KIND, either express or implied. See the License for the specific language governing rights and
7 limitations under the License.
9 The Original Code is written by Davy Wentzler.
12 #ifdef __AROS__
13 #define DEBUG 1
14 #include <aros/debug.h>
15 #define DebugPrintF bug
16 #endif
18 #include <exec/memory.h>
20 #if !defined(__AROS__)
21 #undef __USE_INLINE__
22 #include <proto/expansion.h>
23 #endif
25 #include <proto/exec.h>
26 #include <proto/dos.h>
27 #include <clib/alib_protos.h>
29 #include "library.h"
30 #include "misc.h"
31 #include "regs.h"
33 #include "pci_wrapper.h"
35 struct DriverBase* AHIsubBase;
37 struct DosLibrary* DOSBase;
38 struct Library* ExpansionBase = NULL;
39 #ifdef __AROS__
40 struct Library * StdCBase = NULL;
41 #endif
43 struct VendorDevice
45 UWORD vendor;
46 UWORD device;
49 #define VENDOR_ID 0x13F6
50 #define DEVICE_ID 0x0111
51 #define CARD_STRING "CMI8738"
52 #define MAX_DEVICE_VENDORS 512
54 struct VendorDevice *vendor_device_list = NULL;
55 static int vendor_device_list_size = 0;
57 /******************************************************************************
58 ** Custom driver init *********************************************************
59 ******************************************************************************/
61 BOOL
62 DriverInit( struct DriverBase* ahisubbase )
64 struct CMI8738Base *CMI8738Base = (struct CMI8738Base*) ahisubbase;
65 struct PCIDevice *dev;
66 int card_no, i;
67 struct List foundCards;
68 struct Node *devTmp;
70 bug("[CMI8738]: %s()\n", __PRETTY_FUNCTION__);
72 CMI8738Base->driverdatas = 0;
73 CMI8738Base->cards_found = 0;
74 AHIsubBase = ahisubbase;
76 NewList(&foundCards);
78 DOSBase = (struct DosLibrary *)OpenLibrary( DOSNAME, 37 );
80 if( DOSBase == NULL )
82 Req( "CMI8738: Unable to open 'dos.library' version 37.\n" );
83 return FALSE;
86 ExpansionBase = OpenLibrary( "expansion.library", 1 );
87 if( ExpansionBase == NULL )
89 Req( "CMI8738: Unable to open 'expansion.library' version 1.\n" );
90 return FALSE;
93 #ifdef __AROS__
94 StdCBase = OpenLibrary( "stdc.library", 0 );
95 if( StdCBase == NULL )
97 Req( "CMI8738: Unable to open 'stdc.library'.\n" );
98 return FALSE;
100 #endif
102 if (!ahi_pci_init(ahisubbase))
104 return FALSE;
107 InitSemaphore( &CMI8738Base->semaphore );
109 /*** Count cards ***********************************************************/
111 vendor_device_list = (struct VendorDevice *) AllocVec(sizeof(struct VendorDevice) * MAX_DEVICE_VENDORS, MEMF_PUBLIC | MEMF_CLEAR);
113 vendor_device_list[0].vendor = VENDOR_ID;
114 vendor_device_list[0].device = DEVICE_ID;
115 vendor_device_list_size++;
117 bug("vendor_device_list_size = %ld\n", vendor_device_list_size);
119 CMI8738Base->cards_found = 0;
120 dev = NULL;
122 for (i = 0; i < vendor_device_list_size; i++)
124 dev = ahi_pci_find_device(vendor_device_list[i].vendor, vendor_device_list[i].device, dev);
126 if (dev != NULL)
128 bug("[CMI8738] %s: Found CMI8738 #%d [%4x:%4x] pci obj @ 0x%p\n", __PRETTY_FUNCTION__, i, vendor_device_list[i].vendor, vendor_device_list[i].device, dev);
129 ++CMI8738Base->cards_found;
131 devTmp = AllocVec(sizeof(struct Node), MEMF_CLEAR);
132 devTmp->ln_Name = (APTR)dev;
133 AddTail(&foundCards, devTmp);
137 // Fail if no hardware is present (prevents the audio modes from being added to
138 // the database if the driver cannot be used).
140 if(CMI8738Base->cards_found == 0 )
142 DebugPrintF("No CMI8738 found! :-(\n");
143 #if defined(VERBOSE_REQ)
144 Req( "No card present.\n" );
145 #endif
146 return FALSE;
149 /*** CAMD ******************************************************************/
150 #if 0
151 InitSemaphore( &CMI8738Base->camd.Semaphore );
152 CMI8738Base->camd.Semaphore.ss_Link.ln_Pri = 0;
154 CMI8738Base->camd.Semaphore.ss_Link.ln_Name = Card_CAMD_SEMAPHORE;
155 AddSemaphore( &CMI8738Base->camd.Semaphore );
157 CMI8738Base->camd.Cards = CMI8738Base->cards_found;
158 CMI8738Base->camd.Version = VERSION;
159 CMI8738Base->camd.Revision = REVISION;
161 CMI8738Base->camd.OpenPortFunc.h_Entry = OpenCAMDPort;
162 CMI8738Base->camd.OpenPortFunc.h_SubEntry = NULL;
163 CMI8738Base->camd.OpenPortFunc.h_Data = NULL;
165 CMI8738Base->camd.ClosePortFunc.h_Entry = (HOOKFUNC) CloseCAMDPort;
166 CMI8738Base->camd.ClosePortFunc.h_SubEntry = NULL;
167 CMI8738Base->camd.ClosePortFunc.h_Data = NULL;
169 CMI8738Base->camd.ActivateXmitFunc.h_Entry = (HOOKFUNC) ActivateCAMDXmit;
170 CMI8738Base->camd.ActivateXmitFunc.h_SubEntry = NULL;
171 CMI8738Base->camd.ActivateXmitFunc.h_Data = NULL;
172 #endif
174 /*** Allocate and init all cards *******************************************/
176 CMI8738Base->driverdatas = AllocVec( sizeof( *CMI8738Base->driverdatas ) *
177 CMI8738Base->cards_found,
178 MEMF_PUBLIC | MEMF_CLEAR);
180 if( CMI8738Base->driverdatas == NULL )
182 Req( "Out of memory." );
183 return FALSE;
186 card_no = 0;
188 struct Node *scratchNode;
189 ForeachNodeSafe(&foundCards, devTmp, scratchNode)
191 Remove(devTmp);
193 dev = (struct PCIDevice *)devTmp->ln_Name;
194 bug("[CMI8738] %s: Preparing card #%d pci obj @ 0x%p\n", __PRETTY_FUNCTION__, card_no, dev);
195 CMI8738Base->driverdatas[ card_no ] = AllocDriverData( dev, AHIsubBase );
197 FreeVec(devTmp);
198 ++card_no;
201 bug("[CMI8738] %s: Done.\n", __PRETTY_FUNCTION__);
203 return TRUE;
207 /******************************************************************************
208 ** Custom driver clean-up *****************************************************
209 ******************************************************************************/
211 VOID
212 DriverCleanup( struct DriverBase* AHIsubBase )
214 struct CMI8738Base* CMI8738Base = (struct CMI8738Base*) AHIsubBase;
215 int i;
217 bug("[CMI8738]: %s()\n", __PRETTY_FUNCTION__);
219 for( i = 0; i < CMI8738Base->cards_found; ++i )
221 FreeDriverData( CMI8738Base->driverdatas[ i ], AHIsubBase );
224 FreeVec( CMI8738Base->driverdatas );
226 ahi_pci_exit();
228 #ifdef __AROS__
229 if (StdCBase)
230 CloseLibrary( StdCBase );
231 #endif
233 if (ExpansionBase)
234 CloseLibrary( (struct Library*) ExpansionBase);
236 if (UtilityBase)
237 CloseLibrary( (struct Library*) UtilityBase);
239 if (DOSBase)
240 CloseLibrary( (struct Library*) DOSBase);