Re: [PATCH v2 2/3] iio: adc: aspeed: Use syscon phandle for trimming data when available
From: Andy Shevchenko
Date: Fri Oct 02 2026 - 04:34:41 EST
On Thu, Oct 01, 2026 at 05:50:37PM +0800, Billy Tsai wrote:
> aspeed_adc_set_trim_data() locates the SCU holding the ADC's
> reference-voltage trimming data with of_find_node_by_name(NULL,
> "syscon"), a global search that matches the first device-tree node
> named "syscon" regardless of which SCU instance it actually is.
>
> On AST2700, which splits its SCU into "syscon0" (soc0) and "syscon1"
> (soc1), both nodes share the same node name "syscon" and only differ
> by label and unit address, so the lookup always resolves to syscon0
> even though the ADC's trimming data lives in syscon1.
>
> Use the new "aspeed,trim-syscon" phandle property when present to look
> up the correct regmap directly, falling back to the old global by-name
> search when the property is absent so existing device trees keep
> working.
...
> - syscon = of_find_node_by_name(NULL, "syscon");
> - if (syscon == NULL) {
> - dev_warn(data->dev, "Couldn't find syscon node\n");
> - return -EOPNOTSUPP;
> + scu = syscon_regmap_lookup_by_phandle_optional(data->dev->of_node, "aspeed,trim-syscon");
Do not dereference of_node, use dev_of_node(), it will help in the future
if we want to reorganise firmware nodes in the struct device.
> + if (!scu) {
> + /*
> + * No "aspeed,trim-syscon" phandle: either a single-SCU SoC, or a DTB
> + * predating the property. Fall back to the old global
> + * by-name lookup for backward compatibility.
> + */
So, why not doing
struct device_node *np;
const char *propname;
...
np = dev_of_node(data->dev);
propname = "aspeed,trim-syscon";
if (of_property_present(np, propname)) {
scu = syscon_regmap_lookup_by_phandle(np, propname);
...
}
...
?
> + syscon = of_find_node_by_name(NULL, "syscon");
> + if (syscon == NULL) {
> + dev_warn(data->dev, "Couldn't find syscon node\n");
> + return -EOPNOTSUPP;
> + }
> + scu = syscon_node_to_regmap(syscon);
> + of_node_put(syscon);
> }
> - scu = syscon_node_to_regmap(syscon);
> - of_node_put(syscon);
> if (IS_ERR(scu)) {
> dev_warn(data->dev, "Failed to get syscon regmap\n");
> return -EOPNOTSUPP;
--
With Best Regards,
Andy Shevchenko