From nobody Mon Feb 9 11:51:40 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519313969451665.9202491550237; Thu, 22 Feb 2018 07:39:29 -0800 (PST) Received: from localhost ([::1]:39052 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosy0-00023k-IG for importer@patchew.org; Thu, 22 Feb 2018 10:39:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38446) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosif-0004s6-Ic for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosie-0001jL-C5 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:37 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46604) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosie-0001hW-43 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:36 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosid-00023w-10 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:35 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:51 +0000 Message-Id: <20180222152307.7499-17-peter.maydell@linaro.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180222152307.7499-1-peter.maydell@linaro.org> References: <20180222152307.7499-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 16/32] sdcard: use the registerfields API to access the OCR register X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215220540.6556-12-f4bug@amsat.org Signed-off-by: Peter Maydell --- include/hw/sd/sd.h | 1 - hw/sd/sd.c | 21 +++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h index bf1eb0713c..9bdb3c9285 100644 --- a/include/hw/sd/sd.h +++ b/include/hw/sd/sd.h @@ -53,7 +53,6 @@ #define READY_FOR_DATA (1 << 8) #define APP_CMD (1 << 5) #define AKE_SEQ_ERROR (1 << 3) -#define OCR_CCS_BITN 30 =20 typedef enum { SD_VOLTAGE_0_4V =3D 400, /* currently not supported */ diff --git a/hw/sd/sd.c b/hw/sd/sd.c index b3698e34ad..706cb52668 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -32,6 +32,7 @@ #include "qemu/osdep.h" #include "hw/qdev.h" #include "hw/hw.h" +#include "hw/registerfields.h" #include "sysemu/block-backend.h" #include "hw/sd/sd.h" #include "qapi/error.h" @@ -47,8 +48,6 @@ //#define DEBUG_SD 1 =20 #define ACMD41_ENQUIRY_MASK 0x00ffffff -#define OCR_POWER_UP 0x80000000 -#define OCR_POWER_DELAY_NS 500000 /* 0.5ms */ =20 typedef enum { sd_r0 =3D 0, /* no response */ @@ -271,6 +270,11 @@ static uint16_t sd_crc16(void *message, size_t width) return shift_reg; } =20 +#define OCR_POWER_DELAY_NS 500000 /* 0.5ms */ + +FIELD(OCR, CARD_CAPACITY, 30, 1) /* 0:SDSC, 1:SDHC/SDXC */ +FIELD(OCR, CARD_POWER_UP, 31, 1) + static void sd_set_ocr(SDState *sd) { /* All voltages OK, Standard Capacity SD Memory Card, not yet powered = up */ @@ -282,9 +286,10 @@ static void sd_ocr_powerup(void *opaque) SDState *sd =3D opaque; =20 trace_sdcard_powerup(); - /* Set powered up bit in OCR */ - assert(!(sd->ocr & OCR_POWER_UP)); - sd->ocr |=3D OCR_POWER_UP; + assert(!FIELD_EX32(sd->ocr, OCR, CARD_POWER_UP)); + + /* card power-up OK */ + sd->ocr =3D FIELD_DP32(sd->ocr, OCR, CARD_POWER_UP, 1); } =20 static void sd_set_scr(SDState *sd) @@ -570,7 +575,7 @@ static bool sd_ocr_vmstate_needed(void *opaque) SDState *sd =3D opaque; =20 /* Include the OCR state (and timer) if it is not yet powered up */ - return !(sd->ocr & OCR_POWER_UP); + return !FIELD_EX32(sd->ocr, OCR, CARD_POWER_UP); } =20 static const VMStateDescription sd_ocr_vmstate =3D { @@ -680,7 +685,7 @@ static void sd_erase(SDState *sd) return; } =20 - if (extract32(sd->ocr, OCR_CCS_BITN, 1)) { + if (FIELD_EX32(sd->ocr, OCR, CARD_CAPACITY)) { /* High capacity memory card: erase units are 512 byte blocks */ erase_start *=3D 512; erase_end *=3D 512; @@ -1468,7 +1473,7 @@ static sd_rsp_type_t sd_app_command(SDState *sd, * UEFI, which sends an initial enquiry ACMD41, but * assumes that the card is in ready state as soon as it * sees the power up bit set. */ - if (!(sd->ocr & OCR_POWER_UP)) { + if (!FIELD_EX32(sd->ocr, OCR, CARD_POWER_UP)) { if ((req.arg & ACMD41_ENQUIRY_MASK) !=3D 0) { timer_del(sd->ocr_power_timer); sd_ocr_powerup(sd); --=20 2.16.1