From nobody Tue Feb 10 01:35:56 2026 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DEBF3B8BC8 for ; Wed, 4 Feb 2026 10:46:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770201994; cv=none; b=YUMHshL00B7rKkaUwQC8rHFF8XrYZho+Ln1MS/O8c2yPjaTnxEnznxi6FoolGmL7ojbtFQZY9T9BGBnYMQ3zoqL9jPZZRj6FifBtmKly9IAMKpIMWSxoaMnG5RJjFPJSapDA0tK5EjvF+Gl7fQ9IvdNumLw5WjF5PDBt44A8fCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770201994; c=relaxed/simple; bh=hpHbTPPVE8C6Ps+8cGeMo+DVuRmwITWvK35+UamG6as=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=S4Z978ujimpkQkEpYveasMmjgJL366+rG5L8ZOrdM7q4EFfX0Veo4of3VmTWuWaO+2I4ypx1//qYVAqYMq2pSv9Df3Gl5VbyznMHsxgFGOEL7U9GIbfy0Qn3EdK9qv8T6DNsu+BYtxNWxQi7Gwzz002gJgzOZ7bA9rWwTk43zpI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=ZcQ2Zbf8; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="ZcQ2Zbf8" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-482f454be5bso6195745e9.0 for ; Wed, 04 Feb 2026 02:46:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1770201992; x=1770806792; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=IPuW6YZyhCu6SpjrbuRbonH50VFDuevJC4xYp0LKfJ0=; b=ZcQ2Zbf8Oj9uzM7aytsRS+g77Ka9Ih2zz4cmc3WLWNP8iLhZEx+z6opZkwL3kClmi0 Tc455tzoKIL3OU5Ss4tU2wRAIFE5cFqvT+6WEcoaDlD7hblHIZ6KuBARQExgOI8+Qmuk 7g7DR0Gw342PNrCJKBlk/qM057Rlv8YoeL0didm0lB5PNvzcre/NUtKlSWowkc5erOrF 9n/aMkldFUy4fVZ0OCQQHgrxF3PYlfN4D2QnlsbBx+7gWEF44qh2usJOd10F2Z8cKWgq 7BSWUxc6uEf0o1R1x4dmweG39Pxx5P09NJY2v794aoDuRaX6cRcU9uOQCm0WmwokWI2Z j6EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770201992; x=1770806792; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=IPuW6YZyhCu6SpjrbuRbonH50VFDuevJC4xYp0LKfJ0=; b=S+I79aKLdmTA2dobirfnpTiTrkKY7e2nfQAv42BkgERuXTqr5C8bclJm1+jBMKd86W WZmwfESYYih72CVnRzN7dnTxszA4n4MaiJfwGInVVn2+KB53pEnm9bsxj929NhLwnRlb YHB1ZshYqk21i3h5gFM0tl6pmKHghAdNuDZvd2u4QC/G+hMX53CyKuxwzXkgdUHmkXix qT8o58GRyNlH+RUpFniOjdmmukS2xfqfCp3oudohOA/LNQ39hFTXAk+OB7kQSbQzJuaz bvfgLhKFCLQc1cGMuKBXbveBeBiWotRI2y53j9u86viUAoOLw7QkcRGoyiciIuXAqmaU Wj1Q== X-Forwarded-Encrypted: i=1; AJvYcCU1C/Y7OcUbyjvD8CobLqXQVG0udTihbDF58loNz3SX0XAgTbw2T6LYO4fNcbM0zRKg7COs08MdxuwW4IQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yymiac+QU/kCa2ZD6yhh/uil0qYEMF3Xa6Qez6gr1S3PP+UeQka peiJ0LeA0HS8iSc1y3qdd6wxVAzvbjVFWtK3aqQl6tQGwDgU+g1CpdN33bTpIECpcDI= X-Gm-Gg: AZuq6aKRvqkUUQaB2ZYJldrRnIk7t67Hqk6Az75UEQjjVroRX+VtucFUwYUFeff9vL/ 248dqCv6FJANlT5Qdm4kZX5PV15Z/xjotBi5lS0R7jn+b3X4FJu402BjQH1uulCe1MdoMshxHAv Glk3oWmISg9VXhRJFuCSif+n4ElaGzliFbeNIu5GL6SkH+iWWkQygzHfmP9hf8/uBBW0weOKmEN xmP3UcT6OTPUo3W4nHa0XOAKCSebPlNdqAtAEITP9oiCiSKLgoS9oPNmqLm0nrSAUCly/YYKTv3 OkYnm2DjWf1dl4A55jBz+jDahdl0OJ2etOs8sR7a+FmnrJ7o9vYb4AHAFB0aZRTrH5gAjAmdT8+ nZs3Bnr9fhBIBQg6/nefUfvdqw+6Ot6fACx8ayDtEBQRu2F1OPCk+UNIZ5Gx7CLlnwAzBGh4140 aG/DR8Y+3J X-Received: by 2002:a05:600c:6209:b0:479:13e9:3d64 with SMTP id 5b1f17b1804b1-4830eb6540dmr30504235e9.15.1770201992495; Wed, 04 Feb 2026 02:46:32 -0800 (PST) Received: from localhost ([2001:4090:a244:872b:a354:65f3:92a0:8de7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4830ec10011sm26516805e9.0.2026.02.04.02.46.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Feb 2026 02:46:31 -0800 (PST) From: "Markus Schneider-Pargmann (TI.com)" Date: Wed, 04 Feb 2026 11:45:49 +0100 Subject: [PATCH v3 2/3] clocksource/drivers/timer-ti-dm: Add clocksource support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260204-topic-ti-dm-clkevt-v6-16-v3-2-83e65d01f4ae@baylibre.com> References: <20260204-topic-ti-dm-clkevt-v6-16-v3-0-83e65d01f4ae@baylibre.com> In-Reply-To: <20260204-topic-ti-dm-clkevt-v6-16-v3-0-83e65d01f4ae@baylibre.com> To: Daniel Lezcano , Thomas Gleixner Cc: Vishal Mahaveer , Kevin Hilman , Dhruva Gole , Sebin Francis , Kendall Willis , Akashdeep Kaur , linux-kernel@vger.kernel.org, "Markus Schneider-Pargmann (TI.com)" X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6133; i=msp@baylibre.com; h=from:subject:message-id; bh=hpHbTPPVE8C6Ps+8cGeMo+DVuRmwITWvK35+UamG6as=; b=owGbwMvMwCXWejAsc4KoVzDjabUkhsxm5SpHrqkdu9TuTTomHfbtb5VB08yHgVNvC3wKtW303 2DRXfKmo5SFQYyLQVZMkaUzMTTtv/zOY8mLlm2GmcPKBDKEgYtTACbyVYeR4Wk1q/+LIm7f37Nr Hna0VPW4TFY9xdMa7XyeuTj2q+vfY4wM83pdm49e6WvnTxUO3M91TTG1yEBrJp8jq+Fp45SSQ/w MAA== X-Developer-Key: i=msp@baylibre.com; a=openpgp; fpr=BADD88DB889FDC3E8A3D5FE612FA6A01E0A45B41 Add support for using the TI Dual-Mode Timer as a clocksource. The driver automatically picks the first timer that is marked as always-on on with the "ti,timer-alwon" property to be the clocksource. The timer can then be used for CPU independent time keeping. Signed-off-by: Markus Schneider-Pargmann (TI.com) --- drivers/clocksource/timer-ti-dm.c | 137 ++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 137 insertions(+) diff --git a/drivers/clocksource/timer-ti-dm.c b/drivers/clocksource/timer-= ti-dm.c index 793e7cdcb1b16b58db3a81668e3c8144efc7baaf..75f38394e2598d76c41dd2b250c= 0c42f9f48bbe0 100644 --- a/drivers/clocksource/timer-ti-dm.c +++ b/drivers/clocksource/timer-ti-dm.c @@ -20,6 +20,7 @@ =20 #include #include +#include #include #include #include @@ -27,8 +28,10 @@ #include #include #include +#include #include #include +#include =20 #include #include @@ -148,6 +151,15 @@ static u32 omap_reserved_systimers; static LIST_HEAD(omap_timer_list); static DEFINE_SPINLOCK(dm_timer_lock); =20 +struct dmtimer_clocksource { + struct clocksource dev; + struct dmtimer *timer; + unsigned int loadval; +}; + +static resource_size_t omap_dm_timer_clocksource_base; +static void __iomem *omap_dm_timer_sched_clock_counter; + enum { REQUEST_ANY =3D 0, REQUEST_BY_ID, @@ -1185,6 +1197,117 @@ static const struct dev_pm_ops omap_dm_timer_pm_ops= =3D { =20 static const struct of_device_id omap_timer_match[]; =20 +static void omap_dm_timer_find_alwon(void) +{ + struct device_node *np; + + for_each_matching_node(np, omap_timer_match) { + struct resource res; + + if (!of_device_is_available(np)) + continue; + + if (!of_property_read_bool(np, "ti,timer-alwon")) + continue; + + if (of_address_to_resource(np, 0, &res)) + continue; + + omap_dm_timer_clocksource_base =3D res.start; + + of_node_put(np); + return; + } + + omap_dm_timer_clocksource_base =3D RESOURCE_SIZE_MAX; +} + +static struct dmtimer_clocksource *omap_dm_timer_to_clocksource(struct clo= cksource *cs) +{ + return container_of(cs, struct dmtimer_clocksource, dev); +} + +static u64 omap_dm_timer_read_cycles(struct clocksource *cs) +{ + struct dmtimer_clocksource *clksrc =3D omap_dm_timer_to_clocksource(cs); + struct dmtimer *timer =3D clksrc->timer; + + return (u64)__omap_dm_timer_read_counter(timer); +} + +static u64 notrace omap_dm_timer_read_sched_clock(void) +{ + /* Posted mode is not active here, so we can read directly */ + return readl_relaxed(omap_dm_timer_sched_clock_counter); +} + +static void omap_dm_timer_clocksource_suspend(struct clocksource *cs) +{ + struct dmtimer_clocksource *clksrc =3D omap_dm_timer_to_clocksource(cs); + struct dmtimer *timer =3D clksrc->timer; + + clksrc->loadval =3D __omap_dm_timer_read_counter(timer); + __omap_dm_timer_stop(timer); +} + +static void omap_dm_timer_clocksource_resume(struct clocksource *cs) +{ + struct dmtimer_clocksource *clksrc =3D omap_dm_timer_to_clocksource(cs); + struct dmtimer *timer =3D clksrc->timer; + + dmtimer_write(timer, OMAP_TIMER_COUNTER_REG, clksrc->loadval); + dmtimer_write(timer, OMAP_TIMER_CTRL_REG, OMAP_TIMER_CTRL_ST | OMAP_TIMER= _CTRL_AR); +} + +static void omap_dm_timer_clocksource_unregister(void *data) +{ + struct clocksource *cs =3D data; + + clocksource_unregister(cs); +} + +static int omap_dm_timer_setup_clocksource(struct dmtimer *timer) +{ + struct device *dev =3D &timer->pdev->dev; + struct dmtimer_clocksource *clksrc; + int err; + + __omap_dm_timer_init_regs(timer); + + timer->reserved =3D 1; + + clksrc =3D devm_kzalloc(dev, sizeof(*clksrc), GFP_KERNEL); + if (!clksrc) + return -ENOMEM; + + clksrc->timer =3D timer; + + clksrc->dev.name =3D "omap_dm_timer"; + clksrc->dev.rating =3D 300; + clksrc->dev.read =3D omap_dm_timer_read_cycles; + clksrc->dev.mask =3D CLOCKSOURCE_MASK(32); + clksrc->dev.flags =3D CLOCK_SOURCE_IS_CONTINUOUS; + clksrc->dev.suspend =3D omap_dm_timer_clocksource_suspend; + clksrc->dev.resume =3D omap_dm_timer_clocksource_resume; + + dmtimer_write(timer, OMAP_TIMER_COUNTER_REG, 0); + dmtimer_write(timer, OMAP_TIMER_LOAD_REG, 0); + dmtimer_write(timer, OMAP_TIMER_CTRL_REG, OMAP_TIMER_CTRL_ST | OMAP_TIMER= _CTRL_AR); + + omap_dm_timer_sched_clock_counter =3D timer->func_base + _OMAP_TIMER_COUN= TER_OFFSET; + sched_clock_register(omap_dm_timer_read_sched_clock, 32, timer->fclk_rate= ); + + err =3D clocksource_register_hz(&clksrc->dev, timer->fclk_rate); + if (err) + return dev_err_probe(dev, err, "Could not register as clocksource\n"); + + err =3D devm_add_action_or_reset(dev, omap_dm_timer_clocksource_unregiste= r, &clksrc->dev); + if (err) + return dev_err_probe(dev, err, "Could not register clocksource_unregiste= r action\n"); + + return 0; +} + /** * omap_dm_timer_probe - probe function called for every registered device * @pdev: pointer to current timer platform device @@ -1198,8 +1321,12 @@ static int omap_dm_timer_probe(struct platform_devic= e *pdev) struct dmtimer *timer; struct device *dev =3D &pdev->dev; const struct dmtimer_platform_data *pdata; + struct resource *res; int ret; =20 + if (!omap_dm_timer_clocksource_base) + omap_dm_timer_find_alwon(); + pdata =3D of_device_get_match_data(dev); if (!pdata) pdata =3D dev_get_platdata(dev); @@ -1272,6 +1399,16 @@ static int omap_dm_timer_probe(struct platform_devic= e *pdev) =20 timer->pdev =3D pdev; =20 + res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); + + if (omap_dm_timer_clocksource_base && res && + res->start =3D=3D omap_dm_timer_clocksource_base && + !IS_ERR_OR_NULL(timer->fclk)) { + ret =3D omap_dm_timer_setup_clocksource(timer); + if (ret) + return ret; + } + pm_runtime_enable(dev); =20 if (!timer->reserved) { --=20 2.51.0