diff --git a/meta-opencentauri/recipes-kernel/linux/linux-mainline/0001-mmc-sunxi-add-dt-options-for-stock-like-ddr52-setup.patch b/meta-opencentauri/recipes-kernel/linux/linux-mainline/0001-mmc-sunxi-add-dt-options-for-stock-like-ddr52-setup.patch new file mode 100644 index 00000000..4c01ecf1 --- /dev/null +++ b/meta-opencentauri/recipes-kernel/linux/linux-mainline/0001-mmc-sunxi-add-dt-options-for-stock-like-ddr52-setup.patch @@ -0,0 +1,186 @@ +From: 0xD34DC0DE +Subject: [PATCH] mmc: sunxi: add DT options for a stock-like DDR52 setup + +Some Elegoo Centauri 2 boards use an eMMC ("MMC8GB", manufacturer 0x32, +OEM 0x0101) that fails DDR52 writes with CRC status errors in the +mainline setup, while the stock Allwinner BSP runs it at DDR52 without +errors. Add device tree options, all off by default, to reproduce the +BSP setup: + +- allwinner,ddr-old-timing: run DDR52 in the old timing mode, with the + module clock at the requested rate and the internal divider bypassed +- allwinner,sample-delay: software sample delay (0..63) instead of 0 +- allwinner,fifo-watermark: FTRGL value instead of 0x20070008 +- allwinner,write-threshold: on writes, only start sending a block once + it is fully in the FIFO (when it fits the TX trigger level) + +Upstream-Status: Inappropriate [board specific workaround] +--- + drivers/mmc/host/sunxi-mmc.c | 71 ++++++++++++++++++++++++++++++++++++++++---- + 1 file changed, 66 insertions(+), 5 deletions(-) + +diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c +index fe4c0f6d7..df6cdd825 100644 +--- a/drivers/mmc/host/sunxi-mmc.c ++++ b/drivers/mmc/host/sunxi-mmc.c +@@ -9,6 +9,7 @@ + * (C) Copyright 2017 Sootech SA + */ + ++#include + #include + #include + #include +@@ -69,6 +70,7 @@ + /* New registers introduced in A64 */ + #define SDXC_REG_A12A 0x058 /* SMC Auto Command 12 Register */ + #define SDXC_REG_SD_NTSR 0x05C /* SMC New Timing Set Register */ ++#define SDXC_REG_THLD 0x100 /* SMC Card Threshold Control Register */ + #define SDXC_REG_DRV_DL 0x140 /* Drive Delay Control Register */ + #define SDXC_REG_SAMP_DL_REG 0x144 /* SMC sample delay control */ + #define SDXC_REG_DS_DL_REG 0x148 /* SMC data strobe delay control */ +@@ -228,6 +230,10 @@ + #define SDXC_CAL_DL_SW_SHIFT 0 + #define SDXC_CAL_DL_MASK 0x3f + ++/* Card threshold control register (SDXC_REG_THLD) */ ++#define SDXC_CARD_WR_THLD_EN BIT(2) ++#define SDXC_CARD_THLD_MASK GENMASK(27, 16) ++ + #define SDXC_CAL_TIMEOUT 3 /* in seconds, 3s is enough*/ + + struct sunxi_mmc_clk_delay { +@@ -300,6 +306,12 @@ struct sunxi_mmc_host { + + /* timings */ + bool use_new_timings; ++ ++ /* optional board specific tweaks from the device tree */ ++ bool ddr_old_timing; ++ bool write_threshold; ++ u32 sample_delay; ++ u32 fifo_watermark; + }; + + static int sunxi_mmc_reset_host(struct sunxi_mmc_host *host) +@@ -328,11 +340,12 @@ static int sunxi_mmc_init_host(struct sunxi_mmc_host *host) + return -EIO; + + /* +- * Burst 8 transfers, RX trigger level: 7, TX trigger level: 8 ++ * FIFO trigger levels and DMA burst size, by default burst 8 ++ * transfers, RX trigger level: 7, TX trigger level: 8 + * + * TODO: sun9i has a larger FIFO and supports higher trigger values + */ +- mmc_writel(host, REG_FTRGL, 0x20070008); ++ mmc_writel(host, REG_FTRGL, host->fifo_watermark); + /* Maximum timeout value */ + mmc_writel(host, REG_TMOUT, 0xffffffff); + /* Unmask SDIO interrupt if needed */ +@@ -713,7 +726,8 @@ static int sunxi_mmc_calibrate(struct sunxi_mmc_host *host, int reg_off) + * The only mode that doesn't have such a delay is HS400, that + * is in itself a TODO. + */ +- writel(SDXC_CAL_DL_SW_EN, host->reg_base + reg_off); ++ writel(SDXC_CAL_DL_SW_EN | host->sample_delay, ++ host->reg_base + reg_off); + + return 0; + } +@@ -762,6 +776,8 @@ static int sunxi_mmc_clk_set_rate(struct sunxi_mmc_host *host, + struct mmc_host *mmc = host->mmc; + long rate; + u32 rval, clock = ios->clock, div = 1; ++ bool old_timing_ddr = host->ddr_old_timing && host->use_new_timings && ++ ios->timing == MMC_TIMING_MMC_DDR52; + int ret; + + ret = sunxi_mmc_oclk_onoff(host, 0); +@@ -782,8 +798,14 @@ static int sunxi_mmc_clk_set_rate(struct sunxi_mmc_host *host, + * We currently only support the standard MMC DDR52 mode. + * This block should be updated once support for other DDR + * modes is added. ++ * ++ * Boards with "allwinner,ddr-old-timing" run DDR52 in the old ++ * timing mode instead, with the module clock at the requested ++ * rate and no internal divider, as the Allwinner BSP does. + */ +- if (ios->timing == MMC_TIMING_MMC_DDR52 && ++ if (old_timing_ddr) { ++ /* module clock as requested, internal divider bypassed */ ++ } else if (ios->timing == MMC_TIMING_MMC_DDR52 && + (host->use_new_timings || + ios->bus_width == MMC_BUS_WIDTH_8)) { + div = 2; +@@ -834,7 +856,10 @@ static int sunxi_mmc_clk_set_rate(struct sunxi_mmc_host *host, + if (host->use_new_timings) { + /* Don't touch the delay bits */ + rval = mmc_readl(host, REG_SD_NTSR); +- rval |= SDXC_2X_TIMING_MODE; ++ if (old_timing_ddr) ++ rval &= ~SDXC_2X_TIMING_MODE; ++ else ++ rval |= SDXC_2X_TIMING_MODE; + mmc_writel(host, REG_SD_NTSR, rval); + } + +@@ -1005,6 +1030,24 @@ static void sunxi_mmc_hw_reset(struct mmc_host *mmc) + udelay(300); + } + ++/* ++ * Only start sending a write block once the whole block is in the FIFO, ++ * as the Allwinner BSP does. The block has to fit in the FIFO TX trigger ++ * level, otherwise the transfer never starts. ++ */ ++static void sunxi_mmc_set_write_threshold(struct sunxi_mmc_host *host, ++ struct mmc_data *data) ++{ ++ u32 thld = mmc_readl(host, REG_THLD); ++ ++ thld &= ~(SDXC_CARD_THLD_MASK | SDXC_CARD_WR_THLD_EN); ++ if ((data->flags & MMC_DATA_WRITE) && ++ data->blksz <= (host->fifo_watermark & 0xff) * 4) ++ thld |= FIELD_PREP(SDXC_CARD_THLD_MASK, data->blksz) | ++ SDXC_CARD_WR_THLD_EN; ++ mmc_writel(host, REG_THLD, thld); ++} ++ + static void sunxi_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq) + { + struct sunxi_mmc_host *host = mmc_priv(mmc); +@@ -1089,6 +1132,8 @@ static void sunxi_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq) + if (data) { + mmc_writel(host, REG_BLKSZ, data->blksz); + mmc_writel(host, REG_BCNTR, data->blksz * data->blocks); ++ if (host->write_threshold) ++ sunxi_mmc_set_write_threshold(host, data); + sunxi_mmc_start_dma(host, data); + } + +@@ -1383,6 +1428,22 @@ static int sunxi_mmc_probe(struct platform_device *pdev) + if (ret) + return ret; + ++ /* Optional board specific tweaks, all off by default */ ++ host->fifo_watermark = 0x20070008; ++ of_property_read_u32(pdev->dev.of_node, "allwinner,fifo-watermark", ++ &host->fifo_watermark); ++ of_property_read_u32(pdev->dev.of_node, "allwinner,sample-delay", ++ &host->sample_delay); ++ if (host->sample_delay > SDXC_CAL_DL_MASK) { ++ dev_warn(&pdev->dev, "invalid sample delay %u, using 0\n", ++ host->sample_delay); ++ host->sample_delay = 0; ++ } ++ host->ddr_old_timing = of_property_read_bool(pdev->dev.of_node, ++ "allwinner,ddr-old-timing"); ++ host->write_threshold = of_property_read_bool(pdev->dev.of_node, ++ "allwinner,write-threshold"); ++ + host->sg_cpu = dma_alloc_coherent(&pdev->dev, PAGE_SIZE, + &host->sg_dma, GFP_KERNEL); + if (!host->sg_cpu) +-- +cosmos diff --git a/meta-opencentauri/recipes-kernel/linux/linux-mainline/elegoo-centauri-carbon2.dts b/meta-opencentauri/recipes-kernel/linux/linux-mainline/elegoo-centauri-carbon2.dts index 6974e8d6..5500b76d 100644 --- a/meta-opencentauri/recipes-kernel/linux/linux-mainline/elegoo-centauri-carbon2.dts +++ b/meta-opencentauri/recipes-kernel/linux/linux-mainline/elegoo-centauri-carbon2.dts @@ -275,11 +275,21 @@ vmmc-supply = <®_3v3>; vqmmc-supply = <®_1v8>; cap-mmc-highspeed; - mmc-hs200-1_8v; non-removable; cap-mmc-hw-reset; bus-width = <4>; - max-frequency = <150000000>; + /* + * DDR52 set up like the stock Allwinner BSP: 50 MHz card clock + * from a 100 MHz pll-periph0 module clock in the old timing mode, + * with a fixed sample delay, the stock FIFO watermark and a write + * threshold. Some eMMC chips ("MMC8GB") fail writes otherwise. + * HS200 is not used, as on stock. + */ + max-frequency = <50000000>; + allwinner,ddr-old-timing; + allwinner,sample-delay = <36>; + allwinner,fifo-watermark = <0x300f00f0>; + allwinner,write-threshold; status = "okay"; }; diff --git a/meta-opencentauri/recipes-kernel/linux/linux-mainline_%.bbappend b/meta-opencentauri/recipes-kernel/linux/linux-mainline_%.bbappend index b587762f..f1c6f19a 100644 --- a/meta-opencentauri/recipes-kernel/linux/linux-mainline_%.bbappend +++ b/meta-opencentauri/recipes-kernel/linux/linux-mainline_%.bbappend @@ -19,6 +19,7 @@ SRC_URI:append = " \ file://0003-riscv-dts-allwinner-d1-Add-pwm-node.patch \ file://0001-Make-CONFIG_FB-select-CONFIG_FB_BACKLIGHT.patch \ file://0001-Add-support-for-st77922-touchscreen-driver.patch \ + file://0001-mmc-sunxi-add-dt-options-for-stock-like-ddr52-setup.patch \ " KERNEL_MODULE_PROBECONF += "rtw88_core"