mirror of
https://github.com/ipxe/ipxe
synced 2025-12-20 20:10:18 +03:00
Abstracted out part of the concept of an SPI device to a generalised NVS
device. Separated the mechanisms of non-volatile storage access and non-volatile stored options.
This commit is contained in:
@@ -147,22 +147,21 @@ static int spi_bit_rw ( struct spi_bus *bus, struct spi_device *device,
|
||||
const void *data_out, void *data_in, size_t len ) {
|
||||
struct spi_bit_basher *spibit
|
||||
= container_of ( bus, struct spi_bit_basher, bus );
|
||||
struct spi_device_type *devtype = device->type;
|
||||
uint32_t tmp;
|
||||
|
||||
/* Assert chip select on specified slave */
|
||||
spi_bit_set_slave_select ( spibit, device->slave, SELECT_SLAVE );
|
||||
|
||||
/* Transmit command */
|
||||
assert ( devtype->command_len <= ( 8 * sizeof ( tmp ) ) );
|
||||
assert ( device->command_len <= ( 8 * sizeof ( tmp ) ) );
|
||||
tmp = cpu_to_le32 ( command );
|
||||
spi_bit_transfer ( spibit, &tmp, NULL, devtype->command_len );
|
||||
spi_bit_transfer ( spibit, &tmp, NULL, device->command_len );
|
||||
|
||||
/* Transmit address, if present */
|
||||
if ( address >= 0 ) {
|
||||
assert ( devtype->address_len <= ( 8 * sizeof ( tmp ) ) );
|
||||
assert ( device->address_len <= ( 8 * sizeof ( tmp ) ) );
|
||||
tmp = cpu_to_le32 ( address );
|
||||
spi_bit_transfer ( spibit, &tmp, NULL, devtype->address_len );
|
||||
spi_bit_transfer ( spibit, &tmp, NULL, device->address_len );
|
||||
}
|
||||
|
||||
/* Transmit/receive data */
|
||||
|
||||
@@ -2388,11 +2388,6 @@ static int falcon_write_nvs ( struct nvs_device *nvs, unsigned int offset,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct nvs_operations falcon_nvs_operations = {
|
||||
.read = falcon_read_nvs,
|
||||
.write = falcon_write_nvs,
|
||||
};
|
||||
|
||||
/** RX descriptor */
|
||||
typedef efab_qword_t falcon_rx_desc_t;
|
||||
|
||||
@@ -3046,10 +3041,12 @@ static int falcon_init_nic ( struct efab_nic *efab ) {
|
||||
|
||||
/* Register non-volatile storage */
|
||||
if ( efab->has_eeprom ) {
|
||||
/*
|
||||
efab->nvs.op = &falcon_nvs_operations;
|
||||
efab->nvs.len = 0x100;
|
||||
if ( nvs_register ( &efab->nvs ) != 0 )
|
||||
return 0;
|
||||
*/
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
@@ -240,15 +240,12 @@ static struct bit_basher_operations rtl_basher_ops = {
|
||||
.write = rtl_spi_write_bit,
|
||||
};
|
||||
|
||||
static struct spi_device_type rtl_ee9346 = AT93C46 ( 16 );
|
||||
static struct spi_device_type rtl_ee9356 = AT93C56 ( 16 );
|
||||
|
||||
/**
|
||||
* Set up for EEPROM access
|
||||
*
|
||||
* @v rtl RTL8139 NIC
|
||||
*/
|
||||
static void rtl_init_eeprom ( struct rtl8139_nic *rtl ) {
|
||||
void rtl_init_eeprom ( struct rtl8139_nic *rtl ) {
|
||||
int ee9356;
|
||||
|
||||
/* Initialise three-wire bus */
|
||||
@@ -258,8 +255,13 @@ static void rtl_init_eeprom ( struct rtl8139_nic *rtl ) {
|
||||
|
||||
/* Detect EEPROM type and initialise three-wire device */
|
||||
ee9356 = ( inw ( rtl->ioaddr + RxConfig ) & Eeprom9356 );
|
||||
DBG ( "EEPROM is an %s\n", ( ee9356 ? "AT93C56" : "AT93C46" ) );
|
||||
rtl->eeprom.type = ( ee9356 ? &rtl_ee9356 : &rtl_ee9346 );
|
||||
if ( ee9356 ) {
|
||||
DBG ( "EEPROM is an AT93C56\n" );
|
||||
init_at93c56 ( &rtl->eeprom, 16 );
|
||||
} else {
|
||||
DBG ( "EEPROM is an AT93C46\n" );
|
||||
init_at93c46 ( &rtl->eeprom, 16 );
|
||||
}
|
||||
rtl->eeprom.bus = &rtl->spibit.bus;
|
||||
}
|
||||
|
||||
@@ -271,12 +273,12 @@ static void rtl_init_eeprom ( struct rtl8139_nic *rtl ) {
|
||||
*/
|
||||
static void rtl_read_mac ( struct rtl8139_nic *rtl, uint8_t *mac_addr ) {
|
||||
|
||||
struct spi_device *device = &rtl->eeprom;
|
||||
struct nvs_device *nvs = &rtl->eeprom.nvs;
|
||||
int i;
|
||||
|
||||
DBG ( "MAC address is " );
|
||||
for ( i = EE_MAC ; i < ( EE_MAC + ( ETH_ALEN / 2 ) ) ; i++ ) {
|
||||
device->type->read ( device, i, mac_addr, 2 );
|
||||
nvs_read ( nvs, i, mac_addr, 2 );
|
||||
DBG ( "%02x%02x", mac_addr[0], mac_addr[1] );
|
||||
mac_addr += 2;
|
||||
}
|
||||
|
||||
31
src/drivers/nvs/nvs.c
Normal file
31
src/drivers/nvs/nvs.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <gpxe/nvs.h>
|
||||
|
||||
/** @file
|
||||
*
|
||||
* Non-volatile storage
|
||||
*
|
||||
*/
|
||||
|
||||
int nvs_read ( struct nvs_device *nvs, unsigned int address,
|
||||
void *data, size_t len ) {
|
||||
return nvs->read ( nvs, address, data, len );
|
||||
}
|
||||
@@ -28,14 +28,15 @@
|
||||
|
||||
/** Read data from three-wire device
|
||||
*
|
||||
* @v device SPI device
|
||||
* @v nvs NVS device
|
||||
* @v address Address from which to read
|
||||
* @v data Data buffer
|
||||
* @v len Length of data buffer
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int threewire_read ( struct spi_device *device, unsigned int address,
|
||||
int threewire_read ( struct nvs_device *nvs, unsigned int address,
|
||||
void *data, size_t len ) {
|
||||
struct spi_device *device = nvs_to_spi ( nvs );
|
||||
struct spi_bus *bus = device->bus;
|
||||
|
||||
assert ( bus->mode == SPI_MODE_THREEWIRE );
|
||||
|
||||
Reference in New Issue
Block a user