Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1813850ybk; Mon, 11 May 2020 05:03:52 -0700 (PDT) X-Google-Smtp-Source: APiQypIq/i5ehoU0Ah6MRS5XdeN2m5CqgDHjjcENZWsqbmraz52bB0/v9rXOOMz+NTp+p2rZ3rXv X-Received: by 2002:a17:907:42d6:: with SMTP id ng6mr12709765ejb.265.1589198632327; Mon, 11 May 2020 05:03:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589198632; cv=none; d=google.com; s=arc-20160816; b=eai2MGQOwKFhQte9JCYvh0bZ+uh8zZ+NaQoHS3y9kXHjC4mOYv2W3I8s6JDBG+0KM7 drFhjUIvOXUCRho3LbjQuUpsaRHAzIEe/MkSJlx+D3MiVkShKhv+bZPMEG3c8HIekrjw V736LwsI8pN+lyQPP/C9jiYLmwo41Cs2s0egeBeLMebLlCB/xwPkUV2nzRvdRO5skvP8 Rk45urujfz2Kx4r/Bf2n41JES170dGtodnRyfjmfZrKRwUdxTC8jOIgE65gb+GjUTQ4K iVGlS24XL7kSUyZLxEkuq4bnhJIzZ90TrQkvysSy5Akoy5s/DEVDEiluXvY3SfRAvyKF MEsw== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=BM+J/wf7KhsJolrL0WLyGM7IHL2YsZ36UoQXl3LWcCI=; b=K3qcWEnoUg+TnkMHgXdbkuZeADtEpVa7fT6w75C8ilqpnjc5tR52nqXPV5nnuugsQT ddM/RTC560U6sjwHfIWFAUeac6bn8EoSyiQIFNbG9E1ALFz/2pTIuYiOF0tYjjV2zDiz ks0l8Bkj4Xh4h9DPTdvqsxjnGdrSQDcmB+0EHr58LVaGE/1A+OR7XWpqoRym1mSynznN 2YoyeMr6oDsKvKh8maXXUH8i6AiSaZZyuWC2e8n3ckYAbw5IAdwgpoFJ8obtr1kkqvOm sIPHnjZGoc9pDSeACLNxLskLXh4u+1gQEPoCe319c46CNt63i8FSqWZHThG7sgRxbG0S spzA== ARC-Authentication-Results: i=1; mx.google.com; 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 p2si355103edx.419.2020.05.11.05.03.26; Mon, 11 May 2020 05:03:52 -0700 (PDT) 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; 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 S1729957AbgEKL7d convert rfc822-to-8bit (ORCPT + 99 others); Mon, 11 May 2020 07:59:33 -0400 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:39149 "EHLO relay7-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729929AbgEKL7b (ORCPT ); Mon, 11 May 2020 07:59:31 -0400 X-Originating-IP: 91.224.148.103 Received: from xps13 (unknown [91.224.148.103]) (Authenticated sender: miquel.raynal@bootlin.com) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 50DF220006; Mon, 11 May 2020 11:59:28 +0000 (UTC) Date: Mon, 11 May 2020 13:59:26 +0200 From: Miquel Raynal To: Christophe Kerello Cc: , , , , , , , , , , Subject: Re: [PATCH v4 10/10] mtd: rawnand: stm32_fmc2: get resources from parent node Message-ID: <20200511135926.3e5c622d@xps13> In-Reply-To: <3377adc6-3e5e-b9b7-12be-c7aa44bfac82@st.com> References: <1588756279-17289-1-git-send-email-christophe.kerello@st.com> <1588756279-17289-11-git-send-email-christophe.kerello@st.com> <20200511111855.48216940@xps13> <3377adc6-3e5e-b9b7-12be-c7aa44bfac82@st.com> Organization: Bootlin X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Christophe, Christophe Kerello wrote on Mon, 11 May 2020 12:21:03 +0200: > Hi Miquel, > > On 5/11/20 11:18 AM, Miquel Raynal wrote: > > Hi Christophe, > > > > Christophe Kerello wrote on Wed, 6 May 2020 > > 11:11:19 +0200: > > > >> FMC2 EBI support has been added. Common resources (registers base > >> and clock) are now shared between the 2 drivers. It means that the > >> common resources should now be found in the parent device when EBI > >> node is available. > >> > >> Signed-off-by: Christophe Kerello > >> --- > > > > [...] > > > >> + > >> +static bool stm32_fmc2_nfc_check_for_parent(struct platform_device *pdev) > >> +{ > >> + u32 i; > >> + int nb_resources = 0; > >> + > >> + /* Count the number of resources in reg property */ > >> + for (i = 0; i < pdev->num_resources; i++) { > >> + struct resource *res = &pdev->resource[i]; > >> + > >> + if (resource_type(res) == IORESOURCE_MEM) > >> + nb_resources++; > >> + } > >> + > >> + /* Each CS needs 3 resources defined (data, cmd and addr) */ > >> + if (nb_resources % 3) > >> + return false; > >> + > >> + return true; > >> +} > > > > This function looks fragile. Why not just checking the compatible > > string of the parent node? > > > > Yes, it is another way to check that we have an EBI parent node. > > In this implementation, I was checking the number of reg tuples. > In case we have 6, it means that the register base address is defined in the parent node (EBI node). > In case we have 7, it means that the register base address is defined in the current node (NFC node). Yes, I understand what you are doing, but I kind of dislike the logic. Relying on the number of reg tuples is something that can be done (I used it myself one time), but I think this is more a hack that you do when you have no other way to differentiate. I guess the proper way would be to look at the parent's compatible. If it matches what you expect, then you can store the dev->of_node->parent->dev somewhere in your controller's structure and then use it to initialize the clock and regmap. This way you don't have to move anything else in the probe path. Thanks, Miquèl