-/* $OpenBSD: sximmc.c,v 1.1 2016/08/15 21:03:27 kettenis Exp $ */
+/* $OpenBSD: sximmc.c,v 1.2 2016/08/20 19:41:14 kettenis Exp $ */
/* $NetBSD: awin_mmc.c,v 1.23 2015/11/14 10:32:40 bouyer Exp $ */
/*-
#include <dev/sdmmc/sdmmcchip.h>
#include <dev/sdmmc/sdmmc_ioreg.h>
+#include <armv7/sunxi/sunxireg.h>
#include <armv7/sunxi/sxiccmuvar.h>
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_pinctrl.h>
#include <dev/ofw/fdt.h>
+//#define SXIMMC_DEBUG
+
#define SXIMMC_GCTRL 0x0000
#define SXIMMC_CLKCR 0x0004
#define SXIMMC_TIMEOUT 0x0008
bus_space_handle_t sc_clk_bsh;
bus_dma_tag_t sc_dmat;
int sc_node;
+ int sc_unit;
int sc_use_dma;
return;
sc->sc_node = faa->fa_node;
+ sc->sc_unit = (faa->fa_reg[0].addr - SDMMC0_ADDR) / SDMMCx_SIZE;
sc->sc_bst = faa->fa_iot;
sc->sc_dmat = faa->fa_dmat;
sc->sc_use_dma = 1;
- printf("\n");
+ printf(": unit %d\n", sc->sc_unit);
pinctrl_byname(faa->fa_node, "default");
/* enable clock */
- sxiccmu_enablemodule(CCMU_SDMMC0);
+ sxiccmu_enablemodule(CCMU_SDMMC0 + sc->sc_unit);
delay(5000);
#if 0
saa.saa_clkmax = awin_chip_id() == AWIN_CHIP_ID_A80 ? 48000 : 50000;
#endif
+#if 0
saa.caps = SMC_CAPS_SD_HIGHSPEED | SMC_CAPS_MMC_HIGHSPEED;
+#endif
width = OF_getpropint(sc->sc_node, "bus-width", 1);
if (width >= 8)
delay(20000);
#endif
+ sxiccmu_set_sd_clock(CCMU_SDMMC0 + sc->sc_unit, freq * 1000);
+ delay(20000);
return 0;
}
int
sximmc_host_maxblklen(sdmmc_chipset_handle_t sch)
{
+#if 0
return 8192;
+#else
+ return 512;
+#endif
}
int
cmdval |= SXIMMC_CMD_CHECK_RSP_CRC;
if (cmd->c_datalen > 0) {
- unsigned int nblks;
+ uint16_t blksize;
+ uint16_t blkcount;
cmdval |= SXIMMC_CMD_DATA_EXP | SXIMMC_CMD_WAIT_PRE_OVER;
if (!ISSET(cmd->c_flags, SCF_CMD_READ)) {
cmdval |= SXIMMC_CMD_WRITE;
}
- nblks = cmd->c_datalen / cmd->c_blklen;
- if (nblks == 0 || (cmd->c_datalen % cmd->c_blklen) != 0)
- ++nblks;
-
- if (nblks > 1) {
+ blksize = MIN(cmd->c_datalen, cmd->c_blklen);
+ blkcount = cmd->c_datalen / blksize;
+ if (blkcount > 1) {
cmdval |= SXIMMC_CMD_SEND_AUTO_STOP;
}
- MMC_WRITE(sc, SXIMMC_BLKSZ, cmd->c_blklen);
- MMC_WRITE(sc, SXIMMC_BYTECNT, nblks * cmd->c_blklen);
+ MMC_WRITE(sc, SXIMMC_BLKSZ, blksize);
+ MMC_WRITE(sc, SXIMMC_BYTECNT, blkcount * blksize);
}
sc->sc_intr_rint = 0;