Skip to content

Commit 1ce3e8a

Browse files
Demon000broonie
authored andcommitted
spi: rzv2h-rspi: add support for using PCLK for transfer clock
The Renesas RZ/T2H (R9A09G077) and RZ/N2H (R9A09G087) SoCs support generating the SPI transfer clock from PCLK, with the quirk that SPR 0 is not supported, causing the highest achievable SPI transfer frequency to be 31.25MHz. Add support for generating the SPI transfer clock from PCLK. Renesas RZ/V2H (R9A09G057) also has the BPEN bit used to enable this option in the datasheet, but it is not explicitly documented and there's no details about its limitations as there are on RZ/T2H. Signed-off-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com> Link: https://patch.msgid.link/20251119161434.595677-8-cosmin-gabriel.tanislav.xa@renesas.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 77d9315 commit 1ce3e8a

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

drivers/spi/spi-rzv2h-rspi.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@
3434
#define RSPI_SPFCR 0x6c
3535

3636
/* Register SPCR */
37+
#define RSPI_SPCR_BPEN BIT(31)
3738
#define RSPI_SPCR_MSTR BIT(30)
3839
#define RSPI_SPCR_SPRIE BIT(17)
3940
#define RSPI_SPCR_SCKASE BIT(12)
4041
#define RSPI_SPCR_SPE BIT(0)
4142

4243
/* Register SPBR */
4344
#define RSPI_SPBR_SPR_MIN 0
45+
#define RSPI_SPBR_SPR_PCLK_MIN 1
4446
#define RSPI_SPBR_SPR_MAX 255
4547

4648
/* Register SPCMD */
@@ -79,6 +81,8 @@ struct rzv2h_rspi_best_clock {
7981
struct rzv2h_rspi_info {
8082
void (*find_tclk_rate)(struct clk *clk, u32 hz, u8 spr_min, u8 spr_max,
8183
struct rzv2h_rspi_best_clock *best_clk);
84+
void (*find_pclk_rate)(struct clk *clk, u32 hz, u8 spr_low, u8 spr_high,
85+
struct rzv2h_rspi_best_clock *best_clk);
8286
const char *tclk_name;
8387
unsigned int fifo_size;
8488
unsigned int num_clks;
@@ -90,13 +94,15 @@ struct rzv2h_rspi_priv {
9094
const struct rzv2h_rspi_info *info;
9195
void __iomem *base;
9296
struct clk *tclk;
97+
struct clk *pclk;
9398
wait_queue_head_t wait;
9499
unsigned int bytes_per_word;
95100
u32 last_speed_hz;
96101
u32 freq;
97102
u16 status;
98103
u8 spr;
99104
u8 brdv;
105+
bool use_pclk;
100106
};
101107

102108
#define RZV2H_RSPI_TX(func, type) \
@@ -306,9 +312,18 @@ static u32 rzv2h_rspi_setup_clock(struct rzv2h_rspi_priv *rspi, u32 hz)
306312
rspi->info->find_tclk_rate(rspi->tclk, hz, RSPI_SPBR_SPR_MIN,
307313
RSPI_SPBR_SPR_MAX, &best_clock);
308314

315+
/*
316+
* T2H and N2H can also use PCLK as a source, which is 125MHz, but not
317+
* when both SPR and BRDV are 0.
318+
*/
319+
if (best_clock.error && rspi->info->find_pclk_rate)
320+
rspi->info->find_pclk_rate(rspi->pclk, hz, RSPI_SPBR_SPR_PCLK_MIN,
321+
RSPI_SPBR_SPR_MAX, &best_clock);
322+
309323
if (!best_clock.clk_rate)
310324
return -EINVAL;
311325

326+
rspi->use_pclk = best_clock.clk == rspi->pclk;
312327
rspi->spr = best_clock.spr;
313328
rspi->brdv = best_clock.brdv;
314329

@@ -361,6 +376,9 @@ static int rzv2h_rspi_prepare_message(struct spi_controller *ctlr,
361376
/* SPI receive buffer full interrupt enable */
362377
conf32 |= RSPI_SPCR_SPRIE;
363378

379+
/* Bypass synchronization circuit */
380+
conf32 |= FIELD_PREP(RSPI_SPCR_BPEN, rspi->use_pclk);
381+
364382
writel(conf32, rspi->base + RSPI_SPCR);
365383

366384
/* Use SPCMD0 only */
@@ -433,7 +451,9 @@ static int rzv2h_rspi_probe(struct platform_device *pdev)
433451
for (i = 0; i < rspi->info->num_clks; i++) {
434452
if (!strcmp(clks[i].id, rspi->info->tclk_name)) {
435453
rspi->tclk = clks[i].clk;
436-
break;
454+
} else if (rspi->info->find_pclk_rate &&
455+
!strcmp(clks[i].id, "pclk")) {
456+
rspi->pclk = clks[i].clk;
437457
}
438458
}
439459

0 commit comments

Comments
 (0)