Skip to content

Commit c081197

Browse files
Ranjani VaidyanathanShawn Guo
authored andcommitted
firmware: imx: scu-irq: support identifying SCU wakeup source from sysfs
Record SCU wakeup interrupt in /sys/power/pm_wakeup_irq The user can further identify the exact wakeup source by using the following interface: cat /sys/firmware/scu_wakeup_source/wakeup_src The above will print the wake groups and the irqs that could have contributed to waking up the kernel. For example if ON/OFF button was the wakeup source: cat /sys/firmware/scu_wakeup_source/wakeup_src Wakeup source group = 3, irq = 0x1 The user can refer to the SCFW API documentation to identify all the wake groups and irqs. Signed-off-by: Ranjani Vaidyanathan <ranjani.vaidyanathan@nxp.com> Signed-off-by: Peng Fan <peng.fan@nxp.com> Signed-off-by: Shawn Guo <shawnguo@kernel.org>
1 parent 6c59ce4 commit c081197

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

drivers/firmware/imx/imx-scu-irq.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
#include <dt-bindings/firmware/imx/rsrc.h>
1010
#include <linux/firmware/imx/ipc.h>
1111
#include <linux/firmware/imx/sci.h>
12+
#include <linux/kobject.h>
1213
#include <linux/mailbox_client.h>
1314
#include <linux/suspend.h>
15+
#include <linux/sysfs.h>
1416

1517
#define IMX_SC_IRQ_FUNC_ENABLE 1
1618
#define IMX_SC_IRQ_FUNC_STATUS 2
@@ -40,6 +42,20 @@ struct imx_sc_msg_irq_enable {
4042
u8 enable;
4143
} __packed;
4244

45+
struct scu_wakeup {
46+
u32 mask;
47+
u32 wakeup_src;
48+
bool valid;
49+
};
50+
51+
/* Sysfs functions */
52+
static struct kobject *wakeup_obj;
53+
static ssize_t wakeup_source_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf);
54+
static struct kobj_attribute wakeup_source_attr =
55+
__ATTR(wakeup_src, 0660, wakeup_source_show, NULL);
56+
57+
static struct scu_wakeup scu_irq_wakeup[IMX_SC_IRQ_NUM_GROUP];
58+
4359
static struct imx_sc_ipc *imx_sc_irq_ipc_handle;
4460
static struct work_struct imx_sc_irq_work;
4561
static BLOCKING_NOTIFIER_HEAD(imx_scu_irq_notifier_chain);
@@ -71,6 +87,11 @@ static void imx_scu_irq_work_handler(struct work_struct *work)
7187
u8 i;
7288

7389
for (i = 0; i < IMX_SC_IRQ_NUM_GROUP; i++) {
90+
if (scu_irq_wakeup[i].mask) {
91+
scu_irq_wakeup[i].valid = false;
92+
scu_irq_wakeup[i].wakeup_src = 0;
93+
}
94+
7495
ret = imx_scu_irq_get_status(i, &irq_status);
7596
if (ret) {
7697
pr_err("get irq group %d status failed, ret %d\n",
@@ -80,6 +101,12 @@ static void imx_scu_irq_work_handler(struct work_struct *work)
80101

81102
if (!irq_status)
82103
continue;
104+
if (scu_irq_wakeup[i].mask & irq_status) {
105+
scu_irq_wakeup[i].valid = true;
106+
scu_irq_wakeup[i].wakeup_src = irq_status & scu_irq_wakeup[i].mask;
107+
} else {
108+
scu_irq_wakeup[i].wakeup_src = irq_status;
109+
}
83110

84111
pm_system_wakeup();
85112
imx_scu_irq_notifier_call_chain(irq_status, &i);
@@ -135,6 +162,11 @@ int imx_scu_irq_group_enable(u8 group, u32 mask, u8 enable)
135162
pr_err("enable irq failed, group %d, mask %d, ret %d\n",
136163
group, mask, ret);
137164

165+
if (enable)
166+
scu_irq_wakeup[group].mask |= mask;
167+
else
168+
scu_irq_wakeup[group].mask &= ~mask;
169+
138170
return ret;
139171
}
140172
EXPORT_SYMBOL(imx_scu_irq_group_enable);
@@ -144,6 +176,25 @@ static void imx_scu_irq_callback(struct mbox_client *c, void *msg)
144176
schedule_work(&imx_sc_irq_work);
145177
}
146178

179+
static ssize_t wakeup_source_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
180+
{
181+
int i;
182+
183+
for (i = 0; i < IMX_SC_IRQ_NUM_GROUP; i++) {
184+
if (!scu_irq_wakeup[i].wakeup_src)
185+
continue;
186+
187+
if (scu_irq_wakeup[i].valid)
188+
sprintf(buf, "Wakeup source group = %d, irq = 0x%x\n",
189+
i, scu_irq_wakeup[i].wakeup_src);
190+
else
191+
sprintf(buf, "Spurious SCU wakeup, group = %d, irq = 0x%x\n",
192+
i, scu_irq_wakeup[i].wakeup_src);
193+
}
194+
195+
return strlen(buf);
196+
}
197+
147198
int imx_scu_enable_general_irq_channel(struct device *dev)
148199
{
149200
struct of_phandle_args spec;
@@ -183,6 +234,25 @@ int imx_scu_enable_general_irq_channel(struct device *dev)
183234

184235
mu_resource_id = IMX_SC_R_MU_0A + i;
185236

237+
/* Create directory under /sysfs/firmware */
238+
wakeup_obj = kobject_create_and_add("scu_wakeup_source", firmware_kobj);
239+
if (!wakeup_obj) {
240+
ret = -ENOMEM;
241+
goto free_ch;
242+
}
243+
244+
ret = sysfs_create_file(wakeup_obj, &wakeup_source_attr.attr);
245+
if (ret) {
246+
dev_err(dev, "Cannot create wakeup source src file......\n");
247+
kobject_put(wakeup_obj);
248+
goto free_ch;
249+
}
250+
251+
return 0;
252+
253+
free_ch:
254+
mbox_free_channel(ch);
255+
186256
return ret;
187257
}
188258
EXPORT_SYMBOL(imx_scu_enable_general_irq_channel);

0 commit comments

Comments
 (0)