|
@@ -0,0 +1,102 @@
|
|
1
|
+#ifndef _GPXE_NVS_THREEWIRE_H
|
|
2
|
+#define _GPXE_NVS_THREEWIRE_H
|
|
3
|
+
|
|
4
|
+/** @file
|
|
5
|
+ *
|
|
6
|
+ * Three-wire serial interface
|
|
7
|
+ *
|
|
8
|
+ */
|
|
9
|
+
|
|
10
|
+struct threewire;
|
|
11
|
+
|
|
12
|
+/** Three-wire interface methods */
|
|
13
|
+struct threewire_operations {
|
|
14
|
+ /**
|
|
15
|
+ * Set status of Chip Select line
|
|
16
|
+ *
|
|
17
|
+ * @v three Three-wire interface
|
|
18
|
+ * @v cs New status for chip select line
|
|
19
|
+ */
|
|
20
|
+ void ( * setcs ) ( struct threewire *three, int cs );
|
|
21
|
+ /**
|
|
22
|
+ * Set status of Serial Clock line
|
|
23
|
+ *
|
|
24
|
+ * @v three Three-wire interface
|
|
25
|
+ * @v sk New status for serial clock line
|
|
26
|
+ */
|
|
27
|
+ void ( * setsk ) ( struct threewire *three, int sk );
|
|
28
|
+ /**
|
|
29
|
+ * Set status of Data Input line
|
|
30
|
+ *
|
|
31
|
+ * @v three Three-wire interface
|
|
32
|
+ * @v di New status for data input line
|
|
33
|
+ */
|
|
34
|
+ void ( * setdi ) ( struct threewire *three, int di );
|
|
35
|
+ /**
|
|
36
|
+ * Get status of Data Output line
|
|
37
|
+ *
|
|
38
|
+ * @v three Three-wire interface
|
|
39
|
+ * @ret do Status of data output line
|
|
40
|
+ */
|
|
41
|
+ int ( * getdo ) ( struct threewire *three );
|
|
42
|
+};
|
|
43
|
+
|
|
44
|
+/**
|
|
45
|
+ * A three-wire serial interface
|
|
46
|
+ *
|
|
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.
|
|
51
|
+ *
|
|
52
|
+ */
|
|
53
|
+struct threewire {
|
|
54
|
+ /** Interface methods */
|
|
55
|
+ struct threewire_operations *ops;
|
|
56
|
+ /** Address size (in bits) */
|
|
57
|
+ unsigned int adrsize;
|
|
58
|
+ /** Data size (in bits) */
|
|
59
|
+ unsigned int datasize;
|
|
60
|
+ /** Delay between SK transitions (in us) */
|
|
61
|
+ unsigned int udelay;
|
|
62
|
+};
|
|
63
|
+
|
|
64
|
+/**
|
|
65
|
+ * Calculate read command for a specified address
|
|
66
|
+ *
|
|
67
|
+ * @v three Three-wire interface
|
|
68
|
+ * @v address Address
|
|
69
|
+ * @ret cmd Command
|
|
70
|
+ */
|
|
71
|
+static inline __attribute__ (( always_inline )) unsigned long
|
|
72
|
+threewire_cmd_read ( struct threewire *three, unsigned long address ) {
|
|
73
|
+ return ( ( 0x6 << three->adrsize ) | address );
|
|
74
|
+}
|
|
75
|
+
|
|
76
|
+/**
|
|
77
|
+ * Calculate command length
|
|
78
|
+ *
|
|
79
|
+ * @v three Three-wire interface
|
|
80
|
+ * @ret len Command length, in bits
|
|
81
|
+ */
|
|
82
|
+static inline __attribute__ (( always_inline )) int
|
|
83
|
+threewire_cmd_len ( struct threewire *three ) {
|
|
84
|
+ return ( three->adrsize + 3 );
|
|
85
|
+}
|
|
86
|
+
|
|
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
|
|
98
|
+
|
|
99
|
+extern unsigned long threewire_read ( struct threewire *three,
|
|
100
|
+ unsigned long address );
|
|
101
|
+
|
|
102
|
+#endif /* _GPXE_NVS_THREEWIRE_H */
|