Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp781461ybh; Sat, 3 Aug 2019 09:39:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqz9f1P0Oaw1GhCPqoUSaOZ5S4gW+dhkoc1ryfb3RnZgZl+6L2jz+2bwTgYcAD4VNHnFdzIX X-Received: by 2002:a17:902:e582:: with SMTP id cl2mr137969116plb.60.1564850367229; Sat, 03 Aug 2019 09:39:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1564850367; cv=pass; d=google.com; s=arc-20160816; b=uPkayReoVx/8Ygu3WhvnJYVg3eXal42ycLyfrwX3JL3O0jwL9MIidfWU6b0iRFrbLx hvCBs9C7DfZmwamZzv/hmgnPL3bVIQljxZSgMgsAFJ5oqygxA7dOu4Z+mENUigm50tEB O3iTAkWd87drBRXKhpgF9mcafNdD90AIhRbQqhS6jgSKeGkvJ29zKAcZfyX/dspiTO0x 5PamkzhPAz/pMEWqpmRMA84fWmnPtYmd8zO7b+3nP+Uxv+toqXXmfTUn8Qp5po0f2Gr1 oyODiQtpAaXEHsba3p2eWD2vIuhrq59Rkq3WGmI9r5cZisv1wOWI5cm3J3LEOJAYTdKh jZUw== 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=hq9HEhNjMZsIV+82oNCyVlVyUiYTM4WlplbbNc6h49g=; b=1FTSBN/lTOF0CIfvuyXjP/YSGm4ZkMGS9pzTFZeGhpKua8jnOHLdXpb5vqyHf+wJjj F9Qbw9MjUuzcN1YffFTUeRP4R8Gf6bxaT7rFgUBhCp3NC7J4LgyB5RZI0PAwcYUqDRFj 0ps/JLi5KpaRZEU8YOGh59DZwdi8EW57uXdOswB5n+rfKZQOnFQewMvmsB6IBvitTV7X fkkCfzgkcVgP9vosxcUx3FDUX6kBkOwc2Eo6CQYE1YYTKA0b/QOAAGZUMTbULLEB4OzO 7KgtCnDlliHRvaAHBeM/A4VzYJNDxUJJS6x+ZkKpuOh8oOsGvmQc1Og4rBKsrPWbMqDW f9zg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@towerbridgetechnology.onmicrosoft.com header.s=selector2-towerbridgetechnology-onmicrosoft-com header.b=KR3PtPE9; 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 8si71582432pfv.149.2019.08.03.09.39.12; Sat, 03 Aug 2019 09:39:27 -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=KR3PtPE9; 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 S2405806AbfHBRkX (ORCPT + 99 others); Fri, 2 Aug 2019 13:40:23 -0400 Received: from mail-eopbgr780112.outbound.protection.outlook.com ([40.107.78.112]:52603 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729364AbfHBRkW (ORCPT ); Fri, 2 Aug 2019 13:40:22 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TANhvJLv9wcI948NnQ1B9AUSPuc7irNRUylYn8dxOAsvc3Upv6q9QqBhsAVPcdUiNKwqZXM9HzOT23UnCi9ndH6achkHcsgugjQFIqY1va8UgHb8w8QIWzQNmLdqAsQwKVZ6Hf1cXJ5mSuhnCzV4Oy4c2+RcvnXZqJqJVVsOWdTHzQZzs0OYPK84i7vdualkwP2aB7PepRPHhbo7fm18AESTb34sahUg+m9UUgkpQRxI8mPfEXjz4qQVBheRMDZwDhy+b2M17lVTrPWuJ3b+eFDSGH8RbwyaF+1wpZUh9JpA9qh41l8l92VhEOB7ktsL1F0M4Qfn37D7bB2jvDS+dg== 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=hq9HEhNjMZsIV+82oNCyVlVyUiYTM4WlplbbNc6h49g=; b=KvNHAChc0VCNMmHazYUkNnXj0Gji7FEho60zAAaXl0+lK/WWMrTLoT3jPfvV7XYF2WckOlKhc+NrYrhKBrB7zFeSPLhRSQVUHzfj1OcI6halFUbZWs45i8vHmW3q4ntVN1QJzlFWOWNHFUF1UwbYa3KoVe+pzVapLq3GuYPNADCwbhTvzPnoBf4UuahFWjolP9Yf1P/fCAGFo5EDAUiF1PpQfGa7MTYxctoPtGRayGVipzbLVAvH74PDXYyXmdXvkzrBFjshBLVrvns0mzyjKR7iixtkmjVUWg3tw19v5Mtz7TpIEuUYYZ0n1TLldS/hDZNmtSUodX3C1g2agDG8aw== 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=hq9HEhNjMZsIV+82oNCyVlVyUiYTM4WlplbbNc6h49g=; b=KR3PtPE9VPA+NfWjzvGYPosm51oBi6/KYXTK+oIVccnLb4Pl28ZTpXCi74TC/dHOLEVF/dT5U4OmsZSxs4Zq9ofBd/YUhOCO0BH6xlhbwNGHSW8KVHkIyVvqZB6+rPUpkJt3XLmGdHsnWpfyt6v3+EF618p8z0XWjtGz6itxj2M= Received: from MWHPR16MB1455.namprd16.prod.outlook.com (10.175.5.21) by MWHPR16MB1741.namprd16.prod.outlook.com (10.172.61.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2115.15; Fri, 2 Aug 2019 17:40:18 +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.2136.010; Fri, 2 Aug 2019 17:40:17 +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: "Louis Lu (TP)" , "Chevron Li (WH)" , "Max Huang (SC)" , "Shirley Her (SC)" Subject: [PATCH V4 2/2] mmc: sdhci: Fix O2 Host data read/write DLL Lock Phase shift issue Thread-Topic: [PATCH V4 2/2] mmc: sdhci: Fix O2 Host data read/write DLL Lock Phase shift issue Thread-Index: AQHVSVlZ0md1M2x4r0OhSKpBEOnp1Q== Date: Fri, 2 Aug 2019 17:40:17 +0000 Message-ID: <1564767615-4566-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: BY5PR03CA0026.namprd03.prod.outlook.com (2603:10b6:a03:1e0::36) 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: 15efab2a-5206-414e-5a16-08d717707bba x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(7021145)(8989299)(4534185)(7022145)(4603075)(4627221)(201702281549075)(8990200)(7048125)(7024125)(7027125)(7023125)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:MWHPR16MB1741; x-ms-traffictypediagnostic: MWHPR16MB1741: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:586; x-forefront-prvs: 011787B9DD x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(136003)(346002)(39840400004)(366004)(376002)(396003)(189003)(199004)(53936002)(256004)(6436002)(386003)(2616005)(486006)(52116002)(6486002)(186003)(476003)(6506007)(107886003)(5660300002)(3846002)(71190400001)(36756003)(2201001)(6116002)(4326008)(2906002)(71200400001)(2501003)(68736007)(14444005)(102836004)(81156014)(81166006)(6512007)(14454004)(66556008)(50226002)(8936002)(8676002)(30864003)(26005)(66066001)(305945005)(316002)(99286004)(110136005)(25786009)(86362001)(54906003)(7736002)(66476007)(64756008)(508600001)(66946007)(66446008);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR16MB1741;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: EXeVBmYW7sFJ7pNgtt+6ceqt2T7Q8qtpRV1IIF48hCo/m2aZYiiMqqFlp2Q83TwDFj9tEr1KwVOnP/xqL1EWhQ/Rs6/LImPaV9pG1Aq7gti+L2W9Dw9N8j3ePW/h815Aj+l0PirIIWJewG0/IKsXEpDBDxv6mZWp5rFyjz+AseDMprLeupaYSeZy1MiezJJKWKQQoDAZBWeHJHWLvMrDx5zSjUG0gxUjLHQnF4Azy+EXPRvxK/VCXMGPTXhIrSJGeNVHCrRKWPJpCfEn+KxXdlSm5ZgU31WHGF2M3WSDQgLAmj/bTjQAMOin+2JxtzyzfKmk1N6MQU0Anh2r4BrJzt7WVorc+AtsdQkxmbPW7Nn99riKhSahYbUTMgCvSjWgM1CgmRzDJfn+kiyufIL48bAIZAdDrSWKdyqIOckDWHc= 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: 15efab2a-5206-414e-5a16-08d717707bba X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Aug 2019 17:40:17.8209 (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: shirley.her@bayhubtech.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR16MB1741 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fix data read/write error in HS200 mode due to chip DLL lock phase shift Signed-off-by:Shirley Her --- 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 | 305 ++++++++++++++++++++++++-------= ---- 1 file changed, 208 insertions(+), 97 deletions(-) diff --git a/drivers/mmc/host/sdhci-pci-o2micro.c b/drivers/mmc/host/sdhci-= pci-o2micro.c index 186a33d..aee0d15 100644 --- a/drivers/mmc/host/sdhci-pci-o2micro.c +++ b/drivers/mmc/host/sdhci-pci-o2micro.c @@ -55,9 +55,138 @@ #define O2_PLL_FORCE_ACTIVE BIT(18) #define O2_PLL_LOCK_STATUS BIT(14) #define O2_PLL_SOFT_RESET BIT(12) +#define O2_DLL_LOCK_STATUS BIT(11) =20 #define O2_SD_DETECT_SETTING 0x324 =20 +static const u32 dmdn_table[5] =3D {0x25100000, 0x2B1C0000, + 0x2C1A0000, 0x371B0000, 0x35100000}; + +struct o2_host { + u8 dll_adjust_count; +}; + +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); + + if (!(sdhci_readw(host, O2_PLL_DLL_WDT_CONTROL1) & O2_PLL_LOCK_STATUS)) + 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 int sdhci_o2_wait_dll_detect_lock(struct sdhci_host *host) +{ + ktime_t timeout; + u32 scratch32; + + usleep_range(5000, 6000); + scratch32 =3D sdhci_readl(host, O2_PLL_DLL_WDT_CONTROL1); + if (!(scratch32 & O2_DLL_LOCK_STATUS)) { + pr_warn("%s: DLL is still unlocked after wait 5ms\n", + mmc_hostname(host->mmc)); + } + + /* Detect 1 s */ + timeout =3D ktime_add_ms(ktime_get(), 1000); + while (1) { + bool timedout =3D ktime_after(ktime_get(), timeout); + + scratch32 =3D sdhci_readl(host, O2_PLL_DLL_WDT_CONTROL1); + if (!(scratch32 & O2_DLL_LOCK_STATUS)) + return 0; + + if (timedout) + return 1; + } +} + static void sdhci_o2_set_tuning_mode(struct sdhci_host *host) { u16 reg; @@ -73,7 +202,6 @@ static void __sdhci_o2_execute_tuning(struct sdhci_host = *host, u32 opcode) int i; =20 sdhci_send_tuning(host, MMC_SEND_TUNING_BLOCK_HS200); - for (i =3D 0; i < 150; i++) { u16 ctrl =3D sdhci_readw(host, SDHCI_HOST_CONTROL2); =20 @@ -95,12 +223,87 @@ static void __sdhci_o2_execute_tuning(struct sdhci_hos= t *host, u32 opcode) sdhci_reset_tuning(host); } =20 +/* this function is used to fix o2 dll shift issue */ +static int sdhci_o2_dll_recovery(struct sdhci_host *host) +{ + int ret =3D 0; + u8 scratch_8 =3D 0; + u32 scratch_32 =3D 0; + struct sdhci_pci_slot *slot =3D sdhci_priv(host); + struct sdhci_pci_chip *chip =3D slot->chip; + struct o2_host *o2_host =3D sdhci_pci_priv(slot); + + /* Disable clock */ + sdhci_writeb(host, 0, SDHCI_CLOCK_CONTROL); + while (o2_host->dll_adjust_count < 5) { + o2_host->dll_adjust_count++; + /* UnLock WP */ + ret =3D pci_read_config_byte(chip->pdev, + O2_SD_LOCK_WP, &scratch_8); + if (ret) + return ret; + + scratch_8 &=3D 0x7f; + pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch_8); + + /* PLL software reset */ + scratch_32 =3D sdhci_readl(host, O2_PLL_DLL_WDT_CONTROL1); + scratch_32 |=3D O2_PLL_SOFT_RESET; + sdhci_writel(host, scratch_32, O2_PLL_DLL_WDT_CONTROL1); + + ret =3D pci_read_config_dword(chip->pdev, + O2_SD_FUNC_REG4, + &scratch_32); + /* Enable Base Clk setting change */ + scratch_32 |=3D O2_SD_FREG4_ENABLE_CLK_SET; + pci_write_config_dword(chip->pdev, O2_SD_FUNC_REG4, scratch_32); + o2_pci_set_baseclk(chip, dmdn_table[o2_host->dll_adjust_count]); + + /* Enable internal clock */ + scratch_8 =3D SDHCI_CLOCK_INT_EN; + sdhci_writeb(host, scratch_8, SDHCI_CLOCK_CONTROL); + + if (sdhci_o2_get_cd(host->mmc)) { + if (sdhci_o2_wait_dll_detect_lock(host)) { + scratch_8 |=3D SDHCI_CLOCK_CARD_EN; + sdhci_writeb(host, scratch_8, + SDHCI_CLOCK_CONTROL); + ret =3D 1; + goto out; + } else { + pr_warn("%s: DLL unlocked when dll_adjust_count is %d.\n", + mmc_hostname(host->mmc), + o2_host->dll_adjust_count); + } + } + } +out: + if (o2_host->dll_adjust_count =3D=3D 5) + pr_err("%s: DLL adjust over max times\n", + mmc_hostname(host->mmc)); + /* Lock WP */ + ret =3D pci_read_config_byte(chip->pdev, + O2_SD_LOCK_WP, &scratch_8); + if (ret) + return ret; + scratch_8 |=3D 0x80; + pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch_8); + return ret; +} + static int sdhci_o2_execute_tuning(struct mmc_host *mmc, u32 opcode) { struct sdhci_host *host =3D mmc_priv(mmc); int current_bus_width =3D 0; =20 /* + * Judge the tuning reason, whether caused by dll shift + * If cause by dll shift, should call sdhci_o2_dll_recovery + */ + if (!sdhci_o2_wait_dll_detect_lock(host)) + sdhci_o2_dll_recovery(host); + + /* * This handler only implements the eMMC tuning that is specific to * this controller. Fall back to the standard method for other TIMING. */ @@ -131,24 +334,10 @@ static int sdhci_o2_execute_tuning(struct mmc_host *m= mc, u32 opcode) mmc->ios.bus_width =3D MMC_BUS_WIDTH_8; sdhci_set_bus_width(host, current_bus_width); } - host->flags &=3D ~SDHCI_HS400_TUNING; 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,92 +473,12 @@ static void sdhci_pci_o2_enable_msi(struct sdhci_pci_= chip *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_WDT_CONTROL1); - scratch32 |=3D O2_PLL_SOFT_RESET; - sdhci_writel(host, scratch32, O2_PLL_WDT_CONTROL1); - udelay(1); - scratch32 &=3D ~(O2_PLL_SOFT_RESET); - sdhci_writel(host, scratch32, O2_PLL_WDT_CONTROL1); - - /* PLL force active */ - scratch32 |=3D O2_PLL_FORCE_ACTIVE; - sdhci_writel(host, scratch32, O2_PLL_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_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_WDT_CONTROL1); - scratch32 &=3D ~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 =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 */ clk |=3D SDHCI_CLOCK_INT_EN; sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); - + sdhci_o2_enable_internal_clock(host); if (sdhci_o2_get_cd(host->mmc)) { clk |=3D SDHCI_CLOCK_CARD_EN; sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); @@ -395,12 +504,13 @@ int sdhci_pci_o2_probe_slot(struct sdhci_pci_slot *sl= ot) { struct sdhci_pci_chip *chip; struct sdhci_host *host; + struct o2_host *o2_host =3D sdhci_pci_priv(slot); u32 reg, caps; int ret; =20 chip =3D slot->chip; host =3D slot->host; - + o2_host->dll_adjust_count =3D 0; caps =3D sdhci_readl(host, SDHCI_CAPABILITIES); =20 /* @@ -687,4 +797,5 @@ const struct sdhci_pci_fixes sdhci_o2 =3D { .resume =3D sdhci_pci_o2_resume, #endif .ops =3D &sdhci_pci_o2_ops, + .priv_size =3D sizeof(struct o2_host), }; --=20 2.7.4