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 4EB31C4332F for ; Tue, 22 Nov 2022 18:20:12 +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=zTYdcpYIIwK9l4XcBROPT2aobqwPj/rpqVRpcyO9MKA=; b=tluCYRs57eT0Y3 WTH0zw/OJLJwCw8BNdqtyJGtESpbD7i6ExeJwbFBDeljsibhuY88ixquijL9HAW/zaeHbxvOWp1Yy 0NuGHa6X5KNLjSURGYPjHoomTk8nvKPju1dc7sQkBbqbiB3Eu2cqs0+112GMJbkDEr0wYxYtGDSl7 FZhkEgPdw1rcr79Nx9TYURrXfOSVqPgEKhp3xdXMGCf7Kk4eosAtxnIITwhyxbIWnfPuBex4R8v0o oS1b3w6ochCqzsfD92ArMn5OAV5UQ6QxvnTNF1DxDB/23wBIjoQxLvCwU3P4ybQtPW1zRWZmsfQx0 Iru15wHQ6oUKAxQOMRCw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oxXrR-00BGyB-F4; Tue, 22 Nov 2022 18:19:09 +0000 Received: from relay5-d.mail.gandi.net ([2001:4b98:dc4:8::225]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oxXrN-00BGwL-4V for linux-arm-kernel@lists.infradead.org; Tue, 22 Nov 2022 18:19:07 +0000 Received: (Authenticated sender: alexandre.belloni@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 7893B1C000A; Tue, 22 Nov 2022 18:18:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1669141140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZDNwluvtG1WetRunNnZnkNy7ktuJgRYjHUd4OHQgY8I=; b=L36lKCSi1XfW5DlAarMBCS+HzTxpCvOXlID2bSnYrAmwyRimyeaYmihvCOs9AhjQjDRfrT xGo8ELt/5NimK8Hy3Y5aVa/AOjQ7c31daMRTbwZBTjnOF6yTm1BE5tWt+Zhzm8cqiDqaNh 9kyBc7ciuO7UgoKlJxNkpuO1he/FzZaZBM4OLPRIuWjNsw1q41cY8ojU1BB5zBgDOjAnec XLA5e26Q09Gs2WmNNZPE7P0YE1TlVZ9BQX8M0W9M9nIwN/Jke3nVIKfRW1jo5gdibCznoj GS/nlnlt8ZMoBUTq54NT09RZBMdZ553XjybCwtNZs5kdbas0OOPr2cEnDam8Hg== Date: Tue, 22 Nov 2022 19:18:59 +0100 From: Alexandre Belloni To: Jacky Bai Cc: lee@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, shawnguo@kernel.org, s.hauer@pengutronix.de, dmitry.torokhov@gmail.com, a.zummo@towertech.it, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-input@vger.kernel.org, linux-rtc@vger.kernel.org, kernel@pengutronix.de, linux-imx@nxp.com, festevam@gmail.com Subject: Re: [PATCH 3/4] rtc: bbnsm: Add the bbnsm rtc support Message-ID: References: <20221121065144.3667658-1-ping.bai@nxp.com> <20221121065144.3667658-4-ping.bai@nxp.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20221121065144.3667658-4-ping.bai@nxp.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221122_101905_516112_1E7713FC X-CRM114-Status: GOOD ( 28.83 ) 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 21/11/2022 14:51:43+0800, Jacky Bai wrote: > The BBNSM module includes a real time counter with alarm. > Add a RTC driver for this function. > > Signed-off-by: Jacky Bai > Reviewed-by: Peng Fan > --- > drivers/rtc/Kconfig | 12 +++ > drivers/rtc/Makefile | 1 + > drivers/rtc/rtc-bbnsm.c | 223 ++++++++++++++++++++++++++++++++++++++++ I'd prefer that filename to include imx or mxc if this is only available on those SoCs. > diff --git a/drivers/rtc/rtc-bbnsm.c b/drivers/rtc/rtc-bbnsm.c > new file mode 100644 > index 000000000000..4157b238ed9a > --- /dev/null > +++ b/drivers/rtc/rtc-bbnsm.c > @@ -0,0 +1,223 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +// > +// Copyright 2022 NXP. > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include This list should be sorted alphabetically > + > +#define BBNSM_CTRL 0x8 > +#define BBNSM_INT_EN 0x10 > +#define BBNSM_EVENTS 0x14 > +#define BBNSM_RTC_LS 0x40 > +#define BBNSM_RTC_MS 0x44 > +#define BBNSM_TA 0x50 > + > +#define RTC_EN 0x2 > +#define RTC_EN_MSK 0x3 > +#define TA_EN (0x2 << 2) > +#define TA_DIS (0x1 << 2) > +#define TA_EN_MSK (0x3 << 2) > +#define RTC_INT_EN 0x2 > +#define TA_INT_EN (0x2 << 2) > + > +#define BBNSM_EVENT_TA TA_EN > + I'm not clear why this define is needed > +static irqreturn_t bbnsm_rtc_irq_handler(int irq, void *dev_id) > +{ > + struct device *dev = dev_id; > + struct bbnsm_rtc *bbnsm = dev_get_drvdata(dev); > + u32 val; > + u32 event = 0; You can rework this function to remove this variable because it is either 0 or RTC_AF | RTC_IRQF > + > + regmap_read(bbnsm->regmap, BBNSM_EVENTS, &val); > + if (val & BBNSM_EVENT_TA) { > + event |= (RTC_AF | RTC_IRQF); > + bbnsm_rtc_alarm_irq_enable(dev, false); > + /* clear the alarm event */ > + regmap_write_bits(bbnsm->regmap, BBNSM_EVENTS, TA_EN_MSK, BBNSM_EVENT_TA); > + rtc_update_irq(bbnsm->rtc, 1, event); > + } > + > + return event ? IRQ_HANDLED : IRQ_NONE; > +} > + > +static int bbnsm_rtc_probe(struct platform_device *pdev) > +{ > + struct bbnsm_rtc *bbnsm; > + int ret; > + > + bbnsm = devm_kzalloc(&pdev->dev, sizeof(*bbnsm), GFP_KERNEL); > + if (!bbnsm) > + return -ENOMEM; > + > + bbnsm->rtc = devm_rtc_allocate_device(&pdev->dev); > + > + bbnsm->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, "regmap"); > + if (IS_ERR(bbnsm->regmap)) { > + dev_err(&pdev->dev, "bbnsm get regmap failed\n"); > + return PTR_ERR(bbnsm->regmap); > + } > + > + bbnsm->irq = platform_get_irq(pdev, 0); > + if (bbnsm->irq < 0) > + return bbnsm->irq; > + > + platform_set_drvdata(pdev, bbnsm); > + > + /* clear all the pending events */ > + regmap_write(bbnsm->regmap, BBNSM_EVENTS, 0x7A); > + > + /* Enable the Real-Time counter */ > + regmap_update_bits(bbnsm->regmap, BBNSM_CTRL, RTC_EN_MSK, RTC_EN); > + Please don't do that, this removes an important piece of information. Instead, let .set_time enable it and check it in .read_time as if this is not set, you now you are out of PoR and the time is invalid > + device_init_wakeup(&pdev->dev, true); > + ret = dev_pm_set_wake_irq(&pdev->dev, bbnsm->irq); > + if (ret) > + dev_err(&pdev->dev, "Failed to enable the irq wakeup\n"); dev_err but the function is not failing. Maybe just dev_warn? Also, is this message really necessary? > + > + ret = devm_request_irq(&pdev->dev, bbnsm->irq, bbnsm_rtc_irq_handler, > + IRQF_SHARED, "rtc alarm", &pdev->dev); > + if (ret) { > + dev_err(&pdev->dev, "failed to request irq %d: %d\n", > + bbnsm->irq, ret); > + return ret; > + } > + > + bbnsm->rtc->ops = &bbnsm_rtc_ops; > + bbnsm->rtc->range_max = U32_MAX; > + > + return devm_rtc_register_device(bbnsm->rtc); > +} > + > +static const struct of_device_id bbnsm_dt_ids[] = { > + { .compatible = "nxp,bbnsm-rtc", }, > + { /* sentinel */ }, > +}; > +MODULE_DEVICE_TABLE(of, bbnsm_dt_ids); > + > +static struct platform_driver bbnsm_rtc_driver = { > + .driver = { > + .name = "bbnsm_rtc", > + .of_match_table = bbnsm_dt_ids, > + }, > + .probe = bbnsm_rtc_probe, > +}; > +module_platform_driver(bbnsm_rtc_driver); > + > +MODULE_AUTHOR("Jacky Bai "); > +MODULE_DESCRIPTION("NXP BBNSM RTC Driver"); > +MODULE_LICENSE("GPL"); > -- > 2.37.1 > -- Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel