Skip to contentSkip to conversation

mmc: add OpenPiton mmc support

PATCH Superseded Tianrui Wei 2 participants 10 messages May 6, 2021 – May 8, 2021 MMC, SD and SDIO

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/2 mmc: add OpenPiton mmc support

From: Tianrui Wei <[email protected]>
Date: Thu, 6 May 2021 11:30:20 +0800
Subject: [PATCH V4 1/2] mmc: add OpenPiton mmc support

This patch adds mmc support for OpenPiton. Specifically, some dts bindings were not used because our mmc controller doens't have those configuration options, it only exposes a dummy mmap interface for CPU.

---

 drivers/mmc/Kconfig                     |   7 +
 drivers/mmc/Makefile                    |   1 +
 drivers/mmc/piton_mmc.c                 | 172 +++++
 3 files changed, 180 insertions(+)
 create mode 100644 drivers/mmc/piton_mmc.c
drivers/mmc/Kconfig +7 -0
index 14d79139..1038800f 100644
@@ -707,6 +707,13 @@ config MMC_SUNXI_HAS_MODE_SWITCH
 	bool
 	depends on MMC_SUNXI
 
+config MMC_PITON
+	bool "MMC support for openpiton SoC"
+  depends on DM_MMC && BLK
+	help
+    This driver enables SD card support in U-Boot port for
+    OpenPiton SoC
+
 config GENERIC_ATMEL_MCI
 	bool "Atmel Multimedia Card Interface support"
 	depends on DM_MMC && BLK && ARCH_AT91
drivers/mmc/Makefile +1 -0
index 1c849cba..698dfe05 100644
@@ -71,6 +71,7 @@ obj-$(CONFIG_MMC_SDHCI_XENON)		+= xenon_sdhci.o
 obj-$(CONFIG_MMC_SDHCI_ZYNQ)		+= zynq_sdhci.o
 
 obj-$(CONFIG_MMC_SUNXI)			+= sunxi_mmc.o
+obj-$(CONFIG_MMC_PITON)     	+= piton_mmc.o
 obj-$(CONFIG_MMC_UNIPHIER)		+= tmio-common.o uniphier-sd.o
 obj-$(CONFIG_RENESAS_SDHI)		+= tmio-common.o renesas-sdhi.o
 obj-$(CONFIG_MMC_BCM2835)		+= bcm2835_sdhost.o
drivers/mmc/piton_mmc.c new file +172 -0

172 lines not on this page · raw message

Signature · 1 line
2.17.1
#1 lore raw

PATCH v4 1/2 mmc: add OpenPiton mmc support

Quoted 9 lines · Tianrui Wei

From: Tianrui Wei <[email protected]>
Date: Thu, 6 May 2021 11:30:20 +0800
Subject: [PATCH V4 1/2] mmc: add OpenPiton mmc support

This patch adds mmc support for OpenPiton. Specifically, some dts bindings were not used because our mmc controller doens't have those configuration options, it only exposes a dummy mmap interface for CPU.

Please wrap your commit messages to 75 characterss, not 56 ;)

Quoted 34 lines

---

  drivers/mmc/Kconfig                     |   7 +
  drivers/mmc/Makefile                    |   1 +
  drivers/mmc/piton_mmc.c                 | 172 +++++
  3 files changed, 180 insertions(+)

create mode 100644 drivers/mmc/piton_mmc.c

drivers/mmc/Kconfig +7 -0
index 14d79139..1038800f 100644
@@ -707,6 +707,13 @@ config MMC_SUNXI_HAS_MODE_SWITCH
  	bool
  	depends on MMC_SUNXI
 
+config MMC_PITON
+	bool "MMC support for openpiton SoC"
+  depends on DM_MMC && BLK
+	help
+    This driver enables SD card support in U-Boot port for
+    OpenPiton SoC
+
  config GENERIC_ATMEL_MCI
  	bool "Atmel Multimedia Card Interface support"
  	depends on DM_MMC && BLK && ARCH_AT91
drivers/mmc/Makefile +0 -0
index 1c849cba..698dfe05 100644

drivers/mmc/Makefile obj-$(CONFIG_MMC_SDHCI_XENON) += xenon_sdhci.o · line 74

Quoted 4 lines
drivers/mmc/Makefile +1 -0
@@ -71,6 +71,7 @@ obj-$(CONFIG_MMC_SDHCI_XENON)		+= xenon_sdhci.o
  obj-$(CONFIG_MMC_SDHCI_ZYNQ)		+= zynq_sdhci.o
 
  obj-$(CONFIG_MMC_SUNXI)			+= sunxi_mmc.o
+obj-$(CONFIG_MMC_PITON)     	+= piton_mmc.o

Fix indentation. And please place this object in alphabetical order.

Quoted 9 lines
drivers/mmc/Makefile +0 -0
  obj-$(CONFIG_MMC_UNIPHIER)		+= tmio-common.o uniphier-sd.o
  obj-$(CONFIG_RENESAS_SDHI)		+= tmio-common.o renesas-sdhi.o
  obj-$(CONFIG_MMC_BCM2835)		+= bcm2835_sdhost.o
drivers/mmc/piton_mmc.c new file +0 -0
new file mode 100644
index 00000000..266e26d8

drivers/mmc/piton_mmc.c line 8

Quoted 8 lines
drivers/mmc/piton_mmc.c new file +8 -0
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2009 SAMSUNG Electronics
+ * Minkyu Kang <[email protected]>
+ * Jaehoon Chung <[email protected]>
+ * Portions Copyright 2011-2019 NVIDIA Corporation
+ * Portions Copyright 2021 Tianrui Wei
+ * Tianrui Wei <[email protected]>

This is quite the list of authors. Where does this file come from?

Quoted 9 lines
drivers/mmc/piton_mmc.c new file +9 -0
+ */
+
+#include <asm/gpio.h>
+#include <asm/io.h>
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <linux/bitops.h>
+#include <linux/types.h>

drivers/mmc/piton_mmc.c line 27

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <log.h>
+#include <div64.h>
+#include <mmc.h>
+
+struct piton_mmc_plat {
+	struct mmc_config cfg;
+	struct mmc mmc;
+};

Is platdata used? I don't see it in 2/2.

drivers/mmc/piton_mmc.c line 30

Quoted 3 lines
drivers/mmc/piton_mmc.c new file +3 -0
+
+struct piton_mmc_priv {
+	u64 piton_mmc_base_addr; /* peripheral id */

This should be void __iomem *.

drivers/mmc/piton_mmc.c line 43

Quoted 13 lines
drivers/mmc/piton_mmc.c new file +13 -0
+};
+
+/*
+ * see mmc_read_blocks to see how it is used.
+ * start block is hidden at cmd->arg
+ * also, initialize the block size at init
+ */
+static int piton_mmc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
+			      struct mmc_data *data)
+{
+	/* check first if this is a pure command */
+	if (!data)
+		return 0;

Please place definitions before code (and please run checkpatch).

drivers/mmc/piton_mmc.c line 47

Quoted 4 lines
drivers/mmc/piton_mmc.c new file +4 -0
+
+	u64 byte_cnt = data->blocks * data->blocksize;
+	u64 start_block = cmd->cmdarg;
+	unsigned int *buff = (unsigned int *)data->dest;

Why is buff an unsigned int? If you are using readl, shouldn't it be a long?

drivers/mmc/piton_mmc.c line 57

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+
+	struct piton_mmc_priv *priv = dev_get_priv(dev);
+	u64 start_addr = priv->piton_mmc_base_addr + (start_block);
+
+	/* if there is a read */
+	if (data->flags & MMC_DATA_READ) {
+		for (u64 i = 0; i < byte_cnt; i += 4) {
+			*(buff) = readl((void *)(start_addr + i));
+			buff++;
+		}

Can you use memcpy_fromio here?

drivers/mmc/piton_mmc.c line 62

Quoted 5 lines
drivers/mmc/piton_mmc.c new file +5 -0
+	} else {
+		/* else there is a write
+		 * we don't handle write, so error right away
+		 */
+		return -ENODEV;

Please use -ENOSYS.

Quoted 101 lines
drivers/mmc/piton_mmc.c new file +100 -0
+	}
+
+	return 0;
+}
+
+static int piton_mmc_ofdata_to_platdata(struct udevice *dev)
+{
+	struct piton_mmc_priv *priv = dev_get_priv(dev);
+	struct piton_mmc_plat *plat = dev_get_platdata(dev);
+	struct mmc_config *cfg;
+	struct mmc *mmc;
+	/* fill in device description */
+	struct blk_desc *bdesc;
+
+	priv->piton_mmc_base_addr = dev_read_addr(dev);
+	cfg = &plat->cfg;
+	cfg->name = "PITON MMC";
+	cfg->host_caps = MMC_MODE_8BIT;
+	cfg->f_max = 100000;
+	cfg->f_min = 400000;
+	cfg->voltages = MMC_VDD_21_22;
+
+	mmc = &plat->mmc;
+	mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+	mmc->capacity_user = 0x100000000;
+	mmc->capacity_user *= mmc->read_bl_len;
+	mmc->capacity_boot = 0;
+	mmc->capacity_rpmb = 0;
+	for (int i = 0; i < 4; i++)
+		mmc->capacity_gp[i] = 0;
+	mmc->capacity = 0x2000000000ULL;
+	mmc->has_init = 1;
+
+	bdesc = mmc_get_blk_desc(mmc);
+	bdesc->lun = 0;
+	bdesc->hwpart = 0;
+	bdesc->type = 0;
+	bdesc->blksz = mmc->read_bl_len;
+	bdesc->log2blksz = LOG2(bdesc->blksz);
+	bdesc->lba = lldiv(mmc->capacity, mmc->read_bl_len);
+
+	return 0;
+}
+
+/* test if piton has the micro mmc card present
+ * always return 1, which means present
+ */
+static int piton_mmc_getcd(struct udevice *dev)
+{
+	/*
+	 * always return 1
+	 */
+	return 1;
+}
+
+/* dummy function, piton_mmc don't need initialization
+ * in hw
+ */
+static const struct dm_mmc_ops piton_mmc_ops = {
+	.send_cmd = piton_mmc_send_cmd,
+	.set_ios = piton_mmc_set_ios,
+	.get_cd = piton_mmc_getcd,
+};
+
+static int piton_mmc_probe(struct udevice *dev)
+{
+	struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+	struct piton_mmc_plat *plat = dev_get_platdata(dev);
+	struct mmc_config *cfg = &plat->cfg;
+
+	cfg->name = dev->name;
+	upriv->mmc = &plat->mmc;
+	upriv->mmc->has_init = 1;
+	upriv->mmc->capacity = 0x2000000000ULL;
+	upriv->mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+
+	return 0;
+}
+
+static int piton_mmc_bind(struct udevice *dev)
+{
+	struct piton_mmc_plat *plat = dev_get_platdata(dev);
+	struct mmc_config *cfg = &plat->cfg;
+
+	cfg->name = dev->name;
+	cfg->host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_8BIT;
+	cfg->voltages = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34;
+	cfg->f_min = 1000000;
+	cfg->f_max = 52000000;
+	cfg->b_max = U32_MAX;
+
+	return mmc_bind(dev, &plat->mmc, cfg);
+}
+
+static const struct udevice_id piton_mmc_ids[] = {
+		{.compatible = "openpiton,piton-mmc"},
+		{ /* sentinel */ }
+};
+
+U_BOOT_DRIVER(piton_mmc_drv) = {

drivers/mmc/piton_mmc.c line 172

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+	.name = "piton_mmc",
+	.id = UCLASS_MMC,
+	.of_match = piton_mmc_ids,
+	.ofdata_to_platdata = piton_mmc_ofdata_to_platdata,
+	.bind = piton_mmc_bind,
+	.probe = piton_mmc_probe,
+	.ops = &piton_mmc_ops,
+	.platdata_auto_alloc_size = sizeof(struct piton_mmc_plat),
+	.priv_auto_alloc_size = sizeof(struct piton_mmc_priv),
+};

--Sean

#2 lore raw

PATCH v4 1/2 mmc: add OpenPiton mmc support

Hi Sean,

Many thanks for taking your valuable time to review our patch and give suggestions. I'll improve both our patches accordingly. Just for the record, what would be the exact command you'd recommend to run checkpatch.pl? Because it only showed one warning about me not putting my name on the MAINTAINERS file on this patch.

Many thanks,

Tianrui

Quoted 63 lines · Sean Anderson
Quoted 9 lines · Tianrui Wei

From: Tianrui Wei <[email protected]>
Date: Thu, 6 May 2021 11:30:20 +0800
Subject: [PATCH V4 1/2] mmc: add OpenPiton mmc support

This patch adds mmc support for OpenPiton. Specifically, some dts bindings were not used because our mmc controller doens't have those configuration options, it only exposes a dummy mmap interface for CPU.

Please wrap your commit messages to 75 characterss, not 56 ;)

Quoted 33 lines

---

? drivers/mmc/Kconfig???????????????????? |?? 7 +
? drivers/mmc/Makefile??????????????????? |?? 1 +
? drivers/mmc/piton_mmc.c???????????????? | 172 +++++

? 3 files changed, 180 insertions(+)
? create mode 100644 drivers/mmc/piton_mmc.c

drivers/mmc/Kconfig +0 -0
index 14d79139..1038800f 100644
@@ -707,6 +707,13 @@ config MMC_SUNXI_HAS_MODE_SWITCH

????? bool
????? depends on MMC_SUNXI
? +config MMC_PITON
+??? bool "MMC support for openpiton SoC"
+? depends on DM_MMC && BLK
+??? help
+??? This driver enables SD card support in U-Boot port for +??? OpenPiton SoC
+
? config GENERIC_ATMEL_MCI
????? bool "Atmel Multimedia Card Interface support" ????? depends on DM_MMC && BLK && ARCH_AT91

drivers/mmc/Makefile +0 -0
index 1c849cba..698dfe05 100644
@@ -71,6 +71,7 @@ obj-$(CONFIG_MMC_SDHCI_XENON)??????? += xenon_sdhci.o
Quoted 3 lines

? obj-$(CONFIG_MMC_SDHCI_ZYNQ)??????? += zynq_sdhci.o ? ? obj-$(CONFIG_MMC_SUNXI)??????????? += sunxi_mmc.o +obj-$(CONFIG_MMC_PITON)???????? += piton_mmc.o

Fix indentation. And please place this object in alphabetical order.

Quoted 11 lines

? obj-$(CONFIG_MMC_UNIPHIER)??????? += tmio-common.o uniphier-sd.o ? obj-$(CONFIG_RENESAS_SDHI)??????? += tmio-common.o renesas-sdhi.o ? obj-$(CONFIG_MMC_BCM2835)??????? += bcm2835_sdhost.o

drivers/mmc/piton_mmc.c new file +2 -0
new file mode 100644
index 00000000..266e26d8
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
Quoted 8 lines

drivers/mmc/piton_mmc.c line 8

Quoted 6 lines
drivers/mmc/piton_mmc.c new file +6 -0
+ * (C) Copyright 2009 SAMSUNG Electronics
+ * Minkyu Kang <[email protected]>
+ * Jaehoon Chung <[email protected]>
+ * Portions Copyright 2011-2019 NVIDIA Corporation
+ * Portions Copyright 2021 Tianrui Wei
+ * Tianrui Wei <[email protected]>

This is quite the list of authors. Where does this file come from?

This file was adapted from a Samsung mmc file, so I kept the original authors.

Quoted 187 lines
Quoted 10 lines
drivers/mmc/piton_mmc.c new file +9 -0
+ */
+
+#include <asm/gpio.h>
+#include <asm/io.h>
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <linux/bitops.h>
+#include <linux/types.h>

drivers/mmc/piton_mmc.c line 27

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <log.h>
+#include <div64.h>
+#include <mmc.h>
+
+struct piton_mmc_plat {
+??? struct mmc_config cfg;
+??? struct mmc mmc;
+};

Is platdata used? I don't see it in 2/2.

drivers/mmc/piton_mmc.c

Quoted 3 lines
drivers/mmc/piton_mmc.c new file +3 -0
+
+struct piton_mmc_priv {
+??? u64 piton_mmc_base_addr; /* peripheral id */

This should be void __iomem *.

drivers/mmc/piton_mmc.c

Quoted 13 lines
drivers/mmc/piton_mmc.c new file +13 -0
+};
+
+/*
+ * see mmc_read_blocks to see how it is used.
+ * start block is hidden at cmd->arg
+ * also, initialize the block size at init
+ */
+static int piton_mmc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
+????????????????? struct mmc_data *data)
+{
+??? /* check first if this is a pure command */
+??? if (!data)
+??????? return 0;

Please place definitions before code (and please run checkpatch).

drivers/mmc/piton_mmc.c line 47

Quoted 4 lines
drivers/mmc/piton_mmc.c new file +4 -0
+
+??? u64 byte_cnt = data->blocks * data->blocksize;
+??? u64 start_block = cmd->cmdarg;
+??? unsigned int *buff = (unsigned int *)data->dest;

Why is buff an unsigned int? If you are using readl, shouldn't it be a long?

drivers/mmc/piton_mmc.c line 57

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+
+??? struct piton_mmc_priv *priv = dev_get_priv(dev);
+??? u64 start_addr = priv->piton_mmc_base_addr + (start_block);
+
+??? /* if there is a read */
+??? if (data->flags & MMC_DATA_READ) {
+??????? for (u64 i = 0; i < byte_cnt; i += 4) {
+??????????? *(buff) = readl((void *)(start_addr + i));
+??????????? buff++;
+??????? }

Can you use memcpy_fromio here?

drivers/mmc/piton_mmc.c line 62

Quoted 5 lines
drivers/mmc/piton_mmc.c new file +5 -0
+??? } else {
+??????? /* else there is a write
+???????? * we don't handle write, so error right away
+???????? */
+??????? return -ENODEV;

Please use -ENOSYS.

Quoted 101 lines
drivers/mmc/piton_mmc.c new file +100 -0
+??? }
+
+??? return 0;
+}
+
+static int piton_mmc_ofdata_to_platdata(struct udevice *dev)
+{
+??? struct piton_mmc_priv *priv = dev_get_priv(dev);
+??? struct piton_mmc_plat *plat = dev_get_platdata(dev);
+??? struct mmc_config *cfg;
+??? struct mmc *mmc;
+??? /* fill in device description */
+??? struct blk_desc *bdesc;
+
+??? priv->piton_mmc_base_addr = dev_read_addr(dev);
+??? cfg = &plat->cfg;
+??? cfg->name = "PITON MMC";
+??? cfg->host_caps = MMC_MODE_8BIT;
+??? cfg->f_max = 100000;
+??? cfg->f_min = 400000;
+??? cfg->voltages = MMC_VDD_21_22;
+
+??? mmc = &plat->mmc;
+??? mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+??? mmc->capacity_user = 0x100000000;
+??? mmc->capacity_user *= mmc->read_bl_len;
+??? mmc->capacity_boot = 0;
+??? mmc->capacity_rpmb = 0;
+??? for (int i = 0; i < 4; i++)
+??????? mmc->capacity_gp[i] = 0;
+??? mmc->capacity = 0x2000000000ULL;
+??? mmc->has_init = 1;
+
+??? bdesc = mmc_get_blk_desc(mmc);
+??? bdesc->lun = 0;
+??? bdesc->hwpart = 0;
+??? bdesc->type = 0;
+??? bdesc->blksz = mmc->read_bl_len;
+??? bdesc->log2blksz = LOG2(bdesc->blksz);
+??? bdesc->lba = lldiv(mmc->capacity, mmc->read_bl_len);
+
+??? return 0;
+}
+
+/* test if piton has the micro mmc card present
+ * always return 1, which means present
+ */
+static int piton_mmc_getcd(struct udevice *dev)
+{
+??? /*
+???? * always return 1
+???? */
+??? return 1;
+}
+
+/* dummy function, piton_mmc don't need initialization
+ * in hw
+ */
+static const struct dm_mmc_ops piton_mmc_ops = {
+??? .send_cmd = piton_mmc_send_cmd,
+??? .set_ios = piton_mmc_set_ios,
+??? .get_cd = piton_mmc_getcd,
+};
+
+static int piton_mmc_probe(struct udevice *dev)
+{
+??? struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+??? struct piton_mmc_plat *plat = dev_get_platdata(dev);
+??? struct mmc_config *cfg = &plat->cfg;
+
+??? cfg->name = dev->name;
+??? upriv->mmc = &plat->mmc;
+??? upriv->mmc->has_init = 1;
+??? upriv->mmc->capacity = 0x2000000000ULL;
+??? upriv->mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+
+??? return 0;
+}
+
+static int piton_mmc_bind(struct udevice *dev)
+{
+??? struct piton_mmc_plat *plat = dev_get_platdata(dev);
+??? struct mmc_config *cfg = &plat->cfg;
+
+??? cfg->name = dev->name;
+??? cfg->host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_8BIT;
+??? cfg->voltages = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34;
+??? cfg->f_min = 1000000;
+??? cfg->f_max = 52000000;
+??? cfg->b_max = U32_MAX;
+
+??? return mmc_bind(dev, &plat->mmc, cfg);
+}
+
+static const struct udevice_id piton_mmc_ids[] = {
+??????? {.compatible = "openpiton,piton-mmc"},
+??????? { /* sentinel */ }
+};
+
+U_BOOT_DRIVER(piton_mmc_drv) = {

drivers/mmc/piton_mmc.c line 172

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+??? .name = "piton_mmc",
+??? .id = UCLASS_MMC,
+??? .of_match = piton_mmc_ids,
+??? .ofdata_to_platdata = piton_mmc_ofdata_to_platdata,
+??? .bind = piton_mmc_bind,
+??? .probe = piton_mmc_probe,
+??? .ops = &piton_mmc_ops,
+??? .platdata_auto_alloc_size = sizeof(struct piton_mmc_plat),
+??? .priv_auto_alloc_size = sizeof(struct piton_mmc_priv),
+};

--Sean

#3 lore raw

PATCH v4 1/2 mmc: add OpenPiton mmc support

Quoted 7 lines · Tianrui Wei

Hi Sean,

Many thanks for taking your valuable time to review our patch and give suggestions. I'll improve both our patches accordingly. Just for the record, what would be the exact command you'd recommend to run checkpatch.pl? Because it only showed one warning about me not putting my name on the MAINTAINERS file on this patch.

Huh. I would have expected checkpatch to catch the variable initialization thing, but I guess it didn't.

Quoted 80 lines

Many thanks,

Tianrui

Quoted 63 lines · Sean Anderson
Quoted 9 lines · Tianrui Wei

From: Tianrui Wei <[email protected]>
Date: Thu, 6 May 2021 11:30:20 +0800
Subject: [PATCH V4 1/2] mmc: add OpenPiton mmc support

This patch adds mmc support for OpenPiton. Specifically, some dts bindings were not used because our mmc controller doens't have those configuration options, it only exposes a dummy mmap interface for CPU.

Please wrap your commit messages to 75 characterss, not 56 ;)

Quoted 33 lines

---

  drivers/mmc/Kconfig                     |   7 +
  drivers/mmc/Makefile                    |   1 +
  drivers/mmc/piton_mmc.c                 | 172 +++++
  3 files changed, 180 insertions(+)

create mode 100644 drivers/mmc/piton_mmc.c

drivers/mmc/Kconfig +6 -0
index 14d79139..1038800f 100644
@@ -707,6 +707,13 @@ config MMC_SUNXI_HAS_MODE_SWITCH
      bool
      depends on MMC_SUNXI
  +config MMC_PITON
+    bool "MMC support for openpiton SoC"
+  depends on DM_MMC && BLK
+    help
+    This driver enables SD card support in U-Boot port for
+    OpenPiton SoC
+
  config GENERIC_ATMEL_MCI
      bool "Atmel Multimedia Card Interface support"
      depends on DM_MMC && BLK && ARCH_AT91
drivers/mmc/Makefile +0 -0
index 1c849cba..698dfe05 100644

drivers/mmc/Makefile obj-$(CONFIG_MMC_SDHCI_XENON) += xenon_sdhci.o · line 73

Quoted 3 lines
drivers/mmc/Makefile +1 -0
@@ -71,6 +71,7 @@ obj-$(CONFIG_MMC_SDHCI_XENON)        += xenon_sdhci.o
  obj-$(CONFIG_MMC_SDHCI_ZYNQ)        += zynq_sdhci.o
    obj-$(CONFIG_MMC_SUNXI)            += sunxi_mmc.o
+obj-$(CONFIG_MMC_PITON)         += piton_mmc.o

Fix indentation. And please place this object in alphabetical order.

Quoted 11 lines
drivers/mmc/Makefile +0 -0
  obj-$(CONFIG_MMC_UNIPHIER)        += tmio-common.o uniphier-sd.o
  obj-$(CONFIG_RENESAS_SDHI)        += tmio-common.o renesas-sdhi.o
  obj-$(CONFIG_MMC_BCM2835)        += bcm2835_sdhost.o
drivers/mmc/piton_mmc.c new file +2 -0
new file mode 100644
index 00000000..266e26d8
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
Quoted 8 lines

drivers/mmc/piton_mmc.c line 8

Quoted 6 lines
drivers/mmc/piton_mmc.c new file +6 -0
+ * (C) Copyright 2009 SAMSUNG Electronics
+ * Minkyu Kang <[email protected]>
+ * Jaehoon Chung <[email protected]>
+ * Portions Copyright 2011-2019 NVIDIA Corporation
+ * Portions Copyright 2021 Tianrui Wei
+ * Tianrui Wei <[email protected]>

This is quite the list of authors. Where does this file come from?

Quoted 1 line

This file was adapted from a Samsung mmc file, so I kept the original authors.

Can you add a note along the lines of "Adapted from tegra_mmc.c" for the curiosity of future readers :)

--Sean

Quoted 188 lines
Quoted 188 lines
Quoted 11 lines
drivers/mmc/piton_mmc.c new file +9 -0
+ */
+
+#include <asm/gpio.h>
+#include <asm/io.h>
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <linux/bitops.h>
+#include <linux/types.h>

drivers/mmc/piton_mmc.c line 27

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <log.h>
+#include <div64.h>
+#include <mmc.h>
+
+struct piton_mmc_plat {
+    struct mmc_config cfg;
+    struct mmc mmc;
+};

Is platdata used? I don't see it in 2/2.

drivers/mmc/piton_mmc.c line 30

Quoted 3 lines
drivers/mmc/piton_mmc.c new file +3 -0
+
+struct piton_mmc_priv {
+    u64 piton_mmc_base_addr; /* peripheral id */

This should be void __iomem *.

drivers/mmc/piton_mmc.c line 43

Quoted 13 lines
drivers/mmc/piton_mmc.c new file +13 -0
+};
+
+/*
+ * see mmc_read_blocks to see how it is used.
+ * start block is hidden at cmd->arg
+ * also, initialize the block size at init
+ */
+static int piton_mmc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
+                  struct mmc_data *data)
+{
+    /* check first if this is a pure command */
+    if (!data)
+        return 0;

Please place definitions before code (and please run checkpatch).

drivers/mmc/piton_mmc.c line 47

Quoted 4 lines
drivers/mmc/piton_mmc.c new file +4 -0
+
+    u64 byte_cnt = data->blocks * data->blocksize;
+    u64 start_block = cmd->cmdarg;
+    unsigned int *buff = (unsigned int *)data->dest;

Why is buff an unsigned int? If you are using readl, shouldn't it be a long?

drivers/mmc/piton_mmc.c line 57

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+
+    struct piton_mmc_priv *priv = dev_get_priv(dev);
+    u64 start_addr = priv->piton_mmc_base_addr + (start_block);
+
+    /* if there is a read */
+    if (data->flags & MMC_DATA_READ) {
+        for (u64 i = 0; i < byte_cnt; i += 4) {
+            *(buff) = readl((void *)(start_addr + i));
+            buff++;
+        }

Can you use memcpy_fromio here?

drivers/mmc/piton_mmc.c line 62

Quoted 5 lines
drivers/mmc/piton_mmc.c new file +5 -0
+    } else {
+        /* else there is a write
+         * we don't handle write, so error right away
+         */
+        return -ENODEV;

Please use -ENOSYS.

Quoted 101 lines
drivers/mmc/piton_mmc.c new file +100 -0
+    }
+
+    return 0;
+}
+
+static int piton_mmc_ofdata_to_platdata(struct udevice *dev)
+{
+    struct piton_mmc_priv *priv = dev_get_priv(dev);
+    struct piton_mmc_plat *plat = dev_get_platdata(dev);
+    struct mmc_config *cfg;
+    struct mmc *mmc;
+    /* fill in device description */
+    struct blk_desc *bdesc;
+
+    priv->piton_mmc_base_addr = dev_read_addr(dev);
+    cfg = &plat->cfg;
+    cfg->name = "PITON MMC";
+    cfg->host_caps = MMC_MODE_8BIT;
+    cfg->f_max = 100000;
+    cfg->f_min = 400000;
+    cfg->voltages = MMC_VDD_21_22;
+
+    mmc = &plat->mmc;
+    mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+    mmc->capacity_user = 0x100000000;
+    mmc->capacity_user *= mmc->read_bl_len;
+    mmc->capacity_boot = 0;
+    mmc->capacity_rpmb = 0;
+    for (int i = 0; i < 4; i++)
+        mmc->capacity_gp[i] = 0;
+    mmc->capacity = 0x2000000000ULL;
+    mmc->has_init = 1;
+
+    bdesc = mmc_get_blk_desc(mmc);
+    bdesc->lun = 0;
+    bdesc->hwpart = 0;
+    bdesc->type = 0;
+    bdesc->blksz = mmc->read_bl_len;
+    bdesc->log2blksz = LOG2(bdesc->blksz);
+    bdesc->lba = lldiv(mmc->capacity, mmc->read_bl_len);
+
+    return 0;
+}
+
+/* test if piton has the micro mmc card present
+ * always return 1, which means present
+ */
+static int piton_mmc_getcd(struct udevice *dev)
+{
+    /*
+     * always return 1
+     */
+    return 1;
+}
+
+/* dummy function, piton_mmc don't need initialization
+ * in hw
+ */
+static const struct dm_mmc_ops piton_mmc_ops = {
+    .send_cmd = piton_mmc_send_cmd,
+    .set_ios = piton_mmc_set_ios,
+    .get_cd = piton_mmc_getcd,
+};
+
+static int piton_mmc_probe(struct udevice *dev)
+{
+    struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+    struct piton_mmc_plat *plat = dev_get_platdata(dev);
+    struct mmc_config *cfg = &plat->cfg;
+
+    cfg->name = dev->name;
+    upriv->mmc = &plat->mmc;
+    upriv->mmc->has_init = 1;
+    upriv->mmc->capacity = 0x2000000000ULL;
+    upriv->mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+
+    return 0;
+}
+
+static int piton_mmc_bind(struct udevice *dev)
+{
+    struct piton_mmc_plat *plat = dev_get_platdata(dev);
+    struct mmc_config *cfg = &plat->cfg;
+
+    cfg->name = dev->name;
+    cfg->host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_8BIT;
+    cfg->voltages = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34;
+    cfg->f_min = 1000000;
+    cfg->f_max = 52000000;
+    cfg->b_max = U32_MAX;
+
+    return mmc_bind(dev, &plat->mmc, cfg);
+}
+
+static const struct udevice_id piton_mmc_ids[] = {
+        {.compatible = "openpiton,piton-mmc"},
+        { /* sentinel */ }
+};
+
+U_BOOT_DRIVER(piton_mmc_drv) = {

drivers/mmc/piton_mmc.c line 172

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+    .name = "piton_mmc",
+    .id = UCLASS_MMC,
+    .of_match = piton_mmc_ids,
+    .ofdata_to_platdata = piton_mmc_ofdata_to_platdata,
+    .bind = piton_mmc_bind,
+    .probe = piton_mmc_probe,
+    .ops = &piton_mmc_ops,
+    .platdata_auto_alloc_size = sizeof(struct piton_mmc_plat),
+    .priv_auto_alloc_size = sizeof(struct piton_mmc_priv),
+};

--Sean

#4 lore raw

PATCH v4 1/2 mmc: add OpenPiton mmc support

Hi Sean,

Thanks for reviewing the patches, I'll fix the initialization thing and the tegra_mmc credit :P

Quoted 291 lines · Sean Anderson
Quoted 7 lines · Tianrui Wei

Hi Sean,

Many thanks for taking your valuable time to review our patch and give suggestions. I'll improve both our patches accordingly. Just for the record, what would be the exact command you'd recommend to run checkpatch.pl? Because it only showed one warning about me not putting my name on the MAINTAINERS file on this patch.

Huh. I would have expected checkpatch to catch the variable initialization thing, but I guess it didn't.

Quoted 81 lines

Many thanks,

Tianrui

Quoted 64 lines · Sean Anderson
Quoted 9 lines · Tianrui Wei

From: Tianrui Wei <[email protected]>
Date: Thu, 6 May 2021 11:30:20 +0800
Subject: [PATCH V4 1/2] mmc: add OpenPiton mmc support

This patch adds mmc support for OpenPiton. Specifically, some dts bindings were not used because our mmc controller doens't have those configuration options, it only exposes a dummy mmap interface for CPU.

Please wrap your commit messages to 75 characterss, not 56 ;)

Quoted 33 lines

---

? drivers/mmc/Kconfig???????????????????? |?? 7 +
? drivers/mmc/Makefile??????????????????? |?? 1 +
? drivers/mmc/piton_mmc.c???????????????? | 172 +++++

? 3 files changed, 180 insertions(+)
? create mode 100644 drivers/mmc/piton_mmc.c

drivers/mmc/Kconfig +0 -0
index 14d79139..1038800f 100644
@@ -707,6 +707,13 @@ config MMC_SUNXI_HAS_MODE_SWITCH

????? bool
????? depends on MMC_SUNXI
? +config MMC_PITON
+??? bool "MMC support for openpiton SoC"
+? depends on DM_MMC && BLK
+??? help
+??? This driver enables SD card support in U-Boot port for +??? OpenPiton SoC
+
? config GENERIC_ATMEL_MCI
????? bool "Atmel Multimedia Card Interface support" ????? depends on DM_MMC && BLK && ARCH_AT91

drivers/mmc/Makefile +0 -0
index 1c849cba..698dfe05 100644
@@ -71,6 +71,7 @@ obj-$(CONFIG_MMC_SDHCI_XENON)??????? += 
Quoted 4 lines

xenon_sdhci.o
? obj-$(CONFIG_MMC_SDHCI_ZYNQ)??????? += zynq_sdhci.o ??? obj-$(CONFIG_MMC_SUNXI)??????????? += sunxi_mmc.o +obj-$(CONFIG_MMC_PITON)???????? += piton_mmc.o

Fix indentation. And please place this object in alphabetical order.

Quoted 11 lines

? obj-$(CONFIG_MMC_UNIPHIER)??????? += tmio-common.o uniphier-sd.o ? obj-$(CONFIG_RENESAS_SDHI)??????? += tmio-common.o renesas-sdhi.o ? obj-$(CONFIG_MMC_BCM2835)??????? += bcm2835_sdhost.o

drivers/mmc/piton_mmc.c new file +2 -0
new file mode 100644
index 00000000..266e26d8
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
Quoted 8 lines

drivers/mmc/piton_mmc.c line 8

Quoted 6 lines
drivers/mmc/piton_mmc.c new file +6 -0
+ * (C) Copyright 2009 SAMSUNG Electronics
+ * Minkyu Kang <[email protected]>
+ * Jaehoon Chung <[email protected]>
+ * Portions Copyright 2011-2019 NVIDIA Corporation
+ * Portions Copyright 2021 Tianrui Wei
+ * Tianrui Wei <[email protected]>

This is quite the list of authors. Where does this file come from?

Quoted 2 lines

This file was adapted from a Samsung mmc file, so I kept the original authors.

Can you add a note along the lines of "Adapted from tegra_mmc.c" for the curiosity of future readers :)

--Sean

Quoted 189 lines
Quoted 189 lines
Quoted 11 lines
drivers/mmc/piton_mmc.c new file +9 -0
+ */
+
+#include <asm/gpio.h>
+#include <asm/io.h>
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <linux/bitops.h>
+#include <linux/types.h>

drivers/mmc/piton_mmc.c line 27

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <log.h>
+#include <div64.h>
+#include <mmc.h>
+
+struct piton_mmc_plat {
+??? struct mmc_config cfg;
+??? struct mmc mmc;
+};

Is platdata used? I don't see it in 2/2.

drivers/mmc/piton_mmc.c

Quoted 3 lines
drivers/mmc/piton_mmc.c new file +3 -0
+
+struct piton_mmc_priv {
+??? u64 piton_mmc_base_addr; /* peripheral id */

This should be void __iomem *.

Quoted 8 lines
drivers/mmc/piton_mmc.c new file +8 -0
+};
+
+/*
+ * see mmc_read_blocks to see how it is used.
+ * start block is hidden at cmd->arg
+ * also, initialize the block size at init
+ */
+static int piton_mmc_send_cmd(struct udevice *dev, struct mmc_cmd 
Quoted 6 lines

*cmd,
+????????????????? struct mmc_data *data)
+{
+??? /* check first if this is a pure command */
+??? if (!data)
+??????? return 0;

Please place definitions before code (and please run checkpatch).

Quoted 4 lines

+
+??? u64 byte_cnt = data->blocks * data->blocksize; +??? u64 start_block = cmd->cmdarg;
+??? unsigned int *buff = (unsigned int *)data->dest;

Why is buff an unsigned int? If you are using readl, shouldn't it be a long?

drivers/mmc/piton_mmc.c

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+
+??? struct piton_mmc_priv *priv = dev_get_priv(dev);
+??? u64 start_addr = priv->piton_mmc_base_addr + (start_block);
+
+??? /* if there is a read */
+??? if (data->flags & MMC_DATA_READ) {
+??????? for (u64 i = 0; i < byte_cnt; i += 4) {
+??????????? *(buff) = readl((void *)(start_addr + i));
+??????????? buff++;
+??????? }

Can you use memcpy_fromio here?

Quoted 5 lines

+??? } else {
+??????? /* else there is a write
+???????? * we don't handle write, so error right away +???????? */
+??????? return -ENODEV;

Please use -ENOSYS.

Quoted 101 lines

+??? }

drivers/mmc/piton_mmc.c new file +99 -0
+
+??? return 0;
+}
+
+static int piton_mmc_ofdata_to_platdata(struct udevice *dev)
+{
+??? struct piton_mmc_priv *priv = dev_get_priv(dev);
+??? struct piton_mmc_plat *plat = dev_get_platdata(dev);
+??? struct mmc_config *cfg;
+??? struct mmc *mmc;
+??? /* fill in device description */
+??? struct blk_desc *bdesc;
+
+??? priv->piton_mmc_base_addr = dev_read_addr(dev);
+??? cfg = &plat->cfg;
+??? cfg->name = "PITON MMC";
+??? cfg->host_caps = MMC_MODE_8BIT;
+??? cfg->f_max = 100000;
+??? cfg->f_min = 400000;
+??? cfg->voltages = MMC_VDD_21_22;
+
+??? mmc = &plat->mmc;
+??? mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+??? mmc->capacity_user = 0x100000000;
+??? mmc->capacity_user *= mmc->read_bl_len;
+??? mmc->capacity_boot = 0;
+??? mmc->capacity_rpmb = 0;
+??? for (int i = 0; i < 4; i++)
+??????? mmc->capacity_gp[i] = 0;
+??? mmc->capacity = 0x2000000000ULL;
+??? mmc->has_init = 1;
+
+??? bdesc = mmc_get_blk_desc(mmc);
+??? bdesc->lun = 0;
+??? bdesc->hwpart = 0;
+??? bdesc->type = 0;
+??? bdesc->blksz = mmc->read_bl_len;
+??? bdesc->log2blksz = LOG2(bdesc->blksz);
+??? bdesc->lba = lldiv(mmc->capacity, mmc->read_bl_len);
+
+??? return 0;
+}
+
+/* test if piton has the micro mmc card present
+ * always return 1, which means present
+ */
+static int piton_mmc_getcd(struct udevice *dev)
+{
+??? /*
+???? * always return 1
+???? */
+??? return 1;
+}
+
+/* dummy function, piton_mmc don't need initialization
+ * in hw
+ */
+static const struct dm_mmc_ops piton_mmc_ops = {
+??? .send_cmd = piton_mmc_send_cmd,
+??? .set_ios = piton_mmc_set_ios,
+??? .get_cd = piton_mmc_getcd,
+};
+
+static int piton_mmc_probe(struct udevice *dev)
+{
+??? struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+??? struct piton_mmc_plat *plat = dev_get_platdata(dev);
+??? struct mmc_config *cfg = &plat->cfg;
+
+??? cfg->name = dev->name;
+??? upriv->mmc = &plat->mmc;
+??? upriv->mmc->has_init = 1;
+??? upriv->mmc->capacity = 0x2000000000ULL;
+??? upriv->mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+
+??? return 0;
+}
+
+static int piton_mmc_bind(struct udevice *dev)
+{
+??? struct piton_mmc_plat *plat = dev_get_platdata(dev);
+??? struct mmc_config *cfg = &plat->cfg;
+
+??? cfg->name = dev->name;
+??? cfg->host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_8BIT;
+??? cfg->voltages = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34;
+??? cfg->f_min = 1000000;
+??? cfg->f_max = 52000000;
+??? cfg->b_max = U32_MAX;
+
+??? return mmc_bind(dev, &plat->mmc, cfg);
+}
+
+static const struct udevice_id piton_mmc_ids[] = {
+??????? {.compatible = "openpiton,piton-mmc"},
+??????? { /* sentinel */ }
+};
+
+U_BOOT_DRIVER(piton_mmc_drv) = {

drivers/mmc/piton_mmc.c

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+??? .name = "piton_mmc",
+??? .id = UCLASS_MMC,
+??? .of_match = piton_mmc_ids,
+??? .ofdata_to_platdata = piton_mmc_ofdata_to_platdata,
+??? .bind = piton_mmc_bind,
+??? .probe = piton_mmc_probe,
+??? .ops = &piton_mmc_ops,
+??? .platdata_auto_alloc_size = sizeof(struct piton_mmc_plat),
+??? .priv_auto_alloc_size = sizeof(struct piton_mmc_priv),
+};

--Sean

#5 lore raw

PATCH v4 1/2 mmc: add OpenPiton mmc support

Quoted 4 lines · Tianrui Wei

Hi Sean,

Thanks for reviewing the patches, I'll fix the initialization thing and the tegra_mmc credit :P

Please also add a changelog to your next revision. It helps reviewers know what you have fixed.

--Sean

Quoted 290 lines · Sean Anderson
Quoted 288 lines · Tianrui Wei
Quoted 7 lines

Hi Sean,

Many thanks for taking your valuable time to review our patch and give suggestions. I'll improve both our patches accordingly. Just for the record, what would be the exact command you'd recommend to run checkpatch.pl? Because it only showed one warning about me not putting my name on the MAINTAINERS file on this patch.

Huh. I would have expected checkpatch to catch the variable initialization thing, but I guess it didn't.

Quoted 80 lines

Many thanks,

Tianrui

Quoted 63 lines · Sean Anderson
Quoted 9 lines · Tianrui Wei

From: Tianrui Wei <[email protected]>
Date: Thu, 6 May 2021 11:30:20 +0800
Subject: [PATCH V4 1/2] mmc: add OpenPiton mmc support

This patch adds mmc support for OpenPiton. Specifically, some dts bindings were not used because our mmc controller doens't have those configuration options, it only exposes a dummy mmap interface for CPU.

Please wrap your commit messages to 75 characterss, not 56 ;)

Quoted 33 lines

---

  drivers/mmc/Kconfig                     |   7 +
  drivers/mmc/Makefile                    |   1 +
  drivers/mmc/piton_mmc.c                 | 172 +++++
  3 files changed, 180 insertions(+)

create mode 100644 drivers/mmc/piton_mmc.c

drivers/mmc/Kconfig +6 -0
index 14d79139..1038800f 100644
@@ -707,6 +707,13 @@ config MMC_SUNXI_HAS_MODE_SWITCH
      bool
      depends on MMC_SUNXI
  +config MMC_PITON
+    bool "MMC support for openpiton SoC"
+  depends on DM_MMC && BLK
+    help
+    This driver enables SD card support in U-Boot port for
+    OpenPiton SoC
+
  config GENERIC_ATMEL_MCI
      bool "Atmel Multimedia Card Interface support"
      depends on DM_MMC && BLK && ARCH_AT91
drivers/mmc/Makefile +0 -0
index 1c849cba..698dfe05 100644

drivers/mmc/Makefile obj-$(CONFIG_MMC_SDHCI_XENON) += xenon_sdhci.o · line 73

Quoted 3 lines
drivers/mmc/Makefile +1 -0
@@ -71,6 +71,7 @@ obj-$(CONFIG_MMC_SDHCI_XENON)        += xenon_sdhci.o
  obj-$(CONFIG_MMC_SDHCI_ZYNQ)        += zynq_sdhci.o
    obj-$(CONFIG_MMC_SUNXI)            += sunxi_mmc.o
+obj-$(CONFIG_MMC_PITON)         += piton_mmc.o

Fix indentation. And please place this object in alphabetical order.

Quoted 11 lines
drivers/mmc/Makefile +0 -0
  obj-$(CONFIG_MMC_UNIPHIER)        += tmio-common.o uniphier-sd.o
  obj-$(CONFIG_RENESAS_SDHI)        += tmio-common.o renesas-sdhi.o
  obj-$(CONFIG_MMC_BCM2835)        += bcm2835_sdhost.o
drivers/mmc/piton_mmc.c new file +2 -0
new file mode 100644
index 00000000..266e26d8
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
Quoted 8 lines

drivers/mmc/piton_mmc.c line 8

Quoted 6 lines
drivers/mmc/piton_mmc.c new file +6 -0
+ * (C) Copyright 2009 SAMSUNG Electronics
+ * Minkyu Kang <[email protected]>
+ * Jaehoon Chung <[email protected]>
+ * Portions Copyright 2011-2019 NVIDIA Corporation
+ * Portions Copyright 2021 Tianrui Wei
+ * Tianrui Wei <[email protected]>

This is quite the list of authors. Where does this file come from?

Quoted 1 line

This file was adapted from a Samsung mmc file, so I kept the original authors.

Can you add a note along the lines of "Adapted from tegra_mmc.c" for the curiosity of future readers :)

--Sean

Quoted 188 lines
Quoted 188 lines
Quoted 11 lines
drivers/mmc/piton_mmc.c new file +9 -0
+ */
+
+#include <asm/gpio.h>
+#include <asm/io.h>
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <linux/bitops.h>
+#include <linux/types.h>

drivers/mmc/piton_mmc.c line 27

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <log.h>
+#include <div64.h>
+#include <mmc.h>
+
+struct piton_mmc_plat {
+    struct mmc_config cfg;
+    struct mmc mmc;
+};

Is platdata used? I don't see it in 2/2.

drivers/mmc/piton_mmc.c line 30

Quoted 3 lines
drivers/mmc/piton_mmc.c new file +3 -0
+
+struct piton_mmc_priv {
+    u64 piton_mmc_base_addr; /* peripheral id */

This should be void __iomem *.

drivers/mmc/piton_mmc.c line 43

Quoted 13 lines
drivers/mmc/piton_mmc.c new file +13 -0
+};
+
+/*
+ * see mmc_read_blocks to see how it is used.
+ * start block is hidden at cmd->arg
+ * also, initialize the block size at init
+ */
+static int piton_mmc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
+                  struct mmc_data *data)
+{
+    /* check first if this is a pure command */
+    if (!data)
+        return 0;

Please place definitions before code (and please run checkpatch).

drivers/mmc/piton_mmc.c line 47

Quoted 4 lines
drivers/mmc/piton_mmc.c new file +4 -0
+
+    u64 byte_cnt = data->blocks * data->blocksize;
+    u64 start_block = cmd->cmdarg;
+    unsigned int *buff = (unsigned int *)data->dest;

Why is buff an unsigned int? If you are using readl, shouldn't it be a long?

drivers/mmc/piton_mmc.c line 57

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+
+    struct piton_mmc_priv *priv = dev_get_priv(dev);
+    u64 start_addr = priv->piton_mmc_base_addr + (start_block);
+
+    /* if there is a read */
+    if (data->flags & MMC_DATA_READ) {
+        for (u64 i = 0; i < byte_cnt; i += 4) {
+            *(buff) = readl((void *)(start_addr + i));
+            buff++;
+        }

Can you use memcpy_fromio here?

drivers/mmc/piton_mmc.c line 62

Quoted 5 lines
drivers/mmc/piton_mmc.c new file +5 -0
+    } else {
+        /* else there is a write
+         * we don't handle write, so error right away
+         */
+        return -ENODEV;

Please use -ENOSYS.

Quoted 101 lines
drivers/mmc/piton_mmc.c new file +100 -0
+    }
+
+    return 0;
+}
+
+static int piton_mmc_ofdata_to_platdata(struct udevice *dev)
+{
+    struct piton_mmc_priv *priv = dev_get_priv(dev);
+    struct piton_mmc_plat *plat = dev_get_platdata(dev);
+    struct mmc_config *cfg;
+    struct mmc *mmc;
+    /* fill in device description */
+    struct blk_desc *bdesc;
+
+    priv->piton_mmc_base_addr = dev_read_addr(dev);
+    cfg = &plat->cfg;
+    cfg->name = "PITON MMC";
+    cfg->host_caps = MMC_MODE_8BIT;
+    cfg->f_max = 100000;
+    cfg->f_min = 400000;
+    cfg->voltages = MMC_VDD_21_22;
+
+    mmc = &plat->mmc;
+    mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+    mmc->capacity_user = 0x100000000;
+    mmc->capacity_user *= mmc->read_bl_len;
+    mmc->capacity_boot = 0;
+    mmc->capacity_rpmb = 0;
+    for (int i = 0; i < 4; i++)
+        mmc->capacity_gp[i] = 0;
+    mmc->capacity = 0x2000000000ULL;
+    mmc->has_init = 1;
+
+    bdesc = mmc_get_blk_desc(mmc);
+    bdesc->lun = 0;
+    bdesc->hwpart = 0;
+    bdesc->type = 0;
+    bdesc->blksz = mmc->read_bl_len;
+    bdesc->log2blksz = LOG2(bdesc->blksz);
+    bdesc->lba = lldiv(mmc->capacity, mmc->read_bl_len);
+
+    return 0;
+}
+
+/* test if piton has the micro mmc card present
+ * always return 1, which means present
+ */
+static int piton_mmc_getcd(struct udevice *dev)
+{
+    /*
+     * always return 1
+     */
+    return 1;
+}
+
+/* dummy function, piton_mmc don't need initialization
+ * in hw
+ */
+static const struct dm_mmc_ops piton_mmc_ops = {
+    .send_cmd = piton_mmc_send_cmd,
+    .set_ios = piton_mmc_set_ios,
+    .get_cd = piton_mmc_getcd,
+};
+
+static int piton_mmc_probe(struct udevice *dev)
+{
+    struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+    struct piton_mmc_plat *plat = dev_get_platdata(dev);
+    struct mmc_config *cfg = &plat->cfg;
+
+    cfg->name = dev->name;
+    upriv->mmc = &plat->mmc;
+    upriv->mmc->has_init = 1;
+    upriv->mmc->capacity = 0x2000000000ULL;
+    upriv->mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+
+    return 0;
+}
+
+static int piton_mmc_bind(struct udevice *dev)
+{
+    struct piton_mmc_plat *plat = dev_get_platdata(dev);
+    struct mmc_config *cfg = &plat->cfg;
+
+    cfg->name = dev->name;
+    cfg->host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_8BIT;
+    cfg->voltages = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34;
+    cfg->f_min = 1000000;
+    cfg->f_max = 52000000;
+    cfg->b_max = U32_MAX;
+
+    return mmc_bind(dev, &plat->mmc, cfg);
+}
+
+static const struct udevice_id piton_mmc_ids[] = {
+        {.compatible = "openpiton,piton-mmc"},
+        { /* sentinel */ }
+};
+
+U_BOOT_DRIVER(piton_mmc_drv) = {

drivers/mmc/piton_mmc.c line 172

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+    .name = "piton_mmc",
+    .id = UCLASS_MMC,
+    .of_match = piton_mmc_ids,
+    .ofdata_to_platdata = piton_mmc_ofdata_to_platdata,
+    .bind = piton_mmc_bind,
+    .probe = piton_mmc_probe,
+    .ops = &piton_mmc_ops,
+    .platdata_auto_alloc_size = sizeof(struct piton_mmc_plat),
+    .priv_auto_alloc_size = sizeof(struct piton_mmc_priv),
+};

--Sean

#6 lore raw

PATCH v4 1/2 mmc: add OpenPiton mmc support

Quoted 4 lines · Sean Anderson
Quoted 3 lines · Tianrui Wei

Hi Sean,

Quoted 179 lines
Quoted 2 lines

Thanks for reviewing the patches, I'll fix the initialization thing and the tegra_mmc credit :P

Please also add a changelog to your next revision. It helps reviewers know what you have fixed.

--Sean

Quoted 171 lines · Sean Anderson
Quoted 169 lines · Tianrui Wei
Quoted 7 lines

Hi Sean,

Many thanks for taking your valuable time to review our patch and give suggestions. I'll improve both our patches accordingly. Just for the record, what would be the exact command you'd recommend to run checkpatch.pl? Because it only showed one warning about me not putting my name on the MAINTAINERS file on this patch.

Huh. I would have expected checkpatch to catch the variable initialization thing, but I guess it didn't.

Quoted 80 lines

Many thanks,

Tianrui

Quoted 63 lines · Sean Anderson
Quoted 9 lines · Tianrui Wei

From: Tianrui Wei <[email protected]>
Date: Thu, 6 May 2021 11:30:20 +0800
Subject: [PATCH V4 1/2] mmc: add OpenPiton mmc support

This patch adds mmc support for OpenPiton. Specifically, some dts bindings were not used because our mmc controller doens't have those configuration options, it only exposes a dummy mmap interface for CPU.

Please wrap your commit messages to 75 characterss, not 56 ;)

Quoted 33 lines

---

? drivers/mmc/Kconfig???????????????????? |?? 7 +
? drivers/mmc/Makefile??????????????????? |?? 1 +
? drivers/mmc/piton_mmc.c???????????????? | 172 +++++

? 3 files changed, 180 insertions(+)
? create mode 100644 drivers/mmc/piton_mmc.c

drivers/mmc/Kconfig +0 -0
index 14d79139..1038800f 100644
@@ -707,6 +707,13 @@ config MMC_SUNXI_HAS_MODE_SWITCH

????? bool
????? depends on MMC_SUNXI
? +config MMC_PITON
+??? bool "MMC support for openpiton SoC"
+? depends on DM_MMC && BLK
+??? help
+??? This driver enables SD card support in U-Boot port for +??? OpenPiton SoC
+
? config GENERIC_ATMEL_MCI
????? bool "Atmel Multimedia Card Interface support" ????? depends on DM_MMC && BLK && ARCH_AT91

drivers/mmc/Makefile +0 -0
index 1c849cba..698dfe05 100644
@@ -71,6 +71,7 @@ obj-$(CONFIG_MMC_SDHCI_XENON) += xenon_sdhci.o
Quoted 3 lines

? obj-$(CONFIG_MMC_SDHCI_ZYNQ)??????? += zynq_sdhci.o ??? obj-$(CONFIG_MMC_SUNXI)??????????? += sunxi_mmc.o +obj-$(CONFIG_MMC_PITON)???????? += piton_mmc.o

Fix indentation. And please place this object in alphabetical order.

Quoted 11 lines

obj-$(CONFIG_MMC_UNIPHIER)??????? += tmio-common.o uniphier-sd.o ? obj-$(CONFIG_RENESAS_SDHI)??????? += tmio-common.o renesas-sdhi.o ? obj-$(CONFIG_MMC_BCM2835)??????? += bcm2835_sdhost.o

drivers/mmc/piton_mmc.c new file +2 -0
new file mode 100644
index 00000000..266e26d8
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
Quoted 8 lines

drivers/mmc/piton_mmc.c line 8

Quoted 6 lines
drivers/mmc/piton_mmc.c new file +6 -0
+ * (C) Copyright 2009 SAMSUNG Electronics
+ * Minkyu Kang <[email protected]>
+ * Jaehoon Chung <[email protected]>
+ * Portions Copyright 2011-2019 NVIDIA Corporation
+ * Portions Copyright 2021 Tianrui Wei
+ * Tianrui Wei <[email protected]>

This is quite the list of authors. Where does this file come from?

Quoted 2 lines

This file was adapted from a Samsung mmc file, so I kept the original authors.

Can you add a note along the lines of "Adapted from tegra_mmc.c" for the
curiosity of future readers :)

--Sean

Quoted 68 lines
Quoted 68 lines
Quoted 11 lines
drivers/mmc/piton_mmc.c new file +9 -0
+ */
+
+#include <asm/gpio.h>
+#include <asm/io.h>
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <linux/bitops.h>
+#include <linux/types.h>

drivers/mmc/piton_mmc.c line 27

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <log.h>
+#include <div64.h>
+#include <mmc.h>
+
+struct piton_mmc_plat {
+??? struct mmc_config cfg;
+??? struct mmc mmc;
+};

Is platdata used? I don't see it in 2/2.

drivers/mmc/piton_mmc.c

Quoted 3 lines
drivers/mmc/piton_mmc.c new file +3 -0
+
+struct piton_mmc_priv {
+??? u64 piton_mmc_base_addr; /* peripheral id */

This should be void __iomem *.

Quoted 8 lines
drivers/mmc/piton_mmc.c new file +8 -0
+};
+
+/*
+ * see mmc_read_blocks to see how it is used.
+ * start block is hidden at cmd->arg
+ * also, initialize the block size at init
+ */
+static int piton_mmc_send_cmd(struct udevice *dev, struct 
Quoted 6 lines

mmc_cmd *cmd,
+????????????????? struct mmc_data *data)
+{
+??? /* check first if this is a pure command */
+??? if (!data)
+??????? return 0;

Please place definitions before code (and please run checkpatch).

Quoted 4 lines

+
+??? u64 byte_cnt = data->blocks * data->blocksize; +??? u64 start_block = cmd->cmdarg;
+??? unsigned int *buff = (unsigned int *)data->dest;

Why is buff an unsigned int? If you are using readl, shouldn't it be a
long?

drivers/mmc/piton_mmc.c

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+
+??? struct piton_mmc_priv *priv = dev_get_priv(dev);
+??? u64 start_addr = priv->piton_mmc_base_addr + (start_block);
+
+??? /* if there is a read */
+??? if (data->flags & MMC_DATA_READ) {
+??????? for (u64 i = 0; i < byte_cnt; i += 4) {
+??????????? *(buff) = readl((void *)(start_addr + i));
+??????????? buff++;
+??????? }

Can you use memcpy_fromio here?

I went back and double check, seems that it only applies for board with PCI configured

Quoted 117 lines
Quoted 117 lines
Quoted 117 lines
Quoted 117 lines
Quoted 117 lines
Quoted 6 lines

+??? } else {
+??????? /* else there is a write
+???????? * we don't handle write, so error right away +???????? */
+??????? return -ENODEV;

Please use -ENOSYS.

Quoted 108 lines

+??? }

drivers/mmc/piton_mmc.c new file +85 -0
+
+??? return 0;
+}
+
+static int piton_mmc_ofdata_to_platdata(struct udevice *dev)
+{
+??? struct piton_mmc_priv *priv = dev_get_priv(dev);
+??? struct piton_mmc_plat *plat = dev_get_platdata(dev);
+??? struct mmc_config *cfg;
+??? struct mmc *mmc;
+??? /* fill in device description */
+??? struct blk_desc *bdesc;
+
+??? priv->piton_mmc_base_addr = dev_read_addr(dev);
+??? cfg = &plat->cfg;
+??? cfg->name = "PITON MMC";
+??? cfg->host_caps = MMC_MODE_8BIT;
+??? cfg->f_max = 100000;
+??? cfg->f_min = 400000;
+??? cfg->voltages = MMC_VDD_21_22;
+
+??? mmc = &plat->mmc;
+??? mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+??? mmc->capacity_user = 0x100000000;
+??? mmc->capacity_user *= mmc->read_bl_len;
+??? mmc->capacity_boot = 0;
+??? mmc->capacity_rpmb = 0;
+??? for (int i = 0; i < 4; i++)
+??????? mmc->capacity_gp[i] = 0;
+??? mmc->capacity = 0x2000000000ULL;
+??? mmc->has_init = 1;
+
+??? bdesc = mmc_get_blk_desc(mmc);
+??? bdesc->lun = 0;
+??? bdesc->hwpart = 0;
+??? bdesc->type = 0;
+??? bdesc->blksz = mmc->read_bl_len;
+??? bdesc->log2blksz = LOG2(bdesc->blksz);
+??? bdesc->lba = lldiv(mmc->capacity, mmc->read_bl_len);
+
+??? return 0;
+}
+
+/* test if piton has the micro mmc card present
+ * always return 1, which means present
+ */
+static int piton_mmc_getcd(struct udevice *dev)
+{
+??? /*
+???? * always return 1
+???? */
+??? return 1;
+}
+
+/* dummy function, piton_mmc don't need initialization
+ * in hw
+ */
+static const struct dm_mmc_ops piton_mmc_ops = {
+??? .send_cmd = piton_mmc_send_cmd,
+??? .set_ios = piton_mmc_set_ios,
+??? .get_cd = piton_mmc_getcd,
+};
+
+static int piton_mmc_probe(struct udevice *dev)
+{
+??? struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+??? struct piton_mmc_plat *plat = dev_get_platdata(dev);
+??? struct mmc_config *cfg = &plat->cfg;
+
+??? cfg->name = dev->name;
+??? upriv->mmc = &plat->mmc;
+??? upriv->mmc->has_init = 1;
+??? upriv->mmc->capacity = 0x2000000000ULL;
+??? upriv->mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+
+??? return 0;
+}
+
+static int piton_mmc_bind(struct udevice *dev)
+{
+??? struct piton_mmc_plat *plat = dev_get_platdata(dev);
+??? struct mmc_config *cfg = &plat->cfg;
+
+??? cfg->name = dev->name;
+??? cfg->host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | 

MMC_MODE_8BIT;
+??? cfg->voltages = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34;
+??? cfg->f_min = 1000000;
+??? cfg->f_max = 52000000;
+??? cfg->b_max = U32_MAX;

drivers/mmc/piton_mmc.c new file +16 -0
+
+??? return mmc_bind(dev, &plat->mmc, cfg);
+}
+
+static const struct udevice_id piton_mmc_ids[] = {
+??????? {.compatible = "openpiton,piton-mmc"},
+??????? { /* sentinel */ }
+};
+
+U_BOOT_DRIVER(piton_mmc_drv) = {
+??? .name = "piton_mmc",
+??? .id = UCLASS_MMC,
+??? .of_match = piton_mmc_ids,
+??? .ofdata_to_platdata = piton_mmc_ofdata_to_platdata,
+??? .bind = piton_mmc_bind,
+??? .probe = piton_mmc_probe,
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

+??? .ops = &piton_mmc_ops,
+??? .platdata_auto_alloc_size = sizeof(struct piton_mmc_plat), +??? .priv_auto_alloc_size = sizeof(struct piton_mmc_priv), +};

--Sean

Thanks,

Tianrui

#7 lore raw

PATCH v4 1/2 mmc: add OpenPiton mmc support

Quoted 182 lines · Tianrui Wei
Quoted 4 lines · Sean Anderson
Quoted 3 lines · Tianrui Wei

Hi Sean,

Quoted 174 lines
Quoted 1 line

Thanks for reviewing the patches, I'll fix the initialization thing and the tegra_mmc credit :P

Please also add a changelog to your next revision. It helps reviewers know what you have fixed.

--Sean

Quoted 167 lines · Sean Anderson
Quoted 165 lines · Tianrui Wei
Quoted 7 lines

Hi Sean,

Many thanks for taking your valuable time to review our patch and give suggestions. I'll improve both our patches accordingly. Just for the record, what would be the exact command you'd recommend to run checkpatch.pl? Because it only showed one warning about me not putting my name on the MAINTAINERS file on this patch.

Huh. I would have expected checkpatch to catch the variable initialization thing, but I guess it didn't.

Quoted 80 lines

Many thanks,

Tianrui

Quoted 63 lines · Sean Anderson
Quoted 9 lines · Tianrui Wei

From: Tianrui Wei <[email protected]>
Date: Thu, 6 May 2021 11:30:20 +0800
Subject: [PATCH V4 1/2] mmc: add OpenPiton mmc support

This patch adds mmc support for OpenPiton. Specifically, some dts bindings were not used because our mmc controller doens't have those configuration options, it only exposes a dummy mmap interface for CPU.

Please wrap your commit messages to 75 characterss, not 56 ;)

Quoted 33 lines

---

? drivers/mmc/Kconfig???????????????????? |?? 7 +
? drivers/mmc/Makefile??????????????????? |?? 1 +
? drivers/mmc/piton_mmc.c???????????????? | 172 +++++

? 3 files changed, 180 insertions(+)
? create mode 100644 drivers/mmc/piton_mmc.c

drivers/mmc/Kconfig +0 -0
index 14d79139..1038800f 100644
@@ -707,6 +707,13 @@ config MMC_SUNXI_HAS_MODE_SWITCH

????? bool
????? depends on MMC_SUNXI
? +config MMC_PITON
+??? bool "MMC support for openpiton SoC"
+? depends on DM_MMC && BLK
+??? help
+??? This driver enables SD card support in U-Boot port for +??? OpenPiton SoC
+
? config GENERIC_ATMEL_MCI
????? bool "Atmel Multimedia Card Interface support" ????? depends on DM_MMC && BLK && ARCH_AT91

drivers/mmc/Makefile +0 -0
index 1c849cba..698dfe05 100644
@@ -71,6 +71,7 @@ obj-$(CONFIG_MMC_SDHCI_XENON) += xenon_sdhci.o
Quoted 3 lines

? obj-$(CONFIG_MMC_SDHCI_ZYNQ)??????? += zynq_sdhci.o ??? obj-$(CONFIG_MMC_SUNXI)??????????? += sunxi_mmc.o +obj-$(CONFIG_MMC_PITON)???????? += piton_mmc.o

Fix indentation. And please place this object in alphabetical order.

Quoted 11 lines

obj-$(CONFIG_MMC_UNIPHIER)??????? += tmio-common.o uniphier-sd.o ? obj-$(CONFIG_RENESAS_SDHI)??????? += tmio-common.o renesas-sdhi.o ? obj-$(CONFIG_MMC_BCM2835)??????? += bcm2835_sdhost.o

drivers/mmc/piton_mmc.c new file +2 -0
new file mode 100644
index 00000000..266e26d8
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
Quoted 8 lines

drivers/mmc/piton_mmc.c line 8

Quoted 6 lines
drivers/mmc/piton_mmc.c new file +6 -0
+ * (C) Copyright 2009 SAMSUNG Electronics
+ * Minkyu Kang <[email protected]>
+ * Jaehoon Chung <[email protected]>
+ * Portions Copyright 2011-2019 NVIDIA Corporation
+ * Portions Copyright 2021 Tianrui Wei
+ * Tianrui Wei <[email protected]>

This is quite the list of authors. Where does this file come from?

Quoted 1 line

This file was adapted from a Samsung mmc file, so I kept the original authors.

Can you add a note along the lines of "Adapted from tegra_mmc.c" for the curiosity of future readers :)

--Sean

Quoted 66 lines
Quoted 66 lines
Quoted 11 lines
drivers/mmc/piton_mmc.c new file +9 -0
+ */
+
+#include <asm/gpio.h>
+#include <asm/io.h>
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <linux/bitops.h>
+#include <linux/types.h>

drivers/mmc/piton_mmc.c line 27

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <log.h>
+#include <div64.h>
+#include <mmc.h>
+
+struct piton_mmc_plat {
+??? struct mmc_config cfg;
+??? struct mmc mmc;
+};

Is platdata used? I don't see it in 2/2.

drivers/mmc/piton_mmc.c line 30

Quoted 3 lines
drivers/mmc/piton_mmc.c new file +3 -0
+
+struct piton_mmc_priv {
+??? u64 piton_mmc_base_addr; /* peripheral id */

This should be void __iomem *.

drivers/mmc/piton_mmc.c line 43

Quoted 13 lines
drivers/mmc/piton_mmc.c new file +13 -0
+};
+
+/*
+ * see mmc_read_blocks to see how it is used.
+ * start block is hidden at cmd->arg
+ * also, initialize the block size at init
+ */
+static int piton_mmc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
+????????????????? struct mmc_data *data)
+{
+??? /* check first if this is a pure command */
+??? if (!data)
+??????? return 0;

Please place definitions before code (and please run checkpatch).

drivers/mmc/piton_mmc.c line 47

Quoted 4 lines
drivers/mmc/piton_mmc.c new file +4 -0
+
+??? u64 byte_cnt = data->blocks * data->blocksize;
+??? u64 start_block = cmd->cmdarg;
+??? unsigned int *buff = (unsigned int *)data->dest;

Why is buff an unsigned int? If you are using readl, shouldn't it be a long?

drivers/mmc/piton_mmc.c line 57

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+
+??? struct piton_mmc_priv *priv = dev_get_priv(dev);
+??? u64 start_addr = priv->piton_mmc_base_addr + (start_block);
+
+??? /* if there is a read */
+??? if (data->flags & MMC_DATA_READ) {
+??????? for (u64 i = 0; i < byte_cnt; i += 4) {
+??????????? *(buff) = readl((void *)(start_addr + i));
+??????????? buff++;
+??????? }

Can you use memcpy_fromio here?

Quoted 1 line

I went back and double check, seems that it only applies for board with PCI configured

Ok, then does memcpy work?

--Sean

Quoted 130 lines
Quoted 117 lines
Quoted 117 lines
Quoted 117 lines
Quoted 117 lines
Quoted 117 lines

drivers/mmc/piton_mmc.c line 62

Quoted 8 lines
drivers/mmc/piton_mmc.c new file +5 -0
+??? } else {
+??????? /* else there is a write
+???????? * we don't handle write, so error right away
+???????? */
+??????? return -ENODEV;

Please use -ENOSYS.

Quoted 106 lines
drivers/mmc/piton_mmc.c new file +106 -0
+??? }
+
+??? return 0;
+}
+
+static int piton_mmc_ofdata_to_platdata(struct udevice *dev)
+{
+??? struct piton_mmc_priv *priv = dev_get_priv(dev);
+??? struct piton_mmc_plat *plat = dev_get_platdata(dev);
+??? struct mmc_config *cfg;
+??? struct mmc *mmc;
+??? /* fill in device description */
+??? struct blk_desc *bdesc;
+
+??? priv->piton_mmc_base_addr = dev_read_addr(dev);
+??? cfg = &plat->cfg;
+??? cfg->name = "PITON MMC";
+??? cfg->host_caps = MMC_MODE_8BIT;
+??? cfg->f_max = 100000;
+??? cfg->f_min = 400000;
+??? cfg->voltages = MMC_VDD_21_22;
+
+??? mmc = &plat->mmc;
+??? mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+??? mmc->capacity_user = 0x100000000;
+??? mmc->capacity_user *= mmc->read_bl_len;
+??? mmc->capacity_boot = 0;
+??? mmc->capacity_rpmb = 0;
+??? for (int i = 0; i < 4; i++)
+??????? mmc->capacity_gp[i] = 0;
+??? mmc->capacity = 0x2000000000ULL;
+??? mmc->has_init = 1;
+
+??? bdesc = mmc_get_blk_desc(mmc);
+??? bdesc->lun = 0;
+??? bdesc->hwpart = 0;
+??? bdesc->type = 0;
+??? bdesc->blksz = mmc->read_bl_len;
+??? bdesc->log2blksz = LOG2(bdesc->blksz);
+??? bdesc->lba = lldiv(mmc->capacity, mmc->read_bl_len);
+
+??? return 0;
+}
+
+/* test if piton has the micro mmc card present
+ * always return 1, which means present
+ */
+static int piton_mmc_getcd(struct udevice *dev)
+{
+??? /*
+???? * always return 1
+???? */
+??? return 1;
+}
+
+/* dummy function, piton_mmc don't need initialization
+ * in hw
+ */
+static const struct dm_mmc_ops piton_mmc_ops = {
+??? .send_cmd = piton_mmc_send_cmd,
+??? .set_ios = piton_mmc_set_ios,
+??? .get_cd = piton_mmc_getcd,
+};
+
+static int piton_mmc_probe(struct udevice *dev)
+{
+??? struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+??? struct piton_mmc_plat *plat = dev_get_platdata(dev);
+??? struct mmc_config *cfg = &plat->cfg;
+
+??? cfg->name = dev->name;
+??? upriv->mmc = &plat->mmc;
+??? upriv->mmc->has_init = 1;
+??? upriv->mmc->capacity = 0x2000000000ULL;
+??? upriv->mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+
+??? return 0;
+}
+
+static int piton_mmc_bind(struct udevice *dev)
+{
+??? struct piton_mmc_plat *plat = dev_get_platdata(dev);
+??? struct mmc_config *cfg = &plat->cfg;
+
+??? cfg->name = dev->name;
+??? cfg->host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_8BIT;
+??? cfg->voltages = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34;
+??? cfg->f_min = 1000000;
+??? cfg->f_max = 52000000;
+??? cfg->b_max = U32_MAX;
+
+??? return mmc_bind(dev, &plat->mmc, cfg);
+}
+
+static const struct udevice_id piton_mmc_ids[] = {
+??????? {.compatible = "openpiton,piton-mmc"},
+??????? { /* sentinel */ }
+};
+
+U_BOOT_DRIVER(piton_mmc_drv) = {
+??? .name = "piton_mmc",
+??? .id = UCLASS_MMC,
+??? .of_match = piton_mmc_ids,
+??? .ofdata_to_platdata = piton_mmc_ofdata_to_platdata,
+??? .bind = piton_mmc_bind,
+??? .probe = piton_mmc_probe,
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines

drivers/mmc/piton_mmc.c line 172

Quoted 5 lines
drivers/mmc/piton_mmc.c new file +4 -0
+??? .ops = &piton_mmc_ops,
+??? .platdata_auto_alloc_size = sizeof(struct piton_mmc_plat),
+??? .priv_auto_alloc_size = sizeof(struct piton_mmc_priv),
+};

--Sean

Thanks,

Tianrui

#8 lore raw

PATCH v4 1/2 mmc: add OpenPiton mmc support

Quoted 192 lines · Sean Anderson
Quoted 191 lines · Tianrui Wei
Quoted 187 lines · Sean Anderson
Quoted 5 lines · Tianrui Wei

Hi Sean,

Thanks for reviewing the patches, I'll fix the initialization thing and the tegra_mmc credit :P

Please also add a changelog to your next revision. It helps reviewers know what you have fixed.

--Sean

Quoted 175 lines · Sean Anderson
Quoted 173 lines · Tianrui Wei
Quoted 9 lines

Hi Sean,

Many thanks for taking your valuable time to review our patch and give
suggestions. I'll improve both our patches accordingly. Just for the record, what would be the exact command you'd recommend to run checkpatch.pl? Because it only showed one warning about me not putting
my name on the MAINTAINERS file on this patch.

Huh. I would have expected checkpatch to catch the variable initialization thing, but I guess it didn't.

Quoted 82 lines

Many thanks,

Tianrui

Quoted 65 lines · Sean Anderson
Quoted 9 lines · Tianrui Wei

From: Tianrui Wei <[email protected]>
Date: Thu, 6 May 2021 11:30:20 +0800
Subject: [PATCH V4 1/2] mmc: add OpenPiton mmc support

This patch adds mmc support for OpenPiton. Specifically, some dts bindings were not used because our mmc controller doens't have those configuration options, it only exposes a dummy mmap interface for CPU.

Please wrap your commit messages to 75 characterss, not 56 ;)

Quoted 33 lines

---

? drivers/mmc/Kconfig???????????????????? |?? 7 +
? drivers/mmc/Makefile??????????????????? |?? 1 +
? drivers/mmc/piton_mmc.c???????????????? | 172 +++++

? 3 files changed, 180 insertions(+)
? create mode 100644 drivers/mmc/piton_mmc.c

drivers/mmc/Kconfig +0 -0
index 14d79139..1038800f 100644
@@ -707,6 +707,13 @@ config MMC_SUNXI_HAS_MODE_SWITCH

????? bool
????? depends on MMC_SUNXI
? +config MMC_PITON
+??? bool "MMC support for openpiton SoC"
+? depends on DM_MMC && BLK
+??? help
+??? This driver enables SD card support in U-Boot port for +??? OpenPiton SoC
+
? config GENERIC_ATMEL_MCI
????? bool "Atmel Multimedia Card Interface support" ????? depends on DM_MMC && BLK && ARCH_AT91

drivers/mmc/Makefile +0 -0
index 1c849cba..698dfe05 100644
@@ -71,6 +71,7 @@ obj-$(CONFIG_MMC_SDHCI_XENON) += xenon_sdhci.o
Quoted 3 lines

? obj-$(CONFIG_MMC_SDHCI_ZYNQ)??????? += zynq_sdhci.o ??? obj-$(CONFIG_MMC_SUNXI)??????????? += sunxi_mmc.o +obj-$(CONFIG_MMC_PITON)???????? += piton_mmc.o

Fix indentation. And please place this object in alphabetical order.

Quoted 12 lines

obj-$(CONFIG_MMC_UNIPHIER) += tmio-common.o uniphier-sd.o ? obj-$(CONFIG_RENESAS_SDHI)??????? += tmio-common.o renesas-sdhi.o
? obj-$(CONFIG_MMC_BCM2835)??????? += bcm2835_sdhost.o

drivers/mmc/piton_mmc.c new file +2 -0
new file mode 100644
index 00000000..266e26d8
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
Quoted 8 lines

drivers/mmc/piton_mmc.c line 8

Quoted 6 lines
drivers/mmc/piton_mmc.c new file +6 -0
+ * (C) Copyright 2009 SAMSUNG Electronics
+ * Minkyu Kang <[email protected]>
+ * Jaehoon Chung <[email protected]>
+ * Portions Copyright 2011-2019 NVIDIA Corporation
+ * Portions Copyright 2021 Tianrui Wei
+ * Tianrui Wei <[email protected]>

This is quite the list of authors. Where does this file come from?

Quoted 2 lines

This file was adapted from a Samsung mmc file, so I kept the original authors.

Can you add a note along the lines of "Adapted from tegra_mmc.c" for the
curiosity of future readers :)

--Sean

Quoted 68 lines
Quoted 68 lines
Quoted 11 lines
drivers/mmc/piton_mmc.c new file +9 -0
+ */
+
+#include <asm/gpio.h>
+#include <asm/io.h>
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <linux/bitops.h>
+#include <linux/types.h>

drivers/mmc/piton_mmc.c line 27

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <log.h>
+#include <div64.h>
+#include <mmc.h>
+
+struct piton_mmc_plat {
+??? struct mmc_config cfg;
+??? struct mmc mmc;
+};

Is platdata used? I don't see it in 2/2.

drivers/mmc/piton_mmc.c line 30

Quoted 3 lines
drivers/mmc/piton_mmc.c new file +3 -0
+
+struct piton_mmc_priv {
+??? u64 piton_mmc_base_addr; /* peripheral id */

This should be void __iomem *.

Quoted 8 lines
drivers/mmc/piton_mmc.c new file +8 -0
+};
+
+/*
+ * see mmc_read_blocks to see how it is used.
+ * start block is hidden at cmd->arg
+ * also, initialize the block size at init
+ */
+static int piton_mmc_send_cmd(struct udevice *dev, struct 
Quoted 6 lines

mmc_cmd *cmd,
+????????????????? struct mmc_data *data)
+{
+??? /* check first if this is a pure command */
+??? if (!data)
+??????? return 0;

Please place definitions before code (and please run checkpatch).

Quoted 4 lines

+
+??? u64 byte_cnt = data->blocks * data->blocksize; +??? u64 start_block = cmd->cmdarg;
+??? unsigned int *buff = (unsigned int *)data->dest;

Why is buff an unsigned int? If you are using readl, shouldn't it be a
long?

drivers/mmc/piton_mmc.c

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+
+??? struct piton_mmc_priv *priv = dev_get_priv(dev);
+??? u64 start_addr = priv->piton_mmc_base_addr + (start_block);
+
+??? /* if there is a read */
+??? if (data->flags & MMC_DATA_READ) {
+??????? for (u64 i = 0; i < byte_cnt; i += 4) {
+??????????? *(buff) = readl((void *)(start_addr + i));
+??????????? buff++;
+??????? }

Can you use memcpy_fromio here?

Quoted 6 lines
Quoted 2 lines

I went back and double check, seems that it only applies for board with PCI configured

Ok, then does memcpy work?

--Sean

I'm afraid not, I was under the impression that memcpy cannot deal with uncachable region

Thanks,

Tianrui

Quoted 136 lines
Quoted 134 lines
Quoted 121 lines
Quoted 121 lines
Quoted 121 lines
Quoted 121 lines
Quoted 121 lines
Quoted 10 lines

+??? } else {
+??????? /* else there is a write
+???????? * we don't handle write, so error right away +???????? */
+??????? return -ENODEV;

Please use -ENOSYS.

Quoted 108 lines

+??? }

drivers/mmc/piton_mmc.c new file +85 -0
+
+??? return 0;
+}
+
+static int piton_mmc_ofdata_to_platdata(struct udevice *dev)
+{
+??? struct piton_mmc_priv *priv = dev_get_priv(dev);
+??? struct piton_mmc_plat *plat = dev_get_platdata(dev);
+??? struct mmc_config *cfg;
+??? struct mmc *mmc;
+??? /* fill in device description */
+??? struct blk_desc *bdesc;
+
+??? priv->piton_mmc_base_addr = dev_read_addr(dev);
+??? cfg = &plat->cfg;
+??? cfg->name = "PITON MMC";
+??? cfg->host_caps = MMC_MODE_8BIT;
+??? cfg->f_max = 100000;
+??? cfg->f_min = 400000;
+??? cfg->voltages = MMC_VDD_21_22;
+
+??? mmc = &plat->mmc;
+??? mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+??? mmc->capacity_user = 0x100000000;
+??? mmc->capacity_user *= mmc->read_bl_len;
+??? mmc->capacity_boot = 0;
+??? mmc->capacity_rpmb = 0;
+??? for (int i = 0; i < 4; i++)
+??????? mmc->capacity_gp[i] = 0;
+??? mmc->capacity = 0x2000000000ULL;
+??? mmc->has_init = 1;
+
+??? bdesc = mmc_get_blk_desc(mmc);
+??? bdesc->lun = 0;
+??? bdesc->hwpart = 0;
+??? bdesc->type = 0;
+??? bdesc->blksz = mmc->read_bl_len;
+??? bdesc->log2blksz = LOG2(bdesc->blksz);
+??? bdesc->lba = lldiv(mmc->capacity, mmc->read_bl_len);
+
+??? return 0;
+}
+
+/* test if piton has the micro mmc card present
+ * always return 1, which means present
+ */
+static int piton_mmc_getcd(struct udevice *dev)
+{
+??? /*
+???? * always return 1
+???? */
+??? return 1;
+}
+
+/* dummy function, piton_mmc don't need initialization
+ * in hw
+ */
+static const struct dm_mmc_ops piton_mmc_ops = {
+??? .send_cmd = piton_mmc_send_cmd,
+??? .set_ios = piton_mmc_set_ios,
+??? .get_cd = piton_mmc_getcd,
+};
+
+static int piton_mmc_probe(struct udevice *dev)
+{
+??? struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+??? struct piton_mmc_plat *plat = dev_get_platdata(dev);
+??? struct mmc_config *cfg = &plat->cfg;
+
+??? cfg->name = dev->name;
+??? upriv->mmc = &plat->mmc;
+??? upriv->mmc->has_init = 1;
+??? upriv->mmc->capacity = 0x2000000000ULL;
+??? upriv->mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+
+??? return 0;
+}
+
+static int piton_mmc_bind(struct udevice *dev)
+{
+??? struct piton_mmc_plat *plat = dev_get_platdata(dev);
+??? struct mmc_config *cfg = &plat->cfg;
+
+??? cfg->name = dev->name;
+??? cfg->host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | 

MMC_MODE_8BIT;
+??? cfg->voltages = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34;
+??? cfg->f_min = 1000000;
+??? cfg->f_max = 52000000;
+??? cfg->b_max = U32_MAX;

drivers/mmc/piton_mmc.c new file +16 -0
+
+??? return mmc_bind(dev, &plat->mmc, cfg);
+}
+
+static const struct udevice_id piton_mmc_ids[] = {
+??????? {.compatible = "openpiton,piton-mmc"},
+??????? { /* sentinel */ }
+};
+
+U_BOOT_DRIVER(piton_mmc_drv) = {
+??? .name = "piton_mmc",
+??? .id = UCLASS_MMC,
+??? .of_match = piton_mmc_ids,
+??? .ofdata_to_platdata = piton_mmc_ofdata_to_platdata,
+??? .bind = piton_mmc_bind,
+??? .probe = piton_mmc_probe,
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

+??? .ops = &piton_mmc_ops,
+??? .platdata_auto_alloc_size = sizeof(struct piton_mmc_plat), +??? .priv_auto_alloc_size = sizeof(struct piton_mmc_priv), +};

--Sean

Thanks,

Tianrui

#9 lore raw

PATCH v4 1/2 mmc: add OpenPiton mmc support

In reply to Sean Anderson
Quoted 192 lines · Sean Anderson
Quoted 191 lines · Tianrui Wei
Quoted 187 lines · Sean Anderson
Quoted 5 lines · Tianrui Wei

Hi Sean,

Thanks for reviewing the patches, I'll fix the initialization thing and the tegra_mmc credit :P

Please also add a changelog to your next revision. It helps reviewers know what you have fixed.

--Sean

Quoted 175 lines · Sean Anderson
Quoted 173 lines · Tianrui Wei
Quoted 9 lines

Hi Sean,

Many thanks for taking your valuable time to review our patch and give
suggestions. I'll improve both our patches accordingly. Just for the record, what would be the exact command you'd recommend to run checkpatch.pl? Because it only showed one warning about me not putting
my name on the MAINTAINERS file on this patch.

Huh. I would have expected checkpatch to catch the variable initialization thing, but I guess it didn't.

Quoted 82 lines

Many thanks,

Tianrui

Quoted 65 lines · Sean Anderson
Quoted 9 lines · Tianrui Wei

From: Tianrui Wei <[email protected]>
Date: Thu, 6 May 2021 11:30:20 +0800
Subject: [PATCH V4 1/2] mmc: add OpenPiton mmc support

This patch adds mmc support for OpenPiton. Specifically, some dts bindings were not used because our mmc controller doens't have those configuration options, it only exposes a dummy mmap interface for CPU.

Please wrap your commit messages to 75 characterss, not 56 ;)

Quoted 33 lines

---

? drivers/mmc/Kconfig???????????????????? |?? 7 +
? drivers/mmc/Makefile??????????????????? |?? 1 +
? drivers/mmc/piton_mmc.c???????????????? | 172 +++++

? 3 files changed, 180 insertions(+)
? create mode 100644 drivers/mmc/piton_mmc.c

drivers/mmc/Kconfig +0 -0
index 14d79139..1038800f 100644
@@ -707,6 +707,13 @@ config MMC_SUNXI_HAS_MODE_SWITCH

????? bool
????? depends on MMC_SUNXI
? +config MMC_PITON
+??? bool "MMC support for openpiton SoC"
+? depends on DM_MMC && BLK
+??? help
+??? This driver enables SD card support in U-Boot port for +??? OpenPiton SoC
+
? config GENERIC_ATMEL_MCI
????? bool "Atmel Multimedia Card Interface support" ????? depends on DM_MMC && BLK && ARCH_AT91

drivers/mmc/Makefile +0 -0
index 1c849cba..698dfe05 100644
@@ -71,6 +71,7 @@ obj-$(CONFIG_MMC_SDHCI_XENON) += xenon_sdhci.o
Quoted 3 lines

? obj-$(CONFIG_MMC_SDHCI_ZYNQ)??????? += zynq_sdhci.o ??? obj-$(CONFIG_MMC_SUNXI)??????????? += sunxi_mmc.o +obj-$(CONFIG_MMC_PITON)???????? += piton_mmc.o

Fix indentation. And please place this object in alphabetical order.

Quoted 12 lines

obj-$(CONFIG_MMC_UNIPHIER) += tmio-common.o uniphier-sd.o ? obj-$(CONFIG_RENESAS_SDHI)??????? += tmio-common.o renesas-sdhi.o
? obj-$(CONFIG_MMC_BCM2835)??????? += bcm2835_sdhost.o

drivers/mmc/piton_mmc.c new file +2 -0
new file mode 100644
index 00000000..266e26d8
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
Quoted 8 lines

drivers/mmc/piton_mmc.c line 8

Quoted 6 lines
drivers/mmc/piton_mmc.c new file +6 -0
+ * (C) Copyright 2009 SAMSUNG Electronics
+ * Minkyu Kang <[email protected]>
+ * Jaehoon Chung <[email protected]>
+ * Portions Copyright 2011-2019 NVIDIA Corporation
+ * Portions Copyright 2021 Tianrui Wei
+ * Tianrui Wei <[email protected]>

This is quite the list of authors. Where does this file come from?

Quoted 2 lines

This file was adapted from a Samsung mmc file, so I kept the original authors.

Can you add a note along the lines of "Adapted from tegra_mmc.c" for the
curiosity of future readers :)

--Sean

Quoted 68 lines
Quoted 68 lines
Quoted 11 lines
drivers/mmc/piton_mmc.c new file +9 -0
+ */
+
+#include <asm/gpio.h>
+#include <asm/io.h>
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <linux/bitops.h>
+#include <linux/types.h>

drivers/mmc/piton_mmc.c line 27

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <log.h>
+#include <div64.h>
+#include <mmc.h>
+
+struct piton_mmc_plat {
+??? struct mmc_config cfg;
+??? struct mmc mmc;
+};

Is platdata used? I don't see it in 2/2.

drivers/mmc/piton_mmc.c line 30

Quoted 3 lines
drivers/mmc/piton_mmc.c new file +3 -0
+
+struct piton_mmc_priv {
+??? u64 piton_mmc_base_addr; /* peripheral id */

This should be void __iomem *.

Quoted 8 lines
drivers/mmc/piton_mmc.c new file +8 -0
+};
+
+/*
+ * see mmc_read_blocks to see how it is used.
+ * start block is hidden at cmd->arg
+ * also, initialize the block size at init
+ */
+static int piton_mmc_send_cmd(struct udevice *dev, struct 
Quoted 6 lines

mmc_cmd *cmd,
+????????????????? struct mmc_data *data)
+{
+??? /* check first if this is a pure command */
+??? if (!data)
+??????? return 0;

Please place definitions before code (and please run checkpatch).

Quoted 4 lines

+
+??? u64 byte_cnt = data->blocks * data->blocksize; +??? u64 start_block = cmd->cmdarg;
+??? unsigned int *buff = (unsigned int *)data->dest;

Why is buff an unsigned int? If you are using readl, shouldn't it be a
long?

drivers/mmc/piton_mmc.c

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+
+??? struct piton_mmc_priv *priv = dev_get_priv(dev);
+??? u64 start_addr = priv->piton_mmc_base_addr + (start_block);
+
+??? /* if there is a read */
+??? if (data->flags & MMC_DATA_READ) {
+??????? for (u64 i = 0; i < byte_cnt; i += 4) {
+??????????? *(buff) = readl((void *)(start_addr + i));
+??????????? buff++;
+??????? }

Can you use memcpy_fromio here?

Quoted 6 lines
Quoted 2 lines

I went back and double check, seems that it only applies for board with PCI configured

Ok, then does memcpy work?

--Sean

Scratch the previous email, I stand corrected. You're right about memcpy could work, thanks for the great suggestion :P

Many thanks,

Tianrui

Quoted 135 lines
Quoted 133 lines
Quoted 120 lines
Quoted 120 lines
Quoted 120 lines
Quoted 120 lines
Quoted 120 lines
Quoted 9 lines

+??? } else {
+??????? /* else there is a write
+???????? * we don't handle write, so error right away +???????? */
+??????? return -ENODEV;

Please use -ENOSYS.

Quoted 108 lines

+??? }

drivers/mmc/piton_mmc.c new file +85 -0
+
+??? return 0;
+}
+
+static int piton_mmc_ofdata_to_platdata(struct udevice *dev)
+{
+??? struct piton_mmc_priv *priv = dev_get_priv(dev);
+??? struct piton_mmc_plat *plat = dev_get_platdata(dev);
+??? struct mmc_config *cfg;
+??? struct mmc *mmc;
+??? /* fill in device description */
+??? struct blk_desc *bdesc;
+
+??? priv->piton_mmc_base_addr = dev_read_addr(dev);
+??? cfg = &plat->cfg;
+??? cfg->name = "PITON MMC";
+??? cfg->host_caps = MMC_MODE_8BIT;
+??? cfg->f_max = 100000;
+??? cfg->f_min = 400000;
+??? cfg->voltages = MMC_VDD_21_22;
+
+??? mmc = &plat->mmc;
+??? mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+??? mmc->capacity_user = 0x100000000;
+??? mmc->capacity_user *= mmc->read_bl_len;
+??? mmc->capacity_boot = 0;
+??? mmc->capacity_rpmb = 0;
+??? for (int i = 0; i < 4; i++)
+??????? mmc->capacity_gp[i] = 0;
+??? mmc->capacity = 0x2000000000ULL;
+??? mmc->has_init = 1;
+
+??? bdesc = mmc_get_blk_desc(mmc);
+??? bdesc->lun = 0;
+??? bdesc->hwpart = 0;
+??? bdesc->type = 0;
+??? bdesc->blksz = mmc->read_bl_len;
+??? bdesc->log2blksz = LOG2(bdesc->blksz);
+??? bdesc->lba = lldiv(mmc->capacity, mmc->read_bl_len);
+
+??? return 0;
+}
+
+/* test if piton has the micro mmc card present
+ * always return 1, which means present
+ */
+static int piton_mmc_getcd(struct udevice *dev)
+{
+??? /*
+???? * always return 1
+???? */
+??? return 1;
+}
+
+/* dummy function, piton_mmc don't need initialization
+ * in hw
+ */
+static const struct dm_mmc_ops piton_mmc_ops = {
+??? .send_cmd = piton_mmc_send_cmd,
+??? .set_ios = piton_mmc_set_ios,
+??? .get_cd = piton_mmc_getcd,
+};
+
+static int piton_mmc_probe(struct udevice *dev)
+{
+??? struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+??? struct piton_mmc_plat *plat = dev_get_platdata(dev);
+??? struct mmc_config *cfg = &plat->cfg;
+
+??? cfg->name = dev->name;
+??? upriv->mmc = &plat->mmc;
+??? upriv->mmc->has_init = 1;
+??? upriv->mmc->capacity = 0x2000000000ULL;
+??? upriv->mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+
+??? return 0;
+}
+
+static int piton_mmc_bind(struct udevice *dev)
+{
+??? struct piton_mmc_plat *plat = dev_get_platdata(dev);
+??? struct mmc_config *cfg = &plat->cfg;
+
+??? cfg->name = dev->name;
+??? cfg->host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | 

MMC_MODE_8BIT;
+??? cfg->voltages = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34;
+??? cfg->f_min = 1000000;
+??? cfg->f_max = 52000000;
+??? cfg->b_max = U32_MAX;

drivers/mmc/piton_mmc.c new file +16 -0
+
+??? return mmc_bind(dev, &plat->mmc, cfg);
+}
+
+static const struct udevice_id piton_mmc_ids[] = {
+??????? {.compatible = "openpiton,piton-mmc"},
+??????? { /* sentinel */ }
+};
+
+U_BOOT_DRIVER(piton_mmc_drv) = {
+??? .name = "piton_mmc",
+??? .id = UCLASS_MMC,
+??? .of_match = piton_mmc_ids,
+??? .ofdata_to_platdata = piton_mmc_ofdata_to_platdata,
+??? .bind = piton_mmc_bind,
+??? .probe = piton_mmc_probe,
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

+??? .ops = &piton_mmc_ops,
+??? .platdata_auto_alloc_size = sizeof(struct piton_mmc_plat), +??? .priv_auto_alloc_size = sizeof(struct piton_mmc_priv), +};

--Sean

Thanks,

Tianrui