spi.h
Go to the documentation of this file.00001 #ifndef _GPXE_SPI_H
00002 #define _GPXE_SPI_H
00003
00004
00005
00006
00007
00008
00009
00010 FILE_LICENCE ( GPL2_OR_LATER );
00011
00012 #include <gpxe/nvs.h>
00013
00014
00015
00016
00017
00018
00019
00020 #define SPI_WRSR 0x01
00021
00022
00023 #define SPI_WRITE 0x02
00024
00025
00026 #define SPI_READ 0x03
00027
00028
00029 #define SPI_WRDI 0x04
00030
00031
00032 #define SPI_RDSR 0x05
00033
00034
00035 #define SPI_WREN 0x06
00036
00037
00038
00039
00040
00041
00042
00043 #define ATMEL_SECTOR_ERASE 0x52
00044
00045
00046 #define ATMEL_CHIP_ERASE 0x62
00047
00048
00049 #define ATMEL_RDID 0x15
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 #define SPI_STATUS_WPEN 0x80
00062
00063
00064 #define SPI_STATUS_BP2 0x10
00065
00066
00067 #define SPI_STATUS_BP1 0x08
00068
00069
00070 #define SPI_STATUS_BP0 0x04
00071
00072
00073 #define SPI_STATUS_WEN 0x02
00074
00075
00076 #define SPI_STATUS_NRDY 0x01
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 struct spi_device {
00087
00088 struct nvs_device nvs;
00089
00090 struct spi_bus *bus;
00091
00092 unsigned int slave;
00093
00094 unsigned int command_len;
00095
00096 unsigned int address_len;
00097
00098
00099
00100
00101
00102
00103
00104 unsigned int munge_address : 1;
00105 };
00106
00107
00108
00109
00110
00111
00112
00113 #define SPI_AUTODETECT_ADDRESS_LEN 0
00114
00115 static inline __attribute__ (( always_inline )) struct spi_device *
00116 nvs_to_spi ( struct nvs_device *nvs ) {
00117 return container_of ( nvs, struct spi_device, nvs );
00118 }
00119
00120
00121
00122
00123
00124
00125
00126 struct spi_bus {
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 unsigned int mode;
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 int ( * rw ) ( struct spi_bus *bus, struct spi_device *device,
00153 unsigned int command, int address,
00154 const void *data_out, void *data_in, size_t len );
00155 };
00156
00157
00158
00159
00160
00161
00162
00163 #define SPI_MODE_CPHA 0x01
00164
00165
00166
00167
00168
00169 #define SPI_MODE_CPOL 0x02
00170
00171
00172
00173
00174
00175
00176
00177
00178 #define SPI_MODE_SSPOL 0x10
00179
00180
00181
00182
00183
00184
00185 #define SPI_MODE_MICROWIRE 1
00186
00187
00188
00189
00190
00191
00192 #define SPI_MODE_MICROWIRE_PLUS 0
00193
00194
00195
00196
00197
00198
00199 #define SPI_MODE_THREEWIRE ( SPI_MODE_MICROWIRE_PLUS | SPI_MODE_SSPOL )
00200
00201 extern int spi_read ( struct nvs_device *nvs, unsigned int address,
00202 void *data, size_t len );
00203 extern int spi_write ( struct nvs_device *nvs, unsigned int address,
00204 const void *data, size_t len );
00205
00206
00207
00208
00209
00210
00211 static inline __attribute__ (( always_inline )) void
00212 init_spi ( struct spi_device *device ) {
00213 device->nvs.word_len_log2 = 0;
00214 device->command_len = 8,
00215 device->nvs.read = spi_read;
00216 device->nvs.write = spi_write;
00217 }
00218
00219
00220 static inline __attribute__ (( always_inline )) void
00221 init_at25f1024 ( struct spi_device *device ) {
00222 device->address_len = 24;
00223 device->nvs.size = ( 128 * 1024 );
00224 device->nvs.block_size = 256;
00225 init_spi ( device );
00226 }
00227
00228
00229 static inline __attribute__ (( always_inline )) void
00230 init_at25040 ( struct spi_device *device ) {
00231 device->address_len = 8;
00232 device->munge_address = 1;
00233 device->nvs.size = 512;
00234 device->nvs.block_size = 8;
00235 init_spi ( device );
00236 }
00237
00238
00239 static inline __attribute__ (( always_inline )) void
00240 init_m25p32 ( struct spi_device *device ) {
00241 device->address_len = 24;
00242 device->nvs.size = ( 4 * 1024 * 1024 );
00243 device->nvs.block_size = 256;
00244 init_spi ( device );
00245 }
00246
00247
00248 static inline __attribute__ (( always_inline )) void
00249 init_mc25xx640 ( struct spi_device *device ) {
00250 device->address_len = 16;
00251 device->nvs.size = ( 8 * 1024 );
00252 device->nvs.block_size = 32;
00253 init_spi ( device );
00254 }
00255
00256
00257
00258 #endif