From patchwork Wed Jun 26 14:46:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 167823 Delivered-To: patch@linaro.org Received: by 2002:ac9:6410:0:0:0:0:0 with SMTP id r16csp871417ock; Wed, 26 Jun 2019 07:48:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqx8/z9PTFT58OELMflNP9dAPqNW51bz/1qfAhkFc9pG6PoYz6S7F+4LpjZHJJZKIDbkasd1 X-Received: by 2002:a17:902:76c6:: with SMTP id j6mr5880950plt.263.1561560488497; Wed, 26 Jun 2019 07:48:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561560488; cv=none; d=google.com; s=arc-20160816; b=y91cWMkvRyPjMYtoaTJVBRMCh9v+nExVWmrin1dDp5TAGTxNZs7QSM5/thPfeS/JNG UPX73/E/iDOrvrKi9vsGY0ixsf5GDQ4NRQscT3PKZCEaA38FGFD17I7jpVZ+vtpl7u98 Z1+Wxa8Lh8PCbjRWUM/rAIv3g7QVLBc3jfq+MwFtaDAJ5Vi5Pl5uMQdoPCZRT27dxRhD Z4m3pxDlxX7Fn2egpbJcx9+IQQZiejLoUXCQ1iZ718ZwTjLbpdhMLfe56G/3ygPQ1Xdn jAxIfoAFKXxShlqDFh3DLo0iwEK1It4+RXQK86fZ/hoM49SsWGcej1P+2MSRaviBlpse 4/6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=pZpH6RCNGAxgK3hStX/EjA5VCFJvxP+EAUqW2EeEzuo=; b=C1Vb+JZLkBiHbP0viGgAV73N7H6jxzIuOSgNyS4EjMeW38I4qF9Po8UP7ReOJtkTwd 0DaebELe6OcZLVd4T8xeY2sA5GT+6bhXW0Sl3ZRyhsgNn5j9u7AfNQH4smgFyN3JnNDj uDGVSSOQd0N55zSHhMpowlFBCbWgNkdgqC5GB9UX8QlHal0LfVC+j0E3Rg/x6zibPrs/ xdNKfmjuDqT73N0TtACIdFgl3r07b01V22Xo3GTHNH38eeBDxgVxFmcTvGMU1uoVDMr4 tRbdHQWNjOtEix3oMQENA3g91hLXmLptgZOO3VonJedtLeYnfc4hGu7NdniNbgzVz/re E8Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BpPX0SlV; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a64si19922100pfb.60.2019.06.26.07.48.08; Wed, 26 Jun 2019 07:48:08 -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; dkim=pass header.i=@linaro.org header.s=google header.b=BpPX0SlV; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728444AbfFZOsG (ORCPT + 30 others); Wed, 26 Jun 2019 10:48:06 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:41880 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728402AbfFZOr5 (ORCPT ); Wed, 26 Jun 2019 10:47:57 -0400 Received: by mail-wr1-f67.google.com with SMTP id c2so3060783wrm.8 for ; Wed, 26 Jun 2019 07:47:57 -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=pZpH6RCNGAxgK3hStX/EjA5VCFJvxP+EAUqW2EeEzuo=; b=BpPX0SlVOzgY+4ZuFT2sIfbqsZ8dvsqmx6zUd7W/njJpS4giirBzHLSd8Ju1XaEInW s9SBcYeTsFWVE5A+IXMRQDZRwOCKX0IfzAnWOF+b1mk75zVXwr9F/W1kU2L8/2lc8tfZ 7n5vzujBQSwViuyC04vOYNQZXoIfnaTaQEc9wJjszcyEUwdxNyiWoIWIqC9VCpBIIQvr vN907EPgPL7Wqlv8gdExkpNMfPIudb4YIR9KuA5exwVSbFOh+sT5tyhWDXVpWDdApqmZ r36yOAlNvNRZOZjhVifOyRPqxm91gmJT5pQ0Ixyt4vmwDS3f/XTxrFexr0vMZw3kVtFF TJNA== 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=pZpH6RCNGAxgK3hStX/EjA5VCFJvxP+EAUqW2EeEzuo=; b=OI5st5nCP8cKkZ5J+LL8Uho+3Yhr5BVgW+ON+M1senP8kIm0rv2mk78K68dPHokaII doQbbfSmOGxaQZgTwUfhhTwDgBGusNbiVwZNq1qm3N8Og05ZTNiE//FhDkNmLiVaKvpV h0cuQjVVZHbifJhCBHO8oPERzctRAwv1iFH98MeRXfv6e2f2CW3VQ5Khh+4hJN1B/VrO hMZWD3c7Wpslwts9Jf7pwY/ISzkFBu86E8uE5yMkIMftMOxG/2wbLbcJ5RkLSP6FBmvG g2g4TcCYc4tdouIY1dF+Ou3UjZtaO0MYPrmWlTVv5DBSGcI2kAFSSvaWBqyTHHnvS8yb HLeQ== X-Gm-Message-State: APjAAAWB+mSYQfD+fXW4gO63Paa2QV1ltcSbDyfBAU5oiW4eKhQYn5PM ap2q9IfHjVqBSCKLpBFU6z1gmQ== X-Received: by 2002:adf:fe4e:: with SMTP id m14mr4263040wrs.21.1561560476230; Wed, 26 Jun 2019 07:47:56 -0700 (PDT) Received: from mai.imgcgcw.net (26.92.130.77.rev.sfr.net. [77.130.92.26]) by smtp.gmail.com with ESMTPSA id h84sm2718557wmf.43.2019.06.26.07.47.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Jun 2019 07:47:55 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 25/25] clocksource/drivers/davinci: Add support for clocksource Date: Wed, 26 Jun 2019 16:46:51 +0200 Message-Id: <20190626144651.16742-25-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190626144651.16742-1-daniel.lezcano@linaro.org> References: <20190626144651.16742-1-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski Extend the davinci-timer driver to also register a clock source. Signed-off-by: Bartosz Golaszewski Signed-off-by: Daniel Lezcano --- drivers/clocksource/timer-davinci.c | 85 +++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) -- 2.17.1 diff --git a/drivers/clocksource/timer-davinci.c b/drivers/clocksource/timer-davinci.c index 246a5564495d..62745c962049 100644 --- a/drivers/clocksource/timer-davinci.c +++ b/drivers/clocksource/timer-davinci.c @@ -43,6 +43,8 @@ #define DAVINCI_TIMER_MIN_DELTA 0x01 #define DAVINCI_TIMER_MAX_DELTA 0xfffffffe +#define DAVINCI_TIMER_CLKSRC_BITS 32 + #define DAVINCI_TIMER_TGCR_DEFAULT \ (DAVINCI_TIMER_TIMMODE_32BIT_UNCHAINED | DAVINCI_TIMER_UNRESET) @@ -52,6 +54,16 @@ struct davinci_clockevent { unsigned int cmp_off; }; +/* + * This must be globally accessible by davinci_timer_read_sched_clock(), so + * let's keep it here. + */ +static struct { + struct clocksource dev; + void __iomem *base; + unsigned int tim_off; +} davinci_clocksource; + static struct davinci_clockevent * to_davinci_clockevent(struct clock_event_device *clockevent) { @@ -166,6 +178,53 @@ static irqreturn_t davinci_timer_irq_timer(int irq, void *data) return IRQ_HANDLED; } +static u64 notrace davinci_timer_read_sched_clock(void) +{ + return readl_relaxed(davinci_clocksource.base + + davinci_clocksource.tim_off); +} + +static u64 davinci_clocksource_read(struct clocksource *dev) +{ + return davinci_timer_read_sched_clock(); +} + +/* + * Standard use-case: we're using tim12 for clockevent and tim34 for + * clocksource. The default is making the former run in oneshot mode + * and the latter in periodic mode. + */ +static void davinci_clocksource_init_tim34(void __iomem *base) +{ + int tcr; + + tcr = DAVINCI_TIMER_ENAMODE_PERIODIC << + DAVINCI_TIMER_ENAMODE_SHIFT_TIM34; + tcr |= DAVINCI_TIMER_ENAMODE_ONESHOT << + DAVINCI_TIMER_ENAMODE_SHIFT_TIM12; + + writel_relaxed(0x0, base + DAVINCI_TIMER_REG_TIM34); + writel_relaxed(UINT_MAX, base + DAVINCI_TIMER_REG_PRD34); + writel_relaxed(tcr, base + DAVINCI_TIMER_REG_TCR); +} + +/* + * Special use-case on da830: the DSP may use tim34. We're using tim12 for + * both clocksource and clockevent. We set tim12 to periodic and don't touch + * tim34. + */ +static void davinci_clocksource_init_tim12(void __iomem *base) +{ + unsigned int tcr; + + tcr = DAVINCI_TIMER_ENAMODE_PERIODIC << + DAVINCI_TIMER_ENAMODE_SHIFT_TIM12; + + writel_relaxed(0x0, base + DAVINCI_TIMER_REG_TIM12); + writel_relaxed(UINT_MAX, base + DAVINCI_TIMER_REG_PRD12); + writel_relaxed(tcr, base + DAVINCI_TIMER_REG_TCR); +} + static void davinci_timer_init(void __iomem *base) { /* Set clock to internal mode and disable it. */ @@ -247,6 +306,32 @@ int __init davinci_timer_register(struct clk *clk, DAVINCI_TIMER_MIN_DELTA, DAVINCI_TIMER_MAX_DELTA); + davinci_clocksource.dev.rating = 300; + davinci_clocksource.dev.read = davinci_clocksource_read; + davinci_clocksource.dev.mask = + CLOCKSOURCE_MASK(DAVINCI_TIMER_CLKSRC_BITS); + davinci_clocksource.dev.flags = CLOCK_SOURCE_IS_CONTINUOUS; + davinci_clocksource.base = base; + + if (timer_cfg->cmp_off) { + davinci_clocksource.dev.name = "tim12"; + davinci_clocksource.tim_off = DAVINCI_TIMER_REG_TIM12; + davinci_clocksource_init_tim12(base); + } else { + davinci_clocksource.dev.name = "tim34"; + davinci_clocksource.tim_off = DAVINCI_TIMER_REG_TIM34; + davinci_clocksource_init_tim34(base); + } + + rv = clocksource_register_hz(&davinci_clocksource.dev, tick_rate); + if (rv) { + pr_err("Unable to register clocksource"); + return rv; + } + + sched_clock_register(davinci_timer_read_sched_clock, + DAVINCI_TIMER_CLKSRC_BITS, tick_rate); + return 0; }