Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5012922ybi; Tue, 30 Jul 2019 12:09:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqzyrpobjOmS9HElX1cbeJOQeqWgQ0q0me71a19xUQrgqqOUzq7DdH+mSPpLtCCcw8Wbfgo9 X-Received: by 2002:a63:4c17:: with SMTP id z23mr72705113pga.167.1564513784248; Tue, 30 Jul 2019 12:09:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1564513784; cv=pass; d=google.com; s=arc-20160816; b=zHh/3fZF1Hqpd78j5ZjbK6OfiJ6gpS/jXfBCCgTfwWHGHLYsjRnI53l7Qbyw7a7Fma Fz4NV4b8PGEhvdE8hoklorRU03YZltRr6W2gKlcClmaZ702CVZ8Cs4C9loi50n8g6ZUT PYiOEUf2Mz3sUgoQFAAzHel238g2CbwdRHkxk9gyAquhJhZTnov9CrnNrBwFUNkxp3KH NGq62dYe7Lf5OsBD2cHlRw8AaZzAnY/nUF5acJyGd9N4EOiVV2JYl829+2olJW5qzz3N vkb2QbwAq2HxXm2J+7Z33QeXjMvKBsfFNBRzqSl3nY5+prwlPKLgd60UVdt3Q0JQu3nA hiwQ== 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=Pqjw/vP53i7bSngnn88j3lW4b9qbMuQVoSlTWXc6Jvw=; b=tazcfDG8PgHoD0ZI6/cwIfLqqcI8MTp9jS+eccsMrYkNoISprLfDHYteP+cV4a5ROy +hbGlnvrWTWs0tP+4lD3IBJj3xlT0q7GdG5Chov22R9NbGesicj6bTIjAIdwUwNFngoL ki6b7gyu4q3Wze/8a4Oqn5Rr3cL2WDT0Kln30spTzcRf6ynV/PtdG9lSKhemvBVzMDOe zMgJU3vbca+Q0w4/HFh/zXNBua9Xf63tzmqF0yUD8LiCC3MkVVK5y4qE4fSTNBXzdFO8 bP/0yx9qMUrZCyGCHVpW7sQ40AXs0LgIJSQAJbeRssryuPASdFbJFQVCu+Uy+9D/Khca qALg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@towerbridgetechnology.onmicrosoft.com header.s=selector2-towerbridgetechnology-onmicrosoft-com header.b=rLV1cwwH; 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 bf7si27812953plb.216.2019.07.30.12.09.27; Tue, 30 Jul 2019 12:09:44 -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=rLV1cwwH; 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 S2387869AbfG3TIM (ORCPT + 99 others); Tue, 30 Jul 2019 15:08:12 -0400 Received: from mail-eopbgr760117.outbound.protection.outlook.com ([40.107.76.117]:28937 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387619AbfG3TIK (ORCPT ); Tue, 30 Jul 2019 15:08:10 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UDwpAIMVm+/KrSkNjxuHwJJGhlmnHrmBSEmqQnaEwtvMSM8OvwxF4plAJuk+7trIm8eynLogIXO0V1Hme1a8gWWiYY7jteWyr3zBEPQAw/4JeVdL3QshwyeyHEEBZdJf5A6zCMHRygC/ljZ937OXactoMsXGc3x/mDSDvD+98qVJaZm0ooC7oTNLN0qKmBnI/zqu0YAwz3t5jJkVGel2VIqWWgRKd4pcax1msHAwyG+uhtafIK7eRUUiMXn6qT9mCwqg3Xqh9Tu4XqXceGwAR3UgSXD8m9c4rJ/wUiRrwkjuSrUt4M+zLmW29iewvordPTwimlGxd1LFyPCYbE2G6A== 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=Pqjw/vP53i7bSngnn88j3lW4b9qbMuQVoSlTWXc6Jvw=; b=jFgZnUKi4nUSoHKnTniGoKzecdWc5AbFka3LKxRfYHrrxCQi7m4/h1k9ltXcXoXn62jZ2hpj827pFOiHPEfDysb2QCbxjTgDZrXkNp4AtSm1D2rkFrFRsPTu8jixjl7ply6oxgxHs+yHAHBpU3HDNGpPJy68JNY25sbvgSS+mdBipshIZp7/41IoKA48T+pS2aOsK6+5wqaB4hqPrMsTi6Gl6W3uO8u3gdrucn6oSbMXqmAsxUJMtGTmVIxIwDMm997MWcPe7xKL43qy01OFmS3PJPxIYTFEiSe4/sguK8TngvkhSByYUYcdh7tOW1k4e/3pTddPUgBiOoIII5oPUA== 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=Pqjw/vP53i7bSngnn88j3lW4b9qbMuQVoSlTWXc6Jvw=; b=rLV1cwwHI3lrG+f1i0/Je0yeaYJsft8pZN4G5d052giE2BfUTifVsVS/dHDSaIbUr0fCaemK3erBuUjSFm3CK7l9FJiXgjTptttlA+1FDxkQYruyOz8diInLOcTdRnbPuCWmZfeiTMsk5bs+bs400hCujBeo0G/i5PnkepJyNPg= Received: from MWHPR16MB1455.namprd16.prod.outlook.com (10.175.5.21) by MWHPR16MB1455.namprd16.prod.outlook.com (10.175.5.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2115.15; Tue, 30 Jul 2019 19:08:03 +0000 Received: from MWHPR16MB1455.namprd16.prod.outlook.com ([fe80::cc4a:10c6:fcac:d3e0]) by MWHPR16MB1455.namprd16.prod.outlook.com ([fe80::cc4a:10c6:fcac:d3e0%9]) with mapi id 15.20.2115.005; Tue, 30 Jul 2019 19:08:03 +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)" , "Louis Lu (TP)" , "Max Huang (SC)" , "Shirley Her (SC)" Subject: [PATCH V3 2/2] mmc: sdhci: Fix O2 Host data read/write DLL lock phase shift issue Thread-Topic: [PATCH V3 2/2] mmc: sdhci: Fix O2 Host data read/write DLL lock phase shift issue Thread-Index: AQHVRwoce+Jo1d5oiE+MKgRVipSqJA== Date: Tue, 30 Jul 2019 19:08:02 +0000 Message-ID: <1564513681-16428-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: MWHPR12CA0042.namprd12.prod.outlook.com (2603:10b6:301:2::28) 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: 2bbebd8d-dde0-4302-7da9-08d715213eb9 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:MWHPR16MB1455; x-ms-traffictypediagnostic: MWHPR16MB1455: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:586; x-forefront-prvs: 0114FF88F6 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(366004)(396003)(136003)(39840400004)(346002)(189003)(199004)(66556008)(66476007)(6116002)(71190400001)(71200400001)(186003)(66066001)(99286004)(486006)(386003)(64756008)(6506007)(102836004)(3846002)(107886003)(66946007)(36756003)(5660300002)(6512007)(66446008)(110136005)(52116002)(54906003)(305945005)(53936002)(14454004)(6436002)(8676002)(4326008)(81166006)(2201001)(68736007)(50226002)(26005)(14444005)(2616005)(2906002)(316002)(7736002)(81156014)(256004)(30864003)(8936002)(508600001)(6486002)(2501003)(476003)(86362001)(25786009);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR16MB1455;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: YEGJMKZ3FsEsh5+/2/mIyYqU5WbKdcqKj0c5ypQnu5zrDI3p7ie2FsXg9Jd/N1gZIokox0oDBBKFvtpIrX5xhthvtcY0ZFJZEWMZBBzG5rlV2NOcitRu/Rw+yeGeKNzdRSwNS6RcY2s6vwyNNVLy6MJUGFS7y30XOR3DfoFIEwjbuNxeF1u17so80IAp4fX0HRMMf5tzc3WHo2vinsT+HHVYp1G44/SEe3je3aJ4zqu/F89ii53JEciza6Wz/JALIqt9kHa/ipNvjOg6+Mark1yLu1WMmmpuJy9BKHCysiEf6Ro2V4SszRUlBfKwZ4yFCnNCat0qfNyPA5g0crqOPK5ExOykCIUrmnIQPmbyQwS7he6SO3vtwWP7zKHGdt+l8nIEUGIqp49Mf/2oGKTrutWVRW+7T4yaN4xqSjHUyl0= 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: 2bbebd8d-dde0-4302-7da9-08d715213eb9 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Jul 2019 19:08:02.9614 (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: MWHPR16MB1455 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 V3: 1. add more explanation in dll_recovery and execute_tuning function 2. move dll_adjust_count ot 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 ot sdhci-pci-o2micro.c change 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 | 322 ++++++++++++++++++++++++-------= ---- 1 file changed, 225 insertions(+), 97 deletions(-) diff --git a/drivers/mmc/host/sdhci-pci-o2micro.c b/drivers/mmc/host/sdhci-= pci-o2micro.c index 186a33d..a24df30 100644 --- a/drivers/mmc/host/sdhci-pci-o2micro.c +++ b/drivers/mmc/host/sdhci-pci-o2micro.c @@ -55,9 +55,139 @@ #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 500 ms */ + timeout =3D ktime_add_ms(ktime_get(), 500); + 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; + usleep_range(10, 1000); + } +} + static void sdhci_o2_set_tuning_mode(struct sdhci_host *host) { u16 reg; @@ -73,7 +203,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 +224,103 @@ static void __sdhci_o2_execute_tuning(struct sdhci_ho= st *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; + ktime_t timeout; + 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); + /* set timeout 10 s */ + timeout =3D ktime_add(ktime_get(), 10); + while (1) { + bool timeout =3D ktime_after(ktime_get(), timeout); + + if (timeout) { + pr_warn("%s: error recovery failed with timeout.\n", + mmc_hostname(host->mmc)); + ret =3D 0; + goto out; + } + if (o2_host->dll_adjust_count < 4) { + o2_host->dll_adjust_count++; + } else { + + o2_host->dll_adjust_count =3D 4; + pr_warn("%s: dll_adjust_count reach max value.\n", + mmc_hostname(host->mmc)); + } + + /* 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: + /* 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 +351,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 +490,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 +521,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 +814,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