pwm: renesas: Add R-Car X5H support
Subsystems (3)
v2 cover pwm: renesas: Add R-Car X5H support
From: Geert Uytterhoeven <[email protected]>
Hi all,
This patch series adds support for the 16-Bit Timer Pulse Unit (TPU) and the PWM instances on the Renesas R-Car X5H SoC to the Renesas PWM drivers:
1. The first patch documents support for the 16-Bit Timer Pulse Unit (TPU) on R-Car X5H; no driver changes are needed,
2. Patches 2-6 document and add support for the PWM instances on R-Car X5H, after a few customary refactorings.
Changes compared to v1[1]:
- Drop platform integration patches not intended for the PWM tree,
- Add Acked-by,
- Add Reviewed-by,
- Improve patch description.
PWM instances 0 to 5 and TPU channels 0 and 1 have been tested on the Ironhide development board using a set of blinkenlights and a logic analyzer.
Thanks for your comments!
[1] "[PATCH 00/11] arm64: renesas: r8a78000: Add PWM support"
https://lore.kernel.org/[email protected]
Geert Uytterhoeven (5):
dt-bindings: pwm: renesas,pwm-rcar: Add support for R-Car X5H
pwm: rcar: Use FIELD_PREP() for PWMCR_CC0 access
pwm: rcar: Add helper variable dev to rcar_pwm_probe()
pwm: rcar: Parametrize cycle counter field size
pwm: rcar: Add support for R-Car Gen5
Khanh Le (1):
dt-bindings: pwm: renesas,tpu-pwm: Add support for R-Car X5H
.../bindings/pwm/renesas,pwm-rcar.yaml | 61 ++++++------ .../bindings/pwm/renesas,tpu-pwm.yaml | 1 + drivers/pwm/pwm-rcar.c | 92 +++++++++++++------ 3 files changed, 96 insertions(+), 58 deletions(-)
Signature · 12 lines
2.43.0
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus TorvaldsPATCH v2 1/6 dt-bindings: pwm: renesas,tpu-pwm: Add support for R-Car X5H
From: Khanh Le <[email protected]>
Document support for the 16-Bit Timer Pulse Unit (TPU) in the Renesas R-Car X5H (R8A78000) SoC.
---
v2:
- Add Acked-by.
--- Documentation/devicetree/bindings/pwm/renesas,tpu-pwm.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/pwm/renesas,tpu-pwm.yaml +1 -0
@@ -33,6 +33,7 @@ properties: - renesas,tpu-r8a779a0 # R-Car V3U - renesas,tpu-r8a779g0 # R-Car V4H - renesas,tpu-r8a779h0 # R-Car V4M + - renesas,tpu-r8a78000 # R-Car X5H - const: renesas,tpu reg:
Signature · 1 line
2.43.0
PATCH v2 2/6 dt-bindings: pwm: renesas,pwm-rcar: Add support for R-Car X5H
In reply to Geert UytterhoevenFrom: Geert Uytterhoeven <[email protected]>
Document support for the Pulse Width Modulation (PWM) module in the Renesas R-Car X5H (R8A78000) SoC.
R-Car Gen5 enlarged the PWM output cycle and high-level period fields from 10 to 24 bits. While the added register bits have initial states of all-zeroes, and thus look compatible with previous generations, the register bits may have been modified before Linux boots. Hence no fallback to renesas,pwm-rcar is included.
---
v2:
- Add Reviewed-by.
--- .../bindings/pwm/renesas,pwm-rcar.yaml | 61 ++++++++++--------- 1 file changed, 33 insertions(+), 28 deletions(-)
Documentation/devicetree/bindings/pwm/renesas,pwm-rcar.yaml +33 -28
@@ -11,34 +11,39 @@ maintainers: properties: compatible: - items: - - enum: - - renesas,pwm-r8a7742 # RZ/G1H - - renesas,pwm-r8a7743 # RZ/G1M - - renesas,pwm-r8a7744 # RZ/G1N - - renesas,pwm-r8a7745 # RZ/G1E - - renesas,pwm-r8a77470 # RZ/G1C - - renesas,pwm-r8a774a1 # RZ/G2M - - renesas,pwm-r8a774b1 # RZ/G2N - - renesas,pwm-r8a774c0 # RZ/G2E - - renesas,pwm-r8a774e1 # RZ/G2H - - renesas,pwm-r8a7778 # R-Car M1A - - renesas,pwm-r8a7779 # R-Car H1 - - renesas,pwm-r8a7790 # R-Car H2 - - renesas,pwm-r8a7791 # R-Car M2-W - - renesas,pwm-r8a7794 # R-Car E2 - - renesas,pwm-r8a7795 # R-Car H3 - - renesas,pwm-r8a7796 # R-Car M3-W - - renesas,pwm-r8a77961 # R-Car M3-W+ - - renesas,pwm-r8a77965 # R-Car M3-N - - renesas,pwm-r8a77970 # R-Car V3M - - renesas,pwm-r8a77980 # R-Car V3H - - renesas,pwm-r8a77990 # R-Car E3 - - renesas,pwm-r8a77995 # R-Car D3 - - renesas,pwm-r8a779a0 # R-Car V3U - - renesas,pwm-r8a779g0 # R-Car V4H - - renesas,pwm-r8a779h0 # R-Car V4M - - const: renesas,pwm-rcar + oneOf: + - items: + - enum: + - renesas,pwm-r8a7742 # RZ/G1H + - renesas,pwm-r8a7743 # RZ/G1M + - renesas,pwm-r8a7744 # RZ/G1N + - renesas,pwm-r8a7745 # RZ/G1E + - renesas,pwm-r8a77470 # RZ/G1C + - renesas,pwm-r8a774a1 # RZ/G2M + - renesas,pwm-r8a774b1 # RZ/G2N + - renesas,pwm-r8a774c0 # RZ/G2E + - renesas,pwm-r8a774e1 # RZ/G2H + - renesas,pwm-r8a7778 # R-Car M1A + - renesas,pwm-r8a7779 # R-Car H1 + - renesas,pwm-r8a7790 # R-Car H2 + - renesas,pwm-r8a7791 # R-Car M2-W + - renesas,pwm-r8a7794 # R-Car E2 + - renesas,pwm-r8a7795 # R-Car H3 + - renesas,pwm-r8a7796 # R-Car M3-W + - renesas,pwm-r8a77961 # R-Car M3-W+ + - renesas,pwm-r8a77965 # R-Car M3-N + - renesas,pwm-r8a77970 # R-Car V3M + - renesas,pwm-r8a77980 # R-Car V3H + - renesas,pwm-r8a77990 # R-Car E3 + - renesas,pwm-r8a77995 # R-Car D3 + - renesas,pwm-r8a779a0 # R-Car V3U + - renesas,pwm-r8a779g0 # R-Car V4H + - renesas,pwm-r8a779h0 # R-Car V4M + - const: renesas,pwm-rcar + - items: + - enum: + - renesas,pwm-r8a78000 # R-Car X5H + - const: renesas,rcar-gen5-pwm reg: # base address and length of the registers block for the PWM.
Signature · 1 line
2.43.0
PATCH v2 3/6 pwm: rcar: Use FIELD_PREP() for PWMCR_CC0 access
In reply to Geert UytterhoevenFrom: Geert Uytterhoeven <[email protected]>
Use the FIELD_PREP() helper instead of open-coding the same operation. Drop the now unused RCAR_PWMCR_CC0_SHIFT definition, and redefine RCAR_PWMCR_CC0_SHIFT using GENMASK() while at it.
---
v2:
- No changes.
--- drivers/pwm/pwm-rcar.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/pwm/pwm-rcar.c +2 -3
@@ -25,8 +25,7 @@#define RCAR_PWM_MAX_CYCLE 1023#define RCAR_PWMCR 0x00 -#define RCAR_PWMCR_CC0_MASK 0x000f0000 -#define RCAR_PWMCR_CC0_SHIFT 16 +#define RCAR_PWMCR_CC0_MASK GENMASK(19, 16)#define RCAR_PWMCR_CCMD BIT(15)#define RCAR_PWMCR_SYNC BIT(11)#define RCAR_PWMCR_SS0 BIT(4)
@@ -99,7 +98,7 @@ static void rcar_pwm_set_clock_control(struct rcar_pwm_chip *rp, div >>=1 ; - value |= div <<RCAR_PWMCR_CC0_SHIFT ; + value |=FIELD_PREP (RCAR_PWMCR_CC0_MASK , div);rcar_pwm_write (rp, value,RCAR_PWMCR ); }
Signature · 1 line
2.43.0
PATCH v2 4/6 pwm: rcar: Add helper variable dev to rcar_pwm_probe()
In reply to Geert UytterhoevenFrom: Geert Uytterhoeven <[email protected]>
rcar_pwm_probe() has many users of "&pdev->dev".
Introduce a shorthand to simplify the code.
---
v2:
- No changes.
--- drivers/pwm/pwm-rcar.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/pwm/pwm-rcar.c +8 -7
@@ -202,11 +202,12 @@ static const struct pwm_ops rcar_pwm_ops = {static int rcar_pwm_probe (struct platform_device *pdev) { -struct pwm_chip *chip; +struct device *dev = &pdev->dev;struct rcar_pwm_chip *rcar_pwm; +struct pwm_chip *chip;int ret; - chip =devm_pwmchip_alloc (&pdev->dev,1 ,sizeof (*rcar_pwm)); + chip =devm_pwmchip_alloc (dev,1 ,sizeof (*rcar_pwm));if (IS_ERR (chip))return PTR_ERR (chip); rcar_pwm =to_rcar_pwm_chip (chip);
@@ -215,9 +216,9 @@ static int rcar_pwm_probe(struct platform_device *pdev)if (IS_ERR (rcar_pwm->base))return PTR_ERR (rcar_pwm->base); - rcar_pwm->clk =devm_clk_get (&pdev->dev,NULL ); + rcar_pwm->clk =devm_clk_get (dev,NULL );if (IS_ERR (rcar_pwm->clk)) { -dev_err (&pdev->dev,"cannot get clock\n" ); +dev_err (dev,"cannot get clock\n" );return PTR_ERR (rcar_pwm->clk); }
@@ -225,12 +226,12 @@ static int rcar_pwm_probe(struct platform_device *pdev)platform_set_drvdata (pdev, chip); -pm_runtime_enable (&pdev->dev); +pm_runtime_enable (dev); ret =pwmchip_add (chip);if (ret <0 ) { -dev_err (&pdev->dev,"failed to register PWM chip: %d\n" , ret); -pm_runtime_disable (&pdev->dev); +dev_err (dev,"failed to register PWM chip: %d\n" , ret); +pm_runtime_disable (dev);return ret; }
Signature · 1 line
2.43.0
PATCH v2 5/6 pwm: rcar: Parametrize cycle counter field size
In reply to Geert UytterhoevenFrom: Geert Uytterhoeven <[email protected]>
Prepare for the advent of PWM blocks with output cycle and high-level period fields larger than 10 bits by parametrizing the field size.
---
v2:
- No changes.
--- drivers/pwm/pwm-rcar.c | 51 +++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 18 deletions(-)
drivers/pwm/pwm-rcar.c +33 -18
@@ -22,7 +22,7 @@#include <linux/slab.h> #define RCAR_PWM_MAX_DIVISION 24 -#define RCAR_PWM_MAX_CYCLE 1023 +#define RCAR_PWM_MAX_CYCLE (rp) GENMASK(rp->cycle_bits - 1, 0)#define RCAR_PWMCR 0x00#define RCAR_PWMCR_CC0_MASK GENMASK(19, 16)
@@ -32,14 +32,17 @@#define RCAR_PWMCR_EN0 BIT(0)#define RCAR_PWMCNT 0x04 -#define RCAR_PWMCNT_CYC0_MASK 0x03ff0000 -#define RCAR_PWMCNT_CYC0_SHIFT 16 -#define RCAR_PWMCNT_PH0_MASK 0x000003ff -#define RCAR_PWMCNT_PH0_SHIFT 0 +#define RCAR_PWMCNT_CYC0_MASK GENMASK(31, 16) +#define RCAR_PWMCNT_PH0_MASK GENMASK(15, 0)struct rcar_pwm_chip {void __iomem *base;struct clk *clk; +unsigned int cycle_bits; +}; + +struct rcar_pwm_info { +unsigned int cycle_bits; };static inline struct rcar_pwm_chip *to_rcar_pwm_chip (struct pwm_chip *chip)
@@ -77,7 +80,7 @@ static int rcar_pwm_get_clock_division(struct rcar_pwm_chip *rp, int period_ns)if (clk_rate ==0 )return -EINVAL ; - div = (u64 )NSEC_PER_SEC *RCAR_PWM_MAX_CYCLE ; + div =mul_u32_u32 (NSEC_PER_SEC ,RCAR_PWM_MAX_CYCLE (rp)); tmp = (u64 )period_ns * clk_rate + div -1 ; tmp =div64_u64 (tmp, div); div =ilog2 (tmp -1 ) +1 ;
@@ -111,21 +114,19 @@ static int rcar_pwm_set_counter(struct rcar_pwm_chip *rp, int div, u64 duty_ns,/* div <= 24 == RCAR_PWM_MAX_DIVISION, so the shift doesn't overflow. */ tmp =mul_u64_u64_div_u64 (period_ns, clk_rate, (u64 )NSEC_PER_SEC << div); -if (tmp >FIELD_MAX (RCAR_PWMCNT_CYC0_MASK )) - tmp =FIELD_MAX (RCAR_PWMCNT_CYC0_MASK ); - - cyc =FIELD_PREP (RCAR_PWMCNT_CYC0_MASK , tmp); + cyc =min (tmp,RCAR_PWM_MAX_CYCLE (rp)); tmp =mul_u64_u64_div_u64 (duty_ns, clk_rate, (u64 )NSEC_PER_SEC << div); -if (tmp >FIELD_MAX (RCAR_PWMCNT_PH0_MASK )) - tmp =FIELD_MAX (RCAR_PWMCNT_PH0_MASK ); - ph =FIELD_PREP (RCAR_PWMCNT_PH0_MASK , tmp); + ph =min (tmp,RCAR_PWM_MAX_CYCLE (rp));/* Avoid prohibited setting */ if (cyc ==0 || ph ==0 )return -EINVAL ; -rcar_pwm_write (rp, cyc | ph,RCAR_PWMCNT ); +rcar_pwm_write (rp, +FIELD_PREP (RCAR_PWMCNT_CYC0_MASK , cyc) | +FIELD_PREP (RCAR_PWMCNT_PH0_MASK , ph), +RCAR_PWMCNT );return 0 ; }
@@ -142,12 +143,15 @@ static void rcar_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)static int rcar_pwm_enable (struct rcar_pwm_chip *rp) { -u32 value; +u32 value, cyc, ph;/* Don't enable the PWM device if CYC0 or PH0 is 0 */ value =rcar_pwm_read (rp,RCAR_PWMCNT ); -if ((value &RCAR_PWMCNT_CYC0_MASK ) ==0 || - (value &RCAR_PWMCNT_PH0_MASK ) ==0 ) + cyc =FIELD_GET (RCAR_PWMCNT_CYC0_MASK , value); + ph =FIELD_GET (RCAR_PWMCNT_PH0_MASK , value); + +if ((cyc &RCAR_PWM_MAX_CYCLE (rp)) ==0 || + (ph &RCAR_PWM_MAX_CYCLE (rp)) ==0 )return -EINVAL ;rcar_pwm_update (rp,RCAR_PWMCR_EN0 ,RCAR_PWMCR_EN0 ,RCAR_PWMCR );
@@ -202,11 +206,16 @@ static const struct pwm_ops rcar_pwm_ops = {static int rcar_pwm_probe (struct platform_device *pdev) { +const struct rcar_pwm_info *info;struct device *dev = &pdev->dev;struct rcar_pwm_chip *rcar_pwm;struct pwm_chip *chip;int ret; + info =of_device_get_match_data (dev); +if (!info) +return -ENODEV ; + chip =devm_pwmchip_alloc (dev,1 ,sizeof (*rcar_pwm));if (IS_ERR (chip))return PTR_ERR (chip);
@@ -222,6 +231,8 @@ static int rcar_pwm_probe(struct platform_device *pdev)return PTR_ERR (rcar_pwm->clk); } + rcar_pwm->cycle_bits = info->cycle_bits; + chip->ops = &rcar_pwm_ops;platform_set_drvdata (pdev, chip);
@@ -247,8 +258,12 @@ static void rcar_pwm_remove(struct platform_device *pdev)pm_runtime_disable (&pdev->dev); } +static const struct rcar_pwm_info rcar_pwm_info = { + .cycle_bits =10 , +}; +static const struct of_device_id rcar_pwm_of_table[] = { - { .compatible ="renesas,pwm-rcar" }, + { .compatible ="renesas,pwm-rcar" , .data = &rcar_pwm_info }, { } };MODULE_DEVICE_TABLE (of, rcar_pwm_of_table);
Signature · 1 line
2.43.0
PATCH v2 6/6 pwm: rcar: Add support for R-Car Gen5
In reply to Geert UytterhoevenFrom: Geert Uytterhoeven <[email protected]>
R-Car Gen5 enlarged the PWM output cycle and high-level period fields from 10 to 24 bits. As the existing register bitfields can accommodate only 16 bits, the high parts of each field are stored in a new register.
---
v2:
- Improve patch description.
--- drivers/pwm/pwm-rcar.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-)
drivers/pwm/pwm-rcar.c +22 -5
@@ -31,7 +31,8 @@#define RCAR_PWMCR_SS0 BIT(4)#define RCAR_PWMCR_EN0 BIT(0) -#define RCAR_PWMCNT 0x04 +#define RCAR_PWMCNTA 0x04/* Low part */ +#define RCAR_PWMCNTB 0x08/* High part (R-Car Gen5) */ #define RCAR_PWMCNT_CYC0_MASK GENMASK(31, 16)#define RCAR_PWMCNT_PH0_MASK GENMASK(15, 0)
@@ -124,9 +125,15 @@ static int rcar_pwm_set_counter(struct rcar_pwm_chip *rp, int div, u64 duty_ns,return -EINVAL ;rcar_pwm_write (rp, -FIELD_PREP (RCAR_PWMCNT_CYC0_MASK , cyc) | -FIELD_PREP (RCAR_PWMCNT_PH0_MASK , ph), -RCAR_PWMCNT ); +FIELD_PREP (RCAR_PWMCNT_CYC0_MASK ,lower_16_bits (cyc)) | +FIELD_PREP (RCAR_PWMCNT_PH0_MASK ,lower_16_bits (ph)), +RCAR_PWMCNTA ); + +if (rp->cycle_bits >=16 ) +rcar_pwm_write (rp, +FIELD_PREP (RCAR_PWMCNT_CYC0_MASK ,upper_16_bits (cyc)) | +FIELD_PREP (RCAR_PWMCNT_PH0_MASK ,upper_16_bits (ph)), +RCAR_PWMCNTB );return 0 ; }
@@ -146,9 +153,14 @@ static int rcar_pwm_enable(struct rcar_pwm_chip *rp)u32 value, cyc, ph;/* Don't enable the PWM device if CYC0 or PH0 is 0 */ - value =rcar_pwm_read (rp,RCAR_PWMCNT ); + value =rcar_pwm_read (rp,RCAR_PWMCNTA ); cyc =FIELD_GET (RCAR_PWMCNT_CYC0_MASK , value); ph =FIELD_GET (RCAR_PWMCNT_PH0_MASK , value); +if (rp->cycle_bits >=16 ) { + value =rcar_pwm_read (rp,RCAR_PWMCNTB ); + cyc |=FIELD_GET (RCAR_PWMCNT_CYC0_MASK , value) <<16 ; + ph |=FIELD_GET (RCAR_PWMCNT_PH0_MASK , value) <<16 ; + }if ((cyc &RCAR_PWM_MAX_CYCLE (rp)) ==0 || (ph &RCAR_PWM_MAX_CYCLE (rp)) ==0 )
@@ -262,8 +274,13 @@ static const struct rcar_pwm_info rcar_pwm_info = { .cycle_bits = 10, }; +static const struct rcar_pwm_info rcar_gen5_pwm_info = { + .cycle_bits =24 , +}; +static const struct of_device_id rcar_pwm_of_table[] = { { .compatible ="renesas,pwm-rcar" , .data = &rcar_pwm_info }, + { .compatible ="renesas,rcar-gen5-pwm" , .data = &rcar_gen5_pwm_info }, { } };MODULE_DEVICE_TABLE (of, rcar_pwm_of_table);
Signature · 1 line
2.43.0