Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1855263ybk; Mon, 11 May 2020 06:03:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycEj91ZOCQdB2lqBX7DfHcPk+spe+IjWL3HPMkqYqPh9cBfV59iZ2I+7b9uLAuILiLUBv0 X-Received: by 2002:a17:906:3495:: with SMTP id g21mr1744122ejb.154.1589202237861; Mon, 11 May 2020 06:03:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589202237; cv=none; d=google.com; s=arc-20160816; b=J2IjZB1tVgD1/CJfVvaEp/wOthTDYWjfR24ZUcRwqG3yUc0p4CO2nMGVicHDt8+y+Y i6MsHtljJzbQdu11/aMks7rp+ymbMXoNHB3awS0CI6B867oar8KvVpjTKxf8aqusN1fu EG1rWFoZulL44CdCFeALiZQSK26h6SnAJ0KCXkEatdeOa0ET17o6W4KwXIIaooHZqer1 68Pnm2od8aPAmyWia2xzU/ONEPMhiJ3FdQrJgVUU6tR02/UjkC3Inl7h2Pr0fATdDKvU iBg1oy6Ei6O54fZY3F3LuOumJUuw/wLH1j3Qo51oZtDJr+OMzZbLJ86VlEHkybfgUMPr SDzw== 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=xL1t/8e3+BUmliKYIXMuvlZ4ve0y893c0QQLsxYeF+Q=; b=Z/h6cGwo7nPf+Ig8DrlokrLZat4GZOE/Yxt2WNpP5B6Y9kXrwOIySFMeVFqUCHn2LN NqWIu+Xh2HpPQCZDgeyl5oYxaVFBsPvLV3WWwdeNn+nQCan0/MTmeoBsiuy+0qC2JZYk qO5yPCIbZwDa55pccNmc9y2A4l6gsM8aHMw8+7uFKYhr4RyqjysKYfErVGmUNKTlbVsB lVxfjALMXq8rxKyyFUNrIdBKnvP/JBJvFrfT+82Ql7W7S1ddbpM36ZbeUyvfZDEwDg0s g7GxxkW7GESnyoFosPHpEjzhntfwkdMI9jb5fg7GJlSxb1myLQc6H8U6AtIoeFt5AbbD /2DA== 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 c12si6106190edr.596.2020.05.11.06.03.10; Mon, 11 May 2020 06:03:57 -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 S1729221AbgEKM7B (ORCPT + 99 others); Mon, 11 May 2020 08:59:01 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:58093 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727827AbgEKM7B (ORCPT ); Mon, 11 May 2020 08:59:01 -0400 X-Originating-IP: 91.224.148.103 Received: from xps13 (unknown [91.224.148.103]) (Authenticated sender: miquel.raynal@bootlin.com) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id BBCCF24001A; Mon, 11 May 2020 12:58:56 +0000 (UTC) Date: Mon, 11 May 2020 14:58:55 +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: <20200511145855.35c6abfb@xps13> In-Reply-To: <0c704fea-f2a6-2cec-8741-d322acf6afd5@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> <20200511135926.3e5c622d@xps13> <0c704fea-f2a6-2cec-8741-d322acf6afd5@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=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 Hi Christophe, Christophe Kerello wrote on Mon, 11 May 2020 14:47:09 +0200: > Hi Miquel, > > On 5/11/20 1:59 PM, Miquel Raynal wrote: > > 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. > > > > OK, I will check the compatible string of the parent device using of_device_is_compatible API in v5. > In case of the parent is found, I will add it in the structure of the controller (dev_parent). > I will rely on this field only to get the common resources (the register base address and the clock) in the NFC node or in the EBI node. I had something slightly different in mind: what about setting a default value to this field as being the controller's device itself. This way, once it is set to either the parent device or the device itself, you can use it "blindly" in your devm_clk_get/regmap_init calls?