From 7e8a14e799fba2fd8dc41f5229d529ba8436f352 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 14 Aug 2009 03:34:26 +0200 Subject: [PATCH 02/10] PXAMCI fix --- sys/arch/arm/xscale/pxa2x0_mmc.c | 8 ++-- sys/arch/arm/xscale/pxammcvar.h | 1 + sys/arch/palm/conf/RAMDISK | 6 +- sys/arch/palm/conf/files.palm | 4 ++ sys/arch/palm/dev/palm_mmc.c | 82 +++++++++++++++++++++++++++++++++ sys/arch/palm/include/machine_reg.h | 4 ++ sys/arch/zaurus/dev/scoop_mmc.c | 2 + sys/arch/zaurus/include/machine_reg.h | 1 + 8 files changed, 101 insertions(+), 7 deletions(-) create mode 100644 sys/arch/palm/dev/palm_mmc.c diff --git a/sys/arch/arm/xscale/pxa2x0_mmc.c b/sys/arch/arm/xscale/pxa2x0_mmc.c index bd638a8..554b146 100644 --- a/sys/arch/arm/xscale/pxa2x0_mmc.c +++ b/sys/arch/arm/xscale/pxa2x0_mmc.c @@ -44,7 +44,6 @@ #include /* GPIO pins */ -#define PXAMMC_CARD_DETECT 9 /* XXX zaurus-specific */ #define PXAMMC_MMCLK 32 #define PXAMMC_MMCMD 112 #define PXAMMC_MMDAT0 92 @@ -135,8 +134,8 @@ pxammc_attach(struct pxammc_softc *sc, void *aux) */ s = splsdmmc(); - pxa2x0_gpio_set_function(PXAMMC_CARD_DETECT, GPIO_IN); - sc->sc_card_ih = pxa2x0_gpio_intr_establish(PXAMMC_CARD_DETECT, + pxa2x0_gpio_set_function(sc->sc_gpio_detect, GPIO_IN); + sc->sc_card_ih = pxa2x0_gpio_intr_establish(sc->sc_gpio_detect, IST_EDGE_BOTH, IPL_SDMMC, pxammc_card_intr, sc, "mmccd"); if (sc->sc_card_ih == NULL) { splx(s); @@ -255,7 +254,8 @@ pxammc_host_ocr(sdmmc_chipset_handle_t sch) int pxammc_card_detect(sdmmc_chipset_handle_t sch) { - return !pxa2x0_gpio_get_bit(PXAMMC_CARD_DETECT); + struct pxammc_softc *sc = sch; + return !pxa2x0_gpio_get_bit(sc->sc_gpio_detect); } int diff --git a/sys/arch/arm/xscale/pxammcvar.h b/sys/arch/arm/xscale/pxammcvar.h index 6877127..a568d94 100644 --- a/sys/arch/arm/xscale/pxammcvar.h +++ b/sys/arch/arm/xscale/pxammcvar.h @@ -36,6 +36,7 @@ struct pxammc_softc { #define PMF_CARD_INITED 0x0001 /* card init sequence sent */ int sc_clkdiv; /* current clock divider */ struct sdmmc_command * volatile sc_cmd; /* command in progress */ + int sc_gpio_detect; /* card detect GPIO */ }; int pxammc_match(void); diff --git a/sys/arch/palm/conf/RAMDISK b/sys/arch/palm/conf/RAMDISK index 1b63e50..86d39fb 100644 --- a/sys/arch/palm/conf/RAMDISK +++ b/sys/arch/palm/conf/RAMDISK @@ -89,9 +89,9 @@ pxaost0 at pxaip? addr 0x40a00000 size 0x20 #scsibus* at umass? # SD/MMC support -#pxammc0 at pxaip? # MMC/SD/SDIO controller -#sdmmc* at pxammc? # SD/MMC bus -#scsibus* at sdmmc? # SCSI emulation +pxammc0 at pxaip? # MMC/SD/SDIO controller +sdmmc* at pxammc? # SD/MMC bus +scsibus* at sdmmc? # SCSI emulation softraid0 at root # Software RAID scsibus* at softraid? diff --git a/sys/arch/palm/conf/files.palm b/sys/arch/palm/conf/files.palm index 33910cb..fbdf8ab 100644 --- a/sys/arch/palm/conf/files.palm +++ b/sys/arch/palm/conf/files.palm @@ -28,6 +28,10 @@ include "arch/arm/xscale/files.pxa2x0" attach lcd at pxaip with lcd_pxaip file arch/palm/palm/palm_lcd.c lcd_pxaip +# SD/MMC socket controller +attach pxammc at pxaip with pxammc_palm +file arch/palm/dev/palm_mmc.c pxammc_palm + # # Machine-independent ATA drivers # diff --git a/sys/arch/palm/dev/palm_mmc.c b/sys/arch/palm/dev/palm_mmc.c new file mode 100644 index 0000000..b2e154c --- /dev/null +++ b/sys/arch/palm/dev/palm_mmc.c @@ -0,0 +1,82 @@ +/* $OpenBSD: scoop_mmc.c,v 1.1 2007/03/18 20:53:10 uwe Exp $ */ + +/* + * Copyright (c) 2007 Uwe Stuehler + * + * 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. + */ + +/* Attachment driver for pxammc(4) on Palm */ + +#include +#include +#include + +#include +#include +#include + +#include + +int palm_mmc_match(struct device *, void *, void *); +void palm_mmc_attach(struct device *, struct device *, void *); + +struct cfattach pxammc_palm_ca = { + sizeof(struct pxammc_softc), + palm_mmc_match, + palm_mmc_attach +}; + +u_int32_t palm_mmc_get_ocr(void *); +int palm_mmc_set_power(void *, u_int32_t); + +int +palm_mmc_match(struct device *parent, void *match, void *aux) +{ + return pxammc_match(); +} + +void +palm_mmc_attach(struct device *parent, struct device *self, void *aux) +{ + struct pxammc_softc *sc = (struct pxammc_softc *)self; + + sc->tag.cookie = (void *)sc; + sc->tag.get_ocr = palm_mmc_get_ocr; + sc->tag.set_power = palm_mmc_set_power; + + sc->sc_gpio_detect = GPIO14_MMC_DETECT; + + pxammc_attach(sc, aux); +} + +u_int32_t +palm_mmc_get_ocr(void *cookie) +{ + return MMC_OCR_3_2V_3_3V | MMC_OCR_3_3V_3_4V; +} + +int +palm_mmc_set_power(void *cookie, u_int32_t ocr) +{ + if (ISSET(ocr, MMC_OCR_3_2V_3_3V | MMC_OCR_3_3V_3_4V)) { + pxa2x0_gpio_set_bit(GPIO114_MMC_POWER); + return 0; + } else if (ocr != 0) { + printf("palm_mmc_set_power: unsupported OCR (%#x)\n", ocr); + return EINVAL; + } else { + pxa2x0_gpio_clear_bit(GPIO114_MMC_POWER); + return 0; + } +} diff --git a/sys/arch/palm/include/machine_reg.h b/sys/arch/palm/include/machine_reg.h index 8809dc5..d3ac604 100644 --- a/sys/arch/palm/include/machine_reg.h +++ b/sys/arch/palm/include/machine_reg.h @@ -55,4 +55,8 @@ #define ioreg8_read(a) (*(volatile uint8_t *)(a)) #define ioreg8_write(a,v) (*(volatile uint8_t *)(a)=(v)) +/* GPIOs */ +#define GPIO14_MMC_DETECT 14 /* MMC detect*/ +#define GPIO114_MMC_POWER 114 /* MMC power */ + #endif /* _PALM_REG_H */ diff --git a/sys/arch/zaurus/dev/scoop_mmc.c b/sys/arch/zaurus/dev/scoop_mmc.c index 8bb9977..a15c01f 100644 --- a/sys/arch/zaurus/dev/scoop_mmc.c +++ b/sys/arch/zaurus/dev/scoop_mmc.c @@ -53,6 +53,8 @@ scoop_mmc_attach(struct device *parent, struct device *self, void *aux) sc->tag.get_ocr = scoop_mmc_get_ocr; sc->tag.set_power = scoop_mmc_set_power; + sc->sc_gpio_detect = GPIO9_MMC_DETECT; + pxammc_attach(sc, aux); } diff --git a/sys/arch/zaurus/include/machine_reg.h b/sys/arch/zaurus/include/machine_reg.h index 707501e..a528edd 100644 --- a/sys/arch/zaurus/include/machine_reg.h +++ b/sys/arch/zaurus/include/machine_reg.h @@ -79,5 +79,6 @@ #define PXA_USB_CONNECT_PIN 41 /* connection interrupt */ #define PXA_USB_PULLUP_PIN 45 /* show/hide device presence */ #define GPIO_HP_IN_C3000 116 /* headphone jack */ +#define GPIO9_MMC_DETECT 9 /* card detect */ #endif /* _ZAURUS_REG_H */ -- 1.6.3.4