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 4403BC636CC for ; Mon, 13 Feb 2023 17:34:56 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 77BA285708; Mon, 13 Feb 2023 18:34:54 +0100 (CET) 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="i3Se503Q"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 56CA485708; Mon, 13 Feb 2023 18:34:52 +0100 (CET) Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) (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 D5CA18564B for ; Mon, 13 Feb 2023 18:34:48 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=saproj@gmail.com Received: by mail-ej1-x631.google.com with SMTP id ml19so33894877ejb.0 for ; Mon, 13 Feb 2023 09:34:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=0yNJkJnj7czTigcl/7KOUS47xrP4kc/n6OteCRfIId0=; b=i3Se503QFgE5LJJXjF1UmuH4wYNHbmhGE1ESjY7diqFnfgNgri9PGQdCoT9QzsRBV7 L2yY0xJ9dalhQiorrrLGm+3rA5nl1Ghws3W0EPum8bzujP/DoKTMjsLXnkSurD/0x4u5 MQUFRQCor2iW4sXbhrkykTeTxQYYuJ9k3i1IYkU5qyldUvTloWrndr4VS8lcCHNqS8Xj 9GAl0x2W0P3Q51lGwzK93R4oVfHdtzDIEvYX9TI94kQeCdXi+2Vf0C2OphMTuU/tzx2h uwxgD8It97v0FFONxrISlvRqlslZ2K01/PRiU4zSezR7Xmk1kTK+dbKMLcnhHrYS6cfL Zfng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0yNJkJnj7czTigcl/7KOUS47xrP4kc/n6OteCRfIId0=; b=pQf3/oy8KFnX6E+0i+Xwb843yHIwSWyO3oPdF1u5J5+cNYj5bGPxCmB63l5Z7+rMG3 SJeYwBhBR/lyGBSMCW898nS+uDhmh0mHRLYj5iYCEmlA4P61tkwBB3vd3f59H7hE2fW6 FrlXUfGv2QRTqyEqyqFoC35qw7ToUbO3b51Sna2dohQDuI1plFYjnelFkYQRL5se6Jii 67JCX9Q95WAPbeNQHmVQuXvkhdULnbWeVjNHZ++ASIeH9RtWLeUg7r8xy7wsbm+1Upuy mJQrUbptwpc2YYOtddV1DDXxoSpWyKUYQltWv7tDrgoDuNaHjn/I19GXGU80zPMtNuxs gnuw== X-Gm-Message-State: AO0yUKVj2EW+1TnquXCg0SjXpC6Dy6EPfXocQzQxgVtBGT8eNHDdvjWw 9Gl7njdo2aXO7766qETWqR5u+jljgD4= X-Google-Smtp-Source: AK7set+pA/ngfXOeCA56eImSn4ko691h/EER/ccAtVllxIjlnmPWip55TVcub0T7AlAkVrlfNgOjfg== X-Received: by 2002:a17:906:581b:b0:88d:ba89:1840 with SMTP id m27-20020a170906581b00b0088dba891840mr20665393ejq.17.1676309688409; Mon, 13 Feb 2023 09:34:48 -0800 (PST) Received: from saproj-Latitude-5501.yandex.net ([2a02:6b8:0:40c:d591:434a:7107:941c]) by smtp.gmail.com with ESMTPSA id y13-20020a170906914d00b0087329ff5922sm7055848ejw.139.2023.02.13.09.34.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 09:34:48 -0800 (PST) From: Sergei Antonov To: u-boot@lists.denx.de, sjg@chromium.org, michal.simek@amd.com, sr@denx.de Cc: Sergei Antonov Subject: [PATCH] timer: fttmr010: return a previously deleted driver now ported to DM Date: Mon, 13 Feb 2023 20:34:36 +0300 Message-Id: <20230213173436.1181691-1-saproj@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 The fttmr010 timer driver was deleted by commit 29fc6f24926e ("ARM: remove a320evb board support") The original source file was: arch/arm/cpu/arm920t/a320/timer.c Return the driver to the codebase in a DM compatible form. A platform using fttmr010 will be submitted later. This hardware is described in the datasheet [1], starting from page 348. According to the datasheet, there is a Revision Register at offset 0x3C, which is not present in 'struct fttmr010'. Add it and debug() print revision in probe function. [1] https://bitbucket.org/Kasreyn/mkrom-uc7112lx/src/master/documents/FIC8120_DS_v1.2.pdf Signed-off-by: Sergei Antonov --- drivers/timer/Kconfig | 7 +++ drivers/timer/Makefile | 1 + drivers/timer/fttmr010_timer.c | 92 ++++++++++++++++++++++++++++++++++ include/faraday/fttmr010.h | 1 + 4 files changed, 101 insertions(+) create mode 100644 drivers/timer/fttmr010_timer.c diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig index f32bd16227e3..915b2af160c1 100644 --- a/drivers/timer/Kconfig +++ b/drivers/timer/Kconfig @@ -145,6 +145,13 @@ config DESIGNWARE_APB_TIMER Enables support for the Designware APB Timer driver. This timer is present on Altera SoCFPGA SoCs. +config FTTMR010_TIMER + bool "Faraday Technology timer support" + depends on TIMER + help + Select this to enable support for the timer found on + devices using Faraday Technology's IP. + config GXP_TIMER bool "HPE GXP Timer" depends on TIMER diff --git a/drivers/timer/Makefile b/drivers/timer/Makefile index 3c92113fc6fd..cdc20f5e946e 100644 --- a/drivers/timer/Makefile +++ b/drivers/timer/Makefile @@ -13,6 +13,7 @@ obj-$(CONFIG_$(SPL_)ATMEL_PIT_TIMER) += atmel_pit_timer.o obj-$(CONFIG_$(SPL_)ATMEL_TCB_TIMER) += atmel_tcb_timer.o obj-$(CONFIG_CADENCE_TTC_TIMER) += cadence-ttc.o obj-$(CONFIG_DESIGNWARE_APB_TIMER) += dw-apb-timer.o +obj-$(CONFIG_FTTMR010_TIMER) += fttmr010_timer.o obj-$(CONFIG_GXP_TIMER) += gxp-timer.o obj-$(CONFIG_MPC83XX_TIMER) += mpc83xx_timer.o obj-$(CONFIG_NOMADIK_MTU_TIMER) += nomadik-mtu-timer.o diff --git a/drivers/timer/fttmr010_timer.c b/drivers/timer/fttmr010_timer.c new file mode 100644 index 000000000000..b6289e646109 --- /dev/null +++ b/drivers/timer/fttmr010_timer.c @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2009 Faraday Technology + * Po-Yu Chuang + * + * 23/08/2022 Port to DM + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#define TIMER_LOAD_VAL 0xffffffff + +struct fttmr010_timer_priv { + struct fttmr010 __iomem *regs; +}; + +static u64 fttmr010_timer_get_count(struct udevice *dev) +{ + struct fttmr010_timer_priv *priv = dev_get_priv(dev); + struct fttmr010 *tmr = priv->regs; + u32 now = TIMER_LOAD_VAL - readl(&tmr->timer3_counter); + + /* increment tbu if tbl has rolled over */ + if (now < gd->arch.tbl) + gd->arch.tbu++; + gd->arch.tbl = now; + + return ((u64)gd->arch.tbu << 32) | gd->arch.tbl; +} + +static int fttmr010_timer_probe(struct udevice *dev) +{ + struct fttmr010_timer_priv *priv = dev_get_priv(dev); + struct fttmr010 *tmr; + unsigned int cr; + + priv->regs = dev_read_addr_ptr(dev); + if (!priv->regs) + return -EINVAL; + tmr = priv->regs; + + debug("Faraday FTTMR010 timer revision 0x%08X\n", readl(&tmr->revision)); + + /* disable timers */ + writel(0, &tmr->cr); + + /* setup timer */ + writel(TIMER_LOAD_VAL, &tmr->timer3_load); + writel(TIMER_LOAD_VAL, &tmr->timer3_counter); + writel(0, &tmr->timer3_match1); + writel(0, &tmr->timer3_match2); + + /* we don't want timer to issue interrupts */ + writel(FTTMR010_TM3_MATCH1 | + FTTMR010_TM3_MATCH2 | + FTTMR010_TM3_OVERFLOW, + &tmr->interrupt_mask); + + cr = readl(&tmr->cr); + cr |= FTTMR010_TM3_CLOCK; /* use external clock */ + cr |= FTTMR010_TM3_ENABLE; + writel(cr, &tmr->cr); + + gd->arch.tbl = 0; + gd->arch.tbu = 0; + + return 0; +} + +static const struct timer_ops fttmr010_timer_ops = { + .get_count = fttmr010_timer_get_count, +}; + +static const struct udevice_id fttmr010_timer_ids[] = { + { .compatible = "faraday,fttmr010-timer" }, + {} +}; + +U_BOOT_DRIVER(fttmr010_timer) = { + .name = "fttmr010_timer", + .id = UCLASS_TIMER, + .of_match = fttmr010_timer_ids, + .priv_auto = sizeof(struct fttmr010_timer_priv), + .probe = fttmr010_timer_probe, + .ops = &fttmr010_timer_ops, +}; diff --git a/include/faraday/fttmr010.h b/include/faraday/fttmr010.h index ec1c9895f57c..5b1bef38c77d 100644 --- a/include/faraday/fttmr010.h +++ b/include/faraday/fttmr010.h @@ -26,6 +26,7 @@ struct fttmr010 { unsigned int cr; /* 0x30 */ unsigned int interrupt_state; /* 0x34 */ unsigned int interrupt_mask; /* 0x38 */ + unsigned int revision; /* 0x3c */ }; /* -- 2.34.1