iPXE
|
Three-wire serial interface. More...
Go to the source code of this file.
Defines | |
#define | THREEWIRE_READ 0x6 |
Read data from memory array. | |
#define | THREEWIRE_WRITE 0x5 |
Write data to memory array. | |
#define | THREEWIRE_EWEN 0x4 |
Write enable. | |
#define | THREEWIRE_EWEN_ADDRESS INT_MAX |
Address to be used for write enable command. | |
#define | THREEWIRE_WRITE_MDELAY 10 |
Time to wait for write cycles to complete. | |
Functions | |
FILE_LICENCE (GPL2_OR_LATER) | |
int | threewire_read (struct nvs_device *nvs, unsigned int address, void *data, size_t len) |
Read data from three-wire device. | |
int | threewire_write (struct nvs_device *nvs, unsigned int address, const void *data, size_t len) |
Write data to three-wire device. | |
int | threewire_detect_address_len (struct spi_device *device) |
Autodetect device address length. | |
static | __attribute__ ((always_inline)) void init_at93cx6(struct spi_device *device |
Three-wire serial interface.
The Atmel three-wire interface is a subset of the (newer) SPI interface, and is implemented here as a layer on top of the SPI support.
Definition in file threewire.h.
FILE_LICENCE | ( | GPL2_OR_LATER | ) |
int threewire_read | ( | struct nvs_device * | nvs, |
unsigned int | address, | ||
void * | data, | ||
size_t | len | ||
) |
Read data from three-wire device.
nvs | NVS device |
address | Address from which to read |
data | Data buffer |
len | Length of data buffer |
rc | Return status code |
Definition at line 47 of file threewire.c.
References assert, spi_device::bus, bus, DBGC, spi_bus::mode, NULL, rc, spi_bus::rw, SPI_MODE_THREEWIRE, strerror(), and THREEWIRE_READ.
Referenced by threewire_detect_address_len().
{ struct spi_device *device = nvs_to_spi ( nvs ); struct spi_bus *bus = device->bus; int rc; assert ( bus->mode == SPI_MODE_THREEWIRE ); DBGC ( device, "3wire %p reading %zd bytes at %04x\n", device, len, address ); if ( ( rc = bus->rw ( bus, device, THREEWIRE_READ, address, NULL, data, len ) ) != 0 ) { DBGC ( device, "3wire %p could not read: %s\n", device, strerror ( rc ) ); return rc; } return 0; }
int threewire_write | ( | struct nvs_device * | nvs, |
unsigned int | address, | ||
const void * | data, | ||
size_t | len | ||
) |
Write data to three-wire device.
nvs | NVS device |
address | Address from which to read |
data | Data buffer |
len | Length of data buffer |
rc | Return status code |
Definition at line 77 of file threewire.c.
References assert, spi_device::bus, bus, DBGC, mdelay(), spi_bus::mode, NULL, rc, spi_bus::rw, SPI_MODE_THREEWIRE, strerror(), THREEWIRE_EWEN, THREEWIRE_EWEN_ADDRESS, THREEWIRE_WRITE, and THREEWIRE_WRITE_MDELAY.
{ struct spi_device *device = nvs_to_spi ( nvs ); struct spi_bus *bus = device->bus; int rc; assert ( bus->mode == SPI_MODE_THREEWIRE ); DBGC ( device, "3wire %p writing %zd bytes at %04x\n", device, len, address ); /* Enable device for writing */ if ( ( rc = bus->rw ( bus, device, THREEWIRE_EWEN, THREEWIRE_EWEN_ADDRESS, NULL, NULL, 0 ) ) != 0 ){ DBGC ( device, "3wire %p could not enable writing: %s\n", device, strerror ( rc ) ); return rc; } /* Write data */ if ( ( rc = bus->rw ( bus, device, THREEWIRE_WRITE, address, data, NULL, len ) ) != 0 ) { DBGC ( device, "3wire %p could not write: %s\n", device, strerror ( rc ) ); return rc; } /* Our model of an SPI bus doesn't provide a mechanism for * "assert CS, wait for MISO to become high, so just wait for * long enough to ensure that the write has completed. */ mdelay ( THREEWIRE_WRITE_MDELAY ); return 0; }
int threewire_detect_address_len | ( | struct spi_device * | device | ) |
Autodetect device address length.
device SPI device rc Return status code
Definition at line 119 of file threewire.c.
References spi_device::address_len, DBGC, NULL, spi_device::nvs, rc, SPI_AUTODETECT_ADDRESS_LEN, strerror(), threewire_read(), and nvs_device::word_len_log2.
Referenced by ifec_init_eeprom().
{ struct nvs_device *nvs = &device->nvs; int rc; DBGC ( device, "3wire %p autodetecting address length\n", device ); device->address_len = SPI_AUTODETECT_ADDRESS_LEN; if ( ( rc = threewire_read ( nvs, 0, NULL, ( 1 << nvs->word_len_log2 ) ) ) != 0 ) { DBGC ( device, "3wire %p could not autodetect address " "length: %s\n", device, strerror ( rc ) ); return rc; } DBGC ( device, "3wire %p autodetected address length %d\n", device, device->address_len ); return 0; }