All of lore.kernel.org
 help / color / mirror / Atom feed
From: Carlos Aguiar <carlos.aguiar@indt.org.br>
To: ext Pierre Ossman <drzeus-list@drzeus.cx>
Cc: Tony Lindgren <tony@atomide.com>, linux-kernel@vger.kernel.org
Subject: [PATCH 06/18] MMC: OMAP: Add back cover switch support
Date: Wed, 26 Mar 2008 16:09:08 -0400	[thread overview]
Message-ID: <47EAAD64.4020401@indt.org.br> (raw)
In-Reply-To: <20080324132631.1e0d2125@mjolnir.drzeus.cx>

From: Juha Yrjola <juha.yrjola@solidboot.com>

This patch adds back MMC cover switch support in a way that
supports multiple slots.

Signed-off-by: Juha Yrjola <juha.yrjola@solidboot.com>
Signed-off-by: Jarkko Lavinen <jarkko.lavinen@nokia.com>
Signed-off-by: Carlos Eduardo Aguiar <carlos.aguiar@indt.org.br>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/mmc/host/omap.c |   87 +++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 84 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
index 6b4f040..fc46a70 100644
--- a/drivers/mmc/host/omap.c
+++ b/drivers/mmc/host/omap.c
@@ -106,6 +106,10 @@ struct mmc_omap_slot {
 	unsigned int		fclk_freq;
 	unsigned		powered:1;
 
+	struct work_struct      switch_work;
+	struct timer_list       switch_timer;
+	unsigned		cover_open;
+
 	struct mmc_request      *mrq;
 	struct mmc_omap_host    *host;
 	struct mmc_host		*mmc;
@@ -226,6 +230,25 @@ static void mmc_omap_release_slot(struct mmc_omap_slot *slot)
 	spin_unlock_irqrestore(&host->slot_lock, flags);
 }
 
+static inline
+int mmc_omap_cover_is_open(struct mmc_omap_slot *slot)
+{
+	return slot->pdata->get_cover_state(mmc_dev(slot->mmc), slot->id);
+}
+
+static ssize_t
+mmc_omap_show_cover_switch(struct device *dev, struct device_attribute *attr,
+			   char *buf)
+{
+	struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev);
+	struct mmc_omap_slot *slot = mmc_priv(mmc);
+
+	return sprintf(buf, "%s\n", mmc_omap_cover_is_open(slot) ? "open" :
+		       "closed");
+}
+
+static DEVICE_ATTR(cover_switch, S_IRUGO, mmc_omap_show_cover_switch, NULL);
+
 static ssize_t
 mmc_omap_show_slot_name(struct device *dev, struct device_attribute *attr,
 			char *buf)
@@ -544,9 +567,10 @@ static irqreturn_t mmc_omap_irq(int irq, void *dev_id)
 			if (host->cmd) {
 				struct mmc_omap_slot *slot =
 					host->current_slot;
-				dev_err(mmc_dev(host->mmc),
-					"command timeout, CMD %d\n",
-					host->cmd->opcode);
+				if (!mmc_omap_cover_is_open(slot))
+					dev_err(mmc_dev(host->mmc),
+						"command timeout, CMD %d\n",
+						host->cmd->opcode);
 				host->cmd->error = -ETIMEDOUT;
 				end_command = 1;
 			}
@@ -592,6 +616,42 @@ static irqreturn_t mmc_omap_irq(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+void omap_mmc_notify_cover_event(struct device *dev, int slot, int is_closed)
+{
+	struct mmc_omap_host *host = dev_get_drvdata(dev);
+
+	BUG_ON(slot >= host->nr_slots);
+
+	/* Other subsystems can call in here before we're initialised. */
+	if (host->nr_slots == 0 || !host->slots[slot])
+		return;
+
+	schedule_work(&host->slots[slot]->switch_work);
+}
+
+static void mmc_omap_switch_timer(unsigned long arg)
+{
+	struct mmc_omap_slot *slot = (struct mmc_omap_slot *) arg;
+
+	schedule_work(&slot->switch_work);
+}
+
+static void mmc_omap_cover_handler(struct work_struct *work)
+{
+	struct mmc_omap_slot *slot = container_of(work, struct mmc_omap_slot,
+						  switch_work);
+	int cover_open;
+
+	cover_open = mmc_omap_cover_is_open(slot);
+	if (cover_open != slot->cover_open) {
+		sysfs_notify(&slot->mmc->class_dev.kobj, NULL, "cover_switch");
+		slot->cover_open = cover_open;
+		dev_info(mmc_dev(slot->mmc), "cover is now %s\n",
+			 cover_open ? "open" : "closed");
+	}
+	mmc_detect_change(slot->mmc, slot->id);
+}
+
 /* Prepare to transfer the next segment of a scatterlist */
 static void
 mmc_omap_prepare_dma(struct mmc_omap_host *host, struct mmc_data *data)
@@ -1062,8 +1122,24 @@ static int __init mmc_omap_new_slot(struct mmc_omap_host *host, int id)
 			goto err_remove_host;
 	}
 
+	if (slot->pdata->get_cover_state != NULL) {
+		r = device_create_file(&mmc->class_dev,
+					&dev_attr_cover_switch);
+		if (r < 0)
+			goto err_remove_slot_name;
+
+		INIT_WORK(&slot->switch_work, mmc_omap_cover_handler);
+		init_timer(&slot->switch_timer);
+		slot->switch_timer.function = mmc_omap_switch_timer;
+		slot->switch_timer.data = (unsigned long) slot;
+		schedule_work(&slot->switch_work);
+	}
+
 	return 0;
 
+err_remove_slot_name:
+	if (slot->pdata->name != NULL)
+		device_remove_file(&mmc->class_dev, &dev_attr_slot_name);
 err_remove_host:
 	mmc_remove_host(mmc);
 	mmc_free_host(mmc);
@@ -1076,6 +1152,11 @@ static void mmc_omap_remove_slot(struct mmc_omap_slot *slot)
 
 	if (slot->pdata->name != NULL)
 		device_remove_file(&mmc->class_dev, &dev_attr_slot_name);
+	if (slot->pdata->get_cover_state != NULL)
+		device_remove_file(&mmc->class_dev, &dev_attr_cover_switch);
+
+	del_timer_sync(&slot->switch_timer);
+	flush_scheduled_work();
 
 	mmc_remove_host(mmc);
 	mmc_free_host(mmc);
-- 1.5.3.GIT


  parent reply	other threads:[~2008-03-26 20:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-14 19:35 [PATCH 00/18] MMC: OMAP: Sync MMC OMAP driver with mainline tree Carlos Aguiar
2008-03-24 12:26 ` Pierre Ossman
2008-03-26 20:08   ` Carlos Aguiar
2008-03-30 16:10     ` Pierre Ossman
2008-03-26 20:08   ` [PATCH 01/18] MMC: OMAP: Remove some opcodes from host driver Carlos Aguiar
2008-03-26 20:08   ` [PATCH 02/18] MMC: OMAP: Remove extra divisor increase Carlos Aguiar
2008-03-26 20:08   ` [PATCH 03/18] MMC: OMAP: Fix the BYTEBLOCK capability removal Carlos Aguiar
2008-03-26 20:08   ` [PATCH 04/18] MMC: OMAP: Remove cover switch handling to allow adding multislot support Carlos Aguiar
2008-03-26 20:08   ` [PATCH 05/18] MMC: OMAP: Introduce new multislot structure and change driver to use it Carlos Aguiar
2008-03-26 20:09   ` Carlos Aguiar [this message]
2008-03-26 20:09   ` [PATCH 07/18] MMC: OMAP: New release dma and abort xfer functions Carlos Aguiar
2008-03-26 20:09   ` [PATCH 08/18] MMC: OMAP: Fix timeout calculation for MMC multislot support Carlos Aguiar
2008-03-26 20:09   ` [PATCH 09/18] MMC: OMAP: Power functions modified to " Carlos Aguiar
2008-03-26 20:09   ` [PATCH 10/18] MMC: OMAP: General cleanup for " Carlos Aguiar
2008-03-26 20:09   ` [PATCH 11/18] MMC: OMAP: Abort stuck commands Carlos Aguiar
2008-03-26 20:09   ` [PATCH 12/18] MMC: OMAP: Using setup_timer instead of init_timer Carlos Aguiar
2008-03-26 20:09   ` [PATCH 13/18] MMC: OMAP: Check the get_cover_state function pointer if not set Carlos Aguiar
2008-03-26 20:09   ` [PATCH 14/18] MMC: OMAP: Use tasklet instead of workqueue for cover switch notification Carlos Aguiar
2008-03-26 20:09   ` [PATCH 15/18] MMC: OMAP: Move failing command abortion to workqueue Carlos Aguiar
2008-03-26 20:09   ` [PATCH 16/18] MMC: OMAP: Lazy clock shutdown Carlos Aguiar
2008-03-26 20:09   ` [PATCH 17/18] MMC: OMAP: Start new commands from work queue instead of irq Carlos Aguiar
2008-03-26 20:10   ` [PATCH 18/18] MMC: OMAP: Do not busy wait for end of command for ever Carlos Aguiar
  -- strict thread matches above, loose matches on Subject: below --
2008-03-14 19:36 [PATCH 06/18] MMC: OMAP: Add back cover switch support Carlos Aguiar
2008-01-28 19:07 Carlos Aguiar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47EAAD64.4020401@indt.org.br \
    --to=carlos.aguiar@indt.org.br \
    --cc=drzeus-list@drzeus.cx \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tony@atomide.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.