iPXE
threewire.h
Go to the documentation of this file.
00001 #ifndef _IPXE_THREEWIRE_H
00002 #define _IPXE_THREEWIRE_H
00003 
00004 /** @file
00005  *
00006  * Three-wire serial interface
00007  *
00008  * The Atmel three-wire interface is a subset of the (newer) SPI
00009  * interface, and is implemented here as a layer on top of the SPI
00010  * support.
00011  */
00012 
00013 FILE_LICENCE ( GPL2_OR_LATER );
00014 
00015 #include <ipxe/spi.h>
00016 #include <limits.h>
00017 
00018 /**
00019  * @defgroup tcmds Three-wire commands
00020  * @{
00021  */
00022 
00023 /** Read data from memory array */
00024 #define THREEWIRE_READ 0x6
00025 
00026 /** Write data to memory array */
00027 #define THREEWIRE_WRITE 0x5
00028 
00029 /** Write enable */
00030 #define THREEWIRE_EWEN 0x4
00031 
00032 /** Address to be used for write enable command */
00033 #define THREEWIRE_EWEN_ADDRESS INT_MAX
00034 
00035 /** Time to wait for write cycles to complete
00036  *
00037  * This is sufficient for AT93C46/AT93C56 devices, but may need to be
00038  * increased in future when other devices are added.
00039  */
00040 #define THREEWIRE_WRITE_MDELAY 10
00041 
00042 /** @} */
00043 
00044 extern int threewire_read ( struct nvs_device *nvs, unsigned int address,
00045                             void *data, size_t len );
00046 extern int threewire_write ( struct nvs_device *nvs, unsigned int address,
00047                              const void *data, size_t len );
00048 extern int threewire_detect_address_len ( struct spi_device *device );
00049 
00050 /**
00051  * @defgroup tdevs Three-wire device types
00052  * @{
00053  */
00054 
00055 static inline __attribute__ (( always_inline )) void
00056 init_at93cx6 ( struct spi_device *device, unsigned int organisation ) {
00057         device->nvs.word_len_log2 = ( ( organisation == 8 ) ? 0 : 1 );
00058         device->nvs.block_size = 1;
00059         device->command_len = 3,
00060         device->nvs.read = threewire_read;
00061         device->nvs.write = threewire_write;
00062 }
00063 
00064 /**
00065  * Initialise Atmel AT93C06 serial EEPROM
00066  *
00067  * @v device            SPI device
00068  * @v organisation      Word organisation (8 or 16)
00069  */
00070 static inline __attribute__ (( always_inline )) void
00071 init_at93c06 ( struct spi_device *device, unsigned int organisation ) {
00072         device->nvs.size = ( 256 / organisation );
00073         device->address_len = ( ( organisation == 8 ) ? 7 : 6 );
00074         init_at93cx6 ( device, organisation );
00075 }
00076 
00077 /**
00078  * Initialise Atmel AT93C46 serial EEPROM
00079  *
00080  * @v device            SPI device
00081  * @v organisation      Word organisation (8 or 16)
00082  */
00083 static inline __attribute__ (( always_inline )) void
00084 init_at93c46 ( struct spi_device *device, unsigned int organisation ) {
00085         device->nvs.size = ( 1024 / organisation );
00086         device->address_len = ( ( organisation == 8 ) ? 7 : 6 );
00087         init_at93cx6 ( device, organisation );
00088 }
00089 
00090 /**
00091  * Initialise Atmel AT93C56 serial EEPROM
00092  *
00093  * @v device            SPI device
00094  * @v organisation      Word organisation (8 or 16)
00095  */
00096 static inline __attribute__ (( always_inline )) void
00097 init_at93c56 ( struct spi_device *device, unsigned int organisation ) {
00098         device->nvs.size = ( 2048 / organisation );
00099         device->address_len = ( ( organisation == 8 ) ? 9 : 8 );
00100         init_at93cx6 ( device, organisation );
00101 }
00102 
00103 /**
00104  * Initialise Atmel AT93C66 serial EEPROM
00105  *
00106  * @v device            SPI device
00107  * @v organisation      Word organisation (8 or 16)
00108  */
00109 static inline __attribute__ (( always_inline )) void
00110 init_at93c66 ( struct spi_device *device, unsigned int organisation ) {
00111         device->nvs.size = ( 4096 / organisation );
00112         device->address_len = ( ( organisation == 8 ) ? 9 : 8 );
00113         init_at93cx6 ( device, organisation );
00114 }
00115 
00116 /** @} */
00117 
00118 #endif /* _IPXE_THREEWIRE_H */