From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5106DC001DE for ; Mon, 7 Aug 2023 03:48:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bXo7ijXTP4vUqGqZ4KUcbb9e0YeRPhNCGAycvccFiXA=; b=TwFKmzqFYnCgrY LSi0O5hPzxDm3CaixsT4xE88+4J85magVDpA6jvXon0BsZWicyBxendDqEAeWYzThr7zWQL03DqYN 5smIFr8s6zq9K6957Z5HIACIdAdMb2EpKuP1ejKr7OOYIc7giIRmoPPGB/Wtoa+M622Z0ZpBqGj9n jZtzEhDjzyEO41smnV3UmpA02YwCJUdgBLFO80Ass1m8SfS71aBcEFo3zD6CQHAe528z0pz/oePxx 0YhVQJmvgwqeQatkZsoQy2rDdpyJi8YIhb8gWW64ItC3XyGtHjtVxLnU6rJxumTgYtovDG6Z56xQI W0PTHqwih3Ro3JvmAcPg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qSrDh-00G5nI-0B; Mon, 07 Aug 2023 03:47:49 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qSrDd-00G5mo-2d for linux-arm-kernel@lists.infradead.org; Mon, 07 Aug 2023 03:47:47 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E2C5E61360; Mon, 7 Aug 2023 03:47:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A49FAC433C8; Mon, 7 Aug 2023 03:47:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691380062; bh=bj5F7ecFqurRkS5eVFeyvZbl/Z7NesxetDXDsHYsUXU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HhqG/fGF24G0B2utg+CXG7JDcCiZR9BISnGY2sNKpI0wuhk3b6Ax1Y7cYln7mA3DA PcyCbbiWpr5pNpYVZWgP7SRR5aHXzdm6lE4/GA7BX8N1KRa/OPdrOTFFEqENyVBDAV Jyc1Io/g0OJ/dexb+G++DqC0zz85dyLTvK1f53YDHZbGIQp+bmc42ptKK9yQJmuLOk Fgxz/FA8RG8X6r5j7qVU04G6lfm31qXcDziErzqnT42uwvzLaaC6A61ekgUBsy8ONb Fj05bMowViKZlgKYFpqpSzitHZcGraweMlhg+8SoSJGLpQixV3c4IdFEGe0ztsa4Hn FCD7X8OjhMG8w== Date: Mon, 7 Aug 2023 11:47:29 +0800 From: Shawn Guo To: "Peng Fan (OSS)" Cc: s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, aisheng.dong@nxp.com, alexander.stein@ew.tq-group.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Ranjani Vaidyanathan , Peng Fan Subject: Re: [PATCH V5 9/9] firmware: imx: scu-irq: support identifying SCU wakeup source from sysfs Message-ID: <20230807034729.GR151430@dragon> References: <20230731090449.2845997-1-peng.fan@oss.nxp.com> <20230731090449.2845997-10-peng.fan@oss.nxp.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230731090449.2845997-10-peng.fan@oss.nxp.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230806_204745_964163_66BC6F71 X-CRM114-Status: GOOD ( 30.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Jul 31, 2023 at 05:04:49PM +0800, Peng Fan (OSS) wrote: > From: Ranjani Vaidyanathan > > 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 > Signed-off-by: Peng Fan > --- > drivers/firmware/imx/imx-scu-irq.c | 66 +++++++++++++++++++++++++++--- > 1 file changed, 61 insertions(+), 5 deletions(-) > > diff --git a/drivers/firmware/imx/imx-scu-irq.c b/drivers/firmware/imx/imx-scu-irq.c > index 8d902db1daf2..fcbaa393897c 100644 > --- a/drivers/firmware/imx/imx-scu-irq.c > +++ b/drivers/firmware/imx/imx-scu-irq.c > @@ -11,6 +11,8 @@ > #include > #include > #include > +#include > +#include Can we keep the list alphabetically sorted? > > #define IMX_SC_IRQ_FUNC_ENABLE 1 > #define IMX_SC_IRQ_FUNC_STATUS 2 > @@ -40,6 +42,20 @@ struct imx_sc_msg_irq_enable { > u8 enable; > } __packed; > > +struct scu_wakeup { > + u32 mask; > + u32 wakeup_src; > + bool valid; > +}; > + > +/* Sysfs functions */ > +static struct kobject *wakeup_obj; > +static ssize_t wakeup_source_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf); > +static struct kobj_attribute wakeup_source_attr = > + __ATTR(wakeup_src, 0660, wakeup_source_show, NULL); > + > +static struct scu_wakeup scu_irq_wakeup[IMX_SC_IRQ_NUM_GROUP]; > + > static struct imx_sc_ipc *imx_sc_irq_ipc_handle; > static struct work_struct imx_sc_irq_work; > static BLOCKING_NOTIFIER_HEAD(imx_scu_irq_notifier_chain); > @@ -71,16 +87,24 @@ static void imx_scu_irq_work_handler(struct work_struct *work) > u8 i; > > for (i = 0; i < IMX_SC_IRQ_NUM_GROUP; i++) { > + if (scu_irq_wakeup[i].mask) { > + scu_irq_wakeup[i].valid = false; > + scu_irq_wakeup[i].wakeup_src = 0; > + } Can we have a newline here? > ret = imx_scu_irq_get_status(i, &irq_status); > if (ret) { > - pr_err("get irq group %d status failed, ret %d\n", > - i, ret); > + pr_err("get irq group %d status failed, ret %d\n", i, ret); Unrelated change? > return; > } > > if (!irq_status) > continue; > - > + if (scu_irq_wakeup[i].mask & irq_status) { > + scu_irq_wakeup[i].valid = true; > + scu_irq_wakeup[i].wakeup_src = irq_status & scu_irq_wakeup[i].mask; > + } else { > + scu_irq_wakeup[i].wakeup_src = irq_status; > + } Can we have a newline here? > pm_system_wakeup(); > imx_scu_irq_notifier_call_chain(irq_status, &i); > } > @@ -135,6 +159,11 @@ int imx_scu_irq_group_enable(u8 group, u32 mask, u8 enable) > pr_err("enable irq failed, group %d, mask %d, ret %d\n", > group, mask, ret); > > + if (enable) > + scu_irq_wakeup[group].mask |= mask; > + else > + scu_irq_wakeup[group].mask &= ~mask; > + > return ret; > } > EXPORT_SYMBOL(imx_scu_irq_group_enable); > @@ -144,6 +173,25 @@ static void imx_scu_irq_callback(struct mbox_client *c, void *msg) > schedule_work(&imx_sc_irq_work); > } > > +static ssize_t wakeup_source_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) > +{ > + int i; > + > + for (i = 0; i < IMX_SC_IRQ_NUM_GROUP; i++) { > + if (!scu_irq_wakeup[i].wakeup_src) > + continue; > + > + if (scu_irq_wakeup[i].valid) > + sprintf(buf, "Wakeup source group = %d, irq = 0x%x\n", > + i, scu_irq_wakeup[i].wakeup_src); > + else > + sprintf(buf, "Spurious SCU wakeup, group = %d, irq = 0x%x\n", > + i, scu_irq_wakeup[i].wakeup_src); > + } > + > + return strlen(buf); > +} > + > int imx_scu_enable_general_irq_channel(struct device *dev) > { > struct of_phandle_args spec; > @@ -173,8 +221,7 @@ int imx_scu_enable_general_irq_channel(struct device *dev) > > 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)) > + if (!of_parse_phandle_with_args(dev->of_node, "mboxes", "#mbox-cells", 0, &spec)) Unrelated change? > i = of_alias_get_id(spec.np, "mu"); > > /* use mu1 as general mu irq channel if failed */ > @@ -183,6 +230,15 @@ int imx_scu_enable_general_irq_channel(struct device *dev) > > mu_resource_id = IMX_SC_R_MU_0A + i; > > + /* Create directory under /sysfs/firmware */ > + wakeup_obj = kobject_create_and_add("scu_wakeup_source", firmware_kobj); Should we check error condition here? > + > + if (sysfs_create_file(wakeup_obj, &wakeup_source_attr.attr)) { Should we populate 'ret' here, or is the sysfs optional? > + pr_err("Cannot create sysfs file......\n"); Can we use dev_err() here? > + kobject_put(wakeup_obj); > + sysfs_remove_file(firmware_kobj, &wakeup_source_attr.attr); The sysfs_remove_file() is the undo of sysfs_create_file() which hasn't been successful, right? Shawn > + } > + > return ret; > } > EXPORT_SYMBOL(imx_scu_enable_general_irq_channel); > -- > 2.37.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel