iPXE
threewire.h
Go to the documentation of this file.
1 #ifndef _IPXE_THREEWIRE_H
2 #define _IPXE_THREEWIRE_H
3 
4 /** @file
5  *
6  * Three-wire serial interface
7  *
8  * The Atmel three-wire interface is a subset of the (newer) SPI
9  * interface, and is implemented here as a layer on top of the SPI
10  * support.
11  */
12 
13 FILE_LICENCE ( GPL2_OR_LATER );
14 FILE_SECBOOT ( PERMITTED );
15 
16 #include <ipxe/spi.h>
17 #include <limits.h>
18 
19 /**
20  * @defgroup tcmds Three-wire commands
21  * @{
22  */
23 
24 /** Read data from memory array */
25 #define THREEWIRE_READ 0x6
26 
27 /** Write data to memory array */
28 #define THREEWIRE_WRITE 0x5
29 
30 /** Write enable */
31 #define THREEWIRE_EWEN 0x4
32 
33 /** Address to be used for write enable command */
34 #define THREEWIRE_EWEN_ADDRESS INT_MAX
35 
36 /** Time to wait for write cycles to complete
37  *
38  * This is sufficient for AT93C46/AT93C56 devices, but may need to be
39  * increased in future when other devices are added.
40  */
41 #define THREEWIRE_WRITE_MDELAY 10
42 
43 /** @} */
44 
45 extern int threewire_read ( struct nvs_device *nvs, unsigned int address,
46  void *data, size_t len );
47 extern int threewire_write ( struct nvs_device *nvs, unsigned int address,
48  const void *data, size_t len );
49 extern int threewire_detect_address_len ( struct spi_device *device );
50 
51 /**
52  * @defgroup tdevs Three-wire device types
53  * @{
54  */
55 
56 static inline __attribute__ (( always_inline )) void
57 init_at93cx6 ( struct spi_device *device, unsigned int organisation ) {
58  device->nvs.word_len_log2 = ( ( organisation == 8 ) ? 0 : 1 );
59  device->nvs.block_size = 1;
60  device->command_len = 3,
61  device->nvs.read = threewire_read;
62  device->nvs.write = threewire_write;
63 }
64 
65 /**
66  * Initialise Atmel AT93C06 serial EEPROM
67  *
68  * @v device SPI device
69  * @v organisation Word organisation (8 or 16)
70  */
71 static inline __attribute__ (( always_inline )) void
72 init_at93c06 ( struct spi_device *device, unsigned int organisation ) {
73  device->nvs.size = ( 256 / organisation );
74  device->address_len = ( ( organisation == 8 ) ? 7 : 6 );
76 }
77 
78 /**
79  * Initialise Atmel AT93C46 serial EEPROM
80  *
81  * @v device SPI device
82  * @v organisation Word organisation (8 or 16)
83  */
84 static inline __attribute__ (( always_inline )) void
85 init_at93c46 ( struct spi_device *device, unsigned int organisation ) {
86  device->nvs.size = ( 1024 / organisation );
87  device->address_len = ( ( organisation == 8 ) ? 7 : 6 );
89 }
90 
91 /**
92  * Initialise Atmel AT93C56 serial EEPROM
93  *
94  * @v device SPI device
95  * @v organisation Word organisation (8 or 16)
96  */
97 static inline __attribute__ (( always_inline )) void
98 init_at93c56 ( struct spi_device *device, unsigned int organisation ) {
99  device->nvs.size = ( 2048 / organisation );
100  device->address_len = ( ( organisation == 8 ) ? 9 : 8 );
102 }
103 
104 /**
105  * Initialise Atmel AT93C66 serial EEPROM
106  *
107  * @v device SPI device
108  * @v organisation Word organisation (8 or 16)
109  */
110 static inline __attribute__ (( always_inline )) void
111 init_at93c66 ( struct spi_device *device, unsigned int organisation ) {
112  device->nvs.size = ( 4096 / organisation );
113  device->address_len = ( ( organisation == 8 ) ? 9 : 8 );
115 }
116 
117 /** @} */
118 
119 #endif /* _IPXE_THREEWIRE_H */
FILE_LICENCE(GPL2_OR_LATER)
A non-volatile storage device.
Definition: nvs.h:16
uint64_t address
Base address.
Definition: ena.h:24
init_at93cx6(device, organisation)
int threewire_detect_address_len(struct spi_device *device)
Autodetect device address length.
Definition: threewire.c:120
A hardware device.
Definition: device.h:77
SPI interface.
ring len
Length.
Definition: dwmac.h:231
int threewire_write(struct nvs_device *nvs, unsigned int address, const void *data, size_t len)
Write data to three-wire device.
Definition: threewire.c:78
static unsigned int organisation
Definition: threewire.h:57
FILE_SECBOOT(PERMITTED)
static __attribute__((always_inline)) void init_at93cx6(struct spi_device *device
Initialise Atmel AT93C06 serial EEPROM.
uint8_t data[48]
Additional event data.
Definition: ena.h:22
An SPI device.
Definition: spi.h:87
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