From 1f8b50cb7a2eb53fe21aedbd356ed06d7973ac1c Mon Sep 17 00:00:00 2001 From: patrick Date: Sun, 11 Feb 2018 20:57:57 +0000 Subject: [PATCH] Add sdmmc_io_read_region_1() and sdmmc_io_write_region_1() as an interface for "reading memory" akin to the bus_space(9) API. The already existing multi interface is used for "reading FIFOs". The technical difference is that one always reads from the same address (FIFO) while the other increments the address while reading (memory). ok kettenis@ --- sys/dev/sdmmc/sdmmc_io.c | 48 +++++++++++++++++++++++++++++++++++++++- sys/dev/sdmmc/sdmmcvar.h | 4 +++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/sys/dev/sdmmc/sdmmc_io.c b/sys/dev/sdmmc/sdmmc_io.c index cd457cb5c58..206d578f06e 100644 --- a/sys/dev/sdmmc/sdmmc_io.c +++ b/sys/dev/sdmmc/sdmmc_io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sdmmc_io.c,v 1.30 2017/10/12 11:54:37 patrick Exp $ */ +/* $OpenBSD: sdmmc_io.c,v 1.31 2018/02/11 20:57:57 patrick Exp $ */ /* * Copyright (c) 2006 Uwe Stuehler @@ -530,6 +530,52 @@ sdmmc_io_write_multi_1(struct sdmmc_function *sf, int reg, u_char *data, SD_ARG_CMD53_WRITE); } +int +sdmmc_io_read_region_1(struct sdmmc_function *sf, int reg, u_char *data, + int datalen) +{ + int error; + + rw_assert_wrlock(&sf->sc->sc_lock); + + while (datalen > SD_ARG_CMD53_LENGTH_MAX) { + error = sdmmc_io_rw_extended(sf->sc, sf, reg, data, + SD_ARG_CMD53_LENGTH_MAX, SD_ARG_CMD53_READ | + SD_ARG_CMD53_INCREMENT); + if (error) + return error; + reg += SD_ARG_CMD53_LENGTH_MAX; + data += SD_ARG_CMD53_LENGTH_MAX; + datalen -= SD_ARG_CMD53_LENGTH_MAX; + } + + return sdmmc_io_rw_extended(sf->sc, sf, reg, data, datalen, + SD_ARG_CMD53_READ | SD_ARG_CMD53_INCREMENT); +} + +int +sdmmc_io_write_region_1(struct sdmmc_function *sf, int reg, u_char *data, + int datalen) +{ + int error; + + rw_assert_wrlock(&sf->sc->sc_lock); + + while (datalen > SD_ARG_CMD53_LENGTH_MAX) { + error = sdmmc_io_rw_extended(sf->sc, sf, reg, data, + SD_ARG_CMD53_LENGTH_MAX, SD_ARG_CMD53_WRITE | + SD_ARG_CMD53_INCREMENT); + if (error) + return error; + reg += SD_ARG_CMD53_LENGTH_MAX; + data += SD_ARG_CMD53_LENGTH_MAX; + datalen -= SD_ARG_CMD53_LENGTH_MAX; + } + + return sdmmc_io_rw_extended(sf->sc, sf, reg, data, datalen, + SD_ARG_CMD53_WRITE | SD_ARG_CMD53_INCREMENT); +} + int sdmmc_io_xchg(struct sdmmc_softc *sc, struct sdmmc_function *sf, int reg, u_char *datap) diff --git a/sys/dev/sdmmc/sdmmcvar.h b/sys/dev/sdmmc/sdmmcvar.h index cc4074cd00b..0b2ffce42be 100644 --- a/sys/dev/sdmmc/sdmmcvar.h +++ b/sys/dev/sdmmc/sdmmcvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sdmmcvar.h,v 1.26 2016/05/05 11:01:08 kettenis Exp $ */ +/* $OpenBSD: sdmmcvar.h,v 1.27 2018/02/11 20:57:57 patrick Exp $ */ /* * Copyright (c) 2006 Uwe Stuehler @@ -258,10 +258,12 @@ u_int8_t sdmmc_io_read_1(struct sdmmc_function *, int); u_int16_t sdmmc_io_read_2(struct sdmmc_function *, int); u_int32_t sdmmc_io_read_4(struct sdmmc_function *, int); int sdmmc_io_read_multi_1(struct sdmmc_function *, int, u_char *, int); +int sdmmc_io_read_region_1(struct sdmmc_function *, int, u_char *, int); void sdmmc_io_write_1(struct sdmmc_function *, int, u_int8_t); void sdmmc_io_write_2(struct sdmmc_function *, int, u_int16_t); void sdmmc_io_write_4(struct sdmmc_function *, int, u_int32_t); int sdmmc_io_write_multi_1(struct sdmmc_function *, int, u_char *, int); +int sdmmc_io_write_region_1(struct sdmmc_function *, int, u_char *, int); int sdmmc_io_function_ready(struct sdmmc_function *); int sdmmc_io_function_enable(struct sdmmc_function *); void sdmmc_io_function_disable(struct sdmmc_function *); -- 2.20.1