From patchwork Thu Jun 27 23:37:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 808554 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 B6E281A2C37 for ; Thu, 27 Jun 2024 23:38:06 +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=1719531488; cv=none; b=I3hpIsDVa/f4Trtikq0GDLc79Bc7GRS9h9tJy3IUHbgVfyVmiwkYpcmyqpKaO7BhVKi82kBGWWJzBcD38uZiphmu52QnA8Hde6PLT2Cvys9jS+Ua5PhsFqTYjRY2G9mVYumP0B/RnhBvh5PMxwkpwWh8eSKenEWA+2ic5tQK1bw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719531488; c=relaxed/simple; bh=sPPwy3OgS712MWOelTtBU0u/uD3t5IE0yF+6lI+vVds=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=l8MjzSidZHGta8FGluR5P8VOGHoZnxO7LAjBn8HVGbCXXvS7Wb8Z6Zy3wR/dhPcivlAQ7nPnY4MErsDj3PKXelzRYiL4F+uQ/qBizMB4e6fcW6Toncqy668oKknqO3YKdavYeImrdo7FLR+N4jom1Mcl2FiiJYGSVtZWHtZs6Xg= 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=HMtzoUpa; 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="HMtzoUpa" 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 6648187E13; Fri, 28 Jun 2024 01:38:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1719531484; bh=Jr1/Dj09BEovlWD7SzHWkk8M/JwtroHdbzcKrK0kBCc=; h=From:To:Cc:Subject:Date:From; b=HMtzoUpa4d1ev9hD7O2bYR+LIGTDwzRLujdG3mkJWrVZnQ0lhOPfEqukKHwdlObju mFBuZ2f5o65axeBk1HKbLrjf6DLayvltduKxO0AfDRbvFB8TICYe9cn5VKjWQbt6XP V4LnqfSq6uF/tMug7/DCHGE8/SmAla7R60D+bbPCJGlz648HewDu1s+8ueaLcdK/2J WgmUtMU6VoFje8vZqbmuWHAN7QDDZoAzPJsOFG7x9zOadxKkhxwiemdDkXw3OxEtoP 70sIxcZyQcmO4/HzdureeWJ+N92pkViwR5J4z0Rg+Jhbnp2DmQAJIlaAACJctHvtU3 HVH/sTiG1qX2A== 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 v4 1/4] nvmem: Replace spaces with tab in documentation Date: Fri, 28 Jun 2024 01:37:27 +0200 Message-ID: <20240627233747.82341-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 V3: - No change V4: - No change --- 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 Thu Jun 27 23:37:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 807963 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 9EFDF199E93 for ; Thu, 27 Jun 2024 23:38:06 +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=1719531488; cv=none; b=GQDm1KIfyaPnhvttSdQdweIASAwkFFCh95W55KVHFxZTHuOM9v4u0+xXOOSJbSqs4wQy9EmouuEbN//Z5+6qpnTmGI/gnqi1M7nQkWNV+Z37QJ92A8Kb4Dx9LOyqfV/ZAZZGrZfuvX6+YZFICG+Tt8tjvKJQIWGFM72Psp0Cok0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719531488; c=relaxed/simple; bh=9K90ZzJ/N4giFuPOWS6D+T2pwBx80OAaZvgQ9BWojYI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dec3gviCPagLfB85oPaIOPt4B4PAuw5VxTfZ2lNEICHLdhJ2JVYlJ+3Yn7ycPUFszgCYBGhLwJwJvGVF8S70jLV0iuM/KJRKB6jtHAxwKZBJrmSWGnBam0RX5h8oZkYpB8koFB+u6OjDFgNN/w+UcyZrC9X2ha5zNWUyzX7CJl8= 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=MpCylN/L; 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="MpCylN/L" 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 C5FE78852A; Fri, 28 Jun 2024 01:38:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1719531485; bh=Lv6J3oXBcYwk3Ox2MW9pBVAGdddaz2nr8GFbIwGmPmc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MpCylN/LI+4RnxSJU8kFbLIE0ve/tYT7dBRylG275y1LOwyJtACfTvG9qHDIg31dF Nol1Uv26N7Xg8r8kR517BRNVeg9TLUZ5Hak8gTmBcV9NexEjT/EVdtFc3jQVZ6syuw ZpPzdkK+MquUx+T3cM0RAAapp4QEziHExM3Ar0GJNeyVA0ZN5YnKRa5Hqu7o8rg+Z9 5sXmPQOvQSiAuY5Iqy9thpb2nhhEVGFGujwufoL1tvvwt7jBLe42qC/ggIdpzD6cT7 Ys2bH7bRq8DL3oMVZA2WY4oCKgUnRi7ySADceFhUsKafrZnfX3DfZGFNETwzxFm1IZ xhLbcmrjbBJbw== 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 v4 2/4] nvmem: Document type attribute Date: Fri, 28 Jun 2024 01:37:28 +0200 Message-ID: <20240627233747.82341-2-marex@denx.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240627233747.82341-1-marex@denx.de> References: <20240627233747.82341-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. Reviewed-by: Alexandre Belloni 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 V3: - Add RB from Alexandre - Add trailing full stop to the paragraph V4: - No change --- 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..3f0a95250aa84 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 Thu Jun 27 23:37:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 807962 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 ED20A1A2FC5 for ; Thu, 27 Jun 2024 23:38:06 +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=1719531488; cv=none; b=ou91Psvl9R9VoIcT5Kh4zVbam/xv7zixC3cO5cUkijskQSmyuZjhSu9CMP1ceMQspQUXJ7PZrQ8m7jKYAmURihe2G6x7S8lqVImORobVUx4raIVclsfYwWXAWipn9uTI7+nj1AglnILHcaYeyhah9hYhhHRATfJi096EPo1gHGE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719531488; c=relaxed/simple; bh=nAFwo7D0gW9O/sMvgBY7XxEz39ucoeofOWIjMi7HBm0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eXZX+IcAUtikt4tgxghclW6yOidognNMz3dQApqz6uhz+3N3R6qOFwxLvc5+0WRqKn8uzyztILsTuc1MsKuOC9m6Xey1zznJSK7Kwxu5g2MUi6P6EcYBrIVUzsYkgA9sSdz73JdOlaHSZOWe4aXEUQTA5o4lFKdz8augReASYsU= 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=MC9VUAvF; 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="MC9VUAvF" 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 11DC38855B; Fri, 28 Jun 2024 01:38:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1719531485; bh=ZjPoWZtHz9km6NRPw56HluRMf/MgeWSiH2/yMZBn9lA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MC9VUAvFLEqg20LtaYcjug/1r45V2MLOTGJJh2ipe6/xWriktVJCWPACkLFGoFKwc rl/ICzFyDyR5c7/Jf5xlGh4OsIy5BUetK/JTFHJSr2O6hY7dGQCBrXA/ENCToZ0Nsg SGeVl1i+lW3ldmsmkklobzIAqXnFCBnvbz0tBSdJ04oVFlsunytkVyrh/SjJ85xDWx W7RePiJRSwwGhqrReqqNWtDOyUIUGXF11sMxcte6TJU8u6MQY/q/oDXborEyvh91Dq wPr4C8RGZcF54L9/JQT4hRhzr4/hZmPdZiK7qEwAx90b0rVl44R4eradZHz5djPHUL IqOSblJPlm5Lw== 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 v4 3/4] nvmem: Use sysfs_emit() for type attribute Date: Fri, 28 Jun 2024 01:37:29 +0200 Message-ID: <20240627233747.82341-3-marex@denx.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240627233747.82341-1-marex@denx.de> References: <20240627233747.82341-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 V3: - No change V4: - No change --- 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 a31ea4275d5ae..5b3606114628b 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 Thu Jun 27 23:37:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 808553 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 7D3111A2FC8 for ; Thu, 27 Jun 2024 23:38:07 +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=1719531489; cv=none; b=ldEpRVrTYVuuvaSW8GSjfuR6O0gzCga20YfK0cDpgqzDqiOpWb948QG1chxFp+Llp/Bce5YxNXwk0xk6b+Tid/gDoWoOa4uC1Ud3d1BSw6qJq90bNmAR+fnU+l/MuQAdkS0k9qmy06p5QckwKm1cRoYhfn5BvkWK6YyCvb7awF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719531489; c=relaxed/simple; bh=7rIJsqAXH5jFMao9VAX81Y2Lh1Fr7TVm2e1pyOVOloc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fJAjbBD4piJYtLuuCrC8hTVaptc4OraKZyIb6GZ7wf04vqoMQDtC40KKv5NinuwHAxh/xof+L0D38XhbWoQ5EDetZyQzVU0yLEP16o/NG4oPib+ptwIXLu+qrajtfoVPhk0FpG+kPnpYbMwjmlfkHLJFK9OrdCCQWH0u17Uvh3c= 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=Nu33VSrz; 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="Nu33VSrz" 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 500868857D; Fri, 28 Jun 2024 01:38:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1719531485; bh=mXm5ooJAECfblFWtjVhUsv+lssDk8YMCerljmu5cWWQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nu33VSrzNoUG6NpluK5ty15jjytYcZToOvW7wGINLevHntGH08mBgECXD5VyHMnPm HPxCBtl8vQ1/XqLcYsV4mfCFrk19IE5nMDmC3wJ4XwHtDvSSdSZ+zILjMH0vD3JUol mhXCMYKfTLygRlHRThGRsyELE6tP5xzltqwWlsTvjG4EFogpyxzyy2fY9EwSHelVrq chbinE0oL1G6hvOIgMfE3VyMCPfG6jlCMDt0ndz7yHd6vYt2r12SfJsC8GgmSY25RB jqtN846ZT2ElfbrWmSstLYCrfVVawBkTcq/EpyGWJRryW7KvMsFrXWnzFHeg8Tqe6L +ETvK4fE1+j7Q== 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 v4 4/4] nvmem: core: Implement force_ro sysfs attribute Date: Fri, 28 Jun 2024 01:37:30 +0200 Message-ID: <20240627233747.82341-4-marex@denx.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240627233747.82341-1-marex@denx.de> References: <20240627233747.82341-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() V3: - Expand ABI documentation with what the force_ro attribute returns and what it can parse. V4: - Drop default_read_only , that is superseded by nvmem_attr_is_visible which outright hides the force_ro attribute for read-only devices, so they cannot be switched to read-write. --- Documentation/ABI/stable/sysfs-bus-nvmem | 17 ++++++++++ drivers/nvmem/core.c | 43 ++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/Documentation/ABI/stable/sysfs-bus-nvmem b/Documentation/ABI/stable/sysfs-bus-nvmem index 3f0a95250aa84..aa89adf18bc55 100644 --- a/Documentation/ABI/stable/sysfs-bus-nvmem +++ b/Documentation/ABI/stable/sysfs-bus-nvmem @@ -1,3 +1,20 @@ +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. + Read returns '0' or '1' for read-write or read-only modes + respectively. + Write parses one of 'YyTt1NnFf0', or [oO][NnFf] for "on" + and "off", i.e. what kstrbool() supports. + 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 5b3606114628b..628d4f940a2b2 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, }; @@ -285,6 +308,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); @@ -341,6 +383,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, }; static const struct attribute_group *nvmem_dev_groups[] = {