From nobody Mon Jan 27 20:06:58 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YhfZp6fVVz5mBtB; Mon, 27 Jan 2025 20:06:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YhfZp65xwz3Gw3; Mon, 27 Jan 2025 20:06:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1738008418; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PSrl8qAOwAsHRegr/fqSjfHco4FmIsIgMeuGD7MiXSQ=; b=GgjwHTtAqx3gE64UIFeJ8b5EUs/wdestzmqjLy/dHYlfctlmC2+fWK+1kRFr0s48kE0sjF ctbASjHMc/EKCptKmZfLoWS2M7ilZ5qXdWxBT0GOBtMj0EgUOvchNHYAoF1nxFsP5EmkZg PUAFslqpFEmlnRcIBpSElAIp9DwOc9g4GogBVezid2yGlARF6SH/34QJOBnqxMWNXOu+cp 5Sd65oNAsL6R18NwxJ8D3O210dRRGcSk8ekreLfzXHpRwy1wWjqomHhEli7yrfQYht7DOS ghJXrJT4/jligmz5gopPtOVngsvZjcA9FU7/lPNo9uxjiaz5cLpcIzYlhwjQRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1738008418; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PSrl8qAOwAsHRegr/fqSjfHco4FmIsIgMeuGD7MiXSQ=; b=Ju5XAkkHR3lAv2s8KPWDyNSAfggmeZ2O2yhEJB7zXDjoGmkVJIaV8Abo4l2JevVjtOHXTQ ryMdTfi2lJvCHgB5de/3UWjx3uyjuboUUEWqqebdQwBSMDpsXjff/HKgMj0uvpiCy7ynz3 dOidhBN4bbMFl/xDoweBKdCFIasTnv98hQ+VZkxAcn4U/9gR2zsAeTi5DIoiaVEYavoLKl WtVsoTOtN7zuWgWEtPrcWKhrQtD5CU4RkZcL9dYUvi9T6Pox4jTDXYAP+nSjBM1N9bX0Jc 4YX6rWOXoQ+KWa1ON7X+tcP34PVOKEJ1xP7cMyvgWYaZqZYZ+M/NYAwIfOSfLg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1738008418; a=rsa-sha256; cv=none; b=RqocrI6yghdzM0SE5BaiLl4to3Av7Yjj2Nl0ZqV7BVBCQCTOEj+FVifhqp/+nXDhKSDVb1 obkRCZGoULRbC/eUejTuPa92AXfzl+K5nIWgQwwzPYHXf1EuqGN7hPF2/3Eh8uOZCLubb+ WGdJKRK8eDVTNKwFADJO9ED2FCcNkAXDtLbWYKHjBlQl1UFsYRps1o1wQMWpSmsZC4aIFw C51z5tZ2xvS1UFjLcKkz3uZMEm8H3I65e/sleNsEBCf3jLLPbAmNmUp0rhzU9xf9DHeFsz rQIU9rmQMc2n4PRBrAHEuGnOqyK3HIt5QO6sNHOwa7tu8FcAaLrff1o+ZDeufA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YhfZp54z5zkMf; Mon, 27 Jan 2025 20:06:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50RK6wtL099025; Mon, 27 Jan 2025 20:06:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50RK6w29099022; Mon, 27 Jan 2025 20:06:58 GMT (envelope-from git) Date: Mon, 27 Jan 2025 20:06:58 GMT Message-Id: <202501272006.50RK6w29099022@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 449e6a9527f6 - main - a10_timer: some tidying/re-organization List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 449e6a9527f6652888a7027cba57330f191e2610 Auto-Submitted: auto-generated The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=449e6a9527f6652888a7027cba57330f191e2610 commit 449e6a9527f6652888a7027cba57330f191e2610 Author: Mitchell Horne AuthorDate: 2025-01-27 19:59:27 +0000 Commit: Mitchell Horne CommitDate: 2025-01-27 20:03:49 +0000 a10_timer: some tidying/re-organization In preparation for enabling the driver on the D1 platform (riscv). - Better isolate armv7-only portions of the driver - Move a10 timecounter setup into a helper function - Small style tweaks Reviewed by: manu, ganbold MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D48670 --- sys/arm/allwinner/a10_timer.c | 90 ++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 39 deletions(-) diff --git a/sys/arm/allwinner/a10_timer.c b/sys/arm/allwinner/a10_timer.c index 18fb2a56da3a..80315914949b 100644 --- a/sys/arm/allwinner/a10_timer.c +++ b/sys/arm/allwinner/a10_timer.c @@ -28,12 +28,13 @@ #include #include #include -#include #include +#include #include #include #include #include + #include #include #include @@ -79,8 +80,8 @@ /* 64 bit counter, available in A10 and A13 */ #define CNT64_CTRL_REG 0xa0 #define CNT64_CTRL_RL_EN 0x02 /* read latch enable */ -#define CNT64_LO_REG 0xa4 -#define CNT64_HI_REG 0xa8 +#define CNT64_LO_REG 0xa4 +#define CNT64_HI_REG 0xa8 #define SYS_TIMER_CLKSRC 24000000 /* clock source */ @@ -104,18 +105,17 @@ struct a10_timer_softc { #define timer_write_4(sc, reg, val) \ bus_write_4(sc->res[A10_TIMER_MEMRES], reg, val) -static u_int a10_timer_get_timecount(struct timecounter *); #if defined(__arm__) +static u_int a10_timer_get_timecount(struct timecounter *); +static uint64_t a10_timer_read_counter64(struct a10_timer_softc *sc); +static void a10_timer_timecounter_setup(struct a10_timer_softc *sc); + +static void a10_timer_eventtimer_setup(struct a10_timer_softc *sc); static int a10_timer_timer_start(struct eventtimer *, sbintime_t first, sbintime_t period); static int a10_timer_timer_stop(struct eventtimer *); #endif -static uint64_t timer_read_counter64(struct a10_timer_softc *sc); -#if defined(__arm__) -static void a10_timer_eventtimer_setup(struct a10_timer_softc *sc); -#endif - #if defined(__aarch64__) static void a23_timer_timecounter_setup(struct a10_timer_softc *sc); static u_int a23_timer_get_timecount(struct timecounter *tc); @@ -127,7 +127,6 @@ static int a10_timer_attach(device_t); #if defined(__arm__) static delay_func a10_timer_delay; -#endif static struct timecounter a10_timer_timecounter = { .tc_name = "a10_timer timer0", @@ -136,6 +135,7 @@ static struct timecounter a10_timer_timecounter = { .tc_frequency = 0, .tc_quality = 1000, }; +#endif #if defined(__aarch64__) static struct timecounter a23_timer_timecounter = { @@ -168,16 +168,12 @@ static struct ofw_compat_data compat_data[] = { static int a10_timer_probe(device_t dev) { -#if defined(__arm__) - u_int soc_family; -#endif - if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) return (ENXIO); #if defined(__arm__) /* For SoC >= A10 we have the ARM Timecounter/Eventtimer */ - soc_family = allwinner_soc_family(); + u_int soc_family = allwinner_soc_family(); if (soc_family != ALLWINNERSOC_SUN4I && soc_family != ALLWINNERSOC_SUN5I) return (ENXIO); @@ -214,34 +210,27 @@ a10_timer_attach(device_t dev) return (ENXIO); } - if (clk_get_by_ofw_index(dev, 0, 0, &clk) != 0) + if (clk_get_by_ofw_index(dev, 0, 0, &clk) != 0) { sc->timer0_freq = SYS_TIMER_CLKSRC; - else { + } else { if (clk_get_freq(clk, &sc->timer0_freq) != 0) { device_printf(dev, "Cannot get clock source frequency\n"); return (ENXIO); } } + if (bootverbose) { + device_printf(sc->sc_dev, "clock: hz=%d stathz = %d\n", hz, + stathz); + } + #if defined(__arm__) a10_timer_eventtimer_setup(sc); - arm_set_delay(a10_timer_delay, sc); - a10_timer_timecounter.tc_priv = sc; - a10_timer_timecounter.tc_frequency = sc->timer0_freq; - tc_init(&a10_timer_timecounter); + a10_timer_timecounter_setup(sc); #elif defined(__aarch64__) a23_timer_timecounter_setup(sc); #endif - if (bootverbose) { - device_printf(sc->sc_dev, "clock: hz=%d stathz = %d\n", hz, stathz); - - device_printf(sc->sc_dev, "event timer clock frequency %ju\n", - sc->timer0_freq); - device_printf(sc->sc_dev, "timecounter clock frequency %jd\n", - a10_timer_timecounter.tc_frequency); - } - return (0); } @@ -311,6 +300,11 @@ a10_timer_eventtimer_setup(struct a10_timer_softc *sc) sc->et.et_stop = a10_timer_timer_stop; sc->et.et_priv = sc; et_register(&sc->et); + + if (bootverbose) { + device_printf(sc->sc_dev, "event timer clock frequency %ju\n", + sc->timer0_freq); + } } static int @@ -368,7 +362,7 @@ a10_timer_timer_stop(struct eventtimer *et) return (0); } -#endif +#endif /* __arm__ */ /* * Timecounter functions for A23 and above @@ -400,6 +394,11 @@ a23_timer_timecounter_setup(struct a10_timer_softc *sc) a23_timer_timecounter.tc_priv = sc; a23_timer_timecounter.tc_frequency = sc->timer0_freq; tc_init(&a23_timer_timecounter); + + if (bootverbose) { + device_printf(sc->sc_dev, "timecounter clock frequency %jd\n", + a23_timer_timecounter.tc_frequency); + } } static u_int @@ -416,14 +415,15 @@ a23_timer_get_timecount(struct timecounter *tc) /* Counter count backwards */ return (~0u - val); } -#endif +#endif /* __aarch64__ */ /* * Timecounter functions for A10 and A13, using the 64 bits counter */ +#if defined(__arm__) static uint64_t -timer_read_counter64(struct a10_timer_softc *sc) +a10_timer_read_counter64(struct a10_timer_softc *sc) { uint32_t lo, hi; @@ -438,30 +438,42 @@ timer_read_counter64(struct a10_timer_softc *sc) return (((uint64_t)hi << 32) | lo); } -#if defined(__arm__) static void a10_timer_delay(int usec, void *arg) { struct a10_timer_softc *sc = arg; uint64_t end, now; - now = timer_read_counter64(sc); + now = a10_timer_read_counter64(sc); end = now + (sc->timer0_freq / 1000000) * (usec + 1); while (now < end) - now = timer_read_counter64(sc); + now = a10_timer_read_counter64(sc); } -#endif static u_int a10_timer_get_timecount(struct timecounter *tc) { - if (tc->tc_priv == NULL) return (0); - return ((u_int)timer_read_counter64(tc->tc_priv)); + return ((u_int)a10_timer_read_counter64(tc->tc_priv)); +} + +static void +a10_timer_timecounter_setup(struct a10_timer_softc *sc) +{ + arm_set_delay(a10_timer_delay, sc); + a10_timer_timecounter.tc_priv = sc; + a10_timer_timecounter.tc_frequency = sc->timer0_freq; + tc_init(&a10_timer_timecounter); + + if (bootverbose) { + device_printf(sc->sc_dev, "timecounter clock frequency %jd\n", + a10_timer_timecounter.tc_frequency); + } } +#endif /* __arm__ */ static device_method_t a10_timer_methods[] = { DEVMETHOD(device_probe, a10_timer_probe),