Skip to contentSkip to conversation

mfd: core: Support auxiliary device

PATCH Superseded Raag Jadav 3 participants 4 messages Apr 18, 2025 – Apr 20, 2025 Multifunction devices (MFD)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Raag Jadav

author
#0 lore raw

PATCH v3 1/1 mfd: core: Support auxiliary device

Extend MFD subsystem to support auxiliary child device. This is useful for MFD usecases where parent device is on a discoverable bus and doesn't fit into the platform device criteria. Purpose of this implementation is to provide discoverable MFDs just enough infrastructure to register independent child devices with their own memory and interrupt resources without abusing the platform device.

Current support is limited to just PCI type MFDs, but this can be further extended to support other types like USB in the future.

---

v2: Introduce a shared struct mfd_aux_device
Introduce MFD_AUX_TYPE flag for auxiliary device opt-in

v3: Fix device_type ABI breakage (Andy)
Aesthetic adjustments (Andy)

PS: I'm leaning towards leaving the ioremap or regmap complexity out of MFD core and think that we should enforce child devices to not overlap.

If there's a need to handle common register access by parent device, then I think it warrants its own driver which adds auxiliary devices along with a custom interface to communicate with them without involving MFD core.

 drivers/mfd/Kconfig      |   1 +
 drivers/mfd/mfd-core.c   | 123 ++++++++++++++++++++++++++++++++++++---
 include/linux/mfd/aux.h  |  30 ++++++++++
 include/linux/mfd/core.h |   3 +
 4 files changed, 149 insertions(+), 8 deletions(-)
 create mode 100644 include/linux/mfd/aux.h
drivers/mfd/Kconfig +1 -0
index 93773201a517..8c8e6797307c 100644
@@ -8,6 +8,7 @@ menu "Multifunction device drivers"
 
 config MFD_CORE
 	tristate
+	select AUXILIARY_BUS
 	select IRQ_DOMAIN
 	default n
 
drivers/mfd/mfd-core.c +115 -8

161 lines not on this page · raw message

include/linux/mfd/aux.h new file +30 -0
new file mode 100644
index 000000000000..826a0a05e9e9
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * MFD auxiliary device
+ *
+ * Copyright (c) 2025 Raag Jadav <[email protected]>
+ */
+
+#ifndef MFD_AUX_H
+#define MFD_AUX_H
+
+#include <linux/auxiliary_bus.h>
+#include <linux/container_of.h>
+#include <linux/ioport.h>
+
+/*
+ * Common structure between MFD parent and auxiliary child device.
+ * To be used by leaf drivers to access child device resources.
+ */
+struct mfd_aux_device {
+	struct auxiliary_device auxdev;
+	struct resource	mem;
+	struct resource	irq;
+	/* Place holder for other types */
+	struct resource	ext;
+};
+
+#define auxiliary_dev_to_mfd_aux_dev(auxiliary_dev) \
+	container_of(auxiliary_dev, struct mfd_aux_device, auxdev)
+
+#endif
include/linux/mfd/core.h +3 -0
index faeea7abd688..96f6ff98a111 100644
@@ -12,6 +12,9 @@
 
 #include <linux/platform_device.h>
 
+/* TODO: Convert the platform device abusers and remove this flag */
+#define MFD_AUX_TYPE	BIT(31)
+
 #define MFD_RES_SIZE(arr) (sizeof(arr) / sizeof(struct resource))
 
 #define MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg, _use_of_reg, _match) \
Signature · 1 line
2.34.1
#1 lore raw
kernel test robot noticed the following build warnings:

Hi Raag,

kernel test robot noticed the following build warnings:

[auto build test WARNING on lee-mfd/for-mfd-next]
[also build test WARNING on lee-mfd/for-mfd-fixes linus/master v6.15-rc2 next-20250417] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Raag-Jadav/mfd-core-Support-auxiliary-device/20250418-203658
base:   https://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git for-mfd-next
patch link:    https://lore.kernel.org/r/20250418123433.2586383-1-raag.jadav%40intel.com
patch subject: [PATCH v3] mfd: core: Support auxiliary device
config: riscv-randconfig-001-20250418 (https://download.01.org/0day-ci/archive/20250418/[email protected]/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project f819f46284f2a79790038e1f6649172789734ae8)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250418/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/mfd/mfd-core.c:389:31: warning: result of comparison of constant 2147483648 with expression of type 'int' is always false [-Wtautological-constant-out-of-range-compare]
     389 |         if (dev_is_pci(parent) && id == MFD_AUX_TYPE)
         |                                   ~~ ^  ~~~~~~~~~~~~

1 warning generated.

vim +/int +389 drivers/mfd/mfd-core.c

384
385 static int mfd_add_device(struct device *parent, int id, const struct mfd_cell *cells,
386 struct resource *mem_base, int irq_base, struct irq_domain *domain)
387 {
388 /* TODO: Convert the platform device abusers and remove this flag */

 > 389		if (dev_is_pci(parent) && id == MFD_AUX_TYPE)

390 return mfd_add_auxiliary_device(parent, id, cells, mem_base, irq_base, domain);
391
392 return mfd_add_platform_device(parent, id, cells, mem_base, irq_base, domain);
393 }
394

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#2 lore raw
In reply to Raag Jadav
Quoted 10 lines · Raag Jadav

Extend MFD subsystem to support auxiliary child device. This is useful for MFD usecases where parent device is on a discoverable bus and doesn't fit into the platform device criteria. Purpose of this implementation is to provide discoverable MFDs just enough infrastructure to register independent child devices with their own memory and interrupt resources without abusing the platform device.

Current support is limited to just PCI type MFDs, but this can be further extended to support other types like USB in the future.

 create mode 100644 include/linux/mfd/aux.h

...

drivers/mfd/Kconfig menu "Multifunction device drivers"

Quoted 6 lines

config MFD_CORE

drivers/mfd/Kconfig +1 -0
 	tristate
+	select AUXILIARY_BUS
 	select IRQ_DOMAIN
 
 	default n

Can be dropped. It's the default 'default' and with user invisible configuration, it makes even less sense.

...

include/linux/mfd/aux.h line 24

Quoted 10 lines
include/linux/mfd/aux.h new file +10 -0
+/*
+ * Common structure between MFD parent and auxiliary child device.
+ * To be used by leaf drivers to access child device resources.
+ */
+struct mfd_aux_device {
+	struct auxiliary_device auxdev;
+	struct resource	mem;
+	struct resource	irq;
+	/* Place holder for other types */
+	struct resource	ext;

I don't like it. It's no-scalable solution, just make it VLA. Each resource already has type in case one needs to extract an exact one, also this won't work in case of the two resources for memory or IRQ needed.

Quoted 1 line

+};

...

include/linux/mfd/core.h line 16

Quoted 2 lines
include/linux/mfd/core.h +2 -0
+/* TODO: Convert the platform device abusers and remove this flag */
+#define MFD_AUX_TYPE	BIT(31)

Yeah, LKP wants this to be signed... Or 'id' to be unsigned.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#3 lore raw
Quoted 18 lines · Andy Shevchenko
Quoted 9 lines · Raag Jadav

Extend MFD subsystem to support auxiliary child device. This is useful for MFD usecases where parent device is on a discoverable bus and doesn't fit into the platform device criteria. Purpose of this implementation is to provide discoverable MFDs just enough infrastructure to register independent child devices with their own memory and interrupt resources without abusing the platform device.

Current support is limited to just PCI type MFDs, but this can be further extended to support other types like USB in the future.

...

Quoted 4 lines

config MFD_CORE

drivers/mfd/Kconfig +1 -0
 	tristate
+	select AUXILIARY_BUS
 	select IRQ_DOMAIN
Quoted 4 lines
Quoted 1 line

default n

Can be dropped. It's the default 'default' and with user invisible configuration, it makes even less sense.

Sure.

Quoted 6 lines
Quoted 6 lines
include/linux/mfd/aux.h new file +6 -0
+/*
+ * Common structure between MFD parent and auxiliary child device.
+ * To be used by leaf drivers to access child device resources.
+ */
+struct mfd_aux_device {
+	struct auxiliary_device auxdev;
Quoted 8 lines

include/linux/mfd/aux.h line 24

Quoted 4 lines
include/linux/mfd/aux.h new file +4 -0
+	struct resource	mem;
+	struct resource	irq;
+	/* Place holder for other types */
+	struct resource	ext;

I don't like it. It's no-scalable solution, just make it VLA. Each resource already has type in case one needs to extract an exact one, also this won't work in case of the two resources for memory or IRQ needed.

Agree, but is it worth introducing a whole new set of get_resource() and friends? I'm not sure if the maintainers will be okay with it.

Quoted 4 lines

include/linux/mfd/core.h line 16

Quoted 2 lines
include/linux/mfd/core.h +2 -0
+/* TODO: Convert the platform device abusers and remove this flag */
+#define MFD_AUX_TYPE	BIT(31)

Yeah, LKP wants this to be signed... Or 'id' to be unsigned.

I'll revert it back to INT_MIN, a specific number would rather become more questionable.

Raag