From patchwork Tue Jan 7 09:29:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khouloud Touil X-Patchwork-Id: 1218694 X-Patchwork-Delegate: bartekgola@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="W/WG8PUZ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47sRtK4Dsmz9sRK for ; Tue, 7 Jan 2020 20:30:01 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727177AbgAGJ37 (ORCPT ); Tue, 7 Jan 2020 04:29:59 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:52064 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727769AbgAGJ37 (ORCPT ); Tue, 7 Jan 2020 04:29:59 -0500 Received: by mail-wm1-f68.google.com with SMTP id d73so18132108wmd.1 for ; Tue, 07 Jan 2020 01:29:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=inWqr0b7IGQSzA+ufbRqSvKpmxVDxis6ow/O4l0fxAk=; b=W/WG8PUZUM68OBBcaXBzdR2NVBD3iseGIXCiRwoETyR4+BvVwpERmQ4rtBnWWqqyx5 zVQE/WBysgBWVKBvD4jAY9/PjebevuRpXfRaHLuO5XiGt6hgzvWIINl9SFJEX5mNVg4D WKrQw0KzbjtlRDQY+sAyHH7XNArE6CXZALOu002nHb4y7mmwTSxwDkikZWp1JSQqtfDJ xCi+F9KsZ0zxuLZPFRhB88BVqcNgWfGZi48JgNcR1yWdqMXUrlYYbbgoIzBbWuXzsHL+ ejsjyXTwFIAvlaFsvUihy5pISAcrObvoMve/hTIXoIy4SeZ3J65U5q0kowYRID1S9LYf TYnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=inWqr0b7IGQSzA+ufbRqSvKpmxVDxis6ow/O4l0fxAk=; b=nh4svqlXeqpnE7w6vSSckmhXkClYDo4TDXSgmpyQWVFmHp8QXKBQ0nrgttfp3iGcvl 6wxNkaGPNIvJNtMP7tiC5OWcW/OHsKlmHfckM0Rd882LnyG2GwJfTnXB0b1S8y2MMAKA R9voqxNXXqSRAEIJUtw4vHjrlt81IIh/6MKa9R5UT5x7t1kSPfLqSpeOBN7GPb9Qnosr 9eIvkb2TlcRnYYGqSUCheDLgMLt0Ydc42FaYEZrkWq2IopixVUqLL3K563M1c/k61ECj hHf4DeywzMBZ4/Cb0ASIixekETJ4vHK0T7yXr+fLtCC4ENg1rFfQjpQUdiOaU4ROQBwN zGig== X-Gm-Message-State: APjAAAWjUlqAwJgss+Ia9RdAhgAtYL9a9HVb0SpQJgXdll5n+5FOf8hw FEkblMIHA3O6clrjx53UZH+vJw== X-Google-Smtp-Source: APXvYqy/n9msDdwCaoPezrsNNkD3kx8fiX7h40X177RHp7BCGEirXcpdgjzhSj2kfRNPTNV+iPcwsA== X-Received: by 2002:a7b:cb86:: with SMTP id m6mr38782306wmi.51.1578389398067; Tue, 07 Jan 2020 01:29:58 -0800 (PST) Received: from localhost.localdomain (i16-les01-ntr-213-44-229-207.sfr.lns.abo.bbox.fr. [213.44.229.207]) by smtp.googlemail.com with ESMTPSA id x14sm25959969wmj.42.2020.01.07.01.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2020 01:29:57 -0800 (PST) From: Khouloud Touil To: bgolaszewski@baylibre.com, robh+dt@kernel.org, mark.rutland@arm.com, srinivas.kandagatla@linaro.org, baylibre-upstreaming@groups.io Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-i2c@vger.kernel.org, linus.walleij@linaro.org, Khouloud Touil Subject: [PATCH v4 2/5] nvmem: add support for the write-protect pin Date: Tue, 7 Jan 2020 10:29:19 +0100 Message-Id: <20200107092922.18408-3-ktouil@baylibre.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200107092922.18408-1-ktouil@baylibre.com> References: <20200107092922.18408-1-ktouil@baylibre.com> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The write-protect pin handling looks like a standard property that could benefit other users if available in the core nvmem framework. Instead of modifying all the memory drivers to check this pin, make the NVMEM subsystem check if the write-protect GPIO being passed through the nvmem_config or defined in the device tree and pull it low whenever writing to the memory. There was a suggestion for introducing the gpiodesc from pdata, but as pdata is already removed it could be replaced by adding it to nvmem_config. Reference: https://lists.96boards.org/pipermail/dev/2018-August/001056.html Signed-off-by: Khouloud Touil Reviewed-by: Linus Walleij Acked-by: Srinivas Kandagatla --- drivers/nvmem/core.c | 19 +++++++++++++++++-- drivers/nvmem/nvmem.h | 2 ++ include/linux/nvmem-provider.h | 3 +++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 9f1ee9c766ec..3e1c94c4eee8 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include "nvmem.h" @@ -54,8 +55,14 @@ static int nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset, static int nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset, void *val, size_t bytes) { - if (nvmem->reg_write) - return nvmem->reg_write(nvmem->priv, offset, val, bytes); + int ret; + + if (nvmem->reg_write) { + gpiod_set_value_cansleep(nvmem->wp_gpio, 0); + ret = nvmem->reg_write(nvmem->priv, offset, val, bytes); + gpiod_set_value_cansleep(nvmem->wp_gpio, 1); + return ret; + } return -EINVAL; } @@ -338,6 +345,14 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) kfree(nvmem); return ERR_PTR(rval); } + if (config->wp_gpio) + nvmem->wp_gpio = config->wp_gpio; + else + nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp", + GPIOD_OUT_HIGH); + if (IS_ERR(nvmem->wp_gpio)) + return PTR_ERR(nvmem->wp_gpio); + kref_init(&nvmem->refcnt); INIT_LIST_HEAD(&nvmem->cells); diff --git a/drivers/nvmem/nvmem.h b/drivers/nvmem/nvmem.h index eb8ed7121fa3..be0d66d75c8a 100644 --- a/drivers/nvmem/nvmem.h +++ b/drivers/nvmem/nvmem.h @@ -9,6 +9,7 @@ #include #include #include +#include struct nvmem_device { struct module *owner; @@ -26,6 +27,7 @@ struct nvmem_device { struct list_head cells; nvmem_reg_read_t reg_read; nvmem_reg_write_t reg_write; + struct gpio_desc *wp_gpio; void *priv; }; diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index fe051323be0a..6d6f8e5d24c9 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -11,6 +11,7 @@ #include #include +#include struct nvmem_device; struct nvmem_cell_info; @@ -45,6 +46,7 @@ enum nvmem_type { * @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 * * Note: A default "nvmem" name will be assigned to the device if * no name is specified in its configuration. In such case "" is @@ -58,6 +60,7 @@ struct nvmem_config { const char *name; int id; struct module *owner; + struct gpio_desc *wp_gpio; const struct nvmem_cell_info *cells; int ncells; enum nvmem_type type;