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
17 * @defgroup tcmds Three-wire commands
21 /** Read data from memory array */
22 #define THREEWIRE_READ 0x6
24 /** Write data to memory array */
25 #define THREEWIRE_WRITE 0x5
28 #define THREEWIRE_EWEN 0x4
30 /** Address to be used for write enable command */
31 #define THREEWIRE_EWEN_ADDRESS INT_MAX
33 /** Time to wait for write cycles to complete
35 * This is sufficient for AT93C46/AT93C56 devices, but may need to be
36 * increased in future when other devices are added.
38 #define THREEWIRE_WRITE_MDELAY 10
42 extern int threewire_read ( struct nvs_device *nvs, unsigned int address,
43 void *data, size_t len );
44 extern int threewire_write ( struct nvs_device *nvs, unsigned int address,
45 const void *data, size_t len );
48 * @defgroup tdevs Three-wire device types
52 static inline __attribute__ (( always_inline )) void
53 init_at93cx6 ( struct spi_device *device, unsigned int organisation ) {
54 device->nvs.word_len_log2 = ( ( organisation == 8 ) ? 0 : 1 );
55 device->nvs.block_size = 1;
56 device->command_len = 3,
57 device->nvs.read = threewire_read;
58 device->nvs.write = threewire_write;
62 * Initialise Atmel AT93C46 serial EEPROM
64 * @v device SPI device
65 * @v organisation Word organisation (8 or 16)
67 static inline __attribute__ (( always_inline )) void
68 init_at93c46 ( struct spi_device *device, unsigned int organisation ) {
69 device->nvs.size = ( 1024 / organisation );
70 device->address_len = ( ( organisation == 8 ) ? 7 : 6 );
71 init_at93cx6 ( device, organisation );
75 * Initialise Atmel AT93C56 serial EEPROM
77 * @v device SPI device
78 * @v organisation Word organisation (8 or 16)
80 static inline __attribute__ (( always_inline )) void
81 init_at93c56 ( struct spi_device *device, unsigned int organisation ) {
82 device->nvs.size = ( 2048 / organisation );
83 device->address_len = ( ( organisation == 8 ) ? 9 : 8 );
84 init_at93cx6 ( device, organisation );
89 #endif /* _GPXE_THREEWIRE_H */