iPXE
threewire.h File Reference

Three-wire serial interface. More...

#include <ipxe/spi.h>
#include <limits.h>

Go to the source code of this file.

Macros

#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)
 FILE_SECBOOT (PERMITTED)
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_at93c06(struct spi_device *device
 Initialise Atmel AT93C06 serial EEPROM.
 init_at93cx6 (device, organisation)

Variables

static unsigned int organisation
device nvs block_size = 1
device command_len = 3
device device nvs read = threewire_read
device nvs write = threewire_write
device address_len = ( ( organisation == 8 ) ? 7 : 6 )

Detailed Description

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.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ threewire_read()

int threewire_read ( struct nvs_device * nvs,
unsigned int address,
void * data,
size_t len )
extern

Read data from three-wire device.

Parameters
nvsNVS device
addressAddress from which to read
dataData buffer
lenLength of data buffer
Return values
rcReturn status code

Definition at line 48 of file threewire.c.

49 {
50 struct spi_device *device = nvs_to_spi ( nvs );
51 struct spi_bus *bus = device->bus;
52 int rc;
53
54 assert ( bus->mode == SPI_MODE_THREEWIRE );
55
56 DBGC ( device, "3wire %p reading %zd bytes at %04x\n",
57 device, len, address );
58
59 if ( ( rc = bus->rw ( bus, device, THREEWIRE_READ, address,
60 NULL, data, len ) ) != 0 ) {
61 DBGC ( device, "3wire %p could not read: %s\n",
62 device, strerror ( rc ) );
63 return rc;
64 }
65
66 return 0;
67}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
ring len
Length.
Definition dwmac.h:226
uint8_t bus
Bus.
Definition edd.h:1
uint8_t data[48]
Additional event data.
Definition ena.h:11
uint64_t address
Base address.
Definition ena.h:13
#define DBGC(...)
Definition compiler.h:505
#define THREEWIRE_READ
Read data from memory array.
Definition threewire.h:25
#define SPI_MODE_THREEWIRE
Threewire-compatible mode.
Definition spi.h:200
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
A hardware device.
Definition device.h:77
An SPI bus.
Definition spi.h:127
An SPI device.
Definition spi.h:87
struct nvs_device nvs
NVS device.
Definition spi.h:89

References address, assert, bus, data, DBGC, len, NULL, spi_device::nvs, rc, SPI_MODE_THREEWIRE, strerror(), and THREEWIRE_READ.

Referenced by threewire_detect_address_len().

◆ threewire_write()

int threewire_write ( struct nvs_device * nvs,
unsigned int address,
const void * data,
size_t len )
extern

Write data to three-wire device.

Parameters
nvsNVS device
addressAddress from which to read
dataData buffer
lenLength of data buffer
Return values
rcReturn status code

Definition at line 78 of file threewire.c.

79 {
80 struct spi_device *device = nvs_to_spi ( nvs );
81 struct spi_bus *bus = device->bus;
82 int rc;
83
84 assert ( bus->mode == SPI_MODE_THREEWIRE );
85
86 DBGC ( device, "3wire %p writing %zd bytes at %04x\n",
87 device, len, address );
88
89 /* Enable device for writing */
90 if ( ( rc = bus->rw ( bus, device, THREEWIRE_EWEN,
91 THREEWIRE_EWEN_ADDRESS, NULL, NULL, 0 ) ) != 0 ){
92 DBGC ( device, "3wire %p could not enable writing: %s\n",
93 device, strerror ( rc ) );
94 return rc;
95 }
96
97 /* Write data */
98 if ( ( rc = bus->rw ( bus, device, THREEWIRE_WRITE, address,
99 data, NULL, len ) ) != 0 ) {
100 DBGC ( device, "3wire %p could not write: %s\n",
101 device, strerror ( rc ) );
102 return rc;
103 }
104
105 /* Our model of an SPI bus doesn't provide a mechanism for
106 * "assert CS, wait for MISO to become high, so just wait for
107 * long enough to ensure that the write has completed.
108 */
110
111 return 0;
112}
#define THREEWIRE_WRITE_MDELAY
Time to wait for write cycles to complete.
Definition threewire.h:41
#define THREEWIRE_WRITE
Write data to memory array.
Definition threewire.h:28
#define THREEWIRE_EWEN
Write enable.
Definition threewire.h:31
#define THREEWIRE_EWEN_ADDRESS
Address to be used for write enable command.
Definition threewire.h:34
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition timer.c:79

References address, assert, bus, data, DBGC, len, mdelay(), NULL, spi_device::nvs, rc, SPI_MODE_THREEWIRE, strerror(), THREEWIRE_EWEN, THREEWIRE_EWEN_ADDRESS, THREEWIRE_WRITE, and THREEWIRE_WRITE_MDELAY.

◆ threewire_detect_address_len()

int threewire_detect_address_len ( struct spi_device * device)
extern

Autodetect device address length.

Parameters
deviceSPI device
Return values
rcReturn status code

Definition at line 120 of file threewire.c.

120 {
121 struct nvs_device *nvs = &device->nvs;
122 int rc;
123
124 DBGC ( device, "3wire %p autodetecting address length\n", device );
125
126 device->address_len = SPI_AUTODETECT_ADDRESS_LEN;
127 if ( ( rc = threewire_read ( nvs, 0, NULL,
128 ( 1 << nvs->word_len_log2 ) ) ) != 0 ) {
129 DBGC ( device, "3wire %p could not autodetect address "
130 "length: %s\n", device, strerror ( rc ) );
131 return rc;
132 }
133
134 DBGC ( device, "3wire %p autodetected address length %d\n",
135 device, device->address_len );
136 return 0;
137}
#define SPI_AUTODETECT_ADDRESS_LEN
SPI magic autodetection address length.
Definition spi.h:114
A non-volatile storage device.
Definition nvs.h:16
unsigned int word_len_log2
Word length.
Definition nvs.h:23
int threewire_read(struct nvs_device *nvs, unsigned int address, void *data, size_t len)
Read data from three-wire device.
Definition threewire.c:48

References DBGC, NULL, rc, SPI_AUTODETECT_ADDRESS_LEN, strerror(), threewire_read(), and nvs_device::word_len_log2.

Referenced by ifec_init_eeprom().