From patchwork Wed May 31 11:15:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 101366 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2803794vqr; Wed, 31 May 2023 04:26:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7VSo/X+TlUfM02DEIgU7+6a74h+oP16Vy04euwfCRQXenobJdBui/lsdATgS4syjhFrI6a X-Received: by 2002:a05:6830:1e34:b0:69f:578a:d1ea with SMTP id t20-20020a0568301e3400b0069f578ad1eamr1986200otr.32.1685532410908; Wed, 31 May 2023 04:26:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685532410; cv=none; d=google.com; s=arc-20160816; b=k3ZjiEw9coyft0B8C+UNuYpKJ1K8Hwv4mqGzuEfh2GW2S5u9z37xAx+1gNsDCZh1gi 7bPPWyk3Bn/RBZ7+6DQ1WRkb1PqvoDRpeMQr4uQJqy3zK9zVAMt+g7JG/ReBKpSCe5RH zc2DWmhYncyub3FW/XlQV+w7nGedz/QpsRC1iLKjJ3uBbcLU2C1PRf5LuH5hvTwhfBhC T7pVqNBChSoS3D+zK90pitp5lX4UlOAmtLFmKRpJp80yNMDoXT6YK2air53Djp4S1NnG p8q3dzpS+Hb7pstFyB0YBbFYKeOsT5FzRPsu0RVX4kMcdtu9FutPA3Ob8OOMF1ahZjSK CJuA== 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=tb1mDFhM0TkiZ/6VHU0sssZ9OqNe3tnE049NIDGtjqw=; b=fPSIiE65KmQSh60Q5p8ZUJaB203iXFVnY/+jnzYHJt8ZxsKptliRIA8RX67s1GLQtc ZoaI3c6brHy0FZ8UQ3kK9W1vymvS39AL0qHcGrVvJVpqi9Sx1inM+s8mUstDHB5SShbO +WvoOZMKQrz138POIQNO08AARuAC1QHcW4lqxEFAxWiymwqFBi4AIR2u9W/I6KL9Uh8D a95m5kbAWgNzv6HNeht9MEWpCxWaS8nlewm6hoZrU5R8yvq7YjWBLNucTe/6yZLalpCP 1vNGZfJwDquFBnfTrIvcaRDxif793NQMeB6xkYAM4LSYEQV0yvRotD1LbR6fQtMaqQ0Z zZHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=OEI8Ycia; 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 123-20020a621981000000b006434bb21d3asi1176609pfz.299.2023.05.31.04.26.38; Wed, 31 May 2023 04:26:50 -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=OEI8Ycia; 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 S235484AbjEaLRd (ORCPT + 99 others); Wed, 31 May 2023 07:17:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232240AbjEaLR3 (ORCPT ); Wed, 31 May 2023 07:17:29 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6662E8; Wed, 31 May 2023 04:17:27 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-53f8da65701so1958369a12.1; Wed, 31 May 2023 04:17:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685531847; x=1688123847; 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=tb1mDFhM0TkiZ/6VHU0sssZ9OqNe3tnE049NIDGtjqw=; b=OEI8YciaXeED8NCobDYU+SD6+VCc4qN3JTZcV5SZlXeOL3ZpS8Hpb1XH1dk8yQ/KLk iO6/kChjU9u5tBybByZuCz8U66TvWv0I8qppakqQTUUJqt45PXo0LIWkduacBI4SKpjl bLqwYGUA5c33HRZAmMOzZ2rnTpOh4hX1k/TgcbFGiobRrci9V1nWSQzKI3B3Jh4MGE2P MyBmdRmtrFU9ifqrIwtwOjs1vKrEYAh+CvT+m1c9y3YJnSXktscraCiXpzHHVpGoZWuM yOxCtQXE3FNgVDtkvFGldgNHkge/ACe8hhLSg3xgkM8Votc3G8dz5IjsI6wFFp6rVQlh JJgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685531847; x=1688123847; 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=tb1mDFhM0TkiZ/6VHU0sssZ9OqNe3tnE049NIDGtjqw=; b=JJoGrSjlOTZecn4KCTdFQAM5ssI4Y8wZlSngDxcymsjITDhojh3wkF24ImRlbKeWqf yMWCxK7uKJFTKkpzTJnzwua5Scr7UFx5qPuhP4OPohjPTktVtOVDZviCxuUzk8ISToty zAUMPUKln1sqH/QIQBIc9eHewX0Fu8YKyCJ1/SzL8c+41FDQs9LVoqSfDgdIBSADqzZL 30BNDrrP2RA4FvasidHGL2gE6w5Ft061InenIfm8dF/k2QH0XMZF2gu8IjPVSl5bs2SN kfXkQxJzj/MbWrI+XcNSnwUozCQZ/ZYoxz3BrBRHbiiQJfBsKbpwZN94eCMqy09O98yU WfJw== X-Gm-Message-State: AC+VfDywR918efMt8WooNm+yrlVoJM/IcuFaZrnXt37t/8+GiWOc4Ifa xhMO3g0/z0JcLfbSJCs0Jn8= X-Received: by 2002:a05:6a20:4288:b0:10c:5ff4:8bc6 with SMTP id o8-20020a056a20428800b0010c5ff48bc6mr5114685pzj.38.1685531847104; Wed, 31 May 2023 04:17:27 -0700 (PDT) Received: from localhost.localdomain (111-82-252-250.emome-ip.hinet.net. [111.82.252.250]) by smtp.gmail.com with ESMTPSA id d17-20020a170903231100b001b0aec3ed59sm1076588plh.256.2023.05.31.04.17.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 04:17:26 -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, Victor Shih , Ben Chuang , Victor Shih Subject: [PATCH V4 1/4] mmc: sdhci-pci-gli: Add Genesys Logic GL9767 support Date: Wed, 31 May 2023 19:15:15 +0800 Message-Id: <20230531111518.396868-2-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230531111518.396868-1-victorshihgli@gmail.com> References: <20230531111518.396868-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_NONE,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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767408832857309956?= X-GMAIL-MSGID: =?utf-8?q?1767408832857309956?= From: Victor Shih Add support for the GL9767 chipset. GL9767 supports SD3 mode likes UHS-I SDR50, SDR104. Enable MSI interrupt for GL9767. Some platform do not support PCI INTx and devices can not work without interrupt. Signed-off-by: Ben Chuang Signed-off-by: Victor Shih Acked-by: Adrian Hunter --- drivers/mmc/host/sdhci-pci-core.c | 1 + drivers/mmc/host/sdhci-pci-gli.c | 160 ++++++++++++++++++++++++++++++ drivers/mmc/host/sdhci-pci.h | 2 + 3 files changed, 163 insertions(+) diff --git a/drivers/mmc/host/sdhci-pci-core.c b/drivers/mmc/host/sdhci-pci-core.c index 01975d145200..1c2572c0f012 100644 --- a/drivers/mmc/host/sdhci-pci-core.c +++ b/drivers/mmc/host/sdhci-pci-core.c @@ -1903,6 +1903,7 @@ static const struct pci_device_id pci_ids[] = { SDHCI_PCI_DEVICE(GLI, 9750, gl9750), SDHCI_PCI_DEVICE(GLI, 9755, gl9755), SDHCI_PCI_DEVICE(GLI, 9763E, gl9763e), + SDHCI_PCI_DEVICE(GLI, 9767, gl9767), SDHCI_PCI_DEVICE_CLASS(AMD, SYSTEM_SDHCI, PCI_CLASS_MASK, amd), /* Generic SD host controller */ {PCI_DEVICE_CLASS(SYSTEM_SDHCI, PCI_CLASS_MASK)}, diff --git a/drivers/mmc/host/sdhci-pci-gli.c b/drivers/mmc/host/sdhci-pci-gli.c index 633a8ee8f8c5..3ed207b89d1a 100644 --- a/drivers/mmc/host/sdhci-pci-gli.c +++ b/drivers/mmc/host/sdhci-pci-gli.c @@ -149,6 +149,32 @@ #define PCI_GLI_9755_PM_CTRL 0xFC #define PCI_GLI_9755_PM_STATE GENMASK(1, 0) +#define SDHCI_GLI_9767_GM_BURST_SIZE 0x510 +#define SDHCI_GLI_9767_GM_BURST_SIZE_AXI_ALWAYS_SET BIT(8) + +#define PCIE_GLI_9767_VHS 0x884 +#define GLI_9767_VHS_REV GENMASK(19, 16) +#define GLI_9767_VHS_REV_R 0x0 +#define GLI_9767_VHS_REV_M 0x1 +#define GLI_9767_VHS_REV_W 0x2 + +#define PCIE_GLI_9767_PWR_MACRO_CTL 0x8D0 +#define PCIE_GLI_9767_PWR_MACRO_CTL_LOW_VOLTAGE GENMASK(3, 0) +#define PCIE_GLI_9767_PWR_MACRO_CTL_LD0_LOW_OUTPUT_VOLTAGE GENMASK(15, 12) +#define PCIE_GLI_9767_PWR_MACRO_CTL_LD0_LOW_OUTPUT_VOLTAGE_VALUE 0x7 +#define PCIE_GLI_9767_PWR_MACRO_CTL_RCLK_AMPLITUDE_CTL GENMASK(29, 28) +#define PCIE_GLI_9767_PWR_MACRO_CTL_RCLK_AMPLITUDE_CTL_VALUE 0x3 + +#define PCIE_GLI_9767_SCR 0x8E0 +#define PCIE_GLI_9767_SCR_AUTO_AXI_W_BURST BIT(6) +#define PCIE_GLI_9767_SCR_AUTO_AXI_R_BURST BIT(7) +#define PCIE_GLI_9767_SCR_AXI_REQ BIT(9) +#define PCIE_GLI_9767_SCR_CARD_DET_PWR_SAVING_EN BIT(10) +#define PCIE_GLI_9767_SCR_SYSTEM_CLK_SELECT_MODE0 BIT(16) +#define PCIE_GLI_9767_SCR_SYSTEM_CLK_SELECT_MODE1 BIT(17) +#define PCIE_GLI_9767_SCR_CORE_PWR_D3_OFF BIT(21) +#define PCIE_GLI_9767_SCR_CFG_RST_DATA_LINK_DOWN BIT(30) + #define GLI_MAX_TUNING_LOOP 40 /* Genesys Logic chipset */ @@ -693,6 +719,89 @@ static void gl9755_hw_setting(struct sdhci_pci_slot *slot) gl9755_wt_off(pdev); } +static inline void gl9767_vhs_read(struct pci_dev *pdev) +{ + u32 vhs_enable; + u32 vhs_value; + + pci_read_config_dword(pdev, PCIE_GLI_9767_VHS, &vhs_value); + vhs_enable = FIELD_GET(GLI_9767_VHS_REV, vhs_value); + + if (vhs_enable == GLI_9767_VHS_REV_R) + return; + + vhs_value &= ~GLI_9767_VHS_REV; + vhs_value |= FIELD_PREP(GLI_9767_VHS_REV, GLI_9767_VHS_REV_R); + + pci_write_config_dword(pdev, PCIE_GLI_9767_VHS, vhs_value); +} + +static inline void gl9767_vhs_write(struct pci_dev *pdev) +{ + u32 vhs_enable; + u32 vhs_value; + + pci_read_config_dword(pdev, PCIE_GLI_9767_VHS, &vhs_value); + vhs_enable = FIELD_GET(GLI_9767_VHS_REV, vhs_value); + + if (vhs_enable == GLI_9767_VHS_REV_W) + return; + + vhs_value &= ~GLI_9767_VHS_REV; + vhs_value |= FIELD_PREP(GLI_9767_VHS_REV, GLI_9767_VHS_REV_W); + + pci_write_config_dword(pdev, PCIE_GLI_9767_VHS, vhs_value); +} + +static void gli_set_9767(struct sdhci_host *host) +{ + u32 value; + + value = sdhci_readl(host, SDHCI_GLI_9767_GM_BURST_SIZE); + value &= ~SDHCI_GLI_9767_GM_BURST_SIZE_AXI_ALWAYS_SET; + sdhci_writel(host, value, SDHCI_GLI_9767_GM_BURST_SIZE); +} + +static void gl9767_hw_setting(struct sdhci_pci_slot *slot) +{ + struct pci_dev *pdev = slot->chip->pdev; + u32 value; + + gl9767_vhs_write(pdev); + + pci_read_config_dword(pdev, PCIE_GLI_9767_PWR_MACRO_CTL, &value); + value &= ~(PCIE_GLI_9767_PWR_MACRO_CTL_LOW_VOLTAGE | + PCIE_GLI_9767_PWR_MACRO_CTL_LD0_LOW_OUTPUT_VOLTAGE | + PCIE_GLI_9767_PWR_MACRO_CTL_RCLK_AMPLITUDE_CTL); + + value |= PCIE_GLI_9767_PWR_MACRO_CTL_LOW_VOLTAGE | + FIELD_PREP(PCIE_GLI_9767_PWR_MACRO_CTL_LD0_LOW_OUTPUT_VOLTAGE, + PCIE_GLI_9767_PWR_MACRO_CTL_LD0_LOW_OUTPUT_VOLTAGE_VALUE) | + FIELD_PREP(PCIE_GLI_9767_PWR_MACRO_CTL_RCLK_AMPLITUDE_CTL, + PCIE_GLI_9767_PWR_MACRO_CTL_RCLK_AMPLITUDE_CTL_VALUE); + pci_write_config_dword(pdev, PCIE_GLI_9767_PWR_MACRO_CTL, value); + + pci_read_config_dword(pdev, PCIE_GLI_9767_SCR, &value); + value &= ~(PCIE_GLI_9767_SCR_SYSTEM_CLK_SELECT_MODE0 | + PCIE_GLI_9767_SCR_SYSTEM_CLK_SELECT_MODE1 | + PCIE_GLI_9767_SCR_CFG_RST_DATA_LINK_DOWN); + + value |= PCIE_GLI_9767_SCR_AUTO_AXI_W_BURST | + PCIE_GLI_9767_SCR_AUTO_AXI_R_BURST | + PCIE_GLI_9767_SCR_AXI_REQ | + PCIE_GLI_9767_SCR_CARD_DET_PWR_SAVING_EN | + PCIE_GLI_9767_SCR_CORE_PWR_D3_OFF; + pci_write_config_dword(pdev, PCIE_GLI_9767_SCR, value); + + gl9767_vhs_read(pdev); +} + +static void sdhci_gl9767_reset(struct sdhci_host *host, u8 mask) +{ + sdhci_reset(host, mask); + gli_set_9767(host); +} + static int gli_probe_slot_gl9750(struct sdhci_pci_slot *slot) { struct sdhci_host *host = slot->host; @@ -717,6 +826,19 @@ static int gli_probe_slot_gl9755(struct sdhci_pci_slot *slot) return 0; } +static int gli_probe_slot_gl9767(struct sdhci_pci_slot *slot) +{ + struct sdhci_host *host = slot->host; + + gli_set_9767(host); + gl9767_hw_setting(slot); + gli_pcie_enable_msi(slot); + slot->host->mmc->caps2 |= MMC_CAP2_NO_SDIO; + sdhci_enable_v4_mode(host); + + return 0; +} + static void sdhci_gli_voltage_switch(struct sdhci_host *host) { /* @@ -740,6 +862,25 @@ static void sdhci_gli_voltage_switch(struct sdhci_host *host) usleep_range(100000, 110000); } +static void sdhci_gl9767_voltage_switch(struct sdhci_host *host) +{ + /* + * According to Section 3.6.1 signal voltage switch procedure in + * SD Host Controller Simplified Spec. 4.20, steps 6~8 are as + * follows: + * (6) Set 1.8V Signal Enable in the Host Control 2 register. + * (7) Wait 5ms. 1.8V voltage regulator shall be stable within this + * period. + * (8) If 1.8V Signal Enable is cleared by Host Controller, go to + * step (12). + * + * Wait 5ms after set 1.8V signal enable in Host Control 2 register + * to ensure 1.8V signal enable bit is set by GL9767. + * + */ + usleep_range(5000, 5500); +} + static void sdhci_gl9750_reset(struct sdhci_host *host, u8 mask) { sdhci_reset(host, mask); @@ -1150,3 +1291,22 @@ const struct sdhci_pci_fixes sdhci_gl9763e = { #endif .add_host = gl9763e_add_host, }; + +static const struct sdhci_ops sdhci_gl9767_ops = { + .set_clock = sdhci_set_clock, + .enable_dma = sdhci_pci_enable_dma, + .set_bus_width = sdhci_set_bus_width, + .reset = sdhci_gl9767_reset, + .set_uhs_signaling = sdhci_set_uhs_signaling, + .voltage_switch = sdhci_gl9767_voltage_switch, +}; + +const struct sdhci_pci_fixes sdhci_gl9767 = { + .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, + .quirks2 = SDHCI_QUIRK2_BROKEN_DDR50, + .probe_slot = gli_probe_slot_gl9767, + .ops = &sdhci_gl9767_ops, +#ifdef CONFIG_PM_SLEEP + .resume = sdhci_pci_gli_resume, +#endif +}; diff --git a/drivers/mmc/host/sdhci-pci.h b/drivers/mmc/host/sdhci-pci.h index 3661a224fb04..9c8863956381 100644 --- a/drivers/mmc/host/sdhci-pci.h +++ b/drivers/mmc/host/sdhci-pci.h @@ -76,6 +76,7 @@ #define PCI_DEVICE_ID_GLI_9755 0x9755 #define PCI_DEVICE_ID_GLI_9750 0x9750 #define PCI_DEVICE_ID_GLI_9763E 0xe763 +#define PCI_DEVICE_ID_GLI_9767 0x9767 /* * PCI device class and mask @@ -195,5 +196,6 @@ extern const struct sdhci_pci_fixes sdhci_o2; extern const struct sdhci_pci_fixes sdhci_gl9750; extern const struct sdhci_pci_fixes sdhci_gl9755; extern const struct sdhci_pci_fixes sdhci_gl9763e; +extern const struct sdhci_pci_fixes sdhci_gl9767; #endif /* __SDHCI_PCI_H */ From patchwork Wed May 31 11:15:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 101367 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2803824vqr; Wed, 31 May 2023 04:26:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7k5DQnfdpDEHapTsnQ8zrr9SrGqTnnJA+FXCnShQYAFWTG7GeQxNKeefkWlcUW1tvGbMHT X-Received: by 2002:a05:6808:10c3:b0:386:d4f7:6791 with SMTP id s3-20020a05680810c300b00386d4f76791mr4538552ois.37.1685532415333; Wed, 31 May 2023 04:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685532415; cv=none; d=google.com; s=arc-20160816; b=tZFt+jRoKaXiFtUMrC9inbxm9WTbMIVS8tM0MqwwUTjPTWHsYY5QQo97qCnCydeGvP 8vhyp2PkoJ6xrgxrmilS23c4ByG/Bk+Bs3KUn/7Sg1HROiQwF2jRNq5Jed7n7bSEdJXo IUWI7vhwzbTnDU2X1HHuGt4AnZNu+pd4zS1phVF0H4mDVCzSNUKsAbTa18JFBhssfBD4 MRVJa/8XXgs8SxjNdSWp1QULD4JpOcdATR79JL9+8zqRmv7eNDhhnYANfwzYqEMpo7Ay bSuMSYb7zMYeueSp3K7JaH4QIOdR8+hE+4wfwONFoKL3WCaftCw1tE+axUDjISfOr9me S3Xw== 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=D6dq4b1xhx1Qx+qJ9zV/ekRGtlRq1SNTzaOgEH+kK1Q=; b=xi77Aa1xdecvzX0KF/i8bgd4h61IRcN/Zx75owJayu9yAm7/x5CCtsbKL0HGUqmruS gp/72I8gT5EnKwhPCCjfXKDMguG0RsWKdJEsB6rndTysqtRxqnYqC3XXQ5Vb9wRgN9TF cqvOaD/2ZXEAnzKO1iQrkhe76/2evx+tjlkpVnvE4yUKHUUDdyVWwrMcAUhAgHwBOMdb eorcWWwruLzIdl/jVAkhF2FG88ApPLdisiDbFh1+lDZS285MARXuwzunQvQMC/G6SUwC Bj/3PLa0Gb2jFYJ7w74olorlmaAzxLBFBkdDpVP6Pn78YwZg54PdOpOSwvI5cnbgrDLU 1lLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=XRG1Nrvy; 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 ng12-20020a17090b1a8c00b002524da9db57si831273pjb.172.2023.05.31.04.26.42; Wed, 31 May 2023 04:26:55 -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=XRG1Nrvy; 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 S235489AbjEaLRh (ORCPT + 99 others); Wed, 31 May 2023 07:17:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235471AbjEaLRb (ORCPT ); Wed, 31 May 2023 07:17:31 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 249C5E8; Wed, 31 May 2023 04:17:30 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1b01bd7093aso30912345ad.1; Wed, 31 May 2023 04:17:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685531849; x=1688123849; 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=D6dq4b1xhx1Qx+qJ9zV/ekRGtlRq1SNTzaOgEH+kK1Q=; b=XRG1NrvybCnz3yu3PTXa6PqJMpCdluAtmempM8w3+LJYHL9CJHZcs/NWOjhvi1dJ1c 0uPaaiLgv980At7I3jHAoJtu1FE7UcnRfo7afMHM7QJvKuk4aYtzwYjmAkul04kopXXw +fpvi7Rmd/HUUvxaZjyS1QM7KkEZx/AVvejSivegCS9LlCAy2OX8AlwSvYfkUwlVFnfq uoyIk0SaWxx06NffVv5VS0sRUhXfoPPfra2hNzTgGa+BdyKNh6GEL0KUPASIVFl7CijE 8JaRUFDl4ZuIvDRDe31IxkUV2ckDaFifbs0TAqfR2MGlE8Y3rp1g5fnR/1AHko0BSGQ7 oV+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685531849; x=1688123849; 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=D6dq4b1xhx1Qx+qJ9zV/ekRGtlRq1SNTzaOgEH+kK1Q=; b=DdJJUfxHHPjw3WivvlnbgRP3UTFuibijE8SL+/vrfu4PLjFSpu4a1ttprQm98XhMpx budzY8YuqgO2ci20OjSgWLqfgwjnEvWhidg0wF+WfLcJHltUxqviwnt6mjBNFCa41zAw xnQLTYri6wr1dM7YFXLcQN98aMyXtKO2S1tTEj8DDtQBkVgY25PaCM1vyL0/vYxkk/Yb mShwA1fbDcVXGbir8ibuzB6DtNVZmneNngCkPF2zEfN2eBUsgLRWcKUjgc/SzRrH1JQ8 ny4EQl4jwbsWa//DxFwizb8FlCbHqlo9Wt2lj0xcfRfZi68ieRwwW9DDZe7kA2xcjxzo qwWg== X-Gm-Message-State: AC+VfDwND0w+szjn9sQwh7MobBsJFeO39B8oqTM5LlPaxVQ+P/U2OUlt OrmdNZ+c5lKvYDQBv0xGdwI= X-Received: by 2002:a17:902:d2ca:b0:1b1:7890:ff48 with SMTP id n10-20020a170902d2ca00b001b17890ff48mr620520plc.5.1685531849548; Wed, 31 May 2023 04:17:29 -0700 (PDT) Received: from localhost.localdomain (111-82-252-250.emome-ip.hinet.net. [111.82.252.250]) by smtp.gmail.com with ESMTPSA id d17-20020a170903231100b001b0aec3ed59sm1076588plh.256.2023.05.31.04.17.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 04:17:29 -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, Victor Shih , Ben Chuang , Victor Shih Subject: [PATCH V4 2/4] mmc: sdhci-pci-gli: Set SDR104's clock to 205MHz and enable SSC for GL9767 Date: Wed, 31 May 2023 19:15:16 +0800 Message-Id: <20230531111518.396868-3-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230531111518.396868-1-victorshihgli@gmail.com> References: <20230531111518.396868-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_NONE,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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767408837982668677?= X-GMAIL-MSGID: =?utf-8?q?1767408837982668677?= From: Victor Shih Set GL9767 SDR104's clock to 205MHz and enable SSC feature depend on register 0x888 BIT(1). Signed-off-by: Ben Chuang Signed-off-by: Victor Shih Acked-by: Adrian Hunter --- drivers/mmc/host/sdhci-pci-gli.c | 135 ++++++++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/sdhci-pci-gli.c b/drivers/mmc/host/sdhci-pci-gli.c index 3ed207b89d1a..392a106cea18 100644 --- a/drivers/mmc/host/sdhci-pci-gli.c +++ b/drivers/mmc/host/sdhci-pci-gli.c @@ -158,6 +158,12 @@ #define GLI_9767_VHS_REV_M 0x1 #define GLI_9767_VHS_REV_W 0x2 +#define PCIE_GLI_9767_COM_MAILBOX 0x888 +#define PCIE_GLI_9767_COM_MAILBOX_SSC_EN BIT(1) + +#define PCIE_GLI_9767_CFG 0x8A0 +#define PCIE_GLI_9767_CFG_LOW_PWR_OFF BIT(12) + #define PCIE_GLI_9767_PWR_MACRO_CTL 0x8D0 #define PCIE_GLI_9767_PWR_MACRO_CTL_LOW_VOLTAGE GENMASK(3, 0) #define PCIE_GLI_9767_PWR_MACRO_CTL_LD0_LOW_OUTPUT_VOLTAGE GENMASK(15, 12) @@ -175,6 +181,16 @@ #define PCIE_GLI_9767_SCR_CORE_PWR_D3_OFF BIT(21) #define PCIE_GLI_9767_SCR_CFG_RST_DATA_LINK_DOWN BIT(30) +#define PCIE_GLI_9767_SD_PLL_CTL 0x938 +#define PCIE_GLI_9767_SD_PLL_CTL_PLL_LDIV GENMASK(9, 0) +#define PCIE_GLI_9767_SD_PLL_CTL_PLL_PDIV GENMASK(15, 12) +#define PCIE_GLI_9767_SD_PLL_CTL_PLL_DIR_EN BIT(16) +#define PCIE_GLI_9767_SD_PLL_CTL_SSC_EN BIT(19) +#define PCIE_GLI_9767_SD_PLL_CTL_SSC_STEP_SETTING GENMASK(28, 24) + +#define PCIE_GLI_9767_SD_PLL_CTL2 0x93C +#define PCIE_GLI_9767_SD_PLL_CTL2_PLLSSC_PPM GENMASK(31, 16) + #define GLI_MAX_TUNING_LOOP 40 /* Genesys Logic chipset */ @@ -753,6 +769,123 @@ static inline void gl9767_vhs_write(struct pci_dev *pdev) pci_write_config_dword(pdev, PCIE_GLI_9767_VHS, vhs_value); } +static bool gl9767_ssc_enable(struct pci_dev *pdev) +{ + u32 value; + u8 enable; + + gl9767_vhs_write(pdev); + + pci_read_config_dword(pdev, PCIE_GLI_9767_COM_MAILBOX, &value); + enable = FIELD_GET(PCIE_GLI_9767_COM_MAILBOX_SSC_EN, value); + + gl9767_vhs_read(pdev); + + return enable; +} + +static void gl9767_set_ssc(struct pci_dev *pdev, u8 enable, u8 step, u16 ppm) +{ + u32 pll; + u32 ssc; + + gl9767_vhs_write(pdev); + + pci_read_config_dword(pdev, PCIE_GLI_9767_SD_PLL_CTL, &pll); + pci_read_config_dword(pdev, PCIE_GLI_9767_SD_PLL_CTL2, &ssc); + pll &= ~(PCIE_GLI_9767_SD_PLL_CTL_SSC_STEP_SETTING | + PCIE_GLI_9767_SD_PLL_CTL_SSC_EN); + ssc &= ~PCIE_GLI_9767_SD_PLL_CTL2_PLLSSC_PPM; + pll |= FIELD_PREP(PCIE_GLI_9767_SD_PLL_CTL_SSC_STEP_SETTING, step) | + FIELD_PREP(PCIE_GLI_9767_SD_PLL_CTL_SSC_EN, enable); + ssc |= FIELD_PREP(PCIE_GLI_9767_SD_PLL_CTL2_PLLSSC_PPM, ppm); + pci_write_config_dword(pdev, PCIE_GLI_9767_SD_PLL_CTL2, ssc); + pci_write_config_dword(pdev, PCIE_GLI_9767_SD_PLL_CTL, pll); + + gl9767_vhs_read(pdev); +} + +static void gl9767_set_pll(struct pci_dev *pdev, u8 dir, u16 ldiv, u8 pdiv) +{ + u32 pll; + + gl9767_vhs_write(pdev); + + pci_read_config_dword(pdev, PCIE_GLI_9767_SD_PLL_CTL, &pll); + pll &= ~(PCIE_GLI_9767_SD_PLL_CTL_PLL_LDIV | + PCIE_GLI_9767_SD_PLL_CTL_PLL_PDIV | + PCIE_GLI_9767_SD_PLL_CTL_PLL_DIR_EN); + pll |= FIELD_PREP(PCIE_GLI_9767_SD_PLL_CTL_PLL_LDIV, ldiv) | + FIELD_PREP(PCIE_GLI_9767_SD_PLL_CTL_PLL_PDIV, pdiv) | + FIELD_PREP(PCIE_GLI_9767_SD_PLL_CTL_PLL_DIR_EN, dir); + pci_write_config_dword(pdev, PCIE_GLI_9767_SD_PLL_CTL, pll); + + gl9767_vhs_read(pdev); + + /* wait for pll stable */ + msleep(1); +} + +static void gl9767_set_ssc_pll_205mhz(struct pci_dev *pdev) +{ + bool enable = gl9767_ssc_enable(pdev); + + /* set pll to 205MHz and ssc */ + gl9767_set_ssc(pdev, enable, 0x1F, 0xF5C3); + gl9767_set_pll(pdev, 0x1, 0x246, 0x0); +} + +static void gl9767_disable_ssc_pll(struct pci_dev *pdev) +{ + u32 pll; + + gl9767_vhs_write(pdev); + + pci_read_config_dword(pdev, PCIE_GLI_9767_SD_PLL_CTL, &pll); + pll &= ~(PCIE_GLI_9767_SD_PLL_CTL_PLL_DIR_EN | PCIE_GLI_9767_SD_PLL_CTL_SSC_EN); + pci_write_config_dword(pdev, PCIE_GLI_9767_SD_PLL_CTL, pll); + + gl9767_vhs_read(pdev); +} + +static void sdhci_gl9767_set_clock(struct sdhci_host *host, unsigned int clock) +{ + struct sdhci_pci_slot *slot = sdhci_priv(host); + struct mmc_ios *ios = &host->mmc->ios; + struct pci_dev *pdev; + u32 value; + u16 clk; + + pdev = slot->chip->pdev; + host->mmc->actual_clock = 0; + + gl9767_vhs_write(pdev); + + pci_read_config_dword(pdev, PCIE_GLI_9767_CFG, &value); + value |= PCIE_GLI_9767_CFG_LOW_PWR_OFF; + pci_write_config_dword(pdev, PCIE_GLI_9767_CFG, value); + + gl9767_disable_ssc_pll(pdev); + sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL); + + if (clock == 0) + return; + + clk = sdhci_calc_clk(host, clock, &host->mmc->actual_clock); + if (clock == 200000000 && ios->timing == MMC_TIMING_UHS_SDR104) { + host->mmc->actual_clock = 205000000; + gl9767_set_ssc_pll_205mhz(pdev); + } + + sdhci_enable_clk(host, clk); + + pci_read_config_dword(pdev, PCIE_GLI_9767_CFG, &value); + value &= ~PCIE_GLI_9767_CFG_LOW_PWR_OFF; + pci_write_config_dword(pdev, PCIE_GLI_9767_CFG, value); + + gl9767_vhs_read(pdev); +} + static void gli_set_9767(struct sdhci_host *host) { u32 value; @@ -1293,7 +1426,7 @@ const struct sdhci_pci_fixes sdhci_gl9763e = { }; static const struct sdhci_ops sdhci_gl9767_ops = { - .set_clock = sdhci_set_clock, + .set_clock = sdhci_gl9767_set_clock, .enable_dma = sdhci_pci_enable_dma, .set_bus_width = sdhci_set_bus_width, .reset = sdhci_gl9767_reset, From patchwork Wed May 31 11:15:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 101374 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2804268vqr; Wed, 31 May 2023 04:27:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4RcMUda9Bfnuf4OnIonTf+XLdxooG+k6fQtNW9ozbFBE51QYApFRua9mXhkv+AEVyQxW5k X-Received: by 2002:a05:6808:308c:b0:398:a09:3cb with SMTP id bl12-20020a056808308c00b003980a0903cbmr4130048oib.36.1685532477389; Wed, 31 May 2023 04:27:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685532477; cv=none; d=google.com; s=arc-20160816; b=CUsSHEuKPY5huaBunz6tXFn+ru8K/PGbDw0VwhrENqDcBdVnbcVID0TOwClT6uXA5v wcVrO7E5UzVKHsxSyasrXuJhewFY9tfjcyBKw6L3aCKFwSNri6RDZcCejuIsTy0uEheJ 9XP91/BAL+PPjWD10dWgO+6bjdZgtnss+2lni3ieQmYZlnlHhh8yH1ibN9mAtDFe3C0t FG6GE1oml7svADQwmdefnWiQIK5fBeflvZiYreHfiwBeSBoLpxQZw2Nl8hTp5Pht2VIN 4W3pMdLVkLsNT2F6fO7pvbwr7pneVZwo326w2uiTBlZ9ynrDlljSLlIhtAf/izk0z/FL rVig== 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=pqCO0zG8sg4sud8a/zg7+AbJ/Mka1xuDjw890KKydlg=; b=N+xI3ovuRm6URfAykWJS4VxpW9L3MUz0ZWVc1CSOX0wEZZFk9zNSDbjShCWicJbbKV QtEnRY8K0BbvZg32zEaJ3OnmrfNo4ogEzToAPGIXtOwcT9F9tRbYnZ31xLQDCHKRNJLW 4MABm0P1E7eTdQQnioeITXhmNsNgzxL7ssTNOSf161FiDJOr7SzJaBRA184W49g6sl5C zxmdp1U47U7p8s7u8NwSEGGMpEVB/JHZ6g3ZmChl5Pbzc77u/qxcWc97pJz3vXmUKsCD ylLeoRhoIGD4wec2g4IXBi6ueEjlZGtNghWiBdQaIN9sIV8bCHGibPbH8VoizojNYPSi tRVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=nsMryPQV; 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 j185-20020a636ec2000000b0053b8f59ac25si828038pgc.194.2023.05.31.04.27.45; Wed, 31 May 2023 04:27: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=nsMryPQV; 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 S235516AbjEaLRl (ORCPT + 99 others); Wed, 31 May 2023 07:17:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235505AbjEaLRe (ORCPT ); Wed, 31 May 2023 07:17:34 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B435F135; Wed, 31 May 2023 04:17:32 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-64d247a023aso3843991b3a.2; Wed, 31 May 2023 04:17:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685531852; x=1688123852; 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=pqCO0zG8sg4sud8a/zg7+AbJ/Mka1xuDjw890KKydlg=; b=nsMryPQVRfzMORrX9K4nt7H70UHnEGHTCwD9vBp0dciYv3aDQ5yxxhtJB/kQ8S2AQ6 YOR9tjOAvlqsxagRCX4ms102lNe4NBjEpKQX2RN/wxnbdo10tLne9a6yVDGVyxMqHaTD CuBnmZehhGuXe0UtThrjZq7qLomnNvCFaVWq741C9nRKGQi2lpepBlBmrNIqmdkb59i+ 8g88cYZp6E3GypvSEuXzzL9fbOwCJc6IFMYqRRihzTFlRlHfegyy6hwArLdxCS8jOJJD hT9wYjZp+uBLgxsSv2ACSapIdkI2Hm3I/wkbPKUrUS1SnkFJYAvnn71nfkxzjt1mRRvf HWFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685531852; x=1688123852; 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=pqCO0zG8sg4sud8a/zg7+AbJ/Mka1xuDjw890KKydlg=; b=PTLtFabC0TKHcoloKQ3MgYYTqteyFRfnBwfSkO1QU23KaV935URCp1qjxiBTDg8HUT LrXXPJw6i9ZUhntZnwI7JasJuQ0XJwnIeEBUSco37cRFmy3Tfg2B93ibPHvrUQArT0cP rALuV40DtmAk6a++BMDXtuHdMHAZzCKMXcR+v4SMVoT3zv68L5w+REeWxXeJWW18Iz57 O/TCTPzKhYg9nfrrmD7O54FuuQL+CWiwZcyvYRNnG+cFDJFaizHT0+zHVGI2AG1n52dT IR9W5cI7TltKrUA+FDmPMsH3A7L3VphAwe7k5sQ468+DbqTKJVbRY+Cirrl7wQ1IPPZF oFlQ== X-Gm-Message-State: AC+VfDxmrTna48yRDY5j8YII8bkf2NpZy8/HU8YBgA6P02TpIuBylyfR JALNQt0wc/IpwABDmhZCvmo= X-Received: by 2002:a17:902:f54b:b0:1b0:5425:2165 with SMTP id h11-20020a170902f54b00b001b054252165mr4891687plf.29.1685531852102; Wed, 31 May 2023 04:17:32 -0700 (PDT) Received: from localhost.localdomain (111-82-252-250.emome-ip.hinet.net. [111.82.252.250]) by smtp.gmail.com with ESMTPSA id d17-20020a170903231100b001b0aec3ed59sm1076588plh.256.2023.05.31.04.17.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 04:17:31 -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, Victor Shih , Ben Chuang , Victor Shih Subject: [PATCH V4 3/4] mmc: sdhci: Add VDD2 definition for power control register Date: Wed, 31 May 2023 19:15:17 +0800 Message-Id: <20230531111518.396868-4-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230531111518.396868-1-victorshihgli@gmail.com> References: <20230531111518.396868-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_NONE,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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767408902729342261?= X-GMAIL-MSGID: =?utf-8?q?1767408902729342261?= From: Victor Shih Add new definition for VDD2 - UHS2 or PCIe/NVMe. Signed-off-by: Ben Chuang Signed-off-by: Victor Shih --- drivers/mmc/host/sdhci.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index f4f2085c274c..140a0c20d4f2 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -100,6 +100,14 @@ #define SDHCI_POWER_300 0x0C #define SDHCI_POWER_330 0x0E +/* + * VDD2 - UHS2 or PCIe/NVMe + * VDD2 power on/off and voltage select + */ +#define SDHCI_VDD2_POWER_ON 0x10 +#define SDHCI_VDD2_POWER_120 0x80 +#define SDHCI_VDD2_POWER_180 0xA0 + #define SDHCI_BLOCK_GAP_CONTROL 0x2A #define SDHCI_WAKE_UP_CONTROL 0x2B From patchwork Wed May 31 11:15:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 101368 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2803829vqr; Wed, 31 May 2023 04:26:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7U9VXvoukSHXECMe/6Pccjw46mdSnrNPnseW/Hq5sxloSkdFB+ofYWoTnjAyH6LeOpZ2hq X-Received: by 2002:a17:90b:e0c:b0:255:59e9:7984 with SMTP id ge12-20020a17090b0e0c00b0025559e97984mr5257361pjb.33.1685532416693; Wed, 31 May 2023 04:26:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685532416; cv=none; d=google.com; s=arc-20160816; b=m3karz8zLkuMB1OZ9FcwnkhgieShUGEpjMEnaHMhzrRAxZSljMNFJaA7Ek2vRQEbsF gDw+NMuhBcbF+tv7GWY825IpW1uQQwKIhunSeRXuX3FZEtg1Tb+7aMzVQ4DJs5fpk+XX r7blYVnG9uB8Mliwqe5rHKMeRy1k44W72+uvFpGgQPF1Ooee3kNjFQDeEExbob7j2lgB C5QGCBdkEr58pWZolutncD+o+YUV2PWucuDOcEIUKzW8Hp90A9FkSUjOuV8B59BlY9s1 xje5xSRwqEcv/wMBwHpvQrJe4m7+ZZSG8b0qF7lWsoFmMj92rsBWbRsm2X5BXDjfffsu e2Sg== 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=xtPxOefjM4ZZdvGD2evpcXztukQ57ylG6FBkyjgKbVM=; b=Q13xLlHPVKmU/Ox9apBA9yBr3XwqF0FLteSqaWUY8wKzVlJxeoeXtK73jj0dBx71xM rybPsaqxFf4m0Jp+mjTsvflsavxvVkr2TFwHnB2DpgeYoY5dnVTkUk4TEVjrV5OGuYr/ D1DyLdzrsb4G7PXY9bW95HefnZf2OQxGzJR6ETnCcS35eCdJ8N5c6BOcfyiukYMijTuv cT6yPlUalyDrL0IZjQ4DFDpcyh4jX0FC7HxxPeCMiEN1pE94SymwIzS7BAHFgMAmev6x 4Q28jUmSLL+Oa9WHwaj7RoNn5jzi/gSAz2pXgDwz37DXZgd7PzH/zurzIedH0axgr0wC 5HNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=JWFKoins; 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 w63-20020a17090a6bc500b00256a4676b7asi835296pjj.14.2023.05.31.04.26.44; Wed, 31 May 2023 04:26:56 -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=JWFKoins; 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 S235519AbjEaLRp (ORCPT + 99 others); Wed, 31 May 2023 07:17:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235482AbjEaLRg (ORCPT ); Wed, 31 May 2023 07:17:36 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F04E12B; Wed, 31 May 2023 04:17:35 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1b04949e5baso25210405ad.0; Wed, 31 May 2023 04:17:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685531855; x=1688123855; 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=xtPxOefjM4ZZdvGD2evpcXztukQ57ylG6FBkyjgKbVM=; b=JWFKoinsE2V/9SpLB1uLSEP86duqVBAZ9I67W7uyZykLSs7tBifZq9sfPF24MTKJs1 S8VuuqV4snWsZ9nDKArd2telquFglvduMk4QPZ9BCVWCWpGNA78UbqeWChucVQ4QU7zQ qk1mrfzgWu6Q9PXT7ryOqB9VHOzeSn4/6H/uKb542v9YJ1iDxGoiGdKY0xOgWRvTrcDP JEPs4z5Gx7hRPTTAGN8wVl6pV9IfY3ZjPKJaP0lCUHxOQWRqgi53wI/ur/PsV0zx4x0Q GjuyN+gF1W0FvXYLmEn1Pr/Vb/B2NdoZyMTwbjP/qc/SZnd8V/O0OmghgJHkbLTm13MS H7JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685531855; x=1688123855; 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=xtPxOefjM4ZZdvGD2evpcXztukQ57ylG6FBkyjgKbVM=; b=PdhzClLK1RY+lSKiAhZrPqoU+/TOVpVMciBMdnLbVkGSKSqifMFZBhpACM2vNG3t+S 1QaScFmhVsB2PCe8BviH1dyu3DNJjzpoXwKeB4lkoJxSXTxGF6GTC2l2DeMxgag25jwZ Q+MnhTokoyruTfGNuLtSbv431VrXXJ6Cd8hnnI5rSLck9Cs5FG3yODcfDYQluuUaGrer OG91TfJiCuiY9e/RQTOcRbR3VgPJKH/nHEkroksfZxsJ1tDHVJYd5rpmzmeqVTwNjqUO uVrYHFImIOOPmUPNNSd4uFxUA2yDSbVlN5mF86E2pxvWbWM89qGcT6kg5D7nL3HIM/l1 24Dw== X-Gm-Message-State: AC+VfDw5vXicdCBThibWE+87j4Ij/v+TvxQM+wOl8cAIRxJLd/nFIibc Tmf+FtUm2TSQdkTtypVcfU4= X-Received: by 2002:a17:903:22cb:b0:1b0:bf80:d1f2 with SMTP id y11-20020a17090322cb00b001b0bf80d1f2mr3365069plg.49.1685531854654; Wed, 31 May 2023 04:17:34 -0700 (PDT) Received: from localhost.localdomain (111-82-252-250.emome-ip.hinet.net. [111.82.252.250]) by smtp.gmail.com with ESMTPSA id d17-20020a170903231100b001b0aec3ed59sm1076588plh.256.2023.05.31.04.17.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 04:17:34 -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, Victor Shih , Ben Chuang , Victor Shih Subject: [PATCH V4 4/4] mmc: sdhci-pci-gli: Add support SD Express card for GL9767 Date: Wed, 31 May 2023 19:15:18 +0800 Message-Id: <20230531111518.396868-5-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230531111518.396868-1-victorshihgli@gmail.com> References: <20230531111518.396868-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_NONE,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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767408839207667875?= X-GMAIL-MSGID: =?utf-8?q?1767408839207667875?= From: Victor Shih Add support SD Express card for GL9767. The workflow of the SD Express card in GL9767 is as below. 1. GL9767 operates in SD mode and set MMC_CAP2_SD_EXP flag. 2. If card is inserted, Host send CMD8 to ask the capabilities of the card. 3. If the card has PCIe capability, then init_sd_express() will be invoked. 4. If the card has been put in write protect state then the SD features supported by SD mode but not supported by PCIe mode, therefore GL9767 switch to SD mode. 5. If the card has not been put in write protect state then GL9767 switch from SD mode to PCIe/NVMe mode and mmc driver handover control to NVMe driver. 6. If card is removed, GL9767 will return to SD mode. Signed-off-by: Ben Chuang Signed-off-by: Victor Shih Acked-by: Adrian Hunter --- drivers/mmc/host/sdhci-pci-gli.c | 113 +++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/drivers/mmc/host/sdhci-pci-gli.c b/drivers/mmc/host/sdhci-pci-gli.c index 392a106cea18..e47236e3b89a 100644 --- a/drivers/mmc/host/sdhci-pci-gli.c +++ b/drivers/mmc/host/sdhci-pci-gli.c @@ -164,6 +164,10 @@ #define PCIE_GLI_9767_CFG 0x8A0 #define PCIE_GLI_9767_CFG_LOW_PWR_OFF BIT(12) +#define PCIE_GLI_9767_COMBO_MUX_CTL 0x8C8 +#define PCIE_GLI_9767_COMBO_MUX_CTL_RST_EN BIT(6) +#define PCIE_GLI_9767_COMBO_MUX_CTL_WAIT_PERST_EN BIT(10) + #define PCIE_GLI_9767_PWR_MACRO_CTL 0x8D0 #define PCIE_GLI_9767_PWR_MACRO_CTL_LOW_VOLTAGE GENMASK(3, 0) #define PCIE_GLI_9767_PWR_MACRO_CTL_LD0_LOW_OUTPUT_VOLTAGE GENMASK(15, 12) @@ -181,6 +185,9 @@ #define PCIE_GLI_9767_SCR_CORE_PWR_D3_OFF BIT(21) #define PCIE_GLI_9767_SCR_CFG_RST_DATA_LINK_DOWN BIT(30) +#define PCIE_GLI_9767_SDHC_CAP 0x91C +#define PCIE_GLI_9767_SDHC_CAP_SDEI_RESULT BIT(5) + #define PCIE_GLI_9767_SD_PLL_CTL 0x938 #define PCIE_GLI_9767_SD_PLL_CTL_PLL_LDIV GENMASK(9, 0) #define PCIE_GLI_9767_SD_PLL_CTL_PLL_PDIV GENMASK(15, 12) @@ -191,6 +198,23 @@ #define PCIE_GLI_9767_SD_PLL_CTL2 0x93C #define PCIE_GLI_9767_SD_PLL_CTL2_PLLSSC_PPM GENMASK(31, 16) +#define PCIE_GLI_9767_SD_EXPRESS_CTL 0x940 +#define PCIE_GLI_9767_SD_EXPRESS_CTL_SDEI_EXE BIT(0) +#define PCIE_GLI_9767_SD_EXPRESS_CTL_SD_EXPRESS_MODE BIT(1) + +#define PCIE_GLI_9767_SD_DATA_MULTI_CTL 0x944 +#define PCIE_GLI_9767_SD_DATA_MULTI_CTL_DISCONNECT_TIME GENMASK(23, 16) +#define PCIE_GLI_9767_SD_DATA_MULTI_CTL_DISCONNECT_TIME_VALUE 0x64 + +#define PCIE_GLI_9767_NORMAL_ERR_INT_STATUS_REG2 0x950 +#define PCIE_GLI_9767_NORMAL_ERR_INT_STATUS_REG2_SDEI_COMPLETE BIT(0) + +#define PCIE_GLI_9767_NORMAL_ERR_INT_STATUS_EN_REG2 0x954 +#define PCIE_GLI_9767_NORMAL_ERR_INT_STATUS_EN_REG2_SDEI_COMPLETE_STATUS_EN BIT(0) + +#define PCIE_GLI_9767_NORMAL_ERR_INT_SIGNAL_EN_REG2 0x958 +#define PCIE_GLI_9767_NORMAL_ERR_INT_SIGNAL_EN_REG2_SDEI_COMPLETE_SIGNAL_EN BIT(0) + #define GLI_MAX_TUNING_LOOP 40 /* Genesys Logic chipset */ @@ -935,6 +959,93 @@ static void sdhci_gl9767_reset(struct sdhci_host *host, u8 mask) gli_set_9767(host); } +static int gl9767_init_sd_express(struct mmc_host *mmc, struct mmc_ios *ios) +{ + struct sdhci_host *host = mmc_priv(mmc); + struct sdhci_pci_slot *slot = sdhci_priv(host); + struct pci_dev *pdev; + u32 value; + int i; + + pdev = slot->chip->pdev; + + if (mmc->ops->get_ro(mmc)) { + mmc->ios.timing &= ~(MMC_TIMING_SD_EXP | MMC_TIMING_SD_EXP_1_2V); + return 0; + } + + gl9767_vhs_write(pdev); + + pci_read_config_dword(pdev, PCIE_GLI_9767_COMBO_MUX_CTL, &value); + value &= ~(PCIE_GLI_9767_COMBO_MUX_CTL_RST_EN | PCIE_GLI_9767_COMBO_MUX_CTL_WAIT_PERST_EN); + pci_write_config_dword(pdev, PCIE_GLI_9767_COMBO_MUX_CTL, value); + + pci_read_config_dword(pdev, PCIE_GLI_9767_SD_DATA_MULTI_CTL, &value); + value &= ~PCIE_GLI_9767_SD_DATA_MULTI_CTL_DISCONNECT_TIME; + value |= FIELD_PREP(PCIE_GLI_9767_SD_DATA_MULTI_CTL_DISCONNECT_TIME, + PCIE_GLI_9767_SD_DATA_MULTI_CTL_DISCONNECT_TIME_VALUE); + pci_write_config_dword(pdev, PCIE_GLI_9767_SD_DATA_MULTI_CTL, value); + + pci_read_config_dword(pdev, PCIE_GLI_9767_NORMAL_ERR_INT_STATUS_REG2, &value); + value |= PCIE_GLI_9767_NORMAL_ERR_INT_STATUS_REG2_SDEI_COMPLETE; + pci_write_config_dword(pdev, PCIE_GLI_9767_NORMAL_ERR_INT_STATUS_REG2, value); + + pci_read_config_dword(pdev, PCIE_GLI_9767_NORMAL_ERR_INT_STATUS_EN_REG2, &value); + value |= PCIE_GLI_9767_NORMAL_ERR_INT_STATUS_EN_REG2_SDEI_COMPLETE_STATUS_EN; + pci_write_config_dword(pdev, PCIE_GLI_9767_NORMAL_ERR_INT_STATUS_EN_REG2, value); + + pci_read_config_dword(pdev, PCIE_GLI_9767_NORMAL_ERR_INT_SIGNAL_EN_REG2, &value); + value |= PCIE_GLI_9767_NORMAL_ERR_INT_SIGNAL_EN_REG2_SDEI_COMPLETE_SIGNAL_EN; + pci_write_config_dword(pdev, PCIE_GLI_9767_NORMAL_ERR_INT_SIGNAL_EN_REG2, value); + + pci_read_config_dword(pdev, PCIE_GLI_9767_CFG, &value); + value |= PCIE_GLI_9767_CFG_LOW_PWR_OFF; + pci_write_config_dword(pdev, PCIE_GLI_9767_CFG, value); + + value = sdhci_readw(host, SDHCI_CLOCK_CONTROL); + value &= ~(SDHCI_CLOCK_CARD_EN | SDHCI_CLOCK_PLL_EN); + sdhci_writew(host, value, SDHCI_CLOCK_CONTROL); + + value = sdhci_readb(host, SDHCI_POWER_CONTROL); + value |= (SDHCI_VDD2_POWER_180 | SDHCI_VDD2_POWER_ON); + sdhci_writeb(host, value, SDHCI_POWER_CONTROL); + + pci_read_config_dword(pdev, PCIE_GLI_9767_SD_EXPRESS_CTL, &value); + value |= PCIE_GLI_9767_SD_EXPRESS_CTL_SDEI_EXE; + pci_write_config_dword(pdev, PCIE_GLI_9767_SD_EXPRESS_CTL, value); + + for (i = 0; i < 2; i++) { + msleep(10); + pci_read_config_dword(pdev, PCIE_GLI_9767_NORMAL_ERR_INT_STATUS_REG2, &value); + if (value & PCIE_GLI_9767_NORMAL_ERR_INT_STATUS_REG2_SDEI_COMPLETE) { + pci_write_config_dword(pdev, PCIE_GLI_9767_NORMAL_ERR_INT_STATUS_REG2, + value); + break; + } + } + + pci_read_config_dword(pdev, PCIE_GLI_9767_SDHC_CAP, &value); + if (value & PCIE_GLI_9767_SDHC_CAP_SDEI_RESULT) { + pci_read_config_dword(pdev, PCIE_GLI_9767_SD_EXPRESS_CTL, &value); + value |= PCIE_GLI_9767_SD_EXPRESS_CTL_SD_EXPRESS_MODE; + pci_write_config_dword(pdev, PCIE_GLI_9767_SD_EXPRESS_CTL, value); + } else { + mmc->ios.timing &= ~(MMC_TIMING_SD_EXP | MMC_TIMING_SD_EXP_1_2V); + + value = sdhci_readb(host, SDHCI_POWER_CONTROL); + value &= ~(SDHCI_VDD2_POWER_180 | SDHCI_VDD2_POWER_ON); + sdhci_writeb(host, value, SDHCI_POWER_CONTROL); + + value = sdhci_readw(host, SDHCI_CLOCK_CONTROL); + value |= (SDHCI_CLOCK_CARD_EN | SDHCI_CLOCK_PLL_EN); + sdhci_writew(host, value, SDHCI_CLOCK_CONTROL); + } + + gl9767_vhs_read(pdev); + + return 0; +} + static int gli_probe_slot_gl9750(struct sdhci_pci_slot *slot) { struct sdhci_host *host = slot->host; @@ -967,6 +1078,8 @@ static int gli_probe_slot_gl9767(struct sdhci_pci_slot *slot) gl9767_hw_setting(slot); gli_pcie_enable_msi(slot); slot->host->mmc->caps2 |= MMC_CAP2_NO_SDIO; + host->mmc->caps2 |= MMC_CAP2_SD_EXP; + host->mmc_host_ops.init_sd_express = gl9767_init_sd_express; sdhci_enable_v4_mode(host); return 0;