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 C3819C4332F for ; Wed, 12 Oct 2022 06:22:53 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BCB4E8492B; Wed, 12 Oct 2022 08:22:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.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=kernel.org header.i=@kernel.org header.b="AJNPYjh7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A617C84C90; Wed, 12 Oct 2022 08:22:48 +0200 (CEST) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 77E2C84567 for ; Wed, 12 Oct 2022 08:22:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rogerq@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0525760E05; Wed, 12 Oct 2022 06:22:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C73CC433C1; Wed, 12 Oct 2022 06:22:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665555763; bh=iJz81/TTeb671Xryjuwl9FyIo4Q8Ci12ifdDj6dz14g=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=AJNPYjh7iJ2g5eImGGBqm0v7cBPrAes/s1SUasiL3xCLimTTU+baZJuoffwwxZDcA m2g/emBpCJPLUXjXPCJIRal1/j0LyIOf7E9i+tr3ZLPOj4YvC4Rvqq2H7IX2a+ckXT J2Tp9NCWfrIgr8FqZ3jUxH+K67hpo9D8bZFIvGz/OnvUSOrftVez/REuUChRS8ZVON roBWsX3bczbwx77M6m0QJH1TdCFt3BDidApvjP7+69ncbT0N2dDGrSmie5w3ujIqJR MiKWbgXpDG0dIfhemS9IdAFjwlzkPHecddXw9u3bn9or/Tb7GZCuCm+y5furlscCKG s7yc1V9Szo+mQ== Message-ID: <2b4e24dc-6eb6-81d5-fc14-ecd6923e4308@kernel.org> Date: Wed, 12 Oct 2022 09:22:39 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [u-boot][PATCH 10/14] mtd: rawnand: omap_gpmc: support u-boot driver model Content-Language: en-US To: Adam Ford Cc: dario.binacchi@amarulasolutions.com, michael@amarulasolutions.com, trini@konsulko.com, u-boot@lists.denx.de References: <20221011115012.6181-1-rogerq@kernel.org> <20221011115012.6181-11-rogerq@kernel.org> From: Roger Quadros In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 Hi Adam, On 11/10/2022 18:01, Adam Ford wrote: > On Tue, Oct 11, 2022 at 6:52 AM Roger Quadros wrote: >> >> Adds driver model support. >> >> We need to be able to self initialize the NAND controller/chip >> at probe and so enable CONFIG_SYS_NAND_SELF_INIT. >> >> Doing so requires nand_register() API which is provided by nand.c >> and needs to be enabled during SPL build via CONFIG_SPL_NAND_INIT. >> But nand.c also provides nand_init() so we need to get rid of nand_init() >> in omap_gpmc driver if CONFIG_SPL_NAND_INIT is set. >> >> Signed-off-by: Roger Quadros >> --- >> drivers/mtd/nand/raw/Kconfig | 1 + >> drivers/mtd/nand/raw/omap_gpmc.c | 55 +++++++++++++++++++++++++++++++- >> 2 files changed, 55 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/mtd/nand/raw/Kconfig b/drivers/mtd/nand/raw/Kconfig >> index bc5cabdfc2..1d23144ce4 100644 >> --- a/drivers/mtd/nand/raw/Kconfig >> +++ b/drivers/mtd/nand/raw/Kconfig >> @@ -190,6 +190,7 @@ config NAND_LPC32XX_SLC >> config NAND_OMAP_GPMC >> bool "Support OMAP GPMC NAND controller" >> depends on ARCH_OMAP2PLUS || ARCH_KEYSTONE || ARCH_K3 >> + select SYS_NAND_SELF_INIT if ARCH_K3 > > I have a question about this down below. > >> help >> Enables omap_gpmc.c driver for OMAPx and AMxxxx platforms. >> GPMC controller is used for parallel NAND flash devices, and can >> diff --git a/drivers/mtd/nand/raw/omap_gpmc.c b/drivers/mtd/nand/raw/omap_gpmc.c >> index e772a914c8..7192ca9e5a 100644 >> --- a/drivers/mtd/nand/raw/omap_gpmc.c >> +++ b/drivers/mtd/nand/raw/omap_gpmc.c >> @@ -7,6 +7,7 @@ >> #include >> #include >> #include >> +#include >> #include >> >> #ifdef CONFIG_ARCH_OMAP2PLUS >> @@ -1121,7 +1122,7 @@ int __maybe_unused omap_nand_switch_ecc(uint32_t hardware, uint32_t eccstrength) >> * nand_scan about special functionality. See the defines for further >> * explanation >> */ >> -int board_nand_init(struct nand_chip *nand) >> +int gpmc_nand_init(struct nand_chip *nand) >> { >> int32_t gpmc_config = 0; >> int cs = cs_next++; >> @@ -1201,3 +1202,55 @@ int board_nand_init(struct nand_chip *nand) >> >> return 0; >> } >> + >> +static struct nand_chip *nand_chip; /* First NAND chip for SPL use only */ >> + >> +#if CONFIG_IS_ENABLED(SYS_NAND_SELF_INIT) >> + >> +static int gpmc_nand_probe(struct udevice *dev) >> +{ >> + struct nand_chip *nand = dev_get_priv(dev); >> + struct mtd_info *mtd = nand_to_mtd(nand); >> + int ret; >> + >> + gpmc_nand_init(nand); >> + >> + ret = nand_scan(mtd, CONFIG_SYS_NAND_MAX_CHIPS); >> + if (ret) >> + return ret; >> + >> + ret = nand_register(0, mtd); >> + if (ret) >> + return ret; >> + >> + if (!nand_chip) >> + nand_chip = nand; >> + >> + return 0; >> +} >> + >> +static const struct udevice_id gpmc_nand_ids[] = { >> + { .compatible = "ti,am64-nand" }, >> + { .compatible = "ti,omap2-nand" }, > > The gpmc_nand_ids reference to omap2, but it's encapsulated inside the > SYS_NAND_SELF_INIT ifdef which appears to only be set if K3. Should > this code be expected to work on OMAP2? I don't think K3 is set for > OMAP2+. If so, should the SYS_NAND_SELF_INIT be selected if OMAP2 is > selected? We want to eventually get this working using driver model and SYS_NAND_SELF_INIT for OMAP2 as well but just that I didn't work on it yet or test it. One challenge is that OMAP2 boards tend to either select nand_spl_simple.c or am335x_spl_bch.c for NAND support at SPL. We will need to figure out if it is possible to use CONFIG_SPL_NAND_INIT and this driver instead. One issue might be that everything doesn't fit in resources available at SPL? > > I have a DM3730 that I can test with this. Do you have a repo I can That would be great. Thanks! > point to to test? If not, I'll pull the series from patchwork, but I > need to know what branch to use as a starting point. You can use this Repo as reference. https://github.com/rogerq/u-boot/commits/for-v2023.01/am64-nand-base-1.0-test It has a few patches on top consisting of device tree and u-boot configuration for AM64 platform. You can ignore the last 2 patches as they are only for a workaround on early AM64 boards. If you hit any hurdles, we can discuss how to resolve. > > thanks, > > adam > >> + { } >> +}; >> + >> +U_BOOT_DRIVER(gpmc_nand) = { >> + .name = "gpmc-nand", >> + .id = UCLASS_MTD, >> + .of_match = gpmc_nand_ids, >> + .probe = gpmc_nand_probe, >> + .priv_auto = sizeof(struct nand_chip), >> +}; >> + >> +void board_nand_init(void) >> +{ >> + struct udevice *dev; >> + int ret; >> + >> + ret = uclass_get_device_by_driver(UCLASS_MTD, >> + DM_DRIVER_GET(gpmc_nand), &dev); >> + if (ret && ret != -ENODEV) >> + pr_err("%s: Failed to get GPMC device: %d\n", __func__, ret); >> +} >> +#endif /* CONFIG_SYS_NAND_SELF_INIT */ >> -- >> 2.17.1 >> cheers, -roger