From nobody Tue Apr 15 19:53:26 2025 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520618193695993.8798504504405; Fri, 9 Mar 2018 09:56:33 -0800 (PST) Received: from localhost ([::1]:47049 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euMFl-0000WI-LO for importer@patchew.org; Fri, 09 Mar 2018 12:56:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euLmz-000052-Li for qemu-devel@nongnu.org; Fri, 09 Mar 2018 12:26:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1euLmy-0006Bd-P3 for qemu-devel@nongnu.org; Fri, 09 Mar 2018 12:26:41 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:47008) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1euLmy-0006A9-HT for qemu-devel@nongnu.org; Fri, 09 Mar 2018 12:26:40 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1euLmx-00079O-BB for qemu-devel@nongnu.org; Fri, 09 Mar 2018 17:26:39 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 9 Mar 2018 17:26:20 +0000 Message-Id: <20180309172622.4277-24-peter.maydell@linaro.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180309172622.4277-1-peter.maydell@linaro.org> References: <20180309172622.4277-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 23/25] sdcard: Add the Tuning Command (CMD19) 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 From the "Physical Layer Simplified Specification Version 3.01": A known data block ("Tuning block") can be used to tune sampling point for tuning required hosts. [...] This procedure gives the system optimal timing for each specific host and card combination and compensates for static delays in the timing budget including process, voltage and different PCB loads and skews. [...] Data block, carried by DAT[3:0], contains a pattern for tuning sampling position to receive data on the CMD and DAT[3:0] line. [based on a patch from Alistair Francis from qemu/xilinx tag xilinx-v2015.2] Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180309153654.13518-5-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/sd.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index dc50d6bbf7..235e0518d6 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1169,6 +1169,14 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, = SDRequest req) } break; =20 + case 19: /* CMD19: SEND_TUNING_BLOCK (SD) */ + if (sd->state =3D=3D sd_transfer_state) { + sd->state =3D sd_sendingdata_state; + sd->data_offset =3D 0; + return sd_r1; + } + break; + case 23: /* CMD23: SET_BLOCK_COUNT */ switch (sd->state) { case sd_transfer_state: @@ -1893,6 +1901,20 @@ void sd_write_data(SDState *sd, uint8_t value) } } =20 +#define SD_TUNING_BLOCK_SIZE 64 + +static const uint8_t sd_tuning_block_pattern[SD_TUNING_BLOCK_SIZE] =3D { + /* See: Physical Layer Simplified Specification Version 3.01, Table 4-= 2 */ + 0xff, 0x0f, 0xff, 0x00, 0x0f, 0xfc, 0xc3, 0xcc, + 0xc3, 0x3c, 0xcc, 0xff, 0xfe, 0xff, 0xfe, 0xef, + 0xff, 0xdf, 0xff, 0xdd, 0xff, 0xfb, 0xff, 0xfb, + 0xbf, 0xff, 0x7f, 0xff, 0x77, 0xf7, 0xbd, 0xef, + 0xff, 0xf0, 0xff, 0xf0, 0x0f, 0xfc, 0xcc, 0x3c, + 0xcc, 0x33, 0xcc, 0xcf, 0xff, 0xef, 0xff, 0xee, + 0xff, 0xfd, 0xff, 0xfd, 0xdf, 0xff, 0xbf, 0xff, + 0xbb, 0xff, 0xf7, 0xff, 0xf7, 0x7f, 0x7b, 0xde, +}; + uint8_t sd_read_data(SDState *sd) { /* TODO: Append CRCs */ @@ -1972,6 +1994,13 @@ uint8_t sd_read_data(SDState *sd) } break; =20 + case 19: /* CMD19: SEND_TUNING_BLOCK (SD) */ + if (sd->data_offset >=3D SD_TUNING_BLOCK_SIZE - 1) { + sd->state =3D sd_transfer_state; + } + ret =3D sd_tuning_block_pattern[sd->data_offset++]; + break; + case 22: /* ACMD22: SEND_NUM_WR_BLOCKS */ ret =3D sd->data[sd->data_offset ++]; =20 --=20 2.16.2