From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96B20C77B7F for ; Sat, 13 May 2023 13:27:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237237AbjEMN1l (ORCPT ); Sat, 13 May 2023 09:27:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229910AbjEMN1i (ORCPT ); Sat, 13 May 2023 09:27:38 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B5A519B4 for ; Sat, 13 May 2023 06:27:32 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 0405E5FD1A; Sat, 13 May 2023 16:27:29 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1683984449; bh=6s5t1h5bNWHI3YCWI4siWjtZBnr+VzeI83m2ZwBqCms=; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; b=kUELyJhDMFZkdvk948EyayBbGbwsD50k5oy5acdZqr84v8Q8HXQQ9kpWG8cRcvCUb BV09ulczuwqkhTnpTR9aGShyjPcQh+Pvip6bHcOMifsbramB4xu0OUHPLnnpuP/2bY noJlZ72GgUTtltqRnGMxZ1Ui6/WxvmrJPqwSk3hiKYu5hOuttUG4EtdEKt3ZbXLmqx ljhH06Id8+Lnih60cAGscwvVDeGXIap20c5E6g1GdvCuDvzXZ4o4TZFWQse51/pn+E D8y8V+KQtW4/yFVydHTl4OvXYb1wI94fhlwdXxa6tyrNizmiZ5rxJbQ/bYfporS46g RMr8JJuBprUBA== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 13 May 2023 16:27:26 +0300 (MSK) Message-ID: <59d2c9d1-dc68-2427-5ff4-ca22bc51d5b3@sberdevices.ru> Date: Sat, 13 May 2023 16:22:41 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [PATCH v3 6/6] mtd: rawnand: meson: rename node for chip select Content-Language: en-US To: Miquel Raynal CC: Martin Blumenstingl , Liang Yang , Richard Weinberger , Vignesh Raghavendra , Neil Armstrong , Kevin Hilman , Jerome Brunet , Jianxin Pan , Yixun Lan , , , , , , , Michael Walle , =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= References: <20230510110835.26115-1-AVKrasnov@sberdevices.ru> <20230510110835.26115-7-AVKrasnov@sberdevices.ru> <20230510225359.061c2df6@xps-13> <6918ed54-3929-4832-1e93-6eb55b75c82b@sberdevices.ru> <20230511111204.0b0b3d70@xps-13> <4561f558-1d34-a7a9-2a05-f6453b0ed9a9@sberdevices.ru> <20230511141114.04cbd9f1@xps-13> <0b0bb315-8e5c-fb30-7786-34824b8d385d@sberdevices.ru> <20230512164918.59f8965f@xps-13> From: Arseniy Krasnov In-Reply-To: <20230512164918.59f8965f@xps-13> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH01.sberdevices.ru (172.16.1.4) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/05/13 07:34:00 #21275929 X-KSMG-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12.05.2023 17:49, Miquel Raynal wrote: > Hi Arseniy, > > I'm adding Rafał & Michael: any idea what could be wrong? The behavior > below does not look expected at all, but I thought we (= Rafał, mainly) > already sorted this out? > Hi Miquel, thanks for help! just to clarify an expected behaviour: if i have the following layout in the device tree mtd_nand: nfc@7800 { compatible = "amlogic,meson-axg-nfc"; ... nand@0 { reg = <0>; }; } node used by 'nvmem_add_cells_from_of()' must be NULL? or 'nand@0'? I guess, that in above dts I have node 'nfc@7800' in use, because 'mtd_otp_nvmem_register()' uses the following device before passing 'config' to 'nvmem_register()': /* OTP nvmem will be registered on the physical device */ config.dev = mtd->dev.parent; 'mtd->dev.parent' is 'nfc@7800'. May be 'mtd_otp_nvmem_register()' must initialize 'no_of_node' field of 'config' like in 'mtd_nvmem_add()' ? This field is documented as: * @no_of_node: Device should not use the parent's of_node even if it's !NULL. In this case node passed to 'nvmem_add_cells_from_of()' will be NULL. Thanks, Arseniy >>>>>>>>> On Wed, May 10, 2023 at 1:13 PM Arseniy Krasnov >>>>>>>>> wrote: >>>>>>>>>> >>>>>>>>>> This renames node with values for chip select from "reg" to "cs". It is >>>>>>>>>> needed because when OTP access is enabled on the attached storage, MTD >>>>>>>>>> subsystem registers this storage in the NVMEM subsystem. NVMEM in turn >>>>>>>>>> tries to use "reg" node in its own manner, supposes that it has another >>>>>>>>>> layout. All of this leads to device initialization failure. >>>>>>>>> In general: if we change the device-tree interface (in this case: >>>>>>>>> replacing a "reg" with a "cs" property) the dt-bindings have to be >>>>>>>>> updated as well. >>>>>>>> >>>>>>>> True, and I would add, bindings should not be broken. >>>>>>> >>>>>>> I see, that's true. That is bad way to change bindings. >>>>>>> >>>>>>>> >>>>>>>>> Documentation/devicetree/bindings/mtd/nand-controller.yaml and >>>>>>>>> Documentation/devicetree/bindings/mtd/amlogic,meson-nand.yaml show >>>>>>>>> that the chip select of a NAND chip is specified with a "reg" >>>>>>>>> property. >>>>>>>> >>>>>>>> All NAND controller binding expect the chip-select to be in the >>>>>>>> 'reg' property, very much like a spi device would use reg to store the >>>>>>>> cs as well: the reg property tells you how you address the device. >>>>>>>> >>>>>>>> I also fully agree with Martin's comments below. Changing reg is likely >>>>>>>> a wrong approach :) >>>>>>>> >>>>>>>>> Also the code has to be backwards compatible with old .dtbs. >>>>>>>>> >>>>>>>>>> Example: >>>>>>>>>> >>>>>>>>>> [...] nvmem mtd0-user-otp: nvmem: invalid reg on /soc/bus@ffe00000/... >>>>>>>>>> [...] mtd mtd0: Failed to register OTP NVMEM device >>>>>>>>>> [...] meson-nand ffe07800.nfc: failed to register MTD device: -22 >>>>>>>>>> [...] meson-nand ffe07800.nfc: failed to init NAND chips >>>>>>>>>> [...] meson-nand: probe of ffe07800.nfc failed with error -22 >>>>>>>>> This is odd - can you please share your definition of the &nfc node? >>>>>>> >>>>>>> Sure, here it is: >>>>>>> >>>>>>> mtd_nand: nfc@7800 { >>>>>>> compatible = "amlogic,meson-axg-nfc"; >>>>>>> ... >>>>>>> nand@0 { >>>>>>> reg = <0>; >>>>>>> }; >>>>>>> } >>>>>>> >>>>>>> I checked, that 'nand_set_flash_node()' is called with 'nand@0' and i suppose >>>>>>> that it is correct (as You mentioned below). But, 'nvmem_add_cells_from_of()' is called >>>>>>> with parent: 'nfc@7800', then it iterates over its childs, e.g. 'nand@0' and thus i get such >>>>>>> situation. I guess, that 'nvmem_add_cells_from_of()' must be called with 'nand@0' ? >>>>>> >>>>>> We recently had issues with nvmem parsing, but I believe a mainline >>>>>> kernel should now be perfectly working on this regard. What version of >>>>>> the Linux kernel are you using? >>>>> >>>>> My current version is: >>>>> >>>>> VERSION = 6 >>>>> PATCHLEVEL = 2 >>>>> SUBLEVEL = 0 >>>>> EXTRAVERSION = -rc8 >>>>> >>>>> Fix was in drivers/nvmem/* ? >>>>> >>>>> Thanks, Arseniy >>>> >>>> Upd: I resolved problem in the following way: >>>> >>>> nand@0 { >>>> reg = <0>;//chip select >>>> >>> partitions { >>> compatible = ... >>> >>>> otp@0 { >>>> #address-cells = <2>; >>>> #size-cells = <0>; >>> >>> #address/size-cells is not needed here >>> >>>> compatible = "user-otp"; >>>> reg = ; >>>> }; >>>> otp@1 { >>>> #address-cells = <2>; >>>> #size-cells = <0>; >>> >>> Ditto >>> >>>> compatible = "factory-otp"; >>>> reg = ; >>>> }; >>> >>> }; >>> >>>> }; >>>> >>>> Now nvmem subsystem parses 'otp@0' and 'otp@1' and error is gone. 'compatible' values are >>>> the same as in drivers/mtd/mtdcore.c:mtd_otp_nvmem_add(). 'reg' in 'nand@0' is used as >>>> chip select as supposed. >>> >>> I don't fully get it. The parsing on the nvmem side should not fail if >>> there is no subpartition/otp-region defined. Can you confirm an empty >>> NAND device node works? Because your last e-mail suggested the opposite. >> >> Ok, so i'll describe what happens in my case. Let's NAND node be like this (IIUC this is >> considered as empty NAND device): >> >> mtd_nand: nfc@7800 { >> compatible = "amlogic,meson-axg-nfc"; >> ... >> nand@0 { >> reg = <0>; >> }; >> } >> >> I see, that >> >> 1) 'mtd_otp_nvmem_add()' calls 'mtd_otp_nvmem_register()' twice for two types of >> OTP memory "user-otp" and "factory-otp". Let's take a look only on "user-otp". >> 2) 'mtd_otp_nvmem_register()' tries to lookup for node in 'nand@0' which is compatible with >> "user-otp" and then passes found (or not found, e.g. NULL) node to 'nvmem_register()'. >> 3) 'nvmem_register()' uses this node iterating over its childs and searching value "reg" in >> each child. If "user-otp" node is not found in 2), 'nvmem_register()' uses node 'nfc@7800' >> also looking for "reg" value in each of its child. In this case it found "reg" in 'nand@0' >> and fails. >> >> Now, if i add "compatible = "user-otp";" to 'nand@0', in step 2) search will be successful, >> and "reg" value will be used from this new node (or we remove "reg" from it - nothing happens >> as You wrote). So, problem is that nvmem tries to parse node with invalid "reg" value. >> >> Also I see, that 'nvmem_register()' is called earlier in 'mtd_nvmem_add()', but with no effect. >> I think, that it is not related with enabled OTP feature. >> >> Thanks, Arseniy