Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1209417ybl; Wed, 21 Aug 2019 11:44:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqz72NlffBpoXl9f1raKYdteH7n1xpUlfH0CnpLMX6+sv/DxITO2f6IXKy3eHbCagIszMlfo X-Received: by 2002:a17:90a:bb92:: with SMTP id v18mr1447428pjr.78.1566413089020; Wed, 21 Aug 2019 11:44:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1566413089; cv=pass; d=google.com; s=arc-20160816; b=v9PRD2S0mU4zRCkPz797gdRdlcDvlmMPZcsQa3tPXCYz5h7NhVdb6y3fQtgmH8DnnY I+ApqGFB+dTfFceLDXYP/BAFthQLohGlSuBIY5DfuaFu9HqwSa7sKXOxVPyQu/fmd7y9 9kuCxj/bG3R8KumlQuwPAuaF+qGYod9D0mqD5ugaFjAcCKpXekaHtsrYIzSN8anZK3Ra uAas3oqutvQmCDIPhfwNKi+Yy+L1YpHfaBuuttpn8SRPgZlORDBPfsxTeh25N6xsVd7Z zNfSgu035sglwv60lC8Jg0D1gOtgDv0HbgjoYaAMyt4pLGEiZskVNusl66cKa1le3xFE ArUQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature; bh=jN3J9XQsCKODmoKEnJnFtJzBwsNukXdglfYpBoWEg2c=; b=gDaYROuUDxobf+n9PsVLs1866pB2o+jsAntPQ5rq7bvsCBqxh0GgKT+qzS25ygyHsE klsyA0a64XVfPeF4XxGrdh3V+mWR+SqZVuJnNKEQmCjuJpklwQg9nZKZfSKbABbedZ3J Q5N7TAJfbdrwNK5L1AaXEMKqi6DAHlDYtUApwsk4vZy3jcj6EN1ZO64P2kAF9WIhe50i yxUU186vR9sLTEN+ZHkpS8t7sLJMEDK1E99yrRThtrD88nV4G2WYYP7B/MxZRNdcKI0N SjoVe06iZfaUgNgbdCP5YyMC+B7MIpH7rM8MKJUq8iazUwPPJvWxRdCKI11MxUdYxGHq JZNA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@towerbridgetechnology.onmicrosoft.com header.s=selector2-towerbridgetechnology-onmicrosoft-com header.b=nspcap5j; arc=pass (i=1 spf=pass spfdomain=bayhubtech.com dkim=pass dkdomain=bayhubtech.com dmarc=pass fromdomain=bayhubtech.com); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a13si16197884pfc.101.2019.08.21.11.44.33; Wed, 21 Aug 2019 11:44:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@towerbridgetechnology.onmicrosoft.com header.s=selector2-towerbridgetechnology-onmicrosoft-com header.b=nspcap5j; arc=pass (i=1 spf=pass spfdomain=bayhubtech.com dkim=pass dkdomain=bayhubtech.com dmarc=pass fromdomain=bayhubtech.com); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727992AbfHUSjh (ORCPT + 99 others); Wed, 21 Aug 2019 14:39:37 -0400 Received: from mail-eopbgr720138.outbound.protection.outlook.com ([40.107.72.138]:6170 "EHLO NAM05-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726252AbfHUSjh (ORCPT ); Wed, 21 Aug 2019 14:39:37 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Lq/HWGvuG+UDf2YlLHpQ1Gi9gzPZBi8wbwXrIQeKgKD5QeooeYmXSenuLBowauQNxCx1i5gdRPL02SqXkzq1GPajMbp38YpAjczVlH1GW31RRt9wkVZU7izv/Ur/IVZbwhjyxvzp59x9XHWs4gyi4vrmmOFU9+75/PJaHpubLNuS0ZMnnbXr+1h/XtXnZtjbpsqvHD2YyUbTcrHUYJwIVTwxsSMNpITwEcrNbXqvTeXE/CUnvhziic20IMMFwHEYpBaRduWz+ZBsDW93AhJsKgSR4rhMTV7Jfj0kAP9MOBA3Bk6Bzzk9fbLwHNpv45JzBFcNB9WnG+LbSHnzrR8nMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jN3J9XQsCKODmoKEnJnFtJzBwsNukXdglfYpBoWEg2c=; b=VTjOR8zUGOLBI5DRlC8U/8mQNcMK1GM9I3KemscpOP1wuw4/MybYc6rZfkIxL8mV3IgWndxAhA7pgwm14kI4J+hlgOXkLNuRdCvbt3iJ4127HnEB/G/o0nEPZrAc/mwy63StiCU1FkyURIpv/RakvaeZPSl9IfMcrOi5zoRvImWIcbkvj18Qalq8dvsUQgrAfUHzkNSzUFNd9J2oo7FLR1fh3v1EgkpxpK4l5BkTzOndHZNLUIdRhAXA2h8NrMy6UEFzcupyzXcVA7E9DPRkBTvBSBKFeDflsW+JQgfpNIVoXefcLG5bCAXYgpU+h0GaG3iIzhPO6tejSgA8Lmecnw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bayhubtech.com; dmarc=pass action=none header.from=bayhubtech.com; dkim=pass header.d=bayhubtech.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=towerbridgetechnology.onmicrosoft.com; s=selector2-towerbridgetechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jN3J9XQsCKODmoKEnJnFtJzBwsNukXdglfYpBoWEg2c=; b=nspcap5j27J0PIkKLTeM46CKwbX3UjqYO/C/Oi2Bg4Jq4czP4Ur/G8RnHv1jIv5dbOZLADYvw6vEOlyqlN/YXHrTVS4yahTW6iQSl8VmyQitgCpR8UOJU4QwEFB/5QKXd/XcIwKI8dvKnI2QZoWCCPTdurqG6anXR5xSSyc86NM= Received: from MWHPR16MB1455.namprd16.prod.outlook.com (10.175.5.21) by MWHPR16MB1693.namprd16.prod.outlook.com (10.172.59.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2178.18; Wed, 21 Aug 2019 18:39:33 +0000 Received: from MWHPR16MB1455.namprd16.prod.outlook.com ([fe80::48f4:c6d9:3a8:e7dd]) by MWHPR16MB1455.namprd16.prod.outlook.com ([fe80::48f4:c6d9:3a8:e7dd%4]) with mapi id 15.20.2178.020; Wed, 21 Aug 2019 18:39:33 +0000 From: "Shirley Her (SC)" To: "adrian.hunter@intel.com" , "ulf.hansson@linaro.org" , "linux-mmc@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: "Chevron Li (WH)" , "Shaper Liu (WH)" , "Louis Lu (TP)" , "Max Huang (SC)" , "Shirley Her (SC)" Subject: [PATCH V8 2/3] mmc: sdhci-pci-o2micro: Modify get CD status function Thread-Topic: [PATCH V8 2/3] mmc: sdhci-pci-o2micro: Modify get CD status function Thread-Index: AQHVWE/GeF7j+w6oEUmnvDOmg5O3Rw== Date: Wed, 21 Aug 2019 18:39:33 +0000 Message-ID: <1566412771-6178-1-git-send-email-shirley.her@bayhubtech.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR01CA0053.prod.exchangelabs.com (2603:10b6:a03:94::30) To MWHPR16MB1455.namprd16.prod.outlook.com (2603:10b6:320:28::21) authentication-results: spf=none (sender IP is ) smtp.mailfrom=shirley.her@bayhubtech.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.7.4 x-originating-ip: [209.36.105.184] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0bff2438-c2b0-4baf-4c16-08d72666e8ea x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(7021145)(8989299)(5600148)(711020)(4605104)(1401327)(4534185)(7022145)(4603075)(4627221)(201702281549075)(8990200)(7048125)(7024125)(7027125)(7023125)(2017052603328)(7193020);SRVR:MWHPR16MB1693; x-ms-traffictypediagnostic: MWHPR16MB1693: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:126; x-forefront-prvs: 0136C1DDA4 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(136003)(396003)(39830400003)(346002)(376002)(189003)(199004)(305945005)(6486002)(50226002)(2201001)(6116002)(3846002)(2906002)(36756003)(4326008)(8676002)(81156014)(81166006)(25786009)(66066001)(14454004)(2616005)(66556008)(64756008)(66446008)(486006)(476003)(86362001)(71190400001)(71200400001)(66476007)(66946007)(6436002)(99286004)(110136005)(107886003)(14444005)(256004)(7736002)(6512007)(508600001)(52116002)(54906003)(316002)(53936002)(186003)(26005)(8936002)(102836004)(386003)(6506007)(2501003)(5660300002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR16MB1693;H:MWHPR16MB1455.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-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: i4HVkPUNO5fCyA/pOQTp1pT7BsXyhqPfUQyqEoBlf1gIbwMQtwyY/lcgTtbc4wHWENw8p5AyK+lrMSBwPplmQ0KJNqdFoiSWgTGNON0X8WzvhfaUgN8YBKv5J4jfzZ0DojFvSeLmO9Q0Jvb/i36fBB4saolGgbqNIg/6BhAYW8pjVCtHePB5kkgb2TdZNKLBUQR4vg9fh0E21c01ixIdrtuwXA9m1Ngm1pykG9OhDgoKgLWLg8N1Rrt7/DzdrSnHOJBxtp8q3zRyMHaSKZausNglLl52QhVl8Md5ITkgh0xCLFJFyrhGpBnx2eD8bm14Zznyq1WFJgbmzUuIuLNU+GB3JQciHOll9qojPeVi3iXpL6aZRxR+XlA6ImVvS67Yg4+qu42+l2Y2ROnJW8uDOgue1rZAhX+vws1iFLkRoNU= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: bayhubtech.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0bff2438-c2b0-4baf-4c16-08d72666e8ea X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Aug 2019 18:39:33.4532 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 0a7aae2b-8f2e-44df-ba2f-42de7f93c642 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: qbY3F/KcYdfC0562RRIzK+w0VEwDh/Oq3vXRKweEROC/BF6/Ql7oHm5tkxa1vVoPTjKf5Uwp56uiUX2lnCmBJTN7N0JmG6wHwqWudQ1TQTI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR16MB1693 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Modify get CD status function Signed-off-by: Shirley Her --- change in V8: 1. fix patch format error change in V7: 1. change subject to match the patch 2. move functions in preparation to fix DLL lock phase shift issue change in V6: 1. change subjec and commit message to match the patch 2. modify the get CD status function 3. re-arrange the order of some functions change in V5: 1. split 2 patches into 3 patches 2. make dll_adjust_count start from 0 3. fix ret overwritten issue 4. use break instead of goto change in V4: 1. add a bug fix for V3 change in V3: 1. add more explanation in dll_recovery and execute_tuning function 2. move dll_adjust_count to O2_host struct 3. fix some coding style error 4. renaming O2_PLL_WDT_CONTROL1 TO O2_PLL_DLL_WDT_CONTROL1 change in V2: 1. use usleep_range instead of udelay 2. move dll_adjust_count to sdhci-pci-o2micro.c chagne in V1: 1. add error recovery function to relock DLL with correct phase 2. retuning HS200 after DLL locked --- drivers/mmc/host/sdhci-pci-o2micro.c | 187 ++++++++++++++++++-------------= ---- 1 file changed, 94 insertions(+), 93 deletions(-) diff --git a/drivers/mmc/host/sdhci-pci-o2micro.c b/drivers/mmc/host/sdhci-= pci-o2micro.c index b3a33d9..57c8b83 100644 --- a/drivers/mmc/host/sdhci-pci-o2micro.c +++ b/drivers/mmc/host/sdhci-pci-o2micro.c @@ -58,6 +58,100 @@ =20 #define O2_SD_DETECT_SETTING 0x324 =20 +static void sdhci_o2_wait_card_detect_stable(struct sdhci_host *host) +{ + ktime_t timeout; + u32 scratch32; + + /* Wait max 50 ms */ + timeout =3D ktime_add_ms(ktime_get(), 50); + while (1) { + bool timedout =3D ktime_after(ktime_get(), timeout); + + scratch32 =3D sdhci_readl(host, SDHCI_PRESENT_STATE); + if ((scratch32 & SDHCI_CARD_PRESENT) >> SDHCI_CARD_PRES_SHIFT + =3D=3D (scratch32 & SDHCI_CD_LVL) >> SDHCI_CD_LVL_SHIFT) + break; + + if (timedout) { + 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 =3D sdhci_readl(host, O2_PLL_DLL_WDT_CONTROL1); + scratch32 |=3D O2_PLL_SOFT_RESET; + sdhci_writel(host, scratch32, O2_PLL_DLL_WDT_CONTROL1); + udelay(1); + scratch32 &=3D ~(O2_PLL_SOFT_RESET); + sdhci_writel(host, scratch32, O2_PLL_DLL_WDT_CONTROL1); + + /* PLL force active */ + scratch32 |=3D O2_PLL_FORCE_ACTIVE; + sdhci_writel(host, scratch32, O2_PLL_DLL_WDT_CONTROL1); + + /* Wait max 20 ms */ + timeout =3D ktime_add_ms(ktime_get(), 20); + while (1) { + bool timedout =3D ktime_after(ktime_get(), timeout); + + scratch =3D sdhci_readw(host, O2_PLL_DLL_WDT_CONTROL1); + if (scratch & O2_PLL_LOCK_STATUS) + break; + if (timedout) { + pr_err("%s: Internal clock never stabilised.\n", + mmc_hostname(host->mmc)); + sdhci_dumpregs(host); + goto out; + } + udelay(10); + } + + /* Wait for card detect finish */ + udelay(1); + sdhci_o2_wait_card_detect_stable(host); + +out: + /* Cancel PLL force active */ + scratch32 =3D sdhci_readl(host, O2_PLL_DLL_WDT_CONTROL1); + scratch32 &=3D ~O2_PLL_FORCE_ACTIVE; + sdhci_writel(host, scratch32, O2_PLL_DLL_WDT_CONTROL1); +} + +static int sdhci_o2_get_cd(struct mmc_host *mmc) +{ + struct sdhci_host *host =3D mmc_priv(mmc); + + sdhci_o2_enable_internal_clock(host); + + return !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT); +} + +static void o2_pci_set_baseclk(struct sdhci_pci_chip *chip, u32 value) +{ + u32 scratch_32; + + pci_read_config_dword(chip->pdev, + O2_SD_PLL_SETTING, &scratch_32); + + scratch_32 &=3D 0x0000FFFF; + scratch_32 |=3D value; + + pci_write_config_dword(chip->pdev, + O2_SD_PLL_SETTING, scratch_32); +} + static void sdhci_o2_set_tuning_mode(struct sdhci_host *host) { u16 reg; @@ -136,19 +230,6 @@ static int sdhci_o2_execute_tuning(struct mmc_host *mm= c, u32 opcode) return 0; } =20 -static void o2_pci_set_baseclk(struct sdhci_pci_chip *chip, u32 value) -{ - u32 scratch_32; - pci_read_config_dword(chip->pdev, - O2_SD_PLL_SETTING, &scratch_32); - - scratch_32 &=3D 0x0000FFFF; - scratch_32 |=3D value; - - pci_write_config_dword(chip->pdev, - O2_SD_PLL_SETTING, scratch_32); -} - static void o2_pci_led_enable(struct sdhci_pci_chip *chip) { int ret; @@ -284,86 +365,6 @@ static void sdhci_pci_o2_enable_msi(struct sdhci_pci_c= hip *chip, host->irq =3D pci_irq_vector(chip->pdev, 0); } =20 -static void sdhci_o2_wait_card_detect_stable(struct sdhci_host *host) -{ - ktime_t timeout; - u32 scratch32; - - /* Wait max 50 ms */ - timeout =3D ktime_add_ms(ktime_get(), 50); - while (1) { - bool timedout =3D ktime_after(ktime_get(), timeout); - - scratch32 =3D sdhci_readl(host, SDHCI_PRESENT_STATE); - if ((scratch32 & SDHCI_CARD_PRESENT) >> SDHCI_CARD_PRES_SHIFT - =3D=3D (scratch32 & SDHCI_CD_LVL) >> SDHCI_CD_LVL_SHIFT) - break; - - if (timedout) { - 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 =3D sdhci_readl(host, O2_PLL_DLL_WDT_CONTROL1); - scratch32 |=3D O2_PLL_SOFT_RESET; - sdhci_writel(host, scratch32, O2_PLL_DLL_WDT_CONTROL1); - udelay(1); - scratch32 &=3D ~(O2_PLL_SOFT_RESET); - sdhci_writel(host, scratch32, O2_PLL_DLL_WDT_CONTROL1); - - /* PLL force active */ - scratch32 |=3D O2_PLL_FORCE_ACTIVE; - sdhci_writel(host, scratch32, O2_PLL_DLL_WDT_CONTROL1); - - /* Wait max 20 ms */ - timeout =3D ktime_add_ms(ktime_get(), 20); - while (1) { - bool timedout =3D ktime_after(ktime_get(), timeout); - - scratch =3D sdhci_readw(host, O2_PLL_DLL_WDT_CONTROL1); - if (scratch & O2_PLL_LOCK_STATUS) - break; - if (timedout) { - pr_err("%s: Internal clock never stabilised.\n", - mmc_hostname(host->mmc)); - sdhci_dumpregs(host); - goto out; - } - udelay(10); - } - - /* Wait for card detect finish */ - udelay(1); - sdhci_o2_wait_card_detect_stable(host); - -out: - /* Cancel PLL force active */ - scratch32 =3D sdhci_readl(host, O2_PLL_DLL_WDT_CONTROL1); - scratch32 &=3D ~O2_PLL_FORCE_ACTIVE; - sdhci_writel(host, scratch32, O2_PLL_DLL_WDT_CONTROL1); -} - -static int sdhci_o2_get_cd(struct mmc_host *mmc) -{ - struct sdhci_host *host =3D 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 */ --=20 2.7.4