2005-05-30 08:35:22 +04:00
|
|
|
/* $NetBSD: i82365_pci.c,v 1.20 2005/05/30 04:35:22 christos Exp $ */
|
1997-10-17 03:23:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1997 Marc Horowitz. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Marc Horowitz.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2000-02-02 01:39:51 +03:00
|
|
|
/*
|
|
|
|
* XXX this driver frontend is *very* i386 dependent and should be relocated
|
|
|
|
*/
|
|
|
|
|
2001-11-13 10:48:40 +03:00
|
|
|
#include <sys/cdefs.h>
|
2005-05-30 08:35:22 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: i82365_pci.c,v 1.20 2005/05/30 04:35:22 christos Exp $");
|
2001-11-13 10:48:40 +03:00
|
|
|
|
1997-10-17 03:23:14 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <dev/ic/i82365reg.h>
|
|
|
|
#include <dev/ic/i82365var.h>
|
|
|
|
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcidevs.h>
|
1998-12-20 20:53:28 +03:00
|
|
|
#include <dev/pci/i82365_pcivar.h>
|
2000-02-23 01:46:16 +03:00
|
|
|
|
|
|
|
#include <dev/isa/isavar.h>
|
2000-02-02 01:39:51 +03:00
|
|
|
#include <dev/isa/i82365_isavar.h>
|
1997-10-17 03:23:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* PCI constants.
|
|
|
|
* XXX These should be in a common file!
|
|
|
|
*/
|
|
|
|
#define PCI_CBIO 0x10 /* Configuration Base IO Address */
|
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
int pcic_pci_match(struct device *, struct cfdata *, void *);
|
|
|
|
void pcic_pci_attach(struct device *, struct device *, void *);
|
1997-10-17 03:23:14 +04:00
|
|
|
|
2002-10-01 00:37:04 +04:00
|
|
|
CFATTACH_DECL(pcic_pci, sizeof(struct pcic_pci_softc),
|
2002-10-02 20:51:16 +04:00
|
|
|
pcic_pci_match, pcic_pci_attach, NULL, NULL);
|
1997-10-17 03:23:14 +04:00
|
|
|
|
|
|
|
static struct pcmcia_chip_functions pcic_pci_functions = {
|
|
|
|
pcic_chip_mem_alloc,
|
|
|
|
pcic_chip_mem_free,
|
|
|
|
pcic_chip_mem_map,
|
|
|
|
pcic_chip_mem_unmap,
|
|
|
|
|
|
|
|
pcic_chip_io_alloc,
|
|
|
|
pcic_chip_io_free,
|
|
|
|
pcic_chip_io_map,
|
|
|
|
pcic_chip_io_unmap,
|
|
|
|
|
2000-02-02 01:39:51 +03:00
|
|
|
/* XXX */
|
|
|
|
pcic_isa_chip_intr_establish,
|
|
|
|
pcic_isa_chip_intr_disestablish,
|
1997-10-17 03:23:14 +04:00
|
|
|
|
|
|
|
pcic_chip_socket_enable,
|
|
|
|
pcic_chip_socket_disable,
|
2004-08-11 04:18:18 +04:00
|
|
|
pcic_chip_socket_settype,
|
1997-10-17 03:23:14 +04:00
|
|
|
};
|
|
|
|
|
1998-12-20 20:53:28 +03:00
|
|
|
static void pcic_pci_callback(struct device *);
|
|
|
|
|
1997-10-17 03:23:14 +04:00
|
|
|
int
|
|
|
|
pcic_pci_match(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct pci_attach_args *pa = (struct pci_attach_args *) aux;
|
|
|
|
|
1998-12-20 20:53:28 +03:00
|
|
|
switch (PCI_VENDOR(pa->pa_id)) {
|
|
|
|
case PCI_VENDOR_CIRRUS:
|
|
|
|
switch(PCI_PRODUCT(pa->pa_id)) {
|
|
|
|
case PCI_PRODUCT_CIRRUS_CL_PD6729:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (0);
|
|
|
|
}
|
1997-10-17 03:23:14 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
void pcic_isa_config_interrupts(struct device *);
|
2000-02-02 01:39:51 +03:00
|
|
|
|
1997-10-17 03:23:14 +04:00
|
|
|
void
|
|
|
|
pcic_pci_attach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct pcic_softc *sc = (void *) self;
|
2000-02-22 19:04:44 +03:00
|
|
|
struct pcic_pci_softc *psc = (void *) self;
|
1997-10-17 03:23:14 +04:00
|
|
|
struct pci_attach_args *pa = aux;
|
|
|
|
pci_chipset_tag_t pc = pa->pa_pc;
|
|
|
|
bus_space_tag_t memt = pa->pa_memt;
|
|
|
|
bus_space_handle_t memh;
|
2005-05-30 08:35:22 +04:00
|
|
|
const char *model;
|
1997-10-17 03:23:14 +04:00
|
|
|
|
2003-01-31 03:07:39 +03:00
|
|
|
aprint_naive(": PCMCIA controller\n");
|
|
|
|
|
1997-10-17 03:23:14 +04:00
|
|
|
if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
|
|
|
|
&sc->iot, &sc->ioh, NULL, NULL)) {
|
2003-01-31 03:07:39 +03:00
|
|
|
aprint_error(": can't map i/o space\n");
|
1997-10-17 03:23:14 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX need some memory for mapping pcmcia cards into. Ideally, this
|
|
|
|
* would be completely dynamic. Practically this doesn't work,
|
|
|
|
* because the extent mapper doesn't know about all the devices all
|
|
|
|
* the time. With ISA we could finesse the issue by specifying the
|
|
|
|
* memory region in the config line. We can't do that here, so we
|
|
|
|
* cheat for now. Jason Thorpe, you are my Savior, come up with a fix
|
|
|
|
* :-)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Map mem space. */
|
|
|
|
if (bus_space_map(memt, 0xd0000, 0x4000, 0, &memh))
|
1998-12-17 20:45:08 +03:00
|
|
|
panic("pcic_pci_attach: can't map mem space");
|
1997-10-17 03:23:14 +04:00
|
|
|
|
|
|
|
sc->membase = 0xd0000;
|
|
|
|
sc->subregionmask = (1 << (0x4000 / PCIC_MEM_PAGESIZE)) - 1;
|
|
|
|
|
|
|
|
/* same deal for io allocation */
|
|
|
|
|
|
|
|
sc->iobase = 0x400;
|
|
|
|
sc->iosize = 0xbff;
|
|
|
|
|
|
|
|
/* end XXX */
|
|
|
|
|
|
|
|
sc->pct = (pcmcia_chipset_tag_t) & pcic_pci_functions;
|
|
|
|
|
|
|
|
sc->memt = memt;
|
|
|
|
sc->memh = memh;
|
|
|
|
|
|
|
|
switch (PCI_PRODUCT(pa->pa_id)) {
|
1998-11-30 22:47:16 +03:00
|
|
|
case PCI_PRODUCT_CIRRUS_CL_PD6729:
|
|
|
|
model = "Cirrus Logic PD6729 PCMCIA controller";
|
1997-10-17 03:23:14 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
model = "Model unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-01-31 03:07:39 +03:00
|
|
|
aprint_normal(": %s\n", model);
|
1997-10-17 03:23:14 +04:00
|
|
|
|
|
|
|
/* Enable the card. */
|
|
|
|
pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
|
|
|
|
pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
|
|
|
|
PCI_COMMAND_MASTER_ENABLE);
|
|
|
|
|
|
|
|
pcic_attach(sc);
|
|
|
|
|
1998-12-20 20:53:28 +03:00
|
|
|
/*
|
|
|
|
* Check to see if we're using PCI or ISA interrupts. I don't
|
|
|
|
* know of any i386 systems that use the 6729 in PCI interrupt
|
|
|
|
* mode, but maybe when the PCMCIA code runs on other platforms
|
|
|
|
* we'll need to fix this.
|
|
|
|
*/
|
|
|
|
pcic_write(&sc->handle[0], PCIC_CIRRUS_EXTENDED_INDEX,
|
|
|
|
PCIC_CIRRUS_EXT_CONTROL_1);
|
2000-02-02 01:39:51 +03:00
|
|
|
if ((pcic_read(&sc->handle[0], PCIC_CIRRUS_EXTENDED_DATA) &
|
|
|
|
PCIC_CIRRUS_EXT_CONTROL_1_PCI_INTR_MASK)) {
|
2003-01-31 03:07:39 +03:00
|
|
|
aprint_error("%s: PCI interrupts not supported\n",
|
1997-10-17 03:23:14 +04:00
|
|
|
sc->dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-02-22 19:04:44 +03:00
|
|
|
psc->intr_est = pcic_pci_machdep_intr_est(pc);
|
2000-02-02 01:39:51 +03:00
|
|
|
sc->irq = -1;
|
1997-10-17 03:23:14 +04:00
|
|
|
|
2000-02-02 01:39:51 +03:00
|
|
|
#if 0
|
1998-12-20 20:53:28 +03:00
|
|
|
/* Map and establish the interrupt. */
|
|
|
|
sc->ih = pcic_pci_machdep_pcic_intr_establish(sc, pcic_intr);
|
|
|
|
if (sc->ih == NULL) {
|
2003-01-31 03:07:39 +03:00
|
|
|
aprint_error("%s: couldn't map interrupt\n", sc->dev.dv_xname);
|
1998-12-20 20:53:28 +03:00
|
|
|
return;
|
|
|
|
}
|
2000-02-02 01:39:51 +03:00
|
|
|
#endif
|
|
|
|
|
1997-10-17 03:23:14 +04:00
|
|
|
/*
|
1998-12-20 20:53:28 +03:00
|
|
|
* Defer configuration of children until ISA has had its chance
|
|
|
|
* to use up whatever IO space and IRQs it wants. XXX This will
|
|
|
|
* only work if ISA is attached to a pcib, AND the PCI probe finds
|
|
|
|
* and defers the ISA attachment before this one.
|
1997-10-17 03:23:14 +04:00
|
|
|
*/
|
1998-12-20 20:53:28 +03:00
|
|
|
config_defer(self, pcic_pci_callback);
|
2000-02-02 01:39:51 +03:00
|
|
|
config_interrupts(self, pcic_isa_config_interrupts);
|
1997-10-17 03:23:14 +04:00
|
|
|
}
|
|
|
|
|
1998-12-20 20:53:28 +03:00
|
|
|
static void
|
|
|
|
pcic_pci_callback(self)
|
|
|
|
struct device *self;
|
1997-10-17 03:23:14 +04:00
|
|
|
{
|
1998-12-20 20:53:28 +03:00
|
|
|
struct pcic_softc *sc = (void *) self;
|
1997-10-17 03:23:14 +04:00
|
|
|
|
1998-12-20 20:53:28 +03:00
|
|
|
pcic_attach_sockets(sc);
|
1997-10-17 03:23:14 +04:00
|
|
|
}
|