Add i.MX SCU general interrupt support
Subsystems (3)
v2 cover Add i.MX SCU general interrupt support
This patch series adds i.MX SCU general interrupt support, the SCU general interrupt supports RTC alarm, wdog, thermal alarm etc., e.g. RTC alarm irq is controlled by system controller and when RTC alarm fires, system controller will general SCU MU general interrupt rather than RTC IRQ, so need to use notification for RTC driver to handle the alarm event.
RTC alarm function patch depends on i.MX SCU general interrupt support, so put it into same series for review.
Anson Huang (4):
dt-bindings: fsl: scu: add general interrupt support
firmware: imx: enable imx scu general irq function
arm64: dts: freescale: imx8qxp: enable scu general irq channel
rtc: imx-sc: add rtc alarm support
.../devicetree/bindings/arm/freescale/fsl,scu.txt | 18 ++-- arch/arm64/boot/dts/freescale/imx8qxp.dtsi | 6 +- drivers/firmware/imx/imx-scu.c | 101 +++++++++++++++++++++ drivers/rtc/rtc-imx-sc.c | 100 ++++++++++++++++++++ include/linux/firmware/imx/sci.h | 3 + 5 files changed, 220 insertions(+), 8 deletions(-)
Signature · 1 line
2.7.4
PATCH v2 1/4 dt-bindings: fsl: scu: add general interrupt support
Add scu general interrupt function support.
---
Changes since V1:
no change, just update the patch based on latest next branch.
--- .../devicetree/bindings/arm/freescale/fsl,scu.txt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt +12 -6
@@ -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", + "gi3". +- mboxes: List of phandle of 4 MU channels for tx, 4 MU channels for + rx, and 1 MU channel for general interrupt. All 9 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 channel must be "gi3". e.g. mboxes = <&lsio_mu1 0 0 &lsio_mu1 0 1
@@ -42,7 +45,8 @@ 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.
@@ -133,7 +137,8 @@ firmware { scu { compatible = "fsl,imx-scu"; mbox-names = "tx0", "tx1", "tx2", "tx3", - "rx0", "rx1", "rx2", "rx3"; + "rx0", "rx1", "rx2", "rx3", + "gi3"; mboxes = <&lsio_mu1 0 0 &lsio_mu1 0 1 &lsio_mu1 0 2
@@ -141,7 +146,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";
Signature · 1 line
2.7.4
PATCH v2 2/4 firmware: imx: enable imx scu general irq function
In reply to Anson HuangThe 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.
---
No change since V1.
--- drivers/firmware/imx/imx-scu.c | 101 +++++++++++++++++++++++++++++++++++++++ include/linux/firmware/imx/sci.h | 3 ++ 2 files changed, 104 insertions(+)
drivers/firmware/imx/imx-scu.c +101 -0
@@ -7,6 +7,7 @@* */ +#include <dt-bindings/firmware/imx/rsrc.h> #include <linux/err.h> #include <linux/firmware/imx/types.h> #include <linux/firmware/imx/ipc.h>
@@ -21,6 +22,8 @@#define SCU_MU_CHAN_NUM 8#define MAX_RX_TIMEOUT (msecs_to_jiffies(30)) +#define IMX_SC_IRQ_FUNC_STATUS 2 +#define IMX_SC_IRQ_NUM_GROUP 6struct imx_sc_chan {struct imx_sc_ipc *sc_ipc;
@@ -77,7 +80,23 @@ static int imx_sc_linux_errmap[IMX_SC_ERR_LAST] = { -EIO, /* IMX_SC_ERR_FAIL */ }; +struct imx_sc_msg_irq_get_status { +struct imx_sc_rpc_msg hdr; +union { +struct { +u16 resource; +u8 group; +u8 reserved; + } send; +struct { +u32 status; + } receive; + } data; +} __packed; +static struct imx_sc_ipc *imx_sc_ipc_handle; +static struct work_struct imx_sc_general_irq_work; +static BLOCKING_NOTIFIER_HEAD (imx_scu_notifier_chain);static inline int imx_sc_to_linux_errno (int errno) {
@@ -194,6 +213,86 @@ int imx_scu_call_rpc(struct imx_sc_ipc *sc_ipc, void *msg, bool have_resp) }EXPORT_SYMBOL (imx_scu_call_rpc); +int imx_scu_register_notifier (struct notifier_block *nb) +{ +return blocking_notifier_chain_register (&imx_scu_notifier_chain, nb); +} +EXPORT_SYMBOL (imx_scu_register_notifier); + +int imx_scu_unregister_notifier (struct notifier_block *nb) +{ +return blocking_notifier_chain_unregister (&imx_scu_notifier_chain, nb); +} +EXPORT_SYMBOL (imx_scu_unregister_notifier); + +static int imx_scu_notifier_call_chain (unsigned long status,u8 *group) +{ +return blocking_notifier_call_chain (&imx_scu_notifier_chain, + status, (void *)group); +} + +static void imx_scu_general_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.send.resource =IMX_SC_R_MU_1A ; + msg.data.send.group = i; + + ret =imx_scu_call_rpc (imx_sc_ipc_handle, &msg, true); +if (ret) { +pr_err ("get irq status failed, ret %d\n" , ret); +return ; + } + + irq_status = msg.data.receive.status; +if (!irq_status) +continue ; + +imx_scu_notifier_call_chain (irq_status, &i); + } +} + +static void imx_scu_rxdb_callback (struct mbox_client *c,void *msg) +{ +schedule_work (&imx_sc_general_irq_work); +} + +static int imx_scu_enable_general_irq_channel (struct device *dev) +{ +struct mbox_client *cl; +struct mbox_chan *ch; +int ret =0 ; + + cl =devm_kzalloc (dev,sizeof (*cl),GFP_KERNEL ); +if (!cl) +return -ENOMEM ; + + cl->dev = dev; + cl->rx_callback = imx_scu_rxdb_callback; + +/* SCU general IRQ uses general interrupt channel 3 */ + ch =mbox_request_channel_byname (cl,"gi3" ); +if (IS_ERR (ch)) { + ret =PTR_ERR (ch); +dev_err (dev,"failed to request mbox chan gi3, ret %d\n" , ret); +return ret; + } + +INIT_WORK (&imx_sc_general_irq_work, imx_scu_general_irq_work_handler); + +return ret; +} +static int imx_scu_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -246,6 +345,8 @@ static int imx_scu_probe(struct platform_device *pdev) imx_sc_ipc_handle = sc_ipc; +imx_scu_enable_general_irq_channel (dev); +dev_info (dev,"NXP i.MX SCU Initialized\n" );return devm_of_platform_populate (dev);
include/linux/firmware/imx/sci.h +3 -0
@@ -15,4 +15,7 @@#include <linux/firmware/imx/svc/misc.h> #include <linux/firmware/imx/svc/pm.h> + +int imx_scu_register_notifier (struct notifier_block *nb); +int imx_scu_unregister_notifier (struct notifier_block *nb);#endif /* _SC_SCI_H */
Signature · 1 line
2.7.4
PATCH v2 3/4 arm64: dts: freescale: imx8qxp: enable scu general irq channel
In reply to Anson HuangOn 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.
---
No change since V1.
--- arch/arm64/boot/dts/freescale/imx8qxp.dtsi | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/freescale/imx8qxp.dtsi +4 -2
@@ -112,7 +112,8 @@ scu { compatible = "fsl,imx-scu"; mbox-names = "tx0", "tx1", "tx2", "tx3", - "rx0", "rx1", "rx2", "rx3"; + "rx0", "rx1", "rx2", "rx3", + "gi3"; mboxes = <&lsio_mu1 0 0 &lsio_mu1 0 1 &lsio_mu1 0 2
@@ -120,7 +121,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";
Signature · 1 line
2.7.4
PATCH v2 4/4 rtc: imx-sc: add rtc alarm support
In reply to Anson HuangAdd 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.
---
No V1 patch, just add it into the i.MX SC general irq support patch series, to support system controller RTC's alarm function and also to provide an example of how to use general MU irq, this patch depends on the i.MX SC general irq support patch set, so add it into same patch series. --
drivers/rtc/rtc-imx-sc.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+)
drivers/rtc/rtc-imx-sc.c +100 -0
@@ -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,17 @@#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_SC_IRQ_FUNC_ENABLE 1 +#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 +31,24 @@ struct imx_sc_msg_timer_get_rtc_time {u32 time; } __packed; +struct imx_sc_msg_timer_enable_irq { +struct imx_sc_rpc_msg hdr; +u32 mask; +u16 resource; +u8 group; +u8 enable; +} __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 +85,80 @@ 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) +{ +struct imx_sc_msg_timer_enable_irq 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 =IMX_SC_R_MU_1A ; + msg.group =SC_IRQ_GROUP_RTC ; + msg.mask =SC_IRQ_RTC ; + msg.enable = enable; + + ret =imx_scu_call_rpc (rtc_ipc_handle, &msg, true); +if (ret) { +dev_err (dev,"enable rtc irq failed, ret %d\n" , ret); +return ret; + } + +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; + } + +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, + .set_alarm = imx_sc_rtc_set_alarm, + .alarm_irq_enable = imx_sc_rtc_alarm_irq_enable, +}; + +static int imx_sc_rtc_alarm_sc_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_sc_notify, };static int imx_sc_rtc_probe (struct platform_device *pdev)
@@ -73,6 +169,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 +185,8 @@ static int imx_sc_rtc_probe(struct platform_device *pdev)return ret; } +imx_scu_register_notifier (&imx_sc_rtc_alarm_sc_notifier); +return 0 ; }
Signature · 1 line
2.7.4
Re: [PATCH V2 1/4] dt-bindings: fsl: scu: add general interrupt support
In reply to Anson HuangQuoted 10 lines · Anson Huang
Add scu general interrupt function support.
Signed-off-by Anson Huang <[email protected]>---
Changes since V1:
no change, just update the patch based on latest next branch.--- .../devicetree/bindings/arm/freescale/fsl,scu.txt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
Alexandre Belloni
maintainerRe: [PATCH V2 4/4] rtc: imx-sc: add rtc alarm support
In reply to Anson HuangHi,
Quoted 7 lines · Anson Huang
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.
Quoted 6 lines
Signed-off-by Anson Huang <[email protected]>---
No V1 patch, just add it into the i.MX SC general irq support patch series, to support system controller RTC's alarm function and also to provide an example of how to use general MU irq, this patch depends on the i.MX SC general irq support patch set, so add it into same patch series.
Through which tree do you expect this patch to be merged?
Quoted 103 lines
--
drivers/rtc/rtc-imx-sc.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+)drivers/rtc/rtc-imx-sc.c +65
-0@@ -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,17 @@#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_SC_IRQ_FUNC_ENABLE 1 +#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 +31,24 @@ struct imx_sc_msg_timer_get_rtc_time {u32 time; } __packed; +struct imx_sc_msg_timer_enable_irq { +struct imx_sc_rpc_msg hdr; +u32 mask; +u16 resource; +u8 group; +u8 enable; +} __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 +85,80 @@ 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) +{ +struct imx_sc_msg_timer_enable_irq 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 =IMX_SC_R_MU_1A ; + msg.group =SC_IRQ_GROUP_RTC ; + msg.mask =SC_IRQ_RTC ; + msg.enable = enable; + + ret =imx_scu_call_rpc (rtc_ipc_handle, &msg, true); +if (ret) { +dev_err (dev,"enable rtc irq failed, ret %d\n" , ret); +return ret; + } + +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;
drivers/rtc/rtc-imx-sc.c static int imx_sc_rtc_set_time(struct device *dev, struct rtc_time *tm) · line 137
Quoted 10 lines
drivers/rtc/rtc-imx-sc.c +10
-0+ 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; + } +
You must check whether the alarm needs to be enabled here and enable the alarm else the userspace application that are using RTC_WKALM_SET will not work properly.
Quoted 48 lines
drivers/rtc/rtc-imx-sc.c +25
-0+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, + .set_alarm = imx_sc_rtc_set_alarm, + .alarm_irq_enable = imx_sc_rtc_alarm_irq_enable, +}; + +static int imx_sc_rtc_alarm_sc_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_sc_notify, };static int imx_sc_rtc_probe (struct platform_device *pdev)@@ -73,6 +169,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 +185,8 @@ static int imx_sc_rtc_probe(struct platform_device *pdev)return ret; } +imx_scu_register_notifier (&imx_sc_rtc_alarm_sc_notifier); +return 0 ; }Signature · 1 line
2.7.4
Signature · 3 lines
Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
RE: [PATCH V2 4/4] rtc: imx-sc: add rtc alarm support
Hi, Alexandre
Best Regards!
Anson Huang
Quoted 23 lines
-----Original Message-----
From: Alexandre Belloni [mailto:[email protected]]
Sent: 2019年2月19日 5:58
To: Anson Huang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Aisheng Dong <[email protected]>; [email protected]; [email protected]; Daniel Baluta <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux- [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH V2 4/4] rtc: imx-sc: add rtc alarm supportHi,
Quoted 7 lines · Anson Huang
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.
Quoted 8 lines
Quoted 6 lines
Signed-off-by Anson Huang <[email protected]>---
No V1 patch, just add it into the i.MX SC general irq support patch series, to support system controller RTC's alarm function and also to provide an example of how to use general MU irq, this patch depends on the i.MX SC general irq support patch set, so add it into same patch series.Through which tree do you expect this patch to be merged?
Since this patch depends on the general MU irq support, to avoid build break, I think may be after the general MU irq support patches are merged, then I will notify you to pick up this patch to your tree?
Quoted 112 lines
Quoted 51 lines
--
drivers/rtc/rtc-imx-sc.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+)drivers/rtc/rtc-imx-sc.c index renamed from drivers/rtc/rtc-imx-sc.c +0
-060570a2..147545e 100644
drivers/rtc/rtc-imx-sc.c +18
-0@@ -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,17 @@#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_SC_IRQ_FUNC_ENABLE 1 +#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 +31,24 @@ struct imx_sc_msg_timer_get_rtc_time {u32 time; } __packed; +struct imx_sc_msg_timer_enable_irq { +struct imx_sc_rpc_msg hdr; +u32 mask; +u16 resource; +u8 group; +u8 enable; +} __packed; + +struct imx_sc_msg_timer_rtc_set_alarm { +struct imx_sc_rpc_msg hdr; +u16 year;drivers/rtc/rtc-imx-sc.c struct imx_sc_msg_timer_get_rtc_time { · line 54
Quoted 10 lines
drivers/rtc/rtc-imx-sc.c +7
-0+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 +85,80 @@static
Quoted 50 lines
int
imx_sc_rtc_set_time(struct device *dev, struct rtc_time *tm)drivers/rtc/rtc-imx-sc.c +46
-0return res.a0; } +static int imx_sc_rtc_alarm_irq_enable (struct device *dev,unsigned +int enable) { +struct imx_sc_msg_timer_enable_irq 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 =IMX_SC_R_MU_1A ; + msg.group =SC_IRQ_GROUP_RTC ; + msg.mask =SC_IRQ_RTC ; + msg.enable = enable; + + ret =imx_scu_call_rpc (rtc_ipc_handle, &msg, true); +if (ret) { +dev_err (dev,"enable rtc irq failed, ret %d\n" , ret); +return ret; + } + +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) {
Quoted 8 lines
drivers/rtc/rtc-imx-sc.c static int imx_sc_rtc_set_time(struct device *dev, struct rtc_time *tm) · line 137
Quoted 4 lines
drivers/rtc/rtc-imx-sc.c +4
-0+dev_err (dev,"set rtc alarm failed, ret %d\n" , ret); +return ret; + } +You must check whether the alarm needs to be enabled here and enable the alarm else the userspace application that are using
RTC_WKALM_SETwill not work properly.
Oops, missed the alarm irq enable, and also need to add read_alarm callback to make RTC alarm work properly, made mistake in V2, now fix it in V3, please review.
Thanks,
Anson.
Quoted 46 lines
Quoted 4 lines
drivers/rtc/rtc-imx-sc.c +3
-0+return 0 ; +} +drivers/rtc/rtc-imx-sc.c static int imx_sc_rtc_set_time(struct device *dev, struct rtc_time *tm)
Quoted 10 lines
drivers/rtc/rtc-imx-sc.c +7
-0static const struct rtc_class_ops imx_sc_rtc_ops = { .read_time = imx_sc_rtc_read_time, .set_time = imx_sc_rtc_set_time, + .set_alarm = imx_sc_rtc_set_alarm, + .alarm_irq_enable = imx_sc_rtc_alarm_irq_enable, }; + +static int imx_sc_rtc_alarm_sc_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)))drivers/rtc/rtc-imx-sc.c static int imx_sc_rtc_probe(struct platform_device
Quoted 22 lines
drivers/rtc/rtc-imx-sc.c +12
-0+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_sc_notify, }; static int imx_sc_rtc_probe(struct platform_device *pdev) @@ -73,6 +169,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 +185,8 @@ static int imx_sc_rtc_probe(struct platform_device*pdev)
Quoted 8 lines
drivers/rtc/rtc-imx-sc.c +2
-0return ret; } +imx_scu_register_notifier (&imx_sc_rtc_alarm_sc_notifier); +return 0 ; }
Quoted 12 lines
Quoted 3 lines
--
2.7.4--
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fboo
tlin.com&data=02%7C01%7Canson.huang%40nxp.com%7C42f5ff583e1 d4291e96f08d695ec21a0%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C 0%7C636861238739290396&sdata=m6zYiMboulNT%2FbcB7mUk509FqR PJutjMUE7kPtZCctI%3D&reserved=0
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel