[PATCH v7 7/9] pwm: rzg2l-gpt: Add RZ/G3E support
Biju <[email protected]>
| Newsgroups | org.kernel.vger.linux-pwm,org.kernel.vger.linux-kernel,org.kernel.vger.linux-renesas-soc |
|---|---|
| Message-ID | <[email protected]> |
From: Biju Das <[email protected]> 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 <[email protected]> Signed-off-by: Biju Das <[email protected]> --- 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 --- 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 2a1c5a22484b..c61c648f71a8 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-users-manual-hardware-0?language=en + * https://www.renesas.com/en/document/mah/rzg3e-group-users-manual-hardware * * 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) #define RZG2L_GTCR_MD_SAW_WAVE_PWM_MODE FIELD_PREP(RZG2L_GTCR_MD, 0) @@ -146,6 +153,22 @@ static u8 rzg2l_gpt_calculate_prescale(u64 period_ticks) return prescale; } +static u8 rzg3e_gpt_calculate_prescale(u64 period_ticks) +{ + u32 prescaled_period_ticks; + u8 prescale; + + prescaled_period_ticks = period_ticks >> 32; + if (prescaled_period_ticks > 64 && prescaled_period_ticks < 256) + prescale = 8; + else if (prescaled_period_ticks >= 256) + prescale = 10; + else + prescale = 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 = to_rzg2l_gpt_chip(chip); @@ -227,7 +250,8 @@ static u64 rzg2l_gpt_calculate_period_or_duty(struct rzg2l_gpt_chip *rzg2l_gpt, /* * The calculation doesn't overflow a u64 because, - * prescale ≤ 5 for info->prescale_mult = 2 and so + * prescale ≤ 5 for info->prescale_mult = 2, + * prescale ≤ 10 for info->prescale_mult = 1, and so * tmp = val << (info->prescale_mult * prescale) * NSEC_PER_MSEC * < 2^32 * 2^10 * 10^6 * < 2^32 * 2^10 * 2^20 @@ -460,6 +484,14 @@ static int rzg2l_gpt_probe(struct platform_device *pdev) if (IS_ERR(rstc)) return dev_err_probe(dev, PTR_ERR(rstc), "Cannot deassert reset control\n"); + rstc = 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 = 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 = devm_clk_get_enabled(dev, NULL); if (IS_ERR(clk)) return dev_err_probe(dev, PTR_ERR(clk), "Cannot get clock\n"); @@ -498,6 +530,12 @@ static int rzg2l_gpt_probe(struct platform_device *pdev) return 0; } +static const struct rzg2l_gpt_info rzg3e_data = { + .calculate_prescale = rzg3e_gpt_calculate_prescale, + .gtcr_tpcs = RZG3E_GTCR_TPCS, + .prescale_mult = 1, +}; + static const struct rzg2l_gpt_info rzg2l_data = { .calculate_prescale = rzg2l_gpt_calculate_prescale, .gtcr_tpcs = RZG2L_GTCR_TPCS, @@ -505,6 +543,7 @@ static const struct rzg2l_gpt_info rzg2l_data = { }; static const struct of_device_id rzg2l_gpt_of_table[] = { + { .compatible = "renesas,r9a09g047-gpt", .data = &rzg3e_data }, { .compatible = "renesas,rzg2l-gpt", .data = &rzg2l_data }, { /* Sentinel */ } }; -- 2.43.0