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 <aros/debug.h>
15 #define DebugPrintF bug
18 #include <exec/memory.h>
20 #if !defined(__AROS__)
22 #include <proto/expansion.h>
25 #include <proto/exec.h>
26 #include <proto/dos.h>
33 #include "pci_wrapper.h"
35 struct DriverBase
* AHIsubBase
;
37 struct DosLibrary
* DOSBase
;
38 struct Library
* ExpansionBase
= NULL
;
46 #define VENDOR_ID 0x13F6
47 #define DEVICE_ID 0x0111
48 #define CARD_STRING "CMI8738"
49 #define MAX_DEVICE_VENDORS 512
51 struct VendorDevice
*vendor_device_list
= NULL
;
52 static int vendor_device_list_size
= 0;
54 /******************************************************************************
55 ** Custom driver init *********************************************************
56 ******************************************************************************/
59 DriverInit( struct DriverBase
* ahisubbase
)
61 struct CMI8738Base
*CMI8738Base
= (struct CMI8738Base
*) ahisubbase
;
62 struct PCIDevice
*dev
;
64 struct List foundCards
;
67 bug("[CMI8738]: %s()\n", __PRETTY_FUNCTION__
);
69 CMI8738Base
->driverdatas
= 0;
70 CMI8738Base
->cards_found
= 0;
71 AHIsubBase
= ahisubbase
;
75 DOSBase
= OpenLibrary( DOSNAME
, 37 );
79 Req( "CMI8738: Unable to open 'dos.library' version 37.\n" );
83 ExpansionBase
= OpenLibrary( "expansion.library", 1 );
84 if( ExpansionBase
== NULL
)
86 Req( "CMI8738: Unable to open 'expansion.library' version 1.\n" );
90 if (!ahi_pci_init(ahisubbase
))
95 InitSemaphore( &CMI8738Base
->semaphore
);
97 /*** Count cards ***********************************************************/
99 vendor_device_list
= (struct VendorDevice
*) AllocVec(sizeof(struct VendorDevice
) * MAX_DEVICE_VENDORS
, MEMF_PUBLIC
| MEMF_CLEAR
);
101 vendor_device_list
[0].vendor
= VENDOR_ID
;
102 vendor_device_list
[0].device
= DEVICE_ID
;
103 vendor_device_list_size
++;
105 bug("vendor_device_list_size = %ld\n", vendor_device_list_size
);
107 CMI8738Base
->cards_found
= 0;
110 for (i
= 0; i
< vendor_device_list_size
; i
++)
112 dev
= ahi_pci_find_device(vendor_device_list
[i
].vendor
, vendor_device_list
[i
].device
, dev
);
116 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
);
117 ++CMI8738Base
->cards_found
;
119 devTmp
= AllocVec(sizeof(struct Node
), MEMF_CLEAR
);
120 devTmp
->ln_Name
= dev
;
121 AddTail(&foundCards
, devTmp
);
125 // Fail if no hardware is present (prevents the audio modes from being added to
126 // the database if the driver cannot be used).
128 if(CMI8738Base
->cards_found
== 0 )
130 DebugPrintF("No CMI8738 found! :-(\n");
131 #if defined(VERBOSE_REQ)
132 Req( "No card present.\n" );
137 /*** CAMD ******************************************************************/
139 InitSemaphore( &CMI8738Base
->camd
.Semaphore
);
140 CMI8738Base
->camd
.Semaphore
.ss_Link
.ln_Pri
= 0;
142 CMI8738Base
->camd
.Semaphore
.ss_Link
.ln_Name
= Card_CAMD_SEMAPHORE
;
143 AddSemaphore( &CMI8738Base
->camd
.Semaphore
);
145 CMI8738Base
->camd
.Cards
= CMI8738Base
->cards_found
;
146 CMI8738Base
->camd
.Version
= VERSION
;
147 CMI8738Base
->camd
.Revision
= REVISION
;
149 CMI8738Base
->camd
.OpenPortFunc
.h_Entry
= OpenCAMDPort
;
150 CMI8738Base
->camd
.OpenPortFunc
.h_SubEntry
= NULL
;
151 CMI8738Base
->camd
.OpenPortFunc
.h_Data
= NULL
;
153 CMI8738Base
->camd
.ClosePortFunc
.h_Entry
= (HOOKFUNC
) CloseCAMDPort
;
154 CMI8738Base
->camd
.ClosePortFunc
.h_SubEntry
= NULL
;
155 CMI8738Base
->camd
.ClosePortFunc
.h_Data
= NULL
;
157 CMI8738Base
->camd
.ActivateXmitFunc
.h_Entry
= (HOOKFUNC
) ActivateCAMDXmit
;
158 CMI8738Base
->camd
.ActivateXmitFunc
.h_SubEntry
= NULL
;
159 CMI8738Base
->camd
.ActivateXmitFunc
.h_Data
= NULL
;
162 /*** Allocate and init all cards *******************************************/
164 CMI8738Base
->driverdatas
= AllocVec( sizeof( *CMI8738Base
->driverdatas
) *
165 CMI8738Base
->cards_found
,
166 MEMF_PUBLIC
| MEMF_CLEAR
);
168 if( CMI8738Base
->driverdatas
== NULL
)
170 Req( "Out of memory." );
176 struct Node
*scratchNode
;
177 ForeachNodeSafe(&foundCards
, devTmp
, scratchNode
)
181 dev
= devTmp
->ln_Name
;
182 bug("[CMI8738] %s: Prepairing card #%d pci obj @ 0x%p\n", __PRETTY_FUNCTION__
, card_no
, dev
);
183 CMI8738Base
->driverdatas
[ card_no
] = AllocDriverData( dev
, AHIsubBase
);
189 bug("[CMI8738] %s: Done.\n", __PRETTY_FUNCTION__
);
195 /******************************************************************************
196 ** Custom driver clean-up *****************************************************
197 ******************************************************************************/
200 DriverCleanup( struct DriverBase
* AHIsubBase
)
202 struct CMI8738Base
* CMI8738Base
= (struct CMI8738Base
*) AHIsubBase
;
205 bug("[CMI8738]: %s()\n", __PRETTY_FUNCTION__
);
207 for( i
= 0; i
< CMI8738Base
->cards_found
; ++i
)
209 FreeDriverData( CMI8738Base
->driverdatas
[ i
], AHIsubBase
);
212 FreeVec( CMI8738Base
->driverdatas
);
217 CloseLibrary( (struct Library
*) ExpansionBase
);
220 CloseLibrary( (struct Library
*) UtilityBase
);
223 CloseLibrary( (struct Library
*) DOSBase
);