Lines Matching refs:sspi
141 static int read_fifo(struct synquacer_spi *sspi) in read_fifo() argument
143 u32 len = readl(sspi->regs + SYNQUACER_HSSPI_REG_DMSTATUS); in read_fifo()
147 len = min(len, sspi->rx_words); in read_fifo()
149 switch (sspi->bpw) { in read_fifo()
151 u8 *buf = sspi->rx_buf; in read_fifo()
153 ioread8_rep(sspi->regs + SYNQUACER_HSSPI_REG_RX_FIFO, in read_fifo()
155 sspi->rx_buf = buf + len; in read_fifo()
159 u16 *buf = sspi->rx_buf; in read_fifo()
161 ioread16_rep(sspi->regs + SYNQUACER_HSSPI_REG_RX_FIFO, in read_fifo()
163 sspi->rx_buf = buf + len; in read_fifo()
169 u32 *buf = sspi->rx_buf; in read_fifo()
171 ioread32_rep(sspi->regs + SYNQUACER_HSSPI_REG_RX_FIFO, in read_fifo()
173 sspi->rx_buf = buf + len; in read_fifo()
180 sspi->rx_words -= len; in read_fifo()
184 static int write_fifo(struct synquacer_spi *sspi) in write_fifo() argument
186 u32 len = readl(sspi->regs + SYNQUACER_HSSPI_REG_DMSTATUS); in write_fifo()
191 sspi->tx_words); in write_fifo()
193 switch (sspi->bpw) { in write_fifo()
195 const u8 *buf = sspi->tx_buf; in write_fifo()
197 iowrite8_rep(sspi->regs + SYNQUACER_HSSPI_REG_TX_FIFO, in write_fifo()
199 sspi->tx_buf = buf + len; in write_fifo()
203 const u16 *buf = sspi->tx_buf; in write_fifo()
205 iowrite16_rep(sspi->regs + SYNQUACER_HSSPI_REG_TX_FIFO, in write_fifo()
207 sspi->tx_buf = buf + len; in write_fifo()
213 const u32 *buf = sspi->tx_buf; in write_fifo()
215 iowrite32_rep(sspi->regs + SYNQUACER_HSSPI_REG_TX_FIFO, in write_fifo()
217 sspi->tx_buf = buf + len; in write_fifo()
224 sspi->tx_words -= len; in write_fifo()
232 struct synquacer_spi *sspi = spi_master_get_devdata(master); in synquacer_spi_config() local
239 dev_err(sspi->dev, in synquacer_spi_config()
258 if (speed == sspi->speed && in synquacer_spi_config()
259 bus_width == sspi->bus_width && bpw == sspi->bpw && in synquacer_spi_config()
260 mode == sspi->mode && cs == sspi->cs && in synquacer_spi_config()
261 transfer_mode == sspi->transfer_mode) { in synquacer_spi_config()
265 sspi->transfer_mode = transfer_mode; in synquacer_spi_config()
270 dev_err(sspi->dev, "Requested rate too low (%u)\n", in synquacer_spi_config()
271 sspi->speed); in synquacer_spi_config()
275 val = readl(sspi->regs + SYNQUACER_HSSPI_REG_PCC(cs)); in synquacer_spi_config()
304 if (sspi->aces) in synquacer_spi_config()
309 if (sspi->rtm) in synquacer_spi_config()
321 writel(val, sspi->regs + SYNQUACER_HSSPI_REG_PCC(cs)); in synquacer_spi_config()
323 val = readl(sspi->regs + SYNQUACER_HSSPI_REG_FIFOCFG); in synquacer_spi_config()
327 writel(val, sspi->regs + SYNQUACER_HSSPI_REG_FIFOCFG); in synquacer_spi_config()
329 val = readl(sspi->regs + SYNQUACER_HSSPI_REG_DMSTART); in synquacer_spi_config()
342 writel(val, sspi->regs + SYNQUACER_HSSPI_REG_DMSTART); in synquacer_spi_config()
344 sspi->bpw = bpw; in synquacer_spi_config()
345 sspi->mode = mode; in synquacer_spi_config()
346 sspi->speed = speed; in synquacer_spi_config()
347 sspi->cs = spi_get_chipselect(spi, 0); in synquacer_spi_config()
348 sspi->bus_width = bus_width; in synquacer_spi_config()
357 struct synquacer_spi *sspi = spi_master_get_devdata(master); in synquacer_spi_transfer_one() local
364 val = readl(sspi->regs + SYNQUACER_HSSPI_REG_DMSTART); in synquacer_spi_transfer_one()
366 writel(val, sspi->regs + SYNQUACER_HSSPI_REG_DMSTART); in synquacer_spi_transfer_one()
368 val = readl(sspi->regs + SYNQUACER_HSSPI_REG_FIFOCFG); in synquacer_spi_transfer_one()
371 writel(val, sspi->regs + SYNQUACER_HSSPI_REG_FIFOCFG); in synquacer_spi_transfer_one()
389 reinit_completion(&sspi->transfer_done); in synquacer_spi_transfer_one()
391 sspi->tx_buf = xfer->tx_buf; in synquacer_spi_transfer_one()
392 sspi->rx_buf = xfer->rx_buf; in synquacer_spi_transfer_one()
394 switch (sspi->bpw) { in synquacer_spi_transfer_one()
407 dev_err(sspi->dev, "unsupported bpw: %d\n", sspi->bpw); in synquacer_spi_transfer_one()
412 sspi->tx_words = words; in synquacer_spi_transfer_one()
414 sspi->tx_words = 0; in synquacer_spi_transfer_one()
417 sspi->rx_words = words; in synquacer_spi_transfer_one()
419 sspi->rx_words = 0; in synquacer_spi_transfer_one()
422 status = write_fifo(sspi); in synquacer_spi_transfer_one()
424 dev_err(sspi->dev, "failed write_fifo. status: 0x%x\n", in synquacer_spi_transfer_one()
431 val = readl(sspi->regs + SYNQUACER_HSSPI_REG_FIFOCFG); in synquacer_spi_transfer_one()
434 val |= ((sspi->rx_words > SYNQUACER_HSSPI_FIFO_DEPTH ? in synquacer_spi_transfer_one()
435 SYNQUACER_HSSPI_FIFO_RX_THRESHOLD : sspi->rx_words) << in synquacer_spi_transfer_one()
437 writel(val, sspi->regs + SYNQUACER_HSSPI_REG_FIFOCFG); in synquacer_spi_transfer_one()
440 writel(~0, sspi->regs + SYNQUACER_HSSPI_REG_TXC); in synquacer_spi_transfer_one()
441 writel(~0, sspi->regs + SYNQUACER_HSSPI_REG_RXC); in synquacer_spi_transfer_one()
444 val = readl(sspi->regs + SYNQUACER_HSSPI_REG_DMSTART); in synquacer_spi_transfer_one()
446 writel(val, sspi->regs + SYNQUACER_HSSPI_REG_DMSTART); in synquacer_spi_transfer_one()
450 writel(val, sspi->regs + SYNQUACER_HSSPI_REG_TXE); in synquacer_spi_transfer_one()
451 status = wait_for_completion_timeout(&sspi->transfer_done, in synquacer_spi_transfer_one()
453 writel(0, sspi->regs + SYNQUACER_HSSPI_REG_TXE); in synquacer_spi_transfer_one()
461 writel(val, sspi->regs + SYNQUACER_HSSPI_REG_RXE); in synquacer_spi_transfer_one()
462 status = wait_for_completion_timeout(&sspi->transfer_done, in synquacer_spi_transfer_one()
464 writel(0, sspi->regs + SYNQUACER_HSSPI_REG_RXE); in synquacer_spi_transfer_one()
467 val = readl(sspi->regs + SYNQUACER_HSSPI_REG_DMSTART); in synquacer_spi_transfer_one()
469 writel(val, sspi->regs + SYNQUACER_HSSPI_REG_DMSTART); in synquacer_spi_transfer_one()
470 sspi->rx_buf = buf; in synquacer_spi_transfer_one()
471 sspi->rx_words = SYNQUACER_HSSPI_FIFO_DEPTH; in synquacer_spi_transfer_one()
472 read_fifo(sspi); in synquacer_spi_transfer_one()
476 dev_err(sspi->dev, "failed to transfer. Timeout.\n"); in synquacer_spi_transfer_one()
485 struct synquacer_spi *sspi = spi_master_get_devdata(spi->master); in synquacer_spi_set_cs() local
488 val = readl(sspi->regs + SYNQUACER_HSSPI_REG_DMSTART); in synquacer_spi_set_cs()
496 writel(val, sspi->regs + SYNQUACER_HSSPI_REG_DMSTART); in synquacer_spi_set_cs()
499 static int synquacer_spi_wait_status_update(struct synquacer_spi *sspi, in synquacer_spi_wait_status_update() argument
508 val = readl(sspi->regs + SYNQUACER_HSSPI_REG_MCTRL) & in synquacer_spi_wait_status_update()
516 dev_err(sspi->dev, "timeout occurs in updating Module Enable Status\n"); in synquacer_spi_wait_status_update()
524 struct synquacer_spi *sspi = spi_master_get_devdata(master); in synquacer_spi_enable() local
527 writel(0, sspi->regs + SYNQUACER_HSSPI_REG_MCTRL); in synquacer_spi_enable()
528 status = synquacer_spi_wait_status_update(sspi, false); in synquacer_spi_enable()
532 writel(0, sspi->regs + SYNQUACER_HSSPI_REG_TXE); in synquacer_spi_enable()
533 writel(0, sspi->regs + SYNQUACER_HSSPI_REG_RXE); in synquacer_spi_enable()
534 writel(~0, sspi->regs + SYNQUACER_HSSPI_REG_TXC); in synquacer_spi_enable()
535 writel(~0, sspi->regs + SYNQUACER_HSSPI_REG_RXC); in synquacer_spi_enable()
536 writel(~0, sspi->regs + SYNQUACER_HSSPI_REG_FAULTC); in synquacer_spi_enable()
538 val = readl(sspi->regs + SYNQUACER_HSSPI_REG_DMCFG); in synquacer_spi_enable()
541 writel(val, sspi->regs + SYNQUACER_HSSPI_REG_DMCFG); in synquacer_spi_enable()
543 val = readl(sspi->regs + SYNQUACER_HSSPI_REG_MCTRL); in synquacer_spi_enable()
544 if (sspi->clk_src_type == SYNQUACER_HSSPI_CLOCK_SRC_IPCLK) in synquacer_spi_enable()
554 writel(val, sspi->regs + SYNQUACER_HSSPI_REG_MCTRL); in synquacer_spi_enable()
555 status = synquacer_spi_wait_status_update(sspi, true); in synquacer_spi_enable()
565 struct synquacer_spi *sspi = priv; in sq_spi_rx_handler() local
567 val = readl(sspi->regs + SYNQUACER_HSSPI_REG_RXF); in sq_spi_rx_handler()
570 read_fifo(sspi); in sq_spi_rx_handler()
572 if (sspi->rx_words == 0) { in sq_spi_rx_handler()
573 writel(0, sspi->regs + SYNQUACER_HSSPI_REG_RXE); in sq_spi_rx_handler()
574 complete(&sspi->transfer_done); in sq_spi_rx_handler()
585 struct synquacer_spi *sspi = priv; in sq_spi_tx_handler() local
587 val = readl(sspi->regs + SYNQUACER_HSSPI_REG_TXF); in sq_spi_tx_handler()
589 if (sspi->tx_words == 0) { in sq_spi_tx_handler()
590 writel(0, sspi->regs + SYNQUACER_HSSPI_REG_TXE); in sq_spi_tx_handler()
591 complete(&sspi->transfer_done); in sq_spi_tx_handler()
593 write_fifo(sspi); in sq_spi_tx_handler()
605 struct synquacer_spi *sspi; in synquacer_spi_probe() local
609 master = spi_alloc_master(&pdev->dev, sizeof(*sspi)); in synquacer_spi_probe()
615 sspi = spi_master_get_devdata(master); in synquacer_spi_probe()
616 sspi->dev = &pdev->dev; in synquacer_spi_probe()
618 init_completion(&sspi->transfer_done); in synquacer_spi_probe()
620 sspi->regs = devm_platform_ioremap_resource(pdev, 0); in synquacer_spi_probe()
621 if (IS_ERR(sspi->regs)) { in synquacer_spi_probe()
622 ret = PTR_ERR(sspi->regs); in synquacer_spi_probe()
626 sspi->clk_src_type = SYNQUACER_HSSPI_CLOCK_SRC_IHCLK; /* Default */ in synquacer_spi_probe()
633 sspi->clk_src_type = SYNQUACER_HSSPI_CLOCK_SRC_IHCLK; in synquacer_spi_probe()
634 sspi->clk = devm_clk_get(sspi->dev, "iHCLK"); in synquacer_spi_probe()
637 sspi->clk_src_type = SYNQUACER_HSSPI_CLOCK_SRC_IPCLK; in synquacer_spi_probe()
638 sspi->clk = devm_clk_get(sspi->dev, "iPCLK"); in synquacer_spi_probe()
645 if (IS_ERR(sspi->clk)) { in synquacer_spi_probe()
646 ret = dev_err_probe(&pdev->dev, PTR_ERR(sspi->clk), in synquacer_spi_probe()
651 ret = clk_prepare_enable(sspi->clk); in synquacer_spi_probe()
658 master->max_speed_hz = clk_get_rate(sspi->clk); in synquacer_spi_probe()
668 sspi->aces = device_property_read_bool(&pdev->dev, in synquacer_spi_probe()
670 sspi->rtm = device_property_read_bool(&pdev->dev, "socionext,use-rtm"); in synquacer_spi_probe()
679 snprintf(sspi->rx_irq_name, SYNQUACER_HSSPI_IRQ_NAME_MAX, "%s-rx", in synquacer_spi_probe()
682 0, sspi->rx_irq_name, sspi); in synquacer_spi_probe()
693 snprintf(sspi->tx_irq_name, SYNQUACER_HSSPI_IRQ_NAME_MAX, "%s-tx", in synquacer_spi_probe()
696 0, sspi->tx_irq_name, sspi); in synquacer_spi_probe()
719 pm_runtime_set_active(sspi->dev); in synquacer_spi_probe()
720 pm_runtime_enable(sspi->dev); in synquacer_spi_probe()
722 ret = devm_spi_register_master(sspi->dev, master); in synquacer_spi_probe()
729 pm_runtime_disable(sspi->dev); in synquacer_spi_probe()
731 clk_disable_unprepare(sspi->clk); in synquacer_spi_probe()
741 struct synquacer_spi *sspi = spi_master_get_devdata(master); in synquacer_spi_remove() local
743 pm_runtime_disable(sspi->dev); in synquacer_spi_remove()
745 clk_disable_unprepare(sspi->clk); in synquacer_spi_remove()
751 struct synquacer_spi *sspi = spi_master_get_devdata(master); in synquacer_spi_suspend() local
759 clk_disable_unprepare(sspi->clk); in synquacer_spi_suspend()
767 struct synquacer_spi *sspi = spi_master_get_devdata(master); in synquacer_spi_resume() local
772 sspi->speed = 0; in synquacer_spi_resume()
774 ret = clk_prepare_enable(sspi->clk); in synquacer_spi_resume()
783 clk_disable_unprepare(sspi->clk); in synquacer_spi_resume()
791 clk_disable_unprepare(sspi->clk); in synquacer_spi_resume()