Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp673482pxb; Tue, 1 Feb 2022 08:08:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJwzM5EiusXXug/kxnba8byLE1rSErG6PLbfymi/Ao1PttbKoqE4PNrSee6omVWGSYZpqdg1 X-Received: by 2002:a17:907:3ea9:: with SMTP id hs41mr22698275ejc.727.1643731682862; Tue, 01 Feb 2022 08:08:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643731682; cv=none; d=google.com; s=arc-20160816; b=Pbtfxsf5/4YBXFfLDESmdlhSUgP99Pr43gFxA5fOBAXafqalulpj9b8B2SDKTpTStP yzucm9S0lywnRxHjqrAVXqyxfek6qrWEMGbEVI7A2RfuqPtDn3QgApTMQIuTf4nV7NlS qiNl7sme/y15XkNuVl95DpcazcrfKws8dnIgqYUBkRPiqDUdgEvFwPEv2x8LOv1+sqcz jGWH8Sp4XWwdIpJmF2iHEigdDr0G+vfiWt6MckjXAVbiPMBOAbSftn4sIugUoC3aFGof nLs85cLS4m2AoKleV69WacLWAF60G8qhFwiTzAjZQDG74TL6IFVjF1DZwLQR7MJK7VXa 9J6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wYNNkm/t/7b5hr9n2LuviOHiASEdotR00BRcy3HUpZQ=; b=fiRVPzG+vbKF7ntePp6D3ZE8XxU717so9Jw2sBOEqblFJqqWMHPtgJ5hyFoAAsDhh9 EfnIXT098IJYSNht4tUzpqM7nLsuGGkXtJMEXIc0My/6wyXMrLY5J7X0RF8Pn+1esKTr JmA9psotCsDB3xnxfcr25Emjdwe6z/RtKsPEoA7ggeIeAdh8redF9xpxGWZCi3+syceY rsoJffWhg9xmbgwunWKYcYngNUpIsBWHpSKSY2EHogJFRWU8OUBv1xCkZnNSNMSnuqPe Egrqt8tkXhS0ZVN3m0E4ES2QNLs1Mar6wFLY+4xI87Y2NKFa4dAGLRogB/Wuw1oKlN8c Wgqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=3rT+XieK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w13si8747237edx.605.2022.02.01.08.07.37; Tue, 01 Feb 2022 08:08:02 -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=@foss.st.com header.s=selector1 header.b=3rT+XieK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357988AbiAaKBI (ORCPT + 99 others); Mon, 31 Jan 2022 05:01:08 -0500 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:46682 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1358119AbiAaJ7y (ORCPT ); Mon, 31 Jan 2022 04:59:54 -0500 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 20V8vMwx027165; Mon, 31 Jan 2022 10:59:21 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=selector1; bh=wYNNkm/t/7b5hr9n2LuviOHiASEdotR00BRcy3HUpZQ=; b=3rT+XieKN+pTmcrsxGnXKfJjCeZUpnlUDZYZwp/onZN3ANvRAAwCmnAyKlb8pRB+fVu8 guiJWDTijMaBg+hVYELiV/kP4z1laFdxOvxZJFHq4fVQJZ1y+7dwFiIe4QgvtLOU7XB2 t4yzVRH1nV9nV1JkNACIHrdms9EEezqas80SF02+3myigNanMh4Lct0s2fhlsiihUKff DyLcum3NQyvlpoxOVI7cYX811m6Dw6IuaCGlwV0Ex5b9TPXO61/Bxwz23rboG08fzWtb 3kM0SkCQjUi0D14HaSdRiiwe4jv38OylcEhZBxrOXcRo7qNOSkW9iHYSZA0mJ11CLS/M tg== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3dwwf3uktj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 31 Jan 2022 10:59:21 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 3DF7110002A; Mon, 31 Jan 2022 10:59:21 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 3303B210F85; Mon, 31 Jan 2022 10:59:21 +0100 (CET) Received: from localhost (10.75.127.50) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Mon, 31 Jan 2022 10:59:20 +0100 From: Christophe Kerello To: , , , , CC: , , , , , Christophe Kerello Subject: [PATCH v2 3/4] nvmem: core: Fix a conflict between MTD and NVMEM on wp-gpios property Date: Mon, 31 Jan 2022 10:57:54 +0100 Message-ID: <20220131095755.8981-4-christophe.kerello@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220131095755.8981-1-christophe.kerello@foss.st.com> References: <20220131095755.8981-1-christophe.kerello@foss.st.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG2NODE1.st.com (10.75.127.4) To SFHDAG2NODE2.st.com (10.75.127.5) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-31_02,2022-01-28_01,2021-12-02_01 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 skip_wp_gpio. In case skip_wp_gpio is set, the GPIO resource will be managed by the provider. Signed-off-by: Christophe Kerello --- Changes in v2: - rework the proposal done to fix a conflict between MTD and NVMEM on wp-gpios property. 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..cb40dca6a51d 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->skip_wp_gpio) 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..4b480023c265 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 + * @skip_wp_gpio: 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 skip_wp_gpio; struct device_node *of_node; bool no_of_node; nvmem_reg_read_t reg_read; -- 2.25.1