Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2885273imm; Fri, 19 Oct 2018 01:06:43 -0700 (PDT) X-Google-Smtp-Source: ACcGV63uh5oqTPxMlvnhOKdGo1hIYtbauEl1bVij41ICfrGYV5pP3fEhtxg4vTIZ58M9Vw3rW1+2 X-Received: by 2002:a17:902:6b46:: with SMTP id g6-v6mr32120064plt.19.1539936403614; Fri, 19 Oct 2018 01:06:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539936403; cv=none; d=google.com; s=arc-20160816; b=jMW9BDxAEhHhfQDV6v9qVyVXTNhxUpMKrP5Z0P8NFW1WsDwI6+l+beHuKGGqBtvuUR vkN5yy/iUvmV5hPet8d/3DhDMFzkzhG+5AQ+TvdNFPZ1fsUhOycdNGfBH4LbLXsbHUYC Bs/nspDcpAUGak/8IxGuxpIGdcsyRBLZF36oeAEkuo4rwVecCjFB1DXyC3ha3p3RjRN1 GgJXwpQRyf4GIyc3o6YRnF86+Cs0naLrdYW/RcDIVc1I64mPG3VB32nGa0veqNHusWpA uKTFBrjssmJUIn2eoqa716/v8nlbLh+RlU97RwpQFoBq/h/3zhDXai6QmbTyBqScH8jw ifRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=hgWAhcQZvfbZpob7hKW08bv13oRq8HJic/ak0rZc3aM=; b=W+mEiOtU/CNpKre8Ek+Ey/cnOHM9nTJeRm0zZgVMkk0NxIiGD/V/R9euHmaHY3geqK YNcmpnxMIT6r6fWZv+GqyHcUccNIgQBEZlvYpffqYeIFkHS4tZOT2p4RTvSGW2nUbruQ ztr7OLPzcDEPz9Ut2IHDa9jZnU6ID4IOmV5IwS9hP0BwzJDqRHtXQ+CeKC+jz1GTUiFG g5KqLrW8tC/asJtRC8cRN11OWNPLkBGCnxts5bqS9tFRtLs+EkbYDfbS2lezYGtYNctk xB5/fqT5tVA8bXibFrH8xWDM37yXZA4YsP7U5sIY+83UKCILw2jgNOFT+tsAZ3OAxe7J nmtQ== ARC-Authentication-Results: i=1; mx.google.com; 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 a16-v6si22057107pgw.187.2018.10.19.01.06.27; Fri, 19 Oct 2018 01:06:43 -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; 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 S1727067AbeJSQJP (ORCPT + 99 others); Fri, 19 Oct 2018 12:09:15 -0400 Received: from mail-sz2.amlogic.com ([211.162.65.114]:45204 "EHLO mail-sz2.amlogic.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726758AbeJSQJO (ORCPT ); Fri, 19 Oct 2018 12:09:14 -0400 Received: from [10.28.18.51] (10.28.18.51) by mail-sz2.amlogic.com (10.28.11.6) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Fri, 19 Oct 2018 16:04:09 +0800 Subject: Re: [PATCH v5 2/2] mtd: rawnand: meson: add support for Amlogic NAND flash controller To: Boris Brezillon , Jianxin Pan CC: , Yixun Lan , David Woodhouse , Brian Norris , Marek Vasut , Richard Weinberger , Jerome Brunet , Neil Armstrong , Martin Blumenstingl , Carlo Caione , Kevin Hilman , Rob Herring , Jian Hu , Hanjie Lin , Victor Wan , , , References: <1539839345-14021-1-git-send-email-jianxin.pan@amlogic.com> <1539839345-14021-3-git-send-email-jianxin.pan@amlogic.com> <20181018223943.145e5497@bbrezillon> From: Liang Yang Message-ID: Date: Fri, 19 Oct 2018 16:04:09 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20181018223943.145e5497@bbrezillon> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.28.18.51] X-ClientProxiedBy: mail-sz2.amlogic.com (10.28.11.6) To mail-sz2.amlogic.com (10.28.11.6) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018/10/19 4:39, Boris Brezillon wrote: > On Thu, 18 Oct 2018 13:09:05 +0800 > Jianxin Pan wrote: > >> +static int meson_nfc_calc_set_timing(struct meson_nfc *nfc, >> + const struct nand_sdr_timings *timings) >> +{ >> + struct nand_timing *timing = &nfc->timing; >> + int div, bt_min, bt_max, bus_timing; >> + int ret; >> + >> + div = DIV_ROUND_UP((timings->tRC_min / 1000), NFC_CLK_CYCLE); >> + ret = clk_set_rate(nfc->device_clk, 1000000000 / div); >> + if (ret) { >> + dev_err(nfc->dev, "failed to set nand clock rate\n"); >> + return ret; >> + } >> + >> + timing->twb = DIV_ROUND_UP(PSEC_TO_NSEC(timings->tWB_max), >> + div * NFC_CLK_CYCLE); >> + timing->tadl = DIV_ROUND_UP(PSEC_TO_NSEC(timings->tADL_min), >> + div * NFC_CLK_CYCLE); >> + timing->twhr = DIV_ROUND_UP(PSEC_TO_NSEC(timings->tWHR_min), >> + div * NFC_CLK_CYCLE); >> + >> + bt_min = (timings->tREA_max + NFC_DEFAULT_DELAY) / div; >> + bt_max = (NFC_DEFAULT_DELAY + timings->tRHOH_min >> + + timings->tRC_min / 2) / div; >> + >> + bt_min = DIV_ROUND_UP(bt_min, 1000); >> + bt_max = DIV_ROUND_UP(bt_max, 1000); >> + >> + if (bt_max < bt_min) >> + return -EINVAL; >> + >> + bus_timing = (bt_min + bt_max) / 2 + 1; >> + >> + writel((1 << 21), nfc->reg_base + NFC_REG_CFG); >> + writel((NFC_CLK_CYCLE - 1) | (bus_timing << 5), >> + nfc->reg_base + NFC_REG_CFG); >> + >> + writel((1 << 31), nfc->reg_base + NFC_REG_CMD); >> + >> + return 0; >> +} >> + >> +static int >> +meson_nfc_setup_data_interface(struct nand_chip *nand, int csline, >> + const struct nand_data_interface *conf) >> +{ >> + struct meson_nfc *nfc = nand_get_controller_data(nand); >> + const struct nand_sdr_timings *timings; >> + >> + timings = nand_get_sdr_timings(conf); >> + if (IS_ERR(timings)) >> + return -ENOTSUPP; >> + >> + if (csline == NAND_DATA_IFACE_CHECK_ONLY) >> + return 0; > > Hm, before saying you supporting the requested timing, you should make > sure they are actually supported. I'd recommend splitting this in 2 > steps: > > 1/ calc timings > 2/ store the timings in the chip priv struct so that they can be > applied next time ->select_chip() is called. > ok, i will try to split. >> + >> + meson_nfc_calc_set_timing(nfc, timings); > > You should not set the timing from ->setup_data_interface(), just > calculate them, make sure they are supported and store the state in the > private chip struct. Applying those timings should be done in > ->select_chip(), so that you can support 2 chips with different timings. > em, i will fix it. >> + return 0; >> +} > > . >