Lines Matching +full:spi +full:- +full:tx +full:- +full:delay +full:- +full:us

2  * Driver for Cirrus Logic EP93xx SPI controller.
4 * Copyright (C) 2010-2011 Mika Westerberg
6 * Explicit FIFO handling code was inspired by amba-pl022 driver.
8 * Chip select support using other than built-in GPIOs by H. Hartley Sweeten.
10 * For more information about the SPI controller see documentation on Cirrus
22 #include <linux/delay.h>
32 #include <linux/spi/spi.h>
68 /* maximum depth of RX/TX FIFO */
72 * struct ep93xx_spi - EP93xx SPI controller structure
88 * @tx: current byte in transfer to transmit
90 * @fifo_level: how full is FIFO (%0..%SPI_FIFO_SIZE - %1). Receiving one
93 * @dma_tx: TX DMA channel
95 * @dma_tx_data: TX parameters passed to the DMA engine
97 * @tx_sgt: sg table for TX transfers
98 * @zeropage: dummy page used as RX buffer when only TX buffer is passed in by
101 * This structure holds EP93xx SPI controller specific information. When
126 size_t tx; member
139 * struct ep93xx_spi_chip - SPI device hardware settings
140 * @spi: back pointer to the SPI device
142 * @div_cpsr: cpsr (pre-scaler) divider
144 * @dss: bits per word (4 - 16 bits)
148 * SPI device. Settings are written to hardware by function
152 const struct spi_device *spi; member
161 #define bits_per_word_to_dss(bpw) ((bpw) - 1)
166 __raw_writeb(value, espi->regs_base + reg); in ep93xx_spi_write_u8()
170 ep93xx_spi_read_u8(const struct ep93xx_spi *spi, u16 reg) in ep93xx_spi_read_u8() argument
172 return __raw_readb(spi->regs_base + reg); in ep93xx_spi_read_u8()
178 __raw_writew(value, espi->regs_base + reg); in ep93xx_spi_write_u16()
182 ep93xx_spi_read_u16(const struct ep93xx_spi *spi, u16 reg) in ep93xx_spi_read_u16() argument
184 return __raw_readw(spi->regs_base + reg); in ep93xx_spi_read_u16()
192 err = clk_enable(espi->clk); in ep93xx_spi_enable()
211 clk_disable(espi->clk); in ep93xx_spi_disable()
233 * ep93xx_spi_calc_divisors() - calculates SPI clock divisors
234 * @espi: ep93xx SPI controller struct
236 * @rate: desired SPI output clock rate
238 * Function calculates cpsr (clock pre-scaler) and scr divisors based on
239 * given @rate and places them to @chip->div_cpsr and @chip->div_scr. If,
241 * %-EINVAL is returned.
247 unsigned long spi_clk_rate = clk_get_rate(espi->clk); in ep93xx_spi_calc_divisors()
255 rate = clamp(rate, espi->min_rate, espi->max_rate); in ep93xx_spi_calc_divisors()
268 chip->div_scr = (u8)scr; in ep93xx_spi_calc_divisors()
269 chip->div_cpsr = (u8)cpsr; in ep93xx_spi_calc_divisors()
275 return -EINVAL; in ep93xx_spi_calc_divisors()
278 static void ep93xx_spi_cs_control(struct spi_device *spi, bool control) in ep93xx_spi_cs_control() argument
280 struct ep93xx_spi_chip *chip = spi_get_ctldata(spi); in ep93xx_spi_cs_control()
281 int value = (spi->mode & SPI_CS_HIGH) ? control : !control; in ep93xx_spi_cs_control()
283 if (chip->ops && chip->ops->cs_control) in ep93xx_spi_cs_control()
284 chip->ops->cs_control(spi, value); in ep93xx_spi_cs_control()
288 * ep93xx_spi_setup() - setup an SPI device
289 * @spi: SPI device to setup
291 * This function sets up SPI device mode, speed etc. Can be called multiple
296 static int ep93xx_spi_setup(struct spi_device *spi) in ep93xx_spi_setup() argument
298 struct ep93xx_spi *espi = spi_master_get_devdata(spi->master); in ep93xx_spi_setup()
301 if (spi->bits_per_word < 4 || spi->bits_per_word > 16) { in ep93xx_spi_setup()
302 dev_err(&espi->pdev->dev, "invalid bits per word %d\n", in ep93xx_spi_setup()
303 spi->bits_per_word); in ep93xx_spi_setup()
304 return -EINVAL; in ep93xx_spi_setup()
307 chip = spi_get_ctldata(spi); in ep93xx_spi_setup()
309 dev_dbg(&espi->pdev->dev, "initial setup for %s\n", in ep93xx_spi_setup()
310 spi->modalias); in ep93xx_spi_setup()
314 return -ENOMEM; in ep93xx_spi_setup()
316 chip->spi = spi; in ep93xx_spi_setup()
317 chip->ops = spi->controller_data; in ep93xx_spi_setup()
319 if (chip->ops && chip->ops->setup) { in ep93xx_spi_setup()
320 int ret = chip->ops->setup(spi); in ep93xx_spi_setup()
327 spi_set_ctldata(spi, chip); in ep93xx_spi_setup()
330 if (spi->max_speed_hz != chip->rate) { in ep93xx_spi_setup()
333 err = ep93xx_spi_calc_divisors(espi, chip, spi->max_speed_hz); in ep93xx_spi_setup()
335 spi_set_ctldata(spi, NULL); in ep93xx_spi_setup()
339 chip->rate = spi->max_speed_hz; in ep93xx_spi_setup()
342 chip->dss = bits_per_word_to_dss(spi->bits_per_word); in ep93xx_spi_setup()
344 ep93xx_spi_cs_control(spi, false); in ep93xx_spi_setup()
349 * ep93xx_spi_transfer() - queue message to be transferred
350 * @spi: target SPI device
353 * This function is called by SPI device drivers when they are going to transfer
359 static int ep93xx_spi_transfer(struct spi_device *spi, struct spi_message *msg) in ep93xx_spi_transfer() argument
361 struct ep93xx_spi *espi = spi_master_get_devdata(spi->master); in ep93xx_spi_transfer()
365 if (!msg || !msg->complete) in ep93xx_spi_transfer()
366 return -EINVAL; in ep93xx_spi_transfer()
369 list_for_each_entry(t, &msg->transfers, transfer_list) { in ep93xx_spi_transfer()
370 if (t->bits_per_word) { in ep93xx_spi_transfer()
371 if (t->bits_per_word < 4 || t->bits_per_word > 16) in ep93xx_spi_transfer()
372 return -EINVAL; in ep93xx_spi_transfer()
374 if (t->speed_hz && t->speed_hz < espi->min_rate) in ep93xx_spi_transfer()
375 return -EINVAL; in ep93xx_spi_transfer()
380 * suitable for us. We use @msg->status to signal whether there was in ep93xx_spi_transfer()
381 * error in transfer and @msg->state is used to hold pointer to the in ep93xx_spi_transfer()
384 msg->state = NULL; in ep93xx_spi_transfer()
385 msg->status = 0; in ep93xx_spi_transfer()
386 msg->actual_length = 0; in ep93xx_spi_transfer()
388 spin_lock_irqsave(&espi->lock, flags); in ep93xx_spi_transfer()
389 if (!espi->running) { in ep93xx_spi_transfer()
390 spin_unlock_irqrestore(&espi->lock, flags); in ep93xx_spi_transfer()
391 return -ESHUTDOWN; in ep93xx_spi_transfer()
393 list_add_tail(&msg->queue, &espi->msg_queue); in ep93xx_spi_transfer()
394 queue_work(espi->wq, &espi->msg_work); in ep93xx_spi_transfer()
395 spin_unlock_irqrestore(&espi->lock, flags); in ep93xx_spi_transfer()
401 * ep93xx_spi_cleanup() - cleans up master controller specific state
402 * @spi: SPI device to cleanup
404 * This function releases master controller specific state for given @spi
407 static void ep93xx_spi_cleanup(struct spi_device *spi) in ep93xx_spi_cleanup() argument
411 chip = spi_get_ctldata(spi); in ep93xx_spi_cleanup()
413 if (chip->ops && chip->ops->cleanup) in ep93xx_spi_cleanup()
414 chip->ops->cleanup(spi); in ep93xx_spi_cleanup()
415 spi_set_ctldata(spi, NULL); in ep93xx_spi_cleanup()
421 * ep93xx_spi_chip_setup() - configures hardware according to given @chip
422 * @espi: ep93xx SPI controller struct
434 cr0 = chip->div_scr << SSPCR0_SCR_SHIFT; in ep93xx_spi_chip_setup()
435 cr0 |= (chip->spi->mode & (SPI_CPHA|SPI_CPOL)) << SSPCR0_MODE_SHIFT; in ep93xx_spi_chip_setup()
436 cr0 |= chip->dss; in ep93xx_spi_chip_setup()
438 dev_dbg(&espi->pdev->dev, "setup: mode %d, cpsr %d, scr %d, dss %d\n", in ep93xx_spi_chip_setup()
439 chip->spi->mode, chip->div_cpsr, chip->div_scr, chip->dss); in ep93xx_spi_chip_setup()
440 dev_dbg(&espi->pdev->dev, "setup: cr0 %#x", cr0); in ep93xx_spi_chip_setup()
442 ep93xx_spi_write_u8(espi, SSPCPSR, chip->div_cpsr); in ep93xx_spi_chip_setup()
448 struct spi_message *msg = espi->current_msg; in bits_per_word()
449 struct spi_transfer *t = msg->state; in bits_per_word()
451 return t->bits_per_word ? t->bits_per_word : msg->spi->bits_per_word; in bits_per_word()
459 if (t->tx_buf) in ep93xx_do_write()
460 tx_val = ((u16 *)t->tx_buf)[espi->tx]; in ep93xx_do_write()
462 espi->tx += sizeof(tx_val); in ep93xx_do_write()
466 if (t->tx_buf) in ep93xx_do_write()
467 tx_val = ((u8 *)t->tx_buf)[espi->tx]; in ep93xx_do_write()
469 espi->tx += sizeof(tx_val); in ep93xx_do_write()
479 if (t->rx_buf) in ep93xx_do_read()
480 ((u16 *)t->rx_buf)[espi->rx] = rx_val; in ep93xx_do_read()
481 espi->rx += sizeof(rx_val); in ep93xx_do_read()
486 if (t->rx_buf) in ep93xx_do_read()
487 ((u8 *)t->rx_buf)[espi->rx] = rx_val; in ep93xx_do_read()
488 espi->rx += sizeof(rx_val); in ep93xx_do_read()
493 * ep93xx_spi_read_write() - perform next RX/TX transfer
494 * @espi: ep93xx SPI controller struct
496 * This function transfers next bytes (or half-words) to/from RX/TX FIFOs. If
498 * %-EINPROGRESS when current transfer was not yet completed otherwise %0.
500 * When this function is finished, RX FIFO should be empty and TX FIFO should be
505 struct spi_message *msg = espi->current_msg; in ep93xx_spi_read_write()
506 struct spi_transfer *t = msg->state; in ep93xx_spi_read_write()
511 espi->fifo_level--; in ep93xx_spi_read_write()
514 /* write as long as TX FIFO has room */ in ep93xx_spi_read_write()
515 while (espi->fifo_level < SPI_FIFO_SIZE && espi->tx < t->len) { in ep93xx_spi_read_write()
517 espi->fifo_level++; in ep93xx_spi_read_write()
520 if (espi->rx == t->len) in ep93xx_spi_read_write()
523 return -EINPROGRESS; in ep93xx_spi_read_write()
529 * Now everything is set up for the current transfer. We prime the TX in ep93xx_spi_pio_transfer()
534 wait_for_completion(&espi->wait); in ep93xx_spi_pio_transfer()
539 * ep93xx_spi_dma_prepare() - prepares a DMA transfer
540 * @espi: ep93xx SPI controller struct
550 struct spi_transfer *t = espi->current_msg->state; in ep93xx_spi_dma_prepare()
559 size_t len = t->len; in ep93xx_spi_dma_prepare()
571 chan = espi->dma_rx; in ep93xx_spi_dma_prepare()
572 buf = t->rx_buf; in ep93xx_spi_dma_prepare()
573 sgt = &espi->rx_sgt; in ep93xx_spi_dma_prepare()
575 conf.src_addr = espi->sspdr_phys; in ep93xx_spi_dma_prepare()
579 chan = espi->dma_tx; in ep93xx_spi_dma_prepare()
580 buf = t->tx_buf; in ep93xx_spi_dma_prepare()
581 sgt = &espi->tx_sgt; in ep93xx_spi_dma_prepare()
583 conf.dst_addr = espi->sspdr_phys; in ep93xx_spi_dma_prepare()
594 * because we are using @espi->zeropage to provide a zero RX buffer in ep93xx_spi_dma_prepare()
595 * for the TX transfers and we have only allocated one page for that. in ep93xx_spi_dma_prepare()
598 * needed. Otherwise we will re-use the current one. Eventually the in ep93xx_spi_dma_prepare()
603 if (nents != sgt->nents) { in ep93xx_spi_dma_prepare()
612 for_each_sg(sgt->sgl, sg, sgt->nents, i) { in ep93xx_spi_dma_prepare()
619 sg_set_page(sg, virt_to_page(espi->zeropage), in ep93xx_spi_dma_prepare()
624 len -= bytes; in ep93xx_spi_dma_prepare()
628 dev_warn(&espi->pdev->dev, "len = %d expected 0!", len); in ep93xx_spi_dma_prepare()
629 return ERR_PTR(-EINVAL); in ep93xx_spi_dma_prepare()
632 nents = dma_map_sg(chan->device->dev, sgt->sgl, sgt->nents, dir); in ep93xx_spi_dma_prepare()
634 return ERR_PTR(-ENOMEM); in ep93xx_spi_dma_prepare()
636 txd = chan->device->device_prep_slave_sg(chan, sgt->sgl, nents, in ep93xx_spi_dma_prepare()
639 dma_unmap_sg(chan->device->dev, sgt->sgl, sgt->nents, dir); in ep93xx_spi_dma_prepare()
640 return ERR_PTR(-ENOMEM); in ep93xx_spi_dma_prepare()
646 * ep93xx_spi_dma_finish() - finishes with a DMA transfer
647 * @espi: ep93xx SPI controller struct
660 chan = espi->dma_rx; in ep93xx_spi_dma_finish()
661 sgt = &espi->rx_sgt; in ep93xx_spi_dma_finish()
663 chan = espi->dma_tx; in ep93xx_spi_dma_finish()
664 sgt = &espi->tx_sgt; in ep93xx_spi_dma_finish()
667 dma_unmap_sg(chan->device->dev, sgt->sgl, sgt->nents, dir); in ep93xx_spi_dma_finish()
677 struct spi_message *msg = espi->current_msg; in ep93xx_spi_dma_transfer()
682 dev_err(&espi->pdev->dev, "DMA RX failed: %ld\n", PTR_ERR(rxd)); in ep93xx_spi_dma_transfer()
683 msg->status = PTR_ERR(rxd); in ep93xx_spi_dma_transfer()
690 dev_err(&espi->pdev->dev, "DMA TX failed: %ld\n", PTR_ERR(rxd)); in ep93xx_spi_dma_transfer()
691 msg->status = PTR_ERR(txd); in ep93xx_spi_dma_transfer()
696 rxd->callback = ep93xx_spi_dma_callback; in ep93xx_spi_dma_transfer()
697 rxd->callback_param = &espi->wait; in ep93xx_spi_dma_transfer()
703 dma_async_issue_pending(espi->dma_rx); in ep93xx_spi_dma_transfer()
704 dma_async_issue_pending(espi->dma_tx); in ep93xx_spi_dma_transfer()
706 wait_for_completion(&espi->wait); in ep93xx_spi_dma_transfer()
713 * ep93xx_spi_process_transfer() - processes one SPI transfer
714 * @espi: ep93xx SPI controller struct
718 * This function processes one SPI transfer given in @t. Function waits until
719 * transfer is complete (may sleep) and updates @msg->status based on whether
726 struct ep93xx_spi_chip *chip = spi_get_ctldata(msg->spi); in ep93xx_spi_process_transfer()
728 msg->state = t; in ep93xx_spi_process_transfer()
735 if (t->speed_hz || t->bits_per_word) { in ep93xx_spi_process_transfer()
738 if (t->speed_hz) { in ep93xx_spi_process_transfer()
742 t->speed_hz); in ep93xx_spi_process_transfer()
744 dev_err(&espi->pdev->dev, in ep93xx_spi_process_transfer()
746 msg->status = err; in ep93xx_spi_process_transfer()
751 if (t->bits_per_word) in ep93xx_spi_process_transfer()
752 tmp_chip.dss = bits_per_word_to_dss(t->bits_per_word); in ep93xx_spi_process_transfer()
760 espi->rx = 0; in ep93xx_spi_process_transfer()
761 espi->tx = 0; in ep93xx_spi_process_transfer()
768 if (espi->dma_rx && t->len > SPI_FIFO_SIZE) in ep93xx_spi_process_transfer()
777 if (msg->status) in ep93xx_spi_process_transfer()
780 msg->actual_length += t->len; in ep93xx_spi_process_transfer()
784 * post-transfer actions requested by the protocol driver. in ep93xx_spi_process_transfer()
786 if (t->delay_usecs) { in ep93xx_spi_process_transfer()
788 schedule_timeout(usecs_to_jiffies(t->delay_usecs)); in ep93xx_spi_process_transfer()
790 if (t->cs_change) { in ep93xx_spi_process_transfer()
791 if (!list_is_last(&t->transfer_list, &msg->transfers)) { in ep93xx_spi_process_transfer()
793 * In case protocol driver is asking us to drop the in ep93xx_spi_process_transfer()
795 * any "delay" here. in ep93xx_spi_process_transfer()
797 ep93xx_spi_cs_control(msg->spi, false); in ep93xx_spi_process_transfer()
799 ep93xx_spi_cs_control(msg->spi, true); in ep93xx_spi_process_transfer()
803 if (t->speed_hz || t->bits_per_word) in ep93xx_spi_process_transfer()
808 * ep93xx_spi_process_message() - process one SPI message
809 * @espi: ep93xx SPI controller struct
812 * This function processes a single SPI message. We go through all transfers in
816 * @msg->status contains %0 in case of success or negative error code in case of
827 * Enable the SPI controller and its clock. in ep93xx_spi_process_message()
831 dev_err(&espi->pdev->dev, "failed to enable SPI controller\n"); in ep93xx_spi_process_message()
832 msg->status = err; in ep93xx_spi_process_message()
842 dev_warn(&espi->pdev->dev, in ep93xx_spi_process_message()
844 msg->status = -ETIMEDOUT; in ep93xx_spi_process_message()
851 * We explicitly handle FIFO level. This way we don't have to check TX in ep93xx_spi_process_message()
854 espi->fifo_level = 0; in ep93xx_spi_process_message()
857 * Update SPI controller registers according to spi device and assert in ep93xx_spi_process_message()
860 ep93xx_spi_chip_setup(espi, spi_get_ctldata(msg->spi)); in ep93xx_spi_process_message()
861 ep93xx_spi_cs_control(msg->spi, true); in ep93xx_spi_process_message()
863 list_for_each_entry(t, &msg->transfers, transfer_list) { in ep93xx_spi_process_message()
865 if (msg->status) in ep93xx_spi_process_message()
871 * deselect the device and disable the SPI controller. in ep93xx_spi_process_message()
873 ep93xx_spi_cs_control(msg->spi, false); in ep93xx_spi_process_message()
880 * ep93xx_spi_work() - EP93xx SPI workqueue worker function
884 * SPI messages to be processed. Message is taken out from the queue and then
888 * @msg->complete(). In case of error, @msg->status is set to negative error
889 * number, otherwise it contains zero (and @msg->actual_length is updated).
896 spin_lock_irq(&espi->lock); in ep93xx_spi_work()
897 if (!espi->running || espi->current_msg || in ep93xx_spi_work()
898 list_empty(&espi->msg_queue)) { in ep93xx_spi_work()
899 spin_unlock_irq(&espi->lock); in ep93xx_spi_work()
902 msg = list_first_entry(&espi->msg_queue, struct spi_message, queue); in ep93xx_spi_work()
903 list_del_init(&msg->queue); in ep93xx_spi_work()
904 espi->current_msg = msg; in ep93xx_spi_work()
905 spin_unlock_irq(&espi->lock); in ep93xx_spi_work()
910 * Update the current message and re-schedule ourselves if there are in ep93xx_spi_work()
913 spin_lock_irq(&espi->lock); in ep93xx_spi_work()
914 espi->current_msg = NULL; in ep93xx_spi_work()
915 if (espi->running && !list_empty(&espi->msg_queue)) in ep93xx_spi_work()
916 queue_work(espi->wq, &espi->msg_work); in ep93xx_spi_work()
917 spin_unlock_irq(&espi->lock); in ep93xx_spi_work()
920 msg->complete(msg->context); in ep93xx_spi_work()
935 dev_warn(&espi->pdev->dev, in ep93xx_spi_interrupt()
937 espi->current_msg->status = -EIO; in ep93xx_spi_interrupt()
940 * Interrupt is either RX (RIS) or TX (TIS). For both cases we in ep93xx_spi_interrupt()
956 * any post-processing of the message. in ep93xx_spi_interrupt()
959 complete(&espi->wait); in ep93xx_spi_interrupt()
968 chan->private = filter_param; in ep93xx_spi_dma_filter()
977 espi->zeropage = (void *)get_zeroed_page(GFP_KERNEL); in ep93xx_spi_setup_dma()
978 if (!espi->zeropage) in ep93xx_spi_setup_dma()
979 return -ENOMEM; in ep93xx_spi_setup_dma()
984 espi->dma_rx_data.port = EP93XX_DMA_SSP; in ep93xx_spi_setup_dma()
985 espi->dma_rx_data.direction = DMA_DEV_TO_MEM; in ep93xx_spi_setup_dma()
986 espi->dma_rx_data.name = "ep93xx-spi-rx"; in ep93xx_spi_setup_dma()
988 espi->dma_rx = dma_request_channel(mask, ep93xx_spi_dma_filter, in ep93xx_spi_setup_dma()
989 &espi->dma_rx_data); in ep93xx_spi_setup_dma()
990 if (!espi->dma_rx) { in ep93xx_spi_setup_dma()
991 ret = -ENODEV; in ep93xx_spi_setup_dma()
995 espi->dma_tx_data.port = EP93XX_DMA_SSP; in ep93xx_spi_setup_dma()
996 espi->dma_tx_data.direction = DMA_MEM_TO_DEV; in ep93xx_spi_setup_dma()
997 espi->dma_tx_data.name = "ep93xx-spi-tx"; in ep93xx_spi_setup_dma()
999 espi->dma_tx = dma_request_channel(mask, ep93xx_spi_dma_filter, in ep93xx_spi_setup_dma()
1000 &espi->dma_tx_data); in ep93xx_spi_setup_dma()
1001 if (!espi->dma_tx) { in ep93xx_spi_setup_dma()
1002 ret = -ENODEV; in ep93xx_spi_setup_dma()
1009 dma_release_channel(espi->dma_rx); in ep93xx_spi_setup_dma()
1010 espi->dma_rx = NULL; in ep93xx_spi_setup_dma()
1012 free_page((unsigned long)espi->zeropage); in ep93xx_spi_setup_dma()
1019 if (espi->dma_rx) { in ep93xx_spi_release_dma()
1020 dma_release_channel(espi->dma_rx); in ep93xx_spi_release_dma()
1021 sg_free_table(&espi->rx_sgt); in ep93xx_spi_release_dma()
1023 if (espi->dma_tx) { in ep93xx_spi_release_dma()
1024 dma_release_channel(espi->dma_tx); in ep93xx_spi_release_dma()
1025 sg_free_table(&espi->tx_sgt); in ep93xx_spi_release_dma()
1028 if (espi->zeropage) in ep93xx_spi_release_dma()
1029 free_page((unsigned long)espi->zeropage); in ep93xx_spi_release_dma()
1040 info = pdev->dev.platform_data; in ep93xx_spi_probe()
1042 master = spi_alloc_master(&pdev->dev, sizeof(*espi)); in ep93xx_spi_probe()
1044 dev_err(&pdev->dev, "failed to allocate spi master\n"); in ep93xx_spi_probe()
1045 return -ENOMEM; in ep93xx_spi_probe()
1048 master->setup = ep93xx_spi_setup; in ep93xx_spi_probe()
1049 master->transfer = ep93xx_spi_transfer; in ep93xx_spi_probe()
1050 master->cleanup = ep93xx_spi_cleanup; in ep93xx_spi_probe()
1051 master->bus_num = pdev->id; in ep93xx_spi_probe()
1052 master->num_chipselect = info->num_chipselect; in ep93xx_spi_probe()
1053 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; in ep93xx_spi_probe()
1059 espi->clk = clk_get(&pdev->dev, NULL); in ep93xx_spi_probe()
1060 if (IS_ERR(espi->clk)) { in ep93xx_spi_probe()
1061 dev_err(&pdev->dev, "unable to get spi clock\n"); in ep93xx_spi_probe()
1062 error = PTR_ERR(espi->clk); in ep93xx_spi_probe()
1066 spin_lock_init(&espi->lock); in ep93xx_spi_probe()
1067 init_completion(&espi->wait); in ep93xx_spi_probe()
1073 espi->max_rate = clk_get_rate(espi->clk) / 2; in ep93xx_spi_probe()
1074 espi->min_rate = clk_get_rate(espi->clk) / (254 * 256); in ep93xx_spi_probe()
1075 espi->pdev = pdev; in ep93xx_spi_probe()
1077 espi->irq = platform_get_irq(pdev, 0); in ep93xx_spi_probe()
1078 if (espi->irq < 0) { in ep93xx_spi_probe()
1079 error = -EBUSY; in ep93xx_spi_probe()
1080 dev_err(&pdev->dev, "failed to get irq resources\n"); in ep93xx_spi_probe()
1086 dev_err(&pdev->dev, "unable to get iomem resource\n"); in ep93xx_spi_probe()
1087 error = -ENODEV; in ep93xx_spi_probe()
1091 res = request_mem_region(res->start, resource_size(res), pdev->name); in ep93xx_spi_probe()
1093 dev_err(&pdev->dev, "unable to request iomem resources\n"); in ep93xx_spi_probe()
1094 error = -EBUSY; in ep93xx_spi_probe()
1098 espi->sspdr_phys = res->start + SSPDR; in ep93xx_spi_probe()
1099 espi->regs_base = ioremap(res->start, resource_size(res)); in ep93xx_spi_probe()
1100 if (!espi->regs_base) { in ep93xx_spi_probe()
1101 dev_err(&pdev->dev, "failed to map resources\n"); in ep93xx_spi_probe()
1102 error = -ENODEV; in ep93xx_spi_probe()
1106 error = request_irq(espi->irq, ep93xx_spi_interrupt, 0, in ep93xx_spi_probe()
1107 "ep93xx-spi", espi); in ep93xx_spi_probe()
1109 dev_err(&pdev->dev, "failed to request irq\n"); in ep93xx_spi_probe()
1113 if (info->use_dma && ep93xx_spi_setup_dma(espi)) in ep93xx_spi_probe()
1114 dev_warn(&pdev->dev, "DMA setup failed. Falling back to PIO\n"); in ep93xx_spi_probe()
1116 espi->wq = create_singlethread_workqueue("ep93xx_spid"); in ep93xx_spi_probe()
1117 if (!espi->wq) { in ep93xx_spi_probe()
1118 dev_err(&pdev->dev, "unable to create workqueue\n"); in ep93xx_spi_probe()
1121 INIT_WORK(&espi->msg_work, ep93xx_spi_work); in ep93xx_spi_probe()
1122 INIT_LIST_HEAD(&espi->msg_queue); in ep93xx_spi_probe()
1123 espi->running = true; in ep93xx_spi_probe()
1130 dev_err(&pdev->dev, "failed to register SPI master\n"); in ep93xx_spi_probe()
1134 dev_info(&pdev->dev, "EP93xx SPI Controller at 0x%08lx irq %d\n", in ep93xx_spi_probe()
1135 (unsigned long)res->start, espi->irq); in ep93xx_spi_probe()
1140 destroy_workqueue(espi->wq); in ep93xx_spi_probe()
1143 free_irq(espi->irq, espi); in ep93xx_spi_probe()
1145 iounmap(espi->regs_base); in ep93xx_spi_probe()
1147 release_mem_region(res->start, resource_size(res)); in ep93xx_spi_probe()
1149 clk_put(espi->clk); in ep93xx_spi_probe()
1163 spin_lock_irq(&espi->lock); in ep93xx_spi_remove()
1164 espi->running = false; in ep93xx_spi_remove()
1165 spin_unlock_irq(&espi->lock); in ep93xx_spi_remove()
1167 destroy_workqueue(espi->wq); in ep93xx_spi_remove()
1170 * Complete remaining messages with %-ESHUTDOWN status. in ep93xx_spi_remove()
1172 spin_lock_irq(&espi->lock); in ep93xx_spi_remove()
1173 while (!list_empty(&espi->msg_queue)) { in ep93xx_spi_remove()
1176 msg = list_first_entry(&espi->msg_queue, in ep93xx_spi_remove()
1178 list_del_init(&msg->queue); in ep93xx_spi_remove()
1179 msg->status = -ESHUTDOWN; in ep93xx_spi_remove()
1180 spin_unlock_irq(&espi->lock); in ep93xx_spi_remove()
1181 msg->complete(msg->context); in ep93xx_spi_remove()
1182 spin_lock_irq(&espi->lock); in ep93xx_spi_remove()
1184 spin_unlock_irq(&espi->lock); in ep93xx_spi_remove()
1187 free_irq(espi->irq, espi); in ep93xx_spi_remove()
1188 iounmap(espi->regs_base); in ep93xx_spi_remove()
1190 release_mem_region(res->start, resource_size(res)); in ep93xx_spi_remove()
1191 clk_put(espi->clk); in ep93xx_spi_remove()
1200 .name = "ep93xx-spi",
1208 MODULE_DESCRIPTION("EP93xx SPI Controller driver");
1211 MODULE_ALIAS("platform:ep93xx-spi");