From patchwork Mon Mar 30 20:17:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 46544 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6C6FA218BE for ; Mon, 30 Mar 2015 20:18:02 +0000 (UTC) Received: by lajy8 with SMTP id y8sf12204073laj.3 for ; Mon, 30 Mar 2015 13:18:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=+jdmqU/BwFitbUvgW2pHrklt74Eyic0Zk210U5QsYo8=; b=VlmY/4RDC+4Q8yKmNw6Px+KKJLsuaEk11Lu4WgsMrklHT/U+2ksUm1BnmFykzmJbMp zJvf0OPIY3EOyFA8zTw++lbKJDiJSUhhDFzr7v4XSiAy+WE9StF2jCHzUZiuamZAnEve 9QrxUsES1ZCRg8WEVwbK3qP+J/xcg+4mVE6CISmA/iXFmn2JY9paugmmqjCrAGbu3402 Xl500FUn1Y/nyYof1WEcuswiHD7RneAfomo6gGQbIEweb9oy4DThroL2pe9SmkAcKqo6 W847ecqnOF5LoiDqsr6WNws2yQiTfcME5aIaEim5VP1DZbibIWB7JErEa92xXNdl+kQX y/zg== X-Gm-Message-State: ALoCoQml/+Gzh3OU4f3+8uuQujMuGfMYwcs1S/Fn7j/zqOhTZpEoNlrawBCod97PnypTVsHGK7/7 X-Received: by 10.112.138.233 with SMTP id qt9mr1417342lbb.2.1427746681375; Mon, 30 Mar 2015 13:18:01 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.37 with SMTP id q5ls627952lag.40.gmail; Mon, 30 Mar 2015 13:18:01 -0700 (PDT) X-Received: by 10.112.162.167 with SMTP id yb7mr27427223lbb.76.1427746680916; Mon, 30 Mar 2015 13:18:00 -0700 (PDT) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id jl10si7741568lbc.38.2015.03.30.13.18.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Mar 2015 13:18:00 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by lbbug6 with SMTP id ug6so103369396lbb.3 for ; Mon, 30 Mar 2015 13:18:00 -0700 (PDT) X-Received: by 10.152.87.135 with SMTP id ay7mr12957906lab.88.1427746680813; Mon, 30 Mar 2015 13:18:00 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.57.201 with SMTP id k9csp1368127lbq; Mon, 30 Mar 2015 13:17:59 -0700 (PDT) X-Received: by 10.68.248.39 with SMTP id yj7mr61926340pbc.58.1427746678073; Mon, 30 Mar 2015 13:17:58 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qc10si16182638pac.160.2015.03.30.13.17.56; Mon, 30 Mar 2015 13:17:58 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754561AbbC3URi (ORCPT + 27 others); Mon, 30 Mar 2015 16:17:38 -0400 Received: from mail-wi0-f172.google.com ([209.85.212.172]:36535 "EHLO mail-wi0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754518AbbC3UR3 (ORCPT ); Mon, 30 Mar 2015 16:17:29 -0400 Received: by wibg7 with SMTP id g7so115720116wib.1 for ; Mon, 30 Mar 2015 13:17:28 -0700 (PDT) X-Received: by 10.180.107.99 with SMTP id hb3mr25448196wib.79.1427746648190; Mon, 30 Mar 2015 13:17:28 -0700 (PDT) Received: from mai.lan (135-224-190-109.dsl.ovh.fr. [109.190.224.135]) by mx.google.com with ESMTPSA id ha10sm17205957wjc.37.2015.03.30.13.17.26 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 30 Mar 2015 13:17:27 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de, mingo@kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, maxime.ripard@free-electrons.com, viresh.kumar@linaro.org, ben.dooks@codethink.co.uk, digetx@gmail.com, hdegoede@redhat.com, laurent.pinchart+renesas@ideasonboard.com Subject: [PATCH 06/11] clocksource: sun5i: Add clock notifiers Date: Mon, 30 Mar 2015 22:17:08 +0200 Message-Id: <1427746633-9137-6-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1427746633-9137-1-git-send-email-daniel.lezcano@linaro.org> References: <5519AEB2.8050306@linaro.org> <1427746633-9137-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: daniel.lezcano@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Maxime Ripard The parent clock of the sun5i timer is the AHB clock, which rate might change because of other devices requirements. This is for example the case on the Allwinner A31, where the DMA controller needs a minimum rate higher than the default, that is enforced after the timer driver has probed. Add clock notifiers to make sure we reflect the clock rate changes in the timer rates. Signed-off-by: Maxime Ripard Signed-off-by: Daniel Lezcano --- drivers/clocksource/timer-sun5i.c | 68 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/drivers/clocksource/timer-sun5i.c b/drivers/clocksource/timer-sun5i.c index 824ce2d..b3840f6 100644 --- a/drivers/clocksource/timer-sun5i.c +++ b/drivers/clocksource/timer-sun5i.c @@ -41,9 +41,13 @@ struct sun5i_timer { void __iomem *base; struct clk *clk; + struct notifier_block clk_rate_cb; u32 ticks_per_jiffy; }; +#define to_sun5i_timer(x) \ + container_of(x, struct sun5i_timer, clk_rate_cb) + struct sun5i_timer_clksrc { struct sun5i_timer timer; struct clocksource clksrc; @@ -152,6 +156,30 @@ static cycle_t sun5i_clksrc_read(struct clocksource *clksrc) return ~readl(cs->timer.base + TIMER_CNTVAL_LO_REG(1)); } +static int sun5i_rate_cb_clksrc(struct notifier_block *nb, + unsigned long event, void *data) +{ + struct clk_notifier_data *ndata = data; + struct sun5i_timer *timer = to_sun5i_timer(nb); + struct sun5i_timer_clksrc *cs = container_of(timer, + struct sun5i_timer_clksrc, timer); + + switch (event) { + case PRE_RATE_CHANGE: + clocksource_unregister(&cs->clksrc); + break; + + case POST_RATE_CHANGE: + clocksource_register_hz(&cs->clksrc, ndata->new_rate); + break; + + default: + break; + } + + return NOTIFY_DONE; +} + static int __init sun5i_setup_clocksource(struct device_node *node, void __iomem *base, struct clk *clk, int irq) @@ -174,6 +202,14 @@ static int __init sun5i_setup_clocksource(struct device_node *node, cs->timer.base = base; cs->timer.clk = clk; + cs->timer.clk_rate_cb.notifier_call = sun5i_rate_cb_clksrc; + cs->timer.clk_rate_cb.next = NULL; + + ret = clk_notifier_register(clk, &cs->timer.clk_rate_cb); + if (ret) { + pr_err("Unable to register clock notifier.\n"); + goto err_disable_clk; + } writel(~0, base + TIMER_INTVAL_LO_REG(1)); writel(TIMER_CTL_ENABLE | TIMER_CTL_RELOAD, @@ -188,11 +224,13 @@ static int __init sun5i_setup_clocksource(struct device_node *node, ret = clocksource_register_hz(&cs->clksrc, rate); if (ret) { pr_err("Couldn't register clock source.\n"); - goto err_disable_clk; + goto err_remove_notifier; } return 0; +err_remove_notifier: + clk_notifier_unregister(clk, &cs->timer.clk_rate_cb); err_disable_clk: clk_disable_unprepare(clk); err_free: @@ -200,6 +238,22 @@ err_free: return ret; } +static int sun5i_rate_cb_clkevt(struct notifier_block *nb, + unsigned long event, void *data) +{ + struct clk_notifier_data *ndata = data; + struct sun5i_timer *timer = to_sun5i_timer(nb); + struct sun5i_timer_clkevt *ce = container_of(timer, + struct sun5i_timer_clkevt, timer); + + if (event == POST_RATE_CHANGE) { + clockevents_update_freq(&ce->clkevt, ndata->new_rate); + ce->timer.ticks_per_jiffy = DIV_ROUND_UP(ndata->new_rate, HZ); + } + + return NOTIFY_DONE; +} + static int __init sun5i_setup_clockevent(struct device_node *node, void __iomem *base, struct clk *clk, int irq) { @@ -223,6 +277,14 @@ static int __init sun5i_setup_clockevent(struct device_node *node, void __iomem ce->timer.base = base; ce->timer.ticks_per_jiffy = DIV_ROUND_UP(rate, HZ); ce->timer.clk = clk; + ce->timer.clk_rate_cb.notifier_call = sun5i_rate_cb_clkevt; + ce->timer.clk_rate_cb.next = NULL; + + ret = clk_notifier_register(clk, &ce->timer.clk_rate_cb); + if (ret) { + pr_err("Unable to register clock notifier.\n"); + goto err_disable_clk; + } ce->clkevt.name = node->name; ce->clkevt.features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT; @@ -243,11 +305,13 @@ static int __init sun5i_setup_clockevent(struct device_node *node, void __iomem "sun5i_timer0", ce); if (ret) { pr_err("Unable to register interrupt\n"); - goto err_disable_clk; + goto err_remove_notifier; } return 0; +err_remove_notifier: + clk_notifier_unregister(clk, &ce->timer.clk_rate_cb); err_disable_clk: clk_disable_unprepare(clk); err_free: