From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7C607C433F5 for ; Wed, 30 Mar 2022 20:46:03 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1610C83BDB; Wed, 30 Mar 2022 22:46:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="V+My9tL4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ED25683CEE; Wed, 30 Mar 2022 22:45:59 +0200 (CEST) Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 65CD683B74 for ; Wed, 30 Mar 2022 22:45:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=macroalpha82@gmail.com Received: by mail-oi1-x229.google.com with SMTP id q129so23312153oif.4 for ; Wed, 30 Mar 2022 13:45:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=upqRZ/yoyxK46MtV/jkktFfm+fZAcqK6B2J3FC7dHkU=; b=V+My9tL4F7DvQ3yeKI7om0OkyFpeDPLGBVXVY6QnmUONTP9nxK7E7b3yG9TtWnY/mA xAdOg/P4zUm+C12VF+DHNfHZbkeMF9TnYt7UPWouTS5W731Im5tNcVT/L5d/WtM5b0zu JrDPUwbQcVE0SU4HaqM4b+tvt7frIKt9O5d/M+FyS3yz8RlYu2/Itmv4KPdEiyYH/noo H1r0uEKN3G8dSelpKx/tc5BpU0umcUAkbu5ZJsIoPk4mA0v537ochf4r7W8ThJtL4sgd 1bUcRpf08kKPPSDsKKhYTnb68j6JGJ9+FTTDY3pRbc+QUE7Rhg9lZuSaTz43n2lTv0SX B2VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=upqRZ/yoyxK46MtV/jkktFfm+fZAcqK6B2J3FC7dHkU=; b=wsDoMwJztCmrBLdTU6LaAAdrg3Lv2Wbaf4Mgow/1mGwd5NsyCPOiItWUq0vWWZQDVJ 5/PehuaNkTzsY1ZEqtMFPW96kcuc6tl0sFm3uPNe27SCoCnuaEnGyOC9XxMdm5Ijglvj 6wgwHQ+AoVqP4MMm2FQtdZhE69kUd6yFtgjolLfnE8JR7C75er6Vr7c2gxZHexztSA5T l/1HZ6j/iXhHUJH5Pgudsi0UyAtaKVZhXl4a+Ws9OmgzyH5r6KnUvQpxtrj6nRHW2XFk k9VrdeJUekme4vpKwpF9ckUSh/xwvsxyhH6S18RTsxuMZRHkmirGEN7iDTD4Ik+skxmd Z0dQ== X-Gm-Message-State: AOAM530qlAo5j6znCQh5wKh9cl9b3KvLVZ7c2QhZJmNZ30bLYJE2YkXB yMrQfGLKA1pHcSrRM9aE4RbbJGB2KCY= X-Google-Smtp-Source: ABdhPJwutdV+ob9TzW5fdo97cjKEVh7N3pebJMfiMk9hlmqTjJprZqslxhnojG0PBauu/u3nEMvQ3Q== X-Received: by 2002:a05:6808:1115:b0:2ec:e78e:3fc0 with SMTP id e21-20020a056808111500b002ece78e3fc0mr977856oih.207.1648673150563; Wed, 30 Mar 2022 13:45:50 -0700 (PDT) Received: from wintermute.localdomain (cpe-76-183-134-35.tx.res.rr.com. [76.183.134.35]) by smtp.gmail.com with ESMTPSA id w1-20020a056808090100b002da82caced5sm10608794oih.3.2022.03.30.13.45.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 13:45:49 -0700 (PDT) From: Chris Morgan To: u-boot@lists.denx.de Cc: jagan@amarulasolutions.com, andre.przywara@arm.com, hdegoede@redhat.com, Chris Morgan Subject: [PATCH] [PATCH] sunxi-nand: Undo removal of DMA that breaks NAND SPL Date: Wed, 30 Mar 2022 15:45:43 -0500 Message-Id: <20220330204543.3790-1-macroalpha82@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean From: Chris Morgan For the sun5i based NAND, removal of the DMA specific code from the SPL driver caused it to no longer function. These patches revert the changes made here, specifically patches 13/20 and 14/20: https://lore.kernel.org/u-boot/20210624120540.7oyhdmerjndsylbq@gilmour/ These patches only apply for sun5i based boards. Tested on my NTC CHIP (an R8/A13 based device) and it is able to boot U-Boot properly with these patches. Signed-off-by: Chris Morgan --- board/sunxi/board.c | 3 + drivers/mtd/nand/raw/sunxi_nand_spl.c | 105 ++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) diff --git a/board/sunxi/board.c b/board/sunxi/board.c index 28f702bc29..289f568415 100644 --- a/board/sunxi/board.c +++ b/board/sunxi/board.c @@ -393,6 +393,9 @@ static void nand_clock_setup(void) #if defined CONFIG_MACH_SUN6I || defined CONFIG_MACH_SUN8I || \ defined CONFIG_MACH_SUN9I || defined CONFIG_MACH_SUN50I setbits_le32(&ccm->ahb_reset0_cfg, (1 << AHB_GATE_OFFSET_NAND0)); +#endif +#if defined(CONFIG_MACH_SUN5I) && defined(CONFIG_NAND_SUNXI) + setbits_le32(&ccm->ahb_gate0, (1 << AHB_GATE_OFFSET_DMA)); #endif setbits_le32(&ccm->nand0_clk_cfg, CCM_NAND_CTRL_ENABLE | AHB_DIV_1); } diff --git a/drivers/mtd/nand/raw/sunxi_nand_spl.c b/drivers/mtd/nand/raw/sunxi_nand_spl.c index a29a76c58d..1b2c995803 100644 --- a/drivers/mtd/nand/raw/sunxi_nand_spl.c +++ b/drivers/mtd/nand/raw/sunxi_nand_spl.c @@ -12,6 +12,7 @@ #include #include #include +#include #include /* registers */ @@ -85,6 +86,22 @@ #define NFC_CMD_RNDOUT 0x05 #define NFC_CMD_READSTART 0x30 +#define SUNXI_DMA_CFG_REG0 0x300 +#define SUNXI_DMA_SRC_START_ADDR_REG0 0x304 +#define SUNXI_DMA_DEST_START_ADDRR_REG0 0x308 +#define SUNXI_DMA_DDMA_BC_REG0 0x30C +#define SUNXI_DMA_DDMA_PARA_REG0 0x318 + +#define SUNXI_DMA_DDMA_CFG_REG_LOADING (1 << 31) +#define SUNXI_DMA_DDMA_CFG_REG_DMA_DEST_DATA_WIDTH_32 (2 << 25) +#define SUNXI_DMA_DDMA_CFG_REG_DDMA_DST_DRQ_TYPE_DRAM (1 << 16) +#define SUNXI_DMA_DDMA_CFG_REG_DMA_SRC_DATA_WIDTH_32 (2 << 9) +#define SUNXI_DMA_DDMA_CFG_REG_DMA_SRC_ADDR_MODE_IO (1 << 5) +#define SUNXI_DMA_DDMA_CFG_REG_DDMA_SRC_DRQ_TYPE_NFC (3 << 0) + +#define SUNXI_DMA_DDMA_PARA_REG_SRC_WAIT_CYC (0x0F << 0) +#define SUNXI_DMA_DDMA_PARA_REG_SRC_BLK_SIZE (0x7F << 8) + struct nfc_config { int page_size; int ecc_strength; @@ -254,6 +271,93 @@ static int nand_change_column(u16 column) static const int ecc_bytes[] = {32, 46, 54, 60, 74, 88, 102, 110, 116}; +#if defined(CONFIG_MACH_SUN5I) +static int nand_read_page(const struct nfc_config *conf, u32 offs, + void *dest, int len) +{ + dma_addr_t dst = (dma_addr_t)dest; + int nsectors = len / conf->ecc_size; + u16 rand_seed = 0; + u32 val; + int page; + + page = offs / conf->page_size; + + if (offs % conf->page_size || len % conf->ecc_size || + len > conf->page_size || len < 0) + return -EINVAL; + + /* clear ecc status */ + writel(0, SUNXI_NFC_BASE + NFC_ECC_ST); + + /* Choose correct seed if randomized */ + if (conf->randomize) + rand_seed = random_seed[page % conf->nseeds]; + + writel((rand_seed << 16) | (conf->ecc_strength << 12) | + (conf->randomize ? NFC_ECC_RANDOM_EN : 0) | + (conf->ecc_size == 512 ? NFC_ECC_BLOCK_SIZE : 0) | + NFC_ECC_EN | NFC_ECC_PIPELINE | NFC_ECC_EXCEPTION, + SUNXI_NFC_BASE + NFC_ECC_CTL); + + flush_dcache_range(dst, ALIGN(dst + conf->ecc_size, ARCH_DMA_MINALIGN)); + + /* SUNXI_DMA */ + writel(0x0, SUNXI_DMA_BASE + SUNXI_DMA_CFG_REG0); /* clr dma cmd */ + /* read from REG_IO_DATA */ + writel(SUNXI_NFC_BASE + NFC_IO_DATA, + SUNXI_DMA_BASE + SUNXI_DMA_SRC_START_ADDR_REG0); + /* read to RAM */ + writel(dst, SUNXI_DMA_BASE + SUNXI_DMA_DEST_START_ADDRR_REG0); + writel(SUNXI_DMA_DDMA_PARA_REG_SRC_WAIT_CYC | + SUNXI_DMA_DDMA_PARA_REG_SRC_BLK_SIZE, + SUNXI_DMA_BASE + SUNXI_DMA_DDMA_PARA_REG0); + writel(len, SUNXI_DMA_BASE + SUNXI_DMA_DDMA_BC_REG0); + writel(SUNXI_DMA_DDMA_CFG_REG_LOADING | + SUNXI_DMA_DDMA_CFG_REG_DMA_DEST_DATA_WIDTH_32 | + SUNXI_DMA_DDMA_CFG_REG_DDMA_DST_DRQ_TYPE_DRAM | + SUNXI_DMA_DDMA_CFG_REG_DMA_SRC_DATA_WIDTH_32 | + SUNXI_DMA_DDMA_CFG_REG_DMA_SRC_ADDR_MODE_IO | + SUNXI_DMA_DDMA_CFG_REG_DDMA_SRC_DRQ_TYPE_NFC, + SUNXI_DMA_BASE + SUNXI_DMA_CFG_REG0); + + writel(nsectors, SUNXI_NFC_BASE + NFC_SECTOR_NUM); + writel(NFC_ST_DMA_INT_FLAG, SUNXI_NFC_BASE + NFC_ST); + writel(NFC_DATA_TRANS | NFC_PAGE_CMD | NFC_DATA_SWAP_METHOD, + SUNXI_NFC_BASE + NFC_CMD); + + if (!check_value(SUNXI_NFC_BASE + NFC_ST, NFC_ST_DMA_INT_FLAG, + DEFAULT_TIMEOUT_US)) { + printf("Error while initializing dma interrupt\n"); + return -EIO; + } + + writel(NFC_ST_DMA_INT_FLAG, SUNXI_NFC_BASE + NFC_ST); + + if (!check_value_negated(SUNXI_DMA_BASE + SUNXI_DMA_CFG_REG0, + SUNXI_DMA_DDMA_CFG_REG_LOADING, + DEFAULT_TIMEOUT_US)) { + printf("Error while waiting for dma transfer to finish\n"); + return -EIO; + } + + invalidate_dcache_range(dst, + ALIGN(dst + conf->ecc_size, ARCH_DMA_MINALIGN)); + + val = readl(SUNXI_NFC_BASE + NFC_ECC_ST); + + /* ECC error detected. */ + if (val & 0xffff) + return -EIO; + + /* + * Return 1 if the page is empty. + * We consider the page as empty if the first ECC block is marked + * empty. + */ + return (val & 0x10000) ? 1 : 0; +} +#else static int nand_read_page(const struct nfc_config *conf, u32 offs, void *dest, int len) { @@ -326,6 +430,7 @@ static int nand_read_page(const struct nfc_config *conf, u32 offs, return 0; } +#endif static int nand_max_ecc_strength(struct nfc_config *conf) { -- 2.30.2