diff mbox

[02/12] ARM: ep93xx: vision_ep9307: Use MMC CD and RO GPIO

Message ID 1374794808-21890-3-git-send-email-laurent.pinchart+renesas@ideasonboard.com (mailing list archive)
State New, archived
Headers show

Commit Message

Laurent Pinchart July 25, 2013, 11:26 p.m. UTC
Pass the CD and RO GPIO numbers to the MMC SPI driver and remove the
custom .get_cd() and .get_ro() callback functions.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 arch/arm/mach-ep93xx/vision_ep9307.c | 56 +++---------------------------------
 1 file changed, 4 insertions(+), 52 deletions(-)

Comments

Hartley Sweeten July 25, 2013, 11:33 p.m. UTC | #1
On Thursday, July 25, 2013 4:27 PM, Laurent Pinchart wrote:
>
> Pass the CD and RO GPIO numbers to the MMC SPI driver and remove the
> custom .get_cd() and .get_ro() callback functions.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> ---
>  arch/arm/mach-ep93xx/vision_ep9307.c | 56 +++---------------------------------
>  1 file changed, 4 insertions(+), 52 deletions(-)

I'll try testing this tomorrow.

Thanks,
Hartley
Hartley Sweeten July 26, 2013, 12:19 a.m. UTC | #2
On Thursday, July 25, 2013 4:27 PM, Laurent Pinchart wrote:
>
> Pass the CD and RO GPIO numbers to the MMC SPI driver and remove the
> custom .get_cd() and .get_ro() callback functions.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> ---
>  arch/arm/mach-ep93xx/vision_ep9307.c | 56 +++---------------------------------
>  1 file changed, 4 insertions(+), 52 deletions(-)
>
> diff --git a/arch/arm/mach-ep93xx/vision_ep9307.c b/arch/arm/mach-ep93xx/vision_ep9307.c
> index 605956f..ab94dc5 100644
> --- a/arch/arm/mach-ep93xx/vision_ep9307.c
> +++ b/arch/arm/mach-ep93xx/vision_ep9307.c
> @@ -224,62 +224,14 @@ static struct ep93xx_spi_chip_ops vision_spi_flash_hw = {
>  #define VISION_SPI_MMC_WP	EP93XX_GPIO_LINE_F(0)
>  #define VISION_SPI_MMC_CD	EP93XX_GPIO_LINE_EGPIO15
>  
> -static struct gpio vision_spi_mmc_gpios[] = {
> -	{ VISION_SPI_MMC_WP, GPIOF_DIR_IN, "mmc_spi:wp" },
> -	{ VISION_SPI_MMC_CD, GPIOF_DIR_IN, "mmc_spi:cd" },
> -};
> -
> -static int vision_spi_mmc_init(struct device *pdev,
> -			irqreturn_t (*func)(int, void *), void *pdata)
> -{
> -	int err;
> -
> -	err = gpio_request_array(vision_spi_mmc_gpios,
> -				 ARRAY_SIZE(vision_spi_mmc_gpios));
> -	if (err)
> -		return err;
> -
> -	err = gpio_set_debounce(VISION_SPI_MMC_CD, 1);
> -	if (err)
> -		goto exit_err;

I tested this and it _kind_ of works.

The card detect is a bit flaky due to the gpio interrupt debounce not being enabled.

The only way I can see to fix this is add the following to this patch:

@@ -233,8 +233,31 @@ static struct mmc_spi_platform_data vision_spi_mmc_data = {
        .caps2          = MMC_CAP2_RO_ACTIVE_HIGH,
 };
 
+static int vision_spi_mmc_enable_cd_debounce(struct spi_device *spi)
+{
+       int ret;
+
+       ret = gpio_request_one(VISION_SPI_MMC_CD, GPIOF_DIR_IN, spi->modalias);
+       if (ret)
+               return ret;
+
+       ret = gpio_set_debounce(VISION_SPI_MMC_CD, 1);
+       if (ret)
+               return ret;
+
+       gpio_free(VISION_SPI_MMC_CD);
+
+       return 0;
+}
+
 static int vision_spi_mmc_hw_setup(struct spi_device *spi)
 {
+       int ret;
+
+       ret = vision_spi_mmc_enable_cd_debounce(spi);
+       if (ret)
+               return ret;
+
        return gpio_request_one(VISION_SPI_MMC_CS, GPIOF_INIT_HIGH,
                                spi->modalias);
 }

Regards,
Hartley
Laurent Pinchart July 26, 2013, 9:54 a.m. UTC | #3
Hi Hartley,

On Thursday 25 July 2013 19:19:52 H Hartley Sweeten wrote:
> On Thursday, July 25, 2013 4:27 PM, Laurent Pinchart wrote:
> > Pass the CD and RO GPIO numbers to the MMC SPI driver and remove the
> > custom .get_cd() and .get_ro() callback functions.
> > 
> > Signed-off-by: Laurent Pinchart
> > <laurent.pinchart+renesas@ideasonboard.com>
> > ---
> > 
> >  arch/arm/mach-ep93xx/vision_ep9307.c | 56  +++---------------------------
> >  1 file changed, 4 insertions(+), 52 deletions(-)
> > 
> > diff --git a/arch/arm/mach-ep93xx/vision_ep9307.c
> > b/arch/arm/mach-ep93xx/vision_ep9307.c index 605956f..ab94dc5 100644
> > --- a/arch/arm/mach-ep93xx/vision_ep9307.c
> > +++ b/arch/arm/mach-ep93xx/vision_ep9307.c
> > @@ -224,62 +224,14 @@ static struct ep93xx_spi_chip_ops
> > vision_spi_flash_hw = {> 
> >  #define VISION_SPI_MMC_WP	EP93XX_GPIO_LINE_F(0)
> >  #define VISION_SPI_MMC_CD	EP93XX_GPIO_LINE_EGPIO15
> > 
> > -static struct gpio vision_spi_mmc_gpios[] = {
> > -	{ VISION_SPI_MMC_WP, GPIOF_DIR_IN, "mmc_spi:wp" },
> > -	{ VISION_SPI_MMC_CD, GPIOF_DIR_IN, "mmc_spi:cd" },
> > -};
> > -
> > -static int vision_spi_mmc_init(struct device *pdev,
> > -			irqreturn_t (*func)(int, void *), void *pdata)
> > -{
> > -	int err;
> > -
> > -	err = gpio_request_array(vision_spi_mmc_gpios,
> > -				 ARRAY_SIZE(vision_spi_mmc_gpios));
> > -	if (err)
> > -		return err;
> > -
> > -	err = gpio_set_debounce(VISION_SPI_MMC_CD, 1);
> > -	if (err)
> > -		goto exit_err;
> 
> I tested this and it _kind_ of works.
> 
> The card detect is a bit flaky due to the gpio interrupt debounce not being
> enabled.
> 
> The only way I can see to fix this is add the following to this patch:
> 
> @@ -233,8 +233,31 @@ static struct mmc_spi_platform_data vision_spi_mmc_data
> = { .caps2          = MMC_CAP2_RO_ACTIVE_HIGH,
>  };
> 
> +static int vision_spi_mmc_enable_cd_debounce(struct spi_device *spi)
> +{
> +       int ret;
> +
> +       ret = gpio_request_one(VISION_SPI_MMC_CD, GPIOF_DIR_IN,
> spi->modalias);
> +       if (ret)
> +               return ret;
> +
> +       ret = gpio_set_debounce(VISION_SPI_MMC_CD, 1);
> +       if (ret)
> +               return ret;
> +
> +       gpio_free(VISION_SPI_MMC_CD);
> +
> +       return 0;
> +}
> +
>  static int vision_spi_mmc_hw_setup(struct spi_device *spi)
>  {
> +       int ret;
> +
> +       ret = vision_spi_mmc_enable_cd_debounce(spi);
> +       if (ret)
> +               return ret;
> +
>         return gpio_request_one(VISION_SPI_MMC_CS, GPIOF_INIT_HIGH,
>                                 spi->modalias);
>  }

What about extending the mmc_spi and MMC core with GPIO debounce support ? The 
mmc_spi driver would get a new cd_gpio_debounce field, which would be passed 
to mmc_gpio_request_cd(). I can cook up a patch.
Hartley Sweeten July 26, 2013, 4:26 p.m. UTC | #4
On Friday, July 26, 2013 2:55 AM, Laurent Pinchart wrote:
> On Thursday 25 July 2013 19:19:52 H Hartley Sweeten wrote:
>> On Thursday, July 25, 2013 4:27 PM, Laurent Pinchart wrote:
>>> Pass the CD and RO GPIO numbers to the MMC SPI driver and remove the
>>> custom .get_cd() and .get_ro() callback functions.
>>> 
>>> Signed-off-by: Laurent Pinchart
>>> <laurent.pinchart+renesas@ideasonboard.com>
>>> ---
>>> 
>>>  arch/arm/mach-ep93xx/vision_ep9307.c | 56  +++---------------------------
>>>  1 file changed, 4 insertions(+), 52 deletions(-)

<snip>

>> I tested this and it _kind_ of works.
>> 
>> The card detect is a bit flaky due to the gpio interrupt debounce not being
>> enabled.
>> 
>> The only way I can see to fix this is add the following to this patch:

<snip>

> What about extending the mmc_spi and MMC core with GPIO debounce support ? The 
> mmc_spi driver would get a new cd_gpio_debounce field, which would be passed 
> to mmc_gpio_request_cd(). I can cook up a patch.

Works for me. That would also remove the need for the platform init to request then free
the GPIO just to set the debounce.

Make sure you do the gpiu_set_debounce() after the GPIO has been requested or you
trigger a WARN due to the auto-requested GPIO. Then, of course, the drivers gpio request
will fail...

I'll give it a test when you post it.

Thanks,
Hartley
diff mbox

Patch

diff --git a/arch/arm/mach-ep93xx/vision_ep9307.c b/arch/arm/mach-ep93xx/vision_ep9307.c
index 605956f..ab94dc5 100644
--- a/arch/arm/mach-ep93xx/vision_ep9307.c
+++ b/arch/arm/mach-ep93xx/vision_ep9307.c
@@ -224,62 +224,14 @@  static struct ep93xx_spi_chip_ops vision_spi_flash_hw = {
 #define VISION_SPI_MMC_WP	EP93XX_GPIO_LINE_F(0)
 #define VISION_SPI_MMC_CD	EP93XX_GPIO_LINE_EGPIO15
 
-static struct gpio vision_spi_mmc_gpios[] = {
-	{ VISION_SPI_MMC_WP, GPIOF_DIR_IN, "mmc_spi:wp" },
-	{ VISION_SPI_MMC_CD, GPIOF_DIR_IN, "mmc_spi:cd" },
-};
-
-static int vision_spi_mmc_init(struct device *pdev,
-			irqreturn_t (*func)(int, void *), void *pdata)
-{
-	int err;
-
-	err = gpio_request_array(vision_spi_mmc_gpios,
-				 ARRAY_SIZE(vision_spi_mmc_gpios));
-	if (err)
-		return err;
-
-	err = gpio_set_debounce(VISION_SPI_MMC_CD, 1);
-	if (err)
-		goto exit_err;
-
-	err = request_irq(gpio_to_irq(VISION_SPI_MMC_CD), func,
-			IRQ_TYPE_EDGE_BOTH, "mmc_spi:cd", pdata);
-	if (err)
-		goto exit_err;
-
-	return 0;
-
-exit_err:
-	gpio_free_array(vision_spi_mmc_gpios, ARRAY_SIZE(vision_spi_mmc_gpios));
-	return err;
-
-}
-
-static void vision_spi_mmc_exit(struct device *pdev, void *pdata)
-{
-	free_irq(gpio_to_irq(VISION_SPI_MMC_CD), pdata);
-	gpio_free_array(vision_spi_mmc_gpios, ARRAY_SIZE(vision_spi_mmc_gpios));
-}
-
-static int vision_spi_mmc_get_ro(struct device *pdev)
-{
-	return !!gpio_get_value(VISION_SPI_MMC_WP);
-}
-
-static int vision_spi_mmc_get_cd(struct device *pdev)
-{
-	return !gpio_get_value(VISION_SPI_MMC_CD);
-}
-
 static struct mmc_spi_platform_data vision_spi_mmc_data = {
-	.init		= vision_spi_mmc_init,
-	.exit		= vision_spi_mmc_exit,
-	.get_ro		= vision_spi_mmc_get_ro,
-	.get_cd		= vision_spi_mmc_get_cd,
 	.detect_delay	= 100,
 	.powerup_msecs	= 100,
 	.ocr_mask	= MMC_VDD_32_33 | MMC_VDD_33_34,
+	.flags		= MMC_SPI_USE_CD_GPIO | MMC_SPI_USE_RO_GPIO,
+	.cd_gpio	= VISION_SPI_MMC_CD,
+	.ro_gpio	= VISION_SPI_MMC_WP,
+	.caps2		= MMC_CAP2_RO_ACTIVE_HIGH,
 };
 
 static int vision_spi_mmc_hw_setup(struct spi_device *spi)