|
@@ -18,6 +18,7 @@
|
18
|
18
|
|
19
|
19
|
#include <stddef.h>
|
20
|
20
|
#include <assert.h>
|
|
21
|
+#include <timer.h>
|
21
|
22
|
#include <gpxe/threewire.h>
|
22
|
23
|
|
23
|
24
|
/** @file
|
|
@@ -26,7 +27,8 @@
|
26
|
27
|
*
|
27
|
28
|
*/
|
28
|
29
|
|
29
|
|
-/** Read data from three-wire device
|
|
30
|
+/**
|
|
31
|
+ * Read data from three-wire device
|
30
|
32
|
*
|
31
|
33
|
* @v nvs NVS device
|
32
|
34
|
* @v address Address from which to read
|
|
@@ -46,3 +48,41 @@ int threewire_read ( struct nvs_device *nvs, unsigned int address,
|
46
|
48
|
return bus->rw ( bus, device, THREEWIRE_READ, address,
|
47
|
49
|
NULL, data, len );
|
48
|
50
|
}
|
|
51
|
+
|
|
52
|
+/**
|
|
53
|
+ * Write data to three-wire device
|
|
54
|
+ *
|
|
55
|
+ * @v nvs NVS device
|
|
56
|
+ * @v address Address from which to read
|
|
57
|
+ * @v data Data buffer
|
|
58
|
+ * @v len Length of data buffer
|
|
59
|
+ * @ret rc Return status code
|
|
60
|
+ */
|
|
61
|
+int threewire_write ( struct nvs_device *nvs, unsigned int address,
|
|
62
|
+ const void *data, size_t len ) {
|
|
63
|
+ struct spi_device *device = nvs_to_spi ( nvs );
|
|
64
|
+ struct spi_bus *bus = device->bus;
|
|
65
|
+ int rc;
|
|
66
|
+
|
|
67
|
+ assert ( bus->mode == SPI_MODE_THREEWIRE );
|
|
68
|
+
|
|
69
|
+ DBG ( "3wire %p writing %d bytes at %04x\n", device, len, address );
|
|
70
|
+
|
|
71
|
+ /* Enable device for writing */
|
|
72
|
+ if ( ( rc = bus->rw ( bus, device, THREEWIRE_EWEN,
|
|
73
|
+ THREEWIRE_EWEN_ADDRESS, NULL, NULL, 0 ) ) != 0 )
|
|
74
|
+ return rc;
|
|
75
|
+
|
|
76
|
+ /* Write data */
|
|
77
|
+ if ( ( rc = bus->rw ( bus, device, THREEWIRE_WRITE, address,
|
|
78
|
+ data, NULL, len ) ) != 0 )
|
|
79
|
+ return rc;
|
|
80
|
+
|
|
81
|
+ /* Our model of an SPI bus doesn't provide a mechanism for
|
|
82
|
+ * "assert CS, wait for MISO to become high, so just wait for
|
|
83
|
+ * long enough to ensure that the write has completed.
|
|
84
|
+ */
|
|
85
|
+ mdelay ( THREEWIRE_WRITE_MDELAY );
|
|
86
|
+
|
|
87
|
+ return 0;
|
|
88
|
+}
|