From patchwork Mon Jun 24 13:14:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 807033 Delivered-To: patch@linaro.org Received: by 2002:a5d:508d:0:b0:362:4979:7f74 with SMTP id a13csp1877945wrt; Mon, 24 Jun 2024 06:17:35 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXZIOIU6pIiSk5/pbTMuPJLpQ63Ht9yiVq1lr5dc9IahCYnUs3LlU/WmYz0NbklOoRj5f5FupTSfi6tWqkZtklk X-Google-Smtp-Source: AGHT+IFbSRL86QnS61PMkxtGx4wGEbWZs0GOqkWF47bHZHlcF8FGJGjZrf9N9icjV13mXeLC9acf X-Received: by 2002:a05:6214:174b:b0:6b5:4bd5:74b0 with SMTP id 6a1803df08f44-6b54bd57535mr24900826d6.3.1719235055625; Mon, 24 Jun 2024 06:17:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719235055; cv=none; d=google.com; s=arc-20160816; b=ekgv9nqGIeywUE6//kMRbq530ExwI5ZB1UxT44OGmospM9UxUMGXQjr/p6P3RxbyjN 76M+foXiHI2sq1wCF9PgaDpiXwAvUoII+Y0rUo+Pi9R1hW3pBUX87LYZQnu5iAv0kj3E lMSXAsBa6n2zWvSDtsSJOOI/zRwa22omQEmuAIWyPqHwJ9l0Of4eXztQEr4rIJ7g41/i zLHG5tUsoOn6yoIhbbrdGEEsApdnSCLFVdcgvmrScqpq0BIbY5SWtTNkSBqR4xgufzZR 8omXl8fUefzGl47RMn0DJFO2HaJgvpnwOvb6eQpJti+FMUX22Ieo46F89jmy5Rya/dR9 Hg2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HXfJJfCbngNXWETKRmSoaVmSjOkjTU89WVvhepuXul8=; fh=SWrD6ZzKChsLNd0MI2/W9aN13/YqYpoy69YA//3JWDk=; b=haT/xkVMM67aXq8B4zewsmptIeXLCWcBGjgaPs5VdvySoOX1FcntveoINo3WNm1X81 eKRtSynQa6n5vNwfAZl+VHt1H3tYyiZC/Q14H2oUIbiNnlRxMesvXljbo8nPdAkyoJRm wQbAS3DY7c1ezrXXRixoLtmEDByBAS8Pynk9msTvPaHd5VUrLZ3tmJ2xDey0GgpSFKSI QdY/L/mkT+AFvwbzetCn5zqUyt8CCylSpr7QPcCBW0fwVpcBdQY8tQ5a5TMCnud7r+lb VaFFa8jkk7gUCUhpW6xgk3I1bfOJbWLqIx4NOMqFNFy66w1uUh0F0DWCZoMOSJMNTNV1 o5cQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fir262Vd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6b539d2990fsi48722706d6.424.2024.06.24.06.17.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 24 Jun 2024 06:17:35 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fir262Vd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLjZM-0005jU-Sg; Mon, 24 Jun 2024 09:17:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLjYe-0004ix-1N for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:16:37 -0400 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLjYb-0005de-N1 for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:16:31 -0400 Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2ec1620a956so51699961fa.1 for ; Mon, 24 Jun 2024 06:16:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234987; x=1719839787; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HXfJJfCbngNXWETKRmSoaVmSjOkjTU89WVvhepuXul8=; b=fir262VdbE3+A4+6tFWLLdW2ydwg8ioyytaFvNDzRA70DQdUKTvy3z72csUw7XXVJO kb7D3mlckeu13XzwJpgr9GRbLz/gXQgB+6K/mzr+CwlTOOy9DqklWhdiBtCDrLfyDYsw BcpSMR4RbA6IHhXalUpQZe2+3rIzb/VfjsFkRSjWWWSQMN0mcT7b8GbsU4+6PnfTJKAC +8L8a/3oM0xqbgTIf6B/S+mr3x9wDGTJEsvf8k+8fYM777dIFHeeU0XV00DUpHU7XHZj /6E7ltMTVMums8hvQUi2kLWQHkUqC7E47WS9H+I8ZrNs8DCVTHuq3pVlltTtw9AnyAbl Luhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234987; x=1719839787; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HXfJJfCbngNXWETKRmSoaVmSjOkjTU89WVvhepuXul8=; b=A+eE1xzVHhO0Q7MQzJrCmClnZ7VPw1hYq5WOssxMkZf5Jh8Bp5eROkUr1WoTLuODha i/jayxtNw78dl+tnqjZKOW1aaCMPUbbXpmJCEg2XEc1RTKk+fHxVlAce5UlTQOtxoFeh BEqK1oh3Qx2MxgcwlZw9lbVJk6n8GtjVYScMLjf72KEJQXLvaP6DXdltGcaZiLBig/vT IPX1aYqjUMxoxLKFwv9/w2kgZH/5SSH1tVTGuG88q43RFhDYatdZfJp3B7m8NtgKgDPh +sktbRQs8OIydkakqFTHO/lpcMCAjyGObGURundGpVO23QMP+Y3Z22bPvrbgW5yR0iw4 +CFw== X-Gm-Message-State: AOJu0Yw23i5Hl1AK+uaUSnuhuBfuJRBYPgNf3mLkjtKHAlBIHmAqr7PO Y2ioJJo2Awy4+WSYQV9omfKkvJk3v+R0ag9L1iPBCEmIWsNM478TLaymUDmHT2TsDappuCRRDyY Y X-Received: by 2002:a05:651c:211d:b0:2ec:5dfc:a64e with SMTP id 38308e7fff4ca-2ec5dfca6demr30542061fa.0.1719234986576; Mon, 24 Jun 2024 06:16:26 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4248482f1c4sm120290265e9.10.2024.06.24.06.16.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:16:26 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9?= =?utf-8?q?dric_Le_Goater?= Subject: [PULL 19/19] hw/sd/sdcard: Add comments around registers and commands Date: Mon, 24 Jun 2024 15:14:40 +0200 Message-ID: <20240624131440.81111-20-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22c; envelope-from=philmd@linaro.org; helo=mail-lj1-x22c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240621080554.18986-21-philmd@linaro.org> --- hw/sd/sd.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index d4e3d079a8..a48010cfc1 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -315,6 +315,8 @@ static uint8_t sd_crc7(const void *message, size_t width) return shift_reg; } +/* Operation Conditions register */ + #define OCR_POWER_DELAY_NS 500000 /* 0.5ms */ FIELD(OCR, VDD_VOLTAGE_WINDOW, 0, 24) @@ -364,6 +366,8 @@ static void sd_set_ocr(SDState *sd) } } +/* SD Configuration register */ + static void sd_set_scr(SDState *sd) { sd->scr[0] = 0 << 4; /* SCR structure version 1.0 */ @@ -386,6 +390,8 @@ static void sd_set_scr(SDState *sd) sd->scr[7] = 0x00; } +/* Card IDentification register */ + #define MID 0xaa #define OID "XY" #define PNM "QEMU!" @@ -411,6 +417,8 @@ static void sd_set_cid(SDState *sd) sd->cid[15] = (sd_crc7(sd->cid, 15) << 1) | 1; } +/* Card-Specific Data register */ + #define HWBLOCK_SHIFT 9 /* 512 bytes */ #define SECTOR_SHIFT 5 /* 16 kilobytes */ #define WPGROUP_SHIFT 7 /* 2 megs */ @@ -480,6 +488,8 @@ static void sd_set_csd(SDState *sd, uint64_t size) sd->csd[15] = (sd_crc7(sd->csd, 15) << 1) | 1; } +/* Relative Card Address register */ + static void sd_set_rca(SDState *sd) { sd->rca += 0x4567; @@ -493,6 +503,8 @@ static uint16_t sd_req_get_rca(SDState *s, SDRequest req) return 0; } +/* Card Status register */ + FIELD(CSR, AKE_SEQ_ERROR, 3, 1) FIELD(CSR, APP_CMD, 5, 1) FIELD(CSR, FX_EVENT, 6, 1) @@ -623,6 +635,8 @@ static void sd_reset(DeviceState *dev) sect = sd_addr_to_wpnum(size) + 1; sd->state = sd_idle_state; + + /* card registers */ sd->rca = 0x0000; sd->size = size; sd_set_ocr(sd); @@ -1055,6 +1069,7 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) return sd_illegal; } +/* CMD0 */ static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd, SDRequest req) { if (sd->state != sd_inactive_state) { @@ -1065,6 +1080,7 @@ static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd, SDRequest req) return sd_is_spi(sd) ? sd_r1 : sd_r0; } +/* CMD1 */ static sd_rsp_type_t spi_cmd_SEND_OP_COND(SDState *sd, SDRequest req) { sd->state = sd_transfer_state; @@ -1072,6 +1088,7 @@ static sd_rsp_type_t spi_cmd_SEND_OP_COND(SDState *sd, SDRequest req) return sd_r1; } +/* CMD2 */ static sd_rsp_type_t sd_cmd_ALL_SEND_CID(SDState *sd, SDRequest req) { switch (sd->state) { @@ -1083,6 +1100,7 @@ static sd_rsp_type_t sd_cmd_ALL_SEND_CID(SDState *sd, SDRequest req) } } +/* CMD3 */ static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR(SDState *sd, SDRequest req) { switch (sd->state) { @@ -1097,6 +1115,7 @@ static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR(SDState *sd, SDRequest req) } } +/* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req) { if (sd->spec_version < SD_PHY_SPECv3_01_VERS) { @@ -1113,6 +1132,7 @@ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req) return sd_r1; } +/* CMD23 */ static sd_rsp_type_t sd_cmd_SET_BLOCK_COUNT(SDState *sd, SDRequest req) { if (sd->spec_version < SD_PHY_SPECv3_01_VERS) {