From patchwork Fri Mar 31 10:55:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 77740 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp479416vqo; Fri, 31 Mar 2023 04:10:13 -0700 (PDT) X-Google-Smtp-Source: AKy350bGAZEbzHjmUcgWpcLAA9VHVvTKyObAfiiUMWA0R/T064OBugClyjhMz2gtNk7P9t9ELjqP X-Received: by 2002:a05:6a20:b394:b0:e4:9f3c:21f3 with SMTP id eg20-20020a056a20b39400b000e49f3c21f3mr645353pzb.35.1680261013626; Fri, 31 Mar 2023 04:10:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680261013; cv=none; d=google.com; s=arc-20160816; b=QYuGKWo0zJYEHJvlp9N8pNjY9Iz6pNFghPKvv9lSHTg0GMyUGMCWoWVX32nRgwRW+r TclO5EyRS/sdmzzlJkJuMdC3n0nBOlpm4lyqwzliLoT6Yq8WntDYrTadJ/c5RHzg9gXf sPaAW+KAMwFIX5+pnyxPxxc9Oxaa90fQE7/9+P/3YxYyV63DSZQUb4mkSJRnLUS5zaR0 grDo76bpdsqI/psNgQ5q9lCKnAzKIgDfTVQ1xo4q5BPPUdNo34U+LshtyzxCOKhX4oEk Kmi2hl5zEpNSBmXlP5x94PYrMa3vOUf37KLc1CjuhbZ7Gm5KoHEBnysnbUHiGq/EcEuP Zrwg== 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=AEuXxhp4qHoiYKzslqhx+XlA1usXlIds0JD7B0pv+sQ=; b=EmRP5SF5qN4sCwFQKAuRPl3+CxyvKBuwDnzbSboQEZLP8inXOEUiRMWuf9tYBx2BAw xD5wV0Wv5J+ibD8Qtr092Obh5GPg/GdbSuiBiGQnbX3URCaubnggIT5Wsbwyl0BrombP AckJzOq418ExXjUnzAM5cjAq2F/pV3Ze43uR+Bdl0pDk2G2T8IixtiU0HDDAA4YDD600 D0zBud6U1qgy7OD/tOrpn7iLJGlKofoLmBpAsucYkqQrE+D4iiIs7h3W9urdp1781ZEw ZfsxgtlHihsks3HjuBBOTgB0ig+VgIKsBS8keDGVXax8wFQBFvg72lQ2drbl9u9QLfxy 7pAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fMKpoleo; 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 t185-20020a635fc2000000b004fc21da0340si2200461pgb.129.2023.03.31.04.10.01; Fri, 31 Mar 2023 04:10:13 -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=fMKpoleo; 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 S231991AbjCaK6Q (ORCPT + 99 others); Fri, 31 Mar 2023 06:58:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231858AbjCaK5G (ORCPT ); Fri, 31 Mar 2023 06:57:06 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0FF51DF8C; Fri, 31 Mar 2023 03:56:46 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id f22so16746882plr.0; Fri, 31 Mar 2023 03:56:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680260206; 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=AEuXxhp4qHoiYKzslqhx+XlA1usXlIds0JD7B0pv+sQ=; b=fMKpoleouzT/PMHQEvIT0IL81Eu92Q3JpbP/8juEzoG/UH+914z6TViQ4oxMLe/9Fn YjdmYtoblGXOwA2JiZeKLu2MY0BTErd/+0cgqO2psWPTLPue1uJIxsz1Uf4tcoZDGV6H +tRNDfz17JigB7GZfIYju/NQLCA7q70DP1cin2FwxDnDDV4hGtywkpMXlM1uC5Xaq39h 8p04kHF9adhJ/hUYUpQAgd7ru0GngxHbZ488uH3STSs/SfZXLsyghjX7T97NCOcnu1GY l4ols/rLNUrybUP21xPCowpTGVzQkKdAN3E9tenoXdW7KNmOVKBxpSdYSIOaDxEZR+VJ YPwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680260206; 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=AEuXxhp4qHoiYKzslqhx+XlA1usXlIds0JD7B0pv+sQ=; b=g2px2WYbczltxB51cv0OPlo3srHhcV4+ekvtlXUhtgocU5p7ood0Zuc5QVLb72+LmO tTD4NDWKSwDBQRcji3VwngEKkH6VF5uknB8F4RSv4HU1i7VT3HIM9AXID898aUxvcaHh g0rjju7bE58vAejw8nsz5BGU7D1u9g9fp5WAbPN095pHInG11diJjhRAhprApd6tkl3J tasjJ1uhGm8svxDrZJWfNkzALdAwgYX/NBEQdqliqstFV5DCCgk1SVe09MkfRXG4sd1R kItqsudgfzcoSLPtOSuH8rnlCOVALYs25yax7szgMXBNyAE/DeYJqTOZa1n55Ji/jvwc 7twA== X-Gm-Message-State: AAQBX9cE06zjd9tEPfVs5VkOrdsQqIP8nx27N5dnS6qKbPGzcjqq0X66 kTLpSPrcHn9DTYr4ZytioDE= X-Received: by 2002:a17:902:e2ca:b0:1a2:9051:f0a3 with SMTP id l10-20020a170902e2ca00b001a29051f0a3mr3941023plc.24.1680260205949; Fri, 31 Mar 2023 03:56:45 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 03:56:45 -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 15/23] mmc: sdhci-uhs2: add detect_init() to detect the interface Date: Fri, 31 Mar 2023 18:55:38 +0800 Message-Id: <20230331105546.13607-16-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?1761881372529851374?= X-GMAIL-MSGID: =?utf-8?q?1761881372529851374?= Sdhci_uhs2_do_detect_init() is a sdhci version of mmc's uhs2_detect_init operation. After detected, the host's UHS-II capabilities will be set up here and interrupts will also be enabled. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Signed-off-by: Victor Shih --- drivers/mmc/host/sdhci-uhs2.c | 117 ++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index 9b519bd6d76e..e2972be1889f 100644 --- a/drivers/mmc/host/sdhci-uhs2.c +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -334,6 +334,123 @@ static int sdhci_uhs2_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) * * \*****************************************************************************/ +static int sdhci_uhs2_interface_detect(struct sdhci_host *host) +{ + /* 100ms */ + int timeout = 100000; + u32 val; + + udelay(200); /* wait for 200us before check */ + + if (read_poll_timeout_atomic(sdhci_readl, val, (val & SDHCI_UHS2_IF_DETECT), + 100, timeout, true, host, SDHCI_PRESENT_STATE)) { + pr_warn("%s: not detect UHS2 interface in 200us.\n", mmc_hostname(host->mmc)); + sdhci_dumpregs(host); + return -EIO; + } + + /* Enable UHS2 error interrupts */ + sdhci_uhs2_clear_set_irqs(host, SDHCI_INT_ALL_MASK, SDHCI_UHS2_INT_ERROR_MASK); + + /* 150ms */ + timeout = 150000; + if (read_poll_timeout_atomic(sdhci_readl, val, (val & SDHCI_UHS2_LANE_SYNC), + 100, timeout, true, host, SDHCI_PRESENT_STATE)) { + pr_warn("%s: UHS2 Lane sync fail in 150ms.\n", mmc_hostname(host->mmc)); + sdhci_dumpregs(host); + return -EIO; + } + + DBG("%s: UHS2 Lane synchronized in UHS2 mode, PHY is initialized.\n", + mmc_hostname(host->mmc)); + return 0; +} + +static int sdhci_uhs2_init(struct sdhci_host *host) +{ + u16 caps_ptr = 0; + u32 caps_gen = 0; + u32 caps_phy = 0; + u32 caps_tran[2] = {0, 0}; + struct mmc_host *mmc = host->mmc; + + caps_ptr = sdhci_readw(host, SDHCI_UHS2_CAPS_PTR); + if (caps_ptr < 0x100 || caps_ptr > 0x1FF) { + pr_err("%s: SDHCI_UHS2_CAPS_PTR(%d) is wrong.\n", + mmc_hostname(mmc), caps_ptr); + return -ENODEV; + } + caps_gen = sdhci_readl(host, caps_ptr + SDHCI_UHS2_CAPS_OFFSET); + caps_phy = sdhci_readl(host, caps_ptr + SDHCI_UHS2_CAPS_PHY_OFFSET); + caps_tran[0] = sdhci_readl(host, caps_ptr + SDHCI_UHS2_CAPS_TRAN_OFFSET); + caps_tran[1] = sdhci_readl(host, caps_ptr + SDHCI_UHS2_CAPS_TRAN_1_OFFSET); + + /* General Caps */ + mmc->uhs2_caps.dap = caps_gen & SDHCI_UHS2_CAPS_DAP_MASK; + mmc->uhs2_caps.gap = FIELD_GET(SDHCI_UHS2_CAPS_GAP_MASK, caps_gen); + mmc->uhs2_caps.n_lanes = FIELD_GET(SDHCI_UHS2_CAPS_LANE_MASK, caps_gen); + mmc->uhs2_caps.addr64 = (caps_gen & SDHCI_UHS2_CAPS_ADDR_64) ? 1 : 0; + mmc->uhs2_caps.card_type = FIELD_GET(SDHCI_UHS2_CAPS_DEV_TYPE_MASK, caps_gen); + + /* PHY Caps */ + mmc->uhs2_caps.phy_rev = caps_phy & SDHCI_UHS2_CAPS_PHY_REV_MASK; + mmc->uhs2_caps.speed_range = FIELD_GET(SDHCI_UHS2_CAPS_PHY_RANGE_MASK, caps_phy); + mmc->uhs2_caps.n_lss_sync = FIELD_GET(SDHCI_UHS2_CAPS_PHY_N_LSS_SYN_MASK, caps_phy); + mmc->uhs2_caps.n_lss_dir = FIELD_GET(SDHCI_UHS2_CAPS_PHY_N_LSS_DIR_MASK, caps_phy); + if (mmc->uhs2_caps.n_lss_sync == 0) + mmc->uhs2_caps.n_lss_sync = 16 << 2; + else + mmc->uhs2_caps.n_lss_sync <<= 2; + if (mmc->uhs2_caps.n_lss_dir == 0) + mmc->uhs2_caps.n_lss_dir = 16 << 3; + else + mmc->uhs2_caps.n_lss_dir <<= 3; + + /* LINK/TRAN Caps */ + mmc->uhs2_caps.link_rev = caps_tran[0] & SDHCI_UHS2_CAPS_TRAN_LINK_REV_MASK; + mmc->uhs2_caps.n_fcu = FIELD_GET(SDHCI_UHS2_CAPS_TRAN_N_FCU_MASK, caps_tran[0]); + if (mmc->uhs2_caps.n_fcu == 0) + mmc->uhs2_caps.n_fcu = 256; + mmc->uhs2_caps.host_type = FIELD_GET(SDHCI_UHS2_CAPS_TRAN_HOST_TYPE_MASK, caps_tran[0]); + mmc->uhs2_caps.maxblk_len = FIELD_GET(SDHCI_UHS2_CAPS_TRAN_BLK_LEN_MASK, caps_tran[0]); + mmc->uhs2_caps.n_data_gap = caps_tran[1] & SDHCI_UHS2_CAPS_TRAN_1_N_DATA_GAP_MASK; + + return 0; +} + +static int sdhci_uhs2_do_detect_init(struct mmc_host *mmc) +{ + struct sdhci_host *host = mmc_priv(mmc); + int ret = -EIO; + + DBG("Begin do uhs2 detect init.\n"); + + if (sdhci_uhs2_interface_detect(host)) { + pr_warn("%s: cannot detect UHS2 interface.\n", + mmc_hostname(host->mmc)); + goto out; + } + + if (sdhci_uhs2_init(host)) { + pr_warn("%s: UHS2 init fail.\n", mmc_hostname(host->mmc)); + goto out; + } + + /* Init complete, do soft reset and enable UHS2 error irqs. */ + sdhci_uhs2_reset(host, SDHCI_UHS2_SW_RESET_SD); + sdhci_uhs2_clear_set_irqs(host, SDHCI_INT_ALL_MASK, SDHCI_UHS2_INT_ERROR_MASK); + /* + * N.B SDHCI_INT_ENABLE and SDHCI_SIGNAL_ENABLE was cleared + * by SDHCI_UHS2_SW_RESET_SD + */ + sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); + sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); + + ret = 0; +out: + return ret; +} + static int sdhci_uhs2_host_ops_init(struct sdhci_host *host) { host->mmc_host_ops.start_signal_voltage_switch =