Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6295362iob; Tue, 10 May 2022 15:10:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqAGfrFQrKN4SFogPQkw15k9jam2jj86wnMIsXLRwTM5ZQbBlrr+DLUYDNxR+N6WHeLqv7 X-Received: by 2002:a63:4d17:0:b0:3da:eda2:444a with SMTP id a23-20020a634d17000000b003daeda2444amr3815831pgb.180.1652220649100; Tue, 10 May 2022 15:10:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652220649; cv=none; d=google.com; s=arc-20160816; b=Z4MzxkpXY8620F5/m5/9VLnsQ1SCOpb9J71rMtOKxI0lQWWlKdPLd9EVlVhFQ1Svwf iENppCs2sU+NnNo0fd9YLnt5YE3T/qo4hL6WLlSHsyn8+QNpERxO/kV4PdoZ5vSSnTEW s4RAvquK5XUHLFVJxpfNDmuH1pq7jWAEer932GXwgtY7ZfNxJ0wd//msJFQfgZSl5aLa CybFBT/O/YCngrwrxPEyoc/hAf3KTelAQiJTRAdfLExYybr+d9nqtLX0ONhWVfxPa5R3 DytA1iEYqAere5mXHSsLqXDnJQUwHR501CRYGsvZa2VeKD3HUgnob6r7BEfjMqCazj09 6B1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kqRO+rkhqrEL1NfppnpjByDNNT8ZfK3tuj+FoUprP9I=; b=nnDJE8vAAv6xyhBTgsFvII7cmF08//mDBrFBRgCeWriVdqP4mNBmeUxq1CLMGhBLsd nVY+EEG7xTkFvitNHJcDe8Lplq9/M4CAZWWvF5ISeFqEQ7WT9/zVGF8z0y4Ho2VziR4a bswofL9rE4aEr3o17jsC73LxX39UMSd+wO2i/r9qiOiZfNBkLqPbHvhROCf9QZtxK1sI nm0Wxq8IKrPs9XNnj9s46xu+NLVLHwAq1yy0WQrQrjLNnVgitE3tTldF+40iEENc9juY GqAeQNzAFLqcXRkowx1Ifkt5dI2Le7PFIZR6H4CFAozkhb0j7OUGDSqq5rwg89BwqNSD Fxrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JEhNtssU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ic6-20020a17090b414600b001dc72c6382csi3783345pjb.31.2022.05.10.15.10.35; Tue, 10 May 2022 15:10:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JEhNtssU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244452AbiEJNyk (ORCPT + 99 others); Tue, 10 May 2022 09:54:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244499AbiEJNhq (ORCPT ); Tue, 10 May 2022 09:37:46 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4B7F4615C; Tue, 10 May 2022 06:25:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AF44FB81DA8; Tue, 10 May 2022 13:25:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DDA25C385A6; Tue, 10 May 2022 13:25:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652189144; bh=SpTd5v1cKdnH4q4euKFNGaSYJ80pqSSMye9/X1Sbz20=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JEhNtssUoY7ywen4IqpjvK13mylwSPezYgbY6SCWmAvWySFADagt8CgDosfTrby8q CqzobM3x2V69ufi4Xlxzr3mGJoU7DC1wLw1Bk6GqOdOw2n79n1VDVU/ExZvaz1ZKJG Ob1M8tsD2dlMm/KUa42DOGZzoRdlphrqqQpbv1Q4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shawn Lin , Luca Weiss , Brian Norris , Ulf Hansson Subject: [PATCH 5.10 06/70] mmc: core: Set HS clock speed before sending HS CMD13 Date: Tue, 10 May 2022 15:07:25 +0200 Message-Id: <20220510130733.049928309@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220510130732.861729621@linuxfoundation.org> References: <20220510130732.861729621@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Brian Norris commit 4bc31edebde51fcf8ad0794763b8679a7ecb5ec0 upstream. Way back in commit 4f25580fb84d ("mmc: core: changes frequency to hs_max_dtr when selecting hs400es"), Rockchip engineers noticed that some eMMC don't respond to SEND_STATUS commands very reliably if they're still running at a low initial frequency. As mentioned in that commit, JESD84-B51 P49 suggests a sequence in which the host: 1. sets HS_TIMING 2. bumps the clock ("<= 52 MHz") 3. sends further commands It doesn't exactly require that we don't use a lower-than-52MHz frequency, but in practice, these eMMC don't like it. The aforementioned commit tried to get that right for HS400ES, although it's unclear whether this ever truly worked as committed into mainline, as other changes/refactoring adjusted the sequence in conflicting ways: 08573eaf1a70 ("mmc: mmc: do not use CMD13 to get status after speed mode switch") 53e60650f74e ("mmc: core: Allow CMD13 polling when switching to HS mode for mmc") In any case, today we do step 3 before step 2. Let's fix that, and also apply the same logic to HS200/400, where this eMMC has problems too. Resolves errors like this seen when booting some RK3399 Gru/Scarlet systems: [ 2.058881] mmc1: CQHCI version 5.10 [ 2.097545] mmc1: SDHCI controller on fe330000.mmc [fe330000.mmc] using ADMA [ 2.209804] mmc1: mmc_select_hs400es failed, error -84 [ 2.215597] mmc1: error -84 whilst initialising MMC card [ 2.417514] mmc1: mmc_select_hs400es failed, error -110 [ 2.423373] mmc1: error -110 whilst initialising MMC card [ 2.605052] mmc1: mmc_select_hs400es failed, error -110 [ 2.617944] mmc1: error -110 whilst initialising MMC card [ 2.835884] mmc1: mmc_select_hs400es failed, error -110 [ 2.841751] mmc1: error -110 whilst initialising MMC card Ealier versions of this patch bumped to 200MHz/HS200 speeds too early, which caused issues on, e.g., qcom-msm8974-fairphone-fp2. (Thanks for the report Luca!) After a second look, it appears that aligns with JESD84 / page 45 / table 28, so we need to keep to lower (HS / 52 MHz) rates first. Fixes: 08573eaf1a70 ("mmc: mmc: do not use CMD13 to get status after speed mode switch") Fixes: 53e60650f74e ("mmc: core: Allow CMD13 polling when switching to HS mode for mmc") Fixes: 4f25580fb84d ("mmc: core: changes frequency to hs_max_dtr when selecting hs400es") Cc: Shawn Lin Link: https://lore.kernel.org/linux-mmc/11962455.O9o76ZdvQC@g550jk/ Reported-by: Luca Weiss Signed-off-by: Brian Norris Tested-by: Luca Weiss Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20220422100824.v4.1.I484f4ee35609f78b932bd50feed639c29e64997e@changeid Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/core/mmc.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -1378,13 +1378,17 @@ static int mmc_select_hs400es(struct mmc goto out_err; } + /* + * Bump to HS timing and frequency. Some cards don't handle + * SEND_STATUS reliably at the initial frequency. + */ mmc_set_timing(host, MMC_TIMING_MMC_HS); + mmc_set_bus_speed(card); + err = mmc_switch_status(card, true); if (err) goto out_err; - mmc_set_clock(host, card->ext_csd.hs_max_dtr); - /* Switch card to DDR with strobe bit */ val = EXT_CSD_DDR_BUS_WIDTH_8 | EXT_CSD_BUS_WIDTH_STROBE; err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, @@ -1442,7 +1446,7 @@ out_err: static int mmc_select_hs200(struct mmc_card *card) { struct mmc_host *host = card->host; - unsigned int old_timing, old_signal_voltage; + unsigned int old_timing, old_signal_voltage, old_clock; int err = -EINVAL; u8 val; @@ -1473,8 +1477,17 @@ static int mmc_select_hs200(struct mmc_c false, true); if (err) goto err; + + /* + * Bump to HS timing and frequency. Some cards don't handle + * SEND_STATUS reliably at the initial frequency. + * NB: We can't move to full (HS200) speeds until after we've + * successfully switched over. + */ old_timing = host->ios.timing; + old_clock = host->ios.clock; mmc_set_timing(host, MMC_TIMING_MMC_HS200); + mmc_set_clock(card->host, card->ext_csd.hs_max_dtr); /* * For HS200, CRC errors are not a reliable way to know the @@ -1487,8 +1500,10 @@ static int mmc_select_hs200(struct mmc_c * mmc_select_timing() assumes timing has not changed if * it is a switch error. */ - if (err == -EBADMSG) + if (err == -EBADMSG) { + mmc_set_clock(host, old_clock); mmc_set_timing(host, old_timing); + } } err: if (err) {