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.
14 #include <exec/memory.h>
17 #include <proto/expansion.h>
19 #include <proto/exec.h>
20 #include <proto/dos.h>
21 #include <proto/fakedma.h>
23 #include "library_card.h"
27 #include "DriverData.h"
29 struct DriverBase
* AHIsubBase
;
31 struct Library
* ExpansionBase
= NULL
;
32 struct ExpansionIFace
* IExpansion
= NULL
;
33 //struct DOSIFace* IDOS = NULL;
34 struct UtilityIFace
* IUtility
= NULL
;
35 struct AHIsubIFace
* IAHIsub
= NULL
;
36 struct PCIIFace
* IPCI
= NULL
;
37 struct MMUIFace
* IMMU
= NULL
;
38 struct Library
*FakeDMABase
= NULL
;
39 struct FakeDMAIFace
*IFakeDMA
= NULL
;
42 #define VENDOR_ID 0x13F6
43 #define DEVICE_ID 0x0111
44 #define CARD_STRING "CMI8738"
47 /******************************************************************************
48 ** Custom driver init *********************************************************
49 ******************************************************************************/
52 DriverInit( struct DriverBase
* ahisubbase
)
54 struct CardBase
* CardBase
= (struct CardBase
*) ahisubbase
;
55 struct PCIDevice
*dev
;
58 //IExec->DebugPrintF("DRIVERINIT\n");
60 CardBase
->driverdatas
= 0;
61 CardBase
->cards_found
= 0;
62 AHIsubBase
= ahisubbase
;
64 DOSBase
= IExec
->OpenLibrary( DOSNAME
, 37 );
68 Req( "Unable to open 'dos.library' version 37.\n" );
72 if ((IDOS
= (struct DOSIFace
*) IExec
->GetInterface((struct Library
*) DOSBase
, "main", 1, NULL
)) == NULL
)
74 Req("Couldn't open IDOS interface!\n");
78 ExpansionBase
= IExec
->OpenLibrary( "expansion.library", 1 );
79 if( ExpansionBase
== NULL
)
81 Req( "Unable to open 'expansion.library' version 1.\n" );
84 if ((IExpansion
= (struct ExpansionIFace
*) IExec
->GetInterface((struct Library
*) ExpansionBase
, "main", 1, NULL
)) == NULL
)
86 Req("Couldn't open IExpansion interface!\n");
90 if ((IPCI
= (struct PCIIFace
*) IExec
->GetInterface((struct Library
*) ExpansionBase
, "pci", 1, NULL
)) == NULL
)
92 Req("Couldn't open IPCI interface!\n");
96 if ((IAHIsub
= (struct AHIsubIFace
*) IExec
->GetInterface((struct Library
*) AHIsubBase
, "main", 1, NULL
)) == NULL
)
98 Req("Couldn't open IAHIsub interface!\n");
102 if ((IUtility
= (struct UtilityIFace
*) IExec
->GetInterface((struct Library
*) UtilityBase
, "main", 1, NULL
)) == NULL
)
104 Req("Couldn't open IUtility interface!\n");
108 if ((IMMU
= (struct MMUIFace
*) IExec
->GetInterface((struct Library
*) SysBase
, "mmu", 1, NULL
)) == NULL
)
110 Req("Couldn't open IMMU interface!\n");
114 if(!( FakeDMABase
= (struct Library
*)IExec
->OpenLibrary( "fakedma.library", 52L )))
116 IExec
->DebugPrintF("No fakemda.library found. Using PIO\n");
120 if(!( IFakeDMA
= (struct FakeDMAIFace
*)IExec
->GetInterface( FakeDMABase
, "main", 1L, NULL
)))
122 IExec
->CloseLibrary( FakeDMABase
);
126 IExec
->InitSemaphore( &CardBase
->semaphore
);
129 /*** Count cards ***********************************************************/
131 CardBase
->cards_found
= 0;
134 if ( (dev
= IPCI
->FindDeviceTags( FDT_VendorID
, VENDOR_ID
, // while
135 FDT_DeviceID
, DEVICE_ID
, //FDT_INDEX, CardBase->cards_found,
136 TAG_DONE
) ) != NULL
)
138 ++CardBase
->cards_found
;
139 // IExec->DebugPrintF("%s found! :-)\n", CARD_STRING);
142 // Fail if no hardware is present (prevents the audio modes from being added to
143 // the database if the driver cannot be used).
145 if(CardBase
->cards_found
== 0 )
147 IExec
->DebugPrintF("No %s found! :-(\n", CARD_STRING
);
148 Req( "No card present.\n" );
152 if (dev
->Lock(EXCLUSIVE_LOCK
) == FALSE
)
154 IExec
->DebugPrintF("CMI8738: Couldn't lock the device\n");
158 /*** CAMD ******************************************************************/
160 IExec
->InitSemaphore( &CardBase
->camd
.Semaphore
);
161 CardBase
->camd
.Semaphore
.ss_Link
.ln_Pri
= 0;
163 CardBase
->camd
.Semaphore
.ss_Link
.ln_Name
= Card_CAMD_SEMAPHORE
;
164 IExec
->AddSemaphore( &CardBase
->camd
.Semaphore
);
166 CardBase
->camd
.Cards
= CardBase
->cards_found
;
167 CardBase
->camd
.Version
= VERSION
;
168 CardBase
->camd
.Revision
= REVISION
;
171 CardBase
->camd
.OpenPortFunc
.h_Entry
= OpenCAMDPort
;
172 CardBase
->camd
.OpenPortFunc
.h_SubEntry
= NULL
;
173 CardBase
->camd
.OpenPortFunc
.h_Data
= NULL
;
175 CardBase
->camd
.ClosePortFunc
.h_Entry
= (HOOKFUNC
) CloseCAMDPort
;
176 CardBase
->camd
.ClosePortFunc
.h_SubEntry
= NULL
;
177 CardBase
->camd
.ClosePortFunc
.h_Data
= NULL
;
179 CardBase
->camd
.ActivateXmitFunc
.h_Entry
= (HOOKFUNC
) ActivateCAMDXmit
;
180 CardBase
->camd
.ActivateXmitFunc
.h_SubEntry
= NULL
;
181 CardBase
->camd
.ActivateXmitFunc
.h_Data
= NULL
;
185 /*** Allocate and init all cards *******************************************/
187 CardBase
->driverdatas
= IExec
->AllocVec( sizeof( *CardBase
->driverdatas
) *
188 CardBase
->cards_found
,
191 if( CardBase
->driverdatas
== NULL
)
193 Req( "Out of memory." );
199 if( ( dev
= IPCI
->FindDeviceTags( FDT_VendorID
, VENDOR_ID
, // while
200 FDT_DeviceID
, DEVICE_ID
, //FDT_INDEX, CardBase->cards_found,
201 TAG_DONE
) ) != NULL
)
203 CardBase
->driverdatas
[ card_no
] = AllocDriverData( dev
, AHIsubBase
);
207 //IExec->DebugPrintF("exit init\n");
212 /******************************************************************************
213 ** Custom driver clean-up *****************************************************
214 ******************************************************************************/
217 DriverCleanup( struct DriverBase
* AHIsubBase
)
219 struct CardBase
* CardBase
= (struct CardBase
*) AHIsubBase
;
224 if( CardBase
->camd
.Semaphore
.ss_Link
.ln_Name
!= NULL
)
226 IExec
->ObtainSemaphore( &CardBase
->camd
.Semaphore
);
227 IExec
->RemSemaphore( &CardBase
->camd
.Semaphore
);
228 IExec
->ReleaseSemaphore( &CardBase
->camd
.Semaphore
);
231 for( i
= 0; i
< CardBase
->cards_found
; ++i
)
233 if (CardBase
->driverdatas
)
235 if (CardBase
->driverdatas
)
237 CardBase
->driverdatas
[i
]->pci_dev
->Unlock();
238 FreeDriverData( CardBase
->driverdatas
[ i
], AHIsubBase
);
243 if (CardBase
->driverdatas
)
244 IExec
->FreeVec( CardBase
->driverdatas
);
247 IExec
->DropInterface( (struct Interface
*)IFakeDMA
);
250 IExec
->CloseLibrary( FakeDMABase
);
253 IExec
->DropInterface( (struct Interface
*) IUtility
);
256 IExec
->DropInterface( (struct Interface
*) IExpansion
);
259 IExec
->DropInterface( (struct Interface
*) IPCI
);
262 IExec
->DropInterface( (struct Interface
*) IAHIsub
);
265 IExec
->DropInterface( (struct Interface
*) IDOS
);
268 IExec
->CloseLibrary( (struct Library
*) ExpansionBase
);
271 IExec
->CloseLibrary( (struct Library
*) UtilityBase
);
274 IExec
->CloseLibrary( (struct Library
*) DOSBase
);