Skip to contentSkip to conversation

mmc: sdhci-pxav3: dt: Support "cd-gpios" property

PATCH In review Chris Ball 2 participants 3 messages Sep 9, 2012 – Sep 11, 2012

Subsystems (2)
lore
Share & tools
lore

Chris Ball

author
#0 lore raw

PATCH 1/1 mmc: sdhci-pxav3: dt: Support "cd-gpios" property

Tested on OLPC XO-4/MMP3, where the card detection pin for one of the controllers is a sideband GPIO. The third cell in the power-gpios property controls whether the GPIO is active high/active low.

---
 drivers/mmc/host/sdhci-pxav3.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/mmc/host/sdhci-pxav3.c +17 -0
index 0bdb326..5427d52 100644
@@ -211,6 +211,10 @@ static struct sdhci_pxa_platdata *pxav3_get_mmc_pdata(struct device *dev)
 	if (gpio_flags != OF_GPIO_ACTIVE_LOW)
 		pdata->host_caps2 |= MMC_CAP2_PWR_ACTIVE_HIGH;
 
+	pdata->ext_cd_gpio = of_get_named_gpio_flags(np, "cd-gpios", 0, &gpio_flags);
+	if (gpio_flags != OF_GPIO_ACTIVE_LOW)
+		pdata->host_caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
+
 	return pdata;
 }
 #else
@@ -292,6 +296,15 @@ static int __devinit sdhci_pxav3_probe(struct platform_device *pdev)
 				goto err_power_req;
 			}
 		}
+
+		if (gpio_is_valid(pdata->ext_cd_gpio)) {
+			ret = mmc_gpio_request_cd(host->mmc, pdata->ext_cd_gpio);
+			if (ret) {
+				dev_err(mmc_dev(host->mmc),
+					"failed to allocate card detect gpio\n");
+				goto err_cd_req;
+			}
+		}
 	}
 
 	host->ops = &pxav3_sdhci_ops;
@@ -309,6 +322,8 @@ static int __devinit sdhci_pxav3_probe(struct platform_device *pdev)
 err_add_host:
 	clk_disable_unprepare(clk);
 	clk_put(clk);
+	mmc_gpio_free_cd(host->mmc);
+err_cd_req:
 	mmc_gpio_free_pwr(host->mmc);
 err_power_req:
 err_clk_get:
@@ -331,6 +346,8 @@ static int __devexit sdhci_pxav3_remove(struct platform_device *pdev)
 
 	if (gpio_is_valid(pdata->power_gpio))
 		mmc_gpio_free_pwr(host->mmc);
+	if (gpio_is_valid(pdata->ext_cd_gpio))
+		mmc_gpio_free_cd(host->mmc);
 
 	sdhci_pltfm_free(pdev);
 	kfree(pxa);
Signature · 2 lines
Chris Ball   <[email protected]>   <http://printf.net/>
One Laptop Per Child
Acked-by on v1 1/1
#1 lore raw
Quoted 59 lines · Chris Ball

Tested on OLPC XO-4/MMP3, where the card detection pin for one of the controllers is a sideband GPIO. The third cell in the power-gpios property controls whether the GPIO is active high/active low.

---
 drivers/mmc/host/sdhci-pxav3.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/mmc/host/sdhci-pxav3.c +17 -1
index 0bdb326..5427d52 100644
@@ -211,6 +211,10 @@ static struct sdhci_pxa_platdata *pxav3_get_mmc_pdata(struct device *dev)
        if (gpio_flags != OF_GPIO_ACTIVE_LOW)
                pdata->host_caps2 |= MMC_CAP2_PWR_ACTIVE_HIGH;
 
+       pdata->ext_cd_gpio = of_get_named_gpio_flags(np, "cd-gpios", 0, &gpio_flags);
+       if (gpio_flags != OF_GPIO_ACTIVE_LOW)
+               pdata->host_caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
+
        return pdata;
 }
 #else
@@ -292,6 +296,15 @@ static int __devinit sdhci_pxav3_probe(struct platform_device *pdev)
                                goto err_power_req;
                        }
                }
+
+               if (gpio_is_valid(pdata->ext_cd_gpio)) {
+                       ret = mmc_gpio_request_cd(host->mmc, pdata->ext_cd_gpio);
+                       if (ret) {
+                               dev_err(mmc_dev(host->mmc),
+                                       "failed to allocate card detect gpio\n");
+                               goto err_cd_req;
+                       }
+               }
        }
 
        host->ops = &pxav3_sdhci_ops;
@@ -309,6 +322,8 @@ static int __devinit sdhci_pxav3_probe(struct platform_device *pdev)
 err_add_host:
        clk_disable_unprepare(clk);
        clk_put(clk);
+       mmc_gpio_free_cd(host->mmc);
+err_cd_req:
        mmc_gpio_free_pwr(host->mmc);
 err_power_req:
 err_clk_get:
@@ -331,6 +346,8 @@ static int __devexit sdhci_pxav3_remove(struct platform_device *pdev)
 
        if (gpio_is_valid(pdata->power_gpio))
                mmc_gpio_free_pwr(host->mmc);
+       if (gpio_is_valid(pdata->ext_cd_gpio))
+               mmc_gpio_free_cd(host->mmc);
 
        sdhci_pltfm_free(pdev);
        kfree(pxa);
--
Quoted 2 lines

Chris Ball <[email protected]> <http://printf.net/>
One Laptop Per Child

author
#2 lore raw

Hi,

Quoted 57 lines · Haojian Zhuang
Quoted 56 lines · Chris Ball

Tested on OLPC XO-4/MMP3, where the card detection pin for one of the controllers is a sideband GPIO. The third cell in the power-gpios property controls whether the GPIO is active high/active low.

---
 drivers/mmc/host/sdhci-pxav3.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/mmc/host/sdhci-pxav3.c +17 -0
index 0bdb326..5427d52 100644
@@ -211,6 +211,10 @@ static struct sdhci_pxa_platdata *pxav3_get_mmc_pdata(struct device *dev)
        if (gpio_flags != OF_GPIO_ACTIVE_LOW)
                pdata->host_caps2 |= MMC_CAP2_PWR_ACTIVE_HIGH;
 
+       pdata->ext_cd_gpio = of_get_named_gpio_flags(np, "cd-gpios", 0, &gpio_flags);
+       if (gpio_flags != OF_GPIO_ACTIVE_LOW)
+               pdata->host_caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
+
        return pdata;
 }
 #else
@@ -292,6 +296,15 @@ static int __devinit sdhci_pxav3_probe(struct platform_device *pdev)
                                goto err_power_req;
                        }
                }
+
+               if (gpio_is_valid(pdata->ext_cd_gpio)) {
+                       ret = mmc_gpio_request_cd(host->mmc, pdata->ext_cd_gpio);
+                       if (ret) {
+                               dev_err(mmc_dev(host->mmc),
+                                       "failed to allocate card detect gpio\n");
+                               goto err_cd_req;
+                       }
+               }
        }
 
        host->ops = &pxav3_sdhci_ops;
@@ -309,6 +322,8 @@ static int __devinit sdhci_pxav3_probe(struct platform_device *pdev)
 err_add_host:
        clk_disable_unprepare(clk);
        clk_put(clk);
+       mmc_gpio_free_cd(host->mmc);
+err_cd_req:
        mmc_gpio_free_pwr(host->mmc);
 err_power_req:
 err_clk_get:
@@ -331,6 +346,8 @@ static int __devexit sdhci_pxav3_remove(struct platform_device *pdev)
 
        if (gpio_is_valid(pdata->power_gpio))
                mmc_gpio_free_pwr(host->mmc);
+       if (gpio_is_valid(pdata->ext_cd_gpio))
+               mmc_gpio_free_cd(host->mmc);
 
Quoted 7 lines
Quoted 5 lines
drivers/mmc/host/sdhci-pxav3.c +0 -1
        sdhci_pltfm_free(pdev);
        kfree(pxa);
--

Chris Ball <[email protected]> <http://printf.net/>
One Laptop Per Child

Thanks, pushed to mmc-next for 3.7 after rebasing to make this patch precede the power_gpio patch (which isn't ready to merge).

- Chris.

Signature · 2 lines
Chris Ball   <[email protected]>   <http://printf.net/>
One Laptop Per Child