3 Copyright (C) 2004-2011 Neil Cafferkey
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 #include <exec/types.h>
24 #include <expansion/pci.h>
26 #include <proto/exec.h>
27 #include <proto/expansion.h>
31 #include "pci_protos.h"
32 #include "expansion_protos.h"
36 IMPORT
const UWORD product_codes
[];
39 /****i* atheros.device/GetExpansionCount ***********************************
42 * GetExpansionCount -- Get the number of compatible PCI Cards.
45 * count = GetExpansionCount()
47 * ULONG GetExpansionCount();
49 ****************************************************************************
53 ULONG
GetExpansionCount(struct DevBase
*base
)
56 struct PCIDevice
*card
;
58 if(base
->i_pci
!= NULL
)
61 base
->i_pci
->FindDeviceTags(FDT_CandidateList
, product_codes
,
62 FDT_Index
, count
, TAG_END
)) != NULL
)
64 base
->i_pci
->FreeDevice(card
);
74 /****i* atheros.device/AllocExpansionCard **********************************
77 * AllocExpansionCard -- Take control of a card.
80 * context = AllocExpansionCard(index)
82 * struct BusContext *AllocExpansionCard(ULONG);
84 ****************************************************************************
88 struct BusContext
*AllocExpansionCard(ULONG index
, struct DevBase
*base
)
91 struct BusContext
*context
;
92 struct PCIDevice
*card
= NULL
;
93 struct PCIResourceRange
*io_range
= NULL
;
95 /* Find a compatible card */
97 context
= AllocMem(sizeof(struct BusContext
), MEMF_PUBLIC
| MEMF_CLEAR
);
103 context
->card
= card
=
104 base
->i_pci
->FindDeviceTags(FDT_CandidateList
, product_codes
,
105 FDT_Index
, index
, TAG_END
);
106 context
->id
= 0x0013;
114 success
= card
->Lock(PCI_LOCK_EXCLUSIVE
);
118 card
->WriteConfigWord(PCI_COMMAND
,
119 PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
); /* For PegII */
121 /* Get the I/O base of the wireless chip */
123 context
->have_card
= TRUE
;
124 card
->SetEndian(PCI_MODE_LITTLE_ENDIAN
);
125 io_range
= card
->GetResourceRange(BAR_NO
);
126 context
->io_base
= io_range
->BaseAddress
;
127 card
->FreeResourceRange(io_range
);
132 FreeExpansionCard(context
, base
);
141 /****i* atheros.device/FreeExpansionCard ***********************************
144 * FreeExpansionCard -- Release a card.
147 * FreeExpansionCard(context)
149 * VOID FreeExpansionCard(struct BusContext *);
151 ****************************************************************************
155 VOID
FreeExpansionCard(struct BusContext
*context
, struct DevBase
*base
)
157 struct PCIDevice
*card
;
161 card
= context
->card
;
164 if(context
->have_card
)
166 base
->i_pci
->FreeDevice(card
);
167 FreeMem(context
, sizeof(struct BusContext
));
176 /****i* atheros.device/AddExpansionIntServer *******************************
179 * AddExpansionIntServer
182 * success = AddExpansionIntServer(card, interrupt)
184 * BOOL AddExpansionIntServer(APTR, struct Interrupt *);
186 ****************************************************************************
190 BOOL
AddExpansionIntServer(APTR card
, struct Interrupt
*interrupt
,
191 struct DevBase
*base
)
193 return AddIntServer(((struct PCIDevice
*)card
)->MapInterrupt(),
199 /****i* atheros.device/RemExpansionIntServer *******************************
202 * RemExpansionIntServer
205 * RemExpansionIntServer(card, interrupt)
207 * VOID RemExpansionIntServer(APTR, struct Interrupt *);
209 ****************************************************************************
213 VOID
RemExpansionIntServer(APTR card
, struct Interrupt
*interrupt
,
214 struct DevBase
*base
)
216 RemIntServer(((struct PCIDevice
*)card
)->MapInterrupt(), interrupt
);