Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2918579imm; Fri, 19 Oct 2018 01:49:32 -0700 (PDT) X-Google-Smtp-Source: ACcGV636njp9wMPjZyzSLhGPJXFtKCPZj+n1UfVxz3WuldX5KYL1iPVVqgedFV28q742/R23Z1SM X-Received: by 2002:a17:902:7408:: with SMTP id g8-v6mr2650597pll.168.1539938972335; Fri, 19 Oct 2018 01:49:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539938972; cv=none; d=google.com; s=arc-20160816; b=bEbnFwCzbabXcjEMFzzk+LOKdnQanCjJW4b7JyiNcJSqCQ0AcF6GFW1JXnT0hv5PqV uURr06zckLjXBLGci+60lxhTt9NhWIuZ5dx4OrDhswpKaxdiTjkk9e4W2yDAVtmTYCvo bJSRAOCy2lQsQf+2/kZmVeSP1WEEHFB4yUC4ZBbVv8i8dMz2UbjDCFmd4ddLFc+ARQmn ibi/O1q+/Znave+8whmcVUCfU2Dq2IrNSVbK4yWpXIQI/6X8X8yCYTmiQYDFtJOFMnlD Io6m3Q9/IJ3C4yXMpy0VM+CPx5uBdca3ZRRNsOyOqPo6jwgqyWp6pR3B8ezfqccAsojX pFUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject :dkim-signature; bh=5PyWh3DIEuBD6OjiJ2xlnGiXa4cwft71UmBzEHvO/uU=; b=lpa+CFy3PVb0LK8Jx25NaVa73qhzOMaGK6vYkX2wVJHsy94HLbv35ZFLN8/pi10IuI BRIf/W8YQJPCtrnbPjnlIZRDawQKcICZ9W3reZintBW6K4XiVILWEyESYQX+mmZPlwM+ NayYziJpi8sy6M99WWyKd8HH5OD3/Hg4PqPRfjeAOFMpFVBHFHDufTCyrY+knUnEsm1K WrIV3ptaXWi1PUxlQNIke3Em8I93/fhUekbpI2djwWiEp68WcxN4jm0+kxsCZfuU52yS 7pa6BrE85pysW8RTLwMFKCugATWBHdzA5ntYg/idFxY3oADH+m1RNIeY2GhPI81I1nqa NDAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iBlAsMHx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d185-v6si18324482pfd.260.2018.10.19.01.49.16; Fri, 19 Oct 2018 01:49:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iBlAsMHx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727061AbeJSQyC (ORCPT + 99 others); Fri, 19 Oct 2018 12:54:02 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:37750 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726609AbeJSQyB (ORCPT ); Fri, 19 Oct 2018 12:54:01 -0400 Received: by mail-ed1-f68.google.com with SMTP id c22-v6so30727558edc.4; Fri, 19 Oct 2018 01:48:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=5PyWh3DIEuBD6OjiJ2xlnGiXa4cwft71UmBzEHvO/uU=; b=iBlAsMHx83RS+Zo/l0iw7lUsi9736TWRovFCzM13och+j3i2exMMHmaKjpoVfo7yhC NCd2jIZ3aoRM4l4l11suieR5SvyBVdcWFJDw1Z71ziyTlZ3CwpZcJETVhaIFAtHkRdut oZrIX8egmaMSfWnu6ZIxU+ulbNEeBzAcepHhXM0NUK3LDJTt6pBsaKkWdpGlvWlD0c/0 RoOdq/7KU1gYu2xz4qkHVkkH45lvE8l6IIEV7408wSRqPdfG6kgKlJ1mAZcDcugdY9/Z ZAR/Kesje2t5BaYjA/JU317YpbRfiKSWuR9BXNZpEW7Y+rEyT6CtcuuA3bWKDaU2x2ip tKmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=5PyWh3DIEuBD6OjiJ2xlnGiXa4cwft71UmBzEHvO/uU=; b=AreCdqhrZ3SKiBCAjkIkK1Uu/1+7jqD7PoI4V2KfHh7pJpwyn2bOmBIJAk4inrKrJX v190FFJbpCwHZzwhsB491Nm9p2NcF1kdQXopyl8zcJoSdD71BkPXKZsO5DU5S2/zjYqY gegwWEMww/8L5VivfXBhCdMbUrJDbv5w/SKWJmUzZcCIYEfAi4ApfUcDeTh2fWroBjmK DNyt2lunK56TxbWJ5xAZsvJNQnwyqmYTd0PydZykOa7tzvysC4V5gkhMBUNCeknfjtPG zcUGYJpigSM2vR1YcxYqu8W4nzhHi3sq2JRzi6jU4Pet+A0Or/OCZMfytUH7SgJq68g3 2XHg== X-Gm-Message-State: ABuFfoj0ZUM+n7vosjYZCQ/xLf71ROze9nwPitXz3t8R0S2ZB38s7EBg icNysk2xR2OtqW7ggdQ8ZMM= X-Received: by 2002:a05:6402:6d8:: with SMTP id n24mr5191553edy.99.1539938931516; Fri, 19 Oct 2018 01:48:51 -0700 (PDT) Received: from ziggy.stardust ([93.176.144.101]) by smtp.gmail.com with ESMTPSA id s46-v6sm10692662edb.49.2018.10.19.01.48.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 01:48:50 -0700 (PDT) Subject: Re: [PATCH 4/6] mmc: mediatek: tune CMD/DATA together To: Chaotian Jing , Ulf Hansson Cc: Rob Herring , Mark Rutland , Ryder Lee , Wolfram Sang , Sean Wang , linux-mmc@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, srv_heupstream@mediatek.com, jjian.zhou@mediatek.com, wenbin.mei@mediatek.com References: <1539415250-32337-1-git-send-email-chaotian.jing@mediatek.com> <1539415250-32337-5-git-send-email-chaotian.jing@mediatek.com> From: Matthias Brugger Openpgp: preference=signencrypt Autocrypt: addr=matthias.bgg@gmail.com; prefer-encrypt=mutual; keydata= xsFNBFP1zgUBEAC21D6hk7//0kOmsUrE3eZ55kjc9DmFPKIz6l4NggqwQjBNRHIMh04BbCMY fL3eT7ZsYV5nur7zctmJ+vbszoOASXUpfq8M+S5hU2w7sBaVk5rpH9yW8CUWz2+ZpQXPJcFa OhLZuSKB1F5JcvLbETRjNzNU7B3TdS2+zkgQQdEyt7Ij2HXGLJ2w+yG2GuR9/iyCJRf10Okq gTh//XESJZ8S6KlOWbLXRE+yfkKDXQx2Jr1XuVvM3zPqH5FMg8reRVFsQ+vI0b+OlyekT/Xe 0Hwvqkev95GG6x7yseJwI+2ydDH6M5O7fPKFW5mzAdDE2g/K9B4e2tYK6/rA7Fq4cqiAw1+u EgO44+eFgv082xtBez5WNkGn18vtw0LW3ESmKh19u6kEGoi0WZwslCNaGFrS4M7OH+aOJeqK fx5dIv2CEbxc6xnHY7dwkcHikTA4QdbdFeUSuj4YhIZ+0QlDVtS1QEXyvZbZky7ur9rHkZvP ZqlUsLJ2nOqsmahMTIQ8Mg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TwWC3HpE/D9sM+xACs803lFUIZC5H62G059cCPAXKgsFpNMKmBAWweBkVJAisoQeX 50OP+/11ArV0cv+fOTfJj0/KwFXJaaYh3LUQNILLBNxkSrhCLl8dUg53IbHx4NfIAgqxLWGf XM8DY1aFdU79pac005PuhxCWkKTJz3gCmznnoat4GCnL5gy/m0Qk45l4PFqwWXVLo9AQg2Kp 3mlIFZ6fsEKIAN5hxlbNvNb9V2Zo5bFZjPWPFTxOteM0omUAS+QopwU0yPLLGJVf2iCmItHc UXI+r2JwH1CJjrHWeQEI2ucSKsNa8FllDmG/fQ== Message-ID: <51d95ab5-896e-c386-7a3e-362e8a3c2960@gmail.com> Date: Fri, 19 Oct 2018 10:46:38 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <1539415250-32337-5-git-send-email-chaotian.jing@mediatek.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13/10/2018 09:20, Chaotian Jing wrote: > for MSDC IP which supports both data tune and async fifo, it can > tune cmd/data together. which can save the time and make the tune > result of CMD more stable as data line are 4bit or 8bit. > > Signed-off-by: Chaotian Jing > --- > drivers/mmc/host/mtk-sd.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 87 insertions(+) > > diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c > index fe80a1d..09d7e44 100644 > --- a/drivers/mmc/host/mtk-sd.c > +++ b/drivers/mmc/host/mtk-sd.c > @@ -1773,12 +1773,98 @@ static int msdc_tune_data(struct mmc_host *mmc, u32 opcode) > return final_delay == 0xff ? -EIO : 0; > } > > +/* > + * MSDC IP which supports data tune + async fifo can do CMD/DAT tune > + * together, which can save the tuning time. > + */ > +static int msdc_tune_together(struct mmc_host *mmc, u32 opcode) > +{ > + struct msdc_host *host = mmc_priv(mmc); > + u32 rise_delay = 0, fall_delay = 0; > + struct msdc_delay_phase final_rise_delay, final_fall_delay = { 0,}; > + u8 final_delay, final_maxlen; > + u32 tune_reg = host->dev_comp->pad_tune_reg; > + int i, ret; > + > + sdr_set_field(host->base + MSDC_PATCH_BIT, MSDC_INT_DAT_LATCH_CK_SEL, > + host->latch_ck); > + > + sdr_clr_bits(host->base + MSDC_IOCON, MSDC_IOCON_RSPL); > + sdr_clr_bits(host->base + MSDC_IOCON, > + MSDC_IOCON_DSPL | MSDC_IOCON_W_DSPL); > + for (i = 0 ; i < PAD_DELAY_MAX; i++) { > + sdr_set_field(host->base + tune_reg, > + MSDC_PAD_TUNE_CMDRDLY, i); > + sdr_set_field(host->base + tune_reg, > + MSDC_PAD_TUNE_DATRRDLY, i); > + ret = mmc_send_tuning(mmc, opcode, NULL); > + if (!ret) > + rise_delay |= (1 << i); > + } > + final_rise_delay = get_best_delay(host, rise_delay); > + /* if rising edge has enough margin, then do not scan falling edge */ > + if (final_rise_delay.maxlen >= 12 || > + (final_rise_delay.start == 0 && final_rise_delay.maxlen >= 4)) > + goto skip_fall; > + > + sdr_set_bits(host->base + MSDC_IOCON, MSDC_IOCON_RSPL); > + sdr_set_bits(host->base + MSDC_IOCON, > + MSDC_IOCON_DSPL | MSDC_IOCON_W_DSPL); > + for (i = 0; i < PAD_DELAY_MAX; i++) { > + sdr_set_field(host->base + tune_reg, > + MSDC_PAD_TUNE_CMDRDLY, i); > + sdr_set_field(host->base + tune_reg, > + MSDC_PAD_TUNE_DATRRDLY, i); > + ret = mmc_send_tuning(mmc, opcode, NULL); > + if (!ret) > + fall_delay |= (1 << i); > + } > + final_fall_delay = get_best_delay(host, fall_delay); > + > +skip_fall: > + final_maxlen = max(final_rise_delay.maxlen, final_fall_delay.maxlen); > + if (final_maxlen == final_rise_delay.maxlen) { > + sdr_clr_bits(host->base + MSDC_IOCON, MSDC_IOCON_RSPL); > + sdr_clr_bits(host->base + MSDC_IOCON, > + MSDC_IOCON_DSPL | MSDC_IOCON_W_DSPL); > + sdr_set_field(host->base + tune_reg, MSDC_PAD_TUNE_CMDRDLY, > + final_rise_delay.final_phase); > + sdr_set_field(host->base + tune_reg, > + MSDC_PAD_TUNE_DATRRDLY, > + final_rise_delay.final_phase); > + final_delay = final_rise_delay.final_phase; > + } else { > + sdr_set_bits(host->base + MSDC_IOCON, MSDC_IOCON_RSPL); > + sdr_set_bits(host->base + MSDC_IOCON, > + MSDC_IOCON_DSPL | MSDC_IOCON_W_DSPL); > + sdr_set_field(host->base + tune_reg, MSDC_PAD_TUNE_CMDRDLY, > + final_fall_delay.final_phase); > + sdr_set_field(host->base + tune_reg, > + MSDC_PAD_TUNE_DATRRDLY, > + final_fall_delay.final_phase); > + final_delay = final_fall_delay.final_phase; > + } > + > + dev_dbg(host->dev, "Final pad delay: %x\n", final_delay); > + return final_delay == 0xff ? -EIO : 0; > +} > + > static int msdc_execute_tuning(struct mmc_host *mmc, u32 opcode) > { > struct msdc_host *host = mmc_priv(mmc); > int ret; > u32 tune_reg = host->dev_comp->pad_tune_reg; > > + if (host->dev_comp->data_tune && host->dev_comp->async_fifo) { > + ret = msdc_tune_together(mmc, opcode); > + if (host->hs400_mode) { > + sdr_clr_bits(host->base + MSDC_IOCON, > + MSDC_IOCON_DSPL | MSDC_IOCON_W_DSPL); > + sdr_set_field(host->base + tune_reg, > + MSDC_PAD_TUNE_DATRRDLY, 0); > + } > + goto tune_done; > + } > if (host->hs400_mode && Couldn't we put a else if here instead of using a goto? Regards, Matthias > host->dev_comp->hs400_tune) > ret = hs400_tune_response(mmc, opcode); > @@ -1794,6 +1880,7 @@ static int msdc_execute_tuning(struct mmc_host *mmc, u32 opcode) > dev_err(host->dev, "Tune data fail!\n"); > } > > +tune_done: > host->saved_tune_para.iocon = readl(host->base + MSDC_IOCON); > host->saved_tune_para.pad_tune = readl(host->base + tune_reg); > host->saved_tune_para.pad_cmd_tune = readl(host->base + PAD_CMD_TUNE); >