linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V7 1/4] dt-bindings: fsl: scu: add general interrupt support
@ 2019-04-09  4:59 Anson Huang
  2019-04-09  4:59 ` [PATCH V7 2/4] firmware: imx: enable imx scu general irq function Anson Huang
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Anson Huang @ 2019-04-09  4:59 UTC (permalink / raw)
  To: robh+dt, mark.rutland, shawnguo, s.hauer, kernel, festevam,
	a.zummo, alexandre.belloni, Aisheng Dong, ulf.hansson, sboyd,
	Peng Fan, Daniel Baluta, devicetree, linux-kernel,
	linux-arm-kernel, linux-rtc
  Cc: dl-linux-imx

Add scu general interrupt function support.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
---
No changes.
---
 .../devicetree/bindings/arm/freescale/fsl,scu.txt  | 29 +++++++++++++++++-----
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt b/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt
index 72d481c..5d7dbab 100644
--- a/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt
+++ b/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt
@@ -22,9 +22,11 @@ Required properties:
 -------------------
 - compatible:	should be "fsl,imx-scu".
 - mbox-names:	should include "tx0", "tx1", "tx2", "tx3",
-			       "rx0", "rx1", "rx2", "rx3".
-- mboxes:	List of phandle of 4 MU channels for tx and 4 MU channels
-		for rx. All 8 MU channels must be in the same MU instance.
+			       "rx0", "rx1", "rx2", "rx3";
+		include "gip3" if want to support general MU interrupt.
+- mboxes:	List of phandle of 4 MU channels for tx, 4 MU channels for
+		rx, and 1 optional MU channel for general interrupt.
+		All MU channels must be in the same MU instance.
 		Cross instances are not allowed. The MU instance can only
 		be one of LSIO MU0~M4 for imx8qxp and imx8qm. Users need
 		to make sure use the one which is not conflict with other
@@ -34,6 +36,7 @@ Required properties:
 		Channel 1 must be "tx1" or "rx1".
 		Channel 2 must be "tx2" or "rx2".
 		Channel 3 must be "tx3" or "rx3".
+		General interrupt rx channel must be "gip3".
 		e.g.
 		mboxes = <&lsio_mu1 0 0
 			  &lsio_mu1 0 1
@@ -42,10 +45,18 @@ Required properties:
 			  &lsio_mu1 1 0
 			  &lsio_mu1 1 1
 			  &lsio_mu1 1 2
-			  &lsio_mu1 1 3>;
+			  &lsio_mu1 1 3
+			  &lsio_mu1 3 3>;
 		See Documentation/devicetree/bindings/mailbox/fsl,mu.txt
 		for detailed mailbox binding.
 
+Note: Each mu which supports general interrupt should have an alias correctly
+numbered in "aliases" node.
+e.g.
+aliases {
+	mu1 = &lsio_mu1;
+};
+
 i.MX SCU Client Device Node:
 ============================================================
 
@@ -124,6 +135,10 @@ Required properties:
 
 Example (imx8qxp):
 -------------
+aliases {
+	mu1 = &lsio_mu1;
+};
+
 lsio_mu1: mailbox@5d1c0000 {
 	...
 	#mbox-cells = <2>;
@@ -133,7 +148,8 @@ firmware {
 	scu {
 		compatible = "fsl,imx-scu";
 		mbox-names = "tx0", "tx1", "tx2", "tx3",
-			     "rx0", "rx1", "rx2", "rx3";
+			     "rx0", "rx1", "rx2", "rx3",
+			     "gip3";
 		mboxes = <&lsio_mu1 0 0
 			  &lsio_mu1 0 1
 			  &lsio_mu1 0 2
@@ -141,7 +157,8 @@ firmware {
 			  &lsio_mu1 1 0
 			  &lsio_mu1 1 1
 			  &lsio_mu1 1 2
-			  &lsio_mu1 1 3>;
+			  &lsio_mu1 1 3
+			  &lsio_mu1 3 3>;
 
 		clk: clk {
 			compatible = "fsl,imx8qxp-clk", "fsl,scu-clk";
-- 
2.7.4


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

* [PATCH V7 2/4] firmware: imx: enable imx scu general irq function
  2019-04-09  4:59 [PATCH V7 1/4] dt-bindings: fsl: scu: add general interrupt support Anson Huang
@ 2019-04-09  4:59 ` Anson Huang
  2019-04-11  7:32   ` Shawn Guo
  2019-04-09  5:00 ` [PATCH V7 3/4] arm64: dts: freescale: imx8qxp: enable scu general irq channel Anson Huang
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 15+ messages in thread
From: Anson Huang @ 2019-04-09  4:59 UTC (permalink / raw)
  To: robh+dt, mark.rutland, shawnguo, s.hauer, kernel, festevam,
	a.zummo, alexandre.belloni, Aisheng Dong, ulf.hansson, sboyd,
	Peng Fan, Daniel Baluta, devicetree, linux-kernel,
	linux-arm-kernel, linux-rtc
  Cc: dl-linux-imx

The System Controller Firmware (SCFW) controls RTC, thermal
and WDOG etc., these resources' interrupt function are managed
by SCU. When any IRQ pending, SCU will notify Linux via MU general
interrupt channel #3, and Linux kernel needs to call SCU APIs
to get IRQ status and notify each module to handle the interrupt.

Since there is no data transmission for SCU IRQ notification, so
doorbell mode is used for this MU channel, and SCU driver will
use notifier mechanism to broadcast to every module which registers
the SCU block notifier.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
---
Changes since V6:
	- improve imx_scu_irq_enable() function name to imx_scu_irq_group_enable();
	- make imx_scu_irq_group_enable() function return int;
---
 drivers/firmware/imx/Makefile      |   2 +-
 drivers/firmware/imx/imx-scu-irq.c | 168 +++++++++++++++++++++++++++++++++++++
 drivers/firmware/imx/imx-scu.c     |   6 ++
 include/linux/firmware/imx/sci.h   |   5 ++
 4 files changed, 180 insertions(+), 1 deletion(-)
 create mode 100644 drivers/firmware/imx/imx-scu-irq.c

diff --git a/drivers/firmware/imx/Makefile b/drivers/firmware/imx/Makefile
index 1b2e15b..802c4ad 100644
--- a/drivers/firmware/imx/Makefile
+++ b/drivers/firmware/imx/Makefile
@@ -1,3 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0
-obj-$(CONFIG_IMX_SCU)		+= imx-scu.o misc.o
+obj-$(CONFIG_IMX_SCU)		+= imx-scu.o misc.o imx-scu-irq.o
 obj-$(CONFIG_IMX_SCU_PD)	+= scu-pd.o
diff --git a/drivers/firmware/imx/imx-scu-irq.c b/drivers/firmware/imx/imx-scu-irq.c
new file mode 100644
index 0000000..043833a
--- /dev/null
+++ b/drivers/firmware/imx/imx-scu-irq.c
@@ -0,0 +1,168 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2019 NXP
+ *
+ * Implementation of the SCU IRQ functions using MU.
+ *
+ */
+
+#include <dt-bindings/firmware/imx/rsrc.h>
+#include <linux/firmware/imx/ipc.h>
+#include <linux/mailbox_client.h>
+
+#define IMX_SC_IRQ_FUNC_ENABLE	1
+#define IMX_SC_IRQ_FUNC_STATUS	2
+#define IMX_SC_IRQ_NUM_GROUP	4
+
+static u32 mu_resource_id;
+
+struct imx_sc_msg_irq_get_status {
+	struct imx_sc_rpc_msg hdr;
+	union {
+		struct {
+			u16 resource;
+			u8 group;
+			u8 reserved;
+		} __packed req;
+		struct {
+			u32 status;
+		} resp;
+	} data;
+};
+
+struct imx_sc_msg_irq_enable {
+	struct imx_sc_rpc_msg hdr;
+	u32 mask;
+	u16 resource;
+	u8 group;
+	u8 enable;
+} __packed;
+
+static struct imx_sc_ipc *imx_sc_irq_ipc_handle;
+static struct work_struct imx_sc_irq_work;
+static ATOMIC_NOTIFIER_HEAD(imx_scu_irq_notifier_chain);
+
+int imx_scu_irq_register_notifier(struct notifier_block *nb)
+{
+	return atomic_notifier_chain_register(
+		&imx_scu_irq_notifier_chain, nb);
+}
+EXPORT_SYMBOL(imx_scu_irq_register_notifier);
+
+int imx_scu_irq_unregister_notifier(struct notifier_block *nb)
+{
+	return atomic_notifier_chain_unregister(
+		&imx_scu_irq_notifier_chain, nb);
+}
+EXPORT_SYMBOL(imx_scu_irq_unregister_notifier);
+
+static int imx_scu_irq_notifier_call_chain(unsigned long status, u8 *group)
+{
+	return atomic_notifier_call_chain(&imx_scu_irq_notifier_chain,
+		status, (void *)group);
+}
+
+static void imx_scu_irq_work_handler(struct work_struct *work)
+{
+	struct imx_sc_msg_irq_get_status msg;
+	struct imx_sc_rpc_msg *hdr = &msg.hdr;
+	u32 irq_status;
+	int ret;
+	u8 i;
+
+	for (i = 0; i < IMX_SC_IRQ_NUM_GROUP; i++) {
+		hdr->ver = IMX_SC_RPC_VERSION;
+		hdr->svc = IMX_SC_RPC_SVC_IRQ;
+		hdr->func = IMX_SC_IRQ_FUNC_STATUS;
+		hdr->size = 2;
+
+		msg.data.req.resource = mu_resource_id;
+		msg.data.req.group = i;
+
+		ret = imx_scu_call_rpc(imx_sc_irq_ipc_handle, &msg, true);
+		if (ret) {
+			pr_err("get irq group %d status failed, ret %d\n",
+			       i, ret);
+			return;
+		}
+
+		irq_status = msg.data.resp.status;
+		if (!irq_status)
+			continue;
+
+		imx_scu_irq_notifier_call_chain(irq_status, &i);
+	}
+}
+
+int imx_scu_irq_group_enable(u8 group, u32 mask, u8 enable)
+{
+	struct imx_sc_msg_irq_enable msg;
+	struct imx_sc_rpc_msg *hdr = &msg.hdr;
+	int ret;
+
+	hdr->ver = IMX_SC_RPC_VERSION;
+	hdr->svc = IMX_SC_RPC_SVC_IRQ;
+	hdr->func = IMX_SC_IRQ_FUNC_ENABLE;
+	hdr->size = 3;
+
+	msg.resource = mu_resource_id;
+	msg.group = group;
+	msg.mask = mask;
+	msg.enable = enable;
+
+	ret = imx_scu_call_rpc(imx_sc_irq_ipc_handle, &msg, true);
+	if (ret)
+		pr_err("enable irq failed, group %d, mask %d, ret %d\n",
+			group, mask, ret);
+
+	return ret;
+}
+EXPORT_SYMBOL(imx_scu_irq_group_enable);
+
+static void imx_scu_irq_callback(struct mbox_client *c, void *msg)
+{
+	schedule_work(&imx_sc_irq_work);
+}
+
+int imx_scu_enable_general_irq_channel(struct device *dev)
+{
+	struct of_phandle_args spec;
+	struct mbox_client *cl;
+	struct mbox_chan *ch;
+	int ret = 0, i = 0;
+
+	ret = imx_scu_get_handle(&imx_sc_irq_ipc_handle);
+	if (ret)
+		return ret;
+
+	cl = devm_kzalloc(dev, sizeof(*cl), GFP_KERNEL);
+	if (!cl)
+		return -ENOMEM;
+
+	cl->dev = dev;
+	cl->rx_callback = imx_scu_irq_callback;
+
+	/* SCU general IRQ uses general interrupt channel 3 */
+	ch = mbox_request_channel_byname(cl, "gip3");
+	if (IS_ERR(ch)) {
+		ret = PTR_ERR(ch);
+		dev_err(dev, "failed to request mbox chan gip3, ret %d\n", ret);
+		devm_kfree(dev, cl);
+		return ret;
+	}
+
+	INIT_WORK(&imx_sc_irq_work, imx_scu_irq_work_handler);
+
+	if (!of_parse_phandle_with_args(dev->of_node, "mboxes",
+				       "#mbox-cells", 0, &spec))
+		i = of_alias_get_id(spec.np, "mu");
+
+	/* use mu1 as general mu irq channel if failed */
+	if (i < 0)
+		i = 1;
+
+	mu_resource_id = IMX_SC_R_MU_0A + i;
+
+	return ret;
+}
+EXPORT_SYMBOL(imx_scu_enable_general_irq_channel);
diff --git a/drivers/firmware/imx/imx-scu.c b/drivers/firmware/imx/imx-scu.c
index 2bb1a19..04a24a8 100644
--- a/drivers/firmware/imx/imx-scu.c
+++ b/drivers/firmware/imx/imx-scu.c
@@ -10,6 +10,7 @@
 #include <linux/err.h>
 #include <linux/firmware/imx/types.h>
 #include <linux/firmware/imx/ipc.h>
+#include <linux/firmware/imx/sci.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/kernel.h>
@@ -246,6 +247,11 @@ static int imx_scu_probe(struct platform_device *pdev)
 
 	imx_sc_ipc_handle = sc_ipc;
 
+	ret = imx_scu_enable_general_irq_channel(dev);
+	if (ret)
+		dev_warn(dev,
+			"failed to enable general irq channel: %d\n", ret);
+
 	dev_info(dev, "NXP i.MX SCU Initialized\n");
 
 	return devm_of_platform_populate(dev);
diff --git a/include/linux/firmware/imx/sci.h b/include/linux/firmware/imx/sci.h
index ebc5509..17ba4e4 100644
--- a/include/linux/firmware/imx/sci.h
+++ b/include/linux/firmware/imx/sci.h
@@ -15,4 +15,9 @@
 
 #include <linux/firmware/imx/svc/misc.h>
 #include <linux/firmware/imx/svc/pm.h>
+
+int imx_scu_enable_general_irq_channel(struct device *dev);
+int imx_scu_irq_register_notifier(struct notifier_block *nb);
+int imx_scu_irq_unregister_notifier(struct notifier_block *nb);
+int imx_scu_irq_group_enable(u8 group, u32 mask, u8 enable);
 #endif /* _SC_SCI_H */
-- 
2.7.4


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

* [PATCH V7 3/4] arm64: dts: freescale: imx8qxp: enable scu general irq channel
  2019-04-09  4:59 [PATCH V7 1/4] dt-bindings: fsl: scu: add general interrupt support Anson Huang
  2019-04-09  4:59 ` [PATCH V7 2/4] firmware: imx: enable imx scu general irq function Anson Huang
@ 2019-04-09  5:00 ` Anson Huang
  2019-04-11  7:34   ` Shawn Guo
  2019-04-09  5:00 ` [PATCH V7 4/4] rtc: imx-sc: add rtc alarm support Anson Huang
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 15+ messages in thread
From: Anson Huang @ 2019-04-09  5:00 UTC (permalink / raw)
  To: robh+dt, mark.rutland, shawnguo, s.hauer, kernel, festevam,
	a.zummo, alexandre.belloni, Aisheng Dong, ulf.hansson, sboyd,
	Peng Fan, Daniel Baluta, devicetree, linux-kernel,
	linux-arm-kernel, linux-rtc
  Cc: dl-linux-imx

On i.MX8QXP, SCU uses MU1 general interrupt channel #3 to notify
user for IRQs of RTC alarm, thermal alarm and WDOG etc., mailbox
RX doorbell mode is used for this function, this patch adds
support for it.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
---
No changes.
---
 arch/arm64/boot/dts/freescale/imx8qxp.dtsi | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/boot/dts/freescale/imx8qxp.dtsi b/arch/arm64/boot/dts/freescale/imx8qxp.dtsi
index 0cb9398..70ef3db 100644
--- a/arch/arm64/boot/dts/freescale/imx8qxp.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8qxp.dtsi
@@ -21,6 +21,7 @@
 		mmc1 = &usdhc2;
 		mmc2 = &usdhc3;
 		serial0 = &adma_lpuart0;
+		mu1 = &lsio_mu1;
 	};
 
 	cpus {
@@ -117,7 +118,8 @@
 	scu {
 		compatible = "fsl,imx-scu";
 		mbox-names = "tx0", "tx1", "tx2", "tx3",
-			     "rx0", "rx1", "rx2", "rx3";
+			     "rx0", "rx1", "rx2", "rx3",
+			     "gip3";
 		mboxes = <&lsio_mu1 0 0
 			  &lsio_mu1 0 1
 			  &lsio_mu1 0 2
@@ -125,7 +127,8 @@
 			  &lsio_mu1 1 0
 			  &lsio_mu1 1 1
 			  &lsio_mu1 1 2
-			  &lsio_mu1 1 3>;
+			  &lsio_mu1 1 3
+			  &lsio_mu1 3 3>;
 
 		clk: clock-controller {
 			compatible = "fsl,imx8qxp-clk";
-- 
2.7.4


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

* [PATCH V7 4/4] rtc: imx-sc: add rtc alarm support
  2019-04-09  4:59 [PATCH V7 1/4] dt-bindings: fsl: scu: add general interrupt support Anson Huang
  2019-04-09  4:59 ` [PATCH V7 2/4] firmware: imx: enable imx scu general irq function Anson Huang
  2019-04-09  5:00 ` [PATCH V7 3/4] arm64: dts: freescale: imx8qxp: enable scu general irq channel Anson Huang
@ 2019-04-09  5:00 ` Anson Huang
  2019-04-12  8:41   ` Alexandre Belloni
  2019-06-01 21:18   ` Alexandre Belloni
  2019-04-11  1:37 ` [PATCH V7 1/4] dt-bindings: fsl: scu: add general interrupt support Anson Huang
  2019-04-11  7:32 ` Shawn Guo
  4 siblings, 2 replies; 15+ messages in thread
From: Anson Huang @ 2019-04-09  5:00 UTC (permalink / raw)
  To: robh+dt, mark.rutland, shawnguo, s.hauer, kernel, festevam,
	a.zummo, alexandre.belloni, Aisheng Dong, ulf.hansson, sboyd,
	Peng Fan, Daniel Baluta, devicetree, linux-kernel,
	linux-arm-kernel, linux-rtc
  Cc: dl-linux-imx

Add i.MX system controller RTC alarm support, the RTC alarm
is implemented via SIP(silicon provider) runtime service call
and ARM-Trusted-Firmware will communicate with system controller
via MU(message unit) IPC to set RTC alarm. When RTC alarm fires,
system controller will generate a common MU irq event and notify
system controller RTC driver to handle the irq event.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
---
Changes since V6:
	- add comments to .read_alarm callback function to explain why it is an empty function;
	- improve irq notify callback function name.
--
 drivers/rtc/rtc-imx-sc.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)

diff --git a/drivers/rtc/rtc-imx-sc.c b/drivers/rtc/rtc-imx-sc.c
index 19642bf..c933045 100644
--- a/drivers/rtc/rtc-imx-sc.c
+++ b/drivers/rtc/rtc-imx-sc.c
@@ -3,6 +3,7 @@
  * Copyright 2018 NXP.
  */
 
+#include <dt-bindings/firmware/imx/rsrc.h>
 #include <linux/arm-smccc.h>
 #include <linux/firmware/imx/sci.h>
 #include <linux/module.h>
@@ -11,11 +12,15 @@
 #include <linux/rtc.h>
 
 #define IMX_SC_TIMER_FUNC_GET_RTC_SEC1970	9
+#define IMX_SC_TIMER_FUNC_SET_RTC_ALARM		8
 #define IMX_SC_TIMER_FUNC_SET_RTC_TIME		6
 
 #define IMX_SIP_SRTC			0xC2000002
 #define IMX_SIP_SRTC_SET_TIME		0x0
 
+#define SC_IRQ_GROUP_RTC    2
+#define SC_IRQ_RTC          1
+
 static struct imx_sc_ipc *rtc_ipc_handle;
 static struct rtc_device *imx_sc_rtc;
 
@@ -24,6 +29,16 @@ struct imx_sc_msg_timer_get_rtc_time {
 	u32 time;
 } __packed;
 
+struct imx_sc_msg_timer_rtc_set_alarm {
+	struct imx_sc_rpc_msg hdr;
+	u16 year;
+	u8 mon;
+	u8 day;
+	u8 hour;
+	u8 min;
+	u8 sec;
+} __packed;
+
 static int imx_sc_rtc_read_time(struct device *dev, struct rtc_time *tm)
 {
 	struct imx_sc_msg_timer_get_rtc_time msg;
@@ -60,9 +75,77 @@ static int imx_sc_rtc_set_time(struct device *dev, struct rtc_time *tm)
 	return res.a0;
 }
 
+static int imx_sc_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
+{
+	return imx_scu_irq_group_enable(SC_IRQ_GROUP_RTC, SC_IRQ_RTC, enable);
+}
+
+static int imx_sc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+	/*
+	 * SCU firmware does NOT provide read alarm API, but .read_alarm
+	 * callback is required by RTC framework to support alarm function,
+	 * so just return here.
+	 */
+	return 0;
+}
+
+static int imx_sc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+	struct imx_sc_msg_timer_rtc_set_alarm msg;
+	struct imx_sc_rpc_msg *hdr = &msg.hdr;
+	int ret;
+	struct rtc_time *alrm_tm = &alrm->time;
+
+	hdr->ver = IMX_SC_RPC_VERSION;
+	hdr->svc = IMX_SC_RPC_SVC_TIMER;
+	hdr->func = IMX_SC_TIMER_FUNC_SET_RTC_ALARM;
+	hdr->size = 3;
+
+	msg.year = alrm_tm->tm_year + 1900;
+	msg.mon = alrm_tm->tm_mon + 1;
+	msg.day = alrm_tm->tm_mday;
+	msg.hour = alrm_tm->tm_hour;
+	msg.min = alrm_tm->tm_min;
+	msg.sec = alrm_tm->tm_sec;
+
+	ret = imx_scu_call_rpc(rtc_ipc_handle, &msg, true);
+	if (ret) {
+		dev_err(dev, "set rtc alarm failed, ret %d\n", ret);
+		return ret;
+	}
+
+	ret = imx_sc_rtc_alarm_irq_enable(dev, alrm->enabled);
+	if (ret) {
+		dev_err(dev, "enable rtc alarm failed, ret %d\n", ret);
+		return ret;
+	}
+
+	return 0;
+}
+
 static const struct rtc_class_ops imx_sc_rtc_ops = {
 	.read_time = imx_sc_rtc_read_time,
 	.set_time = imx_sc_rtc_set_time,
+	.read_alarm = imx_sc_rtc_read_alarm,
+	.set_alarm = imx_sc_rtc_set_alarm,
+	.alarm_irq_enable = imx_sc_rtc_alarm_irq_enable,
+};
+
+static int imx_sc_rtc_alarm_notify(struct notifier_block *nb,
+					unsigned long event, void *group)
+{
+	/* ignore non-rtc irq */
+	if (!((event & SC_IRQ_RTC) && (*(u8 *)group == SC_IRQ_GROUP_RTC)))
+		return 0;
+
+	rtc_update_irq(imx_sc_rtc, 1, RTC_IRQF | RTC_AF);
+
+	return 0;
+}
+
+static struct notifier_block imx_sc_rtc_alarm_sc_notifier = {
+	.notifier_call = imx_sc_rtc_alarm_notify,
 };
 
 static int imx_sc_rtc_probe(struct platform_device *pdev)
@@ -73,6 +156,8 @@ static int imx_sc_rtc_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	device_init_wakeup(&pdev->dev, true);
+
 	imx_sc_rtc = devm_rtc_allocate_device(&pdev->dev);
 	if (IS_ERR(imx_sc_rtc))
 		return PTR_ERR(imx_sc_rtc);
@@ -87,6 +172,8 @@ static int imx_sc_rtc_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	imx_scu_irq_register_notifier(&imx_sc_rtc_alarm_sc_notifier);
+
 	return 0;
 }
 
-- 
2.7.4


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

* RE: [PATCH V7 1/4] dt-bindings: fsl: scu: add general interrupt support
  2019-04-09  4:59 [PATCH V7 1/4] dt-bindings: fsl: scu: add general interrupt support Anson Huang
                   ` (2 preceding siblings ...)
  2019-04-09  5:00 ` [PATCH V7 4/4] rtc: imx-sc: add rtc alarm support Anson Huang
@ 2019-04-11  1:37 ` Anson Huang
  2019-04-11  7:32 ` Shawn Guo
  4 siblings, 0 replies; 15+ messages in thread
From: Anson Huang @ 2019-04-11  1:37 UTC (permalink / raw)
  To: robh+dt, mark.rutland, shawnguo, s.hauer, kernel, festevam,
	a.zummo, alexandre.belloni, Aisheng Dong, ulf.hansson, sboyd,
	Peng Fan, Daniel Baluta, devicetree, linux-kernel,
	linux-arm-kernel, linux-rtc
  Cc: dl-linux-imx

Hi, Shawn
	Can you pick up this patch series if no additional comments? We need this feature to support many modules IRQ function including suspend/resume, thanks. 

Best Regards!
Anson Huang

> -----Original Message-----
> From: Anson Huang
> Sent: 2019年4月9日 13:00
> To: robh+dt@kernel.org; mark.rutland@arm.com; shawnguo@kernel.org;
> s.hauer@pengutronix.de; kernel@pengutronix.de; festevam@gmail.com;
> a.zummo@towertech.it; alexandre.belloni@bootlin.com; Aisheng Dong
> <aisheng.dong@nxp.com>; ulf.hansson@linaro.org; sboyd@kernel.org; Peng
> Fan <peng.fan@nxp.com>; Daniel Baluta <daniel.baluta@nxp.com>;
> devicetree@vger.kernel.org; linux-kernel@vger.kernel.org; linux-arm-
> kernel@lists.infradead.org; linux-rtc@vger.kernel.org
> Cc: dl-linux-imx <linux-imx@nxp.com>
> Subject: [PATCH V7 1/4] dt-bindings: fsl: scu: add general interrupt support
> 
> Add scu general interrupt function support.
> 
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> Reviewed-by: Rob Herring <robh@kernel.org>
> Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
> ---
> No changes.
> ---
>  .../devicetree/bindings/arm/freescale/fsl,scu.txt  | 29 +++++++++++++++++--
> ---
>  1 file changed, 23 insertions(+), 6 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt
> b/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt
> index 72d481c..5d7dbab 100644
> --- a/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt
> +++ b/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt
> @@ -22,9 +22,11 @@ Required properties:
>  -------------------
>  - compatible:	should be "fsl,imx-scu".
>  - mbox-names:	should include "tx0", "tx1", "tx2", "tx3",
> -			       "rx0", "rx1", "rx2", "rx3".
> -- mboxes:	List of phandle of 4 MU channels for tx and 4 MU channels
> -		for rx. All 8 MU channels must be in the same MU instance.
> +			       "rx0", "rx1", "rx2", "rx3";
> +		include "gip3" if want to support general MU interrupt.
> +- mboxes:	List of phandle of 4 MU channels for tx, 4 MU channels for
> +		rx, and 1 optional MU channel for general interrupt.
> +		All MU channels must be in the same MU instance.
>  		Cross instances are not allowed. The MU instance can only
>  		be one of LSIO MU0~M4 for imx8qxp and imx8qm. Users
> need
>  		to make sure use the one which is not conflict with other @@
> -34,6 +36,7 @@ Required properties:
>  		Channel 1 must be "tx1" or "rx1".
>  		Channel 2 must be "tx2" or "rx2".
>  		Channel 3 must be "tx3" or "rx3".
> +		General interrupt rx channel must be "gip3".
>  		e.g.
>  		mboxes = <&lsio_mu1 0 0
>  			  &lsio_mu1 0 1
> @@ -42,10 +45,18 @@ Required properties:
>  			  &lsio_mu1 1 0
>  			  &lsio_mu1 1 1
>  			  &lsio_mu1 1 2
> -			  &lsio_mu1 1 3>;
> +			  &lsio_mu1 1 3
> +			  &lsio_mu1 3 3>;
>  		See Documentation/devicetree/bindings/mailbox/fsl,mu.txt
>  		for detailed mailbox binding.
> 
> +Note: Each mu which supports general interrupt should have an alias
> +correctly numbered in "aliases" node.
> +e.g.
> +aliases {
> +	mu1 = &lsio_mu1;
> +};
> +
>  i.MX SCU Client Device Node:
>  ============================================================
> 
> @@ -124,6 +135,10 @@ Required properties:
> 
>  Example (imx8qxp):
>  -------------
> +aliases {
> +	mu1 = &lsio_mu1;
> +};
> +
>  lsio_mu1: mailbox@5d1c0000 {
>  	...
>  	#mbox-cells = <2>;
> @@ -133,7 +148,8 @@ firmware {
>  	scu {
>  		compatible = "fsl,imx-scu";
>  		mbox-names = "tx0", "tx1", "tx2", "tx3",
> -			     "rx0", "rx1", "rx2", "rx3";
> +			     "rx0", "rx1", "rx2", "rx3",
> +			     "gip3";
>  		mboxes = <&lsio_mu1 0 0
>  			  &lsio_mu1 0 1
>  			  &lsio_mu1 0 2
> @@ -141,7 +157,8 @@ firmware {
>  			  &lsio_mu1 1 0
>  			  &lsio_mu1 1 1
>  			  &lsio_mu1 1 2
> -			  &lsio_mu1 1 3>;
> +			  &lsio_mu1 1 3
> +			  &lsio_mu1 3 3>;
> 
>  		clk: clk {
>  			compatible = "fsl,imx8qxp-clk", "fsl,scu-clk";
> --
> 2.7.4


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

* Re: [PATCH V7 1/4] dt-bindings: fsl: scu: add general interrupt support
  2019-04-09  4:59 [PATCH V7 1/4] dt-bindings: fsl: scu: add general interrupt support Anson Huang
                   ` (3 preceding siblings ...)
  2019-04-11  1:37 ` [PATCH V7 1/4] dt-bindings: fsl: scu: add general interrupt support Anson Huang
@ 2019-04-11  7:32 ` Shawn Guo
  4 siblings, 0 replies; 15+ messages in thread
From: Shawn Guo @ 2019-04-11  7:32 UTC (permalink / raw)
  To: Anson Huang
  Cc: robh+dt, mark.rutland, s.hauer, kernel, festevam, a.zummo,
	alexandre.belloni, Aisheng Dong, ulf.hansson, sboyd, Peng Fan,
	Daniel Baluta, devicetree, linux-kernel, linux-arm-kernel,
	linux-rtc, dl-linux-imx

On Tue, Apr 09, 2019 at 04:59:49AM +0000, Anson Huang wrote:
> Add scu general interrupt function support.
> 
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> Reviewed-by: Rob Herring <robh@kernel.org>
> Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>

Applied, thanks.

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

* Re: [PATCH V7 2/4] firmware: imx: enable imx scu general irq function
  2019-04-09  4:59 ` [PATCH V7 2/4] firmware: imx: enable imx scu general irq function Anson Huang
@ 2019-04-11  7:32   ` Shawn Guo
  2019-04-12  1:05     ` [EXT] " Anson Huang
  0 siblings, 1 reply; 15+ messages in thread
From: Shawn Guo @ 2019-04-11  7:32 UTC (permalink / raw)
  To: Anson Huang
  Cc: robh+dt, mark.rutland, s.hauer, kernel, festevam, a.zummo,
	alexandre.belloni, Aisheng Dong, ulf.hansson, sboyd, Peng Fan,
	Daniel Baluta, devicetree, linux-kernel, linux-arm-kernel,
	linux-rtc, dl-linux-imx

On Tue, Apr 09, 2019 at 04:59:55AM +0000, Anson Huang wrote:
> The System Controller Firmware (SCFW) controls RTC, thermal
> and WDOG etc., these resources' interrupt function are managed
> by SCU. When any IRQ pending, SCU will notify Linux via MU general
> interrupt channel #3, and Linux kernel needs to call SCU APIs
> to get IRQ status and notify each module to handle the interrupt.
> 
> Since there is no data transmission for SCU IRQ notification, so
> doorbell mode is used for this MU channel, and SCU driver will
> use notifier mechanism to broadcast to every module which registers
> the SCU block notifier.
> 
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>

Applied, thanks.

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

* Re: [PATCH V7 3/4] arm64: dts: freescale: imx8qxp: enable scu general irq channel
  2019-04-09  5:00 ` [PATCH V7 3/4] arm64: dts: freescale: imx8qxp: enable scu general irq channel Anson Huang
@ 2019-04-11  7:34   ` Shawn Guo
  0 siblings, 0 replies; 15+ messages in thread
From: Shawn Guo @ 2019-04-11  7:34 UTC (permalink / raw)
  To: Anson Huang
  Cc: robh+dt, mark.rutland, s.hauer, kernel, festevam, a.zummo,
	alexandre.belloni, Aisheng Dong, ulf.hansson, sboyd, Peng Fan,
	Daniel Baluta, devicetree, linux-kernel, linux-arm-kernel,
	linux-rtc, dl-linux-imx

On Tue, Apr 09, 2019 at 05:00:01AM +0000, Anson Huang wrote:
> On i.MX8QXP, SCU uses MU1 general interrupt channel #3 to notify
> user for IRQs of RTC alarm, thermal alarm and WDOG etc., mailbox
> RX doorbell mode is used for this function, this patch adds
> support for it.
> 
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>

Prefix 'arm64: dts: imx8qxp:' would be good enough, and no need for
'freescale' in there.

I fixed it up and applied the patch.

Shawn

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

* RE: [EXT] Re: [PATCH V7 2/4] firmware: imx: enable imx scu general irq function
  2019-04-11  7:32   ` Shawn Guo
@ 2019-04-12  1:05     ` Anson Huang
  2019-04-12  2:25       ` Aisheng Dong
  0 siblings, 1 reply; 15+ messages in thread
From: Anson Huang @ 2019-04-12  1:05 UTC (permalink / raw)
  To: Shawn Guo, alexandre.belloni
  Cc: robh+dt, mark.rutland, s.hauer, kernel, festevam, a.zummo,
	alexandre.belloni, Aisheng Dong, ulf.hansson, sboyd, Peng Fan,
	Daniel Baluta, devicetree, linux-kernel, linux-arm-kernel,
	linux-rtc, dl-linux-imx

Hello, Alexandre
	As i.MX SCU general irq function is picked up by Shawn, could you please also pick up below i.MX SC RTC alarm support patch ?
	https://patchwork.kernel.org/patch/10890525/ 

Best Regards!
Anson Huang

> -----Original Message-----
> From: Shawn Guo [mailto:shawnguo@kernel.org]
> Sent: 2019年4月11日 15:33
> To: Anson Huang <anson.huang@nxp.com>
> Cc: robh+dt@kernel.org; mark.rutland@arm.com; s.hauer@pengutronix.de;
> kernel@pengutronix.de; festevam@gmail.com; a.zummo@towertech.it;
> alexandre.belloni@bootlin.com; Aisheng Dong <aisheng.dong@nxp.com>;
> ulf.hansson@linaro.org; sboyd@kernel.org; Peng Fan <peng.fan@nxp.com>;
> Daniel Baluta <daniel.baluta@nxp.com>; devicetree@vger.kernel.org; linux-
> kernel@vger.kernel.org; linux-arm-kernel@lists.infradead.org; linux-
> rtc@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>
> Subject: [EXT] Re: [PATCH V7 2/4] firmware: imx: enable imx scu general irq
> function
> 
> WARNING: This email was created outside of NXP. DO NOT CLICK links or
> attachments unless you recognize the sender and know the content is safe.
> 
> 
> 
> On Tue, Apr 09, 2019 at 04:59:55AM +0000, Anson Huang wrote:
> > The System Controller Firmware (SCFW) controls RTC, thermal and WDOG
> > etc., these resources' interrupt function are managed by SCU. When any
> > IRQ pending, SCU will notify Linux via MU general interrupt channel
> > #3, and Linux kernel needs to call SCU APIs to get IRQ status and
> > notify each module to handle the interrupt.
> >
> > Since there is no data transmission for SCU IRQ notification, so
> > doorbell mode is used for this MU channel, and SCU driver will use
> > notifier mechanism to broadcast to every module which registers the
> > SCU block notifier.
> >
> > Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> > Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
> 
> Applied, thanks.

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

* RE: [EXT] Re: [PATCH V7 2/4] firmware: imx: enable imx scu general irq function
  2019-04-12  1:05     ` [EXT] " Anson Huang
@ 2019-04-12  2:25       ` Aisheng Dong
  2019-04-12  2:32         ` Anson Huang
  0 siblings, 1 reply; 15+ messages in thread
From: Aisheng Dong @ 2019-04-12  2:25 UTC (permalink / raw)
  To: Anson Huang, Shawn Guo, alexandre.belloni
  Cc: robh+dt, mark.rutland, s.hauer, kernel, festevam, a.zummo,
	alexandre.belloni, ulf.hansson, sboyd, Peng Fan, Daniel Baluta,
	devicetree, linux-kernel, linux-arm-kernel, linux-rtc,
	dl-linux-imx

> From: Anson Huang
> Sent: Friday, April 12, 2019 9:06 AM
> 
> Hello, Alexandre
> 	As i.MX SCU general irq function is picked up by Shawn, could you please
> also pick up below i.MX SC RTC alarm support patch ?
> 	https://patchwork.kernel.org/patch/10890525/
> 

No, it can't go through Alexandre's tree due to dependency issue.

Shawn,
Do you think you can pick it up? Alexandre already gave the Ack.

AFAIK there's no other SCU RTC patches since v5.1-rc1 in Alexandre's tree.

Regards
Dong Aisheng

> > On Tue, Apr 09, 2019 at 04:59:55AM +0000, Anson Huang wrote:
> > > The System Controller Firmware (SCFW) controls RTC, thermal and WDOG
> > > etc., these resources' interrupt function are managed by SCU. When
> > > any IRQ pending, SCU will notify Linux via MU general interrupt
> > > channel #3, and Linux kernel needs to call SCU APIs to get IRQ
> > > status and notify each module to handle the interrupt.
> > >
> > > Since there is no data transmission for SCU IRQ notification, so
> > > doorbell mode is used for this MU channel, and SCU driver will use
> > > notifier mechanism to broadcast to every module which registers the
> > > SCU block notifier.
> > >
> > > Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> > > Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
> >
> > Applied, thanks.

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

* RE: [EXT] Re: [PATCH V7 2/4] firmware: imx: enable imx scu general irq function
  2019-04-12  2:25       ` Aisheng Dong
@ 2019-04-12  2:32         ` Anson Huang
  2019-04-12  8:41           ` Alexandre Belloni
  0 siblings, 1 reply; 15+ messages in thread
From: Anson Huang @ 2019-04-12  2:32 UTC (permalink / raw)
  To: Aisheng Dong, Shawn Guo, alexandre.belloni
  Cc: robh+dt, mark.rutland, s.hauer, kernel, festevam, a.zummo,
	alexandre.belloni, ulf.hansson, sboyd, Peng Fan, Daniel Baluta,
	devicetree, linux-kernel, linux-arm-kernel, linux-rtc,
	dl-linux-imx



Best Regards!
Anson Huang

> -----Original Message-----
> From: Aisheng Dong
> Sent: 2019年4月12日 10:26
> To: Anson Huang <anson.huang@nxp.com>; Shawn Guo
> <shawnguo@kernel.org>; alexandre.belloni@bootlin.com
> Cc: robh+dt@kernel.org; mark.rutland@arm.com; s.hauer@pengutronix.de;
> kernel@pengutronix.de; festevam@gmail.com; a.zummo@towertech.it;
> alexandre.belloni@bootlin.com; ulf.hansson@linaro.org; sboyd@kernel.org;
> Peng Fan <peng.fan@nxp.com>; Daniel Baluta <daniel.baluta@nxp.com>;
> devicetree@vger.kernel.org; linux-kernel@vger.kernel.org; linux-arm-
> kernel@lists.infradead.org; linux-rtc@vger.kernel.org; dl-linux-imx <linux-
> imx@nxp.com>
> Subject: RE: [EXT] Re: [PATCH V7 2/4] firmware: imx: enable imx scu general
> irq function
> 
> > From: Anson Huang
> > Sent: Friday, April 12, 2019 9:06 AM
> >
> > Hello, Alexandre
> > 	As i.MX SCU general irq function is picked up by Shawn, could you
> > please also pick up below i.MX SC RTC alarm support patch ?
> > 	https://patchwork.kernel.org/patch/10890525/
> >
> 
> No, it can't go through Alexandre's tree due to dependency issue.
> 
> Shawn,
> Do you think you can pick it up? Alexandre already gave the Ack.
> 
> AFAIK there's no other SCU RTC patches since v5.1-rc1 in Alexandre's tree.

Yes, need to make sure the dependency is handled, the RTC alarm patch MUST be picked up
ONLY when scu irq patch is ready, NOT sure how to handle this case for such scenario?

Anson.

> 
> Regards
> Dong Aisheng
> 
> > > On Tue, Apr 09, 2019 at 04:59:55AM +0000, Anson Huang wrote:
> > > > The System Controller Firmware (SCFW) controls RTC, thermal and
> > > > WDOG etc., these resources' interrupt function are managed by SCU.
> > > > When any IRQ pending, SCU will notify Linux via MU general
> > > > interrupt channel #3, and Linux kernel needs to call SCU APIs to
> > > > get IRQ status and notify each module to handle the interrupt.
> > > >
> > > > Since there is no data transmission for SCU IRQ notification, so
> > > > doorbell mode is used for this MU channel, and SCU driver will use
> > > > notifier mechanism to broadcast to every module which registers
> > > > the SCU block notifier.
> > > >
> > > > Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> > > > Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
> > >
> > > Applied, thanks.

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

* Re: [EXT] Re: [PATCH V7 2/4] firmware: imx: enable imx scu general irq function
  2019-04-12  2:32         ` Anson Huang
@ 2019-04-12  8:41           ` Alexandre Belloni
  2019-04-15  9:23             ` Shawn Guo
  0 siblings, 1 reply; 15+ messages in thread
From: Alexandre Belloni @ 2019-04-12  8:41 UTC (permalink / raw)
  To: Anson Huang
  Cc: Aisheng Dong, Shawn Guo, robh+dt, mark.rutland, s.hauer, kernel,
	festevam, a.zummo, ulf.hansson, sboyd, Peng Fan, Daniel Baluta,
	devicetree, linux-kernel, linux-arm-kernel, linux-rtc,
	dl-linux-imx

On 12/04/2019 02:32:54+0000, Anson Huang wrote:
> > > 	As i.MX SCU general irq function is picked up by Shawn, could you
> > > please also pick up below i.MX SC RTC alarm support patch ?
> > > 	https://patchwork.kernel.org/patch/10890525/
> > >
> > 
> > No, it can't go through Alexandre's tree due to dependency issue.
> > 
> > Shawn,
> > Do you think you can pick it up? Alexandre already gave the Ack.
> > 
> > AFAIK there's no other SCU RTC patches since v5.1-rc1 in Alexandre's tree.
> 
> Yes, need to make sure the dependency is handled, the RTC alarm patch MUST be picked up
> ONLY when scu irq patch is ready, NOT sure how to handle this case for such scenario?
> 

Either it goes through arm-soc or if it can wait one release, I pick it
up for 5.3. The other solution involves immutable branch but I don't
think this is necessary.


-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

* Re: [PATCH V7 4/4] rtc: imx-sc: add rtc alarm support
  2019-04-09  5:00 ` [PATCH V7 4/4] rtc: imx-sc: add rtc alarm support Anson Huang
@ 2019-04-12  8:41   ` Alexandre Belloni
  2019-06-01 21:18   ` Alexandre Belloni
  1 sibling, 0 replies; 15+ messages in thread
From: Alexandre Belloni @ 2019-04-12  8:41 UTC (permalink / raw)
  To: Anson Huang
  Cc: robh+dt, mark.rutland, shawnguo, s.hauer, kernel, festevam,
	a.zummo, Aisheng Dong, ulf.hansson, sboyd, Peng Fan,
	Daniel Baluta, devicetree, linux-kernel, linux-arm-kernel,
	linux-rtc, dl-linux-imx

On 09/04/2019 05:00:07+0000, Anson Huang wrote:
> Add i.MX system controller RTC alarm support, the RTC alarm
> is implemented via SIP(silicon provider) runtime service call
> and ARM-Trusted-Firmware will communicate with system controller
> via MU(message unit) IPC to set RTC alarm. When RTC alarm fires,
> system controller will generate a common MU irq event and notify
> system controller RTC driver to handle the irq event.
> 
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

> ---
> Changes since V6:
> 	- add comments to .read_alarm callback function to explain why it is an empty function;
> 	- improve irq notify callback function name.
> --
>  drivers/rtc/rtc-imx-sc.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 87 insertions(+)
> 
> diff --git a/drivers/rtc/rtc-imx-sc.c b/drivers/rtc/rtc-imx-sc.c
> index 19642bf..c933045 100644
> --- a/drivers/rtc/rtc-imx-sc.c
> +++ b/drivers/rtc/rtc-imx-sc.c
> @@ -3,6 +3,7 @@
>   * Copyright 2018 NXP.
>   */
>  
> +#include <dt-bindings/firmware/imx/rsrc.h>
>  #include <linux/arm-smccc.h>
>  #include <linux/firmware/imx/sci.h>
>  #include <linux/module.h>
> @@ -11,11 +12,15 @@
>  #include <linux/rtc.h>
>  
>  #define IMX_SC_TIMER_FUNC_GET_RTC_SEC1970	9
> +#define IMX_SC_TIMER_FUNC_SET_RTC_ALARM		8
>  #define IMX_SC_TIMER_FUNC_SET_RTC_TIME		6
>  
>  #define IMX_SIP_SRTC			0xC2000002
>  #define IMX_SIP_SRTC_SET_TIME		0x0
>  
> +#define SC_IRQ_GROUP_RTC    2
> +#define SC_IRQ_RTC          1
> +
>  static struct imx_sc_ipc *rtc_ipc_handle;
>  static struct rtc_device *imx_sc_rtc;
>  
> @@ -24,6 +29,16 @@ struct imx_sc_msg_timer_get_rtc_time {
>  	u32 time;
>  } __packed;
>  
> +struct imx_sc_msg_timer_rtc_set_alarm {
> +	struct imx_sc_rpc_msg hdr;
> +	u16 year;
> +	u8 mon;
> +	u8 day;
> +	u8 hour;
> +	u8 min;
> +	u8 sec;
> +} __packed;
> +
>  static int imx_sc_rtc_read_time(struct device *dev, struct rtc_time *tm)
>  {
>  	struct imx_sc_msg_timer_get_rtc_time msg;
> @@ -60,9 +75,77 @@ static int imx_sc_rtc_set_time(struct device *dev, struct rtc_time *tm)
>  	return res.a0;
>  }
>  
> +static int imx_sc_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
> +{
> +	return imx_scu_irq_group_enable(SC_IRQ_GROUP_RTC, SC_IRQ_RTC, enable);
> +}
> +
> +static int imx_sc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
> +{
> +	/*
> +	 * SCU firmware does NOT provide read alarm API, but .read_alarm
> +	 * callback is required by RTC framework to support alarm function,
> +	 * so just return here.
> +	 */
> +	return 0;
> +}
> +
> +static int imx_sc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
> +{
> +	struct imx_sc_msg_timer_rtc_set_alarm msg;
> +	struct imx_sc_rpc_msg *hdr = &msg.hdr;
> +	int ret;
> +	struct rtc_time *alrm_tm = &alrm->time;
> +
> +	hdr->ver = IMX_SC_RPC_VERSION;
> +	hdr->svc = IMX_SC_RPC_SVC_TIMER;
> +	hdr->func = IMX_SC_TIMER_FUNC_SET_RTC_ALARM;
> +	hdr->size = 3;
> +
> +	msg.year = alrm_tm->tm_year + 1900;
> +	msg.mon = alrm_tm->tm_mon + 1;
> +	msg.day = alrm_tm->tm_mday;
> +	msg.hour = alrm_tm->tm_hour;
> +	msg.min = alrm_tm->tm_min;
> +	msg.sec = alrm_tm->tm_sec;
> +
> +	ret = imx_scu_call_rpc(rtc_ipc_handle, &msg, true);
> +	if (ret) {
> +		dev_err(dev, "set rtc alarm failed, ret %d\n", ret);
> +		return ret;
> +	}
> +
> +	ret = imx_sc_rtc_alarm_irq_enable(dev, alrm->enabled);
> +	if (ret) {
> +		dev_err(dev, "enable rtc alarm failed, ret %d\n", ret);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
>  static const struct rtc_class_ops imx_sc_rtc_ops = {
>  	.read_time = imx_sc_rtc_read_time,
>  	.set_time = imx_sc_rtc_set_time,
> +	.read_alarm = imx_sc_rtc_read_alarm,
> +	.set_alarm = imx_sc_rtc_set_alarm,
> +	.alarm_irq_enable = imx_sc_rtc_alarm_irq_enable,
> +};
> +
> +static int imx_sc_rtc_alarm_notify(struct notifier_block *nb,
> +					unsigned long event, void *group)
> +{
> +	/* ignore non-rtc irq */
> +	if (!((event & SC_IRQ_RTC) && (*(u8 *)group == SC_IRQ_GROUP_RTC)))
> +		return 0;
> +
> +	rtc_update_irq(imx_sc_rtc, 1, RTC_IRQF | RTC_AF);
> +
> +	return 0;
> +}
> +
> +static struct notifier_block imx_sc_rtc_alarm_sc_notifier = {
> +	.notifier_call = imx_sc_rtc_alarm_notify,
>  };
>  
>  static int imx_sc_rtc_probe(struct platform_device *pdev)
> @@ -73,6 +156,8 @@ static int imx_sc_rtc_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> +	device_init_wakeup(&pdev->dev, true);
> +
>  	imx_sc_rtc = devm_rtc_allocate_device(&pdev->dev);
>  	if (IS_ERR(imx_sc_rtc))
>  		return PTR_ERR(imx_sc_rtc);
> @@ -87,6 +172,8 @@ static int imx_sc_rtc_probe(struct platform_device *pdev)
>  		return ret;
>  	}
>  
> +	imx_scu_irq_register_notifier(&imx_sc_rtc_alarm_sc_notifier);
> +
>  	return 0;
>  }
>  
> -- 
> 2.7.4
> 

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

* Re: [EXT] Re: [PATCH V7 2/4] firmware: imx: enable imx scu general irq function
  2019-04-12  8:41           ` Alexandre Belloni
@ 2019-04-15  9:23             ` Shawn Guo
  0 siblings, 0 replies; 15+ messages in thread
From: Shawn Guo @ 2019-04-15  9:23 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Anson Huang, Aisheng Dong, robh+dt, mark.rutland, s.hauer,
	kernel, festevam, a.zummo, ulf.hansson, sboyd, Peng Fan,
	Daniel Baluta, devicetree, linux-kernel, linux-arm-kernel,
	linux-rtc, dl-linux-imx

On Fri, Apr 12, 2019 at 10:41:16AM +0200, Alexandre Belloni wrote:
> On 12/04/2019 02:32:54+0000, Anson Huang wrote:
> > > > 	As i.MX SCU general irq function is picked up by Shawn, could you
> > > > please also pick up below i.MX SC RTC alarm support patch ?
> > > > 	https://patchwork.kernel.org/patch/10890525/
> > > >
> > > 
> > > No, it can't go through Alexandre's tree due to dependency issue.
> > > 
> > > Shawn,
> > > Do you think you can pick it up? Alexandre already gave the Ack.
> > > 
> > > AFAIK there's no other SCU RTC patches since v5.1-rc1 in Alexandre's tree.
> > 
> > Yes, need to make sure the dependency is handled, the RTC alarm patch MUST be picked up
> > ONLY when scu irq patch is ready, NOT sure how to handle this case for such scenario?
> > 
> 
> Either it goes through arm-soc or if it can wait one release, I pick it
> up for 5.3. The other solution involves immutable branch but I don't
> think this is necessary.

I send other subsystem patch through arm-soc tree only when it's
absolutely necessary. This is not anything either critical or urgent,
so I'm not going to take it.  Wait one release, I'd say.

Shawn

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

* Re: [PATCH V7 4/4] rtc: imx-sc: add rtc alarm support
  2019-04-09  5:00 ` [PATCH V7 4/4] rtc: imx-sc: add rtc alarm support Anson Huang
  2019-04-12  8:41   ` Alexandre Belloni
@ 2019-06-01 21:18   ` Alexandre Belloni
  1 sibling, 0 replies; 15+ messages in thread
From: Alexandre Belloni @ 2019-06-01 21:18 UTC (permalink / raw)
  To: Anson Huang
  Cc: robh+dt, mark.rutland, shawnguo, s.hauer, kernel, festevam,
	a.zummo, Aisheng Dong, ulf.hansson, sboyd, Peng Fan,
	Daniel Baluta, devicetree, linux-kernel, linux-arm-kernel,
	linux-rtc, dl-linux-imx

On 09/04/2019 05:00:07+0000, Anson Huang wrote:
> Add i.MX system controller RTC alarm support, the RTC alarm
> is implemented via SIP(silicon provider) runtime service call
> and ARM-Trusted-Firmware will communicate with system controller
> via MU(message unit) IPC to set RTC alarm. When RTC alarm fires,
> system controller will generate a common MU irq event and notify
> system controller RTC driver to handle the irq event.
> 
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
> ---
> Changes since V6:
> 	- add comments to .read_alarm callback function to explain why it is an empty function;
> 	- improve irq notify callback function name.
> --
>  drivers/rtc/rtc-imx-sc.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 87 insertions(+)
> 
Applied, thanks.

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

end of thread, other threads:[~2019-06-01 21:18 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-09  4:59 [PATCH V7 1/4] dt-bindings: fsl: scu: add general interrupt support Anson Huang
2019-04-09  4:59 ` [PATCH V7 2/4] firmware: imx: enable imx scu general irq function Anson Huang
2019-04-11  7:32   ` Shawn Guo
2019-04-12  1:05     ` [EXT] " Anson Huang
2019-04-12  2:25       ` Aisheng Dong
2019-04-12  2:32         ` Anson Huang
2019-04-12  8:41           ` Alexandre Belloni
2019-04-15  9:23             ` Shawn Guo
2019-04-09  5:00 ` [PATCH V7 3/4] arm64: dts: freescale: imx8qxp: enable scu general irq channel Anson Huang
2019-04-11  7:34   ` Shawn Guo
2019-04-09  5:00 ` [PATCH V7 4/4] rtc: imx-sc: add rtc alarm support Anson Huang
2019-04-12  8:41   ` Alexandre Belloni
2019-06-01 21:18   ` Alexandre Belloni
2019-04-11  1:37 ` [PATCH V7 1/4] dt-bindings: fsl: scu: add general interrupt support Anson Huang
2019-04-11  7:32 ` Shawn Guo

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).