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
13FILE_LICENCE ( GPL2_OR_LATER );
14FILE_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
45extern int threewire_read ( struct nvs_device *nvs, unsigned int address,
46 void *data, size_t len );
47extern int threewire_write ( struct nvs_device *nvs, unsigned int address,
48 const void *data, size_t len );
50
51/**
52 * @defgroup tdevs Three-wire device types
53 * @{
54 */
55
56static inline __attribute__ (( always_inline )) void
57init_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,
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 */
71static inline __attribute__ (( always_inline )) void
72init_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 */
84static inline __attribute__ (( always_inline )) void
85init_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 */
97static inline __attribute__ (( always_inline )) void
98init_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 */
110static inline __attribute__ (( always_inline )) void
111init_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 */
ring len
Length.
Definition dwmac.h:226
uint8_t data[48]
Additional event data.
Definition ena.h:11
uint64_t address
Base address.
Definition ena.h:13
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
static unsigned int organisation
Definition threewire.h:57
init_at93cx6(device, organisation)
#define __attribute__(x)
Definition compiler.h:10
SPI interface.
A hardware device.
Definition device.h:77
A non-volatile storage device.
Definition nvs.h:16
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
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
int threewire_detect_address_len(struct spi_device *device)
Autodetect device address length.
Definition threewire.c:120
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
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