Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1450394ybk; Thu, 21 May 2020 07:11:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1LNeUoteTbi9hZ+SWNoLKz5NWIeQOA5Ao+lmpR9ZTDwiOuPX8E6UZlRA6M0KvqsR29cdN X-Received: by 2002:a17:906:d8c1:: with SMTP id re1mr4000370ejb.184.1590070300842; Thu, 21 May 2020 07:11:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590070300; cv=none; d=google.com; s=arc-20160816; b=Shyq10t4S7WiVWL13IGEReFSX4HXLwMQXfESKeqM87tMX00bdrILMqGcsMjO8Qlfkk MSF00KlADLVSMATF31wUpio/J7RA+RPUuRiEhiWHfpOKjRRdbQWVSsPBnsz7VkmDqjrt L3a1Jy+ttu2wfoWVrgteTfJLChu77kBl9HACxN035sQksIbkn03eA65VskF/pm20w+MN yWeRolhjkN+yDqjye9z9cu+Qm54peEWFZQP97QIeUSVrdRFhmcBNd3lb0vyfk/orovh+ 0nuejJ2vPHYuUYUSHx1o44xrhTv+ASyV8PtTBEe49B6hW2OGB9R7gEedNGgV1DSR/LS2 PqWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=NQBvq5FciPPo2kz3Tkbaz+9VRHScH8ZIwIbjkYVeuAA=; b=Q4W4z72CUrIiChtJ2wUaYonMB3/ilrVe0qmAa5bYTY6wew2w34Dq0lgGwpza+mWel2 kS2r2wyCqQquUInruWS9TgsuACb2fnBH8hx9YyPXuGseNOnvi0kqVkNGVZQMmku9RghN MuKb4fIRy1bgESwkQRXOZ9YSQysDp12echjUBiIV4qJArW4hm90m8Iie8tgS0UZ5q6A7 /RhZGGO+S2Kq6cKhXIjV8LuTk1TQzdFV13TBfwerMmtnaEni6a8T1V4Jd4acaLTOjJTf OEPNPDl0YFiIp6K7qcqZLrOQ2Uc+rkFTA8afngdCcEeA3sSKzx4ZhiEXQQLJgVpozA/H DwyA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v13si3405952edi.386.2020.05.21.07.11.15; Thu, 21 May 2020 07:11:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727937AbgEUOJL (ORCPT + 99 others); Thu, 21 May 2020 10:09:11 -0400 Received: from mail.baikalelectronics.com ([87.245.175.226]:38652 "EHLO mail.baikalelectronics.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729919AbgEUOJG (ORCPT ); Thu, 21 May 2020 10:09:06 -0400 Received: from localhost (unknown [127.0.0.1]) by mail.baikalelectronics.ru (Postfix) with ESMTP id 9D76880005EE; Thu, 21 May 2020 14:09:02 +0000 (UTC) X-Virus-Scanned: amavisd-new at baikalelectronics.ru Received: from mail.baikalelectronics.ru ([127.0.0.1]) by localhost (mail.baikalelectronics.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id M1UySfoXILvC; Thu, 21 May 2020 17:09:02 +0300 (MSK) From: Serge Semin To: Thomas Bogendoerfer CC: Serge Semin , Serge Semin , Alexey Malahov , Paul Burton , Ralf Baechle , Greg Kroah-Hartman , Arnd Bergmann , Rob Herring , , afzal mohammed , , Subject: [PATCH v4 13/13] mips: cevt-r4k: Update the r4k-clockevent frequency in sync with CPU Date: Thu, 21 May 2020 17:07:24 +0300 Message-ID: <20200521140725.29571-14-Sergey.Semin@baikalelectronics.ru> In-Reply-To: <20200521140725.29571-1-Sergey.Semin@baikalelectronics.ru> References: <20200521140725.29571-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Due to being embedded into the CPU cores MIPS count/compare timer frequency is changed together with the CPU clocks alteration. In case if frequency really changes the kernel clockevent framework must be notified, otherwise the kernel timers won't work correctly. Fix this by calling clockevents_update_freq() for each r4k clockevent handlers registered per available CPUs. Traditionally MIPS r4k-clock are clocked with CPU frequency divided by 2. But this isn't true for some of the platforms. Due to this we have to save the basic CPU frequency, so then use it to scale the initial timer frequency (mips_hpt_frequency) and pass the updated value further to the clockevent framework. Signed-off-by: Serge Semin Cc: Alexey Malahov Cc: Thomas Bogendoerfer Cc: Paul Burton Cc: Ralf Baechle Cc: Greg Kroah-Hartman Cc: Arnd Bergmann Cc: Rob Herring Cc: devicetree@vger.kernel.org --- arch/mips/kernel/cevt-r4k.c | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/arch/mips/kernel/cevt-r4k.c b/arch/mips/kernel/cevt-r4k.c index 17a9cbb8b3df..995ad9e69ded 100644 --- a/arch/mips/kernel/cevt-r4k.c +++ b/arch/mips/kernel/cevt-r4k.c @@ -8,6 +8,7 @@ */ #include #include +#include #include #include #include @@ -250,6 +251,49 @@ unsigned int __weak get_c0_compare_int(void) return MIPS_CPU_IRQ_BASE + cp0_compare_irq; } +#ifdef CONFIG_CPU_FREQ + +static unsigned long mips_ref_freq; + +static int r4k_cpufreq_callback(struct notifier_block *nb, + unsigned long val, void *data) +{ + struct cpufreq_freqs *freq = data; + struct clock_event_device *cd; + unsigned long rate; + int cpu; + + if (!mips_ref_freq) + mips_ref_freq = freq->old; + + if (val == CPUFREQ_POSTCHANGE) { + rate = cpufreq_scale(mips_hpt_frequency, mips_ref_freq, + freq->new); + + for_each_cpu(cpu, freq->policy->cpus) { + cd = &per_cpu(mips_clockevent_device, cpu); + + clockevents_update_freq(cd, rate); + } + } + + return 0; +} + +static struct notifier_block r4k_cpufreq_notifier = { + .notifier_call = r4k_cpufreq_callback, +}; + +static int __init r4k_register_cpufreq_notifier(void) +{ + return cpufreq_register_notifier(&r4k_cpufreq_notifier, + CPUFREQ_TRANSITION_NOTIFIER); + +} +core_initcall(r4k_register_cpufreq_notifier); + +#endif /* !CONFIG_CPU_FREQ */ + int r4k_clockevent_init(void) { unsigned long flags = IRQF_PERCPU | IRQF_TIMER | IRQF_SHARED; -- 2.25.1