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