Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp2527206rwb; Sun, 6 Aug 2023 21:32:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFnH1aG0Oz74N4f00x1LG7yC+qv7bfCRH2MxL2YeKytbCjiwnppthtd8F8juu1xIhy7bXSE X-Received: by 2002:a17:906:53d1:b0:993:d617:bdc8 with SMTP id p17-20020a17090653d100b00993d617bdc8mr6603995ejo.7.1691382745953; Sun, 06 Aug 2023 21:32:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691382745; cv=none; d=google.com; s=arc-20160816; b=QwNbp9+G3Lq8n52HT2SAdsrOHjgUvbox97/9X15ZxA0QL63ZZRIUXElfYy86Q+OjGg YVKS2N5ap+h4GdzUrIJQr1DmxG0eEqIHIHkvdFjn94UituUXlGzkOKktWoyplOBaJH0W 2GZGg9Bxnm1iTBVJNP0Z3QYX0rbgtRVfA9ZBL0GoP5e5aWfb8jUePDz5A1/bPpYdUE1y jdqrUlvD4PrEEAsM7SGPQFS7bR5+cl8oXbcBmLFkDt9fGCJcYJCaqKZ3JcCq2dWHWDsi fiZIM0T2nU8jLCAM8NiSKhyWqnsn0VtV+1/ajHgM/MD/LVOjS/N6vTg4BWqgAp0rtQ+8 /i8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=npDepF47AoV8zYCEP6lWL+fq0JiOO70glEOb6ol77VY=; fh=9FcmZX8sq5DeLDnRL4GgdARfC9IZWSwiR7SWYqiD+GU=; b=tPaAXyXvwFObbeVCOzTCeSid36pbzl2eJDUswzhRMeCCwcposwDOBAcBg+8YgX4WnE ABv9tj/hXnHiE4sXipA+kow0zg32dOA3j9Q4yxL2hnCwLMJ/TIYReIOkxp9p3YdoKePW x71QlUwTk6BCjc54HbYc6nvit4+oJLgWTA5XejGTPJJJcnvbJoli6okvmBnAo0j3ucU+ XvRy5AUadObK2HGb1cYTN3TBPJKxjaCWur91GoOFZ2jr+2W93PG+SKMEqi4pCZDubxor 7YAiMr0NOFhiJBUti7pvArZP91Hsx6fAXdQNrWmpUOeeApz7qovU2koYTxJzY4EOuJL3 Y8cQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="HhqG/fGF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rp7-20020a170906d96700b0098e16f844f5si3872244ejb.715.2023.08.06.21.32.01; Sun, 06 Aug 2023 21:32:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="HhqG/fGF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230009AbjHGDrq (ORCPT + 99 others); Sun, 6 Aug 2023 23:47:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229810AbjHGDro (ORCPT ); Sun, 6 Aug 2023 23:47:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F24410F9 for ; Sun, 6 Aug 2023 20:47:43 -0700 (PDT) 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 E9E5261365 for ; 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230731090449.2845997-10-peng.fan@oss.nxp.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 >