Lines Matching full:hw

52 	void (*rx_word)(struct au1550_spi *hw);
53 void (*tx_word)(struct au1550_spi *hw);
55 irqreturn_t (*irq_callback)(struct au1550_spi *hw);
89 static void au1550_spi_bits_handlers_set(struct au1550_spi *hw, int bpw);
101 static u32 au1550_spi_baudcfg(struct au1550_spi *hw, unsigned int speed_hz) in au1550_spi_baudcfg() argument
103 u32 mainclk_hz = hw->pdata->mainclk_hz; in au1550_spi_baudcfg()
124 static inline void au1550_spi_mask_ack_all(struct au1550_spi *hw) in au1550_spi_mask_ack_all() argument
126 hw->regs->psc_spimsk = in au1550_spi_mask_ack_all()
132 hw->regs->psc_spievent = in au1550_spi_mask_ack_all()
139 static void au1550_spi_reset_fifos(struct au1550_spi *hw) in au1550_spi_reset_fifos() argument
143 hw->regs->psc_spipcr = PSC_SPIPCR_RC | PSC_SPIPCR_TC; in au1550_spi_reset_fifos()
146 pcr = hw->regs->psc_spipcr; in au1550_spi_reset_fifos()
162 struct au1550_spi *hw = spi_controller_get_devdata(spi->controller); in au1550_spi_chipsel() local
168 if (hw->pdata->deactivate_cs) in au1550_spi_chipsel()
169 hw->pdata->deactivate_cs(hw->pdata, spi_get_chipselect(spi, 0), in au1550_spi_chipsel()
174 au1550_spi_bits_handlers_set(hw, spi->bits_per_word); in au1550_spi_chipsel()
176 cfg = hw->regs->psc_spicfg; in au1550_spi_chipsel()
178 hw->regs->psc_spicfg = cfg & ~PSC_SPICFG_DE_ENABLE; in au1550_spi_chipsel()
195 if (hw->usedma && spi->bits_per_word <= 8) in au1550_spi_chipsel()
204 cfg |= au1550_spi_baudcfg(hw, spi->max_speed_hz); in au1550_spi_chipsel()
206 hw->regs->psc_spicfg = cfg | PSC_SPICFG_DE_ENABLE; in au1550_spi_chipsel()
209 stat = hw->regs->psc_spistat; in au1550_spi_chipsel()
213 if (hw->pdata->activate_cs) in au1550_spi_chipsel()
214 hw->pdata->activate_cs(hw->pdata, spi_get_chipselect(spi, 0), in au1550_spi_chipsel()
222 struct au1550_spi *hw = spi_controller_get_devdata(spi->controller); in au1550_spi_setupxfer() local
237 au1550_spi_bits_handlers_set(hw, spi->bits_per_word); in au1550_spi_setupxfer()
239 cfg = hw->regs->psc_spicfg; in au1550_spi_setupxfer()
241 hw->regs->psc_spicfg = cfg & ~PSC_SPICFG_DE_ENABLE; in au1550_spi_setupxfer()
244 if (hw->usedma && bpw <= 8) in au1550_spi_setupxfer()
253 cfg |= au1550_spi_baudcfg(hw, hz); in au1550_spi_setupxfer()
255 hw->regs->psc_spicfg = cfg; in au1550_spi_setupxfer()
260 stat = hw->regs->psc_spistat; in au1550_spi_setupxfer()
265 au1550_spi_reset_fifos(hw); in au1550_spi_setupxfer()
266 au1550_spi_mask_ack_all(hw); in au1550_spi_setupxfer()
278 static int au1550_spi_dma_rxtmp_alloc(struct au1550_spi *hw, unsigned int size) in au1550_spi_dma_rxtmp_alloc() argument
280 hw->dma_rx_tmpbuf = kmalloc(size, GFP_KERNEL); in au1550_spi_dma_rxtmp_alloc()
281 if (!hw->dma_rx_tmpbuf) in au1550_spi_dma_rxtmp_alloc()
283 hw->dma_rx_tmpbuf_size = size; in au1550_spi_dma_rxtmp_alloc()
284 hw->dma_rx_tmpbuf_addr = dma_map_single(hw->dev, hw->dma_rx_tmpbuf, in au1550_spi_dma_rxtmp_alloc()
286 if (dma_mapping_error(hw->dev, hw->dma_rx_tmpbuf_addr)) { in au1550_spi_dma_rxtmp_alloc()
287 kfree(hw->dma_rx_tmpbuf); in au1550_spi_dma_rxtmp_alloc()
288 hw->dma_rx_tmpbuf = 0; in au1550_spi_dma_rxtmp_alloc()
289 hw->dma_rx_tmpbuf_size = 0; in au1550_spi_dma_rxtmp_alloc()
295 static void au1550_spi_dma_rxtmp_free(struct au1550_spi *hw) in au1550_spi_dma_rxtmp_free() argument
297 dma_unmap_single(hw->dev, hw->dma_rx_tmpbuf_addr, in au1550_spi_dma_rxtmp_free()
298 hw->dma_rx_tmpbuf_size, DMA_FROM_DEVICE); in au1550_spi_dma_rxtmp_free()
299 kfree(hw->dma_rx_tmpbuf); in au1550_spi_dma_rxtmp_free()
300 hw->dma_rx_tmpbuf = 0; in au1550_spi_dma_rxtmp_free()
301 hw->dma_rx_tmpbuf_size = 0; in au1550_spi_dma_rxtmp_free()
306 struct au1550_spi *hw = spi_controller_get_devdata(spi->controller); in au1550_spi_dma_txrxb() local
311 hw->len = t->len; in au1550_spi_dma_txrxb()
312 hw->tx_count = 0; in au1550_spi_dma_txrxb()
313 hw->rx_count = 0; in au1550_spi_dma_txrxb()
315 hw->tx = t->tx_buf; in au1550_spi_dma_txrxb()
316 hw->rx = t->rx_buf; in au1550_spi_dma_txrxb()
326 dma_tx_addr = dma_map_single(hw->dev, (void *)t->tx_buf, in au1550_spi_dma_txrxb()
328 if (dma_mapping_error(hw->dev, dma_tx_addr)) in au1550_spi_dma_txrxb()
329 dev_err(hw->dev, "tx dma map error\n"); in au1550_spi_dma_txrxb()
333 dma_rx_addr = dma_map_single(hw->dev, (void *)t->rx_buf, in au1550_spi_dma_txrxb()
335 if (dma_mapping_error(hw->dev, dma_rx_addr)) in au1550_spi_dma_txrxb()
336 dev_err(hw->dev, "rx dma map error\n"); in au1550_spi_dma_txrxb()
338 if (t->len > hw->dma_rx_tmpbuf_size) { in au1550_spi_dma_txrxb()
341 au1550_spi_dma_rxtmp_free(hw); in au1550_spi_dma_txrxb()
342 ret = au1550_spi_dma_rxtmp_alloc(hw, max(t->len, in au1550_spi_dma_txrxb()
347 hw->rx = hw->dma_rx_tmpbuf; in au1550_spi_dma_txrxb()
348 dma_rx_addr = hw->dma_rx_tmpbuf_addr; in au1550_spi_dma_txrxb()
349 dma_sync_single_for_device(hw->dev, dma_rx_addr, in au1550_spi_dma_txrxb()
354 dma_sync_single_for_device(hw->dev, dma_rx_addr, in au1550_spi_dma_txrxb()
356 hw->tx = hw->rx; in au1550_spi_dma_txrxb()
360 res = au1xxx_dbdma_put_dest(hw->dma_rx_ch, virt_to_phys(hw->rx), in au1550_spi_dma_txrxb()
363 dev_err(hw->dev, "rx dma put dest error\n"); in au1550_spi_dma_txrxb()
365 res = au1xxx_dbdma_put_source(hw->dma_tx_ch, virt_to_phys(hw->tx), in au1550_spi_dma_txrxb()
368 dev_err(hw->dev, "tx dma put source error\n"); in au1550_spi_dma_txrxb()
370 au1xxx_dbdma_start(hw->dma_rx_ch); in au1550_spi_dma_txrxb()
371 au1xxx_dbdma_start(hw->dma_tx_ch); in au1550_spi_dma_txrxb()
374 hw->regs->psc_spimsk = PSC_SPIMSK_SD; in au1550_spi_dma_txrxb()
378 hw->regs->psc_spipcr = PSC_SPIPCR_MS; in au1550_spi_dma_txrxb()
381 wait_for_completion(&hw->host_done); in au1550_spi_dma_txrxb()
383 au1xxx_dbdma_stop(hw->dma_tx_ch); in au1550_spi_dma_txrxb()
384 au1xxx_dbdma_stop(hw->dma_rx_ch); in au1550_spi_dma_txrxb()
388 dma_sync_single_for_cpu(hw->dev, dma_rx_addr, t->len, in au1550_spi_dma_txrxb()
393 dma_unmap_single(hw->dev, dma_rx_addr, t->len, in au1550_spi_dma_txrxb()
396 dma_unmap_single(hw->dev, dma_tx_addr, t->len, in au1550_spi_dma_txrxb()
399 return min(hw->rx_count, hw->tx_count); in au1550_spi_dma_txrxb()
402 static irqreturn_t au1550_spi_dma_irq_callback(struct au1550_spi *hw) in au1550_spi_dma_irq_callback() argument
406 stat = hw->regs->psc_spistat; in au1550_spi_dma_irq_callback()
407 evnt = hw->regs->psc_spievent; in au1550_spi_dma_irq_callback()
410 dev_err(hw->dev, "Unexpected IRQ!\n"); in au1550_spi_dma_irq_callback()
423 au1550_spi_mask_ack_all(hw); in au1550_spi_dma_irq_callback()
424 au1xxx_dbdma_stop(hw->dma_rx_ch); in au1550_spi_dma_irq_callback()
425 au1xxx_dbdma_stop(hw->dma_tx_ch); in au1550_spi_dma_irq_callback()
428 hw->rx_count = hw->len - au1xxx_get_dma_residue(hw->dma_rx_ch); in au1550_spi_dma_irq_callback()
429 hw->tx_count = hw->len - au1xxx_get_dma_residue(hw->dma_tx_ch); in au1550_spi_dma_irq_callback()
431 au1xxx_dbdma_reset(hw->dma_rx_ch); in au1550_spi_dma_irq_callback()
432 au1xxx_dbdma_reset(hw->dma_tx_ch); in au1550_spi_dma_irq_callback()
433 au1550_spi_reset_fifos(hw); in au1550_spi_dma_irq_callback()
436 dev_err(hw->dev, in au1550_spi_dma_irq_callback()
439 dev_err(hw->dev, in au1550_spi_dma_irq_callback()
443 complete(&hw->host_done); in au1550_spi_dma_irq_callback()
449 au1550_spi_mask_ack_all(hw); in au1550_spi_dma_irq_callback()
450 hw->rx_count = hw->len; in au1550_spi_dma_irq_callback()
451 hw->tx_count = hw->len; in au1550_spi_dma_irq_callback()
452 complete(&hw->host_done); in au1550_spi_dma_irq_callback()
460 static void au1550_spi_rx_word_##size(struct au1550_spi *hw) \
462 u32 fifoword = hw->regs->psc_spitxrx & (u32)(mask); \
464 if (hw->rx) { \
465 *(u##size *)hw->rx = (u##size)fifoword; \
466 hw->rx += (size) / 8; \
468 hw->rx_count += (size) / 8; \
472 static void au1550_spi_tx_word_##size(struct au1550_spi *hw) \
475 if (hw->tx) { \
476 fifoword = *(u##size *)hw->tx & (u32)(mask); \
477 hw->tx += (size) / 8; \
479 hw->tx_count += (size) / 8; \
480 if (hw->tx_count >= hw->len) \
482 hw->regs->psc_spitxrx = fifoword; \
496 struct au1550_spi *hw = spi_controller_get_devdata(spi->controller); in au1550_spi_pio_txrxb() local
498 hw->tx = t->tx_buf; in au1550_spi_pio_txrxb()
499 hw->rx = t->rx_buf; in au1550_spi_pio_txrxb()
500 hw->len = t->len; in au1550_spi_pio_txrxb()
501 hw->tx_count = 0; in au1550_spi_pio_txrxb()
502 hw->rx_count = 0; in au1550_spi_pio_txrxb()
508 while (hw->tx_count < hw->len) { in au1550_spi_pio_txrxb()
510 hw->tx_word(hw); in au1550_spi_pio_txrxb()
512 if (hw->tx_count >= hw->len) { in au1550_spi_pio_txrxb()
517 stat = hw->regs->psc_spistat; in au1550_spi_pio_txrxb()
524 hw->regs->psc_spimsk = mask; in au1550_spi_pio_txrxb()
528 hw->regs->psc_spipcr = PSC_SPIPCR_MS; in au1550_spi_pio_txrxb()
531 wait_for_completion(&hw->host_done); in au1550_spi_pio_txrxb()
533 return min(hw->rx_count, hw->tx_count); in au1550_spi_pio_txrxb()
536 static irqreturn_t au1550_spi_pio_irq_callback(struct au1550_spi *hw) in au1550_spi_pio_irq_callback() argument
541 stat = hw->regs->psc_spistat; in au1550_spi_pio_irq_callback()
542 evnt = hw->regs->psc_spievent; in au1550_spi_pio_irq_callback()
545 dev_err(hw->dev, "Unexpected IRQ!\n"); in au1550_spi_pio_irq_callback()
557 au1550_spi_mask_ack_all(hw); in au1550_spi_pio_irq_callback()
558 au1550_spi_reset_fifos(hw); in au1550_spi_pio_irq_callback()
559 dev_err(hw->dev, in au1550_spi_pio_irq_callback()
562 complete(&hw->host_done); in au1550_spi_pio_irq_callback()
572 stat = hw->regs->psc_spistat; in au1550_spi_pio_irq_callback()
584 if (!(stat & PSC_SPISTAT_RE) && hw->rx_count < hw->len) { in au1550_spi_pio_irq_callback()
585 hw->rx_word(hw); in au1550_spi_pio_irq_callback()
588 if (!(stat & PSC_SPISTAT_TF) && hw->tx_count < hw->len) in au1550_spi_pio_irq_callback()
589 hw->tx_word(hw); in au1550_spi_pio_irq_callback()
593 hw->regs->psc_spievent = PSC_SPIEVNT_RR | PSC_SPIEVNT_TR; in au1550_spi_pio_irq_callback()
612 hw->regs->psc_spievent = PSC_SPIEVNT_TU | PSC_SPIEVNT_MD; in au1550_spi_pio_irq_callback()
614 hw->regs->psc_spipcr = PSC_SPIPCR_MS; in au1550_spi_pio_irq_callback()
618 if (hw->rx_count >= hw->len) { in au1550_spi_pio_irq_callback()
620 au1550_spi_mask_ack_all(hw); in au1550_spi_pio_irq_callback()
621 complete(&hw->host_done); in au1550_spi_pio_irq_callback()
628 struct au1550_spi *hw = spi_controller_get_devdata(spi->controller); in au1550_spi_txrx_bufs() local
630 return hw->txrx_bufs(spi, t); in au1550_spi_txrx_bufs()
635 struct au1550_spi *hw = dev; in au1550_spi_irq() local
637 return hw->irq_callback(hw); in au1550_spi_irq()
640 static void au1550_spi_bits_handlers_set(struct au1550_spi *hw, int bpw) in au1550_spi_bits_handlers_set() argument
643 if (hw->usedma) { in au1550_spi_bits_handlers_set()
644 hw->txrx_bufs = &au1550_spi_dma_txrxb; in au1550_spi_bits_handlers_set()
645 hw->irq_callback = &au1550_spi_dma_irq_callback; in au1550_spi_bits_handlers_set()
647 hw->rx_word = &au1550_spi_rx_word_8; in au1550_spi_bits_handlers_set()
648 hw->tx_word = &au1550_spi_tx_word_8; in au1550_spi_bits_handlers_set()
649 hw->txrx_bufs = &au1550_spi_pio_txrxb; in au1550_spi_bits_handlers_set()
650 hw->irq_callback = &au1550_spi_pio_irq_callback; in au1550_spi_bits_handlers_set()
653 hw->rx_word = &au1550_spi_rx_word_16; in au1550_spi_bits_handlers_set()
654 hw->tx_word = &au1550_spi_tx_word_16; in au1550_spi_bits_handlers_set()
655 hw->txrx_bufs = &au1550_spi_pio_txrxb; in au1550_spi_bits_handlers_set()
656 hw->irq_callback = &au1550_spi_pio_irq_callback; in au1550_spi_bits_handlers_set()
658 hw->rx_word = &au1550_spi_rx_word_32; in au1550_spi_bits_handlers_set()
659 hw->tx_word = &au1550_spi_tx_word_32; in au1550_spi_bits_handlers_set()
660 hw->txrx_bufs = &au1550_spi_pio_txrxb; in au1550_spi_bits_handlers_set()
661 hw->irq_callback = &au1550_spi_pio_irq_callback; in au1550_spi_bits_handlers_set()
665 static void au1550_spi_setup_psc_as_spi(struct au1550_spi *hw) in au1550_spi_setup_psc_as_spi() argument
670 hw->regs->psc_ctrl = PSC_CTRL_DISABLE; in au1550_spi_setup_psc_as_spi()
672 hw->regs->psc_sel = PSC_SEL_PS_SPIMODE; in au1550_spi_setup_psc_as_spi()
675 hw->regs->psc_spicfg = 0; in au1550_spi_setup_psc_as_spi()
678 hw->regs->psc_ctrl = PSC_CTRL_ENABLE; in au1550_spi_setup_psc_as_spi()
682 stat = hw->regs->psc_spistat; in au1550_spi_setup_psc_as_spi()
687 cfg = hw->usedma ? 0 : PSC_SPICFG_DD_DISABLE; in au1550_spi_setup_psc_as_spi()
697 hw->regs->psc_spicfg = cfg; in au1550_spi_setup_psc_as_spi()
700 au1550_spi_mask_ack_all(hw); in au1550_spi_setup_psc_as_spi()
702 hw->regs->psc_spicfg |= PSC_SPICFG_DE_ENABLE; in au1550_spi_setup_psc_as_spi()
706 stat = hw->regs->psc_spistat; in au1550_spi_setup_psc_as_spi()
710 au1550_spi_reset_fifos(hw); in au1550_spi_setup_psc_as_spi()
716 struct au1550_spi *hw; in au1550_spi_probe() local
732 hw = spi_controller_get_devdata(host); in au1550_spi_probe()
734 hw->host = host; in au1550_spi_probe()
735 hw->pdata = dev_get_platdata(&pdev->dev); in au1550_spi_probe()
736 hw->dev = &pdev->dev; in au1550_spi_probe()
738 if (hw->pdata == NULL) { in au1550_spi_probe()
750 hw->irq = r->start; in au1550_spi_probe()
752 hw->usedma = 0; in au1550_spi_probe()
755 hw->dma_tx_id = r->start; in au1550_spi_probe()
758 hw->dma_rx_id = r->start; in au1550_spi_probe()
763 hw->usedma = 1; in au1550_spi_probe()
775 hw->ioarea = request_mem_region(r->start, sizeof(psc_spi_t), in au1550_spi_probe()
777 if (!hw->ioarea) { in au1550_spi_probe()
783 hw->regs = (psc_spi_t __iomem *)ioremap(r->start, sizeof(psc_spi_t)); in au1550_spi_probe()
784 if (!hw->regs) { in au1550_spi_probe()
790 platform_set_drvdata(pdev, hw); in au1550_spi_probe()
792 init_completion(&hw->host_done); in au1550_spi_probe()
794 hw->bitbang.ctlr = hw->host; in au1550_spi_probe()
795 hw->bitbang.setup_transfer = au1550_spi_setupxfer; in au1550_spi_probe()
796 hw->bitbang.chipselect = au1550_spi_chipsel; in au1550_spi_probe()
797 hw->bitbang.txrx_bufs = au1550_spi_txrx_bufs; in au1550_spi_probe()
799 if (hw->usedma) { in au1550_spi_probe()
800 hw->dma_tx_ch = au1xxx_dbdma_chan_alloc(ddma_memid, in au1550_spi_probe()
801 hw->dma_tx_id, NULL, (void *)hw); in au1550_spi_probe()
802 if (hw->dma_tx_ch == 0) { in au1550_spi_probe()
808 au1xxx_dbdma_set_devwidth(hw->dma_tx_ch, 8); in au1550_spi_probe()
809 if (au1xxx_dbdma_ring_alloc(hw->dma_tx_ch, in au1550_spi_probe()
818 hw->dma_rx_ch = au1xxx_dbdma_chan_alloc(hw->dma_rx_id, in au1550_spi_probe()
819 ddma_memid, NULL, (void *)hw); in au1550_spi_probe()
820 if (hw->dma_rx_ch == 0) { in au1550_spi_probe()
826 au1xxx_dbdma_set_devwidth(hw->dma_rx_ch, 8); in au1550_spi_probe()
827 if (au1xxx_dbdma_ring_alloc(hw->dma_rx_ch, in au1550_spi_probe()
835 err = au1550_spi_dma_rxtmp_alloc(hw, in au1550_spi_probe()
844 au1550_spi_bits_handlers_set(hw, 8); in au1550_spi_probe()
846 err = request_irq(hw->irq, au1550_spi_irq, 0, pdev->name, hw); in au1550_spi_probe()
853 host->num_chipselect = hw->pdata->num_chipselect; in au1550_spi_probe()
868 host->max_speed_hz = hw->pdata->mainclk_hz / min_div; in au1550_spi_probe()
870 hw->pdata->mainclk_hz / (max_div + 1) + 1; in au1550_spi_probe()
873 au1550_spi_setup_psc_as_spi(hw); in au1550_spi_probe()
875 err = spi_bitbang_start(&hw->bitbang); in au1550_spi_probe()
888 free_irq(hw->irq, hw); in au1550_spi_probe()
891 au1550_spi_dma_rxtmp_free(hw); in au1550_spi_probe()
895 if (hw->usedma) in au1550_spi_probe()
896 au1xxx_dbdma_chan_free(hw->dma_rx_ch); in au1550_spi_probe()
900 if (hw->usedma) in au1550_spi_probe()
901 au1xxx_dbdma_chan_free(hw->dma_tx_ch); in au1550_spi_probe()
904 iounmap((void __iomem *)hw->regs); in au1550_spi_probe()
911 spi_controller_put(hw->host); in au1550_spi_probe()
919 struct au1550_spi *hw = platform_get_drvdata(pdev); in au1550_spi_remove() local
922 hw->host->bus_num); in au1550_spi_remove()
924 spi_bitbang_stop(&hw->bitbang); in au1550_spi_remove()
925 free_irq(hw->irq, hw); in au1550_spi_remove()
926 iounmap((void __iomem *)hw->regs); in au1550_spi_remove()
927 release_mem_region(hw->ioarea->start, sizeof(psc_spi_t)); in au1550_spi_remove()
929 if (hw->usedma) { in au1550_spi_remove()
930 au1550_spi_dma_rxtmp_free(hw); in au1550_spi_remove()
931 au1xxx_dbdma_chan_free(hw->dma_rx_ch); in au1550_spi_remove()
932 au1xxx_dbdma_chan_free(hw->dma_tx_ch); in au1550_spi_remove()
935 spi_controller_put(hw->host); in au1550_spi_remove()