drivers/spi/spi-bitbang-txrx.h

Source file repositories/reference/linux-study-clean/drivers/spi/spi-bitbang-txrx.h

File Facts

System
Linux kernel
Corpus path
drivers/spi/spi-bitbang-txrx.h
Extension
.h
Size
5029 bytes
Lines
177
Domain
Driver Families
Bucket
drivers/spi
Inferred role
Driver Families: implementation source
Status
source 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.

Dependency Surface

Detected Declarations

Annotated Snippet

if ((flags & SPI_CONTROLLER_NO_TX) == 0) {
			if ((word & (1 << 31)) != oldbit) {
				setmosi(spi, word & (1 << 31));
				oldbit = word & (1 << 31);
			}
		}
		spidelay(nsecs);	/* T(setup) */

		setsck(spi, !cpol);
		spidelay(nsecs);

		/* sample MSB (from slave) on leading edge */
		word <<= 1;
		if ((flags & SPI_CONTROLLER_NO_RX) == 0)
			word |= getmiso(spi);
		setsck(spi, cpol);
	}
	return word;
}

static inline u32
bitbang_txrx_be_cpha1(struct spi_device *spi,
		unsigned nsecs, unsigned cpol, unsigned flags,
		u32 word, u8 bits)
{
	/* if (cpol == 0) this is SPI_MODE_1; else this is SPI_MODE_3 */

	u32 oldbit = (!(word & (1<<(bits-1)))) << 31;
	/* clock starts at inactive polarity */
	for (word <<= (32 - bits); likely(bits); bits--) {

		/* setup MSB (to slave) on leading edge */
		setsck(spi, !cpol);
		if ((flags & SPI_CONTROLLER_NO_TX) == 0) {
			if ((word & (1 << 31)) != oldbit) {
				setmosi(spi, word & (1 << 31));
				oldbit = word & (1 << 31);
			}
		}
		spidelay(nsecs); /* T(setup) */

		setsck(spi, cpol);
		spidelay(nsecs);

		/* sample MSB (from slave) on trailing edge */
		word <<= 1;
		if ((flags & SPI_CONTROLLER_NO_RX) == 0)
			word |= getmiso(spi);
	}
	return word;
}

static inline u32
bitbang_txrx_le_cpha0(struct spi_device *spi,
		unsigned int nsecs, unsigned int cpol, unsigned int flags,
		u32 word, u8 bits)
{
	/* if (cpol == 0) this is SPI_MODE_0; else this is SPI_MODE_2 */

	u8 rxbit = bits - 1;
	u32 oldbit = !(word & 1);
	/* clock starts at inactive polarity */
	for (; likely(bits); bits--) {

		/* setup LSB (to slave) on trailing edge */
		if ((flags & SPI_CONTROLLER_NO_TX) == 0) {
			if ((word & 1) != oldbit) {
				setmosi(spi, word & 1);
				oldbit = word & 1;
			}
		}
		spidelay(nsecs);	/* T(setup) */

		setsck(spi, !cpol);
		spidelay(nsecs);

		/* sample LSB (from slave) on leading edge */
		word >>= 1;
		if ((flags & SPI_CONTROLLER_NO_RX) == 0)
			word |= getmiso(spi) << rxbit;
		setsck(spi, cpol);
	}
	return word;
}

static inline u32
bitbang_txrx_le_cpha1(struct spi_device *spi,
		unsigned int nsecs, unsigned int cpol, unsigned int flags,
		u32 word, u8 bits)
{

Annotation

Implementation Notes