mirror of
https://github.com/adulau/aha.git
synced 2024-12-27 19:26:25 +00:00
KS8851: Fix MAC address write order
The MAC address register was being written in the wrong order, so add a new address macro to convert mac-address byte to register address and a ks8851_wrreg8() function to write each byte without having to worry about any difficult byte swapping. Fixes a bug reported by Doong, Ping of Micrel. Signed-off-by: Ben Dooks <ben@simtec.co.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
57dada6819
commit
160d0fadaf
2 changed files with 34 additions and 4 deletions
|
@ -170,6 +170,36 @@ static void ks8851_wrreg16(struct ks8851_net *ks, unsigned reg, unsigned val)
|
||||||
ks_err(ks, "spi_sync() failed\n");
|
ks_err(ks, "spi_sync() failed\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ks8851_wrreg8 - write 8bit register value to chip
|
||||||
|
* @ks: The chip state
|
||||||
|
* @reg: The register address
|
||||||
|
* @val: The value to write
|
||||||
|
*
|
||||||
|
* Issue a write to put the value @val into the register specified in @reg.
|
||||||
|
*/
|
||||||
|
static void ks8851_wrreg8(struct ks8851_net *ks, unsigned reg, unsigned val)
|
||||||
|
{
|
||||||
|
struct spi_transfer *xfer = &ks->spi_xfer1;
|
||||||
|
struct spi_message *msg = &ks->spi_msg1;
|
||||||
|
__le16 txb[2];
|
||||||
|
int ret;
|
||||||
|
int bit;
|
||||||
|
|
||||||
|
bit = 1 << (reg & 3);
|
||||||
|
|
||||||
|
txb[0] = cpu_to_le16(MK_OP(bit, reg) | KS_SPIOP_WR);
|
||||||
|
txb[1] = val;
|
||||||
|
|
||||||
|
xfer->tx_buf = txb;
|
||||||
|
xfer->rx_buf = NULL;
|
||||||
|
xfer->len = 3;
|
||||||
|
|
||||||
|
ret = spi_sync(ks->spidev, msg);
|
||||||
|
if (ret < 0)
|
||||||
|
ks_err(ks, "spi_sync() failed\n");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ks8851_rx_1msg - select whether to use one or two messages for spi read
|
* ks8851_rx_1msg - select whether to use one or two messages for spi read
|
||||||
* @ks: The device structure
|
* @ks: The device structure
|
||||||
|
@ -322,13 +352,12 @@ static void ks8851_soft_reset(struct ks8851_net *ks, unsigned op)
|
||||||
static int ks8851_write_mac_addr(struct net_device *dev)
|
static int ks8851_write_mac_addr(struct net_device *dev)
|
||||||
{
|
{
|
||||||
struct ks8851_net *ks = netdev_priv(dev);
|
struct ks8851_net *ks = netdev_priv(dev);
|
||||||
u16 *mcp = (u16 *)dev->dev_addr;
|
int i;
|
||||||
|
|
||||||
mutex_lock(&ks->lock);
|
mutex_lock(&ks->lock);
|
||||||
|
|
||||||
ks8851_wrreg16(ks, KS_MARL, mcp[0]);
|
for (i = 0; i < ETH_ALEN; i++)
|
||||||
ks8851_wrreg16(ks, KS_MARM, mcp[1]);
|
ks8851_wrreg8(ks, KS_MAR(i), dev->dev_addr[i]);
|
||||||
ks8851_wrreg16(ks, KS_MARH, mcp[2]);
|
|
||||||
|
|
||||||
mutex_unlock(&ks->lock);
|
mutex_unlock(&ks->lock);
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#define CCR_32PIN (1 << 0)
|
#define CCR_32PIN (1 << 0)
|
||||||
|
|
||||||
/* MAC address registers */
|
/* MAC address registers */
|
||||||
|
#define KS_MAR(_m) 0x15 - (_m)
|
||||||
#define KS_MARL 0x10
|
#define KS_MARL 0x10
|
||||||
#define KS_MARM 0x12
|
#define KS_MARM 0x12
|
||||||
#define KS_MARH 0x14
|
#define KS_MARH 0x14
|
||||||
|
|
Loading…
Reference in a new issue