diff options
author | Ben Dooks <ben@simtec.co.uk> | 2009-10-19 19:49:04 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-10-20 22:11:06 -0400 |
commit | 160d0fadaf7ce20e5bad26c8a955504b93c6a5ba (patch) | |
tree | b1f45760cbde7a0b9d819333fef930685e1b67e9 /drivers/net/ks8851.c | |
parent | 57dada6819160eb08f2945fb847045f173d3218d (diff) |
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>
Diffstat (limited to 'drivers/net/ks8851.c')
-rw-r--r-- | drivers/net/ks8851.c | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/drivers/net/ks8851.c b/drivers/net/ks8851.c index 18b17a1deb11..29fa19a076bd 100644 --- a/drivers/net/ks8851.c +++ b/drivers/net/ks8851.c | |||
@@ -171,6 +171,36 @@ static void ks8851_wrreg16(struct ks8851_net *ks, unsigned reg, unsigned val) | |||
171 | } | 171 | } |
172 | 172 | ||
173 | /** | 173 | /** |
174 | * ks8851_wrreg8 - write 8bit register value to chip | ||
175 | * @ks: The chip state | ||
176 | * @reg: The register address | ||
177 | * @val: The value to write | ||
178 | * | ||
179 | * Issue a write to put the value @val into the register specified in @reg. | ||
180 | */ | ||
181 | static void ks8851_wrreg8(struct ks8851_net *ks, unsigned reg, unsigned val) | ||
182 | { | ||
183 | struct spi_transfer *xfer = &ks->spi_xfer1; | ||
184 | struct spi_message *msg = &ks->spi_msg1; | ||
185 | __le16 txb[2]; | ||
186 | int ret; | ||
187 | int bit; | ||
188 | |||
189 | bit = 1 << (reg & 3); | ||
190 | |||
191 | txb[0] = cpu_to_le16(MK_OP(bit, reg) | KS_SPIOP_WR); | ||
192 | txb[1] = val; | ||
193 | |||
194 | xfer->tx_buf = txb; | ||
195 | xfer->rx_buf = NULL; | ||
196 | xfer->len = 3; | ||
197 | |||
198 | ret = spi_sync(ks->spidev, msg); | ||
199 | if (ret < 0) | ||
200 | ks_err(ks, "spi_sync() failed\n"); | ||
201 | } | ||
202 | |||
203 | /** | ||
174 | * ks8851_rx_1msg - select whether to use one or two messages for spi read | 204 | * ks8851_rx_1msg - select whether to use one or two messages for spi read |
175 | * @ks: The device structure | 205 | * @ks: The device structure |
176 | * | 206 | * |
@@ -322,13 +352,12 @@ static void ks8851_soft_reset(struct ks8851_net *ks, unsigned op) | |||
322 | static int ks8851_write_mac_addr(struct net_device *dev) | 352 | static int ks8851_write_mac_addr(struct net_device *dev) |
323 | { | 353 | { |
324 | struct ks8851_net *ks = netdev_priv(dev); | 354 | struct ks8851_net *ks = netdev_priv(dev); |
325 | u16 *mcp = (u16 *)dev->dev_addr; | 355 | int i; |
326 | 356 | ||
327 | mutex_lock(&ks->lock); | 357 | mutex_lock(&ks->lock); |
328 | 358 | ||
329 | ks8851_wrreg16(ks, KS_MARL, mcp[0]); | 359 | for (i = 0; i < ETH_ALEN; i++) |
330 | ks8851_wrreg16(ks, KS_MARM, mcp[1]); | 360 | ks8851_wrreg8(ks, KS_MAR(i), dev->dev_addr[i]); |
331 | ks8851_wrreg16(ks, KS_MARH, mcp[2]); | ||
332 | 361 | ||
333 | mutex_unlock(&ks->lock); | 362 | mutex_unlock(&ks->lock); |
334 | 363 | ||