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_master_get_devdata(spi->master); in au1550_spi_chipsel() local
168 if (hw->pdata->deactivate_cs) in au1550_spi_chipsel()
169 hw->pdata->deactivate_cs(hw->pdata, spi->chip_select, 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->chip_select, in au1550_spi_chipsel()
222 struct au1550_spi *hw = spi_master_get_devdata(spi->master); 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_master_get_devdata(spi->master); 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()
330 dma_tx_addr = dma_map_single(hw->dev, in au1550_spi_dma_txrxb()
333 if (dma_mapping_error(hw->dev, dma_tx_addr)) in au1550_spi_dma_txrxb()
334 dev_err(hw->dev, "tx dma map error\n"); in au1550_spi_dma_txrxb()
340 dma_rx_addr = dma_map_single(hw->dev, in au1550_spi_dma_txrxb()
343 if (dma_mapping_error(hw->dev, dma_rx_addr)) in au1550_spi_dma_txrxb()
344 dev_err(hw->dev, "rx dma map error\n"); in au1550_spi_dma_txrxb()
347 if (t->len > hw->dma_rx_tmpbuf_size) { in au1550_spi_dma_txrxb()
350 au1550_spi_dma_rxtmp_free(hw); in au1550_spi_dma_txrxb()
351 ret = au1550_spi_dma_rxtmp_alloc(hw, max(t->len, in au1550_spi_dma_txrxb()
356 hw->rx = hw->dma_rx_tmpbuf; in au1550_spi_dma_txrxb()
357 dma_rx_addr = hw->dma_rx_tmpbuf_addr; in au1550_spi_dma_txrxb()
358 dma_sync_single_for_device(hw->dev, dma_rx_addr, in au1550_spi_dma_txrxb()
363 dma_sync_single_for_device(hw->dev, dma_rx_addr, in au1550_spi_dma_txrxb()
365 hw->tx = hw->rx; in au1550_spi_dma_txrxb()
369 res = au1xxx_dbdma_put_dest(hw->dma_rx_ch, virt_to_phys(hw->rx), in au1550_spi_dma_txrxb()
372 dev_err(hw->dev, "rx dma put dest error\n"); in au1550_spi_dma_txrxb()
374 res = au1xxx_dbdma_put_source(hw->dma_tx_ch, virt_to_phys(hw->tx), in au1550_spi_dma_txrxb()
377 dev_err(hw->dev, "tx dma put source error\n"); in au1550_spi_dma_txrxb()
379 au1xxx_dbdma_start(hw->dma_rx_ch); in au1550_spi_dma_txrxb()
380 au1xxx_dbdma_start(hw->dma_tx_ch); in au1550_spi_dma_txrxb()
383 hw->regs->psc_spimsk = PSC_SPIMSK_SD; in au1550_spi_dma_txrxb()
387 hw->regs->psc_spipcr = PSC_SPIPCR_MS; in au1550_spi_dma_txrxb()
390 wait_for_completion(&hw->master_done); in au1550_spi_dma_txrxb()
392 au1xxx_dbdma_stop(hw->dma_tx_ch); in au1550_spi_dma_txrxb()
393 au1xxx_dbdma_stop(hw->dma_rx_ch); in au1550_spi_dma_txrxb()
397 dma_sync_single_for_cpu(hw->dev, dma_rx_addr, t->len, in au1550_spi_dma_txrxb()
402 dma_unmap_single(hw->dev, dma_rx_addr, t->len, in au1550_spi_dma_txrxb()
405 dma_unmap_single(hw->dev, dma_tx_addr, t->len, in au1550_spi_dma_txrxb()
408 return min(hw->rx_count, hw->tx_count); in au1550_spi_dma_txrxb()
411 static irqreturn_t au1550_spi_dma_irq_callback(struct au1550_spi *hw) in au1550_spi_dma_irq_callback() argument
415 stat = hw->regs->psc_spistat; in au1550_spi_dma_irq_callback()
416 evnt = hw->regs->psc_spievent; in au1550_spi_dma_irq_callback()
419 dev_err(hw->dev, "Unexpected IRQ!\n"); in au1550_spi_dma_irq_callback()
432 au1550_spi_mask_ack_all(hw); in au1550_spi_dma_irq_callback()
433 au1xxx_dbdma_stop(hw->dma_rx_ch); in au1550_spi_dma_irq_callback()
434 au1xxx_dbdma_stop(hw->dma_tx_ch); in au1550_spi_dma_irq_callback()
437 hw->rx_count = hw->len - au1xxx_get_dma_residue(hw->dma_rx_ch); in au1550_spi_dma_irq_callback()
438 hw->tx_count = hw->len - au1xxx_get_dma_residue(hw->dma_tx_ch); in au1550_spi_dma_irq_callback()
440 au1xxx_dbdma_reset(hw->dma_rx_ch); in au1550_spi_dma_irq_callback()
441 au1xxx_dbdma_reset(hw->dma_tx_ch); in au1550_spi_dma_irq_callback()
442 au1550_spi_reset_fifos(hw); in au1550_spi_dma_irq_callback()
445 dev_err(hw->dev, in au1550_spi_dma_irq_callback()
448 dev_err(hw->dev, in au1550_spi_dma_irq_callback()
452 complete(&hw->master_done); in au1550_spi_dma_irq_callback()
458 au1550_spi_mask_ack_all(hw); in au1550_spi_dma_irq_callback()
459 hw->rx_count = hw->len; in au1550_spi_dma_irq_callback()
460 hw->tx_count = hw->len; in au1550_spi_dma_irq_callback()
461 complete(&hw->master_done); in au1550_spi_dma_irq_callback()
469 static void au1550_spi_rx_word_##size(struct au1550_spi *hw) \
471 u32 fifoword = hw->regs->psc_spitxrx & (u32)(mask); \
473 if (hw->rx) { \
474 *(u##size *)hw->rx = (u##size)fifoword; \
475 hw->rx += (size) / 8; \
477 hw->rx_count += (size) / 8; \
481 static void au1550_spi_tx_word_##size(struct au1550_spi *hw) \
484 if (hw->tx) { \
485 fifoword = *(u##size *)hw->tx & (u32)(mask); \
486 hw->tx += (size) / 8; \
488 hw->tx_count += (size) / 8; \
489 if (hw->tx_count >= hw->len) \
491 hw->regs->psc_spitxrx = fifoword; \
505 struct au1550_spi *hw = spi_master_get_devdata(spi->master); in au1550_spi_pio_txrxb() local
507 hw->tx = t->tx_buf; in au1550_spi_pio_txrxb()
508 hw->rx = t->rx_buf; in au1550_spi_pio_txrxb()
509 hw->len = t->len; in au1550_spi_pio_txrxb()
510 hw->tx_count = 0; in au1550_spi_pio_txrxb()
511 hw->rx_count = 0; in au1550_spi_pio_txrxb()
517 while (hw->tx_count < hw->len) { in au1550_spi_pio_txrxb()
519 hw->tx_word(hw); in au1550_spi_pio_txrxb()
521 if (hw->tx_count >= hw->len) { in au1550_spi_pio_txrxb()
526 stat = hw->regs->psc_spistat; in au1550_spi_pio_txrxb()
533 hw->regs->psc_spimsk = mask; in au1550_spi_pio_txrxb()
537 hw->regs->psc_spipcr = PSC_SPIPCR_MS; in au1550_spi_pio_txrxb()
540 wait_for_completion(&hw->master_done); in au1550_spi_pio_txrxb()
542 return min(hw->rx_count, hw->tx_count); in au1550_spi_pio_txrxb()
545 static irqreturn_t au1550_spi_pio_irq_callback(struct au1550_spi *hw) in au1550_spi_pio_irq_callback() argument
550 stat = hw->regs->psc_spistat; in au1550_spi_pio_irq_callback()
551 evnt = hw->regs->psc_spievent; in au1550_spi_pio_irq_callback()
554 dev_err(hw->dev, "Unexpected IRQ!\n"); in au1550_spi_pio_irq_callback()
566 au1550_spi_mask_ack_all(hw); in au1550_spi_pio_irq_callback()
567 au1550_spi_reset_fifos(hw); in au1550_spi_pio_irq_callback()
568 dev_err(hw->dev, in au1550_spi_pio_irq_callback()
571 complete(&hw->master_done); in au1550_spi_pio_irq_callback()
581 stat = hw->regs->psc_spistat; in au1550_spi_pio_irq_callback()
593 if (!(stat & PSC_SPISTAT_RE) && hw->rx_count < hw->len) { in au1550_spi_pio_irq_callback()
594 hw->rx_word(hw); in au1550_spi_pio_irq_callback()
597 if (!(stat & PSC_SPISTAT_TF) && hw->tx_count < hw->len) in au1550_spi_pio_irq_callback()
598 hw->tx_word(hw); in au1550_spi_pio_irq_callback()
602 hw->regs->psc_spievent = PSC_SPIEVNT_RR | PSC_SPIEVNT_TR; in au1550_spi_pio_irq_callback()
621 hw->regs->psc_spievent = PSC_SPIEVNT_TU | PSC_SPIEVNT_MD; in au1550_spi_pio_irq_callback()
623 hw->regs->psc_spipcr = PSC_SPIPCR_MS; in au1550_spi_pio_irq_callback()
627 if (hw->rx_count >= hw->len) { in au1550_spi_pio_irq_callback()
629 au1550_spi_mask_ack_all(hw); in au1550_spi_pio_irq_callback()
630 complete(&hw->master_done); in au1550_spi_pio_irq_callback()
637 struct au1550_spi *hw = spi_master_get_devdata(spi->master); in au1550_spi_txrx_bufs() local
639 return hw->txrx_bufs(spi, t); in au1550_spi_txrx_bufs()
644 struct au1550_spi *hw = dev; in au1550_spi_irq() local
646 return hw->irq_callback(hw); in au1550_spi_irq()
649 static void au1550_spi_bits_handlers_set(struct au1550_spi *hw, int bpw) in au1550_spi_bits_handlers_set() argument
652 if (hw->usedma) { in au1550_spi_bits_handlers_set()
653 hw->txrx_bufs = &au1550_spi_dma_txrxb; in au1550_spi_bits_handlers_set()
654 hw->irq_callback = &au1550_spi_dma_irq_callback; in au1550_spi_bits_handlers_set()
656 hw->rx_word = &au1550_spi_rx_word_8; in au1550_spi_bits_handlers_set()
657 hw->tx_word = &au1550_spi_tx_word_8; in au1550_spi_bits_handlers_set()
658 hw->txrx_bufs = &au1550_spi_pio_txrxb; in au1550_spi_bits_handlers_set()
659 hw->irq_callback = &au1550_spi_pio_irq_callback; in au1550_spi_bits_handlers_set()
662 hw->rx_word = &au1550_spi_rx_word_16; in au1550_spi_bits_handlers_set()
663 hw->tx_word = &au1550_spi_tx_word_16; in au1550_spi_bits_handlers_set()
664 hw->txrx_bufs = &au1550_spi_pio_txrxb; in au1550_spi_bits_handlers_set()
665 hw->irq_callback = &au1550_spi_pio_irq_callback; in au1550_spi_bits_handlers_set()
667 hw->rx_word = &au1550_spi_rx_word_32; in au1550_spi_bits_handlers_set()
668 hw->tx_word = &au1550_spi_tx_word_32; in au1550_spi_bits_handlers_set()
669 hw->txrx_bufs = &au1550_spi_pio_txrxb; in au1550_spi_bits_handlers_set()
670 hw->irq_callback = &au1550_spi_pio_irq_callback; in au1550_spi_bits_handlers_set()
674 static void au1550_spi_setup_psc_as_spi(struct au1550_spi *hw) in au1550_spi_setup_psc_as_spi() argument
679 hw->regs->psc_ctrl = PSC_CTRL_DISABLE; in au1550_spi_setup_psc_as_spi()
681 hw->regs->psc_sel = PSC_SEL_PS_SPIMODE; in au1550_spi_setup_psc_as_spi()
684 hw->regs->psc_spicfg = 0; in au1550_spi_setup_psc_as_spi()
687 hw->regs->psc_ctrl = PSC_CTRL_ENABLE; in au1550_spi_setup_psc_as_spi()
691 stat = hw->regs->psc_spistat; in au1550_spi_setup_psc_as_spi()
696 cfg = hw->usedma ? 0 : PSC_SPICFG_DD_DISABLE; in au1550_spi_setup_psc_as_spi()
706 hw->regs->psc_spicfg = cfg; in au1550_spi_setup_psc_as_spi()
709 au1550_spi_mask_ack_all(hw); in au1550_spi_setup_psc_as_spi()
711 hw->regs->psc_spicfg |= PSC_SPICFG_DE_ENABLE; in au1550_spi_setup_psc_as_spi()
715 stat = hw->regs->psc_spistat; in au1550_spi_setup_psc_as_spi()
719 au1550_spi_reset_fifos(hw); in au1550_spi_setup_psc_as_spi()
725 struct au1550_spi *hw; in au1550_spi_probe() local
741 hw = spi_master_get_devdata(master); in au1550_spi_probe()
743 hw->master = master; in au1550_spi_probe()
744 hw->pdata = dev_get_platdata(&pdev->dev); in au1550_spi_probe()
745 hw->dev = &pdev->dev; in au1550_spi_probe()
747 if (hw->pdata == NULL) { in au1550_spi_probe()
759 hw->irq = r->start; in au1550_spi_probe()
761 hw->usedma = 0; in au1550_spi_probe()
764 hw->dma_tx_id = r->start; in au1550_spi_probe()
767 hw->dma_rx_id = r->start; in au1550_spi_probe()
772 hw->usedma = 1; in au1550_spi_probe()
784 hw->ioarea = request_mem_region(r->start, sizeof(psc_spi_t), in au1550_spi_probe()
786 if (!hw->ioarea) { in au1550_spi_probe()
792 hw->regs = (psc_spi_t __iomem *)ioremap(r->start, sizeof(psc_spi_t)); in au1550_spi_probe()
793 if (!hw->regs) { in au1550_spi_probe()
799 platform_set_drvdata(pdev, hw); in au1550_spi_probe()
801 init_completion(&hw->master_done); in au1550_spi_probe()
803 hw->bitbang.master = hw->master; in au1550_spi_probe()
804 hw->bitbang.setup_transfer = au1550_spi_setupxfer; in au1550_spi_probe()
805 hw->bitbang.chipselect = au1550_spi_chipsel; in au1550_spi_probe()
806 hw->bitbang.txrx_bufs = au1550_spi_txrx_bufs; in au1550_spi_probe()
808 if (hw->usedma) { in au1550_spi_probe()
809 hw->dma_tx_ch = au1xxx_dbdma_chan_alloc(ddma_memid, in au1550_spi_probe()
810 hw->dma_tx_id, NULL, (void *)hw); in au1550_spi_probe()
811 if (hw->dma_tx_ch == 0) { in au1550_spi_probe()
817 au1xxx_dbdma_set_devwidth(hw->dma_tx_ch, 8); in au1550_spi_probe()
818 if (au1xxx_dbdma_ring_alloc(hw->dma_tx_ch, in au1550_spi_probe()
827 hw->dma_rx_ch = au1xxx_dbdma_chan_alloc(hw->dma_rx_id, in au1550_spi_probe()
828 ddma_memid, NULL, (void *)hw); in au1550_spi_probe()
829 if (hw->dma_rx_ch == 0) { in au1550_spi_probe()
835 au1xxx_dbdma_set_devwidth(hw->dma_rx_ch, 8); in au1550_spi_probe()
836 if (au1xxx_dbdma_ring_alloc(hw->dma_rx_ch, in au1550_spi_probe()
844 err = au1550_spi_dma_rxtmp_alloc(hw, in au1550_spi_probe()
853 au1550_spi_bits_handlers_set(hw, 8); in au1550_spi_probe()
855 err = request_irq(hw->irq, au1550_spi_irq, 0, pdev->name, hw); in au1550_spi_probe()
862 master->num_chipselect = hw->pdata->num_chipselect; in au1550_spi_probe()
877 master->max_speed_hz = hw->pdata->mainclk_hz / min_div; in au1550_spi_probe()
879 hw->pdata->mainclk_hz / (max_div + 1) + 1; in au1550_spi_probe()
882 au1550_spi_setup_psc_as_spi(hw); in au1550_spi_probe()
884 err = spi_bitbang_start(&hw->bitbang); in au1550_spi_probe()
897 free_irq(hw->irq, hw); in au1550_spi_probe()
900 au1550_spi_dma_rxtmp_free(hw); in au1550_spi_probe()
904 if (hw->usedma) in au1550_spi_probe()
905 au1xxx_dbdma_chan_free(hw->dma_rx_ch); in au1550_spi_probe()
909 if (hw->usedma) in au1550_spi_probe()
910 au1xxx_dbdma_chan_free(hw->dma_tx_ch); in au1550_spi_probe()
913 iounmap((void __iomem *)hw->regs); in au1550_spi_probe()
920 spi_master_put(hw->master); in au1550_spi_probe()
928 struct au1550_spi *hw = platform_get_drvdata(pdev); in au1550_spi_remove() local
931 hw->master->bus_num); in au1550_spi_remove()
933 spi_bitbang_stop(&hw->bitbang); in au1550_spi_remove()
934 free_irq(hw->irq, hw); in au1550_spi_remove()
935 iounmap((void __iomem *)hw->regs); in au1550_spi_remove()
936 release_mem_region(hw->ioarea->start, sizeof(psc_spi_t)); in au1550_spi_remove()
938 if (hw->usedma) { in au1550_spi_remove()
939 au1550_spi_dma_rxtmp_free(hw); in au1550_spi_remove()
940 au1xxx_dbdma_chan_free(hw->dma_rx_ch); in au1550_spi_remove()
941 au1xxx_dbdma_chan_free(hw->dma_tx_ch); in au1550_spi_remove()
944 spi_master_put(hw->master); in au1550_spi_remove()