Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3056388ybi; Tue, 2 Jul 2019 01:16:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqxhTzXjQpH5UzDezfccoHYpXT5IC2ljDhRAEJtNMbzScU2J5HN7FnTMT2ozmeEiR7ONC06U X-Received: by 2002:a17:902:b487:: with SMTP id y7mr33157939plr.219.1562055394616; Tue, 02 Jul 2019 01:16:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562055394; cv=none; d=google.com; s=arc-20160816; b=tFks/1+xd+Kpjja1VK+wS9HwhQUzbk0SepRzsTkZa5ULxYs0dxIrS0jarFPv6JNTAa zG8k0cvLz46mmpKGIbYwomPtoXxujdyXOS+MQgigaR8p9VMbQtKZxHsbnBK4faed6GKu 1nmhFniFyoghFHtz56wnHIXYuzVdXKHzQlosKaJxKAywSp3tAuInpjkYL3xZGKsgHiOo 1B7ed+v8cIS22honI0nlE8XfWzJcJKDmHhlpCcP6JIfpuWDnRmWmbndJipYXSIaEXMdU VLqpkztkkYdSUzaRdsA74I8VA/2UHHyXiFZjYxj1rtoARD7WfXH2MX2FEYpHY06IjE+x BEKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=CBOhzp88iY7qWGUyriDvYxZqmCLE21vydfHMzQ4Dz5Q=; b=hNSNZnKu85DzccvuqjkHqRZ+AAkF00JJBEdV1vaV/tq771PmoOHxDRQfWZniB4O/Sz bJn2i7gkLynuDWFRvIpJvY1wxCRwdjjPe/SZBH0qpFXxcn8/Yp7YDSCwRTH2219/TINl WFWBvHKr9b5KyAcnKwPu/OUHE3AykY89u6r6KdxaKHYDpEtob3O2nzCh0Kp0+HPefbt2 JukRrIc8YDb8m7WUO96rKdngR14G1MMgQLsDf0yfWaOuicwdQkm9baZRkWXS0B1js4mx RI+3jWExXDnvXN/n1pYrN2bz34lCt17h0+regezClxH2oBq6FTZEVv5rOYzQH6vdUxTZ CiDQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3si12238885pgs.135.2019.07.02.01.16.20; Tue, 02 Jul 2019 01:16:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727995AbfGBIQD (ORCPT + 99 others); Tue, 2 Jul 2019 04:16:03 -0400 Received: from inva020.nxp.com ([92.121.34.13]:49204 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727742AbfGBIEd (ORCPT ); Tue, 2 Jul 2019 04:04:33 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id A09EE1A0BBD; Tue, 2 Jul 2019 10:04:30 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 9D25D1A0BBA; Tue, 2 Jul 2019 10:04:19 +0200 (CEST) Received: from titan.ap.freescale.net (TITAN.ap.freescale.net [10.192.208.233]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 7E87E402EB; Tue, 2 Jul 2019 16:04:04 +0800 (SGT) From: Anson.Huang@nxp.com To: daniel.lezcano@linaro.org, tglx@linutronix.de, robh+dt@kernel.org, mark.rutland@arm.com, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, leonard.crestez@nxp.com, viresh.kumar@linaro.org, daniel.baluta@nxp.com, ping.bai@nxp.com, l.stach@pengutronix.de, abel.vesa@nxp.com, andrew.smirnov@gmail.com, ccaione@baylibre.com, angus@akkea.ca, agx@sigxcpu.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Linux-imx@nxp.com Subject: [PATCH RESEND V4 1/5] clocksource: timer-of: Support getting clock frequency from DT Date: Tue, 2 Jul 2019 15:55:09 +0800 Message-Id: <20190702075513.17451-1-Anson.Huang@nxp.com> X-Mailer: git-send-email 2.14.1 X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anson Huang More and more platforms use platform driver model for clock driver, so the clock driver is NOT ready during timer initialization phase, it will cause timer initialization failed. To support those platforms with upper scenario, introducing a new flag TIMER_OF_CLOCK_FREQUENCY which is mutually exclusive with TIMER_OF_CLOCK flag to support getting timer clock frequency from DT's timer node, the property name should be "clock-frequency", then of_clk operations can be skipped. User needs to select either TIMER_OF_CLOCK_FREQUENCY or TIMER_OF_CLOCK flag if want to use timer-of driver to initialize the clock rate. Signed-off-by: Anson Huang --- Changes since V3: - use hardcoded "clock-frequency" instead of adding new variable prop_name; - add pre-condition check for TIMER_OF_CLOCK and TIMER_OF_CLOCK_FREQUENCY, they MUST be exclusive. --- drivers/clocksource/timer-of.c | 29 +++++++++++++++++++++++++++++ drivers/clocksource/timer-of.h | 7 ++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/drivers/clocksource/timer-of.c b/drivers/clocksource/timer-of.c index 8054228..858f684 100644 --- a/drivers/clocksource/timer-of.c +++ b/drivers/clocksource/timer-of.c @@ -161,11 +161,30 @@ static __init int timer_of_base_init(struct device_node *np, return 0; } +static __init int timer_of_clk_frequency_init(struct device_node *np, + struct of_timer_clk *of_clk) +{ + int ret; + u32 rate; + + ret = of_property_read_u32(np, "clock-frequency", &rate); + if (!ret) { + of_clk->rate = rate; + of_clk->period = DIV_ROUND_UP(rate, HZ); + } + + return ret; +} + int __init timer_of_init(struct device_node *np, struct timer_of *to) { + unsigned long clock_flags = TIMER_OF_CLOCK | TIMER_OF_CLOCK_FREQUENCY; int ret = -EINVAL; int flags = 0; + if ((to->flags & clock_flags) == clock_flags) + return ret; + if (to->flags & TIMER_OF_BASE) { ret = timer_of_base_init(np, &to->of_base); if (ret) @@ -180,6 +199,13 @@ int __init timer_of_init(struct device_node *np, struct timer_of *to) flags |= TIMER_OF_CLOCK; } + if (to->flags & TIMER_OF_CLOCK_FREQUENCY) { + ret = timer_of_clk_frequency_init(np, &to->of_clk); + if (ret) + goto out_fail; + flags |= TIMER_OF_CLOCK_FREQUENCY; + } + if (to->flags & TIMER_OF_IRQ) { ret = timer_of_irq_init(np, &to->of_irq); if (ret) @@ -201,6 +227,9 @@ int __init timer_of_init(struct device_node *np, struct timer_of *to) if (flags & TIMER_OF_CLOCK) timer_of_clk_exit(&to->of_clk); + if (flags & TIMER_OF_CLOCK_FREQUENCY) + to->of_clk.rate = 0; + if (flags & TIMER_OF_BASE) timer_of_base_exit(&to->of_base); return ret; diff --git a/drivers/clocksource/timer-of.h b/drivers/clocksource/timer-of.h index a5478f3..a08e108 100644 --- a/drivers/clocksource/timer-of.h +++ b/drivers/clocksource/timer-of.h @@ -4,9 +4,10 @@ #include -#define TIMER_OF_BASE 0x1 -#define TIMER_OF_CLOCK 0x2 -#define TIMER_OF_IRQ 0x4 +#define TIMER_OF_BASE 0x1 +#define TIMER_OF_CLOCK 0x2 +#define TIMER_OF_IRQ 0x4 +#define TIMER_OF_CLOCK_FREQUENCY 0x8 struct of_timer_irq { int irq; -- 2.7.4