Skip to content

Commit

Permalink
mfd: syscon: Restore device_node_to_regmap() for non-syscon nodes
Browse files Browse the repository at this point in the history
Commit ba5095e ("mfd: syscon: Allow syscon nodes without a
"syscon" compatible") broke drivers which call device_node_to_regmap()
on nodes without a "syscon" compatible. Restore the prior behavior for
device_node_to_regmap().

This also makes using device_node_to_regmap() incompatible with
of_syscon_register_regmap() again, so add kerneldoc for
device_node_to_regmap() and syscon_node_to_regmap() to make it clear
how and when each one should be used.

Fixes: ba5095e ("mfd: syscon: Allow syscon nodes without a "syscon" compatible")
Reported-by: Vaishnav Achath <[email protected]>
Signed-off-by: Rob Herring (Arm) <[email protected]>
Reviewed-by: Daniel Golle <[email protected]>
Reviewed-by: AngeloGioacchino Del Regno <[email protected]>
Tested-by: Chen-Yu Tsai <[email protected]>
Tested-by: Nishanth Menon <[email protected]>
Tested-by: Daniel Golle <[email protected]>
Tested-by: Frank Wunderlich <[email protected]>
Tested-by: Dhruva Gole <[email protected]>
Tested-by: Nícolas F. R. A. Prado <[email protected]>
Tested-by: AngeloGioacchino Del Regno <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Lee Jones <[email protected]>
  • Loading branch information
robherring authored and lag-linaro committed Feb 11, 2025
1 parent 2014c95 commit 5728c92
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions drivers/mfd/syscon.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
}

static struct regmap *device_node_get_regmap(struct device_node *np,
bool create_regmap,
bool check_res)
{
struct syscon *entry, *syscon = NULL;
Expand All @@ -172,7 +173,7 @@ static struct regmap *device_node_get_regmap(struct device_node *np,
}

if (!syscon) {
if (of_device_is_compatible(np, "syscon"))
if (create_regmap)
syscon = of_syscon_register(np, check_res);
else
syscon = ERR_PTR(-EINVAL);
Expand Down Expand Up @@ -233,15 +234,37 @@ int of_syscon_register_regmap(struct device_node *np, struct regmap *regmap)
}
EXPORT_SYMBOL_GPL(of_syscon_register_regmap);

/**
* device_node_to_regmap() - Get or create a regmap for specified device node
* @np: Device tree node
*
* Get a regmap for the specified device node. If there's not an existing
* regmap, then one is instantiated. This function should not be used if the
* device node has a custom regmap driver or has resources (clocks, resets) to
* be managed. Use syscon_node_to_regmap() instead for those cases.
*
* Return: regmap ptr on success, negative error code on failure.
*/
struct regmap *device_node_to_regmap(struct device_node *np)
{
return device_node_get_regmap(np, false);
return device_node_get_regmap(np, true, false);
}
EXPORT_SYMBOL_GPL(device_node_to_regmap);

/**
* syscon_node_to_regmap() - Get or create a regmap for specified syscon device node
* @np: Device tree node
*
* Get a regmap for the specified device node. If there's not an existing
* regmap, then one is instantiated if the node is a generic "syscon". This
* function is safe to use for a syscon registered with
* of_syscon_register_regmap().
*
* Return: regmap ptr on success, negative error code on failure.
*/
struct regmap *syscon_node_to_regmap(struct device_node *np)
{
return device_node_get_regmap(np, true);
return device_node_get_regmap(np, of_device_is_compatible(np, "syscon"), true);
}
EXPORT_SYMBOL_GPL(syscon_node_to_regmap);

Expand Down

0 comments on commit 5728c92

Please sign in to comment.