Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1476967ybl; Thu, 30 Jan 2020 00:08:09 -0800 (PST) X-Google-Smtp-Source: APXvYqyj9EwK9Lm2G+Dly/MAwnkjkZ7zzq6ZuNCFzp7/DL0vmu6yqD+31aqY94C/4qLiFeZPyG+L X-Received: by 2002:a05:6830:1184:: with SMTP id u4mr2526504otq.221.1580371689012; Thu, 30 Jan 2020 00:08:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580371689; cv=none; d=google.com; s=arc-20160816; b=MR1T9wNRMJbb/xgBtE4ggR8hpc8eIOxOxJKNhRBUDm5uh9QDxw989KBa4eCRVikzrt k09w5UeOoxGQFz7nf0u0oFovCuxJ9VE5kYeNtAD+T+Qp1qDJO3+zEWCB9mALA1GOuHjG 6XL2yJEG4oBz2y2fUQm9Dl5zvoISmDFN7128l5pD41mDB/JGQVCM6bnK+5iAjyRS/uVY /v0/gAPHZuLkhFrHQ8rWZQHgItfhr3XbAcO54zI2GkjOdU0N+3MGWvQKXWT+q+UqJMhr HdG8X9K4MzkI2YkuXnigiFv71jaHnB49GFgalnfue31hoKWhgxDTOOT0GuOnANq94G5F I/5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=UkWpdaCXq06Xmek5bdnoPkC6r56p3tRKd9oAQWdPjs8=; b=MT9RFp747YYQLgAgbM4eAI+UFsUeVuz5muXq2STslXIhpXRVnNJfNckfqWtGK9WNTg oQom6RQSZ8bMW3JpX+llOFsRrBTug2vaG9jtnfknhQW3k8gZ+CG4NANno+zVCLRvtx9s j7uTbrlHCfVg7r6HSypGx8jJDUhx5AlduwDLwJBlhyZKas60PXHtwffU3DpL1npPUrLN jpqcsK6P5GGWm1819MIjDXNJZmpeoukrygJL8/oPhxJtvcbbZfb4E8+PqSUaCoD0fDfo n4ksDEHj3Tqco3pwYb5ulnUDh37TCD04cL2s8BV31v/5v22yMLAdQlQ+vJVlsD7e7zbo Peqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h28si2863829otg.63.2020.01.30.00.07.57; Thu, 30 Jan 2020 00:08:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726952AbgA3IGp (ORCPT + 99 others); Thu, 30 Jan 2020 03:06:45 -0500 Received: from mail-oi1-f193.google.com ([209.85.167.193]:34024 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726397AbgA3IGo (ORCPT ); Thu, 30 Jan 2020 03:06:44 -0500 Received: by mail-oi1-f193.google.com with SMTP id l136so2684387oig.1; Thu, 30 Jan 2020 00:06:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UkWpdaCXq06Xmek5bdnoPkC6r56p3tRKd9oAQWdPjs8=; b=a9VCkKGJk5cdCRIUNce5DSptnNS3ZHtXNvIxAdeOwjWmHDFoVa6EN2mWRya52AbD2E ANb24Lk+j+HiGyZamAAxYNVjIKD61TuO0YQctYSYeh+iAipVcmT9Hrg39CRMSVvdIJ9j cNBKgl70Ulolt7uhv5SEq5XY88igTfnSTK7DOeXSs+GZJX2U+TK3u0BNDSEy+wQhHPJg hZiE7on83pBbcW592UvBN30JTd9Hi4xspORJTcVwpN7FcWwTcxQj282yOs/qHoODN4tF qYlKIGrSy3a+U85IlEFRk4ILt3QypqvecvDUwM7Bm76eTAurosKNOSdsRpBULCsc6yxd Extg== X-Gm-Message-State: APjAAAWL/sZzFX4FlzmX1gA3W8rXZAi7S8tYk8JDWqGdM5CG2UIeUKNp rzzTJN+i9Qbxl7EH2JwOtUnThNr3o/KZuf9Qek4= X-Received: by 2002:aca:1a06:: with SMTP id a6mr2018628oia.148.1580371603697; Thu, 30 Jan 2020 00:06:43 -0800 (PST) MIME-Version: 1.0 References: <20200107092922.18408-1-ktouil@baylibre.com> <20200107092922.18408-3-ktouil@baylibre.com> In-Reply-To: <20200107092922.18408-3-ktouil@baylibre.com> From: Geert Uytterhoeven Date: Thu, 30 Jan 2020 09:06:32 +0100 Message-ID: Subject: Re: [PATCH v4 2/5] nvmem: add support for the write-protect pin To: Khouloud Touil Cc: Bartosz Golaszewski , Rob Herring , Mark Rutland , Srinivas Kandagatla , baylibre-upstreaming@groups.io, Linux Kernel Mailing List , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , Linux I2C , Linus Walleij Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Khouloud, On Tue, Jan 7, 2020 at 10:30 AM Khouloud Touil wrote: > 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 Thanks for your patch! > --- 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); Shouldn't this GPIO be released in nvmem_release(), by calling gpiod_put()? Once that's implemented, I assume it will be auto-released on registration failure by the call to put_device()? > + if (IS_ERR(nvmem->wp_gpio)) > + return PTR_ERR(nvmem->wp_gpio); > + > > kref_init(&nvmem->refcnt); > INIT_LIST_HEAD(&nvmem->cells); Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds