From patchwork Thu Jan 26 14:20:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 48717 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp297268wrn; Thu, 26 Jan 2023 06:25:34 -0800 (PST) X-Google-Smtp-Source: AK7set9d9EKT/XZxyYQvDGHPc218Y4vkq0NC61JQgyHVl2tj2Jvd0HHuzElp0MzIGukgKakRq7Nt X-Received: by 2002:a17:906:94f:b0:878:7921:2240 with SMTP id j15-20020a170906094f00b0087879212240mr865115ejd.64.1674743134132; Thu, 26 Jan 2023 06:25:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674743134; cv=none; d=google.com; s=arc-20160816; b=nkvIkHiuuXJnb8GoCYb3Y3aQrzbq9nUBuq7rJCpSxIr1A2mUC6wDp+fIhilXhQ4ktt doWJBFTKBxOTEnr/Gst14yRAasaRCStsOR3Nde1Th9653X+rblx/emcoWCRjK9CrMTsN uOq9nljC5AhZG/HBWhJPVtwwGBitqX++43mLC3aM0ZLHGDJ29kpN58/C4vme/PZqtYMg qcWMPiZYYdg+Jak3qIVwMQEp5ktW21r/r94O+QFbkZRTNwsHi+rmSoxaVDRTilESyBwG A37TDHqdw2MHhnyyhQiV5AZNqGCSxDtbYZpHsl+WbGmgRTkX4XWbWd9/DGOUVEVM317g JiVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sae48iak0jyIJnVd4jjOc1Yk3WyreChByRKDjMDBWoU=; b=iALKK/bjAFN639QylTe9/Z3s2H7EianmblsxpB4Uc9MNOdWj6h8qGKcInsS9yleD8a nrbJFmo/GEVMTz0X40ck3PH46Hf9ShHe30K+1+0Fsfi0/cdKpdTWJvZjYiFSOWvBMVRu RqS5YZxiGYpMG1Rnn/cK8zakyY0wuKrq3PYkFjpA+UejWkLFIO0+y37fmvFV9oWDWxlk FnVFWByaaFaWKuiXL2cJ3FF5U0yVkCrF3aFPJu1WOhoDD90B4pWeZjNRPFdCfGD5T1qC CnXcMwYRgcesmY/LEWPQ1bZO/CB0+7XAURv9f5GmqlgfUCrVsIpOTpew3DBn9BwQHG4P dacA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EoGIpxvx; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kb16-20020a170907925000b0087777e65f7esi1214376ejb.504.2023.01.26.06.25.09; Thu, 26 Jan 2023 06:25:34 -0800 (PST) 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=EoGIpxvx; 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 S231969AbjAZOX0 (ORCPT + 99 others); Thu, 26 Jan 2023 09:23:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231898AbjAZOXD (ORCPT ); Thu, 26 Jan 2023 09:23:03 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AB361CF59; Thu, 26 Jan 2023 06:23:00 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E6B9BB81DEF; Thu, 26 Jan 2023 14:22:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 866A4C4339E; Thu, 26 Jan 2023 14:22:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674742977; bh=hhCtw+HmTT9km9pBv0XwTlPCeUZBnbPGQDj+D0a9Ak0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EoGIpxvxks3Jv93NwXx2MehlRrAaHGlX2AMteW1QHAc74iTCc1j23iQ4prhVv9O4p oBCWBawvl92ki/iuJNcaYsYSbxAJHmOFVwchirtR/xqr85w2/HpzDFhu7x9d55mD0q zre/9ZXCWzHKNNVmxyDAKGMvD2beQe7PCICu3ouKmleiVMAVH9HufD+XU3fDlOuUbN P8Qbd/a5c1s7FZ8jfogwRgDxLf30aqtfGSVWPbz7yBYdoZ4O1b7EY3saUFKcxQOvEa bZCF3y/n/vRuEo48Xtw4eUWmKXkDNvYNGTamVvPRpzScdn9yJ09imLHDJniMusmun1 qdV2ERuz0Z9ww== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1pL39c-0006iL-9j; Thu, 26 Jan 2023 15:23:04 +0100 From: Johan Hovold To: Alexandre Belloni , Bjorn Andersson Cc: Andy Gross , Konrad Dybcio , Alessandro Zummo , Rob Herring , Krzysztof Kozlowski , Maximilian Luz , linux-arm-msm@vger.kernel.org, linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 04/24] rtc: pm8xxx: drop bogus locking Date: Thu, 26 Jan 2023 15:20:37 +0100 Message-Id: <20230126142057.25715-5-johan+linaro@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230126142057.25715-1-johan+linaro@kernel.org> References: <20230126142057.25715-1-johan+linaro@kernel.org> MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756095456583337748?= X-GMAIL-MSGID: =?utf-8?q?1756095456583337748?= Since commit c8d523a4b053 ("drivers/rtc/rtc-pm8xxx.c: rework to support pm8941 rtc") which removed the shadow control register there is no need for a driver lock. Specifically, the rtc ops are serialised by rtc core and the interrupt handler only unconditionally disables the alarm using the alarm_ctrl register. Note that since only the alarm enable bit of alarm_ctrl is used after enabling the RTC at probe, the locking was not needed when doing open coded read-modify-write cycles either. Signed-off-by: Johan Hovold --- drivers/rtc/rtc-pm8xxx.c | 67 +++++++++++++--------------------------- 1 file changed, 21 insertions(+), 46 deletions(-) diff --git a/drivers/rtc/rtc-pm8xxx.c b/drivers/rtc/rtc-pm8xxx.c index 8c2847ac64f4..053a04f74a91 100644 --- a/drivers/rtc/rtc-pm8xxx.c +++ b/drivers/rtc/rtc-pm8xxx.c @@ -53,7 +53,6 @@ struct pm8xxx_rtc_regs { * @rtc_alarm_irq: rtc alarm irq number. * @regs: rtc registers description. * @rtc_dev: device structure. - * @ctrl_reg_lock: spinlock protecting access to ctrl_reg. */ struct pm8xxx_rtc { struct rtc_device *rtc; @@ -62,7 +61,6 @@ struct pm8xxx_rtc { int rtc_alarm_irq; const struct pm8xxx_rtc_regs *regs; struct device *rtc_dev; - spinlock_t ctrl_reg_lock; }; /* @@ -77,11 +75,11 @@ struct pm8xxx_rtc { static int pm8xxx_rtc_set_time(struct device *dev, struct rtc_time *tm) { int rc, i; - unsigned long secs, irq_flags; struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); const struct pm8xxx_rtc_regs *regs = rtc_dd->regs; u8 value[NUM_8_BIT_RTC_REGS]; bool alarm_enabled; + unsigned long secs; if (!rtc_dd->allow_set_time) return -ENODEV; @@ -95,51 +93,46 @@ static int pm8xxx_rtc_set_time(struct device *dev, struct rtc_time *tm) secs >>= 8; } - spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags); - rc = regmap_update_bits_check(rtc_dd->regmap, regs->alarm_ctrl, regs->alarm_en, 0, &alarm_enabled); if (rc) - goto rtc_rw_fail; + return rc; /* Disable RTC H/w before writing on RTC register */ rc = regmap_update_bits(rtc_dd->regmap, regs->ctrl, PM8xxx_RTC_ENABLE, 0); if (rc) - goto rtc_rw_fail; + return rc; /* Write 0 to Byte[0] */ rc = regmap_write(rtc_dd->regmap, regs->write, 0); if (rc) - goto rtc_rw_fail; + return rc; /* Write Byte[1], Byte[2], Byte[3] */ rc = regmap_bulk_write(rtc_dd->regmap, regs->write + 1, &value[1], sizeof(value) - 1); if (rc) - goto rtc_rw_fail; + return rc; /* Write Byte[0] */ rc = regmap_write(rtc_dd->regmap, regs->write, value[0]); if (rc) - goto rtc_rw_fail; + return rc; /* Enable RTC H/w after writing on RTC register */ rc = regmap_update_bits(rtc_dd->regmap, regs->ctrl, PM8xxx_RTC_ENABLE, PM8xxx_RTC_ENABLE); if (rc) - goto rtc_rw_fail; + return rc; if (alarm_enabled) { rc = regmap_update_bits(rtc_dd->regmap, regs->alarm_ctrl, regs->alarm_en, regs->alarm_en); if (rc) - goto rtc_rw_fail; + return rc; } -rtc_rw_fail: - spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags); - - return rc; + return 0; } static int pm8xxx_rtc_read_time(struct device *dev, struct rtc_time *tm) @@ -184,9 +177,9 @@ static int pm8xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) { int rc, i; u8 value[NUM_8_BIT_RTC_REGS]; - unsigned long secs, irq_flags; struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); const struct pm8xxx_rtc_regs *regs = rtc_dd->regs; + unsigned long secs; secs = rtc_tm_to_time64(&alarm->time); @@ -200,25 +193,22 @@ static int pm8xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) if (rc) return rc; - spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags); - rc = regmap_bulk_write(rtc_dd->regmap, regs->alarm_rw, value, sizeof(value)); if (rc) - goto rtc_rw_fail; + return rc; if (alarm->enabled) { rc = regmap_update_bits(rtc_dd->regmap, regs->alarm_ctrl, regs->alarm_en, regs->alarm_en); if (rc) - goto rtc_rw_fail; + return rc; } dev_dbg(dev, "Alarm Set for h:m:s=%ptRt, y-m-d=%ptRdr\n", &alarm->time, &alarm->time); -rtc_rw_fail: - spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags); - return rc; + + return 0; } static int pm8xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) @@ -255,14 +245,11 @@ static int pm8xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) static int pm8xxx_rtc_alarm_irq_enable(struct device *dev, unsigned int enable) { int rc; - unsigned long irq_flags; struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); const struct pm8xxx_rtc_regs *regs = rtc_dd->regs; u8 value[NUM_8_BIT_RTC_REGS] = {0}; unsigned int val; - spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags); - if (enable) val = regs->alarm_en; else @@ -271,19 +258,17 @@ static int pm8xxx_rtc_alarm_irq_enable(struct device *dev, unsigned int enable) rc = regmap_update_bits(rtc_dd->regmap, regs->alarm_ctrl, regs->alarm_en, val); if (rc) - goto rtc_rw_fail; + return rc; /* Clear Alarm register */ if (!enable) { rc = regmap_bulk_write(rtc_dd->regmap, regs->alarm_rw, value, sizeof(value)); if (rc) - goto rtc_rw_fail; + return rc; } -rtc_rw_fail: - spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags); - return rc; + return 0; } static const struct rtc_class_ops pm8xxx_rtc_ops = { @@ -302,25 +287,18 @@ static irqreturn_t pm8xxx_alarm_trigger(int irq, void *dev_id) rtc_update_irq(rtc_dd->rtc, 1, RTC_IRQF | RTC_AF); - spin_lock(&rtc_dd->ctrl_reg_lock); - /* Clear the alarm enable bit */ rc = regmap_update_bits(rtc_dd->regmap, regs->alarm_ctrl, regs->alarm_en, 0); - if (rc) { - spin_unlock(&rtc_dd->ctrl_reg_lock); - goto rtc_alarm_handled; - } - - spin_unlock(&rtc_dd->ctrl_reg_lock); + if (rc) + goto out; /* Clear RTC alarm register */ rc = regmap_update_bits(rtc_dd->regmap, regs->alarm_ctrl2, PM8xxx_RTC_ALARM_CLEAR, 0); if (rc) - goto rtc_alarm_handled; - -rtc_alarm_handled: + goto out; +out: return IRQ_HANDLED; } @@ -398,9 +376,6 @@ static int pm8xxx_rtc_probe(struct platform_device *pdev) if (rtc_dd == NULL) return -ENOMEM; - /* Initialise spinlock to protect RTC control register */ - spin_lock_init(&rtc_dd->ctrl_reg_lock); - rtc_dd->regmap = dev_get_regmap(pdev->dev.parent, NULL); if (!rtc_dd->regmap) { dev_err(&pdev->dev, "Parent regmap unavailable.\n");