Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3357332pxb; Mon, 17 Jan 2022 18:29:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJyk6L5OwBaQB2ZAUiY2bfrZQXy16Fz7iDzvhix8ooLUtHcOgIUJfqIJMaDX70srM8sRESdA X-Received: by 2002:a05:6a00:17aa:b0:4c0:54f8:9abf with SMTP id s42-20020a056a0017aa00b004c054f89abfmr24059156pfg.0.1642472969569; Mon, 17 Jan 2022 18:29:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642472969; cv=none; d=google.com; s=arc-20160816; b=uO4VcoAtGgCJTWTjECNQ1PflFuAbFoafzGG1rza0yhAxjI3z21Qz2c06QRHioe0dtw jJAdjhFoZpxf23nJfzYDg6+BmmUz6pX8KMyHhcyaCztjsqudlMfdzJT+1xTnT7n2X4cw ksLvbIIleJbVE8X/pv1DXCKDGtw+Cg7ffMd5XZxmgfI7YkOk1OrAEmFdeC0WdsoTcj0B fyictD1AmNsHy+mooeYH63CQJH4/9yiVGbUO+A7KgeTbzQF9H/QD1/t5oWFvZ6qxshcO jXdJcZGMASchI8uqKl/PEDGFwhIY5R33UKyMoHWXOgKabBIQg76+0A1EEW4z9XZ+xKGf 9EYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=x/F5VAIUnuZoKvZjwxrhtVdlFx14UE2p7e9E4YI4S8Q=; b=qZHQt7TJjFNBx/dGmd4iufR8kL+vD/hPphQxsx4Dr9+Xf71IbgmLq00tSbsvmc/UL8 Tu7A7opCO6+5hFLNNLPTGpk2pMm2NKdDOEAQ8bj75kjl/J51RZnZFU/4Isnspvs71Lmo lP9Efl5IfUEikSOnZ0A0G9EcVdrAI6fQDjZokJBCP/NeiDDofq8JI2vz33jE1Dhme9vb LM3eiR/40tLSXJhHor9LtWLfZzkcsg3Mi7pXUWmuKIy5eG2wEnQtRkSk1Zj6lg2MeOI4 PZvmMtp6DXvJ1jKKmVNBYi6P+HCvUyrG1Jt66rMZc0gHt9Jm3LicqdTkM8P7cSjEBm9+ fkYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=dtThkQCB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n12si17530172plc.426.2022.01.17.18.29.17; Mon, 17 Jan 2022 18:29:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=dtThkQCB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232949AbiAQOIp (ORCPT + 99 others); Mon, 17 Jan 2022 09:08:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230445AbiAQOIn (ORCPT ); Mon, 17 Jan 2022 09:08:43 -0500 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51BF8C061574 for ; Mon, 17 Jan 2022 06:08:43 -0800 (PST) Received: by mail-lf1-x12f.google.com with SMTP id b14so39577953lff.3 for ; Mon, 17 Jan 2022 06:08:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=x/F5VAIUnuZoKvZjwxrhtVdlFx14UE2p7e9E4YI4S8Q=; b=dtThkQCBCm+J6vmjue/Tmyk3oTBjYJ9zd+y8nd9e44YNb18prJSoUUJYV5sVSBLmqQ 8PrQZai4p64TkxCs6UPRZcfIoD8uxIaWjFlf210TGtMVPQPxZf+84xJGO0+Qgv14dNQ3 enuoVdwgz/Q0+8Hu9w1nS8foUn7Np+LrDcPQw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=x/F5VAIUnuZoKvZjwxrhtVdlFx14UE2p7e9E4YI4S8Q=; b=wh9FDQM8/PsRtvp6pPPuxR40UR4RhQjZuE3Ah0zbTtRc6MNmkM0x1mWw3dG2gt+t/+ lt4ThHra0aB31NMYtqi3XBBAzeOfogxt/XsFNqaqcYW+Kf0MPOVMj+wVQxj5q7CKNDxk DQGy5FmkBdQZyYzPXhVsTZ8L+DQa+eXxMFqyPfyrwyr1vjVX+xE4PZHiCdJlODXuI6gl V3PjsIj0X8VWIlUfd5CXtVzcoFe0Aet7WREc6MqAQ8Aj+rNIn0v/RCNQRq7SFB+5SjRa XtJsM0DDAsRyBnGOJvZ1GX0LjUhmPz7IWHXjhyAMjDC72BdNViI2FOyu5JrHbBSYvKAJ s9OQ== X-Gm-Message-State: AOAM531xNk8O3L5gcQlX6WgU87TsdvZkMGHCoNb0f9Yt6qmn5Dmo4iQl oyz5unyzDaqpa5BpC6CrmS8jz4i3zsCnSM50rdfstA== X-Received: by 2002:a2e:95cf:: with SMTP id y15mr14765814ljh.132.1642428521589; Mon, 17 Jan 2022 06:08:41 -0800 (PST) MIME-Version: 1.0 References: <20220117111829.1811997-1-dario.binacchi@amarulasolutions.com> <20220117111829.1811997-4-dario.binacchi@amarulasolutions.com> In-Reply-To: From: Dario Binacchi Date: Mon, 17 Jan 2022 15:08:30 +0100 Message-ID: Subject: Re: [RFC PATCH v2 3/5] mtd: rawnand: gpmi: use a table to get EDO mode setup To: Sascha Hauer Cc: linux-kernel@vger.kernel.org, Michael Trimarchi , Han Xu , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , linux-mtd@lists.infradead.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Sascha, On Mon, Jan 17, 2022 at 2:18 PM Sascha Hauer wrote: > > Hi Dario, > > On Mon, Jan 17, 2022 at 12:18:27PM +0100, Dario Binacchi wrote: > > +struct edo_mode { > > + u32 tRC_min; > > + long clk_rate; > > + u8 wrn_dly_sel; > > +}; > > + > > +static const struct edo_mode edo_modes[] = { > > + {.tRC_min = 30000, .clk_rate = 22000000, > > + .wrn_dly_sel = BV_GPMI_CTRL1_WRN_DLY_SEL_4_TO_8NS}, > > + {.tRC_min = 30000, .clk_rate = 22000000, > > + .wrn_dly_sel = BV_GPMI_CTRL1_WRN_DLY_SEL_4_TO_8NS}, > > + {.tRC_min = 30000, .clk_rate = 22000000, > > + .wrn_dly_sel = BV_GPMI_CTRL1_WRN_DLY_SEL_4_TO_8NS}, > > + {.tRC_min = 30000, .clk_rate = 22000000, > > + .wrn_dly_sel = BV_GPMI_CTRL1_WRN_DLY_SEL_4_TO_8NS}, > > + {.tRC_min = 25000, .clk_rate = 80000000, > > + .wrn_dly_sel = BV_GPMI_CTRL1_WRN_DLY_SEL_NO_DELAY}, > > + {.tRC_min = 20000, .clk_rate = 100000000, > > + .wrn_dly_sel = BV_GPMI_CTRL1_WRN_DLY_SEL_NO_DELAY}, > > +}; > > + > > /* > > * <1> Firstly, we should know what's the GPMI-clock means. > > * The GPMI-clock is the internal clock in the gpmi nand controller. > > @@ -657,22 +678,18 @@ static void gpmi_nfc_compute_timings(struct gpmi_nand_data *this, > > int sample_delay_ps, sample_delay_factor; > > u16 busy_timeout_cycles; > > u8 wrn_dly_sel; > > + int i, emode = ARRAY_SIZE(edo_modes) - 1; > > > > - if (sdr->tRC_min >= 30000) { > > - /* ONFI non-EDO modes [0-3] */ > > - hw->clk_rate = 22000000; > > - wrn_dly_sel = BV_GPMI_CTRL1_WRN_DLY_SEL_4_TO_8NS; > > - } else if (sdr->tRC_min >= 25000) { > > - /* ONFI EDO mode 4 */ > > - hw->clk_rate = 80000000; > > - wrn_dly_sel = BV_GPMI_CTRL1_WRN_DLY_SEL_NO_DELAY; > > - } else { > > - /* ONFI EDO mode 5 */ > > - hw->clk_rate = 100000000; > > - wrn_dly_sel = BV_GPMI_CTRL1_WRN_DLY_SEL_NO_DELAY; > > + /* Search the required EDO mode */ > > + for (i = 0; i < ARRAY_SIZE(edo_modes); i++) { > > + if (sdr->tRC_min >= edo_modes[i].tRC_min) { > > + emode = i; > > + break; > > + } > > The first four entries of edo_modes[] all have the same value, so this loop > will never end on the second, third or fourth element. These elements are just > there to match 'emode' with the existing ONFI mode numbers, but then 'emode' is > never used as an ONFI mode number, instead it's only used as an index to the > array. You could equally well remove the second till fourth array entries. > > Then with only three entries left in the array I wonder if you're not better > off with the original code and change it to something like: This implementation is justified by the next patch in the series ([RFC PATCH v2 4/5] mtd: rawnand: gpmi: validate controller clock rate). I thought that clock rate validation could be better implemented by indexing a table. The replication of the second, third and fourth elements makes the index also the edo mode (used in the debug printout). Using a less redundant table (three elements) requires the edo mode to be stored in it if you want to keep the debug printing or remove the debug message. > > if (sdr->tRC_min >= 30000) { > /* ONFI non-EDO modes [0-3] */ > hw->clk_rate = 22000000; > min_rate = 0; > wrn_dly_sel = BV_GPMI_CTRL1_WRN_DLY_SEL_4_TO_8NS; > } else if (sdr->tRC_min >= 25000) { > /* ONFI EDO mode 4 */ > hw->clk_rate = 80000000; > min_rate = 22000000; > wrn_dly_sel = BV_GPMI_CTRL1_WRN_DLY_SEL_NO_DELAY; > } else { > /* ONFI EDO mode 5 */ > hw->clk_rate = 100000000; > min_rate = 80000000; > wrn_dly_sel = BV_GPMI_CTRL1_WRN_DLY_SEL_NO_DELAY; > } > > hw->clk_rate = clk_round_rate(r->clock[0], hw->clk_rate); > if (hw->clk_rate < min_rate) > return -EINVAL; > > I think this would be easier to follow. I think the key point is to decide if the patch "[RFC PATCH v2 4/5] mtd: rawnand: gpmi: validate controller clock rate" makes sense. I thought of this patch to facilitate that implementation, since it compares the real GPMI clock rate to that of the previous edo mode. I thought it wasn't elegant to implement another switch case. Thanks and regards, Dario > > Sascha > > -- > Pengutronix e.K. | | > Steuerwalder Str. 21 | http://www.pengutronix.de/ | > 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | > Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | -- Dario Binacchi Embedded Linux Developer dario.binacchi@amarulasolutions.com __________________________________ Amarula Solutions SRL Via Le Canevare 30, 31100 Treviso, Veneto, IT T. +39 042 243 5310 info@amarulasolutions.com www.amarulasolutions.com