Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'spi-fix-v6.10-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi

Pull spi fixes from Mark Brown:
"This fixes two regressions that have been bubbling along for a large
part of this release.

One is a revert of the multi mode support for the OMAP SPI controller,
this introduced regressions on a number of systems and while there has
been progress on fixing those we've not got something that works for
everyone yet so let's just drop the change for now.

The other is a series of fixes from David Lechner for his recent
message optimisation work, this interacted badly with spi-mux which
is altogether too clever with recursive use of the bus and creates
situations that hadn't been considered.

There are also a couple of small driver specific fixes, including one
more patch from David for sleep duration calculations in the AXI
driver"

* tag 'spi-fix-v6.10-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi:
spi: mux: set ctlr->bits_per_word_mask
spi: add defer_optimize_message controller flag
spi: don't unoptimize message in spi_async()
spi: omap2-mcspi: Revert multi mode support
spi: davinci: Unset POWERDOWN bit when releasing resources
spi: axi-spi-engine: fix sleep calculation
spi: imx: Don't expect DMA for i.MX{25,35,50,51,53} cspi devices

+49 -26
+18 -8
drivers/spi/spi-axi-spi-engine.c
··· 164 164 } 165 165 166 166 static void spi_engine_gen_sleep(struct spi_engine_program *p, bool dry, 167 - int delay_ns, u32 sclk_hz) 167 + int delay_ns, int inst_ns, u32 sclk_hz) 168 168 { 169 169 unsigned int t; 170 170 171 - /* negative delay indicates error, e.g. from spi_delay_to_ns() */ 172 - if (delay_ns <= 0) 171 + /* 172 + * Negative delay indicates error, e.g. from spi_delay_to_ns(). And if 173 + * delay is less that the instruction execution time, there is no need 174 + * for an extra sleep instruction since the instruction execution time 175 + * will already cover the required delay. 176 + */ 177 + if (delay_ns < 0 || delay_ns <= inst_ns) 173 178 return; 174 179 175 - /* rounding down since executing the instruction adds a couple of ticks delay */ 176 - t = DIV_ROUND_DOWN_ULL((u64)delay_ns * sclk_hz, NSEC_PER_SEC); 180 + t = DIV_ROUND_UP_ULL((u64)(delay_ns - inst_ns) * sclk_hz, NSEC_PER_SEC); 177 181 while (t) { 178 182 unsigned int n = min(t, 256U); 179 183 ··· 224 220 struct spi_device *spi = msg->spi; 225 221 struct spi_controller *host = spi->controller; 226 222 struct spi_transfer *xfer; 227 - int clk_div, new_clk_div; 223 + int clk_div, new_clk_div, inst_ns; 228 224 bool keep_cs = false; 229 225 u8 bits_per_word = 0; 226 + 227 + /* 228 + * Take into account instruction execution time for more accurate sleep 229 + * times, especially when the delay is small. 230 + */ 231 + inst_ns = DIV_ROUND_UP(NSEC_PER_SEC, host->max_speed_hz); 230 232 231 233 clk_div = 1; 232 234 ··· 262 252 263 253 spi_engine_gen_xfer(p, dry, xfer); 264 254 spi_engine_gen_sleep(p, dry, spi_delay_to_ns(&xfer->delay, xfer), 265 - xfer->effective_speed_hz); 255 + inst_ns, xfer->effective_speed_hz); 266 256 267 257 if (xfer->cs_change) { 268 258 if (list_is_last(&xfer->transfer_list, &msg->transfers)) { ··· 272 262 spi_engine_gen_cs(p, dry, spi, false); 273 263 274 264 spi_engine_gen_sleep(p, dry, spi_delay_to_ns( 275 - &xfer->cs_change_delay, xfer), 265 + &xfer->cs_change_delay, xfer), inst_ns, 276 266 xfer->effective_speed_hz); 277 267 278 268 if (!list_next_entry(xfer, transfer_list)->cs_off)
+6
drivers/spi/spi-davinci.c
··· 984 984 return ret; 985 985 986 986 free_dma: 987 + /* This bit needs to be cleared to disable dpsi->clk */ 988 + clear_io_bits(dspi->base + SPIGCR1, SPIGCR1_POWERDOWN_MASK); 989 + 987 990 if (dspi->dma_rx) { 988 991 dma_release_channel(dspi->dma_rx); 989 992 dma_release_channel(dspi->dma_tx); ··· 1015 1012 dspi = spi_controller_get_devdata(host); 1016 1013 1017 1014 spi_bitbang_stop(&dspi->bitbang); 1015 + 1016 + /* This bit needs to be cleared to disable dpsi->clk */ 1017 + clear_io_bits(dspi->base + SPIGCR1, SPIGCR1_POWERDOWN_MASK); 1018 1018 1019 1019 if (dspi->dma_rx) { 1020 1020 dma_release_channel(dspi->dma_rx);
+1 -1
drivers/spi/spi-imx.c
··· 1050 1050 .rx_available = mx31_rx_available, 1051 1051 .reset = mx31_reset, 1052 1052 .fifo_size = 8, 1053 - .has_dmamode = true, 1053 + .has_dmamode = false, 1054 1054 .dynamic_burst = false, 1055 1055 .has_targetmode = false, 1056 1056 .devtype = IMX35_CSPI,
+2
drivers/spi/spi-mux.c
··· 158 158 /* supported modes are the same as our parent's */ 159 159 ctlr->mode_bits = spi->controller->mode_bits; 160 160 ctlr->flags = spi->controller->flags; 161 + ctlr->bits_per_word_mask = spi->controller->bits_per_word_mask; 161 162 ctlr->transfer_one_message = spi_mux_transfer_one_message; 162 163 ctlr->setup = spi_mux_setup; 163 164 ctlr->num_chipselect = mux_control_states(priv->mux); 164 165 ctlr->bus_num = -1; 165 166 ctlr->dev.of_node = spi->dev.of_node; 166 167 ctlr->must_async = true; 168 + ctlr->defer_optimize_message = true; 167 169 168 170 ret = devm_spi_register_controller(&spi->dev, ctlr); 169 171 if (ret)
+1 -14
drivers/spi/spi-omap2-mcspi.c
··· 1277 1277 1278 1278 /* 1279 1279 * Check if this transfer contains only one word; 1280 - * OR contains 1 to 4 words, with bits_per_word == 8 and no delay between each word 1281 - * OR contains 1 to 2 words, with bits_per_word == 16 and no delay between each word 1282 - * 1283 - * If one of the two last case is true, this also change the bits_per_word of this 1284 - * transfer to make it a bit faster. 1285 - * It's not an issue to change the bits_per_word here even if the multi-mode is not 1286 - * applicable for this message, the signal on the wire will be the same. 1287 1280 */ 1288 1281 if (bits_per_word < 8 && tr->len == 1) { 1289 1282 /* multi-mode is applicable, only one word (1..7 bits) */ 1290 - } else if (tr->word_delay.value == 0 && bits_per_word == 8 && tr->len <= 4) { 1291 - /* multi-mode is applicable, only one "bigger" word (8,16,24,32 bits) */ 1292 - tr->bits_per_word = tr->len * bits_per_word; 1293 - } else if (tr->word_delay.value == 0 && bits_per_word == 16 && tr->len <= 2) { 1294 - /* multi-mode is applicable, only one "bigger" word (16,32 bits) */ 1295 - tr->bits_per_word = tr->len * bits_per_word / 2; 1296 1283 } else if (bits_per_word >= 8 && tr->len == bits_per_word / 8) { 1297 - /* multi-mode is applicable, only one word (9..15,17..32 bits) */ 1284 + /* multi-mode is applicable, only one word (8..32 bits) */ 1298 1285 } else { 1299 1286 /* multi-mode is not applicable: more than one word in the transfer */ 1300 1287 mcspi->use_multi_mode = false;
+17 -3
drivers/spi/spi.c
··· 2151 2151 */ 2152 2152 static void spi_maybe_unoptimize_message(struct spi_message *msg) 2153 2153 { 2154 - if (!msg->pre_optimized && msg->optimized) 2154 + if (!msg->pre_optimized && msg->optimized && 2155 + !msg->spi->controller->defer_optimize_message) 2155 2156 __spi_unoptimize_message(msg); 2156 2157 } 2157 2158 ··· 4295 4294 static int spi_maybe_optimize_message(struct spi_device *spi, 4296 4295 struct spi_message *msg) 4297 4296 { 4297 + if (spi->controller->defer_optimize_message) { 4298 + msg->spi = spi; 4299 + return 0; 4300 + } 4301 + 4298 4302 if (msg->pre_optimized) 4299 4303 return 0; 4300 4304 ··· 4330 4324 { 4331 4325 int ret; 4332 4326 4327 + /* 4328 + * Pre-optimization is not supported and optimization is deferred e.g. 4329 + * when using spi-mux. 4330 + */ 4331 + if (spi->controller->defer_optimize_message) 4332 + return 0; 4333 + 4333 4334 ret = __spi_optimize_message(spi, msg); 4334 4335 if (ret) 4335 4336 return ret; ··· 4363 4350 */ 4364 4351 void spi_unoptimize_message(struct spi_message *msg) 4365 4352 { 4353 + if (msg->spi->controller->defer_optimize_message) 4354 + return; 4355 + 4366 4356 __spi_unoptimize_message(msg); 4367 4357 msg->pre_optimized = false; 4368 4358 } ··· 4447 4431 ret = __spi_async(spi, message); 4448 4432 4449 4433 spin_unlock_irqrestore(&ctlr->bus_lock_spinlock, flags); 4450 - 4451 - spi_maybe_unoptimize_message(message); 4452 4434 4453 4435 return ret; 4454 4436 }
+4
include/linux/spi/spi.h
··· 533 533 * @queue_empty: signal green light for opportunistically skipping the queue 534 534 * for spi_sync transfers. 535 535 * @must_async: disable all fast paths in the core 536 + * @defer_optimize_message: set to true if controller cannot pre-optimize messages 537 + * and needs to defer the optimization step until the message is actually 538 + * being transferred 536 539 * 537 540 * Each SPI controller can communicate with one or more @spi_device 538 541 * children. These make a small bus, sharing MOSI, MISO and SCK signals ··· 779 776 /* Flag for enabling opportunistic skipping of the queue in spi_sync */ 780 777 bool queue_empty; 781 778 bool must_async; 779 + bool defer_optimize_message; 782 780 }; 783 781 784 782 static inline void *spi_controller_get_devdata(struct spi_controller *ctlr)