From patchwork Thu Jun 1 01:51:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 101635 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1448vqr; Wed, 31 May 2023 18:53:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5CsP6MM4mQbDEtj2ZzHZIv2c7W2sUj72i9scT7T2skTzt0tusk0fCqmcXiUrVt5jm2RJNW X-Received: by 2002:a05:6358:7e90:b0:123:5465:9284 with SMTP id o16-20020a0563587e9000b0012354659284mr4107215rwn.4.1685584391403; Wed, 31 May 2023 18:53:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685584391; cv=none; d=google.com; s=arc-20160816; b=MJR00bztxyHwKcI8/PpIKhFhGV6S+4LZRYfBmZSKC8+cvsMf8V2LZvqXo4+YDISSv6 1E1hPbg7Am5NthKlI0AGFTIz/N80jw1A2WgtKa/QfDaisR/jBTwMME543GLz9CAE36Wm 6ZRo1Tn4mjYUQYfU8NeXYmUVPPFnGf0u78ZSKyqxzq+WBty8XHxGQWYCB9ZMb3wuWMnV +oMUY2aXGxbG0jiF+ho861W9T/DdiLyh/tv0hWZQQVQ8NnHXtCp2j8BMmBVVz5tPqtW8 oPW9XOehkN5NW/nZkoRuiyPgAaQKcmfdGY5DDj9Px8CbylbJTCK/nW8gkYBNLTV0wlcZ C8iQ== 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=VpHhwaoFfaulVz2B5B5gJypc9hlm99PTjL/7tA4dO1X19b2k8e2I3yl+SiYvW0JQHs nM48KIM1R1AGDCL1mpXBoALu1M8+CHodtbm3Jg9Md/P4QHq1nBnnSJGJgDLDr/8r/IJG ST55XXYwKOjg1oAu45QlRAtqQzsx3O4YYU/z9kdLcTE/cz4Kz6a9h8b5a8LbYf76fo5h DzTekK81dmzhSdvl+V0aahP0K21Vv2ey/fKP812/DtBinNDOSFYeg4jHGJnjJkE4RTqo uvguRS/LNIFskHuhBvb5ZmueC005ievr+JA0+eqtHqYn6imhzbmNR5RjvfeuIe9xauKA 5XBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="Yate1fF/"; 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 lr8-20020a17090b4b8800b0024e500f3749si308511pjb.68.2023.05.31.18.52.58; Wed, 31 May 2023 18:53:11 -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="Yate1fF/"; 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 S230328AbjFABvb (ORCPT + 99 others); Wed, 31 May 2023 21:51:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229588AbjFABv2 (ORCPT ); Wed, 31 May 2023 21:51:28 -0400 Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CECD3A3; Wed, 31 May 2023 18:51:26 -0700 (PDT) Received: by mail-ot1-x32e.google.com with SMTP id 46e09a7af769-6af86627460so378772a34.1; Wed, 31 May 2023 18:51:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685584286; x=1688176286; 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=Yate1fF/+TknhGMnXdwmiZdKDJZ5f0Afwqj1nDwcsRfh09DgZplgq2/TFb4q10YWbd wBzb7wjV8GyUEsjXbG33x6wiwKBNjgH6clVz+JwptyYtqprkSt3Ir3cOfbT9Hvo9Idx8 sOdDMtg20WbZQtDuQg4b1vmuJB+hRZ88YSiQKbLIltbVLB2nU83tfFpd1vIB2DJ5zmxm +C6xHgwmGu7rTc+bvx6kj7jihcmRW1aN3UpRq34RsS2CMumXmBZhkijbatIJFJ1yWtf7 ZpU09RHSFbYotS68+upG62f4wZDH1PUJlTj3ii1+Keg0f+DbGOqFN71cjl6p4iwfk14w dBhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685584286; x=1688176286; 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=eOojVah4M4tbIS7IZPgXqQQzF/x5WdS1oI9eGsK8iz5wzcm/g+A0tWAw8SeRj9layy rH5Q4d6ZJX7kCbBC3ZJMIb8xYFGFWvajZh9oHXiixLun03GYQiGpPjVsb3pUMwEY2AgK vWYm3Y+YFC5T4iYq2vGVyzO1tcmK07PqtKaSnB7PvIqEP++UlHIplIHrDIqAzD0N0TYI N+6AcqSGQGX/HnONzZpERhi5ZOSmUZmJTp+RZY0VebVRahseu4ooS8p/2RBwpBlc9yZg y41l3x8kmiSF15lJjan4oTDlSDZ4CQTOCv6tzxVRkimNs/BP48kXQyjUOilREsBKTF1y KkQQ== X-Gm-Message-State: AC+VfDzMpv2YymHNA19/q3lawxCzjZog/iOG+cL2QhfH/gkuPnRmXpif W0PUsS+BDEuX94t8wZ4ncsY= X-Received: by 2002:a05:6358:280c:b0:123:59c1:7c7e with SMTP id k12-20020a056358280c00b0012359c17c7emr4172879rwb.18.1685584285970; Wed, 31 May 2023 18:51:25 -0700 (PDT) Received: from localhost.localdomain (2001-b400-e454-8dbb-0377-d3ab-ebce-7b9b.emome-ip6.hinet.net. [2001:b400:e454:8dbb:377:d3ab:ebce:7b9b]) by smtp.gmail.com with ESMTPSA id e2-20020a17090a7c4200b00253239144c5sm165795pjl.42.2023.05.31.18.51.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 18:51:25 -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 V5 1/4] mmc: sdhci-pci-gli: Add Genesys Logic GL9767 support Date: Thu, 1 Jun 2023 09:51:12 +0800 Message-Id: <20230601015115.406002-2-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230601015115.406002-1-victorshihgli@gmail.com> References: <20230601015115.406002-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?1767463338922956323?= X-GMAIL-MSGID: =?utf-8?q?1767463338922956323?= 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 Thu Jun 1 01:51:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 101639 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3519vqr; Wed, 31 May 2023 19:07:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5dhVe4JpkPnEawsox8PVjiyj2ai/GqzwjnlKCxD/ZfyBfm3bQvvDJFyQ8hJJAtQdU2in4i X-Received: by 2002:a0d:d688:0:b0:559:d39e:e1e8 with SMTP id y130-20020a0dd688000000b00559d39ee1e8mr8591929ywd.44.1685585262680; Wed, 31 May 2023 19:07:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685585262; cv=none; d=google.com; s=arc-20160816; b=TP7SZMf5f+DrUUEXWU397xQFrYZI0049v/NZndOc1UzVgBCtcMQGaPv3T4vUYj9p1O 1BaJKJCQ2+PJ9Vi6pHU1kKsf/Er0/KkNphmNWi6iO8F3m9YZzRxiiF4NdObHr1LhQ217 xjx5g0vP0GVk1KUH92upUgWlC4KCK2YyH7zKxJ93IlroclRaR3uvGFd6RxUT/Oca+EVy SRFsKm0/dJPxBRnlCdHlMqQWy6cQ+2B0bELh7aXd99906OkoN8vGJ9q5jBuiP26xy8st TGYhwPyoIBRvTMwzSxhdDq1dNVta1KpFeXmykl3sVGCAzwaIZqq2zOp9gGdoLL0M9M3W WkXw== 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=GmZhs3xkBFtYjTaj/+/H0NyOdCM/M1jw0znRNVS9PwdHipT6/3UatGZpgjqc3kKATN 6mEJQ66qDGaw0X/fuWbCcCFpWBvvql5pp9K0jGq8/f/nNMWi+aVR/yRRYAKzNTF4/bjS 14y/wd/PaOekbPgKTs5bnpuY7OXjHmKy/HyxBZU6RcagYGDOJ5/tYAF8DpFxHqHzEaRo MimpZxpAaUVw11G3Q/mkkwe3EbWmK6WJI+NYRf9GrZ2HC+lMXetzQ+cgVsra/uZ708UF 15wiqSDO2EBDt+7gX2VRq47XiSuMTfLvdYbqfnVam8ELZXY8fIqeLczvpV49gphZldDE R51Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=knWH0ze5; 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 z128-20020a626586000000b0064d6a514682si2723572pfb.366.2023.05.31.19.07.27; Wed, 31 May 2023 19:07: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=knWH0ze5; 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 S229851AbjFABvd (ORCPT + 99 others); Wed, 31 May 2023 21:51:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229741AbjFABvb (ORCPT ); Wed, 31 May 2023 21:51:31 -0400 Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A008134; Wed, 31 May 2023 18:51:29 -0700 (PDT) Received: by mail-qk1-x72b.google.com with SMTP id af79cd13be357-75b14216386so22845485a.0; Wed, 31 May 2023 18:51:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685584288; x=1688176288; 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=knWH0ze5tDjW2LCZUgDZcXCQ+z4BMXqhXIKNFwmJvnHmwAsx3OjW7/FR9eLG2w78AX UtlpGYIuTelxOdj5l3w1BiDuGWuvyZFYUWxGwJ4akH0QafMvXvlv6ujE4AL8q3OxjULl f0IyBZ+FuxCZB05+d3+sZHoP7/mP1E51FIIJxn1B3pk3duNt19ZEqTugn+dtPunwdj2x V3n+SYpjQBNlncBQ70yGWoWqppTFTBRxjB2y2K8UDvOBPOoEMndoTdAw0Jk9SmaTpmS2 51JohUQuyO5+M8zAjbTIQKBSjp5T3oiU8YD/loSSTqSHGTSjAlJ4K8rRj5FkuF9bpijD tvTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685584288; x=1688176288; 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=kR88ZW/g4Wpi6Cc/Il9BtxGnmZaIHgROtesFK1WuNBFhb9UeHJOh1F4BsQ678HaPJ8 hJa5jzbALMMp0OLA4gLeamC8f/NZYaytx/WDntTOJN4Va+su8M/KNbQ9lCSH0DJVNAyC TeOswuP98pmyrxolfNhRa3yK5gsCMeUQt9LFmjw8YRVcEMVaQaMvMcvAGPE+2nS3pGVh TytikhZiLIb3z6KXkAvcKhBO6gPNKtVGH7Z0uRswqH5B/ufL8YExLOpjo+FsIc9Kc5fp JfufZfUs6kYK0ytgwbVrG5tR1N/3Ra6RnhwKEiqbHzjcF8SuXoNS63l/D+fEn/Q1LHvX VzPA== X-Gm-Message-State: AC+VfDwx6dG+OLW9O6XUTaw0PP5lOc8LYY44cX8qWf/kY0a8ifguAsFe wAcrsvvTXS5KQ0R5UOU9SSglqKuTm0g= X-Received: by 2002:a05:620a:f01:b0:75b:23a0:e7cd with SMTP id v1-20020a05620a0f0100b0075b23a0e7cdmr9567356qkl.46.1685584288451; Wed, 31 May 2023 18:51:28 -0700 (PDT) Received: from localhost.localdomain (2001-b400-e454-8dbb-0377-d3ab-ebce-7b9b.emome-ip6.hinet.net. [2001:b400:e454:8dbb:377:d3ab:ebce:7b9b]) by smtp.gmail.com with ESMTPSA id e2-20020a17090a7c4200b00253239144c5sm165795pjl.42.2023.05.31.18.51.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 18:51:28 -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 V5 2/4] mmc: sdhci-pci-gli: Set SDR104's clock to 205MHz and enable SSC for GL9767 Date: Thu, 1 Jun 2023 09:51:13 +0800 Message-Id: <20230601015115.406002-3-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230601015115.406002-1-victorshihgli@gmail.com> References: <20230601015115.406002-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?1767464252528020576?= X-GMAIL-MSGID: =?utf-8?q?1767464252528020576?= 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 Thu Jun 1 01:51:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 101636 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1530vqr; Wed, 31 May 2023 18:53:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6WmD1rF+ajrT75IdLY5+h09/nite6qxdRkLGoLePuW6IBow6MSZBnItWgxqPJl+PbcRGu3 X-Received: by 2002:a9d:6a8c:0:b0:6a8:b659:d46e with SMTP id l12-20020a9d6a8c000000b006a8b659d46emr4314867otq.8.1685584433553; Wed, 31 May 2023 18:53:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685584433; cv=none; d=google.com; s=arc-20160816; b=tzj19VoPVw7rzD4sPrPTJMA6xwATnI0oTJdnmXx4tkuHa2SmgboMtHpeCdtkTD/0Lf +MkcAmT3IiDA3Ff6dnIPaq21xNaed7y4VJz8vc+F/pH/qBT03In4/ygPmfqjr8umzbwI Y7L4XL++xG9RhrV6lUccJdFWlTgR3P1daai6Kcsfrj1M+gf4gMS7pHurPPfcJ1YEGZ00 Lcp9fOtgs8AyRiwryti8FTr4cBVhSW3GQokctVXswUHeL1vLtYDCJabR4/4FNDOobAM8 LBbM9s14wlh6e3GZD3z1evQHZ+C5KFCUyN6K923xYUTvdATsHnNjez1gn4RhzDvcyi79 3d8Q== 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=CgQbAD4zC7kyh7MqqeeXdMAW7P6yao31pgzuJElJL7w=; b=CREF43AaEKO53P8TGRBB7VS2g/QiegN0iqzlbqvH5kJKrAbNGCO/BNzl4vGB2q4n0I bcKuUP8VFwSepzbBxYO9qB5cy41VXnlQVb12JaHmNGmWcFG6Le4BDOSoECjVZCP81czY NL8ZNaalI82LonlaJnfaLx+vwcvLk1qYFulTPiJqpXenTrDuUIrXD/TV17a535PyhEAp 9ethnQwfQBlEVIlV1+cD+tQrhWr3MgUXOouQ5NTk2ywTWnV2k8ZAHBXC3yiR+rj5ab3e AHEpO3hx8zaVWXFp7t7l6KXaSvSS/BlpIpuXX+E9OfxubBS/kUpJZSaQEhqd6HI9W+RT 2h9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=kkUyzVm4; 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 125-20020a620683000000b0063b82c09424si4120180pfg.151.2023.05.31.18.53.39; Wed, 31 May 2023 18:53:53 -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=kkUyzVm4; 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 S230390AbjFABvf (ORCPT + 99 others); Wed, 31 May 2023 21:51:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229992AbjFABvc (ORCPT ); Wed, 31 May 2023 21:51:32 -0400 Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA5DD133; Wed, 31 May 2023 18:51:31 -0700 (PDT) Received: by mail-oo1-xc33.google.com with SMTP id 006d021491bc7-5552cbcda35so260770eaf.1; Wed, 31 May 2023 18:51:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685584291; x=1688176291; 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=CgQbAD4zC7kyh7MqqeeXdMAW7P6yao31pgzuJElJL7w=; b=kkUyzVm4MihjTQwP3aZCH9VByi9/iotHw8zdfTHaZMCneJN/1tdYpbSFeJ76KlkIlw 3CwEDh2ZMKFdbFHGmbB8lXhk/gFu13dULDc5jksvXtDOB+dUHcdg3maMeWC4VknpWMRI tx6+Y1Cv6aM1V+Fp1QEh/fwc2TMM2o23xXn69XOlLOsr5XJmP6YlBUslvJcDogCZEpDF 3mgNh6awT0MHfnlbKREn3TWdvjHT9pihG3j1Hy8ZfNdEXHbMW6CMAUp/s/a9lrihnC42 Txbhg/nd4qHtVEcZLx1HYIjThOQjg91Y42ZxC+F/LBySCm2VUnA5xCgtrxp7fFb1jAro 4aFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685584291; x=1688176291; 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=CgQbAD4zC7kyh7MqqeeXdMAW7P6yao31pgzuJElJL7w=; b=FJ3k+5Iu+zh+ZamfE8qvgNX/f+ETaclLGs1BkZ3x5UawWGLxfiZG6LvZ+S31WOlOFw 89BLR4Mp1yWddM77eisTnOo8Y2kIuR2ACmJydq5aHUtYSDgfDlbLbd58KR3FXkKepJuF YWoXA54+4DEcIC7FihilfzUkk90pvBigkHG5Kdh0L75cCCxWQxjnk91Uwky+LPW01DrW IYUuqC28p7UJI6n4wQn4NXaDkdEfBUQhVWvjvhuMzc5Ju1Q/PlyP/NyvG0Zd/WHkJ7if JZ1PF7UYEAu4HOEhlFcPEOfeKSXVxPBzsxUGKvsFQ4QrtAriECNcWJNkATHruPqtV2nj 6TWA== X-Gm-Message-State: AC+VfDwMUP5sj4ZQ38JEzmzemOjNYRqgAqQ5/jGYGiJ10afK6MGUqYkk +qiIKLM5DDxphElNXF/1sjoqOGc8Ns0= X-Received: by 2002:a05:6358:4411:b0:123:1395:629f with SMTP id z17-20020a056358441100b001231395629fmr4575739rwc.8.1685584291061; Wed, 31 May 2023 18:51:31 -0700 (PDT) Received: from localhost.localdomain (2001-b400-e454-8dbb-0377-d3ab-ebce-7b9b.emome-ip6.hinet.net. [2001:b400:e454:8dbb:377:d3ab:ebce:7b9b]) by smtp.gmail.com with ESMTPSA id e2-20020a17090a7c4200b00253239144c5sm165795pjl.42.2023.05.31.18.51.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 18:51:30 -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 V5 3/4] mmc: sdhci: Add VDD2 definition for power control register Date: Thu, 1 Jun 2023 09:51:14 +0800 Message-Id: <20230601015115.406002-4-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230601015115.406002-1-victorshihgli@gmail.com> References: <20230601015115.406002-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?1767463382843147854?= X-GMAIL-MSGID: =?utf-8?q?1767463382843147854?= From: Victor Shih Add new definition for VDD2 - UHS2 or PCIe/NVMe. Signed-off-by: Ben Chuang Signed-off-by: Victor Shih Acked-by: Adrian Hunter --- drivers/mmc/host/sdhci.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index f4f2085c274c..f219bdea8f28 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -99,6 +99,13 @@ #define SDHCI_POWER_180 0x0A #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 From patchwork Thu Jun 1 01:51: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: 101637 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2261vqr; Wed, 31 May 2023 19:00:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7SlVHHvvwQ4WZHhtJZTvJMAGkHabKeMM+k/rSywch1p8pbPBHHA6lwR4k2Z8pcRK6DirAC X-Received: by 2002:a05:6358:9910:b0:117:ff48:9582 with SMTP id w16-20020a056358991000b00117ff489582mr5091819rwa.21.1685584818246; Wed, 31 May 2023 19:00:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685584818; cv=none; d=google.com; s=arc-20160816; b=nzfDi9osoG8QRSdZ5ux9cSDUZE5dS1WwwWpZDZ75ejV4fnliT6TeGJJMrkrHqzGVp4 doHEhH519pUAhU83/qcnXEeDlgxym8Xg09oxtEGAMeKDt6F5WrIMuE7GIE4sDL5TpQw5 rjhNCWwarwhvCoHp1fqacykpFZtEYrY3zY9xvbjZQrGENN+JtYleL58nXrNm6zj8ngUW 4kQLzBJfO3gBCiuOaWJwpxsC/HznzFIH5VMEPxt7TfAFDci6o44tKLo5vBA134e+vYm6 VPLDjn2z63X0kRoRVZw46g7bqQdelk4PuyhJnlPnG9aRs9NLC3MBTd+pqlOp1+9OUBom YBKw== 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=0YtnC+ivRd+yaQNSAJHN92lBak7PFbLa8TMCQnN22IM=; b=lWXC2VT2nSmd4Gw/z+Twgw75VEBx0rXkIoBbJZFbR0Zo5uCWZcUXkrvgLO2DIBMr6k f6J59kKSl53JyRCJ3qmd9SOsPIPKKxjI8TzuTHlihjD7F5Da7b+4blvc3lGsy0s0Spg3 uBfWg+ZDP/CpoJflqhaRuyK4vP/IgGEpDacjHalWQdsNV2hQIaZsjoMKEZaqGAr5MzZz CpU0vr3mK0P4VcQ5JTWFGdMdaF0GdAjNNrDUbf8XGjCZsYf/F8xZJt5GnFaJZX0AIwXl jIDlkZgkM44yP1DRxasxpPfKHTrXkthehk7mrr7MCZ1c0T0k6dVJqKDwRx+x9khDlaZi 4yig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=DKvtGGxE; 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 l62-20020a638841000000b0053422305c20si2175254pgd.14.2023.05.31.19.00.01; Wed, 31 May 2023 19:00:18 -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=DKvtGGxE; 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 S230443AbjFABvm (ORCPT + 99 others); Wed, 31 May 2023 21:51:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229714AbjFABvj (ORCPT ); Wed, 31 May 2023 21:51:39 -0400 Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E71B13E; Wed, 31 May 2023 18:51:34 -0700 (PDT) Received: by mail-ot1-x32c.google.com with SMTP id 46e09a7af769-6af6b5cf489so389299a34.3; Wed, 31 May 2023 18:51:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685584293; x=1688176293; 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=0YtnC+ivRd+yaQNSAJHN92lBak7PFbLa8TMCQnN22IM=; b=DKvtGGxEaMnOdL/XwVM6RiZkNbUSuNVVlWfkUr4X9VCBpAxajivEH/kuQjtoo9scih pfrYkI0yCQLic0lWxH5/Wmt+DWNOz8YihfhWrQRC4i/NlbCcoAR8gjhT+pWbPPi25T4M Z+HqZ4mIxkDq3XiF3xkqlJRLT4z5GVNi76oSSm+0VXu8CzA+iHX6BIUfGvaGbr3VSlhs FaWnqiT3ta52aAfsz+Pw5/d6GgvAYWfjIqPj2sabMovv3yBEJqDQLd3BoBpCiCX4JaFd Hp/icFF/E6JP49punPL03v5oMtiUJsgxA5nz2mL/pTC8UtlJweBIFglbe8XK/f0LcShZ oOqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685584293; x=1688176293; 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=0YtnC+ivRd+yaQNSAJHN92lBak7PFbLa8TMCQnN22IM=; b=SRnL14r11W7eL4ZN4lftqb1GLQXPeQl3c7pYpwLBwh8U8hzmQhi11sZHvv38cUZ9pd j8ph2QiM9NHqFvGyH6kG/INqQGmmCSbL61Nba3HiCKLqhHpFrD3YwQpbIUePftpf8FGs 19UhNmROS0eJbY8oIgdKL6vn45Qblhgc52MBe/bC2tMgQrTI0X7v76Cbo6CoyjWe+8Tq ggepDsA1WuB8jr3gg7kRk5p+t5QKJxwTujlJgDg/UJu9/tI4kHepozPAinJWhznAz3Db /gp5wDD2oTVXchTVhEvw+Wo4n+8o9sUVV4nrKRThKx0PtFpFcnafHmurmlzz81Bd9i0D KCOQ== X-Gm-Message-State: AC+VfDx+9cAVYEU7t3+XdIfrHkhImE8T2pKTndv7Ph2vi6qfGwIP6kDo 0r0jDzf9eFARyvwsd19ngnI= X-Received: by 2002:a05:6358:ce1a:b0:127:d8c1:b829 with SMTP id gt26-20020a056358ce1a00b00127d8c1b829mr679039rwb.27.1685584293599; Wed, 31 May 2023 18:51:33 -0700 (PDT) Received: from localhost.localdomain (2001-b400-e454-8dbb-0377-d3ab-ebce-7b9b.emome-ip6.hinet.net. [2001:b400:e454:8dbb:377:d3ab:ebce:7b9b]) by smtp.gmail.com with ESMTPSA id e2-20020a17090a7c4200b00253239144c5sm165795pjl.42.2023.05.31.18.51.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 18:51:33 -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 V5 4/4] mmc: sdhci-pci-gli: Add support SD Express card for GL9767 Date: Thu, 1 Jun 2023 09:51:15 +0800 Message-Id: <20230601015115.406002-5-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230601015115.406002-1-victorshihgli@gmail.com> References: <20230601015115.406002-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?1767463786681491153?= X-GMAIL-MSGID: =?utf-8?q?1767463786681491153?= 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;