From patchwork Thu Mar 30 21:01:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 96329 Delivered-To: patches@linaro.org Received: by 10.140.89.233 with SMTP id v96csp425822qgd; Thu, 30 Mar 2017 14:01:39 -0700 (PDT) X-Received: by 10.84.139.195 with SMTP id 61mr1289304plr.109.1490907699370; Thu, 30 Mar 2017 14:01:39 -0700 (PDT) Return-Path: Received: from mail-pg0-x231.google.com (mail-pg0-x231.google.com. [2607:f8b0:400e:c05::231]) by mx.google.com with ESMTPS id f25si2933891pga.275.2017.03.30.14.01.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Mar 2017 14:01:39 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::231 as permitted sender) client-ip=2607:f8b0:400e:c05::231; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::231 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-pg0-x231.google.com with SMTP id x125so50224034pgb.0 for ; Thu, 30 Mar 2017 14:01:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Sks8Sagi24pL/smluG770Iu4P0/TW2iAOHsWFzinTPk=; b=LDRPZHylcdglvTj0YDNS9an9n30hDL+xIXSxQo90oKvgr21vHfAIeVAUvFeKDmZisw c3kz1kLEr+PIHo1g8ZYB/laE3sriqBvvPAdK8/BksYriw5stVAKxtc3k5StdJPqO+3lY 43VbN9R5St2G2xyq/AdeQrc5ULX0j0TAlQ29o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Sks8Sagi24pL/smluG770Iu4P0/TW2iAOHsWFzinTPk=; b=QjiS92q/WmYpQhYyyfz3VcIMyT/FZbDIPTrUiNyL+Kj8C2vpBRVbld9XlepoELatWn X9MPWbu81Z/cdEzCxgoDGJGOjf30GYwmCay1p2y2QCJY+7l9KU/a/oFlBrtWzZNBs8g1 ThbS+LxpDJD8cDgHaxAc/7b8r2hZs3H7fhhtEcq7VCo4RJg5tJck8+1TZwH5FEnJY5VC xnWWdcyG1thB0JZCYY/VdCQ03hcQgJ/pZ8AJrYa2U0JXFzKWVBIuI3c+iE0T8nFNY2rM Rsg48IGLF4tbpR/16YkU2iAIZbLo4GUlTTsArxXoaZd72aKMZ5R+TfwH+pjHRgI2okY8 keWA== X-Gm-Message-State: AFeK/H3mKF29v2UwApWi3h4AzUtU5M0VVnQWzTbtX6Jgbn4XGzet9S0/DBjvE2Ozq/JIDGT+Ys8= X-Received: by 10.98.214.4 with SMTP id r4mr1111231pfg.185.1490907699058; Thu, 30 Mar 2017 14:01:39 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id y7sm6162626pfk.93.2017.03.30.14.01.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Mar 2017 14:01:37 -0700 (PDT) From: John Stultz To: lkml Cc: Nicolai Stange , Ingo Molnar , Thomas Gleixner , Daniel Lezcano , Richard Cochran , Prarit Bhargava , Stephen Boyd , John Stultz Subject: [PATCH 4/9] clocksource: em_sti: Compute rate before registration Date: Thu, 30 Mar 2017 14:01:19 -0700 Message-Id: <1490907684-11186-5-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490907684-11186-1-git-send-email-john.stultz@linaro.org> References: <1490907684-11186-1-git-send-email-john.stultz@linaro.org> From: Nicolai Stange With the upcoming NTP correction related rate adjustments to be implemented in the clockevents core, the latter needs to get informed about every rate change of a clockevent device made after its registration. Currently, em_sti violates this requirement in that it registers its clockevent device with a dummy rate and sets its final rate through clockevents_config() called from its ->set_state_oneshot(). This patch moves the setting of the clockevent device's rate to its registration. I checked all current em_sti users in arch/arm/mach-shmobile and right now, none of them changes any rate in any clock tree relevant to em_sti after their respective time_init(). Since all em_sti instances are created after time_init(), none of them should ever observe any clock rate changes. - Determine the ->rate value in em_sti_probe() at device probing rather than at first usage. - Set the clockevent device's rate at its registration. - Although not strictly necessary for the upcoming clockevent core changes, set the clocksource's rate at its registration for consistency. Cc: Ingo Molnar Cc: Thomas Gleixner Cc: Daniel Lezcano Cc: Richard Cochran Cc: Prarit Bhargava Cc: Stephen Boyd Signed-off-by: Nicolai Stange Signed-off-by: John Stultz --- drivers/clocksource/em_sti.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) -- 2.7.4 diff --git a/drivers/clocksource/em_sti.c b/drivers/clocksource/em_sti.c index 6c0955a..bc48cbf 100644 --- a/drivers/clocksource/em_sti.c +++ b/drivers/clocksource/em_sti.c @@ -84,9 +84,6 @@ static int em_sti_enable(struct em_sti_priv *p) return ret; } - /* configure channel, periodic mode and maximum timeout */ - p->rate = clk_get_rate(p->clk); - /* reset the counter */ em_sti_write(p, STI_SET_H, 0x40000000); em_sti_write(p, STI_SET_L, 0x00000000); @@ -205,13 +202,9 @@ static u64 em_sti_clocksource_read(struct clocksource *cs) static int em_sti_clocksource_enable(struct clocksource *cs) { - int ret; struct em_sti_priv *p = cs_to_em_sti(cs); - ret = em_sti_start(p, USER_CLOCKSOURCE); - if (!ret) - __clocksource_update_freq_hz(cs, p->rate); - return ret; + return em_sti_start(p, USER_CLOCKSOURCE); } static void em_sti_clocksource_disable(struct clocksource *cs) @@ -240,8 +233,7 @@ static int em_sti_register_clocksource(struct em_sti_priv *p) dev_info(&p->pdev->dev, "used as clock source\n"); - /* Register with dummy 1 Hz value, gets updated in ->enable() */ - clocksource_register_hz(cs, 1); + clocksource_register_hz(cs, p->rate); return 0; } @@ -263,7 +255,6 @@ static int em_sti_clock_event_set_oneshot(struct clock_event_device *ced) dev_info(&p->pdev->dev, "used for oneshot clock events\n"); em_sti_start(p, USER_CLOCKEVENT); - clockevents_config(&p->ced, p->rate); return 0; } @@ -294,8 +285,7 @@ static void em_sti_register_clockevent(struct em_sti_priv *p) dev_info(&p->pdev->dev, "used for clock events\n"); - /* Register with dummy 1 Hz value, gets updated in ->set_state_oneshot() */ - clockevents_config_and_register(ced, 1, 2, 0xffffffff); + clockevents_config_and_register(ced, p->rate, 2, 0xffffffff); } static int em_sti_probe(struct platform_device *pdev) @@ -344,6 +334,15 @@ static int em_sti_probe(struct platform_device *pdev) return ret; } + ret = clk_enable(p->clk); + if (ret < 0) { + dev_err(&p->pdev->dev, "cannot enable clock\n"); + clk_unprepare(p->clk); + return ret; + } + p->rate = clk_get_rate(p->clk); + clk_disable(p->clk); + raw_spin_lock_init(&p->lock); em_sti_register_clockevent(p); em_sti_register_clocksource(p);