[PATCH 1/2] mfd: core: Support multiple OF child devices of the same type

From: Robert Hancock
Date: Tue Jun 04 2019 - 19:04:25 EST


Previously the MFD core supported assigning OF nodes to created MFD
devices, but relied solely on matching the of_compatible string. This
would result in devices being potentially assigned the wrong node if
there are multiple devices with the same compatible string within a
multifunction device.

Add support for matching the full name of the node in the MFD cell
definition, so that we can match against a specific instance of a
device. If this is not specified, we match just based on the
compatible string, as before.

Signed-off-by: Robert Hancock <hancock@xxxxxxxxxxxxx>
---
drivers/mfd/mfd-core.c | 5 ++++-
include/linux/mfd/core.h | 3 +++
2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index 1ade4c8..74bc895 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -177,7 +177,10 @@ static int mfd_add_device(struct device *parent, int id,

if (parent->of_node && cell->of_compatible) {
for_each_child_of_node(parent->of_node, np) {
- if (of_device_is_compatible(np, cell->of_compatible)) {
+ if (of_device_is_compatible(np, cell->of_compatible) &&
+ (!cell->of_full_name ||
+ !strcmp(cell->of_full_name,
+ of_node_full_name(np)))) {
pdev->dev.of_node = np;
break;
}
diff --git a/include/linux/mfd/core.h b/include/linux/mfd/core.h
index 99c0395..470f6cb 100644
--- a/include/linux/mfd/core.h
+++ b/include/linux/mfd/core.h
@@ -55,6 +55,9 @@ struct mfd_cell {
*/
const char *of_compatible;

+ /* Optionally match against a specific device of a given type */
+ const char *of_full_name;
+
/* Matches ACPI */
const struct mfd_cell_acpi_match *acpi_match;

--
1.8.3.1