mfd: nct6694: Refactor transport layer and add HIF (eSPI) support
Subsystems (9)
v10 cover mfd: nct6694: Refactor transport layer and add HIF (eSPI) support
From: Ming Yu <[email protected]>
The Nuvoton NCT6694 is a peripheral expander that provides GPIO, I2C, CAN-FD, Watchdog, HWMON, PWM, and RTC sub-devices. Currently, the driver only supports USB as the host transport interface.
This series refactors the NCT6694 MFD driver to support multiple transport backends and adds a Host Interface (HIF) transport driver that communicates over eSPI using Super-I/O shared memory.
Patches 1-5 fix pre-existing bugs in the current driver. They carry a Fixes tag and can be picked up independently of the rest of the series.
Patches 6-12 isolate the USB transport, extract the transport-agnostic core into nct6694-core.c and wrap the firmware command interface behind regmap, so that the sub-device drivers no longer depend on the transport. Patch 13 adds the HIF transport on top.
Changes since version 9:
- Added "mfd: nct6694: Drop the unused IRQ enable mask", which removes the .irq_enable/.irq_disable callbacks that took a spinlock_t under the raw desc->lock (reported by Sashiko on v9 06/12 and 09/12), and rebased "Refactor USB-specific data into nct6694_usb_data" and "Extract core device management into a separate module" on top of it.
- HIF: commented that a read of a SET register passes val_buf as the write-then-read request.
- Used devm_kzalloc_obj() for the new allocations.
- Rebased on 20eef29b7c84 (after v7.4-rc3), which converts the driver to devm_kzalloc_obj().
Changes since version 8:
- Dropped "gpio: nct6694: Mark the GPIO controller as sleeping", which has been applied by Bartosz to the GPIO tree:
https://git.kernel.org/brgl/c/fcbc48dc650d2f58bfe19c4486830de0e9cad62e
- Rejected transfers larger than NCT6694_MAX_DATA_LEN in the regmap bus callbacks of both transports.
- Reworded the commit message of "Rename USB transport functions with _usb_ prefix".
- Collected tags from Andi.
- Rebased on v7.3-rc7.
Changes since version 7:
- Marked the GPIO controller as sleeping.
- Validated the USB endpoints with usb_check_{bulk,int}_endpoints().
- Checked the length of received USB packets.
- Ignored interrupts without a mapping.
- Moved all fixes to the start of the series.
- Embedded struct nct6694 in the transport data and dropped the priv pointer.
- Renamed variables and buffers consistently.
- Retrieved struct nct6694 from the driver data in the core, and let the transports register their own MFD cells.
- Returned -ENOMEM when the IRQ domain cannot be created.
- Kept MFD_NCT6694 as the core symbol and added MFD_NCT6694_USB.
- Folded the interrupt URB submission fix into the core extraction.
- HIF: requested the interrupt after the core is set up, so that it is freed before the IRQ domain is removed.
Changes since version 6:
- Transfer command payloads through a buffer owned by the transport.
- Locate the interrupt IN endpoint with usb_find_int_in_endpoint().
- Submit the interrupt URB after the core has created the IRQ domain.
- HIF: several robustness fixes in the interrupt and shared memory setup.
Changes since version 5:
- Replaced the read_msg/write_msg function pointers with a regmap-based transport abstraction, and added nct6694_write_read_msg().
Changes since version 4:
- Split the monolithic patch into a series of logical commits.
Changes since version 3:
- Removed redundant module type macro definitions from the sub-device drivers.
Changes since version 2:
- Restored per-device IDA and PLATFORM_DEVID_AUTO.
- Validated the irq_find_mapping() return value.
- Checked the superio_enter() return value.
Changes since version 1:
- Reworked the Super-I/O access helpers.
Ming Yu (13):
mfd: nct6694: Validate the USB endpoints
mfd: nct6694: Check the length of received USB packets
mfd: nct6694: Ignore interrupts without a mapping
mfd: nct6694: Transfer data packets via a dedicated buffer
mfd: nct6694: Drop the unused IRQ enable mask
mfd: nct6694: Move module type macros to shared header
mfd: nct6694: Refactor USB-specific data into nct6694_usb_data
mfd: nct6694: Rename USB transport functions with _usb_ prefix
mfd: nct6694: Rename driver to nct6694-usb
mfd: nct6694: Extract core device management into a separate module
mfd: nct6694: Introduce regmap-based transport abstraction
mfd: nct6694: Add a Kconfig symbol for the USB transport
mfd: nct6694: Add Host Interface (HIF) eSPI transport driver
MAINTAINERS | 2 +- drivers/gpio/gpio-nct6694.c | 7 - drivers/hwmon/nct6694-hwmon.c | 21 - drivers/i2c/busses/i2c-nct6694.c | 9 +- drivers/mfd/Kconfig | 34 +- drivers/mfd/Makefile | 4 +- drivers/mfd/nct6694-core.c | 85 ++++ drivers/mfd/nct6694-hif.c | 579 ++++++++++++++++++++++++++++ drivers/mfd/nct6694-usb.c | 420 ++++++++++++++++++++ drivers/mfd/nct6694.c | 388 ------------------- drivers/net/can/usb/nct6694_canfd.c | 6 - drivers/rtc/rtc-nct6694.c | 7 - drivers/watchdog/nct6694_wdt.c | 7 - include/linux/mfd/nct6694.h | 93 ++++- 14 files changed, 1191 insertions(+), 471 deletions(-) create mode 100644 drivers/mfd/nct6694-core.c create mode 100644 drivers/mfd/nct6694-hif.c create mode 100644 drivers/mfd/nct6694-usb.c delete mode 100644 drivers/mfd/nct6694.c
base-commit: 20eef29b7c8465ac98d7dd6d6f2ac07a8d8056ca
Signature · 1 line
2.34.1
PATCH v10 1/13 mfd: nct6694: Validate the USB endpoints
From: Ming Yu <[email protected]>
The probe reads endpoint[0] of the current altsetting without checking that the interface describes any endpoint, and the bulk endpoints used for the command transfers are never validated. A malformed device can make the driver read past the endpoint array or submit URBs to endpoints of the wrong type.
The interface exposes several interrupt and bulk endpoints, of which only EP1 IN, EP2 IN and EP3 OUT carry the command interface, so the endpoints cannot be looked up by type. Check that the expected endpoints are present with usb_check_{bulk,int}_endpoints(), and take the polling interval from the interrupt endpoint actually used.
Define the interrupt endpoint by its number, like the bulk endpoints, as the pipe macros expect an endpoint number rather than an address.
---
Changes in v10:
- Rebased on the current mainline, which allocates with devm_kzalloc_obj().
Changes in v9:
- None.
Changes in v8:
- Also validate the bulk endpoints. Keep the fixed endpoint numbers and check them with usb_check_{bulk,int}_endpoints() instead of looking up the first endpoint of each type, as the interface exposes several interrupt and bulk endpoints.
- Take the polling interval from the interrupt endpoint actually used, and define it by its number like the bulk endpoints.
Changes in v7:
- New patch.
drivers/mfd/nct6694.c | 29 +++++++++++++++++------------ include/linux/mfd/nct6694.h | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-)
drivers/mfd/nct6694.c +17 -12
@@ -273,13 +273,25 @@ static const struct irq_domain_ops nct6694_irq_domain_ops = {static int nct6694_usb_probe (struct usb_interface *iface,const struct usb_device_id *id) { +static const u8 bulk_ep_addr[] = { +USB_DIR_IN |NCT6694_BULK_IN_EP , +USB_DIR_OUT |NCT6694_BULK_OUT_EP , +0 + }; +static const u8 int_ep_addr[] = { +USB_DIR_IN |NCT6694_INT_IN_EP , +0 + };struct usb_device *udev =interface_to_usbdev (iface); -struct usb_endpoint_descriptor *int_endpoint; -struct usb_host_interface *interface;struct device *dev = &iface->dev;struct nct6694 *nct6694; +unsigned int int_pipe;int ret; +if (!usb_check_bulk_endpoints (iface, bulk_ep_addr) || + !usb_check_int_endpoints (iface, int_ep_addr)) +return -ENODEV ; + nct6694 =devm_kzalloc_obj (dev, *nct6694);if (!nct6694)return -ENOMEM ;
@@ -318,17 +330,10 @@ static int nct6694_usb_probe(struct usb_interface *iface,if (ret) goto err_ida; - interface = iface->cur_altsetting; - - int_endpoint = &interface->endpoint[0 ].desc; -if (!usb_endpoint_is_int_in (int_endpoint)) { - ret = -ENODEV ; - goto err_ida; - } - -usb_fill_int_urb (nct6694->int_in_urb, udev,usb_rcvintpipe (udev,NCT6694_INT_IN_EP ), + int_pipe =usb_rcvintpipe (udev,NCT6694_INT_IN_EP ); +usb_fill_int_urb (nct6694->int_in_urb, udev, int_pipe, nct6694->int_buffer,sizeof (*nct6694->int_buffer), usb_int_callback, - nct6694, int_endpoint->bInterval); + nct6694,usb_pipe_endpoint (udev, int_pipe)->desc.bInterval); ret =usb_submit_urb (nct6694->int_in_urb,GFP_KERNEL );if (ret)
include/linux/mfd/nct6694.h +1 -1
@@ -10,7 +10,7 @@#define NCT6694_VENDOR_ID 0x0416#define NCT6694_PRODUCT_ID 0x200B -#define NCT6694_INT_IN_EP 0x81 +#define NCT6694_INT_IN_EP 0x01#define NCT6694_BULK_IN_EP 0x02#define NCT6694_BULK_OUT_EP 0x03
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v10 01/13] mfd: nct6694: Validate the USB endpoints
Sashiko has reviewed this patch and found no issues.
Quoted 14 lines
From: Ming Yu <[email protected]>
The probe reads endpoint[0] of the current altsetting without checking that the interface describes any endpoint, and the bulk endpoints used for the command transfers are never validated. A malformed device can make the driver read past the endpoint array or submit URBs to endpoints of the wrong type.
The interface exposes several interrupt and bulk endpoints, of which only EP1 IN, EP2 IN and EP3 OUT carry the command interface, so the endpoints cannot be looked up by type. Check that the expected endpoints are present with usb_check_{bulk,int}_endpoints(), and take the polling interval from the interrupt endpoint actually used.
Quoted 5 lines
Define the interrupt endpoint by its number, like the bulk endpoints, as the pipe macros expect an endpoint number rather than an address.
Fixes 51dad33ede63 ("mfd: Add core driver for Nuvoton NCT6694")Signed-off-by Ming Yu <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v10 2/13 mfd: nct6694: Check the length of received USB packets
In reply to [email protected]From: Ming Yu <[email protected]>
The response status and the interrupt status are parsed without checking how many bytes were actually received. A short or zero-length packet leaves stale data in the buffer, which is then taken as a valid status and may repeatedly dispatch the same interrupts.
Reject short response packets and ignore short interrupt packets.
---
Changes in v10:
- None.
Changes in v9:
- None.
Changes in v8:
- New patch. Check the length of the response and interrupt packets before parsing them.
drivers/mfd/nct6694.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/mfd/nct6694.c +15 -0
@@ -117,6 +117,12 @@ int nct6694_read_msg(struct nct6694 *nct6694, const struct nct6694_cmd_header *cif (ret)return ret; +if (rx_len !=sizeof (msg->response_header)) { +dev_err (nct6694->dev,"Expected response length %zu, but got %d\n" , +sizeof (msg->response_header), rx_len); +return -EIO ; + } +/* Receive data packet from USB device */ ret =usb_bulk_msg (udev,usb_rcvbulkpipe (udev,NCT6694_BULK_IN_EP ), buf,le16_to_cpu (cmd_hd->len), &rx_len,NCT6694_URB_TIMEOUT );
@@ -173,6 +179,12 @@ int nct6694_write_msg(struct nct6694 *nct6694, const struct nct6694_cmd_header *if (ret)return ret; +if (rx_len !=sizeof (msg->response_header)) { +dev_err (nct6694->dev,"Expected response length %zu, but got %d\n" , +sizeof (msg->response_header), rx_len); +return -EIO ; + } +/* Receive data packet from USB device */ ret =usb_bulk_msg (udev,usb_rcvbulkpipe (udev,NCT6694_BULK_IN_EP ), buf,le16_to_cpu (cmd_hd->len), &rx_len,NCT6694_URB_TIMEOUT );
@@ -207,6 +219,9 @@ static void usb_int_callback(struct urb *urb) goto resubmit; } +if (urb->actual_length <sizeof (*status_le)) + goto resubmit; + int_status =le32_to_cpu (*status_le);while (int_status) {
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v10 02/13] mfd: nct6694: Check the length of received USB packets
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
From: Ming Yu <[email protected]>
The response status and the interrupt status are parsed without checking how many bytes were actually received. A short or zero-length packet leaves stale data in the buffer, which is then taken as a valid status and may repeatedly dispatch the same interrupts.
Reject short response packets and ignore short interrupt packets.
Fixes 51dad33ede63 ("mfd: Add core driver for Nuvoton NCT6694")Signed-off-by Ming Yu <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v10 3/13 mfd: nct6694: Ignore interrupts without a mapping
In reply to [email protected]From: Ming Yu <[email protected]>
The return value of irq_find_mapping() is passed straight to generic_handle_irq_safe(). If the device reports a hardware interrupt that has no mapping, irq_find_mapping() returns 0 and the handler of the system's IRQ 0 is invoked instead.
Use generic_handle_domain_irq_safe(), which ignores unmapped hardware interrupts.
---
Changes in v10:
- None.
Changes in v9:
- None.
Changes in v8:
- New patch. Use generic_handle_domain_irq_safe() so that unmapped interrupts are ignored.
drivers/mfd/nct6694.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/nct6694.c +1 -1
@@ -227,7 +227,7 @@ static void usb_int_callback(struct urb *urb)while (int_status) {int irq =__ffs (int_status); -generic_handle_irq_safe (irq_find_mapping (nct6694->domain, irq)); +generic_handle_domain_irq_safe (nct6694->domain, irq); int_status &= ~BIT (irq); }
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v10 03/13] mfd: nct6694: Ignore interrupts without a mapping
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
From: Ming Yu <[email protected]>
The return value of
irq_find_mapping()is passed straight togeneric_handle_irq_safe(). If the device reports a hardware interrupt that has no mapping,irq_find_mapping()returns 0 and the handler of the system's IRQ 0 is invoked instead.
Quoted 5 lines
Use
generic_handle_domain_irq_safe(), which ignores unmapped hardware interrupts.Fixes 51dad33ede63 ("mfd: Add core driver for Nuvoton NCT6694")Signed-off-by Ming Yu <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH v10 4/13 mfd: nct6694: Transfer data packets via a dedicated buffer
In reply to [email protected]From: Ming Yu <[email protected]>
The caller's buffer is passed straight to usb_bulk_msg(). Sub-device drivers embed those buffers in their private data, so they are neither cacheline aligned nor exclusively owned by the transfer, and mapping them for DMA can corrupt adjacent fields on non-coherent architectures.
Transfer the data packets through a buffer owned by the transport, and reject commands exceeding the maximum data length.
---
Changes in v10:
- Rebased on the current mainline, which allocates with devm_kzalloc_obj().
Changes in v9:
- None.
Changes in v8:
- Moved before the refactoring so it applies to the original driver.
- Renamed xfer_buf to data_buf, len to data_len and NCT6694_MAX_PACKET_SIZE to NCT6694_MAX_DATA_LEN.
Changes in v7:
- New patch.
drivers/mfd/nct6694.c | 37 +++++++++++++++++++++++++++---------- include/linux/mfd/nct6694.h | 4 ++++ 2 files changed, 31 insertions(+), 10 deletions(-)
drivers/mfd/nct6694.c +27 -10
@@ -98,8 +98,12 @@ int nct6694_read_msg(struct nct6694 *nct6694, const struct nct6694_cmd_header *c {union nct6694_usb_msg *msg = nct6694->usb_msg;struct usb_device *udev = nct6694->udev; +u16 data_len =le16_to_cpu (cmd_hd->len);int tx_len, rx_len, ret; +if (data_len >NCT6694_MAX_DATA_LEN ) +return -EINVAL ; +guard (mutex)(&nct6694->access_lock);memcpy (&msg->cmd_header, cmd_hd,sizeof (*cmd_hd));
@@ -124,17 +128,19 @@ int nct6694_read_msg(struct nct6694 *nct6694, const struct nct6694_cmd_header *c }/* Receive data packet from USB device */ - ret =usb_bulk_msg (udev,usb_rcvbulkpipe (udev,NCT6694_BULK_IN_EP ), buf, -le16_to_cpu (cmd_hd->len), &rx_len,NCT6694_URB_TIMEOUT ); + ret =usb_bulk_msg (udev,usb_rcvbulkpipe (udev,NCT6694_BULK_IN_EP ), nct6694->data_buf, + data_len, &rx_len,NCT6694_URB_TIMEOUT );if (ret)return ret; -if (rx_len !=le16_to_cpu (cmd_hd->len)) { +if (rx_len != data_len) {dev_err (nct6694->dev,"Expected received length %d, but got %d\n" , -le16_to_cpu (cmd_hd->len), rx_len); + data_len, rx_len);return -EIO ; } +memcpy (buf, nct6694->data_buf, data_len); +return nct6694_response_err_handling (nct6694, msg->response_header.sts); }EXPORT_SYMBOL_GPL (nct6694_read_msg);
@@ -154,12 +160,17 @@ int nct6694_write_msg(struct nct6694 *nct6694, const struct nct6694_cmd_header * {union nct6694_usb_msg *msg = nct6694->usb_msg;struct usb_device *udev = nct6694->udev; +u16 data_len =le16_to_cpu (cmd_hd->len);int tx_len, rx_len, ret; +if (data_len >NCT6694_MAX_DATA_LEN ) +return -EINVAL ; +guard (mutex)(&nct6694->access_lock);memcpy (&msg->cmd_header, cmd_hd,sizeof (*cmd_hd)); msg->cmd_header.hctrl =NCT6694_HCTRL_SET ; +memcpy (nct6694->data_buf, buf, data_len);/* Send command packet to USB device */ ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, NCT6694_BULK_OUT_EP), &msg->cmd_header,
@@ -168,8 +179,8 @@ int nct6694_write_msg(struct nct6694 *nct6694, const struct nct6694_cmd_header *return ret;/* Send data packet to USB device */ - ret =usb_bulk_msg (udev,usb_sndbulkpipe (udev,NCT6694_BULK_OUT_EP ), buf, -le16_to_cpu (cmd_hd->len), &tx_len,NCT6694_URB_TIMEOUT ); + ret =usb_bulk_msg (udev,usb_sndbulkpipe (udev,NCT6694_BULK_OUT_EP ), nct6694->data_buf, + data_len, &tx_len,NCT6694_URB_TIMEOUT );if (ret)return ret;
@@ -186,17 +197,19 @@ int nct6694_write_msg(struct nct6694 *nct6694, const struct nct6694_cmd_header * }/* Receive data packet from USB device */ - ret =usb_bulk_msg (udev,usb_rcvbulkpipe (udev,NCT6694_BULK_IN_EP ), buf, -le16_to_cpu (cmd_hd->len), &rx_len,NCT6694_URB_TIMEOUT ); + ret =usb_bulk_msg (udev,usb_rcvbulkpipe (udev,NCT6694_BULK_IN_EP ), nct6694->data_buf, + data_len, &rx_len,NCT6694_URB_TIMEOUT );if (ret)return ret; -if (rx_len !=le16_to_cpu (cmd_hd->len)) { +if (rx_len != data_len) {dev_err (nct6694->dev,"Expected transmitted length %d, but got %d\n" , -le16_to_cpu (cmd_hd->len), rx_len); + data_len, rx_len);return -EIO ; } +memcpy (buf, nct6694->data_buf, data_len); +return nct6694_response_err_handling (nct6694, msg->response_header.sts); }EXPORT_SYMBOL_GPL (nct6694_write_msg);
@@ -315,6 +328,10 @@ static int nct6694_usb_probe(struct usb_interface *iface,if (!nct6694->usb_msg)return -ENOMEM ; + nct6694->data_buf =devm_kzalloc (dev,NCT6694_MAX_DATA_LEN ,GFP_KERNEL ); +if (!nct6694->data_buf) +return -ENOMEM ; + nct6694->int_buffer =devm_kzalloc_obj (dev, *nct6694->int_buffer);if (!nct6694->int_buffer)return -ENOMEM ;
include/linux/mfd/nct6694.h +4 -0
@@ -19,6 +19,9 @@#define NCT6694_URB_TIMEOUT 1000 +/* Maximum data packet length the firmware accepts in a single command */ +#define NCT6694_MAX_DATA_LEN 0x3F0 +enum nct6694_irq_id {NCT6694_IRQ_GPIO0 =0 ,NCT6694_IRQ_GPIO1 ,
@@ -92,6 +95,7 @@ struct nct6694 {struct urb *int_in_urb;struct usb_device *udev;union nct6694_usb_msg *usb_msg; +void *data_buf;__le32 *int_buffer;unsigned int irq_enable; };
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v10 04/13] mfd: nct6694: Transfer data packets via a dedicated buffer
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
From: Ming Yu <[email protected]>
The caller's buffer is passed straight to
usb_bulk_msg(). Sub-device drivers embed those buffers in their private data, so they are neither cacheline aligned nor exclusively owned by the transfer, and mapping them for DMA can corrupt adjacent fields on non-coherent architectures.
Quoted 5 lines
Transfer the data packets through a buffer owned by the transport, and reject commands exceeding the maximum data length.
Fixes 51dad33ede63 ("mfd: Add core driver for Nuvoton NCT6694")Signed-off-by Ming Yu <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
PATCH v10 5/13 mfd: nct6694: Drop the unused IRQ enable mask
In reply to [email protected]From: Ming Yu <[email protected]>
The .irq_enable and .irq_disable callbacks only update the irq_enable bitmask under irq_lock, which is a spinlock_t. Nothing ever reads that bitmask, so the callbacks do not mask anything. They also take irq_lock while the IRQ core holds desc->lock, a raw spinlock. On PREEMPT_RT this is an invalid wait context.
Remove both callbacks, along with irq_enable and irq_lock, and keep IRQCHIP_SKIP_SET_WAKE. Without .irq_disable, the IRQ core falls back to lazy disable, and handle_simple_irq() keeps a disabled interrupt pending instead of calling its handler. The behaviour is therefore unchanged.
---
Changes in v10:
- New patch. Drop the .irq_enable/.irq_disable callbacks, which only update a bitmask that is never read and take a spinlock_t while the IRQ core holds the raw desc->lock (reported by Sashiko on v9 06/12 and 09/12).
drivers/mfd/nct6694.c | 25 ------------------------- include/linux/mfd/nct6694.h | 2 -- 2 files changed, 27 deletions(-)
drivers/mfd/nct6694.c +0 -25
@@ -19,7 +19,6 @@#include <linux/mfd/nct6694.h> #include <linux/module.h> #include <linux/slab.h> -#include <linux/spinlock.h> #include <linux/usb.h> static const struct mfd_cell nct6694_devs[] = {
@@ -250,31 +249,9 @@ static void usb_int_callback(struct urb *urb)dev_warn (nct6694->dev,"Failed to resubmit urb, status %pe" ,ERR_PTR (ret)); } -static void nct6694_irq_enable (struct irq_data *data) -{ -struct nct6694 *nct6694 =irq_data_get_irq_chip_data (data); -irq_hw_number_t hwirq =irqd_to_hwirq (data); - -guard (spinlock_irqsave)(&nct6694->irq_lock); - - nct6694->irq_enable |=BIT (hwirq); -} - -static void nct6694_irq_disable (struct irq_data *data) -{ -struct nct6694 *nct6694 =irq_data_get_irq_chip_data (data); -irq_hw_number_t hwirq =irqd_to_hwirq (data); - -guard (spinlock_irqsave)(&nct6694->irq_lock); - - nct6694->irq_enable &= ~BIT (hwirq); -} -static const struct irq_chip nct6694_irq_chip = { .name ="nct6694-irq" , .flags =IRQCHIP_SKIP_SET_WAKE , - .irq_enable = nct6694_irq_enable, - .irq_disable = nct6694_irq_disable, };static int nct6694_irq_domain_map (struct irq_domain *d,unsigned int irq,irq_hw_number_t hw)
@@ -356,8 +333,6 @@ static int nct6694_usb_probe(struct usb_interface *iface,ida_init (&nct6694->canfd_ida);ida_init (&nct6694->wdt_ida); -spin_lock_init (&nct6694->irq_lock); - ret =devm_mutex_init (dev, &nct6694->access_lock);if (ret) goto err_ida;
include/linux/mfd/nct6694.h +0 -2
@@ -91,13 +91,11 @@ struct nct6694 {struct ida wdt_ida;struct irq_domain *domain;struct mutex access_lock; -spinlock_t irq_lock;struct urb *int_in_urb;struct usb_device *udev;union nct6694_usb_msg *usb_msg;void *data_buf;__le32 *int_buffer; -unsigned int irq_enable; };int nct6694_read_msg (struct nct6694 *nct6694,const struct nct6694_cmd_header *cmd_hd,void *buf);
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v10 05/13] mfd: nct6694: Drop the unused IRQ enable mask
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
From: Ming Yu <[email protected]>
The .irq_enable and .irq_disable callbacks only update the
irq_enablebitmask underirq_lock, which is aspinlock_t. Nothing ever reads that bitmask, so the callbacks do not mask anything. They also takeirq_lockwhile the IRQ core holdsdesc->lock, a raw spinlock. OnPREEMPT_RTthis is an invalid wait context.
Quoted 7 lines
Remove both callbacks, along with
irq_enableandirq_lock, and keepIRQCHIP_SKIP_SET_WAKE. Without .irq_disable, the IRQ core falls back to lazy disable, andhandle_simple_irq()keeps a disabled interrupt pending instead of calling its handler. The behaviour is therefore unchanged.Fixes 51dad33ede63 ("mfd: Add core driver for Nuvoton NCT6694")Signed-off-by Ming Yu <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH v10 05/13] mfd: nct6694: Drop the unused IRQ enable mask
In reply to [email protected]Quoted 8 lines · On 2026-11-18 16:16:16 [+0800], [email protected] wrote:
From: Ming Yu <[email protected]>
The .irq_enable and .irq_disable callbacks only update the
irq_enablebitmask underirq_lock, which is aspinlock_t. Nothing ever reads that bitmask, so the callbacks do not mask anything. They also takeirq_lockwhile the IRQ core holdsdesc->lock, a raw spinlock. OnPREEMPT_RTthis is an invalid wait context.
Quoted 7 lines
Remove both callbacks, along with
irq_enableandirq_lock, and keepIRQCHIP_SKIP_SET_WAKE. Without .irq_disable, the IRQ core falls back to lazy disable, andhandle_simple_irq()keeps a disabled interrupt pending instead of calling its handler. The behaviour is therefore unchanged.Fixes 51dad33ede63 ("mfd: Add core driver for Nuvoton NCT6694")Signed-off-by Ming Yu <[email protected]>
This sort of makes sense. But how does this work? If the interrupt keeps coming the irq-core will just suppress it?
If that is your whole business why not use dummy_irq_chip?
As far as the change goes,
Sebastian
Re: [PATCH v10 05/13] mfd: nct6694: Drop the unused IRQ enable mask
Dear Sebastian,
Thank you for the review.
Sebastian Andrzej Siewior <[email protected]> 於 2026年11月19日週四 下午6:12寫道:
Quoted 15 lines · On 2026-11-18 16:16:16 [+0800], [email protected] wrote:
Quoted 13 lines
From: Ming Yu <[email protected]>
The .irq_enable and .irq_disable callbacks only update the
irq_enablebitmask underirq_lock, which is aspinlock_t. Nothing ever reads that bitmask, so the callbacks do not mask anything. They also takeirq_lockwhile the IRQ core holdsdesc->lock, a raw spinlock. OnPREEMPT_RTthis is an invalid wait context.Remove both callbacks, along with
irq_enableandirq_lock, and keepIRQCHIP_SKIP_SET_WAKE. Without .irq_disable, the IRQ core falls back to lazy disable, andhandle_simple_irq()keeps a disabled interrupt pending instead of calling its handler. The behaviour is therefore unchanged.
Quoted 5 lines
Quoted 2 lines
Fixes 51dad33ede63 ("mfd: Add core driver for Nuvoton NCT6694")Signed-off-by Ming Yu <[email protected]>This sort of makes sense. But how does this work? If the interrupt keeps coming the irq-core will just suppress it?
Yes, that is my understanding. The NCT6694 does not provide an interrupt mask that the host can program. The firmware reports a 32-bit status word, through the interrupt URB on USB and through shared memory on HIF, and the transport handles every report and dispatches each set bit.
While a child interrupt is disabled, handle_simple_irq() only marks it pending and does not call the handler. When the interrupt is enabled again, check_irq_resend() replays it. The parent should not be flooded:
on USB it is the URB completion, and on HIF the handler clears the status on every interrupt.
This is also how the driver behaved before this patch, because the callbacks only updated a bitmask that was never read.
Quoted 1 line
If that is your whole business why not use
dummy_irq_chip?
Thank you for the suggestion. I am looking into it now. As far as I can see, dummy_irq_chip only provides no-op callbacks and also sets IRQCHIP_SKIP_SET_WAKE, so the behaviour should stay the same. It would also let me drop the irq_set_chip_data() calls, since nothing reads the chip data after this change. The only visible difference I found is the chip name shown in /proc/interrupts.
If you agree, I would like to switch to dummy_irq_chip in v11. Since this changes the patch, I will not keep your Reviewed-by unless you are fine with it.
Please let me know if I missed anything.
Best regards,
Ming
PATCH v10 6/13 mfd: nct6694: Move module type macros to shared header
In reply to [email protected]From: Ming Yu <[email protected]>
Each sub-device driver defines the module type used by its own commands. The upcoming HIF transport also needs to recognise NCT6694_RPT_MOD, as report accesses are served from a separate register space rather than through the command mailbox.
Move all module types into the shared header so that the transports and the sub-device drivers use a single set of definitions.
No functional change.
---
Changes in v10:
- None.
Changes in v9:
- Added Andi's Reviewed-by.
Changes in v8:
- Reworded the commit message to explain why the transport needs the module types.
Changes in v7:
- None.
Changes in v6:
- None.
Changes in v5:
- Split from the monolithic v4 patch to follow the single logical change principle.
drivers/gpio/gpio-nct6694.c | 7 ------- drivers/hwmon/nct6694-hwmon.c | 21 --------------------- drivers/i2c/busses/i2c-nct6694.c | 7 ------- drivers/net/can/usb/nct6694_canfd.c | 6 ------ drivers/rtc/rtc-nct6694.c | 7 ------- drivers/watchdog/nct6694_wdt.c | 7 ------- include/linux/mfd/nct6694.h | 9 +++++++++ 7 files changed, 9 insertions(+), 55 deletions(-)
drivers/gpio/gpio-nct6694.c +0 -7
@@ -13,13 +13,6 @@#include <linux/module.h> #include <linux/platform_device.h> -/* -* USB command module type for NCT6694 GPIO controller. -* This defines the module type used for communication with the NCT6694 -* GPIO controller over the USB interface. -*/ -#define NCT6694_GPIO_MOD 0xFF -#define NCT6694_GPIO_VER 0x90#define NCT6694_GPIO_VALID 0x110#define NCT6694_GPI_DATA 0x120
drivers/hwmon/nct6694-hwmon.c +0 -21
@@ -15,13 +15,6 @@#include <linux/platform_device.h> #include <linux/slab.h> -/* -* USB command module type for NCT6694 report channel -* This defines the module type used for communication with the NCT6694 -* report channel over the USB interface. -*/ -#define NCT6694_RPT_MOD 0xFF -/* Report channel */ /* * The report channel is used to report the status of the hardware monitor
@@ -38,13 +31,6 @@#define NCT6694_TIN_STS (x) (0x6A + (x))#define NCT6694_FIN_STS (x) (0x6E + (x)) -/* -* USB command module type for NCT6694 HWMON controller. -* This defines the module type used for communication with the NCT6694 -* HWMON controller over the USB interface. -*/ -#define NCT6694_HWMON_MOD 0x00 -/* Command 00h - Hardware Monitor Control */ #define NCT6694_HWMON_CONTROL 0x00#define NCT6694_HWMON_CONTROL_SEL 0x00
@@ -53,13 +39,6 @@#define NCT6694_HWMON_ALARM 0x02#define NCT6694_HWMON_ALARM_SEL 0x00 -/* -* USB command module type for NCT6694 PWM controller. -* This defines the module type used for communication with the NCT6694 -* PWM controller over the USB interface. -*/ -#define NCT6694_PWM_MOD 0x01 -/* PWM Command - Manual Control */ #define NCT6694_PWM_CONTROL 0x01#define NCT6694_PWM_CONTROL_SEL 0x00
drivers/i2c/busses/i2c-nct6694.c +0 -7
@@ -12,13 +12,6 @@#include <linux/module.h> #include <linux/platform_device.h> -/* -* USB command module type for NCT6694 I2C controller. -* This defines the module type used for communication with the NCT6694 -* I2C controller over the USB interface. -*/ -#define NCT6694_I2C_MOD 0x03 -/* Command 00h - I2C Deliver */ #define NCT6694_I2C_DELIVER 0x00#define NCT6694_I2C_DELIVER_SEL 0x00
drivers/net/can/usb/nct6694_canfd.c +0 -6
@@ -18,12 +18,6 @@#define DEVICE_NAME "nct6694-canfd" -/* USB command module type for NCT6694 CANfd controller. -* This defines the module type used for communication with the NCT6694 -* CANfd controller over the USB interface. -*/ -#define NCT6694_CANFD_MOD 0x05 -/* Command 00h - CAN Setting and Initialization */ #define NCT6694_CANFD_SETTING 0x00#define NCT6694_CANFD_SETTING_ACTIVE_CTRL1 BIT(0)
drivers/rtc/rtc-nct6694.c +0 -7
@@ -14,13 +14,6 @@#include <linux/rtc.h> #include <linux/slab.h> -/* -* USB command module type for NCT6694 RTC controller. -* This defines the module type used for communication with the NCT6694 -* RTC controller over the USB interface. -*/ -#define NCT6694_RTC_MOD 0x08 -/* Command 00h - RTC Time */ #define NCT6694_RTC_TIME 0x0000#define NCT6694_RTC_TIME_SEL 0x00
drivers/watchdog/nct6694_wdt.c +0 -7
@@ -21,13 +21,6 @@#define NCT6694_WDT_MAX_DEVS 2 -/* -* USB command module type for NCT6694 WDT controller. -* This defines the module type used for communication with the NCT6694 -* WDT controller over the USB interface. -*/ -#define NCT6694_WDT_MOD 0x07 -/* Command 00h - WDT Setup */ #define NCT6694_WDT_SETUP 0x00#define NCT6694_WDT_SETUP_SEL (idx) (idx ? 0x01 : 0x00)
include/linux/mfd/nct6694.h +9 -0
@@ -8,6 +8,15 @@#ifndef __MFD_NCT6694_H#define __MFD_NCT6694_H +#define NCT6694_HWMON_MOD 0x00 +#define NCT6694_PWM_MOD 0x01 +#define NCT6694_I2C_MOD 0x03 +#define NCT6694_CANFD_MOD 0x05 +#define NCT6694_WDT_MOD 0x07 +#define NCT6694_RTC_MOD 0x08 +#define NCT6694_RPT_MOD 0xFF +#define NCT6694_GPIO_MOD NCT6694_RPT_MOD +#define NCT6694_VENDOR_ID 0x0416#define NCT6694_PRODUCT_ID 0x200B#define NCT6694_INT_IN_EP 0x01
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v10 06/13] mfd: nct6694: Move module type macros to shared header
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
From: Ming Yu <[email protected]>
Each sub-device driver defines the module type used by its own commands. The upcoming HIF transport also needs to recognise
NCT6694_RPT_MOD, as report accesses are served from a separate register space rather than through the command mailbox.
Quoted 7 lines
Move all module types into the shared header so that the transports and the sub-device drivers use a single set of definitions.
No functional change.
Reviewed-by Andi Shyti <[email protected]>Signed-off-by Ming Yu <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Re: [PATCH v10 06/13] mfd: nct6694: Move module type macros to shared header
In reply to [email protected]Quoted 35 lines · On Wed, Nov 18, 2026 at 04:16:17PM +0800, [email protected] wrote:
From: Ming Yu <[email protected]>
Each sub-device driver defines the module type used by its own commands. The upcoming HIF transport also needs to recognise
NCT6694_RPT_MOD, as report accesses are served from a separate register space rather than through the command mailbox.Move all module types into the shared header so that the transports and the sub-device drivers use a single set of definitions.
No functional change.
Reviewed-by Andi Shyti <[email protected]>Signed-off-by Ming Yu <[email protected]>---
Changes in v10:
- None.Changes in v9:
- Added Andi's Reviewed-by.Changes in v8:
- Reworded the commit message to explain why the transport needs the module types.Changes in v7:
- None.Changes in v6:
- None.Changes in v5:
- Split from the monolithic v4 patch to follow the single logical change principle.
Quoted 8 lines
drivers/gpio/gpio-nct6694.c | 7 ------- drivers/hwmon/nct6694-hwmon.c | 21 --------------------- drivers/i2c/busses/i2c-nct6694.c | 7 ------- drivers/net/can/usb/nct6694_canfd.c | 6 ------ drivers/rtc/rtc-nct6694.c | 7 ------- drivers/watchdog/nct6694_wdt.c | 7 ------- include/linux/mfd/nct6694.h | 9 +++++++++ 7 files changed, 9 insertions(+), 55 deletions(-)
For hwmon and watchdog:
Guenter
PATCH v10 7/13 mfd: nct6694: Refactor USB-specific data into nct6694_usb_data
In reply to [email protected]From: Ming Yu <[email protected]>
Separate the USB transport fields from the core nct6694 structure into a new nct6694_usb_data structure, which embeds struct nct6694 and is retrieved with container_of(). USB-only definitions are moved from the shared header into the USB driver.
While at it, use consistent names for the USB device, the buffers and the core structure.
No functional change.
---
Changes in v10:
- Rebased on top of "mfd: nct6694: Drop the unused IRQ enable mask".
- Allocated usb_data, hdr_buf and int_buf with devm_kzalloc_obj().
Changes in v9:
- None.
Changes in v8:
- Embedded struct nct6694 in nct6694_usb_data and dropped the priv pointer.
- Renamed udev to usb_dev, udata to usb_data, usb_msg to hdr_buf, int_buffer to int_buf, int_in_urb to int_urb, and nct6694 to ddata.
Changes in v7:
- None.
Changes in v6:
- None.
Changes in v5:
- Split from the monolithic v4 patch to follow the single logical change principle.
drivers/mfd/nct6694.c | 229 +++++++++++++++++++++--------------- include/linux/mfd/nct6694.h | 26 +--- 2 files changed, 136 insertions(+), 119 deletions(-)
drivers/mfd/nct6694.c +132 -97
@@ -21,6 +21,34 @@#include <linux/slab.h> #include <linux/usb.h> +#define NCT6694_VENDOR_ID 0x0416 +#define NCT6694_PRODUCT_ID 0x200B +#define NCT6694_INT_IN_EP 0x01 +#define NCT6694_BULK_IN_EP 0x02 +#define NCT6694_BULK_OUT_EP 0x03 + +#define NCT6694_URB_TIMEOUT 1000 + +union __packed nct6694_usb_hdr { +struct nct6694_cmd_header cmd_header; +struct nct6694_response_header response_header; +}; + +struct nct6694_usb_data { +struct nct6694 core; +struct mutex access_lock; +struct usb_device *usb_dev; +struct urb *int_urb; +union nct6694_usb_hdr *hdr_buf; +void *data_buf; +__le32 *int_buf; +}; + +static struct nct6694_usb_data *to_nct6694_usb_data (struct nct6694 *ddata) +{ + return container_of(ddata, struct nct6694_usb_data, core); +} +static const struct mfd_cell nct6694_devs[] = {MFD_CELL_NAME ("nct6694-gpio" ),MFD_CELL_NAME ("nct6694-gpio" ),
@@ -57,22 +85,22 @@ static const struct mfd_cell nct6694_devs[] = { MFD_CELL_NAME("nct6694-rtc"), }; -static int nct6694_response_err_handling (struct nct6694 *nct6694,unsigned char err_status) +static int nct6694_response_err_handling (struct nct6694 *ddata,unsigned char err_status) {switch (err_status) {case NCT6694_NO_ERROR :return 0 ;case NCT6694_NOT_SUPPORT_ERROR : -dev_err (nct6694->dev,"Command is not supported!\n" ); +dev_err (ddata->dev,"Command is not supported!\n" );break ;case NCT6694_NO_RESPONSE_ERROR : -dev_warn (nct6694->dev,"Command received no response!\n" ); +dev_warn (ddata->dev,"Command received no response!\n" );break ;case NCT6694_TIMEOUT_ERROR : -dev_warn (nct6694->dev,"Command timed out!\n" ); +dev_warn (ddata->dev,"Command timed out!\n" );break ;case NCT6694_PENDING : -dev_err (nct6694->dev,"Command is pending!\n" ); +dev_err (ddata->dev,"Command is pending!\n" );break ;default :return -EINVAL ;
@@ -83,7 +111,7 @@ static int nct6694_response_err_handling(struct nct6694 *nct6694, unsigned char/** * nct6694_read_msg() - Read message from NCT6694 device -* @nct6694: NCT6694 device pointer +* @ddata: NCT6694 device pointer * @cmd_hd: command header structure * @buf: buffer to store the response data *
@@ -93,60 +121,61 @@ static int nct6694_response_err_handling(struct nct6694 *nct6694, unsigned char* * Return: Negative value on error or 0 on success. */ -int nct6694_read_msg (struct nct6694 *nct6694,const struct nct6694_cmd_header *cmd_hd,void *buf) +int nct6694_read_msg (struct nct6694 *ddata,const struct nct6694_cmd_header *cmd_hd,void *buf) { -union nct6694_usb_msg *msg = nct6694->usb_msg; -struct usb_device *udev = nct6694->udev; +struct nct6694_usb_data *usb_data =to_nct6694_usb_data (ddata); +union nct6694_usb_hdr *hdr = usb_data->hdr_buf; +struct usb_device *usb_dev = usb_data->usb_dev;u16 data_len =le16_to_cpu (cmd_hd->len);int tx_len, rx_len, ret;if (data_len >NCT6694_MAX_DATA_LEN )return -EINVAL ; -guard (mutex)(&nct6694->access_lock); +guard (mutex)(&usb_data->access_lock); -memcpy (&msg->cmd_header, cmd_hd,sizeof (*cmd_hd)); - msg->cmd_header.hctrl =NCT6694_HCTRL_GET ; +memcpy (&hdr->cmd_header, cmd_hd,sizeof (*cmd_hd)); + hdr->cmd_header.hctrl =NCT6694_HCTRL_GET ;/* Send command packet to USB device */ - ret =usb_bulk_msg (udev,usb_sndbulkpipe (udev,NCT6694_BULK_OUT_EP ), &msg->cmd_header, -sizeof (*msg), &tx_len,NCT6694_URB_TIMEOUT ); + ret =usb_bulk_msg (usb_dev,usb_sndbulkpipe (usb_dev,NCT6694_BULK_OUT_EP ), + &hdr->cmd_header,sizeof (*hdr), &tx_len,NCT6694_URB_TIMEOUT );if (ret)return ret;/* Receive response packet from USB device */ - ret =usb_bulk_msg (udev,usb_rcvbulkpipe (udev,NCT6694_BULK_IN_EP ), &msg->response_header, -sizeof (*msg), &rx_len,NCT6694_URB_TIMEOUT ); + ret =usb_bulk_msg (usb_dev,usb_rcvbulkpipe (usb_dev,NCT6694_BULK_IN_EP ), + &hdr->response_header,sizeof (*hdr), &rx_len,NCT6694_URB_TIMEOUT );if (ret)return ret; -if (rx_len !=sizeof (msg->response_header)) { -dev_err (nct6694->dev,"Expected response length %zu, but got %d\n" , -sizeof (msg->response_header), rx_len); +if (rx_len !=sizeof (hdr->response_header)) { +dev_err (ddata->dev,"Expected response length %zu, but got %d\n" , +sizeof (hdr->response_header), rx_len);return -EIO ; }/* Receive data packet from USB device */ - ret =usb_bulk_msg (udev,usb_rcvbulkpipe (udev,NCT6694_BULK_IN_EP ), nct6694->data_buf, - data_len, &rx_len,NCT6694_URB_TIMEOUT ); + ret =usb_bulk_msg (usb_dev,usb_rcvbulkpipe (usb_dev,NCT6694_BULK_IN_EP ), + usb_data->data_buf, data_len, &rx_len,NCT6694_URB_TIMEOUT );if (ret)return ret;if (rx_len != data_len) { -dev_err (nct6694->dev,"Expected received length %d, but got %d\n" , +dev_err (ddata->dev,"Expected received length %d, but got %d\n" , data_len, rx_len);return -EIO ; } -memcpy (buf, nct6694->data_buf, data_len); +memcpy (buf, usb_data->data_buf, data_len); -return nct6694_response_err_handling (nct6694, msg->response_header.sts); +return nct6694_response_err_handling (ddata, hdr->response_header.sts); }EXPORT_SYMBOL_GPL (nct6694_read_msg);/** * nct6694_write_msg() - Write message to NCT6694 device -* @nct6694: NCT6694 device pointer +* @ddata: NCT6694 device pointer * @cmd_hd: command header structure * @buf: buffer containing the data to be sent *
@@ -155,67 +184,68 @@ EXPORT_SYMBOL_GPL(nct6694_read_msg);* * Return: Negative value on error or 0 on success. */ -int nct6694_write_msg (struct nct6694 *nct6694,const struct nct6694_cmd_header *cmd_hd,void *buf) +int nct6694_write_msg (struct nct6694 *ddata,const struct nct6694_cmd_header *cmd_hd,void *buf) { -union nct6694_usb_msg *msg = nct6694->usb_msg; -struct usb_device *udev = nct6694->udev; +struct nct6694_usb_data *usb_data =to_nct6694_usb_data (ddata); +union nct6694_usb_hdr *hdr = usb_data->hdr_buf; +struct usb_device *usb_dev = usb_data->usb_dev;u16 data_len =le16_to_cpu (cmd_hd->len);int tx_len, rx_len, ret;if (data_len >NCT6694_MAX_DATA_LEN )return -EINVAL ; -guard (mutex)(&nct6694->access_lock); +guard (mutex)(&usb_data->access_lock); -memcpy (&msg->cmd_header, cmd_hd,sizeof (*cmd_hd)); - msg->cmd_header.hctrl =NCT6694_HCTRL_SET ; -memcpy (nct6694->data_buf, buf, data_len); +memcpy (&hdr->cmd_header, cmd_hd,sizeof (*cmd_hd)); + hdr->cmd_header.hctrl =NCT6694_HCTRL_SET ; +memcpy (usb_data->data_buf, buf, data_len);/* Send command packet to USB device */ - ret =usb_bulk_msg (udev,usb_sndbulkpipe (udev,NCT6694_BULK_OUT_EP ), &msg->cmd_header, -sizeof (*msg), &tx_len,NCT6694_URB_TIMEOUT ); + ret =usb_bulk_msg (usb_dev,usb_sndbulkpipe (usb_dev,NCT6694_BULK_OUT_EP ), + &hdr->cmd_header,sizeof (*hdr), &tx_len,NCT6694_URB_TIMEOUT );if (ret)return ret;/* Send data packet to USB device */ - ret =usb_bulk_msg (udev,usb_sndbulkpipe (udev,NCT6694_BULK_OUT_EP ), nct6694->data_buf, - data_len, &tx_len,NCT6694_URB_TIMEOUT ); + ret =usb_bulk_msg (usb_dev,usb_sndbulkpipe (usb_dev,NCT6694_BULK_OUT_EP ), + usb_data->data_buf, data_len, &tx_len,NCT6694_URB_TIMEOUT );if (ret)return ret;/* Receive response packet from USB device */ - ret =usb_bulk_msg (udev,usb_rcvbulkpipe (udev,NCT6694_BULK_IN_EP ), &msg->response_header, -sizeof (*msg), &rx_len,NCT6694_URB_TIMEOUT ); + ret =usb_bulk_msg (usb_dev,usb_rcvbulkpipe (usb_dev,NCT6694_BULK_IN_EP ), + &hdr->response_header,sizeof (*hdr), &rx_len,NCT6694_URB_TIMEOUT );if (ret)return ret; -if (rx_len !=sizeof (msg->response_header)) { -dev_err (nct6694->dev,"Expected response length %zu, but got %d\n" , -sizeof (msg->response_header), rx_len); +if (rx_len !=sizeof (hdr->response_header)) { +dev_err (ddata->dev,"Expected response length %zu, but got %d\n" , +sizeof (hdr->response_header), rx_len);return -EIO ; }/* Receive data packet from USB device */ - ret =usb_bulk_msg (udev,usb_rcvbulkpipe (udev,NCT6694_BULK_IN_EP ), nct6694->data_buf, - data_len, &rx_len,NCT6694_URB_TIMEOUT ); + ret =usb_bulk_msg (usb_dev,usb_rcvbulkpipe (usb_dev,NCT6694_BULK_IN_EP ), + usb_data->data_buf, data_len, &rx_len,NCT6694_URB_TIMEOUT );if (ret)return ret;if (rx_len != data_len) { -dev_err (nct6694->dev,"Expected transmitted length %d, but got %d\n" , +dev_err (ddata->dev,"Expected transmitted length %d, but got %d\n" , data_len, rx_len);return -EIO ; } -memcpy (buf, nct6694->data_buf, data_len); +memcpy (buf, usb_data->data_buf, data_len); -return nct6694_response_err_handling (nct6694, msg->response_header.sts); +return nct6694_response_err_handling (ddata, hdr->response_header.sts); }EXPORT_SYMBOL_GPL (nct6694_write_msg);static void usb_int_callback (struct urb *urb) { -struct nct6694 *nct6694 = urb->context; +struct nct6694 *ddata = urb->context;__le32 *status_le = urb->transfer_buffer;u32 int_status;int ret;
@@ -239,14 +269,14 @@ static void usb_int_callback(struct urb *urb)while (int_status) {int irq =__ffs (int_status); -generic_handle_domain_irq_safe (nct6694->domain, irq); +generic_handle_domain_irq_safe (ddata->domain, irq); int_status &= ~BIT (irq); } resubmit: ret =usb_submit_urb (urb,GFP_ATOMIC );if (ret) -dev_warn (nct6694->dev,"Failed to resubmit urb, status %pe" ,ERR_PTR (ret)); +dev_warn (ddata->dev,"Failed to resubmit urb, status %pe" ,ERR_PTR (ret)); }static const struct irq_chip nct6694_irq_chip = {
@@ -256,9 +286,9 @@ static const struct irq_chip nct6694_irq_chip = {static int nct6694_irq_domain_map (struct irq_domain *d,unsigned int irq,irq_hw_number_t hw) { -struct nct6694 *nct6694 = d->host_data; +struct nct6694 *ddata = d->host_data; -irq_set_chip_data (irq, nct6694); +irq_set_chip_data (irq, ddata);irq_set_chip_and_handler (irq, &nct6694_irq_chip, handle_simple_irq);return 0 ;
@@ -287,9 +317,10 @@ static int nct6694_usb_probe(struct usb_interface *iface,USB_DIR_IN |NCT6694_INT_IN_EP , 0 }; -struct usb_device *udev =interface_to_usbdev (iface); +struct usb_device *usb_dev =interface_to_usbdev (iface); +struct nct6694_usb_data *usb_data;struct device *dev = &iface->dev; -struct nct6694 *nct6694; +struct nct6694 *ddata;unsigned int int_pipe;int ret;
@@ -297,56 +328,59 @@ static int nct6694_usb_probe(struct usb_interface *iface, !usb_check_int_endpoints(iface, int_ep_addr))return -ENODEV ; - nct6694 =devm_kzalloc_obj (dev, *nct6694); -if (!nct6694) + usb_data =devm_kzalloc_obj (dev, *usb_data); +if (!usb_data)return -ENOMEM ; - nct6694->usb_msg = devm_kzalloc_obj(dev, union nct6694_usb_msg); -if (!nct6694->usb_msg) + usb_data->hdr_buf =devm_kzalloc_obj (dev, *usb_data->hdr_buf); +if (!usb_data->hdr_buf)return -ENOMEM ; - nct6694->data_buf =devm_kzalloc (dev,NCT6694_MAX_DATA_LEN ,GFP_KERNEL ); -if (!nct6694->data_buf) + usb_data->data_buf =devm_kzalloc (dev,NCT6694_MAX_DATA_LEN ,GFP_KERNEL ); +if (!usb_data->data_buf)return -ENOMEM ; - nct6694->int_buffer =devm_kzalloc_obj (dev, *nct6694->int_buffer); -if (!nct6694->int_buffer) + usb_data->int_buf =devm_kzalloc_obj (dev, *usb_data->int_buf); +if (!usb_data->int_buf)return -ENOMEM ; - nct6694->int_in_urb =usb_alloc_urb (0 ,GFP_KERNEL ); -if (!nct6694->int_in_urb) + usb_data->int_urb =usb_alloc_urb (0 ,GFP_KERNEL ); +if (!usb_data->int_urb)return -ENOMEM ; - nct6694->domain =irq_domain_create_simple (NULL ,NCT6694_NR_IRQS ,0 , - &nct6694_irq_domain_ops, - nct6694); -if (!nct6694->domain) { + 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; } - nct6694->dev = dev; - nct6694->udev = udev; + ddata->dev = dev; + usb_data->usb_dev = usb_dev; -ida_init (&nct6694->gpio_ida); -ida_init (&nct6694->i2c_ida); -ida_init (&nct6694->canfd_ida); -ida_init (&nct6694->wdt_ida); +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, &nct6694->access_lock); + ret =devm_mutex_init (dev, &usb_data->access_lock);if (ret) goto err_ida; - int_pipe =usb_rcvintpipe (udev,NCT6694_INT_IN_EP ); -usb_fill_int_urb (nct6694->int_in_urb, udev, int_pipe, - nct6694->int_buffer,sizeof (*nct6694->int_buffer), usb_int_callback, - nct6694,usb_pipe_endpoint (udev, int_pipe)->desc.bInterval); + int_pipe =usb_rcvintpipe (usb_dev,NCT6694_INT_IN_EP ); +usb_fill_int_urb (usb_data->int_urb, usb_dev, int_pipe, + usb_data->int_buf,sizeof (*usb_data->int_buf), + usb_int_callback, ddata, +usb_pipe_endpoint (usb_dev, int_pipe)->desc.bInterval); - ret =usb_submit_urb (nct6694->int_in_urb,GFP_KERNEL ); + ret =usb_submit_urb (usb_data->int_urb,GFP_KERNEL );if (ret) goto err_ida; -usb_set_intfdata (iface, nct6694); +usb_set_intfdata (iface, ddata); ret =mfd_add_hotplug_devices (dev, nct6694_devs,ARRAY_SIZE (nct6694_devs));if (ret)
@@ -355,30 +389,31 @@ static int nct6694_usb_probe(struct usb_interface *iface,return 0 ; err_mfd: -usb_kill_urb (nct6694->int_in_urb); +usb_kill_urb (usb_data->int_urb); err_ida: -ida_destroy (&nct6694->wdt_ida); -ida_destroy (&nct6694->canfd_ida); -ida_destroy (&nct6694->i2c_ida); -ida_destroy (&nct6694->gpio_ida); -irq_domain_remove (nct6694->domain); +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: -usb_free_urb (nct6694->int_in_urb); +usb_free_urb (usb_data->int_urb);return ret; }static void nct6694_usb_disconnect (struct usb_interface *iface) { -struct nct6694 *nct6694 =usb_get_intfdata (iface); - -mfd_remove_devices (nct6694->dev); -usb_kill_urb (nct6694->int_in_urb); -ida_destroy (&nct6694->wdt_ida); -ida_destroy (&nct6694->canfd_ida); -ida_destroy (&nct6694->i2c_ida); -ida_destroy (&nct6694->gpio_ida); -irq_domain_remove (nct6694->domain); -usb_free_urb (nct6694->int_in_urb); +struct nct6694 *ddata =usb_get_intfdata (iface); +struct nct6694_usb_data *usb_data =to_nct6694_usb_data (ddata); + +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); +usb_free_urb (usb_data->int_urb); }static const struct usb_device_id nct6694_ids[] = {
include/linux/mfd/nct6694.h +4 -22
@@ -2,7 +2,8 @@/* * Copyright (C) 2025 Nuvoton Technology Corp. * -* Nuvoton NCT6694 USB transaction and data structure. +* Nuvoton NCT6694 core definitions shared by the transport driver +* and the sub-device drivers. */ #ifndef __MFD_NCT6694_H
@@ -17,17 +18,9 @@#define NCT6694_RPT_MOD 0xFF#define NCT6694_GPIO_MOD NCT6694_RPT_MOD -#define NCT6694_VENDOR_ID 0x0416 -#define NCT6694_PRODUCT_ID 0x200B -#define NCT6694_INT_IN_EP 0x01 -#define NCT6694_BULK_IN_EP 0x02 -#define NCT6694_BULK_OUT_EP 0x03 -#define NCT6694_HCTRL_SET 0x40#define NCT6694_HCTRL_GET 0x80 -#define NCT6694_URB_TIMEOUT 1000 -/* Maximum data packet length the firmware accepts in a single command */ #define NCT6694_MAX_DATA_LEN 0x3F0
@@ -87,11 +80,6 @@ struct __packed nct6694_response_header {__le16 len; }; -union __packed nct6694_usb_msg { -struct nct6694_cmd_header cmd_header; -struct nct6694_response_header response_header; -}; -struct nct6694 {struct device *dev;struct ida gpio_ida;
@@ -99,15 +87,9 @@ struct nct6694 {struct ida canfd_ida;struct ida wdt_ida; struct irq_domain *domain; -struct mutex access_lock; -struct urb *int_in_urb; -struct usb_device *udev; -union nct6694_usb_msg *usb_msg; -void *data_buf; - __le32 *int_buffer; }; -int nct6694_read_msg (struct nct6694 *nct6694,const struct nct6694_cmd_header *cmd_hd,void *buf); -int nct6694_write_msg (struct nct6694 *nct6694,const struct nct6694_cmd_header *cmd_hd,void *buf); +int nct6694_read_msg (struct nct6694 *ddata,const struct nct6694_cmd_header *cmd_hd,void *buf); +int nct6694_write_msg (struct nct6694 *ddata,const struct nct6694_cmd_header *cmd_hd,void *buf);#endif
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v10 07/13] mfd: nct6694: Refactor USB-specific data into nct6694_usb_data
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
From: Ming Yu <[email protected]>
Separate the USB transport fields from the core nct6694 structure into a new
nct6694_usb_datastructure, which embeds struct nct6694 and is retrieved withcontainer_of(). USB-only definitions are moved from the shared header into the USB driver.
Quoted 6 lines
While at it, use consistent names for the USB device, the buffers and the core structure.
No functional change.
Signed-off-by Ming Yu <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
PATCH v10 8/13 mfd: nct6694: Rename USB transport functions with _usb_ prefix
In reply to [email protected]From: Ming Yu <[email protected]>
Add a _usb_ prefix to the USB transport functions, tables and driver name to mark them as USB specific, in preparation for the core and HIF transport added in later patches.
Keep nct6694_{read,write}_msg() as static inline wrappers in the shared header so that the sub-device drivers remain untouched; they are reimplemented on top of regmap later in the series.
No functional change.
---
Changes in v10:
- None.
Changes in v9:
- Reworded the commit message: the wrappers are reimplemented on top of regmap rather than removed.
Changes in v8:
- None.
Changes in v7:
- None.
Changes in v6:
- New patch replacing the v5 function-pointer transport abstraction:
rename the exported I/O functions with an _usb_ prefix and add transitional inline nct6694_{read,write}_msg() wrappers in the shared header so sub-device drivers stay untouched in this commit.
drivers/mfd/nct6694.c | 40 ++++++++++++++++++++----------------- include/linux/mfd/nct6694.h | 22 ++++++++++++++++++-- 2 files changed, 42 insertions(+), 20 deletions(-)
drivers/mfd/nct6694.c +22 -18
@@ -49,7 +49,7 @@ static struct nct6694_usb_data *to_nct6694_usb_data(struct nct6694 *ddata) return container_of(ddata, struct nct6694_usb_data, core); } -static const struct mfd_cell nct6694_devs[] = { +static const struct mfd_cell nct6694_usb_devs[] = {MFD_CELL_NAME ("nct6694-gpio" ),MFD_CELL_NAME ("nct6694-gpio" ),MFD_CELL_NAME ("nct6694-gpio" ),
@@ -85,7 +85,7 @@ static const struct mfd_cell nct6694_devs[] = { MFD_CELL_NAME("nct6694-rtc"), }; -static int nct6694_response_err_handling (struct nct6694 *ddata,unsigned char err_status) +static int nct6694_usb_err_handling (struct nct6694 *ddata,unsigned char err_status) {switch (err_status) {case NCT6694_NO_ERROR :
@@ -110,7 +110,7 @@ static int nct6694_response_err_handling(struct nct6694 *ddata, unsigned char er }/** -* nct6694_read_msg() - Read message from NCT6694 device +* nct6694_usb_read_msg() - Read message from NCT6694 device * @ddata: NCT6694 device pointer * @cmd_hd: command header structure * @buf: buffer to store the response data
@@ -121,7 +121,9 @@ static int nct6694_response_err_handling(struct nct6694 *ddata, unsigned char er* * Return: Negative value on error or 0 on success. */ -int nct6694_read_msg (struct nct6694 *ddata,const struct nct6694_cmd_header *cmd_hd,void *buf) +int nct6694_usb_read_msg (struct nct6694 *ddata, +const struct nct6694_cmd_header *cmd_hd, +void *buf) {struct nct6694_usb_data *usb_data =to_nct6694_usb_data (ddata);union nct6694_usb_hdr *hdr = usb_data->hdr_buf;
@@ -169,12 +171,12 @@ int nct6694_read_msg(struct nct6694 *ddata, const struct nct6694_cmd_header *cmdmemcpy (buf, usb_data->data_buf, data_len); -return nct6694_response_err_handling (ddata, hdr->response_header.sts); +return nct6694_usb_err_handling (ddata, hdr->response_header.sts); } -EXPORT_SYMBOL_GPL (nct6694_read_msg); +EXPORT_SYMBOL_GPL (nct6694_usb_read_msg);/** -* nct6694_write_msg() - Write message to NCT6694 device +* nct6694_usb_write_msg() - Write message to NCT6694 device * @ddata: NCT6694 device pointer * @cmd_hd: command header structure * @buf: buffer containing the data to be sent
@@ -184,7 +186,9 @@ EXPORT_SYMBOL_GPL(nct6694_read_msg);* * Return: Negative value on error or 0 on success. */ -int nct6694_write_msg (struct nct6694 *ddata,const struct nct6694_cmd_header *cmd_hd,void *buf) +int nct6694_usb_write_msg (struct nct6694 *ddata, +const struct nct6694_cmd_header *cmd_hd, +void *buf) {struct nct6694_usb_data *usb_data =to_nct6694_usb_data (ddata);union nct6694_usb_hdr *hdr = usb_data->hdr_buf;
@@ -239,11 +243,11 @@ int nct6694_write_msg(struct nct6694 *ddata, const struct nct6694_cmd_header *cmmemcpy (buf, usb_data->data_buf, data_len); -return nct6694_response_err_handling (ddata, hdr->response_header.sts); +return nct6694_usb_err_handling (ddata, hdr->response_header.sts); } -EXPORT_SYMBOL_GPL (nct6694_write_msg); +EXPORT_SYMBOL_GPL (nct6694_usb_write_msg); -static void usb_int_callback (struct urb *urb) +static void nct6694_usb_int_callback (struct urb *urb) {struct nct6694 *ddata = urb->context;__le32 *status_le = urb->transfer_buffer;
@@ -373,7 +377,7 @@ static int nct6694_usb_probe(struct usb_interface *iface, int_pipe =usb_rcvintpipe (usb_dev,NCT6694_INT_IN_EP );usb_fill_int_urb (usb_data->int_urb, usb_dev, int_pipe, usb_data->int_buf,sizeof (*usb_data->int_buf), - usb_int_callback, ddata, + nct6694_usb_int_callback, ddata,usb_pipe_endpoint (usb_dev, int_pipe)->desc.bInterval); ret =usb_submit_urb (usb_data->int_urb,GFP_KERNEL );
@@ -382,7 +386,7 @@ static int nct6694_usb_probe(struct usb_interface *iface,usb_set_intfdata (iface, ddata); - ret =mfd_add_hotplug_devices (dev, nct6694_devs,ARRAY_SIZE (nct6694_devs)); + ret =mfd_add_hotplug_devices (dev, nct6694_usb_devs,ARRAY_SIZE (nct6694_usb_devs));if (ret) goto err_mfd;
@@ -416,20 +420,20 @@ static void nct6694_usb_disconnect(struct usb_interface *iface)usb_free_urb (usb_data->int_urb); } -static const struct usb_device_id nct6694_ids[] = { +static const struct usb_device_id nct6694_usb_ids[] = { {USB_DEVICE_AND_INTERFACE_INFO (NCT6694_VENDOR_ID ,NCT6694_PRODUCT_ID ,0xFF ,0x00 ,0x00 ) }, { } }; -MODULE_DEVICE_TABLE (usb, nct6694_ids); +MODULE_DEVICE_TABLE (usb, nct6694_usb_ids);static struct usb_driver nct6694_usb_driver = { - .name ="nct6694" , - .id_table = nct6694_ids, + .name ="nct6694-usb" , + .id_table = nct6694_usb_ids, .probe = nct6694_usb_probe, .disconnect = nct6694_usb_disconnect, };module_usb_driver (nct6694_usb_driver); -MODULE_DESCRIPTION ("Nuvoton NCT6694 core driver" ); +MODULE_DESCRIPTION ("Nuvoton NCT6694 USB transport driver" );MODULE_AUTHOR ("Ming Yu <[email protected]>" );MODULE_LICENSE ("GPL" );
include/linux/mfd/nct6694.h +20 -2
@@ -89,7 +89,25 @@ struct nct6694 { struct irq_domain *domain; }; -int nct6694_read_msg (struct nct6694 *ddata,const struct nct6694_cmd_header *cmd_hd,void *buf); -int nct6694_write_msg (struct nct6694 *ddata,const struct nct6694_cmd_header *cmd_hd,void *buf); +int nct6694_usb_read_msg (struct nct6694 *ddata, +const struct nct6694_cmd_header *cmd_hd, +void *buf); +int nct6694_usb_write_msg (struct nct6694 *ddata, +const struct nct6694_cmd_header *cmd_hd, +void *buf); + +static inline int nct6694_read_msg (struct nct6694 *ddata, +const struct nct6694_cmd_header *cmd_hd, +void *buf) +{ +return nct6694_usb_read_msg (ddata, cmd_hd, buf); +} + +static inline int nct6694_write_msg (struct nct6694 *ddata, +const struct nct6694_cmd_header *cmd_hd, +void *buf) +{ +return nct6694_usb_write_msg (ddata, cmd_hd, buf); +}#endif
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v10 08/13] mfd: nct6694: Rename USB transport functions with _usb_ prefix
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
From: Ming Yu <[email protected]>
Add a _usb_ prefix to the USB transport functions, tables and driver name to mark them as USB specific, in preparation for the core and HIF transport added in later patches.
Quoted 7 lines
Keep nct6694_{read,write}_msg() as static inline wrappers in the shared header so that the sub-device drivers remain untouched; they are reimplemented on top of regmap later in the series.
No functional change.
Signed-off-by Ming Yu <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
PATCH v10 9/13 mfd: nct6694: Rename driver to nct6694-usb
In reply to [email protected]From: Ming Yu <[email protected]>
Rename nct6694.c to nct6694-usb.c to reflect that it implements the USB transport, in preparation for the core and HIF transport added in later patches. The module is renamed to nct6694-usb accordingly.
No functional change.
---
Changes in v10:
- None.
Changes in v9:
- None.
Changes in v8:
- Only rename the file; the Kconfig split moves to the patch that introduces nct6694-core.c.
Changes in v7:
- None.
Changes in v6:
- None.
Changes in v5:
- Split from the monolithic v4 patch to follow the single logical change principle.
MAINTAINERS | 2 +-
drivers/mfd/Makefile | 2 +-
drivers/mfd/{nct6694.c => nct6694-usb.c} | 0
3 files changed, 2 insertions(+), 2 deletions(-)
rename drivers/mfd/{nct6694.c => nct6694-usb.c} (100%)MAINTAINERS +1 -1
@@ -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.c +F: drivers/mfd/nct6694-usb.c F: drivers/net/can/usb/nct6694_canfd.c F: drivers/rtc/rtc-nct6694.c F: drivers/watchdog/nct6694_wdt.c
drivers/mfd/Makefile +1 -1
@@ -124,7 +124,7 @@ obj-$(CONFIG_MFD_MC13XXX_I2C) += mc13xxx-i2c.o obj-$(CONFIG_MFD_PF1550) += pf1550.o -obj-$(CONFIG_MFD_NCT6694) += nct6694.o +obj-$(CONFIG_MFD_NCT6694) += nct6694-usb.o obj-$(CONFIG_MFD_CORE) += mfd-core.o
drivers/mfd/nct6694-usb.c renamed from drivers/mfd/nct6694.c +0 -0
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v10 09/13] mfd: nct6694: Rename driver to nct6694-usb
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
From: Ming Yu <[email protected]>
Rename
nct6694.ctonct6694-usb.cto reflect that it implements the USB transport, in preparation for the core and HIF transport added in later patches. The module is renamed to nct6694-usb accordingly.No functional change.
Signed-off-by Ming Yu <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
PATCH v10 10/13 mfd: nct6694: Extract core device management into a separate module
In reply to [email protected]From: Ming Yu <[email protected]>
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.
---
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
MAINTAINERS +1 -1
@@ -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
drivers/mfd/Makefile +1 -0
@@ -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
drivers/mfd/nct6694-core.c new file +85 -0
85 lines not on this page · raw message
drivers/mfd/nct6694-usb.c +14 -59
117 lines not on this page · raw message
include/linux/mfd/nct6694.h +3 -0
@@ -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);
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v10 10/13] mfd: nct6694: Extract core device management into a separate module
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
From: Ming Yu <[email protected]>
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.
Quoted 6 lines
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 <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
PATCH v10 11/13 mfd: nct6694: Introduce regmap-based transport abstraction
In reply to [email protected]From: Ming Yu <[email protected]>
Sub-device drivers call into the USB transport directly, so a second transport cannot be added without touching all of them.
Wrap the transport behind a regmap bus. The command header is mapped onto a single 32-bit register by packing the host control byte, the module id and the 16-bit offset, so that the sub-device drivers can use the regmap bulk accessors. The access_lock is dropped as regmap already serialises the bus accesses. Transfers larger than the transport buffer are rejected, as the length field of the command header is 16 bits wide.
Add nct6694_write_read_msg() for the commands that send a request and read the reply back in the same firmware message, and use it for the I2C deliver command.
---
Changes in v10:
- None.
Changes in v9:
- Rejected transfers larger than NCT6694_MAX_DATA_LEN in the regmap bus callbacks, as the length field of the command header is 16 bits wide.
- Added Andi's Acked-by.
Changes in v8:
- Renamed the transport buffer arguments to tx_buf/rx_buf.
- Dropped max_raw_read/max_raw_write from the regmap_config, as they are ignored when a regmap_bus is provided.
Changes in v7:
- Made the USB transport helpers static and gave nct6694_usb_write_msg() separate @tx/@rx buffers, so a SET command only copies the firmware reply back when the caller asks for it.
- Documented in the shared header why nct6694_write_read_msg() is expressed as a read of a SET register.
Changes in v6:
- New patch. Replaces the v5 function-pointer abstraction with a regmap_bus based transport: the firmware command header is packed into a single 32-bit regmap register and sub-device drivers use the regmap bulk accessors. Adds nct6694_write_read_msg() for request/response commands and drops the per-transport access_lock (regmap already serialises bus accesses).
drivers/i2c/busses/i2c-nct6694.c | 2 +- drivers/mfd/Kconfig | 1 + drivers/mfd/nct6694-usb.c | 108 +++++++++++++++++++------------ include/linux/mfd/nct6694.h | 53 ++++++++++++--- 4 files changed, 114 insertions(+), 50 deletions(-)
drivers/i2c/busses/i2c-nct6694.c +1 -1
@@ -77,7 +77,7 @@ static int nct6694_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int deliver->addr =i2c_8bit_addr_from_msg (msg_temp);if (msg_temp->flags &I2C_M_RD ) { deliver->r_cnt = msg_temp->len; - ret =nct6694_write_msg (data->nct6694, &cmd_hd, deliver); + ret =nct6694_write_read_msg (data->nct6694, &cmd_hd, deliver);if (ret <0 )return ret;
drivers/mfd/Kconfig +1 -0
@@ -1182,6 +1182,7 @@ config MFD_MENF21BMC config MFD_NCT6694 tristate "Nuvoton NCT6694 support" select MFD_CORE + select REGMAP depends on USB help This enables support for the Nuvoton USB device NCT6694, which shares
drivers/mfd/nct6694-usb.c +67 -41
173 lines not on this page · raw message
include/linux/mfd/nct6694.h +45 -8
82 lines not on this page · raw message
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v10 11/13] mfd: nct6694: Introduce regmap-based transport abstraction
Sashiko has reviewed this patch and found no issues.
Quoted 12 lines
From: Ming Yu <[email protected]>
Sub-device drivers call into the USB transport directly, so a second transport cannot be added without touching all of them.
Wrap the transport behind a regmap bus. The command header is mapped onto a single 32-bit register by packing the host control byte, the module id and the 16-bit offset, so that the sub-device drivers can use the regmap bulk accessors. The
access_lockis dropped as regmap already serialises the bus accesses. Transfers larger than the transport buffer are rejected, as the length field of the command header is 16 bits wide.
Quoted 6 lines
Add
nct6694_write_read_msg()for the commands that send a request and read the reply back in the same firmware message, and use it for the I2C deliver command.Acked-by Andi Shyti <[email protected]>Signed-off-by Ming Yu <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
PATCH v10 12/13 mfd: nct6694: Add a Kconfig symbol for the USB transport
In reply to [email protected]From: Ming Yu <[email protected]>
Now that the sub-device drivers only access the device through regmap, the core no longer depends on USB.
Build the USB transport under a new MFD_NCT6694_USB symbol and keep MFD_NCT6694 for the core. MFD_NCT6694_USB defaults to MFD_NCT6694 so that existing configurations keep the USB transport enabled.
---
Changes in v10:
- None.
Changes in v9:
- None.
Changes in v8:
- New patch. Split out of v7 "Rename driver to nct6694-usb and update Kconfig"; MFD_NCT6694 remains the user visible core symbol and MFD_NCT6694_USB defaults to it to keep existing configurations working.
drivers/mfd/Kconfig | 20 ++++++++++++++++---- drivers/mfd/Makefile | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-)
drivers/mfd/Kconfig +16 -4
@@ -1183,18 +1183,30 @@ config MFD_NCT6694 tristate "Nuvoton NCT6694 support" select MFD_CORE select REGMAP - depends on USB help - This enables support for the Nuvoton USB device NCT6694, which shares + This enables support for the Nuvoton NCT6694, which shares peripherals. The Nuvoton NCT6694 is a peripheral expander with 16 GPIO chips, 6 I2C controllers, 2 CANfd controllers, 2 Watchdog timers, ADC, PWM, and RTC. - This driver provides core APIs to access the NCT6694 hardware - monitoring and control features. + This driver provides the core support shared by the transport + interface drivers, at least one of which must be enabled. Additional drivers must be enabled to utilize the specific functionalities of the device. +config MFD_NCT6694_USB + tristate "Nuvoton NCT6694 USB interface support" + depends on MFD_NCT6694 && USB + default MFD_NCT6694 + help + This enables support for the Nuvoton NCT6694 connected through + its USB interface. The driver uses USB bulk transfers to send + commands to the device firmware and an interrupt transfer to + receive its interrupt status. + + To compile this driver as a module, choose M here: the module + will be called nct6694-usb. + config MFD_OCELOT tristate "Microsemi Ocelot External Control Support" depends on SPI_MASTER
drivers/mfd/Makefile +1 -1
@@ -125,7 +125,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_NCT6694_USB) += nct6694-usb.o obj-$(CONFIG_MFD_CORE) += mfd-core.o
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v10 12/13] mfd: nct6694: Add a Kconfig symbol for the USB transport
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
From: Ming Yu <[email protected]>
Now that the sub-device drivers only access the device through regmap, the core no longer depends on USB.
Build the USB transport under a new
MFD_NCT6694_USBsymbol and keepMFD_NCT6694for the core.MFD_NCT6694_USBdefaults toMFD_NCT6694so that existing configurations keep the USB transport enabled.Signed-off-by Ming Yu <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
PATCH v10 13/13 mfd: nct6694: Add Host Interface (HIF) eSPI transport driver
In reply to [email protected]From: Ming Yu <[email protected]>
Add support for the Host Interface (HIF) transport over eSPI for the Nuvoton NCT6694.
The driver locates the Super-I/O to configure the shared memory base address and SIRQ, and implements a regmap_bus that exchanges firmware commands through the shared memory window. Report accesses are served from a separate MMIO regmap.
---
Changes in v10:
- Commented that a read of a SET register passes val_buf as the write-then-read request.
- Allocated sio_data and hif_data with devm_kzalloc_obj().
Changes in v9:
- Rejected transfers larger than NCT6694_MAX_DATA_LEN in the regmap bus callbacks.
Changes in v8:
- Embedded struct nct6694 in nct6694_hif_data and dropped the priv pointer; renamed hdata to hif_data and the transfer buffers and lengths consistently with the USB transport.
- Adapted to nct6694_device_{init,exit}() and register the MFD cells from the transport.
- Request the interrupt after the core is set up, so that it is freed before the IRQ domain is removed.
- Dropped the max_raw_read/max_raw_write settings, which are ignored with a regmap_bus.
Changes in v7:
- Zero the tail of the caller buffer when the firmware answers with fewer bytes than requested, and split the transfer helper into separate @tx/@rx buffers instead of a shared scratch buffer.
- Request the interrupt before registering the core, so devres frees it after the sub-devices are removed. Mask the interrupt and clear a stale status in nct6694_hif_irq_init() so the handler cannot run before the IRQ domain exists.
- Return IRQ_HANDLED once the interrupt status has been cleared.
- Skip hardware interrupts that have no mapping instead of dispatching virq 0.
- Bail out with -ENODEV if the BIOS left the shared memory base address unconfigured.
- Program the SIRQ register with the hardware interrupt number rather than the Linux virq.
Changes in v6:
- Reworked the transport to implement a regmap_bus instead of the v5 read_msg/write_msg function pointers.
Changes in v5:
- Split from the monolithic v4 patch.
- Adapted to re-use the newly introduced nct6694_core_probe() and abstracted I/O APIs.
Changes since version 3:
- Remove redundant module type macro definitions from sub-device drivers that are now provided by the shared header <linux/mfd/nct6694.h>, fixing -Wmacro-redefined warnings.
Changes since version 2:
- Restore per-device IDA and mfd_add_hotplug_devices()/PLATFORM_DEVID_AUTO to avoid child device ID conflicts with multiple NCT6694 chips.
- Validate irq_find_mapping() return value before dispatching IRQs.
- Check superio_enter() return value in nct6694_irq_init().
Changes since version 1:
- Drop function pointers from Super-I/O access and use static inline helpers with proper types.
drivers/mfd/Kconfig | 13 + drivers/mfd/Makefile | 1 + drivers/mfd/nct6694-hif.c | 579 ++++++++++++++++++++++++++++++++++++ include/linux/mfd/nct6694.h | 2 +- 4 files changed, 594 insertions(+), 1 deletion(-) create mode 100644 drivers/mfd/nct6694-hif.c
drivers/mfd/Kconfig +13 -0
@@ -1194,6 +1194,19 @@ config MFD_NCT6694 Additional drivers must be enabled to utilize the specific functionalities of the device. +config MFD_NCT6694_HIF + tristate "Nuvoton NCT6694 HIF (eSPI) interface support" + depends on MFD_NCT6694 && HAS_IOPORT && ACPI + select REGMAP_MMIO + help + This enables support for the Nuvoton NCT6694 connected through + the Host Interface (HIF) over eSPI. The driver uses the Super-I/O + configuration and the shared memory window to send commands to + the device firmware. + + To compile this driver as a module, choose M here: the module + will be called nct6694-hif. + config MFD_NCT6694_USB tristate "Nuvoton NCT6694 USB interface support" depends on MFD_NCT6694 && USB
drivers/mfd/Makefile +1 -0
@@ -125,6 +125,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_HIF) += nct6694-hif.o obj-$(CONFIG_MFD_NCT6694_USB) += nct6694-usb.o obj-$(CONFIG_MFD_CORE) += mfd-core.o
drivers/mfd/nct6694-hif.c new file +579 -0
579 lines not on this page · raw message
include/linux/mfd/nct6694.h +1 -1
@@ -2,7 +2,7 @@/* * Copyright (C) 2025 Nuvoton Technology Corp. * -* Nuvoton NCT6694 core definitions shared by the transport driver +* Nuvoton NCT6694 core definitions shared by the transport drivers * and the sub-device drivers. */
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v10 13/13] mfd: nct6694: Add Host Interface (HIF) eSPI transport driver
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
From: Ming Yu <[email protected]>
Add support for the Host Interface (HIF) transport over eSPI for the Nuvoton NCT6694.
The driver locates the Super-I/O to configure the shared memory base address and SIRQ, and implements a
regmap_busthat exchanges firmware commands through the shared memory window. Report accesses are served from a separate MMIO regmap.Signed-off-by Ming Yu <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13