Lines Matching refs:bs

122 #define bcm63xx_prepend_printk_on_checkfail(bs, fmt, ...)	\  argument
124 if (bs->xfer_mode == HSSPI_XFER_MODE_AUTO) \
125 dev_dbg(&bs->pdev->dev, fmt, ##__VA_ARGS__); \
126 else if (bs->xfer_mode == HSSPI_XFER_MODE_PREPEND) \
127 dev_err(&bs->pdev->dev, fmt, ##__VA_ARGS__); \
152 struct bcm63xx_hsspi *bs = spi_controller_get_devdata(ctrl); in wait_mode_show() local
154 return sprintf(buf, "%d\n", bs->wait_mode); in wait_mode_show()
161 struct bcm63xx_hsspi *bs = spi_controller_get_devdata(ctrl); in wait_mode_store() local
172 mutex_lock(&bs->msg_mutex); in wait_mode_store()
173 bs->wait_mode = val; in wait_mode_store()
176 __raw_writel(HSSPI_INT_CLEAR_ALL, bs->regs + HSSPI_INT_STATUS_REG); in wait_mode_store()
177 mutex_unlock(&bs->msg_mutex); in wait_mode_store()
188 struct bcm63xx_hsspi *bs = spi_controller_get_devdata(ctrl); in xfer_mode_show() local
190 return sprintf(buf, "%d\n", bs->xfer_mode); in xfer_mode_show()
197 struct bcm63xx_hsspi *bs = spi_controller_get_devdata(ctrl); in xfer_mode_store() local
208 mutex_lock(&bs->msg_mutex); in xfer_mode_store()
209 bs->xfer_mode = val; in xfer_mode_store()
210 mutex_unlock(&bs->msg_mutex); in xfer_mode_store()
227 static void bcm63xx_hsspi_set_clk(struct bcm63xx_hsspi *bs,
235 static int bcm63xx_hsspi_wait_cmd(struct bcm63xx_hsspi *bs) in bcm63xx_hsspi_wait_cmd() argument
241 if (bs->wait_mode == HSSPI_WAIT_MODE_INTR) { in bcm63xx_hsspi_wait_cmd()
242 if (wait_for_completion_timeout(&bs->done, HZ) == 0) in bcm63xx_hsspi_wait_cmd()
249 reg = __raw_readl(bs->regs + HSSPI_PINGPONG_STATUS_REG(0)); in bcm63xx_hsspi_wait_cmd()
260 dev_err(&bs->pdev->dev, "transfer timed out!\n"); in bcm63xx_hsspi_wait_cmd()
270 struct bcm63xx_hsspi *bs = spi_controller_get_devdata(host); in bcm63xx_prepare_prepend_transfer() local
282 bs->prepend_cnt = 0; in bcm63xx_prepare_prepend_transfer()
285 bcm63xx_prepend_printk_on_checkfail(bs, in bcm63xx_prepare_prepend_transfer()
293 if (bs->prepend_cnt + t->len > in bcm63xx_prepare_prepend_transfer()
295 bcm63xx_prepend_printk_on_checkfail(bs, in bcm63xx_prepare_prepend_transfer()
302 bcm63xx_prepend_printk_on_checkfail(bs, in bcm63xx_prepare_prepend_transfer()
308 memcpy(bs->prepend_buf + bs->prepend_cnt, t->tx_buf, t->len); in bcm63xx_prepare_prepend_transfer()
309 bs->prepend_cnt += t->len; in bcm63xx_prepare_prepend_transfer()
313 bcm63xx_prepend_printk_on_checkfail(bs, in bcm63xx_prepare_prepend_transfer()
327 t_prepend->len = bs->prepend_cnt; in bcm63xx_prepare_prepend_transfer()
328 t_prepend->tx_buf = bs->prepend_buf; in bcm63xx_prepare_prepend_transfer()
329 bs->prepend_cnt = 0; in bcm63xx_prepare_prepend_transfer()
336 if (bs->prepend_cnt > HSSPI_MAX_PREPEND_LEN) { in bcm63xx_prepare_prepend_transfer()
337 bcm63xx_prepend_printk_on_checkfail(bs, in bcm63xx_prepare_prepend_transfer()
351 struct bcm63xx_hsspi *bs = spi_controller_get_devdata(spi->controller); in bcm63xx_hsspi_do_prepend_txrx() local
362 if (t->len + bs->prepend_cnt > (HSSPI_BUFFER_LEN - HSSPI_OPCODE_LEN)) { in bcm63xx_hsspi_do_prepend_txrx()
363 dev_warn(&bs->pdev->dev, in bcm63xx_hsspi_do_prepend_txrx()
365 t->len, bs->prepend_cnt); in bcm63xx_hsspi_do_prepend_txrx()
369 bcm63xx_hsspi_set_clk(bs, spi, t->speed_hz); in bcm63xx_hsspi_do_prepend_txrx()
384 reg |= bs->prepend_cnt << MODE_CTRL_MULTIDATA_RD_STRT_SHIFT; in bcm63xx_hsspi_do_prepend_txrx()
388 reg |= bs->prepend_cnt << MODE_CTRL_MULTIDATA_WR_STRT_SHIFT; in bcm63xx_hsspi_do_prepend_txrx()
392 reg |= bs->prepend_cnt << MODE_CTRL_PREPENDBYTE_CNT_SHIFT; in bcm63xx_hsspi_do_prepend_txrx()
394 bs->regs + HSSPI_PROFILE_MODE_CTRL_REG(chip_select)); in bcm63xx_hsspi_do_prepend_txrx()
396 reinit_completion(&bs->done); in bcm63xx_hsspi_do_prepend_txrx()
397 if (bs->prepend_cnt) in bcm63xx_hsspi_do_prepend_txrx()
398 memcpy_toio(bs->fifo + HSSPI_OPCODE_LEN, bs->prepend_buf, in bcm63xx_hsspi_do_prepend_txrx()
399 bs->prepend_cnt); in bcm63xx_hsspi_do_prepend_txrx()
401 memcpy_toio(bs->fifo + HSSPI_OPCODE_LEN + bs->prepend_cnt, tx, in bcm63xx_hsspi_do_prepend_txrx()
405 __raw_writew(val, bs->fifo); in bcm63xx_hsspi_do_prepend_txrx()
407 if (bs->wait_mode == HSSPI_WAIT_MODE_INTR) in bcm63xx_hsspi_do_prepend_txrx()
408 __raw_writel(HSSPI_PINGx_CMD_DONE(0), bs->regs + HSSPI_INT_MASK_REG); in bcm63xx_hsspi_do_prepend_txrx()
414 __raw_writel(reg, bs->regs + HSSPI_PINGPONG_COMMAND_REG(0)); in bcm63xx_hsspi_do_prepend_txrx()
416 if (bcm63xx_hsspi_wait_cmd(bs)) in bcm63xx_hsspi_do_prepend_txrx()
420 memcpy_fromio(rx, bs->fifo, t->len); in bcm63xx_hsspi_do_prepend_txrx()
425 static void bcm63xx_hsspi_set_cs(struct bcm63xx_hsspi *bs, unsigned int cs, in bcm63xx_hsspi_set_cs() argument
430 mutex_lock(&bs->bus_mutex); in bcm63xx_hsspi_set_cs()
431 reg = __raw_readl(bs->regs + HSSPI_GLOBAL_CTRL_REG); in bcm63xx_hsspi_set_cs()
434 if (active == !(bs->cs_polarity & BIT(cs))) in bcm63xx_hsspi_set_cs()
437 __raw_writel(reg, bs->regs + HSSPI_GLOBAL_CTRL_REG); in bcm63xx_hsspi_set_cs()
438 mutex_unlock(&bs->bus_mutex); in bcm63xx_hsspi_set_cs()
441 static void bcm63xx_hsspi_set_clk(struct bcm63xx_hsspi *bs, in bcm63xx_hsspi_set_clk() argument
447 reg = DIV_ROUND_UP(2048, DIV_ROUND_UP(bs->speed_hz, hz)); in bcm63xx_hsspi_set_clk()
449 bs->regs + HSSPI_PROFILE_CLK_CTRL_REG(profile)); in bcm63xx_hsspi_set_clk()
451 reg = __raw_readl(bs->regs + HSSPI_PROFILE_SIGNAL_CTRL_REG(profile)); in bcm63xx_hsspi_set_clk()
456 __raw_writel(reg, bs->regs + HSSPI_PROFILE_SIGNAL_CTRL_REG(profile)); in bcm63xx_hsspi_set_clk()
458 mutex_lock(&bs->bus_mutex); in bcm63xx_hsspi_set_clk()
460 reg = __raw_readl(bs->regs + HSSPI_GLOBAL_CTRL_REG); in bcm63xx_hsspi_set_clk()
464 __raw_writel(reg, bs->regs + HSSPI_GLOBAL_CTRL_REG); in bcm63xx_hsspi_set_clk()
465 mutex_unlock(&bs->bus_mutex); in bcm63xx_hsspi_set_clk()
470 struct bcm63xx_hsspi *bs = spi_controller_get_devdata(spi->controller); in bcm63xx_hsspi_do_txrx() local
479 bcm63xx_hsspi_set_clk(bs, spi, t->speed_hz); in bcm63xx_hsspi_do_txrx()
481 bcm63xx_hsspi_set_cs(bs, spi_get_chipselect(spi, 0), true); in bcm63xx_hsspi_do_txrx()
504 bs->regs + HSSPI_PROFILE_MODE_CTRL_REG(chip_select)); in bcm63xx_hsspi_do_txrx()
509 reinit_completion(&bs->done); in bcm63xx_hsspi_do_txrx()
511 memcpy_toio(bs->fifo + HSSPI_OPCODE_LEN, tx, curr_step); in bcm63xx_hsspi_do_txrx()
516 __raw_writew(val, bs->fifo); in bcm63xx_hsspi_do_txrx()
519 if (bs->wait_mode == HSSPI_WAIT_MODE_INTR) in bcm63xx_hsspi_do_txrx()
521 bs->regs + HSSPI_INT_MASK_REG); in bcm63xx_hsspi_do_txrx()
526 __raw_writel(reg, bs->regs + HSSPI_PINGPONG_COMMAND_REG(0)); in bcm63xx_hsspi_do_txrx()
528 if (bcm63xx_hsspi_wait_cmd(bs)) in bcm63xx_hsspi_do_txrx()
532 memcpy_fromio(rx, bs->fifo, curr_step); in bcm63xx_hsspi_do_txrx()
544 struct bcm63xx_hsspi *bs = spi_controller_get_devdata(spi->controller); in bcm63xx_hsspi_setup() local
547 reg = __raw_readl(bs->regs + in bcm63xx_hsspi_setup()
554 __raw_writel(reg, bs->regs + in bcm63xx_hsspi_setup()
557 mutex_lock(&bs->bus_mutex); in bcm63xx_hsspi_setup()
558 reg = __raw_readl(bs->regs + HSSPI_GLOBAL_CTRL_REG); in bcm63xx_hsspi_setup()
561 if ((reg & GLOBAL_CTRL_CS_POLARITY_MASK) == bs->cs_polarity) { in bcm63xx_hsspi_setup()
566 __raw_writel(reg, bs->regs + HSSPI_GLOBAL_CTRL_REG); in bcm63xx_hsspi_setup()
570 bs->cs_polarity |= BIT(spi_get_chipselect(spi, 0)); in bcm63xx_hsspi_setup()
572 bs->cs_polarity &= ~BIT(spi_get_chipselect(spi, 0)); in bcm63xx_hsspi_setup()
574 mutex_unlock(&bs->bus_mutex); in bcm63xx_hsspi_setup()
582 struct bcm63xx_hsspi *bs = spi_controller_get_devdata(spi->controller); in bcm63xx_hsspi_do_dummy_cs_txrx() local
604 bcm63xx_hsspi_set_cs(bs, dummy_cs, true); in bcm63xx_hsspi_do_dummy_cs_txrx()
613 if (bs->xfer_mode == HSSPI_XFER_MODE_AUTO) { in bcm63xx_hsspi_do_dummy_cs_txrx()
616 dev_warn_once(&bs->pdev->dev, in bcm63xx_hsspi_do_dummy_cs_txrx()
636 bcm63xx_hsspi_set_cs(bs, spi_get_chipselect(spi, 0), false); in bcm63xx_hsspi_do_dummy_cs_txrx()
641 bcm63xx_hsspi_set_cs(bs, spi_get_chipselect(spi, 0), true); in bcm63xx_hsspi_do_dummy_cs_txrx()
645 bcm63xx_hsspi_set_cs(bs, spi_get_chipselect(spi, 0), t->cs_off); in bcm63xx_hsspi_do_dummy_cs_txrx()
649 bcm63xx_hsspi_set_cs(bs, dummy_cs, false); in bcm63xx_hsspi_do_dummy_cs_txrx()
651 bcm63xx_hsspi_set_cs(bs, spi_get_chipselect(spi, 0), false); in bcm63xx_hsspi_do_dummy_cs_txrx()
659 struct bcm63xx_hsspi *bs = spi_controller_get_devdata(host); in bcm63xx_hsspi_transfer_one() local
665 mutex_lock(&bs->msg_mutex); in bcm63xx_hsspi_transfer_one()
667 if (bs->xfer_mode != HSSPI_XFER_MODE_DUMMYCS) in bcm63xx_hsspi_transfer_one()
672 msg->actual_length = (t_prepend.len + bs->prepend_cnt); in bcm63xx_hsspi_transfer_one()
674 if (bs->xfer_mode == HSSPI_XFER_MODE_PREPEND) { in bcm63xx_hsspi_transfer_one()
675 dev_err(&bs->pdev->dev, in bcm63xx_hsspi_transfer_one()
682 mutex_unlock(&bs->msg_mutex); in bcm63xx_hsspi_transfer_one()
711 struct bcm63xx_hsspi *bs = (struct bcm63xx_hsspi *)dev_id; in bcm63xx_hsspi_interrupt() local
713 if (__raw_readl(bs->regs + HSSPI_INT_STATUS_MASKED_REG) == 0) in bcm63xx_hsspi_interrupt()
716 __raw_writel(HSSPI_INT_CLEAR_ALL, bs->regs + HSSPI_INT_STATUS_REG); in bcm63xx_hsspi_interrupt()
717 __raw_writel(0, bs->regs + HSSPI_INT_MASK_REG); in bcm63xx_hsspi_interrupt()
719 complete(&bs->done); in bcm63xx_hsspi_interrupt()
727 struct bcm63xx_hsspi *bs; in bcm63xx_hsspi_probe() local
782 host = spi_alloc_host(&pdev->dev, sizeof(*bs)); in bcm63xx_hsspi_probe()
788 bs = spi_controller_get_devdata(host); in bcm63xx_hsspi_probe()
789 bs->pdev = pdev; in bcm63xx_hsspi_probe()
790 bs->clk = clk; in bcm63xx_hsspi_probe()
791 bs->pll_clk = pll_clk; in bcm63xx_hsspi_probe()
792 bs->regs = regs; in bcm63xx_hsspi_probe()
793 bs->speed_hz = rate; in bcm63xx_hsspi_probe()
794 bs->fifo = (u8 __iomem *)(bs->regs + HSSPI_FIFO_REG(0)); in bcm63xx_hsspi_probe()
795 bs->wait_mode = HSSPI_WAIT_MODE_POLLING; in bcm63xx_hsspi_probe()
796 bs->prepend_buf = devm_kzalloc(dev, HSSPI_BUFFER_LEN, GFP_KERNEL); in bcm63xx_hsspi_probe()
797 if (!bs->prepend_buf) { in bcm63xx_hsspi_probe()
802 mutex_init(&bs->bus_mutex); in bcm63xx_hsspi_probe()
803 mutex_init(&bs->msg_mutex); in bcm63xx_hsspi_probe()
804 init_completion(&bs->done); in bcm63xx_hsspi_probe()
831 __raw_writel(0, bs->regs + HSSPI_INT_MASK_REG); in bcm63xx_hsspi_probe()
834 __raw_writel(HSSPI_INT_CLEAR_ALL, bs->regs + HSSPI_INT_STATUS_REG); in bcm63xx_hsspi_probe()
837 reg = __raw_readl(bs->regs + HSSPI_GLOBAL_CTRL_REG); in bcm63xx_hsspi_probe()
838 bs->cs_polarity = reg & GLOBAL_CTRL_CS_POLARITY_MASK; in bcm63xx_hsspi_probe()
840 bs->regs + HSSPI_GLOBAL_CTRL_REG); in bcm63xx_hsspi_probe()
844 pdev->name, bs); in bcm63xx_hsspi_probe()
884 struct bcm63xx_hsspi *bs = spi_controller_get_devdata(host); in bcm63xx_hsspi_remove() local
887 __raw_writel(0, bs->regs + HSSPI_INT_MASK_REG); in bcm63xx_hsspi_remove()
888 clk_disable_unprepare(bs->pll_clk); in bcm63xx_hsspi_remove()
889 clk_disable_unprepare(bs->clk); in bcm63xx_hsspi_remove()
897 struct bcm63xx_hsspi *bs = spi_controller_get_devdata(host); in bcm63xx_hsspi_suspend() local
900 clk_disable_unprepare(bs->pll_clk); in bcm63xx_hsspi_suspend()
901 clk_disable_unprepare(bs->clk); in bcm63xx_hsspi_suspend()
909 struct bcm63xx_hsspi *bs = spi_controller_get_devdata(host); in bcm63xx_hsspi_resume() local
912 ret = clk_prepare_enable(bs->clk); in bcm63xx_hsspi_resume()
916 if (bs->pll_clk) { in bcm63xx_hsspi_resume()
917 ret = clk_prepare_enable(bs->pll_clk); in bcm63xx_hsspi_resume()
919 clk_disable_unprepare(bs->clk); in bcm63xx_hsspi_resume()