48 #define SELECT_SLAVE 0 51 #define DESELECT_SLAVE SPI_MODE_SSPOL 64 unsigned int state ) {
68 DBGC2 ( spibit,
"SPIBIT %p setting slave %d select %s\n",
92 const void *data_out,
void *data_in,
93 unsigned int len,
int endianness ) {
98 unsigned int bit_offset;
99 unsigned int byte_offset;
100 unsigned int byte_mask;
104 DBGC2 ( spibit,
"SPIBIT %p transferring %d bits in mode %#x\n",
111 byte_offset = ( bit_offset / 8 );
112 byte_mask = ( 1 << ( bit_offset % 8 ) );
115 if ( sclk == cpha ) {
120 byte = ( data_out + byte_offset );
121 bit = ( *
byte & byte_mask );
122 DBGCP ( spibit,
"SPIBIT %p wrote bit %d\n",
123 spibit, (
bit ? 1 : 0 ) );
134 DBGCP ( spibit,
"SPIBIT %p read bit %d\n",
135 spibit, (
bit ? 1 : 0 ) );
136 byte = ( data_in + byte_offset );
138 *
byte |= (
bit & byte_mask );
163 const void *data_out,
void *data_in,
size_t len ) {
184 assert (
device->command_len <= ( 8 * sizeof ( tmp_command ) ) );
191 assert (
device->address_len <= ( 8 * sizeof ( tmp_address )));
198 DBGC ( spibit,
"SPIBIT %p autodetecting device " 199 "address length\n", spibit );
204 &tmp_address_detect, 1,
207 }
while (
le32_to_cpu ( tmp_address_detect ) & 1 );
208 DBGC ( spibit,
"SPIBIT %p autodetected device address " 209 "length %d\n", spibit,
device->address_len );
#define SPI_BIT_UDELAY
Delay between SCLK transitions.
struct bit_basher basher
Bit-bashing interface.
static int spi_bit_rw(struct spi_bus *bus, struct spi_device *device, unsigned int command, int address, const void *data_out, void *data_in, size_t len)
Read/write data via SPI bit-bashing bus.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
int(* rw)(struct spi_bus *bus, struct spi_device *device, unsigned int command, int address, const void *data_out, void *data_in, size_t len)
Read/write data via SPI bus.
static void spi_bit_set_slave_select(struct spi_bit_basher *spibit, unsigned int slave, unsigned int state)
Select/deselect slave.
static void open_bit(struct bit_basher *basher)
Open bit-bashing interface.
static unsigned int unsigned int bit
#define le32_to_cpu(value)
SPI bit-bashing interface.
uint64_t address
Base address.
#define SPI_MODE_CPHA
Clock phase (CPHA) mode bit.
#define SPI_MODE_CPOL
Clock polarity (CPOL) mode bit.
struct bit_basher_operations * op
Bit-bashing operations.
unsigned int mode
SPI interface mode.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define container_of(ptr, type, field)
Get containing structure.
void init_spi_bit_basher(struct spi_bit_basher *spibit)
Initialise SPI bit-bashing interface.
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
#define cpu_to_le32(value)
int(* read)(struct bit_basher *basher, unsigned int bit_id)
Read input bit.
#define DESELECT_SLAVE
Chip select line will be deasserted.
#define SPI_BIT_SS(slave)
Determine bit index for a particular slave.
static void spi_bit_transfer(struct spi_bit_basher *spibit, const void *data_out, void *data_in, unsigned int len, int endianness)
Transfer bits over SPI bit-bashing bus.
struct spi_bus bus
SPI bus.
int read_bit(struct bit_basher *basher, unsigned int bit_id)
Read input bit.
#define SPI_MODE_SSPOL
Slave select polarity mode bit.
#define SPI_BIT_BIG_ENDIAN
SPI bit basher treats data as big-endian.
void(* write)(struct bit_basher *basher, unsigned int bit_id, unsigned long data)
Set/clear output bit.
void step(void)
Single-step a single process.
#define SELECT_SLAVE
Chip select line will be asserted.
static void close_bit(struct bit_basher *basher)
Close bit-bashing interface.
static void spi_bit_delay(void)
Delay between SCLK changes and around SS changes.
#define NULL
NULL pointer (VOID *)
#define SPI_AUTODETECT_ADDRESS_LEN
SPI magic autodetection address length.
void write_bit(struct bit_basher *basher, unsigned int bit_id, unsigned long data)
Set/clear output bit.
int endianness
Endianness of data.