From patchwork Sun Jun 23 03:15:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 807994 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2ECDFD268 for ; Sun, 23 Jun 2024 03:18:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=85.214.62.61 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719112719; cv=none; b=ixiCuRtBtY2lsx/gVAHaZWSVKypEhqA7WPaslGUvP26KTdZSFVs9RCLRODIbcyOpG4oEJR+VzVHmC8/r5A6P86gNq7xzmNv2KURd6V7PC0+bRFhZQMOkx+3yoiJOSlpoPz7QkPh41rBInrSSBFe7dRVAJkNyceioSxL5UJdYswc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719112719; c=relaxed/simple; bh=gADv2+Pyee86Nh3L0QY5TGM8W96BrhLANeNaDNj6ULY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=dMzMZ0L/JzZ8yFLiEoWHPPKiqOCF8uLjwfPdE6hYTueiXHdwQQ7g4rDloT5gmqV0pczL4zgZ4Ya2MtE7DuNFe/a57u+Gx61VF17vPQUsy99bJSlwVO41l3GSCGQCW55lulDrT1QSd7cEnq/10IFLCv28hOfvKwUqQDUpX3D0jxc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de; spf=pass smtp.mailfrom=denx.de; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b=g50AiUx2; arc=none smtp.client-ip=85.214.62.61 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=denx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b="g50AiUx2" Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 88E1187572; Sun, 23 Jun 2024 05:18:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1719112709; bh=NAb9lbBPTrKgT+x8KnblGvszN5C3f+goUvG/SFIzZjk=; h=From:To:Cc:Subject:Date:From; b=g50AiUx2kfjf7FjgnNqWSER1Joa2WUZx72KbfiRuxnFMzVU/AuCewF8fKFkOVQ3Bo TcOEoIOSvV1tIX3O8c6LUfvfmTOWzNOojecWCuhiPby6ooMB9b9eB4X6Az06P/1uIT 6TFyZGGwCf5GgcTIGvmd5WykOJRgfG15xycoWf4Wprknx6sTE2Gai50MtMjOCfl4cM /7jy6BubjOiHQ46hRGPJJNRveUOGQDdy46XnHI4LLYFzzgXPWoVZahSj/gSAnjRJgI kqQheA6gLnm5dilDjkQoI8U3gfHaEzx+dXBpjY3bAg56aelJNeXJFWTeqbyIXd4uS9 Pg2QybEosokBQ== From: Marek Vasut To: linux-i2c@vger.kernel.org Cc: Marek Vasut , Alexandre Belloni , Arnd Bergmann , Bartosz Golaszewski , Greg Kroah-Hartman , Srinivas Kandagatla Subject: [PATCH v2 1/4] nvmem: Replace spaces with tab in documentation Date: Sun, 23 Jun 2024 05:15:44 +0200 Message-ID: <20240623031752.353818-1-marex@denx.de> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Replace two spaces with tab in the sysfs attribute documentation. No functional change. Signed-off-by: Marek Vasut --- Cc: Alexandre Belloni Cc: Arnd Bergmann Cc: Bartosz Golaszewski Cc: Greg Kroah-Hartman Cc: Srinivas Kandagatla Cc: linux-i2c@vger.kernel.org --- V2: - New patch --- Documentation/ABI/stable/sysfs-bus-nvmem | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/ABI/stable/sysfs-bus-nvmem b/Documentation/ABI/stable/sysfs-bus-nvmem index c399323f37de3..854bd11d72ac4 100644 --- a/Documentation/ABI/stable/sysfs-bus-nvmem +++ b/Documentation/ABI/stable/sysfs-bus-nvmem @@ -1,6 +1,6 @@ What: /sys/bus/nvmem/devices/.../nvmem Date: July 2015 -KernelVersion: 4.2 +KernelVersion: 4.2 Contact: Srinivas Kandagatla Description: This file allows user to read/write the raw NVMEM contents. From patchwork Sun Jun 23 03:15:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 806916 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2ED16D271 for ; Sun, 23 Jun 2024 03:18:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=85.214.62.61 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719112721; cv=none; b=DoosyljBxQSTMgsgs5dlCjdddLdAJYm93dCSoUhgqPWE8C8Kx/7cH5f/KYrpqXg7Aht6OB4OUnpu6ZP/NYD+HgjqJHEy5+EhYugh9jsshTHmqOcg8iRo1H0ufcljrcLLzvU78R7InaOxPv2xaX6KBC0qlSm7wMcOqrE5/8JovTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719112721; c=relaxed/simple; bh=EgbOmYAXN5AwE+F/UelOlXARvaj+AKD0/h1ATQNNP7A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mMsMQHBdxCF/wYyQ/nzFcsvqCjfo6lhVTpLWmHb7sRXLB1Hoe+E6AEzAZhD3sYxMIkDKxRc2Zb4fkW8fI5s1Y3BLm6pyDONtUNfzhgZ0ue5tS8H3sF6eKeoMON9GBSsqnpjmdwi658PyRDWGI01JtUnjUScZ9W8gfygk3opIxrY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de; spf=pass smtp.mailfrom=denx.de; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b=XM970SZ3; arc=none smtp.client-ip=85.214.62.61 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=denx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b="XM970SZ3" Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 31BCB88229; Sun, 23 Jun 2024 05:18:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1719112709; bh=8wHGO6ZG4/qqez27QNxMNzpGlI1J7OXQC7Ffkuyibso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XM970SZ3vhG+VBRSCucEVweTEr7Pweyvcc7PYOd6l4Lq7kr0W/Gc17pAlcel/eaPA tcmBH0TvU1pUIPTa6d/uNL6DM89LseENL6ShouuxNMd98EF1u0WiVP03l1gZG0iwBr P6IvgELZ7rB06z460zr7yv4area6NPhv/DeNOMKoZc0jMwgjsscr+sXQGxSSKAdjMG Nf14hDSCMPM0do1C2yHkn4/kzdfs7D7QKPiiyABf4avnKHL5MH6LRDhtMJ/PjnT4Ol r/vquKiEc2Eq8RFxSIwUwTYYOVIHa7/pDODNkpvu2NvXjA52msgY9mcDPQrSI55VRA 5WQph9TPvtPAg== From: Marek Vasut To: linux-i2c@vger.kernel.org Cc: Marek Vasut , Alexandre Belloni , Arnd Bergmann , Bartosz Golaszewski , Greg Kroah-Hartman , Srinivas Kandagatla Subject: [PATCH v2 2/4] nvmem: Document type attribute Date: Sun, 23 Jun 2024 05:15:45 +0200 Message-ID: <20240623031752.353818-2-marex@denx.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240623031752.353818-1-marex@denx.de> References: <20240623031752.353818-1-marex@denx.de> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Document a type attribute used by userspace to discern different types of NVMEM devices. The implementation is already present, the ABI document is missing, add it. Signed-off-by: Marek Vasut Reviewed-by: Alexandre Belloni --- Cc: Alexandre Belloni Cc: Arnd Bergmann Cc: Bartosz Golaszewski Cc: Greg Kroah-Hartman Cc: Srinivas Kandagatla Cc: linux-i2c@vger.kernel.org --- V2: - New patch --- Documentation/ABI/stable/sysfs-bus-nvmem | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/ABI/stable/sysfs-bus-nvmem b/Documentation/ABI/stable/sysfs-bus-nvmem index 854bd11d72ac4..0e3a8492a1082 100644 --- a/Documentation/ABI/stable/sysfs-bus-nvmem +++ b/Documentation/ABI/stable/sysfs-bus-nvmem @@ -20,3 +20,14 @@ Description: ... * 0001000 + +What: /sys/bus/nvmem/devices/.../type +Date: November 2018 +KernelVersion: 5.0 +Contact: Alexandre Belloni +Description: + This read-only attribute allows user to read the NVMEM + device type. Supported types are "Unknown", "EEPROM", + "OTP", "Battery backed", "FRAM". + Note: This file is only present if CONFIG_NVMEM_SYSFS + is enabled From patchwork Sun Jun 23 03:15:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 806917 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27926D518 for ; Sun, 23 Jun 2024 03:18:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=85.214.62.61 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719112719; cv=none; b=Fiy13nbR5sGAQvtOiKt6DuS6nlMa0zkVtwTDChx7t0sI6Lldfznaqv5Ksw3aaFouWdf+KQnrLi7ntXtkLlg8K/Fn7o4PYIofX3zl0mp/uDyyTuEVOaoQZ4NxPmmhPw3lT9ZNIj1ecAMvQ3WaIkeGS5lpGRf/yTuO4bmvvQDzbhc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719112719; c=relaxed/simple; bh=tSlD8kIR9c+Gypj5k24Lz8NnNyHGq7biHSldyLbJ9bI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qbjkv+e2vkTOy9si6ozYZrtwE97jD7YWXeBaGqIx/rosriWT/GO0cWLbBhPvOSe31oCeJJ2XU7F+K6P+70RRr5JLVL/PLOsrdgk87hz7ory/H/PP3O7r3ileUJDbmCcctE0Bn7N1zWcgT0uu0tbJb+pnOOpNFaO8E2Q9Hrc9M4M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de; spf=pass smtp.mailfrom=denx.de; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b=NNjB4JII; arc=none smtp.client-ip=85.214.62.61 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=denx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b="NNjB4JII" Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 9C56188231; Sun, 23 Jun 2024 05:18:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1719112709; bh=Z/1i1s1v006Ysash4YexMENshfCgULNMSzbzpHn3xpA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NNjB4JIIS+HJww4FAzXElmVghBsTYhRaMY8bd4I/J48xelbRQ9GrSmjIcJeuErePi kuvdgpwPD8qRyKoRhgko/9Yv+ThNJ6DbU5RqmGc29vqdxpOzAt7FL+SgcbQY4IkJgb XGFzFGEB7JLPRKL9zCLXjBtMtaoM4LwWnudzwT4KTS7LXB6g3G5+W7qvqppZhoeUrQ F4DxVv8VdNe045sy+PCmDW2Wmc1+Zz6/QhG54wFTLZfeK+/gotKw/Gyg8GVPYqRQoo Y9h128fgwz83e5ge8OKuFcyI9jhwtE9nt4k8hUcEbXxNBlN3HbH8AOS5/0WZkGylnH PrvoJB8ClSsow== From: Marek Vasut To: linux-i2c@vger.kernel.org Cc: Marek Vasut , Alexandre Belloni , Arnd Bergmann , Bartosz Golaszewski , Greg Kroah-Hartman , Srinivas Kandagatla Subject: [PATCH v2 3/4] nvmem: Use sysfs_emit() for type attribute Date: Sun, 23 Jun 2024 05:15:46 +0200 Message-ID: <20240623031752.353818-3-marex@denx.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240623031752.353818-1-marex@denx.de> References: <20240623031752.353818-1-marex@denx.de> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Use sysfs_emit() instead of sprintf() to follow best practice per Documentation/filesystems/sysfs.rst " show() should only use sysfs_emit()... " Signed-off-by: Marek Vasut --- Cc: Alexandre Belloni Cc: Arnd Bergmann Cc: Bartosz Golaszewski Cc: Greg Kroah-Hartman Cc: Srinivas Kandagatla Cc: linux-i2c@vger.kernel.org --- V2: - New patch --- drivers/nvmem/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index e1ec3b7200d7b..b31abffcdfc00 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -179,7 +179,7 @@ static ssize_t type_show(struct device *dev, { struct nvmem_device *nvmem = to_nvmem_device(dev); - return sprintf(buf, "%s\n", nvmem_type_str[nvmem->type]); + return sysfs_emit(buf, "%s\n", nvmem_type_str[nvmem->type]); } static DEVICE_ATTR_RO(type); From patchwork Sun Jun 23 03:15:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 807993 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2555ED28D for ; Sun, 23 Jun 2024 03:18:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=85.214.62.61 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719112720; cv=none; b=uG26MXYgkkRgOwaWbQXD3BPbLy4tcAYsjSK8TMLTfUjul3cTwdPmLyr2gT54eJQAwQ+BGqr49ud+Ah/ZoD6H/A0Vgaq7bZ/imbpKCcx6pE+6T46xSMLpyBDW00YZXt2yDO2zHP5xzenQLDzr+4RXVjIuICML0r1jnJqk8h+d3RQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719112720; c=relaxed/simple; bh=B2c2CsHDD9NyewOFfogYZbPU3T0EvUVf5iMLy9lRl8o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Tub7y6+CnQIn6SYaV4E58PjhbvEEfVaVsZry8gRSNAsH3mvVs7Hxp4xfV+wxxcPpBNeMBXBPJlZhQaX4i4LsqMXUKNhmWSZ9OtDPsPdH+dvioMj1EgnBlcUuiChjv+raXq9YPv9ZWyH96Ed/rqCDSviuQr9sENRHG6sr918vYqc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de; spf=pass smtp.mailfrom=denx.de; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b=G1511dks; arc=none smtp.client-ip=85.214.62.61 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=denx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=denx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.b="G1511dks" Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 138C288239; Sun, 23 Jun 2024 05:18:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1719112710; bh=MzT/5dZOOgyDG5iz7+8iu5vEqWZpSgyPcjU/F6d2NqQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G1511dks30MnC/gsz0anfx+CXDr0HXraBOf+sPiSg9c/4/Zwv8Gm00J8G9O7XLeam 1ZtbGMiitzj8/IzHGoK7H14DbxYcS3YxcMWvCL5/wbVvEM6NhMgoLIk/0v9+TxPeS/ myMDk1nf8vL4LNYPq2GbppSUrAwPLTCC7Gf9mN2uG5m90c/esVlkzacZpKopv+pnLF euuDq//j8FEnUu3ZWoK+gnq8igNPXdEo2YECqc4rvsTKy0IWRlPq/HOZ016WYkCxFd Gx/NlL7StcPI1A5Ze4UkE7UyHu9CUZ55l8OIxH5J4Kvf+Hgbt6iWXI19+j5XDk2MS0 39vL+snswh19w== From: Marek Vasut To: linux-i2c@vger.kernel.org Cc: Marek Vasut , Alexandre Belloni , Arnd Bergmann , Bartosz Golaszewski , Greg Kroah-Hartman , Srinivas Kandagatla Subject: [PATCH v2 4/4] nvmem: core: Implement force_ro sysfs attribute Date: Sun, 23 Jun 2024 05:15:47 +0200 Message-ID: <20240623031752.353818-4-marex@denx.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240623031752.353818-1-marex@denx.de> References: <20240623031752.353818-1-marex@denx.de> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Implement "force_ro" sysfs attribute to allow users to set read-write devices as read-only and back to read-write from userspace. The choice of the name is based on MMC core 'force_ro' attribute. This solves a situation where an AT24 I2C EEPROM with GPIO based nWP signal may have to be occasionally updated. Such I2C EEPROM device is usually set as read-only during most of the regular system operation, but in case it has to be updated in a controlled manner, it could be unlocked using this new "force_ro" sysfs attribute and then re-locked again. The "read-only" DT property and config->read_only configuration is respected and is used to set default state of the device, read-only or read-write, for devices which do implement .reg_write function. For devices which do not implement .reg_write function, the device is unconditionally read-only and the "force_ro" attribute is not visible. Signed-off-by: Marek Vasut --- Cc: Alexandre Belloni Cc: Arnd Bergmann Cc: Bartosz Golaszewski Cc: Greg Kroah-Hartman Cc: Srinivas Kandagatla Cc: linux-i2c@vger.kernel.org --- V2: - Document the force_ro attribute - Use sysfs_emit() --- Documentation/ABI/stable/sysfs-bus-nvmem | 13 +++++++ drivers/nvmem/core.c | 44 ++++++++++++++++++++++++ drivers/nvmem/internals.h | 1 + 3 files changed, 58 insertions(+) diff --git a/Documentation/ABI/stable/sysfs-bus-nvmem b/Documentation/ABI/stable/sysfs-bus-nvmem index 0e3a8492a1082..c713c4e6cecb1 100644 --- a/Documentation/ABI/stable/sysfs-bus-nvmem +++ b/Documentation/ABI/stable/sysfs-bus-nvmem @@ -1,3 +1,16 @@ +What: /sys/bus/nvmem/devices/.../force_ro +Date: June 2024 +KernelVersion: 6.11 +Contact: Marek Vasut +Description: + This read/write attribute allows users to set read-write + devices as read-only and back to read-write from userspace. + This can be used to unlock and relock write-protection of + devices which are generally locked, except during sporadic + programming operation. + Note: This file is only present if CONFIG_NVMEM_SYSFS + is enabled + What: /sys/bus/nvmem/devices/.../nvmem Date: July 2015 KernelVersion: 4.2 diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index b31abffcdfc00..2321fb7da1e92 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -184,7 +184,30 @@ static ssize_t type_show(struct device *dev, static DEVICE_ATTR_RO(type); +static ssize_t force_ro_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct nvmem_device *nvmem = to_nvmem_device(dev); + + return sysfs_emit(buf, "%d\n", nvmem->read_only); +} + +static ssize_t force_ro_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct nvmem_device *nvmem = to_nvmem_device(dev); + int ret = kstrtobool(buf, &nvmem->read_only); + + if (ret < 0) + return ret; + + return count; +} + +static DEVICE_ATTR_RW(force_ro); + static struct attribute *nvmem_attrs[] = { + &dev_attr_force_ro.attr, &dev_attr_type.attr, NULL, }; @@ -299,6 +322,25 @@ static umode_t nvmem_bin_attr_is_visible(struct kobject *kobj, return nvmem_bin_attr_get_umode(nvmem); } +static umode_t nvmem_attr_is_visible(struct kobject *kobj, + struct attribute *attr, int i) +{ + struct device *dev = kobj_to_dev(kobj); + struct nvmem_device *nvmem = to_nvmem_device(dev); + + /* + * If the device has no .reg_write operation, do not allow + * configuration as read-write. + * If the device is set as read-only by configuration, it + * can be forced into read-write mode using the 'force_ro' + * attribute. + */ + if (attr == &dev_attr_force_ro.attr && !nvmem->reg_write) + return 0; /* Attribute not visible */ + + return attr->mode; +} + static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry, const char *id, int index); @@ -355,6 +397,7 @@ static const struct attribute_group nvmem_bin_group = { .bin_attrs = nvmem_bin_attributes, .attrs = nvmem_attrs, .is_bin_visible = nvmem_bin_attr_is_visible, + .is_visible = nvmem_attr_is_visible, }; /* Cell attributes will be dynamically allocated */ @@ -971,6 +1014,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->read_only = device_property_present(config->dev, "read-only") || config->read_only || !nvmem->reg_write; + nvmem->default_read_only = nvmem->read_only; #ifdef CONFIG_NVMEM_SYSFS nvmem->dev.groups = nvmem_dev_groups; diff --git a/drivers/nvmem/internals.h b/drivers/nvmem/internals.h index 18fed57270e5e..0667937ebb86b 100644 --- a/drivers/nvmem/internals.h +++ b/drivers/nvmem/internals.h @@ -16,6 +16,7 @@ struct nvmem_device { int id; struct kref refcnt; size_t size; + bool default_read_only; bool read_only; bool root_only; int flags;