From patchwork Fri Jul 21 10:13:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 123775 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp114563vqg; Fri, 21 Jul 2023 03:46:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlGHrgTWenbFeQc2NcIReQ0J8QidfpbKfMhlWQeA2wFMjmQrll3VMUHByY0wcGBRIQ5ttLHs X-Received: by 2002:a05:6870:b681:b0:1b3:8cfb:78c5 with SMTP id cy1-20020a056870b68100b001b38cfb78c5mr1618922oab.34.1689936402764; Fri, 21 Jul 2023 03:46:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689936402; cv=none; d=google.com; s=arc-20160816; b=T8urpsWIlnGmYRr+qZomOrC8NMiaXhRzLLeOmHJlFSuKnDJm/vXDoYwUI7lueuaB2B wdB5BItsKZotWKHyZQWeo8YA+QlmB+hjBg+GYD9xEcefTr8g0PVuaUkMPUKFgqlY22oQ 7TmlrbHkTqlEXDdYlxo4k1TNWCisnexX1ympt0WbHUcVzwS41xyydh+8uT2mc0076G1v 1jhUEUeQ8UQCP8jijPtkYigX1OcL7DtDAj7psJJbp43zvXHJctKwBpmoVOUfLfk+2OM3 zo9fm98E2OSk50sRWLN2XFw/yUDfiixj8zqPCpmcTrpaEC7VDli2Za9HvNA9IztyAEZz n+jg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=x+8qMzQWLf1maBEd9CYn7OGN6iIICRaUvOvwh/uO7uw=; fh=fI4q009785iZEQbMo9mPiCtk2O+O6Kfjq5womanK3eI=; b=c5GXZB6kOSYZZ8VYxPLaUGSlV1S0e4U3N2Zv67OTs3pw91c8aO9K5OJYA0BW5chiY4 xPVs5Mqd2H9GGVzeIwRm8G57Ss0ewNLEIcqWqicw2ilauqewaDU9P/Jsapj2YhN4xMMI mZtZUF+Dver3IKSjRYAB0Sf8YZucz1fBpJTtA//eO7mgRayV3QzaTp1TnXrBn9TkOeuM /TF9jlTHRPEEAToenjrs/vlwl/1tGApp2aTMhln8AeHnrGxk2ugZKnvJEEm/q6KTURZX Rxrdmc5GZkAaH8OCelhJlBPWjsiSuMga1fHFqhlw5hS0RbARW3awOyIurQn1DJvcKyr7 FH4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=MdN2otZX; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u14-20020a62790e000000b0067a5e89333esi2720748pfc.101.2023.07.21.03.46.28; Fri, 21 Jul 2023 03:46:42 -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=@gmail.com header.s=20221208 header.b=MdN2otZX; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229903AbjGUKQs (ORCPT + 99 others); Fri, 21 Jul 2023 06:16:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232038AbjGUKQN (ORCPT ); Fri, 21 Jul 2023 06:16:13 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90C283C06; Fri, 21 Jul 2023 03:15:19 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1b9cd6a0051so11929465ad.1; Fri, 21 Jul 2023 03:15:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689934508; x=1690539308; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=x+8qMzQWLf1maBEd9CYn7OGN6iIICRaUvOvwh/uO7uw=; b=MdN2otZXH1LMRI+7W5sZsBg1T0Mj5nQyYTpKZ3eBBglvOhnGaySVbN3hiP5Cs6q/XY SyMbTJVTyH11mSuvB0mshqL7/bpDmFK/AAxyp6Sn6ucGgjE/1bHK7YO97WjxGetl6g5r Gqp7X6E8AEJtmK/L4NzR5R2ijHuhvpLwA2PkQQSspUqhqDq5XuqULrWDAZmIHygvVkEd xcl1ybGKAkonwUh1WBk6wLOk1RaMlLlbxMx6ih3kIW50ToKPV8Pc/9XMJRXyGgBofT6T MivTztPV1gFPiEFc2IVWVa+8yZoSzjXJiv404ZmUvSKHJ1BRCfglbA53dFMyPV2NduHC vYXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689934508; x=1690539308; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x+8qMzQWLf1maBEd9CYn7OGN6iIICRaUvOvwh/uO7uw=; b=RnYdbUYg/3hCVByPj88eNSQGhJBIAZBnYIippQxKxSmvsQQgck8+osliqKTNqZkpT5 SeZn7cq8o9Yu7bLbDQSsBQyCmvoUpd9qRSESFOMGRsvPRX8bpo5yXEbHRJTUaLRXKV2d VsyFzvJ7ABW29KfPqiH1zq/rdt7Oih6Kwo7XCOdmuIQ2IMHsB9FgEkqDbtXr1IYlmQj+ i6zFnA5o/Szs4AHxpGgm8NcWLDI8EUlJGYIwQjnHiBzwOSyy/YrQ9+RhAX5haJv6Z2HP xylDXwjY0FurUoTxQNLwjd3tjFZ4stxfiOVjK4u7f5nVh6NUm+rvdoVAY1HB++1Ju58P jJhg== X-Gm-Message-State: ABy/qLaLWU+1XFUExmvJk/8z54/vBALsq75WS9DYiJU844MOWBRe8Rps shZeAxlClMIjRP/M7vDNuzs= X-Received: by 2002:a17:902:ea0b:b0:1b9:e399:4c8d with SMTP id s11-20020a170902ea0b00b001b9e3994c8dmr1324625plg.3.1689934507856; Fri, 21 Jul 2023 03:15:07 -0700 (PDT) Received: from localhost.localdomain (2001-b400-e23e-6b0d-6c46-3684-497a-06ee.emome-ip6.hinet.net. [2001:b400:e23e:6b0d:6c46:3684:497a:6ee]) by smtp.gmail.com with ESMTPSA id y1-20020a170902b48100b001b86492d724sm3050719plr.223.2023.07.21.03.15.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 03:15:07 -0700 (PDT) From: Victor Shih To: ulf.hansson@linaro.org, adrian.hunter@intel.com Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, benchuanggli@gmail.com, HL.Liu@genesyslogic.com.tw, Greg.tu@genesyslogic.com.tw, takahiro.akashi@linaro.org, dlunev@chromium.org, Victor Shih , Ben Chuang , Victor Shih Subject: [PATCH V9 17/23] mmc: sdhci-uhs2: add uhs2_control() to initialise the interface Date: Fri, 21 Jul 2023 18:13:43 +0800 Message-Id: <20230721101349.12387-18-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230721101349.12387-1-victorshihgli@gmail.com> References: <20230721101349.12387-1-victorshihgli@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772026753197958943 X-GMAIL-MSGID: 1772026753197958943 From: Victor Shih This is a sdhci version of mmc's uhs2_set_reg operation. UHS-II interface (related registers) will be initialised here. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Signed-off-by: Victor Shih --- Updates in V8: - Reorder the definitions and lose the parentheses in sdhci_uhs2_set_config(). - read_poll_timeout() to instead of read_poll_timeout_atomic() in sdhci_uhs2_check_dormant(). Updates in V7: - Remove unnecessary function. Updates in V6: - Remove unnecessary function. - Remove unnecessary parameter when call the DBG(). - Cancel export state of some functions. --- drivers/mmc/host/sdhci-uhs2.c | 88 +++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index af1b0c5e48fd..09b86fec9f7b 100644 --- a/drivers/mmc/host/sdhci-uhs2.c +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -278,6 +278,48 @@ static void __sdhci_uhs2_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) sdhci_set_clock(host, host->clock); } +static void sdhci_uhs2_set_config(struct sdhci_host *host) +{ + u32 value; + u16 sdhci_uhs2_set_ptr = sdhci_readw(host, SDHCI_UHS2_SETTINGS_PTR); + u16 sdhci_uhs2_gen_set_reg = sdhci_uhs2_set_ptr; + u16 sdhci_uhs2_phy_set_reg = sdhci_uhs2_set_ptr + 4; + u16 sdhci_uhs2_tran_set_reg = sdhci_uhs2_set_ptr + 8; + u16 sdhci_uhs2_tran_set_1_reg = sdhci_uhs2_set_ptr + 12; + + /* Set Gen Settings */ + value = FIELD_PREP(SDHCI_UHS2_GEN_SETTINGS_N_LANES_MASK, host->mmc->uhs2_caps.n_lanes_set); + sdhci_writel(host, value, sdhci_uhs2_gen_set_reg); + + /* Set PHY Settings */ + value = FIELD_PREP(SDHCI_UHS2_PHY_N_LSS_DIR_MASK, host->mmc->uhs2_caps.n_lss_dir_set) | + FIELD_PREP(SDHCI_UHS2_PHY_N_LSS_SYN_MASK, host->mmc->uhs2_caps.n_lss_sync_set); + if (host->mmc->ios.timing == MMC_TIMING_UHS2_SPEED_B || + host->mmc->ios.timing == MMC_TIMING_UHS2_SPEED_B_HD) + value |= SDHCI_UHS2_PHY_SET_SPEED_B; + sdhci_writel(host, value, sdhci_uhs2_phy_set_reg); + + /* Set LINK-TRAN Settings */ + value = FIELD_PREP(SDHCI_UHS2_TRAN_RETRY_CNT_MASK, host->mmc->uhs2_caps.max_retry_set) | + FIELD_PREP(SDHCI_UHS2_TRAN_N_FCU_MASK, host->mmc->uhs2_caps.n_fcu_set); + sdhci_writel(host, value, sdhci_uhs2_tran_set_reg); + sdhci_writel(host, host->mmc->uhs2_caps.n_data_gap_set, sdhci_uhs2_tran_set_1_reg); +} + +static int sdhci_uhs2_check_dormant(struct sdhci_host *host) +{ + int timeout = 100000; /* 100ms */ + u32 val; + + if (read_poll_timeout(sdhci_readl, val, (val & SDHCI_UHS2_IN_DORMANT_STATE), + 100, timeout, true, host, SDHCI_PRESENT_STATE)) { + pr_warn("%s: UHS2 IN_DORMANT fail in 100ms.\n", mmc_hostname(host->mmc)); + sdhci_dumpregs(host); + return -EIO; + } + return 0; +} + /*****************************************************************************\ * * * MMC callbacks * @@ -359,6 +401,51 @@ static int sdhci_uhs2_enable_clk(struct mmc_host *mmc) return 0; } +static int sdhci_uhs2_do_detect_init(struct mmc_host *mmc); + +static int sdhci_uhs2_control(struct mmc_host *mmc, enum sd_uhs2_operation op) +{ + struct sdhci_host *host = mmc_priv(mmc); + struct mmc_ios *ios = &mmc->ios; + int err = 0; + + DBG("Begin uhs2 control, act %d.\n", op); + + switch (op) { + case UHS2_PHY_INIT: + err = sdhci_uhs2_do_detect_init(mmc); + break; + case UHS2_SET_CONFIG: + sdhci_uhs2_set_config(host); + break; + case UHS2_ENABLE_INT: + sdhci_uhs2_clear_set_irqs(host, 0, SDHCI_INT_CARD_INT); + break; + case UHS2_DISABLE_INT: + sdhci_uhs2_clear_set_irqs(host, SDHCI_INT_CARD_INT, 0); + break; + case UHS2_CHECK_DORMANT: + err = sdhci_uhs2_check_dormant(host); + break; + case UHS2_DISABLE_CLK: + err = sdhci_uhs2_disable_clk(mmc); + break; + case UHS2_ENABLE_CLK: + err = sdhci_uhs2_enable_clk(mmc); + break; + case UHS2_SET_IOS: + err = sdhci_uhs2_set_ios(mmc, ios); + break; + default: + pr_err("%s: input sd uhs2 operation %d is wrong!\n", + mmc_hostname(host->mmc), op); + err = -EIO; + break; + } + + return err; +} + /*****************************************************************************\ * * * Driver init/exit * @@ -481,6 +568,7 @@ static int sdhci_uhs2_host_ops_init(struct sdhci_host *host) { host->mmc_host_ops.start_signal_voltage_switch = sdhci_uhs2_start_signal_voltage_switch; + host->mmc_host_ops.uhs2_control = sdhci_uhs2_control; return 0; }