2 Copyright © 2005-2013, Davy Wentzler. All rights reserved.
6 #include <exec/memory.h>
7 #include <proto/expansion.h>
8 #include <proto/exec.h>
12 #include "library_card.h"
13 struct Library
* SysBase
;
15 struct ExecBase
* SysBase
;
16 #include "library_mos.h"
18 struct DosLibrary
* DOSBase
;
24 #include "DriverData.h"
27 struct DriverBase
* AHIsubBase
;
29 #include "pci_wrapper.h"
34 struct Library
* ExpansionBase
= NULL
;
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
;
44 #define VENDOR_ID 0x1412
45 #define DEVICE_ID 0x1724
46 #define CARD_STRING "Envy24HT"
49 #include <proto/stdc.h>
50 struct StdCBase
*StdCBase
= NULL
;
53 /******************************************************************************
54 ** Custom driver init *********************************************************
55 ******************************************************************************/
57 BOOL
DriverInit( struct DriverBase
* ahisubbase
)
59 struct CardBase
* CardBase
= (struct CardBase
*) ahisubbase
;
60 struct PCIDevice
*dev
;
63 DEBUGPRINTF("\n%s DriverInit\n", CARD_STRING
);
65 AHIsubBase
= ahisubbase
;
68 StdCBase
= (struct StdCBase
*)OpenLibrary((CONST_STRPTR
)"stdc.library", 0);
75 if (!ahi_pci_init(ahisubbase
))
80 /*** Count cards ***********************************************************/
82 CardBase
->cards_found
= 0;
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" );
101 /*if (dev->Lock(EXCLUSIVE_LOCK) == FALSE)
103 DEBUGPRINTF("Envy24HT: Couldn't lock the device\n");
107 /*** CAMD ******************************************************************/
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
;
134 /*** Allocate and init all cards *******************************************/
136 CardBase
->driverdatas
= ALLOCVEC(sizeof(*CardBase
->driverdatas
) *
137 CardBase
->cards_found
,
140 if( CardBase
->driverdatas
== NULL
)
142 Req( "Out of memory." );
148 if( ( dev
= ahi_pci_find_device(VENDOR_ID
, DEVICE_ID
, 0) ) != NULL
)
150 CardBase
->driverdatas
[ card_no
] = AllocDriverData( dev
, AHIsubBase
);
155 //DEBUGPRINTF("Envy24HT exit\n");
160 /******************************************************************************
161 ** Custom driver clean-up *****************************************************
162 ******************************************************************************/
165 DriverCleanup( struct DriverBase
* AHIsubBase
)
167 struct CardBase
* CardBase
= (struct CardBase
*) AHIsubBase
;
168 struct CardData
*card
;
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
);
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
);
193 CloseLibrary((struct Library
*)StdCBase
);