From patchwork Sat Jan 21 23:45:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 645068 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp1510521pvb; Sat, 21 Jan 2023 15:45:53 -0800 (PST) X-Google-Smtp-Source: AMrXdXsAOauB6KvOVCInx+32biuX4VUvxT5RyfnC4Tu+vKGrzm2OzSw5FY+E4p/d8MB8AkUTsEnb X-Received: by 2002:a9d:2c06:0:b0:684:c8ff:8844 with SMTP id f6-20020a9d2c06000000b00684c8ff8844mr9290135otb.12.1674344753185; Sat, 21 Jan 2023 15:45:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674344753; cv=none; d=google.com; s=arc-20160816; b=p+qyMrY6bS2FLTkpBAIyla3+GzSk/0IW0TaQPbAQ4ZeghAow9rnUJpcB/lzB1fztJD V9RNPK+BHadfznLXYsfj4dnso3ACMMumM4+oVuWC7i/yeWQO/PAAuew03lBjapbgfoof scx6H2N+4pkbiNyPFCu23ZFj/3BWrFQXtCbiggZMr3VU7vFnJ59IpKfZOSwn93epkDt9 eVvHzGAo0oyVACndZl+ucFm2+zp3R64XD5cpfg1XhbxZFb48fYNCXs1mhEQpp5ybV9oB 32ikxXMUTEhInKf13uiM0Xi/sjYbpRnlUbYGvhnlchO9WrzCCUjZ2N5EgQDnVF9lcLVW UupA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=IQfrJg7vBWfQnyOAtrhc3u0Z4xFcZQEql0RFaIF8Sj0=; b=dwQRZLSkzG+ESVD2wvN6eoSV8tttkk4gMOK882lAYFYmmG3ixQKJrB7GC1aZU+SWEJ FrodK7UU9dtF9OXNeD7Gyfhk1HZyPiX7W1EJ/etOaDVfwczQgG3Mfsh9DrYZ9p+/EoaD KRKZOuldPG5Oyc33nyk5Vfv23ot1YhJkmobIJu29k4fHZrL0pkrLJ+r7W5dhTjf2m+iz ME8A0xHOvZMPt7A4tQ8uCFtZEe6E56RmnmVixxPUM3JtJ7PUBBawDVVGp85hmvCsyH+9 UX3EAcdwJNHmOWA788Z82DFMDdjHNLkmxbGKm4n5TwY30lPWVQUOwH/7NxjmkNfuuoix FOxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=STO2zHeB; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id 17-20020a9d0291000000b0066a76ca1f6dsi40663564otl.325.2023.01.21.15.45.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Jan 2023 15:45:53 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=STO2zHeB; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4766D85162; Sun, 22 Jan 2023 00:45:51 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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=linaro.org header.i=@linaro.org header.b="STO2zHeB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 15ED785321; Sun, 22 Jan 2023 00:45:50 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) (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 4736884474 for ; Sun, 22 Jan 2023 00:45:47 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=linus.walleij@linaro.org Received: by mail-ej1-x634.google.com with SMTP id kt14so22429670ejc.3 for ; Sat, 21 Jan 2023 15:45:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=IQfrJg7vBWfQnyOAtrhc3u0Z4xFcZQEql0RFaIF8Sj0=; b=STO2zHeBQm7E5HRbFj/dY/xL+oJB4mhWoB+4P11H0V4Pp8HmHvrPuUuqXwqbZxjEzL 5qinzd016PKYY/0zPCmmfgEwuXrcx8XdU55Ep5IhUUWbduvHtKfmb1v8367KhMtJFzU+ V7/Ew27Y5Yitmiqz+GH30XHzDBh3qD9wbyEmRLw8sryfsU1eeld8wK8rQ96tf/sdZNnS DqXXltPlB0a9lIgMwV9Oky+5QmD/x43f6K27nlKNeokL8S3GwVDgiaGQykVr2YZWCaAq VCWHxI1l8d7EDElNfxhMRi0nQTOCIXZ53cGYq1DnT+MKvvIAXub9IHfOC7xB+hzhNsol fu5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IQfrJg7vBWfQnyOAtrhc3u0Z4xFcZQEql0RFaIF8Sj0=; b=LE6eNajmguXBtCa96pTzSq0Hul992SEOsHlbcqb+yF8F7LTvPYb7LcjKNP+MoMvMVF HiswEXQsm9yV/XSXkXoNAr4BGscAxrCspOJ+9mWlCeXXv7POIJJlfXoq8+tBhK47r8nL /0o4HZ8ayJJFdgua0qXYGSTd38dDP52hlpP2FJAScQSmpp4RWoQKmFqOyv+P510ElSzb cmjXAjfLmqfgbFBbxUiFBguMffojekSVrK/irVMgOQa9fK6o22ofeOS3pdviOiKV3buw /emdzqfh6iFfxZ10nCNvzIvRL/hIirvymg1qF+gsgeBGQ0SB7qvk0fxa9HDNZyKZFB4a BwNw== X-Gm-Message-State: AFqh2koFXR3AIBuU6B9ZgC1N4PDvQ7JvTWAEjRq07PtlMldOYH2kd4lI hJ+GbxVWM485PlsuALfA+mKHkY1SLW+rXQmD X-Received: by 2002:a17:906:4557:b0:84d:3a95:cdf5 with SMTP id s23-20020a170906455700b0084d3a95cdf5mr19114068ejq.10.1674344746586; Sat, 21 Jan 2023 15:45:46 -0800 (PST) Received: from localhost.localdomain (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id o14-20020a17090637ce00b00871390a3b74sm9117422ejc.177.2023.01.21.15.45.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Jan 2023 15:45:46 -0800 (PST) From: Linus Walleij To: u-boot@lists.denx.de, Tom Rini Cc: Anand Gore , William Zhang , Kursad Oney , Joel Peshkin , Philippe Reynes , Linus Walleij Subject: [PATCH] nand: brcmnand: add iproc support Date: Sun, 22 Jan 2023 00:45:32 +0100 Message-Id: <20230121234532.2242857-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 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.6 at phobos.denx.de X-Virus-Status: Clean Add support for the iproc Broadcom NAND controller, used in Northstar SoCs for example. Based on the Linux driver. Cc: Philippe Reynes Signed-off-by: Linus Walleij Reviewed-by: Michael Trimarchi --- drivers/mtd/nand/raw/Kconfig | 7 + drivers/mtd/nand/raw/brcmnand/Makefile | 1 + drivers/mtd/nand/raw/brcmnand/iproc_nand.c | 141 +++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 drivers/mtd/nand/raw/brcmnand/iproc_nand.c diff --git a/drivers/mtd/nand/raw/Kconfig b/drivers/mtd/nand/raw/Kconfig index 5b35da45f584..6a13bc1e228a 100644 --- a/drivers/mtd/nand/raw/Kconfig +++ b/drivers/mtd/nand/raw/Kconfig @@ -156,6 +156,13 @@ config NAND_BRCMNAND_63158 help Enable support for broadcom nand driver on bcm63158. +config NAND_BRCMNAND_IPROC + bool "Support Broadcom NAND controller on the iproc family" + depends on NAND_BRCMNAND + help + Enable support for broadcom nand driver on the Broadcom + iproc family such as Northstar (BCM5301x, BCM4708...) + config NAND_DAVINCI bool "Support TI Davinci NAND controller" select SYS_NAND_SELF_INIT if TARGET_DA850EVM diff --git a/drivers/mtd/nand/raw/brcmnand/Makefile b/drivers/mtd/nand/raw/brcmnand/Makefile index f46a7edae321..0c6325aaa618 100644 --- a/drivers/mtd/nand/raw/brcmnand/Makefile +++ b/drivers/mtd/nand/raw/brcmnand/Makefile @@ -6,5 +6,6 @@ obj-$(CONFIG_NAND_BRCMNAND_6753) += bcm6753_nand.o obj-$(CONFIG_NAND_BRCMNAND_68360) += bcm68360_nand.o obj-$(CONFIG_NAND_BRCMNAND_6838) += bcm6838_nand.o obj-$(CONFIG_NAND_BRCMNAND_6858) += bcm6858_nand.o +obj-$(CONFIG_NAND_BRCMNAND_IPROC) += iproc_nand.o obj-$(CONFIG_NAND_BRCMNAND) += brcmnand.o obj-$(CONFIG_NAND_BRCMNAND) += brcmnand_compat.o diff --git a/drivers/mtd/nand/raw/brcmnand/iproc_nand.c b/drivers/mtd/nand/raw/brcmnand/iproc_nand.c new file mode 100644 index 000000000000..c61a120b6d27 --- /dev/null +++ b/drivers/mtd/nand/raw/brcmnand/iproc_nand.c @@ -0,0 +1,141 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Code borrowed from the Linux driver + * Copyright (C) 2015 Broadcom Corporation + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "brcmnand.h" + +struct iproc_nand_soc { + struct brcmnand_soc soc; + void __iomem *idm_base; + void __iomem *ext_base; +}; + +#define IPROC_NAND_CTLR_READY_OFFSET 0x10 +#define IPROC_NAND_CTLR_READY BIT(0) + +#define IPROC_NAND_IO_CTRL_OFFSET 0x00 +#define IPROC_NAND_APB_LE_MODE BIT(24) +#define IPROC_NAND_INT_CTRL_READ_ENABLE BIT(6) + +static bool iproc_nand_intc_ack(struct brcmnand_soc *soc) +{ + struct iproc_nand_soc *priv = + container_of(soc, struct iproc_nand_soc, soc); + void __iomem *mmio = priv->ext_base + IPROC_NAND_CTLR_READY_OFFSET; + u32 val = brcmnand_readl(mmio); + + if (val & IPROC_NAND_CTLR_READY) { + brcmnand_writel(IPROC_NAND_CTLR_READY, mmio); + return true; + } + + return false; +} + +static void iproc_nand_intc_set(struct brcmnand_soc *soc, bool en) +{ + struct iproc_nand_soc *priv = + container_of(soc, struct iproc_nand_soc, soc); + void __iomem *mmio = priv->idm_base + IPROC_NAND_IO_CTRL_OFFSET; + u32 val = brcmnand_readl(mmio); + + if (en) + val |= IPROC_NAND_INT_CTRL_READ_ENABLE; + else + val &= ~IPROC_NAND_INT_CTRL_READ_ENABLE; + + brcmnand_writel(val, mmio); +} + +static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare, + bool is_param) +{ + struct iproc_nand_soc *priv = + container_of(soc, struct iproc_nand_soc, soc); + void __iomem *mmio = priv->idm_base + IPROC_NAND_IO_CTRL_OFFSET; + u32 val; + + val = brcmnand_readl(mmio); + + /* + * In the case of BE or when dealing with NAND data, always configure + * the APB bus to LE mode before accessing the FIFO and back to BE mode + * after the access is done + */ + if (IS_ENABLED(CONFIG_SYS_BIG_ENDIAN) || !is_param) { + if (prepare) + val |= IPROC_NAND_APB_LE_MODE; + else + val &= ~IPROC_NAND_APB_LE_MODE; + } else { /* when in LE accessing the parameter page, keep APB in BE */ + val &= ~IPROC_NAND_APB_LE_MODE; + } + + brcmnand_writel(val, mmio); +} + +static int iproc_nand_probe(struct udevice *dev) +{ + struct udevice *pdev = dev; + struct iproc_nand_soc *priv = dev_get_priv(dev); + struct brcmnand_soc *soc; + struct resource res; + + soc = &priv->soc; + + dev_read_resource_byname(pdev, "iproc-idm", &res); + priv->idm_base = ioremap(res.start, resource_size(&res)); + if (IS_ERR(priv->idm_base)) + return PTR_ERR(priv->idm_base); + + dev_read_resource_byname(pdev, "iproc-ext", &res); + priv->ext_base = ioremap(res.start, resource_size(&res)); + if (IS_ERR(priv->ext_base)) + return PTR_ERR(priv->ext_base); + + soc->ctlrdy_ack = iproc_nand_intc_ack; + soc->ctlrdy_set_enabled = iproc_nand_intc_set; + soc->prepare_data_bus = iproc_nand_apb_access; + + return brcmnand_probe(pdev, soc); +} + +static const struct udevice_id iproc_nand_dt_ids[] = { + { + .compatible = "brcm,nand-iproc", + }, + { /* sentinel */ } +}; + +U_BOOT_DRIVER(iproc_nand) = { + .name = "iproc-nand", + .id = UCLASS_MTD, + .of_match = iproc_nand_dt_ids, + .probe = iproc_nand_probe, + .priv_auto = sizeof(struct iproc_nand_soc), +}; + +void board_nand_init(void) +{ + struct udevice *dev; + int ret; + + ret = uclass_get_device_by_driver(UCLASS_MTD, + DM_DRIVER_GET(iproc_nand), &dev); + if (ret && ret != -ENODEV) + pr_err("Failed to initialize %s. (error %d)\n", dev->name, + ret); +}