From nobody Mon Sep 28 06:35:54 2026 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (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 97709386C3B for ; Tue, 25 Aug 2026 15:48:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787672935; cv=none; b=asOph9wbPUCBgxhDcitfBLV1dNVleHZswcI7KUzbi3fxcvkNVhBVdaln0pn4jSQrdcpuGf2KQfEuW4qqlibXWIB2DbgMWsus2iPyD6IMvQeHhkxJm+XPnRg/qLGENN8kMubNFaqEXM+I+R6080WKQdp6xBUO5N+mu6siU2YPZDI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787672935; c=relaxed/simple; bh=DvwGC2hiaOQv6vXVCrf81R5oEbk2paFhxZaDMe7ibeA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TkxCqMhLDLe8jPB67gNo1RSih7afvW2v8HQRdSQ/nBsyRIIO9mB8fYthm3Ey1BH+rmYyA480NXET/uHIP72Z15e7ylVHD0bNoy3+zslHS2VG9EtWE7j1bd2IdbBag4VBXZ8/5hxxbLEbMR07QJEklq6apIB1sQtZbgvd4jcGYHo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=c3s0h3T4; arc=none smtp.client-ip=209.85.208.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c3s0h3T4" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-6a173ad7cf4so256908a12.3 for ; Tue, 25 Aug 2026 08:48:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787672932; x=1788277732; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=zPZf7gPmP8B8UD6UqrTKwvbuyubRbJ0al5ye5Ryd+7s=; b=c3s0h3T44vKPK5Z+WgyPQblZTtBwOfqG+W9+5ZjtZYJ3jgp3FvtZk+zS7/1zTXDxLQ ar/Yh6vKnYZcxY1MmNbBxPfAV7CYYvGuJYxBU3q/XXR9IiW5/c8N2V2W+6sLfOyDtWKJ bz/W5GSFe/WRxGoYiBafyL9H/xLvyDoLJLAOK+eviBkfSAOfmJCcQkQKlbYLIOXrkCv9 yvTy7gsZhq3fPCraIC8seOWwYZBHJsozFMr3ev+FaJNQS19x+FLsa32lpTnMHsHbS+3B vb4mKa6jRDumUukvzql06u2x1Jtq1mNSPo3omiOvV0maNLhmGINKPFXsxU/oOABgIAsS mqnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787672932; x=1788277732; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=zPZf7gPmP8B8UD6UqrTKwvbuyubRbJ0al5ye5Ryd+7s=; b=MTy8sZaV4bgq7bcv2gGh54oFF9z8D4AYnkpKwZFmbDei+A24sOSTzdFJlSUKgcKY+H n8HpQllsAgM3Y0ilQyE1EOuddAgS/mEyzgA3IsviL69h7ASS8wyCG1LuUYY8XKP9JMUU Vjm02n/MuFDTjkeGODx2vYlJib2UIqSq3CzYlBqg8N2m9GkvFgHpD3xaWO+29pYoJloX JpXBp6DQxzZVRSWnJzCaXc0AeDfevPyHcv0RP8vIPVfncJs2lGfPO6M3ZQre1CtI/9xR GGbeiDjXHX4WSlbRwprSA2s29TmMwwR4q+o1ihpVLJ3y+Kh7EEHm77HNEyCctEe1SJ02 jjGA== X-Forwarded-Encrypted: i=1; AHgh+Rr/JIzSpLkCI/AibR3pv/gzNCNo8v/61OaKfh8c2mJshLZDSWdv+ectVdTcAbZssFFIuHeUZddTSXziTps=@vger.kernel.org X-Gm-Message-State: AFuF++kdfvOuoTA2xJYSoJQYL6bZQCwKSXrRWDb5CCZC2Jyv2g1e1CDk ieYK27cZ7Q0UQ8u9g30tj1wNH5FV9F7qakCNK0yoTEjv4A2b7X6/hCRc X-Gm-Gg: AR+sD10fnrbeqCh0/LAXVmEBvXVrXDkZF3OsRVoYx/imKCilesqHnekJAGzcmVJ+/jf 0wvcHmz8ZyrMqxmSg1rp2tIRPXQuR3vcid1TGYmz6TYDl8NP+5XFfmuUybyaKdMbZL+PIw9erD7 cayaLn2dJMIQp4R3ME3A742UDSjte+HJriwaEdodFvMo+gs8kKp8cUOTZrNh6pYZbvVWQYLNiYw wZ3bUKJS/V+xfNXHA4hYobrSyc/N2IfTeUHm/eRUSzpc+QgOzlRcvizl9y6Y+EljwuKjZDrP6A8 J9XWj3+9owl535UET7N4D0IzkHcGyne9geWAzy1JAWjbuPS03ZBBTW5EHmbc0LDyl0hfpDcYxx7 FFitYFj28U6vLW0zcn7M+KinLTpkPcOW1fX9MjdGAxCOl0jzuJ75d91G7yjBU3we5i3EhDUeBmC OR2Mta/5iyXHgRtVhzlat7A98VRRz2XCPPcs6ICQezegHxc1MOwtdkV13qE00/uiUi2Ib+kRsqB 9KLezNyfXX2 X-Received: by 2002:a17:907:9626:b0:c24:87e3:b8b8 with SMTP id a640c23a62f3a-c249209907amr2738438566b.17.1787672931520; Tue, 25 Aug 2026 08:48:51 -0700 (PDT) Received: from localhost.localdomain ([2a00:23c4:a702:d301:81d:57c0:e4cb:959c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c250a6fd69asm16682066b.18.2026.08.25.08.48.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 08:48:51 -0700 (PDT) From: Biju X-Google-Original-From: Biju To: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Cc: Biju Das , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven , Prabhakar Mahadev Lad , Biju Das , linux-renesas-soc@vger.kernel.org, stable@kernel.org Subject: [PATCH v8 1/9] pwm: rzg2l-gpt: Fix macro used for period/duty cycle conversion Date: Tue, 25 Aug 2026 16:48:29 +0100 Message-ID: <20260825154847.197948-2-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825154847.197948-1-biju.das.jz@bp.renesas.com> References: <20260825154847.197948-1-biju.das.jz@bp.renesas.com> 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 From: Biju Das The driver converts state->period and state->duty_cycle (both in nanoseconds) into timer ticks by multiplying with rate_khz and dividing by USEC_PER_SEC. Since rate_khz is expressed in kHz (cycles per millisecond), the correct divisor is NSEC_PER_MSEC, not USEC_PER_SEC. Both constants evaluate to 1000000, so this is a readability/correctness fix with no functional change, and it keeps the calculation's units self-consistent with the comment describing the overflow bound. Update rzg2l_gpt_calculate_period_or_duty() and rzg2l_gpt_config() accordingly. Cc: stable@kernel.org Fixes: 061f087f5d0b ("pwm: Add support for RZ/G2L GPT") Signed-off-by: Biju Das --- v7->v8: * No change. v7: * New patch. --- drivers/pwm/pwm-rzg2l-gpt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/pwm/pwm-rzg2l-gpt.c b/drivers/pwm/pwm-rzg2l-gpt.c index 1569f3ba8c53..108fa99f832d 100644 --- a/drivers/pwm/pwm-rzg2l-gpt.c +++ b/drivers/pwm/pwm-rzg2l-gpt.c @@ -208,13 +208,13 @@ static u64 rzg2l_gpt_calculate_period_or_duty(struct = rzg2l_gpt_chip *rzg2l_gpt, =20 /* * The calculation doesn't overflow an u64 because prescale =E2=89=A4 5 a= nd so - * tmp =3D val << (2 * prescale) * USEC_PER_SEC + * tmp =3D val << (2 * prescale) * NSEC_PER_MSEC * < 2^32 * 2^10 * 10^6 * < 2^32 * 2^10 * 2^20 * =3D 2^62 */ tmp =3D (u64)val << (2 * prescale); - tmp *=3D USEC_PER_SEC; + tmp *=3D NSEC_PER_MSEC; =20 return DIV64_U64_ROUND_UP(tmp, rzg2l_gpt->rate_khz); } @@ -266,7 +266,7 @@ static int rzg2l_gpt_config(struct pwm_chip *chip, stru= ct pwm_device *pwm, u8 prescale; =20 /* Limit period/duty cycle to max value supported by the HW */ - period_ticks =3D mul_u64_u64_div_u64(state->period, rzg2l_gpt->rate_khz, = USEC_PER_SEC); + period_ticks =3D mul_u64_u64_div_u64(state->period, rzg2l_gpt->rate_khz, = NSEC_PER_MSEC); if (period_ticks > RZG2L_MAX_TICKS) period_ticks =3D RZG2L_MAX_TICKS; /* @@ -288,7 +288,7 @@ static int rzg2l_gpt_config(struct pwm_chip *chip, stru= ct pwm_device *pwm, prescale =3D rzg2l_gpt_calculate_prescale(period_ticks); pv =3D rzg2l_gpt_calculate_pv_or_dc(period_ticks, prescale); =20 - duty_ticks =3D mul_u64_u64_div_u64(state->duty_cycle, rzg2l_gpt->rate_khz= , USEC_PER_SEC); + duty_ticks =3D mul_u64_u64_div_u64(state->duty_cycle, rzg2l_gpt->rate_khz= , NSEC_PER_MSEC); if (duty_ticks > period_ticks) duty_ticks =3D period_ticks; dc =3D rzg2l_gpt_calculate_pv_or_dc(duty_ticks, prescale); --=20 2.43.0 From nobody Mon Sep 28 06:35:54 2026 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.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 5C22B44838A for ; Tue, 25 Aug 2026 15:48:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787672936; cv=none; b=rVPVxdWrBFfd5F3/DITgOvMv2OfuEKLM5KdBIM1wnIB6GLsNANbuRgrlYnw3pOeRt7/dPVzPd4ch4C27vZzygfHZZm+11Y0KHO89Go0VK/d+XSCmCwqh3CricEyCgxKPLbOVF35vXfvQQz6P0WV6FHLc3k27ksZ51myxSUEsOQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787672936; c=relaxed/simple; bh=X7xuRdTC8VW2yrAqZrMZDMKyxd/w6rsGmcCypG/hsl4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nQrQwQa9uh1n6x7iGU47xgNu+h8vU+aWB8tucTssFRxAbV4CLLgqfOolfe/lG7sP7UPwT6gHCr5B6LsoJsNLFcKIRZX8f+Yx0VrS9gqxoyzMTZMs9wgmCmy7oaR24viBFqZ+I9O4TiETda35i5W3+1QJHq+J8TQuwNx4hOniJKw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=spi+il61; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="spi+il61" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-c15cb6f5c12so885194266b.0 for ; Tue, 25 Aug 2026 08:48:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787672933; x=1788277733; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=KQckpbvK5ftrfEZi7ETQMy5CFLIXmnvRXSGh5Es/vhw=; b=spi+il61guWzsTd59AM/2X7VRv+lijKpvILKYLHGxzkfj6dCLXafe0Rnu99NCIi8Do rpb2m2zN2QGCOlJcNhJO8tOmAd2EnXi66MXuBxa6EzdyCPWEHgzFQ8tUcnK4H4MTdkNx /2p4EAGm6RYRnoe0m2pIfv3PTPpEs+wsFjfpSa7TTM3nxpI5VwAdvk1qrzKqNzvj9bns u/or6cxjJ9xwwmYP2RR9oYEBpQ8Y49EEYjXrSlhgoi8QLwwLvdkngCS+TU1QyzmboFUR rf78b9yveJiFCV6tjvIR8yHFAE0fZEQE9Ultnz5Gvmx7jXHGeeNX/4sBPoa2un+TsR7P gaPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787672933; x=1788277733; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=KQckpbvK5ftrfEZi7ETQMy5CFLIXmnvRXSGh5Es/vhw=; b=dgA9mLRRGpbP4uWKX/t5wseDovgbmAl4FcFzpFwgmnGeYkG5/2ltNfh3FkWKpJ6pxp leIG14zxWJuHB6YUnQjgQVbVLd9oLpd6Bo7Q/Sx1EmXsvcqwn+PmZKukq7dJCa8lNtnM 5pAo1A1uulHUiqTVf9Ztws6OtlqAUuuXRpjLoOPMrJtC6sc3Xr2LXQuCKR0/UUUmMboZ TOXxQJNzw1ASPRPhiCrpRkkgqIhB3f8fyCh83pr2+yAXvulZXriUbodEOWE7scncfzOP vqgRTA2cjU41vi12cox2XZ0e4+L21vTLzYu+7XFwvUDP2NCUDMT2xJuz9dlKnF4BF8A1 VdnQ== X-Forwarded-Encrypted: i=1; AHgh+RpC7ISba6WH+CC+aZ71++uJIW7RXO7roHBN666Wb1nvHUeItmdtZtphgYPj2nFj6+PtuSZVREzHgrE5rd4=@vger.kernel.org X-Gm-Message-State: AFuF++nvs3FwjiocOIQjMTEWxd4djgE5VnxJt+n5NqYkltPQqd6IJDmo ZSX45TCZ7/3R4JHw7FrYewJvcKv0ezT5K4WDRSjaMRnahr3pMomvWX4+ X-Gm-Gg: AR+sD13vJBwRciWbwOQg6LHITmCZPg4LYYvYU4av4Q266DWjSuCxXqUoipUgkhdPEhv W8NNY7HcTzj4vjxhXlKkvcqGKIoaKK1uvvXBgzUDtEfORdYx6xUKrKdWjqe/l+5B282DvJWXWue qffD1Ay5jOV75ujn1nmXkUDMyCKp4N10dCDboHMxF420X2NaEznpn36cGCpINpN3iLKpoE2GYaw tUbJDQuOPYHD3AdKmlKVMkGyilrb5LuHoO4fCI94Gzd0Fieqh45i0kYolOLh9DiXjDITyYiCymM 7s2CynNQTdrLvQ95Elo+DBjWvOQCn7sTR2ybgZw/ARyPo7tzA736aJuLdMGoKeV4kxLdLS7Z9aD 8v404s59jwdC4uWQ//ZGdduTf0koe+AI8QA+6jHM8dl5JAYy3jXukp8r0mOwwRcdhiBVEabmSl1 1bjk4sfTsEBhtLJz3KYv1T8NZyzp6l6D/PWb+yWw7h+hjl9Yb7mAZJKEjkNqX2w9crFMUIMwB4m GBPCcC41ieK X-Received: by 2002:a17:907:d28:b0:c21:72b:dec0 with SMTP id a640c23a62f3a-c249238cd9cmr3125388766b.5.1787672932261; Tue, 25 Aug 2026 08:48:52 -0700 (PDT) Received: from localhost.localdomain ([2a00:23c4:a702:d301:81d:57c0:e4cb:959c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c250a6fd69asm16682066b.18.2026.08.25.08.48.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 08:48:51 -0700 (PDT) From: Biju X-Google-Original-From: Biju To: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Cc: Biju Das , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven , Prabhakar Mahadev Lad , Biju Das , linux-renesas-soc@vger.kernel.org Subject: [PATCH v8 2/9] pwm: rzg2l-gpt: Convert to waveform callbacks Date: Tue, 25 Aug 2026 16:48:30 +0100 Message-ID: <20260825154847.197948-3-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825154847.197948-1-biju.das.jz@bp.renesas.com> References: <20260825154847.197948-1-biju.das.jz@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Biju Das Migrate the rzg2l-gpt driver from the legacy .get_state/.apply ops to the new waveform callback interface. Introduce struct rzg2l_gpt_waveform to represent a hardware waveform configuration holding the period register value (gtpr), compare/capture register value (gtccr), and prescaler (prescale). Signed-off-by: Biju Das --- v7->v8: * Cached prescale value. * Updated rzg2l_gpt_write_waveform() for caching the period, If the channel is already enabled and the user changes its period. v6->v7: * Avoided recalculation of prescale, if is_small_second_period =3D=3D true. * Moved `wfhw->gtccr =3D 0` into the if block in rzg2l_gpt_config(). v5->v6: * Dropped local variables pv and dc from rzg2l_gpt_round_waveform_tohw(). * Dropped blank line in rzg2l_gpt_round_waveform_tohw(). * Moved assignment of rzg2l_gpt->period_ticks[ch] to *_write_waveform(). * Restored clamping of duty_ticks with period_ticks in rzg2l_gpt_round_waveform_tohw(). * Simplified rzg2l_gpt_write_waveform() using else if statement. * Dropped local variable gptr in rzg2l_gpt_write_waveform(). * Moved mutex after early return in rzg2l_gpt_round_waveform_tohw(). v5: * Updated commit description. * Updated rzg2l_gpt_round_waveform_tohw() to initialize gtccr when the period of the second channel is smaller. * Replaced period_ticks with RZG2L_MAX_TICKS for the duty_ticks maximum value check in rzg2l_gpt_round_waveform_tohw(). v4 from [1] [1] https://lore.kernel.org/all/20251208152133.269316-3-biju.das.jz@bp.rene= sas.com/ --- drivers/pwm/pwm-rzg2l-gpt.c | 213 +++++++++++++++++++++++------------- 1 file changed, 134 insertions(+), 79 deletions(-) diff --git a/drivers/pwm/pwm-rzg2l-gpt.c b/drivers/pwm/pwm-rzg2l-gpt.c index 108fa99f832d..0a66da0f98c9 100644 --- a/drivers/pwm/pwm-rzg2l-gpt.c +++ b/drivers/pwm/pwm-rzg2l-gpt.c @@ -84,6 +84,14 @@ struct rzg2l_gpt_chip { u64 period_ticks[RZG2L_MAX_HW_CHANNELS]; u32 channel_request_count[RZG2L_MAX_HW_CHANNELS]; u32 channel_enable_count[RZG2L_MAX_HW_CHANNELS]; + u8 prescale[RZG2L_MAX_HW_CHANNELS]; +}; + +/* This represents a hardware configuration for one channel */ +struct rzg2l_gpt_waveform { + u32 gtpr; + u32 gtccr; + u8 prescale; }; =20 static inline struct rzg2l_gpt_chip *to_rzg2l_gpt_chip(struct pwm_chip *ch= ip) @@ -152,7 +160,8 @@ static void rzg2l_gpt_free(struct pwm_chip *chip, struc= t pwm_device *pwm) rzg2l_gpt->channel_request_count[ch]--; } =20 -static bool rzg2l_gpt_is_ch_enabled(struct rzg2l_gpt_chip *rzg2l_gpt, u8 h= wpwm) +static bool rzg2l_gpt_is_ch_enabled(struct rzg2l_gpt_chip *rzg2l_gpt, u8 h= wpwm, + u32 *gtcr) { u8 ch =3D RZG2L_GET_CH(hwpwm); u32 val; @@ -161,6 +170,9 @@ static bool rzg2l_gpt_is_ch_enabled(struct rzg2l_gpt_ch= ip *rzg2l_gpt, u8 hwpwm) if (!(val & RZG2L_GTCR_CST)) return false; =20 + if (gtcr) + *gtcr =3D val; + val =3D rzg2l_gpt_read(rzg2l_gpt, RZG2L_GTIOR(ch)); =20 return val & RZG2L_GTIOR_OxE(rzg2l_gpt_subchannel(hwpwm)); @@ -219,56 +231,40 @@ static u64 rzg2l_gpt_calculate_period_or_duty(struct = rzg2l_gpt_chip *rzg2l_gpt, return DIV64_U64_ROUND_UP(tmp, rzg2l_gpt->rate_khz); } =20 -static int rzg2l_gpt_get_state(struct pwm_chip *chip, struct pwm_device *p= wm, - struct pwm_state *state) -{ - struct rzg2l_gpt_chip *rzg2l_gpt =3D to_rzg2l_gpt_chip(chip); - - state->enabled =3D rzg2l_gpt_is_ch_enabled(rzg2l_gpt, pwm->hwpwm); - if (state->enabled) { - u32 sub_ch =3D rzg2l_gpt_subchannel(pwm->hwpwm); - u32 ch =3D RZG2L_GET_CH(pwm->hwpwm); - u8 prescale; - u32 val; - - val =3D rzg2l_gpt_read(rzg2l_gpt, RZG2L_GTCR(ch)); - prescale =3D FIELD_GET(RZG2L_GTCR_TPCS, val); - - val =3D rzg2l_gpt_read(rzg2l_gpt, RZG2L_GTPR(ch)); - state->period =3D rzg2l_gpt_calculate_period_or_duty(rzg2l_gpt, val, pre= scale); - - val =3D rzg2l_gpt_read(rzg2l_gpt, RZG2L_GTCCR(ch, sub_ch)); - state->duty_cycle =3D rzg2l_gpt_calculate_period_or_duty(rzg2l_gpt, val,= prescale); - if (state->duty_cycle > state->period) - state->duty_cycle =3D state->period; - } - - state->polarity =3D PWM_POLARITY_NORMAL; - - return 0; -} - static u32 rzg2l_gpt_calculate_pv_or_dc(u64 period_or_duty_cycle, u8 presc= ale) { return min_t(u64, DIV_ROUND_DOWN_ULL(period_or_duty_cycle, 1 << (2 * pres= cale)), U32_MAX); } =20 -/* Caller holds the lock while calling rzg2l_gpt_config() */ -static int rzg2l_gpt_config(struct pwm_chip *chip, struct pwm_device *pwm, - const struct pwm_state *state) +static int rzg2l_gpt_round_waveform_tohw(struct pwm_chip *chip, + struct pwm_device *pwm, + const struct pwm_waveform *wf, + void *_wfhw) { struct rzg2l_gpt_chip *rzg2l_gpt =3D to_rzg2l_gpt_chip(chip); - u8 sub_ch =3D rzg2l_gpt_subchannel(pwm->hwpwm); + struct rzg2l_gpt_waveform *wfhw =3D _wfhw; + bool is_small_second_period =3D false; u8 ch =3D RZG2L_GET_CH(pwm->hwpwm); u64 period_ticks, duty_ticks; - unsigned long pv, dc; - u8 prescale; + + if (wf->period_length_ns =3D=3D 0) { + *wfhw =3D (struct rzg2l_gpt_waveform){ + .gtpr =3D 0, + .gtccr =3D 0, + .prescale =3D 0, + }; + + return 0; + } =20 /* Limit period/duty cycle to max value supported by the HW */ - period_ticks =3D mul_u64_u64_div_u64(state->period, rzg2l_gpt->rate_khz, = NSEC_PER_MSEC); + period_ticks =3D mul_u64_u64_div_u64(wf->period_length_ns, + rzg2l_gpt->rate_khz, NSEC_PER_MSEC); if (period_ticks > RZG2L_MAX_TICKS) period_ticks =3D RZG2L_MAX_TICKS; + + guard(mutex)(&rzg2l_gpt->lock); /* * GPT counter is shared by the two IOs of a single channel, so * prescale and period can NOT be modified when there are multiple IOs @@ -277,29 +273,88 @@ static int rzg2l_gpt_config(struct pwm_chip *chip, st= ruct pwm_device *pwm, if (rzg2l_gpt->channel_request_count[ch] > 1) { u8 sibling_ch =3D rzg2l_gpt_sibling(pwm->hwpwm); =20 - if (rzg2l_gpt_is_ch_enabled(rzg2l_gpt, sibling_ch)) { + if (rzg2l_gpt_is_ch_enabled(rzg2l_gpt, sibling_ch, NULL)) { if (period_ticks < rzg2l_gpt->period_ticks[ch]) - return -EBUSY; + is_small_second_period =3D true; =20 period_ticks =3D rzg2l_gpt->period_ticks[ch]; + wfhw->prescale =3D rzg2l_gpt->prescale[ch]; } + } else { + wfhw->prescale =3D rzg2l_gpt_calculate_prescale(period_ticks); + rzg2l_gpt->prescale[ch] =3D wfhw->prescale; } =20 - prescale =3D rzg2l_gpt_calculate_prescale(period_ticks); - pv =3D rzg2l_gpt_calculate_pv_or_dc(period_ticks, prescale); + wfhw->gtpr =3D rzg2l_gpt_calculate_pv_or_dc(period_ticks, wfhw->prescale); + if (is_small_second_period) { + wfhw->gtccr =3D 0; + return 1; + } =20 - duty_ticks =3D mul_u64_u64_div_u64(state->duty_cycle, rzg2l_gpt->rate_khz= , NSEC_PER_MSEC); + duty_ticks =3D mul_u64_u64_div_u64(wf->duty_length_ns, rzg2l_gpt->rate_kh= z, NSEC_PER_MSEC); if (duty_ticks > period_ticks) duty_ticks =3D period_ticks; - dc =3D rzg2l_gpt_calculate_pv_or_dc(duty_ticks, prescale); + wfhw->gtccr =3D rzg2l_gpt_calculate_pv_or_dc(duty_ticks, wfhw->prescale); =20 - /* - * GPT counter is shared by multiple channels, we cache the period ticks - * from the first enabled channel and use the same value for both - * channels. - */ - rzg2l_gpt->period_ticks[ch] =3D period_ticks; + return 0; +} + +static int rzg2l_gpt_round_waveform_fromhw(struct pwm_chip *chip, + struct pwm_device *pwm, + const void *_wfhw, + struct pwm_waveform *wf) +{ + struct rzg2l_gpt_chip *rzg2l_gpt =3D to_rzg2l_gpt_chip(chip); + const struct rzg2l_gpt_waveform *wfhw =3D _wfhw; + + wf->period_length_ns =3D rzg2l_gpt_calculate_period_or_duty(rzg2l_gpt, wf= hw->gtpr, + wfhw->prescale); + wf->duty_length_ns =3D rzg2l_gpt_calculate_period_or_duty(rzg2l_gpt, wfhw= ->gtccr, + wfhw->prescale); + wf->duty_offset_ns =3D 0; + + return 0; +} + +static int rzg2l_gpt_read_waveform(struct pwm_chip *chip, + struct pwm_device *pwm, + void *_wfhw) +{ + struct rzg2l_gpt_chip *rzg2l_gpt =3D to_rzg2l_gpt_chip(chip); + struct rzg2l_gpt_waveform *wfhw =3D _wfhw; + u32 sub_ch =3D rzg2l_gpt_subchannel(pwm->hwpwm); + u32 ch =3D RZG2L_GET_CH(pwm->hwpwm); + u32 gtcr; + + guard(mutex)(&rzg2l_gpt->lock); + if (rzg2l_gpt_is_ch_enabled(rzg2l_gpt, pwm->hwpwm, >cr)) { + wfhw->prescale =3D FIELD_GET(RZG2L_GTCR_TPCS, gtcr); + wfhw->gtpr =3D rzg2l_gpt_read(rzg2l_gpt, RZG2L_GTPR(ch)); + wfhw->gtccr =3D rzg2l_gpt_read(rzg2l_gpt, RZG2L_GTCCR(ch, sub_ch)); + if (wfhw->gtccr > wfhw->gtpr) + wfhw->gtccr =3D wfhw->gtpr; + } else { + *wfhw =3D (struct rzg2l_gpt_waveform) { }; + } + + return 0; +} + +static u64 rzg2l_gpt_calculate_cycles(u32 value, u8 prescale) +{ + return (u64)value << (2 * prescale); +} + +static int rzg2l_gpt_write_waveform(struct pwm_chip *chip, + struct pwm_device *pwm, + const void *_wfhw) +{ + struct rzg2l_gpt_chip *rzg2l_gpt =3D to_rzg2l_gpt_chip(chip); + const struct rzg2l_gpt_waveform *wfhw =3D _wfhw; + u8 sub_ch =3D rzg2l_gpt_subchannel(pwm->hwpwm); + u8 ch =3D RZG2L_GET_CH(pwm->hwpwm); =20 + guard(mutex)(&rzg2l_gpt->lock); /* * Counter must be stopped before modifying mode, prescaler, timer * counter and buffer enable registers. These registers are shared @@ -318,14 +373,16 @@ static int rzg2l_gpt_config(struct pwm_chip *chip, st= ruct pwm_device *pwm, =20 /* Select count clock */ rzg2l_gpt_modify(rzg2l_gpt, RZG2L_GTCR(ch), RZG2L_GTCR_TPCS, - FIELD_PREP(RZG2L_GTCR_TPCS, prescale)); + FIELD_PREP(RZG2L_GTCR_TPCS, wfhw->prescale)); =20 /* Set period */ - rzg2l_gpt_write(rzg2l_gpt, RZG2L_GTPR(ch), pv); + rzg2l_gpt_write(rzg2l_gpt, RZG2L_GTPR(ch), wfhw->gtpr); + } else if (wfhw->gtpr && (wfhw->gtpr < rzg2l_gpt_read(rzg2l_gpt, RZG2L_GT= PR(ch)))) { + return -EBUSY; } =20 /* Set duty cycle */ - rzg2l_gpt_write(rzg2l_gpt, RZG2L_GTCCR(ch, sub_ch), dc); + rzg2l_gpt_write(rzg2l_gpt, RZG2L_GTCCR(ch, sub_ch), wfhw->gtccr); =20 if (rzg2l_gpt->channel_enable_count[ch] <=3D 1) { /* Set initial value for counter */ @@ -334,44 +391,42 @@ static int rzg2l_gpt_config(struct pwm_chip *chip, st= ruct pwm_device *pwm, /* Set no buffer operation */ rzg2l_gpt_write(rzg2l_gpt, RZG2L_GTBER(ch), 0); =20 - /* Restart the counter after updating the registers */ - rzg2l_gpt_modify(rzg2l_gpt, RZG2L_GTCR(ch), - RZG2L_GTCR_CST, RZG2L_GTCR_CST); + if (wfhw->gtpr) + /* Restart the counter after updating the registers */ + rzg2l_gpt_modify(rzg2l_gpt, RZG2L_GTCR(ch), + RZG2L_GTCR_CST, RZG2L_GTCR_CST); } =20 - return 0; -} - -static int rzg2l_gpt_apply(struct pwm_chip *chip, struct pwm_device *pwm, - const struct pwm_state *state) -{ - struct rzg2l_gpt_chip *rzg2l_gpt =3D to_rzg2l_gpt_chip(chip); - bool enabled =3D pwm->state.enabled; - int ret; - - if (state->polarity !=3D PWM_POLARITY_NORMAL) - return -EINVAL; + if (wfhw->gtpr) { + bool enable =3D rzg2l_gpt_is_ch_enabled(rzg2l_gpt, pwm->hwpwm, NULL); + u8 sibling_ch =3D rzg2l_gpt_sibling(pwm->hwpwm); =20 - guard(mutex)(&rzg2l_gpt->lock); - if (!state->enabled) { - if (enabled) + if (!enable) + rzg2l_gpt_enable(rzg2l_gpt, pwm); + /* + * GPT counter is shared by multiple channels, we cache the + * period ticks from the first enabled channel and use the same + * value for both channels. + */ + if (!enable || (enable && !rzg2l_gpt_is_ch_enabled(rzg2l_gpt, sibling_ch= , NULL))) + rzg2l_gpt->period_ticks[ch] =3D rzg2l_gpt_calculate_cycles(wfhw->gtpr, + wfhw->prescale); + } else { + if (rzg2l_gpt_is_ch_enabled(rzg2l_gpt, pwm->hwpwm, NULL)) rzg2l_gpt_disable(rzg2l_gpt, pwm); - - return 0; } =20 - ret =3D rzg2l_gpt_config(chip, pwm, state); - if (!ret && !enabled) - rzg2l_gpt_enable(rzg2l_gpt, pwm); - - return ret; + return 0; } =20 static const struct pwm_ops rzg2l_gpt_ops =3D { .request =3D rzg2l_gpt_request, .free =3D rzg2l_gpt_free, - .get_state =3D rzg2l_gpt_get_state, - .apply =3D rzg2l_gpt_apply, + .sizeof_wfhw =3D sizeof(struct rzg2l_gpt_waveform), + .round_waveform_tohw =3D rzg2l_gpt_round_waveform_tohw, + .round_waveform_fromhw =3D rzg2l_gpt_round_waveform_fromhw, + .read_waveform =3D rzg2l_gpt_read_waveform, + .write_waveform =3D rzg2l_gpt_write_waveform, }; =20 static int rzg2l_gpt_probe(struct platform_device *pdev) --=20 2.43.0 From nobody Mon Sep 28 06:35:54 2026 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (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 3471D3E47B for ; Tue, 25 Aug 2026 15:48:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787672937; cv=none; b=JK7K0Vts+D6cEWzihVu9Ir46VMAmrTFp74HG0BbsZOgB5UdO+xQ1oATJvvcz0++Aw/Gco/ARFT/OZ1Gt3EXX8EQSTZiBhs18Jr2aRdm/ire7gO4mFcycDvtPDh2oWAalR2SsppR3c1yKuXvK0cUT+1Z2GFeFIrwTDQskysgJiaE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787672937; c=relaxed/simple; bh=VuB36E1lq8H9yU/laDI8ZESD79W3YHrEkAWuM3sQtc0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ARnUkofsHQ+oZDkDWE1JQ1E1h9XIiLNidMDKtyVUfs8MjO/rLwQaFKax0kFNSS2ChQYLfTxicK9okHEFT7JF5h4UugG5tkhLrvbFHm4zFMEcBCqGPwi6mznNk1AqFMfZXQhdEFscmNIeOdpI5dTUSpvA6EW6RR0pGucmeiaaQw4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=frZ3Svma; arc=none smtp.client-ip=209.85.218.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="frZ3Svma" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-c1f758014b8so541928166b.3 for ; Tue, 25 Aug 2026 08:48:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787672933; x=1788277733; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Q0is4BUzYiPNaBY1I22YbPSJWBHP4ENy579LWW0iQKA=; b=frZ3SvmaKlAQTefI3KFuiWfeByevL/SYqEDT7htrIqElokL49XUJgFm7Fcy3f7Z03+ 04E+x87Vy2LgAQfrQosEuCD1/CWDErTLqFa+bhwHUBPmUjfOh76lSlNHIRHVeYOEwxTJ Kwx26RlI5DbYGZPWxMVD8Jh0HGaPvCMw9CA+QiQuTWK1k+4Y032oTKZ6dsyXq6B1hj8I ks2YycRXbr8XRx5TGITcS1DVjalr4mjJ3rxpBmfdp6kGyiwtjFoHyNvk7ddvS2q5iI1G VLGtCa9uUSfedRXEEPT/HpVxlXIQ/KXkNypxVA7LKxHZc1vrU1fuBPIOcQshYgD4HqDs 3aRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787672933; x=1788277733; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Q0is4BUzYiPNaBY1I22YbPSJWBHP4ENy579LWW0iQKA=; b=nzA2eojIFfdGhQnAtFKNb0QMiKOdbtWtWbmTFG8fiF/e6oVnKv4BeA5V6nhSM5l2Af sdxStVxjCs/5z4mjOAUUie2T0ydryKW+eOy4b9lbrZq7MWOYH15Yg6FQMvWoo8XsFp07 y07DXbho8PvUx44JEXXeZfijGwourbr2/K/z2M+3m3PoqAusQQYg8pde97iO0rCWe0e5 d/hQEDBli024Q4uMMkgOTbr0PoIVTgPJGO54cmCFx4XRsqMlKeRyH6Rx686WO+aRtmXs Wki1+F4x6LxDxiFH9ZnVjicwYkxi2/cWfcrz5PlYqOZX+uBvgA2lJRDDRCn3mr95Mdqm M4ZQ== X-Forwarded-Encrypted: i=1; AHgh+RpvdpXaFi1kx10tKblJi8G9P+BPP6aTdvDIwXe9hL+7ZD0eyHZjhp+xEA01uqBunwc9K7Js2KdBisnxYpg=@vger.kernel.org X-Gm-Message-State: AFuF++loo47mB31O3PsixY9Ez/t88it1WDdFIdUDRoGqx3IGqj+u65PS c8jEMi7HHactS1IuLRr9fm3MkAiBjbkXZnqTAeohQNNSBL1aBOIKLR51 X-Gm-Gg: AR+sD11D4c8qI1DRa8gKH3a+IIl8o5rGORnXcZhlgYxgTEZ8DOW6lzbAiw0+idfXtoj xvEHU/7a6lbcEBnntE7jcLCGQDVUSkYZxEv4zlA7Wn/926ZKsyrAOXGSA9+pcZSgddUV2PlDeZA hjeaBEtG4tzIJSETMtF5xFlQSMTMvVOLJp5v9GSase31EYCv5j0B20rLvFpq1qmftqJ0JQeSvEB wuFQOCEueydgzPY8IfP93FteE/t3dJogE4IiULELFvDVvYy6VoTrAmIDhhZy4VrFb/OO+QZ2aCs FbyxR7gBw59+vNVcj3udMLcgjAlgFJFFoew5omv+Y2vsPYMmibUUPJJgzuB7bXXzDycMzvO+U/V UmowrQHMXlBBp19lj/n50qiAZWUCPe+hNv4L0WdJH4cm05+8BCR3VQogg/bt/vDqdk9SiWG4EJk XmmtZxCrsIrLvmWPGnzdV7WqB/W22yw4Ac5he6wvdnRpgYa7Kx9LkhXZZF0HHycqrBFTPM+xYDm OUwqMibjOu0 X-Received: by 2002:a17:906:99c4:b0:c20:af9d:4544 with SMTP id a640c23a62f3a-c246a4e6388mr3638556166b.6.1787672933181; Tue, 25 Aug 2026 08:48:53 -0700 (PDT) Received: from localhost.localdomain ([2a00:23c4:a702:d301:81d:57c0:e4cb:959c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c250a6fd69asm16682066b.18.2026.08.25.08.48.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 08:48:52 -0700 (PDT) From: Biju X-Google-Original-From: Biju To: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Geert Uytterhoeven , Magnus Damm Cc: Biju Das , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar Mahadev Lad , Biju Das , Tommaso Merciai Subject: [PATCH v8 3/9] pwm: rzg2l-gpt: Add info variable to struct rzg2l_gpt_chip Date: Tue, 25 Aug 2026 16:48:31 +0100 Message-ID: <20260825154847.197948-4-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825154847.197948-1-biju.das.jz@bp.renesas.com> References: <20260825154847.197948-1-biju.das.jz@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Biju Das Introduce struct rzg2l_gpt_info to capture SoC-specific hardware differences, starting with the gtcr_tpcs field mask for the prescaler bitfield in GTCR. This is needed because the RZ/G3E GPT has a 4-bit prescaler field versus the 3-bit field on RZ/G2L. Reviewed-by: Tommaso Merciai Signed-off-by: Biju Das --- v7->v8: * No change. v6->v7: * No change. v5->v6: * No change. v4->v5: * Updated commit description. v3->v4: * Dropped field_{get,prep} as mainline now support it. * Updated commit description. * Retained RZG2L_GTCR_TPCS bit definitons * Replaced gtcr_tpcs_mask->gtcr_tpcs v2->v3: * No change. v1->v2: * Collected tag. --- drivers/pwm/pwm-rzg2l-gpt.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/pwm/pwm-rzg2l-gpt.c b/drivers/pwm/pwm-rzg2l-gpt.c index 0a66da0f98c9..87309f519827 100644 --- a/drivers/pwm/pwm-rzg2l-gpt.c +++ b/drivers/pwm/pwm-rzg2l-gpt.c @@ -77,9 +77,14 @@ #define RZG2L_MAX_SCALE_FACTOR 1024 #define RZG2L_MAX_TICKS ((u64)U32_MAX * RZG2L_MAX_SCALE_FACTOR) =20 +struct rzg2l_gpt_info { + u32 gtcr_tpcs; +}; + struct rzg2l_gpt_chip { void __iomem *mmio; struct mutex lock; /* lock to protect shared channel resources */ + const struct rzg2l_gpt_info *info; unsigned long rate_khz; u64 period_ticks[RZG2L_MAX_HW_CHANNELS]; u32 channel_request_count[RZG2L_MAX_HW_CHANNELS]; @@ -328,7 +333,7 @@ static int rzg2l_gpt_read_waveform(struct pwm_chip *chi= p, =20 guard(mutex)(&rzg2l_gpt->lock); if (rzg2l_gpt_is_ch_enabled(rzg2l_gpt, pwm->hwpwm, >cr)) { - wfhw->prescale =3D FIELD_GET(RZG2L_GTCR_TPCS, gtcr); + wfhw->prescale =3D field_get(rzg2l_gpt->info->gtcr_tpcs, gtcr); wfhw->gtpr =3D rzg2l_gpt_read(rzg2l_gpt, RZG2L_GTPR(ch)); wfhw->gtccr =3D rzg2l_gpt_read(rzg2l_gpt, RZG2L_GTCCR(ch, sub_ch)); if (wfhw->gtccr > wfhw->gtpr) @@ -372,8 +377,8 @@ static int rzg2l_gpt_write_waveform(struct pwm_chip *ch= ip, rzg2l_gpt_write(rzg2l_gpt, RZG2L_GTUDDTYC(ch), RZG2L_GTUDDTYC_UP_COUNTIN= G); =20 /* Select count clock */ - rzg2l_gpt_modify(rzg2l_gpt, RZG2L_GTCR(ch), RZG2L_GTCR_TPCS, - FIELD_PREP(RZG2L_GTCR_TPCS, wfhw->prescale)); + rzg2l_gpt_modify(rzg2l_gpt, RZG2L_GTCR(ch), rzg2l_gpt->info->gtcr_tpcs, + field_prep(rzg2l_gpt->info->gtcr_tpcs, wfhw->prescale)); =20 /* Set period */ rzg2l_gpt_write(rzg2l_gpt, RZG2L_GTPR(ch), wfhw->gtpr); @@ -448,6 +453,8 @@ static int rzg2l_gpt_probe(struct platform_device *pdev) if (IS_ERR(rzg2l_gpt->mmio)) return PTR_ERR(rzg2l_gpt->mmio); =20 + rzg2l_gpt->info =3D of_device_get_match_data(dev); + rstc =3D devm_reset_control_get_exclusive_deasserted(dev, NULL); if (IS_ERR(rstc)) return dev_err_probe(dev, PTR_ERR(rstc), "Cannot deassert reset control\= n"); @@ -490,8 +497,12 @@ static int rzg2l_gpt_probe(struct platform_device *pde= v) return 0; } =20 +static const struct rzg2l_gpt_info rzg2l_data =3D { + .gtcr_tpcs =3D RZG2L_GTCR_TPCS, +}; + static const struct of_device_id rzg2l_gpt_of_table[] =3D { - { .compatible =3D "renesas,rzg2l-gpt" }, + { .compatible =3D "renesas,rzg2l-gpt", .data =3D &rzg2l_data }, { /* Sentinel */ } }; MODULE_DEVICE_TABLE(of, rzg2l_gpt_of_table); --=20 2.43.0 From nobody Mon Sep 28 06:35:54 2026 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 2BA5948B38A for ; Tue, 25 Aug 2026 15:48:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787672938; cv=none; b=cDzFvMqtih4e2u6O3pzkML+KnzgR72DcdT+Tzs6SSeogXtB6xBngwBySH5XrsKg7c9U4FU05Nxh7McitvSFDgA6ht1QUFoGBis87Cc+mTuljFHYxZhiHltqY1iw84o8x/VtYM/AQWkRkSTqFOKgAE7D+Smw9RTj51R0i06k03uA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787672938; c=relaxed/simple; bh=MC7THKP3n+rONNU4ruiX6A/Ys9tL+iBw1lcqRapc5MQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Y87lmbxq447yS4mcD57yYO3pyCJDnqjku3ve3nr7UfMJlQIJsdBCoEJjrUVf0gwL/SH8r3sCNyyBT4dAqNa/NN4Rvk167a9B89OoPCmgV486M8hI08n/9GaV05W0XB4BiJPd3/aJxnmx8ceRrUxSB9rPzD6uNsLiVqf4L+Z+BcA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aOODqF84; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aOODqF84" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-c1c26d7e951so748139366b.0 for ; Tue, 25 Aug 2026 08:48:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787672934; x=1788277734; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=MExga4WlZgw7CqaXNVe0QE7cTJjo0WpKD+kxUNlUNiQ=; b=aOODqF84mmcwDdNCOUJEgrX4Nnl3yo148cowAkou0hmck+vxph8wHpAOfUZeZ+ZoJo DSHbY+U7K788cuaRsuWBaoTekmnTn6pdqgfZJhnLstNEbJzruvonA8mfpps71wYdp4u0 9kDE7o+PjCJtSlFUyK7yqTXgYURyXvqcGblYIC1eWryE3t/YqdXawcVAaihz/7JMmGc6 +45/xBhJ8ZTKAapRSVGckOL0pA8H6vPdrjtH4gzM0PE69S1GpOHGPpHrb/B9n7n52pT3 34dTBitNWJxrcDfXGWwdxP8hUjGOC0/xdXNeNf5b46HZkg1BlNW2N4Kwp6I6Ls+SjnvN IR4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787672934; x=1788277734; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=MExga4WlZgw7CqaXNVe0QE7cTJjo0WpKD+kxUNlUNiQ=; b=Sbq6gLfAu2++13kD9q/syV1VjNsQfX3m2bCZvDNgo1JHOwutsjjqvm/v4UtN9cLoTT kEmJPtbN39io22phajir+FuSXknAa1CK4mFQzVJ0NPpIkl6valqvUja8AgpdGBdI1nNG RVEDS2E8EsZfHNQ9gT+dwKnP3/t6Mn79ganoFITcOvhY8vtiqFJ9ztBmih/9DL1AKy1y er2zgiFiyhwmwOAyq1o3rVQwPrJBaGtUVtDk/qZSf9gJkimlf0oC4Fa99X8Fql5JWXxq vQjq7ev8ASxHq85tD2YkurLkwLkF6mbmePpaN9UpZ/qLk7da+OHqx04yz9Apfrhm+qQZ +9hA== X-Forwarded-Encrypted: i=1; AHgh+Rr7eCwBgeKbBTcfFRytzWOuWBkW79A8EpGH3FHj4rVkJRPnSsVKSs76kVB7okK1hNnBxGzBXd25mVXTycw=@vger.kernel.org X-Gm-Message-State: AFuF++nIicSlQcHk9De3COmx5FfPH1J8r0iAXxVhEADaNFwe9rf098Yd yVT/jnq0YYVNpXErKiks467iL6nazQYQIqjKCjCrIUR4tRLGAxOdiLcb X-Gm-Gg: AR+sD13M5bo4M1vLVg1Yllj/HYfePEoJSFElpEnS2hGr2t3YIbdv4Xfg5iWAlLS8hta kWPwpdhX/pVeviflSkGJvzaIausFjveJ0bOh2CtCTQ8L2cf64ZSrtNL3ELk2UukYuuTWTnWbS4l XneRh/pOy5ZnARHPgtCaz+6krlcwIaFRaZaIRVsKmb3jsUex7iAeZWv+IDpdv+1c+QmMyIFeMzK WfwVwxhRUOEwD0CpwfN/MoZKqSJfF54Zcws9U+vY2KRsYF/x1BhsFKUp0JNgvj0RLLY9TFd58FT fyLGhHrUkdGtyJ23wwFD53S18h31eN1C+LbswWUzf4zvNt7n127QMguIhFFWnu4VDQBI+aWiH3P xC+qFasAh8FmkifKlgfHWAjOFkyppoEhuK9MLZbg/QX8jhNf9VxrXzt/GYqb8+qF/H2bxPSIpBn XfcUSbsUxFX+ngKNOMkg+Sz+oEcrtlCpjZY5pfNPFsaHORMCNiv/PwIU7TdmwG2BfceB9TLhcQy 2+qLOqlxS7W X-Received: by 2002:a17:906:7944:b0:c25:659:89ba with SMTP id a640c23a62f3a-c25065995b7mr206234466b.9.1787672933983; Tue, 25 Aug 2026 08:48:53 -0700 (PDT) Received: from localhost.localdomain ([2a00:23c4:a702:d301:81d:57c0:e4cb:959c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c250a6fd69asm16682066b.18.2026.08.25.08.48.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 08:48:53 -0700 (PDT) From: Biju X-Google-Original-From: Biju To: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Cc: Biju Das , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven , Prabhakar Mahadev Lad , Biju Das , linux-renesas-soc@vger.kernel.org, Tommaso Merciai Subject: [PATCH v8 4/9] pwm: rzg2l-gpt: Add prescale_mult variable to struct rzg2l_gpt_info Date: Tue, 25 Aug 2026 16:48:32 +0100 Message-ID: <20260825154847.197948-5-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825154847.197948-1-biju.das.jz@bp.renesas.com> References: <20260825154847.197948-1-biju.das.jz@bp.renesas.com> 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 From: Biju Das RZ/G3E GPT IP has prescale factor power of 2 where as that of RZ/G2L is 4. Add prescale_mult variable to struct rzg2l_gpt_info for handling this difference. Reviewed-by: Tommaso Merciai Signed-off-by: Biju Das --- v7->v8: * No change. v6->v7: * No change. v5->v6: * Dropped extra parameter rzg2l_gpt from rzg2l_gpt_calculate_prescale() in rzg2l_gpt_round_waveform_tohw(). * Updated comment in rzg2l_gpt_calculate_period_or_duty(). v4->v5: * No change. v3->v4: * Updated commit header and description * Renamed prescale_pow_of_two_mult_factor->prescale_mult v2->v3: * No change. v1->v2: * Collected tag. --- drivers/pwm/pwm-rzg2l-gpt.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/drivers/pwm/pwm-rzg2l-gpt.c b/drivers/pwm/pwm-rzg2l-gpt.c index 87309f519827..47be358cd749 100644 --- a/drivers/pwm/pwm-rzg2l-gpt.c +++ b/drivers/pwm/pwm-rzg2l-gpt.c @@ -79,6 +79,7 @@ =20 struct rzg2l_gpt_info { u32 gtcr_tpcs; + u8 prescale_mult; }; =20 struct rzg2l_gpt_chip { @@ -221,24 +222,29 @@ static void rzg2l_gpt_disable(struct rzg2l_gpt_chip *= rzg2l_gpt, static u64 rzg2l_gpt_calculate_period_or_duty(struct rzg2l_gpt_chip *rzg2l= _gpt, u32 val, u8 prescale) { + const struct rzg2l_gpt_info *info =3D rzg2l_gpt->info; u64 tmp; =20 /* - * The calculation doesn't overflow an u64 because prescale =E2=89=A4 5 a= nd so - * tmp =3D val << (2 * prescale) * NSEC_PER_MSEC + * The calculation doesn't overflow a u64 because, + * prescale =E2=89=A4 5 for info->prescale_mult =3D 2 and so + * tmp =3D val << (info->prescale_mult * prescale) * NSEC_PER_MSEC * < 2^32 * 2^10 * 10^6 * < 2^32 * 2^10 * 2^20 * =3D 2^62 */ - tmp =3D (u64)val << (2 * prescale); + tmp =3D (u64)val << (info->prescale_mult * prescale); tmp *=3D NSEC_PER_MSEC; =20 return DIV64_U64_ROUND_UP(tmp, rzg2l_gpt->rate_khz); } =20 -static u32 rzg2l_gpt_calculate_pv_or_dc(u64 period_or_duty_cycle, u8 presc= ale) +static u32 rzg2l_gpt_calculate_pv_or_dc(const struct rzg2l_gpt_info *info, + u64 period_or_duty_cycle, u8 prescale) { - return min_t(u64, DIV_ROUND_DOWN_ULL(period_or_duty_cycle, 1 << (2 * pres= cale)), + return min_t(u64, + DIV_ROUND_DOWN_ULL(period_or_duty_cycle, + 1 << (info->prescale_mult * prescale)), U32_MAX); } =20 @@ -248,6 +254,7 @@ static int rzg2l_gpt_round_waveform_tohw(struct pwm_chi= p *chip, void *_wfhw) { struct rzg2l_gpt_chip *rzg2l_gpt =3D to_rzg2l_gpt_chip(chip); + const struct rzg2l_gpt_info *info =3D rzg2l_gpt->info; struct rzg2l_gpt_waveform *wfhw =3D _wfhw; bool is_small_second_period =3D false; u8 ch =3D RZG2L_GET_CH(pwm->hwpwm); @@ -290,7 +297,7 @@ static int rzg2l_gpt_round_waveform_tohw(struct pwm_chi= p *chip, rzg2l_gpt->prescale[ch] =3D wfhw->prescale; } =20 - wfhw->gtpr =3D rzg2l_gpt_calculate_pv_or_dc(period_ticks, wfhw->prescale); + wfhw->gtpr =3D rzg2l_gpt_calculate_pv_or_dc(info, period_ticks, wfhw->pre= scale); if (is_small_second_period) { wfhw->gtccr =3D 0; return 1; @@ -299,7 +306,7 @@ static int rzg2l_gpt_round_waveform_tohw(struct pwm_chi= p *chip, duty_ticks =3D mul_u64_u64_div_u64(wf->duty_length_ns, rzg2l_gpt->rate_kh= z, NSEC_PER_MSEC); if (duty_ticks > period_ticks) duty_ticks =3D period_ticks; - wfhw->gtccr =3D rzg2l_gpt_calculate_pv_or_dc(duty_ticks, wfhw->prescale); + wfhw->gtccr =3D rzg2l_gpt_calculate_pv_or_dc(info, duty_ticks, wfhw->pres= cale); =20 return 0; } @@ -345,9 +352,9 @@ static int rzg2l_gpt_read_waveform(struct pwm_chip *chi= p, return 0; } =20 -static u64 rzg2l_gpt_calculate_cycles(u32 value, u8 prescale) +static u64 rzg2l_gpt_calculate_cycles(u32 value, u8 mult, u8 prescale) { - return (u64)value << (2 * prescale); + return (u64)value << (mult * prescale); } =20 static int rzg2l_gpt_write_waveform(struct pwm_chip *chip, @@ -355,6 +362,7 @@ static int rzg2l_gpt_write_waveform(struct pwm_chip *ch= ip, const void *_wfhw) { struct rzg2l_gpt_chip *rzg2l_gpt =3D to_rzg2l_gpt_chip(chip); + const struct rzg2l_gpt_info *info =3D rzg2l_gpt->info; const struct rzg2l_gpt_waveform *wfhw =3D _wfhw; u8 sub_ch =3D rzg2l_gpt_subchannel(pwm->hwpwm); u8 ch =3D RZG2L_GET_CH(pwm->hwpwm); @@ -414,8 +422,9 @@ static int rzg2l_gpt_write_waveform(struct pwm_chip *ch= ip, * value for both channels. */ if (!enable || (enable && !rzg2l_gpt_is_ch_enabled(rzg2l_gpt, sibling_ch= , NULL))) - rzg2l_gpt->period_ticks[ch] =3D rzg2l_gpt_calculate_cycles(wfhw->gtpr, - wfhw->prescale); + rzg2l_gpt->period_ticks[ch] =3D + rzg2l_gpt_calculate_cycles(wfhw->gtpr, info->prescale_mult, + wfhw->prescale); } else { if (rzg2l_gpt_is_ch_enabled(rzg2l_gpt, pwm->hwpwm, NULL)) rzg2l_gpt_disable(rzg2l_gpt, pwm); @@ -499,6 +508,7 @@ static int rzg2l_gpt_probe(struct platform_device *pdev) =20 static const struct rzg2l_gpt_info rzg2l_data =3D { .gtcr_tpcs =3D RZG2L_GTCR_TPCS, + .prescale_mult =3D 2, }; =20 static const struct of_device_id rzg2l_gpt_of_table[] =3D { --=20 2.43.0 From nobody Mon Sep 28 06:35:54 2026 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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 EEFA748AE00 for ; Tue, 25 Aug 2026 15:48:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787672939; cv=none; b=qBITJCvYVTEfYGT/wg5iPLnSsZA3us8AXEfm0GkeLRZmWej1jGR+/8gBTZ1ZjR3RpjBzylNpxcF/sTLTAB9kSRmqwx+clQe87rbE+8lKIVaXg9o1gG4pDjfXGLgH1HMio8oENQQMJQq6myXppnQsp8RhsSE8/sF4w3UryTV6vd8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787672939; c=relaxed/simple; bh=XXZ5i5IksEBJwAVQKMAf++N15Fqn4fMxzGytdUiCm/Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gQqYMy+PZCWSfhFcLPIk6G+ZHrL5UuiOe38AEWGUvPTpnIWCa8bq+gU2QKGR/FIWvLdhKM26XLrDiBn1K+sOiWG1JP9wE733CM/QtPjBe6Bhnnqxw+aZ1yM5gsj0Qz++gWQEcugVyB6E+dd+mtUhldkLETovuGsNWIj2theii4A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=M9J7pjkj; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M9J7pjkj" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-c197e7e4e94so861142266b.2 for ; Tue, 25 Aug 2026 08:48:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787672935; x=1788277735; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=mQ8qhR8/HKXyE4EUMBBNGdK4y+PK8YryxX3K0VTnjak=; b=M9J7pjkj0WftVRVx4KHhBuoGJF9dAgEJyqWsrc6kw2VkwWMpOzWZzAjda0MtcR0ElP +TydhwXz8P0ePH9ZeHUnC4NiIeQxDoyqYqNJTciEI6ckNzLc8i9SUvXcTk/KlR5p1X8G nTMAy+9Yk5mnrxZtamv3GvFdWXcRQ0aYvCjR6EKbtvzJuFimM2JJRZAkQqlX/JP1HaNj a8zd0kKU4tt0BZVGPrgvqtsvU8GwNuJwMIWtY35TO0Dovgrc5+uLTRXbxxApaWc0WG5y 4EPsnj/B6F3DJWtvi49KdMIGspVxsfPh31OyP3ag0BxKysOarTDzZ/2YtqUOT0gqmUfb KSBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787672935; x=1788277735; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=mQ8qhR8/HKXyE4EUMBBNGdK4y+PK8YryxX3K0VTnjak=; b=bIC0ya383zimZS4IxK75cfSOxoh3RPay9VUI2dw/nDZRLOKl5CjjJLxmrCV2JMke3l 09A9k+NKCjqGtY4rSYW7RhiGcZTY3u5fiuuxh4SGQfy295zWXDsy/Utd/k2HNXJFSD0w Vn4Dk9JwdOcNsrp6gCIAM7y7UwYWbOBaPjxHcRR8YsEXnMeTXowIj64jHLmGnmU7TgNJ LX5bd+TgYE5lpy/QRDtWonWIlSnflnGTPAzTte5D/unpnR5ke1zAPI32r9fF7OJd1kRX dnoENt+xELNnzU8Oapa8IOnlcjCQSgyQ+DgNzw1GUr3pwRSevl7QYANWL92SOxcuIRIR JMdw== X-Forwarded-Encrypted: i=1; AHgh+RrN2UqfJubQ1x+7DU1LsbW5miXprRFZo0Ao/FVNYDHhceG1q00XmRTK6ZfeSD1SyxN1C2hnNqL0AOo+icU=@vger.kernel.org X-Gm-Message-State: AFuF++nUNHyhe7mOkQXbdJOhUr9t06ngKeoJihgC11EZDo6XYsCrm5H0 r7KlGDOR9m3U77s/12PNLdO/RqtuN2FrClHTn8svgpN9R4PgwuDp/3OEww2Znw== X-Gm-Gg: AR+sD12mmrKWgLSzFei67Wr2nCS3RqCSQSCM6MUhm2AjncIDqEKqeu2f6H2rvWPTEGG j1SD0RA/E0iresa56ZbXxBXSNLZnv6GW+Ptb2c6nnB0J2WVotizDkZPn22pUxYK0RAoALZIKCbE OcGBKb7jr5QAv8XZaIW1PQdWANufgmiPhsIPhTlNdLe12gTetRBrImQ8iIaRvRwFsGUX0wZqah5 hha5yQF7zYLz5h3qsYMt8+g9JMO9JpckF5hig8e/Tj5oUjqijdalWDRIRQZ0HfyXltITl+Zqrp5 j/y/cQhv5DzHx9i2cjDUyfJDjzfeB2oeeKvjuZqb0A6vAsdUd+lnJO2+Kb1FrA2XsSvJ3R+AAId KAJGavwyNVeGOoYd8HfX6IMrLE1kQMzk+C54ZGyZzURgKeGDkesa8jWajGF/+36iE6nIFj6qtAS eCMow90J9AWuBOG0wLo6r7e+HZiH309YJdP3AX2QA5aF42DQlP4A/GMWiBItDQMXiHp7rXn3793 IJ/lNif7tuT X-Received: by 2002:a17:907:1c0f:b0:c1c:4a80:30c4 with SMTP id a640c23a62f3a-c24925e4915mr2610407366b.11.1787672934816; Tue, 25 Aug 2026 08:48:54 -0700 (PDT) Received: from localhost.localdomain ([2a00:23c4:a702:d301:81d:57c0:e4cb:959c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c250a6fd69asm16682066b.18.2026.08.25.08.48.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 08:48:54 -0700 (PDT) From: Biju X-Google-Original-From: Biju To: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Cc: Biju Das , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven , Prabhakar Mahadev Lad , Biju Das , linux-renesas-soc@vger.kernel.org, Tommaso Merciai Subject: [PATCH v8 5/9] pwm: rzg2l-gpt: Add calculate_prescale() callback to struct rzg2l_gpt_info Date: Tue, 25 Aug 2026 16:48:33 +0100 Message-ID: <20260825154847.197948-6-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825154847.197948-1-biju.das.jz@bp.renesas.com> References: <20260825154847.197948-1-biju.das.jz@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Biju Das The RZ/G2L GPT prescaler steps are continuous powers of 4, while RZ/G3E uses powers of 2 but with a discontinuous sequence. Add a calculate_prescale function pointer to struct rzg2l_gpt_info to allow per-SoC prescaler selection logic. Replace the direct call to rzg2l_gpt_calculate_prescale() in rzg2l_gpt_round_waveform_tohw() with an indirect call through info->calculate_prescale(). Wire the existing rzg2l_gpt_calculate_prescale() into rzg2l_data to preserve current RZ/G2L behaviour. Reviewed-by: Tommaso Merciai Signed-off-by: Biju Das --- v7->v8: * No change. v6->v7: * No change. v5->v6: * No change. v4->v5: * Updated commit description. v3->v4: * No change. v2->v3: * No change. v1->v2: * Collected tag. --- drivers/pwm/pwm-rzg2l-gpt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/pwm/pwm-rzg2l-gpt.c b/drivers/pwm/pwm-rzg2l-gpt.c index 47be358cd749..a5f85a510dee 100644 --- a/drivers/pwm/pwm-rzg2l-gpt.c +++ b/drivers/pwm/pwm-rzg2l-gpt.c @@ -78,6 +78,7 @@ #define RZG2L_MAX_TICKS ((u64)U32_MAX * RZG2L_MAX_SCALE_FACTOR) =20 struct rzg2l_gpt_info { + u8 (*calculate_prescale)(u64 period); u32 gtcr_tpcs; u8 prescale_mult; }; @@ -293,7 +294,7 @@ static int rzg2l_gpt_round_waveform_tohw(struct pwm_chi= p *chip, wfhw->prescale =3D rzg2l_gpt->prescale[ch]; } } else { - wfhw->prescale =3D rzg2l_gpt_calculate_prescale(period_ticks); + wfhw->prescale =3D info->calculate_prescale(period_ticks); rzg2l_gpt->prescale[ch] =3D wfhw->prescale; } =20 @@ -507,6 +508,7 @@ static int rzg2l_gpt_probe(struct platform_device *pdev) } =20 static const struct rzg2l_gpt_info rzg2l_data =3D { + .calculate_prescale =3D rzg2l_gpt_calculate_prescale, .gtcr_tpcs =3D RZG2L_GTCR_TPCS, .prescale_mult =3D 2, }; --=20 2.43.0 From nobody Mon Sep 28 06:35:54 2026 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 465D748BD24 for ; Tue, 25 Aug 2026 15:48:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787672941; cv=none; b=DonVu1oAd6S9BO9keL6S7Et9BKT3yHYemWf8dp3U1XETIrsqYFHV+0lqf16RjKsPcCbSY3+jlsjOcb/WwHkiBly6uX+PSr2b7wZVNIjLdoRgV7oO30CId8qjLdX7hDLtN2x6WmXCE0D2Q7M49vja7dkp+a/wSCr5BhDFG5AOTzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787672941; c=relaxed/simple; bh=Lz6VEBOBJEQ22e502FSDUQOnVNJAYiHCm1RHA6boMK4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X8MiptdV+zD+j1OP/iQB2R8EBeOsav7nxn1gnZQnRUa7Mf3+/k95+jePMQ+H6kshNUl2JBfoMD2rJ8IafxPi7wP8cgu5bnf6y8srNSnDk/4RqPcLNNcJs0VUdmIR1W4hovhSsoFTEDf32urUeoqx1v6RtOPHW6H4TFsIDHVuCdU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gzXFhCM8; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gzXFhCM8" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-c20ce3c118aso197270366b.0 for ; Tue, 25 Aug 2026 08:48:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787672936; x=1788277736; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=rz5CLnebK51je4sELcdSpCaf9YuXm/zrK57sQsjNp4Q=; b=gzXFhCM8apeQARaDapJdWnfFNQTJomcBpXBPsULsRfG/tsKXJXmunkaoVafQzQxYF4 v5p7MWcFig+i1heyVfoWig1nr0gMAACKAAy4OInJW4twaT5Mo2TdyjRsG9NJZnXtQtno HK5LksMVl0GsytBa8EeUJhD+jt5FZLH9hOKxHamhFQYCQQjy3V/6y1EALqxh/sfINNZ5 HG+KLmiw5UEnTNYUCBmaHY42dsECMxqXj0ZyBhTXi2fCHZJn3DP5msk9UHtLqXzUYJX8 Qa29iwFyZsnIr5yC8fZgCBeRQ/NLaYNUezX6vcmHFLvZlshXadrUKcQQlSymd8MgEqXI su9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787672936; x=1788277736; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=rz5CLnebK51je4sELcdSpCaf9YuXm/zrK57sQsjNp4Q=; b=MhxqCirwTg0D94CXW8978AXruO+w89gaLPv60aUn8LiYfzLUT+VmfdXAabhiTeQ5Mi 7tawnIZYgxTg0pTp776WH8eDyPRAd0KUPuZkzczaaJq8thK8wJRK6lkJRNipOtxuksZe SoIm9UNWfRJVO9tdJsHqTUpomTdNT8Kb78hFrFX7lPTl8gVIWkIJQVKxKbUhtf15z3aA 9IPMGLP/jQ42vVdgmwLI7ET9wNeiqsFd7hXrXeRuBhz1pWtKgkg32O90iuA6w9tRmNwl FGqBKHMf0Rz8Pv1ITgjGdxy03XkHA66dmTGrsSohSieDYPfXxXsofP/WoTut20YCYNLp JrYA== X-Forwarded-Encrypted: i=1; AHgh+Rp32MpeFKMdwidafMLRFB0RuEbzMlS0XR6elphc45LFp6DQbOEJFS+wkEoPa7FAiGEDEoSe3AgPqPfn0oY=@vger.kernel.org X-Gm-Message-State: AFuF++kNLNKlFGDQLzeOpIFmRruWbLhLT94EudzBJB7boUzc2up8z4j2 EzLncJHXE/TFaO9Bv3qa1aKwznTqb3T4Uz2pVRtayvK49SooaWfZmZoZ X-Gm-Gg: AR+sD10PAP2g/Xv0DI7C1NgdPnZ/lsn4XtKrDf6eOSwJvQIpiTcW+CTzc3/kiVqaGyI eTJDU9otlUEGMnsQcB+0ytDbmIMAYcDfKjZ9DfxZqJWwbdE5Dp5yDeNe/Fz+C1VGo3lTIEmUOBx m40mwvBYyXT9pNlClgpsTPVuLT3lEcWt9KUT4HfkHZJKfojUT9dHpxCwJQ+FAaXuC/BYjo4N6MJ 8qIolgasMt0C6pcp7+UFWkpZNHOZK5j8MY7d7RBEKtPgh50Kc4N0uvws+YHr/Gx7a2MiQ8BAnK+ USbF1VBNrkeeFsIBxTEwMekC84CVis31pGC2jHw7r4BqAUioP13OxQGgyD2QVr2W1WRsbvzZy0+ mq7t8vERbN6yJcV+G31huVzTaian9+j0bjovXc44DZ8XF7Di7ecOn0X2c9jNi6D8bpQKh8PCEmg rM7HFcXmJMsMupEWEQ7iEprnJ4F5REMH4VAXCkbxD1iGH+/y2pB/Dv0+UlU5QcVwWhx6ALRBOZI T1dibX3o/df X-Received: by 2002:a17:907:3ea6:b0:c21:393e:6d10 with SMTP id a640c23a62f3a-c250aaa03cfmr14376766b.4.1787672935755; Tue, 25 Aug 2026 08:48:55 -0700 (PDT) Received: from localhost.localdomain ([2a00:23c4:a702:d301:81d:57c0:e4cb:959c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c250a6fd69asm16682066b.18.2026.08.25.08.48.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 08:48:55 -0700 (PDT) From: Biju X-Google-Original-From: Biju To: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Geert Uytterhoeven , Magnus Damm Cc: Biju Das , linux-pwm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar Mahadev Lad , Biju Das Subject: [PATCH v8 6/9] dt-bindings: pwm: Document RZ/G3E GPT support Date: Tue, 25 Aug 2026 16:48:34 +0100 Message-ID: <20260825154847.197948-7-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825154847.197948-1-biju.das.jz@bp.renesas.com> References: <20260825154847.197948-1-biju.das.jz@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Biju Das Document support for the GPT found on the Renesas RZ/G3E (R9A09G047) SoC. The GPT is a 32-bit timer with 16 hardware channels (GPT0: 8 channel and GPT1: 8channels). The hardware supports simultaneous control of all channels. PWM waveforms can be generated by controlling the up-counter, downcounter, or up- and down-counter. Reviewed-by: Rob Herring (Arm) Signed-off-by: Biju Das --- v7->v8: * No change. v6->v7: * No change. v5->v6: * No change. v4->v5: * No change. v3->v4: * No change. v2->v3: * Added Rb tag from Rob. v1->v2: * Created separate document for RZ/G3E GPT. * Updated commit header and description. --- .../bindings/pwm/renesas,rzg3e-gpt.yaml | 323 ++++++++++++++++++ 1 file changed, 323 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/renesas,rzg3e-gpt= .yaml diff --git a/Documentation/devicetree/bindings/pwm/renesas,rzg3e-gpt.yaml b= /Documentation/devicetree/bindings/pwm/renesas,rzg3e-gpt.yaml new file mode 100644 index 000000000000..cb4ffab5f47f --- /dev/null +++ b/Documentation/devicetree/bindings/pwm/renesas,rzg3e-gpt.yaml @@ -0,0 +1,323 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pwm/renesas,rzg3e-gpt.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Renesas RZ/G3E General PWM Timer (GPT) + +maintainers: + - Biju Das + +description: | + RZ/G3E General PWM Timer (GPT) composed of 16 channels with 32-bit + timer. It supports the following functions + * 32 bits x 16 channels. + * Up-counting or down-counting (saw waves) or up/down-counting + (triangle waves) for each counter. + * Clock sources independently selectable for each channel. + * Four I/O pins per channel. + * Two output compare/input capture registers per channel. + * For the two output compare/input capture registers of each channel, + four registers are provided as buffer registers and are capable of + operating as comparison registers when buffering is not in use. + * In output compare operation, buffer switching can be at crests or + troughs, enabling the generation of laterally asymmetric PWM waveforms. + * Registers for setting up frame cycles in each channel (with capability + for generating interrupts at overflow or underflow) + * Generation of dead times in PWM operation. + * Synchronous starting, stopping and clearing counters for arbitrary + channels. + * Count start, count stop, count clear, up-count, down-count, or input + capture operation in response to a maximum of 8 ELC events. + * Count start, count stop, count clear, up-count, down-count, or input + capture operation in response to the status of two input pins. + * Starting, clearing, stopping and up/down counters in response to a + maximum of four external triggers. + * Output pin disable function by detected short-circuits between output + pins. + * A/D converter start triggers can be generated. + * Compare match A to F event and overflow/underflow event can be output + to the ELC. + * Enables the noise filter for input capture. + * Logical operation between the channel output. + +properties: + compatible: + items: + - const: renesas,r9a09g047-gpt # RZ/G3E + + reg: + maxItems: 1 + + '#pwm-cells': + const: 3 + + interrupts: + items: + - description: Input capture/compare match of the GTCCRA for channel= GPT{0,1}.0 + - description: Input capture/compare match of the GTCCRB for channel= GPT{0,1}.0 + - description: Compare match with the GTCCRC for channel GPT{0,1}.0 + - description: Compare match with the GTCCRD for channel GPT{0,1}.0 + - description: Compare match with the GTCCRE for channel GPT{0,1}.0 + - description: Compare match with the GTCCRF for channel GPT{0,1}.0 + - description: A and B both high interrupt for channel GPT{0,1}.0 + - description: A and B both low interrupt for channel GPT{0,1}.0 + - description: Input capture/compare match of the GTCCRA for channel= GPT{0,1}.1 + - description: Input capture/compare match of the GTCCRB for channel= GPT{0,1}.1 + - description: Compare match with the GTCCRC for channel GPT{0,1}.1 + - description: Compare match with the GTCCRD for channel GPT{0,1}.1 + - description: Compare match with the GTCCRE for channel GPT{0,1}.1 + - description: Compare match with the GTCCRF for channel GPT{0,1}.1 + - description: A and B both high interrupt for channel GPT{0,1}.1 + - description: A and B both low interrupt for channel GPT{0,1}.1 + - description: Input capture/compare match of the GTCCRA for channel= GPT{0,1}.2 + - description: Input capture/compare match of the GTCCRB for channel= GPT{0,1}.2 + - description: Compare match with the GTCCRC for channel GPT{0,1}.2 + - description: Compare match with the GTCCRD for channel GPT{0,1}.2 + - description: Compare match with the GTCCRE for channel GPT{0,1}.2 + - description: Compare match with the GTCCRF for channel GPT{0,1}.2 + - description: A and B both high interrupt for channel GPT{0,1}.2 + - description: A and B both low interrupt for channel GPT{0,1}.2 + - description: Input capture/compare match of the GTCCRA for channel= GPT{0,1}.3 + - description: Input capture/compare match of the GTCCRB for channel= GPT{0,1}.3 + - description: Compare match with the GTCCRC for channel GPT{0,1}.3 + - description: Compare match with the GTCCRD for channel GPT{0,1}.3 + - description: Compare match with the GTCCRE for channel GPT{0,1}.3 + - description: Compare match with the GTCCRF for channel GPT{0,1}.3 + - description: A and B both high interrupt for channel GPT{0,1}.3 + - description: A and B both low interrupt for channel GPT{0,1}.3 + - description: Input capture/compare match of the GTCCRA for channel= GPT{0,1}.4 + - description: Input capture/compare match of the GTCCRB for channel= GPT{0,1}.4 + - description: Compare match with the GTCCRC for channel GPT{0,1}.4 + - description: Compare match with the GTCCRD for channel GPT{0,1}.4 + - description: Compare match with the GTCCRE for channel GPT{0,1}.4 + - description: Compare match with the GTCCRF for channel GPT{0,1}.4 + - description: A and B both high interrupt for channel GPT{0,1}.4 + - description: A and B both low interrupt for channel GPT{0,1}.4 + - description: Input capture/compare match of the GTCCRA for channel= GPT{0,1}.5 + - description: Input capture/compare match of the GTCCRB for channel= GPT{0,1}.5 + - description: Compare match with the GTCCRC for channel GPT{0,1}.5 + - description: Compare match with the GTCCRD for channel GPT{0,1}.5 + - description: Compare match with the GTCCRE for channel GPT{0,1}.5 + - description: Compare match with the GTCCRF for channel GPT{0,1}.5 + - description: A and B both high interrupt for channel GPT{0,1}.5 + - description: A and B both low interrupt for channel GPT{0,1}.5 + - description: Input capture/compare match of the GTCCRA for channel= GPT{0,1}.6 + - description: Input capture/compare match of the GTCCRB for channel= GPT{0,1}.6 + - description: Compare match with the GTCCRC for channel GPT{0,1}.6 + - description: Compare match with the GTCCRD for channel GPT{0,1}.6 + - description: Compare match with the GTCCRE for channel GPT{0,1}.6 + - description: Compare match with the GTCCRF for channel GPT{0,1}.6 + - description: A and B both high interrupt for channel GPT{0,1}.6 + - description: A and B both low interrupt for channel GPT{0,1}.6 + - description: Input capture/compare match of the GTCCRA for channel= GPT{0,1}.7 + - description: Input capture/compare match of the GTCCRB for channel= GPT{0,1}.7 + - description: Compare match with the GTCCRC for channel GPT{0,1}.7 + - description: Compare match with the GTCCRD for channel GPT{0,1}.7 + - description: Compare match with the GTCCRE for channel GPT{0,1}.7 + - description: Compare match with the GTCCRF for channel GPT{0,1}.7 + - description: A and B both high interrupt for channel GPT{0,1}.7 + - description: A and B both low interrupt for channel GPT{0,1}.7 + + interrupt-names: + items: + - const: gtcia0 + - const: gtcib0 + - const: gtcic0 + - const: gtcid0 + - const: gtcie0 + - const: gtcif0 + - const: gtcih0 + - const: gtcil0 + - const: gtcia1 + - const: gtcib1 + - const: gtcic1 + - const: gtcid1 + - const: gtcie1 + - const: gtcif1 + - const: gtcih1 + - const: gtcil1 + - const: gtcia2 + - const: gtcib2 + - const: gtcic2 + - const: gtcid2 + - const: gtcie2 + - const: gtcif2 + - const: gtcih2 + - const: gtcil2 + - const: gtcia3 + - const: gtcib3 + - const: gtcic3 + - const: gtcid3 + - const: gtcie3 + - const: gtcif3 + - const: gtcih3 + - const: gtcil3 + - const: gtcia4 + - const: gtcib4 + - const: gtcic4 + - const: gtcid4 + - const: gtcie4 + - const: gtcif4 + - const: gtcih4 + - const: gtcil4 + - const: gtcia5 + - const: gtcib5 + - const: gtcic5 + - const: gtcid5 + - const: gtcie5 + - const: gtcif5 + - const: gtcih5 + - const: gtcil5 + - const: gtcia6 + - const: gtcib6 + - const: gtcic6 + - const: gtcid6 + - const: gtcie6 + - const: gtcif6 + - const: gtcih6 + - const: gtcil6 + - const: gtcia7 + - const: gtcib7 + - const: gtcic7 + - const: gtcid7 + - const: gtcie7 + - const: gtcif7 + - const: gtcih7 + - const: gtcil7 + + clocks: + items: + - description: Core clock (PCLKD) + - description: Bus clock (PCLKA) + + clock-names: + items: + - const: core + - const: bus + + power-domains: + maxItems: 1 + + resets: + items: + - description: Reset for bus clock (PCLKA/PCLKD) + - description: Reset for core clock (PCLKD) + + reset-names: + items: + - const: rst_p + - const: rst_s + +required: + - compatible + - reg + - interrupts + - interrupt-names + - clocks + - clock-names + - power-domains + - resets + - reset-names + +allOf: + - $ref: pwm.yaml# + +additionalProperties: false + +examples: + - | + #include + #include + + pwm@13010000 { + compatible =3D "renesas,r9a09g047-gpt"; + reg =3D <0x13010000 0x10000>; + interrupts =3D , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + ; + interrupt-names =3D "gtcia0", "gtcib0", "gtcic0", "gtcid0", + "gtcie0", "gtcif0", "gtcih0", "gtcil0", + "gtcia1", "gtcib1", "gtcic1", "gtcid1", + "gtcie1", "gtcif1", "gtcih1", "gtcil1", + "gtcia2", "gtcib2", "gtcic2", "gtcid2", + "gtcie2", "gtcif2", "gtcih2", "gtcil2", + "gtcia3", "gtcib3", "gtcic3", "gtcid3", + "gtcie3", "gtcif3", "gtcih3", "gtcil3", + "gtcia4", "gtcib4", "gtcic4", "gtcid4", + "gtcie4", "gtcif4", "gtcih4", "gtcil4", + "gtcia5", "gtcib5", "gtcic5", "gtcid5", + "gtcie5", "gtcif5", "gtcih5", "gtcil5", + "gtcia6", "gtcib6", "gtcic6", "gtcid6", + "gtcie6", "gtcif6", "gtcih6", "gtcil6", + "gtcia7", "gtcib7", "gtcic7", "gtcid7", + "gtcie7", "gtcif7", "gtcih7", "gtcil7"; + clocks =3D <&cpg CPG_MOD 0x31>, <&cpg CPG_MOD 0x31>; + clock-names =3D "core", "bus"; + power-domains =3D <&cpg>; + resets =3D <&cpg 0x59>, <&cpg 0x5a>; + reset-names =3D "rst_p", "rst_s"; + #pwm-cells =3D <3>; + }; --=20 2.43.0 From nobody Mon Sep 28 06:35:54 2026 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 000D8351C13 for ; Tue, 25 Aug 2026 15:48:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787672943; cv=none; b=mHhJxUlVXmKncJ1KrDxRSibl12oDduyjjx3dy28Nb17t0Tj+WEujXgTHWix7WKMcNcSIf3gamszPQf5nizew8fq/NZc24eukOPGgmMpbBcSl9ESlN82X4K6bDE+4hOI63qAO9zDz8M7sAP1/+WhWRHM014GkVnzsvDkb+FcFvSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787672943; c=relaxed/simple; bh=efRF6KROkenLNDxb7TbiGycoeh0/iynB2mbKSlbIWqU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HQHzvHYn5fEJXH4ydjLMx32xdFmZh3SNjrYw1p4Iuo5hyV5XGyOuF0jT+AOugejtYi8VlJhDPyo2z5GWgUA0E7bPuo9pGSC2WdWcX5EOMl8N/ISKgVtviYS+qeNR7X719jpDxu7QRI4wpxS9cJ0i+dERWB3LQjKc+ja7pcIvuug= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Vm94tA7D; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Vm94tA7D" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-c15b1da6b82so548095966b.1 for ; Tue, 25 Aug 2026 08:48:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787672937; x=1788277737; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=KbzPyRA35vt/mJDbnSSeCRH9FEDa0mitnkMN67SloUY=; b=Vm94tA7DUOJZEYGfxs7j/BmWtl6ZabRRc9EO+7BTHAMb+cOWYDg9RYOaLDRjndaiQf uPIONnQ88dzd4+UXdu8mzHmHRjnYauREz11UWmXU3xHxCmdr2vsuNRCG69jV8vWdSLW+ 2nPlMFFBvc+PEcF/vFxbaJvCcpgCCBYfLWef4g5rQ8xbNda+jUdRCRaaGo7eP3kbWm3w X0iwpe2KDHfe2xXqeZpydKpuARylhxV36dOgS8N4E67cH+CFJMuwSTPyks94FHJQUn3U V89ChMSjcHYMDbSDOBfRXwrh9lkWWUYGGXeC7273e21UomLF46t7rmPeKvBB+AYLR2VJ i7Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787672937; x=1788277737; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=KbzPyRA35vt/mJDbnSSeCRH9FEDa0mitnkMN67SloUY=; b=NydrGEDbSmeTOlLdOminC771INIGS1wP8s5zor97wItA6oUfUcUtYdHW7fHekt6deP IJ+efR9tXRMV8Bv/apnn0PHQGnzQ84DZuPUbDIkfB73e+db0K/Q6OQtWnFRg0L2haLcI ueUSGGLjqaEaUmrp9p/CaQfZEcH0rcFHtbb1PpCXiiAIt6RSow6v+mFoOPDPQAuIrrRV WbJuc6jdlwY+m3rx6Pe3ufqSVJXz7N+r8n/EuCWsSaHBTOPHo8DJg9ZhBJMbZ+2W/ueZ QXqKQncQzZZKVa0mTCsY9cUZQ/QMnBLsaPsUxO7hk5AUm48W7zuuXDHPQgiqFAQJXB0F t+Gg== X-Forwarded-Encrypted: i=1; AHgh+RpdG1xR6u7xWEwwCgUidhIRPXW6l0/vbPWYCKGS8cSPEJCQHBhE5NRPggja/1T2RixgFphYJp5C97F5a88=@vger.kernel.org X-Gm-Message-State: AFuF++mdL6OQTnzaZqpmCWrHCHp/FJ3eAQIDANMoJdibY+EomIPOyRvx thnXNE56IuGLtaRCGxk2jtRkfAscDSiZnMeUJPffXVyAK7FFZx60ngd8 X-Gm-Gg: AR+sD12+FtmkQ2zXXGjfxHrOLPU0bSY2M8ISOEnyxxUhD68N+wvb1K2wCz7b9FEx/jL 2ci2b/BRzysTOtLfgdToDNXHy6zEyI73kxLPVKieU3aEvXUvVxXGy0010VjNGIPvekf1VlwNdxJ hcAM+3F2JmnS+wEs9G8DdxChe4WCa7MKp5ErW8Pvjs39mWZOLdFZlRoEyGkIGQ08CtrSAL1LgRE NRWxVhb1acANSySW7Kc4UZ+yYrPHirLE/dIwRJ/NbN6DeFE9y68eBFdQ3B+1ufaJCm+FoJVsltv QhEnyD/ZJBoH7oLT9FTp1IPqoRo7PhHV/UjeX4ywCnhgbB0QoBX5CDp8gaHFYRoSbymXTGqpReU MIDcZOsW/ifnn+aVP3EMqorCZRbFxYod0hcJmZEN2b8TJNTavig94W4Ml2ebprhJpF8LJ5eauXA ReVXapMv8jLpWt70aPESw6ObZFWpQH/NENAitPGTyt9xJiZFoFA/F/5KYCYP11FPrDzNcWhNrYy /m3mFHpeqDP X-Received: by 2002:a17:907:97cd:b0:c21:9cf4:e1b0 with SMTP id a640c23a62f3a-c24e58cfc35mr790555766b.3.1787672936642; Tue, 25 Aug 2026 08:48:56 -0700 (PDT) Received: from localhost.localdomain ([2a00:23c4:a702:d301:81d:57c0:e4cb:959c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c250a6fd69asm16682066b.18.2026.08.25.08.48.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 08:48:56 -0700 (PDT) From: Biju X-Google-Original-From: Biju To: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Philipp Zabel , Geert Uytterhoeven , Magnus Damm Cc: Biju Das , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar Mahadev Lad , Biju Das , Tommaso Merciai Subject: [PATCH v8 7/9] pwm: rzg2l-gpt: Add RZ/G3E support Date: Tue, 25 Aug 2026 16:48:35 +0100 Message-ID: <20260825154847.197948-8-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825154847.197948-1-biju.das.jz@bp.renesas.com> References: <20260825154847.197948-1-biju.das.jz@bp.renesas.com> 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 From: Biju Das Add RZ/G3E GPT support. It has multiple clocks and resets compared to RZ/G2L. Also prescale field width and factor for calculating prescale are different. Reviewed-by: Tommaso Merciai Signed-off-by: Biju Das --- v7->v8: * Updated rzg3e_gpt_calculate_prescale() with >=3D 64. v6->v7: * No change. v5->v6: * Updated rzg3e_gpt_calculate_prescale(). * Updated comment in rzg2l_gpt_calculate_period_or_duty(). v4->v5: * No change. v3->v4: * Added RZG3E_GTCR_TPCS bit definition for RZ/G3E and added to rzg3e_data. v2->v3: * No change. v1->v2: * Added link to hardware manual * Updated limitation section * Collected tag=20 --- drivers/pwm/pwm-rzg2l-gpt.c | 45 ++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/drivers/pwm/pwm-rzg2l-gpt.c b/drivers/pwm/pwm-rzg2l-gpt.c index a5f85a510dee..6f47e14cceab 100644 --- a/drivers/pwm/pwm-rzg2l-gpt.c +++ b/drivers/pwm/pwm-rzg2l-gpt.c @@ -6,15 +6,21 @@ * * Hardware manual for this IP can be found here * https://www.renesas.com/eu/en/document/mah/rzg2l-group-rzg2lc-group-use= rs-manual-hardware-0?language=3Den + * https://www.renesas.com/en/document/mah/rzg3e-group-users-manual-hardwa= re * * Limitations: * - Counter must be stopped before modifying Mode and Prescaler. * - When PWM is disabled, the output is driven to inactive. * - While the hardware supports both polarities, the driver (for now) * only handles normal polarity. - * - General PWM Timer (GPT) has 8 HW channels for PWM operations and - * each HW channel have 2 IOs. + * - For RZ/G2L, the General PWM Timer (GPT) has 8 HW channels for PWM + operations and each HW channel have 2 IOs (GTIOCn{A, B}). * - Each IO is modelled as an independent PWM channel. + * - For RZ/G3E, the General PWM Timer (GPT) has 16 HW channels for PWM + operations (GPT0: 8 channels, GPT1: 8 Channels) and each HW channel + have 4 IOs (GTIOCn{A,AN,B,BN}). The 2 extra IOs GTIOCnAN and GTIOCnBN + in RZ/G3E are anti-phase signals of GTIOCnA and GTIOCnB. The + anti-phase signals of RZ/G3E are not modelled as PWM channel. * - When both channels are used, disabling the channel on one stops the * other. * - When both channels are used, the period of both IOs in the HW channel @@ -47,6 +53,7 @@ #define RZG2L_GTCR_CST BIT(0) #define RZG2L_GTCR_MD GENMASK(18, 16) #define RZG2L_GTCR_TPCS GENMASK(26, 24) +#define RZG3E_GTCR_TPCS GENMASK(26, 23) =20 #define RZG2L_GTCR_MD_SAW_WAVE_PWM_MODE FIELD_PREP(RZG2L_GTCR_MD, 0) =20 @@ -147,6 +154,22 @@ static u8 rzg2l_gpt_calculate_prescale(u64 period_tick= s) return prescale; } =20 +static u8 rzg3e_gpt_calculate_prescale(u64 period_ticks) +{ + u32 prescaled_period_ticks; + u8 prescale; + + prescaled_period_ticks =3D period_ticks >> 32; + if (prescaled_period_ticks >=3D 64 && prescaled_period_ticks < 256) + prescale =3D 8; + else if (prescaled_period_ticks >=3D 256) + prescale =3D 10; + else + prescale =3D fls(prescaled_period_ticks); + + return prescale; +} + static int rzg2l_gpt_request(struct pwm_chip *chip, struct pwm_device *pwm) { struct rzg2l_gpt_chip *rzg2l_gpt =3D to_rzg2l_gpt_chip(chip); @@ -228,7 +251,8 @@ static u64 rzg2l_gpt_calculate_period_or_duty(struct rz= g2l_gpt_chip *rzg2l_gpt, =20 /* * The calculation doesn't overflow a u64 because, - * prescale =E2=89=A4 5 for info->prescale_mult =3D 2 and so + * prescale =E2=89=A4 5 for info->prescale_mult =3D 2, + * prescale =E2=89=A4 10 for info->prescale_mult =3D 1, and so * tmp =3D val << (info->prescale_mult * prescale) * NSEC_PER_MSEC * < 2^32 * 2^10 * 10^6 * < 2^32 * 2^10 * 2^20 @@ -469,6 +493,14 @@ static int rzg2l_gpt_probe(struct platform_device *pde= v) if (IS_ERR(rstc)) return dev_err_probe(dev, PTR_ERR(rstc), "Cannot deassert reset control\= n"); =20 + rstc =3D devm_reset_control_get_optional_exclusive_deasserted(dev, "rst_s= "); + if (IS_ERR(rstc)) + return dev_err_probe(dev, PTR_ERR(rstc), "Cannot deassert rst_s reset\n"= ); + + clk =3D devm_clk_get_optional_enabled(dev, "bus"); + if (IS_ERR(clk)) + return dev_err_probe(dev, PTR_ERR(clk), "Cannot get bus clock\n"); + clk =3D devm_clk_get_enabled(dev, NULL); if (IS_ERR(clk)) return dev_err_probe(dev, PTR_ERR(clk), "Cannot get clock\n"); @@ -507,6 +539,12 @@ static int rzg2l_gpt_probe(struct platform_device *pde= v) return 0; } =20 +static const struct rzg2l_gpt_info rzg3e_data =3D { + .calculate_prescale =3D rzg3e_gpt_calculate_prescale, + .gtcr_tpcs =3D RZG3E_GTCR_TPCS, + .prescale_mult =3D 1, +}; + static const struct rzg2l_gpt_info rzg2l_data =3D { .calculate_prescale =3D rzg2l_gpt_calculate_prescale, .gtcr_tpcs =3D RZG2L_GTCR_TPCS, @@ -514,6 +552,7 @@ static const struct rzg2l_gpt_info rzg2l_data =3D { }; =20 static const struct of_device_id rzg2l_gpt_of_table[] =3D { + { .compatible =3D "renesas,r9a09g047-gpt", .data =3D &rzg3e_data }, { .compatible =3D "renesas,rzg2l-gpt", .data =3D &rzg2l_data }, { /* Sentinel */ } }; --=20 2.43.0 From nobody Mon Sep 28 06:35:54 2026 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.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 1116E3382FC for ; Tue, 25 Aug 2026 15:48:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787672943; cv=none; b=OtKc+OthQodvh5wUJOsk8KnhM3SLcc8ElE7kQAeXqwDRgztmGJkdQTNLekzC83ei2AJIUxXUVc1TwcU+pIerQU972HNwCvslO61D/aQedFvJzUYHyZ3q9u7kjvjDdRbrEdh4MQsSfWcTPMBl6Evjd3MqzHWCwJfjknnrL5FPSOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787672943; c=relaxed/simple; bh=Smy6j+jvyzcjX3oQa5z23WouidnyYH+/yVbzp6giW+o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s9aVt22K/E+sMQ+IjGqzshWFHrjAvD8bf8A3ahYac9eTVJyHIShPVD0iuLZzmxRx+3ucd+zcPLU63NksUkbhsNvEjez04IMAXinyRuzbRyLTle7MNUm9wRxOevedPB2JLkjeoQMlY8i7q0qdTt+Uv0GV2qYhczCLHLbRQ3whcM4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WBj+GSEV; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WBj+GSEV" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-c1712a04ddaso823942366b.2 for ; Tue, 25 Aug 2026 08:48:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787672938; x=1788277738; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=L41oBJgkTA0hJ2K5fg9Bazx7ynuYkWueRKGvRCk3LHs=; b=WBj+GSEVcTcNyakwEAt8Xv5LYvjPfXLf7GZ23d7z1U8c1btd5dOIX3diXN5IeFdK72 +5htTRyy/7u8dMZA66tzJmJs5wsiVmqWlxfBLSUUeFDAl1RKOafMmdcKMYbXpW9+j0dC hPeZVni4/GCXpKSi2WvOfiByTW8ya7aK1nYyntV0U+b/P621ktJnrbVwat7s166JnIam WPa8e9Hk8ElktfS88PeiKr2YhwMPjzcf7rxwfQwTjssFznAORH3Rqr40U5HC4/EUQ5IZ ec3D72JCQBrPtf1T+oZKmyqWN1ojMQhV7x9lD3u5xGm5RmQbv03tLyfbN+i652iFtkQo /LZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787672938; x=1788277738; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=L41oBJgkTA0hJ2K5fg9Bazx7ynuYkWueRKGvRCk3LHs=; b=E23zvHPxTcNS3IMou8tPDK9Uh8mN2wSHP6SkTydRbxu25hHkFBypGeMJvPH2xXOc3v pWA3L8iUymHe8ru1k2rVURPfKQQO+Mmm+APLy46pvWpswpvQLL3eKKkVsy4QYdCz4EDh mCbq1fhNZ+9K6S/75thQHKjLUDev/XJ+e99bg2wltXiZAfuSCr52lNWzDjTuIJuJt746 uqQGvlLF5JOYciV7lijEG3J2R3+4Ibpq+8yTTcEVZxX6KNkd3h9tbgNTiahz/+t2LeGb YIB6jSyXm6pNMxIH5Yq61UKDLiPaRcqY9vYu7B89NClONjp6s7vtj1k01M5RAjbUFidx xG0w== X-Forwarded-Encrypted: i=1; AHgh+RpawTNoNB63ReV529+EeaH3U3D0QFVDXWzwZVJbSuwUrguXD1vRi7Oe1QkZx1gm34kr1o7MOkvgFdl45HU=@vger.kernel.org X-Gm-Message-State: AFuF++lDbvNlG2ndnw6AqkamHrHBhQ/G8W48B7Edz/pid54iwiGmFI7A 0yatQ7WfHFNKiX8lo+pA3ChsKbuMLEp4T9BfDj7izgFzA18H16U4OT0g X-Gm-Gg: AR+sD10KBWQyZuvgrFQR7ZGwDvveC5aPgjWBERNVFec73htiKrmqqparATaY2DtayUU aK9Mwm2mKCJrH7c/G7HQ1k0KOpnCjQCE2iGEzZH0y0sgGUhjSr9xjOXBhtUgm+IdoI9kK155FGz zP3EbvgKT44ANR2FTftCXV6mWgmxecjjZl6swM0jQlxYSslO+LGRcj1G+ML0hD9sBUraz0MpPl5 FqGoATam4cEOQf99rqczCT6BN51xQXNIxhmPTo5LRJpeYb+5FnxjwvLS01baOy2u/xDpO026ntQ lijwqBb9Jbrd02pylUWyY/vysDRrtH+KN9DFLHfWrL2ihfLpCdK+Vv3lqSAE6dZn107hDK/oyFJ hC1YVwrGiJl9Ic4f2ppxExpf6jaZXZ1wPHXfg2mkrKI54FmHLzt+vNYQZMG1n9+uaN3WeZI2Rr8 vyFqe9h5nABhE5ltQ4nCg/F3hkeCuEAtImF84HJtBIdyRdpLarULhASHXb1+7fndrauaL/7koiC K4FHkpaqUPm X-Received: by 2002:a17:907:c8c7:b0:c24:680a:1c42 with SMTP id a640c23a62f3a-c2491c9a6eamr3228063966b.7.1787672937652; Tue, 25 Aug 2026 08:48:57 -0700 (PDT) Received: from localhost.localdomain ([2a00:23c4:a702:d301:81d:57c0:e4cb:959c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c250a6fd69asm16682066b.18.2026.08.25.08.48.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 08:48:57 -0700 (PDT) From: Biju X-Google-Original-From: Biju To: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Geert Uytterhoeven , Magnus Damm Cc: Biju Das , linux-pwm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar Mahadev Lad , Biju Das Subject: [PATCH v8 8/9] dt-bindings: pwm: rzg2l-gpt: Document renesas,poegs property Date: Tue, 25 Aug 2026 16:48:36 +0100 Message-ID: <20260825154847.197948-9-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825154847.197948-1-biju.das.jz@bp.renesas.com> References: <20260825154847.197948-1-biju.das.jz@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Biju Das RZ/G2L GPT IP supports output pin disable function by dead time error and detecting short-circuits between output pins. Add documentation for the optional property renesas,poegs to link a pair of GPT IOs with POEG. Reviewed-by: Rob Herring Signed-off-by: Biju Das --- v7->v8: * No change v6->v7: * No change v5->v6: * No change v5: * No change v24 from [1]: [1] https://lore.kernel.org/all/20250226144531.176819-1-biju.das.jz@bp.rene= sas.com/ --- .../bindings/pwm/renesas,rzg2l-gpt.yaml | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Documentation/devicetree/bindings/pwm/renesas,rzg2l-gpt.yaml b= /Documentation/devicetree/bindings/pwm/renesas,rzg2l-gpt.yaml index 13b807765a30..98bcde755fb9 100644 --- a/Documentation/devicetree/bindings/pwm/renesas,rzg2l-gpt.yaml +++ b/Documentation/devicetree/bindings/pwm/renesas,rzg2l-gpt.yaml @@ -245,6 +245,28 @@ properties: resets: maxItems: 1 =20 + renesas,poegs: + minItems: 1 + maxItems: 8 + $ref: /schemas/types.yaml#/definitions/phandle-array + items: + items: + - description: phandle to POEG instance that serves the output dis= able + - enum: [ 0, 1, 2, 3, 4, 5, 6, 7 ] + description: | + An index identifying pair of GPT channels. + <0> : GPT channels 0 and 1 + <1> : GPT channels 2 and 3 + <2> : GPT channels 4 and 5 + <3> : GPT channels 6 and 7 + <4> : GPT channels 8 and 9 + <5> : GPT channels 10 and 11 + <6> : GPT channels 12 and 13 + <7> : GPT channels 14 and 15 + description: + A list of phandle and channel index pair tuples to the POEGs that ha= ndle the + output disable for the GPT channels. + required: - compatible - reg @@ -375,4 +397,5 @@ examples: power-domains =3D <&cpg>; resets =3D <&cpg R9A07G044_GPT_RST_C>; #pwm-cells =3D <3>; + renesas,poegs =3D <&poeggd 4>; }; --=20 2.43.0 From nobody Mon Sep 28 06:35:54 2026 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 9933635C6A1 for ; Tue, 25 Aug 2026 15:49:00 +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=1787672943; cv=none; b=HzGQop+M5Pp9G6F2+N4O3KimDQEJiR3XxyWLv49gAyC+TY6SkxzIAbBBkGu62iOcTMOx2+h/t5c14n3Y+nNXLEhLxDP9zYLDW1AhDM+EUYm0PPCKb+LbNxzQsSpgoaQx5GK+/I8eg5FYxZOVscM0XIOXIQKwgE3YKOmgovGglHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787672943; c=relaxed/simple; bh=Fr6vZ1NVUY/ybNbFnbE6lWd5PnSaqK+am3TZW/YW1RQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=H1uTJ6K2ldX3J+VHb/TLB6QVxU98t+5ERC1B2zrOdqrNHpQGTWLlEaGVuwCp2PnaqPJviiHBJ4GqaYar4I1mmEHxYpB+jas2ukkFwHjkRv3rDU9t+SL4dDecE1RSx6eGFqc0lLa3YicDut01PE9Z1p/kb5aXzNRhtzrJg3Rj3hY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=raaf8iqW; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="raaf8iqW" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-c15e2dab83eso916527966b.1 for ; Tue, 25 Aug 2026 08:49:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787672938; x=1788277738; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=VNEW08Lt7wc/0z32MZRrbpAxfkdBvCnakXic3N1PQJE=; b=raaf8iqW+TN9l7+s5QcDe2BRQj9x0cBHhQcbnFfaZ0pZle+kuYGCJSrrpSpmwJ/c5B 9guxkSGZDCTxncVRa3N94TZAUUrgBuVO57gvGaHM+pIMt2dbQmKGZnOO29v2HArYON89 XS6okDmJxUguRIDWVcUe0t6TzND5XTkEPiSATxKLhL4hv2U9lzkWo4/xGoYBlskLL7cO S0fNFPxD+x4/X92RJq9Fq1vd1jqVXdZmFGt7wuHDNOQqIrDADS6r1pzkL3en6WR6uSU3 G3fYMjymZHs0ZfVRRsmgnt1GhuiaSNoX0Q6sViyNVjM6g8AlSxvlp8mYNp6krB1b08nk z55g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787672938; x=1788277738; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=VNEW08Lt7wc/0z32MZRrbpAxfkdBvCnakXic3N1PQJE=; b=eeXJz2whxbPOipZ25Hj6wu8o0rQOc121O2jutJ5P7ZcidQd3imM+A0IQYQORDOEB1K J8dByaQ/B8jlj2dWjCoZ20YBo/OS3GvJVqNkMzvlV+YvxAWT2lmAQkPlG9vSkdY3vNzA qIbIkOORQBIDvu5fTSWvACA3xLmPVnHekULWfxOFH2F24/aeSxObDBrR7lag5G3TIXBe sZzqJTB3lbftzw8A8Kb5SBFpRajdoZp/jg1EwtQqG0U0gOaHcWiTy8XPL7duCBjZHul2 gIzRwKf+4kw2Hbh6N+Ud+eiGDH4o9iWQUPbfgcuZTD/kPNCQSvq9CUpV8L1PmDrmwxXe WjGQ== X-Forwarded-Encrypted: i=1; AHgh+RqQiI5Jnr/UH6YW83jZq/uvD1BenuprM30Lu1Oxqk12WIlIQ8wzd5FP/QBZckLVYvF0NRxvAHv49xRBFsA=@vger.kernel.org X-Gm-Message-State: AFuF++m1LTPFi3CPlLDMy6EQdtMBDYPrn6zLcofkzBVCUiFe3uPbTFzX wujXXYgSOgS1cCeBZ/EbKYqeX/kX+7pwo7/89A4cqkV6F5vxzTAv88Xf X-Gm-Gg: AR+sD10BQHVYNldAT2IGv+1d8evNAbdNqJZ98A5CsrsA7XK6rAI+Pn5q9VRo+fZG1YV biVoNSrh9qdCTAdoytEPjIRPvBXNzgtERpleJL9yg3UxAYHgPXJ4BBQ31pFx0uDvaSB1dt/+DRi plHDzjSpHikKROU2EeA/K+3vn+kJnSEDUxcOGuipe+UrPDw86tcP+0OixEOeJHW9eqiX9vvRWUm yXXTrXTkOkCtmdXMANkTKPFI36aNrztNcQriNnEtIt8lW+xCPYPSqddYUa5CaixaTgGvkTOBzeu u6ntnZa7AgfnWg6oz34EBoDtMiHNYrkR/Nv679FcEPVRciBeWQCig4CkA/wk8u238ecuYcJw2KG h11TIDQwbWT6qqcKgOpWC3EKdgkUKIpyKv12Q0WE9NRcF6RoVNIY7L8l0OsfoNToWVbqzITDxEJ 3Kbrkw6QSC0vsLxOyQnDaNh1q9fLpKwabQ/cf+7tPGhIk+zEJJ2h3BrT/+QHyPosFWTtPkQAGOZ znRl8G4xq0X X-Received: by 2002:a17:906:f591:b0:c24:6045:2a94 with SMTP id a640c23a62f3a-c24e5c8ad60mr1042925466b.4.1787672938487; Tue, 25 Aug 2026 08:48:58 -0700 (PDT) Received: from localhost.localdomain ([2a00:23c4:a702:d301:81d:57c0:e4cb:959c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c250a6fd69asm16682066b.18.2026.08.25.08.48.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 08:48:58 -0700 (PDT) From: Biju X-Google-Original-From: Biju To: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Geert Uytterhoeven , Magnus Damm Cc: Biju Das , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar Mahadev Lad , Biju Das Subject: [PATCH v8 9/9] pwm: rzg2l-gpt: Add support for gpt linking with poeg Date: Tue, 25 Aug 2026 16:48:37 +0100 Message-ID: <20260825154847.197948-10-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825154847.197948-1-biju.das.jz@bp.renesas.com> References: <20260825154847.197948-1-biju.das.jz@bp.renesas.com> 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 From: Biju Das The General PWM Timer (GPT) is capable of detecting "dead time error and short-circuits between output pins" and send Output disable request to poeg(Port Output Enable for GPT). Add support for linking poeg group with gpt, so that gpt can control the output disable function by adding rzg2l_gpt_poeg_init() to parse the renesas,poegs device tree property and establish links between POEG groups (A=E2=80=93D) and GPT hardware channels (0=E2=80=937). For each vali= d, enabled POEG phandle entry, the driver: - Reads the renesas,poeg-id from the POEG node and validates it against the supported range - Records the GPT=E2=80=93POEG association in a per-chip bitmap (poeg_gpt_= link) - Configures GTINTAD to route the output disable request to the correct POEG group - Configures GTIOR (OADF/OBDF fields) to set both output pins to high-impedance on an output disable event Non-enabled POEG nodes are silently skipped. Signed-off-by: Biju Das --- v7->v8: * No change. v6->v7: * Added rzg2l_gpt_poeg_link_channels() and used __free for deallocating device node pointer. * Replaced dev_err()->dev_err_probe() in rzg2l_gpt_poeg_link_channels(). * Replaced local variable cells with num_poeg_pairs in rzg2l_gpt_poeg_init(). v5->v6: * Dropped extra space in poegs variable assignment in rzg2l_gpt_poeg_init(). * Updated the comment sections of rzg2l_gpt_poeg_init() with POEG and GPT in upper-case and replaced configure->configures. * Format specifiers in dev_err() changed from %d to %u in rzg2l_gpt_poeg_init(). v5: * Updated commit description. * Replaced return type of rzg2l_gpt_poeg_init() from void->int and probe() checks this return value. * Added more error checks in rzg2l_gpt_poeg_init()=20 V24 from [1]: [1] https://lore.kernel.org/all/20250226144531.176819-1-biju.das.jz@bp.rene= sas.com/ --- drivers/pwm/pwm-rzg2l-gpt.c | 92 +++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/drivers/pwm/pwm-rzg2l-gpt.c b/drivers/pwm/pwm-rzg2l-gpt.c index 6f47e14cceab..ff28ad0ba75f 100644 --- a/drivers/pwm/pwm-rzg2l-gpt.c +++ b/drivers/pwm/pwm-rzg2l-gpt.c @@ -45,6 +45,7 @@ #define RZG2L_GTCR(ch) (0x2c + RZG2L_GET_CH_OFFS(ch)) #define RZG2L_GTUDDTYC(ch) (0x30 + RZG2L_GET_CH_OFFS(ch)) #define RZG2L_GTIOR(ch) (0x34 + RZG2L_GET_CH_OFFS(ch)) +#define RZG2L_GTINTAD(ch) (0x38 + RZG2L_GET_CH_OFFS(ch)) #define RZG2L_GTBER(ch) (0x40 + RZG2L_GET_CH_OFFS(ch)) #define RZG2L_GTCNT(ch) (0x48 + RZG2L_GET_CH_OFFS(ch)) #define RZG2L_GTCCR(ch, sub_ch) (0x4c + RZG2L_GET_CH_OFFS(ch) + 4 * (sub_c= h)) @@ -62,12 +63,19 @@ #define RZG2L_GTUDDTYC_UP_COUNTING (RZG2L_GTUDDTYC_UP | RZG2L_GTUDDTYC_UDF) =20 #define RZG2L_GTIOR_GTIOA GENMASK(4, 0) +#define RZG2L_GTIOR_OADF GENMASK(10, 9) #define RZG2L_GTIOR_GTIOB GENMASK(20, 16) +#define RZG2L_GTIOR_OBDF GENMASK(26, 25) #define RZG2L_GTIOR_GTIOx(sub_ch) ((sub_ch) ? RZG2L_GTIOR_GTIOB : RZG2L_GT= IOR_GTIOA) #define RZG2L_GTIOR_OAE BIT(8) #define RZG2L_GTIOR_OBE BIT(24) #define RZG2L_GTIOR_OxE(sub_ch) ((sub_ch) ? RZG2L_GTIOR_OBE : RZG2L_GTIOR= _OAE) =20 +#define RZG2L_GTIOR_OADF_HIGH_IMP_ON_OUT_DISABLE BIT(9) +#define RZG2L_GTIOR_OBDF_HIGH_IMP_ON_OUT_DISABLE BIT(25) +#define RZG2L_GTIOR_PIN_DISABLE_SETTING \ + (RZG2L_GTIOR_OADF_HIGH_IMP_ON_OUT_DISABLE | RZG2L_GTIOR_OBDF_HIGH_IMP_ON_= OUT_DISABLE) + #define RZG2L_INIT_OUT_HI_OUT_HI_END_TOGGLE 0x1b #define RZG2L_GTIOR_GTIOA_OUT_HI_END_TOGGLE_CMP_MATCH \ (RZG2L_INIT_OUT_HI_OUT_HI_END_TOGGLE | RZG2L_GTIOR_OAE) @@ -78,12 +86,17 @@ ((sub_ch) ? RZG2L_GTIOR_GTIOB_OUT_HI_END_TOGGLE_CMP_MATCH : \ RZG2L_GTIOR_GTIOA_OUT_HI_END_TOGGLE_CMP_MATCH) =20 +#define RZG2L_GTINTAD_GRP_MASK GENMASK(25, 24) + #define RZG2L_MAX_HW_CHANNELS 8 #define RZG2L_CHANNELS_PER_IO 2 #define RZG2L_MAX_PWM_CHANNELS (RZG2L_MAX_HW_CHANNELS * RZG2L_CHANNELS_PER= _IO) #define RZG2L_MAX_SCALE_FACTOR 1024 #define RZG2L_MAX_TICKS ((u64)U32_MAX * RZG2L_MAX_SCALE_FACTOR) =20 +#define RZG2L_MAX_POEG_GROUPS 4 +#define RZG2L_LAST_POEG_GROUP 3 + struct rzg2l_gpt_info { u8 (*calculate_prescale)(u64 period); u32 gtcr_tpcs; @@ -99,6 +112,7 @@ struct rzg2l_gpt_chip { u32 channel_request_count[RZG2L_MAX_HW_CHANNELS]; u32 channel_enable_count[RZG2L_MAX_HW_CHANNELS]; u8 prescale[RZG2L_MAX_HW_CHANNELS]; + DECLARE_BITMAP(poeg_gpt_link, RZG2L_MAX_POEG_GROUPS * RZG2L_MAX_HW_CHANNE= LS); }; =20 /* This represents a hardware configuration for one channel */ @@ -468,6 +482,80 @@ static const struct pwm_ops rzg2l_gpt_ops =3D { .write_waveform =3D rzg2l_gpt_write_waveform, }; =20 +static int rzg2l_gpt_poeg_link_channels(struct device *dev, + struct rzg2l_gpt_chip *rzg2l_gpt, + struct of_phandle_args *of_args) +{ + struct device_node *np __free(device_node) =3D of_args->np; + u32 poeg_grp, bitpos; + + if (of_args->args[0] >=3D RZG2L_MAX_HW_CHANNELS) + return dev_err_probe(dev, -EINVAL, "Invalid channel %u >=3D %u\n", + of_args->args[0], RZG2L_MAX_HW_CHANNELS); + + if (!of_device_is_available(of_args->np)) + /* It's fine to have a phandle to a non-enabled poeg. */ + return 0; + + if (!of_property_read_u32(of_args->np, "renesas,poeg-id", &poeg_grp)) { + if (poeg_grp > RZG2L_LAST_POEG_GROUP) + return dev_err_probe(dev, -EINVAL, "Invalid poeg group %u > %u\n", + poeg_grp, RZG2L_LAST_POEG_GROUP); + + bitpos =3D of_args->args[0] + poeg_grp * RZG2L_MAX_HW_CHANNELS; + set_bit(bitpos, rzg2l_gpt->poeg_gpt_link); + + rzg2l_gpt_modify(rzg2l_gpt, RZG2L_GTINTAD(of_args->args[0]), + RZG2L_GTINTAD_GRP_MASK, poeg_grp << 24); + + rzg2l_gpt_modify(rzg2l_gpt, RZG2L_GTIOR(of_args->args[0]), + RZG2L_GTIOR_OBDF | RZG2L_GTIOR_OADF, + RZG2L_GTIOR_PIN_DISABLE_SETTING); + } + + return 0; +} + +/* + * This function links a POEG group{A,B,C,D} with a GPT channel{0..7} and + * configures the pin for output disable. + */ +static int rzg2l_gpt_poeg_init(struct platform_device *pdev, + struct rzg2l_gpt_chip *rzg2l_gpt) +{ + const char *poeg_name =3D "renesas,poegs"; + struct of_phandle_args of_args; + struct property *poegs; + int num_poeg_pairs; + int ret; + + poegs =3D of_find_property(pdev->dev.of_node, poeg_name, NULL); + if (!poegs) + return 0; + + num_poeg_pairs =3D of_property_count_u32_elems(pdev->dev.of_node, poeg_na= me); + if (num_poeg_pairs < 0) + return num_poeg_pairs; + + if (num_poeg_pairs & 1) + return -EINVAL; + + num_poeg_pairs >>=3D 1; + for (unsigned int i =3D 0; i < num_poeg_pairs; i++) { + ret =3D of_parse_phandle_with_fixed_args(pdev->dev.of_node, + poeg_name, 1, i, + &of_args); + if (ret) + return ret; + + ret =3D rzg2l_gpt_poeg_link_channels(&pdev->dev, rzg2l_gpt, &of_args); + if (ret) + return ret; + } + + return 0; +} + static int rzg2l_gpt_probe(struct platform_device *pdev) { struct rzg2l_gpt_chip *rzg2l_gpt; @@ -529,6 +617,10 @@ static int rzg2l_gpt_probe(struct platform_device *pde= v) if (rzg2l_gpt->rate_khz * KILO !=3D rate) return dev_err_probe(dev, -EINVAL, "Rate is not multiple of 1000\n"); =20 + ret =3D rzg2l_gpt_poeg_init(pdev, rzg2l_gpt); + if (ret) + return dev_err_probe(dev, ret, "Failed to link gpt with poeg\n"); + mutex_init(&rzg2l_gpt->lock); =20 chip->ops =3D &rzg2l_gpt_ops; --=20 2.43.0