From nobody Mon Sep 28 14:47:12 2026 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 827A6483BE6 for ; Thu, 20 Aug 2026 17:41:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787247671; cv=none; b=uu/iHJMkp4dgSWdWwf9BqZ0sAHlGxwne5A5I9aZxdkZ/47CVAQyHdqYJgVhVURrWW7BmY6QVQqlG9Pvh4mwmMfYYu+jK45mchyFw5Zmd0xJ+HC31Z4ulQTVNj8td5P/HlDEb5rWaeE69AoaHl41jd13JR2lqZjTCdO41i0P3+ko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787247671; c=relaxed/simple; bh=lTNPzVr6aEGfj5ESPPhRasa2ZHq56ejhJWmSkgBxpYs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=o2LZ4JQrLtKXgov9+wZ+E/v3c2c3XUGa1IY+efRDtBnUcvksbgWCiV4yS1cEhJLGAv+gyEUaF1Fz3aaJQaO2VkaGylH/t5rwnph+1zQ+ef+4ySqpulRMj3WFolWJfBQjZmu8ufuKkJyK4OLTxwTJeB3Ji0hkghR28AHxBPx4FQk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eSjq2vPC; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eSjq2vPC" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2ceaf8a1265so1636605ad.2 for ; Thu, 20 Aug 2026 10:41:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787247669; x=1787852469; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=O7KMdDzbIC1QroGeo8Cy4bum1ArkV9EBPN0TLsbF4kI=; b=eSjq2vPCh7JeQFj/2h9Y5SfYgSTF0bMW7mLfekZIQ5nS4Yl91TDuP4gzgZLOTIh/G9 Ts7BNi3KmIJ/1h5cQxHoxnUlGsiOhPn5e7HzOu0F/9o53m10yLOnny17xd0wDEeX5LH5 1PbvoW4izj2NjdWghxNzibpRMI3kTzMtZxeG3cs2sTCmscBBXH4V5VJJaefJUoJAd6g3 u32nLNz02U7mAROXwKUJmRA856XdD+c4bVX7BCeYQEShoH/yFn0Je4CDBuCsoVAmi6Gl 9nGEaynRxuS7nGZp3GFCKPnJKhLq7JI/3sCAR27QeYc7FRhWj4neJd5Ndk97oThu1pEM ydsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787247669; x=1787852469; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=O7KMdDzbIC1QroGeo8Cy4bum1ArkV9EBPN0TLsbF4kI=; b=h79mcvTCWW7TIZo+cs1xJuE6xrzSfam1l3FmAEZHilaVkhcPrEAAwCafs5ax+IMYUK AyNHyyCBTz5NJHwfFCyA4E7cfvdVfjtdr6ce2cN4ICIDKcVSdm6UjPVv/lC9JeWpIurR b8jUgDfTmkm6eWLBViyW6suS++dsIHrejL0cNeWnevdOJiEj/LCGX23PNteYj2CHQOPg zIacdoURPhhcIsR6wxRCxzQEUWYVfAvDlW03CoGSPmAQzz+1I0B6lksThkW8TFBUKLbn t3Go8PziAjHwVI3tYMq9snyCLtRm4Yohu1+E/HMpw1xHKNWZVJb2v9f0zem7LY1x5FVi jX2g== X-Forwarded-Encrypted: i=1; AHgh+RoSSJpIstAkwG+/B/GqFNcb4+qsJSFHSxNEVBgj7TLey0JLNC0jyG3QQVr0o46tqMCShqnsQ21YZkHMywc=@vger.kernel.org X-Gm-Message-State: AOJu0YznRG1HVO6Fz+6BKwwafkbzg/3p4Klg2q4NpSYDpRC+od0QqVvY d9xihRRYCB71qGlKK7WmcS+yEK5TnJ5e4nmk1WlhFPzbjIh4O19tHHqSx4H+/1aW X-Gm-Gg: AR+sD13fpiAar+ySux7iKl6Tk1B+dKGOuMbiI8EG5bdVGa/7ogElMDXkblLRDq8NufI c6lhVkvEDGjECjx4fjNccQkUwPfrVBU9VN06zGadgNDD/gwLG6N8UykraHGB9dg2QnPMDPi8WoC zBQ72OkFh44hGmH34NZFh9wzgOqStOeapOFd/NXjIBjciGr7illPjpwrYjoewC9LSGpHCGNIZy2 OdApbwYmjCX1AdtFdL/MFTBLK5gtSc/e4mSX7V66CNmp0uo6ordWlWXPHHBApN7qidw7s9Y1BPs OujReDt9byVFFctdcoI7Kgg1+2byB5jOLXbNyzKhFF8zqkIP07t3DlxImCpWbHP4Rp6jex95H76 CS/1HNGcFVo/9ZVkFZK7ftdqj0ez+nyPD4PmN2sepKaBMsZb3sS9Od7AVXGIgOADVXO41cQ955g EYK24y4iOIw5cP/KDMcXJNodgQ+CKH2AL/WqwV/EAXN5ru9PqFKyqvjUkZRmByOffkSenNMELMn bj59FJRCWZId83d7u+PMYGTNscJ3z+yo1+uejyN4+HC9Cb+U5VGxQ== X-Received: by 2002:a05:6a20:43ac:b0:3b4:8f18:33a with SMTP id adf61e73a8af0-3cd2fd8e233mr264870637.1.1787247668691; Thu, 20 Aug 2026 10:41:08 -0700 (PDT) Received: from Mac.net ([12.162.234.74]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-327d6168e5bsm7943356eec.1.2026.08.20.10.41.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 20 Aug 2026 10:41:07 -0700 (PDT) From: Ahmad Byagowi To: Andi Shyti Cc: Peter Rosin , Jakub Kicinski , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6] i2c: mux: Propagate software nodes to channel adapters Date: Thu, 20 Aug 2026 10:41:06 -0700 Message-ID: X-Mailer: git-send-email 2.50.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Device Tree channel nodes are associated with the adapters created by i2c-mux, but equivalent software-node descriptions are not. When the mux device has a primary software node, find the child whose reg value matches the channel and use it as the new adapter firmware node. Keep the node reference through child-client removal and release it after adapter deletion. Also balance the Device Tree channel-node reference when adapter registration fails. Signed-off-by: Ahmad Byagowi --- Changes since v5: - Send the I2C prerequisite as a standalone patch for the I2C tree. - Limit propagation to mux devices with a primary software node. - Avoid secondary-fwnode access and changes to generic adapter lookup. - Follow the i2c-atr reference-lifetime pattern for channel nodes. - Balance the Device Tree channel reference on adapter-add failure. - Rebase onto the I2C i2c-next branch. v5: https://lore.kernel.org/r/cover.1786746757.git.ahmadexp@gmail.com/ --- drivers/i2c/i2c-mux.c | 61 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c index 681a201c239ba..76fa89dc6a222 100644 --- a/drivers/i2c/i2c-mux.c +++ b/drivers/i2c/i2c-mux.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include =20 @@ -33,6 +34,7 @@ struct i2c_mux_priv { struct i2c_adapter adap; struct i2c_algorithm algo; struct i2c_mux_core *muxc; + struct fwnode_handle *swnode; u32 chan_id; }; =20 @@ -264,6 +266,49 @@ static const struct i2c_lock_operations i2c_parent_loc= k_ops =3D { .unlock_bus =3D i2c_parent_unlock_bus, }; =20 +static struct fwnode_handle * +i2c_mux_get_channel_swnode(struct i2c_mux_core *muxc, u32 chan_id) +{ + struct fwnode_handle *dev_node =3D dev_fwnode(muxc->dev); + struct fwnode_handle *mux_node, *child =3D NULL; + u32 reg; + + if (!is_software_node(dev_node)) + return NULL; + + if (muxc->arbitrator) + mux_node =3D fwnode_get_named_child_node(dev_node, "i2c-arb"); + else if (muxc->gate) + mux_node =3D fwnode_get_named_child_node(dev_node, "i2c-gate"); + else + mux_node =3D fwnode_get_named_child_node(dev_node, "i2c-mux"); + + if (mux_node) { + /* A "reg" property indicates an old-style firmware entry. */ + if (!fwnode_property_read_u32(mux_node, "reg", ®)) { + fwnode_handle_put(mux_node); + mux_node =3D NULL; + } + } + + if (!mux_node) + mux_node =3D fwnode_handle_get(dev_node); + else if (muxc->arbitrator || muxc->gate) + child =3D fwnode_handle_get(mux_node); + + if (!child) { + fwnode_for_each_child_node(mux_node, child) { + if (fwnode_property_read_u32(child, "reg", ®)) + continue; + if (chan_id =3D=3D reg) + break; + } + } + + fwnode_handle_put(mux_node); + return child; +} + int i2c_mux_add_adapter(struct i2c_mux_core *muxc, u32 force_nr, u32 chan_id) { @@ -324,8 +369,8 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc, priv->adap.lock_ops =3D &i2c_parent_lock_ops; =20 /* - * Try to populate the mux adapter's of_node, expands to - * nothing if !CONFIG_OF. + * Associate the mux adapter with its DT or software-node channel. + * DT support expands to nothing if !CONFIG_OF. */ if (muxc->dev->of_node) { struct device_node *dev_node =3D muxc->dev->of_node; @@ -364,6 +409,10 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc, =20 priv->adap.dev.of_node =3D child; of_node_put(mux_node); + } else { + priv->swnode =3D i2c_mux_get_channel_swnode(muxc, chan_id); + if (priv->swnode) + device_set_node(&priv->adap.dev, priv->swnode); } =20 /* @@ -408,6 +457,8 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc, return 0; =20 err_free_priv: + fwnode_handle_put(priv->swnode); + of_node_put(priv->adap.dev.of_node); kfree(priv); return ret; } @@ -429,7 +480,13 @@ void i2c_mux_del_adapters(struct i2c_mux_core *muxc) sysfs_remove_link(&muxc->dev->kobj, symlink_name); =20 sysfs_remove_link(&priv->adap.dev.kobj, "mux_device"); + /* + * Keep the software node through child removal. The adapter + * device is cleared on deletion, so release the saved reference + * afterwards. + */ i2c_del_adapter(adap); + fwnode_handle_put(priv->swnode); of_node_put(np); kfree(priv); } base-commit: b0e590bb83a9e40dc1e77a2c82d7f3e670fb74b3 --=20 2.50.1 (Apple Git-155)