From patchwork Sat Oct 3 09:19:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Chou X-Patchwork-Id: 525865 X-Patchwork-Delegate: thomas@wytron.com.tw Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 4840E1402A8 for ; Sat, 3 Oct 2015 19:19:39 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 53DFC4B804; Sat, 3 Oct 2015 11:19:35 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HgzNSZSaYvDO; Sat, 3 Oct 2015 11:19:35 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DB3284B80D; Sat, 3 Oct 2015 11:19:34 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EDBDA4B83A for ; Sat, 3 Oct 2015 11:19:28 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ks0jy7THH-Dh for ; Sat, 3 Oct 2015 11:19:28 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from www.wytron.com.tw (220-134-43-68.HINET-IP.hinet.net [220.134.43.68]) by theia.denx.de (Postfix) with ESMTP id 21C7A4B804 for ; Sat, 3 Oct 2015 11:19:25 +0200 (CEST) Received: from localhost.localdomain (unknown [192.168.1.250]) by www.wytron.com.tw (Postfix) with ESMTP id 4B698D00343; Sat, 3 Oct 2015 17:19:22 +0800 (CST) From: Thomas Chou To: u-boot@lists.denx.de Date: Sat, 3 Oct 2015 17:19:20 +0800 Message-Id: <1443863960-8314-2-git-send-email-thomas@wytron.com.tw> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1443863960-8314-1-git-send-email-thomas@wytron.com.tw> References: <1443446357-21393-1-git-send-email-thomas@wytron.com.tw> <1443863960-8314-1-git-send-email-thomas@wytron.com.tw> Cc: Marek Vasut , clsee@altera.com, lftan@altera.com Subject: [U-Boot] [PATCH v3 2/2] nios2: convert altera timer to driver model X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Convert altera timer to driver model. Signed-off-by: Thomas Chou --- v2 fix coding style. v3 doc dts binding. arch/nios2/cpu/Makefile | 2 +- arch/nios2/cpu/timer.c | 65 -------------- common/board_f.c | 3 +- configs/nios2-generic_defconfig | 2 + doc/device-tree-bindings/timer/altera_timer.txt | 19 ++++ drivers/timer/Kconfig | 7 ++ drivers/timer/Makefile | 1 + drivers/timer/altera_timer.c | 110 ++++++++++++++++++++++++ include/configs/nios2-generic.h | 6 -- 9 files changed, 141 insertions(+), 74 deletions(-) delete mode 100644 arch/nios2/cpu/timer.c create mode 100644 doc/device-tree-bindings/timer/altera_timer.txt create mode 100644 drivers/timer/altera_timer.c diff --git a/arch/nios2/cpu/Makefile b/arch/nios2/cpu/Makefile index c85e261..3fe7847 100644 --- a/arch/nios2/cpu/Makefile +++ b/arch/nios2/cpu/Makefile @@ -7,5 +7,5 @@ extra-y = start.o obj-y = exceptions.o -obj-y += cpu.o interrupts.o sysid.o timer.o traps.o +obj-y += cpu.o interrupts.o sysid.o traps.o obj-y += fdt.o diff --git a/arch/nios2/cpu/timer.c b/arch/nios2/cpu/timer.c deleted file mode 100644 index b8aa9dd..0000000 --- a/arch/nios2/cpu/timer.c +++ /dev/null @@ -1,65 +0,0 @@ -/* - * (C) Copyright 2000-2002 - * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * (C) Copyright 2004, Psyent Corporation - * Scott McNutt - * - * SPDX-License-Identifier: GPL-2.0+ - */ - -#include -#include -#include -#include - -struct nios_timer { - u32 status; /* Timer status reg */ - u32 control; /* Timer control reg */ - u32 periodl; /* Timeout period low */ - u32 periodh; /* Timeout period high */ - u32 snapl; /* Snapshot low */ - u32 snaph; /* Snapshot high */ -}; - -/* status register */ -#define NIOS_TIMER_TO (1 << 0) /* Timeout */ -#define NIOS_TIMER_RUN (1 << 1) /* Timer running */ - -/* control register */ -#define NIOS_TIMER_ITO (1 << 0) /* Timeout interrupt enable */ -#define NIOS_TIMER_CONT (1 << 1) /* Continuous mode */ -#define NIOS_TIMER_START (1 << 2) /* Start timer */ -#define NIOS_TIMER_STOP (1 << 3) /* Stop timer */ - -/*************************************************************************/ -unsigned long notrace timer_read_counter(void) -{ - struct nios_timer *tmr = (struct nios_timer *)CONFIG_SYS_TIMER_BASE; - u32 val; - - /* Trigger update */ - writel(0x0, &tmr->snapl); - - /* Read timer value */ - val = readl(&tmr->snapl) & 0xffff; - val |= (readl(&tmr->snaph) & 0xffff) << 16; - - return ~val; -} - -int timer_init(void) -{ - struct nios_timer *tmr = (struct nios_timer *)CONFIG_SYS_TIMER_BASE; - - writel(0, &tmr->status); - writel(0, &tmr->control); - writel(NIOS_TIMER_STOP, &tmr->control); - - writel(0xffff, &tmr->periodl); - writel(0xffff, &tmr->periodh); - - writel(NIOS_TIMER_CONT | NIOS_TIMER_START, &tmr->control); - - return 0; -} diff --git a/common/board_f.c b/common/board_f.c index d0a9ff7..613332e 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -795,8 +795,7 @@ static init_fnc_t init_sequence_f[] = { init_timebase, #endif #if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \ - defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \ - defined(CONFIG_NIOS2) + defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) timer_init, /* initialize timer */ #endif #ifdef CONFIG_SYS_ALLOC_DPRAM diff --git a/configs/nios2-generic_defconfig b/configs/nios2-generic_defconfig index 707ee33..dac0b62 100644 --- a/configs/nios2-generic_defconfig +++ b/configs/nios2-generic_defconfig @@ -18,3 +18,5 @@ CONFIG_NET_RANDOM_ETHADDR=y CONFIG_ALTERA_PIO=y CONFIG_ALTERA_JTAG_UART=y CONFIG_ALTERA_JTAG_UART_BYPASS=y +CONFIG_DM_TIMER=y +CONFIG_ALTERA_TIMER=y diff --git a/doc/device-tree-bindings/timer/altera_timer.txt b/doc/device-tree-bindings/timer/altera_timer.txt new file mode 100644 index 0000000..904a584 --- /dev/null +++ b/doc/device-tree-bindings/timer/altera_timer.txt @@ -0,0 +1,19 @@ +Altera Timer + +Required properties: + +- compatible : should be "altr,timer-1.0" +- reg : Specifies base physical address and size of the registers. +- interrupt-parent: phandle of the interrupt controller +- interrupts : Should contain the timer interrupt number +- clock-frequency : The frequency of the clock that drives the counter, in Hz. + +Example: + +timer { + compatible = "altr,timer-1.0"; + reg = <0x00400000 0x00000020>; + interrupt-parent = <&cpu>; + interrupts = <11>; + clock-frequency = <125000000>; +}; diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig index 5228e26..5a5558d 100644 --- a/drivers/timer/Kconfig +++ b/drivers/timer/Kconfig @@ -8,4 +8,11 @@ config DM_TIMER lib/time.c. But now implemented by the uclass. The first timer will be used. +config ALTERA_TIMER + bool "Altera Timer support" + depends on DM_TIMER + help + Select this to enable an timer for Altera devices. Please find + details on the "Embedded Peripherals IP User Guide" of Altera. + endmenu diff --git a/drivers/timer/Makefile b/drivers/timer/Makefile index a24179a..0c7398f 100644 --- a/drivers/timer/Makefile +++ b/drivers/timer/Makefile @@ -5,3 +5,4 @@ # obj-$(CONFIG_DM_TIMER) += timer-uclass.o +obj-$(CONFIG_ALTERA_TIMER) += altera_timer.o diff --git a/drivers/timer/altera_timer.c b/drivers/timer/altera_timer.c new file mode 100644 index 0000000..25856d9 --- /dev/null +++ b/drivers/timer/altera_timer.c @@ -0,0 +1,110 @@ +/* + * (C) Copyright 2000-2002 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * (C) Copyright 2004, Psyent Corporation + * Scott McNutt + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +struct altera_timer_regs { + u32 status; /* Timer status reg */ + u32 control; /* Timer control reg */ + u32 periodl; /* Timeout period low */ + u32 periodh; /* Timeout period high */ + u32 snapl; /* Snapshot low */ + u32 snaph; /* Snapshot high */ +}; + +struct altera_timer_platdata { + struct altera_timer_regs *regs; + unsigned long timerclk; +}; + +/* control register */ +#define ALTERA_TIMER_CONT (1 << 1) /* Continuous mode */ +#define ALTERA_TIMER_START (1 << 2) /* Start timer */ +#define ALTERA_TIMER_STOP (1 << 3) /* Stop timer */ + +static int altera_timer_get_count(struct udevice *dev, unsigned long *count) +{ + struct altera_timer_platdata *plat = dev->platdata; + struct altera_timer_regs *const regs = plat->regs; + u32 val; + + /* Trigger update */ + writel(0x0, ®s->snapl); + + /* Read timer value */ + val = readl(®s->snapl) & 0xffff; + val |= (readl(®s->snaph) & 0xffff) << 16; + *count = ~val; + + return 0; +} + +static int altera_timer_get_clock(struct udevice *dev, unsigned long *freq) +{ + struct altera_timer_platdata *plat = dev->platdata; + + *freq = plat->timerclk; + + return 0; +} + +static int altera_timer_probe(struct udevice *dev) +{ + struct altera_timer_platdata *plat = dev->platdata; + struct altera_timer_regs *const regs = plat->regs; + + writel(0, ®s->status); + writel(0, ®s->control); + writel(ALTERA_TIMER_STOP, ®s->control); + + writel(0xffff, ®s->periodl); + writel(0xffff, ®s->periodh); + writel(ALTERA_TIMER_CONT | ALTERA_TIMER_START, ®s->control); + + return 0; +} + +static int altera_timer_ofdata_to_platdata(struct udevice *dev) +{ + struct altera_timer_platdata *plat = dev_get_platdata(dev); + + plat->regs = ioremap(dev_get_addr(dev), + sizeof(struct altera_timer_regs)); + plat->timerclk = fdtdec_get_int(gd->fdt_blob, dev->of_offset, + "clock-frequency", 0); + + return 0; +} + +static const struct dm_timer_ops altera_timer_ops = { + .get_count = altera_timer_get_count, + .get_clock = altera_timer_get_clock, +}; + +static const struct udevice_id altera_timer_ids[] = { + { .compatible = "altr,timer-1.0", }, + { } +}; + +U_BOOT_DRIVER(altera_timer) = { + .name = "altera_timer", + .id = UCLASS_TIMER, + .of_match = altera_timer_ids, + .ofdata_to_platdata = altera_timer_ofdata_to_platdata, + .platdata_auto_alloc_size = sizeof(struct altera_timer_platdata), + .probe = altera_timer_probe, + .ops = &altera_timer_ops, +}; diff --git a/include/configs/nios2-generic.h b/include/configs/nios2-generic.h index 90ccbd1..ae19676 100644 --- a/include/configs/nios2-generic.h +++ b/include/configs/nios2-generic.h @@ -27,12 +27,6 @@ #define CONFIG_SYS_CONSOLE_INFO_QUIET /* Suppress console info */ /* - * TIMER - */ -#define CONFIG_SYS_TIMER_COUNTS_DOWN -#define CONFIG_SYS_TIMER_RATE CONFIG_SYS_TIMER_FREQ - -/* * BOOTP options */ #define CONFIG_BOOTP_BOOTFILESIZE