drivers/spi/spi-bitbang.c
Source file repositories/reference/linux-study-clean/drivers/spi/spi-bitbang.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/spi/spi-bitbang.c- Extension
.c- Size
- 11692 bytes
- Lines
- 451
- Domain
- Driver Families
- Bucket
- drivers/spi
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/spinlock.hlinux/workqueue.hlinux/interrupt.hlinux/module.hlinux/delay.hlinux/errno.hlinux/platform_device.hlinux/slab.hlinux/time64.hlinux/spi/spi.hlinux/spi/spi_bitbang.h
Detected Declarations
struct spi_bitbang_csfunction bitbang_txrx_8function bitbang_txrx_16function bitbang_txrx_32function spi_bitbang_setup_transferfunction spi_bitbang_setupfunction spi_bitbang_cleanupfunction spi_bitbang_bufsfunction spi_bitbang_prepare_hardwarefunction spi_bitbang_transfer_onefunction spi_bitbang_unprepare_hardwarefunction spi_bitbang_set_csfunction spi_bitbang_initfunction spi_bitbang_cleanupfunction spi_bitbang_stopexport spi_bitbang_setup_transferexport spi_bitbang_setupexport spi_bitbang_cleanupexport spi_bitbang_initexport spi_bitbang_startexport spi_bitbang_stop
Annotated Snippet
struct spi_bitbang_cs {
unsigned int nsecs; /* (clock cycle time) / 2 */
spi_bb_txrx_word_fn txrx_word;
spi_bb_txrx_bufs_fn txrx_bufs;
};
static unsigned int bitbang_txrx_8(struct spi_device *spi,
spi_bb_txrx_word_fn txrx_word,
unsigned int ns,
struct spi_transfer *t,
unsigned int flags)
{
struct spi_bitbang *bitbang;
unsigned int bits = t->bits_per_word;
unsigned int count = t->len;
const u8 *tx = t->tx_buf;
u8 *rx = t->rx_buf;
bitbang = spi_controller_get_devdata(spi->controller);
while (likely(count > 0)) {
u8 word = 0;
if (tx)
word = *tx++;
else
word = spi->mode & SPI_MOSI_IDLE_HIGH ? 0xFF : 0;
word = txrx_word(spi, ns, word, bits, flags);
if (rx)
*rx++ = word;
count -= 1;
}
if (bitbang->set_mosi_idle)
bitbang->set_mosi_idle(spi);
return t->len - count;
}
static unsigned int bitbang_txrx_16(struct spi_device *spi,
spi_bb_txrx_word_fn txrx_word,
unsigned int ns,
struct spi_transfer *t,
unsigned int flags)
{
struct spi_bitbang *bitbang;
unsigned int bits = t->bits_per_word;
unsigned int count = t->len;
const u16 *tx = t->tx_buf;
u16 *rx = t->rx_buf;
bitbang = spi_controller_get_devdata(spi->controller);
while (likely(count > 1)) {
u16 word = 0;
if (tx)
word = *tx++;
else
word = spi->mode & SPI_MOSI_IDLE_HIGH ? 0xFFFF : 0;
word = txrx_word(spi, ns, word, bits, flags);
if (rx)
*rx++ = word;
count -= 2;
}
if (bitbang->set_mosi_idle)
bitbang->set_mosi_idle(spi);
return t->len - count;
}
static unsigned int bitbang_txrx_32(struct spi_device *spi,
spi_bb_txrx_word_fn txrx_word,
unsigned int ns,
struct spi_transfer *t,
unsigned int flags)
{
struct spi_bitbang *bitbang;
unsigned int bits = t->bits_per_word;
unsigned int count = t->len;
const u32 *tx = t->tx_buf;
u32 *rx = t->rx_buf;
bitbang = spi_controller_get_devdata(spi->controller);
while (likely(count > 3)) {
u32 word = 0;
if (tx)
word = *tx++;
else
word = spi->mode & SPI_MOSI_IDLE_HIGH ? 0xFFFFFFFF : 0;
word = txrx_word(spi, ns, word, bits, flags);
if (rx)
Annotation
- Immediate include surface: `linux/spinlock.h`, `linux/workqueue.h`, `linux/interrupt.h`, `linux/module.h`, `linux/delay.h`, `linux/errno.h`, `linux/platform_device.h`, `linux/slab.h`.
- Detected declarations: `struct spi_bitbang_cs`, `function bitbang_txrx_8`, `function bitbang_txrx_16`, `function bitbang_txrx_32`, `function spi_bitbang_setup_transfer`, `function spi_bitbang_setup`, `function spi_bitbang_cleanup`, `function spi_bitbang_bufs`, `function spi_bitbang_prepare_hardware`, `function spi_bitbang_transfer_one`.
- Atlas domain: Driver Families / drivers/spi.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.