sdhci-dove GPIO support for card detection
cover sdhci-dove GPIO support for card detection
The following three patches allow sdhci-dove to use a GPIO for card presence detection. This is a three stage process:
1. Clean up error paths by using devm_clk_get().
2. Use the two-stage sdhci initialization.
3. Implement the GPIO card detection support.
A very similar patch has been tested by Sebastian on the cubox; since that version, I've changed the error printing slightly and dropped the non-DT support for this feature as mainline doesn't have non-DT cubox support.
drivers/mmc/host/sdhci-dove.c | 108 +++++++++++++++++++++++++++++++++-------- 1 files changed, 88 insertions(+), 20 deletions(-)
PATCH 1/3 MMC: sdhci-dove: use devm_clk_get()
Use devm_clk_get() rather than clk_get() to make cleanup paths more simple.
--- drivers/mmc/host/sdhci-dove.c | 11 ++++------- 1 files changed, 4 insertions(+), 7 deletions(-)
drivers/mmc/host/sdhci-dove.c +4 -7
@@ -92,7 +92,7 @@ static int __devinit sdhci_dove_probe(struct platform_device *pdev)return -ENOMEM ; } - priv->clk =clk_get (&pdev->dev,NULL ); + priv->clk =devm_clk_get (&pdev->dev,NULL );if (!IS_ERR (priv->clk))clk_prepare_enable (priv->clk);
@@ -107,10 +107,8 @@ static int __devinit sdhci_dove_probe(struct platform_device *pdev)return 0 ; sdhci_dove_register_fail: -if (!IS_ERR (priv->clk)) { +if (!IS_ERR (priv->clk))clk_disable_unprepare (priv->clk); -clk_put (priv->clk); - }return ret; }
@@ -122,10 +120,9 @@ static int __devexit sdhci_dove_remove(struct platform_device *pdev)sdhci_pltfm_unregister (pdev); -if (!IS_ERR (priv->clk)) { +if (!IS_ERR (priv->clk))clk_disable_unprepare (priv->clk); -clk_put (priv->clk); - } +return 0 ; }
Signature · 1 line
1.7.4.4
PATCH 2/3 MMC: sdhci-dove: use two-stage initialization for sdhci-pltfm
In reply to Russell King - ARM LinuxWe need to use the two-stage initialization for sdhci-pltfm if we're going to do anything extra at initialization time.
--- drivers/mmc/host/sdhci-dove.c | 24 +++++++++++++++++------- 1 files changed, 17 insertions(+), 7 deletions(-)
drivers/mmc/host/sdhci-dove.c +17 -7
@@ -93,22 +93,32 @@ static int __devinit sdhci_dove_probe(struct platform_device *pdev) } priv->clk =devm_clk_get (&pdev->dev,NULL ); -if (!IS_ERR (priv->clk)) -clk_prepare_enable (priv->clk); - ret =sdhci_pltfm_register (pdev, &sdhci_dove_pdata); -if (ret) - goto sdhci_dove_register_fail; + host =sdhci_pltfm_init (pdev, &sdhci_dove_pdata); +if (IS_ERR (host)) { + ret =PTR_ERR (host); + goto err_sdhci_pltfm_init; + } - host =platform_get_drvdata (pdev); pltfm_host =sdhci_priv (host); pltfm_host->priv = priv; +if (!IS_ERR (priv->clk)) +clk_prepare_enable (priv->clk); + +sdhci_get_of_property (pdev); + + ret =sdhci_add_host (host); +if (ret) + goto err_sdhci_add; +return 0 ; -sdhci_dove_register_fail: +err_sdhci_add:if (!IS_ERR (priv->clk))clk_disable_unprepare (priv->clk); +sdhci_pltfm_free (pdev); +err_sdhci_pltfm_init:return ret; }
Signature · 1 line
1.7.4.4
PATCH 3/3 MMC: sdhci-dove: allow GPIOs to be used for card detection on Dove
In reply to Russell King - ARM LinuxThis commit taken from Rabeeh's Cubox kernel and re-worked for DT; Sebastian Hasselbrath is believed to be the original author.
Some Cuboxes require a GPIO for card detection; this implements the optional GPIO support for card detection. This GPIO is logic 0 for card inserted.
--- drivers/mmc/host/sdhci-dove.c | 73 +++++++++++++++++++++++++++++++++++++--- 1 files changed, 67 insertions(+), 6 deletions(-)
drivers/mmc/host/sdhci-dove.c +67 -6
@@ -19,20 +19,30 @@* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <linux/err.h> -#include <linux/io.h> #include <linux/clk.h> #include <linux/err.h> -#include <linux/module.h> +#include <linux/gpio.h> +#include <linux/io.h> #include <linux/mmc/host.h> +#include <linux/module.h> #include <linux/of.h> +#include <linux/of_gpio.h> #include "sdhci-pltfm.h" struct sdhci_dove_priv {struct clk *clk; +int gpio_cd; }; +static irqreturn_t sdhci_dove_carddetect_irq (int irq,void *data) +{ +struct sdhci_host *host = data; + +tasklet_schedule (&host->card_tasklet); +return IRQ_HANDLED ; +} +static u16 sdhci_dove_readw (struct sdhci_host *host,int reg) {u16 ret;
@@ -50,16 +60,25 @@ static u16 sdhci_dove_readw(struct sdhci_host *host, int reg)static u32 sdhci_dove_readl (struct sdhci_host *host,int reg) { +struct sdhci_pltfm_host *pltfm_host =sdhci_priv (host); +struct sdhci_dove_priv *priv = pltfm_host->priv;u32 ret; + ret =readl (host->ioaddr + reg); +switch (reg) {case SDHCI_CAPABILITIES : - ret =readl (host->ioaddr + reg);/* Mask the support for 3.0V */ ret &= ~SDHCI_CAN_VDD_300 ;break ; -default : - ret =readl (host->ioaddr + reg); +case SDHCI_PRESENT_STATE : +if (gpio_is_valid (priv->gpio_cd)) { +if (gpio_get_value (priv->gpio_cd) ==0 ) + ret |=SDHCI_CARD_PRESENT ; +else + ret &= ~SDHCI_CARD_PRESENT ; + } +break ; }return ret; }
@@ -94,6 +113,23 @@ static int __devinit sdhci_dove_probe(struct platform_device *pdev) priv->clk =devm_clk_get (&pdev->dev,NULL ); +if (pdev->dev.of_node) { + priv->gpio_cd =of_get_named_gpio (pdev->dev.of_node, +"cd-gpios" ,0 ); + }else { + priv->gpio_cd = -EINVAL ; + } + +if (gpio_is_valid (priv->gpio_cd)) { + ret =gpio_request (priv->gpio_cd,"sdhci-cd" ); +if (ret) { +dev_err (&pdev->dev,"card detect gpio request failed: %d\n" , + ret); +return ret; + } +gpio_direction_input (priv->gpio_cd); + } + host =sdhci_pltfm_init (pdev, &sdhci_dove_pdata);if (IS_ERR (host)) { ret =PTR_ERR (host);
@@ -112,13 +148,33 @@ static int __devinit sdhci_dove_probe(struct platform_device *pdev)if (ret) goto err_sdhci_add; +/* +* We must request the IRQ after sdhci_add_host(), as the tasklet only +* gets setup in sdhci_add_host() and we oops. +*/ +if (gpio_is_valid (priv->gpio_cd)) { + ret =request_irq (gpio_to_irq (priv->gpio_cd), + sdhci_dove_carddetect_irq, +IRQF_TRIGGER_FALLING |IRQF_TRIGGER_RISING , +mmc_hostname (host->mmc), host); +if (ret) { +dev_err (&pdev->dev,"card detect irq request failed: %d\n" , + ret); + goto err_request_irq; + } + } +return 0 ; +err_request_irq: +sdhci_remove_host (host,0 ); err_sdhci_add:if (!IS_ERR (priv->clk))clk_disable_unprepare (priv->clk);sdhci_pltfm_free (pdev); err_sdhci_pltfm_init: +if (gpio_is_valid (priv->gpio_cd)) +gpio_free (priv->gpio_cd);return ret; }
@@ -130,6 +186,11 @@ static int __devexit sdhci_dove_remove(struct platform_device *pdev)sdhci_pltfm_unregister (pdev); +if (gpio_is_valid (priv->gpio_cd)) { +free_irq (gpio_to_irq (priv->gpio_cd), host); +gpio_free (priv->gpio_cd); + } +if (!IS_ERR (priv->clk))clk_disable_unprepare (priv->clk);
Signature · 1 line
1.7.4.4
PATCH 3/3 MMC: sdhci-dove: allow GPIOs to be used for card detection on Dove
Quoted 66 lines · Russell King
This commit taken from Rabeeh's Cubox kernel and re-worked for DT; Sebastian Hasselbrath is believed to be the original author.
Some Cuboxes require a GPIO for card detection; this implements the optional GPIO support for card detection. This GPIO is logic 0 for card inserted.
Signed-off-by Russell King <[email protected]>--- drivers/mmc/host/sdhci-dove.c | 73 +++++++++++++++++++++++++++++++++++++--- 1 files changed, 67 insertions(+), 6 deletions(-)drivers/mmc/host/sdhci-dove.c +17
-4@@ -19,20 +19,30 @@* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <linux/err.h> -#include <linux/io.h> #include <linux/clk.h> #include <linux/err.h> -#include <linux/module.h> +#include <linux/gpio.h> +#include <linux/io.h> #include <linux/mmc/host.h> +#include <linux/module.h> #include <linux/of.h> +#include <linux/of_gpio.h> #include "sdhci-pltfm.h" struct sdhci_dove_priv {struct clk *clk; +int gpio_cd; }; +static irqreturn_t sdhci_dove_carddetect_irq (int irq,void *data) +{ +struct sdhci_host *host = data; + +tasklet_schedule (&host->card_tasklet); +return IRQ_HANDLED ; +} +static u16 sdhci_dove_readw (struct sdhci_host *host,int reg) {u16 ret;@@ -50,16 +60,25 @@ static u16 sdhci_dove_readw(struct sdhci_host *host, int reg)static u32 sdhci_dove_readl (struct sdhci_host *host,int reg) { +struct sdhci_pltfm_host *pltfm_host =sdhci_priv (host); +struct sdhci_dove_priv *priv = pltfm_host->priv;u32 ret; + ret =readl (host->ioaddr + reg); +switch (reg) {case SDHCI_CAPABILITIES : - ret =readl (host->ioaddr + reg);/* Mask the support for 3.0V */ ret &= ~SDHCI_CAN_VDD_300 ;break ;
drivers/mmc/host/sdhci-dove.c static u16 sdhci_dove_readw(struct sdhci_host *host, int reg) · line 81
Quoted 10 lines
drivers/mmc/host/sdhci-dove.c +8
-2-default : - ret =readl (host->ioaddr + reg); +case SDHCI_PRESENT_STATE : +if (gpio_is_valid (priv->gpio_cd)) { +if (gpio_get_value (priv->gpio_cd) ==0 ) + ret |=SDHCI_CARD_PRESENT ; +else + ret &= ~SDHCI_CARD_PRESENT ; + } +break ;
It seems that the helpers in drivers/mmc/core/slot-gpio.c can help to simplify the patch a lot. With sdhci core code being calling mmc_gpio_get_cd() to query card present, the fake SDHCI_PRESENT_STATE implementation above can be totally saved.
Shawn
Quoted 80 lines
drivers/mmc/host/sdhci-dove.c +42
-0}return ret; }@@ -94,6 +113,23 @@ static int __devinit sdhci_dove_probe(struct platform_device *pdev) priv->clk =devm_clk_get (&pdev->dev,NULL ); +if (pdev->dev.of_node) { + priv->gpio_cd =of_get_named_gpio (pdev->dev.of_node, +"cd-gpios" ,0 ); + }else { + priv->gpio_cd = -EINVAL ; + } + +if (gpio_is_valid (priv->gpio_cd)) { + ret =gpio_request (priv->gpio_cd,"sdhci-cd" ); +if (ret) { +dev_err (&pdev->dev,"card detect gpio request failed: %d\n" , + ret); +return ret; + } +gpio_direction_input (priv->gpio_cd); + } + host =sdhci_pltfm_init (pdev, &sdhci_dove_pdata);if (IS_ERR (host)) { ret =PTR_ERR (host);@@ -112,13 +148,33 @@ static int __devinit sdhci_dove_probe(struct platform_device *pdev)if (ret) goto err_sdhci_add; +/* +* We must request the IRQ after sdhci_add_host(), as the tasklet only +* gets setup in sdhci_add_host() and we oops. +*/ +if (gpio_is_valid (priv->gpio_cd)) { + ret =request_irq (gpio_to_irq (priv->gpio_cd), + sdhci_dove_carddetect_irq, +IRQF_TRIGGER_FALLING |IRQF_TRIGGER_RISING , +mmc_hostname (host->mmc), host); +if (ret) { +dev_err (&pdev->dev,"card detect irq request failed: %d\n" , + ret); + goto err_request_irq; + } + } +return 0 ; +err_request_irq: +sdhci_remove_host (host,0 ); err_sdhci_add:if (!IS_ERR (priv->clk))clk_disable_unprepare (priv->clk);sdhci_pltfm_free (pdev); err_sdhci_pltfm_init: +if (gpio_is_valid (priv->gpio_cd)) +gpio_free (priv->gpio_cd);return ret; }@@ -130,6 +186,11 @@ static int __devexit sdhci_dove_remove(struct platform_device *pdev)sdhci_pltfm_unregister (pdev); +if (gpio_is_valid (priv->gpio_cd)) { +free_irq (gpio_to_irq (priv->gpio_cd), host); +gpio_free (priv->gpio_cd); + } +if (!IS_ERR (priv->clk))clk_disable_unprepare (priv->clk);Signature · 6 lines
1.7.4.4 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/3 MMC: sdhci-dove: allow GPIOs to be used for card detection on Dove
Quoted 74 lines · Shawn Guo
Quoted 73 lines · Russell King
This commit taken from Rabeeh's Cubox kernel and re-worked for DT; Sebastian Hasselbrath is believed to be the original author.
Some Cuboxes require a GPIO for card detection; this implements the optional GPIO support for card detection. This GPIO is logic 0 for card inserted.
Signed-off-by Russell King <[email protected]>--- drivers/mmc/host/sdhci-dove.c | 73 +++++++++++++++++++++++++++++++++++++--- 1 files changed, 67 insertions(+), 6 deletions(-)drivers/mmc/host/sdhci-dove.c +22
-6@@ -19,20 +19,30 @@* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <linux/err.h> -#include <linux/io.h> #include <linux/clk.h> #include <linux/err.h> -#include <linux/module.h> +#include <linux/gpio.h> +#include <linux/io.h> #include <linux/mmc/host.h> +#include <linux/module.h> #include <linux/of.h> +#include <linux/of_gpio.h> #include "sdhci-pltfm.h" struct sdhci_dove_priv {struct clk *clk; +int gpio_cd; }; +static irqreturn_t sdhci_dove_carddetect_irq (int irq,void *data) +{ +struct sdhci_host *host = data; + +tasklet_schedule (&host->card_tasklet); +return IRQ_HANDLED ; +} +static u16 sdhci_dove_readw (struct sdhci_host *host,int reg) {u16 ret;@@ -50,16 +60,25 @@ static u16 sdhci_dove_readw(struct sdhci_host *host, int reg)static u32 sdhci_dove_readl (struct sdhci_host *host,int reg) { +struct sdhci_pltfm_host *pltfm_host =sdhci_priv (host); +struct sdhci_dove_priv *priv = pltfm_host->priv;u32 ret; + ret =readl (host->ioaddr + reg); +switch (reg) {case SDHCI_CAPABILITIES : - ret =readl (host->ioaddr + reg);/* Mask the support for 3.0V */ ret &= ~SDHCI_CAN_VDD_300 ;break ; -default : - ret =readl (host->ioaddr + reg); +case SDHCI_PRESENT_STATE : +if (gpio_is_valid (priv->gpio_cd)) { +if (gpio_get_value (priv->gpio_cd) ==0 ) + ret |=SDHCI_CARD_PRESENT ; +else
Quoted 8 lines
drivers/mmc/host/sdhci-dove.c static u16 sdhci_dove_readw(struct sdhci_host *host, int reg) · line 81
Quoted 3 lines
drivers/mmc/host/sdhci-dove.c +3
-0+ ret &= ~SDHCI_CARD_PRESENT ; + } +break ;It seems that the helpers in
drivers/mmc/core/slot-gpio.ccan help to simplify the patch a lot. With sdhci core code being callingmmc_gpio_get_cd()to query card present, the fakeSDHCI_PRESENT_STATEimplementation above can be totally saved.
Does this work with the sdhci stuff? I notice that sdhci does some special additional resetting of the host when it detects that a card is removed; this would be lost if that were to be used because the tasklet in sdhci.c would be bypassed.
So no, I don't think slot-gpio.c can be used here.
PATCH 3/3 MMC: sdhci-dove: allow GPIOs to be used for card detection on Dove
Quoted 1 line · Russell King - ARM Linux
Does this work with the sdhci stuff?
Honestly, I'm not sure, but I guess it does, since I have seen sdhci-pxav3 driver using the helpers. Anyway, I'm going to adopt the helpers for sdhci-esdhc-imx driver to find it out.
Shawn
PATCH 3/3 MMC: sdhci-dove: allow GPIOs to be used for card detection on Dove
Quoted 6 lines · Shawn Guo
Quoted 1 line · Russell King - ARM Linux
Does this work with the sdhci stuff?
Honestly, I'm not sure, but I guess it does, since I have seen sdhci-pxav3 driver using the helpers. Anyway, I'm going to adopt the helpers for sdhci-esdhc-imx driver to find it out.
The thing that worries me is this:
static void sdhci_tasklet_card(unsigned long param) {
...
/* Check host->mrq first in case we are runtime suspended */
if (host->mrq &&
!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) {
pr_err("%s: Card removed during transfer!\n",
mmc_hostname(host->mmc));
pr_err("%s: Resetting controller.\n",
mmc_hostname(host->mmc));
sdhci_reset(host, SDHCI_RESET_CMD);
sdhci_reset(host, SDHCI_RESET_DATA);
host->mrq->cmd->error = -ENOMEDIUM;
tasklet_schedule(&host->finish_tasklet);
}
...
mmc_detect_change(host->mmc, msecs_to_jiffies(200));
}That gets called whenever a card is inserted/removed by the SDHCI code (if the SDHCI card detect is wired), or in my case by the interrupt routine the code in my patch adds.
The slot-gpio.c stuff directly calls into mmc_detect_change (a) with a shorter delay, and (b) completely omits the above handling and resetting. My guess from the above code is that it'll work fine 90% of the time (because you'll remove the card without an active request), but the above code looks like it's addressing a corner case which will be omitted with the "generic" slot-gpio.c solution.
So I don't think it's a good idea to use slot-gpio.c in this case.
PATCH 3/3 MMC: sdhci-dove: allow GPIOs to be used for card detection on Dove
Hi, adding Guennadi,
Quoted 36 lines · Russell King - ARM Linux
Quoted 6 lines · Shawn Guo
Quoted 1 line · Russell King - ARM Linux
Does this work with the sdhci stuff?
Honestly, I'm not sure, but I guess it does, since I have seen sdhci-pxav3 driver using the helpers. Anyway, I'm going to adopt the helpers for sdhci-esdhc-imx driver to find it out.
The thing that worries me is this:
static void
sdhci_tasklet_card(unsigned long param){
.../* Check host->mrq first in case we are runtime suspended */ if (host->mrq && !(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) { pr_err("%s: Card removed during transfer!\n", mmc_hostname(host->mmc)); pr_err("%s: Resetting controller.\n", mmc_hostname(host->mmc)); sdhci_reset(host, SDHCI_RESET_CMD); sdhci_reset(host, SDHCI_RESET_DATA); host->mrq->cmd->error = -ENOMEDIUM; tasklet_schedule(&host->finish_tasklet); } ... mmc_detect_change(host->mmc, msecs_to_jiffies(200)); }That gets called whenever a card is inserted/removed by the SDHCI code (if the SDHCI card detect is wired), or in my case by the interrupt routine the code in my patch adds.
Quoted 8 lines
The
slot-gpio.cstuff directly calls intommc_detect_change(a) with a shorter delay, and (b) completely omits the above handling and resetting. My guess from the above code is that it'll work fine 90% of the time (because you'll remove the card without an active request), but the above code looks like it's addressing a corner case which will be omitted with the "generic"slot-gpio.csolution.So I don't think it's a good idea to use
slot-gpio.cin this case.
Guennadi, what are your thoughts about consolidating this reset logic between the sdhci tasklet and slot-gpio? It would certainly be nice to use slot-gpio in cases like this one, so it's worth fixing.
Thanks,
- Chris.
Signature · 2 lines
Chris Ball <[email protected]> <http://printf.net/> One Laptop Per Child
PATCH 3/3 MMC: sdhci-dove: allow GPIOs to be used for card detection on Dove
Hi Chris
Quoted 46 lines · Chris Ball
Hi, adding Guennadi,
Quoted 43 lines · Russell King - ARM Linux
Quoted 6 lines · Shawn Guo
Quoted 1 line · Russell King - ARM Linux
Does this work with the sdhci stuff?
Honestly, I'm not sure, but I guess it does, since I have seen sdhci-pxav3 driver using the helpers. Anyway, I'm going to adopt the helpers for sdhci-esdhc-imx driver to find it out.
The thing that worries me is this:
static void
sdhci_tasklet_card(unsigned long param){
.../* Check host->mrq first in case we are runtime suspended */ if (host->mrq && !(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) { pr_err("%s: Card removed during transfer!\n", mmc_hostname(host->mmc)); pr_err("%s: Resetting controller.\n", mmc_hostname(host->mmc)); sdhci_reset(host, SDHCI_RESET_CMD); sdhci_reset(host, SDHCI_RESET_DATA); host->mrq->cmd->error = -ENOMEDIUM; tasklet_schedule(&host->finish_tasklet); } ... mmc_detect_change(host->mmc, msecs_to_jiffies(200)); }That gets called whenever a card is inserted/removed by the SDHCI code (if the SDHCI card detect is wired), or in my case by the interrupt routine the code in my patch adds.
The
slot-gpio.cstuff directly calls intommc_detect_change(a) with a shorter delay, and (b) completely omits the above handling and resetting. My guess from the above code is that it'll work fine 90% of the time (because you'll remove the card without an active request), but the above code looks like it's addressing a corner case which will be omitted with the "generic"slot-gpio.csolution.
Quoted 5 lines
Quoted 1 line
So I don't think it's a good idea to use
slot-gpio.cin this case.Guennadi, what are your thoughts about consolidating this reset logic between the sdhci tasklet and slot-gpio? It would certainly be nice to use slot-gpio in cases like this one, so it's worth fixing.
Sure, this can be added. As for how - I see at least two possibilities:
(1) put the complete above block in a new mmc host operation and just call it from the GPIO card-detect ISR, (2) taking into account, that many (nearly all? all?) host drivers keep a pointer to the current mrq in their private data struct, we could instead add such a pointer to struct mmc_host, then the check "request in progress" could also be generalised, and the operation would just have to reset the host and complete the request (in the sdhci case schedule the task).
Note, that there's already a .hw_reset() operation, used by sdhci-pci only so far, still, it seems we cannot (easily) hijack it.
So, what would be the preferred way?
Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
PATCH 3/3 MMC: sdhci-dove: allow GPIOs to be used for card detection on Dove
Hi Guennadi,
Quoted 4 lines · Guennadi Liakhovetski
Quoted 3 lines
Guennadi, what are your thoughts about consolidating this reset logic between the sdhci tasklet and slot-gpio? It would certainly be nice to use slot-gpio in cases like this one, so it's worth fixing.
Quoted 8 lines
Sure, this can be added. As for how - I see at least two possibilities:
(1) put the complete above block in a new mmc host operation and just call it from the GPIO card-detect ISR, (2) taking into account, that many (nearly all? all?) host drivers keep a pointer to the current mrq in their private data struct, we could instead add such a pointer to structmmc_host, then the check "request in progress" could also be generalised, and the operation would just have to reset the host and complete the request (in the sdhci case schedule the task).
They both sound pretty attractive. Maybe we start out with (1), which would create a patch we could more reasonably send to stable@ to get slot-gpio handling the reset during transfers properly in older kernels, and then refactor into (2) later?
Quoted 2 lines
Note, that there's already a .hw_reset() operation, used by sdhci-pci only so far, still, it seems we cannot (easily) hijack it.
That one's implementing an eMMC 4.5 spec feature, not related to this kind of reset.
Thanks!
- Chris.
Signature · 2 lines
Chris Ball <[email protected]> <http://printf.net/> One Laptop Per Child
PATCH 3/3 MMC: sdhci-dove: allow GPIOs to be used for card detection on Dove
Hi Chris
Quoted 16 lines · Chris Ball
Hi Guennadi,
Quoted 4 lines · Guennadi Liakhovetski
Quoted 3 lines
Guennadi, what are your thoughts about consolidating this reset logic between the sdhci tasklet and slot-gpio? It would certainly be nice to use slot-gpio in cases like this one, so it's worth fixing.
Quoted 8 lines
Sure, this can be added. As for how - I see at least two possibilities:
(1) put the complete above block in a new mmc host operation and just call it from the GPIO card-detect ISR, (2) taking into account, that many (nearly all? all?) host drivers keep a pointer to the current mrq in their private data struct, we could instead add such a pointer to structmmc_host, then the check "request in progress" could also be generalised, and the operation would just have to reset the host and complete the request (in the sdhci case schedule the task).
Quoted 4 lines
They both sound pretty attractive. Maybe we start out with (1), which would create a patch we could more reasonably send to stable@ to get slot-gpio handling the reset during transfers properly in older kernels, and then refactor into (2) later?
Just posted 3 patches for this, have a look if that's what you were thinking about. Not sure though why this is needed for stable, but I'm probably just missing some crucial information on the topic.
Thanks
Guennadi
Quoted 13 lines
Quoted 2 lines
Note, that there's already a .hw_reset() operation, used by sdhci-pci only so far, still, it seems we cannot (easily) hijack it.
That one's implementing an eMMC 4.5 spec feature, not related to this kind of reset.
Thanks!
- Chris.
Signature · 2 lines
Chris Ball <[email protected]> <http://printf.net/> One Laptop Per Child
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
PATCH 3/3 MMC: sdhci-dove: allow GPIOs to be used for card detection on Dove
Hi Guennadi,
Quoted 8 lines · Guennadi Liakhovetski
Quoted 4 lines
They both sound pretty attractive. Maybe we start out with (1), which would create a patch we could more reasonably send to stable@ to get slot-gpio handling the reset during transfers properly in older kernels, and then refactor into (2) later?
Just posted 3 patches for this, have a look if that's what you were thinking about. Not sure though why this is needed for stable, but I'm probably just missing some crucial information on the topic.
Thanks! I'll take a look. I agree that this isn't definitely needed in -stable, but I'm glad we have the option if someone finds that their host isn't functioning after card removal during a transfer.
Russell, are you happy with switching sdhci-dove over to slot-gpio with this patchset?
Thanks,
- Chris.
Signature · 2 lines
Chris Ball <[email protected]> <http://printf.net/> One Laptop Per Child
PATCH 3/3 MMC: sdhci-dove: allow GPIOs to be used for card detection on Dove
Quoted 12 lines · Chris Ball
Hi Guennadi,
Quoted 8 lines · Guennadi Liakhovetski
Quoted 4 lines
They both sound pretty attractive. Maybe we start out with (1), which would create a patch we could more reasonably send to stable@ to get slot-gpio handling the reset during transfers properly in older kernels, and then refactor into (2) later?
Just posted 3 patches for this, have a look if that's what you were thinking about. Not sure though why this is needed for stable, but I'm probably just missing some crucial information on the topic.
Quoted 6 lines
Thanks! I'll take a look. I agree that this isn't definitely needed in -stable, but I'm glad we have the option if someone finds that their host isn't functioning after card removal during a transfer.
Russell, are you happy with switching sdhci-dove over to slot-gpio with this patchset?
I'd rather not until I've moved my cubox kernel tree to v3.7 (when it's out.) Keeping stuff straight between that tree and mainline is far from easy - I'm having to maintain two independent patches for each change, one against each kernel tree, one gets tested (the one in the cubox tree) the other (against mainline) does not.
PATCH 3/3 MMC: sdhci-dove: allow GPIOs to be used for card detection on Dove
Hi,
Quoted 8 lines · Russell King - ARM Linux
Quoted 2 lines
Russell, are you happy with switching sdhci-dove over to slot-gpio with this patchset?
I'd rather not until I've moved my cubox kernel tree to v3.7 (when it's out.) Keeping stuff straight between that tree and mainline is far from easy - I'm having to maintain two independent patches for each change, one against each kernel tree, one gets tested (the one in the cubox tree) the other (against mainline) does not.
Okay -- I'll take the patchset as-is for 3.8, with a plan to move to slot-gpio after you're caught up. Thanks!
- Chris.
Signature · 2 lines
Chris Ball <[email protected]> <http://printf.net/> One Laptop Per Child
PATCH 3/3 MMC: sdhci-dove: allow GPIOs to be used for card detection on Dove
In reply to Russell KingQuoted 138 lines · Russell King
This commit taken from Rabeeh's Cubox kernel and re-worked for DT; Sebastian Hasselbrath is believed to be the original author.
Some Cuboxes require a GPIO for card detection; this implements the optional GPIO support for card detection. This GPIO is logic 0 for card inserted.
Signed-off-by Russell King <[email protected]>--- drivers/mmc/host/sdhci-dove.c | 73 +++++++++++++++++++++++++++++++++++++--- 1 files changed, 67 insertions(+), 6 deletions(-)drivers/mmc/host/sdhci-dove.c +62
-6@@ -19,20 +19,30 @@* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <linux/err.h> -#include <linux/io.h> #include <linux/clk.h> #include <linux/err.h> -#include <linux/module.h> +#include <linux/gpio.h> +#include <linux/io.h> #include <linux/mmc/host.h> +#include <linux/module.h> #include <linux/of.h> +#include <linux/of_gpio.h> #include "sdhci-pltfm.h" struct sdhci_dove_priv {struct clk *clk; +int gpio_cd; }; +static irqreturn_t sdhci_dove_carddetect_irq (int irq,void *data) +{ +struct sdhci_host *host = data; + +tasklet_schedule (&host->card_tasklet); +return IRQ_HANDLED ; +} +static u16 sdhci_dove_readw (struct sdhci_host *host,int reg) {u16 ret;@@ -50,16 +60,25 @@ static u16 sdhci_dove_readw(struct sdhci_host *host, int reg)static u32 sdhci_dove_readl (struct sdhci_host *host,int reg) { +struct sdhci_pltfm_host *pltfm_host =sdhci_priv (host); +struct sdhci_dove_priv *priv = pltfm_host->priv;u32 ret; + ret =readl (host->ioaddr + reg); +switch (reg) {case SDHCI_CAPABILITIES : - ret =readl (host->ioaddr + reg);/* Mask the support for 3.0V */ ret &= ~SDHCI_CAN_VDD_300 ;break ; -default : - ret =readl (host->ioaddr + reg); +case SDHCI_PRESENT_STATE : +if (gpio_is_valid (priv->gpio_cd)) { +if (gpio_get_value (priv->gpio_cd) ==0 ) + ret |=SDHCI_CARD_PRESENT ; +else + ret &= ~SDHCI_CARD_PRESENT ; + } +break ; }return ret; }@@ -94,6 +113,23 @@ static int __devinit sdhci_dove_probe(struct platform_device *pdev) priv->clk =devm_clk_get (&pdev->dev,NULL ); +if (pdev->dev.of_node) { + priv->gpio_cd =of_get_named_gpio (pdev->dev.of_node, +"cd-gpios" ,0 ); + }else { + priv->gpio_cd = -EINVAL ; + } + +if (gpio_is_valid (priv->gpio_cd)) { + ret =gpio_request (priv->gpio_cd,"sdhci-cd" ); +if (ret) { +dev_err (&pdev->dev,"card detect gpio request failed: %d\n" , + ret); +return ret; + } +gpio_direction_input (priv->gpio_cd); + } + host =sdhci_pltfm_init (pdev, &sdhci_dove_pdata);if (IS_ERR (host)) { ret =PTR_ERR (host);@@ -112,13 +148,33 @@ static int __devinit sdhci_dove_probe(struct platform_device *pdev)if (ret) goto err_sdhci_add; +/* +* We must request the IRQ after sdhci_add_host(), as the tasklet only +* gets setup in sdhci_add_host() and we oops. +*/ +if (gpio_is_valid (priv->gpio_cd)) { + ret =request_irq (gpio_to_irq (priv->gpio_cd), + sdhci_dove_carddetect_irq, +IRQF_TRIGGER_FALLING |IRQF_TRIGGER_RISING , +mmc_hostname (host->mmc), host); +if (ret) { +dev_err (&pdev->dev,"card detect irq request failed: %d\n" , + ret); + goto err_request_irq; + } + } +return 0 ; +err_request_irq: +sdhci_remove_host (host,0 ); err_sdhci_add:if (!IS_ERR (priv->clk))clk_disable_unprepare (priv->clk);sdhci_pltfm_free (pdev); err_sdhci_pltfm_init: +if (gpio_is_valid (priv->gpio_cd)) +gpio_free (priv->gpio_cd);return ret; }
drivers/mmc/host/sdhci-dove.c static int __devexit sdhci_dove_remove(struct platform_device *pdev) · line 193
Quoted 8 lines
drivers/mmc/host/sdhci-dove.c +5
-0@@ -130,6 +186,11 @@ static int __devexit sdhci_dove_remove(struct platform_device *pdev)sdhci_pltfm_unregister (pdev); +if (gpio_is_valid (priv->gpio_cd)) { +free_irq (gpio_to_irq (priv->gpio_cd), host); +gpio_free (priv->gpio_cd); + } +
You can probably use devm_gpio_request() and devm_request_irq() to save these cleanups like what patch #1 is doing?
Shawn
Quoted 10 lines
drivers/mmc/host/sdhci-dove.c +0
-0if (!IS_ERR (priv->clk))clk_disable_unprepare (priv->clk);Signature · 6 lines
1.7.4.4 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html