Lines Matching +full:poll +full:- +full:timeout +full:- +full:ms

1 // SPDX-License-Identifier: GPL-2.0
7 // Based on spi-sifive.c, Copyright 2018 SiFive, Inc.
114 * intra-word delay is 0xffff refclocks. So the maximum time a transfer
117 * (0x7ff * 32 + 0xffff) * 16 / 24e6 Hz ~= 87ms
119 * Double it and round it up to 200ms for good measure.
126 struct completion done; /* wake-up from interrupt */
131 writel_relaxed(value, spi->regs + offset); in reg_write()
136 return readl_relaxed(spi->regs + offset); in reg_read()
150 /* Set CS high (inactive) and disable override and auto-CS */ in apple_spi_init()
176 struct spi_device *device = msg->spi; in apple_spi_prepare_message()
178 u32 cfg = ((device->mode & SPI_CPHA ? APPLE_SPI_CFG_CPHA : 0) | in apple_spi_prepare_message()
179 (device->mode & SPI_CPOL ? APPLE_SPI_CFG_CPOL : 0) | in apple_spi_prepare_message()
180 (device->mode & SPI_LSB_FIRST ? APPLE_SPI_CFG_LSB_FIRST : 0)); in apple_spi_prepare_message()
191 struct apple_spi *spi = spi_controller_get_devdata(device->controller); in apple_spi_set_cs()
201 cr = DIV_ROUND_UP(clk_get_rate(spi->clk), t->speed_hz); in apple_spi_prep_transfer()
206 FIELD_PREP(APPLE_SPI_SHIFTCFG_BITS, t->bits_per_word)); in apple_spi_prep_transfer()
208 /* We will want to poll if the time we need to wait is in apple_spi_prep_transfer()
211 * bits_per_word * fifo_threshold / hz <= 5 * 10^-6 in apple_spi_prep_transfer()
215 return (200000 * t->bits_per_word * fifo_threshold) <= t->speed_hz; in apple_spi_prep_transfer()
228 complete(&spi->done); in apple_spi_irq()
235 static int apple_spi_wait(struct apple_spi *spi, u32 fifo_bit, u32 xfer_bit, int poll) in apple_spi_wait() argument
239 if (poll) { in apple_spi_wait()
241 unsigned long timeout = jiffies + APPLE_SPI_TIMEOUT_MS * HZ / 1000; in apple_spi_wait() local
246 if (time_after(jiffies, timeout)) { in apple_spi_wait()
247 ret = -ETIMEDOUT; in apple_spi_wait()
252 reinit_completion(&spi->done); in apple_spi_wait()
256 if (!wait_for_completion_timeout(&spi->done, in apple_spi_wait()
258 ret = -ETIMEDOUT; in apple_spi_wait()
276 words = wrote = min_t(u32, *left, APPLE_SPI_FIFO_DEPTH - inuse); in apple_spi_tx()
281 *left -= words; in apple_spi_tx()
287 while (words--) in apple_spi_tx()
294 while (words--) in apple_spi_tx()
301 while (words--) in apple_spi_tx()
326 *left -= min_t(u32, *left, words); in apple_spi_rx()
332 while (words--) in apple_spi_rx()
339 while (words--) in apple_spi_rx()
346 while (words--) in apple_spi_rx()
361 bool poll = apple_spi_prep_transfer(spi, t); in apple_spi_transfer_one() local
362 const void *tx_ptr = t->tx_buf; in apple_spi_transfer_one()
363 void *rx_ptr = t->rx_buf; in apple_spi_transfer_one()
371 if (t->bits_per_word > 16) in apple_spi_transfer_one()
373 else if (t->bits_per_word > 8) in apple_spi_transfer_one()
378 words = t->len / bytes_per_word; in apple_spi_transfer_one()
417 ret = apple_spi_wait(spi, fifo_flags, xfer_flags, poll); in apple_spi_transfer_one()
419 dev_err(&ctlr->dev, "transfer timed out (remaining %d tx, %d rx)\n", in apple_spi_transfer_one()
436 while (remaining_rx && retries--) in apple_spi_transfer_one()
440 dev_err(&ctlr->dev, "transfer completed with %d words left to transmit\n", in apple_spi_transfer_one()
443 dev_err(&ctlr->dev, "transfer completed with %d words left to receive\n", in apple_spi_transfer_one()
463 ctlr = devm_spi_alloc_host(&pdev->dev, sizeof(struct apple_spi)); in apple_spi_probe()
465 return -ENOMEM; in apple_spi_probe()
468 init_completion(&spi->done); in apple_spi_probe()
470 spi->regs = devm_platform_ioremap_resource(pdev, 0); in apple_spi_probe()
471 if (IS_ERR(spi->regs)) in apple_spi_probe()
472 return PTR_ERR(spi->regs); in apple_spi_probe()
474 spi->clk = devm_clk_get_enabled(&pdev->dev, NULL); in apple_spi_probe()
475 if (IS_ERR(spi->clk)) in apple_spi_probe()
476 return dev_err_probe(&pdev->dev, PTR_ERR(spi->clk), in apple_spi_probe()
483 ret = devm_request_irq(&pdev->dev, irq, apple_spi_irq, 0, in apple_spi_probe()
484 dev_name(&pdev->dev), spi); in apple_spi_probe()
486 return dev_err_probe(&pdev->dev, ret, "Unable to bind to interrupt\n"); in apple_spi_probe()
488 ctlr->dev.of_node = pdev->dev.of_node; in apple_spi_probe()
489 ctlr->bus_num = pdev->id; in apple_spi_probe()
490 ctlr->num_chipselect = 1; in apple_spi_probe()
491 ctlr->mode_bits = SPI_CPHA | SPI_CPOL | SPI_LSB_FIRST; in apple_spi_probe()
492 ctlr->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); in apple_spi_probe()
493 ctlr->prepare_message = apple_spi_prepare_message; in apple_spi_probe()
494 ctlr->set_cs = apple_spi_set_cs; in apple_spi_probe()
495 ctlr->transfer_one = apple_spi_transfer_one; in apple_spi_probe()
496 ctlr->use_gpio_descriptors = true; in apple_spi_probe()
497 ctlr->auto_runtime_pm = true; in apple_spi_probe()
499 pm_runtime_set_active(&pdev->dev); in apple_spi_probe()
500 ret = devm_pm_runtime_enable(&pdev->dev); in apple_spi_probe()
506 ret = devm_spi_register_controller(&pdev->dev, ctlr); in apple_spi_probe()
508 return dev_err_probe(&pdev->dev, ret, "devm_spi_register_controller failed\n"); in apple_spi_probe()
522 .name = "apple-spi",