Lines Matching full:xspi

116 static void xilinx_spi_tx(struct xilinx_spi *xspi)  in xilinx_spi_tx()  argument
120 if (!xspi->tx_ptr) { in xilinx_spi_tx()
121 xspi->write_fn(0, xspi->regs + XSPI_TXD_OFFSET); in xilinx_spi_tx()
125 switch (xspi->bytes_per_word) { in xilinx_spi_tx()
127 data = *(u8 *)(xspi->tx_ptr); in xilinx_spi_tx()
130 data = *(u16 *)(xspi->tx_ptr); in xilinx_spi_tx()
133 data = *(u32 *)(xspi->tx_ptr); in xilinx_spi_tx()
137 xspi->write_fn(data, xspi->regs + XSPI_TXD_OFFSET); in xilinx_spi_tx()
138 xspi->tx_ptr += xspi->bytes_per_word; in xilinx_spi_tx()
141 static void xilinx_spi_rx(struct xilinx_spi *xspi) in xilinx_spi_rx() argument
143 u32 data = xspi->read_fn(xspi->regs + XSPI_RXD_OFFSET); in xilinx_spi_rx()
145 if (!xspi->rx_ptr) in xilinx_spi_rx()
148 switch (xspi->bytes_per_word) { in xilinx_spi_rx()
150 *(u8 *)(xspi->rx_ptr) = data; in xilinx_spi_rx()
153 *(u16 *)(xspi->rx_ptr) = data; in xilinx_spi_rx()
156 *(u32 *)(xspi->rx_ptr) = data; in xilinx_spi_rx()
160 xspi->rx_ptr += xspi->bytes_per_word; in xilinx_spi_rx()
163 static void xspi_init_hw(struct xilinx_spi *xspi) in xspi_init_hw() argument
165 void __iomem *regs_base = xspi->regs; in xspi_init_hw()
168 xspi->write_fn(XIPIF_V123B_RESET_MASK, in xspi_init_hw()
173 xspi->write_fn(XSPI_INTR_TX_EMPTY, in xspi_init_hw()
176 xspi->write_fn(0, regs_base + XIPIF_V123B_DGIER_OFFSET); in xspi_init_hw()
178 xspi->write_fn(0xffff, regs_base + XSPI_SSR_OFFSET); in xspi_init_hw()
181 xspi->write_fn(XSPI_CR_MANUAL_SSELECT | XSPI_CR_MASTER_MODE | in xspi_init_hw()
188 struct xilinx_spi *xspi = spi_controller_get_devdata(spi->controller); in xilinx_spi_chipselect() local
194 xspi->write_fn(xspi->cs_inactive, xspi->regs + XSPI_SSR_OFFSET); in xilinx_spi_chipselect()
199 cr = xspi->read_fn(xspi->regs + XSPI_CR_OFFSET) & ~XSPI_CR_MODE_MASK; in xilinx_spi_chipselect()
208 xspi->write_fn(cr, xspi->regs + XSPI_CR_OFFSET); in xilinx_spi_chipselect()
215 cs = xspi->cs_inactive; in xilinx_spi_chipselect()
219 xspi->write_fn(cs, xspi->regs + XSPI_SSR_OFFSET); in xilinx_spi_chipselect()
228 struct xilinx_spi *xspi = spi_controller_get_devdata(spi->controller); in xilinx_spi_setup_transfer() local
231 xspi->cs_inactive &= ~BIT(spi_get_chipselect(spi, 0)); in xilinx_spi_setup_transfer()
233 xspi->cs_inactive |= BIT(spi_get_chipselect(spi, 0)); in xilinx_spi_setup_transfer()
240 struct xilinx_spi *xspi = spi_controller_get_devdata(spi->controller); in xilinx_spi_txrx_bufs() local
247 xspi->tx_ptr = t->tx_buf; in xilinx_spi_txrx_bufs()
248 xspi->rx_ptr = t->rx_buf; in xilinx_spi_txrx_bufs()
249 remaining_words = t->len / xspi->bytes_per_word; in xilinx_spi_txrx_bufs()
251 if (xspi->irq >= 0 && in xilinx_spi_txrx_bufs()
252 (xspi->force_irq || remaining_words > xspi->buffer_size)) { in xilinx_spi_txrx_bufs()
256 cr = xspi->read_fn(xspi->regs + XSPI_CR_OFFSET); in xilinx_spi_txrx_bufs()
257 xspi->write_fn(cr | XSPI_CR_TRANS_INHIBIT, in xilinx_spi_txrx_bufs()
258 xspi->regs + XSPI_CR_OFFSET); in xilinx_spi_txrx_bufs()
260 isr = xspi->read_fn(xspi->regs + XIPIF_V123B_IISR_OFFSET); in xilinx_spi_txrx_bufs()
262 xspi->write_fn(isr, in xilinx_spi_txrx_bufs()
263 xspi->regs + XIPIF_V123B_IISR_OFFSET); in xilinx_spi_txrx_bufs()
265 xspi->write_fn(XIPIF_V123B_GINTR_ENABLE, in xilinx_spi_txrx_bufs()
266 xspi->regs + XIPIF_V123B_DGIER_OFFSET); in xilinx_spi_txrx_bufs()
267 reinit_completion(&xspi->done); in xilinx_spi_txrx_bufs()
275 n_words = min(remaining_words, xspi->buffer_size); in xilinx_spi_txrx_bufs()
279 xilinx_spi_tx(xspi); in xilinx_spi_txrx_bufs()
286 xspi->write_fn(cr, xspi->regs + XSPI_CR_OFFSET); in xilinx_spi_txrx_bufs()
287 wait_for_completion(&xspi->done); in xilinx_spi_txrx_bufs()
294 xspi->write_fn(cr | XSPI_CR_TRANS_INHIBIT, in xilinx_spi_txrx_bufs()
295 xspi->regs + XSPI_CR_OFFSET); in xilinx_spi_txrx_bufs()
298 sr = xspi->read_fn(xspi->regs + XSPI_SR_OFFSET); in xilinx_spi_txrx_bufs()
309 xspi_init_hw(xspi); in xilinx_spi_txrx_bufs()
314 xilinx_spi_rx(xspi); in xilinx_spi_txrx_bufs()
319 sr = xspi->read_fn(xspi->regs + XSPI_SR_OFFSET); in xilinx_spi_txrx_bufs()
321 xilinx_spi_rx(xspi); in xilinx_spi_txrx_bufs()
330 xspi->write_fn(0, xspi->regs + XIPIF_V123B_DGIER_OFFSET); in xilinx_spi_txrx_bufs()
331 xspi->write_fn(cr, xspi->regs + XSPI_CR_OFFSET); in xilinx_spi_txrx_bufs()
345 struct xilinx_spi *xspi = dev_id; in xilinx_spi_irq() local
349 ipif_isr = xspi->read_fn(xspi->regs + XIPIF_V123B_IISR_OFFSET); in xilinx_spi_irq()
350 xspi->write_fn(ipif_isr, xspi->regs + XIPIF_V123B_IISR_OFFSET); in xilinx_spi_irq()
353 complete(&xspi->done); in xilinx_spi_irq()
360 static int xilinx_spi_find_buffer_size(struct xilinx_spi *xspi) in xilinx_spi_find_buffer_size() argument
369 xspi->write_fn(XIPIF_V123B_RESET_MASK, in xilinx_spi_find_buffer_size()
370 xspi->regs + XIPIF_V123B_RESETR_OFFSET); in xilinx_spi_find_buffer_size()
374 xspi->write_fn(0, xspi->regs + XSPI_TXD_OFFSET); in xilinx_spi_find_buffer_size()
375 sr = xspi->read_fn(xspi->regs + XSPI_SR_OFFSET); in xilinx_spi_find_buffer_size()
392 struct xilinx_spi *xspi; in xilinx_spi_probe() local
435 xspi = spi_controller_get_devdata(host); in xilinx_spi_probe()
436 xspi->cs_inactive = 0xffffffff; in xilinx_spi_probe()
437 xspi->bitbang.ctlr = host; in xilinx_spi_probe()
438 xspi->bitbang.chipselect = xilinx_spi_chipselect; in xilinx_spi_probe()
439 xspi->bitbang.setup_transfer = xilinx_spi_setup_transfer; in xilinx_spi_probe()
440 xspi->bitbang.txrx_bufs = xilinx_spi_txrx_bufs; in xilinx_spi_probe()
441 init_completion(&xspi->done); in xilinx_spi_probe()
443 xspi->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in xilinx_spi_probe()
444 if (IS_ERR(xspi->regs)) in xilinx_spi_probe()
445 return PTR_ERR(xspi->regs); in xilinx_spi_probe()
458 xspi->read_fn = xspi_read32; in xilinx_spi_probe()
459 xspi->write_fn = xspi_write32; in xilinx_spi_probe()
461 xspi->write_fn(XSPI_CR_LOOP, xspi->regs + XSPI_CR_OFFSET); in xilinx_spi_probe()
462 tmp = xspi->read_fn(xspi->regs + XSPI_CR_OFFSET); in xilinx_spi_probe()
465 xspi->read_fn = xspi_read32_be; in xilinx_spi_probe()
466 xspi->write_fn = xspi_write32_be; in xilinx_spi_probe()
470 xspi->bytes_per_word = bits_per_word / 8; in xilinx_spi_probe()
471 xspi->buffer_size = xilinx_spi_find_buffer_size(xspi); in xilinx_spi_probe()
473 xspi->irq = platform_get_irq(pdev, 0); in xilinx_spi_probe()
474 if (xspi->irq < 0 && xspi->irq != -ENXIO) { in xilinx_spi_probe()
475 return xspi->irq; in xilinx_spi_probe()
476 } else if (xspi->irq >= 0) { in xilinx_spi_probe()
478 ret = devm_request_irq(&pdev->dev, xspi->irq, xilinx_spi_irq, 0, in xilinx_spi_probe()
479 dev_name(&pdev->dev), xspi); in xilinx_spi_probe()
483 xspi->force_irq = force_irq; in xilinx_spi_probe()
487 xspi_init_hw(xspi); in xilinx_spi_probe()
489 ret = spi_bitbang_start(&xspi->bitbang); in xilinx_spi_probe()
495 dev_info(&pdev->dev, "at %pR, irq=%d\n", res, xspi->irq); in xilinx_spi_probe()
509 struct xilinx_spi *xspi = spi_controller_get_devdata(host); in xilinx_spi_remove() local
510 void __iomem *regs_base = xspi->regs; in xilinx_spi_remove()
512 spi_bitbang_stop(&xspi->bitbang); in xilinx_spi_remove()
515 xspi->write_fn(0, regs_base + XIPIF_V123B_IIER_OFFSET); in xilinx_spi_remove()
517 xspi->write_fn(0, regs_base + XIPIF_V123B_DGIER_OFFSET); in xilinx_spi_remove()
519 spi_controller_put(xspi->bitbang.ctlr); in xilinx_spi_remove()