Skip to content

Commit

Permalink
KS8851: Fix MAC address write order
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Ben Dooks authored and David S. Miller committed Oct 21, 2009
1 parent 57dada6 commit 160d0fa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
37 changes: 33 additions & 4 deletions drivers/net/ks8851.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,36 @@ static void ks8851_wrreg16(struct ks8851_net *ks, unsigned reg, unsigned val)
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
* @ks: The device structure
Expand Down Expand Up @@ -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)
{
struct ks8851_net *ks = netdev_priv(dev);
u16 *mcp = (u16 *)dev->dev_addr;
int i;

mutex_lock(&ks->lock);

ks8851_wrreg16(ks, KS_MARL, mcp[0]);
ks8851_wrreg16(ks, KS_MARM, mcp[1]);
ks8851_wrreg16(ks, KS_MARH, mcp[2]);
for (i = 0; i < ETH_ALEN; i++)
ks8851_wrreg8(ks, KS_MAR(i), dev->dev_addr[i]);

mutex_unlock(&ks->lock);

Expand Down
1 change: 1 addition & 0 deletions drivers/net/ks8851.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define CCR_32PIN (1 << 0)

/* MAC address registers */
#define KS_MAR(_m) 0x15 - (_m)
#define KS_MARL 0x10
#define KS_MARM 0x12
#define KS_MARH 0x14
Expand Down

0 comments on commit 160d0fa

Please sign in to comment.