1 #ifndef _GPXE_NVS_THREEWIRE_H
2 #define _GPXE_NVS_THREEWIRE_H
6 * Three-wire serial interface
12 /** Three-wire interface methods */
13 struct threewire_operations {
15 * Set status of Chip Select line
17 * @v three Three-wire interface
18 * @v cs New status for chip select line
20 void ( * setcs ) ( struct threewire *three, int cs );
22 * Set status of Serial Clock line
24 * @v three Three-wire interface
25 * @v sk New status for serial clock line
27 void ( * setsk ) ( struct threewire *three, int sk );
29 * Set status of Data Input line
31 * @v three Three-wire interface
32 * @v di New status for data input line
34 void ( * setdi ) ( struct threewire *three, int di );
36 * Get status of Data Output line
38 * @v three Three-wire interface
39 * @ret do Status of data output line
41 int ( * getdo ) ( struct threewire *three );
45 * A three-wire serial interface
47 * This interface consists of a clock line (SK), data input (DI) and
48 * data output (DO). There is also a chip select line (CS) which is
49 * integral to the operation of the device, but Atmel still calls it a
50 * three-wire interface.
54 /** Interface methods */
55 struct threewire_operations *ops;
56 /** Address size (in bits) */
58 /** Data size (in bits) */
59 unsigned int datasize;
60 /** Delay between SK transitions (in us) */
65 * Calculate read command for a specified address
67 * @v three Three-wire interface
71 static inline __attribute__ (( always_inline )) unsigned long
72 threewire_cmd_read ( struct threewire *three, unsigned long address ) {
73 return ( ( 0x6 << three->adrsize ) | address );
77 * Calculate command length
79 * @v three Three-wire interface
80 * @ret len Command length, in bits
82 static inline __attribute__ (( always_inline )) int
83 threewire_cmd_len ( struct threewire *three ) {
84 return ( three->adrsize + 3 );
87 /* Constants for some standard parts */
88 #define AT93C46_ORG8_ADRSIZE 7
89 #define AT93C46_ORG8_DATASIZE 8
90 #define AT93C46_ORG16_ADRSIZE 6
91 #define AT93C46_ORG16_DATASIZE 16
92 #define AT93C46_UDELAY 1
93 #define AT93C56_ORG8_ADRSIZE 9
94 #define AT93C56_ORG8_DATASIZE 8
95 #define AT93C56_ORG16_ADRSIZE 8
96 #define AT93C56_ORG16_DATASIZE 16
97 #define AT93C56_UDELAY 1
99 extern unsigned long threewire_read ( struct threewire *three,
100 unsigned long address );
102 #endif /* _GPXE_NVS_THREEWIRE_H */