Lines Matching full:spi

28 #include <linux/spi/spi.h>
30 #include <linux/platform_data/spi-omap2-mcspi.h>
159 static inline void mcspi_write_cs_reg(const struct spi_device *spi, in mcspi_write_cs_reg() argument
162 struct omap2_mcspi_cs *cs = spi->controller_state; in mcspi_write_cs_reg()
167 static inline u32 mcspi_read_cs_reg(const struct spi_device *spi, int idx) in mcspi_read_cs_reg() argument
169 struct omap2_mcspi_cs *cs = spi->controller_state; in mcspi_read_cs_reg()
174 static inline u32 mcspi_cached_chconf0(const struct spi_device *spi) in mcspi_cached_chconf0() argument
176 struct omap2_mcspi_cs *cs = spi->controller_state; in mcspi_cached_chconf0()
181 static inline void mcspi_write_chconf0(const struct spi_device *spi, u32 val) in mcspi_write_chconf0() argument
183 struct omap2_mcspi_cs *cs = spi->controller_state; in mcspi_write_chconf0()
186 mcspi_write_cs_reg(spi, OMAP2_MCSPI_CHCONF0, val); in mcspi_write_chconf0()
187 mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHCONF0); in mcspi_write_chconf0()
200 static void omap2_mcspi_set_dma_req(const struct spi_device *spi, in omap2_mcspi_set_dma_req() argument
205 l = mcspi_cached_chconf0(spi); in omap2_mcspi_set_dma_req()
217 mcspi_write_chconf0(spi, l); in omap2_mcspi_set_dma_req()
220 static void omap2_mcspi_set_enable(const struct spi_device *spi, int enable) in omap2_mcspi_set_enable() argument
222 struct omap2_mcspi_cs *cs = spi->controller_state; in omap2_mcspi_set_enable()
231 mcspi_write_cs_reg(spi, OMAP2_MCSPI_CHCTRL0, cs->chctrl0); in omap2_mcspi_set_enable()
233 mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHCTRL0); in omap2_mcspi_set_enable()
236 static void omap2_mcspi_set_cs(struct spi_device *spi, bool enable) in omap2_mcspi_set_cs() argument
238 struct omap2_mcspi *mcspi = spi_master_get_devdata(spi->master); in omap2_mcspi_set_cs()
245 if (spi->mode & SPI_CS_HIGH) in omap2_mcspi_set_cs()
248 if (spi->controller_state) { in omap2_mcspi_set_cs()
256 l = mcspi_cached_chconf0(spi); in omap2_mcspi_set_cs()
263 mcspi_write_chconf0(spi, l); in omap2_mcspi_set_cs()
292 static void omap2_mcspi_set_fifo(const struct spi_device *spi, in omap2_mcspi_set_fifo() argument
295 struct spi_master *master = spi->master; in omap2_mcspi_set_fifo()
296 struct omap2_mcspi_cs *cs = spi->controller_state; in omap2_mcspi_set_fifo()
304 chconf = mcspi_cached_chconf0(spi); in omap2_mcspi_set_fifo()
331 mcspi_write_chconf0(spi, chconf); in omap2_mcspi_set_fifo()
344 mcspi_write_chconf0(spi, chconf); in omap2_mcspi_set_fifo()
381 struct spi_device *spi = data; in omap2_mcspi_rx_callback() local
382 struct omap2_mcspi *mcspi = spi_master_get_devdata(spi->master); in omap2_mcspi_rx_callback()
383 struct omap2_mcspi_dma *mcspi_dma = &mcspi->dma_channels[spi->chip_select]; in omap2_mcspi_rx_callback()
386 omap2_mcspi_set_dma_req(spi, 1, 0); in omap2_mcspi_rx_callback()
393 struct spi_device *spi = data; in omap2_mcspi_tx_callback() local
394 struct omap2_mcspi *mcspi = spi_master_get_devdata(spi->master); in omap2_mcspi_tx_callback()
395 struct omap2_mcspi_dma *mcspi_dma = &mcspi->dma_channels[spi->chip_select]; in omap2_mcspi_tx_callback()
398 omap2_mcspi_set_dma_req(spi, 0, 0); in omap2_mcspi_tx_callback()
403 static void omap2_mcspi_tx_dma(struct spi_device *spi, in omap2_mcspi_tx_dma() argument
411 mcspi = spi_master_get_devdata(spi->master); in omap2_mcspi_tx_dma()
412 mcspi_dma = &mcspi->dma_channels[spi->chip_select]; in omap2_mcspi_tx_dma()
422 tx->callback_param = spi; in omap2_mcspi_tx_dma()
428 omap2_mcspi_set_dma_req(spi, 0, 1); in omap2_mcspi_tx_dma()
432 omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer, in omap2_mcspi_rx_dma() argument
445 struct omap2_mcspi_cs *cs = spi->controller_state; in omap2_mcspi_rx_dma()
449 mcspi = spi_master_get_devdata(spi->master); in omap2_mcspi_rx_dma()
450 mcspi_dma = &mcspi->dma_channels[spi->chip_select]; in omap2_mcspi_rx_dma()
462 l = mcspi_cached_chconf0(spi); in omap2_mcspi_rx_dma()
499 dev_err(&spi->dev, "sg_split failed\n"); in omap2_mcspi_rx_dma()
508 tx->callback_param = spi; in omap2_mcspi_rx_dma()
515 omap2_mcspi_set_dma_req(spi, 1, 1); in omap2_mcspi_rx_dma()
520 omap2_mcspi_set_dma_req(spi, 1, 0); in omap2_mcspi_rx_dma()
534 omap2_mcspi_set_enable(spi, 0); in omap2_mcspi_rx_dma()
545 w = mcspi_read_cs_reg(spi, OMAP2_MCSPI_RX0); in omap2_mcspi_rx_dma()
554 dev_err(&spi->dev, "DMA RX penultimate word empty\n"); in omap2_mcspi_rx_dma()
556 omap2_mcspi_set_enable(spi, 1); in omap2_mcspi_rx_dma()
563 w = mcspi_read_cs_reg(spi, OMAP2_MCSPI_RX0); in omap2_mcspi_rx_dma()
571 dev_err(&spi->dev, "DMA RX last word empty\n"); in omap2_mcspi_rx_dma()
574 omap2_mcspi_set_enable(spi, 1); in omap2_mcspi_rx_dma()
579 omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer) in omap2_mcspi_txrx_dma() argument
582 struct omap2_mcspi_cs *cs = spi->controller_state; in omap2_mcspi_txrx_dma()
594 mcspi = spi_master_get_devdata(spi->master); in omap2_mcspi_txrx_dma()
595 mcspi_dma = &mcspi->dma_channels[spi->chip_select]; in omap2_mcspi_txrx_dma()
627 if (spi_controller_is_slave(spi->master)) in omap2_mcspi_txrx_dma()
628 mcspi_write_reg(spi->master, in omap2_mcspi_txrx_dma()
631 omap2_mcspi_tx_dma(spi, xfer, cfg); in omap2_mcspi_txrx_dma()
635 count = omap2_mcspi_rx_dma(spi, xfer, cfg, es); in omap2_mcspi_txrx_dma()
643 omap2_mcspi_set_dma_req(spi, 0, 0); in omap2_mcspi_txrx_dma()
658 dev_err(&spi->dev, "EOW timed out\n"); in omap2_mcspi_txrx_dma()
671 dev_err(&spi->dev, "TXFFE timed out\n"); in omap2_mcspi_txrx_dma()
676 dev_err(&spi->dev, "TXS timed out\n"); in omap2_mcspi_txrx_dma()
681 dev_err(&spi->dev, "EOT timed out\n"); in omap2_mcspi_txrx_dma()
688 omap2_mcspi_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer) in omap2_mcspi_txrx_pio() argument
690 struct omap2_mcspi_cs *cs = spi->controller_state; in omap2_mcspi_txrx_pio()
703 l = mcspi_cached_chconf0(spi); in omap2_mcspi_txrx_pio()
726 dev_err(&spi->dev, "TXS timed out\n"); in omap2_mcspi_txrx_pio()
729 dev_vdbg(&spi->dev, "write-%d %02x\n", in omap2_mcspi_txrx_pio()
736 dev_err(&spi->dev, "RXS timed out\n"); in omap2_mcspi_txrx_pio()
742 omap2_mcspi_set_enable(spi, 0); in omap2_mcspi_txrx_pio()
744 dev_vdbg(&spi->dev, "read-%d %02x\n", in omap2_mcspi_txrx_pio()
748 dev_err(&spi->dev, in omap2_mcspi_txrx_pio()
754 omap2_mcspi_set_enable(spi, 0); in omap2_mcspi_txrx_pio()
758 dev_vdbg(&spi->dev, "read-%d %02x\n", in omap2_mcspi_txrx_pio()
773 dev_err(&spi->dev, "TXS timed out\n"); in omap2_mcspi_txrx_pio()
776 dev_vdbg(&spi->dev, "write-%d %04x\n", in omap2_mcspi_txrx_pio()
783 dev_err(&spi->dev, "RXS timed out\n"); in omap2_mcspi_txrx_pio()
789 omap2_mcspi_set_enable(spi, 0); in omap2_mcspi_txrx_pio()
791 dev_vdbg(&spi->dev, "read-%d %04x\n", in omap2_mcspi_txrx_pio()
795 dev_err(&spi->dev, in omap2_mcspi_txrx_pio()
801 omap2_mcspi_set_enable(spi, 0); in omap2_mcspi_txrx_pio()
805 dev_vdbg(&spi->dev, "read-%d %04x\n", in omap2_mcspi_txrx_pio()
820 dev_err(&spi->dev, "TXS timed out\n"); in omap2_mcspi_txrx_pio()
823 dev_vdbg(&spi->dev, "write-%d %08x\n", in omap2_mcspi_txrx_pio()
830 dev_err(&spi->dev, "RXS timed out\n"); in omap2_mcspi_txrx_pio()
836 omap2_mcspi_set_enable(spi, 0); in omap2_mcspi_txrx_pio()
838 dev_vdbg(&spi->dev, "read-%d %08x\n", in omap2_mcspi_txrx_pio()
842 dev_err(&spi->dev, in omap2_mcspi_txrx_pio()
848 omap2_mcspi_set_enable(spi, 0); in omap2_mcspi_txrx_pio()
852 dev_vdbg(&spi->dev, "read-%d %08x\n", in omap2_mcspi_txrx_pio()
862 dev_err(&spi->dev, "TXS timed out\n"); in omap2_mcspi_txrx_pio()
865 dev_err(&spi->dev, "EOT timed out\n"); in omap2_mcspi_txrx_pio()
871 omap2_mcspi_set_enable(spi, 0); in omap2_mcspi_txrx_pio()
874 omap2_mcspi_set_enable(spi, 1); in omap2_mcspi_txrx_pio()
890 static int omap2_mcspi_setup_transfer(struct spi_device *spi, in omap2_mcspi_setup_transfer() argument
893 struct omap2_mcspi_cs *cs = spi->controller_state; in omap2_mcspi_setup_transfer()
896 u8 word_len = spi->bits_per_word; in omap2_mcspi_setup_transfer()
897 u32 speed_hz = spi->max_speed_hz; in omap2_mcspi_setup_transfer()
899 mcspi = spi_master_get_devdata(spi->master); in omap2_mcspi_setup_transfer()
922 l = mcspi_cached_chconf0(spi); in omap2_mcspi_setup_transfer()
942 if (!(spi->mode & SPI_CS_HIGH)) in omap2_mcspi_setup_transfer()
957 mcspi_write_cs_reg(spi, OMAP2_MCSPI_CHCTRL0, cs->chctrl0); in omap2_mcspi_setup_transfer()
960 /* set SPI mode 0..3 */ in omap2_mcspi_setup_transfer()
961 if (spi->mode & SPI_CPOL) in omap2_mcspi_setup_transfer()
965 if (spi->mode & SPI_CPHA) in omap2_mcspi_setup_transfer()
970 mcspi_write_chconf0(spi, l); in omap2_mcspi_setup_transfer()
972 cs->mode = spi->mode; in omap2_mcspi_setup_transfer()
974 dev_dbg(&spi->dev, "setup: speed %d, sample %s edge, clk %s\n", in omap2_mcspi_setup_transfer()
976 (spi->mode & SPI_CPHA) ? "trailing" : "leading", in omap2_mcspi_setup_transfer()
977 (spi->mode & SPI_CPOL) ? "inverted" : "normal"); in omap2_mcspi_setup_transfer()
1035 static int omap2_mcspi_setup(struct spi_device *spi) in omap2_mcspi_setup() argument
1038 struct omap2_mcspi *mcspi = spi_master_get_devdata(spi->master); in omap2_mcspi_setup()
1040 struct omap2_mcspi_cs *cs = spi->controller_state; in omap2_mcspi_setup()
1046 cs->base = mcspi->base + spi->chip_select * 0x14; in omap2_mcspi_setup()
1047 cs->phys = mcspi->phys + spi->chip_select * 0x14; in omap2_mcspi_setup()
1051 spi->controller_state = cs; in omap2_mcspi_setup()
1063 ret = omap2_mcspi_setup_transfer(spi, NULL); in omap2_mcspi_setup()
1070 static void omap2_mcspi_cleanup(struct spi_device *spi) in omap2_mcspi_cleanup() argument
1074 if (spi->controller_state) { in omap2_mcspi_cleanup()
1076 cs = spi->controller_state; in omap2_mcspi_cleanup()
1114 struct spi_device *spi, in omap2_mcspi_transfer_one() argument
1134 mcspi_dma = mcspi->dma_channels + spi->chip_select; in omap2_mcspi_transfer_one()
1135 cs = spi->controller_state; in omap2_mcspi_transfer_one()
1136 cd = spi->controller_data; in omap2_mcspi_transfer_one()
1139 * The slave driver could have changed spi->mode in which case in omap2_mcspi_transfer_one()
1145 if (spi->mode != cs->mode) in omap2_mcspi_transfer_one()
1148 omap2_mcspi_set_enable(spi, 0); in omap2_mcspi_transfer_one()
1150 if (spi->cs_gpiod) in omap2_mcspi_transfer_one()
1151 omap2_mcspi_set_cs(spi, spi->mode & SPI_CS_HIGH); in omap2_mcspi_transfer_one()
1154 (t->speed_hz != spi->max_speed_hz) || in omap2_mcspi_transfer_one()
1155 (t->bits_per_word != spi->bits_per_word)) { in omap2_mcspi_transfer_one()
1157 status = omap2_mcspi_setup_transfer(spi, t); in omap2_mcspi_transfer_one()
1160 if (t->speed_hz == spi->max_speed_hz && in omap2_mcspi_transfer_one()
1161 t->bits_per_word == spi->bits_per_word) in omap2_mcspi_transfer_one()
1169 mcspi_read_cs_reg(spi, OMAP2_MCSPI_MODULCTRL); in omap2_mcspi_transfer_one()
1172 chconf = mcspi_cached_chconf0(spi); in omap2_mcspi_transfer_one()
1187 mcspi_write_chconf0(spi, chconf); in omap2_mcspi_transfer_one()
1194 master->can_dma(master, spi, t)) in omap2_mcspi_transfer_one()
1195 omap2_mcspi_set_fifo(spi, t, 1); in omap2_mcspi_transfer_one()
1197 omap2_mcspi_set_enable(spi, 1); in omap2_mcspi_transfer_one()
1206 master->can_dma(master, spi, t)) in omap2_mcspi_transfer_one()
1207 count = omap2_mcspi_txrx_dma(spi, t); in omap2_mcspi_transfer_one()
1209 count = omap2_mcspi_txrx_pio(spi, t); in omap2_mcspi_transfer_one()
1217 omap2_mcspi_set_enable(spi, 0); in omap2_mcspi_transfer_one()
1220 omap2_mcspi_set_fifo(spi, t, 0); in omap2_mcspi_transfer_one()
1226 status = omap2_mcspi_setup_transfer(spi, NULL); in omap2_mcspi_transfer_one()
1234 mcspi_read_cs_reg(spi, OMAP2_MCSPI_MODULCTRL); in omap2_mcspi_transfer_one()
1237 omap2_mcspi_set_enable(spi, 0); in omap2_mcspi_transfer_one()
1239 if (spi->cs_gpiod) in omap2_mcspi_transfer_one()
1240 omap2_mcspi_set_cs(spi, !(spi->mode & SPI_CS_HIGH)); in omap2_mcspi_transfer_one()
1243 omap2_mcspi_set_fifo(spi, t, 0); in omap2_mcspi_transfer_one()
1261 if (msg->spi->controller_state == cs) in omap2_mcspi_prepare_message()
1276 struct spi_device *spi, in omap2_mcspi_can_dma() argument
1279 struct omap2_mcspi *mcspi = spi_master_get_devdata(spi->master); in omap2_mcspi_can_dma()
1281 &mcspi->dma_channels[spi->chip_select]; in omap2_mcspi_can_dma()
1295 static size_t omap2_mcspi_max_xfer_size(struct spi_device *spi) in omap2_mcspi_max_xfer_size() argument
1297 struct omap2_mcspi *mcspi = spi_master_get_devdata(spi->master); in omap2_mcspi_max_xfer_size()
1299 &mcspi->dma_channels[spi->chip_select]; in omap2_mcspi_max_xfer_size()
1331 * When SPI wake up from off-mode, CS is in activate state. If it was in
1408 if (of_property_read_bool(node, "spi-slave")) in omap2_mcspi_probe()
1415 /* the spi->mode bits understood by this driver: */ in omap2_mcspi_probe()
1441 of_property_read_u32(node, "ti,spi-num-cs", &num_cs); in omap2_mcspi_probe()