Lines Matching refs:bs

110 static inline u32 bcm2835aux_rd(struct bcm2835aux_spi *bs, unsigned reg)  in bcm2835aux_rd()  argument
112 return readl(bs->regs + reg); in bcm2835aux_rd()
115 static inline void bcm2835aux_wr(struct bcm2835aux_spi *bs, unsigned reg, in bcm2835aux_wr() argument
118 writel(val, bs->regs + reg); in bcm2835aux_wr()
121 static inline void bcm2835aux_rd_fifo(struct bcm2835aux_spi *bs) in bcm2835aux_rd_fifo() argument
124 int count = min(bs->rx_len, 3); in bcm2835aux_rd_fifo()
126 data = bcm2835aux_rd(bs, BCM2835_AUX_SPI_IO); in bcm2835aux_rd_fifo()
127 if (bs->rx_buf) { in bcm2835aux_rd_fifo()
130 *bs->rx_buf++ = (data >> 24) & 0xff; in bcm2835aux_rd_fifo()
133 *bs->rx_buf++ = (data >> 16) & 0xff; in bcm2835aux_rd_fifo()
136 *bs->rx_buf++ = (data >> 8) & 0xff; in bcm2835aux_rd_fifo()
139 *bs->rx_buf++ = (data >> 0) & 0xff; in bcm2835aux_rd_fifo()
143 bs->rx_len -= count; in bcm2835aux_rd_fifo()
144 bs->pending -= count; in bcm2835aux_rd_fifo()
147 static inline void bcm2835aux_wr_fifo(struct bcm2835aux_spi *bs) in bcm2835aux_wr_fifo() argument
155 count = min(bs->tx_len, 3); in bcm2835aux_wr_fifo()
158 byte = bs->tx_buf ? *bs->tx_buf++ : 0; in bcm2835aux_wr_fifo()
166 bs->tx_len -= count; in bcm2835aux_wr_fifo()
167 bs->pending += count; in bcm2835aux_wr_fifo()
170 if (bs->tx_len) in bcm2835aux_wr_fifo()
171 bcm2835aux_wr(bs, BCM2835_AUX_SPI_TXHOLD, data); in bcm2835aux_wr_fifo()
173 bcm2835aux_wr(bs, BCM2835_AUX_SPI_IO, data); in bcm2835aux_wr_fifo()
176 static void bcm2835aux_spi_reset_hw(struct bcm2835aux_spi *bs) in bcm2835aux_spi_reset_hw() argument
179 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, 0); in bcm2835aux_spi_reset_hw()
180 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL0, in bcm2835aux_spi_reset_hw()
187 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_interrupt() local
191 while (bs->rx_len && in bcm2835aux_spi_interrupt()
192 (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) & in bcm2835aux_spi_interrupt()
194 bcm2835aux_rd_fifo(bs); in bcm2835aux_spi_interrupt()
199 while (bs->tx_len && in bcm2835aux_spi_interrupt()
200 (bs->pending < 12) && in bcm2835aux_spi_interrupt()
201 (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) & in bcm2835aux_spi_interrupt()
203 bcm2835aux_wr_fifo(bs); in bcm2835aux_spi_interrupt()
208 while (bs->rx_len && in bcm2835aux_spi_interrupt()
209 (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) & in bcm2835aux_spi_interrupt()
211 bcm2835aux_rd_fifo(bs); in bcm2835aux_spi_interrupt()
216 if (!bs->rx_len) { in bcm2835aux_spi_interrupt()
217 bcm2835aux_spi_reset_hw(bs); in bcm2835aux_spi_interrupt()
229 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in __bcm2835aux_spi_transfer_one_irq() local
232 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1] | in __bcm2835aux_spi_transfer_one_irq()
244 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_transfer_one_irq() local
247 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1]); in bcm2835aux_spi_transfer_one_irq()
248 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL0, bs->cntl[0]); in bcm2835aux_spi_transfer_one_irq()
251 while ((bs->tx_len) && in bcm2835aux_spi_transfer_one_irq()
252 (bs->pending < 12) && in bcm2835aux_spi_transfer_one_irq()
253 (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) & in bcm2835aux_spi_transfer_one_irq()
255 bcm2835aux_wr_fifo(bs); in bcm2835aux_spi_transfer_one_irq()
266 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_transfer_one_poll() local
271 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1]); in bcm2835aux_spi_transfer_one_poll()
272 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL0, bs->cntl[0]); in bcm2835aux_spi_transfer_one_poll()
278 while (bs->rx_len) { in bcm2835aux_spi_transfer_one_poll()
280 stat = bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT); in bcm2835aux_spi_transfer_one_poll()
283 if ((bs->tx_len) && (!(stat & BCM2835_AUX_SPI_STAT_TX_FULL))) { in bcm2835aux_spi_transfer_one_poll()
284 bcm2835aux_wr_fifo(bs); in bcm2835aux_spi_transfer_one_poll()
290 bcm2835aux_rd_fifo(bs); in bcm2835aux_spi_transfer_one_poll()
294 bcm2835aux_rd_fifo(bs); in bcm2835aux_spi_transfer_one_poll()
299 if (bs->rx_len && time_after(jiffies, timeout)) { in bcm2835aux_spi_transfer_one_poll()
303 bs->tx_len, bs->rx_len); in bcm2835aux_spi_transfer_one_poll()
311 bcm2835aux_spi_reset_hw(bs); in bcm2835aux_spi_transfer_one_poll()
321 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_transfer_one() local
333 bs->cntl[0] = BCM2835_AUX_SPI_CNTL0_ENABLE | in bcm2835aux_spi_transfer_one()
336 bs->cntl[1] = BCM2835_AUX_SPI_CNTL1_MSBF_IN; in bcm2835aux_spi_transfer_one()
340 clk_hz = clk_get_rate(bs->clk); in bcm2835aux_spi_transfer_one()
351 bs->cntl[0] |= speed << BCM2835_AUX_SPI_CNTL0_SPEED_SHIFT; in bcm2835aux_spi_transfer_one()
357 bs->cntl[0] |= BCM2835_AUX_SPI_CNTL0_CPOL; in bcm2835aux_spi_transfer_one()
359 bs->cntl[0] |= BCM2835_AUX_SPI_CNTL0_CPHA_OUT | in bcm2835aux_spi_transfer_one()
363 bs->tx_buf = tfr->tx_buf; in bcm2835aux_spi_transfer_one()
364 bs->rx_buf = tfr->rx_buf; in bcm2835aux_spi_transfer_one()
365 bs->tx_len = tfr->len; in bcm2835aux_spi_transfer_one()
366 bs->rx_len = tfr->len; in bcm2835aux_spi_transfer_one()
367 bs->pending = 0; in bcm2835aux_spi_transfer_one()
388 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_handle_err() local
390 bcm2835aux_spi_reset_hw(bs); in bcm2835aux_spi_handle_err()
396 struct bcm2835aux_spi *bs; in bcm2835aux_spi_probe() local
401 master = spi_alloc_master(&pdev->dev, sizeof(*bs)); in bcm2835aux_spi_probe()
415 bs = spi_master_get_devdata(master); in bcm2835aux_spi_probe()
419 bs->regs = devm_ioremap_resource(&pdev->dev, res); in bcm2835aux_spi_probe()
420 if (IS_ERR(bs->regs)) { in bcm2835aux_spi_probe()
421 err = PTR_ERR(bs->regs); in bcm2835aux_spi_probe()
425 bs->clk = devm_clk_get(&pdev->dev, NULL); in bcm2835aux_spi_probe()
426 if ((!bs->clk) || (IS_ERR(bs->clk))) { in bcm2835aux_spi_probe()
427 err = PTR_ERR(bs->clk); in bcm2835aux_spi_probe()
432 bs->irq = platform_get_irq(pdev, 0); in bcm2835aux_spi_probe()
433 if (bs->irq <= 0) { in bcm2835aux_spi_probe()
434 dev_err(&pdev->dev, "could not get IRQ: %d\n", bs->irq); in bcm2835aux_spi_probe()
435 err = bs->irq ? bs->irq : -ENODEV; in bcm2835aux_spi_probe()
440 err = clk_prepare_enable(bs->clk); in bcm2835aux_spi_probe()
447 clk_hz = clk_get_rate(bs->clk); in bcm2835aux_spi_probe()
455 bcm2835aux_spi_reset_hw(bs); in bcm2835aux_spi_probe()
457 err = devm_request_irq(&pdev->dev, bs->irq, in bcm2835aux_spi_probe()
475 clk_disable_unprepare(bs->clk); in bcm2835aux_spi_probe()
484 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_remove() local
486 bcm2835aux_spi_reset_hw(bs); in bcm2835aux_spi_remove()
489 clk_disable_unprepare(bs->clk); in bcm2835aux_spi_remove()