From patchwork Thu Mar 23 00:20:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 1760064 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=mailbox.org header.i=@mailbox.org header.a=rsa-sha256 header.s=mail20150812 header.b=OnDT5l1y; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.a=rsa-sha256 header.s=mail20150812 header.b=mN1p+Dj9; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PhmHD2sSNz247J for ; Thu, 23 Mar 2023 11:21:44 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3173885D66; Thu, 23 Mar 2023 01:21:21 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=mailbox.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; secure) header.d=mailbox.org header.i=@mailbox.org header.b="OnDT5l1y"; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="mN1p+Dj9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 21C2385925; Thu, 23 Mar 2023 01:21:15 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [IPv6:2001:67c:2050:0:465::201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C2B6D85D5D for ; Thu, 23 Mar 2023 01:21:03 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=mailbox.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=marek.vasut+renesas@mailbox.org Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4PhmGP3vp0z9scm; Thu, 23 Mar 2023 01:21:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1679530861; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aLyc5XMmpUWEP/N6+Put8ql1b3LjJubYUJBPDvA/zUk=; b=OnDT5l1yaErhWfURUoH5l0FdYqeBZkoiazvwcge4w/jie88FoGfxzda2m8gYIgAoCjwTpX l1lWgBm8TqwFwCiepu0aOR8VhzVsbTP5466GrJS5lhiNv6CMmi2tjzICYRf+lI8sPE5icc Q6JuDWtjo2SyTDP/QOvAoLp6mqAyIXAabtw1kL9wQbcw7Z4MAsQhRRu7XCJSssXd/W83S9 uquRfNNjkW14G21RGFHtMI3OrGCjAZ5CGNvXYZ/4nhWv/VcsYNE4x+OSBJojst874R4LHO Vf1BnoHv3nD51puO5W1Ez4LkIW0FAurk15IEAb4Q6xEZsL2O1G/dOJ+nOPJxpg== From: Marek Vasut DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1679530859; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aLyc5XMmpUWEP/N6+Put8ql1b3LjJubYUJBPDvA/zUk=; b=mN1p+Dj9mtrJrz2Ut5oQxusTjjhxtCT7sJijXCYOcoKSwP8nhEftQYmeru2rzxWUHKzFEa N5ylNoOZSNUi2mM8niojE3eqjiPGJgelvVSZUh/E6eT88Dp/ORuP9fQ+XdE6drQWdw62kh bzOMNJjaCVc/i6hCVP6kZTvHAypi8ITiuP93OpWLGQkiVJE4RUq/g9kyYlTa+m8EenIIsz 0KJNEbmfGfgEU1vwtBNcTcA5+8ENA+HWFWw1FDxALkjCuasMsYpu+IBhtNztnvy8cenFl8 JOH2Pad8LJb99MPYgNxfCLXVJtblyROANoE20t9DBMZLbLlTazgSzxjkeD2UAA== To: u-boot@lists.denx.de Cc: Marek Vasut , Angelo Dureghello , Huan Wang , Simon Glass , Stefan Roese , Tom Rini Subject: [PATCH v2 2/3] arch: m68k: Introduce trivial PIT based timer Date: Thu, 23 Mar 2023 01:20:40 +0100 Message-Id: <20230323002041.46158-2-marek.vasut+renesas@mailbox.org> In-Reply-To: <20230323002041.46158-1-marek.vasut+renesas@mailbox.org> References: <20230323002041.46158-1-marek.vasut+renesas@mailbox.org> MIME-Version: 1.0 X-MBO-RS-ID: a7ff0bc637e6c2c7c5b X-MBO-RS-META: tkeq1mac4djb1ag34u9z1zo4c79w4kr7 X-Rspamd-Queue-Id: 4PhmGP3vp0z9scm X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean The QEMU emulation of m68k does not support DMA timer, the only timer that is supported is the PIT timer. Implement trivial PIT timer support for m68k. Signed-off-by: Marek Vasut --- Cc: Angelo Dureghello Cc: Huan Wang Cc: Marek Vasut Cc: Simon Glass Cc: Stefan Roese Cc: Tom Rini --- V2: Replace CFG_MCFTMR with CONFIG_MCFTMR in common/board_f.c --- arch/m68k/include/asm/immap.h | 24 +++++++++++++++++++++++ arch/m68k/lib/time.c | 36 +++++++++++++++++++++++++++++++++-- common/board_f.c | 2 +- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/arch/m68k/include/asm/immap.h b/arch/m68k/include/asm/immap.h index 3b515fe2c65..aafa4f40cb3 100644 --- a/arch/m68k/include/asm/immap.h +++ b/arch/m68k/include/asm/immap.h @@ -25,6 +25,8 @@ #define CFG_SYS_TMRINTR_PEND (CFG_SYS_TMRINTR_MASK) #define CFG_SYS_TMRINTR_PRI (6) #define CFG_SYS_TIMER_PRESCALER (((gd->bus_clk / 1000000) - 1) << 8) +#else +#define CFG_SYS_UDELAY_BASE (MMAP_PIT0) #endif #define CFG_SYS_INTR_BASE (MMAP_INTC0) @@ -47,6 +49,8 @@ #define CFG_SYS_TMRINTR_PEND (CFG_SYS_TMRINTR_MASK) #define CFG_SYS_TMRINTR_PRI (0x1E) /* Level must include inorder to work */ #define CFG_SYS_TIMER_PRESCALER (((gd->bus_clk / 1000000) - 1) << 8) +#else +#define CFG_SYS_UDELAY_BASE (MMAP_PIT0) #endif #define CFG_SYS_INTR_BASE (MMAP_INTC0) @@ -72,6 +76,8 @@ #define CFG_SYS_TMRINTR_PEND (CFG_SYS_TMRINTR_MASK) #define CFG_SYS_TMRINTR_PRI (MCFSIM_ICR_AUTOVEC | MCFSIM_ICR_LEVEL7 | MCFSIM_ICR_PRI3) #define CFG_SYS_TIMER_PRESCALER (((gd->bus_clk / 2000000) - 1) << 8) +#else +#define CFG_SYS_UDELAY_BASE (MMAP_PIT0) #endif #endif /* CONFIG_M5249 */ @@ -95,6 +101,8 @@ #define CFG_SYS_TMRINTR_PEND (CFG_SYS_TMRINTR_MASK) #define CFG_SYS_TMRINTR_PRI (MCFSIM_ICR_AUTOVEC | MCFSIM_ICR_LEVEL3 | MCFSIM_ICR_PRI3) #define CFG_SYS_TIMER_PRESCALER (((gd->bus_clk / 2000000) - 1) << 8) +#else +#define CFG_SYS_UDELAY_BASE (MMAP_PIT0) #endif #endif /* CONFIG_M5253 */ @@ -114,6 +122,8 @@ #define CFG_SYS_TMRINTR_PEND (CFG_SYS_TMRINTR_MASK) #define CFG_SYS_TMRINTR_PRI (0x1E) /* Interrupt level 3, priority 6 */ #define CFG_SYS_TIMER_PRESCALER (((gd->bus_clk / 1000000) - 1) << 8) +#else +#define CFG_SYS_UDELAY_BASE (MMAP_PIT0) #endif #define CFG_SYS_INTR_BASE (MMAP_INTC0) @@ -139,6 +149,8 @@ #define CFG_SYS_TMRINTR_PEND (0) #define CFG_SYS_TMRINTR_PRI (INT_ICR1_TMR3PI | INT_ICR1_TMR3IPL(5)) #define CFG_SYS_TIMER_PRESCALER (((gd->bus_clk / 1000000) - 1) << 8) +#else +#define CFG_SYS_UDELAY_BASE (MMAP_PIT0) #endif #endif /* CONFIG_M5272 */ @@ -161,6 +173,8 @@ #define CFG_SYS_TMRINTR_PEND (CFG_SYS_TMRINTR_MASK) #define CFG_SYS_TMRINTR_PRI (0x1E) #define CFG_SYS_TIMER_PRESCALER (((gd->bus_clk / 1000000) - 1) << 8) +#else +#define CFG_SYS_UDELAY_BASE (MMAP_PIT0) #endif #endif /* CONFIG_M5275 */ @@ -183,6 +197,8 @@ #define CFG_SYS_TMRINTR_PEND (CFG_SYS_TMRINTR_MASK) #define CFG_SYS_TMRINTR_PRI (0x1E) /* Level must include inorder to work */ #define CFG_SYS_TIMER_PRESCALER (((gd->bus_clk / 1000000) - 1) << 8) +#else +#define CFG_SYS_UDELAY_BASE (MMAP_PIT0) #endif #endif /* CONFIG_M5282 */ @@ -207,6 +223,8 @@ #define CFG_SYS_TMRINTR_PRI (MCFSIM_ICR_AUTOVEC | \ MCFSIM_ICR_LEVEL7 | MCFSIM_ICR_PRI3) #define CFG_SYS_TIMER_PRESCALER (((gd->bus_clk / 1000000) - 1) << 8) +#else +#define CFG_SYS_UDELAY_BASE (MMAP_PIT0) #endif #endif /* CONFIG_M5307 */ @@ -226,6 +244,8 @@ #define CFG_SYS_TMRINTR_PEND (CFG_SYS_TMRINTR_MASK) #define CFG_SYS_TMRINTR_PRI (6) #define CFG_SYS_TIMER_PRESCALER (((gd->bus_clk / 1000000) - 1) << 8) +#else +#define CFG_SYS_UDELAY_BASE (MMAP_PIT0) #endif #define CFG_SYS_INTR_BASE (MMAP_INTC0) @@ -248,6 +268,8 @@ #define CFG_SYS_TMRINTR_PEND (CFG_SYS_TMRINTR_MASK) #define CFG_SYS_TMRINTR_PRI (6) #define CFG_SYS_TIMER_PRESCALER (((gd->bus_clk / 1000000) - 1) << 8) +#else +#define CFG_SYS_UDELAY_BASE (MMAP_PIT0) #endif #define CFG_SYS_INTR_BASE (MMAP_INTC0) @@ -278,6 +300,8 @@ #define CFG_SYS_TMRINTR_PEND (CFG_SYS_TMRINTR_MASK) #define CFG_SYS_TMRINTR_PRI (6) #define CFG_SYS_TIMER_PRESCALER (((gd->bus_clk / 1000000) - 1) << 8) +#else +#define CFG_SYS_UDELAY_BASE (MMAP_PIT0) #endif #define CFG_SYS_INTR_BASE (MMAP_INTC0) diff --git a/arch/m68k/lib/time.c b/arch/m68k/lib/time.c index 500e4dbbba2..61db1e6c500 100644 --- a/arch/m68k/lib/time.c +++ b/arch/m68k/lib/time.c @@ -111,8 +111,6 @@ ulong get_timer(ulong base) return (timestamp - base); } -#endif /* CONFIG_MCFTMR */ - /* * This function is derived from PowerPC code (read timebase as long long). * On M68K it just returns the timer value. @@ -121,6 +119,40 @@ unsigned long long get_ticks(void) { return get_timer(0); } +#else +static u64 timer64 __section(".data"); +static u16 timer16 __section(".data"); + +uint64_t __weak get_ticks(void) +{ + volatile pit_t *timerp = (pit_t *) (CFG_SYS_UDELAY_BASE); + u16 val = ~timerp->pcntr; + + if (timer16 > val) + timer64 += 0xffff - timer16 + val; + else + timer64 += val - timer16; + + timer16 = val; + + return timer64; +} + +/* PIT timer */ +int timer_init(void) +{ + volatile pit_t *timerp = (pit_t *) (CFG_SYS_UDELAY_BASE); + + timer16 = 0; + timer64 = 0; + + /* Set up PIT as timebase clock */ + timerp->pmr = 0xffff; + timerp->pcsr = PIT_PCSR_EN | PIT_PCSR_OVW; + + return 0; +} +#endif /* CONFIG_MCFTMR */ unsigned long usec2ticks(unsigned long usec) { diff --git a/common/board_f.c b/common/board_f.c index f3c1ab53b1c..1688e27071f 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -863,7 +863,7 @@ static const init_fnc_t init_sequence_f[] = { /* get CPU and bus clocks according to the environment variable */ get_clocks, /* get CPU and bus clocks (etc.) */ #endif -#if !defined(CONFIG_M68K) +#if !defined(CONFIG_M68K) || (defined(CONFIG_M68K) && !defined(CONFIG_MCFTMR)) timer_init, /* initialize timer */ #endif #if defined(CONFIG_BOARD_POSTCLK_INIT)