From patchwork Tue Oct 30 08:12:49 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: 1669101 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 268DE3FDDA for ; Tue, 30 Oct 2012 08:55:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756431Ab2J3Izs (ORCPT ); Tue, 30 Oct 2012 04:55:48 -0400 Received: from ch1ehsobe004.messaging.microsoft.com ([216.32.181.184]:28597 "EHLO ch1outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756587Ab2J3Izq (ORCPT ); Tue, 30 Oct 2012 04:55:46 -0400 Received: from mail86-ch1-R.bigfish.com (10.43.68.250) by CH1EHSOBE015.bigfish.com (10.43.70.65) with Microsoft SMTP Server id 14.1.225.23; Tue, 30 Oct 2012 08:55:45 +0000 Received: from mail86-ch1 (localhost [127.0.0.1]) by mail86-ch1-R.bigfish.com (Postfix) with ESMTP id D515520355; Tue, 30 Oct 2012 08:55:45 +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(zzzz1202h1d1ah1d2ahzz8275bh8275dhz2dh2a8h668h839hd24he5bhf0ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h1155h) Received: from mail86-ch1 (localhost.localdomain [127.0.0.1]) by mail86-ch1 (MessageSwitch) id 1351587343479408_8466; Tue, 30 Oct 2012 08:55:43 +0000 (UTC) Received: from CH1EHSMHS034.bigfish.com (snatpool1.int.messaging.microsoft.com [10.43.68.252]) by mail86-ch1.bigfish.com (Postfix) with ESMTP id 6888446005B; Tue, 30 Oct 2012 08:55:43 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CH1EHSMHS034.bigfish.com (10.43.70.34) with Microsoft SMTP Server (TLS) id 14.1.225.23; Tue, 30 Oct 2012 08:55:43 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-003.039d.mgd.msft.net (10.84.1.16) with Microsoft SMTP Server (TLS) id 14.2.318.3; Tue, 30 Oct 2012 08:55:42 +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 q9U8tdRm013238; Tue, 30 Oct 2012 01:55:40 -0700 From: To: CC: Jerry Huang , Anton Vorontsov , Chris Ball Subject: [PATCH 4/4 v4] ESDHC: add callback esdhc_of_get_cd to detect card Date: Tue, 30 Oct 2012 16:12:49 +0800 Message-ID: <1351584769-16662-4-git-send-email-r66093@freescale.com> X-Mailer: git-send-email 1.6.4 In-Reply-To: <1351584769-16662-3-git-send-email-r66093@freescale.com> References: <1351584769-16662-1-git-send-email-r66093@freescale.com> <1351584769-16662-2-git-send-email-r66093@freescale.com> <1351584769-16662-3-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 CC: Anton Vorontsov CC: Chris Ball Reviewed-by: Anton Vorontsov --- 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 drivers/mmc/host/sdhci-of-esdhc.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/mmc/host/sdhci-of-esdhc.c b/drivers/mmc/host/sdhci-of-esdhc.c index 63d219f..7053218 100644 --- a/drivers/mmc/host/sdhci-of-esdhc.c +++ b/drivers/mmc/host/sdhci-of-esdhc.c @@ -179,6 +179,28 @@ 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; + + if (host->flags & SDHCI_DEVICE_DEAD) + present = 0; + else { + int 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 +213,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,