From patchwork Sun Feb 20 15:14:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 544391 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 CD358C433EF for ; Sun, 20 Feb 2022 15:14:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238761AbiBTPPB (ORCPT ); Sun, 20 Feb 2022 10:15:01 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:50054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236044AbiBTPPA (ORCPT ); Sun, 20 Feb 2022 10:15:00 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56EB734B99 for ; Sun, 20 Feb 2022 07:14:38 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id az26-20020a05600c601a00b0037c078db59cso9650369wmb.4 for ; Sun, 20 Feb 2022 07:14:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wotUyCfca8/zG519U5/af89Me2Zg5VHivde488B+0/k=; b=kSIafJLo1kafBS98UX2zOOmFNXbp+gOAaMPuWX6B30F/0hHFxHx+b6mirLbuWdyPlH trcwVN8Z3gMmNmVFUzBPKfU5dWuJdZblIph9vV4xJPOoDTE3Y3wKmZGCsOk0wXEFe2P4 Ivsu9vqCY1/LvdAjI6vcRirHUMP0PQ01K0tWgyHBb6uGLoXg3FDPuLB39VT5jqgxnJ+r 98/iPJq51Ec4kmj3ifyljDIP8HfTjnIxL6sRv8MlHoIrxjC4KY5Z0JekZOMshFWmX+HM DP8iM/kIOakA5k/dor02gPX6VMvJXy9mk2/44Mpo96ctVORDKBZOtfRiV23f3/XXVA+a FqsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wotUyCfca8/zG519U5/af89Me2Zg5VHivde488B+0/k=; b=I+E8MjUGE3rzNBGMiP8Kv+0/sNrqkH40X1h+N+POBTNVChBAXvAse95yurJ3MzC3a8 8YQ36sYLE0fYi99zY/mNEOQpkfVHJt2o83PaHWedUi+ct8etS1ei50y7byXLznsnh4RJ a5/3t/hWH7+auAgOfo62BThW8aW3xBStV8aQn8LCq896XEt2zofdCA7+IYlUt2qeYV+W DEdJWQhqpHQYA4/wAet9Zt2Z9nG9ZilokLZGW3Ttb+JD5z1ZFgh2Y4uXrsRVNf3eQA5C DZTy7nCnp2X+8SDzdbccpghyMqakl5ncnna83C2ItSgomnG7SJC2DuF3eo0ufIsQt/lj aTGw== X-Gm-Message-State: AOAM5339DqSI0D08ZczZueePaZviDDZZIqHdpK+4OMit36xeEQ3joAgR /q0YmVpBq7J91WWZ0IXlOI8f7w== X-Google-Smtp-Source: ABdhPJz3XibEQYrsDmXIkvjitdL5RVZsTy7QaoAA+NYJQ1et19WIrkgJjyTtw9bxRpJxOJugiR6DvA== X-Received: by 2002:a7b:cb44:0:b0:37c:4e2d:3bb2 with SMTP id v4-20020a7bcb44000000b0037c4e2d3bb2mr17926595wmj.96.1645370076845; Sun, 20 Feb 2022 07:14:36 -0800 (PST) Received: from srini-hackbox.lan (cpc90716-aztw32-2-0-cust825.18-1.cable.virginm.net. [86.26.103.58]) by smtp.gmail.com with ESMTPSA id d6sm46703322wrs.85.2022.02.20.07.14.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Feb 2022 07:14:36 -0800 (PST) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Christophe Kerello , stable@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH 1/2] nvmem: core: Fix a conflict between MTD and NVMEM on wp-gpios property Date: Sun, 20 Feb 2022 15:14:31 +0000 Message-Id: <20220220151432.16605-2-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220220151432.16605-1-srinivas.kandagatla@linaro.org> References: <20220220151432.16605-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Christophe Kerello Wp-gpios property can be used on NVMEM nodes and the same property can be also used on MTD NAND nodes. In case of the wp-gpios property is defined at NAND level node, the GPIO management is done at NAND driver level. Write protect is disabled when the driver is probed or resumed and is enabled when the driver is released or suspended. When no partitions are defined in the NAND DT node, then the NAND DT node will be passed to NVMEM framework. If wp-gpios property is defined in this node, the GPIO resource is taken twice and the NAND controller driver fails to probe. It would be possible to set config->wp_gpio at MTD level before calling nvmem_register function but NVMEM framework will toggle this GPIO on each write when this GPIO should only be controlled at NAND level driver to ensure that the Write Protect has not been enabled. A way to fix this conflict is to add a new boolean flag in nvmem_config named ignore_wp. In case ignore_wp is set, the GPIO resource will be managed by the provider. Fixes: 2a127da461a9 ("nvmem: add support for the write-protect pin") Signed-off-by: Christophe Kerello Cc: stable@vger.kernel.org Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/core.c | 2 +- include/linux/nvmem-provider.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 23a38dcf0fc4..9fd1602b539d 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -771,7 +771,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) if (config->wp_gpio) nvmem->wp_gpio = config->wp_gpio; - else + else if (!config->ignore_wp) nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp", GPIOD_OUT_HIGH); if (IS_ERR(nvmem->wp_gpio)) { diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 98efb7b5660d..c9a3ac9efeaa 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -70,7 +70,8 @@ struct nvmem_keepout { * @word_size: Minimum read/write access granularity. * @stride: Minimum read/write access stride. * @priv: User context passed to read/write callbacks. - * @wp-gpio: Write protect pin + * @wp-gpio: Write protect pin + * @ignore_wp: Write Protect pin is managed by the provider. * * Note: A default "nvmem" name will be assigned to the device if * no name is specified in its configuration. In such case "" is @@ -92,6 +93,7 @@ struct nvmem_config { enum nvmem_type type; bool read_only; bool root_only; + bool ignore_wp; struct device_node *of_node; bool no_of_node; nvmem_reg_read_t reg_read; From patchwork Sun Feb 20 15:14:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 545032 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 EA2D1C433EF for ; Sun, 20 Feb 2022 15:14:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236044AbiBTPPB (ORCPT ); Sun, 20 Feb 2022 10:15:01 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:50066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237306AbiBTPPA (ORCPT ); Sun, 20 Feb 2022 10:15:00 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D8FC34B9A for ; Sun, 20 Feb 2022 07:14:39 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id m126-20020a1ca384000000b0037bb8e379feso11946590wme.5 for ; Sun, 20 Feb 2022 07:14:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xVb0fT1MGhcBbhhTafWv2pABvtbVRcxp+NDQSOBSHBI=; b=vrUhGbzWYj9b0IvENuCjMtgDybie2NNldRu/4ngPcWe+XGiXsvwrMpfRvcEvVaP3Ps UJCnKFn+dmvzzjzM9JLBxemtS6FsgvCHYfZREBuBx/aqs/U3r5TPjSNoTAKTbxtQiz0P rIqhmznel+D2xTurkav2gDEPUIjJD0xed1eMPjEWnQIAZKgUMcyViX3CnyU0sxGV1osN r7/KYIk39sxKnmLKQwUvUcGs7WAmYh3m3M+tVqfhecNSCZXoiOM93tTofC/Ot/xWh5k1 d1xruKTiXtp7GXbKUN/vn6p1xgYvC70uJ0zCsrWLsh4iLxMybafTJBLgxOZdU+XDmrY1 rGkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xVb0fT1MGhcBbhhTafWv2pABvtbVRcxp+NDQSOBSHBI=; b=pgkCxl8X33m+YZigLFzqx9acSla3cQwmXyXeIKvW34PyxF/+378ERQc4cn7I8g70Vi xu6UccQ2gLSRQfY+8uxzK45hmvCQciyuXLviDGASVemfElAlw/kNYZXgRGV17ifi13mm yK2AN/Y0g9Wp7MQOrkYjhEYRRAfbRVxZsZUFSBrLaZfWISqAMMYdTcwM4Vw5rxBReEIr l9cA977uCGwFzxvSQE3va7f1xJ52JrayY/Je+HG7V3HaEHPhAb3/TE21MZOcUJLLJN3M IR93pTManTkrRi4IvmrWawv9YzZK2Y58LkLbJPt+1agr5OKkYA6tb0lKKscwayaYVmpj XfWw== X-Gm-Message-State: AOAM530DlcRhIIRz6ywT7jYC8nturkrQr9fJSK06XmyV3gZAGbAC1Htp xcTraN6bZgfhyq3kfMd47Hv8NQ== X-Google-Smtp-Source: ABdhPJx0+otiYCAHPq6CQ9cJdD6jVkuoNt9NaRuoXNvS+K1VEh/IhESSbQ3rerpybwtaOmEeML66jw== X-Received: by 2002:a7b:c74e:0:b0:37b:9785:fbe5 with SMTP id w14-20020a7bc74e000000b0037b9785fbe5mr14373492wmk.54.1645370078205; Sun, 20 Feb 2022 07:14:38 -0800 (PST) Received: from srini-hackbox.lan (cpc90716-aztw32-2-0-cust825.18-1.cable.virginm.net. [86.26.103.58]) by smtp.gmail.com with ESMTPSA id d6sm46703322wrs.85.2022.02.20.07.14.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Feb 2022 07:14:37 -0800 (PST) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Christophe Kerello , stable@vger.kernel.org, Miquel Raynal , Srinivas Kandagatla Subject: [PATCH 2/2] mtd: core: Fix a conflict between MTD and NVMEM on wp-gpios property Date: Sun, 20 Feb 2022 15:14:32 +0000 Message-Id: <20220220151432.16605-3-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220220151432.16605-1-srinivas.kandagatla@linaro.org> References: <20220220151432.16605-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Christophe Kerello Wp-gpios property can be used on NVMEM nodes and the same property can be also used on MTD NAND nodes. In case of the wp-gpios property is defined at NAND level node, the GPIO management is done at NAND driver level. Write protect is disabled when the driver is probed or resumed and is enabled when the driver is released or suspended. When no partitions are defined in the NAND DT node, then the NAND DT node will be passed to NVMEM framework. If wp-gpios property is defined in this node, the GPIO resource is taken twice and the NAND controller driver fails to probe. A new Boolean flag named ignore_wp has been added in nvmem_config. In case ignore_wp is set, it means that the GPIO is handled by the provider. Lets set this flag in MTD layer to avoid the conflict on wp_gpios property. Fixes: 2a127da461a9 ("nvmem: add support for the write-protect pin") Signed-off-by: Christophe Kerello Cc: stable@vger.kernel.org Acked-by: Miquel Raynal Signed-off-by: Srinivas Kandagatla --- drivers/mtd/mtdcore.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 70f492dce158..eef87b28d6c8 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -546,6 +546,7 @@ static int mtd_nvmem_add(struct mtd_info *mtd) config.stride = 1; config.read_only = true; config.root_only = true; + config.ignore_wp = true; config.no_of_node = !of_device_is_compatible(node, "nvmem-cells"); config.priv = mtd; @@ -833,6 +834,7 @@ static struct nvmem_device *mtd_otp_nvmem_register(struct mtd_info *mtd, config.owner = THIS_MODULE; config.type = NVMEM_TYPE_OTP; config.root_only = true; + config.ignore_wp = true; config.reg_read = reg_read; config.size = size; config.of_node = np;