diff options
author | Michael Brown <mcb30@etherboot.org> | 2006-12-04 15:36:51 +0000 |
---|---|---|
committer | Michael Brown <mcb30@etherboot.org> | 2006-12-04 15:36:51 +0000 |
commit | 931f94dca30b04f8303acdcfd08436e61a491a92 (patch) | |
tree | b478b672436d696ce8d0a4d91c804d29a65db6a9 /src/drivers/net | |
parent | 2e41bfd268e161a45958a8371c321e6c706e0073 (diff) | |
download | ipxe-931f94dca30b04f8303acdcfd08436e61a491a92.tar.gz |
Generalised the SPI abstraction layer to also be able to handle interfaces
that don't provide the full flexibility of a bit-bashing interface.
Temporarily hacked rtl8139.c to use the new interface.
Diffstat (limited to 'src/drivers/net')
-rw-r--r-- | src/drivers/net/etherfabric.c | 8 | ||||
-rw-r--r-- | src/drivers/net/rtl8139.c | 50 |
2 files changed, 30 insertions, 28 deletions
diff --git a/src/drivers/net/etherfabric.c b/src/drivers/net/etherfabric.c index 1b5f29a7..9afe65df 100644 --- a/src/drivers/net/etherfabric.c +++ b/src/drivers/net/etherfabric.c @@ -1058,9 +1058,13 @@ static int ef1002_i2c_read_bit ( struct bit_basher *basher, return ( EFAB_DWORD_FIELD ( reg, EF1_EEPROM ) & mask ); } +static struct bit_basher_operations ef1002_basher_ops = { + .read = ef1002_i2c_read_bit, + .write = ef1002_i2c_write_bit, +}; + static void ef1002_init_eeprom ( struct efab_nic *efab ) { - efab->ef1002_i2c.basher.write = ef1002_i2c_write_bit; - efab->ef1002_i2c.basher.read = ef1002_i2c_read_bit; + efab->ef1002_i2c.basher.op = &ef1002_basher_ops; init_i2c_bit_basher ( &efab->ef1002_i2c ); efab->ef1002_eeprom.address = EF1_EEPROM_I2C_ID; } diff --git a/src/drivers/net/rtl8139.c b/src/drivers/net/rtl8139.c index d42d3c2d..c1a29e4f 100644 --- a/src/drivers/net/rtl8139.c +++ b/src/drivers/net/rtl8139.c @@ -77,7 +77,7 @@ #include <gpxe/ethernet.h> #include <gpxe/pkbuff.h> #include <gpxe/netdevice.h> -#include <gpxe/spi.h> +#include <gpxe/spi_bit.h> #include <gpxe/threewire.h> #define TX_RING_SIZE 4 @@ -97,7 +97,7 @@ struct rtl8139_nic { struct rtl8139_tx tx; struct rtl8139_rx rx; struct spi_bit_basher spibit; - struct threewire_device eeprom; + struct spi_device eeprom; }; /* Tuning Parameters */ @@ -204,11 +204,6 @@ enum RxConfigBits { /* Offsets within EEPROM (these are word offsets) */ #define EE_MAC 7 -static inline struct rtl8139_nic * -basher_to_rtl ( struct bit_basher *basher ) { - return container_of ( basher, struct rtl8139_nic, spibit.basher ); -} - static const uint8_t rtl_ee_bits[] = { [SPI_BIT_SCLK] = EE_SK, [SPI_BIT_MOSI] = EE_DI, @@ -218,7 +213,8 @@ static const uint8_t rtl_ee_bits[] = { static int rtl_spi_read_bit ( struct bit_basher *basher, unsigned int bit_id ) { - struct rtl8139_nic *rtl = basher_to_rtl ( basher ); + struct rtl8139_nic *rtl = container_of ( basher, struct rtl8139_nic, + spibit.basher ); uint8_t mask = rtl_ee_bits[bit_id]; uint8_t eereg; @@ -228,7 +224,8 @@ static int rtl_spi_read_bit ( struct bit_basher *basher, static void rtl_spi_write_bit ( struct bit_basher *basher, unsigned int bit_id, unsigned long data ) { - struct rtl8139_nic *rtl = basher_to_rtl ( basher ); + struct rtl8139_nic *rtl = container_of ( basher, struct rtl8139_nic, + spibit.basher ); uint8_t mask = rtl_ee_bits[bit_id]; uint8_t eereg; @@ -238,6 +235,14 @@ static void rtl_spi_write_bit ( struct bit_basher *basher, outb ( eereg, rtl->ioaddr + Cfg9346 ); } +static struct bit_basher_operations rtl_basher_ops = { + .read = rtl_spi_read_bit, + .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 * @@ -247,19 +252,15 @@ static void rtl_init_eeprom ( struct rtl8139_nic *rtl ) { int ee9356; /* Initialise three-wire bus */ - rtl->spibit.basher.read = rtl_spi_read_bit; - rtl->spibit.basher.write = rtl_spi_write_bit; - rtl->spibit.spi.mode = SPI_MODE_THREEWIRE; + rtl->spibit.basher.op = &rtl_basher_ops; + rtl->spibit.bus.mode = SPI_MODE_THREEWIRE; init_spi_bit_basher ( &rtl->spibit ); /* 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.adrsize = - ( ee9356 ? AT93C56_ORG16_ADRSIZE : AT93C46_ORG16_ADRSIZE ); - rtl->eeprom.datasize = - ( ee9356 ? AT93C56_ORG16_DATASIZE : AT93C46_ORG16_DATASIZE ); - rtl->eeprom.spi = &rtl->spibit.spi; + DBG ( "EEPROM is an %s\n", ( ee9356 ? "AT93C56" : "AT93C46" ) ); + rtl->eeprom.type = ( ee9356 ? &rtl_ee9356 : &rtl_ee9346 ); + rtl->eeprom.bus = &rtl->spibit.bus; } /** @@ -269,18 +270,15 @@ static void rtl_init_eeprom ( struct rtl8139_nic *rtl ) { * @v mac_addr Buffer to contain MAC address (ETH_ALEN bytes) */ static void rtl_read_mac ( struct rtl8139_nic *rtl, uint8_t *mac_addr ) { - union { - uint16_t word; - uint8_t bytes[2]; - } u; + + struct spi_device *device = &rtl->eeprom; int i; DBG ( "MAC address is " ); for ( i = EE_MAC ; i < ( EE_MAC + ( ETH_ALEN / 2 ) ) ; i++ ) { - u.word = cpu_to_le16 ( threewire_read ( &rtl->eeprom, i ) ); - *mac_addr++ = u.bytes[0]; - *mac_addr++ = u.bytes[1]; - DBG ( "%02x%02x", u.bytes[0], u.bytes[1] ); + device->type->read ( device, i, mac_addr, 1 ); + DBG ( "%02x%02x", mac_addr[0], mac_addr[1] ); + mac_addr += 2; } DBG ( "\n" ); } |