From patchwork Wed Mar 20 05:41:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chang-Ming.Huang@freescale.com X-Patchwork-Id: 2305351 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 0C7EADF24C for ; Wed, 20 Mar 2013 06:16:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751219Ab3CTGQg (ORCPT ); Wed, 20 Mar 2013 02:16:36 -0400 Received: from db3ehsobe004.messaging.microsoft.com ([213.199.154.142]:55244 "EHLO db3outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750810Ab3CTGQf (ORCPT ); Wed, 20 Mar 2013 02:16:35 -0400 Received: from mail37-db3-R.bigfish.com (10.3.81.247) by DB3EHSOBE002.bigfish.com (10.3.84.22) with Microsoft SMTP Server id 14.1.225.23; Wed, 20 Mar 2013 06:16:33 +0000 Received: from mail37-db3 (localhost [127.0.0.1]) by mail37-db3-R.bigfish.com (Postfix) with ESMTP id 7FBF14400C1; Wed, 20 Mar 2013 06:16:33 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 5 X-BigFish: VS5(zz78fbmzz1f42h1ee6h1de0h1202h1e76h1d1ah1d2ahzz8275dh8275bhz2dh2a8h668h839he5bhf0ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h16a6h1758h1898h18e1h1946h19b5h1ad9h1b0ah1155h) Received: from mail37-db3 (localhost.localdomain [127.0.0.1]) by mail37-db3 (MessageSwitch) id 1363760191819124_12141; Wed, 20 Mar 2013 06:16:31 +0000 (UTC) Received: from DB3EHSMHS010.bigfish.com (unknown [10.3.81.252]) by mail37-db3.bigfish.com (Postfix) with ESMTP id BC1783C0045; Wed, 20 Mar 2013 06:16:31 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by DB3EHSMHS010.bigfish.com (10.3.87.110) with Microsoft SMTP Server (TLS) id 14.1.225.23; Wed, 20 Mar 2013 06:16:31 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-005.039d.mgd.msft.net (10.84.1.17) with Microsoft SMTP Server (TLS) id 14.2.328.11; Wed, 20 Mar 2013 06:16:30 +0000 Received: from localhost (rock.ap.freescale.net [10.193.20.106]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id r2K6GS98027667; Tue, 19 Mar 2013 23:16:29 -0700 From: To: CC: Jerry Huang , Chris Ball Subject: [PATCH 3/3 v6] ESDHC: add callback esdhc_of_get_cd to detect card Date: Wed, 20 Mar 2013 13:41:35 +0800 Message-ID: <1363758095-32378-3-git-send-email-Chang-Ming.Huang@freescale.com> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1363758095-32378-1-git-send-email-Chang-Ming.Huang@freescale.com> References: <1363758095-32378-1-git-send-email-Chang-Ming.Huang@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org From: Jerry Huang In order to check if the card is present, we will read the PRESENT STATE register and check the bit13(Card detect pin level) and bit15(CINS). Signed-off-by: Jerry Huang Reviewed-by: Anton Vorontsov CC: Chris Ball --- changes for v2: - add new callback for esdhc to detect the card state - add the CC changes for v3: - enable the controller clock when detect the card state, not core changes for v4: - based on the latest version changes for v5: - modify codes according to Anton's suggest and add reviewed-by. changes for v6: - change the variable to u32 and change the retrun value. drivers/mmc/host/sdhci-of-esdhc.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/mmc/host/sdhci-of-esdhc.c b/drivers/mmc/host/sdhci-of-esdhc.c index f32526d..dbb32a5 100644 --- a/drivers/mmc/host/sdhci-of-esdhc.c +++ b/drivers/mmc/host/sdhci-of-esdhc.c @@ -230,6 +230,31 @@ static void esdhc_of_platform_init(struct sdhci_host *host) host->quirks &= ~SDHCI_QUIRK_NO_BUSY_IRQ; } +/* Return: 1 - the card is present; 0 - card is absent */ +static int esdhc_of_get_cd(struct sdhci_host *host) +{ + u32 present; + u32 sysctl; + + if (host->flags & SDHCI_DEVICE_DEAD) + return 0; + + sysctl = sdhci_be32bs_readl(host, SDHCI_CLOCK_CONTROL); + + /* Enable the controller clock to update the present state */ + sdhci_be32bs_writel(host, sysctl | SDHCI_CLOCK_INT_EN, + SDHCI_CLOCK_CONTROL); + + /* Detect the card present or absent */ + present = sdhci_be32bs_readl(host, SDHCI_PRESENT_STATE); + present &= (SDHCI_CARD_PRESENT | SDHCI_CARD_CDPL); + + /* Resave the previous to System control register */ + sdhci_be32bs_writel(host, sysctl, SDHCI_CLOCK_CONTROL); + + return !!present; +} + static struct sdhci_ops sdhci_esdhc_ops = { .read_l = esdhc_readl, .read_w = esdhc_readw, @@ -242,6 +267,7 @@ static struct sdhci_ops sdhci_esdhc_ops = { .get_max_clock = esdhc_of_get_max_clock, .get_min_clock = esdhc_of_get_min_clock, .platform_init = esdhc_of_platform_init, + .get_cd = esdhc_of_get_cd, #ifdef CONFIG_PM .platform_suspend = esdhc_of_suspend, .platform_resume = esdhc_of_resume,