From patchwork Mon Nov 19 05:27:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Changming-R66093 X-Patchwork-Id: 1763261 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 27B0B3FCA5 for ; Mon, 19 Nov 2012 06:13:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752230Ab2KSGNx (ORCPT ); Mon, 19 Nov 2012 01:13:53 -0500 Received: from tx2ehsobe005.messaging.microsoft.com ([65.55.88.15]:3713 "EHLO tx2outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752018Ab2KSGNx (ORCPT ); Mon, 19 Nov 2012 01:13:53 -0500 Received: from mail7-tx2-R.bigfish.com (10.9.14.250) by TX2EHSOBE004.bigfish.com (10.9.40.24) with Microsoft SMTP Server id 14.1.225.23; Mon, 19 Nov 2012 06:13:52 +0000 Received: from mail7-tx2 (localhost [127.0.0.1]) by mail7-tx2-R.bigfish.com (Postfix) with ESMTP id A7163320180; Mon, 19 Nov 2012 06:13:52 +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: 0 X-BigFish: VS0(zzzz1de0h1202h1d1ah1d2ahzz8275bh8275dhz2dh2a8h668h839hd24he5bhf0ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h1155h) Received: from mail7-tx2 (localhost.localdomain [127.0.0.1]) by mail7-tx2 (MessageSwitch) id 1353305630895845_8283; Mon, 19 Nov 2012 06:13:50 +0000 (UTC) Received: from TX2EHSMHS025.bigfish.com (unknown [10.9.14.245]) by mail7-tx2.bigfish.com (Postfix) with ESMTP id CD4181A0052; Mon, 19 Nov 2012 06:13:50 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by TX2EHSMHS025.bigfish.com (10.9.99.125) with Microsoft SMTP Server (TLS) id 14.1.225.23; Mon, 19 Nov 2012 06:13:50 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-004.039d.mgd.msft.net (10.84.1.14) with Microsoft SMTP Server (TLS) id 14.2.318.3; Mon, 19 Nov 2012 06:13:50 +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 qAJ6DgtP018395; Sun, 18 Nov 2012 23:13:49 -0700 From: To: CC: Jerry Huang , Chris Ball Subject: [PATCH 3/3 v5] ESDHC: add callback esdhc_of_get_cd to detect card Date: Mon, 19 Nov 2012 13:27:26 +0800 Message-ID: <1353302846-19514-3-git-send-email-r66093@freescale.com> X-Mailer: git-send-email 1.6.4 In-Reply-To: <1353302846-19514-2-git-send-email-r66093@freescale.com> References: <1353302846-19514-1-git-send-email-r66093@freescale.com> <1353302846-19514-2-git-send-email-r66093@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. 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 63d219f..f50f7b0 100644 --- a/drivers/mmc/host/sdhci-of-esdhc.c +++ b/drivers/mmc/host/sdhci-of-esdhc.c @@ -179,6 +179,31 @@ static void esdhc_of_platform_init(struct sdhci_host *host) host->quirks2 |= SDHCI_QUIRK2_HOST_NO_CMD23; } +/* Return: none zero - the card is presetn; 0 - card is absent */ +static int esdhc_of_get_cd(struct sdhci_host *host) +{ + int present; + int 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); + + /* Resve 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, @@ -191,6 +216,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,