13 * @defgroup spicmds SPI commands
17 /** Write status register */
20 /** Write data to memory array */
21 #define SPI_WRITE 0x02
23 /** Read data from memory array */
26 /** Reset write enable latch */
29 /** Read status register */
32 /** Set write enable latch */
36 * @defgroup atmelcmds Atmel-specific SPI commands
40 /** Erase one sector in memory array (Not supported on all devices) */
41 #define ATMEL_SECTOR_ERASE 0x52
43 /** Erase all sections in memory array (Not supported on all devices) */
44 #define ATMEL_CHIP_ERASE 0x62
46 /** Read manufacturer and product ID (Not supported on all devices) */
47 #define ATMEL_RDID 0x15
54 * @defgroup spistatus SPI status register bits (not present on all devices)
58 /** Write-protect pin enabled */
59 #define SPI_STATUS_WPEN 0x80
61 /** Block protection bit 2 */
62 #define SPI_STATUS_BP2 0x10
64 /** Block protection bit 1 */
65 #define SPI_STATUS_BP1 0x08
67 /** Block protection bit 0 */
68 #define SPI_STATUS_BP0 0x04
70 /** State of the write enable latch */
71 #define SPI_STATUS_WEN 0x02
73 /** Device busy flag */
74 #define SPI_STATUS_NRDY 0x01
81 * This data structure represents a physical SPI device attached to an
86 struct nvs_device nvs;
87 /** SPI bus to which device is attached */
91 /** Command length, in bits */
92 unsigned int command_len;
93 /** Address length, in bits */
94 unsigned int address_len;
97 * Some devices with 9-bit addresses (e.g. AT25040A EEPROM)
98 * use bit 3 of the command byte as address bit A8, rather
99 * than having a two-byte address. If this flag is set, then
100 * commands should be munged in this way.
102 unsigned int munge_address : 1;
105 static inline __attribute__ (( always_inline )) struct spi_device *
106 nvs_to_spi ( struct nvs_device *nvs ) {
107 return container_of ( nvs, struct spi_device, nvs );
113 * This data structure represents an SPI bus controller capable of
114 * issuing commands to attached SPI devices.
117 /** SPI interface mode
119 * This is the bitwise OR of zero or more of @c SPI_MODE_CPHA
120 * and @c SPI_MODE_CPOL. It is also the number conventionally
121 * used to describe the SPI interface mode. For example, SPI
122 * mode 1 is the mode in which CPOL=0 and CPHA=1, which
123 * therefore corresponds to a mode value of (0|SPI_MODE_CPHA)
124 * which, happily, equals 1.
128 * Read/write data via SPI bus
131 * @v device SPI device
133 * @v address Address to read/write (<0 for no address)
134 * @v data_out TX data buffer (or NULL)
135 * @v data_in RX data buffer (or NULL)
136 * @v len Length of data buffer(s)
138 * This issues the specified command and optional address to
139 * the SPI device, then reads and/or writes data to/from the
142 int ( * rw ) ( struct spi_bus *bus, struct spi_device *device,
143 unsigned int command, int address,
144 const void *data_out, void *data_in, size_t len );
147 /** Clock phase (CPHA) mode bit
149 * Phase 0 is sample on rising edge, shift data on falling edge.
151 * Phase 1 is shift data on rising edge, sample data on falling edge.
153 #define SPI_MODE_CPHA 0x01
155 /** Clock polarity (CPOL) mode bit
157 * This bit reflects the idle state of the clock line (SCLK).
159 #define SPI_MODE_CPOL 0x02
161 /** Slave select polarity mode bit
163 * This bit reflects that active state of the slave select lines. It
164 * is not part of the normal SPI mode number (which covers only @c
165 * SPI_MODE_CPOL and @c SPI_MODE_CPHA), but is included here for
168 #define SPI_MODE_SSPOL 0x10
170 /** Microwire-compatible mode
172 * This is SPI mode 1 (i.e. CPOL=0, CPHA=1), and is compatible with
173 * the original Microwire protocol.
175 #define SPI_MODE_MICROWIRE 1
177 /** Microwire/Plus-compatible mode
179 * This is SPI mode 0 (i.e. CPOL=0, CPHA=0), and is compatible with
180 * the Microwire/Plus protocol
182 #define SPI_MODE_MICROWIRE_PLUS 0
184 /** Threewire-compatible mode
186 * This mode is compatible with Atmel's series of "three-wire"
189 #define SPI_MODE_THREEWIRE ( SPI_MODE_MICROWIRE_PLUS | SPI_MODE_SSPOL )
191 #endif /* _GPXE_SPI_H */