Received: by 10.223.164.202 with SMTP id h10csp61707wrb; Tue, 7 Nov 2017 02:56:19 -0800 (PST) X-Google-Smtp-Source: ABhQp+S2EtnT3Y2gwr4SfwZz7a6tx8lCFFr6S6lTEHgMkaggva8cnof4pqHPvGJvEnbtv6+1AdKk X-Received: by 10.101.71.132 with SMTP id e4mr2126875pgs.206.1510052179371; Tue, 07 Nov 2017 02:56:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510052179; cv=none; d=google.com; s=arc-20160816; b=a4lABEFSlLWmlFbrrlWyyNd0HXGdGBEbTL8hbxvCkrNGLeWG09vNBSCrHHLCMy26u2 BifCvu1xMeZC1EbugKEGbXaaqV+55d37EMqYKtrVnbCSP/F3Ma7DxI1K3+d9pwM03BdF 5Xst01nicaTJQ2eE5d8ICNRKv51VOHcgI99Q2F0s1gvvdcP2j2H/khIwQ+tVy/X/QpXa VYPrtg93gj/PeZVJF2PsfdhcgnJAhVTWL4A4dJf0uigrU85jAWpVBQ6g4icEhUclYTbS q8EZSruqpB2wzEgVEgx0QL8Mf8leqC6YsrvrKiGqQe/a4d39W7N7BdYpdJ1f5QQPg4/+ 1KAA== 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=YdXb9T1u7t3XWHtvfrGtuvkho6TRAlG6izmjb9uK3Rs=; b=bWTBLO2aWlAWvoVV3vjQZ2PdAJ5STkivxt8v3+rNhEfZumGx+7JM51D1UD1QXqyfMA yLKuakhiJYgId4+LHhgw1Osv1+tNLv4J6dT1Av2eEhM/TlAfe1R4u+tFzBdd+NURj9al 4dTh4NdPGKChuzxlmzgvCMbCIWN/kfq7ywzMEFvWXCstdtUWXvs21FbCm1BvID54q60h 5qZkD6gmR43f8VDSKlD3Ujfqe8UTErHUQzibNO5wm5NVat5pPqagGdPJQ2Queqcs/pNG UEdjZ0mhKJ1agIlLcFXqGmYPxmZ1GlMnuhyU6qhMCOvjvLxTVfYOsvLTroiKfuEBn+QC /aRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TM8BvRcu; 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 m25si862651pge.354.2017.11.07.02.56.06; Tue, 07 Nov 2017 02:56:19 -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=TM8BvRcu; 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 S1755635AbdKGHod (ORCPT + 91 others); Tue, 7 Nov 2017 02:44:33 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:50844 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754872AbdKGHoa (ORCPT ); Tue, 7 Nov 2017 02:44:30 -0500 Received: by mail-pg0-f65.google.com with SMTP id y5so10369869pgq.7; Mon, 06 Nov 2017 23:44:29 -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; bh=YdXb9T1u7t3XWHtvfrGtuvkho6TRAlG6izmjb9uK3Rs=; b=TM8BvRcuGAvboZczNN8/sosJQVNTXfvjOgWOTnZCYz8mbl4VoRk9TKNzeQH/o3w+pI QMgEpQZuk3JXD39CCvxJgkzpt4yew/JVtMc0BQpoBwJTuhAimCAmh1n334CyJh82epuA 9X/F6rHmZs2x2S7SW3ARGUO7/6YrhBf2knGhLeQZY0EjJyWnDR89OaJdLaCd9AwZLbB8 hm4lZSivqg0u0yL2JC8bHj1ewX+ZKO8iyQfos4H5YL1wOaM/hc1zk2qLWZ0KZd+AGqf7 uL5yBIW+o20LMR6BdBEXi7Urr1K0fR+PnysWx+P5BQEeU+5mANMBNAaA0VIWcwWPAsgI EvQw== 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=YdXb9T1u7t3XWHtvfrGtuvkho6TRAlG6izmjb9uK3Rs=; b=A6WBu01LCPvswt671QhBomwGhKc3VAHSSBzzgeKv5Y8ria5DEA3h+8XAtR+/iWspd+ pzxv9LfO/VgRke0z83PIVCyBHYdprnPpXailB6XTKhajMaK8X1HAK7+CqFA1Plb9ibks mGygRv6eeK2mILmZ6Gjx+lgGk/20iNKx8eXrLwMdc/MnTYpsJrOCh8GiBag7MLtnHLV5 OVXe2HZl6MTl60f9+CG1X+fMNVYNnSgdx+QXIaWd8qvI4AQ3ZCCtgmm7galiVkpQ3sqT eLSWpi76fBHNtoCBhB292ISyEjTkZD0vUir2S4b/BwDQK3wTWx/T2NVJhkUsd+Z8IQ76 DrJg== X-Gm-Message-State: AMCzsaVznd5f2pBL9dxc5Djw8GmqbrPz4WznprIvC9JBQlDjvEunHwKN AkBliGsBxOaycYY/wYhlxpM= X-Received: by 10.98.24.80 with SMTP id 77mr19825800pfy.195.1510040669430; Mon, 06 Nov 2017 23:44:29 -0800 (PST) Received: from app09.andestech.com ([118.163.51.199]) by smtp.gmail.com with ESMTPSA id y10sm1473256pfl.186.2017.11.06.23.44.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 23:44:28 -0800 (PST) From: Rick Chen To: daniel.lezcano@linaro.org, tglx@linutronix.de, robh@kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, rick@andestech.com Cc: Rick Chen , Greentime Hu Subject: [PATCH v3 1/3] clocksource/drivers/atcpit100: Add andestech atcpit100 timer Date: Tue, 7 Nov 2017 15:19:51 +0800 Message-Id: <1510039193-32522-2-git-send-email-rickchen36@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1510039193-32522-1-git-send-email-rickchen36@gmail.com> References: <1510039193-32522-1-git-send-email-rickchen36@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 32-bit timer0 as clock source and count downwards until underflow and restart again. It also set 32-bit timer1 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 | 199 ++++++++++++++++++++++++++++++++++ 1 file changed, 199 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..1a5538b --- /dev/null +++ b/drivers/clocksource/timer-atcpit100.c @@ -0,0 +1,199 @@ +/* + * Andestech ATCPIT100 Timer Device Driver Implementation + * + * Copyright (C) 2016 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 + +void __iomem *base; +static u32 freq; + +/* + * 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 irqaction timer1_irq = { + .name = "Timer Tick", + .flags = IRQF_TIMER | IRQF_IRQPOLL, + .handler = timer1_interrupt, + .dev_id = &clockevent_atcpit100 +}; + +static void __init atcpit100_clockevent_init(int irq) +{ + struct clock_event_device *evt = &clockevent_atcpit100; + + evt->mult = div_sc(freq, NSEC_PER_SEC, evt->shift); + evt->max_delta_ns = clockevent_delta2ns(0xffffffff, evt); + evt->min_delta_ns = clockevent_delta2ns(3, evt); + clockevents_register_device(evt); + setup_irq(irq, &timer1_irq); +} + +static int __init atcpit100_init(struct device_node *dev) +{ + int irq; + + base = of_iomap(dev, 0); + if (!base) { + pr_warn("Can't remap registers"); + return -ENXIO; + } + + if (of_property_read_u32(dev, "clock-frequency", &freq)) { + pr_warn("Can't read clock-frequency"); + return -EINVAL; + } + irq = irq_of_parse_and_map(dev, 0); + + if (irq <= 0) { + pr_warn("Failed to map timer IRQ\n"); + return -EINVAL; + } + pr_info("ATCPIT100 timer 1 installed on IRQ %d, with clock %d at %d HZ. in %p\n", + irq, freq, HZ, base); + writel(APB_CLK|TMR_32, base + CH_CTL(0)); + writel(readl(base + INT_EN) | CH_INT_EN(0, 0), base + INT_EN); + writel(readl(base + CH_EN) | CH_TMR_EN(0, 0), base + CH_EN); + atcpit100_clocksource_init(); + atcpit100_clockevent_init(irq); + + return 0; +} + +TIMER_OF_DECLARE(atcpit100, "andestech,atcpit100", atcpit100_init); -- 2.7.4 From 1583392466009239553@xxx Tue Nov 07 07:45:27 +0000 2017 X-GM-THRID: 1583392466009239553 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread