Skip to contentSkip to conversation

MMC BUGFIX TRIVIAL STUFFS

PATCH In review Hiroshi DOYU 2 participants 6 messages Mar 8, 2006 – Mar 9, 2006 1 message not in the archive MMC, SD and SDIO

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/5 MMC BUGFIX TRIVIAL STUFFS

This includes small modifications as below.

- kmalloc() & memset(0) was replaced by kzalloc()
- bugfix for incorrect pointer argument

 drivers/mmc/mmc_sysfs.c |    4 +---
 drivers/mmc/omap.c      |    2 +-
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/mmc/mmc_sysfs.c +1 -3
Index: linux-omap/drivers/mmc/mmc_sysfs.c
===================================================================
@@ -262,10 +262,8 @@
 {
 	struct mmc_host *host;
 
-	host = kmalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL);
+	host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL);
 	if (host) {
-		memset(host, 0, sizeof(struct mmc_host) + extra);
-
 		host->dev = dev;
 		host->class_dev.dev = host->dev;
 		host->class_dev.class = &mmc_host_class;
drivers/mmc/omap.c +1 -1
Index: linux-omap/drivers/mmc/omap.c
===================================================================
@@ -1362,7 +1362,7 @@
 
 	if (omap_has_menelaus())
 		menelaus_mmc_register(mmc_omap_switch_callback,
-	  (unsigned long)&host);
+				      (unsigned long)host);
 
 no_switch:
 	return 0;

--

Hiroshi DOYU

#2 lore raw

PATCH 2/5 MMC MULTIPLE SLOT SUPPORT BASE

In reply to a message not in the archive

This modification handles multiple slots at the same time when an external transceiver(in case, Menelaus) is used.

MMC should handle multiple slots(bus) if an external transceiver is used. In that case, we have to take care of current working slot until RCA number is assigned to every cards in slots by host during card detection phase. Until RCA assignment is done(in card detection phase), when issuing the command, we choose a slot which we want to access(detect cards), and then after card detection, we can access any card by using RCA number and we do not have to choose slot number anymore. the concept of slot number is only needed in detection phase.

For choosing a slot for detection, new struct member "slot" is added in "struct mmc_omap_host". This struct can be seen only in omap layer("drivers/mmc/omap.c"), not by mmc common layer( "drivers/mmc/mmc.c"). mmc common layer does not know anything about slot concept. It can work because a real slot selecting work(for card detection) is just done by omap layer when issuing a mmc command(setting some value in register) indeed. This advantage is that we can use mmc common layer just as a library which is a collection of functions to meet just mmc specs without h/w information at all. There is not h/w specific stuffs in it, which means, there are some h/w specific datas, the number of slots, current working slot, interrupt event from cover switch, such kind of concept, mmc common layer need not to care about them at all. H/W specific work is just handled by omap layer transparently by setting slot number to detect by setting slot number in memeber "slot" of "struct mmc_omap_host".

 drivers/i2c/chips/menelaus.c         |   19 ++++++++++
 drivers/mmc/mmc.c                    |    4 +-
 drivers/mmc/omap.c                   |   63 ++++++++++++++++++++++++++++-------
 include/asm-arm/arch-omap/menelaus.h |    1 
 4 files changed, 73 insertions(+), 14 deletions(-)
drivers/i2c/chips/menelaus.c +18 -1
Index: linux-omap/drivers/i2c/chips/menelaus.c
===================================================================
@@ -254,6 +254,20 @@
 	return 0;
 }
 
+/* Enable slot selection */
+void menelaus_mmc_slot_selectable(int enable)
+{
+	int reg;
+	down(&menelaus.lock);
+	reg = menelaus_read(MENELAUS_GPIO_CTRL);
+	if (enable)
+		reg |= 0x22;  /* Set SLETSELEN and GPIO2 INPUT*/
+	else
+		reg &= ~0x22;
+	menelaus_write(reg, MENELAUS_GPIO_CTRL);
+	up(&menelaus.lock);
+}
+
 /* Initializes MMC slots */
 void menelaus_mmc_register(void (*callback)(unsigned long data, u8 card_mask), unsigned long data)
 {
@@ -265,7 +279,7 @@
 	menelaus_write(reg, MENELAUS_DCDC_CTRL1);
 
 	reg = menelaus_read(MENELAUS_DCDC_CTRL3);
-	reg |= 0x6;
+	reg = 0x3;
 	menelaus_write(reg, MENELAUS_DCDC_CTRL3);
 
 	/* Enable both slots, do not set auto shutdown */
@@ -288,6 +302,9 @@
 	reg |= 0x03;
 	menelaus_write(reg, MENELAUS_LDO_CTRL7);
 
+	/* set off slot selection at first */
+	menelaus_mmc_slot_selectable(0);
+
 	menelaus.mmc_callback_data = data;
 	menelaus.mmc_callback = callback;
 
drivers/mmc/mmc.c +3 -1
Index: linux-omap/drivers/mmc/mmc.c
===================================================================
@@ -285,6 +285,7 @@
 	remove_wait_queue(&host->wq, &wait);
 
 	if (card != (void *)-1) {
+		host->ops->set_ios(host, &host->ios);
 		err = mmc_select_card(host, card);
 		if (err != MMC_ERR_NONE)
 			return err;
@@ -1035,7 +1036,7 @@
 
 			err = mmc_send_op_cond(host, 0, &ocr);
 			if (err != MMC_ERR_NONE)
-				return;
+				goto out;
 		}
 
 		host->ocr = mmc_select_voltage(host, ocr);
@@ -1086,6 +1087,7 @@
 	/*
 	 * Ok, now switch to push-pull mode.
 	 */
+ out:
 	host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
 	host->ops->set_ios(host, &host->ios);
 
drivers/mmc/omap.c +51 -12

108 lines not on this page · raw message

include/asm-arm/arch-omap/menelaus.h +1 -0
Index: linux-omap/include/asm-arm/arch-omap/menelaus.h
===================================================================
@@ -11,6 +11,7 @@
 				  unsigned long data);
 extern void menelaus_mmc_remove(void);
 extern void menelaus_mmc_opendrain(int enable);
+extern void menelaus_mmc_slot_selectable(int enable);
 
 #if defined(CONFIG_ARCH_OMAP24XX) && defined(CONFIG_MENELAUS)
 #define omap_has_menelaus()	1

--

Hiroshi DOYU

#3 lore raw

PATCH 3/5 SD MULTIPLE SUPPORT

In reply to a message not in the archive

SD seems to use different RCA assignment mechanism from MMC. This introduces RCA bitmap to manage RCA number and assign adequate RCA number to SD cards.

 drivers/mmc/mmc.c        |   83 ++++++++++++++++++++++++++---------------------
 include/linux/mmc/card.h |    2 -
 2 files changed, 47 insertions(+), 38 deletions(-)
drivers/mmc/mmc.c +46 -37
Index: linux-omap/drivers/mmc/mmc.c
===================================================================
@@ -635,13 +635,12 @@
 }
 
 /*
- * Allocate a new MMC card, and assign a unique RCA.
+ * Allocate a new MMC card
  */
 static struct mmc_card *
-mmc_alloc_card(struct mmc_host *host, u32 *raw_cid, unsigned int *frca)
+mmc_alloc_card(struct mmc_host *host, u32 *raw_cid)
 {
-	struct mmc_card *card, *c;
-	unsigned int rca = *frca;
+	struct mmc_card *card;
 
 	card = kmalloc(sizeof(struct mmc_card), GFP_KERNEL);
 	if (!card)
@@ -650,17 +649,6 @@
 	mmc_init_card(card, host);
 	memcpy(card->raw_cid, raw_cid, sizeof(card->raw_cid));
 
- again:
-	list_for_each_entry(c, &host->cards, node)
-		if (c->rca == rca) {
-			rca++;
-			goto again;
-		}
-
-	card->rca = rca;
-
-	*frca = rca;
-
 	return card;
 }
 
@@ -796,10 +784,22 @@
  * Create a mmc_card entry for each discovered card, assigning
  * it an RCA, and save the raw CID for decoding later.
  */
-static void mmc_discover_cards(struct mmc_host *host)
+static int mmc_discover_cards(struct mmc_host *host)
 {
 	struct mmc_card *card;
-	unsigned int first_rca = 1, err;
+	unsigned int err;
+	unsigned long *rca_bitmap;
+	const unsigned int nbits = (1 << (sizeof(card->rca)*8))/8;
+
+	rca_bitmap = kzalloc(nbits, GFP_KERNEL);
+	if (!rca_bitmap)
+		return -ENOMEM;
+
+	set_bit(0, rca_bitmap); /* rca:0 reserved for deselect */
+
+	/* make bitmap for rca availability */
+	list_for_each_entry(card, &host->cards, node)
+		set_bit(card->rca, rca_bitmap);
 
 	while (1) {
 		struct mmc_command cmd;
@@ -821,7 +821,7 @@
 
 		card = mmc_find_card(host, cmd.resp);
 		if (!card) {
-			card = mmc_alloc_card(host, cmd.resp, &first_rca);
+			card = mmc_alloc_card(host, cmd.resp);
 			if (IS_ERR(card)) {
 				err = PTR_ERR(card);
 				break;
@@ -834,27 +834,31 @@
 		if (host->mode == MMC_MODE_SD) {
 			mmc_card_set_sd(card);
 
-			cmd.opcode = SD_SEND_RELATIVE_ADDR;
-			cmd.arg = 0;
-			cmd.flags = MMC_RSP_R6 | MMC_CMD_BCR;
-
-			err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES);
-			if (err != MMC_ERR_NONE)
-				mmc_card_set_dead(card);
-			else {
-				card->rca = cmd.resp[0] >> 16;
-
-				if (!host->ops->get_ro) {
-					printk(KERN_WARNING "%s: host does not "
-						"support reading read-only "
-						"switch. assuming write-enable.\n",
-						mmc_hostname(host));
-				} else {
-					if (host->ops->get_ro(host))
-						mmc_card_set_readonly(card);
+			do {
+				cmd.opcode = SD_SEND_RELATIVE_ADDR;
+				cmd.arg = 0;
+				cmd.flags = MMC_RSP_R6 | MMC_CMD_BCR;
+
+				err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES);
+				if (err != MMC_ERR_NONE)
+					mmc_card_set_dead(card);
+				else {
+					card->rca = cmd.resp[0] >> 16;
+
+					if (!host->ops->get_ro) {
+						printk(KERN_WARNING "%s: host does not "
+						       "support reading read-only "
+						       "switch. assuming write-enable.\n",
+						       mmc_hostname(host));
+					} else {
+						if (host->ops->get_ro(host))
+							mmc_card_set_readonly(card);
+					}
 				}
-			}
+			} while (test_bit(card->rca, rca_bitmap));
 		} else {
+			card->rca = find_first_zero_bit(rca_bitmap, nbits);
+
 			cmd.opcode = MMC_SET_RELATIVE_ADDR;
 			cmd.arg = card->rca << 16;
 			cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
@@ -863,7 +867,12 @@
 			if (err != MMC_ERR_NONE)
 				mmc_card_set_dead(card);
 		}
+
+		set_bit(card->rca, rca_bitmap);
 	}
+
+	kfree(rca_bitmap);
+	return 0;
 }
 
 static void mmc_read_csds(struct mmc_host *host)
include/linux/mmc/card.h +1 -1
Index: linux-omap/include/linux/mmc/card.h
===================================================================
@@ -54,7 +54,7 @@
 	struct list_head	node;		/* node in hosts devices list */
 	struct mmc_host		*host;		/* the host this device belongs to */
 	struct device		dev;		/* the device */
-	unsigned int		rca;		/* relative card address of device */
+	unsigned short		rca;		/* relative card address of device */
 	unsigned int		state;		/* (our) card state */
 #define MMC_STATE_PRESENT	(1<<0)		/* present in sysfs */
 #define MMC_STATE_DEAD		(1<<1)		/* device no longer in stack */

--

Hiroshi DOYU

#4 lore raw

PATCH 4/5 MMC HOTSWAP SUPPORT

In reply to a message not in the archive

This modification can handle MMC/SD cards hotplug.

"Cover switch interrupt" and "polling slots" mechanism can be used in order to manage MMC/SD cards hotplug.

 drivers/mmc/omap.c |  118 +++++++++++++++++++++++++++++------------------------
 1 files changed, 65 insertions(+), 53 deletions(-)
drivers/mmc/omap.c +65 -53
Index: linux-omap/drivers/mmc/omap.c
===================================================================
@@ -61,8 +61,6 @@
  * when the cover switch is open */
 #define OMAP_MMC_SWITCH_POLL_DELAY	500
 
-static int mmc_omap_enable_poll = 1;
-
 struct mmc_omap_host {
 	int			initialized;
 	int			suspended;
@@ -106,6 +104,8 @@
 	struct work_struct	switch_work;
 	struct timer_list	switch_timer;
 	int			switch_last_state;
+
+	int                     enable_poll;
 };
 
 static inline void mmc_omap_enable_slot(struct mmc_omap_host *host)
@@ -142,9 +142,10 @@
 static inline int
 mmc_omap_cover_is_open(struct mmc_omap_host *host)
 {
-	if (host->switch_pin < 0)
-		return 0;
-	return omap_get_gpio_datain(host->switch_pin);
+	if (host->switch_pin >= 0)
+		return omap_get_gpio_datain(host->switch_pin);
+
+	return host->switch_last_state;
 }
 
 static ssize_t
@@ -162,7 +163,8 @@
 mmc_omap_show_enable_poll(struct device *dev,
 	struct device_attribute *attr, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%d\n", mmc_omap_enable_poll);
+	struct mmc_omap_host *host = dev_get_drvdata(dev);
+	return snprintf(buf, PAGE_SIZE, "%d\n", host->enable_poll);
 }
 
 static ssize_t
@@ -171,15 +173,14 @@
 	size_t size)
 {
 	int enable_poll;
+	struct mmc_omap_host *host = dev_get_drvdata(dev);
 
 	if (sscanf(buf, "%10d", &enable_poll) != 1)
 		return -EINVAL;
 
-	if (enable_poll != mmc_omap_enable_poll) {
-		struct mmc_omap_host *host = dev_get_drvdata(dev);
-
-		mmc_omap_enable_poll = enable_poll;
-		if (enable_poll && host->switch_pin >= 0)
+	if (enable_poll != host->enable_poll) {
+		host->enable_poll = enable_poll;
+		if (enable_poll)
 			schedule_work(&host->switch_work);
 	}
 	return size;
@@ -694,6 +695,8 @@
  * for MMC state? */
 static void mmc_omap_switch_callback(unsigned long data, u8 mmc_mask)
 {
+	struct mmc_omap_host *host = (struct mmc_omap_host *) data;
+
 	if (machine_is_omap_h4()) {
 		if (mmc_mask & 0x1)
 			printk("XXX card in slot 1\n");
@@ -701,11 +704,12 @@
 			printk("XXX card in slot 2\n");
 	} else {
 		/* Assume card detect connected to cover switch */
-		if (mmc_mask & 0x2)
-			printk("XXX cover open\n");
-		else
-			printk("XXX cover closed\n");
+		host->switch_last_state = (mmc_mask & 0x2) ? 1 : 0;
+		DBG("MMC%d cover is now %s\n", host->id,
+		    host->switch_last_state ? "open" : "closed");
 	}
+
+	schedule_work(&host->switch_work);
 }
 
 static void mmc_omap_switch_handler(void *data)
@@ -715,16 +719,21 @@
 	static int complained = 0;
 	int cards = 0, cover_open;
 
-	if (host->switch_pin == -1)
-		return;
-	set_irq_type(OMAP_GPIO_IRQ(host->switch_pin), IRQT_RISING | IRQT_FALLING);
+	if (host->switch_pin >= 0)
+		set_irq_type(OMAP_GPIO_IRQ(host->switch_pin), IRQT_RISING | IRQT_FALLING);
 	cover_open = mmc_omap_cover_is_open(host);
 	if (cover_open != host->switch_last_state) {
 		kobject_uevent(&host->dev->kobj, KOBJ_CHANGE);
 		host->switch_last_state = cover_open;
 	}
 	DBG("MMC cover switch handler started\n");
-	mmc_detect_change(host->mmc, 0);
+
+	host->slot = 0;
+	do {
+ 		mmc_detect_change(host->mmc, 0);
+ 		flush_scheduled_work();
+	} while (++host->slot < host->slots);
+
 	list_for_each_entry(card, &host->mmc->cards, node) {
 		if (mmc_card_present(card))
 			cards++;
@@ -735,7 +744,7 @@
 			printk(KERN_INFO "MMC%d: cover is open\n", host->id);
 			complained = 1;
 		}
-		if (cover_open && (cards || mmc_omap_enable_poll))
+		if (cover_open && (cards || host->enable_poll))
 			mod_timer(&host->switch_timer, jiffies +
 				  msecs_to_jiffies(OMAP_MMC_SWITCH_POLL_DELAY));
 	} else {
@@ -1356,16 +1365,21 @@
 		flush_scheduled_work();
 	} 
 
-	if (host->switch_pin >= 0) {
-		INIT_WORK(&host->switch_work, mmc_omap_switch_handler, host);
-		init_timer(&host->switch_timer);
-		host->switch_timer.function = mmc_omap_switch_timer;
-		host->switch_timer.data = (unsigned long) host;
+	INIT_WORK(&host->switch_work, mmc_omap_switch_handler, host);
+
+	init_timer(&host->switch_timer);
+	host->switch_timer.function = mmc_omap_switch_timer;
+	host->switch_timer.data = (unsigned long) host;
+
+	if (omap_has_menelaus())
+		menelaus_mmc_register(mmc_omap_switch_callback,
+				      (unsigned long)host);
+	else if (host->switch_pin >= 0) {
 		if (omap_request_gpio(host->switch_pin) != 0) {
 			printk(KERN_WARNING "MMC%d: Unable to get GPIO pin for MMC cover switch\n",
 			       host->id);
 			host->switch_pin = -1;
-			goto no_switch;
+			return 0;
 		}
 
 		omap_set_gpio_direction(host->switch_pin, 1);
@@ -1378,34 +1392,30 @@
 			       host->id);
 			omap_free_gpio(host->switch_pin);
 			host->switch_pin = -1;
-			goto no_switch;
-		}
-		ret = device_create_file(&pdev->dev, &dev_attr_cover_switch);
-		if (ret == 0) {
-			ret = device_create_file(&pdev->dev, &dev_attr_enable_poll);
-			if (ret != 0)
-				device_remove_file(&pdev->dev, &dev_attr_cover_switch);
-		}
-		if (ret) {
-			printk(KERN_WARNING "MMC%d: Unable to create sysfs attributes\n", 
-			       host->id);
-			free_irq(OMAP_GPIO_IRQ(host->switch_pin), host);
-			omap_free_gpio(host->switch_pin);
-			host->switch_pin = -1;
-			goto no_switch;
+			return 0;
 		}
-		host->switch_last_state = mmc_omap_cover_is_open(host);
-		if (mmc_omap_enable_poll && mmc_omap_cover_is_open(host))
-			schedule_work(&host->switch_work);
+	} else
+		host->enable_poll = host->switch_last_state = 1;
+
+	ret = device_create_file(&pdev->dev, &dev_attr_cover_switch);
+	if (ret == 0) {
+		ret = device_create_file(&pdev->dev, &dev_attr_enable_poll);
+		if (ret != 0)
+			device_remove_file(&pdev->dev, &dev_attr_cover_switch);
+	}
+	if (ret) {
+		printk(KERN_WARNING "MMC%d: Unable to create sysfs attributes\n",
+		       host->id);
+		free_irq(OMAP_GPIO_IRQ(host->switch_pin), host);
+		omap_free_gpio(host->switch_pin);
+		host->switch_pin = -1;
 	}
 
-	if (omap_has_menelaus())
-		menelaus_mmc_register(mmc_omap_switch_callback,
-				      (unsigned long)host);
+	host->switch_last_state = mmc_omap_cover_is_open(host);
+	if (host->enable_poll && mmc_omap_cover_is_open(host))
+		schedule_work(&host->switch_work);
 
-no_switch:
 	return 0;
-
 out:
 	/* FIXME: Free other resources too. */
 	if (host) {
@@ -1432,14 +1442,16 @@
 		if (host->power_pin >= 0)
 			omap_free_gpio(host->power_pin);
 		if (host->switch_pin >= 0) {
-			device_remove_file(&pdev->dev, &dev_attr_enable_poll);
-			device_remove_file(&pdev->dev, &dev_attr_cover_switch);
 			free_irq(OMAP_GPIO_IRQ(host->switch_pin), host);
 			omap_free_gpio(host->switch_pin);
 			host->switch_pin = -1;
-			del_timer_sync(&host->switch_timer);
-			flush_scheduled_work();
 		}
+
+		device_remove_file(&pdev->dev, &dev_attr_enable_poll);
+		device_remove_file(&pdev->dev, &dev_attr_cover_switch);
+		del_timer_sync(&host->switch_timer);
+		flush_scheduled_work();
+
 		if (host->iclk && !IS_ERR(host->iclk))
 			clk_put(host->iclk);
 		if (host->fclk && !IS_ERR(host->fclk))

--

Hiroshi DOYU

#5 lore raw

PATCH 5/5 MMC OMAP DBG CLEANUP

In reply to a message not in the archive

convert DBG() to pr_debug

 drivers/mmc/omap.c |   33 ++++++++++-----------------------
 1 files changed, 10 insertions(+), 23 deletions(-)
drivers/mmc/omap.c +10 -23
Index: linux-omap/drivers/mmc/omap.c
===================================================================
@@ -12,12 +12,6 @@
  */
 
 #include <linux/config.h>
-
-// #define CONFIG_MMC_DEBUG
-#ifdef CONFIG_MMC_DEBUG
-#define DEBUG	/* for dev_dbg(), pr_debug(), etc */
-#endif
-
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/init.h>
@@ -50,13 +44,6 @@
 
 #define DRIVER_NAME "mmci-omap"
 
-#ifdef CONFIG_MMC_DEBUG
-#define DBG(x...)	pr_debug(x)
-//#define DBG(x...)	printk(x)
-#else
-#define DBG(x...)	do { } while (0)
-#endif
-
 /* Specifies how often in millisecs to poll for card status changes
  * when the cover switch is open */
 #define OMAP_MMC_SWITCH_POLL_DELAY	500
@@ -342,7 +329,7 @@
 {
 	struct mmc_omap_host *host = (struct mmc_omap_host *) data;
 
-	DBG("MMC%d: Freeing DMA channel %d\n", host->id, host->dma_ch);
+	pr_debug("MMC%d: Freeing DMA channel %d\n", host->id, host->dma_ch);
 	BUG_ON(host->dma_ch < 0);
 	omap_free_dma(host->dma_ch);
 	host->dma_ch = -1;
@@ -384,7 +371,7 @@
 		cmd->resp[0] =
 			OMAP_MMC_READ(host->base, RSP6) |
 			(OMAP_MMC_READ(host->base, RSP7) << 16);
-		DBG("MMC%d: Response %08x %08x %08x %08x\n", host->id,
+		pr_debug("MMC%d: Response %08x %08x %08x %08x\n", host->id,
 		    cmd->resp[0], cmd->resp[1],
 		    cmd->resp[2], cmd->resp[3]);
 	} else {
@@ -392,7 +379,7 @@
 		cmd->resp[0] =
 			OMAP_MMC_READ(host->base, RSP6) |
 			(OMAP_MMC_READ(host->base, RSP7) << 16);
-		DBG("MMC%d: Response %08x\n", host->id, cmd->resp[0]);
+		pr_debug("MMC%d: Response %08x\n", host->id, cmd->resp[0]);
 		if (card_ready) {
 			pr_debug("MMC%d: Faking card ready based on EOFB\n", host->id);
 			cmd->resp[0] |= R1_READY_FOR_DATA;
@@ -400,7 +387,7 @@
 	}
 
 	if (host->data == NULL || cmd->error != MMC_ERR_NONE) {
-		DBG("MMC%d: End request, err %x\n", host->id, cmd->error);
+		pr_debug("MMC%d: End request, err %x\n", host->id, cmd->error);
 		if (host->data != NULL)
 			del_timer_sync(&host->xfer_timer);
  		host->mrq = NULL;
@@ -587,7 +574,7 @@
 			/* OCR Busy ... happens a lot */
 			if (host->cmd && host->cmd->opcode != MMC_SEND_OP_COND
 				&& host->cmd->opcode != MMC_SET_RELATIVE_ADDR) {
-				DBG("MMC%d: OCR busy error, CMD%d\n",
+				pr_debug("MMC%d: OCR busy error, CMD%d\n",
 				       host->id, host->cmd->opcode);
 			}
 		}
@@ -656,7 +643,7 @@
 	int cover_open, detect_now;
 
 	cover_open = mmc_omap_cover_is_open(host);
-	DBG("MMC%d cover is now %s\n", host->id,
+	pr_debug("MMC%d cover is now %s\n", host->id,
 	    cover_open ? "open" : "closed");
 	set_irq_type(OMAP_GPIO_IRQ(host->switch_pin), 0);
 	detect_now = 0;
@@ -705,7 +692,7 @@
 	} else {
 		/* Assume card detect connected to cover switch */
 		host->switch_last_state = (mmc_mask & 0x2) ? 1 : 0;
-		DBG("MMC%d cover is now %s\n", host->id,
+		pr_debug("MMC%d cover is now %s\n", host->id,
 		    host->switch_last_state ? "open" : "closed");
 	}
 
@@ -726,7 +713,7 @@
 		kobject_uevent(&host->dev->kobj, KOBJ_CHANGE);
 		host->switch_last_state = cover_open;
 	}
-	DBG("MMC cover switch handler started\n");
+	pr_debug("MMC cover switch handler started\n");
 
 	host->slot = 0;
 	do {
@@ -738,7 +725,7 @@
 		if (mmc_card_present(card))
 			cards++;
 	}
-	DBG("MMC%d: %d card(s) present\n", host->id, cards);
+	pr_debug("MMC%d: %d card(s) present\n", host->id, cards);
 	if (cover_open) {
 		if (!complained) {
 			printk(KERN_INFO "MMC%d: cover is open\n", host->id);
@@ -1169,7 +1156,7 @@
 	int dsor;
 	int realclock, i;
 
-	DBG("MMC%d: set_ios: clock %dHz busmode %d powermode %d Vdd %d.%02d\n",
+	pr_debug("MMC%d: set_ios: clock %dHz busmode %d powermode %d Vdd %d.%02d\n",
 	    host->id, ios->clock, ios->bus_mode, ios->power_mode,
 	    ios->vdd / 100, ios->vdd % 100);
 

--

Hiroshi DOYU

#6 lore raw

Re: [patch 5/5] MMC OMAP DBG CLEANUP

Hi folks,

Find below my propose of debug cleanup in omap.c. I'm working now in a merging
of omap.c into mainline kernel (http://marc.theaimsgroup.com/?l=linux-kernel&m=114176508216915&w=2).

Following the Russell King's suggestion, there's no need to print host->id - mmc_dev(host->mmc) will print the platform device bus_id, which is generated from the platform device name and the platform device id. This change was applied for dev_err, dev_dbg, dev_warn and dev_info.

All suggestions and comments are welcome!

BR,

Carlos.

Signature · 7 lines
Carlos Eduardo
Software Engineer
Nokia Institute of Technology - INdT
Embedded Linux Laboratory - 10LE
Phone: +55 92 2126-1079
Mobile: +55 92 8127-1797
E-mail: [email protected]
drivers/mmc/omap.c +49 -71
Index: linux-omap-2.6.git/drivers/mmc/omap.c
===================================================================
@@ -50,13 +50,6 @@
 
 #define DRIVER_NAME "mmci-omap"
 
-#ifdef CONFIG_MMC_DEBUG
-#define DBG(x...)	pr_debug(x)
-//#define DBG(x...)	printk(x)
-#else
-#define DBG(x...)	do { } while (0)
-#endif
-
 /* Specifies how often in millisecs to poll for card status changes
  * when the cover switch is open */
 #define OMAP_MMC_SWITCH_POLL_DELAY	500
@@ -160,13 +153,6 @@ mmc_omap_start_command(struct mmc_omap_h
 	u32 resptype;
 	u32 cmdtype;
 
-	pr_debug("MMC%d: CMD%d, argument 0x%08x%s%s%s%s\n",
-		host->id, cmd->opcode, cmd->arg,
-		(cmd->flags & MMC_RSP_SHORT) ?  ", 32-bit response" : "",
-		(cmd->flags & MMC_RSP_LONG) ?  ", 128-bit response" : "",
-		(cmd->flags & MMC_RSP_CRC) ?  ", CRC" : "",
-		(cmd->flags & MMC_RSP_BUSY) ?  ", busy notification" : "");
-
 	host->cmd = cmd;
 
 	resptype = 0;
@@ -309,7 +295,7 @@ mmc_omap_dma_timer(unsigned long data)
 {
 	struct mmc_omap_host *host = (struct mmc_omap_host *) data;
 
-	DBG("MMC%d: Freeing DMA channel %d\n", host->id, host->dma_ch);
+	dev_dbg(mmc_dev(host->mmc), "Freeing DMA channel %d\n", host->dma_ch);
 	BUG_ON(host->dma_ch < 0);
 	omap_free_dma(host->dma_ch);
 	host->dma_ch = -1;
@@ -351,7 +337,7 @@ mmc_omap_cmd_done(struct mmc_omap_host *
 		cmd->resp[0] =
 			OMAP_MMC_READ(host->base, RSP6) |
 			(OMAP_MMC_READ(host->base, RSP7) << 16);
-		DBG("MMC%d: Response %08x %08x %08x %08x\n", host->id,
+		dev_dbg(mmc_dev(host->mmc), "Response %08x %08x %08x %08x\n",
 		    cmd->resp[0], cmd->resp[1],
 		    cmd->resp[2], cmd->resp[3]);
 	} else {
@@ -359,15 +345,15 @@ mmc_omap_cmd_done(struct mmc_omap_host *
 		cmd->resp[0] =
 			OMAP_MMC_READ(host->base, RSP6) |
 			(OMAP_MMC_READ(host->base, RSP7) << 16);
-		DBG("MMC%d: Response %08x\n", host->id, cmd->resp[0]);
+		dev_dbg(mmc_dev(host->mmc), "Response %08x\n", cmd->resp[0]);
 		if (card_ready) {
-			pr_debug("MMC%d: Faking card ready based on EOFB\n", host->id);
+			dev_dbg(mmc_dev(host->mmc), "Faking card ready based on EOFB\n");
 			cmd->resp[0] |= R1_READY_FOR_DATA;
 		}
 	}
 
 	if (host->data == NULL || cmd->error != MMC_ERR_NONE) {
-		DBG("MMC%d: End request, err %x\n", host->id, cmd->error);
+		dev_dbg(mmc_dev(host->mmc), "End request, err %x\n", cmd->error);
 		if (host->data != NULL)
 			del_timer_sync(&host->xfer_timer);
  		host->mrq = NULL;
@@ -381,7 +367,7 @@ mmc_omap_xfer_timeout(unsigned long data
 {
 	struct mmc_omap_host *host = (struct mmc_omap_host *) data;
 
-	printk(KERN_ERR "MMC%d: Data xfer timeout\n", host->id);
+	dev_err(mmc_dev(host->mmc), "Data xfer timeout\n");
 	if (host->data != NULL) {
 		host->data->error |= MMC_ERR_TIMEOUT;
 		/* Perform a pseudo-reset of the MMC core logic, since
@@ -468,7 +454,7 @@ static irqreturn_t mmc_omap_irq(int irq,
 
 	if (host->cmd == NULL && host->data == NULL) {
 		status = OMAP_MMC_READ(host->base, STAT);
-		printk(KERN_INFO "MMC%d: Spurious interrupt 0x%04x\n", host->id, status);
+		dev_info(mmc_dev(host->mmc), "spurious irq 0x%04x\n", status);
 		if (status != 0) {
 			OMAP_MMC_WRITE(host->base, STAT, status);
 			OMAP_MMC_WRITE(host->base, IE, 0);
@@ -484,8 +470,8 @@ static irqreturn_t mmc_omap_irq(int irq,
 	while ((status = OMAP_MMC_READ(host->base, STAT)) != 0) {
 		OMAP_MMC_WRITE(host->base, STAT, status); // Reset status bits
 #ifdef CONFIG_MMC_DEBUG
-		printk(KERN_DEBUG "\tMMC IRQ %04x (CMD %d): ", status,
-		       host->cmd != NULL ? host->cmd->opcode : -1);
+		dev_dbg(mmc_dev(host->mmc), "MMC IRQ %04x (CMD %d): ",
+			status, host->cmd != NULL ? host->cmd->opcode : -1);
 		mmc_omap_report_irq(status);
 		printk("\n");
 #endif
@@ -504,7 +490,7 @@ static irqreturn_t mmc_omap_irq(int irq,
 
 		if (status & OMAP_MMC_STAT_DATA_TOUT) {
 			// Data timeout
-			printk(KERN_DEBUG "MMC%d: Data timeout\n", host->id);
+			dev_dbg(mmc_dev(host->mmc), "data timeout\n");
 			if (host->data) {
 				host->data->error |= MMC_ERR_TIMEOUT;
 				transfer_error = 1;
@@ -515,12 +501,12 @@ static irqreturn_t mmc_omap_irq(int irq,
 			// Data CRC error
 			if (host->data) {
 				host->data->error |= MMC_ERR_BADCRC;
-				printk(KERN_DEBUG "MMC%d: Data CRC error, bytes left %d\n",
-				       host->id, host->total_bytes_left);
+				dev_dbg(mmc_dev(host->mmc),
+					 "data CRC error, bytes left %d\n",
+					host->total_bytes_left);
 				transfer_error = 1;
 			} else {
-				printk(KERN_DEBUG "MMC%d: Data CRC error\n",
-				       host->id);
+				dev_dbg(mmc_dev(host->mmc), "data CRC error\n");
 			}
 		}
 
@@ -528,11 +514,14 @@ static irqreturn_t mmc_omap_irq(int irq,
 			/* Timeouts are routine with some commands */
 			if (host->cmd) {
 				if (host->cmd->opcode != MMC_ALL_SEND_CID &&
-				    host->cmd->opcode != MMC_SEND_OP_COND &&
-				    host->cmd->opcode != MMC_APP_CMD &&
-				    !mmc_omap_cover_is_open(host))
-					printk(KERN_ERR "MMC%d: Command timeout, CMD%d\n",
-					       host->id, host->cmd->opcode);
+						host->cmd->opcode !=
+						MMC_SEND_OP_COND &&
+						host->cmd->opcode !=
+						MMC_APP_CMD &&
+						!mmc_omap_cover_is_open(host))
+					dev_err(mmc_dev(host->mmc),
+						"command timeout, CMD %d\n",
+						host->cmd->opcode);
 				host->cmd->error |= MMC_ERR_TIMEOUT;
 				end_command = 1;
 			}
@@ -541,21 +530,21 @@ static irqreturn_t mmc_omap_irq(int irq,
 		if (status & OMAP_MMC_STAT_CMD_CRC) {
 			// Command CRC error
 			if (host->cmd) {
-				printk(KERN_ERR "MMC%d: Command CRC error (CMD%d, arg 0x%08x)\n",
-				       host->id, host->cmd->opcode,
-				       host->cmd->arg);
+				dev_err(mmc_dev(host->mmc),
+					"command CRC error (CMD%d, arg 0x%08x)\n",
+					host->cmd->opcode, host->cmd->arg);
 				host->cmd->error |= MMC_ERR_BADCRC;
 				end_command = 1;
 			} else
-				printk(KERN_ERR "MMC%d: Command CRC error without cmd?\n", host->id);
+				dev_err(mmc_dev(host->mmc),
+					"command CRC error without cmd?\n");
 		}
 
 		if (status & OMAP_MMC_STAT_OCR_BUSY) {
 			/* OCR Busy ... happens a lot */
 			if (host->cmd && host->cmd->opcode != MMC_SEND_OP_COND
 				&& host->cmd->opcode != MMC_SET_RELATIVE_ADDR) {
-				DBG("MMC%d: OCR busy error, CMD%d\n",
-				       host->id, host->cmd->opcode);
+				dev_dbg(mmc_dev(host->mmc), "OCR busy error, CMD%d\n", host->cmd->opcode);
 			}
 		}
 
@@ -573,8 +562,8 @@ static irqreturn_t mmc_omap_irq(int irq,
 			}
 
 			// Card status error
-			printk(KERN_DEBUG "MMC%d: Card status error (CMD%d)\n",
-			       host->id, host->cmd->opcode);
+			dev_dbg(mmc_dev(host->mmc), "card status error (CMD%d)\n",
+				host->cmd->opcode);
 			if (host->cmd) {
 				host->cmd->error |= MMC_ERR_FAILED;
 				end_command = 1;
@@ -623,8 +612,7 @@ static irqreturn_t mmc_omap_switch_irq(i
 	int cover_open, detect_now;
 
 	cover_open = mmc_omap_cover_is_open(host);
-	DBG("MMC%d cover is now %s\n", host->id,
-	    cover_open ? "open" : "closed");
+	dev_dbg(mmc_dev(host->mmc), "cover is now %s\n", cover_open ? "open" : "closed");
 	set_irq_type(OMAP_GPIO_IRQ(host->switch_pin), 0);
 	detect_now = 0;
 	if (host->switch_last_state != cover_open) {
@@ -691,16 +679,16 @@ static void mmc_omap_switch_handler(void
 		kobject_uevent(&host->dev->kobj, KOBJ_CHANGE);
 		host->switch_last_state = cover_open;
 	}
-	DBG("MMC cover switch handler started\n");
+	dev_dbg(mmc_dev(host->mmc), "MMC cover switch handler started\n");
 	mmc_detect_change(host->mmc, 0);
 	list_for_each_entry(card, &host->mmc->cards, node) {
 		if (mmc_card_present(card))
 			cards++;
 	}
-	DBG("MMC%d: %d card(s) present\n", host->id, cards);
+	dev_dbg(mmc_dev(host->mmc), "%d card(s) present\n", cards);
 	if (cover_open) {
 		if (!complained) {
-			printk(KERN_INFO "MMC%d: cover is open\n", host->id);
+			dev_info(mmc_dev(host->mmc), "cover is open");
 			complained = 1;
 		}
 		if (cover_open && (cards || mmc_omap_enable_poll))
@@ -802,17 +790,16 @@ static void mmc_omap_dma_cb(int lch, u16
 	struct mmc_data *mmcdat = host->data;
 
 	if (unlikely(host->dma_ch < 0)) {
-		printk(KERN_ERR "MMC%d: DMA callback while DMA not enabled\n",
-		       host->id);
+		dev_err(mmc_dev(host->mmc), "DMA callback while DMA not enabled\n");
 		return;
 	}
 	/* FIXME: We really should do something to _handle_ the errors */
 	if (ch_status & OMAP_DMA_TOUT_IRQ) {
-		printk(KERN_ERR "MMC%d: DMA timeout\n", host->id);
+		dev_err(mmc_dev(host->mmc), "DMA timeout\n");
 		return;
 	}
 	if (ch_status & OMAP_DMA_DROP_IRQ) {
-		printk(KERN_ERR "MMC%d: DMA sync error\n", host->id);
+		dev_err(mmc_dev(host->mmc), "DMA sync error\n");
 		return;
 	}
 	if (!(ch_status & OMAP_DMA_BLOCK_IRQ)) {
@@ -820,16 +807,13 @@ static void mmc_omap_dma_cb(int lch, u16
 		 * just SYNC status ...
 		 */
 		if ((ch_status & ~OMAP1_DMA_SYNC_IRQ))
-			pr_debug("MMC%d: DMA channel status: %04x\n",
-			       host->id, ch_status);
+			dev_dbg(mmc_dev(host->mmc), "DMA channel status: %04x\n", ch_status);
 		return;
 	}
 	mmcdat->bytes_xfered += host->dma_len;
 
-	pr_debug("\tMMC DMA %d bytes CB %04x (%d segments to go), %p\n",
-		host->dma_len, ch_status,
+	dev_dbg(mmc_dev(host->mmc), "DMA %d bytes CB %04x (%d segments to go), %p\n", host->dma_len, ch_status,
 		host->sg_len - host->sg_idx - 1, host->data);
-
 	host->sg_idx++;
 	if (host->sg_idx < host->sg_len) {
 		mmc_omap_prepare_dma(host, host->data);
@@ -872,8 +856,7 @@ static int mmc_omap_get_dma_channel(stru
 	r = omap_request_dma(sync_dev, dev_name, mmc_omap_dma_cb,
 			     host, &dma_ch);
 	if (r != 0) {
-		printk("MMC%d: omap_request_dma() failed with %d\n",
-		       host->id, r);
+		dev_dbg(mmc_dev(host->mmc), "omap_request_dma() failed with %d\n", r);
 		return r;
 	}
 	host->dma_ch = dma_ch;
@@ -1049,13 +1032,12 @@ static void mmc_omap_request(struct mmc_
 			static int complained = 0;
 
 			if (!complained) {
-				printk(KERN_WARNING "MMC%d: Broken card workaround enabled\n",
-				       host->id);
+				dev_warn(mmc_dev(host->mmc), "Broken card workaround enabled\n");
 				complained = 1;
 			}
 			if (in_interrupt()) {
 				/* This is nasty */
-				 printk(KERN_ERR "Sleeping in IRQ handler, FIXME please!\n");
+				dev_err(mmc_dev(host->mmc), "Sleeping in IRQ handler, FIXME please!\n");
 				 dump_stack();
 				 mdelay(100);
 			} else {
@@ -1128,8 +1110,8 @@ static void mmc_omap_set_ios(struct mmc_
 	int dsor;
 	int realclock, i;
 
-	DBG("MMC%d: set_ios: clock %dHz busmode %d powermode %d Vdd %d.%02d\n",
-	    host->id, ios->clock, ios->bus_mode, ios->power_mode,
+	dev_dbg(mmc_dev(host->mmc), "set_ios: clock %dHz busmode %d powermode %d Vdd %d.%02d\n",
+	    ios->clock, ios->bus_mode, ios->power_mode,
 	    ios->vdd / 100, ios->vdd % 100);
 
 	if (ios->power_mode == MMC_POWER_UP && ios->clock < 400000)
@@ -1221,7 +1203,7 @@ static int __init mmc_omap_probe(struct 
 
 	if (pdev->resource[0].flags != IORESOURCE_MEM
 	    || pdev->resource[1].flags != IORESOURCE_IRQ) {
-		printk(KERN_ERR "mmc_omap_probe: invalid resource type\n");
+		dev_err(&pdev->dev, "mmc_omap_probe: invalid resource type\n");
 		return -ENODEV;
 	}
 
@@ -1301,8 +1283,7 @@ static int __init mmc_omap_probe(struct 
 
 	if (host->power_pin >= 0) {
 		if ((ret = omap_request_gpio(host->power_pin)) != 0) {
-			printk(KERN_ERR "MMC%d: Unable to get GPIO pin for MMC power\n",
-			       host->id);
+			dev_err(mmc_dev(host->mmc), "Unable to get GPIO pin for MMC power\n");
 			goto out;
 		}
 		omap_set_gpio_direction(host->power_pin, 0);
@@ -1323,8 +1304,7 @@ static int __init mmc_omap_probe(struct 
 		host->switch_timer.function = mmc_omap_switch_timer;
 		host->switch_timer.data = (unsigned long) host;
 		if (omap_request_gpio(host->switch_pin) != 0) {
-			printk(KERN_WARNING "MMC%d: Unable to get GPIO pin for MMC cover switch\n",
-			       host->id);
+			dev_warn(mmc_dev(host->mmc), "Unable to get GPIO pin for MMC cover switch\n");
 			host->switch_pin = -1;
 			goto no_switch;
 		}
@@ -1335,8 +1315,7 @@ static int __init mmc_omap_probe(struct 
 				  SA_TRIGGER_RISING | SA_TRIGGER_FALLING,
 				  DRIVER_NAME, host);
 		if (ret) {
-			printk(KERN_WARNING "MMC%d: Unable to get IRQ for MMC cover switch\n",
-			       host->id);
+			dev_warn(mmc_dev(host->mmc), "Unable to get IRQ for MMC cover switch\n");
 			omap_free_gpio(host->switch_pin);
 			host->switch_pin = -1;
 			goto no_switch;
@@ -1348,8 +1327,7 @@ static int __init mmc_omap_probe(struct 
 				device_remove_file(&pdev->dev, &dev_attr_cover_switch);
 		}
 		if (ret) {
-			printk(KERN_WARNING "MMC%d: Unable to create sysfs attributes\n", 
-			       host->id);
+			dev_warn(mmc_dev(host->mmc), "Unable to create sysfs attributes\n");
 			free_irq(OMAP_GPIO_IRQ(host->switch_pin), host);
 			omap_free_gpio(host->switch_pin);
 			host->switch_pin = -1;