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 B14BFC43334 for ; Thu, 14 Jul 2022 03:17:02 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 89B0684070; Thu, 14 Jul 2022 05:16:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sholland.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sholland.org header.i=@sholland.org header.b="TnMxTB7z"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="J+at+3ax"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DE95984043; Thu, 14 Jul 2022 05:15:52 +0200 (CEST) Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0F39F84051 for ; Thu, 14 Jul 2022 05:15:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sholland.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=samuel@sholland.org Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 44D145C00E7; Wed, 13 Jul 2022 23:15:34 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Wed, 13 Jul 2022 23:15:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1657768534; x=1657854934; bh=cs Vo5TrX/l1aKKg1QUsyHLTz7wcYs293pzSPZ4LQ/xA=; b=TnMxTB7zMZ/QwJSJW1 hhMKHCfU+nuzxTI/pXxUqeIShKIjMNHU1cSqhVOLiypmyaeme4+f98fttn+TEbXI mRAp8/DLXtXPtb7qt0czByzJH9hTd9bnF3X8oAcmHxZSOH7m47uVdaM9itZtcEph V38iUpTVul0nEyHwRBBajVu+lm53pQbKw4NYNdvMn36mrKGqZQ1FY2lbkG/W6tVD Ccmhp8CNJVB5LcYHpZfFQwBRWb8JRyNSkYw+j+9rFBKe6YtWT5R6UOlJWvBgXh0k Ga8lCLXGGo9x2VlGxecBYV9Mb2LyZuOVFTvUp76L6M6YCEJwXyfk6if257HIE83U H1Pg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1657768534; x=1657854934; bh=csVo5TrX/l1aK Kg1QUsyHLTz7wcYs293pzSPZ4LQ/xA=; b=J+at+3axAVTk1sqg0uVUR6V3kZbte rvE11p2MdTNSaawRW2I8ooYJC4TFaSTaHid/ZkK7ctm7s5ja6Cqdtxxu+t2NvY5t FliReEdPUyht75JBjU2mdghEDxzjk/UKqmRDutpIU6xZaCq6ljbKFdnzPMgHC9Hp S/3Wat+U1c6M9qIU4fj6XetD6kdD59PhxSg/UyKgOj/BKCYDfzkKRtQOpZAs337C MARYaRoKncNr4ny27XmvHAaMwrFfRUb2q/swp/zkMuSHxJxYN8iqCpyH8r93qBnl WQp2HPcBUi5L4nkTJ2VPLfg0Cu1KUC9no4NmaLdfNuhiTNgVNIAdEJbVQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudejkedgieekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepufgrmhhu vghlucfjohhllhgrnhguuceoshgrmhhuvghlsehshhholhhlrghnugdrohhrgheqnecugg ftrfgrthhtvghrnhepudekteeuudehtdelteevgfduvddvjefhfedulefgudevgeeghefg udefiedtveetnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrh homhepshgrmhhuvghlsehshhholhhlrghnugdrohhrgh X-ME-Proxy: Feedback-ID: i0ad843c9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 13 Jul 2022 23:15:33 -0400 (EDT) From: Samuel Holland To: u-boot@lists.denx.de, Jagan Teki , Andre Przywara Cc: Samuel Holland , Dario Binacchi , Hans de Goede , Lukasz Majewski , Michael Trimarchi , Sean Anderson , Simon Glass Subject: [PATCH 5/6] mtd: nand: sunxi: Convert to the driver model Date: Wed, 13 Jul 2022 22:15:25 -0500 Message-Id: <20220714031526.33697-6-samuel@sholland.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220714031526.33697-1-samuel@sholland.org> References: <20220714031526.33697-1-samuel@sholland.org> 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.6 at phobos.denx.de X-Virus-Status: Clean Clocks, resets, and pinmuxes are now handled by the driver model, so the only thing the "board" code needs to do is load the driver. This matches the pattern used by other DM raw NAND drivers (there is no NAND uclass). The actual board code is now only needed in SPL. Signed-off-by: Samuel Holland --- board/sunxi/board.c | 5 +- drivers/mtd/nand/raw/sunxi_nand.c | 81 ++++++++++++++++++------------- 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/board/sunxi/board.c b/board/sunxi/board.c index 21a2407e062f..ea0f33ed31db 100644 --- a/board/sunxi/board.c +++ b/board/sunxi/board.c @@ -315,7 +315,7 @@ int dram_init(void) return 0; } -#if defined(CONFIG_NAND_SUNXI) +#if defined(CONFIG_NAND_SUNXI) && defined(CONFIG_SPL_BUILD) static void nand_pinmux_setup(void) { unsigned int pin; @@ -351,9 +351,6 @@ void board_nand_init(void) { nand_pinmux_setup(); nand_clock_setup(); -#ifndef CONFIG_SPL_BUILD - sunxi_nand_init(); -#endif } #endif diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c index 7185efbebfdd..dda51a39b065 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -24,11 +24,13 @@ * GNU General Public License for more details. */ +#include #include #include #include #include #include +#include #include #include #include @@ -260,7 +262,7 @@ static inline struct sunxi_nand_chip *to_sunxi_nand(struct nand_chip *nand) * NAND Controller structure: stores sunxi NAND controller information * * @controller: base controller structure - * @dev: parent device (used to print error messages) + * @dev: DM device (used to print error messages) * @regs: NAND controller registers * @ahb_clk: NAND Controller AHB clock * @mod_clk: NAND Controller mod clock @@ -273,7 +275,7 @@ static inline struct sunxi_nand_chip *to_sunxi_nand(struct nand_chip *nand) */ struct sunxi_nfc { struct nand_hw_control controller; - struct device *dev; + struct udevice *dev; void __iomem *regs; struct clk *ahb_clk; struct clk *mod_clk; @@ -1772,54 +1774,67 @@ static void sunxi_nand_chips_cleanup(struct sunxi_nfc *nfc) } #endif /* __UBOOT__ */ -void sunxi_nand_init(void) +static int sunxi_nand_probe(struct udevice *dev) { - struct sunxi_nfc *nfc; - phys_addr_t regs; - ofnode node; + struct sunxi_nfc *nfc = dev_get_priv(dev); + struct reset_ctl_bulk rst_bulk; + struct clk_bulk clk_bulk; int ret; - nfc = kzalloc(sizeof(*nfc), GFP_KERNEL); - if (!nfc) - return; - + nfc->dev = dev; spin_lock_init(&nfc->controller.lock); init_waitqueue_head(&nfc->controller.wq); INIT_LIST_HEAD(&nfc->chips); - node = ofnode_by_compatible(ofnode_null(), "allwinner,sun4i-a10-nand"); - if (!ofnode_valid(node)) { - pr_err("unable to find nfc node in device tree\n"); - goto err; - } - - if (!ofnode_is_enabled(node)) { - pr_err("nfc disabled in device tree\n"); - goto err; - } + nfc->regs = dev_read_addr_ptr(dev); + if (!nfc->regs) + return -EINVAL; - regs = ofnode_get_addr(node); - if (regs == FDT_ADDR_T_NONE) { - pr_err("unable to find nfc address in device tree\n"); - goto err; - } + ret = reset_get_bulk(dev, &rst_bulk); + if (!ret) + reset_deassert_bulk(&rst_bulk); - nfc->regs = (void *)regs; + ret = clk_get_bulk(dev, &clk_bulk); + if (!ret) + clk_enable_bulk(&clk_bulk); ret = sunxi_nfc_rst(nfc); if (ret) - goto err; + return ret; - ret = sunxi_nand_chips_init(node, nfc); + ret = sunxi_nand_chips_init(dev_ofnode(dev), nfc); if (ret) { - dev_err(nfc->dev, "failed to init nand chips\n"); - goto err; + dev_err(dev, "failed to init nand chips\n"); + return ret; } - return; + return 0; +} -err: - kfree(nfc); +static const struct udevice_id sunxi_nand_ids[] = { + { + .compatible = "allwinner,sun4i-a10-nand", + }, + { } +}; + +U_BOOT_DRIVER(sunxi_nand) = { + .name = "sunxi_nand", + .id = UCLASS_MTD, + .of_match = sunxi_nand_ids, + .probe = sunxi_nand_probe, + .priv_auto = sizeof(struct sunxi_nfc), +}; + +void board_nand_init(void) +{ + struct udevice *dev; + int ret; + + ret = uclass_get_device_by_driver(UCLASS_MTD, + DM_DRIVER_GET(sunxi_nand), &dev); + if (ret && ret != -ENODEV) + pr_err("Failed to initialize sunxi NAND controller: %d\n", ret); } MODULE_LICENSE("GPL v2"); -- 2.35.1