Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

threewire.h 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef _GPXE_THREEWIRE_H
  2. #define _GPXE_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. #include <gpxe/spi.h>
  12. #include <limits.h>
  13. /**
  14. * @defgroup tcmds Three-wire commands
  15. * @{
  16. */
  17. /** Read data from memory array */
  18. #define THREEWIRE_READ 0x6
  19. /** Write data to memory array */
  20. #define THREEWIRE_WRITE 0x5
  21. /** Write enable */
  22. #define THREEWIRE_EWEN 0x4
  23. /** Address to be used for write enable command */
  24. #define THREEWIRE_EWEN_ADDRESS INT_MAX
  25. /** Time to wait for write cycles to complete
  26. *
  27. * This is sufficient for AT93C46/AT93C56 devices, but may need to be
  28. * increased in future when other devices are added.
  29. */
  30. #define THREEWIRE_WRITE_MDELAY 10
  31. /** @} */
  32. extern int threewire_read ( struct nvs_device *nvs, unsigned int address,
  33. void *data, size_t len );
  34. extern int threewire_write ( struct nvs_device *nvs, unsigned int address,
  35. const void *data, size_t len );
  36. /**
  37. * @defgroup tdevs Three-wire device types
  38. * @{
  39. */
  40. static inline __attribute__ (( always_inline )) void
  41. init_at93cx6 ( struct spi_device *device, unsigned int organisation ) {
  42. device->nvs.word_len_log2 = ( ( organisation == 8 ) ? 0 : 1 );
  43. device->nvs.block_size = 1;
  44. device->command_len = 3,
  45. device->nvs.read = threewire_read;
  46. device->nvs.write = threewire_write;
  47. }
  48. /**
  49. * Initialise Atmel AT93C46 serial EEPROM
  50. *
  51. * @v device SPI device
  52. * @v organisation Word organisation (8 or 16)
  53. */
  54. static inline __attribute__ (( always_inline )) void
  55. init_at93c46 ( struct spi_device *device, unsigned int organisation ) {
  56. device->nvs.size = ( 1024 / organisation );
  57. device->address_len = ( ( organisation == 8 ) ? 7 : 6 );
  58. init_at93cx6 ( device, organisation );
  59. }
  60. /**
  61. * Initialise Atmel AT93C56 serial EEPROM
  62. *
  63. * @v device SPI device
  64. * @v organisation Word organisation (8 or 16)
  65. */
  66. static inline __attribute__ (( always_inline )) void
  67. init_at93c56 ( struct spi_device *device, unsigned int organisation ) {
  68. device->nvs.size = ( 2048 / organisation );
  69. device->address_len = ( ( organisation == 8 ) ? 9 : 8 );
  70. init_at93cx6 ( device, organisation );
  71. }
  72. /** @} */
  73. #endif /* _GPXE_THREEWIRE_H */