3 Copyright (C) 2004-2012 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 <libraries/cybpci.h>
26 #include <proto/exec.h>
27 #include <proto/cybpci.h>
32 #include "pci_protos.h"
33 #include "cybpci_protos.h"
36 /****i* prism2.device/GetCybPCICount ***************************************
42 * count = GetCybPCICount()
44 * ULONG GetCybPCICount();
46 ****************************************************************************
50 ULONG
GetCybPCICount(struct DevBase
*base
)
54 UWORD vendor_id
, product_id
;
56 while((card
= PCIFindBoardTagList(card
, NULL
)) != NULL
)
58 vendor_id
= PCIReadConfigWord(card
, CYBPCICONFIG_VENDOR
);
59 product_id
= PCIReadConfigWord(card
, CYBPCICONFIG_DEVICE
);
60 if(IsCardCompatible(vendor_id
, product_id
, base
))
69 /****i* prism2.device/AllocCybPCICard **************************************
72 * AllocCybPCICard -- Create a unit.
75 * context = AllocCybPCICard(index)
77 * struct BusContext *AllocCybPCICard(ULONG);
79 ****************************************************************************
83 struct BusContext
*AllocCybPCICard(ULONG index
, struct DevBase
*base
)
86 struct BusContext
*context
;
89 UPINT vendor_id
, product_id
, plx_base
;
91 volatile UBYTE
*cor_reg
;
94 /* Find a compatible card */
96 context
= AllocMem(sizeof(struct BusContext
), MEMF_PUBLIC
| MEMF_CLEAR
);
104 card
= PCIFindBoardTagList(card
, NULL
);
105 vendor_id
= PCIReadConfigWord(card
, CYBPCICONFIG_VENDOR
);
106 product_id
= PCIReadConfigWord(card
, CYBPCICONFIG_DEVICE
);
107 if(IsCardCompatible(vendor_id
, product_id
, base
))
111 context
->card
= card
;
118 /* Find out what type of Prism II PCI card this is */
120 context
->bus_type
= GetBusType(product_id
, base
);
122 if(context
->bus_type
== TMD_BUS
)
124 /* Enable the PCCard */
126 cor_reg
= (APTR
)PCIGetBoardAttr(card
, CYBPCITAG_BASEADDRESS1
);
127 BYTEOUT((UPINT
)cor_reg
, COR_ENABLE
);
130 else if(context
->bus_type
== PLX_BUS
)
132 /* Enable interrupts on the bridge */
134 plx_base
= PCIGetBoardAttr(card
, CYBPCITAG_BASEADDRESS1
);
135 LELONGOUT(plx_base
+ PLX9052_INTS
,
136 LELONGIN(plx_base
+ PLX9052_INTS
) | (1 << 6));
138 /* Enable the PCCard */
140 cor_reg
= (APTR
)PCIGetBoardAttr(card
, CYBPCITAG_BASEADDRESS2
);
142 *cor_reg
= COR_ENABLE
;
148 /* Get the I/O base of the wireless chip */
150 context
->io_base
= PCIGetBoardAttr(card
,
151 CYBPCITAG_BASEADDRESS0
+ io_range_no
);
152 if(context
->io_base
== 0)
158 FreeCybPCICard(context
, base
);
167 /****i* prism2.device/FreeCybPCICard ***************************************
173 * FreeCybPCICard(context)
175 * VOID FreeCybPCICard(struct BusContext *);
177 ****************************************************************************
181 VOID
FreeCybPCICard(struct BusContext
*context
, struct DevBase
*base
)
187 FreeMem(context
, sizeof(struct BusContext
));
194 /****i* prism2.device/AddCybPCIIntServer ***********************************
200 * success = AddCybPCIIntServer(card, interrupt)
202 * BOOL AddCybPCIIntServer(APTR, struct Interrupt *);
204 ****************************************************************************
208 BOOL
AddCybPCIIntServer(APTR card
, struct Interrupt
*interrupt
,
209 struct DevBase
*base
)
211 return (interrupt
->is_Data
= PCICreateIntObjectTagList(card
,
212 (APTR
)interrupt
->is_Code
, interrupt
->is_Data
, NULL
)) != NULL
;
217 /****i* prism2.device/RemCybPCIIntServer ***********************************
223 * RemCybPCIIntServer(card, interrupt)
225 * VOID RemCybPCIIntServer(APTR, struct Interrupt *);
227 ****************************************************************************
231 VOID
RemCybPCIIntServer(APTR card
, struct Interrupt
*interrupt
,
232 struct DevBase
*base
)
234 if(interrupt
->is_Data
!= NULL
)
235 PCIDeleteIntObject(interrupt
->is_Data
);