From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Wed, 07 May 2025 11:27:25 +0200 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by lore.white.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uCb3k-0035UV-37 for lore@lore.pengutronix.de; Wed, 07 May 2025 11:27:24 +0200 Received: from bombadil.infradead.org ([2607:7c80:54:3::133]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1uCb3k-0006Id-4c for lore@pengutronix.de; Wed, 07 May 2025 11:27:24 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=73vH96d8UKBOXQwkGSlLlEfYGX3oMlVFl/wj35aGT2s=; b=HgpzGH+peflMFTgUj4LKz2RjMJ yXRx/DgG5OSPNuAZ7KLWNwxOuDtD6Ew/2ilUTDXlaliEHzeTOXT3SuWCGlUgkiY+n0FvFCcVM/b2h PnsQaxT26xapkEZt7kxlchjGoStcABtDhV51Dih4tYbndOc1oe+2pheidI+qNlwL9mbYcDjLWQC6q eZsneXXk2xy/qZP+YhGj8JkH5xnERqCjtkqsBeFSFKAFo/ApHpXAMt4ITtXJDyKuUUBEXsSAnYJm3 etgO27RiG34W/m+bDX1gzj7/En6v6DduhgeV1lD3XyMwp5mbMsRC2awBPG9KOgghZN9LbZTBsX46u 1oDC49Aw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uCb3E-0000000EwrM-0kOX; Wed, 07 May 2025 09:26:52 +0000 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uCaFA-0000000Elaq-3FW1 for barebox@lists.infradead.org; Wed, 07 May 2025 08:35:17 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1uCaF9-0003wz-A1; Wed, 07 May 2025 10:35:07 +0200 Received: from dude05.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::54]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uCaF9-001WuJ-0A; Wed, 07 May 2025 10:35:07 +0200 Received: from localhost ([::1] helo=dude05.red.stw.pengutronix.de) by dude05.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1uCa2e-00AQeI-2b; Wed, 07 May 2025 10:22:12 +0200 From: Ahmad Fatoum To: barebox@lists.infradead.org Cc: Ahmad Fatoum Date: Wed, 7 May 2025 10:22:05 +0200 Message-Id: <20250507082209.3289972-27-a.fatoum@pengutronix.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250507082209.3289972-1-a.fatoum@pengutronix.de> References: <20250507082209.3289972-1-a.fatoum@pengutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250507_013508_915061_69FB6191 X-CRM114-Status: GOOD ( 12.82 ) X-BeenThere: barebox@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "barebox" X-SA-Exim-Connect-IP: 2607:7c80:54:3::133 X-SA-Exim-Mail-From: barebox-bounces+lore=pengutronix.de@lists.infradead.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on metis.whiteo.stw.pengutronix.de X-Spam-Level: X-Spam-Status: No, score=-6.0 required=4.0 tests=AWL,BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.2 Subject: [PATCH v2 26/30] mci: core: implement mmc_send_tuning X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on metis.whiteo.stw.pengutronix.de) For use by drivers that support eMMC standard tuning, add a new mmc_send_tuning helper that sends 64-128 bytes and checks the result for bit errors. Signed-off-by: Ahmad Fatoum --- drivers/mci/mci-core.c | 78 ++++++++++++++++++++++++++++++++++++++++++ include/mci.h | 1 + 2 files changed, 79 insertions(+) diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c index 5f0fdd2206a5..23cde58c0c5b 100644 --- a/drivers/mci/mci-core.c +++ b/drivers/mci/mci-core.c @@ -1607,6 +1607,84 @@ int mci_execute_tuning(struct mci *mci) return host->ops.execute_tuning(host, opcode); } +static const u8 tuning_blk_pattern_4bit[] = { + 0xff, 0x0f, 0xff, 0x00, 0xff, 0xcc, 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, +}; + +static const u8 tuning_blk_pattern_8bit[] = { + 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, + 0xff, 0xff, 0xcc, 0xcc, 0xcc, 0x33, 0xcc, 0xcc, + 0xcc, 0x33, 0x33, 0xcc, 0xcc, 0xcc, 0xff, 0xff, + 0xff, 0xee, 0xff, 0xff, 0xff, 0xee, 0xee, 0xff, + 0xff, 0xff, 0xdd, 0xff, 0xff, 0xff, 0xdd, 0xdd, + 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb, + 0xbb, 0xff, 0xff, 0xff, 0x77, 0xff, 0xff, 0xff, + 0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee, 0xff, + 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, + 0x00, 0xff, 0xff, 0xcc, 0xcc, 0xcc, 0x33, 0xcc, + 0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc, 0xcc, 0xff, + 0xff, 0xff, 0xee, 0xff, 0xff, 0xff, 0xee, 0xee, + 0xff, 0xff, 0xff, 0xdd, 0xff, 0xff, 0xff, 0xdd, + 0xdd, 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff, 0xff, + 0xbb, 0xbb, 0xff, 0xff, 0xff, 0x77, 0xff, 0xff, + 0xff, 0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee, +}; + +int mmc_send_tuning(struct mci *mci, u32 opcode) +{ + struct mci_cmd cmd = {}; + struct mci_data data = {}; + const u8 *tuning_block_pattern; + int size, err = 0; + u8 *data_buf; + + if (mci->host->ios.bus_width == MMC_BUS_WIDTH_8) { + tuning_block_pattern = tuning_blk_pattern_8bit; + size = sizeof(tuning_blk_pattern_8bit); + } else if (mci->host->ios.bus_width == MMC_BUS_WIDTH_4) { + tuning_block_pattern = tuning_blk_pattern_4bit; + size = sizeof(tuning_blk_pattern_4bit); + } else + return -EINVAL; + + data_buf = calloc(size, 1); + if (!data_buf) + return -ENOMEM; + + mci_setup_cmd(&cmd, opcode, 0, MMC_RSP_R1 | MMC_CMD_ADTC); + + + data.blocksize = size; + data.blocks = 1; + data.flags = MMC_DATA_READ; + + /* + * According to the tuning specs, Tuning process + * is normally shorter 40 executions of CMD19, + * and timeout value should be shorter than 150 ms + */ + data.timeout_ns = 150 * NSEC_PER_MSEC; + + err = mci_send_cmd(mci, &cmd, &data); + if (err) + goto out; + + if (memcmp(data_buf, tuning_block_pattern, size)) + err = -EIO; + +out: + free(data_buf); + return err; +} +EXPORT_SYMBOL_GPL(mmc_send_tuning); + int mci_send_abort_tuning(struct mci *mci, u32 opcode) { struct mci_cmd cmd = {}; diff --git a/include/mci.h b/include/mci.h index 29aaecb46305..207fb9779a14 100644 --- a/include/mci.h +++ b/include/mci.h @@ -773,6 +773,7 @@ static inline int mmc_card_hs(struct mci *mci) */ int mmc_hs200_tuning(struct mci *mci); int mci_execute_tuning(struct mci *mci); +int mmc_send_tuning(struct mci *mci, u32 opcode); int mci_send_abort_tuning(struct mci *mci, u32 opcode); int mmc_select_timing(struct mci *mci); int mci_set_blockcount(struct mci *mci, unsigned int cmdarg); -- 2.39.5