mfd: nct6694: Move module type macros to shared header
Subsystems (8)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v5 1/7 mfd: nct6694: Move module type macros to shared header
From: Ming Yu <[email protected]>
Move NCT6694_XXX_MOD macro definitions from individual sub-device drivers into the shared header include/linux/mfd/nct6694.h.
This is a prerequisite for supporting multiple transport interfaces (USB, HIF) without duplicating these definitions.
No functional change.
---
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
@@ -20,13 +20,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 0x81
Signature · 1 line
2.34.1
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines
From: Ming Yu <[email protected]>
Move
NCT6694_XXX_MODmacro definitions from individual sub-device drivers into the shared headerinclude/linux/mfd/nct6694.h.This is a prerequisite for supporting multiple transport interfaces (USB, HIF) without duplicating these definitions.
No functional change.
Signed-off-by Ming Yu <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v5 2/7 mfd: nct6694: Refactor USB-specific data into nct6694_usb_data
In reply to a message not in the archiveFrom: Ming Yu <[email protected]>
Separate USB transport-specific fields from the core nct6694 structure into a new nct6694_usb_data structure. This decouples the shared MFD core from the USB transport layer, preparing the driver for potential support of alternative transport backends in the future.
The following fields are moved into nct6694_usb_data:
- access_lock
- int_in_urb
- udev
- usb_msg
- int_buffer
The core nct6694 structure now holds a void *priv pointer to reference the transport-specific data. USB-only definitions (vendor/product IDs, endpoint addresses, URB timeout, and the USB message union) are also moved from the shared header into the USB driver source file.
---
Changes in v5:
- Split from the monolithic v4 patch to follow the single logical change principle.
drivers/mfd/nct6694.c | 76 ++++++++++++++++++++++++++----------- include/linux/mfd/nct6694.h | 27 ++++--------- 2 files changed, 62 insertions(+), 41 deletions(-)
drivers/mfd/nct6694.c +54 -22
@@ -10,8 +10,8 @@*/ #include <linux/bits.h> -#include <linux/interrupt.h> #include <linux/idr.h> +#include <linux/interrupt.h> #include <linux/irq.h> #include <linux/irqdomain.h> #include <linux/kernel.h>
@@ -22,6 +22,27 @@#include <linux/spinlock.h> #include <linux/usb.h> +#define NCT6694_VENDOR_ID 0x0416 +#define NCT6694_PRODUCT_ID 0x200B +#define NCT6694_INT_IN_EP 0x81 +#define NCT6694_BULK_IN_EP 0x02 +#define NCT6694_BULK_OUT_EP 0x03 + +#define NCT6694_URB_TIMEOUT 1000 + +union __packed nct6694_usb_msg { +struct nct6694_cmd_header cmd_header; +struct nct6694_response_header response_header; +}; + +struct nct6694_usb_data { +struct mutex access_lock; +struct urb *int_in_urb; +struct usb_device *udev; +union nct6694_usb_msg *usb_msg; +__le32 *int_buffer; +}; +static const struct mfd_cell nct6694_devs[] = {MFD_CELL_NAME ("nct6694-gpio" ),MFD_CELL_NAME ("nct6694-gpio" ),
@@ -96,11 +117,12 @@ static int nct6694_response_err_handling(struct nct6694 *nct6694, unsigned char*/ int nct6694_read_msg (struct nct6694 *nct6694,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 *udata = nct6694->priv; +union nct6694_usb_msg *msg = udata->usb_msg; +struct usb_device *udev = udata->udev;int tx_len, rx_len, ret; -guard (mutex)(&nct6694->access_lock); +guard (mutex)(&udata->access_lock);memcpy (&msg->cmd_header, cmd_hd,sizeof (*cmd_hd)); msg->cmd_header.hctrl =NCT6694_HCTRL_GET ;
@@ -146,11 +168,12 @@ EXPORT_SYMBOL_GPL(nct6694_read_msg);*/ int nct6694_write_msg (struct nct6694 *nct6694,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 *udata = nct6694->priv; +union nct6694_usb_msg *msg = udata->usb_msg; +struct usb_device *udev = udata->udev;int tx_len, rx_len, ret; -guard (mutex)(&nct6694->access_lock); +guard (mutex)(&udata->access_lock);memcpy (&msg->cmd_header, cmd_hd,sizeof (*cmd_hd)); msg->cmd_header.hctrl =NCT6694_HCTRL_SET ;
@@ -277,6 +300,7 @@ static int nct6694_usb_probe(struct usb_interface *iface,struct usb_endpoint_descriptor *int_endpoint;struct usb_host_interface *interface;struct device *dev = &iface->dev; +struct nct6694_usb_data *udata;struct nct6694 *nct6694;int ret;
@@ -284,18 +308,26 @@ static int nct6694_usb_probe(struct usb_interface *iface,if (!nct6694)return -ENOMEM ; - nct6694->usb_msg =devm_kzalloc (dev,sizeof (union nct6694_usb_msg ),GFP_KERNEL ); -if (!nct6694->usb_msg) + udata =devm_kzalloc (dev,sizeof (*udata),GFP_KERNEL ); +if (!udata) +return -ENOMEM ; + + udata->usb_msg =devm_kzalloc (dev,sizeof (*udata->usb_msg),GFP_KERNEL ); +if (!udata->usb_msg)return -ENOMEM ; - nct6694->int_buffer =devm_kzalloc (dev,sizeof (*nct6694->int_buffer),GFP_KERNEL ); -if (!nct6694->int_buffer) + udata->int_buffer =devm_kzalloc (dev,sizeof (*udata->int_buffer),GFP_KERNEL ); +if (!udata->int_buffer)return -ENOMEM ; - nct6694->int_in_urb =usb_alloc_urb (0 ,GFP_KERNEL ); -if (!nct6694->int_in_urb) + udata->int_in_urb =usb_alloc_urb (0 ,GFP_KERNEL ); +if (!udata->int_in_urb)return -ENOMEM ; + udata->udev = udev; + + nct6694->priv = udata; + nct6694->domain =irq_domain_create_simple (NULL ,NCT6694_NR_IRQS ,0 , &nct6694_irq_domain_ops, nct6694);
@@ -305,7 +337,6 @@ static int nct6694_usb_probe(struct usb_interface *iface, } nct6694->dev = dev; - nct6694->udev = udev;ida_init (&nct6694->gpio_ida);ida_init (&nct6694->i2c_ida);
@@ -314,7 +345,7 @@ static int nct6694_usb_probe(struct usb_interface *iface,spin_lock_init (&nct6694->irq_lock); - ret =devm_mutex_init (dev, &nct6694->access_lock); + ret =devm_mutex_init (dev, &udata->access_lock);if (ret) goto err_ida;
@@ -326,11 +357,11 @@ static int nct6694_usb_probe(struct usb_interface *iface, goto err_ida; } -usb_fill_int_urb (nct6694->int_in_urb, udev,usb_rcvintpipe (udev,NCT6694_INT_IN_EP ), - nct6694->int_buffer,sizeof (*nct6694->int_buffer), usb_int_callback, +usb_fill_int_urb (udata->int_in_urb, udev,usb_rcvintpipe (udev,NCT6694_INT_IN_EP ), + udata->int_buffer,sizeof (*udata->int_buffer), usb_int_callback, nct6694, int_endpoint->bInterval); - ret =usb_submit_urb (nct6694->int_in_urb,GFP_KERNEL ); + ret =usb_submit_urb (udata->int_in_urb,GFP_KERNEL );if (ret) goto err_ida;
@@ -343,7 +374,7 @@ static int nct6694_usb_probe(struct usb_interface *iface,return 0 ; err_mfd: -usb_kill_urb (nct6694->int_in_urb); +usb_kill_urb (udata->int_in_urb); err_ida:ida_destroy (&nct6694->wdt_ida);ida_destroy (&nct6694->canfd_ida);
@@ -351,22 +382,23 @@ static int nct6694_usb_probe(struct usb_interface *iface,ida_destroy (&nct6694->gpio_ida);irq_domain_remove (nct6694->domain); err_urb: -usb_free_urb (nct6694->int_in_urb); +usb_free_urb (udata->int_in_urb);return ret; }static void nct6694_usb_disconnect (struct usb_interface *iface) {struct nct6694 *nct6694 =usb_get_intfdata (iface); +struct nct6694_usb_data *udata = nct6694->priv;mfd_remove_devices (nct6694->dev); -usb_kill_urb (nct6694->int_in_urb); +usb_kill_urb (udata->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); +usb_free_urb (udata->int_in_urb); }static const struct usb_device_id nct6694_ids[] = {
include/linux/mfd/nct6694.h +8 -19
@@ -2,12 +2,18 @@/* * Copyright (C) 2025 Nuvoton Technology Corp. * -* Nuvoton NCT6694 USB transaction and data structure. +* Nuvoton NCT6694 core definitions shared by all transport drivers +* and sub-device drivers. */ #ifndef __MFD_NCT6694_H#define __MFD_NCT6694_H +#include <linux/idr.h> +#include <linux/mutex.h> +#include <linux/spinlock.h> +#include <linux/types.h> +#define NCT6694_HWMON_MOD 0x00#define NCT6694_PWM_MOD 0x01#define NCT6694_I2C_MOD 0x03
@@ -17,17 +23,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 0x81 -#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 -enum nct6694_irq_id {NCT6694_IRQ_GPIO0 =0 ,NCT6694_IRQ_GPIO1 ,
@@ -84,11 +82,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;
@@ -96,13 +89,9 @@ struct nct6694 {struct ida canfd_ida;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; -__le32 *int_buffer;unsigned int irq_enable; +void *priv; };int nct6694_read_msg (struct nct6694 *nct6694,const struct nct6694_cmd_header *cmd_hd,void *buf);
Signature · 1 line
2.34.1
PATCH v5 3/7 mfd: nct6694: Introduce transport abstraction with function pointers
In reply to a message not in the archiveFrom: Ming Yu <[email protected]>
Add read_msg and write_msg function pointers to struct nct6694 and provide static inline helpers for sub-devices. The USB-specific I/O functions are made static and assigned during probe.
This decouples sub-device drivers from the underlying USB implementation, paving the way for alternative transport interfaces (e.g., HIF) in the future without modifying client drivers.
---
Changes in v5:
- Split from the monolithic v4 patch to follow the single logical change principle.
drivers/mfd/nct6694.c | 12 ++++++++---- include/linux/mfd/nct6694.h | 22 ++++++++++++++++++++-- 2 files changed, 28 insertions(+), 6 deletions(-)
drivers/mfd/nct6694.c +8 -4
@@ -115,7 +115,9 @@ 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) +static int nct6694_read_msg (struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf) {struct nct6694_usb_data *udata = nct6694->priv;union nct6694_usb_msg *msg = udata->usb_msg;
@@ -153,7 +155,6 @@ int nct6694_read_msg(struct nct6694 *nct6694, const struct nct6694_cmd_header *creturn nct6694_response_err_handling (nct6694, msg->response_header.sts); } -EXPORT_SYMBOL_GPL (nct6694_read_msg);/** * nct6694_write_msg() - Write message to NCT6694 device
@@ -166,7 +167,9 @@ 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) +static int nct6694_write_msg (struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf) {struct nct6694_usb_data *udata = nct6694->priv;union nct6694_usb_msg *msg = udata->usb_msg;
@@ -210,7 +213,6 @@ int nct6694_write_msg(struct nct6694 *nct6694, const struct nct6694_cmd_header *return nct6694_response_err_handling (nct6694, msg->response_header.sts); } -EXPORT_SYMBOL_GPL (nct6694_write_msg);static void usb_int_callback (struct urb *urb) {
@@ -327,6 +329,8 @@ static int nct6694_usb_probe(struct usb_interface *iface, udata->udev = udev; nct6694->priv = udata; + nct6694->read_msg = nct6694_read_msg; + nct6694->write_msg = nct6694_write_msg; nct6694->domain = irq_domain_create_simple(NULL, NCT6694_NR_IRQS, 0, &nct6694_irq_domain_ops,
include/linux/mfd/nct6694.h +20 -2
@@ -92,9 +92,27 @@ struct nct6694 {spinlock_t irq_lock;unsigned int irq_enable;void *priv; + +int (*read_msg)(struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf); +int (*write_msg)(struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, + void *buf); }; -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); +static inline int nct6694_read_msg (struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf) +{ +return nct6694->read_msg (nct6694, cmd_hd, buf); +} + +static inline int nct6694_write_msg (struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf) +{ +return nct6694->write_msg (nct6694, cmd_hd, buf); +}#endif
Signature · 1 line
2.34.1
Lee Jones
maintainerRe: [PATCH v5 3/7] mfd: nct6694: Introduce transport abstraction with function pointers
Quoted 92 lines · On Mon, 25 May 2026, [email protected] wrote:
From: Ming Yu <[email protected]>
Add
read_msgandwrite_msgfunction pointers tostruct nct6694and provide static inline helpers for sub-devices. The USB-specific I/O functions are made static and assigned during probe.This decouples sub-device drivers from the underlying USB implementation, paving the way for alternative transport interfaces (e.g., HIF) in the future without modifying client drivers.
Signed-off-by Ming Yu <[email protected]>---
Changes in v5:
- Split from the monolithic v4 patch to follow the single logical change principle.drivers/mfd/nct6694.c | 12 ++++++++---- include/linux/mfd/nct6694.h | 22 ++++++++++++++++++++-- 2 files changed, 28 insertions(+), 6 deletions(-)drivers/mfd/nct6694.c +8
-4@@ -115,7 +115,9 @@ 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) +static int nct6694_read_msg (struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf) {struct nct6694_usb_data *udata = nct6694->priv;union nct6694_usb_msg *msg = udata->usb_msg;@@ -153,7 +155,6 @@ int nct6694_read_msg(struct nct6694 *nct6694, const struct nct6694_cmd_header *creturn nct6694_response_err_handling (nct6694, msg->response_header.sts); } -EXPORT_SYMBOL_GPL (nct6694_read_msg);/** * nct6694_write_msg() - Write message to NCT6694 device @@ -166,7 +167,9 @@ 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) +static int nct6694_write_msg (struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf) {struct nct6694_usb_data *udata = nct6694->priv;union nct6694_usb_msg *msg = udata->usb_msg;@@ -210,7 +213,6 @@ int nct6694_write_msg(struct nct6694 *nct6694, const struct nct6694_cmd_header *return nct6694_response_err_handling (nct6694, msg->response_header.sts); } -EXPORT_SYMBOL_GPL (nct6694_write_msg);static void usb_int_callback (struct urb *urb) {@@ -327,6 +329,8 @@ static int nct6694_usb_probe(struct usb_interface *iface, udata->udev = udev; nct6694->priv = udata; + nct6694->read_msg = nct6694_read_msg; + nct6694->write_msg = nct6694_write_msg; nct6694->domain = irq_domain_create_simple(NULL, NCT6694_NR_IRQS, 0, &nct6694_irq_domain_ops,include/linux/mfd/nct6694.h +10
-2@@ -92,9 +92,27 @@ struct nct6694 {spinlock_t irq_lock;unsigned int irq_enable;void *priv; + +int (*read_msg)(struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf); +int (*write_msg)(struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf); }; -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); +static inline int nct6694_read_msg (struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf)
include/linux/mfd/nct6694.h struct nct6694 { · line 116
Quoted 10 lines
include/linux/mfd/nct6694.h +10
-0+{ +return nct6694->read_msg (nct6694, cmd_hd, buf); +} + +static inline int nct6694_write_msg (struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf) +{ +return nct6694->write_msg (nct6694, cmd_hd, buf); +}
I very much dislike pointers to functions and abstraction for the sake of abstraction, at least at the driver-level.
Can you find another way to solve this problem please?
Signature · 1 line
Lee Jones
Re: [PATCH v5 3/7] mfd: nct6694: Introduce transport abstraction with function pointers
Dear Lee,
Thanks for the review.
Lee Jones <[email protected]> 於 2026年6月5日週五 上午12:25寫道:
Quoted 33 lines
Quoted 19 lines
include/linux/mfd/nct6694.h +10
-2@@ -92,9 +92,27 @@ struct nct6694 {spinlock_t irq_lock;unsigned int irq_enable;void *priv; + +int (*read_msg)(struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf); +int (*write_msg)(struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf); }; -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); +static inline int nct6694_read_msg (struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf)include/linux/mfd/nct6694.h struct nct6694 { · line 116
Quoted 10 lines
include/linux/mfd/nct6694.h +10
-0+{ +return nct6694->read_msg (nct6694, cmd_hd, buf); +} + +static inline int nct6694_write_msg (struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf) +{ +return nct6694->write_msg (nct6694, cmd_hd, buf); +}I very much dislike pointers to functions and abstraction for the sake of abstraction, at least at the driver-level.
Quoted 2 lines
Can you find another way to solve this problem please?
The reason for the abstraction is that patch 7/7 introduces a second transport (HIF/eSPI), and the sub-device drivers need a way to perform I/O without being coupled to a specific transport.
I'd like to rework this -- could you let me know which approach you'd prefer?
Keep nct6694_read_msg()/nct6694_write_msg() as exported functions in nct6694-core.c, with the core dispatching to the appropriate transport-specific implementation based on an internal transport type indicator.
Use a const struct nct6694_transport_ops *ops in struct nct6694, following the pattern used by subsystems like regmap_bus and spi_controller_mem_ops.
Happy to go with whichever direction you think is cleaner.
Thanks,
Ming
Lee Jones
maintainerRe: [PATCH v5 3/7] mfd: nct6694: Introduce transport abstraction with function pointers
Quoted 52 lines · Ming Yu
Dear Lee,
Thanks for the review.
Lee Jones <[email protected]> 於 2026年6月5日週五 上午12:25寫道:
Quoted 33 lines
Quoted 19 lines
include/linux/mfd/nct6694.h +10
-2@@ -92,9 +92,27 @@ struct nct6694 {spinlock_t irq_lock;unsigned int irq_enable;void *priv; + +int (*read_msg)(struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf); +int (*write_msg)(struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf); }; -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); +static inline int nct6694_read_msg (struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf)include/linux/mfd/nct6694.h struct nct6694 { · line 116
Quoted 10 lines
include/linux/mfd/nct6694.h +10
-0+{ +return nct6694->read_msg (nct6694, cmd_hd, buf); +} + +static inline int nct6694_write_msg (struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf) +{ +return nct6694->write_msg (nct6694, cmd_hd, buf); +}I very much dislike pointers to functions and abstraction for the sake of abstraction, at least at the driver-level.
Quoted 2 lines
Can you find another way to solve this problem please?
The reason for the abstraction is that patch 7/7 introduces a second transport (HIF/eSPI), and the sub-device drivers need a way to perform I/O without being coupled to a specific transport.
I'd like to rework this -- could you let me know which approach you'd prefer?
Keep nct6694_read_msg()/nct6694_write_msg() as exported functions in
nct6694-core.c, with the core dispatching to the appropriate transport-specific implementation based on an internal transport type indicator.
Quoted 5 lines
Use a const struct
nct6694_transport_ops*ops in struct nct6694, following the pattern used by subsystems likeregmap_busandspi_controller_mem_ops.Happy to go with whichever direction you think is cleaner.
Can you let Regmap handle it?
Most of our multi-bus drivers either create a Regmap in their bus-specific leaf driver then pass it up when initialising via the core, or use the Ops offered by Regmap Bus.
Calling from core (higher level) _back_ into the leaf bus-specific drivers (lower level) is generally decried as are driver level Ops. I'm aware we have 2 drivers already doing this, but this has not been the way for the past 16 and 13 years!
Signature · 1 line
Lee Jones
PATCH v5 4/7 mfd: nct6694: Rename static I/O functions with _usb_ prefix
In reply to a message not in the archiveFrom: Ming Yu <[email protected]>
Rename the static I/O and error handling routines to include an _usb_ prefix (e.g., nct6694_usb_read_msg, nct6694_usb_err_handling).
This clearly identifies these functions as specific to the USB transport implementation. It improves code readability and avoids naming confusion with the core API abstracted in the shared header, preparing the codebase for future alternative transport drivers.
---
Changes in v5:
- Split from the monolithic v4 patch to follow the single logical change principle.
drivers/mfd/nct6694.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/mfd/nct6694.c +13 -13
@@ -79,7 +79,7 @@ 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_usb_err_handling (struct nct6694 *nct6694,unsigned char err_status) {switch (err_status) {case NCT6694_NO_ERROR :
@@ -104,7 +104,7 @@ static int nct6694_response_err_handling(struct nct6694 *nct6694, unsigned char }/** -* nct6694_read_msg() - Read message from NCT6694 device +* nct6694_usb_read_msg() - Read message from NCT6694 device via USB * @nct6694: NCT6694 device pointer * @cmd_hd: command header structure * @buf: buffer to store the response data
@@ -115,9 +115,9 @@ static int nct6694_response_err_handling(struct nct6694 *nct6694, unsigned char* * Return: Negative value on error or 0 on success. */ -static int nct6694_read_msg (struct nct6694 *nct6694, -const struct nct6694_cmd_header *cmd_hd, -void *buf) +static int nct6694_usb_read_msg (struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf) {struct nct6694_usb_data *udata = nct6694->priv;union nct6694_usb_msg *msg = udata->usb_msg;
@@ -153,11 +153,11 @@ static int nct6694_read_msg(struct nct6694 *nct6694,return -EIO ; } -return nct6694_response_err_handling (nct6694, msg->response_header.sts); +return nct6694_usb_err_handling (nct6694, msg->response_header.sts); }/** -* nct6694_write_msg() - Write message to NCT6694 device +* nct6694_usb_write_msg() - Write message to NCT6694 device via USB * @nct6694: NCT6694 device pointer * @cmd_hd: command header structure * @buf: buffer containing the data to be sent
@@ -167,9 +167,9 @@ static int nct6694_read_msg(struct nct6694 *nct6694,* * Return: Negative value on error or 0 on success. */ -static int nct6694_write_msg (struct nct6694 *nct6694, -const struct nct6694_cmd_header *cmd_hd, -void *buf) +static int nct6694_usb_write_msg (struct nct6694 *nct6694, +const struct nct6694_cmd_header *cmd_hd, +void *buf) {struct nct6694_usb_data *udata = nct6694->priv;union nct6694_usb_msg *msg = udata->usb_msg;
@@ -211,7 +211,7 @@ static int nct6694_write_msg(struct nct6694 *nct6694,return -EIO ; } -return nct6694_response_err_handling (nct6694, msg->response_header.sts); +return nct6694_usb_err_handling (nct6694, msg->response_header.sts); }static void usb_int_callback (struct urb *urb)
@@ -329,8 +329,8 @@ static int nct6694_usb_probe(struct usb_interface *iface, udata->udev = udev; nct6694->priv = udata; - nct6694->read_msg = nct6694_read_msg; - nct6694->write_msg = nct6694_write_msg; + nct6694->read_msg = nct6694_usb_read_msg; + nct6694->write_msg = nct6694_usb_write_msg; nct6694->domain = irq_domain_create_simple(NULL, NCT6694_NR_IRQS, 0, &nct6694_irq_domain_ops,
Signature · 1 line
2.34.1
PATCH v5 5/7 mfd: nct6694: Rename driver to nct6694-usb and update Kconfig
In reply to a message not in the archiveFrom: Ming Yu <[email protected]>
Rename nct6694.c to nct6694-usb.c to accurately reflect that it implements the USB transport backend.
Additionally, introduce a new MFD_NCT6694_USB Kconfig option and convert the existing MFD_NCT6694 into a hidden core symbol. The core symbol is now automatically selected by the transport drivers.
This Kconfig and naming restructure aligns with standard MFD transport abstraction practices, paving the way for future interfaces (e.g., HIF) to be seamlessly integrated.
---
Changes in v5:
- Split from the monolithic v4 patch to follow the single logical change principle.
MAINTAINERS | 2 +-
drivers/mfd/Kconfig | 22 +++++++++++++++++++++-
drivers/mfd/Makefile | 2 +-
drivers/mfd/{nct6694.c => nct6694-usb.c} | 0
4 files changed, 23 insertions(+), 3 deletions(-)
rename drivers/mfd/{nct6694.c => nct6694-usb.c} (100%)MAINTAINERS +1 -1
@@ -19098,7 +19098,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/Kconfig +21 -1
@@ -1164,8 +1164,19 @@ config MFD_MENF21BMC will be called menf21bmc. config MFD_NCT6694 - tristate "Nuvoton NCT6694 support" + tristate select MFD_CORE + help + Core MFD support for the Nuvoton NCT6694 peripheral expander. + This provides the common APIs and shared structures used by all + interfaces (USB, HIF) to access the NCT6694 hardware features + such as GPIO, I2C, CAN-FD, Watchdog, ADC, PWM, and RTC. + + It is selected automatically by the transport interface drivers. + +config MFD_NCT6694_USB + tristate "Nuvoton NCT6694 USB interface support" + select MFD_NCT6694 depends on USB help This enables support for the Nuvoton USB device NCT6694, which shares
@@ -1177,6 +1188,15 @@ config MFD_NCT6694 monitoring and control features. Additional drivers must be enabled to utilize the specific functionalities of the device. + This enables support for the Nuvoton NCT6694 peripheral expander + connected via the USB interface. + + The transport driver uses USB bulk and interrupt transfers to + communicate with the NCT6694 firmware. Enable this option if you + are using the NCT6694 via a USB connection. + + To compile this driver as a module, choose M here: the module + will be called nct6694. config MFD_OCELOT tristate "Microsemi Ocelot External Control Support"
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_USB) += 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
PATCH v5 6/7 mfd: nct6694: Extract core device management into a separate module
In reply to a message not in the archiveFrom: Ming Yu <[email protected]>
Extract the transport-agnostic core logic, including IRQ domain setup, IDA initialization, and MFD sub-device registration, from the USB driver into a new nct6694-core.c module.
The core routines are exported as nct6694_core_probe() and nct6694_core_remove() to be consumed by the transport drivers. The USB driver is updated to pass its specific MFD cells to the core probe routine.
This completes the transport abstraction, ensuring that the shared device management logic is cleanly separated from the underlying I/O implementation, and is fully ready for new transport backends (e.g., HIF).
---
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 | 136 ++++++++++++++++++++++++++++++++++++ drivers/mfd/nct6694-usb.c | 95 +++---------------------- include/linux/mfd/nct6694.h | 9 ++- 5 files changed, 155 insertions(+), 88 deletions(-) create mode 100644 drivers/mfd/nct6694-core.c
MAINTAINERS +1 -1
@@ -19098,7 +19098,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_USB) += nct6694-usb.o obj-$(CONFIG_MFD_CORE) += mfd-core.o
drivers/mfd/nct6694-core.c new file +136 -0
136 lines not on this page · raw message
drivers/mfd/nct6694-usb.c +9 -86
166 lines not on this page · raw message
include/linux/mfd/nct6694.h +8 -1
@@ -10,10 +10,13 @@#define __MFD_NCT6694_H#include <linux/idr.h> -#include <linux/mutex.h> #include <linux/spinlock.h> #include <linux/types.h> +struct device ; +struct irq_domain ; +struct mfd_cell ; +#define NCT6694_HWMON_MOD 0x00#define NCT6694_PWM_MOD 0x01#define NCT6694_I2C_MOD 0x03
@@ -115,4 +118,8 @@ static inline int nct6694_write_msg(struct nct6694 *nct6694, return nct6694->write_msg(nct6694, cmd_hd, buf); } +int nct6694_core_probe (struct device *dev,struct nct6694 *nct6694, +const struct mfd_cell *cells,int n_cells); +void nct6694_core_remove (struct nct6694 *nct6694); +#endif
Signature · 1 line
2.34.1
PATCH v5 7/7 mfd: nct6694: Add Host Interface (HIF) eSPI transport driver
In reply to a message not in the archiveFrom: Ming Yu <[email protected]>
Add support for the Host Interface (HIF) transport via eSPI for the Nuvoton NCT6694 peripheral expander.
This transport driver initializes the Super-I/O to configure the device's shared memory base address and SIRQ. It provides the required I/O callbacks (read_msg/write_msg) utilizing memory-mapped I/O and regmap for command transactions. The initialized device config is then passed to the MFD core (nct6694_core_probe) for sub-device registration and IRQ domain setup.
---
Changes since version 4:
- 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 | 16 ++ drivers/mfd/Makefile | 1 + drivers/mfd/nct6694-hif.c | 529 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 546 insertions(+) create mode 100644 drivers/mfd/nct6694-hif.c
drivers/mfd/Kconfig +16 -0
@@ -1174,6 +1174,22 @@ config MFD_NCT6694 It is selected automatically by the transport interface drivers. +config MFD_NCT6694_HIF + tristate "Nuvoton NCT6694 HIF (eSPI) interface support" + depends on HAS_IOPORT && ACPI + select MFD_NCT6694 + select REGMAP_MMIO + help + This enables support for the Nuvoton NCT6694 peripheral expander + connected via the Host Interface (HIF) using eSPI transport. + + The transport driver uses Super-I/O mapping and shared memory to + communicate with the NCT6694 firmware. Enable this option if you + are using the NCT6694 over an eSPI interface on an ACPI platform. + + 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" select MFD_NCT6694
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 +529 -0
529 lines not on this page · raw message
Signature · 1 line
2.34.1