Skip to contentSkip to conversation

Fixing MMC access on Raspberry Pi CM3

PATCH Applied Tomaz Solc 2 participants 10 messages Feb 18, 2019 – Feb 19, 2019

Subsystems (7)
lore
Share & tools
lore

Tomaz Solc

author
#0 lore raw

v2 cover Fixing MMC access on Raspberry Pi CM3

Changes from the first patch series:

- Base Compute Module 3 device tree off upstream device tree for CM3 + IO3 dev board, instead of R. Pi 3B.
- Keep Makefile.bcm283x without a newline at the end of file.
- Make mci init before pinctrl by moving mci-bcm2835 to device_initcall() instead of changing link order.
- Add CONFIG_PINCTRL to rpi_defconfig.

Best regards
Tomaz

Tomaz Solc (8):
ARM: rpi: switch emmc from sdhost to sdhci
Kconfig: add pin controllers submenu.
pinctrl: bcm2835: move existing code from gpio.
pinctrl: bcm2835: register the pin controller.
mci: bcm2835: use device_initcall(), not coredev.
mci: bcm2835: parse other device tree properties.
ARM: rpi: Add device tree for Compute Module 3.
ARM: rpi: add CONFIG_PINCTRL to rpi_defconfig.

 arch/arm/boards/raspberry-pi/lowlevel.c            | 10 +++++
 arch/arm/configs/rpi_defconfig                     |  4 +-
 arch/arm/dts/Makefile                              |  1 +
 arch/arm/dts/bcm2837-rpi-3.dts                     |  9 ++++
 arch/arm/dts/bcm2837-rpi-cm3.dts                   | 18 ++++++++
 arch/arm/mach-bcm283x/Kconfig                      |  6 +++
 drivers/gpio/Kconfig                               |  4 --
 drivers/gpio/Makefile                              |  1 -
 drivers/mci/mci-bcm2835.c                          |  5 ++-
 drivers/pinctrl/Kconfig                            | 10 +++++
 drivers/pinctrl/Makefile                           |  1 +
 .../gpio-bcm2835.c => pinctrl/pinctrl-bcm2835.c}   | 52 +++++++++++++++++++++-
 images/Makefile.bcm283x                            |  6 ++-
 13 files changed, 117 insertions(+), 10 deletions(-)
 create mode 100644 arch/arm/dts/bcm2837-rpi-cm3.dts
 rename drivers/{gpio/gpio-bcm2835.c => pinctrl/pinctrl-bcm2835.c} (77%)
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
author
#1 lore raw

PATCH v2 1/8 ARM: rpi: switch emmc from sdhost to sdhci

BCM2837 has two mmc interfaces: sdhost and sdhci. On Raspberry Pi 3, sdhost is normally used for SD card/MMC flash and sdhci for the wireless interface. Barebox currently only has a driver for sdhci, so we disable the sdhost interface and remap the pins so that the sdhci has access to the SD card/MMC flash.

---
 arch/arm/dts/bcm2837-rpi-3.dts | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm/dts/bcm2837-rpi-3.dts +9 -0
index 194b41c23..51883613c 100644
@@ -9,3 +9,12 @@
 		reg = <0x0 0x0>;
 	};
 };
+
+&sdhci {
+	pinctrl-0 = <&emmc_gpio48>;
+	/delete-node/ wifi@1;
+};
+
+&sdhost {
+	status = "disabled";
+};
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
author
#2 lore raw

PATCH v2 2/8 Kconfig: add pin controllers submenu.

In reply to Tomaz Solc
---
 drivers/pinctrl/Kconfig | 4 ++++
 1 file changed, 4 insertions(+)
drivers/pinctrl/Kconfig +4 -0
index 12fff4f01..de83c124a 100644
@@ -1,3 +1,5 @@
+menu "Pin controllers"
+
 config PINCTRL
 	bool "Pin controller core support"
 	default y if OFDEVICE
@@ -83,3 +85,5 @@ config PINCTRL_VF610
 	help
 	  Pinmux controller found on Vybrid VF610 family of SoCs
 endif
+
+endmenu
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
author
#3 lore raw

PATCH v2 3/8 pinctrl: bcm2835: move existing code from gpio.

In reply to Tomaz Solc
---
 arch/arm/configs/rpi_defconfig                             | 2 +-
 drivers/gpio/Kconfig                                       | 4 ----
 drivers/gpio/Makefile                                      | 1 -
 drivers/pinctrl/Kconfig                                    | 6 ++++++
 drivers/pinctrl/Makefile                                   | 1 +
 drivers/{gpio/gpio-bcm2835.c => pinctrl/pinctrl-bcm2835.c} | 0
 6 files changed, 8 insertions(+), 6 deletions(-)
 rename drivers/{gpio/gpio-bcm2835.c => pinctrl/pinctrl-bcm2835.c} (100%)
arch/arm/configs/rpi_defconfig +1 -1
index dc5ab1fe1..35943e025 100644
@@ -71,7 +71,7 @@ CONFIG_LED_GPIO=y
 CONFIG_LED_TRIGGERS=y
 CONFIG_WATCHDOG=y
 CONFIG_WATCHDOG_BCM2835=y
-CONFIG_GPIO_BCM283X=y
+CONFIG_PINCTRL_BCM283X=y
 # CONFIG_PINCTRL is not set
 CONFIG_REGULATOR=y
 CONFIG_FS_EXT4=y
drivers/gpio/Kconfig +0 -4
index ed93e868a..c535904ed 100644
@@ -21,10 +21,6 @@ config GPIO_74164
 	  shift registers. This driver can be used to provide access
 	  to more gpio outputs.
 
-config GPIO_BCM283X
-	bool "GPIO support for BCM283X"
-	depends on ARCH_BCM283X
-
 config GPIO_CLPS711X
 	bool "GPIO support for CLPS711X"
 	depends on ARCH_CLPS711X
drivers/gpio/Makefile +0 -1
index f5ed876d5..52280f0bb 100644
@@ -2,7 +2,6 @@ obj-$(CONFIG_GPIOLIB)		+= gpiolib.o
 
 obj-$(CONFIG_GPIO_74164)	+= gpio-74164.o
 obj-$(CONFIG_MACH_MIPS_ATH79)	+= gpio-ath79.o
-obj-$(CONFIG_GPIO_BCM283X)	+= gpio-bcm2835.o
 obj-$(CONFIG_GPIO_DAVINCI)	+= gpio-davinci.o
 obj-$(CONFIG_GPIO_CLPS711X)	+= gpio-clps711x.o
 obj-$(CONFIG_GPIO_DIGIC)	+= gpio-digic.o
drivers/pinctrl/Kconfig +6 -0
index de83c124a..45c3b351d 100644
@@ -17,6 +17,12 @@ config PINCTRL_AT91
 	help
 	    The pinmux controller found on AT91 SoCs.
 
+config PINCTRL_BCM283X
+	bool "GPIO and pinmux support for BCM283X"
+	depends on ARCH_BCM283X
+	help
+	    The pinmux controller on BCM2835
+
 config PINCTRL_IMX_IOMUX_V1
 	bool
 	help
drivers/pinctrl/Makefile +1 -0
index 9450dbbdf..35b2d4707 100644
@@ -1,5 +1,6 @@
 obj-$(CONFIG_PINCTRL)	+= pinctrl.o
 obj-$(CONFIG_PINCTRL_AT91) += pinctrl-at91.o
+obj-$(CONFIG_PINCTRL_BCM283X)	+= pinctrl-bcm2835.o
 obj-$(CONFIG_PINCTRL_IMX_IOMUX_V1) += imx-iomux-v1.o
 obj-$(CONFIG_PINCTRL_IMX_IOMUX_V2) += imx-iomux-v2.o
 obj-$(CONFIG_PINCTRL_IMX_IOMUX_V3) += imx-iomux-v3.o
drivers/pinctrl/pinctrl-bcm2835.c renamed from drivers/gpio/gpio-bcm2835.c +0 -0
similarity index 100%
rename from drivers/gpio/gpio-bcm2835.c
rename to drivers/pinctrl/pinctrl-bcm2835.c
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
author
#4 lore raw

PATCH v2 4/8 pinctrl: bcm2835: register the pin controller.

In reply to Tomaz Solc

This adds hooks for the pin controller driver to the existing bcm2835_set_function().

---
 drivers/pinctrl/pinctrl-bcm2835.c | 52 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)
drivers/pinctrl/pinctrl-bcm2835.c +51 -1
index 1802ab7cc..5fd5740e8 100644
@@ -1,7 +1,9 @@
 /*
  * Author: Carlo Caione <[email protected]>
  *
- * Based on linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
+ * GPIO code based on linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
+ *
+ * pinctrl part added by Tomaz Solc <[email protected]>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -21,6 +23,7 @@
 #include <io.h>
 #include <gpio.h>
 #include <init.h>
+#include <pinctrl.h>
 
 #define GPIOFSEL(x)  (0x00+(x)*4)
 #define GPIOSET(x)   (0x1c+(x)*4)
@@ -46,6 +49,7 @@ enum {
 struct bcm2835_gpio_chip {
 	void __iomem *base;
 	struct gpio_chip chip;
+	struct pinctrl_device pctl;
 };
 
 static int bcm2835_set_function(struct gpio_chip *chip, unsigned gpio, int function)
@@ -110,6 +114,39 @@ static struct gpio_ops bcm2835_gpio_ops = {
 	.set = bcm2835_gpio_set_value,
 };
 
+static int bcm2835_pinctrl_set_state(struct pinctrl_device *pdev, struct device_node *np)
+{
+	const __be32 *list;
+	u32 function;
+	int i, size;
+
+	list = of_get_property(np, "brcm,pins", &size);
+	if (!list) {
+		return -EINVAL;
+	}
+
+	size /= sizeof(*list);
+
+	if (of_property_read_u32(np, "brcm,function", &function)) {
+		return -EINVAL;
+	}
+
+	for (i = 0; i < size; i++) {
+		int pin = be32_to_cpu(list[i]);
+		struct bcm2835_gpio_chip *bcmgpio = container_of(pdev, struct bcm2835_gpio_chip, pctl);
+
+		dev_dbg(pdev->dev, "set_state pin %d to function %d\n", pin, function);
+
+		bcm2835_set_function(&bcmgpio->chip, pin, function);
+	}
+
+	return 0;
+}
+
+static struct pinctrl_ops bcm2835_pinctrl_ops = {
+	.set_state = bcm2835_pinctrl_set_state,
+};
+
 static int bcm2835_gpio_probe(struct device_d *dev)
 {
 	struct resource *iores;
@@ -125,14 +162,27 @@ static int bcm2835_gpio_probe(struct device_d *dev)
 	bcmgpio->chip.base = 0;
 	bcmgpio->chip.ngpio = 54;
 	bcmgpio->chip.dev = dev;
+	bcmgpio->pctl.ops = &bcm2835_pinctrl_ops;
+	bcmgpio->pctl.dev = dev;
 
 	ret = gpiochip_add(&bcmgpio->chip);
 	if (ret) {
 		dev_err(dev, "couldn't add gpiochip, ret = %d\n", ret);
 		goto err;
 	}
+
 	dev_info(dev, "probed gpiochip%d with base %d\n", dev->id, bcmgpio->chip.base);
 
+	if (IS_ENABLED(CONFIG_PINCTRL)) {
+		ret = pinctrl_register(&bcmgpio->pctl);
+		if (ret) {
+			dev_err(dev, "couldn't add pinctrl, ret = %d\n", ret);
+			// don't free bcmgpio, since it's already used by gpiochip.
+		} else {
+			dev_dbg(dev, "bcm283x pinctrl registered\n");
+		}
+	}
+
 	return 0;
 
 err:
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
author
#5 lore raw

PATCH v2 5/8 mci: bcm2835: use device_initcall(), not coredev.

In reply to Tomaz Solc

pinctrl driver needs to be initialized before mci driver on Raspberry Pi. Otherwise the pinctrl device tree properties in the mci node are ignored. pinctrl is initialized by coredevice_initcall(), so moving mci-bcm2835 to device_initcall() ensures that it is initialized later.

There is no reason for mci-bcm2835 to use coredevice_initcall(). Other mci drivers already use device_initcall().

---
 drivers/mci/mci-bcm2835.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mci/mci-bcm2835.c +1 -1
index 9438e66af..e7dbb4f1d 100644
@@ -561,4 +561,4 @@ static int bcm2835_mci_add(void)
 {
 	return platform_driver_register(&bcm2835_mci_driver);
 }
-coredevice_initcall(bcm2835_mci_add);
+device_initcall(bcm2835_mci_add);
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
author
#6 lore raw

PATCH v2 6/8 mci: bcm2835: parse other device tree properties.

In reply to Tomaz Solc

The driver was missing a call to mci_of_parse() which fills in properties such as "bus-width", "no-sd" into the mci_host struct.

---
 drivers/mci/mci-bcm2835.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/mci/mci-bcm2835.c +3 -0
index e7dbb4f1d..2ed125167 100644
@@ -506,6 +506,9 @@ static int bcm2835_mci_probe(struct device_d *hw_dev)
 	host->mci.hw_dev = hw_dev;
 	host->hw_dev = hw_dev;
 	host->max_clock = clk_get_rate(clk);
+
+	mci_of_parse(&host->mci);
+
 	iores = dev_request_mem_resource(hw_dev, 0);
 	if (IS_ERR(iores)) {
 		dev_err(host->hw_dev, "Failed request mem region, aborting...\n");
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
author
#7 lore raw

PATCH v2 7/8 ARM: rpi: Add device tree for Compute Module 3.

In reply to Tomaz Solc

Compute Module needs "no-sd" property on the MMC interface otherwise mci-bcm2835 hangs on SD card probe.

---
 arch/arm/boards/raspberry-pi/lowlevel.c | 10 ++++++++++
 arch/arm/dts/Makefile                   |  1 +
 arch/arm/dts/bcm2837-rpi-cm3.dts        | 18 ++++++++++++++++++
 arch/arm/mach-bcm283x/Kconfig           |  6 ++++++
 images/Makefile.bcm283x                 |  6 +++++-
 5 files changed, 40 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/bcm2837-rpi-cm3.dts
arch/arm/boards/raspberry-pi/lowlevel.c +10 -0
index 34c935092..1a3d39421 100644
@@ -33,3 +33,13 @@ ENTRY_FUNCTION(start_raspberry_pi3, r0, r1, r2)
 
 	barebox_arm_entry(BCM2835_SDRAM_BASE, SZ_512M, fdt);
 }
+
+extern char __dtb_bcm2837_rpi_cm3_start[];
+ENTRY_FUNCTION(start_raspberry_pi_cm3, r0, r1, r2)
+{
+	void *fdt = __dtb_bcm2837_rpi_cm3_start + get_runtime_offset();
+
+	arm_cpu_lowlevel_init();
+
+	barebox_arm_entry(BCM2835_SDRAM_BASE, SZ_512M, fdt);
+}
arch/arm/dts/Makefile +1 -0
index 3cdee1ffb..82595f9b7 100644
@@ -75,6 +75,7 @@ pbl-dtb-$(CONFIG_MACH_REALQ7) += imx6q-dmo-edmqmx6.dtb.o
 pbl-dtb-$(CONFIG_MACH_RPI) += bcm2835-rpi.dtb.o
 pbl-dtb-$(CONFIG_MACH_RPI2) += bcm2836-rpi-2.dtb.o
 pbl-dtb-$(CONFIG_MACH_RPI3) += bcm2837-rpi-3.dtb.o
+pbl-dtb-$(CONFIG_MACH_RPI_CM3) += bcm2837-rpi-cm3.dtb.o
 pbl-dtb-$(CONFIG_MACH_SABRELITE) += imx6q-sabrelite.dtb.o imx6dl-sabrelite.dtb.o
 pbl-dtb-$(CONFIG_MACH_SABRESD) += imx6q-sabresd.dtb.o
 pbl-dtb-$(CONFIG_MACH_FREESCALE_IMX6SX_SABRESDB) += imx6sx-sdb.dtb.o
arch/arm/dts/bcm2837-rpi-cm3.dts new file +18 -0
new file mode 100644
index 000000000..cfbffe175
@@ -0,0 +1,18 @@
+#include <arm/bcm2837-rpi-cm3-io3.dts>
+
+/ {
+	chosen {
+		stdout-path = &uart0;
+	};
+
+	memory {
+		reg = <0x0 0x0>;
+	};
+};
+
+&sdhci {
+	pinctrl-0 = <&emmc_gpio48>;
+	no-sd;
+	non-removable;
+	status = "okay";
+};
arch/arm/mach-bcm283x/Kconfig +6 -0
index af2f88c47..bb5f75dc9 100644
@@ -25,6 +25,12 @@ config MACH_RPI3
 	select MACH_RPI_COMMON
 	select ARM_SECURE_MONITOR
 
+config MACH_RPI_CM3
+	bool "RaspberryPi Compute Module 3 (BCM2837/CORTEX-A53)"
+	select CPU_V7
+	select MACH_RPI_COMMON
+	select ARM_SECURE_MONITOR
+
 endmenu
 
 config MACH_RPI_DEBUG_UART_BASE
images/Makefile.bcm283x +5 -1
index 9199f153d..3fd2c3d06 100644
@@ -12,4 +12,8 @@ image-$(CONFIG_MACH_RPI2) += barebox-raspberry-pi-2.img
 
 pblb-$(CONFIG_MACH_RPI3) += start_raspberry_pi3
 FILE_barebox-raspberry-pi-3.img = start_raspberry_pi3.pblb
-image-$(CONFIG_MACH_RPI3) += barebox-raspberry-pi-3.img
\ No newline at end of file
+image-$(CONFIG_MACH_RPI3) += barebox-raspberry-pi-3.img
+
+pblb-$(CONFIG_MACH_RPI_CM3) += start_raspberry_pi_cm3
+FILE_barebox-raspberry-pi-cm3.img = start_raspberry_pi_cm3.pblb
+image-$(CONFIG_MACH_RPI_CM3) += barebox-raspberry-pi-cm3.img
\ No newline at end of file
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
author
#8 lore raw

PATCH v2 8/8 ARM: rpi: add CONFIG_PINCTRL to rpi_defconfig.

In reply to Tomaz Solc

Required for emmc pin function switching on Raspberry Pi 3.

---
 arch/arm/configs/rpi_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/configs/rpi_defconfig +1 -1
index 35943e025..f167625c9 100644
@@ -71,8 +71,8 @@ CONFIG_LED_GPIO=y
 CONFIG_LED_TRIGGERS=y
 CONFIG_WATCHDOG=y
 CONFIG_WATCHDOG_BCM2835=y
+CONFIG_PINCTRL=y
 CONFIG_PINCTRL_BCM283X=y
-# CONFIG_PINCTRL is not set
 CONFIG_REGULATOR=y
 CONFIG_FS_EXT4=y
 CONFIG_FS_FAT=y
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#9 lore raw
In reply to Tomaz Solc
Quoted 12 lines · Tomaz Solc

Changes from the first patch series:

- Base Compute Module 3 device tree off upstream device tree for CM3 + IO3 dev board, instead of R. Pi 3B.
- Keep Makefile.bcm283x without a newline at the end of file.
- Make mci init before pinctrl by moving mci-bcm2835 to device_initcall() instead of changing link order.
- Add CONFIG_PINCTRL to rpi_defconfig.

Best regards
Tomaz

Quoted 9 lines

Tomaz Solc (8):
ARM: rpi: switch emmc from sdhost to sdhci
Kconfig: add pin controllers submenu.
pinctrl: bcm2835: move existing code from gpio.
pinctrl: bcm2835: register the pin controller.
mci: bcm2835: use device_initcall(), not coredev.
mci: bcm2835: parse other device tree properties.
ARM: rpi: Add device tree for Compute Module 3.
ARM: rpi: add CONFIG_PINCTRL to rpi_defconfig.

Applied, thanks

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox