From patchwork Wed Jun 26 04:11:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 807608 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 0AAB8132103 for ; Wed, 26 Jun 2024 04:12:41 +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=1719375163; cv=none; b=rfD6vxc5VqETYy78p+I5sX6OMEQoTt8CJpgmKCDGbymlrzkP6PINVrFZwTCfLtMCXbXsGsj2RItWYx+Y5Zt/ob7p0gZt6WAtyCEdyGmSo6IL+L1leM9N1KlUDbJRERiOP5HFGnd6J0bK6Tmcbrg7lnMyT7OPF3nJhVVVzgFAcao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719375163; c=relaxed/simple; bh=BIzVq21O0UEEJGgNWcR0sQeMSNHvdFYmXD+RpE4rc9s=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=p7UssX5RgMyQpZDNUNqY6V5LM4qYxc7EXg+B6yZrBxwQ202GewrTB7Df0mlj+fZYsD88B0z8s9BpUdEeGFI2AkYgYnS9gYOivAL7q2WZ6oAllP9paEv3KL+gDUuT+7tIM3wstkj5th4W6OCQMHS+HnxPLhOicfFFvhlXn+5O8HM= 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=UEXETlX9; 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="UEXETlX9" 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 9F96588216; Wed, 26 Jun 2024 06:12:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1719375160; bh=h585xFpqaczjbUYr4JYZkQHiTfuHjkeqU8jL3tW17CU=; h=From:To:Cc:Subject:Date:From; b=UEXETlX9Pn/S15tRlo77kh72PcgxpTn1eygp/elXSOY3+vjLb0HDUbHRVhA9DEk8d lcDsaxs5avztbXr3Iehc1/q3JJmjnzlKf/0LogXNp63VEilfVvtrwKIku980dxhGWF vMlQMiTdKJc+7NBoCKe0eyjzbodT1MJnV9QIpz65eDu2lQI21A4OpAz8kIMEj+WEHw YC0Sqltyqa5dPDNyoOv24lgQuuDWh355rcTrAej9AVnMiUFToLUrggU4aL9d8UjCvi V2GbPxQP3Z0wx9VkwJxk/UOmUATio8XD4QM1xNFu/e64O97DZnYVDvNZE9crT1evRm hF9LgH77cdhJQ== 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 v3 1/4] nvmem: Replace spaces with tab in documentation Date: Wed, 26 Jun 2024 06:11:14 +0200 Message-ID: <20240626041214.513242-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 --- 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 Wed Jun 26 04:11:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 807607 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 7DCEF135417 for ; Wed, 26 Jun 2024 04:12:42 +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=1719375164; cv=none; b=mPTEvkcgVXXwYOPLdKpAxHGoRIBBwi80rfkewMyu2S1iRvEpryY+nKw9Dc7jIvBlaTwxaAktYWXrJp4wu3TjNnrgzVPnnn+jvUlZhQODgLevT2IDKEoNfpsYZkof3Bor+siHl1pF3IfZuhCIfhv7bU0LZzfWrojygNCvMGZ+85Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719375164; c=relaxed/simple; bh=DMfHImeVQacrbJLdW9Gm1gJayI0A4oashzejx8lHTUY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QgluocgNi+X62FPAHHa9fQIEBnfppduDeqS8q+1pCtw8Jyi1GVQMP1PQTQZ3m+siNHO4jZlrd8HNoucsXiTSF/zwNsNnuP0bME03TA/gJknP+eRM/6csKEndfNdSC9hy9DcBNN5XsL/PR2HSeAvvQ8t+dOIsgPSP5g/6Z5GK0a8= 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=Np4ur2b4; 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="Np4ur2b4" 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 3A46888405; Wed, 26 Jun 2024 06:12:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1719375160; bh=3gO1NwHnOedIW6ntjXW2EqQTewKzsrtIp9NJodnbHzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Np4ur2b4Eil5bKxfss60+7udvtyS5P4dtQWe9lubRtVQhpNrioD5s96Qfc2fAaLYB aix/RV4jFq3cxGBKkuFHFvSW9xCB4l2Gw/00oxGqljBlcx8YNzkg3V6xTYoqubWp9s 5obEw1eu8lNUu1lKaUp+9kEH0jMK8ybLoswizOiCxmyAEKTtcZl37084B+L3Qdql6b fEIe3E+a6YPB/ggl67xdKEnTXx8As1SrGDln18Fl7wcm5Ntu1HM6hKDtGGkSjHHJeV s1EmoP+yK81Tl0OPMt03Gu+x13dtHOvBa/1G/S1F+BD19RgX2HhlV+agWWg0akAypC 8qtGCu+eYEanA== 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 v3 2/4] nvmem: Document type attribute Date: Wed, 26 Jun 2024 06:11:15 +0200 Message-ID: <20240626041214.513242-2-marex@denx.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240626041214.513242-1-marex@denx.de> References: <20240626041214.513242-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 --- 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 Wed Jun 26 04:11:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 807980 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 9C3E21369A8 for ; Wed, 26 Jun 2024 04:12:42 +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=1719375164; cv=none; b=HSspFW2RY8j95mkLosmXNoXHvyVRSg3QVhq7wWPc5/jViUCRwJb/Xe2xhte+2QkD4gDL35CaDu2beLLVp2uD6cZx5y3mbrAZppXYpyNH+UHdOPnvsPZLjE401RMgDExpHrqNjv975AeuzmzQ8IrkJkUNl9p4YIMx/p5vgRSNx94= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719375164; c=relaxed/simple; bh=Yc8bhzuTh5dhrTwhgguiLNMs+Z0G0L2JfjVeDqybMLw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B+E+LBk+ztDUHeTTfh+peXJdoiFj0c0t+4IyiauyrPKoFHDxr4V6pkCUw5J5KHFkATr0qca1Feou83rBzkBK5hj07gI0dRQOZzEgAD1JPo6gfcvmlIAv7DT1FTKWksFL4VakzQCCnXHTjj/6VAlk3QMMk29AYAiEQfa9//jRCZo= 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=GxeILalo; 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="GxeILalo" 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 8A5738843A; Wed, 26 Jun 2024 06:12:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1719375160; bh=MqJJiK5ZcpTj6ohr4IvakBBTXdeJGhI3BdkcN6YPFyI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GxeILalo1Jf+o9BPB20z1P2/q7OYXdUgzhNwTFhfuo8RlOWUZRA2R6TgvzMdNhK9f m3z5FoiCtYLKYo7w3Yp1diO+FnK+zdcjcel1Qfb67WZKd5Dt2K1HDb8PnKnfiQJAi8 QqXD/Njd0/1Y1n95Hg1nG8n89jD4yMWNGypAKQqdKY3u6GZz49KI0TYXe6NTG4Ufiq n48IqnNztlLg1yq8QRTGuxMUKsQmfh6cVovuxTiANkN7IuNhRhjKir0aa7SQxBb3N4 JuIyLQz5D32J/hTjnDrQoKA5Y8h5xjfAd+z9ltIYyJkNdBTI9GkSv7Fegp5L9FglCK EzJ78Zl5NCY+g== 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 v3 3/4] nvmem: Use sysfs_emit() for type attribute Date: Wed, 26 Jun 2024 06:11:16 +0200 Message-ID: <20240626041214.513242-3-marex@denx.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240626041214.513242-1-marex@denx.de> References: <20240626041214.513242-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 --- 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 Wed Jun 26 04:11:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 807979 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 EEA691369B6 for ; Wed, 26 Jun 2024 04:12:42 +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=1719375165; cv=none; b=udmq0RRM2JALB6KOs0DyzwR2tDogtUiW1IA58iCeTo5MUDtsPhNvfMSyVqsRLakJ71Uboe4F1CAg9b2pDtJbKb8rVv53y2mNmQLmT0NXGKILTvyfWg7nk3GGgnfwauSqQRR6s5yhtEBAz16fuKLrLV66NapcC+PrM08iAV+Q0zs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719375165; c=relaxed/simple; bh=zJXSuPTm2iFg66Kuu5zIAzQ0wZWatD4sATsUE8YFJXc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ciEmIEH7dO3/u2RsklJt225Sa8bOSvxQsxJy1mW8tGxhoQ8dsb+67QULZEZkSkExtGJ2SVLbPB5VIOC0/F5UBFlPvExIDDiYTHgwxVtmWy3RSUDLE2z9CEC9NhS4BGIhdZtYNj3xJXtRhqod3p9Ns6kXBdcgKglb8lEVAgXP47s= 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=Fz0zW3Jz; 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="Fz0zW3Jz" 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 E82EA8844F; Wed, 26 Jun 2024 06:12:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1719375161; bh=3BhXKe+7/0qtKfP5AeeYitbsXZHR+OjtZSCYf5GAxeo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fz0zW3JzL3uxuILj492SC6n4qfmWYzBQOKXhj0hp2Nn8k/HMsnnz0v8H/Sf/sLVaF PXS5MmqaicvBTUwYUxlImcAj4i2UfrqgZxxpalQyRy5E1u8Q51ZgRnMVpPMEimxcOP J359LOPQB0SHaGRU6l4pPtk/TWM/A1zFi55t7sqI4SdJwNMca/Rkhhk733GiNlTm+k HIjKDBi6F4WlqslbRTr31IvK9OliP9o1PC2ymf+bIyqnt2NMz8fBxJGqk9VvwHjPfh 3mfGLha5fou90mC/MGUnDJsUBxMD2VXbQ7NdLTlocY4hCcVINqFPIL+PhB91x7xwmi YsjJ6GAPEVrJA== 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 v3 4/4] nvmem: core: Implement force_ro sysfs attribute Date: Wed, 26 Jun 2024 06:11:17 +0200 Message-ID: <20240626041214.513242-4-marex@denx.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240626041214.513242-1-marex@denx.de> References: <20240626041214.513242-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. --- Documentation/ABI/stable/sysfs-bus-nvmem | 17 +++++++++ drivers/nvmem/core.c | 44 ++++++++++++++++++++++++ drivers/nvmem/internals.h | 1 + 3 files changed, 62 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..91ff5e2ce613c 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[] = { @@ -945,6 +988,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;