Add RSPI support for RZ/G3E SoC
Subsystems (8)
cover Add RSPI support for RZ/G3E SoC
Dear All,
This patch series adds RSPI support for the Renesas RZ/G3E SoC, which features three RSPI controllers. The series also enables DMA support in the RSPI driver, and backports the necessary infrastructure changes into linux-6.12.y-cip.
The series is structured as follows:
- Clock entries for the three RSPI instances on RZ/G3E SoC
- DT binding updates: document DMA properties and add RZ/G3E compatible
- Device tree nodes for RZ/G3E RSPI controllers and SMARC board enablement
- Driver improvements backported from mainline: DMA support, device-managed APIs, bug fixes for clock setup and FIFO thresholds
Kind Regards,
Tommaso
Bence Csókás (1):
dmaengine: Add devm_dma_request_chan()
Biju Das (1):
spi: rzv2h-rspi: Add support for RZ/G3L (R9A08G046)
Cosmin Tanislav (12):
spi: dt-bindings: renesas,rzv2h-rspi: document optional support for
DMA
spi: dt-bindings: renesas,rzv2h-rspi: allow multiple DMAs
spi: rzv2h-rspi: fix rzv2h_rspi_transfer_one() indentation
spi: rzv2h-rspi: remove call to spi_finalize_current_transfer()
spi: rzv2h-rspi: do not set SPI_TRANS_FAIL_IO
spi: rzv2h-rspi: use device-managed APIs
spi: rzv2h-rspi: store RX interrupt in state
spi: rzv2h-rspi: set MUST_RX/MUST_TX
spi: rzv2h-rspi: set TX FIFO threshold to 0
spi: rzv2h-rspi: enable TX buffer empty interrupt
spi: rzv2h-rspi: split out PIO transfer
spi: rzv2h-rspi: add support for DMA mode
Dragan Simic (1):
driver core: Add device probe log helper dev_warn_probe()
John Madieu (1):
spi: rzv2h-rspi: Fix silent failure in clock setup error path
Lad Prabhakar (3):
spi: rzv2h-rspi: Fix max_speed_hz advertising prohibited bit rate
spi: rzv2h-rspi: Fix invalid SPR=0/BRDV=0 clock configuration
spi: rzv2h-rspi: Simplify clock rate search function signatures
Tommaso Merciai (5):
clk: renesas: r9a09g047: Add entries for the RSPIs
spi: dt-bindings: renesas,rzv2h-rspi: Document dmas property
spi: dt-bindings: renesas,rzv2h-rspi: Document RZ/G3E SoC support
arm64: dts: renesas: r9a09g047: Add RSPI nodes
arm64: dts: renesas: r9a09g047e57-smarc: Enable RSPI0
.../bindings/spi/renesas,rzv2h-rspi.yaml | 25 +- arch/arm64/boot/dts/renesas/r9a09g047.dtsi | 84 +++++ .../boot/dts/renesas/r9a09g047e57-smarc.dts | 16 + drivers/base/core.c | 129 +++++-- drivers/clk/renesas/r9a09g047-cpg.c | 24 ++ drivers/dma/dmaengine.c | 30 ++ drivers/spi/spi-rzv2h-rspi.c | 335 +++++++++++++----- include/linux/dev_printk.h | 1 + include/linux/dmaengine.h | 7 + 9 files changed, 535 insertions(+), 116 deletions(-)
Signature · 1 line
2.54.0
PATCH 1/24 dmaengine: Add devm_dma_request_chan()
From: Bence Csókás <[email protected]>
commit 08bf1663c21a3e815eda28fa242d84c945ca3b94 upstream.
Expand the arsenal of devm functions for DMA devices, this time for requesting channels.
--- drivers/dma/dmaengine.c | 30 ++++++++++++++++++++++++++++++ include/linux/dmaengine.h | 7 +++++++ 2 files changed, 37 insertions(+)
drivers/dma/dmaengine.c +30 -0
@@ -926,6 +926,36 @@ void dma_release_channel(struct dma_chan *chan) }EXPORT_SYMBOL_GPL (dma_release_channel); +static void dmaenginem_release_channel (void *chan) +{ +dma_release_channel (chan); +} + +/** +* devm_dma_request_chan - try to allocate an exclusive slave channel +* @dev: pointer to client device structure +* @name: slave channel name +* +* Returns pointer to appropriate DMA channel on success or an error pointer. +* +* The operation is managed and will be undone on driver detach. +*/ + +struct dma_chan *devm_dma_request_chan (struct device *dev,const char *name) +{ +struct dma_chan *chan =dma_request_chan (dev, name); +int ret =0 ; + +if (!IS_ERR (chan)) + ret =devm_add_action_or_reset (dev, dmaenginem_release_channel, chan); + +if (ret) +return ERR_PTR (ret); + +return chan; +} +EXPORT_SYMBOL_GPL (devm_dma_request_chan); +/** * dmaengine_get - register interest in dma_channels */
include/linux/dmaengine.h +7 -0
@@ -1521,6 +1521,7 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,struct dma_chan *dma_request_chan (struct device *dev,const char *name);struct dma_chan *dma_request_chan_by_mask (const dma_cap_mask_t *mask); +struct dma_chan *devm_dma_request_chan (struct device *dev,const char *name);void dma_release_channel (struct dma_chan *chan);int dma_get_slave_caps (struct dma_chan *chan,struct dma_slave_caps *caps);
@@ -1557,6 +1558,12 @@ static inline struct dma_chan *dma_request_chan_by_mask( {return ERR_PTR (-ENODEV ); } + +static inline struct dma_chan *devm_dma_request_chan (struct device *dev,const char *name) +{ +return ERR_PTR (-ENODEV ); +} +static inline void dma_release_channel (struct dma_chan *chan) { }
Signature · 1 line
2.54.0
PATCH 2/24 driver core: Add device probe log helper dev_warn_probe()
In reply to Tommaso MerciaiFrom: Dragan Simic <[email protected]>
commit 36e69b160705b65bf136c2fb6a1194447eeb8478 upstream.
Some drivers can still provide their functionality to a certain extent even when some of their resource acquisitions eventually fail. In such cases, emitting errors isn't the desired action, but warnings should be emitted instead.
To solve this, introduce dev_warn_probe() as a new device probe log helper, which behaves identically as the already existing dev_err_probe(), while it produces warnings instead of errors. The intended use is with the resources that are actually optional for a particular driver.
While there, copyedit the kerneldoc for dev_err_probe() a bit, to simplify its wording a bit, and reuse it as the kerneldoc for dev_warn_probe(), with the necessary wording adjustments, of course.
--- drivers/base/core.c | 129 +++++++++++++++++++++++++++++-------- include/linux/dev_printk.h | 1 + 2 files changed, 102 insertions(+), 28 deletions(-)
drivers/base/core.c +101 -28
@@ -5049,6 +5049,49 @@ define_dev_printk_level(_dev_info, KERN_INFO);#endif +static void __dev_probe_failed (const struct device *dev,int err,bool fatal, +const char *fmt,va_list vargsp) +{ +struct va_format vaf; +va_list vargs; + +/* +* On x86_64 and possibly on other architectures, va_list is actually a +* size-1 array containing a structure. As a result, function parameter +* vargsp decays from T[1] to T*, and &vargsp has type T** rather than +* T(*)[1], which is expected by its assignment to vaf.va below. +* +* One standard way to solve this mess is by creating a copy in a local +* variable of type va_list and then using a pointer to that local copy +* instead, which is the approach employed here. +*/ +va_copy (vargs, vargsp); + + vaf.fmt = fmt; + vaf.va = &vargs; + +switch (err) { +case -EPROBE_DEFER : +device_set_deferred_probe_reason (dev, &vaf); +dev_dbg (dev,"error %pe: %pV" ,ERR_PTR (err), &vaf); +break ; + +case -ENOMEM : +/* Don't print anything on -ENOMEM, there's already enough output */ +break ; + +default : +/* Log fatal final failures as errors, otherwise produce warnings */ +if (fatal) +dev_err (dev,"error %pe: %pV" ,ERR_PTR (err), &vaf); +else +dev_warn (dev,"error %pe: %pV" ,ERR_PTR (err), &vaf); +break ; + } + +va_end (vargs); +} +/** * dev_err_probe - probe error check and log helper * @dev: the pointer to the struct device
@@ -5061,7 +5104,7 @@ define_dev_printk_level(_dev_info, KERN_INFO);* -EPROBE_DEFER and propagate error upwards. * In case of -EPROBE_DEFER it sets also defer probe reason, which can be * checked later by reading devices_deferred debugfs attribute. -* It replaces code sequence:: +* It replaces the following code sequence:: * * if (err != -EPROBE_DEFER) * dev_err(dev, ...);
@@ -5073,47 +5116,77 @@ define_dev_printk_level(_dev_info, KERN_INFO);* * return dev_err_probe(dev, err, ...); * -* Using this helper in your probe function is totally fine even if @err is -* known to never be -EPROBE_DEFER. +* Using this helper in your probe function is totally fine even if @err +* is known to never be -EPROBE_DEFER. * The benefit compared to a normal dev_err() is the standardized format -* of the error code, it being emitted symbolically (i.e. you get "EAGAIN" -* instead of "-35") and the fact that the error code is returned which allows -* more compact error paths. +* of the error code, which is emitted symbolically (i.e. you get "EAGAIN" +* instead of "-35"), and having the error code returned allows more +* compact error paths. * * Returns @err. */ int dev_err_probe (const struct device *dev,int err,const char *fmt, ...) { -struct va_format vaf; -va_list args; +va_list vargs; -va_start (args, fmt); - vaf.fmt = fmt; - vaf.va = &args; +va_start (vargs, fmt); -switch (err) { -case -EPROBE_DEFER : -device_set_deferred_probe_reason (dev, &vaf); -dev_dbg (dev,"error %pe: %pV" ,ERR_PTR (err), &vaf); -break ; +/* Use dev_err() for logging when err doesn't equal -EPROBE_DEFER */ +__dev_probe_failed (dev, err, true, fmt, vargs); -case -ENOMEM : -/* -* We don't print anything on -ENOMEM, there is already enough -* output. -*/ -break ; +va_end (vargs); -default : -dev_err (dev,"error %pe: %pV" ,ERR_PTR (err), &vaf); -break ; - } +return err; +} +EXPORT_SYMBOL_GPL (dev_err_probe); -va_end (args); +/** +* dev_warn_probe - probe error check and log helper +* @dev: the pointer to the struct device +* @err: error value to test +* @fmt: printf-style format string +* @...: arguments as specified in the format string +* +* This helper implements common pattern present in probe functions for error +* checking: print debug or warning message depending if the error value is +* -EPROBE_DEFER and propagate error upwards. +* In case of -EPROBE_DEFER it sets also defer probe reason, which can be +* checked later by reading devices_deferred debugfs attribute. +* It replaces the following code sequence:: +* +* if (err != -EPROBE_DEFER) +* dev_warn(dev, ...); +* else +* dev_dbg(dev, ...); +* return err; +* +* with:: +* +* return dev_warn_probe(dev, err, ...); +* +* Using this helper in your probe function is totally fine even if @err +* is known to never be -EPROBE_DEFER. +* The benefit compared to a normal dev_warn() is the standardized format +* of the error code, which is emitted symbolically (i.e. you get "EAGAIN" +* instead of "-35"), and having the error code returned allows more +* compact error paths. +* +* Returns @err. +*/ +int dev_warn_probe (const struct device *dev,int err,const char *fmt, ...) +{ +va_list vargs; + +va_start (vargs, fmt); + +/* Use dev_warn() for logging when err doesn't equal -EPROBE_DEFER */ +__dev_probe_failed (dev, err, false, fmt, vargs); + +va_end (vargs);return err; } -EXPORT_SYMBOL_GPL (dev_err_probe); +EXPORT_SYMBOL_GPL (dev_warn_probe);static inline bool fwnode_is_primary (struct fwnode_handle *fwnode) {
include/linux/dev_printk.h +1 -0
@@ -276,6 +276,7 @@ do { \ dev_driver_string(dev), dev_name(dev), ## arg) __printf(3, 4) int dev_err_probe(const struct device *dev, int err, const char *fmt, ...); +__printf(3, 4) int dev_warn_probe(const struct device *dev, int err, const char *fmt, ...);/* Simple helper for dev_err_probe() when ERR_PTR() is to be returned. */ #define dev_err_ptr_probe (dev, ___err, fmt, ...) \
Signature · 1 line
2.54.0
PATCH 3/24 clk: renesas: r9a09g047: Add entries for the RSPIs
In reply to Tommaso Merciaicommit 24a51f8bf869053de4927e0798d17dbcda9ea3cf upstream.
Add clock and reset entries for the Renesas RZ/G3E RSPI IPs.
--- drivers/clk/renesas/r9a09g047-cpg.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/clk/renesas/r9a09g047-cpg.c +24 -0
@@ -218,6 +218,24 @@ static const struct rzv2h_mod_clk r9a09g047_mod_clks[] __initconst = { BUS_MSTOP(5, BIT(13))),DEF_MOD ("wdt_3_clk_loco" ,CLK_QEXTAL ,5 ,2 ,2 ,18 ,BUS_MSTOP (5 ,BIT (13 ))), +DEF_MOD ("rspi_0_pclk" ,CLK_PLLCLN_DIV8 ,5 ,4 ,2 ,20 , +BUS_MSTOP (11 ,BIT (0 ))), +DEF_MOD ("rspi_0_pclk_sfr" ,CLK_PLLCLN_DIV8 ,5 ,5 ,2 ,21 , +BUS_MSTOP (11 ,BIT (0 ))), +DEF_MOD ("rspi_0_tclk" ,CLK_PLLCLN_DIV8 ,5 ,6 ,2 ,22 , +BUS_MSTOP (11 ,BIT (0 ))), +DEF_MOD ("rspi_1_pclk" ,CLK_PLLCLN_DIV8 ,5 ,7 ,2 ,23 , +BUS_MSTOP (11 ,BIT (1 ))), +DEF_MOD ("rspi_1_pclk_sfr" ,CLK_PLLCLN_DIV8 ,5 ,8 ,2 ,24 , +BUS_MSTOP (11 ,BIT (1 ))), +DEF_MOD ("rspi_1_tclk" ,CLK_PLLCLN_DIV8 ,5 ,9 ,2 ,25 , +BUS_MSTOP (11 ,BIT (1 ))), +DEF_MOD ("rspi_2_pclk" ,CLK_PLLCLN_DIV8 ,5 ,10 ,2 ,26 , +BUS_MSTOP (11 ,BIT (2 ))), +DEF_MOD ("rspi_2_pclk_sfr" ,CLK_PLLCLN_DIV8 ,5 ,11 ,2 ,27 , +BUS_MSTOP (11 ,BIT (2 ))), +DEF_MOD ("rspi_2_tclk" ,CLK_PLLCLN_DIV8 ,5 ,12 ,2 ,28 , +BUS_MSTOP (11 ,BIT (2 ))),DEF_MOD ("rsci0_pclk" ,CLK_PLLCLN_DIV16 ,5 ,13 ,2 ,29 ,BUS_MSTOP (11 ,BIT (3 ))), DEF_MOD("rsci0_tclk", CLK_PLLCLN_DIV16, 5, 14, 2, 30,
@@ -441,6 +459,12 @@ static const struct rzv2h_reset r9a09g047_resets[] __initconst = {DEF_RST (7 ,6 ,3 ,7 ),/* WDT_1_RESET */ DEF_RST (7 ,7 ,3 ,8 ),/* WDT_2_RESET */ DEF_RST (7 ,8 ,3 ,9 ),/* WDT_3_RESET */ +DEF_RST (7 ,11 ,3 ,12 ),/* RSPI_0_PRESETN */ +DEF_RST (7 ,12 ,3 ,13 ),/* RSPI_0_TRESETN */ +DEF_RST (7 ,13 ,3 ,14 ),/* RSPI_1_PRESETN */ +DEF_RST (7 ,14 ,3 ,15 ),/* RSPI_1_TRESETN */ +DEF_RST (7 ,15 ,3 ,16 ),/* RSPI_2_PRESETN */ +DEF_RST (8 ,0 ,3 ,17 ),/* RSPI_2_TRESETN */ DEF_RST (8 ,1 ,3 ,18 ),/* RSCI0_PRESETN */ DEF_RST (8 ,2 ,3 ,19 ),/* RSCI0_TRESETN */ DEF_RST(8, 3, 3, 20), /* RSCI1_PRESETN */
Signature · 1 line
2.54.0
PATCH 4/24 spi: dt-bindings: renesas,rzv2h-rspi: document optional support for DMA
In reply to Tommaso MerciaiFrom: Cosmin Tanislav <[email protected]>
commit 163345e356722e98ba57cd120787d6e991da7b1d upstream.
The IP supports using DMA for reading and writing data from the FIFO, document it.
--- .../devicetree/bindings/spi/renesas,rzv2h-rspi.yaml | 8 ++++++++ 1 file changed, 8 insertions(+)
Documentation/devicetree/bindings/spi/renesas,rzv2h-rspi.yaml +8 -0
@@ -57,6 +57,14 @@ properties: - const: presetn - const: tresetn + dmas: + maxItems: 2 + + dma-names: + items: + - const: rx + - const: tx + power-domains: maxItems: 1
Signature · 1 line
2.54.0
PATCH 5/24 spi: dt-bindings: renesas,rzv2h-rspi: allow multiple DMAs
In reply to Tommaso MerciaiFrom: Cosmin Tanislav <[email protected]>
commit 4d28f38f64ef69ab27839069ef3346c3c878d137 upstream.
All supported SoCs have multiple DMA controllers that can be used with the RSPI peripheral. The current bindings only allow a single pair of RX and TX DMAs.
The DMA core allows specifying multiple DMAs with the same name, and it will pick the first available one.
There is an exception in the base dt-schema rules specifically for allowing this behavior (dtschema/schemas/dma/dma.yaml).
dma-names:
anyOf:
- uniqueItems: true
- items:
# Hack around Renesas bindings which repeat entries to support # multiple possible DMA providers
enum: [rx, tx]
Allow multiple DMAs to have the same name and only restrict the possible names of the DMA channels, not their count.
For RZ/T2H and RZ/N2H SoCs, limit the number of DMA channels to 6, as they have 3 DMA controllers.
For RZ/V2H and RZ/V2N SoCs, limit the number of DMA channels to 10, as they have 5 DMA controllers.
--- .../bindings/spi/renesas,rzv2h-rspi.yaml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/spi/renesas,rzv2h-rspi.yaml +13 -3
@@ -58,12 +58,16 @@ properties: - const: tresetn dmas: - maxItems: 2 + minItems: 2 + maxItems: 10 dma-names: + minItems: 2 + maxItems: 10 items: - - const: rx - - const: tx + enum: + - rx + - tx power-domains: maxItems: 1
@@ -121,6 +125,12 @@ allOf: resets: false reset-names: false + dmas: + maxItems: 6 + + dma-names: + maxItems: 6 + unevaluatedProperties: false examples:
Signature · 1 line
2.54.0
PATCH 6/24 spi: dt-bindings: renesas,rzv2h-rspi: Document dmas property
In reply to Tommaso Merciaicommit c2edd7841f58cf228347b91256f0d9efcc1a1f50 upstream.
Document the dmas property to state it must be specified as TX/RX DMA specifier pairs.
This clarifies the expected ordering and improves binding readability without changing behavior.
--- Documentation/devicetree/bindings/spi/renesas,rzv2h-rspi.yaml | 3 +++ 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/spi/renesas,rzv2h-rspi.yaml +3 -0
@@ -60,6 +60,9 @@ properties: dmas: minItems: 2 maxItems: 10 + description: + Must contain a list of pairs of references to DMA specifiers, one for + transmission, and one for reception. dma-names: minItems: 2
Signature · 1 line
2.54.0
PATCH 7/24 spi: dt-bindings: renesas,rzv2h-rspi: Document RZ/G3E SoC support
In reply to Tommaso Merciaicommit 5b7ac8ca0eae522735d24f7c5c2296c8094328b1 upstream.
Document the RSPI controller on the Renesas RZ/G3E SoC. The block is compatible with the RSPI implementation found on the RZ/V2H(P) family.
--- Documentation/devicetree/bindings/spi/renesas,rzv2h-rspi.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/spi/renesas,rzv2h-rspi.yaml +3 -1
@@ -16,7 +16,9 @@ properties: - renesas,r9a09g057-rspi # RZ/V2H(P) - renesas,r9a09g077-rspi # RZ/T2H - items: - - const: renesas,r9a09g056-rspi # RZ/V2N + - enum: + - renesas,r9a09g047-rspi # RZ/G3E + - renesas,r9a09g056-rspi # RZ/V2N - const: renesas,r9a09g057-rspi - items: - const: renesas,r9a09g087-rspi # RZ/N2H
Signature · 1 line
2.54.0
PATCH 8/24 spi: rzv2h-rspi: fix rzv2h_rspi_transfer_one() indentation
In reply to Tommaso MerciaiFrom: Cosmin Tanislav <[email protected]>
commit fb0140774aff45b8dc326987cc1da89484ecb081 upstream.
Add the missing space to align to open pararenthesis.
--- drivers/spi/spi-rzv2h-rspi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/spi/spi-rzv2h-rspi.c +2 -2
@@ -225,8 +225,8 @@ static int rzv2h_rspi_receive(struct rzv2h_rspi_priv *rspi, void *rxbuf, }static int rzv2h_rspi_transfer_one (struct spi_controller *controller, -struct spi_device *spi, -struct spi_transfer *transfer) +struct spi_device *spi, +struct spi_transfer *transfer) {struct rzv2h_rspi_priv *rspi =spi_controller_get_devdata (controller);unsigned int words_to_transfer, i;
Signature · 1 line
2.54.0
PATCH 9/24 spi: rzv2h-rspi: remove call to spi_finalize_current_transfer()
In reply to Tommaso MerciaiFrom: Cosmin Tanislav <[email protected]>
commit 9e4830b35dc0d522f45e1ec3ee5b1ff1648afe1b upstream.
A call to spi_finalize_current_transfer() is only needed when the SPI transfer is completed outside of the current context, when the .transfer_one() implementation returns > 0.
Since the SPI transfer is completed in the current context, and we return 0 from .transfer_one(), the SPI core assumes that the transfer has completed and it does not wait for the completion variable that would be set by a call to spi_finalize_current_transfer().
Remove the call to spi_finalize_current_transfer().
--- drivers/spi/spi-rzv2h-rspi.c | 2 -- 1 file changed, 2 deletions(-)
drivers/spi/spi-rzv2h-rspi.c +0 -2
@@ -250,8 +250,6 @@ static int rzv2h_rspi_transfer_one(struct spi_controller *controller,if (ret) transfer->error =SPI_TRANS_FAIL_IO ; -spi_finalize_current_transfer (controller); -return ret; }
Signature · 1 line
2.54.0
PATCH 10/24 spi: rzv2h-rspi: do not set SPI_TRANS_FAIL_IO
In reply to Tommaso MerciaiFrom: Cosmin Tanislav <[email protected]>
commit 218917659df165cff72439480929e68a6e127b55 upstream.
Setting SPI_TRANS_FAIL_IO has no effect if the transfer completes in the current context, as it is only handled when .transfer_one() returns > 0, when the SPI core must wait for the SPI transfer to complete.
Do not set SPI_TRANS_FAIL_IO as we either return an error or 0, since we do our own waiting.
--- drivers/spi/spi-rzv2h-rspi.c | 3 --- 1 file changed, 3 deletions(-)
drivers/spi/spi-rzv2h-rspi.c +0 -3
@@ -247,9 +247,6 @@ static int rzv2h_rspi_transfer_one(struct spi_controller *controller,rzv2h_rspi_clear_all_irqs (rspi); -if (ret) - transfer->error =SPI_TRANS_FAIL_IO ; -return ret; }
Signature · 1 line
2.54.0
PATCH 11/24 spi: rzv2h-rspi: use device-managed APIs
In reply to Tommaso MerciaiFrom: Cosmin Tanislav <[email protected]>
commit b73ac782828f27c2217a17bd26aa8710769f032d upstream.
Non-device-managed APIs were initially used here to avoid the buggy interaction between PM domains and device-managed actions.
Commit f99508074e78 ("PM: domains: Detach on device_unbind_cleanup()") fixed the interaction between PM domains and device-managed actions.
Simplify the code by using device-managed actions to unregister the SPI controller and to assert and release the resets.
--- drivers/spi/spi-rzv2h-rspi.c | 58 ++++++++++++------------------------ 1 file changed, 19 insertions(+), 39 deletions(-)
drivers/spi/spi-rzv2h-rspi.c +19 -39
@@ -93,7 +93,6 @@ struct rzv2h_rspi_info { };struct rzv2h_rspi_priv { -struct reset_control_bulk_data resets[RSPI_RESET_NUM ];struct spi_controller *controller;const struct rzv2h_rspi_info *info;void __iomem *base;
@@ -533,6 +532,7 @@ static int rzv2h_rspi_probe(struct platform_device *pdev)struct spi_controller *controller;struct device *dev = &pdev->dev;struct rzv2h_rspi_priv *rspi; +struct reset_control *reset;struct clk_bulk_data *clks;int irq_rx, ret, i;long tclk_rate;
@@ -568,28 +568,29 @@ static int rzv2h_rspi_probe(struct platform_device *pdev)if (!rspi->tclk)return dev_err_probe (dev, -EINVAL ,"Failed to get tclk\n" ); - rspi->resets[0 ].id ="presetn" ; - rspi->resets[1 ].id ="tresetn" ; - ret =devm_reset_control_bulk_get_optional_exclusive (dev,RSPI_RESET_NUM , - rspi->resets); -if (ret) -return dev_err_probe (dev, ret,"cannot get resets\n" ); + reset =devm_reset_control_get_optional_exclusive_deasserted (&pdev->dev, +"presetn" ); +if (IS_ERR (reset)) +return dev_err_probe (&pdev->dev,PTR_ERR (reset), +"cannot get presetn reset\n" ); + + reset =devm_reset_control_get_optional_exclusive_deasserted (&pdev->dev, +"tresetn" ); +if (IS_ERR (reset)) +return dev_err_probe (&pdev->dev,PTR_ERR (reset), +"cannot get tresetn reset\n" ); irq_rx =platform_get_irq_byname (pdev,"rx" );if (irq_rx <0 )return dev_err_probe (dev, irq_rx,"cannot get IRQ 'rx'\n" ); - ret =reset_control_bulk_deassert (RSPI_RESET_NUM , rspi->resets); -if (ret) -return dev_err_probe (dev, ret,"failed to deassert resets\n" ); -init_waitqueue_head (&rspi->wait); ret =devm_request_irq (dev, irq_rx, rzv2h_rx_irq_handler,0 ,dev_name (dev), rspi);if (ret) {dev_err (dev,"cannot request `rx` IRQ\n" ); - goto quit_resets; +return ret; } controller->mode_bits = SPI_CPHA | SPI_CPOL | SPI_CS_HIGH |
@@ -601,20 +602,16 @@ static int rzv2h_rspi_probe(struct platform_device *pdev) controller->transfer_one = rzv2h_rspi_transfer_one; tclk_rate =clk_round_rate (rspi->tclk,0 ); -if (tclk_rate <0 ) { - ret = tclk_rate; - goto quit_resets; - } +if (tclk_rate <0 ) +return tclk_rate; controller->min_speed_hz =rzv2h_rspi_calc_bitrate (tclk_rate,RSPI_SPBR_SPR_MAX ,RSPI_SPCMD_BRDV_MAX ); tclk_rate =clk_round_rate (rspi->tclk,ULONG_MAX ); -if (tclk_rate <0 ) { - ret = tclk_rate; - goto quit_resets; - } +if (tclk_rate <0 ) +return tclk_rate; controller->max_speed_hz = rzv2h_rspi_calc_bitrate(tclk_rate, RSPI_SPBR_SPR_MIN,
@@ -622,29 +619,13 @@ static int rzv2h_rspi_probe(struct platform_device *pdev)device_set_node (&controller->dev,dev_fwnode (dev)); - ret =spi_register_controller (controller); -if (ret) { + ret =devm_spi_register_controller (dev, controller); +if (ret)dev_err (dev,"register controller failed\n" ); - goto quit_resets; - } - -return 0 ; - -quit_resets: -reset_control_bulk_assert (RSPI_RESET_NUM , rspi->resets);return ret; } -static void rzv2h_rspi_remove (struct platform_device *pdev) -{ -struct rzv2h_rspi_priv *rspi =platform_get_drvdata (pdev); - -spi_unregister_controller (rspi->controller); - -reset_control_bulk_assert (RSPI_RESET_NUM , rspi->resets); -} -static const struct rzv2h_rspi_info rzv2h_info = { .find_tclk_rate = rzv2h_rspi_find_rate_fixed, .tclk_name ="tclk" ,
@@ -669,7 +650,6 @@ MODULE_DEVICE_TABLE(of, rzv2h_rspi_match);static struct platform_driver rzv2h_rspi_drv = { .probe = rzv2h_rspi_probe, - .remove = rzv2h_rspi_remove, .driver = { .name ="rzv2h_rspi" , .of_match_table = rzv2h_rspi_match,
Signature · 1 line
2.54.0
PATCH 12/24 spi: rzv2h-rspi: store RX interrupt in state
In reply to Tommaso MerciaiFrom: Cosmin Tanislav <[email protected]>
commit 28b590bd4c6a051ec61cf286a46a8b14846e6fcf upstream.
In preparation for implementing DMA support, store the RX interrupt number in the private state, to allow disabling it during DMA.
--- drivers/spi/spi-rzv2h-rspi.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/spi/spi-rzv2h-rspi.c +6 -5
@@ -100,6 +100,7 @@ struct rzv2h_rspi_priv {struct clk *pclk;wait_queue_head_t wait;unsigned int bytes_per_word; +int irq_rx;u32 last_speed_hz;u32 freq;u16 status;
@@ -534,8 +535,8 @@ static int rzv2h_rspi_probe(struct platform_device *pdev)struct rzv2h_rspi_priv *rspi;struct reset_control *reset;struct clk_bulk_data *clks; -int irq_rx, ret, i;long tclk_rate; +int ret, i; controller =devm_spi_alloc_host (dev,sizeof (*rspi));if (!controller)
@@ -580,13 +581,13 @@ static int rzv2h_rspi_probe(struct platform_device *pdev)return dev_err_probe (&pdev->dev,PTR_ERR (reset),"cannot get tresetn reset\n" ); - irq_rx =platform_get_irq_byname (pdev,"rx" ); -if (irq_rx <0 ) -return dev_err_probe (dev, irq_rx,"cannot get IRQ 'rx'\n" ); + rspi->irq_rx =platform_get_irq_byname (pdev,"rx" ); +if (rspi->irq_rx <0 ) +return dev_err_probe (dev, rspi->irq_rx,"cannot get IRQ 'rx'\n" );init_waitqueue_head (&rspi->wait); - ret =devm_request_irq (dev, irq_rx, rzv2h_rx_irq_handler,0 , + ret =devm_request_irq (dev, rspi->irq_rx, rzv2h_rx_irq_handler,0 ,dev_name (dev), rspi);if (ret) {dev_err (dev,"cannot request `rx` IRQ\n" );
Signature · 1 line
2.54.0
PATCH 13/24 spi: rzv2h-rspi: set MUST_RX/MUST_TX
In reply to Tommaso MerciaiFrom: Cosmin Tanislav <[email protected]>
commit 6f9026b5a18acdf190d1622831b100aacfca0eb3 upstream.
In preparation for implementing DMA support, set MUST_RX and MUST_TX flags on the controller so that we always receive non-NULL buffers.
The PIO mode already handles this manually by checking if rx_buf/tx_buf are set on the transfer, and doing a dummy read/write if not.
DMA will not be able to implement this special handling, and although the SPI controller advertises support for transmit-only or receive-only transfers via SPCR's register TXMD bitfield, it does not seem to work.
Remove the special handling for PIO and let the SPI controller core handle it.
--- drivers/spi/spi-rzv2h-rspi.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/spi/spi-rzv2h-rspi.c +3 -8
@@ -113,11 +113,7 @@ struct rzv2h_rspi_priv { static inline void rzv2h_rspi_tx_##type(struct rzv2h_rspi_priv *rspi, \ const void *txbuf, \ unsigned int index) { \ - type buf = 0; \ - \ - if (txbuf) \ - buf = ((type *)txbuf)[index]; \ - \ + type buf = ((type *)txbuf)[index]; \ func(buf, rspi->base + RSPI_SPDR); \ }
@@ -126,9 +122,7 @@ static inline void rzv2h_rspi_rx_##type(struct rzv2h_rspi_priv *rspi, \ void *rxbuf, \ unsigned int index) { \type buf =func (rspi->base +RSPI_SPDR ); \ - \ -if (rxbuf) \ - ((type *)rxbuf)[index] = buf; \ + ((type *)rxbuf)[index] = buf; \ }RZV2H_RSPI_TX (writel, u32)
@@ -596,6 +590,7 @@ static int rzv2h_rspi_probe(struct platform_device *pdev) controller->mode_bits =SPI_CPHA |SPI_CPOL |SPI_CS_HIGH |SPI_LSB_FIRST |SPI_LOOP ; + controller->flags =SPI_CONTROLLER_MUST_RX |SPI_CONTROLLER_MUST_TX ; controller->bits_per_word_mask =SPI_BPW_RANGE_MASK (4 ,32 ); controller->prepare_message = rzv2h_rspi_prepare_message; controller->unprepare_message = rzv2h_rspi_unprepare_message;
Signature · 1 line
2.54.0
PATCH 14/24 spi: rzv2h-rspi: set TX FIFO threshold to 0
In reply to Tommaso MerciaiFrom: Cosmin Tanislav <[email protected]>
commit a886baaaa6e12a9b7d5a9687d11d3b895f1b87c9 upstream.
In PIO mode we send data word-by-word, and wait for the received data to be available after each sent word, making no use of the TX interrupt.
In DMA mode, we need to set the RX and TX FIFO thresholds to 0, as described in the User Manual.
In preparation for implementing DMA support, set TX FIFO threshold to 0, as RX FIFO threshold is already 0.
--- drivers/spi/spi-rzv2h-rspi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-rzv2h-rspi.c +1 -1
@@ -501,7 +501,7 @@ static int rzv2h_rspi_prepare_message(struct spi_controller *ctlr,writeb (0 , rspi->base +RSPI_SSLP );/* Setup FIFO thresholds */ - conf16 =FIELD_PREP (RSPI_SPDCR2_TTRG , rspi->info->fifo_size -1 ); + conf16 =FIELD_PREP (RSPI_SPDCR2_TTRG ,0 ); conf16 |=FIELD_PREP (RSPI_SPDCR2_RTRG ,0 );writew (conf16, rspi->base +RSPI_SPDCR2 );
Signature · 1 line
2.54.0
PATCH 15/24 spi: rzv2h-rspi: enable TX buffer empty interrupt
In reply to Tommaso MerciaiFrom: Cosmin Tanislav <[email protected]>
commit d49eea07de5851e1b8941ad6b6179be7ec36a986 upstream.
In preparation for implementing DMA support, enable the transmit buffer empty interrupt, which is necessary for DMA to write more data to the FIFO.
This does not affect the PIO mode as we do not even request the TX interrupt line.
--- drivers/spi/spi-rzv2h-rspi.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/spi/spi-rzv2h-rspi.c +4 -0
@@ -37,6 +37,7 @@/* Register SPCR */ #define RSPI_SPCR_BPEN BIT(31)#define RSPI_SPCR_MSTR BIT(30) +#define RSPI_SPCR_SPTIE BIT(20)#define RSPI_SPCR_SPRIE BIT(17)#define RSPI_SPCR_SCKASE BIT(12)#define RSPI_SPCR_SPE BIT(0)
@@ -474,6 +475,9 @@ static int rzv2h_rspi_prepare_message(struct spi_controller *ctlr,/* SPI receive buffer full interrupt enable */ conf32 |=RSPI_SPCR_SPRIE ; +/* SPI transmit buffer empty interrupt enable */ + conf32 |=RSPI_SPCR_SPTIE ; +/* Bypass synchronization circuit */ conf32 |=FIELD_PREP (RSPI_SPCR_BPEN , rspi->use_pclk);
Signature · 1 line
2.54.0
PATCH 16/24 spi: rzv2h-rspi: split out PIO transfer
In reply to Tommaso MerciaiFrom: Cosmin Tanislav <[email protected]>
commit 1e5e10df8b9be71ca64435cbe7c96b189e5ee293 upstream.
In preparation for implementing DMA support, split out the PIO transfer code into its own function.
--- drivers/spi/spi-rzv2h-rspi.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)
drivers/spi/spi-rzv2h-rspi.c +20 -7
@@ -219,17 +219,14 @@ static int rzv2h_rspi_receive(struct rzv2h_rspi_priv *rspi, void *rxbuf,return 0 ; } -static int rzv2h_rspi_transfer_one (struct spi_controller *controller, +static int rzv2h_rspi_transfer_pio (struct rzv2h_rspi_priv *rspi,struct spi_device *spi, -struct spi_transfer *transfer) +struct spi_transfer *transfer, +unsigned int words_to_transfer) { -struct rzv2h_rspi_priv *rspi =spi_controller_get_devdata (controller); -unsigned int words_to_transfer, i; +unsigned int i;int ret =0 ; - transfer->effective_speed_hz = rspi->freq; - words_to_transfer = transfer->len / rspi->bytes_per_word; -for (i =0 ; i < words_to_transfer; i++) {rzv2h_rspi_clear_all_irqs (rspi);
@@ -240,6 +237,22 @@ static int rzv2h_rspi_transfer_one(struct spi_controller *controller,break ; } +return ret; +} + +static int rzv2h_rspi_transfer_one (struct spi_controller *controller, +struct spi_device *spi, +struct spi_transfer *transfer) +{ +struct rzv2h_rspi_priv *rspi =spi_controller_get_devdata (controller); +unsigned int words_to_transfer; +int ret; + + transfer->effective_speed_hz = rspi->freq; + words_to_transfer = transfer->len / rspi->bytes_per_word; + + ret =rzv2h_rspi_transfer_pio (rspi, spi, transfer, words_to_transfer); +rzv2h_rspi_clear_all_irqs (rspi);return ret;
Signature · 1 line
2.54.0
PATCH 17/24 spi: rzv2h-rspi: add support for DMA mode
In reply to Tommaso MerciaiFrom: Cosmin Tanislav <[email protected]>
commit fa08b566860bca8ebf9300090b85174c34de7ca5 upstream.
The DMA controller can be used to transfer data to and from the SPI controller without involving the CPU for each word of a SPI transfer.
Add support for DMA mode.
--- drivers/spi/spi-rzv2h-rspi.c | 169 ++++++++++++++++++++++++++++++++++- 1 file changed, 168 insertions(+), 1 deletion(-)
drivers/spi/spi-rzv2h-rspi.c +168 -1
@@ -9,6 +9,7 @@#include <linux/bitops.h> #include <linux/bits.h> #include <linux/clk.h> +#include <linux/dmaengine.h> #include <linux/interrupt.h> #include <linux/io.h> #include <linux/limits.h>
@@ -21,6 +22,8 @@#include <linux/spi/spi.h> #include <linux/wait.h> +#include "internals.h" +/* Registers */ #define RSPI_SPDR 0x00#define RSPI_SPCR 0x08
@@ -96,6 +99,7 @@ struct rzv2h_rspi_info {struct rzv2h_rspi_priv {struct spi_controller *controller;const struct rzv2h_rspi_info *info; +struct platform_device *pdev;void __iomem *base;struct clk *tclk;struct clk *pclk;
@@ -108,6 +112,7 @@ struct rzv2h_rspi_priv {u8 spr;u8 brdv;bool use_pclk; +bool dma_callbacked; };#define RZV2H_RSPI_TX (func, type) \
@@ -219,6 +224,20 @@ static int rzv2h_rspi_receive(struct rzv2h_rspi_priv *rspi, void *rxbuf,return 0 ; } +static bool rzv2h_rspi_can_dma (struct spi_controller *ctlr,struct spi_device *spi, +struct spi_transfer *xfer) +{ +struct rzv2h_rspi_priv *rspi =spi_controller_get_devdata (ctlr); + +if (ctlr->fallback) +return false; + +if (!ctlr->dma_tx || !ctlr->dma_rx) +return false; + +return xfer->len > rspi->info->fifo_size; +} + static int rzv2h_rspi_transfer_pio(struct rzv2h_rspi_priv *rspi, struct spi_device *spi, struct spi_transfer *transfer,
@@ -240,21 +259,149 @@ static int rzv2h_rspi_transfer_pio(struct rzv2h_rspi_priv *rspi,return ret; } +static void rzv2h_rspi_dma_complete (void *arg) +{ +struct rzv2h_rspi_priv *rspi = arg; + + rspi->dma_callbacked =1 ; +wake_up_interruptible (&rspi->wait); +} + +static struct dma_async_tx_descriptor * +rzv2h_rspi_setup_dma_channel (struct rzv2h_rspi_priv *rspi, +struct dma_chan *chan,struct sg_table *sg, +enum dma_slave_buswidth width, +enum dma_transfer_direction direction) +{ +struct dma_slave_config config = { + .dst_addr = rspi->pdev->resource->start +RSPI_SPDR , + .src_addr = rspi->pdev->resource->start +RSPI_SPDR , + .dst_addr_width = width, + .src_addr_width = width, + .direction = direction, + }; +struct dma_async_tx_descriptor *desc; +int ret; + + ret =dmaengine_slave_config (chan, &config); +if (ret) +return ERR_PTR (ret); + + desc =dmaengine_prep_slave_sg (chan, sg->sgl, sg->nents, direction, +DMA_PREP_INTERRUPT |DMA_CTRL_ACK ); +if (!desc) +return ERR_PTR (-EAGAIN ); + +if (direction ==DMA_DEV_TO_MEM ) { + desc->callback = rzv2h_rspi_dma_complete; + desc->callback_param = rspi; + } + +return desc; +} + +static enum dma_slave_buswidth +rzv2h_rspi_dma_width (struct rzv2h_rspi_priv *rspi) +{ +switch (rspi->bytes_per_word) { +case 4 : +return DMA_SLAVE_BUSWIDTH_4_BYTES ; +case 2 : +return DMA_SLAVE_BUSWIDTH_2_BYTES ; +case 1 : +return DMA_SLAVE_BUSWIDTH_1_BYTE ; +default : +return DMA_SLAVE_BUSWIDTH_UNDEFINED ; + } +} + +static int rzv2h_rspi_transfer_dma (struct rzv2h_rspi_priv *rspi, +struct spi_device *spi, +struct spi_transfer *transfer, +unsigned int words_to_transfer) +{ +struct dma_async_tx_descriptor *tx_desc =NULL , *rx_desc =NULL ; +enum dma_slave_buswidth width; +dma_cookie_t cookie; +int ret; + + width =rzv2h_rspi_dma_width (rspi); +if (width ==DMA_SLAVE_BUSWIDTH_UNDEFINED ) +return -EINVAL ; + + rx_desc =rzv2h_rspi_setup_dma_channel (rspi, rspi->controller->dma_rx, + &transfer->rx_sg, width, +DMA_DEV_TO_MEM ); +if (IS_ERR (rx_desc)) +return PTR_ERR (rx_desc); + + tx_desc =rzv2h_rspi_setup_dma_channel (rspi, rspi->controller->dma_tx, + &transfer->tx_sg, width, +DMA_MEM_TO_DEV ); +if (IS_ERR (tx_desc)) +return PTR_ERR (tx_desc); + + cookie =dmaengine_submit (rx_desc); +if (dma_submit_error (cookie)) +return cookie; + + cookie =dmaengine_submit (tx_desc); +if (dma_submit_error (cookie)) { +dmaengine_terminate_sync (rspi->controller->dma_rx); +return cookie; + } + +/* +* DMA transfer does not need IRQs to be enabled. +* For PIO, we only use RX IRQ, so disable that. +*/ +disable_irq (rspi->irq_rx); + + rspi->dma_callbacked =0 ; + +dma_async_issue_pending (rspi->controller->dma_rx); +dma_async_issue_pending (rspi->controller->dma_tx); +rzv2h_rspi_clear_all_irqs (rspi); + + ret =wait_event_interruptible_timeout (rspi->wait, rspi->dma_callbacked,HZ ); +if (ret) { +dmaengine_synchronize (rspi->controller->dma_tx); +dmaengine_synchronize (rspi->controller->dma_rx); + ret =0 ; + }else { +dmaengine_terminate_sync (rspi->controller->dma_tx); +dmaengine_terminate_sync (rspi->controller->dma_rx); + ret = -ETIMEDOUT ; + } + +enable_irq (rspi->irq_rx); + +return ret; +} +static int rzv2h_rspi_transfer_one (struct spi_controller *controller,struct spi_device *spi,struct spi_transfer *transfer) {struct rzv2h_rspi_priv *rspi =spi_controller_get_devdata (controller); +bool is_dma =spi_xfer_is_dma_mapped (controller, spi, transfer);unsigned int words_to_transfer;int ret; transfer->effective_speed_hz = rspi->freq; words_to_transfer = transfer->len / rspi->bytes_per_word; - ret =rzv2h_rspi_transfer_pio (rspi, spi, transfer, words_to_transfer); +if (is_dma) + ret =rzv2h_rspi_transfer_dma (rspi, spi, transfer, words_to_transfer); +else + ret =rzv2h_rspi_transfer_pio (rspi, spi, transfer, words_to_transfer);rzv2h_rspi_clear_all_irqs (rspi); +if (is_dma && ret == -EAGAIN ) +/* Retry with PIO */ + transfer->error =SPI_TRANS_FAIL_NO_START ; +return ret; }
@@ -557,6 +704,7 @@ static int rzv2h_rspi_probe(struct platform_device *pdev)platform_set_drvdata (pdev, rspi); rspi->controller = controller; + rspi->pdev = pdev; rspi->info =device_get_match_data (dev);
@@ -613,6 +761,7 @@ static int rzv2h_rspi_probe(struct platform_device *pdev) controller->unprepare_message = rzv2h_rspi_unprepare_message; controller->num_chipselect =4 ; controller->transfer_one = rzv2h_rspi_transfer_one; + controller->can_dma = rzv2h_rspi_can_dma; tclk_rate =clk_round_rate (rspi->tclk,0 );if (tclk_rate <0 )
@@ -630,6 +779,24 @@ static int rzv2h_rspi_probe(struct platform_device *pdev)RSPI_SPBR_SPR_MIN , RSPI_SPCMD_BRDV_MIN); + controller->dma_tx =devm_dma_request_chan (dev,"tx" ); +if (IS_ERR (controller->dma_tx)) { + ret =dev_warn_probe (dev,PTR_ERR (controller->dma_tx), +"failed to request TX DMA channel\n" ); +if (ret == -EPROBE_DEFER ) +return ret; + controller->dma_tx =NULL ; + } + + controller->dma_rx =devm_dma_request_chan (dev,"rx" ); +if (IS_ERR (controller->dma_rx)) { + ret =dev_warn_probe (dev,PTR_ERR (controller->dma_rx), +"failed to request RX DMA channel\n" ); +if (ret == -EPROBE_DEFER ) +return ret; + controller->dma_rx =NULL ; + } +device_set_node (&controller->dev,dev_fwnode (dev)); ret =devm_spi_register_controller (dev, controller);
Signature · 1 line
2.54.0
PATCH 18/24 spi: rzv2h-rspi: Add support for RZ/G3L (R9A08G046)
In reply to Tommaso MerciaiFrom: Biju Das <[email protected]>
commit 9be1143516473694ffd731304198a8b02e832d1d upstream.
Add support for RZ/G3L RSPI. The RZ/G3L variant requires only 2 clocks (pclk + tclk), unlike the RZ/V2H which needs 3.
--- drivers/spi/spi-rzv2h-rspi.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/spi/spi-rzv2h-rspi.c +8 -0
@@ -813,6 +813,13 @@ static const struct rzv2h_rspi_info rzv2h_info = { .num_clks = 3, }; +static const struct rzv2h_rspi_info rzg3l_info = { + .find_tclk_rate = rzv2h_rspi_find_rate_fixed, + .tclk_name ="tclk" , + .fifo_size =16 , + .num_clks =2 , +}; +static const struct rzv2h_rspi_info rzt2h_info = { .find_tclk_rate = rzv2h_rspi_find_rate_variable, .find_pclk_rate = rzv2h_rspi_find_rate_fixed,
@@ -822,6 +829,7 @@ static const struct rzv2h_rspi_info rzt2h_info = { };static const struct of_device_id rzv2h_rspi_match[] = { + { .compatible ="renesas,r9a08g046-rspi" , &rzg3l_info }, { .compatible ="renesas,r9a09g057-rspi" , &rzv2h_info }, { .compatible ="renesas,r9a09g077-rspi" , &rzt2h_info }, {/* sentinel */ }
Signature · 1 line
2.54.0
PATCH 19/24 spi: rzv2h-rspi: Fix max_speed_hz advertising prohibited bit rate
In reply to Tommaso MerciaiFrom: Lad Prabhakar <[email protected]>
commit 4e292cbf3890657db2f2692942cb0f168c80167e upstream.
On RZ/V2H(P), RZ/G3E and RZ/G3L, RSPI_n_TCLK is fixed at 200MHz. The max_speed_hz was computed using clk_round_rate(tclk, ULONG_MAX) with SPR=0 and BRDV=0, resulting in 100Mbps - the exact combination prohibited on these SoCs. This could cause the SPI framework to request a speed that rzv2h_rspi_find_rate_fixed() would skip, potentially leading to a clock selection failure.
On RZ/T2H and RZ/N2H the max_speed_hz was correctly calculated as 50Mbps for both the variable PCLKSPIn and fixed PCLK clock sources.
Since the maximum supported bit rate is 50Mbps across all supported SoC variants, replace the clk_round_rate() based calculation with a define RSPI_MAX_SPEED_HZ set to 50MHz and use it directly for max_speed_hz.
--- drivers/spi/spi-rzv2h-rspi.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/spi/spi-rzv2h-rspi.c +3 -7
@@ -77,6 +77,8 @@#define RSPI_RESET_NUM 2 +#define RSPI_MAX_SPEED_HZ 50000000 +struct rzv2h_rspi_best_clock {struct clk *clk;unsigned long clk_rate;
@@ -771,13 +773,7 @@ static int rzv2h_rspi_probe(struct platform_device *pdev)RSPI_SPBR_SPR_MAX , RSPI_SPCMD_BRDV_MAX); - tclk_rate =clk_round_rate (rspi->tclk,ULONG_MAX ); -if (tclk_rate <0 ) -return tclk_rate; - - controller->max_speed_hz =rzv2h_rspi_calc_bitrate (tclk_rate, -RSPI_SPBR_SPR_MIN , -RSPI_SPCMD_BRDV_MIN ); + controller->max_speed_hz =RSPI_MAX_SPEED_HZ ; controller->dma_tx =devm_dma_request_chan (dev,"tx" );if (IS_ERR (controller->dma_tx)) {
Signature · 1 line
2.54.0
PATCH 20/24 spi: rzv2h-rspi: Fix invalid SPR=0/BRDV=0 clock configuration
In reply to Tommaso MerciaiFrom: Lad Prabhakar <[email protected]>
commit 0335767dd8e7ade8a8e3028d08c4621515d47388 upstream.
The combination of SPR=0 and BRDV=0 results in the minimum division ratio of 2, producing the maximum possible bit rate for a given clock source. This combination is not supported in two cases:
- On RZ/G3E, RZ/G3L, RZ/V2H(P) and RZ/V2N, RSPI_n_TCLK is fixed at 200MHz, which would yield 100Mbps. The next hardware manual update will explicitly state that since the maximum frequency of the RSPICKn clock signal is 50MHz, settings with N=0 and n=0 resulting in 100Mbps are prohibited.
- On RZ/T2H and RZ/N2H, when PCLK (125MHz) is used as the clock source, SPR=0 and BRDV=0 is explicitly listed as unsupported in the hardware manual (Table 36.7).
Skip the SPR=0/BRDV=0 combination in rzv2h_rspi_find_rate_fixed() to prevent the driver from selecting an invalid clock configuration on the affected SoCs.
Additionally, remove the now redundant RSPI_SPBR_SPR_PCLK_MIN define which was previously set to 1 to work around the PCLK restriction, but was overly broad as it incorrectly blocked valid combinations such as SPR=0/BRDV=1 (31.25Mbps on PCLK=125MHz).
--- drivers/spi/spi-rzv2h-rspi.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/spi/spi-rzv2h-rspi.c +12 -6
@@ -50,7 +50,6 @@/* Register SPBR */ #define RSPI_SPBR_SPR_MIN 0 -#define RSPI_SPBR_SPR_PCLK_MIN 1#define RSPI_SPBR_SPR_MAX 255/* Register SPCMD */
@@ -535,6 +534,17 @@ static void rzv2h_rspi_find_rate_fixed(struct clk *clk, u32 hz,for (brdv =RSPI_SPCMD_BRDV_MIN ; brdv <=RSPI_SPCMD_BRDV_MAX ; brdv++) { spr =DIV_ROUND_UP (clk_rate, hz * (1 << (brdv +1 ))); spr--; +/* +* Skip SPR=0 and BRDV=0 as it is not a valid combination: +* - On RZ/G3E, RZ/G3L, RZ/V2H(P) and RZ/V2N, RSPI_n_TCLK is +* fixed at 200MHz and SPR=0 and BRDV=0 results in the maximum +* bit rate of 100Mbps which is prohibited. +* - On RZ/T2H and RZ/N2H, when PCLK (125MHz) is used as +* the clock source, SPR=0 and BRDV=0 is explicitly listed +* as unsupported in the hardware manual (Table 36.7). +*/ +if (!spr && !brdv) +continue ;if (spr >= spr_min && spr <= spr_max) goto clock_found; }
@@ -568,12 +578,8 @@ static u32 rzv2h_rspi_setup_clock(struct rzv2h_rspi_priv *rspi, u32 hz) rspi->info->find_tclk_rate (rspi->tclk, hz,RSPI_SPBR_SPR_MIN ,RSPI_SPBR_SPR_MAX , &best_clock); -/* -* T2H and N2H can also use PCLK as a source, which is 125MHz, but not -* when both SPR and BRDV are 0. -*/ if (best_clock.error && rspi->info->find_pclk_rate) - rspi->info->find_pclk_rate (rspi->pclk, hz,RSPI_SPBR_SPR_PCLK_MIN , + rspi->info->find_pclk_rate (rspi->pclk, hz,RSPI_SPBR_SPR_MIN ,RSPI_SPBR_SPR_MAX , &best_clock);if (!best_clock.clk_rate)
Signature · 1 line
2.54.0
PATCH 21/24 spi: rzv2h-rspi: Simplify clock rate search function signatures
In reply to Tommaso MerciaiFrom: Lad Prabhakar <[email protected]>
commit c958bb67b2dfd87b09d725a60162d13674fc5fd9 upstream.
The spr_min and spr_max parameters passed to rzv2h_rspi_find_rate_variable() and rzv2h_rspi_find_rate_fixed() were always called with RSPI_SPBR_SPR_MIN and RSPI_SPBR_SPR_MAX respectively. There is no need to pass these as parameters since the valid SPR range is fixed by the hardware.
--- drivers/spi/spi-rzv2h-rspi.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-)
drivers/spi/spi-rzv2h-rspi.c +11 -15
@@ -88,9 +88,9 @@ struct rzv2h_rspi_best_clock { };struct rzv2h_rspi_info { -void (*find_tclk_rate)(struct clk *clk,u32 hz,u8 spr_min,u8 spr_max, +void (*find_tclk_rate)(struct clk *clk,u32 hz,struct rzv2h_rspi_best_clock *best_clk); -void (*find_pclk_rate)(struct clk *clk,u32 hz,u8 spr_low,u8 spr_high, +void (*find_pclk_rate)(struct clk *clk,u32 hz,struct rzv2h_rspi_best_clock *best_clk);const char *tclk_name;unsigned int fifo_size;
@@ -413,7 +413,6 @@ static inline u32 rzv2h_rspi_calc_bitrate(unsigned long tclk_rate, u8 spr, }static void rzv2h_rspi_find_rate_variable (struct clk *clk,u32 hz, -u8 spr_min,u8 spr_max,struct rzv2h_rspi_best_clock *best) {long clk_rate, clk_min_rate, clk_max_rate;
@@ -464,7 +463,7 @@ static void rzv2h_rspi_find_rate_variable(struct clk *clk, u32 hz,* minimum SPR that is in the valid range. */ min_rate_spr =DIV_ROUND_CLOSEST (clk_min_rate, rate_div) -1 ; -if (min_rate_spr > spr_max) +if (min_rate_spr >RSPI_SPBR_SPR_MAX )continue ;/*
@@ -474,14 +473,14 @@ static void rzv2h_rspi_find_rate_variable(struct clk *clk, u32 hz,* maximum SPR that is in the valid range. */ max_rate_spr =DIV_ROUND_CLOSEST (clk_max_rate, rate_div) -1 ; -if (max_rate_spr < spr_min) +if (max_rate_spr <RSPI_SPBR_SPR_MIN )break ; -if (min_rate_spr < spr_min) - min_rate_spr = spr_min; +if (min_rate_spr <RSPI_SPBR_SPR_MIN ) + min_rate_spr =RSPI_SPBR_SPR_MIN ; -if (max_rate_spr > spr_max) - max_rate_spr = spr_max; +if (max_rate_spr >RSPI_SPBR_SPR_MAX ) + max_rate_spr =RSPI_SPBR_SPR_MAX ;for (spr = min_rate_spr; spr <= max_rate_spr; spr++) { clk_rate = (spr +1 ) * rate_div;
@@ -512,7 +511,6 @@ static void rzv2h_rspi_find_rate_variable(struct clk *clk, u32 hz, }static void rzv2h_rspi_find_rate_fixed (struct clk *clk,u32 hz, -u8 spr_min,u8 spr_max,struct rzv2h_rspi_best_clock *best) {unsigned long clk_rate;
@@ -545,7 +543,7 @@ static void rzv2h_rspi_find_rate_fixed(struct clk *clk, u32 hz,*/ if (!spr && !brdv)continue ; -if (spr >= spr_min && spr <= spr_max) +if (spr >=RSPI_SPBR_SPR_MIN && spr <=RSPI_SPBR_SPR_MAX ) goto clock_found; }
@@ -575,12 +573,10 @@ static u32 rzv2h_rspi_setup_clock(struct rzv2h_rspi_priv *rspi, u32 hz) };int ret; - rspi->info->find_tclk_rate (rspi->tclk, hz,RSPI_SPBR_SPR_MIN , -RSPI_SPBR_SPR_MAX , &best_clock); + rspi->info->find_tclk_rate (rspi->tclk, hz, &best_clock);if (best_clock.error && rspi->info->find_pclk_rate) - rspi->info->find_pclk_rate (rspi->pclk, hz,RSPI_SPBR_SPR_MIN , -RSPI_SPBR_SPR_MAX , &best_clock); + rspi->info->find_pclk_rate (rspi->pclk, hz, &best_clock);if (!best_clock.clk_rate)return -EINVAL ;
Signature · 1 line
2.54.0
PATCH 22/24 spi: rzv2h-rspi: Fix silent failure in clock setup error path
In reply to Tommaso MerciaiFrom: John Madieu <[email protected]>
commit 54900126ae0a2671f8790a7f95706b9ea95fac4e upstream.
rzv2h_rspi_setup_clock() is declared to return u32 but returns -EINVAL when no valid clock parameters are found. Cast to u32, -EINVAL becomes 0xffffffea, which is a non-zero value. The caller in rzv2h_rspi_prepare_message() guards against failure with:
rspi->freq = rzv2h_rspi_setup_clock(rspi, speed_hz); if (!rspi->freq) return -EINVAL;
Because 0xffffffea is non-zero, the check is bypassed and the controller proceeds to program SPBR/SPCMD with stale values, leading to an unknown bit rate.
Return 0 on the failed-search path, consistent with the existing clk_set_rate() failure path which already returns 0.
--- drivers/spi/spi-rzv2h-rspi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-rzv2h-rspi.c +1 -1
@@ -579,7 +579,7 @@ static u32 rzv2h_rspi_setup_clock(struct rzv2h_rspi_priv *rspi, u32 hz) rspi->info->find_pclk_rate (rspi->pclk, hz, &best_clock);if (!best_clock.clk_rate) -return -EINVAL ; +return 0 ; ret =clk_set_rate (best_clock.clk, best_clock.clk_rate);if (ret)
Signature · 1 line
2.54.0
PATCH 23/24 arm64: dts: renesas: r9a09g047: Add RSPI nodes
In reply to Tommaso Merciaicommit d2c3353ddbebd07b27ded9813a665557cc0f96d7 upstream.
Add nodes for the RSPI IPs found in the Renesas RZ/G3E SoC.
--- arch/arm64/boot/dts/renesas/r9a09g047.dtsi | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+)
arch/arm64/boot/dts/renesas/r9a09g047.dtsi +84 -0
@@ -591,6 +591,90 @@ channel5 { }; }; + rspi0: spi@12800000 { + compatible = "renesas,r9a09g047-rspi", "renesas,r9a09g057-rspi"; + reg = <0x0 0x12800000 0x0 0x400>; + interrupts = <GIC_SPI 105 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 106 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 107 IRQ_TYPE_EDGE_RISING>, + <GIC_SPI 500 IRQ_TYPE_EDGE_RISING>, + <GIC_SPI 501 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "idle", "error", "end", "rx", "tx"; + clocks = <&cpg CPG_MOD 0x54>, + <&cpg CPG_MOD 0x55>, + <&cpg CPG_MOD 0x56>; + clock-names = "pclk", "pclk_sfr", "tclk"; + resets = <&cpg 0x7b>, <&cpg 0x7c>; + reset-names = "presetn", "tresetn"; + dmas = <&dmac0 0x448c>, <&dmac0 0x448d>, + <&dmac1 0x448c>, <&dmac1 0x448d>, + <&dmac2 0x448c>, <&dmac2 0x448d>, + <&dmac3 0x448c>, <&dmac3 0x448d>, + <&dmac4 0x448c>, <&dmac4 0x448d>; + dma-names = "rx", "tx", "rx", "tx", "rx", "tx", + "rx", "tx", "rx", "tx"; + power-domains = <&cpg>; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + }; + + rspi1: spi@12800400 { + compatible = "renesas,r9a09g047-rspi", "renesas,r9a09g057-rspi"; + reg = <0x0 0x12800400 0x0 0x400>; + interrupts = <GIC_SPI 108 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 109 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 110 IRQ_TYPE_EDGE_RISING>, + <GIC_SPI 502 IRQ_TYPE_EDGE_RISING>, + <GIC_SPI 503 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "idle", "error", "end", "rx", "tx"; + clocks = <&cpg CPG_MOD 0x57>, + <&cpg CPG_MOD 0x58>, + <&cpg CPG_MOD 0x59>; + clock-names = "pclk", "pclk_sfr", "tclk"; + resets = <&cpg 0x7d>, <&cpg 0x7e>; + reset-names = "presetn", "tresetn"; + dmas = <&dmac0 0x448e>, <&dmac0 0x448f>, + <&dmac1 0x448e>, <&dmac1 0x448f>, + <&dmac2 0x448e>, <&dmac2 0x448f>, + <&dmac3 0x448e>, <&dmac3 0x448f>, + <&dmac4 0x448e>, <&dmac4 0x448f>; + dma-names = "rx", "tx", "rx", "tx", "rx", "tx", + "rx", "tx", "rx", "tx"; + power-domains = <&cpg>; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + }; + + rspi2: spi@12800800 { + compatible = "renesas,r9a09g047-rspi", "renesas,r9a09g057-rspi"; + reg = <0x0 0x12800800 0x0 0x400>; + interrupts = <GIC_SPI 111 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 112 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 113 IRQ_TYPE_EDGE_RISING>, + <GIC_SPI 504 IRQ_TYPE_EDGE_RISING>, + <GIC_SPI 505 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "idle", "error", "end", "rx", "tx"; + clocks = <&cpg CPG_MOD 0x5a>, + <&cpg CPG_MOD 0x5b>, + <&cpg CPG_MOD 0x5c>; + clock-names = "pclk", "pclk_sfr", "tclk"; + resets = <&cpg 0x7f>, <&cpg 0x80>; + reset-names = "presetn", "tresetn"; + dmas = <&dmac0 0x4490>, <&dmac0 0x4491>, + <&dmac1 0x4490>, <&dmac1 0x4491>, + <&dmac2 0x4490>, <&dmac2 0x4491>, + <&dmac3 0x4490>, <&dmac3 0x4491>, + <&dmac4 0x4490>, <&dmac4 0x4491>; + dma-names = "rx", "tx", "rx", "tx", "rx", "tx", + "rx", "tx", "rx", "tx"; + power-domains = <&cpg>; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + }; + rsci0: serial@12800c00 { compatible = "renesas,r9a09g047-rsci"; reg = <0 0x12800c00 0 0x400>;
Signature · 1 line
2.54.0
PATCH 24/24 arm64: dts: renesas: r9a09g047e57-smarc: Enable RSPI0
In reply to Tommaso Merciaicommit 19ca423f61b66ee3328b6a2f35fbb3ff2c8566f5 upstream.
Enable RSPI0 on the RZ/G3E SMARC EVK, where it is accessible on the PMOD0 connector.
--- .../boot/dts/renesas/r9a09g047e57-smarc.dts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
arch/arm64/boot/dts/renesas/r9a09g047e57-smarc.dts +16 -0
@@ -183,6 +183,13 @@ rsci9_pins: rsci9 { bias-pull-up; }; + rspi0_pins: rspi0 { + pinmux = <RZG3E_PORT_PINMUX(M, 4, 2)>, /* MISOA */ + <RZG3E_PORT_PINMUX(M, 5, 2)>, /* MOSIA */ + <RZG3E_PORT_PINMUX(M, 6, 2)>, /* RSPCKA */ + <RZG3E_PORT_PINMUX(M, 7, 2)>; /* SSLA0 */ + }; + scif_pins: scif { pins = "SCIF_TXD", "SCIF_RXD"; renesas,output-impedance = <1>;
@@ -250,6 +257,15 @@ &rsci9 { }; #endif +&rspi0 { + pinctrl-0 = <&rspi0_pins>; + pinctrl-names = "default"; + #address-cells = <1>; + #size-cells = <0>; + + status = "okay"; +}; + &scif0 { pinctrl-0 = <&scif_pins>; pinctrl-names = "default";
Signature · 1 line
2.54.0
Hi!
Quoted 11 lines
This patch series adds RSPI support for the Renesas RZ/G3E SoC, which features three RSPI controllers. The series also enables DMA support in the RSPI driver, and backports the necessary infrastructure changes into linux-6.12.y-cip.
The series is structured as follows:
- Clock entries for the three RSPI instances on RZ/G3E SoC
- DT binding updates: document DMA properties and add RZ/G3E compatible
- Device tree nodes for RZ/G3E RSPI controllers and SMARC board enablement
- Driver improvements backported from mainline: DMA support, device-managed APIs, bug fixes for clock setup and FIFO thresholds
There will likely be some minor comments, but this looks okay to me, too.
I can apply the series if it passes testing and there are no other comments.
Best regards,
Pavel
Pavel Machek
AppliedHi!
Quoted 11 lines
This patch series adds RSPI support for the Renesas RZ/G3E SoC, which features three RSPI controllers. The series also enables DMA support in the RSPI driver, and backports the necessary infrastructure changes into linux-6.12.y-cip.
The series is structured as follows:
- Clock entries for the three RSPI instances on RZ/G3E SoC
- DT binding updates: document DMA properties and add RZ/G3E compatible
- Device tree nodes for RZ/G3E RSPI controllers and SMARC board enablement
- Driver improvements backported from mainline: DMA support, device-managed APIs, bug fixes for clock setup and FIFO thresholds
Thank you, applied.
Best regards,
Pavel