From nobody Wed Oct 8 22:17:55 2025 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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 B57B6299A90 for ; Mon, 23 Jun 2025 19:26:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750706769; cv=none; b=RMHB4dSyxpWsbGKAP7FE1NdadTa8qITFOfxhaaeF6Iob82vx05eDUKUEuo2Cn24oMVLqJAniZ5Kn+B4/4CKBzElrIMuWVosgThKIdVcIoKXvURdkJY8DEoG/KwkKFTO1gyraxp/OcyMQ0MkfIkzKkUgWH61DB8OvfTYjTKooxw4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750706769; c=relaxed/simple; bh=2do0m4eS04pLS6E+t981rBqNdOJ9dK+R9dX2h3pPpl0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NX5wkR7gVRdCfeiAaxIpyK3Vu9LFKxLO5GZfQkSKGRm17Ozbe75o2iyZ7G6sBCK2VyN7sdGNG3loFYrt9UI+i5dYGQpfzYLnOBDXv9vR6J6n86kz76oY10vV1oh0RXrwOjcvQ9LBTw1Uo3pRCCQ2GEuLPSTm4Y0QbY5bvUlhupY= 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=m0VJRRi6; arc=none smtp.client-ip=209.85.208.47 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="m0VJRRi6" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-608acb0a27fso7032950a12.0 for ; Mon, 23 Jun 2025 12:26:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1750706765; x=1751311565; 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=5pXeWDiz3VTsRPC4fd9L/dNZnY19/uuc2gPQ4wcO2zw=; b=m0VJRRi6/oistSQOEwsJL8hiMRE1EOUi+ku7x0o2JQIFciWqaioalc5ARh4Z6AmyIB 5ITIfRSwgfcHugyqtHFgsP2H18bX2wdmlPTuyxNCnn0y7e/XzqzJWbSwEc29L89aQAVz AYR83n8i/6WQoq7/zonR5BH4O/3aTwIdV2ZjetXThOSf53f7NCgAzOV9a6z/+Xrm+iyC uZN9dUGXD784yMUjp2X2KnmKL2oaEtjUklSEwxE77k+ZXO4Yz2yx8ou65ye/9jhMFLmo 9yB5oMXDuMD90+iibj84k1QcB0WCaAjoiUPNp7xefjLmv47KLlpYYjaVxXIWimkRTI04 ETxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750706765; x=1751311565; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5pXeWDiz3VTsRPC4fd9L/dNZnY19/uuc2gPQ4wcO2zw=; b=Jy/Qm/jqvnQpc+dEKUvZUdo0D6+swgoci5i+KBx7zJutNnXxfAxgMk7S4fQ8zj/OsA vuFxIrj61LpLVlYSFnxc3hgAb9aCKf54ZXMdowalYE9kPJA5x2iqo+USXEWlttXmBpHf E8pqwe5Uwqtk1DI1xJPZXrGef8rBQzeNumOrKj4LqQalX+9CK3hTycc+BwIFpEDDCWpC mlrCxIleO59lQ72D858mA0WQaBJPXCv4Yh3FCuCB+yVrHnSAon8CnC57UZdpXkGppCLP XkzEohwealPQQXDtpix2xQXozfzmSyp015zS9MSsfjlDfo/AAM4Jo0rfqzbDELlPLqq3 ktng== X-Forwarded-Encrypted: i=1; AJvYcCXU2GGI45htO+bvNWAN0S8aEVciwhWGEKEHTNGZwnLJfzkzDb47IPPkm6Mh0E5HHggFGGxvVWxZkIMcvXs=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+1KW3ibmtlF26XVHt5vQCUqJHGIBDrlBLnS/mshlSas9BTKio LMse7QkfGB0AVV/fEZ+FikfW/2cEU51Racp+fzlPmO51fxI8Ex9ju8MMLvSDtAPStDDQsF/ZiOn Oo3g/ X-Gm-Gg: ASbGncvuHVDsltoLeBAAGwsOPhkAVKFTt8hZU3g0aHIZKoFDMGzRwVU3W3caylerkgM s8Q9PHqtwEfNL7UEw4aMIRu59Y6MU0xge6jr4eLr1mFUN8BG84EWScijupBWVvqGG5H1RqOvhjl hPy1TGdm1uUvsQc3cs774ZKTLIHYqt+/M9l96l0F+iKh0iwU1vNB+GV0agJoRnr5VRjrqezIvUJ nUUtRaWciKkQtsQ5BxHH4GOgFJlMGfzPtsu49TiY/7tq/sYsVC5Pvjl7tmvdmgReybKx0YmPr3v va2dlx79rVYIU0E23saWMlyYCSrPP2Qg9ZhiXv40xZ6s55RJW6LbAdXDOvk= X-Google-Smtp-Source: AGHT+IGvW8Bcivz7RdQbWRva/Bh2ZYAw7JSA749WpYWFkoUVql55UY9RAPWXcGRRSH8pPoN9cJ2ctQ== X-Received: by 2002:a17:907:3e0f:b0:ae0:1883:78ce with SMTP id a640c23a62f3a-ae057f21663mr1282338066b.47.1750706764886; Mon, 23 Jun 2025 12:26:04 -0700 (PDT) Received: from localhost ([2001:4090:a244:83c4:9fe4:a128:a20c:8b84]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-ae054082d25sm743685066b.88.2025.06.23.12.26.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jun 2025 12:26:04 -0700 (PDT) From: Markus Schneider-Pargmann Date: Mon, 23 Jun 2025 21:24:28 +0200 Subject: [PATCH 1/3] clocksource/drivers/timer-ti-dm: Fix property name in comment 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: <20250623-topic-ti-dm-clkevt-v6-16-v1-1-b00086761ee1@baylibre.com> References: <20250623-topic-ti-dm-clkevt-v6-16-v1-0-b00086761ee1@baylibre.com> In-Reply-To: <20250623-topic-ti-dm-clkevt-v6-16-v1-0-b00086761ee1@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 X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1225; i=msp@baylibre.com; h=from:subject:message-id; bh=2do0m4eS04pLS6E+t981rBqNdOJ9dK+R9dX2h3pPpl0=; b=owGbwMvMwCXWejAsc4KoVzDjabUkhozIVVYyuv+deRKtquWm7YyodPVmrPRtOpe2v7PBUafvI cuM42c7SlkYxLgYZMUUWToTQ9P+y+88lrxo2WaYOaxMIEMYuDgFYCLq1owM57/6vc/zZzOw1zod qLrH88jx7ADlOzfLPRftnFDV5sXEzMjwg0k4Z1ug/71Z31zXn8s8N4Xjw8KAudXRX/5c+XaKv2c GJwA= X-Developer-Key: i=msp@baylibre.com; a=openpgp; fpr=BADD88DB889FDC3E8A3D5FE612FA6A01E0A45B41 ti,always-on property doesn't exist. ti,timer-alwon is meant here. Fix this minor bug in the comment. Signed-off-by: Markus Schneider-Pargmann Reviewed-by: Dhruva Gole Reviewed-by: Kevin Hilman --- drivers/clocksource/timer-ti-dm-systimer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/clocksource/timer-ti-dm-systimer.c b/drivers/clocksour= ce/timer-ti-dm-systimer.c index 985a6d08512b42f499b3e243eb69cc9674bc8e53..fb0a3cc23b5a35e2906a253d36c= cef2baccca50a 100644 --- a/drivers/clocksource/timer-ti-dm-systimer.c +++ b/drivers/clocksource/timer-ti-dm-systimer.c @@ -226,7 +226,7 @@ static bool __init dmtimer_is_preferred(struct device_n= ode *np) * Some omap3 boards with unreliable oscillator must not use the counter_3= 2k * or dmtimer1 with 32 KiHz source. Additionally, the boards with unreliab= le * oscillator should really set counter_32k as disabled, and delete dmtime= r1 - * ti,always-on property, but let's not count on it. For these quirky case= s, + * ti,timer-alwon property, but let's not count on it. For these quirky ca= ses, * we prefer using the always-on secure dmtimer12 with the internal 32 KiHz * clock as the clocksource, and any available dmtimer as clockevent. * --=20 2.49.0 From nobody Wed Oct 8 22:17:55 2025 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (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 C5BC21E1DFE for ; Mon, 23 Jun 2025 19:26:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750706770; cv=none; b=qWm7CDvzwgQU6PT70sMWOeRntPpK029KPpFb2UgrFcIwZtUMwKPLktgsYil3MthzSZ9b+WmcOdTcQmI/s35xKwm4/PrH0eHlYfQaF88wlKGzh1AmIHaIWecGYUGOgvVu/CxzB5/bEsAkHXkatrKlp7OkWu+vtHddnS/hnxQMOVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750706770; c=relaxed/simple; bh=M2CqLZ0we9DeOHjdeaLn157gWrOfT6VUa3BCVJb11LI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gKLfYvLYMo+33rABdp4wwqbkRn41MxI7SRrE40qlgI8E/4BG9DM5AqrkWyvSpXgcpSZE3pptZqAcAwN7a0uGwuibGfMFCfYPIr2m8kZyRiikjb2TAH+AD/zjhx9Xucu6h1GSkMvaJAi2HVUDlrbU55urqbwfC2Gw4RmnikfevMU= 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=ax6vwBo6; arc=none smtp.client-ip=209.85.208.53 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="ax6vwBo6" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-6099d89a19cso9616601a12.2 for ; Mon, 23 Jun 2025 12:26:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1750706766; x=1751311566; 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=ZMV1moI4oywoM9xdSdqey4ZkIFS6cCeNCpT5ft900Nc=; b=ax6vwBo60+BZmTpCGoiGzUyWGkQzvcYm8TzlwSEh882bcfecKeA8aF4klIyMNnMjB+ F2guyL0UPcD4hSfnGSKon44SWOYs4qT8w2f0PP9nwS7XDopzRb6okNAnkGrpuG4PUHr0 mWBqqbKeDI2Kc2n1QqNxw79ISAmqXLZmesq653CyBC+ph50dA7WSp+922ucXOk93ioEc cV8KtzAOJQB/9cdHIm5qz7ymDsV58CiHWi06yQ7clod+YNIarpNy3ioDZhASxYKZr1WR qSgDblDVuPco/Ly/vzll0IeTvJb9dn3mAIbKVdQVFfaInSoTUoCNXpCH7FGd/B6/MucR WmZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750706766; x=1751311566; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZMV1moI4oywoM9xdSdqey4ZkIFS6cCeNCpT5ft900Nc=; b=Oj9kU7CH+FoQDxPDYIkyKUBcZkzOJX+N+kqddA46MiyVOWN2Km13OkK/a3I5EwJENs F/P2o0gPLVTdnWb7NtP6XxCnIEsYSJjcM3EAzR0gWfQLra6eSZfEBs9XGRvM2dwUS8oZ k8UvbQ1/E36I6hSzyL2Qd8j6EksqqszcCbfizdpgigSghEZWsAIG5n7bPgvPkjCC+MlX BYGqtIa3PklzHLacvmOeA9puUlw1lAnf+7O9ghIHj5hoqGPcYC0C+TPtLn2UbpLZEqYw UIqBxi2mb5sQfWdm4EChH89CFrCA24mN25TbmbStO91QOUMjF1c4yoRRL82VdTw2jlYG ltJQ== X-Forwarded-Encrypted: i=1; AJvYcCULuIyqY7zCl1+rbpN74+r6Jp8qqrUYwYHUMmCeA3Bhq6c+LOIsXsHdcUDCVdTnKhIju/IflktNn7mDCHA=@vger.kernel.org X-Gm-Message-State: AOJu0Yzdw8Mky0V5TxiJIkvLMCHi9K/UJ0srqYiz5M+vQtaBkZLWN70N QEQrojEMp0vcYNV5fabLPPxjYrmty56Ljc8usyNz26gHKNbWaBXyrk+O9kNB0ftM4uA= X-Gm-Gg: ASbGncvHUYGX6LSum/wCrYI6KUNRbP6DtKVfR7HoDy8or2on0+I6CbCudzCw01Li2XH Aud/rUhHi5QvM8loncEqP8qioKuSmQp5LmKFWhEVMciULy9sKaAyOO4bpoEutc1XGiUs0hP9Z6e CVuNrvtKdmPxUb/bzOsOjHhOwiVInX4rjbhrPrQNE+1BbBMnzrUrGiqpWUX3aTZYlPR4XEDYC7Z cwXvg1HuJnCcZWHjoGILQNgmVE8iDABZaMa4cn/xnmPb86W4ZgAjO/9hvKQufRypDi9j5uA8FgY YEgy6THQY3OhZM+1ZNTGj2F2PLLJd8o1U9R2STrMI9zZGHhTRLGjApg+TvY= X-Google-Smtp-Source: AGHT+IFJuXhaFRH27Fy79DnV1ailWssd+BP+YwZERJQll/onbOiIQacL7DjMugkt2pRsUdVvzMgAHA== X-Received: by 2002:a17:907:7286:b0:ade:4300:6c8f with SMTP id a640c23a62f3a-ae057c4685fmr1388618566b.57.1750706766045; Mon, 23 Jun 2025 12:26:06 -0700 (PDT) Received: from localhost ([2001:4090:a244:83c4:9fe4:a128:a20c:8b84]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-ae053e7fbd9sm750159166b.33.2025.06.23.12.26.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jun 2025 12:26:05 -0700 (PDT) From: Markus Schneider-Pargmann Date: Mon, 23 Jun 2025 21:24:29 +0200 Subject: [PATCH 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: <20250623-topic-ti-dm-clkevt-v6-16-v1-2-b00086761ee1@baylibre.com> References: <20250623-topic-ti-dm-clkevt-v6-16-v1-0-b00086761ee1@baylibre.com> In-Reply-To: <20250623-topic-ti-dm-clkevt-v6-16-v1-0-b00086761ee1@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 X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6695; i=msp@baylibre.com; h=from:subject:message-id; bh=M2CqLZ0we9DeOHjdeaLn157gWrOfT6VUa3BCVJb11LI=; b=owGbwMvMwCXWejAsc4KoVzDjabUkhozIVfaCOUxRperz7JTlI9acqGHp+r7auijwl8wW523Vp /bIzdjRUcrCIMbFICumyNKZGJr2X37nseRFyzbDzGFlAhnCwMUpABP5JcDwh19bwGDXh7mRv6+V bI3odWZnjnBXNjjx+OvLvffena2VX8zwz7Ts4YWk3/F/69fE/Dw6h6vqbMO+pBm+f7ZUaxl5bFD qYwUA 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 --- drivers/clocksource/timer-ti-dm.c | 137 ++++++++++++++++++++++++++++++++++= +++- 1 file changed, 136 insertions(+), 1 deletion(-) diff --git a/drivers/clocksource/timer-ti-dm.c b/drivers/clocksource/timer-= ti-dm.c index e9e32df6b56664bc0bd94050380314a757d05ebd..085609ba2d249dcc8f53c8aaa83= 1d8fbe69b3753 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 =20 @@ -141,12 +144,23 @@ struct dmtimer { struct notifier_block nb; struct notifier_block fclk_nb; unsigned long fclk_rate; + + struct dmtimer_clocksource *clksrc; }; =20 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, @@ -1073,6 +1087,107 @@ 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 -1; +} + +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 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; + timer->clksrc =3D clksrc; + + 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"); + + return 0; +} + /** * omap_dm_timer_probe - probe function called for every registered device * @pdev: pointer to current timer platform device @@ -1086,8 +1201,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); @@ -1160,6 +1279,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) { @@ -1187,6 +1316,9 @@ static int omap_dm_timer_probe(struct platform_device= *pdev) return 0; =20 err_disable: + if (timer->clksrc) + clocksource_unregister(&timer->clksrc->dev); + pm_runtime_disable(dev); return ret; } @@ -1201,10 +1333,13 @@ static int omap_dm_timer_probe(struct platform_devi= ce *pdev) */ static void omap_dm_timer_remove(struct platform_device *pdev) { - struct dmtimer *timer; + struct dmtimer *timer =3D dev_get_drvdata(&pdev->dev); unsigned long flags; int ret =3D -EINVAL; =20 + if (timer->clksrc) + clocksource_unregister(&timer->clksrc->dev); + spin_lock_irqsave(&dm_timer_lock, flags); list_for_each_entry(timer, &omap_timer_list, node) if (!strcmp(dev_name(&timer->pdev->dev), --=20 2.49.0 From nobody Wed Oct 8 22:17:55 2025 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 3C82F2D4B40 for ; Mon, 23 Jun 2025 19:26:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750706774; cv=none; b=bucloVS1wuxGySV8nBOZNC4MWwCV3LoIZ4NYKh07FIHSAkvhUdcZowWJGThL3GHQGJHCyDQexoU7ad+8TIeBD/dk5d4hs7Fz/pBreTaVaShYoo+gMdMBXWO/Ak4oMKb4g1/qW55X2wg1Bw6LZ0NzIkbtpMk9hj7mQChjrmeYOvU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750706774; c=relaxed/simple; bh=XwwMkrgJbQ+iphWDh7a1A3iYblM9/iVX+IUeIy/8wrc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QCTQHSocVfFLPHHjbuzz7JPvxzE/A9FDWJ/teGY01fLJp7qLspEKTcSm1FjZg6DELeHeZ/jIs5Uz+cK1TRiflzxHEPgqdH4hvEWjpZpYpNf7z9AADzbT9dzvXhGXdjNJ+/enNSCYWu8K0L5SbU9/tjQ8ptCLGLt6Y+aebNH6UHA= 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=GMcHEavG; arc=none smtp.client-ip=209.85.218.45 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="GMcHEavG" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-addda47ebeaso952848766b.1 for ; Mon, 23 Jun 2025 12:26:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1750706767; x=1751311567; 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=wHvDFrJ6H1+v1HU0C9Dh3b9mcZBS7rbiWmZCIgdgUQQ=; b=GMcHEavG7nqxHVl7o/7fX7lO+e+q28z0dzSxgpSnFTM+IiW1BVrisBrFW+YOgVc4Mg XcviGwuiWwiHTNulfqqKRc9gPei6Jr0F8Q+pfJryttL7+X6rCiB7WEHVGUqZL1SCVk6l tPOJKQ6FQOTogZtK6/g4gYZbcYu3lNYV3pq8nxMa+hpSEaFeARRzkQHr34PeBzkdxay3 VGtKvEjFOQPBEopzWAx6UfSlaDoHy/tyng9biIP/KfqVxhdaDvkr7z5ZU9lua4pbsTX8 gvHNe88H/jHXVWFc6qtlFHiZdOpTiSY3PIAHcrLRhDCuBkJzLEobiKVMYpInx+29YoWJ glmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750706767; x=1751311567; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wHvDFrJ6H1+v1HU0C9Dh3b9mcZBS7rbiWmZCIgdgUQQ=; b=Wa4yrKyQOcO4ICvK9jNze4m5e5dO4nu1vTZbS6VcCizFj9nKkw6Ud32Ny5Dtr88AJT SkTMke6+qzUbXBW83S409M2Inbt46DECFpg/+OfGHfUu9ahwz4mtnNvxGkAiKLKEMeOT 9xF2KKGlVk4FXbFVNX0fe7twydauhndvyqaKuiyWcMHg7Y2NEMSN5DDLjsry76MVVjLp axTuHCKm+5TP+ksl7d3MwYEhLb8BI0LHFNN1/PpVQDgJNvqBZPUjSbU5ixkVffwxQH9Q WJVk0to3CBgjWwJP9Yq9gUD+KSfgjP9GhtWSCpIvajXBFS7jE8AOpQjGyxh+8BY62XiI 0dpw== X-Forwarded-Encrypted: i=1; AJvYcCVo2v996vODTtEaodJwLR0ZvEZJ3dC52Gw2WNsnYh52kPdpfvPGLvPhX5gCBdfJVZtZiK7GMCPfSQxbwYQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxTdQlwcn1mLLVcd2l+4sEdcJz0LKI9bxsQ1+jXN3yY7r/OdbAg YDz6fo0ophYxKzDj5c/lSWZbtQiqaRVauW5dnG1rdusi1lM5QPfv7BySX6TJEedSIrQ= X-Gm-Gg: ASbGncvetmIbWxL1JRQQqCUZEfgwuRrUnaksv0KU+AHaoFDmLKT2eyTDMNnI+kZES6D 4Cpnf32Fax9vqgWBUzV4oZKlvD4ae0rX2qtNJBiU0mhdvOQ2G2i1RvKKthWWogJYVk+tlameFpV WlBGG5nqT2YW3alqgYfFL52AzSZUG27g5KIUf59n77Pj8HTpG/Mj6PnHUL/THF5uS6gVkF3ZyW8 X83BIwoKYXf/n8LFVWos07mCuos3ZUuzWp+5X+tNtDofstnZnvYI6GOIU5+sZuEm7W2zGizIMGB EUQo1A/VumNUBJrg3CNT46cIM2d8+98Sb2AHhr98NCfwRBERrlHqJgNBpUw/8Gf8VkLqHg== X-Google-Smtp-Source: AGHT+IGSavjgIZ9sXrSj5rozKvqmWef3mvFzR/a5f+aszpHgcxKWhvv9wF7jXblJfFcjqdtuPSj0KA== X-Received: by 2002:a17:907:c0e:b0:adf:f883:aa78 with SMTP id a640c23a62f3a-ae0578d5db5mr1417258966b.10.1750706767405; Mon, 23 Jun 2025 12:26:07 -0700 (PDT) Received: from localhost ([2001:4090:a244:83c4:9fe4:a128:a20c:8b84]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-ae09d72008dsm113675466b.55.2025.06.23.12.26.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jun 2025 12:26:06 -0700 (PDT) From: Markus Schneider-Pargmann Date: Mon, 23 Jun 2025 21:24:30 +0200 Subject: [PATCH 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: <20250623-topic-ti-dm-clkevt-v6-16-v1-3-b00086761ee1@baylibre.com> References: <20250623-topic-ti-dm-clkevt-v6-16-v1-0-b00086761ee1@baylibre.com> In-Reply-To: <20250623-topic-ti-dm-clkevt-v6-16-v1-0-b00086761ee1@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 X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6658; i=msp@baylibre.com; h=from:subject:message-id; bh=XwwMkrgJbQ+iphWDh7a1A3iYblM9/iVX+IUeIy/8wrc=; b=owGbwMvMwCXWejAsc4KoVzDjabUkhozIVa6b1nHzFvuuE5l2+5prcPXkp5q3yh2MGFZ+WHPW1 Saj5zZTRykLgxgXg6yYIktnYmjaf/mdx5IXLdsMM4eVCWQIAxenAEzE/AfDX6E1+z8zFzyLjt+6 LT/HZ73Djvd790Xl2bw12OkofXWpQwDD/4zX57jMvaZ0/TL8+/xAoJ7y91nz+Walxq8XNxU3n3/ jORsA 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 --- 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 085609ba2d249dcc8f53c8aaa831d8fbe69b3753..a17e3e81508793a46cdee815bde= 3ad17fedd55e7 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 @@ -158,7 +160,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 { @@ -1091,6 +1100,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 @@ -1103,13 +1115,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) @@ -1188,6 +1209,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 @@ -1204,7 +1324,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); @@ -1281,6 +1401,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.49.0