Home | History | Annotate | Line # | Download | only in ic
pl181.c revision 1.3
      1  1.3  jmcneill /* $NetBSD: pl181.c,v 1.3 2017/06/02 11:01:15 jmcneill Exp $ */
      2  1.1  jmcneill 
      3  1.1  jmcneill /*-
      4  1.1  jmcneill  * Copyright (c) 2015 Jared D. McNeill <jmcneill (at) invisible.ca>
      5  1.1  jmcneill  * All rights reserved.
      6  1.1  jmcneill  *
      7  1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
      8  1.1  jmcneill  * modification, are permitted provided that the following conditions
      9  1.1  jmcneill  * are met:
     10  1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     11  1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     12  1.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     15  1.1  jmcneill  *
     16  1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.1  jmcneill  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  1.1  jmcneill  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  1.1  jmcneill  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  1.1  jmcneill  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  1.1  jmcneill  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22  1.1  jmcneill  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  1.1  jmcneill  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  1.1  jmcneill  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.1  jmcneill  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.1  jmcneill  * SUCH DAMAGE.
     27  1.1  jmcneill  */
     28  1.1  jmcneill 
     29  1.1  jmcneill #include <sys/cdefs.h>
     30  1.3  jmcneill __KERNEL_RCSID(0, "$NetBSD: pl181.c,v 1.3 2017/06/02 11:01:15 jmcneill Exp $");
     31  1.1  jmcneill 
     32  1.1  jmcneill #include <sys/param.h>
     33  1.1  jmcneill #include <sys/bus.h>
     34  1.1  jmcneill #include <sys/device.h>
     35  1.1  jmcneill #include <sys/intr.h>
     36  1.1  jmcneill #include <sys/systm.h>
     37  1.1  jmcneill #include <sys/kernel.h>
     38  1.1  jmcneill 
     39  1.1  jmcneill #include <dev/sdmmc/sdmmcvar.h>
     40  1.1  jmcneill #include <dev/sdmmc/sdmmcchip.h>
     41  1.1  jmcneill #include <dev/sdmmc/sdmmc_ioreg.h>
     42  1.1  jmcneill 
     43  1.1  jmcneill #include <dev/ic/pl181reg.h>
     44  1.1  jmcneill #include <dev/ic/pl181var.h>
     45  1.1  jmcneill 
     46  1.1  jmcneill static int	plmmc_host_reset(sdmmc_chipset_handle_t);
     47  1.1  jmcneill static uint32_t	plmmc_host_ocr(sdmmc_chipset_handle_t);
     48  1.1  jmcneill static int	plmmc_host_maxblklen(sdmmc_chipset_handle_t);
     49  1.1  jmcneill static int	plmmc_card_detect(sdmmc_chipset_handle_t);
     50  1.1  jmcneill static int	plmmc_write_protect(sdmmc_chipset_handle_t);
     51  1.1  jmcneill static int	plmmc_bus_power(sdmmc_chipset_handle_t, uint32_t);
     52  1.1  jmcneill static int	plmmc_bus_clock(sdmmc_chipset_handle_t, int);
     53  1.1  jmcneill static int	plmmc_bus_width(sdmmc_chipset_handle_t, int);
     54  1.1  jmcneill static int	plmmc_bus_rod(sdmmc_chipset_handle_t, int);
     55  1.1  jmcneill static void	plmmc_exec_command(sdmmc_chipset_handle_t,
     56  1.1  jmcneill 				     struct sdmmc_command *);
     57  1.1  jmcneill static void	plmmc_card_enable_intr(sdmmc_chipset_handle_t, int);
     58  1.1  jmcneill static void	plmmc_card_intr_ack(sdmmc_chipset_handle_t);
     59  1.1  jmcneill 
     60  1.1  jmcneill static int	plmmc_wait_status(struct plmmc_softc *, uint32_t, int);
     61  1.1  jmcneill static int	plmmc_pio_wait(struct plmmc_softc *,
     62  1.1  jmcneill 				 struct sdmmc_command *);
     63  1.1  jmcneill static int	plmmc_pio_transfer(struct plmmc_softc *,
     64  1.1  jmcneill 				     struct sdmmc_command *);
     65  1.1  jmcneill 
     66  1.1  jmcneill static struct sdmmc_chip_functions plmmc_chip_functions = {
     67  1.1  jmcneill 	.host_reset = plmmc_host_reset,
     68  1.1  jmcneill 	.host_ocr = plmmc_host_ocr,
     69  1.1  jmcneill 	.host_maxblklen = plmmc_host_maxblklen,
     70  1.1  jmcneill 	.card_detect = plmmc_card_detect,
     71  1.1  jmcneill 	.write_protect = plmmc_write_protect,
     72  1.1  jmcneill 	.bus_power = plmmc_bus_power,
     73  1.1  jmcneill 	.bus_clock = plmmc_bus_clock,
     74  1.1  jmcneill 	.bus_width = plmmc_bus_width,
     75  1.1  jmcneill 	.bus_rod = plmmc_bus_rod,
     76  1.1  jmcneill 	.exec_command = plmmc_exec_command,
     77  1.1  jmcneill 	.card_enable_intr = plmmc_card_enable_intr,
     78  1.1  jmcneill 	.card_intr_ack = plmmc_card_intr_ack,
     79  1.1  jmcneill };
     80  1.1  jmcneill 
     81  1.1  jmcneill #define MMCI_WRITE(sc, reg, val) \
     82  1.1  jmcneill 	bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
     83  1.1  jmcneill #define MMCI_READ(sc, reg) \
     84  1.1  jmcneill 	bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))
     85  1.1  jmcneill 
     86  1.1  jmcneill void
     87  1.1  jmcneill plmmc_init(struct plmmc_softc *sc)
     88  1.1  jmcneill {
     89  1.1  jmcneill 	struct sdmmcbus_attach_args saa;
     90  1.1  jmcneill 
     91  1.1  jmcneill 	mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_BIO);
     92  1.1  jmcneill 	cv_init(&sc->sc_intr_cv, "plmmcirq");
     93  1.1  jmcneill 
     94  1.1  jmcneill #ifdef PLMMC_DEBUG
     95  1.1  jmcneill 	device_printf(sc->sc_dev, "PeriphID %#x %#x %#x %#x\n",
     96  1.1  jmcneill 	    MMCI_READ(sc, MMCI_PERIPH_ID0_REG),
     97  1.1  jmcneill 	    MMCI_READ(sc, MMCI_PERIPH_ID1_REG),
     98  1.1  jmcneill 	    MMCI_READ(sc, MMCI_PERIPH_ID2_REG),
     99  1.1  jmcneill 	    MMCI_READ(sc, MMCI_PERIPH_ID3_REG));
    100  1.1  jmcneill 	device_printf(sc->sc_dev, "PCellID %#x %#x %#x %#x\n",
    101  1.1  jmcneill 	    MMCI_READ(sc, MMCI_PCELL_ID0_REG),
    102  1.1  jmcneill 	    MMCI_READ(sc, MMCI_PCELL_ID1_REG),
    103  1.1  jmcneill 	    MMCI_READ(sc, MMCI_PCELL_ID2_REG),
    104  1.1  jmcneill 	    MMCI_READ(sc, MMCI_PCELL_ID3_REG));
    105  1.1  jmcneill #endif
    106  1.1  jmcneill 
    107  1.1  jmcneill 	plmmc_bus_clock(sc, 400);
    108  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_POWER_REG, 0);
    109  1.1  jmcneill 	delay(10000);
    110  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_POWER_REG, MMCI_POWER_CTRL_POWERUP);
    111  1.1  jmcneill 	delay(10000);
    112  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_POWER_REG, MMCI_POWER_CTRL_POWERON);
    113  1.1  jmcneill 	plmmc_host_reset(sc);
    114  1.1  jmcneill 
    115  1.1  jmcneill 	memset(&saa, 0, sizeof(saa));
    116  1.1  jmcneill 	saa.saa_busname = "sdmmc";
    117  1.1  jmcneill 	saa.saa_sct = &plmmc_chip_functions;
    118  1.1  jmcneill 	saa.saa_sch = sc;
    119  1.1  jmcneill 	saa.saa_clkmin = 400;
    120  1.3  jmcneill 	saa.saa_clkmax = sc->sc_max_freq > 0 ?
    121  1.3  jmcneill 	    sc->sc_max_freq / 1000 : sc->sc_clock_freq / 1000;
    122  1.2  jmcneill 	saa.saa_caps = SMC_CAPS_4BIT_MODE | SMC_CAPS_SINGLE_ONLY;
    123  1.1  jmcneill 
    124  1.1  jmcneill 	sc->sc_sdmmc_dev = config_found(sc->sc_dev, &saa, NULL);
    125  1.1  jmcneill }
    126  1.1  jmcneill 
    127  1.1  jmcneill int
    128  1.1  jmcneill plmmc_intr(void *priv)
    129  1.1  jmcneill {
    130  1.1  jmcneill 	struct plmmc_softc *sc = priv;
    131  1.1  jmcneill 	uint32_t status;
    132  1.1  jmcneill 
    133  1.1  jmcneill 	mutex_enter(&sc->sc_intr_lock);
    134  1.1  jmcneill 	status = MMCI_READ(sc, MMCI_STATUS_REG);
    135  1.1  jmcneill #ifdef PLMMC_DEBUG
    136  1.1  jmcneill 	printf("%s: MMCI_STATUS_REG = %#x\n", __func__, status);
    137  1.1  jmcneill #endif
    138  1.1  jmcneill 	if (!status) {
    139  1.1  jmcneill 		mutex_exit(&sc->sc_intr_lock);
    140  1.1  jmcneill 		return 0;
    141  1.1  jmcneill 	}
    142  1.1  jmcneill 
    143  1.1  jmcneill 	sc->sc_intr_status |= status;
    144  1.1  jmcneill 	cv_broadcast(&sc->sc_intr_cv);
    145  1.1  jmcneill 
    146  1.1  jmcneill 	mutex_exit(&sc->sc_intr_lock);
    147  1.1  jmcneill 
    148  1.1  jmcneill 	return 1;
    149  1.1  jmcneill }
    150  1.1  jmcneill 
    151  1.1  jmcneill static int
    152  1.1  jmcneill plmmc_wait_status(struct plmmc_softc *sc, uint32_t mask, int timeout)
    153  1.1  jmcneill {
    154  1.1  jmcneill 	int retry, error;
    155  1.1  jmcneill 
    156  1.1  jmcneill 	KASSERT(mutex_owned(&sc->sc_intr_lock));
    157  1.1  jmcneill 
    158  1.1  jmcneill 	if (sc->sc_intr_status & mask)
    159  1.1  jmcneill 		return 0;
    160  1.1  jmcneill 
    161  1.1  jmcneill 	retry = timeout / hz;
    162  1.1  jmcneill 	if (sc->sc_ih == NULL)
    163  1.1  jmcneill 		retry *= 1000;
    164  1.1  jmcneill 
    165  1.1  jmcneill 	while (retry > 0) {
    166  1.1  jmcneill 		if (sc->sc_ih == NULL) {
    167  1.1  jmcneill 			sc->sc_intr_status |= MMCI_READ(sc, MMCI_STATUS_REG);
    168  1.1  jmcneill 			if (sc->sc_intr_status & mask)
    169  1.1  jmcneill 				return 0;
    170  1.1  jmcneill 			delay(10000);
    171  1.1  jmcneill 		} else {
    172  1.1  jmcneill 			error = cv_timedwait(&sc->sc_intr_cv,
    173  1.1  jmcneill 			    &sc->sc_intr_lock, hz);
    174  1.1  jmcneill 			if (error && error != EWOULDBLOCK) {
    175  1.1  jmcneill 				device_printf(sc->sc_dev,
    176  1.1  jmcneill 				    "cv_timedwait returned %d\n", error);
    177  1.1  jmcneill 				return error;
    178  1.1  jmcneill 			}
    179  1.1  jmcneill 			if (sc->sc_intr_status & mask)
    180  1.1  jmcneill 				return 0;
    181  1.1  jmcneill 		}
    182  1.1  jmcneill 		--retry;
    183  1.1  jmcneill 	}
    184  1.1  jmcneill 
    185  1.1  jmcneill 	device_printf(sc->sc_dev, "%s timeout, MMCI_STATUS_REG = %#x\n",
    186  1.1  jmcneill 	    __func__, MMCI_READ(sc, MMCI_STATUS_REG));
    187  1.1  jmcneill 
    188  1.1  jmcneill 	return ETIMEDOUT;
    189  1.1  jmcneill }
    190  1.1  jmcneill 
    191  1.1  jmcneill static int
    192  1.1  jmcneill plmmc_pio_wait(struct plmmc_softc *sc, struct sdmmc_command *cmd)
    193  1.1  jmcneill {
    194  1.1  jmcneill 	uint32_t bit = (cmd->c_flags & SCF_CMD_READ) ?
    195  1.1  jmcneill 	    MMCI_INT_RX_DATA_AVAIL : MMCI_INT_TX_FIFO_EMPTY;
    196  1.1  jmcneill 
    197  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_CLEAR_REG, bit);
    198  1.1  jmcneill 	const int error = plmmc_wait_status(sc,
    199  1.1  jmcneill 		bit | MMCI_INT_DATA_END | MMCI_INT_DATA_BLOCK_END, hz*2);
    200  1.1  jmcneill 	sc->sc_intr_status &= ~bit;
    201  1.1  jmcneill 
    202  1.1  jmcneill 	return error;
    203  1.1  jmcneill }
    204  1.1  jmcneill 
    205  1.1  jmcneill static int
    206  1.1  jmcneill plmmc_pio_transfer(struct plmmc_softc *sc, struct sdmmc_command *cmd)
    207  1.1  jmcneill {
    208  1.1  jmcneill 	uint32_t *datap = (uint32_t *)cmd->c_data;
    209  1.1  jmcneill 	int i;
    210  1.1  jmcneill 
    211  1.1  jmcneill 	cmd->c_resid = cmd->c_datalen;
    212  1.1  jmcneill 	for (i = 0; i < (cmd->c_datalen >> 2); i++) {
    213  1.1  jmcneill 		if (plmmc_pio_wait(sc, cmd))
    214  1.1  jmcneill 			return ETIMEDOUT;
    215  1.1  jmcneill 		if (cmd->c_flags & SCF_CMD_READ) {
    216  1.1  jmcneill 			datap[i] = MMCI_READ(sc, MMCI_FIFO_REG);
    217  1.1  jmcneill 		} else {
    218  1.1  jmcneill 			MMCI_WRITE(sc, MMCI_FIFO_REG, datap[i]);
    219  1.1  jmcneill 		}
    220  1.1  jmcneill 		cmd->c_resid -= 4;
    221  1.1  jmcneill 	}
    222  1.1  jmcneill 
    223  1.1  jmcneill 	return 0;
    224  1.1  jmcneill }
    225  1.1  jmcneill 
    226  1.1  jmcneill static int
    227  1.1  jmcneill plmmc_host_reset(sdmmc_chipset_handle_t sch)
    228  1.1  jmcneill {
    229  1.1  jmcneill 	struct plmmc_softc *sc = sch;
    230  1.1  jmcneill 
    231  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_MASK0_REG, 0);
    232  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_MASK1_REG, 0);
    233  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_CLEAR_REG, 0xffffffff);
    234  1.1  jmcneill 
    235  1.1  jmcneill 	return 0;
    236  1.1  jmcneill }
    237  1.1  jmcneill 
    238  1.1  jmcneill static uint32_t
    239  1.1  jmcneill plmmc_host_ocr(sdmmc_chipset_handle_t sch)
    240  1.1  jmcneill {
    241  1.1  jmcneill 	return MMC_OCR_3_2V_3_3V | MMC_OCR_3_3V_3_4V;
    242  1.1  jmcneill }
    243  1.1  jmcneill 
    244  1.1  jmcneill static int
    245  1.1  jmcneill plmmc_host_maxblklen(sdmmc_chipset_handle_t sch)
    246  1.1  jmcneill {
    247  1.1  jmcneill 	return 2048;
    248  1.1  jmcneill }
    249  1.1  jmcneill 
    250  1.1  jmcneill static int
    251  1.1  jmcneill plmmc_card_detect(sdmmc_chipset_handle_t sch)
    252  1.1  jmcneill {
    253  1.1  jmcneill 	return 1;
    254  1.1  jmcneill }
    255  1.1  jmcneill 
    256  1.1  jmcneill static int
    257  1.1  jmcneill plmmc_write_protect(sdmmc_chipset_handle_t sch)
    258  1.1  jmcneill {
    259  1.1  jmcneill 	return 0;
    260  1.1  jmcneill }
    261  1.1  jmcneill 
    262  1.1  jmcneill static int
    263  1.1  jmcneill plmmc_bus_power(sdmmc_chipset_handle_t sch, uint32_t ocr)
    264  1.1  jmcneill {
    265  1.1  jmcneill 	return 0;
    266  1.1  jmcneill }
    267  1.1  jmcneill 
    268  1.1  jmcneill static int
    269  1.1  jmcneill plmmc_bus_clock(sdmmc_chipset_handle_t sch, int freq)
    270  1.1  jmcneill {
    271  1.1  jmcneill 	struct plmmc_softc *sc = sch;
    272  1.1  jmcneill 	u_int pll_freq, clk_div;
    273  1.1  jmcneill 	uint32_t clock;
    274  1.1  jmcneill 
    275  1.1  jmcneill 	clock = MMCI_CLOCK_PWRSAVE;
    276  1.1  jmcneill 	if (freq) {
    277  1.1  jmcneill 		pll_freq = sc->sc_clock_freq / 1000;
    278  1.1  jmcneill 		clk_div = (howmany(pll_freq, freq) >> 1) - 1;
    279  1.1  jmcneill 		clock |= __SHIFTIN(clk_div, MMCI_CLOCK_CLKDIV);
    280  1.1  jmcneill 		clock |= MMCI_CLOCK_ENABLE;
    281  1.1  jmcneill 	}
    282  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_CLOCK_REG, clock);
    283  1.1  jmcneill 
    284  1.1  jmcneill 	return 0;
    285  1.1  jmcneill }
    286  1.1  jmcneill 
    287  1.1  jmcneill static int
    288  1.1  jmcneill plmmc_bus_width(sdmmc_chipset_handle_t sch, int width)
    289  1.1  jmcneill {
    290  1.1  jmcneill 	return 0;
    291  1.1  jmcneill }
    292  1.1  jmcneill 
    293  1.1  jmcneill static int
    294  1.1  jmcneill plmmc_bus_rod(sdmmc_chipset_handle_t sch, int on)
    295  1.1  jmcneill {
    296  1.1  jmcneill 	struct plmmc_softc *sc = sch;
    297  1.1  jmcneill 	uint32_t power;
    298  1.1  jmcneill 
    299  1.1  jmcneill 
    300  1.1  jmcneill 	power = MMCI_READ(sc, MMCI_POWER_REG);
    301  1.1  jmcneill 	if (on) {
    302  1.1  jmcneill 		power |= MMCI_POWER_ROD;
    303  1.1  jmcneill 	} else {
    304  1.1  jmcneill 		power &= ~MMCI_POWER_ROD;
    305  1.1  jmcneill 	}
    306  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_POWER_REG, power);
    307  1.1  jmcneill 
    308  1.1  jmcneill 	return 0;
    309  1.1  jmcneill }
    310  1.1  jmcneill 
    311  1.1  jmcneill static void
    312  1.1  jmcneill plmmc_exec_command(sdmmc_chipset_handle_t sch, struct sdmmc_command *cmd)
    313  1.1  jmcneill {
    314  1.1  jmcneill 	struct plmmc_softc *sc = sch;
    315  1.1  jmcneill 	uint32_t cmdval = MMCI_COMMAND_ENABLE;
    316  1.1  jmcneill 
    317  1.1  jmcneill #ifdef PLMMC_DEBUG
    318  1.1  jmcneill 	device_printf(sc->sc_dev, "opcode %d flags %#x datalen %d\n",
    319  1.1  jmcneill 	    cmd->c_opcode, cmd->c_flags, cmd->c_datalen);
    320  1.1  jmcneill #endif
    321  1.1  jmcneill 
    322  1.1  jmcneill 	mutex_enter(&sc->sc_intr_lock);
    323  1.1  jmcneill 
    324  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_COMMAND_REG, 0);
    325  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_MASK0_REG, 0);
    326  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_CLEAR_REG, 0xffffffff);
    327  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_MASK0_REG,
    328  1.1  jmcneill 	    MMCI_INT_CMD_TIMEOUT | MMCI_INT_DATA_TIMEOUT |
    329  1.1  jmcneill 	    MMCI_INT_RX_DATA_AVAIL | MMCI_INT_TX_FIFO_EMPTY |
    330  1.1  jmcneill 	    MMCI_INT_DATA_END | MMCI_INT_DATA_BLOCK_END |
    331  1.1  jmcneill 	    MMCI_INT_CMD_RESP_END | MMCI_INT_CMD_SENT);
    332  1.1  jmcneill 
    333  1.1  jmcneill 	sc->sc_intr_status = 0;
    334  1.1  jmcneill 
    335  1.1  jmcneill 	if (cmd->c_flags & SCF_RSP_PRESENT)
    336  1.1  jmcneill 		cmdval |= MMCI_COMMAND_RESPONSE;
    337  1.1  jmcneill 	if (cmd->c_flags & SCF_RSP_136)
    338  1.1  jmcneill 		cmdval |= MMCI_COMMAND_LONGRSP;
    339  1.1  jmcneill 
    340  1.1  jmcneill 	if (cmd->c_datalen > 0) {
    341  1.1  jmcneill 		unsigned int nblks = cmd->c_datalen / cmd->c_blklen;
    342  1.1  jmcneill 		if (nblks == 0 || (cmd->c_datalen % cmd->c_blklen) != 0)
    343  1.1  jmcneill 			++nblks;
    344  1.1  jmcneill 
    345  1.1  jmcneill 		const uint32_t dir = (cmd->c_flags & SCF_CMD_READ) ? 1 : 0;
    346  1.1  jmcneill 		const uint32_t blksize = ffs(cmd->c_blklen) - 1;
    347  1.1  jmcneill 
    348  1.1  jmcneill 		MMCI_WRITE(sc, MMCI_DATA_TIMER_REG, 0xffffffff);
    349  1.1  jmcneill 		MMCI_WRITE(sc, MMCI_DATA_LENGTH_REG, nblks * cmd->c_blklen);
    350  1.1  jmcneill 		MMCI_WRITE(sc, MMCI_DATA_CTRL_REG,
    351  1.1  jmcneill 		    __SHIFTIN(dir, MMCI_DATA_CTRL_DIRECTION) |
    352  1.1  jmcneill 		    __SHIFTIN(blksize, MMCI_DATA_CTRL_BLOCKSIZE) |
    353  1.1  jmcneill 		    MMCI_DATA_CTRL_ENABLE);
    354  1.1  jmcneill 	}
    355  1.1  jmcneill 
    356  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_ARGUMENT_REG, cmd->c_arg);
    357  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_COMMAND_REG, cmdval | cmd->c_opcode);
    358  1.1  jmcneill 
    359  1.1  jmcneill 	if (cmd->c_datalen > 0) {
    360  1.1  jmcneill 		cmd->c_error = plmmc_pio_transfer(sc, cmd);
    361  1.1  jmcneill 		if (cmd->c_error) {
    362  1.1  jmcneill 			device_printf(sc->sc_dev,
    363  1.1  jmcneill 			    "error (%d) waiting for xfer\n", cmd->c_error);
    364  1.1  jmcneill 			goto done;
    365  1.1  jmcneill 		}
    366  1.1  jmcneill 	}
    367  1.1  jmcneill 
    368  1.1  jmcneill 	if (cmd->c_flags & SCF_RSP_PRESENT) {
    369  1.1  jmcneill 		cmd->c_error = plmmc_wait_status(sc,
    370  1.1  jmcneill 		    MMCI_INT_CMD_RESP_END|MMCI_INT_CMD_TIMEOUT, hz * 2);
    371  1.1  jmcneill 		if (cmd->c_error == 0 &&
    372  1.1  jmcneill 		    (sc->sc_intr_status & MMCI_INT_CMD_TIMEOUT)) {
    373  1.1  jmcneill 			cmd->c_error = ETIMEDOUT;
    374  1.1  jmcneill 		}
    375  1.1  jmcneill 		if (cmd->c_error) {
    376  1.1  jmcneill #ifdef PLMMC_DEBUG
    377  1.1  jmcneill 			device_printf(sc->sc_dev,
    378  1.1  jmcneill 			    "error (%d) waiting for resp\n", cmd->c_error);
    379  1.1  jmcneill #endif
    380  1.1  jmcneill 			goto done;
    381  1.1  jmcneill 		}
    382  1.1  jmcneill 
    383  1.1  jmcneill 		if (cmd->c_flags & SCF_RSP_136) {
    384  1.1  jmcneill 			cmd->c_resp[3] = MMCI_READ(sc, MMCI_RESP0_REG);
    385  1.1  jmcneill 			cmd->c_resp[2] = MMCI_READ(sc, MMCI_RESP1_REG);
    386  1.1  jmcneill 			cmd->c_resp[1] = MMCI_READ(sc, MMCI_RESP2_REG);
    387  1.1  jmcneill 			cmd->c_resp[0] = MMCI_READ(sc, MMCI_RESP3_REG);
    388  1.1  jmcneill 			if (cmd->c_flags & SCF_RSP_CRC) {
    389  1.1  jmcneill 				cmd->c_resp[0] = (cmd->c_resp[0] >> 8) |
    390  1.1  jmcneill 				    (cmd->c_resp[1] << 24);
    391  1.1  jmcneill 				cmd->c_resp[1] = (cmd->c_resp[1] >> 8) |
    392  1.1  jmcneill 				    (cmd->c_resp[2] << 24);
    393  1.1  jmcneill 				cmd->c_resp[2] = (cmd->c_resp[2] >> 8) |
    394  1.1  jmcneill 				    (cmd->c_resp[3] << 24);
    395  1.1  jmcneill 				cmd->c_resp[3] = (cmd->c_resp[3] >> 8);
    396  1.1  jmcneill 			}
    397  1.1  jmcneill 		} else {
    398  1.1  jmcneill 			cmd->c_resp[0] = MMCI_READ(sc, MMCI_RESP0_REG);
    399  1.1  jmcneill 		}
    400  1.1  jmcneill 	}
    401  1.1  jmcneill 
    402  1.1  jmcneill done:
    403  1.1  jmcneill 	cmd->c_flags |= SCF_ITSDONE;
    404  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_COMMAND_REG, 0);
    405  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_MASK0_REG, 0);
    406  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_CLEAR_REG, 0xffffffff);
    407  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_DATA_CNT_REG, 0);
    408  1.1  jmcneill 
    409  1.1  jmcneill #ifdef PLMMC_DEBUG
    410  1.1  jmcneill 	device_printf(sc->sc_dev, "MMCI_STATUS_REG = %#x\n",
    411  1.1  jmcneill 	    MMCI_READ(sc, MMCI_STATUS_REG));
    412  1.1  jmcneill #endif
    413  1.1  jmcneill 	mutex_exit(&sc->sc_intr_lock);
    414  1.1  jmcneill }
    415  1.1  jmcneill 
    416  1.1  jmcneill static void
    417  1.1  jmcneill plmmc_card_enable_intr(sdmmc_chipset_handle_t sch, int enable)
    418  1.1  jmcneill {
    419  1.1  jmcneill }
    420  1.1  jmcneill 
    421  1.1  jmcneill static void
    422  1.1  jmcneill plmmc_card_intr_ack(sdmmc_chipset_handle_t sch)
    423  1.1  jmcneill {
    424  1.1  jmcneill }
    425