Skip to contentSkip to conversation

mmc: add a card-event host call-back

PATCH New Guennadi Liakhovetski 3 participants 6 messages Dec 4, 2012 – Dec 7, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover mmc: add a card-event host call-back

In a recent thread [1] an extension to the slot-gpio MMC API, adding a host call-back for card detection events, has been proposed. This extension shall be used by the SDHCI driver to reset the host if the card is ejected during a running request. These patches add such a call-back.

Thanks
Guennadi

[1] http://thread.gmane.org/gmane.linux.kernel.mmc/17924/focus=17927

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#1 lore raw

PATCH 1/3 mmc: add a card-event host operation

Some hosts need to perform additional actions upon card insertion or ejection. Add a host operation to be called from card detection handlers.

---
 include/linux/mmc/host.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
include/linux/mmc/host.h +1 -0
index 7abb0e1..79ead24 100644
@@ -136,6 +136,7 @@ struct mmc_host_ops {
 	void	(*enable_preset_value)(struct mmc_host *host, bool enable);
 	int	(*select_drive_strength)(unsigned int max_dtr, int host_drv, int card_drv);
 	void	(*hw_reset)(struct mmc_host *host);
+	void	(*card_event)(struct mmc_host *host);
 };
 
 struct mmc_card;
Signature · 1 line
1.7.2.5
#2 lore raw

PATCH 2/3 mmc: extend the slot-gpio card-detection to use host's .card_event() method

In reply to Guennadi Liakhovetski

The slot-gpio API provides a generic card-detection handler. To support a wider range of hosts it has to call the host's card-event callback, if implemented. Also increase the debounce interval to 200ms to match the SDHCI driver.

---
 drivers/mmc/core/slot-gpio.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
drivers/mmc/core/slot-gpio.c +7 -1
index 08c6b3d..16a1c0b 100644
@@ -27,7 +27,13 @@ struct mmc_gpio {
 static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id)
 {
 	/* Schedule a card detection after a debounce timeout */
-	mmc_detect_change(dev_id, msecs_to_jiffies(100));
+	struct mmc_host *host = dev_id;
+
+	if (host->ops->card_event)
+		host->ops->card_event(host);
+
+	mmc_detect_change(host, msecs_to_jiffies(200));
+
 	return IRQ_HANDLED;
 }
 
Signature · 1 line
1.7.2.5
#3 lore raw

PATCH 3/3 mmc: sdhci: implement the .card_event() method

In reply to Guennadi Liakhovetski

Extracting a part of the SDHCI card tasklet into a .card_event() implementation allows SDHCI hosts to use generic card-detection services, e.g. the GPIO slot function.

---
 drivers/mmc/host/sdhci.c |   48 +++++++++++++++++++++++++--------------------
 1 files changed, 27 insertions(+), 21 deletions(-)
drivers/mmc/host/sdhci.c +27 -21
index c7851c0..2323553 100644
@@ -1994,30 +1994,11 @@ static void sdhci_enable_preset_value(struct mmc_host *mmc, bool enable)
 	sdhci_runtime_pm_put(host);
 }
 
-static const struct mmc_host_ops sdhci_ops = {
-	.request	= sdhci_request,
-	.set_ios	= sdhci_set_ios,
-	.get_ro		= sdhci_get_ro,
-	.hw_reset	= sdhci_hw_reset,
-	.enable_sdio_irq = sdhci_enable_sdio_irq,
-	.start_signal_voltage_switch	= sdhci_start_signal_voltage_switch,
-	.execute_tuning			= sdhci_execute_tuning,
-	.enable_preset_value		= sdhci_enable_preset_value,
-};
-
-/*****************************************************************************\
- *                                                                           *
- * Tasklets                                                                  *
- *                                                                           *
-\*****************************************************************************/
-
-static void sdhci_tasklet_card(unsigned long param)
+static void sdhci_card_event(struct mmc_host *mmc)
 {
-	struct sdhci_host *host;
+	struct sdhci_host *host = mmc_priv(mmc);
 	unsigned long flags;
 
-	host = (struct sdhci_host*)param;
-
 	spin_lock_irqsave(&host->lock, flags);
 
 	/* Check host->mrq first in case we are runtime suspended */
@@ -2036,6 +2017,31 @@ static void sdhci_tasklet_card(unsigned long param)
 	}
 
 	spin_unlock_irqrestore(&host->lock, flags);
+}
+
+static const struct mmc_host_ops sdhci_ops = {
+	.request	= sdhci_request,
+	.set_ios	= sdhci_set_ios,
+	.get_ro		= sdhci_get_ro,
+	.hw_reset	= sdhci_hw_reset,
+	.enable_sdio_irq = sdhci_enable_sdio_irq,
+	.start_signal_voltage_switch	= sdhci_start_signal_voltage_switch,
+	.execute_tuning			= sdhci_execute_tuning,
+	.enable_preset_value		= sdhci_enable_preset_value,
+	.card_event			= sdhci_card_event,
+};
+
+/*****************************************************************************\
+ *                                                                           *
+ * Tasklets                                                                  *
+ *                                                                           *
+\*****************************************************************************/
+
+static void sdhci_tasklet_card(unsigned long param)
+{
+	struct sdhci_host *host = (struct sdhci_host*)param;
+
+	sdhci_card_event(host->mmc);
 
 	mmc_detect_change(host->mmc, msecs_to_jiffies(200));
 }
Signature · 1 line
1.7.2.5
#4 lore raw

cover mmc: add a card-event host call-back

In reply to Guennadi Liakhovetski
Quoted 5 lines · Guennadi Liakhovetski

In a recent thread [1] an extension to the slot-gpio MMC API, adding a host call-back for card detection events, has been proposed. This extension shall be used by the SDHCI driver to reset the host if the card is ejected during a running request. These patches add such a call-back.

For the series,

#5 lore raw

cover mmc: add a card-event host call-back

Hi,

Quoted 9 lines · Shawn Guo
Quoted 5 lines · Guennadi Liakhovetski

In a recent thread [1] an extension to the slot-gpio MMC API, adding a host call-back for card detection events, has been proposed. This extension shall be used by the SDHCI driver to reset the host if the card is ejected during a running request. These patches add such a call-back.

For the series,

Thanks, pushed to mmc-next for 3.8.

- Chris.

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