Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 25840FA373E for ; Mon, 24 Oct 2022 11:51:50 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8982180F1E; Mon, 24 Oct 2022 13:51:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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; unprotected) header.d=gmail.com header.i=@gmail.com header.b="UvoXGCRH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B01B784DE8; Mon, 24 Oct 2022 08:26:51 +0200 (CEST) Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BD15284F28 for ; Mon, 24 Oct 2022 08:26:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=clamor95@gmail.com Received: by mail-wm1-x32e.google.com with SMTP id jb18so2537742wmb.4 for ; Sun, 23 Oct 2022 23:26:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=X1TP7gRdDxqgM8VJ6GQ93AwSj0t4273RDMCqrENUJNk=; b=UvoXGCRHfjOOGoor9uKpAmtFQPl4li/n/c4bJncFCLqqNXW9PtDCc3NZvJvmAIdaS1 Up79kAyWzRBosTUm4lH4D9MtAwCOi35UCxqLz6AAVYkwQP33K1FCUn2iBNKEwfazwOjg VsY4IuswZdwEygczHzM8SkL/PAuj3+EGjFdc18gZjTxm3IF2fOhfxZAfddCZSHIQAJOT jz3wVDWXAnEU7ZyDS9EWSh83ZYhNofB8Iy5xqlfCf31PjjKn6vOaZRSFUnVB120y6Jv2 JuDaDma0CQAAGL+hkkFvisS2qDnV08cvYwXu98w815emZTwPMRyYxSFOmjJlw97seqpz lHJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X1TP7gRdDxqgM8VJ6GQ93AwSj0t4273RDMCqrENUJNk=; b=E2kscfFD3sxwBEZsiOWrX78tOi0BhQX2daPz9XyhRpze5FFH/uFh1lAwjW1mxcnBKq 3sjnx3kFmsFsE2LRdb45LpcPul20mwRE4zu/0oo+nMeYzkunGTxug30STOXUmdfYVZtz 29m0Pia7k/B+onaaOZZ4COsBjH8La2qoavJWdXGhUjXd4cvy/fablN4yBvMQXF9Jg9fu 239PoSkgede6lZPagIxWDz2kjV3G+kqPiX8dwfQNCmJO34OBQ70A+XYlyowdLkltAzxj 8SMIbTFsFej+vbUMaMoYqU166AvouufKgUpqAl7Kxjl7G8NjO3pdcNiAGItat1pTLPPr NXqg== X-Gm-Message-State: ACrzQf0CFQXZjYzFqa5fJWs+0Zqv7IvMYfUwzT6JkHMxhJ2XJZsjNt8c WTwihpNNJK67MtdS4jGSiRw= X-Google-Smtp-Source: AMsMyM5sXnMaJlagivpAwyb44toqovza6wKk1wcAQi3T3YSuf1umgrJ+uLyXIqeGXvR4ajIu9jBOyA== X-Received: by 2002:a05:600c:4ec6:b0:3c6:c469:d295 with SMTP id g6-20020a05600c4ec600b003c6c469d295mr42321425wmq.117.1666592806185; Sun, 23 Oct 2022 23:26:46 -0700 (PDT) Received: from localhost.localdomain ([188.163.112.70]) by smtp.gmail.com with ESMTPSA id j28-20020a5d6e5c000000b0022cd27bc8c1sm30981057wrz.9.2022.10.23.23.26.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 23:26:45 -0700 (PDT) From: Svyatoslav Ryhel To: Tom Warren , Marek Vasut , Heinrich Schuchardt , Svyatoslav Ryhel , Michal Simek , Stefan Roese , Eugen Hristev , Claudiu Beznea , =?UTF-8?q?Jonas=20Schw=C3=B6bel?= , Simon Glass , Jim Liu , Nick Hawkins , Stefan Herbrechtsmeier , Michael Walle Cc: u-boot@lists.denx.de Subject: [PATCH v1 2/3] drivers: timer: add timer driver for ARMv7 based Tegra devices Date: Mon, 24 Oct 2022 09:26:20 +0300 Message-Id: <20221024062621.7942-3-clamor95@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221024062621.7942-1-clamor95@gmail.com> References: <20221024062621.7942-1-clamor95@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Mon, 24 Oct 2022 13:50:49 +0200 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.6 at phobos.denx.de X-Virus-Status: Clean Add timer support for T20/T30/T114 and T124 based devices. Driver is based on DM, has device tree support and can be used on SPL and early boot stage. Tested-by: Andreas Westman Dorcsak # ASUS TF600T T30 Tested-by: Jonas Schwöbel # Surface RT T30 Tested-by: Robert Eckelmann # ASUS TF101 T20 Tested-by: Svyatoslav Ryhel # LG P895 T30 Co-developed-by: Jonas Schwöbel Signed-off-by: Jonas Schwöbel Signed-off-by: Svyatoslav Ryhel --- drivers/timer/Kconfig | 8 +++ drivers/timer/Makefile | 1 + drivers/timer/tegra-timer.c | 124 ++++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 drivers/timer/tegra-timer.c diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig index fd8745ffc2..702ffd3084 100644 --- a/drivers/timer/Kconfig +++ b/drivers/timer/Kconfig @@ -244,6 +244,14 @@ config STM32_TIMER Select this to enable support for the timer found on STM32 devices. +config TEGRA_TIMER + bool "Tegra timer support" + depends on TIMER + select TIMER_EARLY + help + Select this to enable support for the timer found on + Tegra devices. + config X86_TSC_TIMER bool "x86 Time-Stamp Counter (TSC) timer support" depends on TIMER && X86 diff --git a/drivers/timer/Makefile b/drivers/timer/Makefile index 7bfb7749e9..ccbff05d43 100644 --- a/drivers/timer/Makefile +++ b/drivers/timer/Makefile @@ -26,6 +26,7 @@ obj-$(CONFIG_SANDBOX_TIMER) += sandbox_timer.o obj-$(CONFIG_$(SPL_)SIFIVE_CLINT) += sifive_clint_timer.o obj-$(CONFIG_STI_TIMER) += sti-timer.o obj-$(CONFIG_STM32_TIMER) += stm32_timer.o +obj-$(CONFIG_TEGRA_TIMER) += tegra-timer.o obj-$(CONFIG_X86_TSC_TIMER) += tsc_timer.o obj-$(CONFIG_MTK_TIMER) += mtk_timer.o obj-$(CONFIG_MCHP_PIT64B_TIMER) += mchp-pit64b-timer.o diff --git a/drivers/timer/tegra-timer.c b/drivers/timer/tegra-timer.c new file mode 100644 index 0000000000..cda460921f --- /dev/null +++ b/drivers/timer/tegra-timer.c @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2022 Svyatoslav Ryhel + */ + +#include +#include +#include +#include + +#include +#include +#include + +#define TEGRA_OSC_CLK_ENB_L_SET (NV_PA_CLK_RST_BASE + 0x320) +#define TEGRA_OSC_SET_CLK_ENB_TMR BIT(5) + +#define TEGRA_TIMER_USEC_CNTR (NV_PA_TMRUS_BASE + 0) +#define TEGRA_TIMER_USEC_CFG (NV_PA_TMRUS_BASE + 4) + +#define TEGRA_TIMER_RATE 1000000 /* 1 MHz */ + +u64 notrace timer_early_get_count(void) +{ + /* At this stage raw timer is used */ + return readl(TEGRA_TIMER_USEC_CNTR); +} + +unsigned long notrace timer_early_get_rate(void) +{ + return TEGRA_TIMER_RATE; +} + +#if CONFIG_IS_ENABLED(BOOTSTAGE) +ulong timer_get_boot_us(void) +{ + u64 ticks = 0; + int ret; + + ret = dm_timer_init(); + if (!ret) + timer_get_count(gd->timer, &ticks); + else + ticks = timer_early_get_count(); + + return ticks; +} +#endif + +static notrace u64 tegra_timer_get_count(struct udevice *dev) +{ + u32 val = timer_early_get_count(); + return timer_conv_64(val); +} + +static int tegra_timer_probe(struct udevice *dev) +{ + struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev); + u32 usec_config, value; + + /* Timer rate has to be set unconditionally */ + uc_priv->clock_rate = TEGRA_TIMER_RATE; + + /* + * Configure microsecond timers to have 1MHz clock + * Config register is 0xqqww, where qq is "dividend", ww is "divisor" + * Uses n+1 scheme + */ + switch (clock_get_osc_freq()) { + case CLOCK_OSC_FREQ_13_0: + usec_config = 0x000c; /* (12+1)/(0+1) */ + break; + case CLOCK_OSC_FREQ_19_2: + usec_config = 0x045f; /* (95+1)/(4+1) */ + break; + case CLOCK_OSC_FREQ_12_0: + usec_config = 0x000b; /* (11+1)/(0+1) */ + break; + case CLOCK_OSC_FREQ_26_0: + usec_config = 0x0019; /* (25+1)/(0+1) */ + break; + case CLOCK_OSC_FREQ_16_8: + usec_config = 0x0453; /* (83+1)/(4+1) */ + break; + case CLOCK_OSC_FREQ_38_4: + usec_config = 0x04bf; /* (191+1)/(4+1) */ + break; + case CLOCK_OSC_FREQ_48_0: + usec_config = 0x002f; /* (47+1)/(0+1) */ + break; + default: + return -EINVAL; + } + + /* Enable clock to timer hardware */ + value = readl_relaxed(TEGRA_OSC_CLK_ENB_L_SET); + writel_relaxed(value | TEGRA_OSC_SET_CLK_ENB_TMR, + TEGRA_OSC_CLK_ENB_L_SET); + + writel_relaxed(usec_config, TEGRA_TIMER_USEC_CFG); + + return 0; +} + +static const struct timer_ops tegra_timer_ops = { + .get_count = tegra_timer_get_count, +}; + +static const struct udevice_id tegra_timer_ids[] = { + { .compatible = "nvidia,tegra20-timer" }, + { .compatible = "nvidia,tegra30-timer" }, + { .compatible = "nvidia,tegra114-timer" }, + { .compatible = "nvidia,tegra124-timer" }, + { } +}; + +U_BOOT_DRIVER(tegra_timer) = { + .name = "tegra_timer", + .id = UCLASS_TIMER, + .of_match = tegra_timer_ids, + .probe = tegra_timer_probe, + .ops = &tegra_timer_ops, + .flags = DM_FLAG_PRE_RELOC, +}; -- 2.34.1