Received: by 10.223.164.202 with SMTP id h10csp1589743wrb; Mon, 27 Nov 2017 04:57:00 -0800 (PST) X-Google-Smtp-Source: AGs4zMbWMpU9Y/Y9YoagF3H/TeqMZ1FWK2SCDIRJ+fWXO+4JsJuvY62uamqMtYVY9If+3WDB+V2M X-Received: by 10.84.198.67 with SMTP id o61mr27540446pld.261.1511787420617; Mon, 27 Nov 2017 04:57:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511787420; cv=none; d=google.com; s=arc-20160816; b=zloDIHV1O09TZQIvgX11DGLIr7EPfNfXr8BozB1dQ6CeOC1IdpOKe6uWLLGVif8rnx Q/8spgOWRgrbg04HEmwo3qbhB6gbOfsr/9KI/QanFKQ8e+zEFPNOkhuHGMP/e8VOsz5E 8R/hUqzU5Yfd+JEl56vLIUoG3jH1PCiTHZ52DsjVjiFck8Mr1q7KJirv+gdeYxcaZq82 UG4ytNUNYMAAbRBUyXeoxB+knuIQYf1ktzBrXNoJYD/TV73wce7s/eqcsRBkKFNMnfO6 qPGkn5CsY3W2PMXE1KGCk1CKsw35mylUZaiw2vHW/h+OlrhEZki1JAazm0VRAMl4AXtI aF9A== 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:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=MiEWXBAutYwBbLHZrzoFgN/iILUKj0/KAKkHW3WzCbU=; b=LcLN689pIoWyAO+02pIwTdWLma+K6/uk0kMenn1TZRx7ftJ0o2fwNcL5CozBYhVFfg +lzLxBF4oWEKJVfFpOGuSOWfrCFi5rnv74n5BSaMdKTlB+4H/tjmgjvbVHQied3Jaj/t 4SDbriCfyGFg1Dp5xXwHFr0MAbtaEXcwV6Z9RgX1a5Wv3esOSUTw+uFrNQehP8bYkpyQ e2Jdqns07tggOTsXBX5SwTfixS0vt0+sqbLEYbhBfWnfe10E1rNNqAVk01xRgDG3DD2t +dFewpuftuauxbLLK2G2QOz/7Hxb3ueHi1KFc2d8xK8plMP8EU1e3aXrq9ed+p1YNmkH 4dIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MJSj9rfr; 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=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bi10si17823161plb.561.2017.11.27.04.56.48; Mon, 27 Nov 2017 04:57:00 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=MJSj9rfr; 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=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752872AbdK0Mz1 (ORCPT + 77 others); Mon, 27 Nov 2017 07:55:27 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33814 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752827AbdK0MzU (ORCPT ); Mon, 27 Nov 2017 07:55:20 -0500 Received: by mail-pf0-f195.google.com with SMTP id k24so7585091pfb.1; Mon, 27 Nov 2017 04:55:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=MiEWXBAutYwBbLHZrzoFgN/iILUKj0/KAKkHW3WzCbU=; b=MJSj9rfrU6WsjGuYotyELwDHnOZ6runTMSEZ49KHDQAHfbjOJ6bjWTlcqMd1Od0kUl FA81yAXD6HJN8rY2quQa/q+yxKmUQmeaH5ZcjgPoPPXmaPzplS3s4zTnzSZf4qD0aQOr 460jLPkls8Jp43q6TaVpd4TGU2p3vTA5Kcn/YToQ2N7xSSqzrAMC2K5tDAQyhrEeOVPC mzjniP/SlRe42VdTgw/oDIBn/4BJ3C5SlMklOs59S89bMGsrf1t7tEyV7/zQBdkt1eQL 8xTfDJDq6xcBCDArj+HPm38QEwFlz7bNVcv9aBMXn+F1aHTFjEEPOvu8hrWDKMcpq27w h/Jg== 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:in-reply-to:references; bh=MiEWXBAutYwBbLHZrzoFgN/iILUKj0/KAKkHW3WzCbU=; b=Y26zKvR7aJBkohv0mcGd1QqtxianWLjzZ5KaD0r558N/2lQB1RmEA0o1WL/RB9v+SJ 0y4ThbElWJ0z7CCkGHCvoXWL9hYlx+iLTF/Xsyk0TRGLfFhvDqh6DPAXk/lw0aCqaKe9 LVrTzy0g9VtgEnX2Km+a1/cCaMkSYz5mHtvWYmp/M17YO5brOXX/Al8ty3ickk8cPn+x /FGxhta4gvBLLJ0ruZML7bNvErjVrnF9k/iYAvxYrnCP6M2/R+F1/0GmkYKbPqYyAd24 jYZCPe0N0RpJN0LAmqpdHPmUbR5SCisWuhp6wOTO8ZXRtQmkdcnPwTGDtuy0zdKd5GoU HPeA== X-Gm-Message-State: AJaThX7gKF8mARI5p8b/Inqft2DwIjxNg45BGn+qmGujTxoDEp6TmMCE ea/5x31eMqN/mpMaDULaLgI= X-Received: by 10.101.66.11 with SMTP id c11mr35922159pgq.169.1511787319468; Mon, 27 Nov 2017 04:55:19 -0800 (PST) Received: from app09.andestech.com ([118.163.51.199]) by smtp.gmail.com with ESMTPSA id w64sm55225459pfj.62.2017.11.27.04.55.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Nov 2017 04:55:18 -0800 (PST) From: Greentime Hu To: greentime@andestech.com, linux-kernel@vger.kernel.org, arnd@arndb.de, linux-arch@vger.kernel.org, tglx@linutronix.de, jason@lakedaemon.net, marc.zyngier@arm.com, robh+dt@kernel.org, netdev@vger.kernel.org, deanbo422@gmail.com, devicetree@vger.kernel.org, viro@zeniv.linux.org.uk, dhowells@redhat.com, will.deacon@arm.com, daniel.lezcano@linaro.org, linux-serial@vger.kernel.org Cc: Rick Chen , green.hu@gmail.com Subject: [PATCH v2 33/35] clocksource/drivers/atcpit100: Add andestech atcpit100 timer Date: Mon, 27 Nov 2017 20:28:20 +0800 Message-Id: <672e0b3843953d1ab69bc19baf1a0f217ec1b1fa.1511785528.git.green.hu@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rick Chen ATCPIT100 is often used on the Andes architecture, This timer provide 4 PIT channels. Each PIT channel is a multi-function timer, can be configured as 32,16,8 bit timers or PWM as well. For system timer it will set channel 1 32-bit timer0 as clock source and count downwards until underflow and restart again. It also set channel 0 32-bit timer0 as clock event and count downwards until condition match. It will generate an interrupt for handling periodically. Signed-off-by: Rick Chen Signed-off-by: Greentime Hu --- drivers/clocksource/timer-atcpit100.c | 247 +++++++++++++++++++++++++++++++++ 1 file changed, 247 insertions(+) create mode 100644 drivers/clocksource/timer-atcpit100.c diff --git a/drivers/clocksource/timer-atcpit100.c b/drivers/clocksource/timer-atcpit100.c new file mode 100644 index 0000000..76ddd2f --- /dev/null +++ b/drivers/clocksource/timer-atcpit100.c @@ -0,0 +1,247 @@ +/* + * Andestech ATCPIT100 Timer Device Driver Implementation + * + * Copyright (C) 2017 Andes Technology Corporation + * Rick Chen, Andes Technology Corporation + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "timer-of.h" + +/* + * Definition of register offsets + */ + +/* ID and Revision Register */ +#define ID_REV 0x0 + +/* Configuration Register */ +#define CFG 0x10 + +/* Interrupt Enable Register */ +#define INT_EN 0x14 +#define CH_INT_EN(c, i) ((1<event_handler(evt); + + return IRQ_HANDLED; +} + +static struct timer_of to = { + .flags = TIMER_OF_IRQ | TIMER_OF_CLOCK | TIMER_OF_BASE, + + .clkevt = { + .name = "atcpit100_tick", + .rating = 300, + .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT, + .set_state_shutdown = atcpit100_clkevt_shutdown, + .set_state_periodic = atcpit100_clkevt_set_periodic, + .set_state_oneshot = atcpit100_clkevt_set_oneshot, + .tick_resume = atcpit100_clkevt_shutdown, + .set_next_event = atcpit100_clkevt_next_event, + .cpumask = cpu_all_mask, + }, + + .of_irq = { + .handler = atcpit100_timer_interrupt, + .flags = IRQF_TIMER | IRQF_IRQPOLL, + }, +}; + +static u64 notrace atcpit100_timer_sched_read(void) +{ + return ~readl(timer_of_base(&to) + CH1_CNT); +} + +static int __init atcpit100_timer_init(struct device_node *node) +{ + int ret; + u32 val; + void __iomem *base; + + ret = timer_of_init(node, &to); + if (ret) + return ret; + + base = timer_of_base(&to); + + sched_clock_register(atcpit100_timer_sched_read, 32, + timer_of_rate(&to)); + + ret = clocksource_mmio_init(base + CH1_CNT, + node->name, timer_of_rate(&to), 300, 32, + clocksource_mmio_readl_down); + + if (ret) { + pr_err("Failed to register clocksource\n"); + return ret; + } + + /* clear channel 0 timer0 interrupt */ + atcpit100_timer_clear_interrupt(base); + + clockevents_config_and_register(&to.clkevt, timer_of_rate(&to), + TIMER_SYNC_TICKS, 0xffffffff); + atcpit100_ch0_tmr0_en(base); + atcpit100_ch1_tmr0_en(base); + atcpit100_clocksource_start(base); + atcpit100_clkevt_time_start(base); + + /* Enable channel 0 timer0 interrupt */ + val = readl(base + INT_EN); + writel(val | CH0INT0EN, base + INT_EN); + + return ret; +} + +TIMER_OF_DECLARE(atcpit100, "andestech,atcpit100", atcpit100_timer_init); -- 1.7.9.5 From 1586624378858898050@xxx Tue Dec 12 23:55:19 +0000 2017 X-GM-THRID: 1586624378858898050 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread