From patchwork Thu Jul 26 10:15:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 142952 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp274055ljj; Thu, 26 Jul 2018 03:16:33 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfIFDoeNWYVy4igUEz6VkE7DgzvLQM1yl+3jr5WmfjXLyKzXxJuumQDN68I94EGP6anBZ8r X-Received: by 2002:a63:b91c:: with SMTP id z28-v6mr1380876pge.22.1532600193283; Thu, 26 Jul 2018 03:16:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532600193; cv=none; d=google.com; s=arc-20160816; b=sptcghapG/4n3ecKkTpN2gtDRSwzPgYuEBtEPxaWswY5WsvEVo8ZG1TEHq9DnPZ7WE cZnB/xoKi1L4U050PX3UxKABG5iVrCs6AKyD8mP9s2sR3S+ITyUA4fntJCF0MfO8XXlh KLkC9qIUKOCc/D9l3H9TSOD62Ce2vn26X0oKe4pQx2jPud/7nencanWkl5h6Br8CGdgw dKjWDfVYlM0f63fRKDeInJ5kOil+5Tp8C6bMSogoTmrgXlScFYOO4r0v9/NvSt7p9uGY 1zgPLMMHOiHYCfov3WkUx33TZNuhFJ3po00MDlkqqPMwZgtALFBrbeF7TIDeil1SPNTC m5ZA== 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:arc-authentication-results; bh=GkrEodfqJJ8aTUmNgXy4dk77JThB9rdS+3bHfRD7mVo=; b=vRMzdY4gjtR6LNkPbi7x37UnOI4JP61CJEHLYsifhYxonpe+vRVM5UfHpUEty1nRJ2 fvY9YGEJ3eaz+6gDhJ9ZI6v0lAQhRRD9P/JjrO5CKhWLW2j82dN9eMA7/CUjsytXMf8/ RaxL9muDhgQ283+SMyy+t97xr2gD/lGrsUiv+FukA3t5OjwPxEeSCmtR61PO77p5lDed Bc3u1lv793EcSXkUe/eCD8AkvsygO5rtVBuvUXggFulFBV8NgMvUCdpQ9NQSIILP+bhg 1rshHmKGvp5bEp7hw4skGtM8Aua9rWzGE5SDvsWqKefuSj7bUmbdjcZiPwHHlmoOx/J7 XXlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DzQ4Hh00; 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 g4-v6si982794plm.181.2018.07.26.03.16.33; Thu, 26 Jul 2018 03:16:33 -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=DzQ4Hh00; 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 S1729521AbeGZLcj (ORCPT + 31 others); Thu, 26 Jul 2018 07:32:39 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36094 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729031AbeGZLci (ORCPT ); Thu, 26 Jul 2018 07:32:38 -0400 Received: by mail-wr1-f67.google.com with SMTP id h9-v6so1150401wro.3 for ; Thu, 26 Jul 2018 03:16:27 -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=GkrEodfqJJ8aTUmNgXy4dk77JThB9rdS+3bHfRD7mVo=; b=DzQ4Hh001XPzoeCUk+CQceEsyAYL5j0ou1m/1yNPw9UpF73LRVq7yxbFjtmH67D3g7 vWDP0Y754GJV6ouq5V25e/9cBhCVSD56X9Nf4fIo8KEm/t80SOMEVtbqUHhWAiB6PP/l DqbNQWui2jGizvLiGXVq3f+JehzIF0QFdclY0= 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=GkrEodfqJJ8aTUmNgXy4dk77JThB9rdS+3bHfRD7mVo=; b=lEszjOb10j2FJ0AIxO8AGIhAcpQP9dnHiLRdOZzKsNDD+2LSiLtifKYO4MR+QBp4VA VysDU+2r6cZbe7nYui5WWPTn5Ze1pvrC7+x+ZAkSl9xDlzQxqXPbSelVTi5jL1sJlY+a BLNohC5gTQFRG51BsJ5n1/w/w3m73PRxHzl1ArP1CV9HJmIjKrrMMZ2w4hDfSQF+p1Db jFeVpJ4r69pjcLxJQ5DBQu6rAouKV70H7F20hpu2BTbKpJABIXRc3nlMdnKcRQXzGSX9 95KZybmGQUYpIucv530gkViD0xj0WAv6Vjy2NjhfLhXuNkr9id6d4JIvtDwhz1m3GJoF zxwg== X-Gm-Message-State: AOUpUlG0HvEOLVGMQArABau/YtNuFuoOBGR7C45uwqQRpS2bzZMbC5gd JZKQgk0ZVDu3io8dfpZTuDJRtw== X-Received: by 2002:adf:e584:: with SMTP id l4-v6mr1024964wrm.190.1532600186925; Thu, 26 Jul 2018 03:16:26 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:35bd:fbdf:74b5:3f51]) by smtp.gmail.com with ESMTPSA id f6-v6sm957303wrp.30.2018.07.26.03.16.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Jul 2018 03:16:26 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de, mingo@kernel.org Cc: linux-kernel@vger.kernel.org, stanley.chu@mediatek.com, baolin.wang@linaro.org, Sudeep.Holla@arm.com, Matthias Brugger , linux-arm-kernel@lists.infradead.org (moderated list:ARM/Mediatek SoC support), linux-mediatek@lists.infradead.org (moderated list:ARM/Mediatek SoC support) Subject: [PATCH 6/7] clocksource/drivers/timer-mediatek: Add support for system timer Date: Thu, 26 Jul 2018 12:15:29 +0200 Message-Id: <1532600131-28168-6-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1532600131-28168-1-git-send-email-daniel.lezcano@linaro.org> References: <014f94f9-54d4-1ee0-aa89-67ca5d221989@free.fr> <1532600131-28168-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stanley Chu This patch adds a new "System Timer" on the Mediatek SoCs. The System Timer is introduced as an always-on timer being clockevent device for tick-broadcasting. For clock, it is driven by 13 MHz system clock. The implementation uses the system clock with no clock source divider. For interrupt, the clock event timer can be used by all cores. Signed-off-by: Stanley Chu Signed-off-by: Daniel Lezcano --- drivers/clocksource/timer-mediatek.c | 104 ++++++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/drivers/clocksource/timer-mediatek.c b/drivers/clocksource/timer-mediatek.c index e57c4d7..eb10321 100644 --- a/drivers/clocksource/timer-mediatek.c +++ b/drivers/clocksource/timer-mediatek.c @@ -56,8 +56,86 @@ #define GPT_CNT_REG(val) (0x08 + (0x10 * (val))) #define GPT_CMP_REG(val) (0x0C + (0x10 * (val))) +/* system timer */ +#define SYST_BASE (0x40) + +#define SYST_CON (SYST_BASE + 0x0) +#define SYST_VAL (SYST_BASE + 0x4) + +#define SYST_CON_REG(to) (timer_of_base(to) + SYST_CON) +#define SYST_VAL_REG(to) (timer_of_base(to) + SYST_VAL) + +/* + * SYST_CON_EN: Clock enable. Shall be set to + * - Start timer countdown. + * - Allow timeout ticks being updated. + * - Allow changing interrupt functions. + * + * SYST_CON_IRQ_EN: Set to allow interrupt. + * + * SYST_CON_IRQ_CLR: Set to clear interrupt. + */ +#define SYST_CON_EN BIT(0) +#define SYST_CON_IRQ_EN BIT(1) +#define SYST_CON_IRQ_CLR BIT(4) + static void __iomem *gpt_sched_reg __read_mostly; +static void mtk_syst_ack_irq(struct timer_of *to) +{ + /* Clear and disable interrupt */ + writel(SYST_CON_IRQ_CLR | SYST_CON_EN, SYST_CON_REG(to)); +} + +static irqreturn_t mtk_syst_handler(int irq, void *dev_id) +{ + struct clock_event_device *clkevt = dev_id; + struct timer_of *to = to_timer_of(clkevt); + + mtk_syst_ack_irq(to); + clkevt->event_handler(clkevt); + + return IRQ_HANDLED; +} + +static int mtk_syst_clkevt_next_event(unsigned long ticks, + struct clock_event_device *clkevt) +{ + struct timer_of *to = to_timer_of(clkevt); + + /* Enable clock to allow timeout tick update later */ + writel(SYST_CON_EN, SYST_CON_REG(to)); + + /* + * Write new timeout ticks. Timer shall start countdown + * after timeout ticks are updated. + */ + writel(ticks, SYST_VAL_REG(to)); + + /* Enable interrupt */ + writel(SYST_CON_EN | SYST_CON_IRQ_EN, SYST_CON_REG(to)); + + return 0; +} + +static int mtk_syst_clkevt_shutdown(struct clock_event_device *clkevt) +{ + /* Disable timer */ + writel(0, SYST_CON_REG(to_timer_of(clkevt))); + + return 0; +} + +static int mtk_syst_clkevt_resume(struct clock_event_device *clkevt) +{ + return mtk_syst_clkevt_shutdown(clkevt); +} + +static int mtk_syst_clkevt_oneshot(struct clock_event_device *clkevt) +{ + return 0; +} + static u64 notrace mtk_gpt_read_sched_clock(void) { return readl_relaxed(gpt_sched_reg); @@ -186,6 +264,30 @@ static struct timer_of to = { }, }; +static int __init mtk_syst_init(struct device_node *node) +{ + int ret; + + to.clkevt.features = CLOCK_EVT_FEAT_DYNIRQ | CLOCK_EVT_FEAT_ONESHOT; + to.clkevt.set_state_shutdown = mtk_syst_clkevt_shutdown; + to.clkevt.set_state_oneshot = mtk_syst_clkevt_oneshot; + to.clkevt.tick_resume = mtk_syst_clkevt_resume; + to.clkevt.set_next_event = mtk_syst_clkevt_next_event; + to.of_irq.handler = mtk_syst_handler; + + ret = timer_of_init(node, &to); + if (ret) + goto err; + + clockevents_config_and_register(&to.clkevt, timer_of_rate(&to), + TIMER_SYNC_TICKS, 0xffffffff); + + return 0; +err: + timer_of_cleanup(&to); + return ret; +} + static int __init mtk_gpt_init(struct device_node *node) { int ret; @@ -218,9 +320,9 @@ static int __init mtk_gpt_init(struct device_node *node) mtk_gpt_enable_irq(&to, TIMER_CLK_EVT); return 0; - err: timer_of_cleanup(&to); return ret; } TIMER_OF_DECLARE(mtk_mt6577, "mediatek,mt6577-timer", mtk_gpt_init); +TIMER_OF_DECLARE(mtk_mt6765, "mediatek,mt6765-timer", mtk_syst_init);