Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / AHI / Drivers / Envy24HT / driver-init.c
blobf5ddb72ebc2cfdd3fd9ddd08755a792c97757785
1 /*
2 Copyright © 2005-2013, Davy Wentzler. All rights reserved.
3 $Id$
4 */
6 #include <exec/memory.h>
7 #include <proto/expansion.h>
8 #include <proto/exec.h>
9 #include <proto/dos.h>
11 #ifdef __amigaos4__
12 #include "library_card.h"
13 struct Library* SysBase;
14 #elif __MORPHOS__
15 struct ExecBase* SysBase;
16 #include "library_mos.h"
17 #else
18 struct DosLibrary* DOSBase;
19 #include "library.h"
20 #endif
21 #include "version.h"
22 #include "misc.h"
23 #include "regs.h"
24 #include "DriverData.h"
27 struct DriverBase* AHIsubBase;
29 #include "pci_wrapper.h"
34 struct Library* ExpansionBase = NULL;
36 #ifdef __amigaos4__
37 struct ExpansionIFace* IExpansion = NULL;
38 struct UtilityIFace* IUtility = NULL;
39 struct AHIsubIFace* IAHIsub = NULL;
40 struct PCIIFace* IPCI = NULL;
41 struct MMUIFace* IMMU = NULL;
42 #endif
44 #define VENDOR_ID 0x1412
45 #define DEVICE_ID 0x1724
46 #define CARD_STRING "Envy24HT"
48 #ifdef __AROS__
49 #include <proto/stdc.h>
50 struct StdCBase *StdCBase = NULL;
51 #endif
53 /******************************************************************************
54 ** Custom driver init *********************************************************
55 ******************************************************************************/
57 BOOL DriverInit( struct DriverBase* ahisubbase )
59 struct CardBase* CardBase = (struct CardBase*) ahisubbase;
60 struct PCIDevice *dev;
61 int card_no;
63 DEBUGPRINTF("\n%s DriverInit\n", CARD_STRING);
65 AHIsubBase = ahisubbase;
67 #ifdef __AROS__
68 StdCBase = (struct StdCBase *)OpenLibrary((CONST_STRPTR)"stdc.library", 0);
69 if (!StdCBase)
71 return FALSE;
73 #endif
75 if (!ahi_pci_init(ahisubbase))
77 return FALSE;
80 /*** Count cards ***********************************************************/
82 CardBase->cards_found = 0;
83 dev = NULL;
85 if ( (dev = ahi_pci_find_device(VENDOR_ID, DEVICE_ID, 0) ))
87 ++CardBase->cards_found;
88 DEBUGPRINTF("%s found! :-)\n", CARD_STRING);
91 // Fail if no hardware is present (prevents the audio modes from being added to
92 // the database if the driver cannot be used).
94 if( CardBase->cards_found == 0 )
96 DEBUGPRINTF("No %s found! :-(\n", CARD_STRING);
97 //Req( "No card present.\n" );
98 return FALSE;
101 /*if (dev->Lock(EXCLUSIVE_LOCK) == FALSE)
103 DEBUGPRINTF("Envy24HT: Couldn't lock the device\n");
104 return FALSE;
107 /*** CAMD ******************************************************************/
108 #if 0
109 IExec->InitSemaphore( &CardBase->camd.Semaphore );
110 CardBase->camd.Semaphore.ss_Link.ln_Pri = 0;
112 CardBase->camd.Semaphore.ss_Link.ln_Name = Card_CAMD_SEMAPHORE;
113 IExec->AddSemaphore( &CardBase->camd.Semaphore );
115 CardBase->camd.Cards = CardBase->cards_found;
116 CardBase->camd.Version = VERSION;
117 CardBase->camd.Revision = REVISION;
120 CardBase->camd.OpenPortFunc.h_Entry = OpenCAMDPort;
121 CardBase->camd.OpenPortFunc.h_SubEntry = NULL;
122 CardBase->camd.OpenPortFunc.h_Data = NULL;
124 CardBase->camd.ClosePortFunc.h_Entry = (HOOKFUNC) CloseCAMDPort;
125 CardBase->camd.ClosePortFunc.h_SubEntry = NULL;
126 CardBase->camd.ClosePortFunc.h_Data = NULL;
128 CardBase->camd.ActivateXmitFunc.h_Entry = (HOOKFUNC) ActivateCAMDXmit;
129 CardBase->camd.ActivateXmitFunc.h_SubEntry = NULL;
130 CardBase->camd.ActivateXmitFunc.h_Data = NULL;
131 #endif
134 /*** Allocate and init all cards *******************************************/
136 CardBase->driverdatas = ALLOCVEC(sizeof(*CardBase->driverdatas) *
137 CardBase->cards_found,
138 MEMF_PUBLIC);
140 if( CardBase->driverdatas == NULL )
142 Req( "Out of memory." );
143 return FALSE;
146 card_no = 0;
148 if( ( dev = ahi_pci_find_device(VENDOR_ID, DEVICE_ID, 0) ) != NULL )
150 CardBase->driverdatas[ card_no ] = AllocDriverData( dev, AHIsubBase );
151 ++card_no;
155 //DEBUGPRINTF("Envy24HT exit\n");
156 return TRUE;
160 /******************************************************************************
161 ** Custom driver clean-up *****************************************************
162 ******************************************************************************/
164 VOID
165 DriverCleanup( struct DriverBase* AHIsubBase )
167 struct CardBase* CardBase = (struct CardBase*) AHIsubBase;
168 struct CardData *card;
169 int i;
170 #if 0
171 if( CardBase->camd.Semaphore.ss_Link.ln_Name != NULL )
173 OBTAINSEMAPHORE( &CardBase->camd.Semaphore );
174 IExec->RemSemaphore( &CardBase->camd.Semaphore );
175 RELEASESEMAPHORE( &CardBase->camd.Semaphore );
177 #endif
178 for( i = 0; i < CardBase->cards_found; ++i )
180 card = CardBase->driverdatas[ i ];
181 OUTWORD(card->iobase + CCS_INTR_MASK, ~0);
182 //CardBase->driverdatas[i]->pci_dev->Unlock();
183 FreeDriverData( card, AHIsubBase );
186 FREEVEC( CardBase->driverdatas );
188 ahi_pci_exit();
190 #ifdef __AROS__
191 if (StdCBase)
193 CloseLibrary((struct Library *)StdCBase);
194 StdCBase = NULL;
196 #endif