Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp10705008rwp; Fri, 21 Jul 2023 03:46:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlGnKeCTaLcoCkaOMkYLtN8yFxNAUk0c+0FGQVFqx4FUwLEGApN0OTMEYiAu1r114J8JY0yF X-Received: by 2002:a17:902:8692:b0:1af:ffda:855a with SMTP id g18-20020a170902869200b001afffda855amr1267789plo.9.1689936417831; Fri, 21 Jul 2023 03:46:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689936417; cv=none; d=google.com; s=arc-20160816; b=BLSatpyOjEpQW7vcl80APGCr4i0u8QLY5/+QwfSsjZ4xXBAh7R7BkrQzRFqVSX+Gpb 1s41egaBqPm8LK5jMi1wpaFt6+heRZfgrrF6MM+AbYP5c0RNE65AyN1AVYzZvR38wQtm Vc4YE+ogaKZJpDGI+ZXLPzfZULT/Luf//+ctXuOda7EVmdZVaXPSpTvQhnx15zD1mlDP M/SaNvWMEHYrZc89XT9rv3l0jHjvFeBq5wOI95+21ZMSNGqpbZAxFruz8xkCqP4O9v6r wghVYpSf0FixC5OqHZ3rBTMePLkVakSDX4D7FV0T/h4hVloKo0mNO80+BK2FoQqbIkP6 dyBg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id la5-20020a170902fa0500b001b9d5fb7fc8si2704558plb.101.2023.07.21.03.46.40; Fri, 21 Jul 2023 03:46:57 -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 S231993AbjGUKQr (ORCPT + 99 others); Fri, 21 Jul 2023 06:16:47 -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 Content-Transfer-Encoding: 8bit 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 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; } -- 2.25.1