Lines Matching refs:bs

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