mbox series

[v7,0/7] Add Nuvoton NCT6694 MFD drivers

Message ID 20250207074502.1055111-1-a0282524688@gmail.com
Headers show
Series Add Nuvoton NCT6694 MFD drivers | expand

Message

Ming Yu Feb. 7, 2025, 7:44 a.m. UTC
This patch series introduces support for Nuvoton NCT6694, a peripheral
expander based on USB interface. It models the chip as an MFD driver
(1/7), GPIO driver(2/7), I2C Adapter driver(3/7), CANfd driver(4/7),
WDT driver(5/7), HWMON driver(6/7), and RTC driver(7/7).

The MFD driver implements USB device functionality to issue
custom-define USB bulk pipe packets for NCT6694. Each child device can
use the USB functions nct6694_read_msg() and nct6694_write_msg() to issue
a command. They can also request interrupt that will be called when the
USB device receives its interrupt pipe.

The following introduces the custom-define USB transactions:
        nct6694_read_msg - Send bulk-out pipe to write request packet
                           Receive bulk-in pipe to read response packet
                           Receive bulk-in pipe to read data packet

        nct6694_write_msg - Send bulk-out pipe to write request packet
                            Send bulk-out pipe to write data packet
                            Receive bulk-in pipe to read response packet
                            Receive bulk-in pipe to read data packet

Changes since version 6:
- Fix nct6694_can_handle_state_change() in nct6694_canfd.c
- Fix warnings in nct6694_canfd.c
- Move the nct6694_can_priv's bec to the end in nct6694_canfd.c
- Fix warning in nct6694_wdt.c
- Fix temp_hyst's data type to signed variable in nct6694-hwmon.c

Changes since version 5:
- Modify the module name and the driver name consistently
- Fix mfd_cell to MFD_CELL_NAME() and MFD_CELL_BASIC()
- Drop unnecessary macros in nct6694.c
- Update private data and drop mutex in nct6694_canfd.c
- Fix nct6694_can_handle_state_change() in nct6694_canfd.c

Changes since version 4:
- Modify arguments in read/write function to a pointer to cmd_header
- Modify all callers that call the read/write function
- Move the nct6694_canfd.c to drivers/net/can/usb/
- Fix the missing rx offload function in nct6694_canfd.c
- Fix warngings in nct6694-hwmon.c

Changes since version 3:
- Modify array buffer to structure for each drivers
- Fix defines and comments for each drivers
- Add header <linux/bits.h> and use BIT macro in nct6694.c and
  gpio-nct6694.c
- Modify mutex_init() to devm_mutex_init()
- Add rx-offload helper in nct6694_canfd.c
- Drop watchdog_init_timeout() in nct6694_wdt.c
- Modify the division method to DIV_ROUND_CLOSEST() in nct6694-hwmon.c
- Drop private mutex and use rtc core lock in rtc-nct6694.c
- Modify device_set_wakeup_capable() to device_init_wakeup() in
  rtc-nct6694.c

Changes since version 2:
- Add MODULE_ALIAS() for each child driver
- Modify gpio line names be a local variable in gpio-nct6694.c
- Drop unnecessary platform_get_drvdata() in gpio-nct6694.c
- Rename each command in nct6694_canfd.c
- Modify each function name consistently in nct6694_canfd.c
- Modify the pretimeout validation procedure in nct6694_wdt.c
- Fix warnings in nct6694-hwmon.c

Changes since version 1:
- Implement IRQ domain to handle IRQ demux in nct6694.c
- Modify USB_DEVICE to USB_DEVICE_AND_INTERFACE_INFO API in nct6694.c
- Add each driver's command structure
- Fix USB functions in nct6694.c
- Fix platform driver registration in each child driver
- Sort each driver's header files alphabetically
- Drop unnecessary header in gpio-nct6694.c
- Add gpio line names in gpio-nct6694.c
- Fix errors and warnings in nct6694_canfd.c
- Fix TX-flow control in nct6694_canfd.c
- Fix warnings in nct6694_wdt.c
- Drop unnecessary logs in nct6694_wdt.c
- Modify start() function to setup device in nct6694_wdt.c
- Add voltage sensors functionality in nct6694-hwmon.c
- Add temperature sensors functionality in nct6694-hwmon.c
- Fix overwrite error return values in nct6694-hwmon.c
- Add write value limitation for each write() function in nct6694-hwmon.c
- Drop unnecessary logs in rtc-nct6694.c
- Fix overwrite error return values in rtc-nct6694.c
- Modify to use dev_err_probe API in rtc-nct6694.c


Ming Yu (7):
  mfd: Add core driver for Nuvoton NCT6694
  gpio: Add Nuvoton NCT6694 GPIO support
  i2c: Add Nuvoton NCT6694 I2C support
  can: Add Nuvoton NCT6694 CANFD support
  watchdog: Add Nuvoton NCT6694 WDT support
  hwmon: Add Nuvoton NCT6694 HWMON support
  rtc: Add Nuvoton NCT6694 RTC support

 MAINTAINERS                         |  13 +
 drivers/gpio/Kconfig                |  12 +
 drivers/gpio/Makefile               |   1 +
 drivers/gpio/gpio-nct6694.c         | 458 ++++++++++++++
 drivers/hwmon/Kconfig               |  10 +
 drivers/hwmon/Makefile              |   1 +
 drivers/hwmon/nct6694-hwmon.c       | 947 ++++++++++++++++++++++++++++
 drivers/i2c/busses/Kconfig          |  10 +
 drivers/i2c/busses/Makefile         |   1 +
 drivers/i2c/busses/i2c-nct6694.c    | 152 +++++
 drivers/mfd/Kconfig                 |  18 +
 drivers/mfd/Makefile                |   2 +
 drivers/mfd/nct6694.c               | 373 +++++++++++
 drivers/net/can/usb/Kconfig         |  11 +
 drivers/net/can/usb/Makefile        |   1 +
 drivers/net/can/usb/nct6694_canfd.c | 809 ++++++++++++++++++++++++
 drivers/rtc/Kconfig                 |  10 +
 drivers/rtc/Makefile                |   1 +
 drivers/rtc/rtc-nct6694.c           | 286 +++++++++
 drivers/watchdog/Kconfig            |  11 +
 drivers/watchdog/Makefile           |   1 +
 drivers/watchdog/nct6694_wdt.c      | 295 +++++++++
 include/linux/mfd/nct6694.h         | 102 +++
 23 files changed, 3525 insertions(+)
 create mode 100644 drivers/gpio/gpio-nct6694.c
 create mode 100644 drivers/hwmon/nct6694-hwmon.c
 create mode 100644 drivers/i2c/busses/i2c-nct6694.c
 create mode 100644 drivers/mfd/nct6694.c
 create mode 100644 drivers/net/can/usb/nct6694_canfd.c
 create mode 100644 drivers/rtc/rtc-nct6694.c
 create mode 100644 drivers/watchdog/nct6694_wdt.c
 create mode 100644 include/linux/mfd/nct6694.h

Comments

Ming Yu Feb. 12, 2025, 2:20 a.m. UTC | #1
Dear Christophe,

Thank you for reviewing,

Christophe JAILLET <christophe.jaillet@wanadoo.fr> 於 2025年2月8日 週六 上午2:37寫道:
>
> Le 07/02/2025 à 08:44, Ming Yu a écrit :
> > 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 implements USB device functionality and shares the
> > chip's peripherals as a child device.
> >
> > Each child device can use the USB functions nct6694_read_msg()
> > and nct6694_write_msg() to issue a command. They can also request
> > interrupt that will be called when the USB device receives its
> > interrupt pipe.
>
> ...
>
> > +static struct irq_chip nct6694_irq_chip = {
>
> This could be const.
>
> (I'm working on a serie that should constify struct irq_chip, so this
> one would already be done)
>
Okay, I will fix it in the next patch.


Best regards,
Ming
Ming Yu Feb. 12, 2025, 2:25 a.m. UTC | #2
Dear Christophe,

Thank you for reviewing,

Christophe JAILLET <christophe.jaillet@wanadoo.fr> 於 2025年2月8日 週六 上午3:06寫道:
>
> Le 07/02/2025 à 08:44, Ming Yu a écrit :
> > This driver supports I2C adapter functionality for NCT6694 MFD
> > device based on USB interface, each I2C controller use default
> > baudrate(100K).
>
> ...
>
> > +static int nct6694_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
> > +{
> > +     struct nct6694_i2c_data *data = adap->algo_data;
> > +     struct nct6694_i2c_deliver *deliver = &data->deliver;
> > +     static const struct nct6694_cmd_header cmd_hd = {
> > +             .mod = NCT6694_I2C_MOD,
> > +             .cmd = NCT6694_I2C_DELIVER,
> > +             .sel = NCT6694_I2C_DELIVER_SEL,
> > +             .len = cpu_to_le16(sizeof(*deliver))
> > +     };
> > +     int ret, i;
> > +
> > +     for (i = 0; i < num ; i++) {
>
> Tiny tiny nitpick: unneeded extra space after num
>
Okay, I will fix it in the next patch.


Best regards,
Ming
Ming Yu Feb. 12, 2025, 2:27 a.m. UTC | #3
Dear Christophe,

Thank you for reviewing,

Christophe JAILLET <christophe.jaillet@wanadoo.fr> 於 2025年2月8日 週六 上午4:30寫道:
>
> Le 07/02/2025 à 08:45, Ming Yu a écrit :
> > This driver supports Watchdog timer functionality for NCT6694 MFD
> > device based on USB interface.
>
> ...
>
> > +static int nct6694_wdt_probe(struct platform_device *pdev)
> > +{
> > +     const struct mfd_cell *cell = mfd_get_cell(pdev);
> > +     struct device *dev = &pdev->dev;
> > +     struct nct6694 *nct6694 = dev_get_drvdata(pdev->dev.parent);
> > +     struct nct6694_wdt_data *data;
> > +     struct watchdog_device *wdev;
> > +
> > +     data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> > +     if (!data)
> > +             return -ENOMEM;
> > +
> > +     data->msg = devm_kzalloc(dev, sizeof(union nct6694_wdt_msg),
> > +                              GFP_KERNEL);
> > +     if (!data->msg)
> > +             return -ENOMEM;
> > +
> > +     data->dev = dev;
> > +     data->nct6694 = nct6694;
> > +     data->wdev_idx = cell->id;
> > +
> > +     wdev = &data->wdev;
> > +     wdev->info = &nct6694_wdt_info;
> > +     wdev->ops = &nct6694_wdt_ops;
> > +     wdev->timeout = timeout;
> > +     wdev->pretimeout = pretimeout;
> > +     if (timeout < pretimeout) {
> > +             dev_warn(data->dev, "pretimeout < timeout. Setting to zero\n");
> > +             wdev->pretimeout = 0;
> > +     }
> > +
> > +     wdev->min_timeout = 1;
> > +     wdev->max_timeout = 255;
> > +
> > +     devm_mutex_init(dev, &data->lock);
>
> Error handling?
> (also apply for patch 1/7 and 6/7)
>
I will add error handling for these in the next patch.


Best regards,
Ming
Alexandre Belloni April 8, 2025, 12:54 p.m. UTC | #4
On 07/02/2025 15:45:02+0800, Ming Yu wrote:
> This driver supports RTC functionality for NCT6694 MFD device
> based on USB interface.
> 
> Signed-off-by: Ming Yu <a0282524688@gmail.com>
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
> ---
>  MAINTAINERS               |   1 +
>  drivers/rtc/Kconfig       |  10 ++
>  drivers/rtc/Makefile      |   1 +
>  drivers/rtc/rtc-nct6694.c | 286 ++++++++++++++++++++++++++++++++++++++
>  4 files changed, 298 insertions(+)
>  create mode 100644 drivers/rtc/rtc-nct6694.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index a9eda4530b07..7eba4ffdc877 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -16927,6 +16927,7 @@ F:	drivers/hwmon/nct6694-hwmon.c
>  F:	drivers/i2c/busses/i2c-nct6694.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
>  F:	include/linux/mfd/nct6694.h
>  
> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
> index 0bbbf778ecfa..248425bf26f3 100644
> --- a/drivers/rtc/Kconfig
> +++ b/drivers/rtc/Kconfig
> @@ -416,6 +416,16 @@ config RTC_DRV_NCT3018Y
>  	   This driver can also be built as a module, if so, the module will be
>  	   called "rtc-nct3018y".
>  
> +config RTC_DRV_NCT6694
> +	tristate "Nuvoton NCT6694 RTC support"
> +	depends on MFD_NCT6694
> +	help
> +	  If you say yes to this option, support will be included for Nuvoton
> +	  NCT6694, a USB device to RTC.
> +
> +	  This driver can also be built as a module. If so, the module will
> +	  be called rtc-nct6694.
> +
>  config RTC_DRV_RK808
>  	tristate "Rockchip RK805/RK808/RK809/RK817/RK818 RTC"
>  	depends on MFD_RK8XX
> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
> index 489b4ab07068..d0d6f4a4972e 100644
> --- a/drivers/rtc/Makefile
> +++ b/drivers/rtc/Makefile
> @@ -118,6 +118,7 @@ obj-$(CONFIG_RTC_DRV_MXC)	+= rtc-mxc.o
>  obj-$(CONFIG_RTC_DRV_MXC_V2)	+= rtc-mxc_v2.o
>  obj-$(CONFIG_RTC_DRV_GAMECUBE)	+= rtc-gamecube.o
>  obj-$(CONFIG_RTC_DRV_NCT3018Y)	+= rtc-nct3018y.o
> +obj-$(CONFIG_RTC_DRV_NCT6694)	+= rtc-nct6694.o
>  obj-$(CONFIG_RTC_DRV_NTXEC)	+= rtc-ntxec.o
>  obj-$(CONFIG_RTC_DRV_OMAP)	+= rtc-omap.o
>  obj-$(CONFIG_RTC_DRV_OPAL)	+= rtc-opal.o
> diff --git a/drivers/rtc/rtc-nct6694.c b/drivers/rtc/rtc-nct6694.c
> new file mode 100644
> index 000000000000..892674d453d1
> --- /dev/null
> +++ b/drivers/rtc/rtc-nct6694.c
> @@ -0,0 +1,286 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Nuvoton NCT6694 RTC driver based on USB interface.
> + *
> + * Copyright (C) 2024 Nuvoton Technology Corp.
> + */
> +
> +#include <linux/bcd.h>
> +#include <linux/irqdomain.h>
> +#include <linux/kernel.h>
> +#include <linux/mfd/core.h>
> +#include <linux/mfd/nct6694.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#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
> +
> +/* Command 01h - RTC Alarm */
> +#define NCT6694_RTC_ALARM	0x01
> +#define NCT6694_RTC_ALARM_SEL	0x00
> +
> +/* Command 02h - RTC Status */
> +#define NCT6694_RTC_STATUS	0x02
> +#define NCT6694_RTC_STATUS_SEL	0x00
> +
> +#define NCT6694_RTC_IRQ_INT_EN	BIT(0)	/* Transmit a USB INT-in when RTC alarm */
> +#define NCT6694_RTC_IRQ_GPO_EN	BIT(5)	/* Trigger a GPO Low Pulse when RTC alarm */
> +
> +#define NCT6694_RTC_IRQ_EN	(NCT6694_RTC_IRQ_INT_EN | NCT6694_RTC_IRQ_GPO_EN)
> +#define NCT6694_RTC_IRQ_STS	BIT(0)	/* Write 1 clear IRQ status */
> +
> +struct __packed nct6694_rtc_time {
> +	u8 sec;
> +	u8 min;
> +	u8 hour;
> +	u8 week;
> +	u8 day;
> +	u8 month;
> +	u8 year;
> +};
> +
> +struct __packed nct6694_rtc_alarm {
> +	u8 sec;
> +	u8 min;
> +	u8 hour;
> +	u8 alarm_en;
> +	u8 alarm_pend;
> +};
> +
> +struct __packed nct6694_rtc_status {
> +	u8 irq_en;
> +	u8 irq_pend;
> +};
> +
> +union __packed nct6694_rtc_msg {
> +	struct nct6694_rtc_time time;
> +	struct nct6694_rtc_alarm alarm;
> +	struct nct6694_rtc_status sts;
> +};
> +
> +struct nct6694_rtc_data {
> +	struct nct6694 *nct6694;
> +	struct rtc_device *rtc;
> +	union nct6694_rtc_msg *msg;
> +};
> +
> +static int nct6694_rtc_read_time(struct device *dev, struct rtc_time *tm)
> +{
> +	struct nct6694_rtc_data *data = dev_get_drvdata(dev);
> +	struct nct6694_rtc_time *time = &data->msg->time;
> +	static const struct nct6694_cmd_header cmd_hd = {
> +		.mod = NCT6694_RTC_MOD,
> +		.cmd = NCT6694_RTC_TIME,
> +		.sel = NCT6694_RTC_TIME_SEL,
> +		.len = cpu_to_le16(sizeof(*time))
> +	};
> +	int ret;
> +
> +	ret = nct6694_read_msg(data->nct6694, &cmd_hd, time);
> +	if (ret)
> +		return ret;
> +
> +	tm->tm_sec = bcd2bin(time->sec);		/* tm_sec expect 0 ~ 59 */
> +	tm->tm_min = bcd2bin(time->min);		/* tm_min expect 0 ~ 59 */
> +	tm->tm_hour = bcd2bin(time->hour);		/* tm_hour expect 0 ~ 23 */
> +	tm->tm_wday = bcd2bin(time->week) - 1;		/* tm_wday expect 0 ~ 6 */
> +	tm->tm_mday = bcd2bin(time->day);		/* tm_mday expect 1 ~ 31 */
> +	tm->tm_mon = bcd2bin(time->month) - 1;		/* tm_month expect 0 ~ 11 */
> +	tm->tm_year = bcd2bin(time->year) + 100;	/* tm_year expect since 1900 */
> +
> +	return ret;
> +}
> +
> +static int nct6694_rtc_set_time(struct device *dev, struct rtc_time *tm)
> +{
> +	struct nct6694_rtc_data *data = dev_get_drvdata(dev);
> +	struct nct6694_rtc_time *time = &data->msg->time;
> +	static const struct nct6694_cmd_header cmd_hd = {
> +		.mod = NCT6694_RTC_MOD,
> +		.cmd = NCT6694_RTC_TIME,
> +		.sel = NCT6694_RTC_TIME_SEL,
> +		.len = cpu_to_le16(sizeof(*time))
> +	};
> +
> +	time->sec = bin2bcd(tm->tm_sec);
> +	time->min = bin2bcd(tm->tm_min);
> +	time->hour = bin2bcd(tm->tm_hour);
> +	time->week = bin2bcd(tm->tm_wday + 1);
> +	time->day = bin2bcd(tm->tm_mday);
> +	time->month = bin2bcd(tm->tm_mon + 1);
> +	time->year = bin2bcd(tm->tm_year - 100);
> +
> +	return nct6694_write_msg(data->nct6694, &cmd_hd, time);
> +}
> +
> +static int nct6694_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
> +{
> +	struct nct6694_rtc_data *data = dev_get_drvdata(dev);
> +	struct nct6694_rtc_alarm *alarm = &data->msg->alarm;
> +	static const struct nct6694_cmd_header cmd_hd = {
> +		.mod = NCT6694_RTC_MOD,
> +		.cmd = NCT6694_RTC_ALARM,
> +		.sel = NCT6694_RTC_ALARM_SEL,
> +		.len = cpu_to_le16(sizeof(*alarm))
> +	};
> +	int ret;
> +
> +	ret = nct6694_read_msg(data->nct6694, &cmd_hd, alarm);
> +	if (ret)
> +		return ret;
> +
> +	alrm->time.tm_sec = bcd2bin(alarm->sec);
> +	alrm->time.tm_min = bcd2bin(alarm->min);
> +	alrm->time.tm_hour = bcd2bin(alarm->hour);
> +	alrm->enabled = alarm->alarm_en;
> +	alrm->pending = alarm->alarm_pend;
> +
> +	return ret;
> +}
> +
> +static int nct6694_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
> +{
> +	struct nct6694_rtc_data *data = dev_get_drvdata(dev);
> +	struct nct6694_rtc_alarm *alarm = &data->msg->alarm;
> +	static const struct nct6694_cmd_header cmd_hd = {
> +		.mod = NCT6694_RTC_MOD,
> +		.cmd = NCT6694_RTC_ALARM,
> +		.sel = NCT6694_RTC_ALARM_SEL,
> +		.len = cpu_to_le16(sizeof(*alarm))
> +	};
> +
> +	alarm->sec = bin2bcd(alrm->time.tm_sec);
> +	alarm->min = bin2bcd(alrm->time.tm_min);
> +	alarm->hour = bin2bcd(alrm->time.tm_hour);
> +	alarm->alarm_en = alrm->enabled ? NCT6694_RTC_IRQ_EN : 0;
> +	alarm->alarm_pend = 0;
> +
> +	return nct6694_write_msg(data->nct6694, &cmd_hd, alarm);
> +}
> +
> +static int nct6694_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
> +{
> +	struct nct6694_rtc_data *data = dev_get_drvdata(dev);
> +	struct nct6694_rtc_status *sts = &data->msg->sts;
> +	static const struct nct6694_cmd_header cmd_hd = {
> +		.mod = NCT6694_RTC_MOD,
> +		.cmd = NCT6694_RTC_STATUS,
> +		.sel = NCT6694_RTC_STATUS_SEL,
> +		.len = cpu_to_le16(sizeof(*sts))
> +	};
> +
> +	if (enabled)
> +		sts->irq_en |= NCT6694_RTC_IRQ_EN;
> +	else
> +		sts->irq_en &= ~NCT6694_RTC_IRQ_EN;
> +
> +	sts->irq_pend = 0;
> +
> +	return nct6694_write_msg(data->nct6694, &cmd_hd, sts);
> +}
> +
> +static const struct rtc_class_ops nct6694_rtc_ops = {
> +	.read_time = nct6694_rtc_read_time,
> +	.set_time = nct6694_rtc_set_time,
> +	.read_alarm = nct6694_rtc_read_alarm,
> +	.set_alarm = nct6694_rtc_set_alarm,
> +	.alarm_irq_enable = nct6694_rtc_alarm_irq_enable,
> +};
> +
> +static irqreturn_t nct6694_irq(int irq, void *dev_id)
> +{
> +	struct nct6694_rtc_data *data = dev_id;
> +	struct nct6694_rtc_status *sts = &data->msg->sts;
> +	static const struct nct6694_cmd_header cmd_hd = {
> +		.mod = NCT6694_RTC_MOD,
> +		.cmd = NCT6694_RTC_STATUS,
> +		.sel = NCT6694_RTC_STATUS_SEL,
> +		.len = cpu_to_le16(sizeof(*sts))
> +	};
> +	int ret;
> +
> +	rtc_lock(data->rtc);
> +
> +	sts->irq_en = NCT6694_RTC_IRQ_EN;
> +	sts->irq_pend = NCT6694_RTC_IRQ_STS;
> +	ret = nct6694_write_msg(data->nct6694, &cmd_hd, sts);
> +	if (ret) {
> +		rtc_unlock(data->rtc);
> +		return IRQ_NONE;
> +	}
> +
> +	rtc_update_irq(data->rtc, 1, RTC_IRQF | RTC_AF);
> +
> +	rtc_unlock(data->rtc);
> +
> +	return IRQ_HANDLED;
> +}
> +
> +static int nct6694_rtc_probe(struct platform_device *pdev)
> +{
> +	struct nct6694_rtc_data *data;
> +	struct nct6694 *nct6694 = dev_get_drvdata(pdev->dev.parent);
> +	int ret, irq;
> +
> +	irq = irq_create_mapping(nct6694->domain, NCT6694_IRQ_RTC);
> +	if (!irq)
> +		return -EINVAL;
> +
> +	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> +	if (!data)
> +		return -ENOMEM;
> +
> +	data->msg = devm_kzalloc(&pdev->dev, sizeof(union nct6694_rtc_msg),
> +				 GFP_KERNEL);
> +	if (!data->msg)
> +		return -ENOMEM;
> +
> +	data->rtc = devm_rtc_allocate_device(&pdev->dev);
> +	if (IS_ERR(data->rtc))
> +		return PTR_ERR(data->rtc);
> +
> +	data->nct6694 = nct6694;
> +	data->rtc->ops = &nct6694_rtc_ops;
> +	data->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
> +	data->rtc->range_max = RTC_TIMESTAMP_END_2099;
> +
> +	platform_set_drvdata(pdev, data);
> +
> +	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
> +					nct6694_irq, IRQF_ONESHOT,
> +					"rtc-nct6694", data);
> +	if (ret < 0)
> +		return dev_err_probe(&pdev->dev, ret, "Failed to request irq\n");
> +
> +	ret = devm_rtc_register_device(data->rtc);
> +	if (ret)
> +		return ret;
> +
> +	device_init_wakeup(&pdev->dev, true);
> +	return 0;
> +}
> +
> +static struct platform_driver nct6694_rtc_driver = {
> +	.driver = {
> +		.name	= "rtc-nct6694",
> +	},
> +	.probe		= nct6694_rtc_probe,
> +};
> +
> +module_platform_driver(nct6694_rtc_driver);
> +
> +MODULE_DESCRIPTION("USB-RTC driver for NCT6694");
> +MODULE_AUTHOR("Ming Yu <tmyu0@nuvoton.com>");
> +MODULE_LICENSE("GPL");
> +MODULE_ALIAS("platform:nct6694-rtc");
> -- 
> 2.34.1
>