From patchwork Fri Mar 31 10:55:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 77729 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp477608vqo; Fri, 31 Mar 2023 04:07:10 -0700 (PDT) X-Google-Smtp-Source: AKy350bKKcOYC4BHuIfZ1d8HfjA1z3OFVetgGe533UifhuGdYi/NJucT9APjMCYDoVgiKZZar8y4 X-Received: by 2002:a17:903:64b:b0:1a1:cc9d:3d55 with SMTP id kh11-20020a170903064b00b001a1cc9d3d55mr21650550plb.20.1680260830101; Fri, 31 Mar 2023 04:07:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680260830; cv=none; d=google.com; s=arc-20160816; b=ziyPTMTk72vcfzNXNKV9/Fdwu20yiF43OaEOmsh+Uav0MJXoM+rPjBXQ5MptX390lG tXv9d6Nk8nGXVD9p8KhDhW7OPMDKERdRt/Gfc2/22iu0vT5XyycfnybMSiHkMUbTzKYw RFdfMyJFoEUwtH/vItOVTr3A6BINncDXqRW5cr8rFNd7WLiVWi41zQymQU+8i2QS3nab eF5t0JX23QoV51k22LYZpu/NHis7X08KxseZSLN7myftZdUInPPGJwB00uQ2hhYXWQXt N5vhyKgcT4+Kk+7K6pP24/RZ2WtbvkqNbU0O8YAMPPjytfZ+nVZhgeolU7Sdunda8mn6 MEkA== 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=pcc2+sS71Kh88KtU/433SQ0C3GbsggZ0n9u9i4f8nKw=; b=VEjWo8Un5DU6bu9ObOIEd/upRCciBHBqk9YuusRPPX5MfAp9m8mqYybZ6VBTPRJKRE w7nR36EVfv6JQaKaLrd+vxAoBwPYqef83SApOkTaX+wzbI6xI6YFYgb0Px0qutZukSo0 gi8QPK7YCbq2/tyJr187fa26cKtCOmo5SzbwbxQKMSmvv6l4TBoGx+dOjwY1RtluCW+b tFbIvEprMWEOWGxLTGu4yBc1jBYbvf9R6BfvtSYQ8w2iwDBYuWpo2vBNVEFv42sfL3Fm bau8vmO1XxCIXPZs5hVHr9VlQaaIHOnQqfcWzOIHr9VNHJ7FN8VqOr7VxbefhKpXsPI0 lhtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YD9DpU2b; 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 u6-20020a170902e5c600b001a23cfb3517si1904621plf.359.2023.03.31.04.06.57; Fri, 31 Mar 2023 04:07:10 -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=20210112 header.b=YD9DpU2b; 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 S232021AbjCaK6o (ORCPT + 99 others); Fri, 31 Mar 2023 06:58:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231464AbjCaK5P (ORCPT ); Fri, 31 Mar 2023 06:57:15 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 794661D85E; Fri, 31 Mar 2023 03:56:51 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id ja10so20872848plb.5; Fri, 31 Mar 2023 03:56:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680260211; 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=pcc2+sS71Kh88KtU/433SQ0C3GbsggZ0n9u9i4f8nKw=; b=YD9DpU2b/jVawT1SbE0ATgh1rbUv4kzpx4mAwToL/9YybPrcKX0cvIuqVspHkZGnHx YkW3MzuABLspV+Om0zt/x/1jteVmrmlj/Rp6l7T6goyIdtvNUpr4gjnkkoIKZmzM6LA8 Hkyg55ZsEvlSgJJEfZoTmzZWTlDA/YXKjhcTNjjnC16CnuktVBArIabXCoNVKr+Z0KGD FdYtnAUKyJGO3z0QPbhWVbOENg//QOSuBLrnZu5oxb4IEidGcrzOJABCC2zcqHivNEzs ibnyFmbRrpOkoRlSo5CkA3t5zWUc4xP+T5CcHA3RDyzOUgW9IOO1WtSYTTYVGMg2tcHd aToA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680260211; 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=pcc2+sS71Kh88KtU/433SQ0C3GbsggZ0n9u9i4f8nKw=; b=fx07sgt8UJjB6dWbbuma9ixo51sp5vm24d7VYzZNdNuMzUiE5leKZCoSlgEas8P7k5 dmr+8ceM45uJhTUTPcb+/7HDyPFfeNFjWNkOd6A04ot5C2Fm2y14avT/mH5aPxaW1R0D TgWvoIkZBzGQ0CX5ymDBwoWnlwZJdnDpmfJAvu5hyj1rea/AY4Bioiquy5muGlU9j1iR /lv6g9W9crAwyuKB1E3ULcs/w1Q+LQsl+h09xjuAxGwLJaSD+wWPUUhveva2X4x1AHbs 5f4PuCYnCrQSpVPVVBA076K4m+JfBROZq19vx/3zNUY728JtRT36/mb08Qu9qedDKDp8 O4ug== X-Gm-Message-State: AAQBX9cOItUb/Cdf6Jac3RT5wHTEl0ZVXQotUuUvRY1JlxU2SM4yVjl3 NnCh/6BtQXQTQJXk061x8s43ymPXkQE= X-Received: by 2002:a17:903:28ce:b0:1a0:6852:16e9 with SMTP id kv14-20020a17090328ce00b001a0685216e9mr20832732plb.14.1680260211068; Fri, 31 Mar 2023 03:56:51 -0700 (PDT) Received: from localhost.localdomain (2001-b400-e25c-983f-c7ff-3efd-77d9-6c16.emome-ip6.hinet.net. [2001:b400:e25c:983f:c7ff:3efd:77d9:6c16]) by smtp.gmail.com with ESMTPSA id f19-20020a170902e99300b0019acd3151d0sm1287665plb.114.2023.03.31.03.56.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 03:56:50 -0700 (PDT) From: Victor Shih X-Google-Original-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 Subject: [PATCH V7 17/23] mmc: sdhci-uhs2: add uhs2_control() to initialise the interface Date: Fri, 31 Mar 2023 18:55:40 +0800 Message-Id: <20230331105546.13607-18-victor.shih@genesyslogic.com.tw> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230331105546.13607-1-victor.shih@genesyslogic.com.tw> References: <20230331105546.13607-1-victor.shih@genesyslogic.com.tw> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761881180106478951?= X-GMAIL-MSGID: =?utf-8?q?1761881180106478951?= 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 --- drivers/mmc/host/sdhci-uhs2.c | 89 +++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index 71ac76065886..6fe394b1a7be 100644 --- a/drivers/mmc/host/sdhci-uhs2.c +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -278,6 +278,49 @@ 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 + 0); + 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) +{ + u32 val; + /* 100ms */ + int timeout = 100000; + + if (read_poll_timeout_atomic(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 * @@ -360,6 +403,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 * @@ -487,6 +575,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; }