From patchwork Tue Nov 27 06:48:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ernest Zhang(WH)" X-Patchwork-Id: 10699755 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4F6FA14D6 for ; Tue, 27 Nov 2018 06:48:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FB072A05B for ; Tue, 27 Nov 2018 06:48:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 336072A0E1; Tue, 27 Nov 2018 06:48:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B05D2A05B for ; Tue, 27 Nov 2018 06:48:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728571AbeK0RpT (ORCPT ); Tue, 27 Nov 2018 12:45:19 -0500 Received: from mail-eopbgr730114.outbound.protection.outlook.com ([40.107.73.114]:10896 "EHLO NAM05-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727684AbeK0RpS (ORCPT ); Tue, 27 Nov 2018 12:45:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=towerbridgetechnology.onmicrosoft.com; s=selector1-bayhubtech-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=F3JBntfT0pIBmvCqqitmk++S19Eo5ru2JtEt9Wag7DE=; b=XsGvijpXHyXl+Hgcz4dWap/xXstlLRKfJP7erxYazGHJXdChY123xLspqZJKyjxu9nfCnJT4YeOZR/q2CLKSL1P2jQttMo7bA4WhzekDS8Yp1cYH3pKTnb8lfRGB6RomrtY8qyoGwtOrwksnPxqkm9q2g1aRXAeZlY2WYHmXmjs= Received: from SN6PR16MB2542.namprd16.prod.outlook.com (52.135.125.202) by SN6PR16MB2576.namprd16.prod.outlook.com (52.135.126.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1361.15; Tue, 27 Nov 2018 06:48:09 +0000 Received: from SN6PR16MB2542.namprd16.prod.outlook.com ([fe80::e952:b844:33e1:d26e]) by SN6PR16MB2542.namprd16.prod.outlook.com ([fe80::e952:b844:33e1:d26e%5]) with mapi id 15.20.1361.019; Tue, 27 Nov 2018 06:48:09 +0000 From: "Ernest Zhang(WH)" To: Adrian Hunter , Ulf Hansson , "linux-mmc@vger.kernel.org" CC: "Xiaoguang Yu (WH)" , "Bobby Wu (WH)" , "Shirley Her (SC)" , "Ernest Zhang(WH)" Subject: [PATCH] mmc: sdhci: Fix O2 Host PLL and card detect issue Thread-Topic: [PATCH] mmc: sdhci: Fix O2 Host PLL and card detect issue Thread-Index: AQHUhh0obLELKw+4yEO002XsgmxNWw== Date: Tue, 27 Nov 2018 06:48:09 +0000 Message-ID: <20181127064410.4770-1-ernest.zhang@bayhubtech.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HK2PR04CA0082.apcprd04.prod.outlook.com (2603:1096:202:15::26) To SN6PR16MB2542.namprd16.prod.outlook.com (2603:10b6:805:d3::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=ernest.zhang@bayhubtech.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [240e:b5:4812:76e9:c575:f98a:b419:d371] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;SN6PR16MB2576;6:ouTu7hTon+1yaWvjyWYReAdi6iZE82+HADIlvmZakIKcI6vuqh3/TocrD/VisDxApCt28C7wIwGLfSTytqHZRpbIYiS5rIAHw8phTaUD22F5q/xPgvWTzoQsSEzwEt72qZQfc6AW91zCrSyhoavT5NCrqjy4ALsY9b9LlkYwfNTM7qamrc5Bbb/2dyO7KoJ/cOpd1obynXxZ3hZRL4rk+sdErTi2vZQcBlWGMC4gWHWaobsOivfq//2itrOxKyEN7wWY9aPins4ms9A4E30epiM6iXxy++8HyKv3yc8bRK3kJVyP/+ftLqfDZTgasJ/UfHuLEP3zfWBaIBj4BWJsaK5Z8BUhwEReewXCUASlzBX9NS/o4XBEnPNvVCr46EKZAfG2675Et5lYa+FLu2O6VUnmwUA7+EsWO2x4myXPERylecM5pFddzVZx54kusoe87G10tS8mbTXu0dt8/oDcOw==;5:fThqaPoQuAcXp40GfH3006sF2sQkiJaS3aEFShzjuuJSsQ5wofvsr9j6xaN28/jdXQkJ5Tzmnq6NPF9lTpYf2qyMhNuM/d9n6/h4lZI3j/M/UUwJEn0sf0sWBjQ8XXQ8lARnPY8tYASXq6bZVoKMP+iMPs3Nne4FUQPc0WSHPTE=;7:1tqAo1bhtgPOyh0Dn2p+P7IiP7z5zAMsE0WhB7Dvx/wUDmG4+sDA6xs7NXHFjJm1W/v+SgnS994WxirgAWk8blAjsANm1HfNjQ0HtmzH5Pj0eOYzqt5EKUjFkzN1bKZc4wk6QSVaJAh6dQGwjtBIUA== x-ms-office365-filtering-correlation-id: d30857fa-deda-499b-cd5f-08d654344a9a x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(7021145)(8989299)(5600074)(711020)(4534185)(7022145)(4603075)(4627221)(201702281549075)(8990200)(7048125)(7024125)(7027125)(7023125)(2017052603328)(7153060)(7193020);SRVR:SN6PR16MB2576; x-ms-traffictypediagnostic: SN6PR16MB2576: x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(8121501046)(5005006)(10201501046)(3002001)(93006095)(93001095)(3231443)(944501410)(52105112)(148016)(149066)(150057)(6041310)(20161123564045)(20161123560045)(20161123558120)(20161123562045)(2016111802025)(6043046)(201708071742011)(7699051)(76991095);SRVR:SN6PR16MB2576;BCL:0;PCL:0;RULEID:;SRVR:SN6PR16MB2576; x-forefront-prvs: 086943A159 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(39830400003)(366004)(396003)(376002)(136003)(189003)(199004)(476003)(110136005)(71200400001)(71190400001)(25786009)(575784001)(86362001)(99286004)(105586002)(54906003)(46003)(102836004)(7736002)(106356001)(386003)(2501003)(6506007)(2616005)(52116002)(256004)(5660300001)(486006)(14444005)(305945005)(186003)(508600001)(316002)(36756003)(97736004)(107886003)(8936002)(1857600001)(8676002)(68736007)(6116002)(6486002)(6436002)(4326008)(6512007)(81166006)(1076002)(53936002)(14454004)(81156014)(2906002);DIR:OUT;SFP:1102;SCL:1;SRVR:SN6PR16MB2576;H:SN6PR16MB2542.namprd16.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: bayhubtech.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: HUWZAtBrtUTPxWAztFKLKQO9S5fu1kY4wjaFPfLKi7GeDaFEy8OzJmf+M0KpFT3msbU9jaWOeABA9BbDFdsM4YwgjvWLvJt1YN8beuGoOvH6p3jgtzZVCZT8c9mTABqMmGGq4iKB4Mh3Tg6/ueNcAm9y4/VHISmVRh4d12cqPKusFQyD2yLvksUn26nIavczCDfQlKyzyHxlsS7YYyzbGA2vk36T3YUPBUl4zOV/8lX/bt8KU8lIxm2RaUvpzK8I71uUbO3e36M87FRQwVulgZduCzSYJCEdUj081GiLSAhGmpUxD2DD/QlJmg6l0isap1OEas4asIzrh3LMjD3n/afeEWFVCHGTY7y3731JI40= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: bayhubtech.com X-MS-Exchange-CrossTenant-Network-Message-Id: d30857fa-deda-499b-cd5f-08d654344a9a X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Nov 2018 06:48:09.6272 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 0a7aae2b-8f2e-44df-ba2f-42de7f93c642 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR16MB2576 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 1. O2 Host Controller PLL lock status is not in compliance with CLOCK_CONTROL register bit 1 2. O2 Host Controller card detect function only work when PLL is enabled and locked Signed-off-by: ernest.zhang --- drivers/mmc/host/sdhci-pci-core.c | 10 +++ drivers/mmc/host/sdhci-pci-o2micro.c | 114 ++++++++++++++++++++++++++- drivers/mmc/host/sdhci-pci.h | 1 + drivers/mmc/host/sdhci.h | 2 + 4 files changed, 124 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/host/sdhci-pci-core.c b/drivers/mmc/host/sdhci-pci-core.c index 7bfd366d970d..c31a52ec2b10 100644 --- a/drivers/mmc/host/sdhci-pci-core.c +++ b/drivers/mmc/host/sdhci-pci-core.c @@ -1173,6 +1173,15 @@ static int jmicron_resume(struct sdhci_pci_chip *chip) } #endif +static const struct sdhci_ops sdhci_pci_o2_ops = { + .set_clock = sdhci_pci_o2_set_clock, + .enable_dma = sdhci_pci_enable_dma, + .set_bus_width = sdhci_set_bus_width, + .reset = sdhci_reset, + .set_uhs_signaling = sdhci_set_uhs_signaling, + .hw_reset = sdhci_pci_hw_reset, +}; + static const struct sdhci_pci_fixes sdhci_o2 = { .probe = sdhci_pci_o2_probe, .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, @@ -1181,6 +1190,7 @@ static const struct sdhci_pci_fixes sdhci_o2 = { #ifdef CONFIG_PM_SLEEP .resume = sdhci_pci_o2_resume, #endif + .ops = &sdhci_pci_o2_ops, }; static const struct sdhci_pci_fixes sdhci_jmicron = { diff --git a/drivers/mmc/host/sdhci-pci-o2micro.c b/drivers/mmc/host/sdhci-pci-o2micro.c index cc3ffeffd7a2..262027761cf2 100644 --- a/drivers/mmc/host/sdhci-pci-o2micro.c +++ b/drivers/mmc/host/sdhci-pci-o2micro.c @@ -60,6 +60,13 @@ #define O2_SD_VENDOR_SETTING2 0x1C8 #define O2_SD_HW_TUNING_DISABLE BIT(4) +#define O2_PLL_WDT_CONTROL1 0x1CC +#define O2_PLL_FORCE_ACTIVE BIT(18) +#define O2_PLL_LOCK_STATUS BIT(14) +#define O2_PLL_SOFT_RESET BIT(12) + +#define O2_SD_DETECT_SETTING 0x324 + static void sdhci_o2_set_tuning_mode(struct sdhci_host *host) { u16 reg; @@ -283,6 +290,105 @@ static void sdhci_pci_o2_enable_msi(struct sdhci_pci_chip *chip, host->irq = pci_irq_vector(chip->pdev, 0); } +static void sdhci_o2_wait_card_detect_stable(struct sdhci_host *host) +{ + ktime_t timeout; + u32 scratch32; + + /* Wait max 50 ms */ + timeout = ktime_add_ms(ktime_get(), 50); + while (1) { + scratch32 = sdhci_readl(host, SDHCI_PRESENT_STATE); + if ((scratch32 & BIT(16)) >> 16 == (scratch32 & BIT(18)) >> 18) + break; + + if (ktime_after(ktime_get(), timeout)) { + pr_err("%s: Card Detect debounce never finished.\n", + mmc_hostname(host->mmc)); + sdhci_dumpregs(host); + return; + } + udelay(10); + } +} + +static void sdhci_o2_enable_internal_clock(struct sdhci_host *host) +{ + ktime_t timeout; + u16 scratch; + u32 scratch32; + + /* PLL software reset */ + scratch32 = sdhci_readl(host, O2_PLL_WDT_CONTROL1); + scratch32 |= O2_PLL_SOFT_RESET; + sdhci_writel(host, scratch32, O2_PLL_WDT_CONTROL1); + udelay(1); + scratch32 &= ~(O2_PLL_SOFT_RESET); + sdhci_writel(host, scratch32, O2_PLL_WDT_CONTROL1); + + /* PLL force active */ + scratch32 |= O2_PLL_FORCE_ACTIVE; + sdhci_writel(host, scratch32, O2_PLL_WDT_CONTROL1); + + /* Wait max 20 ms */ + timeout = ktime_add_ms(ktime_get(), 20); + while (!((scratch = sdhci_readw(host, O2_PLL_WDT_CONTROL1)) + & O2_PLL_LOCK_STATUS)) { + if (ktime_after(ktime_get(), timeout)) { + pr_err("%s: Internal clock never stabilised.\n", + mmc_hostname(host->mmc)); + sdhci_dumpregs(host); + return; + } + udelay(10); + } + + /* Wait for card detect finish */ + udelay(1); + sdhci_o2_wait_card_detect_stable(host); + + /* Cancel PLL force active */ + scratch32 = sdhci_readl(host, O2_PLL_WDT_CONTROL1); + scratch32 &= ~O2_PLL_FORCE_ACTIVE; + sdhci_writel(host, scratch32, O2_PLL_WDT_CONTROL1); +} + +static int sdhci_o2_get_cd(struct mmc_host *mmc) +{ + struct sdhci_host *host = mmc_priv(mmc); + + sdhci_o2_enable_internal_clock(host); + + return !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT); +} + +static void sdhci_o2_enable_clk(struct sdhci_host *host, u16 clk) +{ + /* Enable internal clock */ + clk |= SDHCI_CLOCK_INT_EN; + sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); + + if (sdhci_o2_get_cd(host->mmc)) { + clk |= SDHCI_CLOCK_CARD_EN; + sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); + } +} + +void sdhci_pci_o2_set_clock(struct sdhci_host *host, unsigned int clock) +{ + u16 clk; + + host->mmc->actual_clock = 0; + + sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL); + + if (clock == 0) + return; + + clk = sdhci_calc_clk(host, clock, &host->mmc->actual_clock); + sdhci_o2_enable_clk(host, clk); +} + int sdhci_pci_o2_probe_slot(struct sdhci_pci_slot *slot) { struct sdhci_pci_chip *chip; @@ -316,7 +422,11 @@ int sdhci_pci_o2_probe_slot(struct sdhci_pci_slot *slot) host->flags |= SDHCI_SIGNALING_180; host->mmc->caps2 |= MMC_CAP2_NO_SD; host->mmc->caps2 |= MMC_CAP2_NO_SDIO; + pci_write_config_dword(chip->pdev, + O2_SD_DETECT_SETTING, 3); } + + slot->host->mmc_host_ops.get_cd = sdhci_o2_get_cd; } host->mmc_host_ops.execute_tuning = sdhci_o2_execute_tuning; @@ -490,9 +600,6 @@ int sdhci_pci_o2_probe(struct sdhci_pci_chip *chip) pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch); break; case PCI_DEVICE_ID_O2_SEABIRD0: - if (chip->pdev->revision == 0x01) - chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER; - /* fall through */ case PCI_DEVICE_ID_O2_SEABIRD1: /* UnLock WP */ ret = pci_read_config_byte(chip->pdev, @@ -550,3 +657,4 @@ int sdhci_pci_o2_resume(struct sdhci_pci_chip *chip) return sdhci_pci_resume_host(chip); } #endif + diff --git a/drivers/mmc/host/sdhci-pci.h b/drivers/mmc/host/sdhci-pci.h index 2ef0bdca9197..e41a85f0b40a 100644 --- a/drivers/mmc/host/sdhci-pci.h +++ b/drivers/mmc/host/sdhci-pci.h @@ -184,6 +184,7 @@ int sdhci_pci_o2_probe(struct sdhci_pci_chip *chip); #ifdef CONFIG_PM_SLEEP int sdhci_pci_o2_resume(struct sdhci_pci_chip *chip); #endif +void sdhci_pci_o2_set_clock(struct sdhci_host *host, unsigned int clock); extern const struct sdhci_pci_fixes sdhci_arasan; extern const struct sdhci_pci_fixes sdhci_snps; diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index b001cf4d3d7e..d6564d4caa49 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -73,6 +73,8 @@ #define SDHCI_SPACE_AVAILABLE 0x00000400 #define SDHCI_DATA_AVAILABLE 0x00000800 #define SDHCI_CARD_PRESENT 0x00010000 +#define SDHCI_CARD_STABLE 0x00020000 +#define SDHCI_CARD_DETECT 0x00040000 #define SDHCI_WRITE_PROTECT 0x00080000 #define SDHCI_DATA_LVL_MASK 0x00F00000 #define SDHCI_DATA_LVL_SHIFT 20