From nobody Tue Feb 10 13:37:01 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; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520610256833446.07860238192177; Fri, 9 Mar 2018 07:44:16 -0800 (PST) Received: from localhost ([::1]:46050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euKBo-00040t-IT for importer@patchew.org; Fri, 09 Mar 2018 10:44:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50360) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euK4w-0006Mn-6I for qemu-devel@nongnu.org; Fri, 09 Mar 2018 10:37:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1euK4v-0008DU-4p for qemu-devel@nongnu.org; Fri, 09 Mar 2018 10:37:06 -0500 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:35280) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1euK4u-0008Cw-V3 for qemu-devel@nongnu.org; Fri, 09 Mar 2018 10:37:05 -0500 Received: by mail-wr0-x243.google.com with SMTP id a27so1744311wra.2 for ; Fri, 09 Mar 2018 07:37:04 -0800 (PST) Received: from x1.local (ABayonne-654-1-76-150.w86-222.abo.wanadoo.fr. [86.222.219.150]) by smtp.gmail.com with ESMTPSA id m191sm1584175wma.21.2018.03.09.07.37.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Mar 2018 07:37:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kB1OTCp2TdH2yW1HFVLZIOG5JBOFO8vZgh7VKcZkq98=; b=R0Bd2d1gHre2KKH2gmT9UAdxldP10hlWx42lmTttmdM0Pr/pwDKg6VbbP+ndMgNDDe 8qXwI/uN9ZLPaRlFPqI/49vEPFxLs/Sw7cVhCRCws8QbecMbzaMdZ50DUC2QomDE2FLS xyoQpEXg6rkz1Gf2dyKBdRyexTDbpPUw4M342EIh2OA5GpnVdQa+OV8dxAM/Fu2DR5hM C3VUURLobb50HYXKzokGIt+JqdCM0WYgBgs4yJZP0rHTU/nB/qWI4g0G7M97ByHIgqdr HHbKK6OGHNe8VRDr6lz8MTePYW6HZYTSapAud52EwdOY8LIKseOXF5qwGSxuaQ/320Ko D4kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=kB1OTCp2TdH2yW1HFVLZIOG5JBOFO8vZgh7VKcZkq98=; b=mfbVJ/rMk6O5WEiTXXNpy5nblB5K4EVoYPkzqhmagYrNoJs3AvTjsxuCir1SU4Szpv nBg29+Hwd89EjCm/P11Crw8EGCxEWrdQ4st0dRSJVvFK0EhPOQK5rifSzA8GJ4fFbOPp BSMMVCKGNJ/zbg4E2S4XaxCTyOLI7j6ti8eCMbsBSRGWbckEymwFcRMIJmuGyCfqJtGS WXswvPyYsLJ9PR/AOPsYZb9vIoep8meC8ygH3GXgj+m+R1ANh6Wv6sDKfeVCHIQasdRR E5LJ4yomNIOW6FLHwvwgNgfdBPmFwY+fmIVvHW5CgXoK2GfCEx1pHkh0zKNga516Cydd Moew== X-Gm-Message-State: AElRT7FJ/fyDeOl8Pnt0UzyASIMLDgRoTb6ZIAdstJ5PvovKnjVodHIz dSOkNjJeqm44usyi8tp8kemAvvWV X-Google-Smtp-Source: AG47ELskaD5eZgN8fafdqa5xkQUOAExS9aLkcsqgMAPKFnQa8Zl4aR4LQSpcV6e1v8K+doDPHDlWCQ== X-Received: by 10.223.184.253 with SMTP id c58mr929526wrg.190.1520609823732; Fri, 09 Mar 2018 07:37:03 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Alistair Francis , Peter Maydell , "Edgar E . Iglesias" Date: Fri, 9 Mar 2018 16:36:50 +0100 Message-Id: <20180309153654.13518-5-f4bug@amsat.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180309153654.13518-1-f4bug@amsat.org> References: <20180309153654.13518-1-f4bug@amsat.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: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PATCH 4/8] 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: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 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 --- 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