• Home
  • Raw
  • Download

Lines Matching refs:spi_imx

136 static void spi_imx_buf_rx_##type(struct spi_imx_data *spi_imx)		\
138 unsigned int val = readl(spi_imx->base + MXC_CSPIRXDATA); \
140 if (spi_imx->rx_buf) { \
141 *(type *)spi_imx->rx_buf = val; \
142 spi_imx->rx_buf += sizeof(type); \
147 static void spi_imx_buf_tx_##type(struct spi_imx_data *spi_imx) \
151 if (spi_imx->tx_buf) { \
152 val = *(type *)spi_imx->tx_buf; \
153 spi_imx->tx_buf += sizeof(type); \
156 spi_imx->count -= sizeof(type); \
158 writel(val, spi_imx->base + MXC_CSPITXDATA); \
212 struct spi_imx_data *spi_imx = spi_master_get_devdata(master); in spi_imx_can_dma() local
230 if (transfer->len < spi_imx->wml * bpw) in spi_imx_can_dma()
233 if (transfer->len % (spi_imx->wml * bpw)) in spi_imx_can_dma()
276 static unsigned int mx51_ecspi_clkdiv(struct spi_imx_data *spi_imx, in mx51_ecspi_clkdiv() argument
284 unsigned int fin = spi_imx->spi_clk; in mx51_ecspi_clkdiv()
297 dev_err(spi_imx->dev, "cannot set clock freq: %u (base freq: %u)\n", in mx51_ecspi_clkdiv()
304 dev_dbg(spi_imx->dev, "%s: fin: %u, fspi: %u, post: %u, pre: %u\n", in mx51_ecspi_clkdiv()
314 static void mx51_ecspi_intctrl(struct spi_imx_data *spi_imx, int enable) in mx51_ecspi_intctrl() argument
324 writel(val, spi_imx->base + MX51_ECSPI_INT); in mx51_ecspi_intctrl()
327 static void mx51_ecspi_trigger(struct spi_imx_data *spi_imx) in mx51_ecspi_trigger() argument
331 reg = readl(spi_imx->base + MX51_ECSPI_CTRL); in mx51_ecspi_trigger()
333 writel(reg, spi_imx->base + MX51_ECSPI_CTRL); in mx51_ecspi_trigger()
339 struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master); in mx51_ecspi_config() local
342 u32 cfg = readl(spi_imx->base + MX51_ECSPI_CONFIG); in mx51_ecspi_config()
354 ctrl |= mx51_ecspi_clkdiv(spi_imx, config->speed_hz, &clk); in mx51_ecspi_config()
355 spi_imx->spi_bus_clk = clk; in mx51_ecspi_config()
381 if (spi_imx->usedma) in mx51_ecspi_config()
385 writel(ctrl, spi_imx->base + MX51_ECSPI_CTRL); in mx51_ecspi_config()
387 reg = readl(spi_imx->base + MX51_ECSPI_TESTREG); in mx51_ecspi_config()
392 writel(reg, spi_imx->base + MX51_ECSPI_TESTREG); in mx51_ecspi_config()
394 writel(cfg, spi_imx->base + MX51_ECSPI_CONFIG); in mx51_ecspi_config()
418 writel(MX51_ECSPI_DMA_RX_WML(spi_imx->wml) | in mx51_ecspi_config()
419 MX51_ECSPI_DMA_TX_WML(spi_imx->wml) | in mx51_ecspi_config()
420 MX51_ECSPI_DMA_RXT_WML(spi_imx->wml) | in mx51_ecspi_config()
422 MX51_ECSPI_DMA_RXTDEN, spi_imx->base + MX51_ECSPI_DMA); in mx51_ecspi_config()
427 static int mx51_ecspi_rx_available(struct spi_imx_data *spi_imx) in mx51_ecspi_rx_available() argument
429 return readl(spi_imx->base + MX51_ECSPI_STAT) & MX51_ECSPI_STAT_RR; in mx51_ecspi_rx_available()
432 static void mx51_ecspi_reset(struct spi_imx_data *spi_imx) in mx51_ecspi_reset() argument
435 while (mx51_ecspi_rx_available(spi_imx)) in mx51_ecspi_reset()
436 readl(spi_imx->base + MXC_CSPIRXDATA); in mx51_ecspi_reset()
465 static void mx31_intctrl(struct spi_imx_data *spi_imx, int enable) in mx31_intctrl() argument
474 writel(val, spi_imx->base + MXC_CSPIINT); in mx31_intctrl()
477 static void mx31_trigger(struct spi_imx_data *spi_imx) in mx31_trigger() argument
481 reg = readl(spi_imx->base + MXC_CSPICTRL); in mx31_trigger()
483 writel(reg, spi_imx->base + MXC_CSPICTRL); in mx31_trigger()
488 struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master); in mx31_config() local
492 reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, config->speed_hz, &clk) << in mx31_config()
494 spi_imx->spi_bus_clk = clk; in mx31_config()
496 if (is_imx35_cspi(spi_imx)) { in mx31_config()
511 (is_imx35_cspi(spi_imx) ? MX35_CSPICTRL_CS_SHIFT : in mx31_config()
514 writel(reg, spi_imx->base + MXC_CSPICTRL); in mx31_config()
516 reg = readl(spi_imx->base + MX31_CSPI_TESTREG); in mx31_config()
521 writel(reg, spi_imx->base + MX31_CSPI_TESTREG); in mx31_config()
526 static int mx31_rx_available(struct spi_imx_data *spi_imx) in mx31_rx_available() argument
528 return readl(spi_imx->base + MX31_CSPISTATUS) & MX31_STATUS_RR; in mx31_rx_available()
531 static void mx31_reset(struct spi_imx_data *spi_imx) in mx31_reset() argument
534 while (readl(spi_imx->base + MX31_CSPISTATUS) & MX31_STATUS_RR) in mx31_reset()
535 readl(spi_imx->base + MXC_CSPIRXDATA); in mx31_reset()
551 static void mx21_intctrl(struct spi_imx_data *spi_imx, int enable) in mx21_intctrl() argument
560 writel(val, spi_imx->base + MXC_CSPIINT); in mx21_intctrl()
563 static void mx21_trigger(struct spi_imx_data *spi_imx) in mx21_trigger() argument
567 reg = readl(spi_imx->base + MXC_CSPICTRL); in mx21_trigger()
569 writel(reg, spi_imx->base + MXC_CSPICTRL); in mx21_trigger()
574 struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master); in mx21_config() local
576 unsigned int max = is_imx27_cspi(spi_imx) ? 16 : 18; in mx21_config()
578 reg |= spi_imx_clkdiv_1(spi_imx->spi_clk, config->speed_hz, max) << in mx21_config()
591 writel(reg, spi_imx->base + MXC_CSPICTRL); in mx21_config()
596 static int mx21_rx_available(struct spi_imx_data *spi_imx) in mx21_rx_available() argument
598 return readl(spi_imx->base + MXC_CSPIINT) & MX21_INTREG_RR; in mx21_rx_available()
601 static void mx21_reset(struct spi_imx_data *spi_imx) in mx21_reset() argument
603 writel(1, spi_imx->base + MXC_RESET); in mx21_reset()
617 static void mx1_intctrl(struct spi_imx_data *spi_imx, int enable) in mx1_intctrl() argument
626 writel(val, spi_imx->base + MXC_CSPIINT); in mx1_intctrl()
629 static void mx1_trigger(struct spi_imx_data *spi_imx) in mx1_trigger() argument
633 reg = readl(spi_imx->base + MXC_CSPICTRL); in mx1_trigger()
635 writel(reg, spi_imx->base + MXC_CSPICTRL); in mx1_trigger()
640 struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master); in mx1_config() local
644 reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, config->speed_hz, &clk) << in mx1_config()
646 spi_imx->spi_bus_clk = clk; in mx1_config()
655 writel(reg, spi_imx->base + MXC_CSPICTRL); in mx1_config()
660 static int mx1_rx_available(struct spi_imx_data *spi_imx) in mx1_rx_available() argument
662 return readl(spi_imx->base + MXC_CSPIINT) & MX1_INTREG_RR; in mx1_rx_available()
665 static void mx1_reset(struct spi_imx_data *spi_imx) in mx1_reset() argument
667 writel(1, spi_imx->base + MXC_RESET); in mx1_reset()
772 static void spi_imx_push(struct spi_imx_data *spi_imx) in spi_imx_push() argument
774 while (spi_imx->txfifo < spi_imx_get_fifosize(spi_imx)) { in spi_imx_push()
775 if (!spi_imx->count) in spi_imx_push()
777 spi_imx->tx(spi_imx); in spi_imx_push()
778 spi_imx->txfifo++; in spi_imx_push()
781 spi_imx->devtype_data->trigger(spi_imx); in spi_imx_push()
786 struct spi_imx_data *spi_imx = dev_id; in spi_imx_isr() local
788 while (spi_imx->devtype_data->rx_available(spi_imx)) { in spi_imx_isr()
789 spi_imx->rx(spi_imx); in spi_imx_isr()
790 spi_imx->txfifo--; in spi_imx_isr()
793 if (spi_imx->count) { in spi_imx_isr()
794 spi_imx_push(spi_imx); in spi_imx_isr()
798 if (spi_imx->txfifo) { in spi_imx_isr()
802 spi_imx->devtype_data->intctrl( in spi_imx_isr()
803 spi_imx, MXC_INT_RR); in spi_imx_isr()
807 spi_imx->devtype_data->intctrl(spi_imx, 0); in spi_imx_isr()
808 complete(&spi_imx->xfer_done); in spi_imx_isr()
819 struct spi_imx_data *spi_imx = spi_master_get_devdata(master); in spi_imx_dma_configure() local
821 if (bytes_per_word == spi_imx->bytes_per_word) in spi_imx_dma_configure()
840 tx.dst_addr = spi_imx->base_phys + MXC_CSPITXDATA; in spi_imx_dma_configure()
842 tx.dst_maxburst = spi_imx->wml; in spi_imx_dma_configure()
845 dev_err(spi_imx->dev, "TX dma configuration failed with %d\n", ret); in spi_imx_dma_configure()
850 rx.src_addr = spi_imx->base_phys + MXC_CSPIRXDATA; in spi_imx_dma_configure()
852 rx.src_maxburst = spi_imx->wml; in spi_imx_dma_configure()
855 dev_err(spi_imx->dev, "RX dma configuration failed with %d\n", ret); in spi_imx_dma_configure()
859 spi_imx->bytes_per_word = bytes_per_word; in spi_imx_dma_configure()
867 struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master); in spi_imx_setupxfer() local
881 spi_imx->rx = spi_imx_buf_rx_u8; in spi_imx_setupxfer()
882 spi_imx->tx = spi_imx_buf_tx_u8; in spi_imx_setupxfer()
884 spi_imx->rx = spi_imx_buf_rx_u16; in spi_imx_setupxfer()
885 spi_imx->tx = spi_imx_buf_tx_u16; in spi_imx_setupxfer()
887 spi_imx->rx = spi_imx_buf_rx_u32; in spi_imx_setupxfer()
888 spi_imx->tx = spi_imx_buf_tx_u32; in spi_imx_setupxfer()
891 if (spi_imx_can_dma(spi_imx->bitbang.master, spi, t)) in spi_imx_setupxfer()
892 spi_imx->usedma = 1; in spi_imx_setupxfer()
894 spi_imx->usedma = 0; in spi_imx_setupxfer()
896 if (spi_imx->usedma) { in spi_imx_setupxfer()
903 spi_imx->devtype_data->config(spi, &config); in spi_imx_setupxfer()
908 static void spi_imx_sdma_exit(struct spi_imx_data *spi_imx) in spi_imx_sdma_exit() argument
910 struct spi_master *master = spi_imx->bitbang.master; in spi_imx_sdma_exit()
923 static int spi_imx_sdma_init(struct device *dev, struct spi_imx_data *spi_imx, in spi_imx_sdma_init() argument
932 spi_imx->wml = spi_imx_get_fifosize(spi_imx) / 2; in spi_imx_sdma_init()
954 init_completion(&spi_imx->dma_rx_completion); in spi_imx_sdma_init()
955 init_completion(&spi_imx->dma_tx_completion); in spi_imx_sdma_init()
958 spi_imx->bitbang.master->flags = SPI_MASTER_MUST_RX | in spi_imx_sdma_init()
963 spi_imx_sdma_exit(spi_imx); in spi_imx_sdma_init()
969 struct spi_imx_data *spi_imx = (struct spi_imx_data *)cookie; in spi_imx_dma_rx_callback() local
971 complete(&spi_imx->dma_rx_completion); in spi_imx_dma_rx_callback()
976 struct spi_imx_data *spi_imx = (struct spi_imx_data *)cookie; in spi_imx_dma_tx_callback() local
978 complete(&spi_imx->dma_tx_completion); in spi_imx_dma_tx_callback()
981 static int spi_imx_calculate_timeout(struct spi_imx_data *spi_imx, int size) in spi_imx_calculate_timeout() argument
986 timeout = (8 + 4) * size / spi_imx->spi_bus_clk; in spi_imx_calculate_timeout()
995 static int spi_imx_dma_transfer(struct spi_imx_data *spi_imx, in spi_imx_dma_transfer() argument
1001 struct spi_master *master = spi_imx->bitbang.master; in spi_imx_dma_transfer()
1015 desc_rx->callback_param = (void *)spi_imx; in spi_imx_dma_transfer()
1017 reinit_completion(&spi_imx->dma_rx_completion); in spi_imx_dma_transfer()
1029 desc_tx->callback_param = (void *)spi_imx; in spi_imx_dma_transfer()
1031 reinit_completion(&spi_imx->dma_tx_completion); in spi_imx_dma_transfer()
1034 transfer_timeout = spi_imx_calculate_timeout(spi_imx, transfer->len); in spi_imx_dma_transfer()
1037 timeout = wait_for_completion_timeout(&spi_imx->dma_tx_completion, in spi_imx_dma_transfer()
1040 dev_err(spi_imx->dev, "I/O Error in DMA TX\n"); in spi_imx_dma_transfer()
1046 timeout = wait_for_completion_timeout(&spi_imx->dma_rx_completion, in spi_imx_dma_transfer()
1050 spi_imx->devtype_data->reset(spi_imx); in spi_imx_dma_transfer()
1061 struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master); in spi_imx_pio_transfer() local
1065 spi_imx->tx_buf = transfer->tx_buf; in spi_imx_pio_transfer()
1066 spi_imx->rx_buf = transfer->rx_buf; in spi_imx_pio_transfer()
1067 spi_imx->count = transfer->len; in spi_imx_pio_transfer()
1068 spi_imx->txfifo = 0; in spi_imx_pio_transfer()
1070 reinit_completion(&spi_imx->xfer_done); in spi_imx_pio_transfer()
1072 spi_imx_push(spi_imx); in spi_imx_pio_transfer()
1074 spi_imx->devtype_data->intctrl(spi_imx, MXC_INT_TE); in spi_imx_pio_transfer()
1076 transfer_timeout = spi_imx_calculate_timeout(spi_imx, transfer->len); in spi_imx_pio_transfer()
1078 timeout = wait_for_completion_timeout(&spi_imx->xfer_done, in spi_imx_pio_transfer()
1082 spi_imx->devtype_data->reset(spi_imx); in spi_imx_pio_transfer()
1092 struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master); in spi_imx_transfer() local
1094 if (spi_imx->usedma) in spi_imx_transfer()
1095 return spi_imx_dma_transfer(spi_imx, transfer); in spi_imx_transfer()
1121 struct spi_imx_data *spi_imx = spi_master_get_devdata(master); in spi_imx_prepare_message() local
1124 ret = clk_enable(spi_imx->clk_per); in spi_imx_prepare_message()
1128 ret = clk_enable(spi_imx->clk_ipg); in spi_imx_prepare_message()
1130 clk_disable(spi_imx->clk_per); in spi_imx_prepare_message()
1140 struct spi_imx_data *spi_imx = spi_master_get_devdata(master); in spi_imx_unprepare_message() local
1142 clk_disable(spi_imx->clk_ipg); in spi_imx_unprepare_message()
1143 clk_disable(spi_imx->clk_per); in spi_imx_unprepare_message()
1155 struct spi_imx_data *spi_imx; in spi_imx_probe() local
1173 spi_imx = spi_master_get_devdata(master); in spi_imx_probe()
1174 spi_imx->bitbang.master = master; in spi_imx_probe()
1175 spi_imx->dev = &pdev->dev; in spi_imx_probe()
1177 spi_imx->devtype_data = of_id ? of_id->data : in spi_imx_probe()
1191 spi_imx->bitbang.chipselect = spi_imx_chipselect; in spi_imx_probe()
1192 spi_imx->bitbang.setup_transfer = spi_imx_setupxfer; in spi_imx_probe()
1193 spi_imx->bitbang.txrx_bufs = spi_imx_transfer; in spi_imx_probe()
1194 spi_imx->bitbang.master->setup = spi_imx_setup; in spi_imx_probe()
1195 spi_imx->bitbang.master->cleanup = spi_imx_cleanup; in spi_imx_probe()
1196 spi_imx->bitbang.master->prepare_message = spi_imx_prepare_message; in spi_imx_probe()
1197 spi_imx->bitbang.master->unprepare_message = spi_imx_unprepare_message; in spi_imx_probe()
1198 spi_imx->bitbang.master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; in spi_imx_probe()
1199 if (is_imx35_cspi(spi_imx) || is_imx51_ecspi(spi_imx)) in spi_imx_probe()
1200 spi_imx->bitbang.master->mode_bits |= SPI_LOOP; in spi_imx_probe()
1202 init_completion(&spi_imx->xfer_done); in spi_imx_probe()
1205 spi_imx->base = devm_ioremap_resource(&pdev->dev, res); in spi_imx_probe()
1206 if (IS_ERR(spi_imx->base)) { in spi_imx_probe()
1207 ret = PTR_ERR(spi_imx->base); in spi_imx_probe()
1210 spi_imx->base_phys = res->start; in spi_imx_probe()
1219 dev_name(&pdev->dev), spi_imx); in spi_imx_probe()
1225 spi_imx->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); in spi_imx_probe()
1226 if (IS_ERR(spi_imx->clk_ipg)) { in spi_imx_probe()
1227 ret = PTR_ERR(spi_imx->clk_ipg); in spi_imx_probe()
1231 spi_imx->clk_per = devm_clk_get(&pdev->dev, "per"); in spi_imx_probe()
1232 if (IS_ERR(spi_imx->clk_per)) { in spi_imx_probe()
1233 ret = PTR_ERR(spi_imx->clk_per); in spi_imx_probe()
1237 ret = clk_prepare_enable(spi_imx->clk_per); in spi_imx_probe()
1241 ret = clk_prepare_enable(spi_imx->clk_ipg); in spi_imx_probe()
1245 spi_imx->spi_clk = clk_get_rate(spi_imx->clk_per); in spi_imx_probe()
1250 if (is_imx51_ecspi(spi_imx)) { in spi_imx_probe()
1251 ret = spi_imx_sdma_init(&pdev->dev, spi_imx, master); in spi_imx_probe()
1260 spi_imx->devtype_data->reset(spi_imx); in spi_imx_probe()
1262 spi_imx->devtype_data->intctrl(spi_imx, 0); in spi_imx_probe()
1265 ret = spi_bitbang_start(&spi_imx->bitbang); in spi_imx_probe()
1292 clk_disable(spi_imx->clk_ipg); in spi_imx_probe()
1293 clk_disable(spi_imx->clk_per); in spi_imx_probe()
1297 clk_disable_unprepare(spi_imx->clk_ipg); in spi_imx_probe()
1299 clk_disable_unprepare(spi_imx->clk_per); in spi_imx_probe()
1309 struct spi_imx_data *spi_imx = spi_master_get_devdata(master); in spi_imx_remove() local
1312 spi_bitbang_stop(&spi_imx->bitbang); in spi_imx_remove()
1314 ret = clk_enable(spi_imx->clk_per); in spi_imx_remove()
1318 ret = clk_enable(spi_imx->clk_ipg); in spi_imx_remove()
1320 clk_disable(spi_imx->clk_per); in spi_imx_remove()
1324 writel(0, spi_imx->base + MXC_CSPICTRL); in spi_imx_remove()
1325 clk_disable_unprepare(spi_imx->clk_ipg); in spi_imx_remove()
1326 clk_disable_unprepare(spi_imx->clk_per); in spi_imx_remove()
1327 spi_imx_sdma_exit(spi_imx); in spi_imx_remove()