From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 7C873310645 for ; Sun, 23 Aug 2026 16:34:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787502884; cv=none; b=pQw8fY5LpkPPRWe17zSOmCAgZsm9uMYkxr9GAg3E37fBWJehwr4tQLhgzV1iZm2gqSa0Lo2m+iaKwa5MwW5qarAbcvLh1dGXOpzarUg3R/UxM0SH52iUOtCAtQ/YZwxQFfyxXTvZ5Oc1OQSJQRveV/8cN0L9586I6L14RdUQK3A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787502884; c=relaxed/simple; bh=EJfCCTqbNqMzi71//u8ytAzKCePxjJyYif64TVPjsjw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g19g6x+jUkDtPzQ0BDUvh8HX4PFmSn+mmwPm7VE5XTTQ2jeJ/6DTcJeyI0HUfkIkrQJ6wtMgRilO71rHDWVbWfVQHecRQgK+mEY4aVV91gdaHbas794f/hc8mxrM2lwJDXmsNDlGZ2OBZUKeWzkrAdOIJz/ln7BrsoRpHE6kaWw= 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=ljlU2ird; arc=none smtp.client-ip=209.85.210.177 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="ljlU2ird" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-84e04df8c46so3467351b3a.2 for ; Sun, 23 Aug 2026 09:34:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787502883; x=1788107683; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=TSuRlPLvqVhvoFr/a6EcJQdMGwGvdr0Nq8RIhTw4Mzs=; b=ljlU2irdobs7Z9q9OYTc3DUhrumb+MjXY+9SO/sQbsCM/piWuUKPVNwAEyOE8HP0GR 9jAS5997RxBS7ORxKTmFOHTvrMT0Fb4CRheGAX3UEWGT4cNmuMHXaTTvzFrB7cKh6M6E +CG1sVuLePjDCnswVNTmCzoIBvyjjWU8IEY6Y/rpiX9vG2r28fg1Vu61gQCR8J++aBmC IubKcvSPfmMzJ786b7aPuAdyjhuaQ4L0+fs+3Hznu00YPmNXcGxRfTf+RCF9QsaqdiVN gWuoDzmSZqgjMPsRPotmtFDUFzRJOl/x4HlQnmAwhyzl1tg29tdxxTUQTLP/+0TyqWxG O9lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787502883; x=1788107683; h=content-transfer-encoding:mime-version:references:in-reply-to :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=TSuRlPLvqVhvoFr/a6EcJQdMGwGvdr0Nq8RIhTw4Mzs=; b=Tj8WjTPz60Tc57ZdcT5l4fjezHwPzorJKh8gJuKEWe8ToDL09MvvbyiDrWDnP71LF/ s33Rj4bjK5AsV0sQ2wd0boZmb9j+9YKUPlP6baXbjvL//U1xoHy1RbGDEdviUn+belLQ 1ktdCRAlXDZ3cZIKQnJir67/p4pPicrczYcZAs6KCA/k4Y27bx2HWaSSISPMxx3BSKxo iNlO4NVvwPoehOP1UNNXrAp3wBccgQ/iktBJqBlPziiwYTco7oymVKgR6nlbCXvGVxuy C0GBR6JcJM3GsDYHfqTjAj+7JKElWVGGrFIrYbL1yXvscflFX9uMIc0/5yKcc2nwtIXh SIRg== X-Forwarded-Encrypted: i=1; AHgh+RpdRvf3ngdm5RnNQJtEjKX8eHctGMc/qGlK/PBCCTICewRE12viM2C0Py/pD97pSY2TFR/CEixvdYHJC6U=@vger.kernel.org X-Gm-Message-State: AFuF++lHRo85Y34Cj510NdeQobTkIFGQYRMzt0o8NlTsR7ZT9hPoTXnz ejIKD5Q7yD1makIqiOxkreWRx7pP+puQ6IKha2Kt275T68F7pqq0zElz6nPub1ko X-Gm-Gg: AR+sD10eH6RrGS0EtlkdALt0cwMBZQGzv4guahl+UVuf0/n3jDqlmjZU4YeQ+6XKced cO+EmDwfU6bvb2Qm+FWAPS/TH929CGduL22VDjp2cw06v79DLLFZ/q4/1FwjsRl8JoDcju8rHYJ 0VxtPlBhej93UxW3cL42BPWD9w6EBumPWSNAYpQ9fRH2BS4o2T8WbvAxNsR2CuolriaOyiFafJt S0L6RLpPK52/GjD0FmOZKeaLYXzYBFijSlm1ygWJhrxwzBcF+VlOovqMg7FIifIzmvDB8B/a+EN AvLtQ/Sft5QfcPevCUc00zi1zpqKVcq00bTFgoXLzGTMNMBLwwej6V2ZBiDifhTAcnUZrtkKjRb 6A9FZ+Pn8isHj2rfQpcY6VMPsr2DiPYeI2yA8DSRlIXC1XjUwMyuFSLUXjBFuuINpD64iaWBd2m VoJ6kOUlfklJqXkExnmv5+wqIklwVgGj4Y/saZdR8z1iOYHTynD/bIZQJnJxZMqC0M9Usrdm1Vn d36ShZaESB9Hma6nnvgjQZHJL7rkUulBmvKwoNBB8ujnJMkH/QAbcljmwqcoM/QiT4albkyGwX4 E/N/2g6C5ug7D9bre2M19H8Q4fXpiVo= X-Received: by 2002:a05:6a20:ac43:b0:3c3:935a:af2c with SMTP id adf61e73a8af0-3cd2fd03751mr41714282637.3.1787502882736; Sun, 23 Aug 2026 09:34:42 -0700 (PDT) Received: from Mac.net (198-27-228-154.fiber.dynamic.sonic.net. [198.27.228.154]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-141860ef75esm17084319c88.7.2026.08.23.09.34.41 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 23 Aug 2026 09:34:42 -0700 (PDT) From: Ahmad Byagowi To: Andi Shyti Cc: Peter Rosin , Jakub Kicinski , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Ahmad Byagowi Subject: [PATCH v7 2/3] i2c: mux: Factor out channel node lookup Date: Sun, 23 Aug 2026 09:34:37 -0700 Message-ID: X-Mailer: git-send-email 2.50.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Move the existing Device Tree channel-node lookup into a helper in preparation for using generic firmware-node operations. This is a pure refactoring with no functional change. Signed-off-by: Ahmad Byagowi --- drivers/i2c/i2c-mux.c | 84 +++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c index 68a4c34b5987..a8b94b97a725 100644 --- a/drivers/i2c/i2c-mux.c +++ b/drivers/i2c/i2c-mux.c @@ -264,6 +264,51 @@ static const struct i2c_lock_operations i2c_parent_lock_ops = { .unlock_bus = i2c_parent_unlock_bus, }; +static struct device_node * +i2c_mux_get_channel_node(struct i2c_mux_core *muxc, u32 chan_id) +{ + struct device_node *dev_node = muxc->dev->of_node; + struct device_node *mux_node, *child = NULL; + u32 reg; + int ret; + + if (!dev_node) + return NULL; + + if (muxc->arbitrator) + mux_node = of_get_child_by_name(dev_node, "i2c-arb"); + else if (muxc->gate) + mux_node = of_get_child_by_name(dev_node, "i2c-gate"); + else + mux_node = of_get_child_by_name(dev_node, "i2c-mux"); + + if (mux_node) { + /* A "reg" property indicates an old-style DT entry */ + if (!of_property_read_u32(mux_node, "reg", ®)) { + of_node_put(mux_node); + mux_node = NULL; + } + } + + if (!mux_node) + mux_node = of_node_get(dev_node); + else if (muxc->arbitrator || muxc->gate) + child = of_node_get(mux_node); + + if (!child) { + for_each_child_of_node(mux_node, child) { + ret = of_property_read_u32(child, "reg", ®); + if (ret) + continue; + if (chan_id == reg) + break; + } + } + + of_node_put(mux_node); + return child; +} + int i2c_mux_add_adapter(struct i2c_mux_core *muxc, u32 force_nr, u32 chan_id) { @@ -327,44 +372,7 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc, * Try to populate the mux adapter's of_node, expands to * nothing if !CONFIG_OF. */ - if (muxc->dev->of_node) { - struct device_node *dev_node = muxc->dev->of_node; - struct device_node *mux_node, *child = NULL; - u32 reg; - - if (muxc->arbitrator) - mux_node = of_get_child_by_name(dev_node, "i2c-arb"); - else if (muxc->gate) - mux_node = of_get_child_by_name(dev_node, "i2c-gate"); - else - mux_node = of_get_child_by_name(dev_node, "i2c-mux"); - - if (mux_node) { - /* A "reg" property indicates an old-style DT entry */ - if (!of_property_read_u32(mux_node, "reg", ®)) { - of_node_put(mux_node); - mux_node = NULL; - } - } - - if (!mux_node) - mux_node = of_node_get(dev_node); - else if (muxc->arbitrator || muxc->gate) - child = of_node_get(mux_node); - - if (!child) { - for_each_child_of_node(mux_node, child) { - ret = of_property_read_u32(child, "reg", ®); - if (ret) - continue; - if (chan_id == reg) - break; - } - } - - priv->adap.dev.of_node = child; - of_node_put(mux_node); - } + priv->adap.dev.of_node = i2c_mux_get_channel_node(muxc, chan_id); /* * Associate the mux channel with an ACPI node. -- 2.50.1 (Apple Git-155)