From: a0282524688@gmail.com
To: lee@kernel.org, Ming Yu <tmyu0@nuvoton.com>
Cc: linux-kernel@vger.kernel.org, Ming Yu <a0282524688@gmail.com>,
mfd@lists.linux.dev
Subject: [PATCH v10 10/13] mfd: nct6694: Extract core device management into a separate module
Date: Wed, 18 Nov 2026 16:16:21 +0800 [thread overview]
Message-ID: <20261118081625.2399247-11-a0282524688@gmail.com> (raw)
In-Reply-To: <20261118081625.2399247-1-a0282524688@gmail.com>
From: Ming Yu <a0282524688@gmail.com>
Move the IRQ domain and IDA handling, which do not depend on the
transport, from the USB driver into a new nct6694-core module. The
core retrieves struct nct6694 from the driver data of the transport
device, and the transport keeps registering its own MFD cells.
The USB driver now creates the IRQ domain before submitting the
interrupt URB, and kills the URB before the domain is removed.
No functional change.
Signed-off-by: Ming Yu <a0282524688@gmail.com>
---
Changes in v10:
- Rebased on top of "mfd: nct6694: Drop the unused IRQ enable mask";
the irq_chip moved to nct6694-core.c no longer has
.irq_enable/.irq_disable.
Changes in v9:
- None.
Changes in v8:
- Pass only the transport device to the core and retrieve struct nct6694
from its driver data.
- Let the transport register its own MFD cells.
- Rename nct6694_core_{probe,remove}() to nct6694_device_{init,exit}().
- Return -ENOMEM when the IRQ domain cannot be created.
- Folded in the v7 patch "Submit the interrupt URB after the core is
registered", whose issue no longer arises.
- Moved the Kconfig split to a later patch.
Changes in v7:
- None.
Changes in v6:
- Reordered to sit before the transport-abstraction patch; no functional
change.
Changes in v5:
- Split from the monolithic v4 patch to follow the single logical change
principle.
MAINTAINERS | 2 +-
drivers/mfd/Makefile | 1 +
drivers/mfd/nct6694-core.c | 85 +++++++++++++++++++++++++++++++++++++
drivers/mfd/nct6694-usb.c | 73 ++++++-------------------------
include/linux/mfd/nct6694.h | 3 ++
5 files changed, 104 insertions(+), 60 deletions(-)
create mode 100644 drivers/mfd/nct6694-core.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 62517279b5f8..69c31fe71f81 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -20081,7 +20081,7 @@ S: Supported
F: drivers/gpio/gpio-nct6694.c
F: drivers/hwmon/nct6694-hwmon.c
F: drivers/i2c/busses/i2c-nct6694.c
-F: drivers/mfd/nct6694-usb.c
+F: drivers/mfd/nct6694-*.c
F: drivers/net/can/usb/nct6694_canfd.c
F: drivers/rtc/rtc-nct6694.c
F: drivers/watchdog/nct6694_wdt.c
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index af81e00b3573..20a5de726071 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -124,6 +124,7 @@ obj-$(CONFIG_MFD_MC13XXX_I2C) += mc13xxx-i2c.o
obj-$(CONFIG_MFD_PF1550) += pf1550.o
+obj-$(CONFIG_MFD_NCT6694) += nct6694-core.o
obj-$(CONFIG_MFD_NCT6694) += nct6694-usb.o
obj-$(CONFIG_MFD_CORE) += mfd-core.o
diff --git a/drivers/mfd/nct6694-core.c b/drivers/mfd/nct6694-core.c
new file mode 100644
index 000000000000..438f391a7bcd
--- /dev/null
+++ b/drivers/mfd/nct6694-core.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Nuvoton Technology Corp.
+ *
+ * Nuvoton NCT6694 core driver providing the IRQ domain and IDA pools
+ * shared by all transport drivers.
+ */
+
+#include <linux/device.h>
+#include <linux/idr.h>
+#include <linux/irq.h>
+#include <linux/irqdomain.h>
+#include <linux/mfd/nct6694.h>
+#include <linux/module.h>
+
+static const struct irq_chip nct6694_irq_chip = {
+ .name = "nct6694-irq",
+ .flags = IRQCHIP_SKIP_SET_WAKE,
+};
+
+static int nct6694_irq_domain_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
+{
+ struct nct6694 *ddata = d->host_data;
+
+ irq_set_chip_data(irq, ddata);
+ irq_set_chip_and_handler(irq, &nct6694_irq_chip, handle_simple_irq);
+
+ return 0;
+}
+
+static void nct6694_irq_domain_unmap(struct irq_domain *d, unsigned int irq)
+{
+ irq_set_chip_and_handler(irq, NULL, NULL);
+ irq_set_chip_data(irq, NULL);
+}
+
+static const struct irq_domain_ops nct6694_irq_domain_ops = {
+ .map = nct6694_irq_domain_map,
+ .unmap = nct6694_irq_domain_unmap,
+};
+
+/**
+ * nct6694_device_init() - Set up the resources shared by all transports
+ * @dev: transport device whose driver data points to the struct nct6694
+ *
+ * Return: 0 on success or negative errno on failure.
+ */
+int nct6694_device_init(struct device *dev)
+{
+ struct nct6694 *ddata = dev_get_drvdata(dev);
+
+ ida_init(&ddata->gpio_ida);
+ ida_init(&ddata->i2c_ida);
+ ida_init(&ddata->canfd_ida);
+ ida_init(&ddata->wdt_ida);
+
+ ddata->domain = irq_domain_create_simple(NULL, NCT6694_NR_IRQS, 0,
+ &nct6694_irq_domain_ops,
+ ddata);
+ if (!ddata->domain)
+ return -ENOMEM;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(nct6694_device_init);
+
+/**
+ * nct6694_device_exit() - Release the resources set up by nct6694_device_init()
+ * @dev: transport device passed to nct6694_device_init()
+ */
+void nct6694_device_exit(struct device *dev)
+{
+ struct nct6694 *ddata = dev_get_drvdata(dev);
+
+ ida_destroy(&ddata->wdt_ida);
+ ida_destroy(&ddata->canfd_ida);
+ ida_destroy(&ddata->i2c_ida);
+ ida_destroy(&ddata->gpio_ida);
+ irq_domain_remove(ddata->domain);
+}
+EXPORT_SYMBOL_GPL(nct6694_device_exit);
+
+MODULE_DESCRIPTION("Nuvoton NCT6694 core driver");
+MODULE_AUTHOR("Ming Yu <tmyu0@nuvoton.com>");
+MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/nct6694-usb.c b/drivers/mfd/nct6694-usb.c
index 10d08ab50e16..8f9c7b7d9471 100644
--- a/drivers/mfd/nct6694-usb.c
+++ b/drivers/mfd/nct6694-usb.c
@@ -11,7 +11,6 @@
#include <linux/bits.h>
#include <linux/interrupt.h>
-#include <linux/idr.h>
#include <linux/irq.h>
#include <linux/irqdomain.h>
#include <linux/kernel.h>
@@ -283,32 +282,6 @@ static void nct6694_usb_int_callback(struct urb *urb)
dev_warn(ddata->dev, "Failed to resubmit urb, status %pe", ERR_PTR(ret));
}
-static const struct irq_chip nct6694_irq_chip = {
- .name = "nct6694-irq",
- .flags = IRQCHIP_SKIP_SET_WAKE,
-};
-
-static int nct6694_irq_domain_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
-{
- struct nct6694 *ddata = d->host_data;
-
- irq_set_chip_data(irq, ddata);
- irq_set_chip_and_handler(irq, &nct6694_irq_chip, handle_simple_irq);
-
- return 0;
-}
-
-static void nct6694_irq_domain_unmap(struct irq_domain *d, unsigned int irq)
-{
- irq_set_chip_and_handler(irq, NULL, NULL);
- irq_set_chip_data(irq, NULL);
-}
-
-static const struct irq_domain_ops nct6694_irq_domain_ops = {
- .map = nct6694_irq_domain_map,
- .unmap = nct6694_irq_domain_unmap,
-};
-
static int nct6694_usb_probe(struct usb_interface *iface,
const struct usb_device_id *id)
{
@@ -353,26 +326,12 @@ static int nct6694_usb_probe(struct usb_interface *iface,
return -ENOMEM;
ddata = &usb_data->core;
-
- ddata->domain = irq_domain_create_simple(NULL, NCT6694_NR_IRQS, 0,
- &nct6694_irq_domain_ops,
- ddata);
- if (!ddata->domain) {
- ret = -ENODEV;
- goto err_urb;
- }
-
ddata->dev = dev;
usb_data->usb_dev = usb_dev;
- ida_init(&ddata->gpio_ida);
- ida_init(&ddata->i2c_ida);
- ida_init(&ddata->canfd_ida);
- ida_init(&ddata->wdt_ida);
-
ret = devm_mutex_init(dev, &usb_data->access_lock);
if (ret)
- goto err_ida;
+ goto err_free_urb;
int_pipe = usb_rcvintpipe(usb_dev, NCT6694_INT_IN_EP);
usb_fill_int_urb(usb_data->int_urb, usb_dev, int_pipe,
@@ -380,27 +339,27 @@ static int nct6694_usb_probe(struct usb_interface *iface,
nct6694_usb_int_callback, ddata,
usb_pipe_endpoint(usb_dev, int_pipe)->desc.bInterval);
- ret = usb_submit_urb(usb_data->int_urb, GFP_KERNEL);
+ usb_set_intfdata(iface, ddata);
+
+ ret = nct6694_device_init(dev);
if (ret)
- goto err_ida;
+ goto err_free_urb;
- usb_set_intfdata(iface, ddata);
+ ret = usb_submit_urb(usb_data->int_urb, GFP_KERNEL);
+ if (ret)
+ goto err_device_exit;
ret = mfd_add_hotplug_devices(dev, nct6694_usb_devs, ARRAY_SIZE(nct6694_usb_devs));
if (ret)
- goto err_mfd;
+ goto err_kill_urb;
return 0;
-err_mfd:
+err_kill_urb:
usb_kill_urb(usb_data->int_urb);
-err_ida:
- ida_destroy(&ddata->wdt_ida);
- ida_destroy(&ddata->canfd_ida);
- ida_destroy(&ddata->i2c_ida);
- ida_destroy(&ddata->gpio_ida);
- irq_domain_remove(ddata->domain);
-err_urb:
+err_device_exit:
+ nct6694_device_exit(dev);
+err_free_urb:
usb_free_urb(usb_data->int_urb);
return ret;
}
@@ -412,11 +371,7 @@ static void nct6694_usb_disconnect(struct usb_interface *iface)
mfd_remove_devices(ddata->dev);
usb_kill_urb(usb_data->int_urb);
- ida_destroy(&ddata->wdt_ida);
- ida_destroy(&ddata->canfd_ida);
- ida_destroy(&ddata->i2c_ida);
- ida_destroy(&ddata->gpio_ida);
- irq_domain_remove(ddata->domain);
+ nct6694_device_exit(ddata->dev);
usb_free_urb(usb_data->int_urb);
}
diff --git a/include/linux/mfd/nct6694.h b/include/linux/mfd/nct6694.h
index 24cfe6a03ef0..26e9034daa53 100644
--- a/include/linux/mfd/nct6694.h
+++ b/include/linux/mfd/nct6694.h
@@ -89,6 +89,9 @@ struct nct6694 {
struct irq_domain *domain;
};
+int nct6694_device_init(struct device *dev);
+void nct6694_device_exit(struct device *dev);
+
int nct6694_usb_read_msg(struct nct6694 *ddata,
const struct nct6694_cmd_header *cmd_hd,
void *buf);
--
2.34.1
next prev parent reply other threads:[~2026-11-18 8:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 8:16 [PATCH v10 00/13] mfd: nct6694: Refactor transport layer and add HIF (eSPI) support a0282524688
2026-11-18 8:16 ` [PATCH v10 01/13] mfd: nct6694: Validate the USB endpoints a0282524688
2026-11-18 8:16 ` [PATCH v10 02/13] mfd: nct6694: Check the length of received USB packets a0282524688
2026-11-18 8:16 ` [PATCH v10 03/13] mfd: nct6694: Ignore interrupts without a mapping a0282524688
2026-11-18 8:16 ` [PATCH v10 04/13] mfd: nct6694: Transfer data packets via a dedicated buffer a0282524688
2026-11-18 8:16 ` [PATCH v10 05/13] mfd: nct6694: Drop the unused IRQ enable mask a0282524688
2026-11-18 8:16 ` [PATCH v10 06/13] mfd: nct6694: Move module type macros to shared header a0282524688
2026-11-18 8:16 ` [PATCH v10 07/13] mfd: nct6694: Refactor USB-specific data into nct6694_usb_data a0282524688
2026-11-18 8:16 ` [PATCH v10 08/13] mfd: nct6694: Rename USB transport functions with _usb_ prefix a0282524688
2026-11-18 8:16 ` [PATCH v10 09/13] mfd: nct6694: Rename driver to nct6694-usb a0282524688
2026-11-18 8:16 ` a0282524688 [this message]
2026-11-18 8:16 ` [PATCH v10 11/13] mfd: nct6694: Introduce regmap-based transport abstraction a0282524688
2026-11-18 8:16 ` [PATCH v10 12/13] mfd: nct6694: Add a Kconfig symbol for the USB transport a0282524688
2026-11-18 8:16 ` [PATCH v10 13/13] mfd: nct6694: Add Host Interface (HIF) eSPI transport driver a0282524688
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118081625.2399247-11-a0282524688@gmail.com \
--to=a0282524688@gmail.com \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mfd@lists.linux.dev \
--cc=tmyu0@nuvoton.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®