From 0de91f430bf941d9f61c958e040420c3b7e3cab0 Mon Sep 17 00:00:00 2001 From: imp Date: Sun, 28 Sep 2008 22:40:11 +0000 Subject: Propigate read-only status of cards. Right now it is read only at device attach time. We may need to read this more often in the future, but for now simplicity of implementation wins. Submitted by: mav@ --- sys/dev/mmc/mmc.c | 7 ++++++- sys/dev/mmc/mmcbrvar.h | 6 ++++++ sys/dev/mmc/mmcvar.h | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/sys/dev/mmc/mmc.c b/sys/dev/mmc/mmc.c index c3f96c9..cc0db3f 100644 --- a/sys/dev/mmc/mmc.c +++ b/sys/dev/mmc/mmc.c @@ -86,6 +86,7 @@ struct mmc_ivars { enum mmc_card_mode mode; struct mmc_cid cid; /* cid decoded */ struct mmc_csd csd; /* csd decoded */ + u_char read_only; /* True when the device is read-only */ }; #define CMD_RETRIES 3 @@ -613,7 +614,8 @@ mmc_discover_cards(struct mmc_softc *sc) mmc_decode_cid(1, ivar->raw_cid, &ivar->cid); mmc_send_relative_addr(sc, &resp); ivar->rca = resp >> 16; - // RO check + if (mmcbr_get_ro(sc->dev)) + ivar->read_only = 1; mmc_send_csd(sc, ivar->rca, ivar->raw_csd); mmc_decode_csd(1, ivar->raw_csd, &ivar->csd); printf("SD CARD: %lld bytes\n", (long long) @@ -738,6 +740,9 @@ mmc_read_ivar(device_t bus, device_t child, int which, u_char *result) case MMC_IVAR_TRAN_SPEED: *(int *)result = ivar->csd.tran_speed; break; + case MMC_IVAR_READ_ONLY: + *(int *)result = ivar->read_only; + break; } return (0); } diff --git a/sys/dev/mmc/mmcbrvar.h b/sys/dev/mmc/mmcbrvar.h index 0f8a9cf..9a8bb47 100644 --- a/sys/dev/mmc/mmcbrvar.h +++ b/sys/dev/mmc/mmcbrvar.h @@ -97,4 +97,10 @@ mmcbr_update_ios(device_t dev) return (MMCBR_UPDATE_IOS(device_get_parent(dev), dev)); } +static int __inline +mmcbr_get_ro(device_t dev) +{ + return (MMCBR_GET_RO(device_get_parent(dev), dev)); +} + #endif /* DEV_MMC_MMCBRVAR_H */ diff --git a/sys/dev/mmc/mmcvar.h b/sys/dev/mmc/mmcvar.h index b5c7c09..c18a25f 100644 --- a/sys/dev/mmc/mmcvar.h +++ b/sys/dev/mmc/mmcvar.h @@ -61,6 +61,7 @@ enum mmc_device_ivars { MMC_IVAR_RCA, MMC_IVAR_SECTOR_SIZE, MMC_IVAR_TRAN_SPEED, + MMC_IVAR_READ_ONLY, // MMC_IVAR_, }; @@ -75,5 +76,6 @@ MMC_ACCESSOR(media_size, MEDIA_SIZE, int) MMC_ACCESSOR(rca, RCA, int) MMC_ACCESSOR(sector_size, SECTOR_SIZE, int) MMC_ACCESSOR(tran_speed, TRAN_SPEED, int) +MMC_ACCESSOR(read_only, READ_ONLY, int) #endif /* DEV_MMC_MMCVAR_H */ -- cgit v1.1