Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2379811imm; Thu, 18 Oct 2018 13:41:20 -0700 (PDT) X-Google-Smtp-Source: ACcGV63DSBQjlFSoc0ctVJG4qF5F14+neIdJWfZesuKxiEwZyW3yCl3AjYbTvcOkFYPLcrz+SRY6 X-Received: by 2002:a17:902:5a0c:: with SMTP id q12-v6mr16365189pli.253.1539895280482; Thu, 18 Oct 2018 13:41:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539895280; cv=none; d=google.com; s=arc-20160816; b=zjGpyo9fk/WRx3j+MgnGVcz6GE4abG18uAmlZ2qdRxAqT/THXaGl7YzCAZ6mWZ636Q LaWLLDPBhXC3tg8y1CXUwnFhDGZT/vwt3KM6OwoMjICj13cFzeEd5CoFJdMvu3rvAoH6 6CbvbCSDa4P6PKLhvnqzmBtPl3H44WKveJiQmxgdSTKS5Xk235AkF0WWqL1NLoeWWL47 l7zJJziGIXMogwei9UCZ/mPbKS3Hlen0tsLuTPNltV09VY6y1xOfgzC3mjiAn5tDbu32 B/6kcSiBdhoI3j3PhUu7ujsBmXWVE8sJ4eYvqHlx7qzcegKo4dALuePc82yJQ8xYJH0M 9/8g== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=n0ea1oisThxyVxO7Lvugx26Nie0vrva3UPB3f/+cEaw=; b=HDYY+UrE5njUKUHZPA7YibIXM9BB6iZu1rSnBSb0hcIOcpeGf/cW4ggn72pnaI3BYQ Wy2rbOSEKgVSLbQbmnX9Vjp+ITWhjNDOvAKzCvq3gnLJ/V6xSSanjLI051ZNpcdmbuR5 0GsdgPVgUhpCqo6V50b6dOfEt2iZgJlWOosNAwdzZZrPNtYOwCY4xF0hD5pLssmlT6Oj S70lPbOXmEpxqNJXDQoNRN1kqHDamg56gLLRVExF3K8ljDYP4nFxRFhcNti+yhCKroS3 l1t2pkHWy4wCWup6a/UkFJtDVeOMHHnGGloA23CsTTcnuJSqnsObQ8jaIohsD17UL76q 3UQw== 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 d18-v6si23576171plj.82.2018.10.18.13.41.04; Thu, 18 Oct 2018 13:41:20 -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 S1727423AbeJSEmc (ORCPT + 99 others); Fri, 19 Oct 2018 00:42:32 -0400 Received: from mail.bootlin.com ([62.4.15.54]:46592 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726653AbeJSEmc (ORCPT ); Fri, 19 Oct 2018 00:42:32 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id C5113207C4; Thu, 18 Oct 2018 22:39:44 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (91-160-177-164.subs.proxad.net [91.160.177.164]) by mail.bootlin.com (Postfix) with ESMTPSA id 253462072C; Thu, 18 Oct 2018 22:39:44 +0200 (CEST) Date: Thu, 18 Oct 2018 22:39:43 +0200 From: Boris Brezillon To: Jianxin Pan Cc: , Liang Yang , 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 , , , Subject: Re: [PATCH v5 2/2] mtd: rawnand: meson: add support for Amlogic NAND flash controller Message-ID: <20181018223943.145e5497@bbrezillon> In-Reply-To: <1539839345-14021-3-git-send-email-jianxin.pan@amlogic.com> References: <1539839345-14021-1-git-send-email-jianxin.pan@amlogic.com> <1539839345-14021-3-git-send-email-jianxin.pan@amlogic.com> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > + > + 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. > + return 0; > +}