Skip to contentSkip to conversation

SDIO driver for Marvell SoCs

PATCH Superseded Nicolas Pitre 3 participants 8 messages Feb 18, 2009 – Feb 20, 2009

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

PATCH 1/1 SDIO driver for Marvell SoCs

From: Maen Suleiman <[email protected]>

This supports MMC/SD/SDIO currently found on the Kirkwood 88F6281 and 88F6192 SoC controllers.

arch/arm/plat-orion/include/plat/mvsdio.h new file +21 -0
new file mode 100644
index 0000000..14ca886
@@ -0,0 +1,21 @@
+/*
+ * arch/arm/plat-orion/include/plat/mvsdio.h
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_MVSDIO_H
+#define __MACH_MVSDIO_H
+
+#include <linux/mbus.h>
+
+struct mvsdio_platform_data {
+	struct mbus_dram_target_info *dram;
+	unsigned int clock;
+	int gpio_card_detect;
+	int gpio_write_protect;
+};
+
+#endif
drivers/mmc/host/Kconfig +11 -0
index 99d4b28..092baf6 100644
@@ -171,6 +171,17 @@ config MMC_TIFM_SD
           To compile this driver as a module, choose M here: the
 	  module will be called tifm_sd.
 
+config MMC_MVSDIO
+	tristate "Marvell MMC/SD/SDIO host driver"
+	depends on PLAT_ORION
+	---help---
+	  This selects the Marvell SDIO host driver.
+	  SDIO may currently be found on the Kirkwood 88F6281 and 88F6192
+	  SoC controllers.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called mvsdio.
+
 config MMC_SPI
 	tristate "MMC/SD/SDIO over SPI"
 	depends on SPI_MASTER && !HIGHMEM && HAS_DMA
drivers/mmc/host/Makefile +1 -0
index dedec55..c006eb4 100644
@@ -20,6 +20,7 @@ obj-$(CONFIG_MMC_OMAP_HS)	+= omap_hsmmc.o
 obj-$(CONFIG_MMC_AT91)		+= at91_mci.o
 obj-$(CONFIG_MMC_ATMELMCI)	+= atmel-mci.o
 obj-$(CONFIG_MMC_TIFM_SD)	+= tifm_sd.o
+obj-$(CONFIG_MMC_MVSDIO)	+= mvsdio.o
 obj-$(CONFIG_MMC_SPI)		+= mmc_spi.o
 ifeq ($(CONFIG_OF),y)
 obj-$(CONFIG_MMC_SPI)		+= of_mmc_spi.o
drivers/mmc/host/mvsdio.c new file +878 -0

878 lines not on this page · raw message

drivers/mmc/host/mvsdio.h new file +190 -0

190 lines not on this page · raw message

#1 lore raw
Quoted 6 lines · On Tue, 17 Feb 2009 23:46:21 -0500 (EST) Nicolas Pitre <[email protected]> wrote:

From: Maen Suleiman <[email protected]>

This supports MMC/SD/SDIO currently found on the Kirkwood 88F6281 and 88F6192 SoC controllers.

It would be nice to have Maen's signoff.

drivers/mmc/host/mvsdio.c line 59

Quoted 5 lines

...

drivers/mmc/host/mvsdio.c new file +2 -0
+#define mvsd_write(offs, val)	writel(val, iobase + (offs))
+#define mvsd_read(offs)		readl(iobase + (offs))

It's rather grotty to have a macro which secretly relies upon the presence of a particularly-named local variable.

Quoted 15 lines

...

drivers/mmc/host/mvsdio.c new file +12 -0
+static int __init mvsd_probe(struct platform_device *pdev)
+{
+	struct mmc_host *mmc = NULL;
+	struct mvsd_host *host = NULL;
+	const struct mvsdio_platform_data *mvsd_data;
+	struct resource *r;
+	int ret, irq;
+
+	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	irq = platform_get_irq(pdev, 0);
+	mvsd_data = pdev->dev.platform_data;
+	if (!r || irq < 0 || !mvsd_data)

drivers/mmc/host/mvsdio.c line 692

Quoted 10 lines
drivers/mmc/host/mvsdio.c new file +10 -0
+		return -ENXIO;
+
+	r = request_mem_region(r->start, SZ_1K, DRIVER_NAME);
+	if (!r)
+		return -EBUSY;
+
+	mmc = mmc_alloc_host(sizeof(struct mvsd_host), &pdev->dev);
+	if (!mmc) {
+		ret = -ENOMEM;
+		goto out;

Resource `r' is leaked here.

Quoted 112 lines
drivers/mmc/host/mvsdio.c new file +112 -0
+	}
+
+	host = mmc_priv(mmc);
+	host->mmc = mmc;
+	host->dev = &pdev->dev;
+	host->res = r;
+	host->base_clock = mvsd_data->clock / 2;
+
+	mmc->ops = &mvsd_ops;
+
+	mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
+	mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ |
+		    MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
+
+	mmc->f_min = DIV_ROUND_UP(host->base_clock, MVSD_BASE_DIV_MAX);
+	mmc->f_max = maxfreq;
+
+	mmc->max_blk_size = 2048;
+	mmc->max_blk_count = 65535;
+
+	mmc->max_hw_segs = 1;
+	mmc->max_phys_segs = 1;
+	mmc->max_seg_size = mmc->max_blk_size * mmc->max_blk_count;
+	mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
+
+	spin_lock_init(&host->lock);
+
+	host->base = ioremap(r->start, SZ_4K);
+	if (!host->base) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	/* (Re-)program MBUS remapping windows if we are asked to. */
+	if (mvsd_data->dram != NULL)
+		mv_conf_mbus_windows(host, mvsd_data->dram);
+
+	mvsd_power_down(host);
+
+	ret = request_irq(irq, mvsd_irq, 0, DRIVER_NAME, host);
+	if (ret) {
+		printk(KERN_ERR "%s: cannot assign irq %d\n", DRIVER_NAME, irq);
+		goto out;
+	} else
+		host->irq = irq;
+
+	if (mvsd_data->gpio_card_detect) {
+		ret = gpio_request(mvsd_data->gpio_card_detect,
+				   DRIVER_NAME " cd");
+		if (ret == 0) {
+			irq = gpio_to_irq(mvsd_data->gpio_card_detect);
+			ret = request_irq(irq, mvsd_card_detect_irq,
+					  IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING,
+					  DRIVER_NAME " cd", host);
+			if (ret == 0)
+				host->gpio_card_detect =
+					mvsd_data->gpio_card_detect;
+			else
+				gpio_free(mvsd_data->gpio_card_detect);
+		}
+	}
+	if (!host->gpio_card_detect)
+		mmc->caps |= MMC_CAP_NEEDS_POLL;
+
+	if (mvsd_data->gpio_write_protect) {
+		ret = gpio_request(mvsd_data->gpio_write_protect,
+				   DRIVER_NAME " wp");
+		if (ret == 0) {
+			gpio_direction_input(mvsd_data->gpio_write_protect);
+			host->gpio_write_protect =
+				mvsd_data->gpio_write_protect;
+		}
+	}
+
+	setup_timer(&host->timer, mvsd_timeout_timer, (unsigned long)host);
+	platform_set_drvdata(pdev, mmc);
+	ret = mmc_add_host(mmc);
+	if (ret)
+		goto out;
+	return 0;
+
+out:
+	if (host) {
+		if (host->irq)
+			free_irq(host->irq, host);
+		if (host->gpio_card_detect) {
+			free_irq(gpio_to_irq(host->gpio_card_detect), host);
+			gpio_free(host->gpio_card_detect);
+		}
+		if (host->gpio_write_protect)
+			gpio_free(host->gpio_write_protect);
+		if (host->base)
+			iounmap(host->base);
+		if (host->res)
+			release_resource(host->res);
+	}
+	if (mmc)
+		mmc_free_host(mmc);
+
+	return ret;
+}
+
+static int __exit mvsd_remove(struct platform_device *pdev)
+{
+	struct mmc_host *mmc = platform_get_drvdata(pdev);
+
+	if (mmc) {
+		struct mvsd_host *host = mmc_priv(mmc);
+
+		if (host->gpio_card_detect) {
+			free_irq(gpio_to_irq(host->gpio_card_detect), host);
+			gpio_free(host->gpio_card_detect);

drivers/mmc/host/mvsdio.c line 814

Quoted 10 lines
drivers/mmc/host/mvsdio.c new file +10 -0
+		}
+		mmc_remove_host(mmc);
+		free_irq(host->irq, host);
+		if (host->gpio_write_protect)
+			gpio_free(host->gpio_write_protect);
+		del_timer_sync(&host->timer);
+		mvsd_power_down(host);
+		iounmap(host->base);
+		release_resource(host->res);
+		mmc_free_host(mmc);

Perhaps this function and the error path ("out:") in the preceding function could share code.

Quoted 3 lines
drivers/mmc/host/mvsdio.c new file +3 -0
+	}
+	platform_set_drvdata(pdev, NULL);
+	return 0;
#2 lore raw
Quoted 11 lines · Andrew Morton
Quoted 6 lines · On Tue, 17 Feb 2009 23:46:21 -0500 (EST) Nicolas Pitre <[email protected]> wrote:

From: Maen Suleiman <[email protected]>

This supports MMC/SD/SDIO currently found on the Kirkwood 88F6281 and 88F6192 SoC controllers.

It would be nice to have Maen's signoff.

Sure, I can add it if this is Maen's wish. Still, this single signoff was made in conformity with option B of the Developer's Certificate of Origin 1.1 as found in Documentation/SubmittingPatches. It is actually my duty at Marvell to act as such.

Quoted 8 lines

drivers/mmc/host/mvsdio.c line 59

Quoted 5 lines

...

drivers/mmc/host/mvsdio.c new file +2 -0
+#define mvsd_write(offs, val)	writel(val, iobase + (offs))
+#define mvsd_read(offs)		readl(iobase + (offs))

It's rather grotty to have a macro which secretly relies upon the presence of a particularly-named local variable.

My call. Otherwise the code becomes bloated with repeated iobase noise everywhere, making many lines bust the 80 column limit imposed by the checkpatch.pl. The alternative is to split those statement on multiple lines making things not prettier. So, unless you want to help maintaining this driver, I prefer this grottiness to remains as is.

Quoted 16 lines
Quoted 16 lines
drivers/mmc/host/mvsdio.c new file +16 -0
+static int __init mvsd_probe(struct platform_device *pdev)
+{
+	struct mmc_host *mmc = NULL;
+	struct mvsd_host *host = NULL;
+	const struct mvsdio_platform_data *mvsd_data;
+	struct resource *r;
+	int ret, irq;
+
+	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	irq = platform_get_irq(pdev, 0);
+	mvsd_data = pdev->dev.platform_data;
+	if (!r || irq < 0 || !mvsd_data)
+		return -ENXIO;
+
+	r = request_mem_region(r->start, SZ_1K, DRIVER_NAME);
+	if (!r)
Quoted 8 lines

drivers/mmc/host/mvsdio.c line 692

Quoted 6 lines
drivers/mmc/host/mvsdio.c new file +6 -0
+		return -EBUSY;
+
+	mmc = mmc_alloc_host(sizeof(struct mvsd_host), &pdev->dev);
+	if (!mmc) {
+		ret = -ENOMEM;
+		goto out;

Resource `r' is leaked here.

Good catch, thanks.

Quoted 15 lines
Quoted 15 lines
drivers/mmc/host/mvsdio.c new file +15 -0
+static int __exit mvsd_remove(struct platform_device *pdev)
+{
+	struct mmc_host *mmc = platform_get_drvdata(pdev);
+
+	if (mmc) {
+		struct mvsd_host *host = mmc_priv(mmc);
+
+		if (host->gpio_card_detect) {
+			free_irq(gpio_to_irq(host->gpio_card_detect), host);
+			gpio_free(host->gpio_card_detect);
+		}
+		mmc_remove_host(mmc);
+		free_irq(host->irq, host);
+		if (host->gpio_write_protect)
+			gpio_free(host->gpio_write_protect);
Quoted 8 lines

drivers/mmc/host/mvsdio.c line 814

Quoted 5 lines
drivers/mmc/host/mvsdio.c new file +5 -0
+		del_timer_sync(&host->timer);
+		mvsd_power_down(host);
+		iounmap(host->base);
+		release_resource(host->res);
+		mmc_free_host(mmc);

Perhaps this function and the error path ("out:") in the preceding function could share code.

Well, one is marked __init and the other __exit. Having common code would mean this needs to be in a non discardable section which is a waste.

Nicolas

#3 lore raw
Quoted 10 lines · On Thu, 19 Feb 2009 17:02:32 -0500 (EST) Nicolas Pitre <[email protected]> wrote:
Quoted 8 lines · Andrew Morton
Quoted 5 lines · On Tue, 17 Feb 2009 23:46:21 -0500 (EST) Nicolas Pitre <[email protected]> wrote:

From: Maen Suleiman <[email protected]>

This supports MMC/SD/SDIO currently found on the Kirkwood 88F6281 and 88F6192 SoC controllers.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

It would be nice to have Maen's signoff.

Sure, I can add it if this is Maen's wish. Still, this single signoff was made in conformity with option B of the Developer's Certificate of Origin 1.1 as found in Documentation/SubmittingPatches. It is actually my duty at Marvell to act as such.

No, it's not required. But "nice".

Quoted 9 lines
Quoted 8 lines

drivers/mmc/host/mvsdio.c line 59

Quoted 5 lines

...

drivers/mmc/host/mvsdio.c new file +2 -0
+#define mvsd_write(offs, val)	writel(val, iobase + (offs))
+#define mvsd_read(offs)		readl(iobase + (offs))

It's rather grotty to have a macro which secretly relies upon the presence of a particularly-named local variable.

Quoted 5 lines

My call. Otherwise the code becomes bloated with repeated iobase noise everywhere, making many lines bust the 80 column limit imposed by the checkpatch.pl. The alternative is to split those statement on multiple lines making things not prettier. So, unless you want to help maintaining this driver, I prefer this grottiness to remains as is.

For the record: you do not get to put bad code into Linux by telling the person who points out that bad code that he needs to maintain a fixed verion. Just cut the sophomoric crap.

I don't care much - we have plenty of grotty code down in drivers/

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
drivers/mmc/host/mvsdio.c new file +9 -0
+
+		if (host->gpio_card_detect) {
+			free_irq(gpio_to_irq(host->gpio_card_detect), host);
+			gpio_free(host->gpio_card_detect);
+		}
+		mmc_remove_host(mmc);
+		free_irq(host->irq, host);
+		if (host->gpio_write_protect)
+			gpio_free(host->gpio_write_protect);
Quoted 8 lines

drivers/mmc/host/mvsdio.c line 814

Quoted 5 lines
drivers/mmc/host/mvsdio.c new file +5 -0
+		del_timer_sync(&host->timer);
+		mvsd_power_down(host);
+		iounmap(host->base);
+		release_resource(host->res);
+		mmc_free_host(mmc);

Perhaps this function and the error path ("out:") in the preceding function could share code.

Quoted 3 lines

Well, one is marked __init and the other __exit. Having common code would mean this needs to be in a non discardable section which is a waste.

OK.

#4 lore raw
Quoted 20 lines · Andrew Morton
Quoted 11 lines · On Thu, 19 Feb 2009 17:02:32 -0500 (EST) Nicolas Pitre <[email protected]> wrote:
Quoted 8 lines · Andrew Morton

drivers/mmc/host/mvsdio.c line 59

Quoted 2 lines · On Tue, 17 Feb 2009 23:46:21 -0500 (EST) Nicolas Pitre <[email protected]> wrote:
drivers/mmc/host/mvsdio.c new file +2 -0
+#define mvsd_write(offs, val)	writel(val, iobase + (offs))
+#define mvsd_read(offs)		readl(iobase + (offs))

It's rather grotty to have a macro which secretly relies upon the presence of a particularly-named local variable.

Quoted 5 lines

My call. Otherwise the code becomes bloated with repeated iobase noise everywhere, making many lines bust the 80 column limit imposed by the checkpatch.pl. The alternative is to split those statement on multiple lines making things not prettier. So, unless you want to help maintaining this driver, I prefer this grottiness to remains as is.

Quoted 5 lines

For the record: you do not get to put bad code into Linux by telling the person who points out that bad code that he needs to maintain a fixed verion. Just cut the sophomoric crap.

I don't care much - we have plenty of grotty code down in drivers/

I think this is a not-so-uncommon pattern in network drivers. FWIW

Harvey

#5 lore raw

PATCH v2 1/1 SDIO driver for Marvell SoCs

In reply to Andrew Morton

From: Maen Suleiman <[email protected]>

This supports MMC/SD/SDIO currently found on the Kirkwood 88F6281 and 88F6192 SoC controllers.

---

With fix for resource leakage found by Andrew Morton.

arch/arm/plat-orion/include/plat/mvsdio.h new file +21 -0
new file mode 100644
index 0000000..14ca886
@@ -0,0 +1,21 @@
+/*
+ * arch/arm/plat-orion/include/plat/mvsdio.h
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_MVSDIO_H
+#define __MACH_MVSDIO_H
+
+#include <linux/mbus.h>
+
+struct mvsdio_platform_data {
+	struct mbus_dram_target_info *dram;
+	unsigned int clock;
+	int gpio_card_detect;
+	int gpio_write_protect;
+};
+
+#endif
drivers/mmc/host/Kconfig +11 -0
index 99d4b28..092baf6 100644
@@ -171,6 +171,17 @@ config MMC_TIFM_SD
           To compile this driver as a module, choose M here: the
 	  module will be called tifm_sd.
 
+config MMC_MVSDIO
+	tristate "Marvell MMC/SD/SDIO host driver"
+	depends on PLAT_ORION
+	---help---
+	  This selects the Marvell SDIO host driver.
+	  SDIO may currently be found on the Kirkwood 88F6281 and 88F6192
+	  SoC controllers.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called mvsdio.
+
 config MMC_SPI
 	tristate "MMC/SD/SDIO over SPI"
 	depends on SPI_MASTER && !HIGHMEM && HAS_DMA
drivers/mmc/host/Makefile +1 -0
index dedec55..c006eb4 100644
@@ -20,6 +20,7 @@ obj-$(CONFIG_MMC_OMAP_HS)	+= omap_hsmmc.o
 obj-$(CONFIG_MMC_AT91)		+= at91_mci.o
 obj-$(CONFIG_MMC_ATMELMCI)	+= atmel-mci.o
 obj-$(CONFIG_MMC_TIFM_SD)	+= tifm_sd.o
+obj-$(CONFIG_MMC_MVSDIO)	+= mvsdio.o
 obj-$(CONFIG_MMC_SPI)		+= mmc_spi.o
 ifeq ($(CONFIG_OF),y)
 obj-$(CONFIG_MMC_SPI)		+= of_mmc_spi.o
drivers/mmc/host/mvsdio.c new file +878 -0

878 lines not on this page · raw message

drivers/mmc/host/mvsdio.h new file +190 -0

190 lines not on this page · raw message

#6 lore raw
Quoted 2 lines · On Thu, 19 Feb 2009 17:14:11 -0500 (EST) Nicolas Pitre <[email protected]> wrote:

This supports MMC/SD/SDIO currently found on the Kirkwood 88F6281 and 88F6192 SoC controllers.

drivers/mmc/host/mvsdio.c renamed from drivers/mmc/host/mvsdio.c~sdio-driver-for-marvell-socs-update +2 -2
@@ -783,9 +783,9 @@ out:
 			gpio_free(host->gpio_write_protect);
 		if (host->base)
 			iounmap(host->base);
-		if (host->res)
-			release_resource(host->res);
 	}
+	if (r)
+		release_resource(host->res);
 	if (mmc)
 		mmc_free_host(mmc);
 

_

Nope, this will deref a null pointer on that error path and wouldn't release the right thing anyway.

Something like this...

drivers/mmc/host/mvsdio.c renamed from drivers/mmc/host/mvsdio.c~sdio-driver-for-marvell-socs-update +1 -0
@@ -688,6 +688,7 @@ static int __init mvsd_probe(struct plat
 
 	mmc = mmc_alloc_host(sizeof(struct mvsd_host), &pdev->dev);
 	if (!mmc) {
+		release_resource(r);
 		ret = -ENOMEM;
 		goto out;
 	}
#7 lore raw
Quoted 16 lines · Andrew Morton
drivers/mmc/host/mvsdio.c renamed from drivers/mmc/host/mvsdio.c~sdio-driver-for-marvell-socs-update +2 -2
@@ -783,9 +783,9 @@ out:
 			gpio_free(host->gpio_write_protect);
 		if (host->base)
 			iounmap(host->base);
-		if (host->res)
-			release_resource(host->res);
 	}
+	if (r)
+		release_resource(host->res);
 	if (mmc)
 		mmc_free_host(mmc);
 

_

Quoted 2 lines

Nope, this will deref a null pointer on that error path and wouldn't release the right thing anyway.

Obviously. I'm just too stupid sometimes. A s/host->res/r/ in both places would be better.

drivers/mmc/host/mvsdio.c static int __init mvsd_probe(struct plat · line 694

Quoted 12 lines

Something like this...

drivers/mmc/host/mvsdio.c renamed from drivers/mmc/host/mvsdio.c~sdio-driver-for-marvell-socs-update +1 -0
@@ -688,6 +688,7 @@ static int __init mvsd_probe(struct plat
 
 	mmc = mmc_alloc_host(sizeof(struct mvsd_host), &pdev->dev);
 	if (!mmc) {
+		release_resource(r);
 		ret = -ENOMEM;
 		goto out;
 	}

That's fine too.

Nicolas