Received: by 2002:a4a:be92:0:0:0:0:0 with SMTP id o18csp3117904oop; Mon, 18 Feb 2019 18:38:24 -0800 (PST) X-Google-Smtp-Source: AHgI3IYYjbvmZ+cCuFg1Bacgp0Wg3eSOSF+s0J2mmw+Al31WNw6bLBigNCPum+gYNIpya+MldHnA X-Received: by 2002:a17:902:1:: with SMTP id 1mr27135446pla.276.1550543904096; Mon, 18 Feb 2019 18:38:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550543904; cv=none; d=google.com; s=arc-20160816; b=DXbRhYMzMfqqn2xT75V44oJTx/oSi2oLgY5aa+IUEdGh0OX98N8ya0wA/S36GjesKx QtBXS0JRjCpS/ZfxmnFLgKU5I6/pPg1uh737CHBfzshnEBNwbGK2/E3YxKx9vTXny0YJ vg4mnoZliL3rsGbJbPPa3kOw9O+T0ycKKsXyyD4k2Oj2Rzdng6zhLDNbR3Afo3gK8OpC 1u5ZgGf6wcU5d7Knkwtfy85XLnrdVMQT/c5Ov8KgD8TLJ3O+GmiIFl89aXqnVfUitYx0 0+TMQcrS4gFDW+eFvbea0DXE0IxeEtYql9/3SLKlDN7Z1kAsqQyrcVx5lQAC4+/Sdby9 4XpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Hds7S9y39NkrpIbnHXN8wj39KplZGXGVcwhuIK+gpv0=; b=kENiQo2LYH5a0mcgCZbLUx+b6QKWeefz1XqHVCr3dhTnsJms/ZnYKqIn7Q6FOjjNfT 5YVgoKR1XLFjMRCx8nnZ1/XeaIyzG1soCK/3COWSEZwwOGm0qLhNVUw34EEQhT31rm1h bNIlHMWvI2wNLY/vShuSGQ3LQm5s4mGiFt8INNq6HQ+00mFoJuFuecm5H3cLUojfmXGz aIKCA94ZKNKE+fXHOr7mfR668Hs7aG0UQSAHpMCyTsUm6x75q/+mFRFOeZr3MvmsGRNt wNWW4uC1F3+aE27AgOAW4qkSaD8brKqZKCakFsb1tjeZRGPrnp/qgjz/jFsKsWux85Oj eKKQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d12si15013619pfd.183.2019.02.18.18.38.08; Mon, 18 Feb 2019 18:38:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731144AbfBRV5y (ORCPT + 99 others); Mon, 18 Feb 2019 16:57:54 -0500 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:55667 "EHLO relay7-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726955AbfBRV5y (ORCPT ); Mon, 18 Feb 2019 16:57:54 -0500 X-Originating-IP: 86.202.231.219 Received: from localhost (lfbn-lyo-1-149-219.w86-202.abo.wanadoo.fr [86.202.231.219]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id B23A020003; Mon, 18 Feb 2019 21:57:48 +0000 (UTC) Date: Mon, 18 Feb 2019 22:57:48 +0100 From: Alexandre Belloni To: Anson Huang Cc: "robh+dt@kernel.org" , "mark.rutland@arm.com" , "shawnguo@kernel.org" , "s.hauer@pengutronix.de" , "kernel@pengutronix.de" , "festevam@gmail.com" , "a.zummo@towertech.it" , Aisheng Dong , "ulf.hansson@linaro.org" , "sboyd@kernel.org" , Daniel Baluta , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-rtc@vger.kernel.org" , dl-linux-imx Subject: Re: [PATCH V2 4/4] rtc: imx-sc: add rtc alarm support Message-ID: <20190218215748.GC10129@piout.net> References: <1550115535-14488-1-git-send-email-Anson.Huang@nxp.com> <1550115535-14488-5-git-send-email-Anson.Huang@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1550115535-14488-5-git-send-email-Anson.Huang@nxp.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 14/02/2019 03:44:48+0000, Anson Huang wrote: > 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. > > Signed-off-by: Anson Huang > --- > 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? > -- > drivers/rtc/rtc-imx-sc.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 100 insertions(+) > > diff --git a/drivers/rtc/rtc-imx-sc.c b/drivers/rtc/rtc-imx-sc.c > index 60570a2..147545e 100644 > --- a/drivers/rtc/rtc-imx-sc.c > +++ b/drivers/rtc/rtc-imx-sc.c > @@ -3,6 +3,7 @@ > * Copyright 2018 NXP. > */ > > +#include > #include > #include > #include > @@ -11,11 +12,17 @@ > #include > > #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; > + } > + 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. > + 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; > } > > -- > 2.7.4 > -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com