Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp3468585ybh; Tue, 17 Mar 2020 00:20:45 -0700 (PDT) X-Google-Smtp-Source: ADFU+vv2H50e1EEp24S4NgngcArWrXsKqVN5WpeLgReHt2NsZDk7qP3R824QaZLYj0xe7/fv/pnY X-Received: by 2002:aca:bd46:: with SMTP id n67mr2355373oif.120.1584429645386; Tue, 17 Mar 2020 00:20:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584429645; cv=none; d=google.com; s=arc-20160816; b=xvi4DYY2CYkT9vfyibBfjE3um3hC1EQVltTSMcoomF4mIjYDHMfTC1dlx6VhaUTW4O 9Irj/NmzEo0CDnzqQMNom7J+/ghtzMin+OoFCMzwsaxG2pF+pGpK1IkB78f9O2gnUiQi r3PdTbcxIXhVppejtpCnk+qiBKbwjROn+u1Hc+dhVxiuwv1uMERgvaasM/rTUeGQzDyQ KVg7/IsPjKg3WCPyTH2eeqhV1QaA2eEhUbclZ+brQNwwIC0PAAS8JqDBls4KlErkBuAm Rca4YBc67KREJxHY1TeBjp11kT7asMTfGdjLT9nmeeWEsAl6przwPQYQKs+A+iOBVCUO Ubew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=fNnkxR8DOGQvxRfKIJdABgxeaKL0NvEnwytfHdcBJm4=; b=WlCFZrz+YuubdOAwe7OMz0JQjuMyF+UNVEXnLrvmTiS8q+0V+OXCs7WumaYaExdd3L 9/DYq9ypf25pZ4FmmTFXEeXVrejhZsAmLItXdjDj/PmrTqQZz1jVvEeJ70hY+D/4ouZn nZp1L92dPYRxd22eRZMqwfS5KYb3+lRQbEUfVdk2AQbZgLJ99PR4W9T39WjjBifibsRT wpGVOPa6BTaMs4DYqMCe4C3jDE7WujbmIV+tAtUU4+argTN/5fu0dzgAnceJiapZJW8+ 0p6M5AqECi4ZrwwnJ0/6Sm7eiMN/3/c6NdiCMnH1/p/Hx8BCW7vq3J6av0eYaUmsWyTd CYlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=dDlA8sZt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w26si1194960otk.156.2020.03.17.00.20.31; Tue, 17 Mar 2020 00:20:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=dDlA8sZt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725906AbgCQHTw (ORCPT + 99 others); Tue, 17 Mar 2020 03:19:52 -0400 Received: from conuserg-08.nifty.com ([210.131.2.75]:58683 "EHLO conuserg-08.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725536AbgCQHTv (ORCPT ); Tue, 17 Mar 2020 03:19:51 -0400 Received: from localhost.localdomain (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id 02H7IOXQ030020; Tue, 17 Mar 2020 16:18:25 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com 02H7IOXQ030020 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1584429505; bh=fNnkxR8DOGQvxRfKIJdABgxeaKL0NvEnwytfHdcBJm4=; h=From:To:Cc:Subject:Date:From; b=dDlA8sZt3GUJ/yWErjaO450OkOiME1Ve7uLILGEV2WCwxjMJD/EbdP21u6pHl1iQ6 Me8YzXp27F8Kz6gEcMc27F/g7Iuq82Rp4EWwAAWRKbvjKTgEgYty8k8XVsIYIyhFoC G6r1TTel5vNcWVi0f3uyP/8OFU8/NALOpxGfxo7RBBEFdTHl9tk+StMNtY1N+2Om/e JMi8Rv6r7fprgn4/CQ+Wl9CxNA7OmzwsTlEwDlD2H10v1AyzxcccRnzTg3N70dGqoQ LAqupbONuS6i8/6FRP35/WTVixKIckqfNu0I54lLOILPXdWEjPJacaYTZr1uHxZUhl CMao0EgSO708Q== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-mtd@lists.infradead.org Cc: Marek Vasut , Miquel Raynal , Masahiro Yamada , Richard Weinberger , Vignesh Raghavendra , linux-kernel@vger.kernel.org Subject: [PATCH v2] mtd: rawnand: denali: add more delays before latching incoming data Date: Tue, 17 Mar 2020 16:18:21 +0900 Message-Id: <20200317071821.9916-1-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The Denali IP have several registers to specify how many clock cycles should be waited between falling/rising signals. You can improve the NAND access performance by programming these registers with optimized values. Because struct nand_sdr_timings represents the device requirement in pico seconds, denali_setup_data_interface() computes the register values by dividing the device timings with the clock period. Marek Vasut reported this driver in the latest kernel does not work on his SOCFPGA board. (The on-board NAND chip is mode 5) The suspicious parameter is acc_clks, so this commit relaxes it. The Denali NAND Flash Memory Controller User's Guide describes this register as follows: acc_clks signifies the number of bus interface clk_x clock cycles, controller should wait from read enable going low to sending out a strobe of clk_x for capturing of incoming data. Currently, acc_clks is calculated only based on tREA, the delay on the chip side. This does not include additional delays that come from the data path on the PCB and in the SoC, load capacity of the pins, etc. This relatively becomes a big factor on faster timing modes like mode 5. Before supporting the ->setup_data_interface() hook (e.g. Linux 4.12), the Denali driver hacks acc_clks in a couple of ways [1] [2] to support the timing mode 5. We would not go back to the hard-coded acc_clks, but we need to include this factor into the delay somehow. Let's say the amount of the additional delay is 10000 pico sec. In the new calculation, acc_clks is determined by timings->tREA_max + data_setup_on_host. Also, prolong the RE# low period to make sure the data hold is met. Finally, re-center the data latch timing for extra safety. [1] https://github.com/torvalds/linux/blob/v4.12/drivers/mtd/nand/denali.c#L276 [2] https://github.com/torvalds/linux/blob/v4.12/drivers/mtd/nand/denali.c#L282 Reported-by: Marek Vasut Signed-off-by: Masahiro Yamada --- Changes in v2: - Use 'unsigned int' instead of 'u32' for data_setup_on_host - Fix 'line over 80 characters' warning from checkpatch.pl drivers/mtd/nand/raw/denali.c | 45 ++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/drivers/mtd/nand/raw/denali.c b/drivers/mtd/nand/raw/denali.c index 6a6c919b2569..2fcd2baf6e35 100644 --- a/drivers/mtd/nand/raw/denali.c +++ b/drivers/mtd/nand/raw/denali.c @@ -764,6 +764,7 @@ static int denali_write_page(struct nand_chip *chip, const u8 *buf, static int denali_setup_data_interface(struct nand_chip *chip, int chipnr, const struct nand_data_interface *conf) { + static const unsigned int data_setup_on_host = 10000; struct denali_controller *denali = to_denali_controller(chip); struct denali_chip_sel *sel; const struct nand_sdr_timings *timings; @@ -796,15 +797,6 @@ static int denali_setup_data_interface(struct nand_chip *chip, int chipnr, sel = &to_denali_chip(chip)->sels[chipnr]; - /* tREA -> ACC_CLKS */ - acc_clks = DIV_ROUND_UP(timings->tREA_max, t_x); - acc_clks = min_t(int, acc_clks, ACC_CLKS__VALUE); - - tmp = ioread32(denali->reg + ACC_CLKS); - tmp &= ~ACC_CLKS__VALUE; - tmp |= FIELD_PREP(ACC_CLKS__VALUE, acc_clks); - sel->acc_clks = tmp; - /* tRWH -> RE_2_WE */ re_2_we = DIV_ROUND_UP(timings->tRHW_min, t_x); re_2_we = min_t(int, re_2_we, RE_2_WE__VALUE); @@ -862,14 +854,45 @@ static int denali_setup_data_interface(struct nand_chip *chip, int chipnr, tmp |= FIELD_PREP(RDWR_EN_HI_CNT__VALUE, rdwr_en_hi); sel->rdwr_en_hi_cnt = tmp; - /* tRP, tWP -> RDWR_EN_LO_CNT */ + /* + * tREA -> ACC_CLKS + * tRP, tWP, tRHOH, tRC, tWC -> RDWR_EN_LO_CNT + */ + + /* + * Determine the minimum of acc_clks to meet the setup timing when + * capturing the incoming data. + * + * The delay on the chip side is well-defined as tREA, but we need to + * take additional delay into account. This includes a certain degree + * of unknowledge, such as signal propagation delays on the PCB and + * in the SoC, load capacity of the I/O pins, etc. + */ + acc_clks = DIV_ROUND_UP(timings->tREA_max + data_setup_on_host, t_x); + + /* Determine the minimum of rdwr_en_lo_cnt from RE#/WE# pulse width */ rdwr_en_lo = DIV_ROUND_UP(max(timings->tRP_min, timings->tWP_min), t_x); + + /* Extend rdwr_en_lo to meet the data hold timing */ + rdwr_en_lo = max_t(int, rdwr_en_lo, + acc_clks - timings->tRHOH_min / t_x); + + /* Extend rdwr_en_lo to meet the requirement for RE#/WE# cycle time */ rdwr_en_lo_hi = DIV_ROUND_UP(max(timings->tRC_min, timings->tWC_min), t_x); - rdwr_en_lo_hi = max_t(int, rdwr_en_lo_hi, mult_x); rdwr_en_lo = max(rdwr_en_lo, rdwr_en_lo_hi - rdwr_en_hi); rdwr_en_lo = min_t(int, rdwr_en_lo, RDWR_EN_LO_CNT__VALUE); + /* Center the data latch timing for extra safety */ + acc_clks = (acc_clks + rdwr_en_lo + + DIV_ROUND_UP(timings->tRHOH_min, t_x)) / 2; + acc_clks = min_t(int, acc_clks, ACC_CLKS__VALUE); + + tmp = ioread32(denali->reg + ACC_CLKS); + tmp &= ~ACC_CLKS__VALUE; + tmp |= FIELD_PREP(ACC_CLKS__VALUE, acc_clks); + sel->acc_clks = tmp; + tmp = ioread32(denali->reg + RDWR_EN_LO_CNT); tmp &= ~RDWR_EN_LO_CNT__VALUE; tmp |= FIELD_PREP(RDWR_EN_LO_CNT__VALUE, rdwr_en_lo); -- 2.17.1