From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D9043AC0D9 for ; Mon, 25 May 2026 08:18:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779697086; cv=none; b=R+LOrceuwABL/1kjGjvidpB7iIdPKVipf0BBwQ8xQZdlltAhjaaJanJ7s9Vum3WDQyoidTs14uK4Z3odLe3yA2SzkiYIIXXGq6IfnkXBIf+4ey+U2oNQl6SfEPsljcE3RCI7zEtNr9BBIB69YBOJpFwHQEk7TgFV9mek8trCOmI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779697086; c=relaxed/simple; bh=jQXn8i5VY7ko8lBbG1+KMVY1A6PihM2ldTUKMWBDb9U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cv15ICfjv521jiEGvGrt12G6UedebL06ENFnbUdgi/I9Zyqqbo3vKEH0RIbpKQWRzOh9wlcBsGvP8br8f38GEqZmzeSsJzT5bo11Bs0kxXSioMa841dA5f5/3zJaJbZtl97Yilk+k+0g6QnEQqacpcx2ZW5QzYR8N/ezBeo7ks4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cSojUhTr; arc=none smtp.client-ip=209.85.216.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cSojUhTr" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-36900945df5so4657680a91.0 for ; Mon, 25 May 2026 01:18:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779697085; x=1780301885; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OXllRStKBduWUxB9hPI4iIOHXPpak/r2f2x+R23OTkE=; b=cSojUhTrjCIGsxL8MbSzb34vdE716aFavIj8ngp+H0hUQZEFfWtzETAhxmnRToP792 O4mqWHXK8d0TpQ5zHI70bBwaOyvkc2Ov6I7oDERkK0pYtiE9ZtQU1jjNVWBJeSYUNlAW VXaredWKqLE0H1/IqEu4fPnrwCdk9+FOvzfTTYTc0JyCv44h7YhRH29+3vEv3Se2uc4/ 5xawaIe7ocxTTqhdXR2lpwQwC8D4Q0g5uHcNz4qGLqNnDXZQnDWS0y9qwSalDpU3UjTi w4XP0oqUvJSktc/KkXo2239lxROIV/8xbYFi2F9CwSJ8UdRk83kMIF9PfScCYHlwGB11 be0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779697085; x=1780301885; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=OXllRStKBduWUxB9hPI4iIOHXPpak/r2f2x+R23OTkE=; b=mEWnPvrHgnpHnqQGjwUEqRzZ5hF6v99hF8ek7O0MshvTfMxaQxxnIq06dJUYwgpKM1 NAiD+LiN0q+vNRcBrsIkBlCbu3S4DbFKIZ7GBuOUm3yj2haA2VJoJZ5x5UPR+oTCpnm+ LMo3R72hCyecvFamOF3Spl8OQcoZKhuqqpeJRLNq/jP2IXmOzwz/zvIFc12Q8Dglgwhu uwVgcaCRxDNcmjXqN/ZhGoPm+tynj/GwMFwwzUCwTJvpYDuQ2iqrZW5NSHwB12k2PODP xjsBsWJFa7qiQOObpIHaVXLgoVRmW4hBnD54tYZpt+2JmQZFhX3cPJlXyCoWfBWI/KpU Ok7w== X-Forwarded-Encrypted: i=1; AFNElJ9diyoqk8hr3aiqwrEpAQ6b5A28Iw3XbT0XAjx80JpBojY1VYTSRpbfOvmrZZq4tZzIQ5tV2czEtzg9HDo=@vger.kernel.org X-Gm-Message-State: AOJu0YyB1pHd+dwA9WOdVgVAM8XaNhzzmWGkKOAO3TxQtuZSNq0DVDvw cNGFj13DpwEBic5nH/74P7TJm49ESHXrZ7kMSsu+Fb/P72c08DZQzsy6 X-Gm-Gg: Acq92OEJnDogXGCrG/TFmg8f7C9zAfIKxabOfKZg4Fdf23vrUEHsXPR4AnQ6OmZ3W76 o9QYIybe3Gvu6VQAlis10T5e5QZJydRjVCrzEYnhrQqdn1iwunCFXOdzTsGPnT02Xnri8m5S/4p aiHmREYQvXfF28Tmn9UIHPO3PivR60HrYgUAhaZbioWTQaQqPaL5rKMo/+Kdfb4H/CKTNZMYyOV LRfQQDIGdrQYPc++fx4QtjeKfuZq4t2x/SjxHzcM12/wVr7KRWkVcw7wQZMqTb/IyfaSHY4ZxgV zab1Qc1fmd3dMrGadzcPYvbgCjsORegkYTZt2zRcGqRjhiuBiMLx48eRbPdLZ/CnNVlwV6DIcQp 3oqMZHbmOHD99sNE9jdBSleDFQ9Q1TUlZd+IAYMxTZsr40sNOqGJ5oZAMjbFwiUq3EGqOP7wcU/ tUmDLd1+oABBr4UdXqGpA+pnOz5/zUVYfW9UjnMeRR6yv8MV/IKGET6crq3jI2rxTNrA== X-Received: by 2002:a17:90b:57c3:b0:36a:f625:47f8 with SMTP id 98e67ed59e1d1-36af6255bf9mr182566a91.26.1779697084641; Mon, 25 May 2026 01:18:04 -0700 (PDT) Received: from hcdev-d520mt2.. (60-250-196-139.hinet-ip.hinet.net. [60.250.196.139]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-36a721c7cf9sm8964102a91.10.2026.05.25.01.18.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2026 01:18:04 -0700 (PDT) From: a0282524688@gmail.com To: Lee Jones , Ming Yu Cc: Ming Yu , linux-kernel@vger.kernel.org Subject: [PATCH v5 2/7] mfd: nct6694: Refactor USB-specific data into nct6694_usb_data Date: Mon, 25 May 2026 16:17:31 +0800 Message-Id: <20260525081736.2904310-3-a0282524688@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260525081736.2904310-1-a0282524688@gmail.com> References: <20260525081736.2904310-1-a0282524688@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Ming Yu 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. Signed-off-by: Ming Yu --- 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(-) diff --git a/drivers/mfd/nct6694.c b/drivers/mfd/nct6694.c index 308b2fda3055..58c1cbcbe3f2 100644 --- a/drivers/mfd/nct6694.c +++ b/drivers/mfd/nct6694.c @@ -10,8 +10,8 @@ */ #include -#include #include +#include #include #include #include @@ -22,6 +22,27 @@ #include #include +#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[] = { diff --git a/include/linux/mfd/nct6694.h b/include/linux/mfd/nct6694.h index 3c683e317aa3..3f5dd53f38de 100644 --- a/include/linux/mfd/nct6694.h +++ b/include/linux/mfd/nct6694.h @@ -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 +#include +#include +#include + #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); -- 2.34.1