Quellcode durchsuchen

Added write support for three-wire devices (e.g. the RTL8139 EEPROM)

tags/v0.9.3
Michael Brown vor 18 Jahren
Ursprung
Commit
d2bf7abe75
2 geänderte Dateien mit 61 neuen und 1 gelöschten Zeilen
  1. 41
    1
      src/drivers/nvs/threewire.c
  2. 20
    0
      src/include/gpxe/threewire.h

+ 41
- 1
src/drivers/nvs/threewire.c Datei anzeigen

@@ -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
+}

+ 20
- 0
src/include/gpxe/threewire.h Datei anzeigen

@@ -11,6 +11,7 @@
11 11
  */
12 12
 
13 13
 #include <gpxe/spi.h>
14
+#include <limits.h>
14 15
 
15 16
 /**
16 17
  * @defgroup tcmds Three-wire commands
@@ -20,10 +21,28 @@
20 21
 /** Read data from memory array */
21 22
 #define THREEWIRE_READ 0x6
22 23
 
24
+/** Write data to memory array */
25
+#define THREEWIRE_WRITE 0x5
26
+
27
+/** Write enable */
28
+#define THREEWIRE_EWEN 0x4
29
+
30
+/** Address to be used for write enable command */
31
+#define THREEWIRE_EWEN_ADDRESS INT_MAX
32
+
33
+/** Time to wait for write cycles to complete
34
+ *
35
+ * This is sufficient for AT93C46/AT93C56 devices, but may need to be
36
+ * increased in future when other devices are added.
37
+ */
38
+#define THREEWIRE_WRITE_MDELAY 10
39
+
23 40
 /** @} */
24 41
 
25 42
 extern int threewire_read ( struct nvs_device *nvs, unsigned int address,
26 43
 			    void *data, size_t len );
44
+extern int threewire_write ( struct nvs_device *nvs, unsigned int address,
45
+			     const void *data, size_t len );
27 46
 
28 47
 /**
29 48
  * @defgroup tdevs Three-wire device types
@@ -36,6 +55,7 @@ init_at93cx6 ( struct spi_device *device, unsigned int organisation ) {
36 55
 	device->nvs.block_size = 1;
37 56
 	device->command_len = 3,
38 57
 	device->nvs.read = threewire_read;
58
+	device->nvs.write = threewire_write;
39 59
 }
40 60
 
41 61
 /**

Laden…
Abbrechen
Speichern