From nobody Fri Dec 19 07:21:36 2025 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 2D0DC2C3252 for ; Tue, 16 Dec 2025 20:04:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765915469; cv=none; b=N4i+4c7jCymOgVURiV3sMC+sq27dZZvpx7aFkrDdt7BeObnxP4nkNFDkRncmpHh+zdl1gqj40fYRbCjbGlsM25tHaiW0AKg+wQIJnMhKXm3rJFqa7YL8UM/wZJEjvQBGXaJ/pvv2uLcuzkSoJCqROXD08G5/uZPad/45FRzq0gA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765915469; c=relaxed/simple; bh=JMgYaq8WQ1kszJyA/EA+8xzCsDM1CdpeYKJ5q2VZfqk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QmReiYpZA3cLdQBkiKcUELrt3Q+AIIJ4FcZaQJfqbtUjahlwmQW6WjHNwn21bneb1VxlchDOidqd+f5tpyZd5ildkazZlQIpH2MiMUC8PCNc6JXfCCnsB2lGNrDvHi+Ittn0j8BI5DEbul691eNDhd8y4uqNQ7XDaXWTZJQBKgg= 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=TxvtAwjd; arc=none smtp.client-ip=209.85.218.51 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="TxvtAwjd" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-b727f452fffso215505666b.1 for ; Tue, 16 Dec 2025 12:04:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1765915465; x=1766520265; 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=Wkz2dMWEsiklTod+JsKqRghf6ECOVY2ifYCyQ3TvS7A=; b=TxvtAwjdPjFQaSgMC5wjGzmDfjkDA/0KfzeoS1MLClTffwNJd+s46sGwjr5ZYgSXmQ Kqt+1vE0xgKWccFLTSn/BzcLZyoSd7tCSWh+8CWL7YXY4+GZXDyhuv+jLO8+2dO4MMSR KCmjHtCwcVa6w0zGAMuvfhEi2krZxbPcnlSw90g4CgkGDm0rL2OeZUBvG/v7BpMrlWI5 H7EMRmo6ehLiEPLUkNV2+F3MHsBmgH/rI9gB7VLpTepOOXoVHxxFnVTXAe/VSuTXUubZ a7daFoe6h5QiV9qSQIhIK/MJlruHBRUcRZPf/DHAcuPPD3VPKY+3DthoN84Uhe8h5T4A QIuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765915465; x=1766520265; 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=Wkz2dMWEsiklTod+JsKqRghf6ECOVY2ifYCyQ3TvS7A=; b=Aj8ROvZksIF0GFvWYupL33aSfQv48mYFQGpNB3JzAFlLFU3KQWj51JPziRWdJwLTbh e17jSC5+SzmfIngb0OCgPH5K7AL7vwsTOvJHKt0qrSkiF3rDBAixYqyGcNfWOlFL5be5 y5aITaYZoPMvAkJovUpJTnEhkgE8oPZBxXsjC+t+MSZY7Uhco5PFxHvhJQ7nBxREwm2J /sTYYndmROYC0WaISeo0R4+Ojm4RyToJCr4+l4EZ8MR+F+t3POX68coRIFBWotsBTTkj E4eqZT6OWBIBpvwB77o/Sp6lWYsaESBB++pu6rdqXxXUbVDs4destiEIngJDH2m42aVK rlow== X-Forwarded-Encrypted: i=1; AJvYcCX0Nr98ajejqLJiKrFsFMMTJPCT1kprqf6PrIf3ADPCyp6lt8j0jga2f5b5cefyduCUdszCPNeN+nFyuyY=@vger.kernel.org X-Gm-Message-State: AOJu0YwY6JkYFtg3P/C9unKw0ikff0TSintC9u76OdHm68y1BXI0/DVS EdtXCensPjLYBL5udJqEX5yylj7sMxksIDOhAFda08xry3jiZHHPm9y4q9pbtBK6I5L1z8jwzvL jU//e X-Gm-Gg: AY/fxX4Pbp938MHJnDbAEf1Zoyam2zB/xcw8BTSHsBAkROhiIaB7KCBBX0QievfK+G6 WynP5uiiML400FKhcf6o14uszzXwTKwIL1j6jCOGJHKOISCsL60TZNSkXSvbQE7k0/H/YJGXyCG 0mOWyQb5uNVd+Iir+u2mR+JLq/0Od4eSKcKtQO5OrwjmZq0RayuOI47fnyYaHnUBVHhNKWqrHzK CBzuKPV3Lx5C5FggbBnLVOqtxc6G93Cnj/V2Y42fNE7fWmEaJKz/YQvlpLgt2vaL8PWSewJ5Jba qeZ1GWu8EXfg2iRGyTjI5lJmp4+LHk8CqEpjbzAmtlU2lCiTJU2u/4XQuKwy8DR/wABZuh5s/1F Mjrii55NYaRIrR8SMbz4cm+aPlZNxabUpJpGLgG9TatIvWeghkpRItzZOlRyCgIAf7zItrUfayE DivBcR/RHy X-Google-Smtp-Source: AGHT+IHXazie4RxRNe32hnz+3El2SlkEpuwErwheGrOF0Z4V8zDOpC7lq+BNhYzIQ9w/N3mvWJI6mg== X-Received: by 2002:a17:907:9302:b0:b76:52d0:3a0b with SMTP id a640c23a62f3a-b7d0250088bmr2261702566b.25.1765915465296; Tue, 16 Dec 2025 12:04:25 -0800 (PST) Received: from localhost ([2001:4091:a246:86d6:2b1a:7262:ad08:3918]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-64b3f584800sm332294a12.30.2025.12.16.12.04.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Dec 2025 12:04:24 -0800 (PST) From: "Markus Schneider-Pargmann (TI.com)" Date: Tue, 16 Dec 2025 21:03:47 +0100 Subject: [PATCH v2 3/3] clocksource/drivers/timer-ti-dm: Add clockevent 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: <20251216-topic-ti-dm-clkevt-v6-16-v2-3-bfd7dd085c19@baylibre.com> References: <20251216-topic-ti-dm-clkevt-v6-16-v2-0-bfd7dd085c19@baylibre.com> In-Reply-To: <20251216-topic-ti-dm-clkevt-v6-16-v2-0-bfd7dd085c19@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=6667; i=msp@baylibre.com; h=from:subject:message-id; bh=JMgYaq8WQ1kszJyA/EA+8xzCsDM1CdpeYKJ5q2VZfqk=; b=owGbwMvMwCXWejAsc4KoVzDjabUkhkzH3ZZK1WUmTYI5EVt3O/MdmO/VdPic44WXHv6cDXNTo pqbn/h1lLIwiHExyIopsnQmhqb9l995LHnRss0wc1iZQIYwcHEKwETe6jMynLuiuIb1s5v5bAne U6zLnuybqNsmOvnH+bXa0+Rn6E24ms7IsDwvuqcw8gbH5cf6Hwr++e/KTvLh0wz8OH9W9QnNsth 57AA= X-Developer-Key: i=msp@baylibre.com; a=openpgp; fpr=BADD88DB889FDC3E8A3D5FE612FA6A01E0A45B41 Add support for using the TI Dual-Mode Timer for clockevents. The second always on device with the "ti,timer-alwon" property is selected to be used for clockevents. The first one is used as clocksource. This allows clockevents to be setup independently of the CPU. Signed-off-by: Markus Schneider-Pargmann (TI.com) --- drivers/clocksource/timer-ti-dm.c | 138 ++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 133 insertions(+), 5 deletions(-) diff --git a/drivers/clocksource/timer-ti-dm.c b/drivers/clocksource/timer-= ti-dm.c index 9617bbe96209b91e58fabc2c275280703ce8af7c..fa2c7d19b9e53e3444a86f6b4f8= baafd7e669887 100644 --- a/drivers/clocksource/timer-ti-dm.c +++ b/drivers/clocksource/timer-ti-dm.c @@ -21,8 +21,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -159,7 +161,14 @@ struct dmtimer_clocksource { unsigned int loadval; }; =20 +struct omap_dm_timer_clockevent { + struct clock_event_device dev; + struct dmtimer *timer; + u32 period; +}; + static resource_size_t omap_dm_timer_clocksource_base; +static resource_size_t omap_dm_timer_clockevent_base; static void __iomem *omap_dm_timer_sched_clock_counter; =20 enum { @@ -1203,6 +1212,9 @@ static void omap_dm_timer_find_alwon(void) { struct device_node *np; =20 + if (omap_dm_timer_clocksource_base && omap_dm_timer_clockevent_base) + return; + for_each_matching_node(np, omap_timer_match) { struct resource res; =20 @@ -1215,13 +1227,22 @@ static void omap_dm_timer_find_alwon(void) if (of_address_to_resource(np, 0, &res)) continue; =20 - omap_dm_timer_clocksource_base =3D res.start; + if (!omap_dm_timer_clocksource_base) { + omap_dm_timer_clocksource_base =3D res.start; + continue; + } =20 - of_node_put(np); - return; + if (res.start !=3D omap_dm_timer_clocksource_base) { + omap_dm_timer_clockevent_base =3D res.start; + + of_node_put(np); + return; + } } =20 - omap_dm_timer_clocksource_base =3D -1; + if (!omap_dm_timer_clocksource_base) + omap_dm_timer_clocksource_base =3D -1; + omap_dm_timer_clockevent_base =3D -1; } =20 static struct dmtimer_clocksource *omap_dm_timer_to_clocksource(struct clo= cksource *cs) @@ -1300,6 +1321,105 @@ static int omap_dm_timer_setup_clocksource(struct d= mtimer *timer) return 0; } =20 +static struct omap_dm_timer_clockevent *to_dm_timer_clockevent(struct cloc= k_event_device *evt) +{ + return container_of(evt, struct omap_dm_timer_clockevent, dev); +} + +static int omap_dm_timer_evt_set_next_event(unsigned long cycles, + struct clock_event_device *evt) +{ + struct omap_dm_timer_clockevent *clkevt =3D to_dm_timer_clockevent(evt); + struct dmtimer *timer =3D clkevt->timer; + + dmtimer_write(timer, OMAP_TIMER_COUNTER_REG, 0xffffffff - cycles); + dmtimer_write(timer, OMAP_TIMER_CTRL_REG, OMAP_TIMER_CTRL_ST); + + return 0; +} + +static int omap_dm_timer_evt_shutdown(struct clock_event_device *evt) +{ + struct omap_dm_timer_clockevent *clkevt =3D to_dm_timer_clockevent(evt); + struct dmtimer *timer =3D clkevt->timer; + + __omap_dm_timer_stop(timer); + + return 0; +} + +static int omap_dm_timer_evt_set_periodic(struct clock_event_device *evt) +{ + struct omap_dm_timer_clockevent *clkevt =3D to_dm_timer_clockevent(evt); + struct dmtimer *timer =3D clkevt->timer; + + omap_dm_timer_evt_shutdown(evt); + + omap_dm_timer_set_load(&timer->cookie, clkevt->period); + dmtimer_write(timer, OMAP_TIMER_COUNTER_REG, clkevt->period); + dmtimer_write(timer, OMAP_TIMER_CTRL_REG, + OMAP_TIMER_CTRL_AR | OMAP_TIMER_CTRL_ST); + + return 0; +} + +static irqreturn_t omap_dm_timer_evt_interrupt(int irq, void *dev_id) +{ + struct omap_dm_timer_clockevent *clkevt =3D dev_id; + struct dmtimer *timer =3D clkevt->timer; + + __omap_dm_timer_write_status(timer, OMAP_TIMER_INT_OVERFLOW); + + clkevt->dev.event_handler(&clkevt->dev); + + return IRQ_HANDLED; +} + +static int omap_dm_timer_setup_clockevent(struct dmtimer *timer) +{ + struct device *dev =3D &timer->pdev->dev; + struct omap_dm_timer_clockevent *clkevt; + int ret; + + clkevt =3D devm_kzalloc(dev, sizeof(*clkevt), GFP_KERNEL); + if (!clkevt) + return -ENOMEM; + + timer->reserved =3D 1; + clkevt->timer =3D timer; + + clkevt->dev.name =3D "omap_dm_timer"; + clkevt->dev.features =3D CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT; + clkevt->dev.rating =3D 300; + clkevt->dev.set_next_event =3D omap_dm_timer_evt_set_next_event; + clkevt->dev.set_state_shutdown =3D omap_dm_timer_evt_shutdown; + clkevt->dev.set_state_periodic =3D omap_dm_timer_evt_set_periodic; + clkevt->dev.set_state_oneshot =3D omap_dm_timer_evt_shutdown; + clkevt->dev.set_state_oneshot_stopped =3D omap_dm_timer_evt_shutdown; + clkevt->dev.tick_resume =3D omap_dm_timer_evt_shutdown; + clkevt->dev.cpumask =3D cpu_possible_mask; + clkevt->period =3D 0xffffffff - DIV_ROUND_CLOSEST(timer->fclk_rate, HZ); + + __omap_dm_timer_init_regs(timer); + __omap_dm_timer_stop(timer); + __omap_dm_timer_enable_posted(timer); + + ret =3D devm_request_irq(dev, timer->irq, omap_dm_timer_evt_interrupt, + IRQF_TIMER, "omap_dm_timer_clockevent", clkevt); + if (ret) { + dev_err(dev, "Failed to request interrupt: %d\n", ret); + return ret; + } + + __omap_dm_timer_int_enable(timer, OMAP_TIMER_INT_OVERFLOW); + + clockevents_config_and_register(&clkevt->dev, timer->fclk_rate, + 3, + 0xffffffff); + + return 0; +} + /** * omap_dm_timer_probe - probe function called for every registered device * @pdev: pointer to current timer platform device @@ -1316,7 +1436,7 @@ static int omap_dm_timer_probe(struct platform_device= *pdev) struct resource *res; int ret; =20 - if (!omap_dm_timer_clocksource_base) + if (!omap_dm_timer_clocksource_base || !omap_dm_timer_clockevent_base) omap_dm_timer_find_alwon(); =20 pdata =3D of_device_get_match_data(dev); @@ -1393,6 +1513,14 @@ static int omap_dm_timer_probe(struct platform_devic= e *pdev) =20 res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); =20 + if (omap_dm_timer_clockevent_base && res && + res->start =3D=3D omap_dm_timer_clockevent_base && + !IS_ERR_OR_NULL(timer->fclk)) { + ret =3D omap_dm_timer_setup_clockevent(timer); + if (ret) + return ret; + } + if (omap_dm_timer_clocksource_base && res && res->start =3D=3D omap_dm_timer_clocksource_base && !IS_ERR_OR_NULL(timer->fclk)) { --=20 2.51.0