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: 10545535 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33261112B for ; Thu, 26 Jul 2018 10:18:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2075F2AFF0 for ; Thu, 26 Jul 2018 10:18:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 145E22AFF5; Thu, 26 Jul 2018 10:18:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 98D4F2AFF0 for ; Thu, 26 Jul 2018 10:18:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ufOVw7Q6OwpSGiqmHH1y83qgTiv3vzTx1bEOi8UL824=; b=ghiG2kH5q42WBMrqaum7xoEnQ2 fg8ua6Q/bEdb6nIOobI9Y9ad7Csd6t09NnzghICtoNAqHTd5kLxlK0C8G2wIzMPpHMKHVIVdQ1M6A eHdGTZxlt1zoQG8bzWs/HVpj2OeBpBRzS4tfP3rgSR39fOp/HAO8CQdWZlDSC57Xu3XR15tG2vso+ W2Nbw8MR7SV3ODm37/b/qZoqc4HdtIFDvKxdpSLKKAZaBLpm1xq6pybwtKgyf8E4UaYktWC509FEI AuzZkT6wAc87gw5UGMx0+kZfB/ouJgAK2z159jn2XpCpg2UZtcm4k6qyEiBrZq0MYGkvVHLvZlRww TBqW+5PA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fidLu-00078m-M5; Thu, 26 Jul 2018 10:18:34 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fidKK-0005lh-Kk for linux-arm-kernel@bombadil.infradead.org; Thu, 26 Jul 2018 10:16:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=GkrEodfqJJ8aTUmNgXy4dk77JThB9rdS+3bHfRD7mVo=; b=f3JxZaCvBwAfgRSao61flGgRm u+MjpvnUs9l+mAZQN9QxLSDUBFM5EQK+WOtKyvdpv3ztcjTMWQQS04z04X9pONOaaYueGcaZq6TZD sUAWWqMn26dIfpS+VelPbg/uIYKaR2XcswuXhj89YDw4ciQ3AeoDsgrzi4WpqbjkovY+4mROwk/oY sbNE49tuk4wZB0fOueUPfQPsRdJ12HZBDACWdqOyf2Lr0nKxP6iJrtw7xT/aStRi306GI5aGlVFat d07SFk9bPIirqTSTK6YvR692hNSzY3i3pbYhYN4Kha8AQKDcgUdPc8nIcsQdhAPoi1lw1Js5h52E0 icwd8IBbw==; Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fidK6-000244-V4 for linux-arm-kernel@lists.infradead.org; Thu, 26 Jul 2018 10:16:54 +0000 Received: by mail-wr1-x443.google.com with SMTP id c13-v6so1151552wrt.1 for ; Thu, 26 Jul 2018 03:16:28 -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=pLis7I1nM3LtABR2wKpdMBaIyIp971hRNBQKoBgDBZzP7QYMSKZ5POIxulLUgajOXj lEkrqozPa72haZjAz3XAIQCNItGvEjndzRSd9cOMB/R5y53Z+q12JQ2W0GW2qwQzCJi5 3j7Ojhy+c9PyvvlHUadgqlh/o9+tVpYvs9QVIHsB3SMQKIB+Z655G70Ae5tlf1nnxVcc yHHIX0L+9K5wPzIu6D1BqEz4ewsrA1G6NJ/qZ5klr3jsMZTKDJQpeOZKV81rZrcEcUKx Cq/nb/PfgiK+PWQkvNowBwyWqpYxRlEm6OR75G2XKurq+6lF3yG33xUdSCxruo7gGZ/2 RKEg== X-Gm-Message-State: AOUpUlEtfSKTmd1QpkmpNcOu0WmBg06AvEoj2Hp9dqLGR9yfceu2cYNS vvQxX5DkmU1W8iugzkifAOi0nA== X-Google-Smtp-Source: AAOMgpfshqSVB+yt4B8TZBBkfRdnYb6qhzaljQui7ONDrjPQb1OApyF/BxrFIJiq6wjIdJ8UQ2Z2uw== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180726_061652_282861_AE958267 X-CRM114-Status: GOOD ( 22.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: baolin.wang@linaro.org, linux-kernel@vger.kernel.org, "moderated list:ARM/Mediatek SoC support" , Sudeep.Holla@arm.com, Matthias Brugger , stanley.chu@mediatek.com, "moderated list:ARM/Mediatek SoC support" MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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);