From: Jon Hunter Subject: Re: [PATCH V2 2/6] clocksource: tegra: add Tegra210 timer driver Date: Tue, 29 Jan 2019 09:16:48 +0000 Message-ID: <8c0bc716-4461-883d-aa75-0ccba8132be5@nvidia.com> References: <20190128091815.7040-1-josephl@nvidia.com> <20190128091815.7040-3-josephl@nvidia.com> <20190128150908.GB31317@ulmo> <3607f32b-c20a-e00f-3dc1-630169342392@nvidia.com> Mime-Version: 1.0 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <3607f32b-c20a-e00f-3dc1-630169342392@nvidia.com> Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org To: Joseph Lo , Thierry Reding Cc: Daniel Lezcano , linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, Thomas Gleixner , linux-arm-kernel@lists.infradead.org List-Id: linux-tegra@vger.kernel.org On 29/01/2019 03:35, Joseph Lo wrote: > On 1/28/19 11:09 PM, Thierry Reding wrote: >> On Mon, Jan 28, 2019 at 05:18:11PM +0800, Joseph Lo wrote: >>> Add support for the Tegra210 timer that runs at oscillator clock >>> (TMR10-TMR13). We need these timers to work as clock event device and t= o >>> replace the ARMv8 architected timer due to it can't survive across the >>> power cycle of the CPU core or CPUPORESET signal. So it can't be a >>> wake-up >>> source when CPU suspends in power down state. >>> >>> Based on the work of Antti P Miettinen >>> >>> Cc: Daniel Lezcano >>> Cc: Thomas Gleixner >>> Cc: linux-kernel@vger.kernel.org >>> Signed-off-by: Joseph Lo >>> --- >>> v2: >>> =A0 * add error clean-up code >>> --- >>> =A0 drivers/clocksource/Kconfig=A0=A0=A0=A0=A0=A0=A0=A0=A0 |=A0=A0 3 + >>> =A0 drivers/clocksource/Makefile=A0=A0=A0=A0=A0=A0=A0=A0 |=A0=A0 1 + >>> =A0 drivers/clocksource/timer-tegra210.c | 268 ++++++++++++++++++++++++= +++ >>> =A0 include/linux/cpuhotplug.h=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 |=A0=A0 1 = + >>> =A0 4 files changed, 273 insertions(+) >>> =A0 create mode 100644 drivers/clocksource/timer-tegra210.c >>> >>> diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig >>> index a9e26f6a81a1..e6e3e64b6320 100644 >>> --- a/drivers/clocksource/Kconfig >>> +++ b/drivers/clocksource/Kconfig >>> @@ -135,6 +135,9 @@ config TEGRA_TIMER >>> =A0=A0=A0=A0=A0 help >>> =A0=A0=A0=A0=A0=A0=A0 Enables support for the Tegra driver. >>> =A0 +config TEGRA210_TIMER >>> +=A0=A0=A0 def_bool ARCH_TEGRA_210_SOC >>> + >>> =A0 config VT8500_TIMER >>> =A0=A0=A0=A0=A0 bool "VT8500 timer driver" if COMPILE_TEST >>> =A0=A0=A0=A0=A0 depends on HAS_IOMEM >>> diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefil= e >>> index cdd210ff89ea..95de59c8a47b 100644 >>> --- a/drivers/clocksource/Makefile >>> +++ b/drivers/clocksource/Makefile >>> @@ -36,6 +36,7 @@ obj-$(CONFIG_SUN4I_TIMER)=A0=A0=A0 +=3D timer-sun4i.o >>> =A0 obj-$(CONFIG_SUN5I_HSTIMER)=A0=A0=A0 +=3D timer-sun5i.o >>> =A0 obj-$(CONFIG_MESON6_TIMER)=A0=A0=A0 +=3D timer-meson6.o >>> =A0 obj-$(CONFIG_TEGRA_TIMER)=A0=A0=A0 +=3D timer-tegra20.o >>> +obj-$(CONFIG_TEGRA210_TIMER)=A0=A0=A0 +=3D timer-tegra210.o >>> =A0 obj-$(CONFIG_VT8500_TIMER)=A0=A0=A0 +=3D timer-vt8500.o >>> =A0 obj-$(CONFIG_NSPIRE_TIMER)=A0=A0=A0 +=3D timer-zevio.o >>> =A0 obj-$(CONFIG_BCM_KONA_TIMER)=A0=A0=A0 +=3D bcm_kona_timer.o >>> diff --git a/drivers/clocksource/timer-tegra210.c >>> b/drivers/clocksource/timer-tegra210.c >>> new file mode 100644 >>> index 000000000000..477b164e540b >>> --- /dev/null >>> +++ b/drivers/clocksource/timer-tegra210.c >>> @@ -0,0 +1,268 @@ >>> +// SPDX-License-Identifier: GPL-2.0 >>> +/* >>> + * Copyright (c) 2014-2019, NVIDIA CORPORATION.=A0 All rights reserved= . >>> + */ >>> + >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> + >>> +static u32 tegra210_timer_freq; >>> +static void __iomem *tegra210_timer_reg_base; >>> +static u32 usec_config; >>> + >>> +#define TIMER_PTV=A0=A0=A0=A0=A0=A0=A0 0x0 >>> +#define TIMER_PTV_EN=A0=A0=A0=A0=A0=A0=A0 BIT(31) >>> +#define TIMER_PTV_PER=A0=A0=A0=A0=A0=A0=A0 BIT(30) >>> +#define TIMER_PCR=A0=A0=A0=A0=A0=A0=A0 0x4 >>> +#define TIMER_PCR_INTR_CLR=A0=A0=A0 BIT(30) >>> +#define TIMERUS_CNTR_1US=A0=A0=A0 0x10 >>> +#define TIMERUS_USEC_CFG=A0=A0=A0 0x14 >>> + >>> +#define TIMER10_OFFSET=A0=A0=A0=A0=A0=A0=A0 0x90 >>> +#define TIMER10_IRQ_IDX=A0=A0=A0=A0=A0=A0=A0 10 >>> + >>> +#define TIMER_FOR_CPU(cpu) (TIMER10_OFFSET + (cpu) * 8) >>> +#define IRQ_IDX_FOR_CPU(cpu)=A0=A0=A0 (TIMER10_IRQ_IDX + cpu) >>> + >>> +struct tegra210_clockevent { >>> +=A0=A0=A0 struct clock_event_device evt; >>> +=A0=A0=A0 char name[20]; >>> +=A0=A0=A0 void __iomem *reg_base; >>> +}; >>> +#define to_tegra_cevt(p) (container_of(p, struct >>> tegra210_clockevent, evt)) >>> + >>> +static struct tegra210_clockevent __percpu *tegra210_evt; >>> + >>> +static int tegra210_timer_set_next_event(unsigned long cycles, >>> +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 struct cl= ock_event_device *evt) >>> +{ >>> +=A0=A0=A0 struct tegra210_clockevent *tevt; >>> + >>> +=A0=A0=A0 tevt =3D to_tegra_cevt(evt); >>> +=A0=A0=A0 writel(TIMER_PTV_EN | >>> +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ((cycles > 1) ? (cycles - 1) : 0), /* n= +1 scheme */ >>> +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 tevt->reg_base + TIMER_PTV); >>> + >>> +=A0=A0=A0 return 0; >>> +} >>> + >>> +static inline void timer_shutdown(struct tegra210_clockevent *tevt) >>> +{ >>> +=A0=A0=A0 writel(0, tevt->reg_base + TIMER_PTV); >>> +} >>> + >>> +static int tegra210_timer_shutdown(struct clock_event_device *evt) >>> +{ >>> +=A0=A0=A0 struct tegra210_clockevent *tevt; >>> + >>> +=A0=A0=A0 tevt =3D to_tegra_cevt(evt); >>> +=A0=A0=A0 timer_shutdown(tevt); >>> + >>> +=A0=A0=A0 return 0; >>> +} >>> + >>> +static int tegra210_timer_set_periodic(struct clock_event_device *evt) >>> +{ >>> +=A0=A0=A0 struct tegra210_clockevent *tevt; >>> + >>> +=A0=A0=A0 tevt =3D to_tegra_cevt(evt); >>> +=A0=A0=A0 writel(TIMER_PTV_EN | TIMER_PTV_PER | ((tegra210_timer_freq = / >>> HZ) - 1), >>> +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 tevt->reg_base + TIMER_PTV); >>> + >>> +=A0=A0=A0 return 0; >>> +} >>> + >>> +static irqreturn_t tegra210_timer_isr(int irq, void *dev_id) >>> +{ >>> +=A0=A0=A0 struct tegra210_clockevent *tevt; >>> + >>> +=A0=A0=A0 tevt =3D dev_id; >>> +=A0=A0=A0 writel(TIMER_PCR_INTR_CLR, tevt->reg_base + TIMER_PCR); >>> +=A0=A0=A0 tevt->evt.event_handler(&tevt->evt); >>> + >>> +=A0=A0=A0 return IRQ_HANDLED; >>> +} >> >> Up to here this is a duplicate of timer-tegra20.c. And a lot of >> tegra210_timer_init() is the same as tegra20_timer_init() as well. Can't >> we unify the two drivers instead? >=20 > I still prefer to remove the timer-tegra20 driver, because it didn't > been used for Tegra 32 bit chips for quite a long time. So currently it > just compiles OK, I also doubt the functionality still can achieve the > same what I want to do for Tegra210. >=20 > My personal opinion is to remove the old and unused driver and enhance > the new one. Although it may not be used it is still a valid clocksource and could be used. Our preference is to keeping the existing timer driver and enhance to support T210 (unless there is some fundamental issue that would prevent this that I am overlooking). Cheers Jon --=20 nvpublic