Skip to contentSkip to conversation

mmc: bcm2835: Add new driver for the sdhost controller

PATCH Superseded Gerd Hoffmann 3 participants 15 messages Feb 3, 2017 – Feb 8, 2017

Subsystems (5)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover mmc: bcm2835: Add new driver for the sdhost controller

Hi,

Next version if the bcm2835 sdhost patch series.
New in this version:
* DMA fixed.
* updated docs (kconfig, file comment, commit message) clarifying the two sd controller situation.
* some code cleanups, as pointed out by Stefan.
* dt bindings use mmc at ... now.
* added patches to update defconfigs.
* added patch for rpi3 device tree, so wifi is actually enabled.

please review & test,
Gerd

Eric Anholt (2):
dt-bindings: Add binding for brcm,bcm2835-sdhost.
mmc: bcm2835: Add new driver for the sdhost controller.

Gerd Hoffmann (6):
mmc: bcm2835: add sdhost controller to devicetree
arm: set CONFIG_MMC_BCM2835=y in bcm2835_defconfig
arm: set CONFIG_MMC_BCM2835=y in multi_v7_defconfig
arm64: set CONFIG_MMC_BCM2835=y in defconfig
ARM: dts: bcm283x: switch from &sdhci to &sdhost
ARM: dts: bcm2837: add &sdhci and &sdhost

 .../bindings/mmc/brcm,bcm2835-sdhost.txt           |   24 +
 arch/arm/boot/dts/bcm2835-rpi.dtsi                 |    6 +
 arch/arm/boot/dts/bcm283x.dtsi                     |   10 +
 arch/arm/configs/bcm2835_defconfig                 |    1 +
 arch/arm/configs/multi_v7_defconfig                |    1 +
 arch/arm64/boot/dts/broadcom/bcm2837-rpi-3-b.dts   |   17 +
 arch/arm64/configs/defconfig                       |    1 +
 drivers/mmc/host/Kconfig                           |   14 +
 drivers/mmc/host/Makefile                          |    1 +
 drivers/mmc/host/bcm2835.c                         | 1521 ++++++++++++++++++++
 10 files changed, 1596 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mmc/brcm,bcm2835-sdhost.txt
 create mode 100644 drivers/mmc/host/bcm2835.c
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v2 1/8 dt-bindings: Add binding for brcm,bcm2835-sdhost.

From: Eric Anholt <[email protected]>

This is the other SD controller on the platform, which can be swapped to the role of SD card host using pin muxing.

---
 .../bindings/mmc/brcm,bcm2835-sdhost.txt           | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mmc/brcm,bcm2835-sdhost.txt
Documentation/devicetree/bindings/mmc/brcm,bcm2835-sdhost.txt new file +24 -0
new file mode 100644
index 0000000..ac676db
@@ -0,0 +1,24 @@
+Broadcom BCM2835 SDHOST controller
+
+This file documents differences between the core properties described
+by mmc.txt and the properties that represent the BCM2835 controller.
+
+Required properties:
+- compatible: Should be "brcm,bcm2835-sdhost".
+- clocks: The clock feeding the SDHOST controller.
+
+Optional properties:
+- dmas: DMA channels for read and write.
+          See Documentation/devicetree/bindings/dma/dma.txt for details
+
+Example:
+
+sdhost: mmc at 7e202000 {
+	compatible = "brcm,bcm2835-sdhost";
+	reg = <0x7e202000 0x100>;
+	interrupts = <2 24>;
+	clocks = <&clocks BCM2835_CLOCK_VPU>;
+	dmas = <&dma 13>,
+	       <&dma 13>;
+	dma-names = "tx", "rx";
+};
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH v2 2/8 mmc: bcm2835: Add new driver for the sdhost controller.

In reply to Gerd Hoffmann

From: Eric Anholt <[email protected]>

The 2835 has two SD controllers: The Arasan sdhci controller (supported by the iproc driver) and a custom sdhost controller. This patch adds a driver for the latter.

The sdhci controller supports both sdcard and sdio. The sdhost controller supports the sdcard only, but has better performance. Also note that the rpi3 has sdio wifi, so driving the sdcard with the sdhost controller allows to use the sdhci controller for wifi support.

The configuration is done by devicetree via pin muxing. Both SD controller are available on the same pins (2 pin groups = pin 22 to 27 + pin 48 to 53). So it's possible to use both SD controllers at the same time with different pin groups.

The code was originally written by Phil Elwell in the downstream Rasbperry Pi tree, and I did a major cleanup on it (+319, -707 lines out of the original 2055) for inclusion.

cleanups by Gerd Hoffmann

mmc: bcm2835: zap mmiowb()
mmc: bcm2835: reset tweaks.
mmc: bcm2835: more reset tweaks.
mmc: bcm2835: rename bcm2835_sdhost to bcm2835
mmc: bcm2835: whitespace & comment style
mmc: bcm2835: zap bcm2835_write
mmc: bcm2835: zap bcm2835_read
mmc: bcm2835: zap bcm2835_read_relaxed
mmc: bcm2835: zap bcm2835_set_ios fwd decl
mmc: bcm2835: use dev_dbg()
mmc: bcm2835: use dev_err()
mmc: bcm2835: use dev_warn() + dev_into()

cleanups by Stefan Wahren

mmc: bcm2835: Fix checkpatch.pl warning
mmc: bcm2835: replace spaces with tabs
mmc: bcm2835: remove bcm2835_set_power
mmc: bcm2835: remove bcm2835_init()
mmc: bcm2835: Avoid separate init statement
mmc: bcm2835: Use local device ptr to make code more compact
mmc: bcm2835: Use local ptr to make code more compact
mmc: bcm2835: Use __func__ macro
mmc: bcm2835: sort includes alphabetical
mmc: bcm2835: fix includes
mmc: bcm2835: refactor bcm2835_wait_transfer_complete()
mmc: bcm2835: Handle error case of of_get_address
mmc: bcm2835: Use MMC_SEND_OP_COND instead of number
mmc: bcm2835: Rearrange mmc capabilities

driver modernizations:
* run most driver code in thread context.
- use threaded irq handler.
- schedule worker for timeout handling.
* use mutex for locking, so we can easily sleep.
* simplify poll/wait code, drop tasklet and work queue.
* fix DMA support.

---
 drivers/mmc/host/Kconfig   |   14 +
 drivers/mmc/host/Makefile  |    1 +
 drivers/mmc/host/bcm2835.c | 1521 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1536 insertions(+)
 create mode 100644 drivers/mmc/host/bcm2835.c
drivers/mmc/host/Kconfig +14 -0
index 2eb9701..ae5b2e7 100644
@@ -790,6 +790,20 @@ config MMC_TOSHIBA_PCI
 	depends on PCI
 	help
 
+config MMC_BCM2835
+	tristate "platform support for the BCM2835 SDHOST MMC Controller"
+	depends on ARCH_BCM2835 || COMPILE_TEST
+	depends on HAS_DMA
+	help
+	  This selects the BCM2835 SDHOST MMC controller. If you have
+	  a BCM2835 platform with SD or MMC devices, say Y or M here.
+
+	  Note that the BCM2835 has two SD controllers: The Arasan
+	  sdhci controller (supported by MMC_SDHCI_IPROC) and a custom
+	  sdhost controller (supported by this driver).
+
+	  If unsure, say N.
+
 config MMC_MTK
 	tristate "MediaTek SD/MMC Card Interface support"
 	depends on HAS_DMA
drivers/mmc/host/Makefile +1 -0
index ccc9c4c..1a8fbab 100644
@@ -58,6 +58,7 @@ obj-$(CONFIG_MMC_MOXART)	+= moxart-mmc.o
 obj-$(CONFIG_MMC_SUNXI)		+= sunxi-mmc.o
 obj-$(CONFIG_MMC_USDHI6ROL0)	+= usdhi6rol0.o
 obj-$(CONFIG_MMC_TOSHIBA_PCI)	+= toshsd.o
+obj-$(CONFIG_MMC_BCM2835)	+= bcm2835.o
 
 obj-$(CONFIG_MMC_REALTEK_PCI)	+= rtsx_pci_sdmmc.o
 obj-$(CONFIG_MMC_REALTEK_USB)	+= rtsx_usb_sdmmc.o
drivers/mmc/host/bcm2835.c new file +1521 -0

1,521 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#3 lore raw

Re: [PATCH v2 2/8] mmc: bcm2835: Add new driver for the sdhost controller.

Hi Gerd,

first of all here my wishlist for the next round of this driver:
* compile test the series with ARM and ARM64
* add me in CC for all patches of the series
* run checkpatch.pl before submission
* apply the patch series to your cgit repo

Quoted 11 lines

Gerd Hoffmann <[email protected]> hat am 3. Februar 2017 um 13:11 geschrieben:

From: Eric Anholt <[email protected]>

The 2835 has two SD controllers: The Arasan sdhci controller (supported by the iproc driver) and a custom sdhost controller. This patch adds a driver for the latter.

The sdhci controller supports both sdcard and sdio. The sdhost controller supports the sdcard only, but has better performance. Also

Sorry, for the confusion. I was wrong. According to the registers the SDHOST should also support SDIO. It's a feature we could implement later.

Quoted 11 lines

note that the rpi3 has sdio wifi, so driving the sdcard with the sdhost controller allows to use the sdhci controller for wifi support.

The configuration is done by devicetree via pin muxing. Both SD controller are available on the same pins (2 pin groups = pin 22 to 27 + pin 48 to 53). So it's possible to use both SD controllers at the same time with different pin groups.

The code was originally written by Phil Elwell in the downstream Rasbperry Pi tree, and I did a major cleanup on it (+319, -707 lines out of the original 2055) for inclusion.

I think it would be helpful to known the downstream commit, because this commit [1] doesn't seem to be included.

[1] - https://github.com/raspberrypi/linux/commit/ea4b1c5c2ddbb6caba43ab9b0103542a4ca7e1f0

I've found and fixed a lot of issues in this version and i think it would be better if i send you the patches for squashing them all together. Here is the preview for my patch series:

Stefan Wahren (15):
mmc: bcm2835: Add missing include for threaded irq
mmc: bcm2835: Remove CMD_DALLY_US
mmc: bcm2835: Fix pio_timeout handling
mmc: bcm2835: Remove unnecessary return in bcm2835_data_irq
mmc: bcm2835: Handle error cases during probe
mmc: bcm2835: Print clk_max as decimal
mmc: bcm2835: Downrate message in case of PIO fallback
mmc: bcm2835: Don't unveil the data pointer
mmc: bcm2835: remove unused host members
mmc: bcm2835: Avoid unnecessary linebreaks
mmc: bcm2835: Add leading zero to register dumps
mmc: bcm2835: Align struct members with tabs
mmc: bcm2835: Rearrange bcm2835_finish_request()
mmc: bcm2835: Rearrange bcm2835_dma_complete_work()
mmc: bcm2835: Rename Kconfig switch

I'll send it after my tests. In the following review i will mention only the issues which aren't fixed in my patch series.

Quoted 151 lines
drivers/mmc/host/bcm2835.c new file +145 -0
new file mode 100644
index 0000000..5ea8bd6
@@ -0,0 +1,1521 @@
+/*
+ * bcm2835 sdhost driver.
+ *
+ * The 2835 has two SD controllers: The Arasan sdhci controller
+ * (supported by the iproc driver) and a custom sdhost controller
+ * (supported by this driver).
+ *
+ * The sdhci controller supports both sdcard and sdio.  The sdhost
+ * controller supports the sdcard only, but has better performance.
+ * Also note that the rpi3 has sdio wifi, so driving the sdcard with
+ * the sdhost controller allows to use the sdhci controller for wifi
+ * support.
+ *
+ * The configuration is done by devicetree via pin muxing.  Both
+ * SD controller are available on the same pins (2 pin groups = pin 22
+ * to 27 + pin 48 to 53).  So it's possible to use both SD controllers
+ * at the same time with different pin groups.
+ *
+ * Author:      Phil Elwell <[email protected]>
+ *              Copyright (C) 2015-2016 Raspberry Pi (Trading) Ltd.
+ *
+ * Based on
+ *  mmc-bcm2835.c by Gellert Weisz
+ * which is, in turn, based on
+ *  sdhci-bcm2708.c by Broadcom
+ *  sdhci-bcm2835.c by Stephen Warren and Oleksandr Tymoshenko
+ *  sdhci.c and sdhci-pci.c by Pierre Ossman
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/dmaengine.h>
+#include <linux/dma-mapping.h>
+#include <linux/err.h>
+#include <linux/highmem.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/module.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <linux/platform_device.h>
+#include <linux/scatterlist.h>
+#include <linux/time.h>
+#include <linux/workqueue.h>
+
+#include <linux/mmc/host.h>
+#include <linux/mmc/mmc.h>
+#include <linux/mmc/sd.h>
+
+#define SDCMD  0x00 /* Command to SD card              - 16 R/W */
+#define SDARG  0x04 /* Argument to SD card             - 32 R/W */
+#define SDTOUT 0x08 /* Start value for timeout counter - 32 R/W */
+#define SDCDIV 0x0c /* Start value for clock divider   - 11 R/W */
+#define SDRSP0 0x10 /* SD card response (31:0)         - 32 R   */
+#define SDRSP1 0x14 /* SD card response (63:32)        - 32 R   */
+#define SDRSP2 0x18 /* SD card response (95:64)        - 32 R   */
+#define SDRSP3 0x1c /* SD card response (127:96)       - 32 R   */
+#define SDHSTS 0x20 /* SD host status                  - 11 R   */
+#define SDVDD  0x30 /* SD card power control           -  1 R/W */
+#define SDEDM  0x34 /* Emergency Debug Mode            - 13 R/W */
+#define SDHCFG 0x38 /* Host configuration              -  2 R/W */
+#define SDHBCT 0x3c /* Host byte count (debug)         - 32 R/W */
+#define SDDATA 0x40 /* Data to/from SD card            - 32 R/W */
+#define SDHBLC 0x50 /* Host block count (SDIO/SDHC)    -  9 R/W */
+
+#define SDCMD_NEW_FLAG			0x8000
+#define SDCMD_FAIL_FLAG			0x4000
+#define SDCMD_BUSYWAIT			0x800
+#define SDCMD_NO_RESPONSE		0x400
+#define SDCMD_LONG_RESPONSE		0x200
+#define SDCMD_WRITE_CMD			0x80
+#define SDCMD_READ_CMD			0x40
+#define SDCMD_CMD_MASK			0x3f
+
+#define SDCDIV_MAX_CDIV			0x7ff
+
+#define SDHSTS_BUSY_IRPT		0x400
+#define SDHSTS_BLOCK_IRPT		0x200
+#define SDHSTS_SDIO_IRPT		0x100
+#define SDHSTS_REW_TIME_OUT		0x80
+#define SDHSTS_CMD_TIME_OUT		0x40
+#define SDHSTS_CRC16_ERROR		0x20
+#define SDHSTS_CRC7_ERROR		0x10
+#define SDHSTS_FIFO_ERROR		0x08
+/* Reserved */
+/* Reserved */
+#define SDHSTS_DATA_FLAG		0x01
+
+#define SDHSTS_TRANSFER_ERROR_MASK	(SDHSTS_CRC7_ERROR | \
+					 SDHSTS_CRC16_ERROR | \
+					 SDHSTS_REW_TIME_OUT | \
+					 SDHSTS_FIFO_ERROR)
+
+#define SDHSTS_ERROR_MASK		(SDHSTS_CMD_TIME_OUT | \
+					 SDHSTS_TRANSFER_ERROR_MASK)
+
+#define SDHCFG_BUSY_IRPT_EN	BIT(10)
+#define SDHCFG_BLOCK_IRPT_EN	BIT(8)
+#define SDHCFG_SDIO_IRPT_EN	BIT(5)
+#define SDHCFG_DATA_IRPT_EN	BIT(4)
+#define SDHCFG_SLOW_CARD	BIT(3)
+#define SDHCFG_WIDE_EXT_BUS	BIT(2)
+#define SDHCFG_WIDE_INT_BUS	BIT(1)
+#define SDHCFG_REL_CMD_LINE	BIT(0)
+
+#define SDVDD_POWER_OFF		0
+#define SDVDD_POWER_ON		1
+
+#define SDEDM_FORCE_DATA_MODE	BIT(19)
+#define SDEDM_CLOCK_PULSE	BIT(20)
+#define SDEDM_BYPASS		BIT(21)
+
+#define SDEDM_WRITE_THRESHOLD_SHIFT	9
+#define SDEDM_READ_THRESHOLD_SHIFT	14
+#define SDEDM_THRESHOLD_MASK		0x1f
+
+#define SDEDM_FSM_MASK		0xf
+#define SDEDM_FSM_IDENTMODE	0x0
+#define SDEDM_FSM_DATAMODE	0x1
+#define SDEDM_FSM_READDATA	0x2
+#define SDEDM_FSM_WRITEDATA	0x3
+#define SDEDM_FSM_READWAIT	0x4
+#define SDEDM_FSM_READCRC	0x5
+#define SDEDM_FSM_WRITECRC	0x6
+#define SDEDM_FSM_WRITEWAIT1	0x7
+#define SDEDM_FSM_POWERDOWN	0x8
+#define SDEDM_FSM_POWERUP	0x9
+#define SDEDM_FSM_WRITESTART1	0xa
+#define SDEDM_FSM_WRITESTART2	0xb
+#define SDEDM_FSM_GENPULSES	0xc
+#define SDEDM_FSM_WRITEWAIT2	0xd
+#define SDEDM_FSM_STARTPOWDOWN	0xf
+

drivers/mmc/host/bcm2835.c line 155

Quoted 10 lines
drivers/mmc/host/bcm2835.c new file +10 -0
+#define SDDATA_FIFO_WORDS	16
+
+#define FIFO_READ_THRESHOLD	4
+#define FIFO_WRITE_THRESHOLD	4
+#define SDDATA_FIFO_PIO_BURST	8
+#define CMD_DALLY_US		1
+
+struct bcm2835_host {
+	spinlock_t		lock;
+	struct mutex            mutex;

Would be nice to have a comment for the lock and mutex.

Quoted 19 lines
drivers/mmc/host/bcm2835.c new file +19 -0
+
+	void __iomem		*ioaddr;
+	u32			phys_addr;
+
+	struct mmc_host		*mmc;
+	struct platform_device	*pdev;
+
+	u32			pio_timeout;	/* In jiffies */
+	int			clock;		/* Current clock speed */
+	unsigned int		max_clk;	/* Max possible freq */
+	struct work_struct      dma_work;
+	struct delayed_work     timeout_work;   /* Timer for timeouts */
+	struct sg_mapping_iter	sg_miter;	/* SG state for PIO */
+	unsigned int		blocks;		/* remaining PIO blocks */
+	int			irq;		/* Device IRQ */
+
+	u32			ns_per_fifo_word;
+
+	/* cached registers */

drivers/mmc/host/bcm2835.c line 184

Quoted 10 lines
drivers/mmc/host/bcm2835.c new file +10 -0
+	u32			hcfg;
+	u32			cdiv;
+
+	struct mmc_request	*mrq;		/* Current request */
+	struct mmc_command	*cmd;		/* Current command */
+	struct mmc_data		*data;		/* Current data request */
+	bool			data_complete:1;/* Data finished before cmd */
+	bool			flush_fifo:1;	/* Drain the fifo when finish */
+	bool			use_busy:1;	/* Wait for busy interrupt */
+	bool			use_sbc:1;	/* Send CMD23 */

It would be nice to get the rid off use_busy and use_sbc. Do you see any chance for use_busy?

Quoted 72 lines
drivers/mmc/host/bcm2835.c new file +72 -0
+
+	/* for threaded irq handler */
+	bool                    irq_block;
+	bool                    irq_busy;
+	bool                    irq_data;
+
+	/* DMA part */
+	struct dma_chan		*dma_chan_rx;
+	struct dma_chan		*dma_chan_tx;
+	struct dma_chan		*dma_chan;
+	struct dma_async_tx_descriptor	*dma_desc;
+	u32			dma_dir;
+	u32			drain_words;
+	struct page		*drain_page;
+	u32			drain_offset;
+	bool			use_dma;
+
+	int	max_delay;	/* maximum length of time spent waiting */
+	u32	pio_limit;	/* Maximum block count for PIO (0 = DMA) */
+};
+
+static void bcm2835_dumpcmd(struct bcm2835_host *host,
+			    struct mmc_command *cmd,
+			    const char *label)
+{
+	struct device *dev = &host->pdev->dev;
+
+	if (!cmd)
+		return;
+
+	dev_dbg(dev, "%c%s op %d arg 0x%x flags 0x%x - resp %08x %08x %08x %08x, err %d\n",
+		(cmd == host->cmd) ? '>' : ' ',
+		label, cmd->opcode, cmd->arg, cmd->flags,
+		cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3],
+		cmd->error);
+}
+
+static void bcm2835_dumpregs(struct bcm2835_host *host)
+{
+	struct mmc_request *mrq = host->mrq;
+	struct device *dev = &host->pdev->dev;
+
+	if (mrq) {
+		bcm2835_dumpcmd(host, mrq->sbc, "sbc");
+		bcm2835_dumpcmd(host, mrq->cmd, "cmd");
+		if (mrq->data) {
+			dev_dbg(dev, "data blocks %x blksz %x - err %d\n",
+				mrq->data->blocks,
+				mrq->data->blksz,
+				mrq->data->error);
+		}
+		bcm2835_dumpcmd(host, mrq->stop, "stop");
+	}
+
+	dev_dbg(dev, "=========== REGISTER DUMP ===========\n");
+	dev_dbg(dev, "SDCMD  0x%08x\n", readl(host->ioaddr + SDCMD));
+	dev_dbg(dev, "SDARG  0x%08x\n", readl(host->ioaddr + SDARG));
+	dev_dbg(dev, "SDTOUT 0x%08x\n", readl(host->ioaddr + SDTOUT));
+	dev_dbg(dev, "SDCDIV 0x%08x\n", readl(host->ioaddr + SDCDIV));
+	dev_dbg(dev, "SDRSP0 0x%08x\n", readl(host->ioaddr + SDRSP0));
+	dev_dbg(dev, "SDRSP1 0x%08x\n", readl(host->ioaddr + SDRSP1));
+	dev_dbg(dev, "SDRSP2 0x%08x\n", readl(host->ioaddr + SDRSP2));
+	dev_dbg(dev, "SDRSP3 0x%08x\n", readl(host->ioaddr + SDRSP3));
+	dev_dbg(dev, "SDHSTS 0x%08x\n", readl(host->ioaddr + SDHSTS));
+	dev_dbg(dev, "SDVDD  0x%08x\n", readl(host->ioaddr + SDVDD));
+	dev_dbg(dev, "SDEDM  0x%08x\n", readl(host->ioaddr + SDEDM));
+	dev_dbg(dev, "SDHCFG 0x%08x\n", readl(host->ioaddr + SDHCFG));
+	dev_dbg(dev, "SDHBCT 0x%08x\n", readl(host->ioaddr + SDHBCT));
+	dev_dbg(dev, "SDHBLC 0x%08x\n", readl(host->ioaddr + SDHBLC));
+	dev_dbg(dev, "===========================================\n");
+}
+

drivers/mmc/host/bcm2835.c line 266

Quoted 10 lines
drivers/mmc/host/bcm2835.c new file +10 -0
+static void bcm2835_reset_internal(struct bcm2835_host *host)
+{
+	u32 temp;
+
+	writel(SDVDD_POWER_OFF, host->ioaddr + SDVDD);
+	writel(0, host->ioaddr + SDCMD);
+	writel(0, host->ioaddr + SDARG);
+	writel(0xf00000, host->ioaddr + SDTOUT);
+	writel(0, host->ioaddr + SDCDIV);
+	writel(0x7f8, host->ioaddr + SDHSTS); /* Write 1s to clear */

Any chance to eliminate the bit magic for SDTOUT and SDHSTS?

Quoted 109 lines
drivers/mmc/host/bcm2835.c new file +108 -0
+	writel(0, host->ioaddr + SDHCFG);
+	writel(0, host->ioaddr + SDHBCT);
+	writel(0, host->ioaddr + SDHBLC);
+
+	/* Limit fifo usage due to silicon bug */
+	temp = readl(host->ioaddr + SDEDM);
+	temp &= ~((SDEDM_THRESHOLD_MASK << SDEDM_READ_THRESHOLD_SHIFT) |
+		  (SDEDM_THRESHOLD_MASK << SDEDM_WRITE_THRESHOLD_SHIFT));
+	temp |= (FIFO_READ_THRESHOLD << SDEDM_READ_THRESHOLD_SHIFT) |
+		(FIFO_WRITE_THRESHOLD << SDEDM_WRITE_THRESHOLD_SHIFT);
+	writel(temp, host->ioaddr + SDEDM);
+	msleep(20);
+	writel(SDVDD_POWER_ON, host->ioaddr + SDVDD);
+	msleep(20);
+	host->clock = 0;
+	writel(host->hcfg, host->ioaddr + SDHCFG);
+	writel(host->cdiv, host->ioaddr + SDCDIV);
+}
+
...
+
+static void bcm2835_finish_data(struct bcm2835_host *host)
+{
+	struct device *dev = &host->pdev->dev;
+	struct mmc_data *data;
+
+	data = host->data;
+
+	dev_dbg(dev, "finish_data(error %d, stop %d, sbc %d)\n",
+		data->error, data->stop ? 1 : 0,
+		host->mrq->sbc ? 1 : 0);
+
+	host->hcfg &= ~(SDHCFG_DATA_IRPT_EN | SDHCFG_BLOCK_IRPT_EN);
+	writel(host->hcfg, host->ioaddr + SDHCFG);
+
+	data->bytes_xfered = data->error ? 0 : (data->blksz * data->blocks);
+
+	host->data_complete = true;
+
+	if (host->cmd) {
+		/* Data managed to finish before the
+		 * command completed. Make sure we do
+		 * things in the proper order.
+		 */
+		dev_dbg(dev, "Finished early - HSTS %x\n",
+			readl(host->ioaddr + SDHSTS));
+	} else {
+		bcm2835_transfer_complete(host);
+	}
+}
+
+static void bcm2835_finish_command(struct bcm2835_host *host)
+{
+	struct device *dev = &host->pdev->dev;
+	struct mmc_command *cmd = host->cmd;
+	u32 sdcmd;
+
+	dev_dbg(dev, "finish_command(%x)\n", readl(host->ioaddr + SDCMD));
+
+	sdcmd = bcm2835_read_wait_sdcmd(host, 100, true);
+
+	/* Check for errors */
+	if (sdcmd & SDCMD_NEW_FLAG) {
+		dev_err(dev, "command never completed.\n");
+		bcm2835_dumpregs(host);
+		host->cmd->error = -EIO;
+		bcm2835_finish_request(host);
+		return;
+	} else if (sdcmd & SDCMD_FAIL_FLAG) {
+		u32 sdhsts = readl(host->ioaddr + SDHSTS);
+
+		/* Clear the errors */
+		writel(SDHSTS_ERROR_MASK, host->ioaddr + SDHSTS);
+
+		if (!(sdhsts & SDHSTS_CRC7_ERROR) ||
+		    (host->cmd->opcode != MMC_SEND_OP_COND)) {
+			if (sdhsts & SDHSTS_CMD_TIME_OUT) {
+				host->cmd->error = -ETIMEDOUT;
+			} else {
+				dev_err(dev, "unexpected command %d error\n",
+					host->cmd->opcode);
+				bcm2835_dumpregs(host);
+				host->cmd->error = -EILSEQ;
+			}
+			bcm2835_finish_request(host);
+			return;
+		}
+	}
+
+	if (cmd->flags & MMC_RSP_PRESENT) {
+		if (cmd->flags & MMC_RSP_136) {
+			int i;
+
+			for (i = 0; i < 4; i++) {
+				cmd->resp[3 - i] =
+					readl(host->ioaddr + SDRSP0 + i * 4);
+			}
+
+			dev_dbg(dev, "finish_command %08x %08x %08x %08x\n",
+				cmd->resp[0], cmd->resp[1],
+				cmd->resp[2], cmd->resp[3]);
+		} else {
+			cmd->resp[0] = readl(host->ioaddr + SDRSP0);
+			dev_dbg(dev, "finish_command %08x\n", cmd->resp[0]);
+		}
+	}
+
+	if (cmd == host->mrq->sbc) {
+		/* Finished CMD23, now send actual command. */

drivers/mmc/host/bcm2835.c

Quoted 10 lines
drivers/mmc/host/bcm2835.c new file +10 -0
+		host->cmd = NULL;
+		if (bcm2835_send_command(host, host->mrq->cmd)) {
+			if (host->data && host->dma_desc)
+				/* DMA transfer starts now, PIO starts
+				 * after irq
+				 */
+				bcm2835_start_dma(host);
+
+			if (!host->use_busy)
+				bcm2835_finish_command(host);

Recursion?

drivers/mmc/host/bcm2835.c line 878

Quoted 11 lines
drivers/mmc/host/bcm2835.c new file +11 -0
+		}
+	} else if (cmd == host->mrq->stop) {
+		/* Finished CMD12 */
+		bcm2835_finish_request(host);
+	} else {
+		/* Processed actual command. */
+		host->cmd = NULL;
+		if (!host->data)
+			bcm2835_finish_request(host);
+		else if (host->data_complete)
+			bcm2835_transfer_complete(host);

bcm2835_finish_command() calls bcm2835_transfer_complete() bcm2835_transfer_complete() calls bcm2835_finish_command()

This should be avoided.

Quoted 27 lines

...

drivers/mmc/host/bcm2835.c new file +26 -0
+int bcm2835_add_host(struct bcm2835_host *host)
+{
+	struct mmc_host *mmc = host->mmc;
+	struct device *dev = &host->pdev->dev;
+	struct dma_slave_config cfg;
+	char pio_limit_string[20];
+	int ret;
+
+	bcm2835_reset_internal(host);
+
+	mmc->f_max = host->max_clk;
+	mmc->f_min = host->max_clk / SDCDIV_MAX_CDIV;
+
+	mmc->max_busy_timeout = ~0 / (mmc->f_max / 1000);
+
+	dev_dbg(dev, "f_max %d, f_min %d, max_busy_timeout %d\n",
+		mmc->f_max, mmc->f_min, mmc->max_busy_timeout);
+
+	/* host controller capabilities */
+	mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED |
+		     MMC_CAP_NEEDS_POLL | MMC_CAP_HW_RESET | MMC_CAP_ERASE |
+		     MMC_CAP_CMD23;
+
+	spin_lock_init(&host->lock);
+	mutex_init(&host->mutex);
+

drivers/mmc/host/bcm2835.c line 1331

Quoted 10 lines
drivers/mmc/host/bcm2835.c new file +10 -0
+	if (IS_ERR_OR_NULL(host->dma_chan_tx) ||
+	    IS_ERR_OR_NULL(host->dma_chan_rx)) {
+		dev_err(dev, "unable to initialise DMA channels. Falling back to PIO\n");
+		host->use_dma = false;
+	} else {
+		host->use_dma = true;
+
+		cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
+		cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
+		cfg.slave_id = 13;		/* DREQ channel */

Is this the same value which is also defined in the DT?

Thanks
Stefan

#4 lore raw

Re: [PATCH v2 2/8] mmc: bcm2835: Add new driver for the sdhost controller.

Quoted 4 lines · Stefan Wahren

Hi Gerd,

first of all here my wishlist for the next round of this driver:
* compile test the series with ARM and ARM64

It is tested on both arm and arm64 (rpi2 + rpi3).

Quoted 1 line

* add me in CC for all patches of the series

Oops. /me should be more careful when reading names. I thought I had you on Cc: Double-checked. Turned out that was Stephen Warren ...

Quoted 1 line

* run checkpatch.pl before submission

Hmm? Are there any issues? /me has a pre-commit hook running checkpatch to avoid anything slipping though.

Quoted 1 line

* apply the patch series to your cgit repo

Branch pushed now: bcm2837-sdhost-squashed-v2

Quoted 4 lines
Quoted 2 lines

The sdhci controller supports both sdcard and sdio. The sdhost controller supports the sdcard only, but has better performance. Also

Sorry, for the confusion. I was wrong. According to the registers the SDHOST should also support SDIO. It's a feature we could implement later.

Ok.

Quoted 36 lines
Quoted 11 lines

note that the rpi3 has sdio wifi, so driving the sdcard with the sdhost controller allows to use the sdhci controller for wifi support.

The configuration is done by devicetree via pin muxing. Both SD controller are available on the same pins (2 pin groups = pin 22 to 27 + pin 48 to 53). So it's possible to use both SD controllers at the same time with different pin groups.

The code was originally written by Phil Elwell in the downstream Rasbperry Pi tree, and I did a major cleanup on it (+319, -707 lines out of the original 2055) for inclusion.

I think it would be helpful to known the downstream commit, because this commit [1] doesn't seem to be included.

[1] - https://github.com/raspberrypi/linux/commit/ea4b1c5c2ddbb6caba43ab9b0103542a4ca7e1f0

I've found and fixed a lot of issues in this version and i think it would be better if i send you the patches for squashing them all together. Here is the preview for my patch series:

Stefan Wahren (15):
mmc: bcm2835: Add missing include for threaded irq
mmc: bcm2835: Remove CMD_DALLY_US
mmc: bcm2835: Fix pio_timeout handling
mmc: bcm2835: Remove unnecessary return in bcm2835_data_irq
mmc: bcm2835: Handle error cases during probe
mmc: bcm2835: Print clk_max as decimal
mmc: bcm2835: Downrate message in case of PIO fallback
mmc: bcm2835: Don't unveil the data pointer
mmc: bcm2835: remove unused host members
mmc: bcm2835: Avoid unnecessary linebreaks
mmc: bcm2835: Add leading zero to register dumps
mmc: bcm2835: Align struct members with tabs
mmc: bcm2835: Rearrange bcm2835_finish_request()
mmc: bcm2835: Rearrange bcm2835_dma_complete_work()
mmc: bcm2835: Rename Kconfig switch

Quoted 1 line

I'll send it after my tests. In the following review i will mention only the issues which aren't fixed in my patch series.

I'll pick up the patches and look at the remaining issues, new version later this week (i hope).

thanks,
Gerd

#5 lore raw

Re: [PATCH v2 2/8] mmc: bcm2835: Add new driver for the sdhost controller.

Hi Gerd,

Am 07.02.2017 um 09:02 schrieb Gerd Hoffmann:

Quoted 6 lines · Stefan Wahren
Quoted 4 lines

Hi Gerd,

first of all here my wishlist for the next round of this driver:
* compile test the series with ARM and ARM64

It is tested on both arm and arm64 (rpi2 + rpi3).

i got implicite declaration for request_threaded_irq() and free_irq(). After including linux/interrupt.h the issue is fixed (patch #1 of my series).

Quoted 4 lines
Quoted 2 lines

* add me in CC for all patches of the series

Oops. /me should be more careful when reading names. I thought I had you on Cc: Double-checked. Turned out that was Stephen Warren ...

No problem

Quoted 4 lines
Quoted 2 lines

* run checkpatch.pl before submission

Hmm? Are there any issues? /me has a pre-commit hook running checkpatch to avoid anything slipping though.

Just a single issue about a unnecessary return at the end of bcm2835_data_irq() (patch #4 of my series). Maybe this was a new rule.

Quoted 3 lines
Quoted 2 lines

* apply the patch series to your cgit repo

Branch pushed now: bcm2837-sdhost-squashed-v2

Thanks

Quoted 21 lines
Quoted 4 lines
Quoted 3 lines

The sdhci controller supports both sdcard and sdio. The sdhost controller supports the sdcard only, but has better performance. Also

Sorry, for the confusion. I was wrong. According to the registers the SDHOST should also support SDIO. It's a feature we could implement later.

Ok.

Quoted 15 lines
Quoted 11 lines

note that the rpi3 has sdio wifi, so driving the sdcard with the sdhost controller allows to use the sdhci controller for wifi support.

The configuration is done by devicetree via pin muxing. Both SD controller are available on the same pins (2 pin groups = pin 22 to 27 + pin 48 to 53). So it's possible to use both SD controllers at the same time with different pin groups.

The code was originally written by Phil Elwell in the downstream Rasbperry Pi tree, and I did a major cleanup on it (+319, -707 lines out of the original 2055) for inclusion.

I think it would be helpful to known the downstream commit, because this commit [1] doesn't seem to be included.

[1] - https://github.com/raspberrypi/linux/commit/ea4b1c5c2ddbb6caba43ab9b0103542a4ca7e1f0

Sorry wrong link, this must be the right one

https://github.com/raspberrypi/linux/commit/1131510a589ae7262b8861af8d2f4a000710d59c

Quoted 26 lines
Quoted 20 lines

I've found and fixed a lot of issues in this version and i think it would be better if i send you the patches for squashing them all together. Here is the preview for my patch series:

Stefan Wahren (15):
mmc: bcm2835: Add missing include for threaded irq
mmc: bcm2835: Remove CMD_DALLY_US
mmc: bcm2835: Fix pio_timeout handling
mmc: bcm2835: Remove unnecessary return in bcm2835_data_irq
mmc: bcm2835: Handle error cases during probe
mmc: bcm2835: Print clk_max as decimal
mmc: bcm2835: Downrate message in case of PIO fallback
mmc: bcm2835: Don't unveil the data pointer
mmc: bcm2835: remove unused host members
mmc: bcm2835: Avoid unnecessary linebreaks
mmc: bcm2835: Add leading zero to register dumps
mmc: bcm2835: Align struct members with tabs
mmc: bcm2835: Rearrange bcm2835_finish_request()
mmc: bcm2835: Rearrange bcm2835_dma_complete_work()
mmc: bcm2835: Rename Kconfig switch

Quoted 1 line

I'll send it after my tests. In the following review i will mention only the issues which aren't fixed in my patch series.

I'll pick up the patches and look at the remaining issues, new version later this week (i hope).

thanks,
Gerd

#6 lore raw

Re: [PATCH v2 2/8] mmc: bcm2835: Add new driver for the sdhost controller.

In reply to Gerd Hoffmann
Quoted 8 lines

Gerd Hoffmann <[email protected]> hat am 7. Februar 2017 um 09:02 geschrieben:
...

Quoted 2 lines

I'll send it after my tests. In the following review i will mention only the issues which aren't fixed in my patch series.

I'll pick up the patches and look at the remaining issues, new version later this week (i hope).

No need to hurry. The merge window opens soon.

Do you take care of the missing downstream patch ( bcm2835-sdhost: Only claim one DMA channel ) which affects most of your patch series?

Quoted 4 lines

thanks,
Gerd

#7 lore raw

PATCH v2 3/8 mmc: bcm2835: add sdhost controller to devicetree

In reply to Gerd Hoffmann
---
 arch/arm/boot/dts/bcm2835-rpi.dtsi |  6 ++++++
 arch/arm/boot/dts/bcm283x.dtsi     | 10 ++++++++++
 2 files changed, 16 insertions(+)
arch/arm/boot/dts/bcm2835-rpi.dtsi +6 -0
index 0b73f9c..7d89af2 100644
@@ -69,6 +69,12 @@
 	bus-width = <4>;
 };
 
+&sdhost {
+	pinctrl-names = "default";
+	pinctrl-0 = <&sdhost_gpio48>;
+	bus-width = <4>;
+};
+
 &pwm {
 	pinctrl-names = "default";
 	pinctrl-0 = <&pwm0_gpio40 &pwm1_gpio45>;
arch/arm/boot/dts/bcm283x.dtsi +10 -0
index a3106aa..180f359 100644
@@ -450,6 +450,16 @@
 			status = "disabled";
 		};
 
+		sdhost: mmc at 7e202000 {
+			compatible = "brcm,bcm2835-sdhost";
+			reg = <0x7e202000 0x100>;
+			interrupts = <2 24>;
+			clocks = <&clocks BCM2835_CLOCK_VPU>;
+			dmas = <&dma 13>, <&dma 13>;
+			dma-names = "tx", "rx";
+			status = "disabled";
+		};
+
 		hvs at 7e400000 {
 			compatible = "brcm,bcm2835-hvs";
 			reg = <0x7e400000 0x6000>;
Signature · 1 line
1.8.3.1
Acked-by on v2 3/8
#8 lore raw

Re: [PATCH v2 3/8] mmc: bcm2835: add sdhost controller to devicetree

Quoted 1 line · Gerd Hoffmann

Patches 3, 7, 8 are:

waiting on Ulf for merging the driver now.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170203/f1e9419d/attachment.sig>

#9 lore raw

PATCH v2 4/8 arm: set CONFIG_MMC_BCM2835=y in bcm2835_defconfig

In reply to Gerd Hoffmann
---
 arch/arm/configs/bcm2835_defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm/configs/bcm2835_defconfig +1 -0
index 4b89f4e..3767c24 100644
@@ -92,6 +92,7 @@ CONFIG_MMC=y
 CONFIG_MMC_SDHCI=y
 CONFIG_MMC_SDHCI_PLTFM=y
 CONFIG_MMC_SDHCI_IPROC=y
+CONFIG_MMC_BCM2835=y
 CONFIG_NEW_LEDS=y
 CONFIG_LEDS_CLASS=y
 CONFIG_LEDS_GPIO=y
Signature · 1 line
1.8.3.1
#10 lore raw

Re: [PATCH v2 4/8] arm: set CONFIG_MMC_BCM2835=y in bcm2835_defconfig

Quoted 9 lines · Gerd Hoffmann
---
 arch/arm/configs/bcm2835_defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm/configs/bcm2835_defconfig +0 -0
index 4b89f4e..3767c24 100644

arch/arm/configs/bcm2835_defconfig CONFIG_MMC=y · line 98

Quoted 7 lines
arch/arm/configs/bcm2835_defconfig +1 -0
@@ -92,6 +92,7 @@ CONFIG_MMC=y
 CONFIG_MMC_SDHCI=y
 CONFIG_MMC_SDHCI_PLTFM=y
 CONFIG_MMC_SDHCI_IPROC=y
+CONFIG_MMC_BCM2835=y
 CONFIG_NEW_LEDS=y
 CONFIG_LEDS_CLASS=y
 CONFIG_LEDS_GPIO=y

If you end up resubmitting this, could you extend the commit message of the defconfig changes to explain why it's being done? Something like:

"We need to enable this controller so that we can switch the SD card's pinmux over to it by default, which will improve storage read/write speed."

(even better if we have some sort of stats on how much better it is).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170203/20099ee6/attachment.sig>

#11 lore raw

PATCH v2 5/8 arm: set CONFIG_MMC_BCM2835=y in multi_v7_defconfig

In reply to Gerd Hoffmann
---
 arch/arm/configs/multi_v7_defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm/configs/multi_v7_defconfig +1 -0
index 028d2b7..5d13894 100644
@@ -727,6 +727,7 @@ CONFIG_MMC_DW_EXYNOS=y
 CONFIG_MMC_DW_ROCKCHIP=y
 CONFIG_MMC_SH_MMCIF=y
 CONFIG_MMC_SUNXI=y
+CONFIG_MMC_BCM2835=y
 CONFIG_NEW_LEDS=y
 CONFIG_LEDS_CLASS=y
 CONFIG_LEDS_CLASS_FLASH=m
Signature · 1 line
1.8.3.1
#12 lore raw

PATCH v2 6/8 arm64: set CONFIG_MMC_BCM2835=y in defconfig

In reply to Gerd Hoffmann
---
 arch/arm64/configs/defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
index 33b744d..75131a6 100644
@@ -391,6 +391,7 @@ CONFIG_MMC_DW_EXYNOS=y
 CONFIG_MMC_DW_K3=y
 CONFIG_MMC_DW_ROCKCHIP=y
 CONFIG_MMC_SUNXI=y
+CONFIG_MMC_BCM2835=y
 CONFIG_NEW_LEDS=y
 CONFIG_LEDS_CLASS=y
 CONFIG_LEDS_GPIO=y
Signature · 1 line
1.8.3.1
#13 lore raw

PATCH v2 7/8 ARM: dts: bcm283x: switch from &sdhci to &sdhost

In reply to Gerd Hoffmann

sdcard access with the sdhost controller is faster.

---
 arch/arm/boot/dts/bcm2835-rpi.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boot/dts/bcm2835-rpi.dtsi +1 -1
index 7d89af2..e6beecb 100644
@@ -65,13 +65,13 @@
 &sdhci {
 	pinctrl-names = "default";
 	pinctrl-0 = <&emmc_gpio48>;
-	status = "okay";
 	bus-width = <4>;
 };
 
 &sdhost {
 	pinctrl-names = "default";
 	pinctrl-0 = <&sdhost_gpio48>;
+	status = "okay";
 	bus-width = <4>;
 };
 
Signature · 1 line
1.8.3.1
#14 lore raw

PATCH v2 8/8 ARM: dts: bcm2837: add &sdhci and &sdhost

In reply to Gerd Hoffmann

For the raspberry pi 3 we'll need both sdhci (handles sdio wifi) and sdhost (handles sdcard).

---
 arch/arm64/boot/dts/broadcom/bcm2837-rpi-3-b.dts | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
arch/arm64/boot/dts/broadcom/bcm2837-rpi-3-b.dts +17 -0
index c309633..972f14d 100644
@@ -22,3 +22,20 @@
 &uart1 {
 	status = "okay";
 };
+
+/* SDHCI is used to control the SDIO for wireless */
+&sdhci {
+	pinctrl-names = "default";
+	pinctrl-0 = <&emmc_gpio34>;
+	status = "okay";
+	bus-width = <4>;
+	non-removable;
+};
+
+/* SDHOST is used to drive the SD card */
+&sdhost {
+	pinctrl-names = "default";
+	pinctrl-0 = <&sdhost_gpio48>;
+	status = "okay";
+	bus-width = <4>;
+};
Signature · 1 line
1.8.3.1