#include <stddef.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <gpxe/threewire.h>
Go to the source code of this file.
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| int | threewire_read (struct nvs_device *nvs, unsigned int address, void *data, size_t len) |
| Read data from three-wire device. | |
| int | threewire_write (struct nvs_device *nvs, unsigned int address, const void *data, size_t len) |
| Write data to three-wire device. | |
| int | threewire_detect_address_len (struct spi_device *device) |
| Autodetect device address length. | |
Definition in file threewire.c.
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
| int threewire_read | ( | struct nvs_device * | nvs, | |
| unsigned int | address, | |||
| void * | data, | |||
| size_t | len | |||
| ) |
Read data from three-wire device.
| nvs | NVS device | |
| address | Address from which to read | |
| data | Data buffer | |
| len | Length of data buffer |
| rc | Return status code |
Definition at line 42 of file threewire.c.
References assert, spi_device::bus, DBGC, spi_bus::mode, NULL, spi_bus::rw, SPI_MODE_THREEWIRE, strerror(), and THREEWIRE_READ.
Referenced by threewire_detect_address_len().
00043 { 00044 struct spi_device *device = nvs_to_spi ( nvs ); 00045 struct spi_bus *bus = device->bus; 00046 int rc; 00047 00048 assert ( bus->mode == SPI_MODE_THREEWIRE ); 00049 00050 DBGC ( device, "3wire %p reading %zd bytes at %04x\n", 00051 device, len, address ); 00052 00053 if ( ( rc = bus->rw ( bus, device, THREEWIRE_READ, address, 00054 NULL, data, len ) ) != 0 ) { 00055 DBGC ( device, "3wire %p could not read: %s\n", 00056 device, strerror ( rc ) ); 00057 return rc; 00058 } 00059 00060 return 0; 00061 }
| int threewire_write | ( | struct nvs_device * | nvs, | |
| unsigned int | address, | |||
| const void * | data, | |||
| size_t | len | |||
| ) |
Write data to three-wire device.
| nvs | NVS device | |
| address | Address from which to read | |
| data | Data buffer | |
| len | Length of data buffer |
| rc | Return status code |
Definition at line 72 of file threewire.c.
References assert, spi_device::bus, DBGC, mdelay(), spi_bus::mode, NULL, spi_bus::rw, SPI_MODE_THREEWIRE, strerror(), THREEWIRE_EWEN, THREEWIRE_EWEN_ADDRESS, THREEWIRE_WRITE, and THREEWIRE_WRITE_MDELAY.
00073 { 00074 struct spi_device *device = nvs_to_spi ( nvs ); 00075 struct spi_bus *bus = device->bus; 00076 int rc; 00077 00078 assert ( bus->mode == SPI_MODE_THREEWIRE ); 00079 00080 DBGC ( device, "3wire %p writing %zd bytes at %04x\n", 00081 device, len, address ); 00082 00083 /* Enable device for writing */ 00084 if ( ( rc = bus->rw ( bus, device, THREEWIRE_EWEN, 00085 THREEWIRE_EWEN_ADDRESS, NULL, NULL, 0 ) ) != 0 ){ 00086 DBGC ( device, "3wire %p could not enable writing: %s\n", 00087 device, strerror ( rc ) ); 00088 return rc; 00089 } 00090 00091 /* Write data */ 00092 if ( ( rc = bus->rw ( bus, device, THREEWIRE_WRITE, address, 00093 data, NULL, len ) ) != 0 ) { 00094 DBGC ( device, "3wire %p could not write: %s\n", 00095 device, strerror ( rc ) ); 00096 return rc; 00097 } 00098 00099 /* Our model of an SPI bus doesn't provide a mechanism for 00100 * "assert CS, wait for MISO to become high, so just wait for 00101 * long enough to ensure that the write has completed. 00102 */ 00103 mdelay ( THREEWIRE_WRITE_MDELAY ); 00104 00105 return 0; 00106 }
| int threewire_detect_address_len | ( | struct spi_device * | device | ) |
Autodetect device address length.
| rc | Return status code |
Definition at line 114 of file threewire.c.
References spi_device::address_len, DBGC, NULL, spi_device::nvs, SPI_AUTODETECT_ADDRESS_LEN, strerror(), threewire_read(), and nvs_device::word_len_log2.
Referenced by ifec_init_eeprom().
00114 { 00115 struct nvs_device *nvs = &device->nvs; 00116 int rc; 00117 00118 DBGC ( device, "3wire %p autodetecting address length\n", device ); 00119 00120 device->address_len = SPI_AUTODETECT_ADDRESS_LEN; 00121 if ( ( rc = threewire_read ( nvs, 0, NULL, 00122 ( 1 << nvs->word_len_log2 ) ) ) != 0 ) { 00123 DBGC ( device, "3wire %p could not autodetect address " 00124 "length: %s\n", device, strerror ( rc ) ); 00125 return rc; 00126 } 00127 00128 DBGC ( device, "3wire %p autodetected address length %d\n", 00129 device, device->address_len ); 00130 return 0; 00131 }
1.5.7.1