Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp28069ybj; Wed, 6 May 2020 10:47:18 -0700 (PDT) X-Google-Smtp-Source: APiQypJkxSauaQTPjjHpjVYNJ9LkiCOn3Eq+cUYV2WmQ6dC6VfgJCJHiRz2oMpU+O28A0fgHZKU/ X-Received: by 2002:aa7:cdcb:: with SMTP id h11mr7799575edw.264.1588787238822; Wed, 06 May 2020 10:47:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588787238; cv=none; d=google.com; s=arc-20160816; b=sCb/WWZadjmanXzNSIXwPo5RlZu5SUm8/TmhpZk4lWXq2G0iOu4qWBuE36wVO39/zo 8mJTCalwc854IuNNCHpofpkQLf5yg+WrRTQ5PD+ZgHyUT8N9DkhTOWc8uGfRi3ZgHigr 1PHm+n16yjK6JXRmhsfhZnHRbhNM9EB/NrgS4zsL7BXw6Y3IGJX32AVqYEwfVLqPz/jL 1j528q+MmGDJkV9n1Gyf1kzWKZyBaEJkQAhCaJgCRKCzbHqFFsdMsVxOCakissipYehJ YA9XuFYZd1XUaRbPfxUurmb15CWRJgG1R5LVqVtVvPwUktnGvoo/4JKnnKlPG2aysV+R Q/DA== 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=vR74JyarEUY5a3GUxu1d1FByVBAVaP2ZG5cRQbu+a2g=; b=a+hoE9LdMdNav8jvB6NQhxTqpSDjEABZ3szg9d436uvqhNgDl5ubpDEfpsJF71VZNd Q2ElGiQ6JNpbuM5amv6ZOrQVwW9TxskCoTkwxcbVEH36I0fCObrcv4ZbC6k3fwPB8cQk ojfR1IXkfjFGNX3fIQFEeGU6Rs4lxGjE/fxD0WIcYR9w8yOwRvnX81pbvNuQx7yDVhAa kI5/cnU+DoAMvWwQPNaEXu2RlGGNLlmM8JpHKiDu+UguZSVQ5UcXSWTKjiMs1oIvMa/2 mBfCd2DuApKW2AeBNJlOxU4YGRU6gVCq1DgkMuYFKf8BhK4GCfLChfYWMWGDcLY53XHt wN9A== 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 s19si1638196ejz.320.2020.05.06.10.46.55; Wed, 06 May 2020 10:47:18 -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 S1730476AbgEFRow (ORCPT + 99 others); Wed, 6 May 2020 13:44:52 -0400 Received: from mail.baikalelectronics.com ([87.245.175.226]:32958 "EHLO mail.baikalelectronics.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730349AbgEFRob (ORCPT ); Wed, 6 May 2020 13:44:31 -0400 Received: from localhost (unknown [127.0.0.1]) by mail.baikalelectronics.ru (Postfix) with ESMTP id 6D5E08000BB3; Wed, 6 May 2020 17:44:27 +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 DyI7IDSfg4EM; Wed, 6 May 2020 20:44:26 +0300 (MSK) From: 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 v2 19/20] mips: cevt-r4k: Update the r4k-clockevent frequency in sync with CPU Date: Wed, 6 May 2020 20:42:37 +0300 Message-ID: <20200506174238.15385-20-Sergey.Semin@baikalelectronics.ru> In-Reply-To: <20200506174238.15385-1-Sergey.Semin@baikalelectronics.ru> References: <20200306124807.3596F80307C2@mail.baikalelectronics.ru> <20200506174238.15385-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 From: Serge Semin 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: linux-pm@vger.kernel.org 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..f5b72fb7d5ee 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 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 cpufreq_notifier = { + .notifier_call = cpufreq_callback, +}; + +static int __init register_cpufreq_notifier(void) +{ + return cpufreq_register_notifier(&cpufreq_notifier, + CPUFREQ_TRANSITION_NOTIFIER); + +} +core_initcall(register_cpufreq_notifier); + +#endif /* !CONFIG_CPU_FREQ */ + int r4k_clockevent_init(void) { unsigned long flags = IRQF_PERCPU | IRQF_TIMER | IRQF_SHARED; -- 2.25.1