Skip to contentSkip to conversation

ARM: mmc: bcm281xx SDHCI driver

PATCH In review Christian Daudt 3 participants 6 messages May 10, 2013 – May 22, 2013

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

PATCH v2 1/2 ARM: mmc: bcm281xx SDHCI driver

Add SDHCI driver for the Broadcom 281xx SoCs. Also add bindings for it into bcm281xx dts files. Still missing:
- power managemement

Changes from V1:
- split DT into separate patch
- use gpio_is_valid instead of direct test
- switch pr_debug calls to dev_dbg
- use of_property_read_bool

arch/arm/configs/bcm_defconfig +7 -0
index e3bf2d6..65edf6d 100644
@@ -78,6 +78,13 @@ CONFIG_BACKLIGHT_LCD_SUPPORT=y
 CONFIG_LCD_CLASS_DEVICE=y
 CONFIG_BACKLIGHT_CLASS_DEVICE=y
 # CONFIG_USB_SUPPORT is not set
+CONFIG_MMC=y
+CONFIG_MMC_UNSAFE_RESUME=y
+CONFIG_MMC_BLOCK_MINORS=32
+CONFIG_MMC_TEST=y
+CONFIG_MMC_SDHCI=y
+CONFIG_MMC_SDHCI_PLTFM=y
+CONFIG_MMC_SDHCI_BCM_KONA=y
 CONFIG_NEW_LEDS=y
 CONFIG_LEDS_CLASS=y
 CONFIG_LEDS_TRIGGERS=y
drivers/mmc/host/Kconfig +11 -0
index d88219e..ad11c7f 100644
@@ -238,6 +238,17 @@ config MMC_SDHCI_S3C_DMA
 
 	  YMMV.
 
+config MMC_SDHCI_BCM_KONA
+	tristate "SDHCI support on Broadcom KONA platform"
+	depends on ARCH_BCM
+	select MMC_SDHCI_PLTFM
+	help
+	  This selects the Broadcom Kona Secure Digital Host Controller
+	  Interface(SDHCI) support.
+	  This is used in Broadcom mobile SoCs.
+
+	  If you have a controller with this interface, say Y or M here.
+
 config MMC_SDHCI_BCM2835
 	tristate "SDHCI platform support for the BCM2835 SD/MMC Controller"
 	depends on ARCH_BCM2835
drivers/mmc/host/Makefile +1 -0
index c380e3c..a9f582b 100644
@@ -59,6 +59,7 @@ obj-$(CONFIG_MMC_SDHCI_DOVE)		+= sdhci-dove.o
 obj-$(CONFIG_MMC_SDHCI_TEGRA)		+= sdhci-tegra.o
 obj-$(CONFIG_MMC_SDHCI_OF_ESDHC)	+= sdhci-of-esdhc.o
 obj-$(CONFIG_MMC_SDHCI_OF_HLWD)		+= sdhci-of-hlwd.o
+obj-$(CONFIG_MMC_SDHCI_BCM_KONA)	+= sdhci-bcm-kona.o
 obj-$(CONFIG_MMC_SDHCI_BCM2835)		+= sdhci-bcm2835.o
 
 ifeq ($(CONFIG_CB710_DEBUG),y)
drivers/mmc/host/sdhci-bcm-kona.c new file +485 -0

485 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v2 2/2 ARM: mmc: bcm281xx SDHCI driver (dt mods)

Add SDHCI driver for the Broadcom 281xx SoCs. Also add bindings for it into bcm281xx dts files.

Changes from V1:
- split original patch into 2, one for driver and this one for dt

Documentation/devicetree/bindings/mmc/bcm,kona-sdhci.txt new file +16 -0
new file mode 100644
index 0000000..ad1c4bd
@@ -0,0 +1,16 @@
+Broadcom BCM281xx SDHCI driver
+
+This file documents differences between the core properties in mmc.txt
+and the properties in the bcm281xx driver.
+
+Required properties:
+- compatible : Should be "bcm,kona-sdhci"
+
+Example:
+
+sdio2: sdio at 0x3f1a0000 {
+	compatible = "bcm,kona-sdhci";
+	reg = <0x3f1a0000 0x10000>;
+	interrupts = <0x0 74 0x4>;
+};
+
arch/arm/boot/dts/bcm11351-brt.dts +17 -0
index 248067c..9ae3404 100644
@@ -27,4 +27,21 @@
 		status = "okay";
 	};
 
+	sdio0: sdio at 0x3f180000 {
+		max-frequency = <48000000>;
+		status = "okay";
+	};
+
+	sdio1: sdio at 0x3f190000 {
+		non-removable;
+		max-frequency = <48000000>;
+		status = "okay";
+	};
+
+	sdio3: sdio at 0x3f1b0000 {
+		max-frequency = <48000000>;
+		status = "okay";
+	};
+
+
 };
arch/arm/boot/dts/bcm11351.dtsi +29 -0
index ad13588..6606b41 100644
@@ -47,4 +47,33 @@
 		    cache-unified;
 		    cache-level = <2>;
 	};
+
+	sdio0: sdio at 0x3f180000 {
+		compatible = "bcm,kona-sdhci";
+		reg = <0x3f180000 0x10000>;
+		interrupts = <0x0 77 0x4>;
+		status = "disabled";
+	};
+
+	sdio1: sdio at 0x3f190000 {
+		compatible = "bcm,kona-sdhci";
+		reg = <0x3f190000 0x10000>;
+		interrupts = <0x0 76 0x4>;
+		status = "disabled";
+	};
+
+	sdio2: sdio at 0x3f1a0000 {
+		compatible = "bcm,kona-sdhci";
+		reg = <0x3f1a0000 0x10000>;
+		interrupts = <0x0 74 0x4>;
+		status = "disabled";
+	};
+
+	sdio3: sdio at 0x3f1b0000 {
+		compatible = "bcm,kona-sdhci";
+		reg = <0x3f1b0000 0x10000>;
+		interrupts = <0x0 73 0x4>;
+		status = "disabled";
+	};
+
 };
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [PATCH V2 2/2] ARM: mmc: bcm281xx SDHCI driver (dt mods)

Hi Christian,

Quoted 2 lines · Christian Daudt

Add SDHCI driver for the Broadcom 281xx SoCs. Also add bindings for it into bcm281xx dts files.

Since this is independent of the driver, the description should probably be updated to reflect that this is just the DT support for the bcm281xx (or kona) SDHCI hw.

Documentation/devicetree/bindings/mmc/bcm,kona-sdhci.txt line 1

Quoted 12 lines

Changes from V1:
- split original patch into 2, one for driver and this one for dt

Documentation/devicetree/bindings/mmc/bcm,kona-sdhci.txt new file +1 -0
new file mode 100644
index 0000000..ad1c4bd
@@ -0,0 +1,16 @@
+Broadcom BCM281xx SDHCI driver

s/driver//

Documentation/devicetree/bindings/mmc/bcm,kona-sdhci.txt line 4

Quoted 3 lines
Documentation/devicetree/bindings/mmc/bcm,kona-sdhci.txt new file +3 -0
+
+This file documents differences between the core properties in mmc.txt
+and the properties in the bcm281xx driver.

The hardware binding should not mention the supporting driver. Borrowing from other examples, you'd want something more like:

"
This file documents differences between the core properties described by mmc.txt and the properties that represent the bcm281xx [kona?] SDHCI. "

-Matt

#3 lore raw
In reply to Christian Daudt

drivers/mmc/host/sdhci-bcm-kona.c line 62

Quoted 9 lines · Christian Daudt
drivers/mmc/host/sdhci-bcm-kona.c new file +9 -0
+
+struct sdhci_bcm_kona_cfg {
+	unsigned int	max_freq;
+	int		is_8bit;
+	int		irq;
+	int		cd_gpio;
+	int		wp_gpio;
+	int		non_removable;
+};

I see no use for this structure to be separate: a lot of the fields are duplicated in the sdhci_host, or should just get merged into sdhci_bcm_kona_dev.

drivers/mmc/host/sdhci-bcm-kona.c line 70

Quoted 7 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +7 -0
+struct sdhci_bcm_kona_dev {
+	struct sdhci_bcm_kona_cfg *cfg;
+	struct device *dev;
+	struct sdhci_host *host;
+	struct clk *peri_clk;
+	struct clk *sleep_clk;
+};

The *dev and *host members in this structure are redundant, just allocate it together with sdhci_host and use use container_of() to get from the sdhci_host back it it.

Quoted 12 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +12 -0
+static void sdhci_bcm_kona_sd_init(struct sdhci_host *host)
+{
+	unsigned int val;
+
+	/* enable the interrupt from the IP core */
+	val = sdhci_readl(host, KONA_SDHOST_COREIMR);
+	val |= KONA_SDHOST_IP;
+	sdhci_writel(host, val, KONA_SDHOST_COREIMR);
+
+	/* Enable the AHB clock gating module to the host */
+	val = sdhci_readl(host, KONA_SDHOST_CORECTRL);
+	val |= KONA_SDHOST_EN;

drivers/mmc/host/sdhci-bcm-kona.c line 130

Quoted 10 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +10 -0
+
+	/*
+	 * Back-to-Back register write needs a delay of 1ms at bootup (min 10uS)
+	 * Back-to-Back writes to same register needs delay when SD bus clock
+	 * is very low w.r.t AHB clock, mainly during boot-time and during card
+	 * insert-removal.
+	 */
+	mdelay(1);
+	sdhci_writel(host, val, KONA_SDHOST_CORECTRL);
+}

Why not use msleep() instead of mdelay() here?

Quoted 11 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +11 -0
+static int sdhci_bcm_kona_sd_card_emulate(struct sdhci_host *host, int insert)
+{
+	struct sdhci_pltfm_host *pltfm_priv = sdhci_priv(host);
+	struct sdhci_bcm_kona_dev *kona_dev = pltfm_priv->priv;
+	u32 val;
+	unsigned long flags;
+
+	/* this function can be called from various contexts including ISR */
+	spin_lock_irqsave(&host->lock, flags);
+	/* Ensure SD bus scanning to detect media change */
+	host->mmc->rescan_disable = 0;

drivers/mmc/host/sdhci-bcm-kona.c line 158

Quoted 10 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +10 -0
+
+	/*
+	 * Back-to-Back register write needs a delay of min 10uS.
+	 * Back-to-Back writes to same register needs delay when SD bus clock
+	 * is very low w.r.t AHB clock, mainly during boot-time and during card
+	 * insert-removal.
+	 * We keep 20uS
+	 */
+	udelay(20);
+	val = sdhci_readl(host, KONA_SDHOST_CORESTAT);

Does the delay have to be done with interrupts disabled? That is not particularly nice.

I hope the hardware designers have been appropriately punished for the creating such crap.

drivers/mmc/host/sdhci-bcm-kona.c line 225

Quoted 8 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +8 -0
+static void sdhci_bcm_kona_init_74_clocks(struct sdhci_host *host,
+				u8 power_mode)
+{
+	if (power_mode == MMC_POWER_OFF)
+		return;
+	else
+		mdelay(10);
+}

This requires at the minimum a comment about why the mdelay is needed. Maybe we can change the set_ios function so we never need to call it in atomic context.

drivers/mmc/host/sdhci-bcm-kona.c line 253

Quoted 6 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +6 -0
+static struct sdhci_bcm_kona_cfg * __init sdhci_bcm_kona_parse_dt(
+			struct platform_device *pdev)
+{
+	struct sdhci_bcm_kona_cfg *cfg;
+	struct device_node *np = pdev->dev.of_node;
+	u32 temp;

fold this function into probe()

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (!np)
+		return NULL;

impossible

drivers/mmc/host/sdhci-bcm-kona.c line 262

Quoted 5 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +5 -0
+	cfg = devm_kzalloc(&pdev->dev, sizeof(*cfg), GFP_KERNEL);
+	if (!cfg) {
+		dev_err(&pdev->dev, "Can't allocate platform cfg\n");
+		return NULL;
+	}

Not needed

drivers/mmc/host/sdhci-bcm-kona.c line 281

Quoted 3 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +3 -0
+static int __init sdhci_bcm_kona_probe(struct platform_device *pdev)
+{
+	const struct of_device_id *match;

constant, so not needed.

drivers/mmc/host/sdhci-bcm-kona.c line 282

Quoted 1 line
drivers/mmc/host/sdhci-bcm-kona.c new file +1 -0
+	struct sdhci_bcm_kona_cfg *kona_cfg = NULL;

No need to initialize this.

drivers/mmc/host/sdhci-bcm-kona.c line 283

Quoted 1 line
drivers/mmc/host/sdhci-bcm-kona.c new file +1 -0
+	const struct sdhci_pltfm_data *plat_data;

make it global.

drivers/mmc/host/sdhci-bcm-kona.c line 284

Quoted 1 line
drivers/mmc/host/sdhci-bcm-kona.c new file +1 -0
+	struct sdhci_bcm_kona_dev *kona_dev = NULL;

No need to initialize this.

drivers/mmc/host/sdhci-bcm-kona.c line 320

Quoted 6 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +6 -0
+	kona_dev = devm_kzalloc(dev, sizeof(*kona_dev), GFP_KERNEL);
+	if (!kona_dev) {
+		dev_err(dev, "Can't allocate kona_dev\n");
+		ret = -ENOMEM;
+		goto err_pltfm_free;
+	}

It is rather silly to have the base sdhci code allocate extra memory for the platform drivers but then require an extra allocation. Better change the sdhci_pltfm_init function to let you pass the extra allocation size.

Quoted 1 line

+MODULE_AUTHOR("Broadcom");

No person?

Arnd

#4 lore raw

Hi Arnd,
Thanks for the review. See below for comments.

Quoted 13 lines · Arnd Bergmann

drivers/mmc/host/sdhci-bcm-kona.c line 62

Quoted 9 lines · Christian Daudt
drivers/mmc/host/sdhci-bcm-kona.c new file +9 -0
+
+struct sdhci_bcm_kona_cfg {
+	unsigned int	max_freq;
+	int		is_8bit;
+	int		irq;
+	int		cd_gpio;
+	int		wp_gpio;
+	int		non_removable;
+};

I see no use for this structure to be separate: a lot of the fields are duplicated in the sdhci_host, or should just get merged into sdhci_bcm_kona_dev.

ok. Will do

Quoted 10 lines

drivers/mmc/host/sdhci-bcm-kona.c line 70

Quoted 7 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +7 -0
+struct sdhci_bcm_kona_dev {
+	struct sdhci_bcm_kona_cfg *cfg;
+	struct device *dev;
+	struct sdhci_host *host;
+	struct clk *peri_clk;
+	struct clk *sleep_clk;
+};

The *dev and *host members in this structure are redundant, just allocate it together with sdhci_host and use use container_of() to get from the sdhci_host back it it.

ok.

Quoted 15 lines
Quoted 15 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +15 -0
+static void sdhci_bcm_kona_sd_init(struct sdhci_host *host)
+{
+	unsigned int val;
+
+	/* enable the interrupt from the IP core */
+	val = sdhci_readl(host, KONA_SDHOST_COREIMR);
+	val |= KONA_SDHOST_IP;
+	sdhci_writel(host, val, KONA_SDHOST_COREIMR);
+
+	/* Enable the AHB clock gating module to the host */
+	val = sdhci_readl(host, KONA_SDHOST_CORECTRL);
+	val |= KONA_SDHOST_EN;
+
+	/*
+	 * Back-to-Back register write needs a delay of 1ms at bootup (min 10uS)
Quoted 8 lines

drivers/mmc/host/sdhci-bcm-kona.c line 107

Quoted 7 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +7 -0
+	 * Back-to-Back writes to same register needs delay when SD bus clock
+	 * is very low w.r.t AHB clock, mainly during boot-time and during card
+	 * insert-removal.
+	 */
+	mdelay(1);
+	sdhci_writel(host, val, KONA_SDHOST_CORECTRL);
+}

Why not use msleep() instead of mdelay() here?

I don't think that there's any reason. will replace.

Quoted 25 lines
Quoted 12 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +11 -0
+static int sdhci_bcm_kona_sd_card_emulate(struct sdhci_host *host, int insert)
+{
+	struct sdhci_pltfm_host *pltfm_priv = sdhci_priv(host);
+	struct sdhci_bcm_kona_dev *kona_dev = pltfm_priv->priv;
+	u32 val;
+	unsigned long flags;
+
+	/* this function can be called from various contexts including ISR */
+	spin_lock_irqsave(&host->lock, flags);
+	/* Ensure SD bus scanning to detect media change */
+	host->mmc->rescan_disable = 0;

drivers/mmc/host/sdhci-bcm-kona.c line 158

Quoted 10 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +10 -0
+
+	/*
+	 * Back-to-Back register write needs a delay of min 10uS.
+	 * Back-to-Back writes to same register needs delay when SD bus clock
+	 * is very low w.r.t AHB clock, mainly during boot-time and during card
+	 * insert-removal.
+	 * We keep 20uS
+	 */
+	udelay(20);
+	val = sdhci_readl(host, KONA_SDHOST_CORESTAT);

Does the delay have to be done with interrupts disabled? That is not particularly nice.

Quoted 2 lines

I hope the hardware designers have been appropriately punished for the creating such crap.

I had some internal discussions on this one, and the code was originally written for non-threaded irqs. Now that it is only called as threaded_irq thread_fn, it is safe to replace the spinlock that includes the delay with a mutex instead.

Quoted 11 lines

drivers/mmc/host/sdhci-bcm-kona.c line 225

Quoted 8 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +8 -0
+static void sdhci_bcm_kona_init_74_clocks(struct sdhci_host *host,
+				u8 power_mode)
+{
+	if (power_mode == MMC_POWER_OFF)
+		return;
+	else
+		mdelay(10);
+}

This requires at the minimum a comment about why the mdelay is needed. Maybe we can change the set_ios function so we never need to call it in atomic context.

I'll look into this one.

Quoted 7 lines

drivers/mmc/host/sdhci-bcm-kona.c line 253

Quoted 6 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +6 -0
+static struct sdhci_bcm_kona_cfg * __init sdhci_bcm_kona_parse_dt(
+			struct platform_device *pdev)
+{
+	struct sdhci_bcm_kona_cfg *cfg;
+	struct device_node *np = pdev->dev.of_node;
+	u32 temp;

fold this function into probe()

ok.

Quoted 3 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (!np)
+		return NULL;

impossible

ok

Quoted 6 lines

drivers/mmc/host/sdhci-bcm-kona.c line 262

Quoted 5 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +5 -0
+	cfg = devm_kzalloc(&pdev->dev, sizeof(*cfg), GFP_KERNEL);
+	if (!cfg) {
+		dev_err(&pdev->dev, "Can't allocate platform cfg\n");
+		return NULL;
+	}

Not needed

what is not needed ?

Quoted 4 lines

drivers/mmc/host/sdhci-bcm-kona.c line 281

Quoted 3 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +3 -0
+static int __init sdhci_bcm_kona_probe(struct platform_device *pdev)
+{
+	const struct of_device_id *match;

constant, so not needed.

I'll remove it.

Quoted 2 lines

drivers/mmc/host/sdhci-bcm-kona.c line 282

Quoted 1 line
drivers/mmc/host/sdhci-bcm-kona.c new file +1 -0
+	struct sdhci_bcm_kona_cfg *kona_cfg = NULL;

No need to initialize this.

ok

Quoted 2 lines

drivers/mmc/host/sdhci-bcm-kona.c line 283

Quoted 1 line
drivers/mmc/host/sdhci-bcm-kona.c new file +1 -0
+	const struct sdhci_pltfm_data *plat_data;

make it global.

why make this global ?

Quoted 3 lines

drivers/mmc/host/sdhci-bcm-kona.c line 284

Quoted 2 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +1 -0
+	struct sdhci_bcm_kona_dev *kona_dev = NULL;

No need to initialize this.

ok.

Quoted 10 lines

drivers/mmc/host/sdhci-bcm-kona.c line 320

Quoted 6 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +6 -0
+	kona_dev = devm_kzalloc(dev, sizeof(*kona_dev), GFP_KERNEL);
+	if (!kona_dev) {
+		dev_err(dev, "Can't allocate kona_dev\n");
+		ret = -ENOMEM;
+		goto err_pltfm_free;
+	}

It is rather silly to have the base sdhci code allocate extra memory for the platform drivers but then require an extra allocation. Better change the sdhci_pltfm_init function to let you pass the extra allocation size.

ok, I'll look into this.

Quoted 3 lines
Quoted 1 line

+MODULE_AUTHOR("Broadcom");

No person?

A collective effort :)

Thanks,
csd

#5 lore raw
Quoted 7 lines · Christian Daudt
Quoted 6 lines

drivers/mmc/host/sdhci-bcm-kona.c line 262

Quoted 5 lines
drivers/mmc/host/sdhci-bcm-kona.c new file +5 -0
+    cfg = devm_kzalloc(&pdev->dev, sizeof(*cfg), GFP_KERNEL);
+    if (!cfg) {
+            dev_err(&pdev->dev, "Can't allocate platform cfg\n");
+            return NULL;
+    }

Not needed

what is not needed ?

The allocation, it can be part of the sdhci_pltfm_host data.

Quoted 3 lines
Quoted 2 lines
Quoted 1 line

+ const struct sdhci_pltfm_data *plat_data;

make it global.

why make this global ?

Sorry for being unclear. I mean you can just use &sdhci_pltfm_data_kona in the probe function, since the data is constant anyway, no need to have a local variable for pulling this out of the device id.

Arnd