From 83d031c024f7bd1a3f75a44abd24fab37982b472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20H=C3=BCbner?= Date: Tue, 4 Apr 2023 08:02:09 +0200 Subject: [PATCH] drivers: w1: Make 1-Wire Skip ROM cmd. optional MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For systems with a true dynamic 1-Wire nature, the 1-Wire devices cannot be defined in the DeviceTree (the number of slaves in the system is not known during the build time). In other words, there are no pre-defined 1-Wire devices on the bus in DeviceTree, and thus the slave_count variable is always zero. That means the skip_rom functionality will always be called even if there are multiple devices connected to the bus. This commit allows the user to override this original behavior and avoid the skip_rom call by ignoring the slave count variable. Also, this work preserves full backward compatibility. Signed-off-by: Pavel Hübner --- drivers/w1/Kconfig | 13 +++++++++++++ drivers/w1/w1_net.c | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/w1/Kconfig b/drivers/w1/Kconfig index a6adea8108b..2fabe874b6d 100644 --- a/drivers/w1/Kconfig +++ b/drivers/w1/Kconfig @@ -53,4 +53,17 @@ config W1_NET help Enable 1-wire network layer +config W1_NET_FORCE_MULTIDROP_ADDRESSING + bool "Force 1-Wire multidrop addressing" + depends on W1_NET + help + This option will ignore the number of 1-Wire + slave devices defined in the DTS. Specifically, + this option avoids the SKIP ROM command, + which is otherwise used in case of a single + 1-Wire slave on the bus. In most cases, enabling + this option is not needed, yet it is essential + if multiple 1-Wire devices unspecified in the + DTS are interfaced. + endif # W1 diff --git a/drivers/w1/w1_net.c b/drivers/w1/w1_net.c index be515c7d151..06ac4b19cba 100644 --- a/drivers/w1/w1_net.c +++ b/drivers/w1/w1_net.c @@ -346,7 +346,7 @@ int w1_skip_rom(const struct device *dev, const struct w1_slave_config *config) static int reset_select(const struct device *dev, const struct w1_slave_config *config) { - if (w1_get_slave_count(dev) > 1) { + if (IS_ENABLED(CONFIG_W1_NET_FORCE_MULTIDROP_ADDRESSING) || w1_get_slave_count(dev) > 1) { return match_rom(dev, config); }