From nobody Fri Jun 12 22:35:58 2026 Received: from mail-dy1-f170.google.com (mail-dy1-f170.google.com [74.125.82.170]) (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 459BB48C40D for ; Tue, 12 May 2026 09:58:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778579924; cv=none; b=Ztf3MIwUu/SqBkx7SslltJ4y9hWX2+ureElRDeJ2+6KudxYgYp2BmSQEjqe6EZ1bgurYppSCrhLx3G80HokuXgbUb/TARODBDHLdA7+hU6kVOtAo6+FimTLt6dpUAlAfIP2MmI7Py9/5aGIIs9CJ1bwcPbK6nsvSWngAprTt9sM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778579924; c=relaxed/simple; bh=bOFM4QU5xu7KgGZMZwMPxnRovR6UYAHIvUlj+2CSig0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=R9l0v32H2R/sUpL3vbuVhy5l7drLhJhrUeIDbtWOI1ai37plAeW7p1rpv5LXT7TBdNjvD0VZP7gzyHflqYGyK76puL89tsZ6FrMeSIYNGnDB5/LvOeEzPlW7bhdd8Nqd51aoPP4B56XgAx3sdjfeiTSO3EGhsbx3qz/n4OFcFaw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai; spf=pass smtp.mailfrom=nexthop.ai; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b=C/J8LH2k; arc=none smtp.client-ip=74.125.82.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b="C/J8LH2k" Received: by mail-dy1-f170.google.com with SMTP id 5a478bee46e88-2ef2a1cc06dso9476449eec.0 for ; Tue, 12 May 2026 02:58:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexthop.ai; s=google; t=1778579922; x=1779184722; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=x1+5OZsWURPavYcobtYNQ0u77xCxFvwCg3S8LRIf/FI=; b=C/J8LH2kmuxnvfhUHsSXGYK5JI/6u2ch8fGtaJyNzyvpA+DnO0qBkqvgyFlPcm9E6I RhsYB3W7k+ubYOG0g1+UoqqziErRMhCoIcq+rRJQn9DFY4gL17eL4Hlh9Daa8xbxL54+ V59MQw3hRq12KL55KTynLwGhVl4QQcUmOS7OkhyQ+cA9Ogq8IlDy9X8nPHsd5Gv90Cd7 HXVw6v5IMkEDIldqY4LolZVFrA+JDFTnI1eegkMkStH9Yazp6yKKem48pl6zVmaD0UFa hl8Krm4NYxirlVP42mY634IO29TZq3Hdfb7MHFVR7sTKfFyTDqiY9I0WAAH658v44EUl /Cug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778579922; x=1779184722; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=x1+5OZsWURPavYcobtYNQ0u77xCxFvwCg3S8LRIf/FI=; b=Z2yIMcXCQueBjUCw/wdUMWMjwmTpE3BqzN59EUVdTvkib5RG2CTdsZPeYFlyM9//3d 8vIrQ3M4prihDyWHksoO8fACF95IFEEjLLbdLiX0tr7jKPiNA3g8Gji6wdp/fa8sUz/Q xgS23eGKpwlz3nMRi7MZN6UCfVxSBORIbcaBKVWcftuA7HWf2kS6yc+D+lyvaHRC8fbq g4ZK9Peej9OU1FJwi0qFbzRbOCINWHYy5K8O8YAs5g7CeoLW56XQXS1moK/7VpMhhTS2 HrDVxU8AoX/nQxrCvdxNcBSmeGiXUNssgzwnSbcOITljn+BG/3sztek3k9v2QCAJ9f0a Tnpw== X-Forwarded-Encrypted: i=1; AFNElJ+b5U9rlLJq0FbdNht3Jds0P4JVjAUr5lFACZ7mjR/ndw0vQN+T7WxdqqGIjz1ND/3l6EZeHKtoPyLLNok=@vger.kernel.org X-Gm-Message-State: AOJu0YwY4K9eI95UaejXbQ/0+B8553gUvZWHR081r5nHl2oCYDkkPAOo 24QWrjXy58eqUB9ZUtB5NOIwojuq8Vr3jKI1sVL0jEaW/Z/G5xUl0AC1vyArFPicYACF0Frct6a qsIJOVi0= X-Gm-Gg: Acq92OF8XAl5nhffUgmTYkilv1xAx5fCI0SlWMhetUl9A2Ca6SvPFvj+1w9LriJMbrz gXu7yQ7Y4HkvFW7ThuIA6/rO4+rcGY8dpNeMz7fFKaeyzBVkl2YHy13wfVedf/13t7n5URWwJW1 XuS/FsXVZakY97Q7jA5bLXDOb37qYAmz/AC2lbA1ghjibggO8Lnnd4CIzhPlZdezR4yEqHynlYH b70DTiA9R0rDvt/IzNiaE2bROH1/YyMSKV6R0ZsjT3RVn9iZDT3x4OU9PVtCWnF8nzV7njx38Yp ioIUSxF4vAZgcHKvzyZr3ZJ2k9I8WZKsyRvKgcx66K/0AyRqtm8OcaCFMjeAqqY52wGaej6zjnB 46pvtolr75IbMGGyCjRuneb/+j+YENZkjQnW2Js0MWeF0NsAskVjVQi6Ks57usTLCTFMzgldXir LtInXVygzhzFYROcXFMQVw9ZODXw== X-Received: by 2002:a05:7301:4b15:b0:2f2:32bc:787d with SMTP id 5a478bee46e88-2fb4bd0a720mr7026387eec.23.1778579922097; Tue, 12 May 2026 02:58:42 -0700 (PDT) Received: from [127.0.0.2] ([50.145.100.174]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2f8893441absm22894743eec.31.2026.05.12.02.58.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 02:58:41 -0700 (PDT) From: Abdurrahman Hussain Date: Tue, 12 May 2026 02:58:14 -0700 Subject: [PATCH v2] i2c: mux: reg: use device property accessors Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260512-i2c-mux-reg-v2-1-80ea1da4cd0a@nexthop.ai> X-B4-Tracking: v=1; b=H4sIALX5AmoC/0XMMQ6DMAxA0asgzzUyThNVnXqPqoMLhmQgIAMVE uLujbp0fMP/ByxqSRe4VweYftKSplzAlwraKHlQTF0xMHEgRx4TtzhuO5oO6D0zuU5uPlyhFLN pn/bf7fkq7m0acY2m8n80jSdynl3NIQTCBuXdbWYSR8mPrPsap7mWBOf5BS1IKnudAAAA X-Change-ID: 20260305-i2c-mux-reg-552203da8564 To: Peter Rosin Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Abdurrahman Hussain X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778579921; l=8668; i=abdurrahman@nexthop.ai; s=20260510; h=from:subject:message-id; bh=bOFM4QU5xu7KgGZMZwMPxnRovR6UYAHIvUlj+2CSig0=; b=wRXvPsmMpOcSHF/D7I62JthrLUl2BWyyOmNx4rW1H4Cd4BjHPKnZns6JsC8OAcRdKad8K5XH0 VP6GnO9+jB+BD9Se42+A3TrBo3/Kk5t3ULaLY4J7mbN5AwvbGZC8FsL X-Developer-Key: i=abdurrahman@nexthop.ai; a=ed25519; pk=omTm9cCAbO0ZhS32aKfJDKue0W3sQGpG9ub5eYHif8I= Convert the device-tree parsing path to the generic fwnode/device property accessors so the driver can be probed on ACPI and swnode platforms as well as OF. The helper is renamed from i2c_mux_reg_probe_dt() to i2c_mux_reg_probe_fw() to reflect that. Accessor translation: of_parse_phandle("i2c-parent") + of_find_i2c_adapter_by_node() -> fwnode_find_reference() + i2c_get_adapter_by_fwnode() of_get_child_count() -> device_get_child_node_count() of_property_read_bool() -> device_property_read_bool() for_each_child_of_node() -> device_for_each_child_node() of_property_read_u32("reg") on OF: fwnode_property_read_u32() on ACPI: acpi_get_local_address() of_property_read_u32("idle-state") -> device_property_read_u32() Behavioural preservations (deliberate, to avoid regressing existing users): - The three-way endian fallback is kept verbatim: an explicit "little-endian" property wins, then "big-endian", and otherwise the host's compile-time byte order. device_is_big_endian() is not used here because it ignores "little-endian" and introduces "native-endian" semantics, which would diverge from the binding. - The platform-resource fallback for an un-mapped reg keeps its "if (!mux->data.reg)" guard so a platdata user that supplies a pre-ioremapped reg through struct i2c_mux_reg_platform_data is not clobbered. The OF-only of_address_to_resource() translation in the old probe_dt() is dropped because the same address is available from the platform_device resource table on both OF and ACPI, and the existing fallback in probe() ioremaps it. Signed-off-by: Abdurrahman Hussain Tested-by tags from anyone running this driver on a current DT --- Convert the device-tree parsing path in i2c-mux-reg to the generic fwnode/device property accessors so the driver can be probed on ACPI and swnode platforms in addition to OF. Changes in v2 (per Peter's review of v1 [1]): - Restore the three-way endian-property fallback verbatim. v1 used device_is_big_endian(), which ignores "little-endian" and adds "native-endian" semantics =E2=80=94 a binding-visible behaviour change on big-endian hosts that did not specify the property. v2 keeps the original logic ("little-endian" wins, then "big-endian", else the host's compile-time byte order), expressed via device_property_read_bool() instead of of_property_read_bool(). - Restore the "if (!mux->data.reg)" guard around devm_platform_get_and_ioremap_resource() in probe(). v1 dropped it and would have clobbered the pre-ioremapped reg supplied by a platdata user through struct i2c_mux_reg_platform_data. - Restore the dev_err_probe() wrapper at the probe_fw() call site so the silent error paths in the helper still produce a dmesg line on failure. - Rewrite the changelog to enumerate the accessor translations, the new ACPI child-node handling via acpi_get_local_address(), and the behavioural preservations above. Tested locally on the ACPI/non-OF code path I added. I do not have any of the in-tree DT users of i2c-mux-reg on hand (the existing boards are on PowerPC and SH), so I have not been able to verify that the OF path is byte-for-byte unchanged in behaviour at runtime. Tested-by tags from anyone running this driver on a current DT board would be very welcome. [1] https://lore.kernel.org/r/20260115003523.26660-1-abdurrahman@nexthop.ai --- drivers/i2c/muxes/i2c-mux-reg.c | 84 +++++++++++++++----------------------= ---- 1 file changed, 31 insertions(+), 53 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-reg.c b/drivers/i2c/muxes/i2c-mux-re= g.c index 1e566ea92bc9..5a7ee763606c 100644 --- a/drivers/i2c/muxes/i2c-mux-reg.c +++ b/drivers/i2c/muxes/i2c-mux-reg.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -75,83 +74,64 @@ static int i2c_mux_reg_deselect(struct i2c_mux_core *mu= xc, u32 chan) return 0; } =20 -#ifdef CONFIG_OF -static int i2c_mux_reg_probe_dt(struct regmux *mux, - struct platform_device *pdev) +static int i2c_mux_reg_probe_fw(struct regmux *mux, struct device *dev) { - struct device_node *np =3D pdev->dev.of_node; - struct device_node *adapter_np, *child; + struct fwnode_handle *fwnode, *child; struct i2c_adapter *adapter; - struct resource res; unsigned *values; - int i =3D 0; + int ret, i =3D 0; =20 - if (!np) + if (!dev_fwnode(dev)) return -ENODEV; =20 - adapter_np =3D of_parse_phandle(np, "i2c-parent", 0); - if (!adapter_np) { - dev_err(&pdev->dev, "Cannot parse i2c-parent\n"); + fwnode =3D fwnode_find_reference(dev_fwnode(dev), "i2c-parent", 0); + if (IS_ERR(fwnode)) { + dev_err(dev, "missing 'i2c-parent' property\n"); return -ENODEV; } - adapter =3D of_find_i2c_adapter_by_node(adapter_np); - of_node_put(adapter_np); + + adapter =3D i2c_get_adapter_by_fwnode(fwnode); + fwnode_handle_put(fwnode); if (!adapter) return -EPROBE_DEFER; =20 mux->data.parent =3D i2c_adapter_id(adapter); put_device(&adapter->dev); =20 - mux->data.n_values =3D of_get_child_count(np); - if (of_property_read_bool(np, "little-endian")) { - mux->data.little_endian =3D true; - } else if (of_property_read_bool(np, "big-endian")) { - mux->data.little_endian =3D false; - } else { -#if defined(__BYTE_ORDER) ? __BYTE_ORDER =3D=3D __LITTLE_ENDIAN : \ - defined(__LITTLE_ENDIAN) + mux->data.n_values =3D device_get_child_node_count(dev); + if (device_property_read_bool(dev, "little-endian")) mux->data.little_endian =3D true; -#elif defined(__BYTE_ORDER) ? __BYTE_ORDER =3D=3D __BIG_ENDIAN : \ - defined(__BIG_ENDIAN) + else if (device_property_read_bool(dev, "big-endian")) mux->data.little_endian =3D false; -#else -#error Endianness not defined? -#endif - } - mux->data.write_only =3D of_property_read_bool(np, "write-only"); + else + mux->data.little_endian =3D IS_ENABLED(CONFIG_CPU_LITTLE_ENDIAN); + mux->data.write_only =3D device_property_read_bool(dev, "write-only"); =20 - values =3D devm_kcalloc(&pdev->dev, - mux->data.n_values, sizeof(*mux->data.values), + values =3D devm_kcalloc(dev, mux->data.n_values, sizeof(*mux->data.values= ), GFP_KERNEL); if (!values) return -ENOMEM; =20 - for_each_child_of_node(np, child) { - of_property_read_u32(child, "reg", values + i); + device_for_each_child_node(dev, child) { + if (is_of_node(child)) { + fwnode_property_read_u32(child, "reg", values + i); + } else if (is_acpi_node(child)) { + ret =3D acpi_get_local_address(ACPI_HANDLE_FWNODE(child), values + i); + if (ret) { + fwnode_handle_put(child); + return dev_err_probe(dev, ret, "Cannot get address\n"); + } + } + i++; } mux->data.values =3D values; =20 - if (!of_property_read_u32(np, "idle-state", &mux->data.idle)) + if (!device_property_read_u32(dev, "idle-state", &mux->data.idle)) mux->data.idle_in_use =3D true; =20 - /* map address from "reg" if exists */ - if (of_address_to_resource(np, 0, &res) =3D=3D 0) { - mux->data.reg_size =3D resource_size(&res); - mux->data.reg =3D devm_ioremap_resource(&pdev->dev, &res); - if (IS_ERR(mux->data.reg)) - return PTR_ERR(mux->data.reg); - } - - return 0; -} -#else -static int i2c_mux_reg_probe_dt(struct regmux *mux, - struct platform_device *pdev) -{ return 0; } -#endif =20 static int i2c_mux_reg_probe(struct platform_device *pdev) { @@ -169,10 +149,10 @@ static int i2c_mux_reg_probe(struct platform_device *= pdev) memcpy(&mux->data, dev_get_platdata(&pdev->dev), sizeof(mux->data)); } else { - ret =3D i2c_mux_reg_probe_dt(mux, pdev); + ret =3D i2c_mux_reg_probe_fw(mux, &pdev->dev); if (ret < 0) return dev_err_probe(&pdev->dev, ret, - "Error parsing device tree"); + "Error parsing firmware description\n"); } =20 parent =3D i2c_get_adapter(mux->data.parent); @@ -180,8 +160,6 @@ static int i2c_mux_reg_probe(struct platform_device *pd= ev) return -EPROBE_DEFER; =20 if (!mux->data.reg) { - dev_info(&pdev->dev, - "Register not set, using platform resource\n"); mux->data.reg =3D devm_platform_get_and_ioremap_resource(pdev, 0, &res); if (IS_ERR(mux->data.reg)) { ret =3D PTR_ERR(mux->data.reg); --- base-commit: 0031c06807cfa8aa51a759ff8aa09e1aa48149af change-id: 20260305-i2c-mux-reg-552203da8564 Best regards, -- =20 Abdurrahman Hussain