16 #include <linux/module.h>
26 #define XILINX_SPI_NAME "xilinx_spi"
31 #define XSPI_CR_OFFSET 0x60
33 #define XSPI_CR_ENABLE 0x02
34 #define XSPI_CR_MASTER_MODE 0x04
35 #define XSPI_CR_CPOL 0x08
36 #define XSPI_CR_CPHA 0x10
37 #define XSPI_CR_MODE_MASK (XSPI_CR_CPHA | XSPI_CR_CPOL)
38 #define XSPI_CR_TXFIFO_RESET 0x20
39 #define XSPI_CR_RXFIFO_RESET 0x40
40 #define XSPI_CR_MANUAL_SSELECT 0x80
41 #define XSPI_CR_TRANS_INHIBIT 0x100
42 #define XSPI_CR_LSB_FIRST 0x200
44 #define XSPI_SR_OFFSET 0x64
46 #define XSPI_SR_RX_EMPTY_MASK 0x01
47 #define XSPI_SR_RX_FULL_MASK 0x02
48 #define XSPI_SR_TX_EMPTY_MASK 0x04
49 #define XSPI_SR_TX_FULL_MASK 0x08
50 #define XSPI_SR_MODE_FAULT_MASK 0x10
52 #define XSPI_TXD_OFFSET 0x68
53 #define XSPI_RXD_OFFSET 0x6c
55 #define XSPI_SSR_OFFSET 0x70
60 #define XIPIF_V123B_DGIER_OFFSET 0x1c
61 #define XIPIF_V123B_GINTR_ENABLE 0x80000000
63 #define XIPIF_V123B_IISR_OFFSET 0x20
64 #define XIPIF_V123B_IIER_OFFSET 0x28
66 #define XSPI_INTR_MODE_FAULT 0x01
67 #define XSPI_INTR_SLAVE_MODE_FAULT 0x02
69 #define XSPI_INTR_TX_EMPTY 0x04
70 #define XSPI_INTR_TX_UNDERRUN 0x08
71 #define XSPI_INTR_RX_FULL 0x10
72 #define XSPI_INTR_RX_OVERRUN 0x20
73 #define XSPI_INTR_TX_HALF_EMPTY 0x40
75 #define XIPIF_V123B_RESETR_OFFSET 0x40
76 #define XIPIF_V123B_RESET_MASK 0x0a
102 static unsigned int xspi_read32(
void __iomem *
addr)
112 static unsigned int xspi_read32_be(
void __iomem *
addr)
123 static void xspi_tx16(
struct xilinx_spi *xspi)
129 static void xspi_tx32(
struct xilinx_spi *xspi)
139 *xspi->
rx_ptr = data & 0xff;
144 static void xspi_rx16(
struct xilinx_spi *xspi)
153 static void xspi_rx32(
struct xilinx_spi *xspi)
162 static void xspi_init_hw(
struct xilinx_spi *xspi)
183 static void xilinx_spi_chipselect(
struct spi_device *
spi,
int is_on)
218 static int xilinx_spi_setup_transfer(
struct spi_device *spi,
227 dev_err(&spi->
dev,
"%s, unsupported bits_per_word=%d\n",
228 __func__, bits_per_word);
235 static int xilinx_spi_setup(
struct spi_device *spi)
250 static void xilinx_spi_fill_tx_fifo(
struct xilinx_spi *xspi)
279 xilinx_spi_fill_tx_fifo(xspi);
338 xilinx_spi_fill_tx_fifo(xspi);
354 static const struct of_device_id xilinx_spi_of_match[] = {
355 { .compatible =
"xlnx,xps-spi-2.00.a", },
356 { .compatible =
"xlnx,xps-spi-2.00.b", },
362 u32 irq,
s16 bus_num,
int num_cs,
int little_endian,
int bits_per_word)
375 xspi = spi_master_get_devdata(master);
376 xspi->
bitbang.master = spi_master_get(master);
377 xspi->
bitbang.chipselect = xilinx_spi_chipselect;
378 xspi->
bitbang.setup_transfer = xilinx_spi_setup_transfer;
379 xspi->
bitbang.txrx_bufs = xilinx_spi_txrx_bufs;
380 xspi->
bitbang.master->setup = xilinx_spi_setup;
381 init_completion(&xspi->
done);
403 xspi->
read_fn = xspi_read32_be;
408 xspi->
tx_fn = xspi_tx8;
409 xspi->
rx_fn = xspi_rx8;
411 xspi->
tx_fn = xspi_tx16;
412 xspi->
rx_fn = xspi_rx16;
414 xspi->
tx_fn = xspi_tx32;
415 xspi->
rx_fn = xspi_rx32;
430 dev_err(dev,
"spi_bitbang_start FAILED\n");
434 dev_info(dev,
"at 0x%08llX mapped to 0x%p, irq=%d\n",
445 spi_master_put(master);
454 xspi = spi_master_get_devdata(master);
461 spi_master_put(xspi->
bitbang.master);
469 int irq, num_cs = 0, little_endian = 0, bits_per_word = 8;
473 pdata = dev->
dev.platform_data;
481 if (dev->
dev.of_node) {
488 if (prop && len >=
sizeof(*prop))
489 num_cs = __be32_to_cpup(prop);
494 dev_err(&dev->
dev,
"Missing slave select configuration data\n");
508 little_endian, bits_per_word);
517 platform_set_drvdata(dev, master);
524 platform_set_drvdata(dev, 0);
533 .probe = xilinx_spi_probe,
538 .of_match_table = xilinx_spi_of_match,