diff options
author | Uwe Stuehler <uwe@cvs.openbsd.org> | 2006-05-28 17:21:15 +0000 |
---|---|---|
committer | Uwe Stuehler <uwe@cvs.openbsd.org> | 2006-05-28 17:21:15 +0000 |
commit | 90b89e27236906ec3f7f1897b01999737db91854 (patch) | |
tree | 72672d523f2651785d15b7f344b37e55cec46e6b /sys/dev/pci | |
parent | 5e4dc0921a9eff2e8cc4f3c24a54ddd30e6c1d4a (diff) |
Support for standard SD host controllers like the Ricoh 5C822, a small
generic bus layer, and SCSI emulation for SD/MMC memory cards.
Diffstat (limited to 'sys/dev/pci')
-rw-r--r-- | sys/dev/pci/files.pci | 6 | ||||
-rw-r--r-- | sys/dev/pci/pcireg.h | 3 | ||||
-rw-r--r-- | sys/dev/pci/sdhc_pci.c | 108 |
3 files changed, 115 insertions, 2 deletions
diff --git a/sys/dev/pci/files.pci b/sys/dev/pci/files.pci index 1f2b12c9682..2c8df1bd2f2 100644 --- a/sys/dev/pci/files.pci +++ b/sys/dev/pci/files.pci @@ -1,4 +1,4 @@ -# $OpenBSD: files.pci,v 1.206 2006/05/27 19:03:55 dlg Exp $ +# $OpenBSD: files.pci,v 1.207 2006/05/28 17:21:14 uwe Exp $ # $NetBSD: files.pci,v 1.20 1996/09/24 17:47:15 christos Exp $ # # Config file and device description for machine-independent PCI code. @@ -617,3 +617,7 @@ file dev/pci/amdiic.c amdiic device nviic: i2cbus attach nviic at pci file dev/pci/nviic.c nviic + +# SD Host Controller +attach sdhc at pci with sdhc_pci +file dev/pci/sdhc_pci.c sdhc diff --git a/sys/dev/pci/pcireg.h b/sys/dev/pci/pcireg.h index 534d833517f..893cbb7640b 100644 --- a/sys/dev/pci/pcireg.h +++ b/sys/dev/pci/pcireg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pcireg.h,v 1.29 2006/05/11 23:29:12 brad Exp $ */ +/* $OpenBSD: pcireg.h,v 1.30 2006/05/28 17:21:14 uwe Exp $ */ /* $NetBSD: pcireg.h,v 1.26 2000/05/10 16:58:42 thorpej Exp $ */ /* @@ -221,6 +221,7 @@ typedef u_int8_t pci_revision_t; #define PCI_SUBCLASS_SYSTEM_TIMER 0x02 #define PCI_SUBCLASS_SYSTEM_RTC 0x03 #define PCI_SUBCLASS_SYSTEM_PCIHOTPLUG 0x04 +#define PCI_SUBCLASS_SYSTEM_SDHC 0x05 #define PCI_SUBCLASS_SYSTEM_MISC 0x80 /* 0x09 input subclasses */ diff --git a/sys/dev/pci/sdhc_pci.c b/sys/dev/pci/sdhc_pci.c new file mode 100644 index 00000000000..d0857c38fc5 --- /dev/null +++ b/sys/dev/pci/sdhc_pci.c @@ -0,0 +1,108 @@ +/* $OpenBSD: sdhc_pci.c,v 1.1 2006/05/28 17:21:14 uwe Exp $ */ + +/* + * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/param.h> +#include <sys/device.h> +#include <sys/systm.h> + +#include <dev/pci/pcivar.h> +#include <dev/sdmmc/sdhcreg.h> +#include <dev/sdmmc/sdhcvar.h> +#include <dev/sdmmc/sdmmcvar.h> + +struct sdhc_pci_softc { + struct sdhc_softc sc; + void *sc_ih; +}; + +int sdhc_pci_match(struct device *, void *, void *); +void sdhc_pci_attach(struct device *, struct device *, void *); + +struct cfattach sdhc_pci_ca = { + sizeof(struct sdhc_pci_softc), sdhc_pci_match, sdhc_pci_attach +}; + +int +sdhc_pci_match(struct device *parent, void *match, void *aux) +{ + struct pci_attach_args *pa = aux; + + if (PCI_CLASS(pa->pa_class) == PCI_CLASS_SYSTEM && + PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_SYSTEM_SDHC) + return 1; + + return 0; +} + +void +sdhc_pci_attach(struct device *parent, struct device *self, void *aux) +{ + struct sdhc_pci_softc *sc = (struct sdhc_pci_softc *)self; + struct pci_attach_args *pa = aux; + pci_intr_handle_t ih; + char const *intrstr; + bus_space_tag_t iot; + bus_space_handle_t ioh; + bus_size_t size; + int usedma; + int reg; + + if (pci_intr_map(pa, &ih)) { + printf(": can't map interrupt\n"); + return; + } + + intrstr = pci_intr_string(pa->pa_pc, ih); + sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_SDMMC, + sdhc_intr, sc, sc->sc.sc_dev.dv_xname); + if (sc->sc_ih == NULL) { + printf(": can't establish interrupt\n"); + return; + } + printf(": %s\n", intrstr); + + /* Enable use of DMA if supported by the interface. */ + usedma = PCI_INTERFACE(pa->pa_class) == SDHC_PCI_INTERFACE_DMA; + + /* + * Map and attach all hosts supported by the host controller. + */ + for (reg = SDHC_PCI_BAR_START; reg < SDHC_PCI_BAR_END; reg += 4) { + + if (pci_mem_find(pa->pa_pc, pa->pa_tag, reg, + NULL, NULL, NULL) != 0) + continue; + + if (pci_mapreg_map(pa, reg, PCI_MAPREG_TYPE_MEM, 0, + &iot, &ioh, NULL, &size, 0)) { + printf("%s at 0x%x: can't map registers\n", + sc->sc.sc_dev.dv_xname, reg); + continue; + } + + if (sdhc_host_found(&sc->sc, iot, ioh, size, usedma) != 0) + printf("%s at 0x%x: can't initialize host\n", + sc->sc.sc_dev.dv_xname, reg); + } + + /* + * Establish power and shutdown hooks. + */ + (void)powerhook_establish(sdhc_power, &sc->sc); + (void)shutdownhook_establish(sdhc_shutdown, &sc->sc); +} |