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>
27 #include <clib/alib_protos.h>
33 #include "pci_wrapper.h"
35 struct DriverBase
* AHIsubBase
;
37 struct DosLibrary
* DOSBase
;
38 struct Library
* ExpansionBase
= NULL
;
40 struct Library
* StdCBase
= NULL
;
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 ******************************************************************************/
62 DriverInit( struct DriverBase
* ahisubbase
)
64 struct CMI8738Base
*CMI8738Base
= (struct CMI8738Base
*) ahisubbase
;
65 struct PCIDevice
*dev
;
67 struct List foundCards
;
70 bug("[CMI8738]: %s()\n", __PRETTY_FUNCTION__
);
72 CMI8738Base
->driverdatas
= 0;
73 CMI8738Base
->cards_found
= 0;
74 AHIsubBase
= ahisubbase
;
78 DOSBase
= (struct DosLibrary
*)OpenLibrary( DOSNAME
, 37 );
82 Req( "CMI8738: Unable to open 'dos.library' version 37.\n" );
86 ExpansionBase
= OpenLibrary( "expansion.library", 1 );
87 if( ExpansionBase
== NULL
)
89 Req( "CMI8738: Unable to open 'expansion.library' version 1.\n" );
94 StdCBase
= OpenLibrary( "stdc.library", 0 );
95 if( StdCBase
== NULL
)
97 Req( "CMI8738: Unable to open 'stdc.library'.\n" );
102 if (!ahi_pci_init(ahisubbase
))
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;
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
);
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" );
149 /*** CAMD ******************************************************************/
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
;
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." );
188 struct Node
*scratchNode
;
189 ForeachNodeSafe(&foundCards
, devTmp
, scratchNode
)
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
);
201 bug("[CMI8738] %s: Done.\n", __PRETTY_FUNCTION__
);
207 /******************************************************************************
208 ** Custom driver clean-up *****************************************************
209 ******************************************************************************/
212 DriverCleanup( struct DriverBase
* AHIsubBase
)
214 struct CMI8738Base
* CMI8738Base
= (struct CMI8738Base
*) AHIsubBase
;
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
);
230 CloseLibrary( StdCBase
);
234 CloseLibrary( (struct Library
*) ExpansionBase
);
237 CloseLibrary( (struct Library
*) UtilityBase
);
240 CloseLibrary( (struct Library
*) DOSBase
);