spi: Fixes for FSI-attached controller
Subsystems (4)
Eddie James
maintainerv2 cover spi: Fixes for FSI-attached controller
This series implements a number of fixes for the FSI-attached SPI controller driver.
Changes since v1:
- Switch to a new compatible string for the restricted version of the SPI controller, rather than a new boolean parameter.
Brad Bishop (3):
spi: fsi: Handle 9 to 15 byte transfers lengths
spi: fsi: Fix clock running too fast
spi: fsi: Fix use of the bneq+ sequencer instruction
Eddie James (3):
dt-bindings: fsi: fsi2spi: Add compatible string for restricted
version
spi: fsi: Implement restricted size for certain controllers
spi: fsi: Check mux status before transfers
.../devicetree/bindings/fsi/ibm,fsi2spi.yaml | 1 + drivers/spi/spi-fsi.c | 139 ++++++++++++++---- 2 files changed, 109 insertions(+), 31 deletions(-)
Signature · 1 line
2.26.2
Eddie James
maintainerPATCH v2 1/6 spi: fsi: Handle 9 to 15 byte transfers lengths
From: Brad Bishop <[email protected]>
The trailing <len> - 8 bytes of transfer data in this size range is no longer ignored.
--- drivers/spi/spi-fsi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/spi/spi-fsi.c +3 -3
@@ -258,15 +258,15 @@ static int fsi_spi_sequence_transfer(struct fsi_spi *ctx,if (loops >1 ) {fsi_spi_sequence_add (seq,SPI_FSI_SEQUENCE_BRANCH (idx)); -if (rem) -fsi_spi_sequence_add (seq, rem); - rc =fsi_spi_write_reg (ctx,SPI_FSI_COUNTER_CFG ,SPI_FSI_COUNTER_CFG_LOOPS (loops -1 ));if (rc)return rc; } +if (rem) +fsi_spi_sequence_add (seq, rem); +return 0 ; }
Signature · 1 line
2.26.2
Eddie James
maintainerPATCH v2 2/6 spi: fsi: Fix clock running too fast
In reply to Eddie JamesFrom: Brad Bishop <[email protected]>
Use a clock divider tuned to a 200MHz FSI bus frequency (the maximum). Use of the previous divider at 200MHz results in corrupt data from endpoint devices. Ideally the clock divider would be calculated from the FSI clock, but that would require some significant work on the FSI driver. With FSI frequencies slower than 200MHz, the SPI clock will simply run slower, but safely.
--- drivers/spi/spi-fsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-fsi.c +1 -1
@@ -350,7 +350,7 @@ static int fsi_spi_transfer_init(struct fsi_spi *ctx)u64 status =0ULL ;u64 wanted_clock_cfg =SPI_FSI_CLOCK_CFG_ECC_DISABLE |SPI_FSI_CLOCK_CFG_SCK_NO_DEL | -FIELD_PREP (SPI_FSI_CLOCK_CFG_SCK_DIV ,4 ); +FIELD_PREP (SPI_FSI_CLOCK_CFG_SCK_DIV ,19 ); end = jiffies +msecs_to_jiffies (SPI_FSI_INIT_TIMEOUT_MS ); do {
Signature · 1 line
2.26.2
Eddie James
maintainerPATCH v2 3/6 spi: fsi: Fix use of the bneq+ sequencer instruction
In reply to Eddie JamesFrom: Brad Bishop <[email protected]>
All of the switches in N2_count_control in the counter configuration are required to make the branch if not equal and increment command work. Set them when using bneq+.
A side effect of this mode requires a dummy write to TDR when both transmitting and receiving otherwise the controller won't start shifting receive data.
It is likely not possible to avoid TDR underrun errors in this mode and they are harmless, so do not check for them.
--- drivers/spi/spi-fsi.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-)
drivers/spi/spi-fsi.c +25 -3
@@ -29,6 +29,10 @@#define SPI_FSI_ERROR 0x0#define SPI_FSI_COUNTER_CFG 0x1#define SPI_FSI_COUNTER_CFG_LOOPS (x) (((u64)(x) & 0xffULL) << 32) +#define SPI_FSI_COUNTER_CFG_N2_RX BIT_ULL(8) +#define SPI_FSI_COUNTER_CFG_N2_TX BIT_ULL(9) +#define SPI_FSI_COUNTER_CFG_N2_IMPLICIT BIT_ULL(10) +#define SPI_FSI_COUNTER_CFG_N2_RELOAD BIT_ULL(11)#define SPI_FSI_CFG1 0x2#define SPI_FSI_CLOCK_CFG 0x3#define SPI_FSI_CLOCK_CFG_MM_ENABLE BIT_ULL(32)
@@ -61,7 +65,7 @@#define SPI_FSI_STATUS_RDR_OVERRUN BIT_ULL(62)#define SPI_FSI_STATUS_RDR_FULL BIT_ULL(63)#define SPI_FSI_STATUS_ANY_ERROR \ - (SPI_FSI_STATUS_ERROR | SPI_FSI_STATUS_TDR_UNDERRUN | \ + (SPI_FSI_STATUS_ERROR | \ SPI_FSI_STATUS_TDR_OVERRUN | SPI_FSI_STATUS_RDR_UNDERRUN | \ SPI_FSI_STATUS_RDR_OVERRUN)#define SPI_FSI_PORT_CTRL 0x9
@@ -238,6 +242,7 @@ static int fsi_spi_sequence_transfer(struct fsi_spi *ctx,int rc;u8 len =min (transfer->len,8U );u8 rem = transfer->len % len; +u64 cfg =0ULL ; loops = transfer->len / len;
@@ -258,8 +263,14 @@ static int fsi_spi_sequence_transfer(struct fsi_spi *ctx,if (loops >1 ) {fsi_spi_sequence_add (seq,SPI_FSI_SEQUENCE_BRANCH (idx)); - rc =fsi_spi_write_reg (ctx,SPI_FSI_COUNTER_CFG , -SPI_FSI_COUNTER_CFG_LOOPS (loops -1 )); + cfg =SPI_FSI_COUNTER_CFG_LOOPS (loops -1 ); +if (transfer->rx_buf) + cfg |=SPI_FSI_COUNTER_CFG_N2_RX | +SPI_FSI_COUNTER_CFG_N2_TX | +SPI_FSI_COUNTER_CFG_N2_IMPLICIT | +SPI_FSI_COUNTER_CFG_N2_RELOAD ; + + rc =fsi_spi_write_reg (ctx,SPI_FSI_COUNTER_CFG , cfg);if (rc)return rc; }
@@ -275,6 +286,7 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx, {int rc =0 ;u64 status =0ULL ; +u64 cfg =0ULL ;if (transfer->tx_buf) {int nb;
@@ -312,6 +324,16 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx,u64 in =0ULL ;u8 *rx = transfer->rx_buf; + rc =fsi_spi_read_reg (ctx,SPI_FSI_COUNTER_CFG , &cfg); +if (rc) +return rc; + +if (cfg &SPI_FSI_COUNTER_CFG_N2_IMPLICIT ) { + rc =fsi_spi_write_reg (ctx,SPI_FSI_DATA_TX ,0 ); +if (rc) +return rc; + } + while (transfer->len > recv) { do { rc = fsi_spi_read_reg(ctx, SPI_FSI_STATUS,
Signature · 1 line
2.26.2
Eddie James
maintainerPATCH v2 4/6 dt-bindings: fsi: fsi2spi: Add compatible string for restricted version
In reply to Eddie JamesAdd a compatible string for the restricted version of the SPI controller. The restricted version cannot process sequence loop operations and therefore has a smaller transfer size.
--- Documentation/devicetree/bindings/fsi/ibm,fsi2spi.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/fsi/ibm,fsi2spi.yaml +1 -0
@@ -19,6 +19,7 @@ properties: compatible: enum: - ibm,fsi2spi + - ibm,fsi2spi-restricted reg: items:
Signature · 1 line
2.26.2
Eddie James
maintainerPATCH v2 5/6 spi: fsi: Implement restricted size for certain controllers
In reply to Eddie JamesSome of the FSI-attached SPI controllers cannot use the loop command in programming the sequencer due to security requirements. Check the devicetree compatibility that indicates this condition and restrict the size for these controllers. Also, add more transfers directly in the sequence up to the length of the sequence register.
--- drivers/spi/spi-fsi.c | 65 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 12 deletions(-)
drivers/spi/spi-fsi.c +53 -12
@@ -24,7 +24,8 @@#define SPI_FSI_BASE 0x70000#define SPI_FSI_INIT_TIMEOUT_MS 1000 -#define SPI_FSI_MAX_TRANSFER_SIZE 2048 +#define SPI_FSI_MAX_XFR_SIZE 2048 +#define SPI_FSI_MAX_XFR_SIZE_RESTRICTED 32#define SPI_FSI_ERROR 0x0#define SPI_FSI_COUNTER_CFG 0x1
@@ -74,6 +75,8 @@ struct fsi_spi {struct device *dev;/* SPI controller device */ struct fsi_device *fsi;/* FSI2SPI CFAM engine device */ u32 base; +size_t max_xfr_size; +bool restricted; };struct fsi_spi_sequence {
@@ -209,8 +212,12 @@ static int fsi_spi_reset(struct fsi_spi *ctx)if (rc)return rc; -return fsi_spi_write_reg (ctx,SPI_FSI_CLOCK_CFG , -SPI_FSI_CLOCK_CFG_RESET2 ); + rc =fsi_spi_write_reg (ctx,SPI_FSI_CLOCK_CFG , +SPI_FSI_CLOCK_CFG_RESET2 ); +if (rc) +return rc; + +return fsi_spi_write_reg (ctx,SPI_FSI_STATUS ,0ULL ); }static int fsi_spi_sequence_add (struct fsi_spi_sequence *seq,u8 val)
@@ -218,8 +225,8 @@ static int fsi_spi_sequence_add(struct fsi_spi_sequence *seq, u8 val)/* * Add the next byte of instruction to the 8-byte sequence register. * Then decrement the counter so that the next instruction will go in -* the right place. Return the number of "slots" left in the sequence -* register. +* the right place. Return the index of the slot we just filled in the +* sequence register. */ seq->data |= (u64 )val << seq->bit; seq->bit -=8 ;
@@ -237,9 +244,11 @@ static int fsi_spi_sequence_transfer(struct fsi_spi *ctx,struct fsi_spi_sequence *seq, struct spi_transfer *transfer) { + bool docfg = false;int loops;int idx;int rc; +u8 val =0 ;u8 len =min (transfer->len,8U );u8 rem = transfer->len % len;u64 cfg =0ULL ;
@@ -247,22 +256,42 @@ static int fsi_spi_sequence_transfer(struct fsi_spi *ctx, loops = transfer->len / len;if (transfer->tx_buf) { - idx =fsi_spi_sequence_add (seq, -SPI_FSI_SEQUENCE_SHIFT_OUT (len)); + val =SPI_FSI_SEQUENCE_SHIFT_OUT (len); + idx =fsi_spi_sequence_add (seq, val); +if (rem) rem =SPI_FSI_SEQUENCE_SHIFT_OUT (rem); }else if (transfer->rx_buf) { - idx =fsi_spi_sequence_add (seq, -SPI_FSI_SEQUENCE_SHIFT_IN (len)); + val =SPI_FSI_SEQUENCE_SHIFT_IN (len); + idx =fsi_spi_sequence_add (seq, val); +if (rem) rem =SPI_FSI_SEQUENCE_SHIFT_IN (rem); }else {return -EINVAL ; } +if (ctx->restricted) { +const int eidx = rem ?5 :6 ; + +while (loops >1 && idx <= eidx) { + idx =fsi_spi_sequence_add (seq, val); + loops--; + docfg = true; + } + +if (loops >1 ) { +dev_warn (ctx->dev,"No sequencer slots; aborting.\n" ); +return -EINVAL ; + } + } +if (loops >1 ) {fsi_spi_sequence_add (seq,SPI_FSI_SEQUENCE_BRANCH (idx)); + docfg = true; + } +if (docfg) { cfg =SPI_FSI_COUNTER_CFG_LOOPS (loops -1 );if (transfer->rx_buf) cfg |= SPI_FSI_COUNTER_CFG_N2_RX |
@@ -273,6 +302,8 @@ static int fsi_spi_sequence_transfer(struct fsi_spi *ctx, rc =fsi_spi_write_reg (ctx,SPI_FSI_COUNTER_CFG , cfg);if (rc)return rc; + }else { +fsi_spi_write_reg (ctx,SPI_FSI_COUNTER_CFG ,0ULL ); }if (rem)
@@ -429,7 +460,7 @@ static int fsi_spi_transfer_one_message(struct spi_controller *ctlr,/* Sequencer must do shift out (tx) first. */ if (!transfer->tx_buf || - transfer->len >SPI_FSI_MAX_TRANSFER_SIZE ) { + transfer->len > (ctx->max_xfr_size +8 )) { rc = -EINVAL ; goto error; }
@@ -453,7 +484,7 @@ static int fsi_spi_transfer_one_message(struct spi_controller *ctlr,/* Sequencer can only do shift in (rx) after tx. */ if (next->rx_buf) { -if (next->len >SPI_FSI_MAX_TRANSFER_SIZE ) { +if (next->len > ctx->max_xfr_size) { rc = -EINVAL ; goto error; }
@@ -498,7 +529,9 @@ static int fsi_spi_transfer_one_message(struct spi_controller *ctlr,static size_t fsi_spi_max_transfer_size (struct spi_device *spi) { -return SPI_FSI_MAX_TRANSFER_SIZE ; +struct fsi_spi *ctx =spi_controller_get_devdata (spi->controller); + +return ctx->max_xfr_size; }static int fsi_spi_probe (struct device *dev)
@@ -546,6 +579,14 @@ static int fsi_spi_probe(struct device *dev) ctx->fsi = fsi; ctx->base = base +SPI_FSI_BASE ; +if (of_device_is_compatible (np,"ibm,fsi2spi-restricted" )) { + ctx->restricted = true; + ctx->max_xfr_size =SPI_FSI_MAX_XFR_SIZE_RESTRICTED ; + }else { + ctx->restricted = false; + ctx->max_xfr_size =SPI_FSI_MAX_XFR_SIZE ; + } + rc =devm_spi_register_controller (dev, ctlr);if (rc)spi_controller_put (ctlr);
Signature · 1 line
2.26.2
Eddie James
maintainerPATCH v2 6/6 spi: fsi: Check mux status before transfers
In reply to Eddie JamesThe SPI controllers are not accessible if the mux isn't set. Therefore, check the mux status before starting a transfer and fail out if it isn't set.
--- drivers/spi/spi-fsi.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-)
drivers/spi/spi-fsi.c +27 -13
@@ -12,6 +12,7 @@#define FSI_ENGID_SPI 0x23#define FSI_MBOX_ROOT_CTRL_8 0x2860 +#define FSI_MBOX_ROOT_CTRL_8_SPI_MUX 0xf0000000#define FSI2SPI_DATA0 0x00#define FSI2SPI_DATA1 0x04
@@ -84,6 +85,26 @@ struct fsi_spi_sequence {u64 data; }; +static int fsi_spi_check_mux (struct fsi_device *fsi,struct device *dev) +{ +int rc; +u32 root_ctrl_8; +__be32 root_ctrl_8_be; + + rc =fsi_slave_read (fsi->slave,FSI_MBOX_ROOT_CTRL_8 , &root_ctrl_8_be, +sizeof (root_ctrl_8_be)); +if (rc) +return rc; + + root_ctrl_8 =be32_to_cpu (root_ctrl_8_be); +dev_dbg (dev,"Root control register 8: %08x\n" , root_ctrl_8); +if ((root_ctrl_8 &FSI_MBOX_ROOT_CTRL_8_SPI_MUX ) == +FSI_MBOX_ROOT_CTRL_8_SPI_MUX ) +return 0 ; + +return -ENOLINK ; +} +static int fsi_spi_check_status (struct fsi_spi *ctx) {int rc;
@@ -449,11 +470,15 @@ static int fsi_spi_transfer_init(struct fsi_spi *ctx)static int fsi_spi_transfer_one_message (struct spi_controller *ctlr,struct spi_message *mesg) { -int rc =0 ; +int rc;u8 seq_slave =SPI_FSI_SEQUENCE_SEL_SLAVE (mesg->spi->chip_select +1 );struct spi_transfer *transfer;struct fsi_spi *ctx =spi_controller_get_devdata (ctlr); + rc =fsi_spi_check_mux (ctx->fsi, ctx->dev); +if (rc) +return rc; +list_for_each_entry (transfer, &mesg->transfers, transfer_list) {struct fsi_spi_sequence seq;struct spi_transfer *next =NULL ;
@@ -537,24 +562,13 @@ static size_t fsi_spi_max_transfer_size(struct spi_device *spi)static int fsi_spi_probe (struct device *dev) {int rc; -u32 root_ctrl_8;struct device_node *np;int num_controllers_registered =0 ;struct fsi_device *fsi =to_fsi_dev (dev); -/* -* Check the SPI mux before attempting to probe. If the mux isn't set -* then the SPI controllers can't access their slave devices. -*/ - rc =fsi_slave_read (fsi->slave,FSI_MBOX_ROOT_CTRL_8 , &root_ctrl_8, -sizeof (root_ctrl_8)); + rc =fsi_spi_check_mux (fsi, dev);if (rc) -return rc; - -if (!root_ctrl_8) { -dev_dbg (dev,"SPI mux not set, aborting probe.\n" );return -ENODEV ; - }for_each_available_child_of_node (dev->of_node, np) {u32 base;
Signature · 1 line
2.26.2
Mark Brown
maintainerQuoted 8 lines · Eddie James
This series implements a number of fixes for the FSI-attached SPI controller driver.
Changes since v1:
- Switch to a new compatible string for the restricted version of the SPI controller, rather than a new boolean parameter.[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[1/6] spi: fsi: Handle 9 to 15 byte transfers lengths
commit: 2b3cef0fc757bd06ed9b83bd4c436bfa55f47370
[2/6] spi: fsi: Fix clock running too fast
commit: 0b546bbe9474ff23e6843916ad6d567f703b2396
[3/6] spi: fsi: Fix use of the bneq+ sequencer instruction
commit: 7909eebb2bea7fdbb2de0aa794cf29843761ed5b
[4/6] spi: fsi: fsi2spi: Add compatible string for restricted version
commit: b0e4dfe93714b21e2fa9b03819b3e99383e5c330
[5/6] spi: fsi: Implement restricted size for certain controllers
commit: 49c9fc1d7c101eceaddb655e4f0e062b0c8f403b
[6/6] spi: fsi: Check mux status before transfers
commit: 9211a441e60686eec2ebd8f7bd65c4f780416404All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark