Lines Matching refs:bs
108 static void bcm2835aux_debugfs_create(struct bcm2835aux_spi *bs, in bcm2835aux_debugfs_create() argument
119 bs->debugfs_dir = dir; in bcm2835aux_debugfs_create()
123 &bs->count_transfer_polling); in bcm2835aux_debugfs_create()
125 &bs->count_transfer_irq); in bcm2835aux_debugfs_create()
127 &bs->count_transfer_irq_after_poll); in bcm2835aux_debugfs_create()
130 static void bcm2835aux_debugfs_remove(struct bcm2835aux_spi *bs) in bcm2835aux_debugfs_remove() argument
132 debugfs_remove_recursive(bs->debugfs_dir); in bcm2835aux_debugfs_remove()
133 bs->debugfs_dir = NULL; in bcm2835aux_debugfs_remove()
136 static void bcm2835aux_debugfs_create(struct bcm2835aux_spi *bs, in bcm2835aux_debugfs_create() argument
141 static void bcm2835aux_debugfs_remove(struct bcm2835aux_spi *bs) in bcm2835aux_debugfs_remove() argument
146 static inline u32 bcm2835aux_rd(struct bcm2835aux_spi *bs, unsigned int reg) in bcm2835aux_rd() argument
148 return readl(bs->regs + reg); in bcm2835aux_rd()
151 static inline void bcm2835aux_wr(struct bcm2835aux_spi *bs, unsigned int reg, in bcm2835aux_wr() argument
154 writel(val, bs->regs + reg); in bcm2835aux_wr()
157 static inline void bcm2835aux_rd_fifo(struct bcm2835aux_spi *bs) in bcm2835aux_rd_fifo() argument
160 int count = min(bs->rx_len, 3); in bcm2835aux_rd_fifo()
162 data = bcm2835aux_rd(bs, BCM2835_AUX_SPI_IO); in bcm2835aux_rd_fifo()
163 if (bs->rx_buf) { in bcm2835aux_rd_fifo()
166 *bs->rx_buf++ = (data >> 16) & 0xff; in bcm2835aux_rd_fifo()
169 *bs->rx_buf++ = (data >> 8) & 0xff; in bcm2835aux_rd_fifo()
172 *bs->rx_buf++ = (data >> 0) & 0xff; in bcm2835aux_rd_fifo()
176 bs->rx_len -= count; in bcm2835aux_rd_fifo()
177 bs->pending -= count; in bcm2835aux_rd_fifo()
180 static inline void bcm2835aux_wr_fifo(struct bcm2835aux_spi *bs) in bcm2835aux_wr_fifo() argument
188 count = min(bs->tx_len, 3); in bcm2835aux_wr_fifo()
191 byte = bs->tx_buf ? *bs->tx_buf++ : 0; in bcm2835aux_wr_fifo()
199 bs->tx_len -= count; in bcm2835aux_wr_fifo()
200 bs->pending += count; in bcm2835aux_wr_fifo()
203 if (bs->tx_len) in bcm2835aux_wr_fifo()
204 bcm2835aux_wr(bs, BCM2835_AUX_SPI_TXHOLD, data); in bcm2835aux_wr_fifo()
206 bcm2835aux_wr(bs, BCM2835_AUX_SPI_IO, data); in bcm2835aux_wr_fifo()
209 static void bcm2835aux_spi_reset_hw(struct bcm2835aux_spi *bs) in bcm2835aux_spi_reset_hw() argument
212 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, 0); in bcm2835aux_spi_reset_hw()
213 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL0, in bcm2835aux_spi_reset_hw()
217 static void bcm2835aux_spi_transfer_helper(struct bcm2835aux_spi *bs) in bcm2835aux_spi_transfer_helper() argument
219 u32 stat = bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT); in bcm2835aux_spi_transfer_helper()
222 for (; bs->rx_len && (stat & BCM2835_AUX_SPI_STAT_RX_LVL); in bcm2835aux_spi_transfer_helper()
223 stat = bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT)) in bcm2835aux_spi_transfer_helper()
224 bcm2835aux_rd_fifo(bs); in bcm2835aux_spi_transfer_helper()
227 while (bs->tx_len && in bcm2835aux_spi_transfer_helper()
228 (bs->pending < 12) && in bcm2835aux_spi_transfer_helper()
229 (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) & in bcm2835aux_spi_transfer_helper()
231 bcm2835aux_wr_fifo(bs); in bcm2835aux_spi_transfer_helper()
238 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_interrupt() local
241 if (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_CNTL1) & in bcm2835aux_spi_interrupt()
246 bcm2835aux_spi_transfer_helper(bs); in bcm2835aux_spi_interrupt()
248 if (!bs->tx_len) { in bcm2835aux_spi_interrupt()
250 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1] | in bcm2835aux_spi_interrupt()
255 if (!bs->rx_len) { in bcm2835aux_spi_interrupt()
256 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1]); in bcm2835aux_spi_interrupt()
267 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in __bcm2835aux_spi_transfer_one_irq() local
270 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1] | in __bcm2835aux_spi_transfer_one_irq()
282 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_transfer_one_irq() local
285 bs->count_transfer_irq++; in bcm2835aux_spi_transfer_one_irq()
288 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1]); in bcm2835aux_spi_transfer_one_irq()
289 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL0, bs->cntl[0]); in bcm2835aux_spi_transfer_one_irq()
292 while ((bs->tx_len) && in bcm2835aux_spi_transfer_one_irq()
293 (bs->pending < 12) && in bcm2835aux_spi_transfer_one_irq()
294 (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) & in bcm2835aux_spi_transfer_one_irq()
296 bcm2835aux_wr_fifo(bs); in bcm2835aux_spi_transfer_one_irq()
307 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_transfer_one_poll() local
311 bs->count_transfer_polling++; in bcm2835aux_spi_transfer_one_poll()
314 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1]); in bcm2835aux_spi_transfer_one_poll()
315 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL0, bs->cntl[0]); in bcm2835aux_spi_transfer_one_poll()
321 while (bs->rx_len) { in bcm2835aux_spi_transfer_one_poll()
324 bcm2835aux_spi_transfer_helper(bs); in bcm2835aux_spi_transfer_one_poll()
327 if (bs->rx_len && time_after(jiffies, timeout)) { in bcm2835aux_spi_transfer_one_poll()
331 bs->tx_len, bs->rx_len); in bcm2835aux_spi_transfer_one_poll()
333 bs->count_transfer_irq_after_poll++; in bcm2835aux_spi_transfer_one_poll()
347 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_transfer_one() local
361 clk_hz = clk_get_rate(bs->clk); in bcm2835aux_spi_transfer_one()
373 bs->cntl[0] &= ~(BCM2835_AUX_SPI_CNTL0_SPEED); in bcm2835aux_spi_transfer_one()
375 bs->cntl[0] |= speed << BCM2835_AUX_SPI_CNTL0_SPEED_SHIFT; in bcm2835aux_spi_transfer_one()
380 bs->tx_buf = tfr->tx_buf; in bcm2835aux_spi_transfer_one()
381 bs->rx_buf = tfr->rx_buf; in bcm2835aux_spi_transfer_one()
382 bs->tx_len = tfr->len; in bcm2835aux_spi_transfer_one()
383 bs->rx_len = tfr->len; in bcm2835aux_spi_transfer_one()
384 bs->pending = 0; in bcm2835aux_spi_transfer_one()
408 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_prepare_message() local
410 bs->cntl[0] = BCM2835_AUX_SPI_CNTL0_ENABLE | in bcm2835aux_spi_prepare_message()
413 bs->cntl[1] = BCM2835_AUX_SPI_CNTL1_MSBF_IN; in bcm2835aux_spi_prepare_message()
417 bs->cntl[0] |= BCM2835_AUX_SPI_CNTL0_CPOL; in bcm2835aux_spi_prepare_message()
418 bs->cntl[0] |= BCM2835_AUX_SPI_CNTL0_OUT_RISING; in bcm2835aux_spi_prepare_message()
420 bs->cntl[0] |= BCM2835_AUX_SPI_CNTL0_IN_RISING; in bcm2835aux_spi_prepare_message()
422 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1]); in bcm2835aux_spi_prepare_message()
423 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL0, bs->cntl[0]); in bcm2835aux_spi_prepare_message()
431 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_unprepare_message() local
433 bcm2835aux_spi_reset_hw(bs); in bcm2835aux_spi_unprepare_message()
441 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_handle_err() local
443 bcm2835aux_spi_reset_hw(bs); in bcm2835aux_spi_handle_err()
493 struct bcm2835aux_spi *bs; in bcm2835aux_spi_probe() local
497 master = devm_spi_alloc_master(&pdev->dev, sizeof(*bs)); in bcm2835aux_spi_probe()
523 bs = spi_master_get_devdata(master); in bcm2835aux_spi_probe()
526 bs->regs = devm_platform_ioremap_resource(pdev, 0); in bcm2835aux_spi_probe()
527 if (IS_ERR(bs->regs)) in bcm2835aux_spi_probe()
528 return PTR_ERR(bs->regs); in bcm2835aux_spi_probe()
530 bs->clk = devm_clk_get(&pdev->dev, NULL); in bcm2835aux_spi_probe()
531 if (IS_ERR(bs->clk)) { in bcm2835aux_spi_probe()
532 err = PTR_ERR(bs->clk); in bcm2835aux_spi_probe()
537 bs->irq = platform_get_irq(pdev, 0); in bcm2835aux_spi_probe()
538 if (bs->irq <= 0) in bcm2835aux_spi_probe()
539 return bs->irq ? bs->irq : -ENODEV; in bcm2835aux_spi_probe()
542 err = clk_prepare_enable(bs->clk); in bcm2835aux_spi_probe()
549 clk_hz = clk_get_rate(bs->clk); in bcm2835aux_spi_probe()
557 bcm2835aux_spi_reset_hw(bs); in bcm2835aux_spi_probe()
559 err = devm_request_irq(&pdev->dev, bs->irq, in bcm2835aux_spi_probe()
574 bcm2835aux_debugfs_create(bs, dev_name(&pdev->dev)); in bcm2835aux_spi_probe()
579 clk_disable_unprepare(bs->clk); in bcm2835aux_spi_probe()
586 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); in bcm2835aux_spi_remove() local
588 bcm2835aux_debugfs_remove(bs); in bcm2835aux_spi_remove()
592 bcm2835aux_spi_reset_hw(bs); in bcm2835aux_spi_remove()
595 clk_disable_unprepare(bs->clk); in bcm2835aux_spi_remove()