Lines Matching refs:bs

105 static void bcm2835aux_debugfs_create(struct bcm2835aux_spi *bs,  in bcm2835aux_debugfs_create()  argument
116 bs->debugfs_dir = dir; in bcm2835aux_debugfs_create()
120 &bs->count_transfer_polling); in bcm2835aux_debugfs_create()
122 &bs->count_transfer_irq); in bcm2835aux_debugfs_create()
124 &bs->count_transfer_irq_after_poll); in bcm2835aux_debugfs_create()
127 static void bcm2835aux_debugfs_remove(struct bcm2835aux_spi *bs) in bcm2835aux_debugfs_remove() argument
129 debugfs_remove_recursive(bs->debugfs_dir); in bcm2835aux_debugfs_remove()
130 bs->debugfs_dir = NULL; in bcm2835aux_debugfs_remove()
133 static void bcm2835aux_debugfs_create(struct bcm2835aux_spi *bs, in bcm2835aux_debugfs_create() argument
138 static void bcm2835aux_debugfs_remove(struct bcm2835aux_spi *bs) in bcm2835aux_debugfs_remove() argument
143 static inline u32 bcm2835aux_rd(struct bcm2835aux_spi *bs, unsigned int reg) in bcm2835aux_rd() argument
145 return readl(bs->regs + reg); in bcm2835aux_rd()
148 static inline void bcm2835aux_wr(struct bcm2835aux_spi *bs, unsigned int reg, in bcm2835aux_wr() argument
151 writel(val, bs->regs + reg); in bcm2835aux_wr()
154 static inline void bcm2835aux_rd_fifo(struct bcm2835aux_spi *bs) in bcm2835aux_rd_fifo() argument
157 int count = min(bs->rx_len, 3); in bcm2835aux_rd_fifo()
159 data = bcm2835aux_rd(bs, BCM2835_AUX_SPI_IO); in bcm2835aux_rd_fifo()
160 if (bs->rx_buf) { in bcm2835aux_rd_fifo()
163 *bs->rx_buf++ = (data >> 16) & 0xff; in bcm2835aux_rd_fifo()
166 *bs->rx_buf++ = (data >> 8) & 0xff; in bcm2835aux_rd_fifo()
169 *bs->rx_buf++ = (data >> 0) & 0xff; in bcm2835aux_rd_fifo()
173 bs->rx_len -= count; in bcm2835aux_rd_fifo()
174 bs->pending -= count; in bcm2835aux_rd_fifo()
177 static inline void bcm2835aux_wr_fifo(struct bcm2835aux_spi *bs) in bcm2835aux_wr_fifo() argument
185 count = min(bs->tx_len, 3); in bcm2835aux_wr_fifo()
188 byte = bs->tx_buf ? *bs->tx_buf++ : 0; in bcm2835aux_wr_fifo()
196 bs->tx_len -= count; in bcm2835aux_wr_fifo()
197 bs->pending += count; in bcm2835aux_wr_fifo()
200 if (bs->tx_len) in bcm2835aux_wr_fifo()
201 bcm2835aux_wr(bs, BCM2835_AUX_SPI_TXHOLD, data); in bcm2835aux_wr_fifo()
203 bcm2835aux_wr(bs, BCM2835_AUX_SPI_IO, data); in bcm2835aux_wr_fifo()
206 static void bcm2835aux_spi_reset_hw(struct bcm2835aux_spi *bs) in bcm2835aux_spi_reset_hw() argument
209 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, 0); in bcm2835aux_spi_reset_hw()
210 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL0, in bcm2835aux_spi_reset_hw()
214 static void bcm2835aux_spi_transfer_helper(struct bcm2835aux_spi *bs) in bcm2835aux_spi_transfer_helper() argument
216 u32 stat = bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT); in bcm2835aux_spi_transfer_helper()
219 for (; bs->rx_len && (stat & BCM2835_AUX_SPI_STAT_RX_LVL); in bcm2835aux_spi_transfer_helper()
220 stat = bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT)) in bcm2835aux_spi_transfer_helper()
221 bcm2835aux_rd_fifo(bs); in bcm2835aux_spi_transfer_helper()
224 while (bs->tx_len && in bcm2835aux_spi_transfer_helper()
225 (bs->pending < 12) && in bcm2835aux_spi_transfer_helper()
226 (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) & in bcm2835aux_spi_transfer_helper()
228 bcm2835aux_wr_fifo(bs); in bcm2835aux_spi_transfer_helper()
235 struct bcm2835aux_spi *bs = spi_controller_get_devdata(host); in bcm2835aux_spi_interrupt() local
238 if (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_CNTL1) & in bcm2835aux_spi_interrupt()
243 bcm2835aux_spi_transfer_helper(bs); in bcm2835aux_spi_interrupt()
245 if (!bs->tx_len) { in bcm2835aux_spi_interrupt()
247 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1] | in bcm2835aux_spi_interrupt()
252 if (!bs->rx_len) { in bcm2835aux_spi_interrupt()
253 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1]); in bcm2835aux_spi_interrupt()
264 struct bcm2835aux_spi *bs = spi_controller_get_devdata(host); in __bcm2835aux_spi_transfer_one_irq() local
267 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1] | in __bcm2835aux_spi_transfer_one_irq()
279 struct bcm2835aux_spi *bs = spi_controller_get_devdata(host); in bcm2835aux_spi_transfer_one_irq() local
282 bs->count_transfer_irq++; in bcm2835aux_spi_transfer_one_irq()
285 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1]); in bcm2835aux_spi_transfer_one_irq()
286 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL0, bs->cntl[0]); in bcm2835aux_spi_transfer_one_irq()
289 while ((bs->tx_len) && in bcm2835aux_spi_transfer_one_irq()
290 (bs->pending < 12) && in bcm2835aux_spi_transfer_one_irq()
291 (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) & in bcm2835aux_spi_transfer_one_irq()
293 bcm2835aux_wr_fifo(bs); in bcm2835aux_spi_transfer_one_irq()
304 struct bcm2835aux_spi *bs = spi_controller_get_devdata(host); in bcm2835aux_spi_transfer_one_poll() local
308 bs->count_transfer_polling++; in bcm2835aux_spi_transfer_one_poll()
311 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1]); in bcm2835aux_spi_transfer_one_poll()
312 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL0, bs->cntl[0]); in bcm2835aux_spi_transfer_one_poll()
318 while (bs->rx_len) { in bcm2835aux_spi_transfer_one_poll()
321 bcm2835aux_spi_transfer_helper(bs); in bcm2835aux_spi_transfer_one_poll()
324 if (bs->rx_len && time_after(jiffies, timeout)) { in bcm2835aux_spi_transfer_one_poll()
328 bs->tx_len, bs->rx_len); in bcm2835aux_spi_transfer_one_poll()
330 bs->count_transfer_irq_after_poll++; in bcm2835aux_spi_transfer_one_poll()
344 struct bcm2835aux_spi *bs = spi_controller_get_devdata(host); in bcm2835aux_spi_transfer_one() local
358 clk_hz = clk_get_rate(bs->clk); in bcm2835aux_spi_transfer_one()
370 bs->cntl[0] &= ~(BCM2835_AUX_SPI_CNTL0_SPEED); in bcm2835aux_spi_transfer_one()
372 bs->cntl[0] |= speed << BCM2835_AUX_SPI_CNTL0_SPEED_SHIFT; in bcm2835aux_spi_transfer_one()
377 bs->tx_buf = tfr->tx_buf; in bcm2835aux_spi_transfer_one()
378 bs->rx_buf = tfr->rx_buf; in bcm2835aux_spi_transfer_one()
379 bs->tx_len = tfr->len; in bcm2835aux_spi_transfer_one()
380 bs->rx_len = tfr->len; in bcm2835aux_spi_transfer_one()
381 bs->pending = 0; in bcm2835aux_spi_transfer_one()
405 struct bcm2835aux_spi *bs = spi_controller_get_devdata(host); in bcm2835aux_spi_prepare_message() local
407 bs->cntl[0] = BCM2835_AUX_SPI_CNTL0_ENABLE | in bcm2835aux_spi_prepare_message()
410 bs->cntl[1] = BCM2835_AUX_SPI_CNTL1_MSBF_IN; in bcm2835aux_spi_prepare_message()
414 bs->cntl[0] |= BCM2835_AUX_SPI_CNTL0_CPOL; in bcm2835aux_spi_prepare_message()
415 bs->cntl[0] |= BCM2835_AUX_SPI_CNTL0_OUT_RISING; in bcm2835aux_spi_prepare_message()
417 bs->cntl[0] |= BCM2835_AUX_SPI_CNTL0_IN_RISING; in bcm2835aux_spi_prepare_message()
419 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1]); in bcm2835aux_spi_prepare_message()
420 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL0, bs->cntl[0]); in bcm2835aux_spi_prepare_message()
428 struct bcm2835aux_spi *bs = spi_controller_get_devdata(host); in bcm2835aux_spi_unprepare_message() local
430 bcm2835aux_spi_reset_hw(bs); in bcm2835aux_spi_unprepare_message()
438 struct bcm2835aux_spi *bs = spi_controller_get_devdata(host); in bcm2835aux_spi_handle_err() local
440 bcm2835aux_spi_reset_hw(bs); in bcm2835aux_spi_handle_err()
477 struct bcm2835aux_spi *bs; in bcm2835aux_spi_probe() local
481 host = devm_spi_alloc_host(&pdev->dev, sizeof(*bs)); in bcm2835aux_spi_probe()
508 bs = spi_controller_get_devdata(host); in bcm2835aux_spi_probe()
511 bs->regs = devm_platform_ioremap_resource(pdev, 0); in bcm2835aux_spi_probe()
512 if (IS_ERR(bs->regs)) in bcm2835aux_spi_probe()
513 return PTR_ERR(bs->regs); in bcm2835aux_spi_probe()
515 bs->clk = devm_clk_get(&pdev->dev, NULL); in bcm2835aux_spi_probe()
516 if (IS_ERR(bs->clk)) { in bcm2835aux_spi_probe()
517 err = PTR_ERR(bs->clk); in bcm2835aux_spi_probe()
522 bs->irq = platform_get_irq(pdev, 0); in bcm2835aux_spi_probe()
523 if (bs->irq < 0) in bcm2835aux_spi_probe()
524 return bs->irq; in bcm2835aux_spi_probe()
527 err = clk_prepare_enable(bs->clk); in bcm2835aux_spi_probe()
534 clk_hz = clk_get_rate(bs->clk); in bcm2835aux_spi_probe()
542 bcm2835aux_spi_reset_hw(bs); in bcm2835aux_spi_probe()
544 err = devm_request_irq(&pdev->dev, bs->irq, in bcm2835aux_spi_probe()
559 bcm2835aux_debugfs_create(bs, dev_name(&pdev->dev)); in bcm2835aux_spi_probe()
564 clk_disable_unprepare(bs->clk); in bcm2835aux_spi_probe()
571 struct bcm2835aux_spi *bs = spi_controller_get_devdata(host); in bcm2835aux_spi_remove() local
573 bcm2835aux_debugfs_remove(bs); in bcm2835aux_spi_remove()
577 bcm2835aux_spi_reset_hw(bs); in bcm2835aux_spi_remove()
580 clk_disable_unprepare(bs->clk); in bcm2835aux_spi_remove()