1 #ifndef _GPXE_THREEWIRE_H
2 #define _GPXE_THREEWIRE_H
6 * Three-wire serial interface
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
13 FILE_LICENCE ( GPL2_OR_LATER );
19 * @defgroup tcmds Three-wire commands
23 /** Read data from memory array */
24 #define THREEWIRE_READ 0x6
26 /** Write data to memory array */
27 #define THREEWIRE_WRITE 0x5
30 #define THREEWIRE_EWEN 0x4
32 /** Address to be used for write enable command */
33 #define THREEWIRE_EWEN_ADDRESS INT_MAX
35 /** Time to wait for write cycles to complete
37 * This is sufficient for AT93C46/AT93C56 devices, but may need to be
38 * increased in future when other devices are added.
40 #define THREEWIRE_WRITE_MDELAY 10
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 );
50 * @defgroup tdevs Three-wire device types
54 static inline __attribute__ (( always_inline )) void
55 init_at93cx6 ( struct spi_device *device, unsigned int organisation ) {
56 device->nvs.word_len_log2 = ( ( organisation == 8 ) ? 0 : 1 );
57 device->nvs.block_size = 1;
58 device->command_len = 3,
59 device->nvs.read = threewire_read;
60 device->nvs.write = threewire_write;
64 * Initialise Atmel AT93C46 serial EEPROM
66 * @v device SPI device
67 * @v organisation Word organisation (8 or 16)
69 static inline __attribute__ (( always_inline )) void
70 init_at93c46 ( struct spi_device *device, unsigned int organisation ) {
71 device->nvs.size = ( 1024 / organisation );
72 device->address_len = ( ( organisation == 8 ) ? 7 : 6 );
73 init_at93cx6 ( device, organisation );
77 * Initialise Atmel AT93C56 serial EEPROM
79 * @v device SPI device
80 * @v organisation Word organisation (8 or 16)
82 static inline __attribute__ (( always_inline )) void
83 init_at93c56 ( struct spi_device *device, unsigned int organisation ) {
84 device->nvs.size = ( 2048 / organisation );
85 device->address_len = ( ( organisation == 8 ) ? 9 : 8 );
86 init_at93cx6 ( device, organisation );
91 #endif /* _GPXE_THREEWIRE_H */