From patchwork Tue Oct 17 08:00:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Kanzenbach X-Patchwork-Id: 826901 X-Patchwork-Delegate: yorksun@freescale.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yGWmF42xQz9s7m for ; Tue, 17 Oct 2017 21:35:09 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 525E6C21D64; Tue, 17 Oct 2017 10:34:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 11E48C21DA1; Tue, 17 Oct 2017 10:33:50 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8AFB1C21CA5; Tue, 17 Oct 2017 07:56:35 +0000 (UTC) Received: from Galois.linutronix.de (Galois.linutronix.de [146.0.238.70]) by lists.denx.de (Postfix) with ESMTPS id 3FA06C21C40 for ; Tue, 17 Oct 2017 07:56:35 +0000 (UTC) Received: from hsi-kbw-5-158-153-52.hsi19.kabel-badenwuerttemberg.de ([5.158.153.52] helo=kurt.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1e4Mjc-0007Ip-EI; Tue, 17 Oct 2017 09:56:20 +0200 From: Kurt Kanzenbach To: u-boot@lists.denx.de Date: Tue, 17 Oct 2017 10:00:45 +0200 Message-Id: <20171017080045.18950-1-kurt@linutronix.de> X-Mailer: git-send-email 2.11.0 X-Mailman-Approved-At: Tue, 17 Oct 2017 10:33:48 +0000 Cc: Scott Wood , Kurt Kanzenbach Subject: [U-Boot] [PATCH] mtd: nand: fsl-ifc: fix support of multiple NAND devices X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Currently the chipselect used to identify the corresponding NAND chip is stored at the controller and only set during fsl_ifc_chip_init(). This way, only the last NAND chip is working, as the previous value of cs_nand gets overwritten. In order to solve this issue the chipselect is moved from the controller to the NAND chip structure. Thus, the correct chipselect for each NAND chip operation is used. Tested on hardware with two NAND chips connected to the IFC controller. Signed-off-by: Kurt Kanzenbach --- drivers/mtd/nand/fsl_ifc_nand.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/nand/fsl_ifc_nand.c b/drivers/mtd/nand/fsl_ifc_nand.c index bc6bdc9b2c..57737dbe94 100644 --- a/drivers/mtd/nand/fsl_ifc_nand.c +++ b/drivers/mtd/nand/fsl_ifc_nand.c @@ -36,6 +36,7 @@ struct fsl_ifc_mtd { struct device *dev; int bank; /* Chip select bank number */ + unsigned int cs_nand; /* On which chipsel NAND is connected */ unsigned int bufnum_mask; /* bufnum = page & bufnum_mask */ u8 __iomem *vbase; /* Chip select base virtual address */ }; @@ -48,7 +49,6 @@ struct fsl_ifc_ctrl { /* device info */ struct fsl_ifc regs; void __iomem *addr; /* Address of assigned IFC buffer */ - unsigned int cs_nand; /* On which chipsel NAND is connected */ unsigned int page; /* Last page written to / read from */ unsigned int read_bytes; /* Number of bytes read during command */ unsigned int column; /* Saved column from SEQIN */ @@ -296,7 +296,7 @@ static int fsl_ifc_run_command(struct mtd_info *mtd) int i; /* set the chip select for NAND Transaction */ - ifc_out32(&ifc->ifc_nand.nand_csel, ifc_ctrl->cs_nand); + ifc_out32(&ifc->ifc_nand.nand_csel, priv->cs_nand); /* start read/write seq */ ifc_out32(&ifc->ifc_nand.nandseq_strt, @@ -798,8 +798,10 @@ static void fsl_ifc_select_chip(struct mtd_info *mtd, int chip) { } -static int fsl_ifc_sram_init(uint32_t ver) +static int fsl_ifc_sram_init(struct mtd_info *mtd, uint32_t ver) { + struct nand_chip *chip = mtd_to_nand(mtd); + struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); struct fsl_ifc_runtime *ifc = ifc_ctrl->regs.rregs; uint32_t cs = 0, csor = 0, csor_8k = 0, csor_ext = 0; uint32_t ncfgr = 0; @@ -823,7 +825,7 @@ static int fsl_ifc_sram_init(uint32_t ver) return 1; } - cs = ifc_ctrl->cs_nand >> IFC_NAND_CSEL_SHIFT; + cs = priv->cs_nand >> IFC_NAND_CSEL_SHIFT; /* Save CSOR and CSOR_ext */ csor = ifc_in32(&ifc_ctrl->regs.gregs->csor_cs[cs].csor); @@ -850,7 +852,7 @@ static int fsl_ifc_sram_init(uint32_t ver) ifc_out32(&ifc->ifc_nand.col0, 0x0); /* set the chip select for NAND Transaction */ - ifc_out32(&ifc->ifc_nand.nand_csel, ifc_ctrl->cs_nand); + ifc_out32(&ifc->ifc_nand.nand_csel, priv->cs_nand); /* start read seq */ ifc_out32(&ifc->ifc_nand.nandseq_strt, IFC_NAND_SEQ_STRT_FIR_STRT); @@ -912,7 +914,7 @@ static int fsl_ifc_chip_init(int devnum, u8 *addr) if ((cspr & CSPR_V) && (cspr & CSPR_MSEL) == CSPR_MSEL_NAND && (cspr & CSPR_BA) == CSPR_PHYS_ADDR(phys_addr)) { - ifc_ctrl->cs_nand = priv->bank << IFC_NAND_CSEL_SHIFT; + priv->cs_nand = priv->bank << IFC_NAND_CSEL_SHIFT; break; } } @@ -1029,7 +1031,7 @@ static int fsl_ifc_chip_init(int devnum, u8 *addr) ver = ifc_in32(&gregs->ifc_rev); if (ver >= FSL_IFC_V1_1_0) - ret = fsl_ifc_sram_init(ver); + ret = fsl_ifc_sram_init(mtd, ver); if (ret) return ret;