SysMon: remove dead code
[AROS.git] / workbench / devs / AHI / Drivers / VIA-AC97 / driver-init.c
blob9104e1c3feb651f9c040877b4a6ae0c20a8a5ad4
1 /*
2 Copyright © 2005-2013, Davy Wentzler. All rights reserved.
3 Copyright © 2010-2013, The AROS Development Team. All rights reserved.
4 $Id$
5 */
7 #ifdef __AROS__
8 #define DEBUG 0
9 #include <aros/debug.h>
10 #define DebugPrintF bug
11 #endif
13 #include <exec/memory.h>
15 #if !defined(__AROS__)
16 #undef __USE_INLINE__
17 #include <proto/expansion.h>
18 #endif
20 #include <proto/exec.h>
21 #include <proto/dos.h>
22 #include <clib/alib_protos.h>
24 #include "library.h"
25 #include "misc.h"
26 #include "regs.h"
28 #include "pci_wrapper.h"
30 struct DriverBase* AHIsubBase;
32 struct DosLibrary* DOSBase;
33 struct Library* ExpansionBase = NULL;
35 struct VendorDevice
37 UWORD vendor;
38 UWORD device;
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 ******************************************************************************/
53 BOOL
54 DriverInit( struct DriverBase* ahisubbase )
56 struct CardBase *CardBase = (struct CardBase*) ahisubbase;
57 struct PCIDevice *dev;
58 int card_no, i;
59 struct List foundCards;
60 struct Node *devTmp;
62 bug("[VIA-AC97]: %s()\n", __PRETTY_FUNCTION__);
64 CardBase->driverdatas = 0;
65 CardBase->cards_found = 0;
66 AHIsubBase = ahisubbase;
68 NewList(&foundCards);
70 DOSBase = (struct DosLibrary *)OpenLibrary( DOSNAME, 37 );
72 if( DOSBase == NULL )
74 Req( "VIA-AC97: Unable to open 'dos.library' version 37.\n" );
75 return FALSE;
78 ExpansionBase = OpenLibrary( "expansion.library", 1 );
79 if( ExpansionBase == NULL )
81 Req( "VIA-AC97: Unable to open 'expansion.library' version 1.\n" );
82 return FALSE;
85 if (!ahi_pci_init(ahisubbase))
87 return FALSE;
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;
103 dev = NULL;
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);
109 if (dev != NULL)
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" );
128 #endif
129 return FALSE;
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." );
141 return FALSE;
144 card_no = 0;
146 struct Node *scratchNode;
147 ForeachNodeSafe(&foundCards, devTmp, scratchNode)
149 Remove(devTmp);
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 );
155 FreeVec(devTmp);
156 ++card_no;
159 bug("[VIA-AC97] %s: Done.\n", __PRETTY_FUNCTION__);
161 return TRUE;
165 /******************************************************************************
166 ** Custom driver clean-up *****************************************************
167 ******************************************************************************/
169 VOID
170 DriverCleanup( struct DriverBase* AHIsubBase )
172 struct CardBase* CardBase = (struct CardBase*) AHIsubBase;
173 int i;
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 );
184 ahi_pci_exit();
186 if (ExpansionBase)
187 CloseLibrary( (struct Library*) ExpansionBase);
189 if (UtilityBase)
190 CloseLibrary( (struct Library*) UtilityBase);
192 if (DOSBase)
193 CloseLibrary( (struct Library*) DOSBase);