Browse Source

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

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
d2bf7abe75
2 changed files with 61 additions and 1 deletions
  1. 41
    1
      src/drivers/nvs/threewire.c
  2. 20
    0
      src/include/gpxe/threewire.h

+ 41
- 1
src/drivers/nvs/threewire.c View File

18
 
18
 
19
 #include <stddef.h>
19
 #include <stddef.h>
20
 #include <assert.h>
20
 #include <assert.h>
21
+#include <timer.h>
21
 #include <gpxe/threewire.h>
22
 #include <gpxe/threewire.h>
22
 
23
 
23
 /** @file
24
 /** @file
26
  *
27
  *
27
  */
28
  */
28
 
29
 
29
-/** Read data from three-wire device
30
+/**
31
+ * Read data from three-wire device
30
  *
32
  *
31
  * @v nvs		NVS device
33
  * @v nvs		NVS device
32
  * @v address		Address from which to read
34
  * @v address		Address from which to read
46
 	return bus->rw ( bus, device, THREEWIRE_READ, address,
48
 	return bus->rw ( bus, device, THREEWIRE_READ, address,
47
 			 NULL, data, len );
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 View File

11
  */
11
  */
12
 
12
 
13
 #include <gpxe/spi.h>
13
 #include <gpxe/spi.h>
14
+#include <limits.h>
14
 
15
 
15
 /**
16
 /**
16
  * @defgroup tcmds Three-wire commands
17
  * @defgroup tcmds Three-wire commands
20
 /** Read data from memory array */
21
 /** Read data from memory array */
21
 #define THREEWIRE_READ 0x6
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
 extern int threewire_read ( struct nvs_device *nvs, unsigned int address,
42
 extern int threewire_read ( struct nvs_device *nvs, unsigned int address,
26
 			    void *data, size_t len );
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
  * @defgroup tdevs Three-wire device types
48
  * @defgroup tdevs Three-wire device types
36
 	device->nvs.block_size = 1;
55
 	device->nvs.block_size = 1;
37
 	device->command_len = 3,
56
 	device->command_len = 3,
38
 	device->nvs.read = threewire_read;
57
 	device->nvs.read = threewire_read;
58
+	device->nvs.write = threewire_write;
39
 }
59
 }
40
 
60
 
41
 /**
61
 /**

Loading…
Cancel
Save