Lines Matching refs:bs
107 static void bcm2835aux_debugfs_create(struct bcm2835aux_spi *bs, in bcm2835aux_debugfs_create() argument
118 bs->debugfs_dir = dir; in bcm2835aux_debugfs_create()
122 &bs->count_transfer_polling); in bcm2835aux_debugfs_create()
124 &bs->count_transfer_irq); in bcm2835aux_debugfs_create()
126 &bs->count_transfer_irq_after_poll); in bcm2835aux_debugfs_create()
129 static void bcm2835aux_debugfs_remove(struct bcm2835aux_spi *bs) in bcm2835aux_debugfs_remove() argument
131 debugfs_remove_recursive(bs->debugfs_dir); in bcm2835aux_debugfs_remove()
132 bs->debugfs_dir = NULL; in bcm2835aux_debugfs_remove()
135 static void bcm2835aux_debugfs_create(struct bcm2835aux_spi *bs, in bcm2835aux_debugfs_create() argument
140 static void bcm2835aux_debugfs_remove(struct bcm2835aux_spi *bs) in bcm2835aux_debugfs_remove() argument
145 static inline u32 bcm2835aux_rd(struct bcm2835aux_spi *bs, unsigned int reg) in bcm2835aux_rd() argument
147 return readl(bs->regs + reg); in bcm2835aux_rd()
150 static inline void bcm2835aux_wr(struct bcm2835aux_spi *bs, unsigned int reg, in bcm2835aux_wr() argument
153 writel(val, bs->regs + reg); in bcm2835aux_wr()
156 static inline void bcm2835aux_rd_fifo(struct bcm2835aux_spi *bs) in bcm2835aux_rd_fifo() argument
159 int count = min(bs->rx_len, 3); in bcm2835aux_rd_fifo()
161 data = bcm2835aux_rd(bs, BCM2835_AUX_SPI_IO); in bcm2835aux_rd_fifo()
162 if (bs->rx_buf) { in bcm2835aux_rd_fifo()
165 *bs->rx_buf++ = (data >> 16) & 0xff; in bcm2835aux_rd_fifo()
168 *bs->rx_buf++ = (data >> 8) & 0xff; in bcm2835aux_rd_fifo()
171 *bs->rx_buf++ = (data >> 0) & 0xff; in bcm2835aux_rd_fifo()
175 bs->rx_len -= count; in bcm2835aux_rd_fifo()
176 bs->pending -= count; in bcm2835aux_rd_fifo()
179 static inline void bcm2835aux_wr_fifo(struct bcm2835aux_spi *bs) in bcm2835aux_wr_fifo() argument
187 count = min(bs->tx_len, 3); in bcm2835aux_wr_fifo()
190 byte = bs->tx_buf ? *bs->tx_buf++ : 0; in bcm2835aux_wr_fifo()
198 bs->tx_len -= count; in bcm2835aux_wr_fifo()
199 bs->pending += count; in bcm2835aux_wr_fifo()
202 if (bs->tx_len) in bcm2835aux_wr_fifo()
203 bcm2835aux_wr(bs, BCM2835_AUX_SPI_TXHOLD, data); in bcm2835aux_wr_fifo()
205 bcm2835aux_wr(bs, BCM2835_AUX_SPI_IO, data); in bcm2835aux_wr_fifo()
208 static void bcm2835aux_spi_reset_hw(struct bcm2835aux_spi *bs) in bcm2835aux_spi_reset_hw() argument
211 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, 0); in bcm2835aux_spi_reset_hw()
212 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL0, in bcm2835aux_spi_reset_hw()
216 static void bcm2835aux_spi_transfer_helper(struct bcm2835aux_spi *bs) in bcm2835aux_spi_transfer_helper() argument
218 u32 stat = bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT); in bcm2835aux_spi_transfer_helper()
221 for (; bs->rx_len && (stat & BCM2835_AUX_SPI_STAT_RX_LVL); in bcm2835aux_spi_transfer_helper()
222 stat = bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT)) in bcm2835aux_spi_transfer_helper()
223 bcm2835aux_rd_fifo(bs); in bcm2835aux_spi_transfer_helper()
226 while (bs->tx_len && in bcm2835aux_spi_transfer_helper()
227 (bs->pending < 12) && in bcm2835aux_spi_transfer_helper()
228 (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) & in bcm2835aux_spi_transfer_helper()
230 bcm2835aux_wr_fifo(bs); in bcm2835aux_spi_transfer_helper()
237 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_interrupt() local
240 if (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_CNTL1) & in bcm2835aux_spi_interrupt()
245 bcm2835aux_spi_transfer_helper(bs); in bcm2835aux_spi_interrupt()
247 if (!bs->tx_len) { in bcm2835aux_spi_interrupt()
249 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1] | in bcm2835aux_spi_interrupt()
254 if (!bs->rx_len) { in bcm2835aux_spi_interrupt()
255 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1]); in bcm2835aux_spi_interrupt()
266 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in __bcm2835aux_spi_transfer_one_irq() local
269 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1] | in __bcm2835aux_spi_transfer_one_irq()
281 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_transfer_one_irq() local
284 bs->count_transfer_irq++; in bcm2835aux_spi_transfer_one_irq()
287 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1]); in bcm2835aux_spi_transfer_one_irq()
288 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL0, bs->cntl[0]); in bcm2835aux_spi_transfer_one_irq()
291 while ((bs->tx_len) && in bcm2835aux_spi_transfer_one_irq()
292 (bs->pending < 12) && in bcm2835aux_spi_transfer_one_irq()
293 (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) & in bcm2835aux_spi_transfer_one_irq()
295 bcm2835aux_wr_fifo(bs); in bcm2835aux_spi_transfer_one_irq()
306 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_transfer_one_poll() local
310 bs->count_transfer_polling++; in bcm2835aux_spi_transfer_one_poll()
313 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1]); in bcm2835aux_spi_transfer_one_poll()
314 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL0, bs->cntl[0]); in bcm2835aux_spi_transfer_one_poll()
320 while (bs->rx_len) { in bcm2835aux_spi_transfer_one_poll()
323 bcm2835aux_spi_transfer_helper(bs); in bcm2835aux_spi_transfer_one_poll()
326 if (bs->rx_len && time_after(jiffies, timeout)) { in bcm2835aux_spi_transfer_one_poll()
330 bs->tx_len, bs->rx_len); in bcm2835aux_spi_transfer_one_poll()
332 bs->count_transfer_irq_after_poll++; in bcm2835aux_spi_transfer_one_poll()
346 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_transfer_one() local
360 clk_hz = clk_get_rate(bs->clk); in bcm2835aux_spi_transfer_one()
372 bs->cntl[0] &= ~(BCM2835_AUX_SPI_CNTL0_SPEED); in bcm2835aux_spi_transfer_one()
374 bs->cntl[0] |= speed << BCM2835_AUX_SPI_CNTL0_SPEED_SHIFT; in bcm2835aux_spi_transfer_one()
379 bs->tx_buf = tfr->tx_buf; in bcm2835aux_spi_transfer_one()
380 bs->rx_buf = tfr->rx_buf; in bcm2835aux_spi_transfer_one()
381 bs->tx_len = tfr->len; in bcm2835aux_spi_transfer_one()
382 bs->rx_len = tfr->len; in bcm2835aux_spi_transfer_one()
383 bs->pending = 0; in bcm2835aux_spi_transfer_one()
407 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_prepare_message() local
409 bs->cntl[0] = BCM2835_AUX_SPI_CNTL0_ENABLE | in bcm2835aux_spi_prepare_message()
412 bs->cntl[1] = BCM2835_AUX_SPI_CNTL1_MSBF_IN; in bcm2835aux_spi_prepare_message()
416 bs->cntl[0] |= BCM2835_AUX_SPI_CNTL0_CPOL; in bcm2835aux_spi_prepare_message()
417 bs->cntl[0] |= BCM2835_AUX_SPI_CNTL0_OUT_RISING; in bcm2835aux_spi_prepare_message()
419 bs->cntl[0] |= BCM2835_AUX_SPI_CNTL0_IN_RISING; in bcm2835aux_spi_prepare_message()
421 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1]); in bcm2835aux_spi_prepare_message()
422 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL0, bs->cntl[0]); in bcm2835aux_spi_prepare_message()
430 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_unprepare_message() local
432 bcm2835aux_spi_reset_hw(bs); in bcm2835aux_spi_unprepare_message()
440 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_handle_err() local
442 bcm2835aux_spi_reset_hw(bs); in bcm2835aux_spi_handle_err()
479 struct bcm2835aux_spi *bs; in bcm2835aux_spi_probe() local
483 master = devm_spi_alloc_master(&pdev->dev, sizeof(*bs)); in bcm2835aux_spi_probe()
510 bs = spi_master_get_devdata(master); in bcm2835aux_spi_probe()
513 bs->regs = devm_platform_ioremap_resource(pdev, 0); in bcm2835aux_spi_probe()
514 if (IS_ERR(bs->regs)) in bcm2835aux_spi_probe()
515 return PTR_ERR(bs->regs); in bcm2835aux_spi_probe()
517 bs->clk = devm_clk_get(&pdev->dev, NULL); in bcm2835aux_spi_probe()
518 if (IS_ERR(bs->clk)) { in bcm2835aux_spi_probe()
519 err = PTR_ERR(bs->clk); in bcm2835aux_spi_probe()
524 bs->irq = platform_get_irq(pdev, 0); in bcm2835aux_spi_probe()
525 if (bs->irq <= 0) in bcm2835aux_spi_probe()
526 return bs->irq ? bs->irq : -ENODEV; in bcm2835aux_spi_probe()
529 err = clk_prepare_enable(bs->clk); in bcm2835aux_spi_probe()
536 clk_hz = clk_get_rate(bs->clk); in bcm2835aux_spi_probe()
544 bcm2835aux_spi_reset_hw(bs); in bcm2835aux_spi_probe()
546 err = devm_request_irq(&pdev->dev, bs->irq, in bcm2835aux_spi_probe()
561 bcm2835aux_debugfs_create(bs, dev_name(&pdev->dev)); in bcm2835aux_spi_probe()
566 clk_disable_unprepare(bs->clk); in bcm2835aux_spi_probe()
573 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_remove() local
575 bcm2835aux_debugfs_remove(bs); in bcm2835aux_spi_remove()
579 bcm2835aux_spi_reset_hw(bs); in bcm2835aux_spi_remove()
582 clk_disable_unprepare(bs->clk); in bcm2835aux_spi_remove()