linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/3] ARM: dts: nuvoton: Add nuvoton RTC3018Y node
@ 2022-05-16 15:27 Medad CChien
  2022-05-16 15:27 ` [PATCH v1 2/3] dt-bindings: rtc: nuvoton: add NCT3018Y Real Time Clock Medad CChien
  2022-05-16 15:27 ` [PATCH v1 3/3] RTC: nuvoton: Add NCT3018Y real time clock driver Medad CChien
  0 siblings, 2 replies; 6+ messages in thread
From: Medad CChien @ 2022-05-16 15:27 UTC (permalink / raw)
  To: benjaminfair, yuenn, venture, tali.perry1, tmaimon77,
	avifishman70, robh+dt, alexandre.belloni, a.zummo, KWLIU, YSCHU,
	JJLIU0, KFTING, ctcchien
  Cc: openbmc, linux-kernel, devicetree, linux-rtc

Add nuvoton real time clock RTC3018Y in I2C node

Signed-off-by: Medad CChien <ctcchien@nuvoton.com>
---
 arch/arm/boot/dts/nuvoton-npcm750-evb.dts | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/boot/dts/nuvoton-npcm750-evb.dts b/arch/arm/boot/dts/nuvoton-npcm750-evb.dts
index 0334641f8829..c1248211b1b4 100644
--- a/arch/arm/boot/dts/nuvoton-npcm750-evb.dts
+++ b/arch/arm/boot/dts/nuvoton-npcm750-evb.dts
@@ -202,6 +202,12 @@
 		reg = <0x48>;
 		status = "okay";
 	};
+	rtc0: rtc@6f {
+		compatible = "nuvoton,nct3018y";
+		reg = <0x6f>;
+		#clock-cells = <0>;
+		host-wakeup-gpios = <&gpio0 0 GPIO_ACTIVE_LOW>;
+	};
 };
 
 /* lm75 on EB */
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v1 2/3] dt-bindings: rtc: nuvoton: add NCT3018Y Real Time Clock
  2022-05-16 15:27 [PATCH v1 1/3] ARM: dts: nuvoton: Add nuvoton RTC3018Y node Medad CChien
@ 2022-05-16 15:27 ` Medad CChien
  2022-05-16 15:27 ` [PATCH v1 3/3] RTC: nuvoton: Add NCT3018Y real time clock driver Medad CChien
  1 sibling, 0 replies; 6+ messages in thread
From: Medad CChien @ 2022-05-16 15:27 UTC (permalink / raw)
  To: benjaminfair, yuenn, venture, tali.perry1, tmaimon77,
	avifishman70, robh+dt, alexandre.belloni, a.zummo, KWLIU, YSCHU,
	JJLIU0, KFTING, ctcchien
  Cc: openbmc, linux-kernel, devicetree, linux-rtc

Document devicetree bindings for the Nuvoton NCT3018Y Real Time Clock.

Signed-off-by: Medad CChien <ctcchien@nuvoton.com>
---
 .../bindings/rtc/nuvoton,nct3018y.yaml        | 44 +++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/nuvoton,nct3018y.yaml

diff --git a/Documentation/devicetree/bindings/rtc/nuvoton,nct3018y.yaml b/Documentation/devicetree/bindings/rtc/nuvoton,nct3018y.yaml
new file mode 100644
index 000000000000..788d92a32a70
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/nuvoton,nct3018y.yaml
@@ -0,0 +1,44 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/rtc/nuvoton,nct3018y.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: NUVOTON NCT3018Y Real Time Clock
+
+allOf:
+  - $ref: "rtc.yaml#"
+
+maintainers:
+  - Medad CChien <ctcchien@nuvoton.com>
+
+properties:
+  compatible:
+    const: nuvoton,nct3018y
+
+  reg:
+    maxItems: 1
+
+  start-year: true
+
+  reset-source: true
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        rtc@6f {
+            compatible = "nuvoton,nct3018y";
+            reg = <0x6f>;
+        };
+    };
+
+...
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v1 3/3] RTC: nuvoton: Add NCT3018Y real time clock driver
  2022-05-16 15:27 [PATCH v1 1/3] ARM: dts: nuvoton: Add nuvoton RTC3018Y node Medad CChien
  2022-05-16 15:27 ` [PATCH v1 2/3] dt-bindings: rtc: nuvoton: add NCT3018Y Real Time Clock Medad CChien
@ 2022-05-16 15:27 ` Medad CChien
  2022-05-16 23:08   ` kernel test robot
                     ` (2 more replies)
  1 sibling, 3 replies; 6+ messages in thread
From: Medad CChien @ 2022-05-16 15:27 UTC (permalink / raw)
  To: benjaminfair, yuenn, venture, tali.perry1, tmaimon77,
	avifishman70, robh+dt, alexandre.belloni, a.zummo, KWLIU, YSCHU,
	JJLIU0, KFTING, ctcchien
  Cc: openbmc, linux-kernel, devicetree, linux-rtc

Add real time clock support for NCT3018Y.

Signed-off-by: Medad CChien <ctcchien@nuvoton.com>
---
 drivers/rtc/Kconfig        |  10 +
 drivers/rtc/Makefile       |   1 +
 drivers/rtc/rtc-nct3018y.c | 599 +++++++++++++++++++++++++++++++++++++
 3 files changed, 610 insertions(+)
 create mode 100644 drivers/rtc/rtc-nct3018y.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index d85a3c31347c..d83d31c76443 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -383,6 +383,16 @@ config RTC_DRV_MAX77686
 	  This driver can also be built as a module. If so, the module
 	  will be called rtc-max77686.
 
+config RTC_DRV_NCT3018Y
+	tristate "Nuvoton Real Time Clock"
+	depends on OF
+	help
+	   If you say yes here you get support for the Nuvoton NCT3018Y RTC
+	   module.
+
+	   This driver can also be built as a module, if so, the module will
+	   be called "rtc-nct3018y".
+
 config RTC_DRV_RK808
 	tristate "Rockchip RK805/RK808/RK809/RK817/RK818 RTC"
 	depends on MFD_RK808
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index e92f3e943245..d3c100e43d1f 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -112,6 +112,7 @@ obj-$(CONFIG_RTC_DRV_MV)	+= rtc-mv.o
 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_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-nct3018y.c b/drivers/rtc/rtc-nct3018y.c
new file mode 100644
index 000000000000..fb7fb8f5266d
--- /dev/null
+++ b/drivers/rtc/rtc-nct3018y.c
@@ -0,0 +1,599 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2022 Nuvoton Technology Corporation
+
+#include <linux/bcd.h>
+#include <linux/clk-provider.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/rtc.h>
+#include <linux/slab.h>
+
+#define NCT3018Y_REG_SC		0x00 /* seconds */
+#define NCT3018Y_REG_SCA	0x01 /* alarm */
+#define NCT3018Y_REG_MN		0x02
+#define NCT3018Y_REG_MNA	0x03 /* alarm */
+#define NCT3018Y_REG_HR		0x04
+#define NCT3018Y_REG_HRA	0x05 /* alarm */
+#define NCT3018Y_REG_DW		0x06
+#define NCT3018Y_REG_DM		0x07
+#define NCT3018Y_REG_MO		0x08
+#define NCT3018Y_REG_YR		0x09
+#define NCT3018Y_REG_CTRL	0x0A /* timer control */
+#define NCT3018Y_REG_ST		0x0B /* status */
+#define NCT3018Y_REG_CLKO	0x0C /* clock out */
+
+#define NCT3018Y_BIT_AF		BIT(7)
+#define NCT3018Y_BIT_ST		BIT(7)
+#define NCT3018Y_BIT_DM		BIT(6)
+#define NCT3018Y_BIT_HF		BIT(5)
+#define NCT3018Y_BIT_DSM	BIT(4)
+#define NCT3018Y_BIT_AIE	BIT(3)
+#define NCT3018Y_BIT_OFIE	BIT(2)
+#define NCT3018Y_BIT_CIE	BIT(1)
+#define NCT3018Y_BIT_TWO	BIT(0)
+
+#define NCT3018Y_REG_CLKO_F_MASK	0x03 /* frequenc mask */
+#define NCT3018Y_REG_CLKO_CKE		0x80 /* clock out enabled */
+
+static struct i2c_driver nct3018y_driver;
+
+struct nct3018y {
+	struct rtc_device *rtc;
+	struct i2c_client *client;
+	struct gpio_desc *wakeup_host;
+#ifdef CONFIG_COMMON_CLK
+	struct clk_hw		clkout_hw;
+#endif
+};
+
+static int nct3018y_read_block_data(struct i2c_client *client,
+				    unsigned char reg, unsigned char length, unsigned char *buf)
+{
+	struct i2c_msg msgs[] = {
+		{/* setup read ptr */
+			.addr = client->addr,
+			.len = 1,
+			.buf = &reg,
+		},
+		{
+			.addr = client->addr,
+			.flags = I2C_M_RD,
+			.len = length,
+			.buf = buf
+		},
+	};
+
+	if ((i2c_transfer(client->adapter, msgs, 2)) != 2) {
+		dev_err(&client->dev, "%s: read error\n", __func__);
+		return -EIO;
+	}
+
+	return 0;
+}
+
+static int nct3018y_write_block_data(struct i2c_client *client,
+				     unsigned char reg, unsigned char length,
+				     unsigned char *buf)
+{
+	int i, err;
+
+	for (i = 0; i < length; i++) {
+		unsigned char data[2] = { reg + i, buf[i] };
+
+		err = i2c_master_send(client, data, sizeof(data));
+		if (err != sizeof(data)) {
+			dev_err(&client->dev, "%s: err=%d addr=%02x, data=%02x\n", __func__,
+				err, data[0], data[1]);
+			return -EIO;
+		}
+	}
+
+	return 0;
+}
+
+static int nct3018y_set_alarm_mode(struct i2c_client *client, bool on)
+{
+	unsigned char buf;
+	int err;
+
+	dev_dbg(&client->dev, "%s:on:%d\n", __func__, on);
+	err = nct3018y_read_block_data(client, NCT3018Y_REG_CTRL, 1, &buf);
+	if (err < 0)
+		return err;
+
+	if (on)
+		buf |= NCT3018Y_BIT_AIE;
+	else
+		buf &= ~NCT3018Y_BIT_AIE;
+
+	buf |= NCT3018Y_BIT_CIE;
+	err = nct3018y_write_block_data(client, NCT3018Y_REG_CTRL, 1, &buf);
+	if (err < 0) {
+		dev_err(&client->dev, "%s: write NCT3018Y_REG_ST error\n", __func__);
+		return -EIO;
+	}
+
+	err = nct3018y_read_block_data(client, NCT3018Y_REG_ST, 1, &buf);
+	if (err < 0)
+		return err;
+
+	buf &= ~(NCT3018Y_BIT_AF);
+	err = nct3018y_write_block_data(client, NCT3018Y_REG_ST, 1, &buf);
+	if (err < 0) {
+		dev_err(&client->dev, "%s: write NCT3018Y_REG_ST error\n", __func__);
+		return -EIO;
+	}
+
+	return 0;
+}
+
+static int nct3018y_get_alarm_mode(struct i2c_client *client, unsigned char *alarm_enable,
+				  unsigned char *alarm_flag)
+{
+	unsigned char buf;
+	int err;
+
+	if (alarm_enable) {
+		dev_dbg(&client->dev, "%s:NCT3018Y_REG_CTRL\n", __func__);
+		err = nct3018y_read_block_data(client, NCT3018Y_REG_CTRL, 1, &buf);
+		if (err)
+			return err;
+		*alarm_enable = buf & NCT3018Y_BIT_AIE;
+	}
+
+	if (alarm_flag) {
+		dev_dbg(&client->dev, "%s:NCT3018Y_REG_ST\n", __func__);
+		err = nct3018y_read_block_data(client, NCT3018Y_REG_ST, 1, &buf);
+		if (err)
+			return err;
+		*alarm_flag = buf & NCT3018Y_BIT_AF;
+	}
+
+	dev_dbg(&client->dev, "%s:alarm_enable:%x alarm_flag:%x\n",
+		__func__, *alarm_enable, *alarm_flag);
+
+	return 0;
+}
+
+static irqreturn_t nct3018y_irq(int irq, void *dev_id)
+{
+	struct nct3018y *nct3018y = i2c_get_clientdata(dev_id);
+	struct i2c_client *client = nct3018y->client;
+	int err;
+	unsigned char alarm_flag;
+	unsigned char alarm_enable;
+
+	dev_dbg(&client->dev, "%s:irq:%d\n", __func__, irq);
+	err = nct3018y_get_alarm_mode(nct3018y->client, &alarm_enable, &alarm_flag);
+	if (err)
+		return IRQ_NONE;
+
+	if (alarm_flag) {
+		dev_dbg(&client->dev, "%s:alarm flag:%x\n",
+			__func__, alarm_flag);
+		rtc_update_irq(nct3018y->rtc, 1, RTC_IRQF | RTC_AF);
+		nct3018y_set_alarm_mode(nct3018y->client, 1);
+		dev_dbg(&client->dev, "%s:IRQ_HANDLED\n", __func__);
+		return IRQ_HANDLED;
+	}
+
+	return IRQ_NONE;
+}
+
+/*
+ * In the routines that deal directly with the nct3018y hardware, we use
+ * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
+ */
+static int nct3018y_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct nct3018y *nct3018y = i2c_get_clientdata(client);
+	unsigned char buf[10];
+	int err;
+
+	err = nct3018y_read_block_data(client, NCT3018Y_REG_ST, 1, buf);
+	if (err)
+		return err;
+
+	if (!buf[0]) {
+		dev_err(&client->dev, " voltage <=1.7, date/time is not reliable.\n");
+		return -EINVAL;
+	}
+
+	err = nct3018y_read_block_data(client, NCT3018Y_REG_SC, 10, buf);
+	if (err)
+		return err;
+
+	tm->tm_sec = bcd2bin(buf[0] & 0x7F);
+	tm->tm_min = bcd2bin(buf[2] & 0x7F);
+	tm->tm_hour = bcd2bin(buf[4] & 0x3F); /* rtc hr 0-24 */
+	tm->tm_wday = buf[6] & 0x07;
+	tm->tm_mday = bcd2bin(buf[7] & 0x3F);
+	tm->tm_mon = bcd2bin(buf[8] & 0x1F) - 1 ; /* rtc mn 1-12 */
+	tm->tm_year = bcd2bin(buf[9]) + 100;
+
+	dev_dbg(&client->dev, "%s:s=%d, m=%d, hr=%d, md=%d, m=%d, yr=%d, wd=%d\n",
+		__func__, tm->tm_sec, tm->tm_min, tm->tm_hour, tm->tm_mday, tm->tm_mon,
+		tm->tm_year, tm->tm_wday);
+
+	return 0;
+}
+
+static int nct3018y_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct nct3018y *nct3018y = i2c_get_clientdata(client);
+	unsigned char buf[10] = {0};
+	int err;
+
+	dev_dbg(&client->dev, "%s:s=%d, m=%d, hr=%d, md=%d, m=%d, yr=%d, wd=%d\n",
+		__func__, tm->tm_sec, tm->tm_min, tm->tm_hour, tm->tm_mday, tm->tm_mon,
+		tm->tm_year, tm->tm_wday);
+
+	err = nct3018y_read_block_data(client, NCT3018Y_REG_CTRL, 1, buf);
+	if (err)
+		return err;
+
+	if (!(buf[0] & NCT3018Y_BIT_TWO)) {
+		dev_err(&client->dev,
+			" TWO is not set.\n");
+		return -EINVAL;
+	}
+
+	/* hours, minutes and seconds */
+	buf[NCT3018Y_REG_SC] = bin2bcd(tm->tm_sec);
+	buf[NCT3018Y_REG_MN] = bin2bcd(tm->tm_min);
+	buf[NCT3018Y_REG_HR] = bin2bcd(tm->tm_hour);
+	buf[NCT3018Y_REG_DW] = tm->tm_wday & 0x07;
+	buf[NCT3018Y_REG_DM] = bin2bcd(tm->tm_mday);
+
+	/* month, 1 - 12 */
+	buf[NCT3018Y_REG_MO] = bin2bcd(tm->tm_mon+1);
+
+	/* year and century */
+	buf[NCT3018Y_REG_YR] = bin2bcd(tm->tm_year - 100);
+
+	return nct3018y_write_block_data(client, NCT3018Y_REG_SC, 10, buf);
+}
+
+static int nct3018y_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *tm)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	unsigned char buf[5];
+	int err;
+
+	err = nct3018y_read_block_data(client, NCT3018Y_REG_SCA, 5, buf);
+	if (err)
+		return err;
+
+	dev_dbg(&client->dev, "%s: raw data is sec=%02x, min=%02x hr=%02x\n",
+		__func__, buf[0], buf[2], buf[4]);
+
+	tm->time.tm_sec = bcd2bin(buf[0] & 0x7F);
+	tm->time.tm_min = bcd2bin(buf[2] & 0x7F);
+	tm->time.tm_hour = bcd2bin(buf[4] & 0x3F);
+
+	err = nct3018y_get_alarm_mode(client, &tm->enabled, &tm->pending);
+	if (err < 0)
+		return err;
+
+	dev_dbg(&client->dev, "%s:s=%d m=%d, hr=%d, enabled=%d, pending=%d\n",
+		__func__, tm->time.tm_sec, tm->time.tm_min,
+		tm->time.tm_hour, tm->enabled, tm->pending);
+
+	return 0;
+}
+
+static int nct3018y_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *tm)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct nct3018y *nct3018y = i2c_get_clientdata(client);
+	unsigned char buf[3];
+	int err;
+
+	dev_dbg(dev, "%s, sec=%d, min=%d hour=%d tm->enabled:%d\n",
+		__func__, tm->time.tm_sec, tm->time.tm_min, tm->time.tm_hour,
+		tm->enabled);
+
+	buf[0] = bin2bcd(tm->time.tm_sec);
+	buf[1] = bin2bcd(tm->time.tm_min);
+	buf[2] = bin2bcd(tm->time.tm_hour);
+
+	err = nct3018y_write_block_data(client, NCT3018Y_REG_SCA, 1, buf);
+	if (err)
+		return err;
+
+	err = nct3018y_write_block_data(client, NCT3018Y_REG_MNA, 1, buf+1);
+	if (err)
+		return err;
+
+	err = nct3018y_write_block_data(client, NCT3018Y_REG_HRA, 1, buf+2);
+	if (err)
+		return err;
+
+	return nct3018y_set_alarm_mode(client, tm->enabled);
+}
+
+static int nct3018y_irq_enable(struct device *dev, unsigned int enabled)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct nct3018y *nct3018y = i2c_get_clientdata(client);
+
+	dev_dbg(dev, "%s: alarm enable=%d\n", __func__, enabled);
+
+	return nct3018y_set_alarm_mode(to_i2c_client(dev), enabled);
+}
+
+#ifdef CONFIG_COMMON_CLK
+/*
+ * Handling of the clkout
+ */
+
+#define clkout_hw_to_nct3018y(_hw) container_of(_hw, struct nct3018y, clkout_hw)
+
+static const int clkout_rates[] = {
+	32768,
+	1024,
+	32,
+	1,
+};
+
+static unsigned long nct3018y_clkout_recalc_rate(struct clk_hw *hw,
+						 unsigned long parent_rate)
+{
+	struct nct3018y *nct3018y = clkout_hw_to_nct3018y(hw);
+	struct i2c_client *client = nct3018y->client;
+	unsigned char buf;
+	int ret = nct3018y_read_block_data(client, NCT3018Y_REG_CLKO, 1, &buf);
+
+	if (ret < 0)
+		return 0;
+
+	buf &= NCT3018Y_REG_CLKO_F_MASK;
+	return clkout_rates[buf];
+}
+
+static long nct3018y_clkout_round_rate(struct clk_hw *hw, unsigned long rate,
+				       unsigned long *prate)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(clkout_rates); i++)
+		if (clkout_rates[i] <= rate)
+			return clkout_rates[i];
+
+	return 0;
+}
+
+static int nct3018y_clkout_set_rate(struct clk_hw *hw, unsigned long rate,
+				   unsigned long parent_rate)
+{
+	struct nct3018y *nct3018y = clkout_hw_to_nct3018y(hw);
+	struct i2c_client *client = nct3018y->client;
+	unsigned char buf;
+	int ret = nct3018y_read_block_data(client, NCT3018Y_REG_CLKO, 1, &buf);
+	int i;
+
+	if (ret < 0)
+		return ret;
+
+	for (i = 0; i < ARRAY_SIZE(clkout_rates); i++)
+		if (clkout_rates[i] == rate) {
+			buf &= ~NCT3018Y_REG_CLKO_F_MASK;
+			buf |= i;
+			ret = nct3018y_write_block_data(client, NCT3018Y_REG_CLKO, 1, &buf);
+			return ret;
+		}
+
+	return -EINVAL;
+}
+
+static int nct3018y_clkout_control(struct clk_hw *hw, bool enable)
+{
+	struct nct3018y *nct3018y = clkout_hw_to_nct3018y(hw);
+	struct i2c_client *client = nct3018y->client;
+	unsigned char buf;
+	int ret = nct3018y_read_block_data(client, NCT3018Y_REG_CLKO, 1, &buf);
+
+	if (ret < 0)
+		return ret;
+
+	if (enable)
+		buf |= NCT3018Y_REG_CLKO_CKE;
+	else
+		buf &= ~NCT3018Y_REG_CLKO_CKE;
+
+	ret = nct3018y_write_block_data(client, NCT3018Y_REG_CLKO, 1, &buf);
+	return ret;
+}
+
+static int nct3018y_clkout_prepare(struct clk_hw *hw)
+{
+	return nct3018y_clkout_control(hw, 1);
+}
+
+static void nct3018y_clkout_unprepare(struct clk_hw *hw)
+{
+	nct3018y_clkout_control(hw, 0);
+}
+
+static int nct3018y_clkout_is_prepared(struct clk_hw *hw)
+{
+	struct nct3018y *nct3018y = clkout_hw_to_nct3018y(hw);
+	struct i2c_client *client = nct3018y->client;
+	unsigned char buf;
+	int ret = nct3018y_read_block_data(client, NCT3018Y_REG_CLKO, 1, &buf);
+
+	if (ret < 0)
+		return ret;
+
+	return buf & NCT3018Y_REG_CLKO_CKE;
+}
+
+static const struct clk_ops nct3018y_clkout_ops = {
+	.prepare = nct3018y_clkout_prepare,
+	.unprepare = nct3018y_clkout_unprepare,
+	.is_prepared = nct3018y_clkout_is_prepared,
+	.recalc_rate = nct3018y_clkout_recalc_rate,
+	.round_rate = nct3018y_clkout_round_rate,
+	.set_rate = nct3018y_clkout_set_rate,
+};
+
+static struct clk *nct3018y_clkout_register_clk(struct nct3018y *nct3018y)
+{
+	struct i2c_client *client = nct3018y->client;
+	struct device_node *node = client->dev.of_node;
+	struct clk *clk;
+	struct clk_init_data init;
+	int ret;
+	unsigned char buf;
+
+	/* disable the clkout output */
+	buf = 0;
+	ret = nct3018y_write_block_data(client, NCT3018Y_REG_CLKO, 1, &buf);
+	if (ret < 0)
+		return ERR_PTR(ret);
+
+	init.name = "nct3018y-clkout";
+	init.ops = &nct3018y_clkout_ops;
+	init.flags = 0;
+	init.parent_names = NULL;
+	init.num_parents = 0;
+	nct3018y->clkout_hw.init = &init;
+
+	/* optional override of the clockname */
+	of_property_read_string(node, "clock-output-names", &init.name);
+
+	/* register the clock */
+	clk = devm_clk_register(&client->dev, &nct3018y->clkout_hw);
+
+	if (!IS_ERR(clk))
+		of_clk_add_provider(node, of_clk_src_simple_get, clk);
+
+	return clk;
+}
+#endif
+
+static const struct rtc_class_ops nct3018y_rtc_ops = {
+	.read_time	= nct3018y_rtc_read_time,
+	.set_time	= nct3018y_rtc_set_time,
+	.read_alarm	= nct3018y_rtc_read_alarm,
+	.set_alarm	= nct3018y_rtc_set_alarm,
+	.alarm_irq_enable = nct3018y_irq_enable,
+};
+
+static int nct3018y_probe(struct i2c_client *client,
+			  const struct i2c_device_id *id)
+{
+	struct nct3018y *nct3018y;
+	int err;
+	unsigned char buf;
+
+	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
+		dev_err(&client->dev, "%s: ENODEV\n", __func__);
+		return -ENODEV;
+	}
+
+	nct3018y = devm_kzalloc(&client->dev, sizeof(struct nct3018y),
+				GFP_KERNEL);
+	if (!nct3018y)
+		return -ENOMEM;
+
+	i2c_set_clientdata(client, nct3018y);
+	nct3018y->client = client;
+	device_set_wakeup_capable(&client->dev, 1);
+
+	err = nct3018y_read_block_data(client, NCT3018Y_REG_CTRL, 1, &buf);
+	if (err < 0) {
+		dev_err(&client->dev, "%s: read error\n", __func__);
+		return err;
+	} else if (buf & NCT3018Y_BIT_TWO) {
+		dev_dbg(&client->dev, "%s: NCT3018Y_BIT_TWO is :%d\n",
+			__func__, buf & NCT3018Y_BIT_TWO);
+	}
+
+	buf = 0 | NCT3018Y_BIT_TWO;
+	err = nct3018y_write_block_data(client, NCT3018Y_REG_CTRL, 1, &buf);
+	if (err < 0) {
+		dev_err(&client->dev, "%s: write fail, so ReadOnly\n", __func__);
+	} else {
+		buf = 0;
+		err = nct3018y_write_block_data(client, NCT3018Y_REG_ST, 1, &buf);
+		if (err < 0) {
+			dev_err(&client->dev, "%s: write error\n", __func__);
+			return err;
+		}
+	}
+
+	nct3018y->rtc = devm_rtc_allocate_device(&client->dev);
+	if (IS_ERR(nct3018y->rtc))
+		return PTR_ERR(nct3018y->rtc);
+
+	nct3018y->rtc->ops = &nct3018y_rtc_ops;
+	nct3018y->rtc->uie_unsupported = 1;
+	nct3018y->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
+	nct3018y->rtc->range_max = RTC_TIMESTAMP_END_2099;
+	nct3018y->rtc->set_start_time = true;
+
+	nct3018y->wakeup_host = devm_gpiod_get(&client->dev, "host-wakeup", GPIOD_IN);
+	if (IS_ERR(nct3018y->wakeup_host)) {
+		err = PTR_ERR(nct3018y->wakeup_host);
+		dev_err(&client->dev, "could not get host wakeup gpio: %d", err);
+		return err;
+	}
+	client->irq = gpiod_to_irq(nct3018y->wakeup_host);
+
+	dev_dbg(&client->dev, "%s: client->irq:%d\n", __func__, client->irq);
+
+	if (client->irq > 0) {
+		err = devm_request_threaded_irq(&client->dev, client->irq,
+				NULL, nct3018y_irq,
+				IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
+				nct3018y_driver.driver.name, client);
+		if (err) {
+			dev_err(&client->dev, "unable to request IRQ %d\n", client->irq);
+			return err;
+		}
+	}
+
+	err = rtc_register_device(nct3018y->rtc);
+	if (err)
+		return err;
+
+#ifdef CONFIG_COMMON_CLK
+	/* register clk in common clk framework */
+	nct3018y_clkout_register_clk(nct3018y);
+#endif
+
+	return 0;
+}
+
+static const struct i2c_device_id nct3018y_id[] = {
+	{ "nct3018y", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, nct3018y_id);
+
+
+static const struct of_device_id nct3018y_of_match[] = {
+	{ .compatible = "nuvoton,nct3018y" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, nct3018y_of_match);
+
+static struct i2c_driver nct3018y_driver = {
+	.driver		= {
+		.name	= "rtc-nct3018y",
+		.of_match_table = of_match_ptr(nct3018y_of_match),
+	},
+	.probe		= nct3018y_probe,
+	.id_table	= nct3018y_id,
+};
+
+module_i2c_driver(nct3018y_driver);
+
+MODULE_AUTHOR("Medad CChien <ctcchien@nuvoton.com>");
+MODULE_DESCRIPTION("Nuvoton NCT3018Y RTC driver");
+MODULE_LICENSE("GPL v2");
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 3/3] RTC: nuvoton: Add NCT3018Y real time clock driver
  2022-05-16 15:27 ` [PATCH v1 3/3] RTC: nuvoton: Add NCT3018Y real time clock driver Medad CChien
@ 2022-05-16 23:08   ` kernel test robot
  2022-05-17  1:00   ` kernel test robot
  2022-05-17 20:27   ` kernel test robot
  2 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2022-05-16 23:08 UTC (permalink / raw)
  To: Medad CChien, benjaminfair, yuenn, venture, tali.perry1,
	tmaimon77, avifishman70, robh+dt, alexandre.belloni, a.zummo,
	KWLIU, YSCHU, JJLIU0, KFTING, ctcchien
  Cc: kbuild-all, openbmc, linux-kernel, devicetree, linux-rtc

Hi Medad,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on abelloni/rtc-next]
[also build test WARNING on robh/for-next v5.18-rc7]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Medad-CChien/ARM-dts-nuvoton-Add-nuvoton-RTC3018Y-node/20220516-232940
base:   https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git rtc-next
config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20220517/202205170654.jQqRSbra-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.2.0-20) 11.2.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/5c51862ee8030cfd9f2e955c10ee580f168663e3
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Medad-CChien/ARM-dts-nuvoton-Add-nuvoton-RTC3018Y-node/20220516-232940
        git checkout 5c51862ee8030cfd9f2e955c10ee580f168663e3
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/rtc/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/rtc/rtc-nct3018y.c: In function 'nct3018y_rtc_read_time':
>> drivers/rtc/rtc-nct3018y.c:192:26: warning: unused variable 'nct3018y' [-Wunused-variable]
     192 |         struct nct3018y *nct3018y = i2c_get_clientdata(client);
         |                          ^~~~~~~~
   drivers/rtc/rtc-nct3018y.c: In function 'nct3018y_rtc_set_time':
   drivers/rtc/rtc-nct3018y.c:227:26: warning: unused variable 'nct3018y' [-Wunused-variable]
     227 |         struct nct3018y *nct3018y = i2c_get_clientdata(client);
         |                          ^~~~~~~~
   drivers/rtc/rtc-nct3018y.c: In function 'nct3018y_rtc_set_alarm':
   drivers/rtc/rtc-nct3018y.c:292:26: warning: unused variable 'nct3018y' [-Wunused-variable]
     292 |         struct nct3018y *nct3018y = i2c_get_clientdata(client);
         |                          ^~~~~~~~
   drivers/rtc/rtc-nct3018y.c: In function 'nct3018y_irq_enable':
   drivers/rtc/rtc-nct3018y.c:322:26: warning: unused variable 'nct3018y' [-Wunused-variable]
     322 |         struct nct3018y *nct3018y = i2c_get_clientdata(client);
         |                          ^~~~~~~~
   In file included from include/linux/printk.h:555,
                    from include/linux/kernel.h:29,
                    from arch/x86/include/asm/percpu.h:27,
                    from arch/x86/include/asm/current.h:6,
                    from include/linux/mutex.h:14,
                    from include/linux/kernfs.h:11,
                    from include/linux/sysfs.h:16,
                    from include/linux/kobject.h:20,
                    from include/linux/of.h:17,
                    from include/linux/clk-provider.h:9,
                    from drivers/rtc/rtc-nct3018y.c:5:
   drivers/rtc/rtc-nct3018y.c: In function 'nct3018y_probe':
   drivers/rtc/rtc-nct3018y.c:513:39: warning: format '%d' expects argument of type 'int', but argument 5 has type 'long unsigned int' [-Wformat=]
     513 |                 dev_dbg(&client->dev, "%s: NCT3018Y_BIT_TWO is :%d\n",
         |                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dynamic_debug.h:134:29: note: in definition of macro '__dynamic_func_call'
     134 |                 func(&id, ##__VA_ARGS__);               \
         |                             ^~~~~~~~~~~
   include/linux/dynamic_debug.h:166:9: note: in expansion of macro '_dynamic_func_call'
     166 |         _dynamic_func_call(fmt,__dynamic_dev_dbg,               \
         |         ^~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:9: note: in expansion of macro 'dynamic_dev_dbg'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:30: note: in expansion of macro 'dev_fmt'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                              ^~~~~~~
   drivers/rtc/rtc-nct3018y.c:513:17: note: in expansion of macro 'dev_dbg'
     513 |                 dev_dbg(&client->dev, "%s: NCT3018Y_BIT_TWO is :%d\n",
         |                 ^~~~~~~
   drivers/rtc/rtc-nct3018y.c:513:66: note: format string is defined here
     513 |                 dev_dbg(&client->dev, "%s: NCT3018Y_BIT_TWO is :%d\n",
         |                                                                 ~^
         |                                                                  |
         |                                                                  int
         |                                                                 %ld
   drivers/rtc/rtc-nct3018y.c:535:22: error: 'struct rtc_device' has no member named 'uie_unsupported'
     535 |         nct3018y->rtc->uie_unsupported = 1;
         |                      ^~
   drivers/rtc/rtc-nct3018y.c:561:15: error: implicit declaration of function 'rtc_register_device'; did you mean 'i2c_unregister_device'? [-Werror=implicit-function-declaration]
     561 |         err = rtc_register_device(nct3018y->rtc);
         |               ^~~~~~~~~~~~~~~~~~~
         |               i2c_unregister_device
   cc1: some warnings being treated as errors


vim +/nct3018y +192 drivers/rtc/rtc-nct3018y.c

   184	
   185	/*
   186	 * In the routines that deal directly with the nct3018y hardware, we use
   187	 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
   188	 */
   189	static int nct3018y_rtc_read_time(struct device *dev, struct rtc_time *tm)
   190	{
   191		struct i2c_client *client = to_i2c_client(dev);
 > 192		struct nct3018y *nct3018y = i2c_get_clientdata(client);
   193		unsigned char buf[10];
   194		int err;
   195	
   196		err = nct3018y_read_block_data(client, NCT3018Y_REG_ST, 1, buf);
   197		if (err)
   198			return err;
   199	
   200		if (!buf[0]) {
   201			dev_err(&client->dev, " voltage <=1.7, date/time is not reliable.\n");
   202			return -EINVAL;
   203		}
   204	
   205		err = nct3018y_read_block_data(client, NCT3018Y_REG_SC, 10, buf);
   206		if (err)
   207			return err;
   208	
   209		tm->tm_sec = bcd2bin(buf[0] & 0x7F);
   210		tm->tm_min = bcd2bin(buf[2] & 0x7F);
   211		tm->tm_hour = bcd2bin(buf[4] & 0x3F); /* rtc hr 0-24 */
   212		tm->tm_wday = buf[6] & 0x07;
   213		tm->tm_mday = bcd2bin(buf[7] & 0x3F);
   214		tm->tm_mon = bcd2bin(buf[8] & 0x1F) - 1 ; /* rtc mn 1-12 */
   215		tm->tm_year = bcd2bin(buf[9]) + 100;
   216	
   217		dev_dbg(&client->dev, "%s:s=%d, m=%d, hr=%d, md=%d, m=%d, yr=%d, wd=%d\n",
   218			__func__, tm->tm_sec, tm->tm_min, tm->tm_hour, tm->tm_mday, tm->tm_mon,
   219			tm->tm_year, tm->tm_wday);
   220	
   221		return 0;
   222	}
   223	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 3/3] RTC: nuvoton: Add NCT3018Y real time clock driver
  2022-05-16 15:27 ` [PATCH v1 3/3] RTC: nuvoton: Add NCT3018Y real time clock driver Medad CChien
  2022-05-16 23:08   ` kernel test robot
@ 2022-05-17  1:00   ` kernel test robot
  2022-05-17 20:27   ` kernel test robot
  2 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2022-05-17  1:00 UTC (permalink / raw)
  To: Medad CChien, benjaminfair, yuenn, venture, tali.perry1,
	tmaimon77, avifishman70, robh+dt, alexandre.belloni, a.zummo,
	KWLIU, YSCHU, JJLIU0, KFTING, ctcchien
  Cc: kbuild-all, openbmc, linux-kernel, devicetree, linux-rtc

Hi Medad,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on abelloni/rtc-next]
[also build test WARNING on robh/for-next v5.18-rc7 next-20220516]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Medad-CChien/ARM-dts-nuvoton-Add-nuvoton-RTC3018Y-node/20220516-232940
base:   https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git rtc-next
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20220517/202205170805.G7wKugZK-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/5c51862ee8030cfd9f2e955c10ee580f168663e3
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Medad-CChien/ARM-dts-nuvoton-Add-nuvoton-RTC3018Y-node/20220516-232940
        git checkout 5c51862ee8030cfd9f2e955c10ee580f168663e3
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash drivers/rtc/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/rtc/rtc-nct3018y.c: In function 'nct3018y_rtc_read_time':
   drivers/rtc/rtc-nct3018y.c:192:26: warning: unused variable 'nct3018y' [-Wunused-variable]
     192 |         struct nct3018y *nct3018y = i2c_get_clientdata(client);
         |                          ^~~~~~~~
   drivers/rtc/rtc-nct3018y.c: In function 'nct3018y_rtc_set_time':
   drivers/rtc/rtc-nct3018y.c:227:26: warning: unused variable 'nct3018y' [-Wunused-variable]
     227 |         struct nct3018y *nct3018y = i2c_get_clientdata(client);
         |                          ^~~~~~~~
   drivers/rtc/rtc-nct3018y.c: In function 'nct3018y_rtc_set_alarm':
   drivers/rtc/rtc-nct3018y.c:292:26: warning: unused variable 'nct3018y' [-Wunused-variable]
     292 |         struct nct3018y *nct3018y = i2c_get_clientdata(client);
         |                          ^~~~~~~~
   drivers/rtc/rtc-nct3018y.c: In function 'nct3018y_irq_enable':
   drivers/rtc/rtc-nct3018y.c:322:26: warning: unused variable 'nct3018y' [-Wunused-variable]
     322 |         struct nct3018y *nct3018y = i2c_get_clientdata(client);
         |                          ^~~~~~~~
   In file included from include/linux/printk.h:555,
                    from include/linux/kernel.h:29,
                    from include/linux/cpumask.h:10,
                    from include/linux/smp.h:13,
                    from include/linux/lockdep.h:14,
                    from include/linux/mutex.h:17,
                    from include/linux/kernfs.h:11,
                    from include/linux/sysfs.h:16,
                    from include/linux/kobject.h:20,
                    from include/linux/of.h:17,
                    from include/linux/clk-provider.h:9,
                    from drivers/rtc/rtc-nct3018y.c:5:
   drivers/rtc/rtc-nct3018y.c: In function 'nct3018y_probe':
>> drivers/rtc/rtc-nct3018y.c:513:39: warning: format '%d' expects argument of type 'int', but argument 5 has type 'long unsigned int' [-Wformat=]
     513 |                 dev_dbg(&client->dev, "%s: NCT3018Y_BIT_TWO is :%d\n",
         |                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dynamic_debug.h:134:29: note: in definition of macro '__dynamic_func_call'
     134 |                 func(&id, ##__VA_ARGS__);               \
         |                             ^~~~~~~~~~~
   include/linux/dynamic_debug.h:166:9: note: in expansion of macro '_dynamic_func_call'
     166 |         _dynamic_func_call(fmt,__dynamic_dev_dbg,               \
         |         ^~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:9: note: in expansion of macro 'dynamic_dev_dbg'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:30: note: in expansion of macro 'dev_fmt'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                              ^~~~~~~
   drivers/rtc/rtc-nct3018y.c:513:17: note: in expansion of macro 'dev_dbg'
     513 |                 dev_dbg(&client->dev, "%s: NCT3018Y_BIT_TWO is :%d\n",
         |                 ^~~~~~~
   drivers/rtc/rtc-nct3018y.c:513:66: note: format string is defined here
     513 |                 dev_dbg(&client->dev, "%s: NCT3018Y_BIT_TWO is :%d\n",
         |                                                                 ~^
         |                                                                  |
         |                                                                  int
         |                                                                 %ld
   drivers/rtc/rtc-nct3018y.c:535:22: error: 'struct rtc_device' has no member named 'uie_unsupported'
     535 |         nct3018y->rtc->uie_unsupported = 1;
         |                      ^~
   drivers/rtc/rtc-nct3018y.c:561:15: error: implicit declaration of function 'rtc_register_device'; did you mean 'i2c_unregister_device'? [-Werror=implicit-function-declaration]
     561 |         err = rtc_register_device(nct3018y->rtc);
         |               ^~~~~~~~~~~~~~~~~~~
         |               i2c_unregister_device
   cc1: some warnings being treated as errors


vim +513 drivers/rtc/rtc-nct3018y.c

   486	
   487	static int nct3018y_probe(struct i2c_client *client,
   488				  const struct i2c_device_id *id)
   489	{
   490		struct nct3018y *nct3018y;
   491		int err;
   492		unsigned char buf;
   493	
   494		if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
   495			dev_err(&client->dev, "%s: ENODEV\n", __func__);
   496			return -ENODEV;
   497		}
   498	
   499		nct3018y = devm_kzalloc(&client->dev, sizeof(struct nct3018y),
   500					GFP_KERNEL);
   501		if (!nct3018y)
   502			return -ENOMEM;
   503	
   504		i2c_set_clientdata(client, nct3018y);
   505		nct3018y->client = client;
   506		device_set_wakeup_capable(&client->dev, 1);
   507	
   508		err = nct3018y_read_block_data(client, NCT3018Y_REG_CTRL, 1, &buf);
   509		if (err < 0) {
   510			dev_err(&client->dev, "%s: read error\n", __func__);
   511			return err;
   512		} else if (buf & NCT3018Y_BIT_TWO) {
 > 513			dev_dbg(&client->dev, "%s: NCT3018Y_BIT_TWO is :%d\n",
   514				__func__, buf & NCT3018Y_BIT_TWO);
   515		}
   516	
   517		buf = 0 | NCT3018Y_BIT_TWO;
   518		err = nct3018y_write_block_data(client, NCT3018Y_REG_CTRL, 1, &buf);
   519		if (err < 0) {
   520			dev_err(&client->dev, "%s: write fail, so ReadOnly\n", __func__);
   521		} else {
   522			buf = 0;
   523			err = nct3018y_write_block_data(client, NCT3018Y_REG_ST, 1, &buf);
   524			if (err < 0) {
   525				dev_err(&client->dev, "%s: write error\n", __func__);
   526				return err;
   527			}
   528		}
   529	
   530		nct3018y->rtc = devm_rtc_allocate_device(&client->dev);
   531		if (IS_ERR(nct3018y->rtc))
   532			return PTR_ERR(nct3018y->rtc);
   533	
   534		nct3018y->rtc->ops = &nct3018y_rtc_ops;
   535		nct3018y->rtc->uie_unsupported = 1;
   536		nct3018y->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
   537		nct3018y->rtc->range_max = RTC_TIMESTAMP_END_2099;
   538		nct3018y->rtc->set_start_time = true;
   539	
   540		nct3018y->wakeup_host = devm_gpiod_get(&client->dev, "host-wakeup", GPIOD_IN);
   541		if (IS_ERR(nct3018y->wakeup_host)) {
   542			err = PTR_ERR(nct3018y->wakeup_host);
   543			dev_err(&client->dev, "could not get host wakeup gpio: %d", err);
   544			return err;
   545		}
   546		client->irq = gpiod_to_irq(nct3018y->wakeup_host);
   547	
   548		dev_dbg(&client->dev, "%s: client->irq:%d\n", __func__, client->irq);
   549	
   550		if (client->irq > 0) {
   551			err = devm_request_threaded_irq(&client->dev, client->irq,
   552					NULL, nct3018y_irq,
   553					IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
   554					nct3018y_driver.driver.name, client);
   555			if (err) {
   556				dev_err(&client->dev, "unable to request IRQ %d\n", client->irq);
   557				return err;
   558			}
   559		}
   560	
   561		err = rtc_register_device(nct3018y->rtc);
   562		if (err)
   563			return err;
   564	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 3/3] RTC: nuvoton: Add NCT3018Y real time clock driver
  2022-05-16 15:27 ` [PATCH v1 3/3] RTC: nuvoton: Add NCT3018Y real time clock driver Medad CChien
  2022-05-16 23:08   ` kernel test robot
  2022-05-17  1:00   ` kernel test robot
@ 2022-05-17 20:27   ` kernel test robot
  2 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2022-05-17 20:27 UTC (permalink / raw)
  To: Medad CChien, benjaminfair, yuenn, venture, tali.perry1,
	tmaimon77, avifishman70, robh+dt, alexandre.belloni, a.zummo,
	KWLIU, YSCHU, JJLIU0, KFTING, ctcchien
  Cc: kbuild-all, openbmc, linux-kernel, devicetree, linux-rtc

Hi Medad,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on abelloni/rtc-next]
[also build test ERROR on robh/for-next v5.18-rc7 next-20220517]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Medad-CChien/ARM-dts-nuvoton-Add-nuvoton-RTC3018Y-node/20220516-232940
base:   https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git rtc-next
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20220518/202205180421.cGv6R8hi-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/5c51862ee8030cfd9f2e955c10ee580f168663e3
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Medad-CChien/ARM-dts-nuvoton-Add-nuvoton-RTC3018Y-node/20220516-232940
        git checkout 5c51862ee8030cfd9f2e955c10ee580f168663e3
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/rtc/rtc-nct3018y.c: In function 'nct3018y_rtc_read_time':
   drivers/rtc/rtc-nct3018y.c:192:26: warning: unused variable 'nct3018y' [-Wunused-variable]
     192 |         struct nct3018y *nct3018y = i2c_get_clientdata(client);
         |                          ^~~~~~~~
   drivers/rtc/rtc-nct3018y.c: In function 'nct3018y_rtc_set_time':
   drivers/rtc/rtc-nct3018y.c:227:26: warning: unused variable 'nct3018y' [-Wunused-variable]
     227 |         struct nct3018y *nct3018y = i2c_get_clientdata(client);
         |                          ^~~~~~~~
   drivers/rtc/rtc-nct3018y.c: In function 'nct3018y_rtc_set_alarm':
   drivers/rtc/rtc-nct3018y.c:292:26: warning: unused variable 'nct3018y' [-Wunused-variable]
     292 |         struct nct3018y *nct3018y = i2c_get_clientdata(client);
         |                          ^~~~~~~~
   drivers/rtc/rtc-nct3018y.c: In function 'nct3018y_irq_enable':
   drivers/rtc/rtc-nct3018y.c:322:26: warning: unused variable 'nct3018y' [-Wunused-variable]
     322 |         struct nct3018y *nct3018y = i2c_get_clientdata(client);
         |                          ^~~~~~~~
   In file included from include/linux/printk.h:555,
                    from include/linux/kernel.h:29,
                    from include/linux/cpumask.h:10,
                    from include/linux/smp.h:13,
                    from include/linux/lockdep.h:14,
                    from include/linux/mutex.h:17,
                    from include/linux/kernfs.h:11,
                    from include/linux/sysfs.h:16,
                    from include/linux/kobject.h:20,
                    from include/linux/of.h:17,
                    from include/linux/clk-provider.h:9,
                    from drivers/rtc/rtc-nct3018y.c:5:
   drivers/rtc/rtc-nct3018y.c: In function 'nct3018y_probe':
   drivers/rtc/rtc-nct3018y.c:513:39: warning: format '%d' expects argument of type 'int', but argument 5 has type 'long unsigned int' [-Wformat=]
     513 |                 dev_dbg(&client->dev, "%s: NCT3018Y_BIT_TWO is :%d\n",
         |                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dynamic_debug.h:134:29: note: in definition of macro '__dynamic_func_call'
     134 |                 func(&id, ##__VA_ARGS__);               \
         |                             ^~~~~~~~~~~
   include/linux/dynamic_debug.h:166:9: note: in expansion of macro '_dynamic_func_call'
     166 |         _dynamic_func_call(fmt,__dynamic_dev_dbg,               \
         |         ^~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:9: note: in expansion of macro 'dynamic_dev_dbg'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:30: note: in expansion of macro 'dev_fmt'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                              ^~~~~~~
   drivers/rtc/rtc-nct3018y.c:513:17: note: in expansion of macro 'dev_dbg'
     513 |                 dev_dbg(&client->dev, "%s: NCT3018Y_BIT_TWO is :%d\n",
         |                 ^~~~~~~
   drivers/rtc/rtc-nct3018y.c:513:66: note: format string is defined here
     513 |                 dev_dbg(&client->dev, "%s: NCT3018Y_BIT_TWO is :%d\n",
         |                                                                 ~^
         |                                                                  |
         |                                                                  int
         |                                                                 %ld
>> drivers/rtc/rtc-nct3018y.c:535:22: error: 'struct rtc_device' has no member named 'uie_unsupported'
     535 |         nct3018y->rtc->uie_unsupported = 1;
         |                      ^~
>> drivers/rtc/rtc-nct3018y.c:561:15: error: implicit declaration of function 'rtc_register_device'; did you mean 'i2c_unregister_device'? [-Werror=implicit-function-declaration]
     561 |         err = rtc_register_device(nct3018y->rtc);
         |               ^~~~~~~~~~~~~~~~~~~
         |               i2c_unregister_device
   cc1: some warnings being treated as errors


vim +535 drivers/rtc/rtc-nct3018y.c

   486	
   487	static int nct3018y_probe(struct i2c_client *client,
   488				  const struct i2c_device_id *id)
   489	{
   490		struct nct3018y *nct3018y;
   491		int err;
   492		unsigned char buf;
   493	
   494		if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
   495			dev_err(&client->dev, "%s: ENODEV\n", __func__);
   496			return -ENODEV;
   497		}
   498	
   499		nct3018y = devm_kzalloc(&client->dev, sizeof(struct nct3018y),
   500					GFP_KERNEL);
   501		if (!nct3018y)
   502			return -ENOMEM;
   503	
   504		i2c_set_clientdata(client, nct3018y);
   505		nct3018y->client = client;
   506		device_set_wakeup_capable(&client->dev, 1);
   507	
   508		err = nct3018y_read_block_data(client, NCT3018Y_REG_CTRL, 1, &buf);
   509		if (err < 0) {
   510			dev_err(&client->dev, "%s: read error\n", __func__);
   511			return err;
   512		} else if (buf & NCT3018Y_BIT_TWO) {
   513			dev_dbg(&client->dev, "%s: NCT3018Y_BIT_TWO is :%d\n",
   514				__func__, buf & NCT3018Y_BIT_TWO);
   515		}
   516	
   517		buf = 0 | NCT3018Y_BIT_TWO;
   518		err = nct3018y_write_block_data(client, NCT3018Y_REG_CTRL, 1, &buf);
   519		if (err < 0) {
   520			dev_err(&client->dev, "%s: write fail, so ReadOnly\n", __func__);
   521		} else {
   522			buf = 0;
   523			err = nct3018y_write_block_data(client, NCT3018Y_REG_ST, 1, &buf);
   524			if (err < 0) {
   525				dev_err(&client->dev, "%s: write error\n", __func__);
   526				return err;
   527			}
   528		}
   529	
   530		nct3018y->rtc = devm_rtc_allocate_device(&client->dev);
   531		if (IS_ERR(nct3018y->rtc))
   532			return PTR_ERR(nct3018y->rtc);
   533	
   534		nct3018y->rtc->ops = &nct3018y_rtc_ops;
 > 535		nct3018y->rtc->uie_unsupported = 1;
   536		nct3018y->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
   537		nct3018y->rtc->range_max = RTC_TIMESTAMP_END_2099;
   538		nct3018y->rtc->set_start_time = true;
   539	
   540		nct3018y->wakeup_host = devm_gpiod_get(&client->dev, "host-wakeup", GPIOD_IN);
   541		if (IS_ERR(nct3018y->wakeup_host)) {
   542			err = PTR_ERR(nct3018y->wakeup_host);
   543			dev_err(&client->dev, "could not get host wakeup gpio: %d", err);
   544			return err;
   545		}
   546		client->irq = gpiod_to_irq(nct3018y->wakeup_host);
   547	
   548		dev_dbg(&client->dev, "%s: client->irq:%d\n", __func__, client->irq);
   549	
   550		if (client->irq > 0) {
   551			err = devm_request_threaded_irq(&client->dev, client->irq,
   552					NULL, nct3018y_irq,
   553					IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
   554					nct3018y_driver.driver.name, client);
   555			if (err) {
   556				dev_err(&client->dev, "unable to request IRQ %d\n", client->irq);
   557				return err;
   558			}
   559		}
   560	
 > 561		err = rtc_register_device(nct3018y->rtc);
   562		if (err)
   563			return err;
   564	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-05-17 20:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16 15:27 [PATCH v1 1/3] ARM: dts: nuvoton: Add nuvoton RTC3018Y node Medad CChien
2022-05-16 15:27 ` [PATCH v1 2/3] dt-bindings: rtc: nuvoton: add NCT3018Y Real Time Clock Medad CChien
2022-05-16 15:27 ` [PATCH v1 3/3] RTC: nuvoton: Add NCT3018Y real time clock driver Medad CChien
2022-05-16 23:08   ` kernel test robot
2022-05-17  1:00   ` kernel test robot
2022-05-17 20:27   ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).