dt-bindings: fsl: scu: add general interrupt support
Subsystems (3)
PATCH v6 1/4 dt-bindings: fsl: scu: add general interrupt support
Add scu general interrupt function support.
---
No changes.
--- .../devicetree/bindings/arm/freescale/fsl,scu.txt | 29 +++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt +23 -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"; + 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";
Signature · 1 line
2.7.4
PATCH v6 2/4 firmware: imx: enable imx scu general irq function
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.
---
Changes since V5:
- use ATOMIC_NOTIFIER instead of BLOCKING_NOTIFIER for irq notification;
- add memory free for failed case to avoid memory leak;
- add new API imx_scu_irq_enable() for modules to enable/disable their own irqs.
--- drivers/firmware/imx/Makefile | 2 +- drivers/firmware/imx/imx-scu-irq.c | 166 +++++++++++++++++++++++++++++++++++++ drivers/firmware/imx/imx-scu.c | 6 ++ include/linux/firmware/imx/sci.h | 5 ++ 4 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 drivers/firmware/imx/imx-scu-irq.c
drivers/firmware/imx/Makefile +1 -1
@@ -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
drivers/firmware/imx/imx-scu-irq.c new file +166 -0
166 lines not on this page · raw message
drivers/firmware/imx/imx-scu.c +6 -0
@@ -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);
include/linux/firmware/imx/sci.h +5 -0
@@ -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); +void imx_scu_irq_enable (u8 group,u32 mask,u8 enable);#endif /* _SC_SCI_H */
Signature · 1 line
2.7.4
RE: [PATCH V6 2/4] firmware: imx: enable imx scu general irq function
Quoted 130 lines
From: Anson Huang
Sent: Tuesday, April 9, 2019 10:43 AM
Subject: [PATCH V6 2/4] firmware: imx: enable imx scu general irq functionThe 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 <[email protected]>---
Changes since V5:
- useATOMIC_NOTIFIERinstead ofBLOCKING_NOTIFIERfor irq
notification;
- add memory free for failed case to avoid memory leak;
- add new APIimx_scu_irq_enable()for modules to enable/disable their
own irqs.--- drivers/firmware/imx/Makefile | 2 +- drivers/firmware/imx/imx-scu-irq.c | 166 +++++++++++++++++++++++++++++++++++++ drivers/firmware/imx/imx-scu.c | 6 ++ include/linux/firmware/imx/sci.h | 5 ++ 4 files changed, 178 insertions(+), 1 deletion(-) create mode 100644
drivers/firmware/imx/imx-scu-irq.cdrivers/firmware/imx/Makefile +1
-1@@ -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.odrivers/firmware/imx/imx-scu-irq.c new file +83
-0@@ -0,0 +1,166 @@ +// 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 ; + }
drivers/firmware/imx/imx-scu-irq.c line 93
Quoted 10 lines
drivers/firmware/imx/imx-scu-irq.c new file +10
-0+ + irq_status = msg.data.resp.status; +if (!irq_status) +continue ; + +imx_scu_irq_notifier_call_chain (irq_status, &i); + } +} + +void imx_scu_irq_enable (u8 group,u32 mask,u8 enable) {
Why should this be a void return?
Besides that, a nitpick better rename to imx_scu_irq_group_enable to distinguish with the exist general irq enable.
Regards
Dong Aisheng
Quoted 107 lines
drivers/firmware/imx/imx-scu-irq.c new file +66
-0+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); +} +EXPORT_SYMBOL (imx_scu_irq_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);drivers/firmware/imx/imx-scu.c +6
-0@@ -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 --gita/include/linux/firmware/imx/sci.hb/include/linux/firmware/imx/sci.hindex ebc5509..4100be7 100644include/linux/firmware/imx/sci.h +0
-0@@ -15,4 +15,9 @@ #include <linux/firmware/imx/svc/misc.h> #include<
linux/firmware/imx/svc/pm.h>include/linux/firmware/imx/sci.h +5
-1+ +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);void +imx_scu_irq_enable (u8 group,u32 mask,u8 enable);#endif /* _SC_SCI_H */ --2.7.4
RE: [PATCH V6 2/4] firmware: imx: enable imx scu general irq function
Best Regards!
Anson Huang
Quoted 159 lines
-----Original Message-----
From: Aisheng Dong
Sent: 2019年4月9日 11:21
To: Anson Huang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Peng Fan <[email protected]>; Daniel Baluta <[email protected]>; [email protected]; [email protected]; linux-arm- [email protected]; [email protected]
Cc: dl-linux-imx <[email protected]>
Subject: RE: [PATCH V6 2/4] firmware: imx: enable imx scu general irq functionQuoted 11 lines
From: Anson Huang
Sent: Tuesday, April 9, 2019 10:43 AM
Subject: [PATCH V6 2/4] firmware: imx: enable imx scu general irq functionThe 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.
Quoted 3 lines
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.
Quoted 117 lines
Signed-off-by Anson Huang <[email protected]>---
Changes since V5:
- useATOMIC_NOTIFIERinstead ofBLOCKING_NOTIFIERfor irq
notification;
- add memory free for failed case to avoid memory leak;
- add new APIimx_scu_irq_enable()for modules to enable/disable
their own irqs.--- drivers/firmware/imx/Makefile | 2 +- drivers/firmware/imx/imx-scu-irq.c | 166 +++++++++++++++++++++++++++++++++++++ drivers/firmware/imx/imx-scu.c | 6 ++ include/linux/firmware/imx/sci.h | 5 ++ 4 files changed, 178 insertions(+), 1 deletion(-) create mode 100644
drivers/firmware/imx/imx-scu-irq.c(quoted diff) +0
-0b/drivers/firmware/imx/Makefile index 1b2e15b..802c4ad 100644
drivers/firmware/imx/Makefile +1
-1@@ -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.odrivers/firmware/imx/imx-scu-irq.c new file +83
-0@@ -0,0 +1,166 @@ +// 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 ; + }drivers/firmware/imx/imx-scu-irq.c line 93
Quoted 10 lines
drivers/firmware/imx/imx-scu-irq.c new file +10
-0+ + irq_status = msg.data.resp.status; +if (!irq_status) +continue ; + +imx_scu_irq_notifier_call_chain (irq_status, &i); + } +} + +void imx_scu_irq_enable (u8 group,u32 mask,u8 enable) {Why should this be a void return?
Quoted 2 lines
Besides that, a nitpick better rename to
imx_scu_irq_group_enableto distinguish with the exist general irq enable.
Will add return value in V7 and rename it as well.
Anson.
Quoted 102 lines
Regards
Dong AishengQuoted 37 lines
drivers/firmware/imx/imx-scu-irq.c new file +37
-0+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); +} +EXPORT_SYMBOL (imx_scu_irq_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)drivers/firmware/imx/imx-scu-irq.c
Quoted 10 lines
drivers/firmware/imx/imx-scu-irq.c new file +10
-0+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);
Quoted 50 lines
drivers/firmware/imx/imx-scu-irq.c new file +19
-0+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);(quoted diff) +0
-0
b/drivers/firmware/imx/imx-scu.cindex 2bb1a19..04a24a8 100644drivers/firmware/imx/imx-scu.c +0
-0@@ -10,6 +10,7 @@#include <linux/err.h> #include <linux/firmware/imx/types.h> #include<
linux/firmware/imx/ipc.h>drivers/firmware/imx/imx-scu.c +6
-0+#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 --gita/include/linux/firmware/imx/sci.hb/include/linux/firmware/imx/sci.hindex ebc5509..4100be7 100644include/linux/firmware/imx/sci.h +0
-0@@ -15,4 +15,9 @@
Quoted 10 lines
Quoted 10 lines
include/linux/firmware/imx/sci.h +0
-0#include <linux/firmware/imx/svc/misc.h> #include<
linux/firmware/imx/svc/pm.h>include/linux/firmware/imx/sci.h +5
-1+ +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);void +imx_scu_irq_enable (u8 group,u32 mask,u8 enable);#endif /* _SC_SCI_H */ --2.7.4
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v6 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 changes.
--- arch/arm64/boot/dts/freescale/imx8qxp.dtsi | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/freescale/imx8qxp.dtsi +5 -2
@@ -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";
Signature · 1 line
2.7.4
PATCH v6 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.
---
Changes since V5:
- move the irq alarm enable RPC to imx-scu-irq driver, and rtc driver just call the API to enable/disable alarm.
--- drivers/rtc/rtc-imx-sc.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+)
drivers/rtc/rtc-imx-sc.c +84 -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,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,74 @@ 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) +{ +imx_scu_irq_enable (SC_IRQ_GROUP_RTC ,SC_IRQ_RTC , enable); + +return 0 ; +} + +static int imx_sc_rtc_read_alarm (struct device *dev,struct rtc_wkalrm *alrm) +{ +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_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 +153,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 +169,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 ; }
Signature · 1 line
2.7.4
RE: [PATCH V6 4/4] rtc: imx-sc: add rtc alarm support
Quoted 68 lines
From: Anson Huang
Sent: Tuesday, April 9, 2019 10:44 AM
Subject: [PATCH V6 4/4] rtc: imx-sc: add rtc alarm supportAdd 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 <[email protected]>---
Changes since V5:
- move the irq alarm enable RPC to imx-scu-irq driver, and rtc driver just
call the
API to enable/disable alarm.--- drivers/rtc/rtc-imx-sc.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+)drivers/rtc/rtc-imx-sc.c index renamed from drivers/rtc/rtc-imx-sc.c +0
-019642bf..3eb4db0 100644
drivers/rtc/rtc-imx-sc.c +15
-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,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,74 @@ staticint imx_sc_rtc_set_time (struct device *dev,struct rtc_time *tm)drivers/rtc/rtc-imx-sc.c +0
-0return res.a0; }
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 +9
-0+static int imx_sc_rtc_alarm_irq_enable (struct device *dev,unsigned int +enable) { +imx_scu_irq_enable (SC_IRQ_GROUP_RTC ,SC_IRQ_RTC , enable); + +return 0 ; +} + +static int imx_sc_rtc_read_alarm (struct device *dev,struct rtc_wkalrm +*alrm) {
I still think here needs a doc explain why needs this and why it's safe to do that. Otherwise:
Quoted 36 lines
drivers/rtc/rtc-imx-sc.c +36
-0+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 ; +}
drivers/rtc/rtc-imx-sc.c static int imx_sc_rtc_set_time(struct device *dev, struct rtc_time *tm) · line 133
Quoted 10 lines
drivers/rtc/rtc-imx-sc.c +7
-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_sc_notify (struct notifier_block *nb, +unsigned long event,void *group)
Not necessary to have such a long function name.Imx_sc_rtc_alarm_notify() should be ok
Regards
Dong Aisheng
Quoted 36 lines
drivers/rtc/rtc-imx-sc.c +12
-0+{ +/* 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 +153,8@@ static int
imx_sc_rtc_probe(struct platform_device *pdev)drivers/rtc/rtc-imx-sc.c +4
-1if (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 +169,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
RE: [PATCH V6 4/4] rtc: imx-sc: add rtc alarm support
Best Regards!
Anson Huang
Quoted 84 lines
-----Original Message-----
From: Aisheng Dong
Sent: 2019年4月9日 11:25
To: Anson Huang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Peng Fan <[email protected]>; Daniel Baluta <[email protected]>; [email protected]; [email protected]; linux-arm- [email protected]; [email protected]
Cc: dl-linux-imx <[email protected]>
Subject: RE: [PATCH V6 4/4] rtc: imx-sc: add rtc alarm supportQuoted 9 lines
From: Anson Huang
Sent: Tuesday, April 9, 2019 10:44 AM
Subject: [PATCH V6 4/4] rtc: imx-sc: add rtc alarm supportAdd 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 46 lines
Signed-off-by Anson Huang <[email protected]>---
Changes since V5:
- move the irq alarm enable RPC to imx-scu-irq driver, and rtc driver
just call the
API to enable/disable alarm.--- drivers/rtc/rtc-imx-sc.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+)drivers/rtc/rtc-imx-sc.c index renamed from drivers/rtc/rtc-imx-sc.c +0
-019642bf..3eb4db0 100644
drivers/rtc/rtc-imx-sc.c +7
-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,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;drivers/rtc/rtc-imx-sc.c struct imx_sc_msg_timer_get_rtc_time { · line 43
Quoted 10 lines
drivers/rtc/rtc-imx-sc.c +8
-0+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,74 @@static
Quoted 4 lines
drivers/rtc/rtc-imx-sc.c +0
-0int imx_sc_rtc_set_time (struct device *dev,struct rtc_time *tm)return res.a0;
}
Quoted 14 lines
drivers/rtc/rtc-imx-sc.c
Quoted 11 lines
drivers/rtc/rtc-imx-sc.c +11
-0+static int imx_sc_rtc_alarm_irq_enable (struct device *dev,unsigned +int +enable) { +imx_scu_irq_enable (SC_IRQ_GROUP_RTC ,SC_IRQ_RTC , enable); + +return 0 ; +} + +static int imx_sc_rtc_read_alarm (struct device *dev,struct +rtc_wkalrm +*alrm) {I still think here needs a doc explain why needs this and why it's safe to do that.
I will add a comment here, for the doc, it should be another topic of RTC framework, we can do it later.
Anson.
Quoted 93 lines
Otherwise:
Reviewed-by Dong Aisheng <[email protected]>Quoted 36 lines
drivers/rtc/rtc-imx-sc.c +36
-0+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 ; +}drivers/rtc/rtc-imx-sc.c static int imx_sc_rtc_set_time(struct device *dev, struct rtc_time *tm) · line 133
Quoted 10 lines
drivers/rtc/rtc-imx-sc.c +7
-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_sc_notify (struct notifier_block *nb, +unsigned long event,void *group)Not necessary to have such a long function name.
Imx_sc_rtc_alarm_notify()should be okRegards
Dong Aishengdrivers/rtc/rtc-imx-sc.c static int imx_sc_rtc_set_time(struct device *dev, struct rtc_time *tm)
Quoted 3 lines
drivers/rtc/rtc-imx-sc.c +3
-0+{ +/* ignore non-rtc irq */ + if (!((event & SC_IRQ_RTC) && (*(u8 *)group ==
SC_IRQ_GROUP_RTC)))Quoted 33 lines
drivers/rtc/rtc-imx-sc.c +14
-1+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 +153,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 +169,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
RE: [PATCH V6 4/4] rtc: imx-sc: add rtc alarm support
[...]
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/rtc/rtc-imx-sc.c +6
-0+static int imx_sc_rtc_alarm_irq_enable (struct device *dev,unsigned +int +enable) { +imx_scu_irq_enable (SC_IRQ_GROUP_RTC ,SC_IRQ_RTC , enable); + +return 0 ;Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+} + +static int imx_sc_rtc_read_alarm(struct device *dev, struct +rtc_wkalrm +*alrm) {I still think here needs a doc explain why needs this and why it's safe to do that.
Quoted 2 lines
I will add a comment here, for the doc, it should be another topic of RTC framework, we can do it later.
I'm fine with it.
BTW, don't miss the next minor comments when you resend.
Regards
Dong Aisheng
Quoted 9 lines
Quoted 9 lines
drivers/rtc/rtc-imx-sc.c static int imx_sc_rtc_set_time(struct device *dev, struct rtc_time *tm) · line 133
Quoted 5 lines
drivers/rtc/rtc-imx-sc.c +5
-0+ .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)Not necessary to have such a long function name.
Imx_sc_rtc_alarm_notify()should be ok