Received: by 10.223.185.116 with SMTP id b49csp3368445wrg; Tue, 13 Feb 2018 01:16:14 -0800 (PST) X-Google-Smtp-Source: AH8x227ARtSyC0YDEraJNks2QNLLmfmyu5NX4MnzqSdvF/7i6ZdLokO2S5l00/W5/6hYrONEA0Ge X-Received: by 10.99.97.211 with SMTP id v202mr462324pgb.193.1518513374096; Tue, 13 Feb 2018 01:16:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518513374; cv=none; d=google.com; s=arc-20160816; b=fqdu01ksh36I3U8gTvfrarq6p2Z9IOn/GkweixmGZ99UsysfJQGUxmgSmt/cCJdy0X OR8Dwtf72dWdyiR+sg9j7rvaTfuHN4wzDvqzC1ioBOo52yMXbJmrbR3k84MFrOeAp93I uW15dpZsGCKfcF0qmGHmBu9qf8xRmBjb5FONnUQvmjctzBMJCWGLLUh40hBt6vKLcyH5 me6gLV8vUbHsR5RIXr0iX9xODWcQcxPEurEi4LRqyEOs8BvI/8r7i4sn6ougpPE7vUZC lE2U4Rwv31HNzKKgMHiueQ1WZK1kZtb5DzMF8RX13pvKnAG6M/qRBIrfDXvm/+BWhljY V5hQ== 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=tpKDBaR7iQfV8Lk+HWMRLGOg9OZGNoQfIMNkWYTv1C8=; b=EJuUdDx+bzhBrJhkDAd7xA8nYc7y21FwDgXShr3NVEHeWrzTL5CDbg4bnY9sXtXMWG 3w3f3nlTCC3QEF2uGpzolAOBdZGlLb+QX9Zi0MElaNr/1f1jUX577ai7QAJzAKzgrm2e 81sq/tDKA4qvru+OeAzJKQMpBjm5oVNTEDOBatuGs11dm2vpk/omAgEJY/Epw6IRNEPf C1NrjppG0ntFkz2wXzkfZvsRf15tWAbzvibs5xNBVe3+ybdzvechPbjNfy42HAYTArLg ASf1eT1SQp9EYJ1pJSpBGnTuDBiPCDOnUY+X/aeOMf81fRDwgTbafSrGHkOVB5KXZTee iVmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tkZBHcnk; 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=QUARANTINE 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 9si1083370pfo.390.2018.02.13.01.15.59; Tue, 13 Feb 2018 01:16:14 -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=tkZBHcnk; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934527AbeBMJOM (ORCPT + 99 others); Tue, 13 Feb 2018 04:14:12 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:38708 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933494AbeBMJOG (ORCPT ); Tue, 13 Feb 2018 04:14:06 -0500 Received: by mail-pg0-f65.google.com with SMTP id l24so3423216pgc.5; Tue, 13 Feb 2018 01:14:06 -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=tpKDBaR7iQfV8Lk+HWMRLGOg9OZGNoQfIMNkWYTv1C8=; b=tkZBHcnk74YR1cCwpf9TpekRAnyS4pxq2+Fef5cGXPiXjNej/6JxLBcUuptHeOrrIJ qoo280ccs8V+E+qO6mvmih/htzNGDzaL6vKp5vLl5oA2/JygFJWV9ki5xo4h5vkcNLez OY+rOJXOpv7ADMVWvX/1nQUpB6f4H8VtdKVQSRNpwVOKAJbTEJHbERvUSu2pPACEC3ge 5CdF+qJ5GFvBvaTASvU5mA6yYSdabmi3ba0V1GYXxLG1zrfKIUp5rY7g/noClQ63WiH0 y/yyVQfGnmajtl+Gu2HlTa6/Ulr2sQJUuRjcpffNo8a83JKo13BkinGOLY2jI++AlLhU z2wg== 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=tpKDBaR7iQfV8Lk+HWMRLGOg9OZGNoQfIMNkWYTv1C8=; b=s23pWwDltf0C/dmAxszoE7bKyFan7kBuSOLuV36uhcTustUVTs7kBCiezk4yYJBUR4 6HWjX4XWJ74IGJL8bmhHZJyawF/fbTcl4C3a59cpgV4ZpVR1W4B/U5ZXOt1OHc7ADroK dsprH3J581MfiUqASHQrnrhsIX3s+SYSu/piiNpHjTgyMOsxQkP/ZRLxTdlCdtWl7f+c EzRpnjyAEDjUfEQh6ye2wlc0Oz/vpf0G2n6B56skMjwViWq9Sz4+VCZj14BbBFPGnkXh hru6uPtTLEJHBrPi+5T1Md5rgdpW8qUFLSo7wYWgBh5HqgT65rioF1zN5SGLi3GQAIqv IRTA== X-Gm-Message-State: APf1xPDvoCMsi4ZKvCF+Ab8uEvJNjNwPb1VOM+SC+Gct3wgUABV5ccMj ZNz4jPJ6L5Whe5L3IjoPFU8= X-Received: by 10.98.225.20 with SMTP id q20mr577334pfh.23.1518513245658; Tue, 13 Feb 2018 01:14:05 -0800 (PST) Received: from app09.andestech.com ([118.163.51.199]) by smtp.gmail.com with ESMTPSA id o7sm23288007pgp.18.2018.02.13.01.14.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Feb 2018 01:14:05 -0800 (PST) From: Greentime Hu X-Google-Original-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, geert.uytterhoeven@gmail.com, linus.walleij@linaro.org, mark.rutland@arm.com, greg@kroah.com, ren_guo@c-sky.com, rdunlap@infradead.org, davem@davemloft.net, jonas@southpole.se, stefan.kristiansson@saunalahti.fi, shorne@gmail.com Cc: Rick Chen , green.hu@gmail.com Subject: [PATCH v7 1/3] clocksource/drivers/atcpit100: Add andestech atcpit100 timer Date: Tue, 13 Feb 2018 17:13:17 +0800 Message-Id: <129d3fd48d42bcea5c83758d8bdfecc9212ad5b8.1518505425.git.greentime@andestech.com> X-Mailer: git-send-email 2.16.1 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 Reviewed-by: Linus Walleij Add andestech atcpit100 timer --- drivers/clocksource/Kconfig | 9 ++ drivers/clocksource/Makefile | 1 + drivers/clocksource/timer-atcpit100.c | 248 ++++++++++++++++++++++++++++++++++ 3 files changed, 258 insertions(+) create mode 100644 drivers/clocksource/timer-atcpit100.c diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index b3b4ed9b6874..19d65fe0627e 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -591,4 +591,13 @@ config CLKSRC_ST_LPC Enable this option to use the Low Power controller timer as clocksource. +config ATCPIT100_TIMER + bool "ATCPIT100 timer driver" + depends on NDS32 || COMPILE_TEST + depends on HAS_IOMEM + select TIMER_OF + default NDS32 + help + This option enables support for the Andestech ATCPIT100 timers. + endmenu diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index d6dec4489d66..a79523b22e52 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile @@ -76,3 +76,4 @@ obj-$(CONFIG_H8300_TMR16) += h8300_timer16.o obj-$(CONFIG_H8300_TPU) += h8300_tpu.o obj-$(CONFIG_CLKSRC_ST_LPC) += clksrc_st_lpc.o obj-$(CONFIG_X86_NUMACHIP) += numachip.o +obj-$(CONFIG_ATCPIT100_TIMER) += timer-atcpit100.o diff --git a/drivers/clocksource/timer-atcpit100.c b/drivers/clocksource/timer-atcpit100.c new file mode 100644 index 000000000000..2190096cffa3 --- /dev/null +++ b/drivers/clocksource/timer-atcpit100.c @@ -0,0 +1,248 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2005-2017 Andes Technology Corporation +/* + * Andestech ATCPIT100 Timer Device Driver Implementation + * Rick Chen, Andes Technology Corporation + * + */ + +#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, + }, + + /* + * FIXME: we currently only support clocking using PCLK + * and using EXTCLK is not supported in the driver. + */ + .of_clk = { + .name = "PCLK", + } +}; + +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); -- 2.16.1