diff mbox

[3/4,v5] SDHCI: add sdhci_get_cd callback to detect the card

Message ID 1351584769-16662-3-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>

Add callback function sdhci_get_cd to detect the card.
And one new callback added to implement the card detect in sdhci struncture.
If special platform has the card detect callback, it will return the card
state, the value zero is for absent cardi and one is for present card.
If the controller don't support card detect, sdhci_get_cd will return -ENOSYS.

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:
	- when controller don't support get_cd, return -ENOSYS
	- add new callback for sdhci to detect the card
	- add the CC
changes for v3:
	- use pin_lock only when get_cd defined
changes for v4:
	- enalbe the controller clock in platform, instead of core
changes for v5:
	- remove the copyright

 drivers/mmc/host/sdhci.c |   21 +++++++++++++++++++++
 drivers/mmc/host/sdhci.h |    2 ++
 2 files changed, 23 insertions(+)

Comments

Huang Changming-R66093 Nov. 19, 2012, 2:50 a.m. UTC | #1
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 3/4 v5] SDHCI: add sdhci_get_cd callback to detect the
> card
> 
> From: Jerry Huang <Chang-Ming.Huang@freescale.com>
> 
> Add callback function sdhci_get_cd to detect the card.
> And one new callback added to implement the card detect in sdhci
> struncture.
> If special platform has the card detect callback, it will return the card
> state, the value zero is for absent cardi and one is for present card.
> If the controller don't support card detect, sdhci_get_cd will return -
> ENOSYS.
> 
> 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:
> 	- when controller don't support get_cd, return -ENOSYS
> 	- add new callback for sdhci to detect the card
> 	- add the CC
> changes for v3:
> 	- use pin_lock only when get_cd defined changes for v4:
> 	- enalbe the controller clock in platform, instead of core changes
> for v5:
> 	- remove the copyright
> 
>  drivers/mmc/host/sdhci.c |   21 +++++++++++++++++++++
>  drivers/mmc/host/sdhci.h |    2 ++
>  2 files changed, 23 insertions(+)
> 
> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index
> f05a377..cc9c8a6 100644
> --- a/drivers/mmc/host/sdhci.c
> +++ b/drivers/mmc/host/sdhci.c
> @@ -1573,6 +1573,26 @@ static int sdhci_get_ro(struct mmc_host *mmc)
>  	return ret;
>  }
> 
> +/* Return values for the sdjco_get_cd callback:
> + *   0 for a absent card
> + *   1 for a present card
> + *   -ENOSYS when not supported (equal to NULL callback)
> + */
> +static int sdhci_get_cd(struct mmc_host *mmc) {
> +	struct sdhci_host *host = mmc_priv(mmc);
> +	unsigned long flags;
> +	int present = -ENOSYS;
> +
> +	if (host->ops->get_cd) {
> +		spin_lock_irqsave(&host->lock, flags);
> +		present = host->ops->get_cd(host);
> +		spin_unlock_irqrestore(&host->lock, flags);
> +	}
> +
> +	return present;
> +}
> +
>  static void sdhci_enable_sdio_irq_nolock(struct sdhci_host *host, int
> enable)  {
>  	if (host->flags & SDHCI_DEVICE_DEAD)
> @@ -1995,6 +2015,7 @@ static const struct mmc_host_ops sdhci_ops = {
>  	.request	= sdhci_request,
>  	.set_ios	= sdhci_set_ios,
>  	.get_ro		= sdhci_get_ro,
> +	.get_cd		= sdhci_get_cd,
>  	.hw_reset	= sdhci_hw_reset,
>  	.enable_sdio_irq = sdhci_enable_sdio_irq,
>  	.start_signal_voltage_switch	= sdhci_start_signal_voltage_switch,
> diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index
> 71a4a7e..7c8f08d 100644
> --- a/drivers/mmc/host/sdhci.h
> +++ b/drivers/mmc/host/sdhci.h
> @@ -69,6 +69,7 @@
>  #define  SDHCI_SPACE_AVAILABLE	0x00000400
>  #define  SDHCI_DATA_AVAILABLE	0x00000800
>  #define  SDHCI_CARD_PRESENT	0x00010000
> +#define  SDHCI_CARD_CDPL	0x00040000
>  #define  SDHCI_WRITE_PROTECT	0x00080000
>  #define  SDHCI_DATA_LVL_MASK	0x00F00000
>  #define   SDHCI_DATA_LVL_SHIFT	20
> @@ -263,6 +264,7 @@ struct sdhci_ops {
> 
>  	void	(*set_clock)(struct sdhci_host *host, unsigned int clock);
> 
> +	int		(*get_cd)(struct sdhci_host *host);
>  	int		(*enable_dma)(struct sdhci_host *host);
>  	unsigned int	(*get_max_clock)(struct sdhci_host *host);
>  	unsigned int	(*get_min_clock)(struct sdhci_host *host);
> --
> 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:58 a.m. UTC | #2
On Mon, Nov 19, 2012 at 02:50:18AM +0000, Huang Changming-R66093 wrote:
[...]
> > diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index
> > f05a377..cc9c8a6 100644
> > --- a/drivers/mmc/host/sdhci.c
> > +++ b/drivers/mmc/host/sdhci.c
> > @@ -1573,6 +1573,26 @@ static int sdhci_get_ro(struct mmc_host *mmc)
> >  	return ret;
> >  }
> > 
> > +/* Return values for the sdjco_get_cd callback:
> > + *   0 for a absent card
> > + *   1 for a present card
> > + *   -ENOSYS when not supported (equal to NULL callback)
> > + */

Incorrect style.

> > +static int sdhci_get_cd(struct mmc_host *mmc) {

ditto

> > +	struct sdhci_host *host = mmc_priv(mmc);
> > +	unsigned long flags;
> > +	int present = -ENOSYS;

	if (!host->ops->get_cd)
		return -ENOSYS;

	...
	...

Otherwise, it looks good.

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
Huang Changming-R66093 Nov. 19, 2012, 3:15 a.m. UTC | #3
> -----Original Message-----

> From: Anton Vorontsov [mailto:cbouatmailru@gmail.com]

> Sent: Monday, November 19, 2012 10:58 AM

> To: Huang Changming-R66093

> Cc: Chris Ball; linux-mmc@vger.kernel.org

> Subject: Re: [PATCH 3/4 v5] SDHCI: add sdhci_get_cd callback to detect

> the card

> 

> On Mon, Nov 19, 2012 at 02:50:18AM +0000, Huang Changming-R66093 wrote:

> [...]

> > > diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c

> index

> > > f05a377..cc9c8a6 100644

> > > --- a/drivers/mmc/host/sdhci.c

> > > +++ b/drivers/mmc/host/sdhci.c

> > > @@ -1573,6 +1573,26 @@ static int sdhci_get_ro(struct mmc_host *mmc)

> > >  	return ret;

> > >  }

> > >

> > > +/* Return values for the sdjco_get_cd callback:

> > > + *   0 for a absent card

> > > + *   1 for a present card

> > > + *   -ENOSYS when not supported (equal to NULL callback)

> > > + */

> 

> Incorrect style.

Hi, Anton, you mean the comment style is incrorrect?
It should be:
/*
 * xxxxx
 * xxxxxx
 */

> > > +static int sdhci_get_cd(struct mmc_host *mmc) {

> 

> ditto

I don't see the issue, could you explain it?

> 

> > > +	struct sdhci_host *host = mmc_priv(mmc);

> > > +	unsigned long flags;

> > > +	int present = -ENOSYS;

> 

> 	if (!host->ops->get_cd)

> 		return -ENOSYS;

> 

> 	...

> 	...

> 

> Otherwise, it looks good.

> 

> Reviewed-by: Anton Vorontsov <cbouatmailru@gmail.com>
Anton Vorontsov Nov. 19, 2012, 3:31 a.m. UTC | #4
On Mon, Nov 19, 2012 at 03:15:53AM +0000, Huang Changming-R66093 wrote:
[...]
> > > > @@ -1573,6 +1573,26 @@ static int sdhci_get_ro(struct mmc_host *mmc)
> > > >  	return ret;
> > > >  }
> > > >
> > > > +/* Return values for the sdjco_get_cd callback:
> > > > + *   0 for a absent card
> > > > + *   1 for a present card
> > > > + *   -ENOSYS when not supported (equal to NULL callback)
> > > > + */
> > 
> > Incorrect style.
> Hi, Anton, you mean the comment style is incrorrect?
> It should be:
> /*
>  * xxxxx
>  * xxxxxx
>  */

Yup.

> 
> > > > +static int sdhci_get_cd(struct mmc_host *mmc) {
> > 
> > ditto
> I don't see the issue, could you explain it?

The issue is in the brace placement. It should be

static int sdhci_get_cd(struct mmc_host *mmc)
{
	...
}

Please refer to Documentation/CodingStyle -- it's a great document.

Thanks,
Anton.
--
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
Huang Changming-R66093 Nov. 19, 2012, 3:38 a.m. UTC | #5
DQoNCkJlc3QgUmVnYXJkcw0KSmVycnkgSHVhbmcNCg0KDQo+IC0tLS0tT3JpZ2luYWwgTWVzc2Fn
ZS0tLS0tDQo+IEZyb206IGxpbnV4LW1tYy1vd25lckB2Z2VyLmtlcm5lbC5vcmcgW21haWx0bzps
aW51eC1tbWMtDQo+IG93bmVyQHZnZXIua2VybmVsLm9yZ10gT24gQmVoYWxmIE9mIEFudG9uIFZv
cm9udHNvdg0KPiBTZW50OiBNb25kYXksIE5vdmVtYmVyIDE5LCAyMDEyIDExOjMxIEFNDQo+IFRv
OiBIdWFuZyBDaGFuZ21pbmctUjY2MDkzDQo+IENjOiBDaHJpcyBCYWxsOyBsaW51eC1tbWNAdmdl
ci5rZXJuZWwub3JnDQo+IFN1YmplY3Q6IFJlOiBbUEFUQ0ggMy80IHY1XSBTREhDSTogYWRkIHNk
aGNpX2dldF9jZCBjYWxsYmFjayB0byBkZXRlY3QNCj4gdGhlIGNhcmQNCj4gDQo+IE9uIE1vbiwg
Tm92IDE5LCAyMDEyIGF0IDAzOjE1OjUzQU0gKzAwMDAsIEh1YW5nIENoYW5nbWluZy1SNjYwOTMg
d3JvdGU6DQo+IFsuLi5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X2hv
c3QgKm1tYykNCj4gew0KPiAJLi4uDQo+IH0NCj4gDQo+IFBsZWFzZSByZWZlciB0byBEb2N1bWVu
dGF0aW9uL0NvZGluZ1N0eWxlIC0tIGl0J3MgYSBncmVhdCBkb2N1bWVudC4NCj4gDQpZZXMsIG15
IGZpcnN0IHBvc3QgaXMgdGhhdCB5b3Ugc2F5LA0KTWF5YmUgdGhlIGV4dHJhIGxpbmVzIGJyZWFr
cyBoYXMgYmVlbiByZW1vdmVkIGluIHlvdSBtZXNzYWdlLCBzbyB5b3Ugc2VlIHRoZSBpbmNvcnJl
Y3Qgc3R5bGUuDQoNCkFueXdheSwgVGhhbmsgeW91IHZlcnkgbXVjaC4NCkkgd2lsbCBwb3N0IG5l
dyB2ZXJzaW9uIHdpdGggeW91ciBSZXZpZXdlZC4NCg0K

--
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.c b/drivers/mmc/host/sdhci.c
index f05a377..cc9c8a6 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -1573,6 +1573,26 @@  static int sdhci_get_ro(struct mmc_host *mmc)
 	return ret;
 }
 
+/* Return values for the sdjco_get_cd callback:
+ *   0 for a absent card
+ *   1 for a present card
+ *   -ENOSYS when not supported (equal to NULL callback)
+ */
+static int sdhci_get_cd(struct mmc_host *mmc)
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+	unsigned long flags;
+	int present = -ENOSYS;
+
+	if (host->ops->get_cd) {
+		spin_lock_irqsave(&host->lock, flags);
+		present = host->ops->get_cd(host);
+		spin_unlock_irqrestore(&host->lock, flags);
+	}
+
+	return present;
+}
+
 static void sdhci_enable_sdio_irq_nolock(struct sdhci_host *host, int enable)
 {
 	if (host->flags & SDHCI_DEVICE_DEAD)
@@ -1995,6 +2015,7 @@  static const struct mmc_host_ops sdhci_ops = {
 	.request	= sdhci_request,
 	.set_ios	= sdhci_set_ios,
 	.get_ro		= sdhci_get_ro,
+	.get_cd		= sdhci_get_cd,
 	.hw_reset	= sdhci_hw_reset,
 	.enable_sdio_irq = sdhci_enable_sdio_irq,
 	.start_signal_voltage_switch	= sdhci_start_signal_voltage_switch,
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index 71a4a7e..7c8f08d 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -69,6 +69,7 @@ 
 #define  SDHCI_SPACE_AVAILABLE	0x00000400
 #define  SDHCI_DATA_AVAILABLE	0x00000800
 #define  SDHCI_CARD_PRESENT	0x00010000
+#define  SDHCI_CARD_CDPL	0x00040000
 #define  SDHCI_WRITE_PROTECT	0x00080000
 #define  SDHCI_DATA_LVL_MASK	0x00F00000
 #define   SDHCI_DATA_LVL_SHIFT	20
@@ -263,6 +264,7 @@  struct sdhci_ops {
 
 	void	(*set_clock)(struct sdhci_host *host, unsigned int clock);
 
+	int		(*get_cd)(struct sdhci_host *host);
 	int		(*enable_dma)(struct sdhci_host *host);
 	unsigned int	(*get_max_clock)(struct sdhci_host *host);
 	unsigned int	(*get_min_clock)(struct sdhci_host *host);