diff mbox

[4/4,v4] ESDHC: add callback esdhc_of_get_cd to detect card

Message ID 1351584769-16662-4-git-send-email-r66093@freescale.com (mailing list archive)
State New, archived
Headers show

Commit Message

Huang Changming-R66093 Oct. 30, 2012, 8:12 a.m. UTC
From: Jerry Huang <Chang-Ming.Huang@freescale.com>

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 <Chang-Ming.Huang@freescale.com>
CC: Anton Vorontsov <cbouatmailru@gmail.com>
CC: Chris Ball <cjb@laptop.org>
---
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(+)

Comments

Huang Changming-R66093 Nov. 19, 2012, 2:50 a.m. UTC | #1
Hi, Anton,
No any feedback since posted.
Could you give some comment about it?

Best Regards
Jerry Huang


> -----Original Message-----
> From: Huang Changming-R66093
> Sent: Tuesday, October 30, 2012 4:13 PM
> To: linux-mmc@vger.kernel.org
> Cc: Huang Changming-R66093; Anton Vorontsov; Chris Ball
> Subject: [PATCH 4/4 v4] ESDHC: add callback esdhc_of_get_cd to detect
> card
> 
> From: Jerry Huang <Chang-Ming.Huang@freescale.com>
> 
> 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 <Chang-Ming.Huang@freescale.com>
> CC: Anton Vorontsov <cbouatmailru@gmail.com>
> CC: Chris Ball <cjb@laptop.org>
> ---
> 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,
> --
> 1.7.9.5


--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Anton Vorontsov Nov. 19, 2012, 2:54 a.m. UTC | #2
On Mon, Nov 19, 2012 at 02:50:49AM +0000, Huang Changming-R66093 wrote:
[...]
> > --- 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;

return 0;

> > +	else {

then you don't need the 'else', which reduces indentation level.

> > +		int sysctl = sdhci_be32bs_readl(host, SDHCI_CLOCK_CONTROL);

empty line is needed here.

> > +		/* Enable the controller clock to update the present state */
> > +		sdhci_be32bs_writel(host, sysctl | SDHCI_CLOCK_INT_EN,
> > +				SDHCI_CLOCK_CONTROL);

empty line for better readability.

> > +		/* Detect the card present or absent */
> > +		present = sdhci_be32bs_readl(host, SDHCI_PRESENT_STATE);
> > +		present &= (SDHCI_CARD_PRESENT | SDHCI_CARD_CDPL);

ditto here.

> > +		/* 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,
> > --
> > 1.7.9.5

Otherwise, it looks good to me.

Reviewed-by: Anton Vorontsov <cbouatmailru@gmail.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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,