Skip to contentSkip to conversation

MMC: add driver for Amlogic GXBB SoCs

PATCH Superseded Kevin Hilman 3 participants 5 messages Sep 14, 2016 – Oct 18, 2016

Subsystems (3)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Kevin Hilman

author maintainer
#0 lore raw

v3 cover MMC: add driver for Amlogic GXBB SoCs

Here's an updated series for the Amlogic MMC driver.

Changes since v2:
- rework voltage regulator support
- drop read/write accessor macros
- drop descriptor struct (had endian issues)
- fix big-endian support, and tested big-endian build

This version is included in the v4.8/integ branch of my git tree
https://git.kernel.org/cgit/linux/kernel/git/khilman/linux-amlogic.git/

Also some RFC quetsions:

I think this is the exact same IP on the GXL family of SoC, so I'm thinking about renaming all occurances of GXBB to just GX. We can have compatibles to match meson-gxbb and meson-gxl etc. though.

Thoughts?

Kevin Hilman (2):
MMC: meson: initial support for GXBB platforms
ARM64: dts: meson-gxbb: add MMC support

 .../devicetree/bindings/mmc/amlogic,meson-gxbb.txt |  29 +
 MAINTAINERS                                        |   1 +
 .../arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts |  87 +++
 arch/arm64/boot/dts/amlogic/meson-gxbb-p20x.dtsi   |  78 ++
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi        |  37 +-
 drivers/mmc/host/Kconfig                           |  10 +
 drivers/mmc/host/Makefile                          |   1 +
 drivers/mmc/host/meson-gxbb.c                      | 838 +++++++++++++++++++++
 8 files changed, 1080 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/mmc/amlogic,meson-gxbb.txt
 create mode 100644 drivers/mmc/host/meson-gxbb.c
Signature · 1 line
2.9.3
author maintainer
#1 lore raw

PATCH v3 1/2 MMC: meson: initial support for GXBB platforms

Initial support for the SD/eMMC controller in the Amlogic S905/GXBB family of SoCs.

Currently working for the SD and eMMC interfaces, but not yet tested for SDIO.

---
 MAINTAINERS                   |   1 +
 drivers/mmc/host/Kconfig      |  10 +
 drivers/mmc/host/Makefile     |   1 +
 drivers/mmc/host/meson-gxbb.c | 838 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 850 insertions(+)
 create mode 100644 drivers/mmc/host/meson-gxbb.c
MAINTAINERS +1 -0
index 20bb1d00098c..c4dd5b2a346d 100644
@@ -999,6 +999,7 @@ F:	arch/arm/mach-meson/
 F:	arch/arm/boot/dts/meson*
 F:	arch/arm64/boot/dts/amlogic/
 F: 	drivers/pinctrl/meson/
+F:	drivers/mmc/host/meson*
 N:	meson
 
 ARM/Annapurna Labs ALPINE ARCHITECTURE
drivers/mmc/host/Kconfig +10 -0
index 5274f503a39a..d3b3a08c2361 100644
@@ -322,6 +322,16 @@ config MMC_SDHCI_IPROC
 
 	  If unsure, say N.
 
+config MMC_MESON_GXBB
+	tristate "Amlogic S905/GXBB SD/MMC Host Controller support"
+	depends on ARCH_MESON && MMC
+	help
+	  This selects support for the Amlogic SD/MMC Host Controller
+	  found on the S905/GXBB family of SoCs.  This controller is
+	  MMC 5.1 compliant and supports SD, eMMC and SDIO interfaces.
+
+	  If you have a controller with this interface, say Y here.
+
 config MMC_MOXART
 	tristate "MOXART SD/MMC Host Controller support"
 	depends on ARCH_MOXART && MMC
drivers/mmc/host/Makefile +1 -0
index e2bdaaf43184..fef21586b4fb 100644
@@ -53,6 +53,7 @@ obj-$(CONFIG_MMC_JZ4740)	+= jz4740_mmc.o
 obj-$(CONFIG_MMC_VUB300)	+= vub300.o
 obj-$(CONFIG_MMC_USHC)		+= ushc.o
 obj-$(CONFIG_MMC_WMT)		+= wmt-sdmmc.o
+obj-$(CONFIG_MMC_MESON_GXBB)	+= meson-gxbb.o
 obj-$(CONFIG_MMC_MOXART)	+= moxart-mmc.o
 obj-$(CONFIG_MMC_SUNXI)		+= sunxi-mmc.o
 obj-$(CONFIG_MMC_USDHI6ROL0)	+= usdhi6rol0.o
drivers/mmc/host/meson-gxbb.c new file +838 -0

838 lines not on this page · raw message

Signature · 1 line
2.9.3
#2 lore raw

PATCH v3 1/2 MMC: meson: initial support for GXBB platforms

[...]

Quoted 16 lines
drivers/mmc/host/meson-gxbb.c new file +16 -0
+static int meson_mmc_clk_set(struct meson_host *host, unsigned long clk_rate)
+{
+       struct mmc_host *mmc = host->mmc;
+       int ret = 0;
+       u32 cfg;
+
+       if (clk_rate) {
+               if (WARN_ON(clk_rate > mmc->f_max))
+                       clk_rate = mmc->f_max;
+               else if (WARN_ON(clk_rate < mmc->f_min))
+                       clk_rate = mmc->f_min;
+       }
+
+       if (clk_rate == mmc->actual_clock)
+               return 0;
+

drivers/mmc/host/meson-gxbb.c line 203

Quoted 10 lines
drivers/mmc/host/meson-gxbb.c new file +10 -0
+       /* stop clock */
+       cfg = readl(host->regs + SD_EMMC_CFG);
+       if (!(cfg & CFG_STOP_CLOCK)) {
+               cfg |= CFG_STOP_CLOCK;
+               writel(cfg, host->regs + SD_EMMC_CFG);
+       }
+
+       dev_dbg(host->dev, "change clock rate %u -> %lu\n",
+               mmc->actual_clock, clk_rate);
+       ret = clk_set_rate(host->cfg_div_clk, clk_rate);

Shouldn't you check the error before proceeding?

Quoted 107 lines
drivers/mmc/host/meson-gxbb.c new file +107 -0
+       if (clk_rate && clk_rate != clk_get_rate(host->cfg_div_clk))
+               dev_warn(host->dev, "divider requested rate %lu != actual rate %lu: ret=%d\n",
+                        clk_rate, clk_get_rate(host->cfg_div_clk), ret);
+       else
+               mmc->actual_clock = clk_rate;
+
+       /* (re)start clock, if non-zero */
+       if (clk_rate) {
+               cfg = readl(host->regs + SD_EMMC_CFG);
+               cfg &= ~CFG_STOP_CLOCK;
+               writel(cfg, host->regs + SD_EMMC_CFG);
+       }
+
+       return ret;
+}
+
+/*
+ * The SD/eMMC IP block has an internal mux and divider used for
+ * generating the MMC clock.  Use the clock framework to create and
+ * manage these clocks.
+ */
+static int meson_mmc_clk_init(struct meson_host *host)
+{
+       struct clk_init_data init;
+       char clk_name[32];
+       int i, ret = 0;
+       const char *mux_parent_names[MUX_CLK_NUM_PARENTS];
+       unsigned int mux_parent_count = 0;
+       const char *clk_div_parents[1];
+       unsigned int f_min = UINT_MAX;
+       u32 clk_reg, cfg;
+
+       /* get the mux parents */
+       for (i = 0; i < MUX_CLK_NUM_PARENTS; i++) {
+               char name[16];
+
+               snprintf(name, sizeof(name), "clkin%d", i);
+               host->mux_parent[i] = devm_clk_get(host->dev, name);
+               if (IS_ERR(host->mux_parent[i])) {
+                       ret = PTR_ERR(host->mux_parent[i]);
+                       if (PTR_ERR(host->mux_parent[i]) != -EPROBE_DEFER)
+                               dev_err(host->dev, "Missing clock %s\n", name);
+                       host->mux_parent[i] = NULL;
+                       return ret;
+               }
+
+               host->mux_parent_rate[i] = clk_get_rate(host->mux_parent[i]);
+               mux_parent_names[i] = __clk_get_name(host->mux_parent[i]);
+               mux_parent_count++;
+               if (host->mux_parent_rate[i] < f_min)
+                       f_min = host->mux_parent_rate[i];
+       }
+
+       /* cacluate f_min based on input clocks, and max divider value */
+       if (f_min != UINT_MAX)
+               f_min = DIV_ROUND_UP(CLK_SRC_XTAL_RATE, CLK_DIV_MAX);
+       else
+               f_min = 4000000;  /* default min: 400 MHz */
+       host->mmc->f_min = f_min;
+
+       /* create the mux */
+       snprintf(clk_name, sizeof(clk_name), "%s#mux", dev_name(host->dev));
+       init.name = clk_name;
+       init.ops = &clk_mux_ops;
+       init.flags = 0;
+       init.parent_names = mux_parent_names;
+       init.num_parents = mux_parent_count;
+
+       host->mux.reg = host->regs + SD_EMMC_CLOCK;
+       host->mux.shift = CLK_SRC_SHIFT;
+       host->mux.mask = CLK_SRC_MASK;
+       host->mux.flags = 0;
+       host->mux.table = NULL;
+       host->mux.hw.init = &init;
+
+       host->mux_clk = devm_clk_register(host->dev, &host->mux.hw);
+       if (WARN_ON(IS_ERR(host->mux_clk)))
+               return PTR_ERR(host->mux_clk);
+
+       /* create the divider */
+       snprintf(clk_name, sizeof(clk_name), "%s#div", dev_name(host->dev));
+       init.name = devm_kstrdup(host->dev, clk_name, GFP_KERNEL);
+       init.ops = &clk_divider_ops;
+       init.flags = CLK_SET_RATE_PARENT;
+       clk_div_parents[0] = __clk_get_name(host->mux_clk);
+       init.parent_names = clk_div_parents;
+       init.num_parents = ARRAY_SIZE(clk_div_parents);
+
+       host->cfg_div.reg = host->regs + SD_EMMC_CLOCK;
+       host->cfg_div.shift = CLK_DIV_SHIFT;
+       host->cfg_div.width = CLK_DIV_WIDTH;
+       host->cfg_div.hw.init = &init;
+       host->cfg_div.flags = CLK_DIVIDER_ONE_BASED |
+               CLK_DIVIDER_ROUND_CLOSEST | CLK_DIVIDER_ALLOW_ZERO;
+
+       host->cfg_div_clk = devm_clk_register(host->dev, &host->cfg_div.hw);
+       if (WARN_ON(PTR_ERR_OR_ZERO(host->cfg_div_clk)))
+               return PTR_ERR(host->cfg_div_clk);
+
+       /* init SD_EMMC_CLOCK to sane defaults w/min clock rate */
+       clk_reg = 0;
+       clk_reg |= CLK_PHASE_180 << CLK_PHASE_SHIFT;
+       clk_reg |= CLK_SRC_XTAL << CLK_SRC_SHIFT;
+       clk_reg |= CLK_DIV_MAX << CLK_DIV_SHIFT;
+       clk_reg &= ~CLK_ALWAYS_ON;
+       writel(clk_reg, host->regs + SD_EMMC_CLOCK);
+

drivers/mmc/host/meson-gxbb.c line 320

Quoted 10 lines
drivers/mmc/host/meson-gxbb.c new file +10 -0
+       /* Ensure clock starts in "auto" mode, not "always on" */
+       cfg = readl(host->regs + SD_EMMC_CFG);
+       cfg &= ~CFG_CLK_ALWAYS_ON;
+       cfg |= CFG_AUTO_CLK;
+       writel(cfg, host->regs + SD_EMMC_CFG);
+
+       ret = clk_prepare_enable(host->cfg_div_clk);
+       if (!ret)
+               ret = meson_mmc_clk_set(host, f_min);
+

In case of errors, I guess you should disable/unprepare the clock.

Quoted 3 lines
drivers/mmc/host/meson-gxbb.c new file +3 -0
+       return ret;
+}
+

[...]

Quoted 19 lines
drivers/mmc/host/meson-gxbb.c new file +19 -0
+
+static int meson_mmc_probe(struct platform_device *pdev)
+{
+       struct resource *res;
+       struct meson_host *host;
+       struct mmc_host *mmc;
+       int ret;
+
+       mmc = mmc_alloc_host(sizeof(struct meson_host), &pdev->dev);
+       if (!mmc)
+               return -ENOMEM;
+       host = mmc_priv(mmc);
+       host->mmc = mmc;
+       host->dev = &pdev->dev;
+       dev_set_drvdata(&pdev->dev, host);
+
+       spin_lock_init(&host->lock);
+
+       host->core_clk = devm_clk_get(&pdev->dev, "core");

drivers/mmc/host/meson-gxbb.c line 727

Quoted 10 lines
drivers/mmc/host/meson-gxbb.c new file +10 -0
+       if (IS_ERR(host->core_clk)) {
+               ret = PTR_ERR(host->core_clk);
+               goto free_host;
+       }
+
+       /* Get regulators and the supported OCR mask */
+       host->vqmmc_enabled = false;
+       ret = mmc_regulator_get_supply(mmc);
+       if (ret == -EPROBE_DEFER)
+               goto free_host;

In free_host you call clk_disable_unprepare(). You don't want to do that unless you already called clk_prepare_enable().

So, I think you need another label to distinguish between these two cases.

Quoted 31 lines
drivers/mmc/host/meson-gxbb.c new file +31 -0
+
+       ret = mmc_of_parse(mmc);
+       if (ret) {
+               dev_warn(&pdev->dev, "error parsing DT: %d\n", ret);
+               goto free_host;
+       }
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       host->regs = devm_ioremap_resource(&pdev->dev, res);
+       if (IS_ERR(host->regs)) {
+               ret = PTR_ERR(host->regs);
+               goto free_host;
+       }
+
+       host->irq = platform_get_irq(pdev, 0);
+       if (host->irq == 0) {
+               dev_err(&pdev->dev, "failed to get interrupt resource.\n");
+               ret = -EINVAL;
+               goto free_host;
+       }
+
+       ret = clk_prepare_enable(host->core_clk);
+       if (ret)
+               goto free_host;
+
+       ret = meson_mmc_clk_init(host);
+       if (ret)
+               goto free_host;
+
+       /* Stop execution */
+       writel(0, host->regs + SD_EMMC_START);

drivers/mmc/host/meson-gxbb.c line 768

Quoted 10 lines
drivers/mmc/host/meson-gxbb.c new file +10 -0
+
+       /* clear, ack, enable all interrupts */
+       writel(0, host->regs + SD_EMMC_IRQ_EN);
+       writel(IRQ_EN_MASK, host->regs + SD_EMMC_STATUS);
+
+       ret = devm_request_threaded_irq(&pdev->dev, host->irq,
+                                       meson_mmc_irq, meson_mmc_irq_thread,
+                                       IRQF_SHARED, DRIVER_NAME, host);
+       if (ret)
+               goto free_host;

Besides the earlier issue mentiond for the label free_host, here you also need to consider yet another clock that has be been enabled in meson_mmc_clk_init(). I assume you want to disable this clock in the error path.

Quoted 9 lines
drivers/mmc/host/meson-gxbb.c new file +9 -0
+
+       /* data bounce buffer */
+       host->bounce_buf_size = SZ_512K;
+       host->bounce_buf =
+               dma_alloc_coherent(host->dev, host->bounce_buf_size,
+                                  &host->bounce_dma_addr, GFP_KERNEL);
+       if (host->bounce_buf == NULL) {
+               dev_err(host->dev, "Unable to map allocate DMA bounce buffer.\n");
+               ret = -ENOMEM;

drivers/mmc/host/meson-gxbb.c line 787

Quoted 10 lines
drivers/mmc/host/meson-gxbb.c new file +10 -0
+               goto free_host;
+       }
+
+       mmc->ops = &meson_mmc_ops;
+       mmc_add_host(mmc);
+
+       return 0;
+
+free_host:
+       dev_dbg(host->dev, "Failed to probe: ret=%d\n", ret);

No need to print this, already managed by driver core.

Quoted 1 line

+ if (host->core_clk)

No need to check above, already done by the clock framework.

Quoted 7 lines
drivers/mmc/host/meson-gxbb.c new file +7 -0
+               clk_disable_unprepare(host->core_clk);
+       mmc_free_host(mmc);
+       return ret;
+}
+
+static int meson_mmc_remove(struct platform_device *pdev)
+{

drivers/mmc/host/meson-gxbb.c line 805

Quoted 10 lines
drivers/mmc/host/meson-gxbb.c new file +10 -0
+       struct meson_host *host = dev_get_drvdata(&pdev->dev);
+
+       if (WARN_ON(!host))
+               return 0;
+
+       if (host->bounce_buf)
+               dma_free_coherent(host->dev, host->bounce_buf_size,
+                                 host->bounce_buf, host->bounce_dma_addr);
+
+       if (host->cfg_div_clk)

No need to check this, aleady done by the clock framework.

drivers/mmc/host/meson-gxbb.c line 808

Quoted 3 lines
drivers/mmc/host/meson-gxbb.c new file +3 -0
+               clk_disable_unprepare(host->cfg_div_clk);
+
+       if (host->core_clk)

Ditto.

drivers/mmc/host/meson-gxbb.c line 814

Quoted 6 lines
drivers/mmc/host/meson-gxbb.c new file +6 -0
+               clk_disable_unprepare(host->core_clk);
+
+       mmc_free_host(host->mmc);
+       return 0;
+}
+

[...]

Besides the minor stuff pointed out above, this looks great to me!

Before you re-spin, please drop this series from your branch which is being integrated into linux-next, as otherwise I can't pick it up.

Kind regards
Uffe

author maintainer
#3 lore raw

PATCH v3 2/2 ARM64: dts: meson-gxbb: add MMC support

In reply to Kevin Hilman

Add binding and basic support for the SD/eMMC controller on Amlogic S905/GXBB devices.

---
 .../devicetree/bindings/mmc/amlogic,meson-gxbb.txt | 29 ++++++++
 .../arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts | 87 ++++++++++++++++++++++
 arch/arm64/boot/dts/amlogic/meson-gxbb-p20x.dtsi   | 78 +++++++++++++++++++
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi        | 37 ++++++++-
 4 files changed, 230 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/mmc/amlogic,meson-gxbb.txt
Documentation/devicetree/bindings/mmc/amlogic,meson-gxbb.txt new file +29 -0
new file mode 100644
index 000000000000..39cbe528b7de
@@ -0,0 +1,29 @@
+Amlogic SD / eMMC controller for S905/GXBB family SoCs
+
+The MMC 5.1 compliant host controller on Amlogic provides the
+interface for SD, eMMC and SDIO devices.
+
+This file documents the properties in addition to those available in
+the MMC core bindings, documented by mmc.txt.
+
+Required properties:
+- compatible : contains "amlogic,meson-gxbb-mmc"
+- clocks     : A list of phandle + clock-specifier pairs for the clocks listed in clock-names.
+- clock-names: Should contain the following:
+	"core" - Main peripheral bus clock
+	"clkin0" - Parent clock of internal mux
+	"clkin1" - Other parent clock of internal mux
+  The driver has an interal mux clock which switches between clkin0 and clkin1 depending on the
+  clock rate requested by the MMC core.
+
+Example:
+
+	sd_emmc_a: mmc at 70000 {
+        	compatible = "amlogic,meson-gxbb-mmc";
+		reg = <0x0 0x70000 0x0 0x2000>;
+                interrupts = < GIC_SPI 216 IRQ_TYPE_EDGE_RISING>;
+		clocks = <&clkc CLKID_SD_EMMC_A>, <&xtal>, <&clkc CLKID_FCLK_DIV2>;
+		clock-names = "core", "clkin0", "clkin1";
+		pinctrl-0 = <&emmc_pins>;
+	};
+
arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts +87 -0

96 lines not on this page · raw message

arch/arm64/boot/dts/amlogic/meson-gxbb-p20x.dtsi +78 -0

87 lines not on this page · raw message

arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi +36 -1
index e502c24b0ac7..3723007146ac 100644
@@ -45,6 +45,7 @@
 #include <dt-bindings/interrupt-controller/arm-gic.h>
 #include <dt-bindings/gpio/meson-gxbb-gpio.h>
 #include <dt-bindings/reset/amlogic,meson-gxbb-reset.h>
+#include <dt-bindings/clock/gxbb-clkc.h>
 
 / {
 	compatible = "amlogic,meson-gxbb";
@@ -246,7 +247,8 @@
 					mux {
 						groups = "emmc_nand_d07",
 						       "emmc_cmd",
-						       "emmc_clk";
+						       "emmc_clk",
+						       "emmc_ds";
 						function = "emmc";
 					};
 				};
@@ -329,6 +331,39 @@
 			#address-cells = <2>;
 			#size-cells = <2>;
 			ranges = <0x0 0x0 0x0 0xd0000000 0x0 0x200000>;
+
+			sd_emmc_a: mmc at 70000 {
+				compatible = "amlogic,meson-gxbb-mmc";
+				reg = <0x0 0x70000 0x0 0x2000>;
+				interrupts = <GIC_SPI 216 IRQ_TYPE_EDGE_RISING>;
+				clocks = <&clkc CLKID_SD_EMMC_A>,
+					 <&xtal>,
+					 <&clkc CLKID_FCLK_DIV2>;
+				clock-names = "core", "clkin0", "clkin1";
+				status = "disabled";
+			};
+
+			sd_emmc_b: mmc at 72000 {
+				compatible = "amlogic,meson-gxbb-mmc";
+				reg = <0x0 0x72000 0x0 0x2000>;
+				interrupts = <GIC_SPI 217 IRQ_TYPE_EDGE_RISING>;
+				clocks = <&clkc CLKID_SD_EMMC_B>,
+					 <&xtal>,
+					 <&clkc CLKID_FCLK_DIV2>;
+				clock-names = "core", "clkin0", "clkin1";
+				status = "disabled";
+			};
+
+			sd_emmc_c: mmc at 74000 {
+				compatible = "amlogic,meson-gxbb-mmc";
+				reg = <0x0 0x74000 0x0 0x2000>;
+				interrupts = <GIC_SPI 218 IRQ_TYPE_EDGE_RISING>;
+				clocks = <&clkc CLKID_SD_EMMC_C>,
+					 <&xtal>,
+					 <&clkc CLKID_FCLK_DIV2>;
+				clock-names = "core", "clkin0", "clkin1";
+				status = "disabled";
+			};
 		};
 
 		ethmac: ethernet at c9410000 {
Signature · 1 line
2.9.3
maintainer
#4 lore raw

PATCH v3 2/2 ARM64: dts: meson-gxbb: add MMC support

Quoted 11 lines · Kevin Hilman

Add binding and basic support for the SD/eMMC controller on Amlogic S905/GXBB devices.

---
 .../devicetree/bindings/mmc/amlogic,meson-gxbb.txt | 29 ++++++++
 .../arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts | 87 ++++++++++++++++++++++
 arch/arm64/boot/dts/amlogic/meson-gxbb-p20x.dtsi   | 78 +++++++++++++++++++
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi        | 37 ++++++++-
 4 files changed, 230 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/mmc/amlogic,meson-gxbb.txt

Some nits below, otherwise:

Quoted 41 lines
Documentation/devicetree/bindings/mmc/amlogic,meson-gxbb.txt new file +29 -0
new file mode 100644
index 000000000000..39cbe528b7de
@@ -0,0 +1,29 @@
+Amlogic SD / eMMC controller for S905/GXBB family SoCs
+
+The MMC 5.1 compliant host controller on Amlogic provides the
+interface for SD, eMMC and SDIO devices.
+
+This file documents the properties in addition to those available in
+the MMC core bindings, documented by mmc.txt.
+
+Required properties:
+- compatible : contains "amlogic,meson-gxbb-mmc"
+- clocks     : A list of phandle + clock-specifier pairs for the clocks listed in clock-names.
+- clock-names: Should contain the following:
+	"core" - Main peripheral bus clock
+	"clkin0" - Parent clock of internal mux
+	"clkin1" - Other parent clock of internal mux
+  The driver has an interal mux clock which switches between clkin0 and clkin1 depending on the
+  clock rate requested by the MMC core.
+
+Example:
+
+	sd_emmc_a: mmc at 70000 {
+        	compatible = "amlogic,meson-gxbb-mmc";
+		reg = <0x0 0x70000 0x0 0x2000>;
+                interrupts = < GIC_SPI 216 IRQ_TYPE_EDGE_RISING>;
+		clocks = <&clkc CLKID_SD_EMMC_A>, <&xtal>, <&clkc CLKID_FCLK_DIV2>;
+		clock-names = "core", "clkin0", "clkin1";
+		pinctrl-0 = <&emmc_pins>;
+	};
+
arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts +0 -0
index 90a84c514d3d..2a9303e7fab8 100644

arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts line 77

Quoted 5 lines
arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts +2 -0
@@ -73,6 +73,56 @@
 			default-state = "off";
 		};
 	};
+
+	tflash_vdd: regulator-tflash_vdd {

Use '-' not '_' in node names.

Quoted 4 lines
arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts +4 -0
+		/*
+		 * signal name from schematics: TFLASH_VDD_EN
+		 */
+		compatible = "regulator-fixed";

arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts line 91

Quoted 10 lines
arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts +10 -0
+
+		regulator-name = "TFLASH_VDD";
+		regulator-min-microvolt = <3300000>;
+		regulator-max-microvolt = <3300000>;
+
+		gpio = <&gpio_ao GPIOAO_12 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+
+	tf_io: gpio-regulator-tf_io {

ditto

Quoted 93 lines
arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts +71 -0
+		compatible = "regulator-gpio";
+
+		regulator-name = "TF_IO";
+		regulator-min-microvolt = <1800000>;
+		regulator-max-microvolt = <3300000>;
+
+		/*
+		 * signal name from schematics: TF_3V3N_1V8_EN
+		 */
+		gpios = <&gpio_ao GPIOAO_3 GPIO_ACTIVE_HIGH>;
+		gpios-states = <0>;
+
+		states = <3300000 0
+			  1800000 1>;
+	};
+
+	vcc1v8: regulator-vcc1v8 {
+		compatible = "regulator-fixed";
+		regulator-name = "VCC1V8";
+		regulator-min-microvolt = <1800000>;
+		regulator-max-microvolt = <1800000>;
+	};
+
+	vcc3v3: regulator-vcc3v3 {
+		compatible = "regulator-fixed";
+		regulator-name = "VCC3V3";
+		regulator-min-microvolt = <3300000>;
+		regulator-max-microvolt = <3300000>;
+	};
+
+	emmc_pwrseq: emmc-pwrseq {
+		compatible = "mmc-pwrseq-emmc";
+		reset-gpios = <&gpio BOOT_9 GPIO_ACTIVE_LOW>;
+	};
 };
 
 &uart_AO {
@@ -87,3 +137,40 @@
 	pinctrl-names = "default";
 };
 
+/* SD */
+&sd_emmc_b {
+	status = "okay";
+	pinctrl-0 = <&sdcard_pins>;
+	pinctrl-names = "default";
+
+	bus-width = <4>;
+	cap-sd-highspeed;
+	max-frequency = <100000000>;
+	disable-wp;
+
+	cd-gpios = <&gpio CARD_6 GPIO_ACTIVE_HIGH>;
+	cd-inverted;
+
+	vmmc-supply = <&tflash_vdd>;
+	vqmmc-supply = <&tf_io>;
+};
+
+/* eMMC */
+&sd_emmc_c {
+	status = "okay";
+	pinctrl-0 = <&emmc_pins>;
+	pinctrl-names = "default";
+
+	bus-width = <8>;
+	cap-sd-highspeed;
+	max-frequency = <200000000>;
+	non-removable;
+	disable-wp;
+	cap-mmc-highspeed;
+	mmc-ddr-1_8v;
+	mmc-hs200-1_8v;
+
+	mmc-pwrseq = <&emmc_pwrseq>;
+	vmmc-supply = <&vcc3v3>;
+	vqmmc-supply = <&vcc1v8>;
+};
arch/arm64/boot/dts/amlogic/meson-gxbb-p20x.dtsi +7 -0
index f4f30f674b4c..77c4d5eb48a2 100644
@@ -57,6 +57,47 @@
 		device_type = "memory";
 		reg = <0x0 0x0 0x0 0x40000000>;
 	};
+
+	vddio_card: gpio-regulator {
+		compatible = "regulator-gpio";
+
+		regulator-name = "VDDIO_CARD";
+		regulator-min-microvolt = <1800000>;
+		regulator-max-microvolt = <3300000>;

arch/arm64/boot/dts/amlogic/meson-gxbb-p20x.dtsi line 76

Quoted 10 lines
arch/arm64/boot/dts/amlogic/meson-gxbb-p20x.dtsi +10 -0
+
+		gpios = <&gpio_ao GPIOAO_5 GPIO_ACTIVE_HIGH>;
+		gpios-states = <1>;
+
+		/* Based on P200 schematics, signal CARD_1.8V/3.3V_CTR */
+		states = <1800000 0
+			  3300000 1>;
+	};
+
+	vddio_boot: regulator-vddio_boot {

ditto

arch/arm64/boot/dts/amlogic/meson-gxbb-p20x.dtsi line 83

Quoted 7 lines
arch/arm64/boot/dts/amlogic/meson-gxbb-p20x.dtsi +7 -0
+		compatible = "regulator-fixed";
+		regulator-name = "VDDIO_BOOT";
+		regulator-min-microvolt = <1800000>;
+		regulator-max-microvolt = <1800000>;
+	};
+
+	vddao_3v3: regulator-vddao_3v3 {

ditto

arch/arm64/boot/dts/amlogic/meson-gxbb-p20x.dtsi line 90

Quoted 7 lines
arch/arm64/boot/dts/amlogic/meson-gxbb-p20x.dtsi +7 -0
+		compatible = "regulator-fixed";
+		regulator-name = "VDDAO_3V3";
+		regulator-min-microvolt = <3300000>;
+		regulator-max-microvolt = <3300000>;
+	};
+
+	vcc_3v3: regulator-vcc_3v3 {

ditto

Quoted 119 lines
arch/arm64/boot/dts/amlogic/meson-gxbb-p20x.dtsi +47 -0
+		compatible = "regulator-fixed";
+		regulator-name = "VCC_3V3";
+		regulator-min-microvolt = <3300000>;
+		regulator-max-microvolt = <3300000>;
+	};
+
+	emmc_pwrseq: emmc-pwrseq {
+		compatible = "mmc-pwrseq-emmc";
+		reset-gpios = <&gpio BOOT_9 GPIO_ACTIVE_LOW>;
+	};
 };
 
 /* This UART is brought out to the DB9 connector */
@@ -72,3 +113,40 @@
 	pinctrl-names = "default";
 };
 
+/* SD card */
+&sd_emmc_b {
+	status = "okay";
+	pinctrl-0 = <&sdcard_pins>;
+	pinctrl-names = "default";
+
+	bus-width = <4>;
+	cap-sd-highspeed;
+	max-frequency = <100000000>;
+	disable-wp;
+
+	cd-gpios = <&gpio CARD_6 GPIO_ACTIVE_HIGH>;
+	cd-inverted;
+
+	vmmc-supply = <&vddao_3v3>;
+	vqmmc-supply = <&vddio_card>;
+};
+
+/* eMMC */
+&sd_emmc_c {
+	status = "okay";
+	pinctrl-0 = <&emmc_pins>;
+	pinctrl-names = "default";
+
+	bus-width = <8>;
+	cap-sd-highspeed;
+	cap-mmc-highspeed;
+	max-frequency = <200000000>;
+	non-removable;
+	disable-wp;
+	mmc-ddr-1_8v;
+	mmc-hs200-1_8v;
+
+	mmc-pwrseq = <&emmc_pwrseq>;
+	vmmc-supply = <&vcc_3v3>;
+	vqmmc-supply = <&vddio_boot>;
+};
arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi +36 -1
index e502c24b0ac7..3723007146ac 100644
@@ -45,6 +45,7 @@
 #include <dt-bindings/interrupt-controller/arm-gic.h>
 #include <dt-bindings/gpio/meson-gxbb-gpio.h>
 #include <dt-bindings/reset/amlogic,meson-gxbb-reset.h>
+#include <dt-bindings/clock/gxbb-clkc.h>
 
 / {
 	compatible = "amlogic,meson-gxbb";
@@ -246,7 +247,8 @@
 					mux {
 						groups = "emmc_nand_d07",
 						       "emmc_cmd",
-						       "emmc_clk";
+						       "emmc_clk",
+						       "emmc_ds";
 						function = "emmc";
 					};
 				};
@@ -329,6 +331,39 @@
 			#address-cells = <2>;
 			#size-cells = <2>;
 			ranges = <0x0 0x0 0x0 0xd0000000 0x0 0x200000>;
+
+			sd_emmc_a: mmc at 70000 {
+				compatible = "amlogic,meson-gxbb-mmc";
+				reg = <0x0 0x70000 0x0 0x2000>;
+				interrupts = <GIC_SPI 216 IRQ_TYPE_EDGE_RISING>;
+				clocks = <&clkc CLKID_SD_EMMC_A>,
+					 <&xtal>,
+					 <&clkc CLKID_FCLK_DIV2>;
+				clock-names = "core", "clkin0", "clkin1";
+				status = "disabled";
+			};
+
+			sd_emmc_b: mmc at 72000 {
+				compatible = "amlogic,meson-gxbb-mmc";
+				reg = <0x0 0x72000 0x0 0x2000>;
+				interrupts = <GIC_SPI 217 IRQ_TYPE_EDGE_RISING>;
+				clocks = <&clkc CLKID_SD_EMMC_B>,
+					 <&xtal>,
+					 <&clkc CLKID_FCLK_DIV2>;
+				clock-names = "core", "clkin0", "clkin1";
+				status = "disabled";
+			};
+
+			sd_emmc_c: mmc at 74000 {
+				compatible = "amlogic,meson-gxbb-mmc";
+				reg = <0x0 0x74000 0x0 0x2000>;
+				interrupts = <GIC_SPI 218 IRQ_TYPE_EDGE_RISING>;
+				clocks = <&clkc CLKID_SD_EMMC_C>,
+					 <&xtal>,
+					 <&clkc CLKID_FCLK_DIV2>;
+				clock-names = "core", "clkin0", "clkin1";
+				status = "disabled";
+			};
 		};
 
 		ethmac: ethernet at c9410000 {
Signature · 1 line
2.9.3