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