From patchwork Fri Jan 18 13:27:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 155927 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3256903jaa; Fri, 18 Jan 2019 05:28:31 -0800 (PST) X-Google-Smtp-Source: ALg8bN78f6I1kTn4TILWFQ/gCaYxUpMIaU5Sy+wM+CGNTHvP8aSxNLjSk18NDocmTXb46mCmTB2E X-Received: by 2002:a62:2044:: with SMTP id g65mr19235830pfg.127.1547818111577; Fri, 18 Jan 2019 05:28:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547818111; cv=none; d=google.com; s=arc-20160816; b=dz/qPeF0jmS42vyTxR/KB9L7v5OsoDvsteCAKnFDycvurhLwO1MwsAugQcUqx47BMJ KtaJuPOfdPyQbKrGVzJn5yZOcp3omDVEAcAgnxgRSHAIWi8fFx+h2oxDYz5gbvz2SsCV R4LeNSMgicaiYxN4pPAOGWaWCFlMIZz+mDBvJWVq2medSuQca7Ks9osxyEOmjpsaUzTf r238H8eemg586Gh+94ObEs5Gk8fywQYIbY1iUGjRg7rzg7PU3kdwiJH59CYCZ5E4l6iN frqVEmTE4Km4JH3cyCthVdQWWyiqyapGKaV/CfWHt6TYaJPrVZGAlS3TdN4oJ+JmIW9u cSIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=9T7pDl1m4NIwx32hT3P+SHtwJ/zWjl57FsWGKtR9Pf4=; b=wRlToGk3qbIpwpoBTpVYlFAmPTuucQcLXnL/iwS/DYk/sDKudN6SRFXLR7zhmcc5Fs IlpyqBlcHTBoqUxD5DQyCuzb/UtLbh8po77K20yoAPGc4SPCc7r9V9/RDnkwtL7vxCFy YbWdRXZXoY2g/2rLHxu59UirqkLmrr6vfwMNK4n3PCNfO6JfmEfAoh3pw/3vTPHUnHIs dpadg0u/RpBQ9hY2oyEZmZpZWu4MeeWSqppncXfmjNxUmLjZPEoZhcLYRTL0uSP/ghDp LIwAC/WrG/QBeVxGxEEBQlSD1vH21CZaLVHN6PqPfW9MpsxLkbdMYi/4Wc0bhMclqwVN SyTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=bIZhk2X1; spf=pass (google.com: best guess record for domain of linux-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-samsung-soc-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v17si4875826pga.566.2019.01.18.05.28.31; Fri, 18 Jan 2019 05:28:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=bIZhk2X1; spf=pass (google.com: best guess record for domain of linux-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-samsung-soc-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726593AbfARN2a (ORCPT + 3 others); Fri, 18 Jan 2019 08:28:30 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:39659 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726065AbfARN2a (ORCPT ); Fri, 18 Jan 2019 08:28:30 -0500 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20190118132828euoutp02d1a496c2618d749e279760f47f4fd83c~69F5py7-k1541315413euoutp02V; Fri, 18 Jan 2019 13:28:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20190118132828euoutp02d1a496c2618d749e279760f47f4fd83c~69F5py7-k1541315413euoutp02V DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1547818108; bh=9T7pDl1m4NIwx32hT3P+SHtwJ/zWjl57FsWGKtR9Pf4=; h=From:To:Cc:Subject:Date:References:From; b=bIZhk2X16MiryfwdMR9hhl3/1iYbAWlh1Dg/mnR/v/depIwAQhdwIbYu+8Lmu/oHr c9m/YrZFook7+7+xns93cgK8BM1oJb0Gxrb1GHw7PCoX8UJijdkG6AMNungTgDMGBY y9Ye961qJ/shrqmx21BpAw7NiDeYWsDKhSohnkls= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20190118132827eucas1p128572742fe9ec35c728ae9b49f00047a~69F41SKTp1790717907eucas1p1e; Fri, 18 Jan 2019 13:28:27 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 15.90.04806.B74D14C5; Fri, 18 Jan 2019 13:28:27 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20190118132826eucas1p2b158579e05c57a4e73edfaf376b0108c~69F37JiQL0858808588eucas1p2c; Fri, 18 Jan 2019 13:28:26 +0000 (GMT) X-AuditID: cbfec7f5-367ff700000012c6-e3-5c41d47b242c Received: from eusync3.samsung.com ( [203.254.199.213]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id BC.A6.04128.A74D14C5; Fri, 18 Jan 2019 13:28:26 +0000 (GMT) Received: from AMDC2765.digital.local ([106.116.147.25]) by eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0PLJ00HN642XSW40@eusync3.samsung.com>; Fri, 18 Jan 2019 13:28:26 +0000 (GMT) From: Marek Szyprowski To: linux-rtc@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Alexandre Belloni , Alessandro Zummo , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz Subject: [PATCH] rtc: s3c: Rewrite clock handling Date: Fri, 18 Jan 2019 14:27:54 +0100 Message-id: <20190118132754.15660-1-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHIsWRmVeSWpSXmKPExsWy7djP87rVVxxjDNY+YrFYcvEqu0X7u2Xs FhtnrGe1OH9+A7vFsdVX2CxmnN/HZLH2yF12B3aPeWuqPTat6mTz6NuyitFj+ryfTB6fN8kF sEZx2aSk5mSWpRbp2yVwZSzt2MBUcEWxYvadX8wNjKukuxg5OSQETCQ2fFjC1sXIxSEksIJR 4uyeJ1DOZ0aJhm8PmWCqzj5bwgSRWMYosXt5NzuE08AkMXvuO0aQKjYBQ4mut11sILaIgIPE 1z9vWUCKmAXeMUrsWbuGBSQhDFS0dxZEEYuAqsTRZz+ZQWxeAVuJ4493MUOsk5dYveEAM0iz hMBLVokrr05D3eEisercB1YIW1ji1fEt7BC2jMTlyd0sEA3NjBLtM2axQzg9jBJb5+xgg6iy ljh8/CJYN7MAn8SkbdOBVnAAxXklOtqEIEo8JJZd+Q52qZBArMTXLW2MExglFjAyrGIUTy0t zk1PLTbOSy3XK07MLS7NS9dLzs/dxAiMtdP/jn/dwbjvT9IhRgEORiUe3hfbHGKEWBPLiitz DzFKcDArifByrXCMEeJNSaysSi3Kjy8qzUktPsQozcGiJM5bzfAgWkggPbEkNTs1tSC1CCbL xMEp1cB4OdvzEktXl8ut+bu+Op15/bpv4Ta3pKC7Om0hmlW753gG2s0yDF0y/1XkG/v6zJoW l3jViaKJay4WTdBbml+24EvQ8xb/S9q8TmtjZpZOiNCWyK4SZ3CW3T93dtOfDQ9XsTarJIfp cB7g/ftNcu3ZaRsn7fwi1OSy/lyyj0nU94DbLau/qX9TYinOSDTUYi4qTgQAKHc+6bECAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPJMWRmVeSWpSXmKPExsVy+t/xq7pVVxxjDC7MY7NYcvEqu0X7u2Xs FhtnrGe1OH9+A7vFsdVX2CxmnN/HZLH2yF12B3aPeWuqPTat6mTz6NuyitFj+ryfTB6fN8kF sEZx2aSk5mSWpRbp2yVwZSzt2MBUcEWxYvadX8wNjKukuxg5OSQETCTOPlvC1MXIxSEksIRR 4se/lWwQThOTxJR5i9lAqtgEDCW63naB2SICDhJf/7xlASliFvjAKLHkwhlmkIQwUNHeWRBF LAKqEkef/QSL8wrYShx/vIsZYp28xOoNB5gnMHItYGRYxSiSWlqcm55bbKRXnJhbXJqXrpec n7uJERgM24793LKDsetd8CFGAQ5GJR7eF9scYoRYE8uKK3MPMUpwMCuJ8HKtcIwR4k1JrKxK LcqPLyrNSS0+xCjNwaIkznveoDJKSCA9sSQ1OzW1ILUIJsvEwSnVwDhfYP/1HNN5d8xnnXq6 /7H0c/OEhR533/4Xu7J0o2ZM5Z3oQzoLgvTnTK1+UZQj8aIy7HPFDise9d031qk97J7TYNW9 98IGU46vrWbPL5/12uQl4pkx+7HL5RKnFoOPLc9TWDaU3hZ6+HLqOYMdO/7N21ukueUo19S2 qY2WW8rjbiaxduhIyW5QYinOSDTUYi4qTgQAERf2tAICAAA= X-CMS-MailID: 20190118132826eucas1p2b158579e05c57a4e73edfaf376b0108c X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20190118132826eucas1p2b158579e05c57a4e73edfaf376b0108c References: Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org s3c_rtc_enable/disable_clk() functions were designed to be called multiple times without reference counting, because they were initially used in alarm setting/clearing functions, which can be called both when alarm is already set or not. Later however, calls to those functions have been added to other places in the driver - like time and /proc reading callbacks, what results in broken alarm if any of such events happens after the alarm has been set. Fix this by simplifying s3c_rtc_enable/disable_clk() functions to rely on proper reference counting in clock core and move alarm enable counter to s3c_rtc_setaie() function. Signed-off-by: Marek Szyprowski --- drivers/rtc/rtc-s3c.c | 67 ++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 39 deletions(-) -- 2.17.1 diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c index 04c68178c42d..e682977b4f6e 100644 --- a/drivers/rtc/rtc-s3c.c +++ b/drivers/rtc/rtc-s3c.c @@ -39,7 +39,7 @@ struct s3c_rtc { void __iomem *base; struct clk *rtc_clk; struct clk *rtc_src_clk; - bool clk_disabled; + bool alarm_enabled; const struct s3c_rtc_data *data; @@ -47,7 +47,7 @@ struct s3c_rtc { int irq_tick; spinlock_t pie_lock; - spinlock_t alarm_clk_lock; + spinlock_t alarm_lock; int ticnt_save; int ticnt_en_save; @@ -70,44 +70,28 @@ struct s3c_rtc_data { static int s3c_rtc_enable_clk(struct s3c_rtc *info) { - unsigned long irq_flags; int ret = 0; - spin_lock_irqsave(&info->alarm_clk_lock, irq_flags); + ret = clk_enable(info->rtc_clk); + if (ret) + goto out; - if (info->clk_disabled) { - ret = clk_enable(info->rtc_clk); - if (ret) + if (info->data->needs_src_clk) { + ret = clk_enable(info->rtc_src_clk); + if (ret) { + clk_disable(info->rtc_clk); goto out; - - if (info->data->needs_src_clk) { - ret = clk_enable(info->rtc_src_clk); - if (ret) { - clk_disable(info->rtc_clk); - goto out; - } } - info->clk_disabled = false; } - out: - spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags); - return ret; } static void s3c_rtc_disable_clk(struct s3c_rtc *info) { - unsigned long irq_flags; - - spin_lock_irqsave(&info->alarm_clk_lock, irq_flags); - if (!info->clk_disabled) { - if (info->data->needs_src_clk) - clk_disable(info->rtc_src_clk); - clk_disable(info->rtc_clk); - info->clk_disabled = true; - } - spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags); + if (info->data->needs_src_clk) + clk_disable(info->rtc_src_clk); + clk_disable(info->rtc_clk); } /* IRQ Handlers */ @@ -135,6 +119,7 @@ static irqreturn_t s3c_rtc_alarmirq(int irq, void *id) static int s3c_rtc_setaie(struct device *dev, unsigned int enabled) { struct s3c_rtc *info = dev_get_drvdata(dev); + unsigned long flags; unsigned int tmp; int ret; @@ -151,17 +136,19 @@ static int s3c_rtc_setaie(struct device *dev, unsigned int enabled) writeb(tmp, info->base + S3C2410_RTCALM); - s3c_rtc_disable_clk(info); + spin_lock_irqsave(&info->alarm_lock, flags); - if (enabled) { - ret = s3c_rtc_enable_clk(info); - if (ret) - return ret; - } else { + if (info->alarm_enabled && !enabled) s3c_rtc_disable_clk(info); - } + else if (!info->alarm_enabled && enabled) + ret = s3c_rtc_enable_clk(info); - return 0; + info->alarm_enabled = enabled; + spin_unlock_irqrestore(&info->alarm_lock, flags); + + s3c_rtc_disable_clk(info); + + return ret; } /* Set RTC frequency */ @@ -357,10 +344,10 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) writeb(alrm_en, info->base + S3C2410_RTCALM); - s3c_rtc_disable_clk(info); - s3c_rtc_setaie(dev, alrm->enabled); + s3c_rtc_disable_clk(info); + return 0; } @@ -491,7 +478,7 @@ static int s3c_rtc_probe(struct platform_device *pdev) return -EINVAL; } spin_lock_init(&info->pie_lock); - spin_lock_init(&info->alarm_clk_lock); + spin_lock_init(&info->alarm_lock); platform_set_drvdata(pdev, info); @@ -591,6 +578,8 @@ static int s3c_rtc_probe(struct platform_device *pdev) s3c_rtc_setfreq(info, 1); + s3c_rtc_disable_clk(info); + return 0; err_nortc: