2 Copyright © 2005-2013, Davy Wentzler. All rights reserved.
3 Copyright © 2010-2013, The AROS Development Team. All rights reserved.
9 #include <aros/debug.h>
10 #define DebugPrintF bug
13 #include <exec/memory.h>
15 #if !defined(__AROS__)
17 #include <proto/expansion.h>
20 #include <proto/exec.h>
21 #include <proto/dos.h>
22 #include <clib/alib_protos.h>
28 #include "pci_wrapper.h"
30 struct DriverBase
* AHIsubBase
;
32 struct DosLibrary
* DOSBase
;
33 struct Library
* ExpansionBase
= NULL
;
41 #define VENDOR_ID 0x1106
42 #define DEVICE_ID 0x3058
43 #define CARD_STRING "VIA AC97 Audio Controller"
44 #define MAX_DEVICE_VENDORS 512
46 struct VendorDevice
*vendor_device_list
= NULL
;
47 static int vendor_device_list_size
= 0;
49 /******************************************************************************
50 ** Custom driver init *********************************************************
51 ******************************************************************************/
54 DriverInit( struct DriverBase
* ahisubbase
)
56 struct CardBase
*CardBase
= (struct CardBase
*) ahisubbase
;
57 struct PCIDevice
*dev
;
59 struct List foundCards
;
62 bug("[VIA-AC97]: %s()\n", __PRETTY_FUNCTION__
);
64 CardBase
->driverdatas
= 0;
65 CardBase
->cards_found
= 0;
66 AHIsubBase
= ahisubbase
;
70 DOSBase
= (struct DosLibrary
*)OpenLibrary( DOSNAME
, 37 );
74 Req( "VIA-AC97: Unable to open 'dos.library' version 37.\n" );
78 ExpansionBase
= OpenLibrary( "expansion.library", 1 );
79 if( ExpansionBase
== NULL
)
81 Req( "VIA-AC97: Unable to open 'expansion.library' version 1.\n" );
85 if (!ahi_pci_init(ahisubbase
))
90 InitSemaphore( &CardBase
->semaphore
);
92 /*** Count cards ***********************************************************/
94 vendor_device_list
= (struct VendorDevice
*) AllocVec(sizeof(struct VendorDevice
) * MAX_DEVICE_VENDORS
, MEMF_PUBLIC
| MEMF_CLEAR
);
96 vendor_device_list
[0].vendor
= VENDOR_ID
;
97 vendor_device_list
[0].device
= DEVICE_ID
;
98 vendor_device_list_size
++;
100 bug("vendor_device_list_size = %ld\n", vendor_device_list_size
);
102 CardBase
->cards_found
= 0;
105 for (i
= 0; i
< vendor_device_list_size
; i
++)
107 dev
= ahi_pci_find_device(vendor_device_list
[i
].vendor
, vendor_device_list
[i
].device
, dev
);
111 bug("[VIA-AC97] %s: Found VIA-AC97 #%d [%4x:%4x] pci obj @ 0x%p\n", __PRETTY_FUNCTION__
, i
, vendor_device_list
[i
].vendor
, vendor_device_list
[i
].device
, dev
);
112 ++CardBase
->cards_found
;
114 devTmp
= AllocVec(sizeof(struct Node
), MEMF_CLEAR
);
115 devTmp
->ln_Name
= (APTR
)dev
;
116 AddTail(&foundCards
, devTmp
);
120 // Fail if no hardware is present (prevents the audio modes from being added to
121 // the database if the driver cannot be used).
123 if(CardBase
->cards_found
== 0 )
125 DebugPrintF("No VIA-AC97 found! :-(\n");
126 #if defined(VERBOSE_REQ)
127 Req( "No card present.\n" );
132 /*** Allocate and init all cards *******************************************/
134 CardBase
->driverdatas
= AllocVec( sizeof( *CardBase
->driverdatas
) *
135 CardBase
->cards_found
,
136 MEMF_PUBLIC
| MEMF_CLEAR
);
138 if( CardBase
->driverdatas
== NULL
)
140 Req( "Out of memory." );
146 struct Node
*scratchNode
;
147 ForeachNodeSafe(&foundCards
, devTmp
, scratchNode
)
151 dev
= (struct PCIDevice
*)devTmp
->ln_Name
;
152 bug("[VIA-AC97] %s: Preparing card #%d pci obj @ 0x%p\n", __PRETTY_FUNCTION__
, card_no
, dev
);
153 CardBase
->driverdatas
[ card_no
] = AllocDriverData( dev
, AHIsubBase
);
159 bug("[VIA-AC97] %s: Done.\n", __PRETTY_FUNCTION__
);
165 /******************************************************************************
166 ** Custom driver clean-up *****************************************************
167 ******************************************************************************/
170 DriverCleanup( struct DriverBase
* AHIsubBase
)
172 struct CardBase
* CardBase
= (struct CardBase
*) AHIsubBase
;
175 bug("[VIA-AC97]: %s()\n", __PRETTY_FUNCTION__
);
177 for( i
= 0; i
< CardBase
->cards_found
; ++i
)
179 FreeDriverData( CardBase
->driverdatas
[ i
], AHIsubBase
);
182 FreeVec( CardBase
->driverdatas
);
187 CloseLibrary( (struct Library
*) ExpansionBase
);
190 CloseLibrary( (struct Library
*) UtilityBase
);
193 CloseLibrary( (struct Library
*) DOSBase
);