Home | History | Annotate | Line # | Download | only in ic
pl181.c revision 1.1
      1  1.1  jmcneill /* $NetBSD: pl181.c,v 1.1 2015/01/27 16:33:26 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.1  jmcneill __KERNEL_RCSID(0, "$NetBSD: pl181.c,v 1.1 2015/01/27 16:33:26 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.1  jmcneill 	saa.saa_clkmax = sc->sc_clock_freq / 1000;
    121  1.1  jmcneill 	saa.saa_caps = 0;
    122  1.1  jmcneill 
    123  1.1  jmcneill 	sc->sc_sdmmc_dev = config_found(sc->sc_dev, &saa, NULL);
    124  1.1  jmcneill }
    125  1.1  jmcneill 
    126  1.1  jmcneill int
    127  1.1  jmcneill plmmc_intr(void *priv)
    128  1.1  jmcneill {
    129  1.1  jmcneill 	struct plmmc_softc *sc = priv;
    130  1.1  jmcneill 	uint32_t status;
    131  1.1  jmcneill 
    132  1.1  jmcneill 	mutex_enter(&sc->sc_intr_lock);
    133  1.1  jmcneill 	status = MMCI_READ(sc, MMCI_STATUS_REG);
    134  1.1  jmcneill #ifdef PLMMC_DEBUG
    135  1.1  jmcneill 	printf("%s: MMCI_STATUS_REG = %#x\n", __func__, status);
    136  1.1  jmcneill #endif
    137  1.1  jmcneill 	if (!status) {
    138  1.1  jmcneill 		mutex_exit(&sc->sc_intr_lock);
    139  1.1  jmcneill 		return 0;
    140  1.1  jmcneill 	}
    141  1.1  jmcneill 
    142  1.1  jmcneill 	sc->sc_intr_status |= status;
    143  1.1  jmcneill 	cv_broadcast(&sc->sc_intr_cv);
    144  1.1  jmcneill 
    145  1.1  jmcneill 	mutex_exit(&sc->sc_intr_lock);
    146  1.1  jmcneill 
    147  1.1  jmcneill 	return 1;
    148  1.1  jmcneill }
    149  1.1  jmcneill 
    150  1.1  jmcneill static int
    151  1.1  jmcneill plmmc_wait_status(struct plmmc_softc *sc, uint32_t mask, int timeout)
    152  1.1  jmcneill {
    153  1.1  jmcneill 	int retry, error;
    154  1.1  jmcneill 
    155  1.1  jmcneill 	KASSERT(mutex_owned(&sc->sc_intr_lock));
    156  1.1  jmcneill 
    157  1.1  jmcneill 	if (sc->sc_intr_status & mask)
    158  1.1  jmcneill 		return 0;
    159  1.1  jmcneill 
    160  1.1  jmcneill 	retry = timeout / hz;
    161  1.1  jmcneill 	if (sc->sc_ih == NULL)
    162  1.1  jmcneill 		retry *= 1000;
    163  1.1  jmcneill 
    164  1.1  jmcneill 	while (retry > 0) {
    165  1.1  jmcneill 		if (sc->sc_ih == NULL) {
    166  1.1  jmcneill 			sc->sc_intr_status |= MMCI_READ(sc, MMCI_STATUS_REG);
    167  1.1  jmcneill 			if (sc->sc_intr_status & mask)
    168  1.1  jmcneill 				return 0;
    169  1.1  jmcneill 			delay(10000);
    170  1.1  jmcneill 		} else {
    171  1.1  jmcneill 			error = cv_timedwait(&sc->sc_intr_cv,
    172  1.1  jmcneill 			    &sc->sc_intr_lock, hz);
    173  1.1  jmcneill 			if (error && error != EWOULDBLOCK) {
    174  1.1  jmcneill 				device_printf(sc->sc_dev,
    175  1.1  jmcneill 				    "cv_timedwait returned %d\n", error);
    176  1.1  jmcneill 				return error;
    177  1.1  jmcneill 			}
    178  1.1  jmcneill 			if (sc->sc_intr_status & mask)
    179  1.1  jmcneill 				return 0;
    180  1.1  jmcneill 		}
    181  1.1  jmcneill 		--retry;
    182  1.1  jmcneill 	}
    183  1.1  jmcneill 
    184  1.1  jmcneill 	device_printf(sc->sc_dev, "%s timeout, MMCI_STATUS_REG = %#x\n",
    185  1.1  jmcneill 	    __func__, MMCI_READ(sc, MMCI_STATUS_REG));
    186  1.1  jmcneill 
    187  1.1  jmcneill 	return ETIMEDOUT;
    188  1.1  jmcneill }
    189  1.1  jmcneill 
    190  1.1  jmcneill static int
    191  1.1  jmcneill plmmc_pio_wait(struct plmmc_softc *sc, struct sdmmc_command *cmd)
    192  1.1  jmcneill {
    193  1.1  jmcneill 	uint32_t bit = (cmd->c_flags & SCF_CMD_READ) ?
    194  1.1  jmcneill 	    MMCI_INT_RX_DATA_AVAIL : MMCI_INT_TX_FIFO_EMPTY;
    195  1.1  jmcneill 
    196  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_CLEAR_REG, bit);
    197  1.1  jmcneill 	const int error = plmmc_wait_status(sc,
    198  1.1  jmcneill 		bit | MMCI_INT_DATA_END | MMCI_INT_DATA_BLOCK_END, hz*2);
    199  1.1  jmcneill 	sc->sc_intr_status &= ~bit;
    200  1.1  jmcneill 
    201  1.1  jmcneill 	return error;
    202  1.1  jmcneill }
    203  1.1  jmcneill 
    204  1.1  jmcneill static int
    205  1.1  jmcneill plmmc_pio_transfer(struct plmmc_softc *sc, struct sdmmc_command *cmd)
    206  1.1  jmcneill {
    207  1.1  jmcneill 	uint32_t *datap = (uint32_t *)cmd->c_data;
    208  1.1  jmcneill 	int i;
    209  1.1  jmcneill 
    210  1.1  jmcneill 	cmd->c_resid = cmd->c_datalen;
    211  1.1  jmcneill 	for (i = 0; i < (cmd->c_datalen >> 2); i++) {
    212  1.1  jmcneill 		if (plmmc_pio_wait(sc, cmd))
    213  1.1  jmcneill 			return ETIMEDOUT;
    214  1.1  jmcneill 		if (cmd->c_flags & SCF_CMD_READ) {
    215  1.1  jmcneill 			datap[i] = MMCI_READ(sc, MMCI_FIFO_REG);
    216  1.1  jmcneill 		} else {
    217  1.1  jmcneill 			MMCI_WRITE(sc, MMCI_FIFO_REG, datap[i]);
    218  1.1  jmcneill 		}
    219  1.1  jmcneill 		cmd->c_resid -= 4;
    220  1.1  jmcneill 	}
    221  1.1  jmcneill 
    222  1.1  jmcneill 	return 0;
    223  1.1  jmcneill }
    224  1.1  jmcneill 
    225  1.1  jmcneill static int
    226  1.1  jmcneill plmmc_host_reset(sdmmc_chipset_handle_t sch)
    227  1.1  jmcneill {
    228  1.1  jmcneill 	struct plmmc_softc *sc = sch;
    229  1.1  jmcneill 
    230  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_MASK0_REG, 0);
    231  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_MASK1_REG, 0);
    232  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_CLEAR_REG, 0xffffffff);
    233  1.1  jmcneill 
    234  1.1  jmcneill 	return 0;
    235  1.1  jmcneill }
    236  1.1  jmcneill 
    237  1.1  jmcneill static uint32_t
    238  1.1  jmcneill plmmc_host_ocr(sdmmc_chipset_handle_t sch)
    239  1.1  jmcneill {
    240  1.1  jmcneill 	return MMC_OCR_3_2V_3_3V | MMC_OCR_3_3V_3_4V;
    241  1.1  jmcneill }
    242  1.1  jmcneill 
    243  1.1  jmcneill static int
    244  1.1  jmcneill plmmc_host_maxblklen(sdmmc_chipset_handle_t sch)
    245  1.1  jmcneill {
    246  1.1  jmcneill 	return 2048;
    247  1.1  jmcneill }
    248  1.1  jmcneill 
    249  1.1  jmcneill static int
    250  1.1  jmcneill plmmc_card_detect(sdmmc_chipset_handle_t sch)
    251  1.1  jmcneill {
    252  1.1  jmcneill 	return 1;
    253  1.1  jmcneill }
    254  1.1  jmcneill 
    255  1.1  jmcneill static int
    256  1.1  jmcneill plmmc_write_protect(sdmmc_chipset_handle_t sch)
    257  1.1  jmcneill {
    258  1.1  jmcneill 	return 0;
    259  1.1  jmcneill }
    260  1.1  jmcneill 
    261  1.1  jmcneill static int
    262  1.1  jmcneill plmmc_bus_power(sdmmc_chipset_handle_t sch, uint32_t ocr)
    263  1.1  jmcneill {
    264  1.1  jmcneill 	return 0;
    265  1.1  jmcneill }
    266  1.1  jmcneill 
    267  1.1  jmcneill static int
    268  1.1  jmcneill plmmc_bus_clock(sdmmc_chipset_handle_t sch, int freq)
    269  1.1  jmcneill {
    270  1.1  jmcneill 	struct plmmc_softc *sc = sch;
    271  1.1  jmcneill 	u_int pll_freq, clk_div;
    272  1.1  jmcneill 	uint32_t clock;
    273  1.1  jmcneill 
    274  1.1  jmcneill 	clock = MMCI_CLOCK_PWRSAVE;
    275  1.1  jmcneill 	if (freq) {
    276  1.1  jmcneill 		pll_freq = sc->sc_clock_freq / 1000;
    277  1.1  jmcneill 		clk_div = (howmany(pll_freq, freq) >> 1) - 1;
    278  1.1  jmcneill 		clock |= __SHIFTIN(clk_div, MMCI_CLOCK_CLKDIV);
    279  1.1  jmcneill 		clock |= MMCI_CLOCK_ENABLE;
    280  1.1  jmcneill 	}
    281  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_CLOCK_REG, clock);
    282  1.1  jmcneill 
    283  1.1  jmcneill 	return 0;
    284  1.1  jmcneill }
    285  1.1  jmcneill 
    286  1.1  jmcneill static int
    287  1.1  jmcneill plmmc_bus_width(sdmmc_chipset_handle_t sch, int width)
    288  1.1  jmcneill {
    289  1.1  jmcneill 	return 0;
    290  1.1  jmcneill }
    291  1.1  jmcneill 
    292  1.1  jmcneill static int
    293  1.1  jmcneill plmmc_bus_rod(sdmmc_chipset_handle_t sch, int on)
    294  1.1  jmcneill {
    295  1.1  jmcneill 	struct plmmc_softc *sc = sch;
    296  1.1  jmcneill 	uint32_t power;
    297  1.1  jmcneill 
    298  1.1  jmcneill 
    299  1.1  jmcneill 	power = MMCI_READ(sc, MMCI_POWER_REG);
    300  1.1  jmcneill 	if (on) {
    301  1.1  jmcneill 		power |= MMCI_POWER_ROD;
    302  1.1  jmcneill 	} else {
    303  1.1  jmcneill 		power &= ~MMCI_POWER_ROD;
    304  1.1  jmcneill 	}
    305  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_POWER_REG, power);
    306  1.1  jmcneill 
    307  1.1  jmcneill 	return 0;
    308  1.1  jmcneill }
    309  1.1  jmcneill 
    310  1.1  jmcneill static void
    311  1.1  jmcneill plmmc_exec_command(sdmmc_chipset_handle_t sch, struct sdmmc_command *cmd)
    312  1.1  jmcneill {
    313  1.1  jmcneill 	struct plmmc_softc *sc = sch;
    314  1.1  jmcneill 	uint32_t cmdval = MMCI_COMMAND_ENABLE;
    315  1.1  jmcneill 
    316  1.1  jmcneill #ifdef PLMMC_DEBUG
    317  1.1  jmcneill 	device_printf(sc->sc_dev, "opcode %d flags %#x datalen %d\n",
    318  1.1  jmcneill 	    cmd->c_opcode, cmd->c_flags, cmd->c_datalen);
    319  1.1  jmcneill #endif
    320  1.1  jmcneill 
    321  1.1  jmcneill 	mutex_enter(&sc->sc_intr_lock);
    322  1.1  jmcneill 
    323  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_COMMAND_REG, 0);
    324  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_MASK0_REG, 0);
    325  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_CLEAR_REG, 0xffffffff);
    326  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_MASK0_REG,
    327  1.1  jmcneill 	    MMCI_INT_CMD_TIMEOUT | MMCI_INT_DATA_TIMEOUT |
    328  1.1  jmcneill 	    MMCI_INT_RX_DATA_AVAIL | MMCI_INT_TX_FIFO_EMPTY |
    329  1.1  jmcneill 	    MMCI_INT_DATA_END | MMCI_INT_DATA_BLOCK_END |
    330  1.1  jmcneill 	    MMCI_INT_CMD_RESP_END | MMCI_INT_CMD_SENT);
    331  1.1  jmcneill 
    332  1.1  jmcneill 	sc->sc_intr_status = 0;
    333  1.1  jmcneill 
    334  1.1  jmcneill 	if (cmd->c_flags & SCF_RSP_PRESENT)
    335  1.1  jmcneill 		cmdval |= MMCI_COMMAND_RESPONSE;
    336  1.1  jmcneill 	if (cmd->c_flags & SCF_RSP_136)
    337  1.1  jmcneill 		cmdval |= MMCI_COMMAND_LONGRSP;
    338  1.1  jmcneill 
    339  1.1  jmcneill 	if (cmd->c_datalen > 0) {
    340  1.1  jmcneill 		unsigned int nblks = cmd->c_datalen / cmd->c_blklen;
    341  1.1  jmcneill 		if (nblks == 0 || (cmd->c_datalen % cmd->c_blklen) != 0)
    342  1.1  jmcneill 			++nblks;
    343  1.1  jmcneill 
    344  1.1  jmcneill 		const uint32_t dir = (cmd->c_flags & SCF_CMD_READ) ? 1 : 0;
    345  1.1  jmcneill 		const uint32_t blksize = ffs(cmd->c_blklen) - 1;
    346  1.1  jmcneill 
    347  1.1  jmcneill 		MMCI_WRITE(sc, MMCI_DATA_TIMER_REG, 0xffffffff);
    348  1.1  jmcneill 		MMCI_WRITE(sc, MMCI_DATA_LENGTH_REG, nblks * cmd->c_blklen);
    349  1.1  jmcneill 		MMCI_WRITE(sc, MMCI_DATA_CTRL_REG,
    350  1.1  jmcneill 		    __SHIFTIN(dir, MMCI_DATA_CTRL_DIRECTION) |
    351  1.1  jmcneill 		    __SHIFTIN(blksize, MMCI_DATA_CTRL_BLOCKSIZE) |
    352  1.1  jmcneill 		    MMCI_DATA_CTRL_ENABLE);
    353  1.1  jmcneill 	}
    354  1.1  jmcneill 
    355  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_ARGUMENT_REG, cmd->c_arg);
    356  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_COMMAND_REG, cmdval | cmd->c_opcode);
    357  1.1  jmcneill 
    358  1.1  jmcneill 	if (cmd->c_datalen > 0) {
    359  1.1  jmcneill 		cmd->c_error = plmmc_pio_transfer(sc, cmd);
    360  1.1  jmcneill 		if (cmd->c_error) {
    361  1.1  jmcneill 			device_printf(sc->sc_dev,
    362  1.1  jmcneill 			    "error (%d) waiting for xfer\n", cmd->c_error);
    363  1.1  jmcneill 			goto done;
    364  1.1  jmcneill 		}
    365  1.1  jmcneill 	}
    366  1.1  jmcneill 
    367  1.1  jmcneill 	if (cmd->c_flags & SCF_RSP_PRESENT) {
    368  1.1  jmcneill 		cmd->c_error = plmmc_wait_status(sc,
    369  1.1  jmcneill 		    MMCI_INT_CMD_RESP_END|MMCI_INT_CMD_TIMEOUT, hz * 2);
    370  1.1  jmcneill 		if (cmd->c_error == 0 &&
    371  1.1  jmcneill 		    (sc->sc_intr_status & MMCI_INT_CMD_TIMEOUT)) {
    372  1.1  jmcneill 			cmd->c_error = ETIMEDOUT;
    373  1.1  jmcneill 		}
    374  1.1  jmcneill 		if (cmd->c_error) {
    375  1.1  jmcneill #ifdef PLMMC_DEBUG
    376  1.1  jmcneill 			device_printf(sc->sc_dev,
    377  1.1  jmcneill 			    "error (%d) waiting for resp\n", cmd->c_error);
    378  1.1  jmcneill #endif
    379  1.1  jmcneill 			goto done;
    380  1.1  jmcneill 		}
    381  1.1  jmcneill 
    382  1.1  jmcneill 		if (cmd->c_flags & SCF_RSP_136) {
    383  1.1  jmcneill 			cmd->c_resp[3] = MMCI_READ(sc, MMCI_RESP0_REG);
    384  1.1  jmcneill 			cmd->c_resp[2] = MMCI_READ(sc, MMCI_RESP1_REG);
    385  1.1  jmcneill 			cmd->c_resp[1] = MMCI_READ(sc, MMCI_RESP2_REG);
    386  1.1  jmcneill 			cmd->c_resp[0] = MMCI_READ(sc, MMCI_RESP3_REG);
    387  1.1  jmcneill 			if (cmd->c_flags & SCF_RSP_CRC) {
    388  1.1  jmcneill 				cmd->c_resp[0] = (cmd->c_resp[0] >> 8) |
    389  1.1  jmcneill 				    (cmd->c_resp[1] << 24);
    390  1.1  jmcneill 				cmd->c_resp[1] = (cmd->c_resp[1] >> 8) |
    391  1.1  jmcneill 				    (cmd->c_resp[2] << 24);
    392  1.1  jmcneill 				cmd->c_resp[2] = (cmd->c_resp[2] >> 8) |
    393  1.1  jmcneill 				    (cmd->c_resp[3] << 24);
    394  1.1  jmcneill 				cmd->c_resp[3] = (cmd->c_resp[3] >> 8);
    395  1.1  jmcneill 			}
    396  1.1  jmcneill 		} else {
    397  1.1  jmcneill 			cmd->c_resp[0] = MMCI_READ(sc, MMCI_RESP0_REG);
    398  1.1  jmcneill 		}
    399  1.1  jmcneill 	}
    400  1.1  jmcneill 
    401  1.1  jmcneill done:
    402  1.1  jmcneill 	cmd->c_flags |= SCF_ITSDONE;
    403  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_COMMAND_REG, 0);
    404  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_MASK0_REG, 0);
    405  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_CLEAR_REG, 0xffffffff);
    406  1.1  jmcneill 	MMCI_WRITE(sc, MMCI_DATA_CNT_REG, 0);
    407  1.1  jmcneill 
    408  1.1  jmcneill #ifdef PLMMC_DEBUG
    409  1.1  jmcneill 	device_printf(sc->sc_dev, "MMCI_STATUS_REG = %#x\n",
    410  1.1  jmcneill 	    MMCI_READ(sc, MMCI_STATUS_REG));
    411  1.1  jmcneill #endif
    412  1.1  jmcneill 	mutex_exit(&sc->sc_intr_lock);
    413  1.1  jmcneill }
    414  1.1  jmcneill 
    415  1.1  jmcneill static void
    416  1.1  jmcneill plmmc_card_enable_intr(sdmmc_chipset_handle_t sch, int enable)
    417  1.1  jmcneill {
    418  1.1  jmcneill }
    419  1.1  jmcneill 
    420  1.1  jmcneill static void
    421  1.1  jmcneill plmmc_card_intr_ack(sdmmc_chipset_handle_t sch)
    422  1.1  jmcneill {
    423  1.1  jmcneill }
    424