summaryrefslogtreecommitdiff
path: root/sys/dev/sdmmc/sdmmc_io.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev/sdmmc/sdmmc_io.c')
-rw-r--r--sys/dev/sdmmc/sdmmc_io.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/sys/dev/sdmmc/sdmmc_io.c b/sys/dev/sdmmc/sdmmc_io.c
index 33ff18a1983..069dc23d24a 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.16 2009/10/03 18:42:36 kettenis Exp $ */
+/* $OpenBSD: sdmmc_io.c,v 1.17 2009/11/11 21:59:16 jasper Exp $ */
/*
* Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org>
@@ -201,10 +201,13 @@ sdmmc_io_function_ready(struct sdmmc_function *sf)
struct sdmmc_function *sf0 = sc->sc_fn0;
u_int8_t rv;
+ SDMMC_ASSERT_LOCKED(sc);
+
if (sf->number == 0)
return 1; /* FN0 is always ready */
rv = sdmmc_io_read_1(sf0, SD_IO_CCCR_FN_READY);
+
return (rv & (1 << sf->number)) != 0;
}
@@ -245,14 +248,14 @@ sdmmc_io_function_disable(struct sdmmc_function *sf)
struct sdmmc_function *sf0 = sc->sc_fn0;
u_int8_t rv;
+ SDMMC_ASSERT_LOCKED(sc);
+
if (sf->number == 0)
return; /* FN0 is always enabled */
- SDMMC_LOCK(sc);
rv = sdmmc_io_read_1(sf0, SD_IO_CCCR_FN_ENABLE);
rv &= ~(1<<sf->number);
sdmmc_io_write_1(sf0, SD_IO_CCCR_FN_ENABLE, rv);
- SDMMC_UNLOCK(sc);
}
void
@@ -353,7 +356,7 @@ sdmmc_io_rw_direct(struct sdmmc_softc *sc, struct sdmmc_function *sf,
struct sdmmc_command cmd;
int error;
- SDMMC_LOCK(sc);
+ SDMMC_ASSERT_LOCKED(sc);
/* Make sure the card is selected. */
if ((error = sdmmc_select_card(sc, sf)) != 0) {
@@ -376,7 +379,6 @@ sdmmc_io_rw_direct(struct sdmmc_softc *sc, struct sdmmc_function *sf,
error = sdmmc_mmc_command(sc, &cmd);
*datap = SD_R5_DATA(cmd.c_resp);
- SDMMC_UNLOCK(sc);
return error;
}
@@ -393,7 +395,7 @@ sdmmc_io_rw_extended(struct sdmmc_softc *sc, struct sdmmc_function *sf,
struct sdmmc_command cmd;
int error;
- SDMMC_LOCK(sc);
+ SDMMC_ASSERT_LOCKED(sc);
#if 0
/* Make sure the card is selected. */
@@ -430,6 +432,8 @@ u_int8_t
sdmmc_io_read_1(struct sdmmc_function *sf, int reg)
{
u_int8_t data = 0;
+
+ SDMMC_ASSERT_LOCKED(sf->sc);
(void)sdmmc_io_rw_direct(sf->sc, sf, reg, (u_char *)&data,
SD_ARG_CMD52_READ);
@@ -439,6 +443,8 @@ sdmmc_io_read_1(struct sdmmc_function *sf, int reg)
void
sdmmc_io_write_1(struct sdmmc_function *sf, int reg, u_int8_t data)
{
+ SDMMC_ASSERT_LOCKED(sf->sc);
+
(void)sdmmc_io_rw_direct(sf->sc, sf, reg, (u_char *)&data,
SD_ARG_CMD52_WRITE);
}
@@ -448,6 +454,8 @@ sdmmc_io_read_2(struct sdmmc_function *sf, int reg)
{
u_int16_t data = 0;
+ SDMMC_ASSERT_LOCKED(sf->sc);
+
(void)sdmmc_io_rw_extended(sf->sc, sf, reg, (u_char *)&data, 2,
SD_ARG_CMD53_READ | SD_ARG_CMD53_INCREMENT);
return data;
@@ -456,6 +464,8 @@ sdmmc_io_read_2(struct sdmmc_function *sf, int reg)
void
sdmmc_io_write_2(struct sdmmc_function *sf, int reg, u_int16_t data)
{
+ SDMMC_ASSERT_LOCKED(sf->sc);
+
(void)sdmmc_io_rw_extended(sf->sc, sf, reg, (u_char *)&data, 2,
SD_ARG_CMD53_WRITE | SD_ARG_CMD53_INCREMENT);
}
@@ -465,6 +475,8 @@ sdmmc_io_read_4(struct sdmmc_function *sf, int reg)
{
u_int32_t data = 0;
+ SDMMC_ASSERT_LOCKED(sf->sc);
+
(void)sdmmc_io_rw_extended(sf->sc, sf, reg, (u_char *)&data, 4,
SD_ARG_CMD53_READ | SD_ARG_CMD53_INCREMENT);
return data;
@@ -473,6 +485,8 @@ sdmmc_io_read_4(struct sdmmc_function *sf, int reg)
void
sdmmc_io_write_4(struct sdmmc_function *sf, int reg, u_int32_t data)
{
+ SDMMC_ASSERT_LOCKED(sf->sc);
+
(void)sdmmc_io_rw_extended(sf->sc, sf, reg, (u_char *)&data, 4,
SD_ARG_CMD53_WRITE | SD_ARG_CMD53_INCREMENT);
}
@@ -483,6 +497,8 @@ sdmmc_io_read_multi_1(struct sdmmc_function *sf, int reg, u_char *data,
{
int error;
+ SDMMC_ASSERT_LOCKED(sf->sc);
+
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);
@@ -502,6 +518,8 @@ sdmmc_io_write_multi_1(struct sdmmc_function *sf, int reg, u_char *data,
{
int error;
+ SDMMC_ASSERT_LOCKED(sf->sc);
+
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);
@@ -519,6 +537,9 @@ int
sdmmc_io_xchg(struct sdmmc_softc *sc, struct sdmmc_function *sf,
int reg, u_char *datap)
{
+
+ SDMMC_ASSERT_LOCKED(sc);
+
return sdmmc_io_rw_direct(sc, sf, reg, datap,
SD_ARG_CMD52_WRITE|SD_ARG_CMD52_EXCHANGE);
}