You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

threewire.h 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #ifndef _IPXE_THREEWIRE_H
  2. #define _IPXE_THREEWIRE_H
  3. /** @file
  4. *
  5. * Three-wire serial interface
  6. *
  7. * The Atmel three-wire interface is a subset of the (newer) SPI
  8. * interface, and is implemented here as a layer on top of the SPI
  9. * support.
  10. */
  11. FILE_LICENCE ( GPL2_OR_LATER );
  12. #include <ipxe/spi.h>
  13. #include <limits.h>
  14. /**
  15. * @defgroup tcmds Three-wire commands
  16. * @{
  17. */
  18. /** Read data from memory array */
  19. #define THREEWIRE_READ 0x6
  20. /** Write data to memory array */
  21. #define THREEWIRE_WRITE 0x5
  22. /** Write enable */
  23. #define THREEWIRE_EWEN 0x4
  24. /** Address to be used for write enable command */
  25. #define THREEWIRE_EWEN_ADDRESS INT_MAX
  26. /** Time to wait for write cycles to complete
  27. *
  28. * This is sufficient for AT93C46/AT93C56 devices, but may need to be
  29. * increased in future when other devices are added.
  30. */
  31. #define THREEWIRE_WRITE_MDELAY 10
  32. /** @} */
  33. extern int threewire_read ( struct nvs_device *nvs, unsigned int address,
  34. void *data, size_t len );
  35. extern int threewire_write ( struct nvs_device *nvs, unsigned int address,
  36. const void *data, size_t len );
  37. extern int threewire_detect_address_len ( struct spi_device *device );
  38. /**
  39. * @defgroup tdevs Three-wire device types
  40. * @{
  41. */
  42. static inline __attribute__ (( always_inline )) void
  43. init_at93cx6 ( struct spi_device *device, unsigned int organisation ) {
  44. device->nvs.word_len_log2 = ( ( organisation == 8 ) ? 0 : 1 );
  45. device->nvs.block_size = 1;
  46. device->command_len = 3,
  47. device->nvs.read = threewire_read;
  48. device->nvs.write = threewire_write;
  49. }
  50. /**
  51. * Initialise Atmel AT93C06 serial EEPROM
  52. *
  53. * @v device SPI device
  54. * @v organisation Word organisation (8 or 16)
  55. */
  56. static inline __attribute__ (( always_inline )) void
  57. init_at93c06 ( struct spi_device *device, unsigned int organisation ) {
  58. device->nvs.size = ( 256 / organisation );
  59. device->address_len = ( ( organisation == 8 ) ? 7 : 6 );
  60. init_at93cx6 ( device, organisation );
  61. }
  62. /**
  63. * Initialise Atmel AT93C46 serial EEPROM
  64. *
  65. * @v device SPI device
  66. * @v organisation Word organisation (8 or 16)
  67. */
  68. static inline __attribute__ (( always_inline )) void
  69. init_at93c46 ( struct spi_device *device, unsigned int organisation ) {
  70. device->nvs.size = ( 1024 / organisation );
  71. device->address_len = ( ( organisation == 8 ) ? 7 : 6 );
  72. init_at93cx6 ( device, organisation );
  73. }
  74. /**
  75. * Initialise Atmel AT93C56 serial EEPROM
  76. *
  77. * @v device SPI device
  78. * @v organisation Word organisation (8 or 16)
  79. */
  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 );
  85. }
  86. /**
  87. * Initialise Atmel AT93C66 serial EEPROM
  88. *
  89. * @v device SPI device
  90. * @v organisation Word organisation (8 or 16)
  91. */
  92. static inline __attribute__ (( always_inline )) void
  93. init_at93c66 ( struct spi_device *device, unsigned int organisation ) {
  94. device->nvs.size = ( 4096 / organisation );
  95. device->address_len = ( ( organisation == 8 ) ? 9 : 8 );
  96. init_at93cx6 ( device, organisation );
  97. }
  98. /** @} */
  99. #endif /* _IPXE_THREEWIRE_H */