Lines Matching +full:long +full:- +full:term
1 // SPDX-License-Identifier: GPL-2.0
7 // Based on spi-mt7621.c:
9 // Copyright (C) 2011-2013 Gabor Juhos <juhosg@openwrt.org>
10 // Copyright (C) 2014-2015 Felix Fietkau <nbd@nbd.name>
20 #define DRIVER_NAME "spi-ar934x"
37 #define AR934X_SPI_SHIFT_VAL(cs, term, count) \ argument
39 (term) << AR934X_SPI_SHIFT_TERM | (count))
52 int div = DIV_ROUND_UP(sp->clk_freq, freq * 2) - 1; in ar934x_spi_clk_div()
57 return -EINVAL; in ar934x_spi_clk_div()
64 struct ar934x_spi *sp = spi_controller_get_devdata(spi->master); in ar934x_spi_setup()
66 if ((spi->max_speed_hz == 0) || in ar934x_spi_setup()
67 (spi->max_speed_hz > (sp->clk_freq / 2))) { in ar934x_spi_setup()
68 spi->max_speed_hz = sp->clk_freq / 2; in ar934x_spi_setup()
69 } else if (spi->max_speed_hz < (sp->clk_freq / 128)) { in ar934x_spi_setup()
70 dev_err(&spi->dev, "spi clock is too low\n"); in ar934x_spi_setup()
71 return -EINVAL; in ar934x_spi_setup()
82 struct spi_device *spi = m->spi; in ar934x_spi_transfer_one_message()
83 unsigned long trx_done, trx_cur; in ar934x_spi_transfer_one_message()
85 u8 term = 0; in ar934x_spi_transfer_one_message() local
91 m->actual_length = 0; in ar934x_spi_transfer_one_message()
92 list_for_each_entry(t, &m->transfers, transfer_list) { in ar934x_spi_transfer_one_message()
93 if (t->speed_hz) in ar934x_spi_transfer_one_message()
94 div = ar934x_spi_clk_div(sp, t->speed_hz); in ar934x_spi_transfer_one_message()
96 div = ar934x_spi_clk_div(sp, spi->max_speed_hz); in ar934x_spi_transfer_one_message()
98 stat = -EIO; in ar934x_spi_transfer_one_message()
102 reg = ioread32(sp->base + AR934X_SPI_REG_CTRL); in ar934x_spi_transfer_one_message()
105 iowrite32(reg, sp->base + AR934X_SPI_REG_CTRL); in ar934x_spi_transfer_one_message()
106 iowrite32(0, sp->base + AR934X_SPI_DATAOUT); in ar934x_spi_transfer_one_message()
108 for (trx_done = 0; trx_done < t->len; trx_done += 4) { in ar934x_spi_transfer_one_message()
109 trx_cur = t->len - trx_done; in ar934x_spi_transfer_one_message()
112 else if (list_is_last(&t->transfer_list, &m->transfers)) in ar934x_spi_transfer_one_message()
113 term = 1; in ar934x_spi_transfer_one_message()
115 if (t->tx_buf) { in ar934x_spi_transfer_one_message()
116 tx_buf = t->tx_buf + trx_done; in ar934x_spi_transfer_one_message()
120 iowrite32(reg, sp->base + AR934X_SPI_DATAOUT); in ar934x_spi_transfer_one_message()
123 reg = AR934X_SPI_SHIFT_VAL(spi->chip_select, term, in ar934x_spi_transfer_one_message()
125 iowrite32(reg, sp->base + AR934X_SPI_REG_SHIFT_CTRL); in ar934x_spi_transfer_one_message()
127 sp->base + AR934X_SPI_REG_SHIFT_CTRL, reg, in ar934x_spi_transfer_one_message()
132 if (t->rx_buf) { in ar934x_spi_transfer_one_message()
133 reg = ioread32(sp->base + AR934X_SPI_DATAIN); in ar934x_spi_transfer_one_message()
134 buf = t->rx_buf + trx_done; in ar934x_spi_transfer_one_message()
136 buf[trx_cur - i - 1] = reg & 0xff; in ar934x_spi_transfer_one_message()
141 m->actual_length += t->len; in ar934x_spi_transfer_one_message()
145 m->status = stat; in ar934x_spi_transfer_one_message()
152 { .compatible = "qca,ar934x-spi" },
169 clk = devm_clk_get(&pdev->dev, NULL); in ar934x_spi_probe()
171 dev_err(&pdev->dev, "failed to get clock\n"); in ar934x_spi_probe()
179 ctlr = spi_alloc_master(&pdev->dev, sizeof(*sp)); in ar934x_spi_probe()
181 dev_info(&pdev->dev, "failed to allocate spi controller\n"); in ar934x_spi_probe()
182 return -ENOMEM; in ar934x_spi_probe()
190 ctlr->mode_bits = SPI_LSB_FIRST; in ar934x_spi_probe()
191 ctlr->setup = ar934x_spi_setup; in ar934x_spi_probe()
192 ctlr->transfer_one_message = ar934x_spi_transfer_one_message; in ar934x_spi_probe()
193 ctlr->bits_per_word_mask = SPI_BPW_MASK(8); in ar934x_spi_probe()
194 ctlr->dev.of_node = pdev->dev.of_node; in ar934x_spi_probe()
195 ctlr->num_chipselect = 3; in ar934x_spi_probe()
197 dev_set_drvdata(&pdev->dev, ctlr); in ar934x_spi_probe()
200 sp->base = base; in ar934x_spi_probe()
201 sp->clk = clk; in ar934x_spi_probe()
202 sp->clk_freq = clk_get_rate(clk); in ar934x_spi_probe()
203 sp->ctlr = ctlr; in ar934x_spi_probe()
205 return devm_spi_register_controller(&pdev->dev, ctlr); in ar934x_spi_probe()
213 ctlr = dev_get_drvdata(&pdev->dev); in ar934x_spi_remove()
216 clk_disable_unprepare(sp->clk); in ar934x_spi_remove()