tools/zstd: update to 1.5.4
[openwrt/staging/aparcar.git] / target / linux / generic / backport-5.10 / 807-v5.17-0003-nvmem-core-Fix-a-conflict-between-MTD-and-NVMEM-on-w.patch
1 From f6c052afe6f802d87c74153b7a57c43b2e9faf07 Mon Sep 17 00:00:00 2001
2 From: Christophe Kerello <christophe.kerello@foss.st.com>
3 Date: Sun, 20 Feb 2022 15:14:31 +0000
4 Subject: [PATCH] nvmem: core: Fix a conflict between MTD and NVMEM on wp-gpios
5 property
6
7 Wp-gpios property can be used on NVMEM nodes and the same property can
8 be also used on MTD NAND nodes. In case of the wp-gpios property is
9 defined at NAND level node, the GPIO management is done at NAND driver
10 level. Write protect is disabled when the driver is probed or resumed
11 and is enabled when the driver is released or suspended.
12
13 When no partitions are defined in the NAND DT node, then the NAND DT node
14 will be passed to NVMEM framework. If wp-gpios property is defined in
15 this node, the GPIO resource is taken twice and the NAND controller
16 driver fails to probe.
17
18 It would be possible to set config->wp_gpio at MTD level before calling
19 nvmem_register function but NVMEM framework will toggle this GPIO on
20 each write when this GPIO should only be controlled at NAND level driver
21 to ensure that the Write Protect has not been enabled.
22
23 A way to fix this conflict is to add a new boolean flag in nvmem_config
24 named ignore_wp. In case ignore_wp is set, the GPIO resource will
25 be managed by the provider.
26
27 Fixes: 2a127da461a9 ("nvmem: add support for the write-protect pin")
28 Cc: stable@vger.kernel.org
29 Signed-off-by: Christophe Kerello <christophe.kerello@foss.st.com>
30 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
31 Link: https://lore.kernel.org/r/20220220151432.16605-2-srinivas.kandagatla@linaro.org
32 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
33 ---
34 drivers/nvmem/core.c | 2 +-
35 include/linux/nvmem-provider.h | 4 +++-
36 2 files changed, 4 insertions(+), 2 deletions(-)
37
38 --- a/drivers/nvmem/core.c
39 +++ b/drivers/nvmem/core.c
40 @@ -771,7 +771,7 @@ struct nvmem_device *nvmem_register(cons
41
42 if (config->wp_gpio)
43 nvmem->wp_gpio = config->wp_gpio;
44 - else
45 + else if (!config->ignore_wp)
46 nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp",
47 GPIOD_OUT_HIGH);
48 if (IS_ERR(nvmem->wp_gpio)) {
49 --- a/include/linux/nvmem-provider.h
50 +++ b/include/linux/nvmem-provider.h
51 @@ -70,7 +70,8 @@ struct nvmem_keepout {
52 * @word_size: Minimum read/write access granularity.
53 * @stride: Minimum read/write access stride.
54 * @priv: User context passed to read/write callbacks.
55 - * @wp-gpio: Write protect pin
56 + * @wp-gpio: Write protect pin
57 + * @ignore_wp: Write Protect pin is managed by the provider.
58 *
59 * Note: A default "nvmem<id>" name will be assigned to the device if
60 * no name is specified in its configuration. In such case "<id>" is
61 @@ -92,6 +93,7 @@ struct nvmem_config {
62 enum nvmem_type type;
63 bool read_only;
64 bool root_only;
65 + bool ignore_wp;
66 struct device_node *of_node;
67 bool no_of_node;
68 nvmem_reg_read_t reg_read;