Skip to content

Commit 3785eb1

Browse files
yupei_linasus-leslieyu
authored andcommitted
Ethernet : read MAC address from EEPROM.
Change-Id: I22d9948a621cc2d25cec0c798fe450af8ad70001
1 parent 2fc31fa commit 3785eb1

6 files changed

Lines changed: 76 additions & 11 deletions

File tree

drivers/misc/eeprom/at24.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ static unsigned write_timeout = 25;
9898
module_param(write_timeout, uint, 0);
9999
MODULE_PARM_DESC(write_timeout, "Time (in ms) to try writes (default 25)");
100100

101+
static struct kobject *eeprom_kobj;
102+
101103
#define AT24_SIZE_BYTELEN 5
102104
#define AT24_SIZE_FLAGS 8
103105

@@ -296,6 +298,13 @@ static ssize_t at24_bin_read(struct file *filp, struct kobject *kobj,
296298
return at24_read(at24, buf, off, count);
297299
}
298300

301+
void at24_read_eeprom(char *buf, loff_t off, size_t count)
302+
{
303+
struct at24_data *at24;
304+
305+
at24 = dev_get_drvdata(container_of(eeprom_kobj, struct device, kobj));
306+
at24_read(at24, buf, off, count);
307+
}
299308

300309
/*
301310
* Note that if the hardware write-protect pin is pulled high, the whole
@@ -637,6 +646,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
637646
if (err)
638647
goto err_clients;
639648

649+
eeprom_kobj = &client->dev.kobj;
640650
i2c_set_clientdata(client, at24);
641651

642652
dev_info(&client->dev, "%zu byte %s EEPROM, %s, %u bytes/write\n",

drivers/net/ethernet/stmicro/stmmac/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ obj-$(CONFIG_STMMAC_ETH) += stmmac.o
22
stmmac-objs:= stmmac_main.o stmmac_ethtool.o stmmac_mdio.o ring_mode.o \
33
chain_mode.o dwmac_lib.o dwmac1000_core.o dwmac1000_dma.o \
44
dwmac100_core.o dwmac100_dma.o enh_desc.o norm_desc.o \
5-
mmc_core.o stmmac_hwtstamp.o stmmac_ptp.o $(stmmac-y)
5+
mmc_core.o stmmac_hwtstamp.o stmmac_ptp.o eth_mac_tinker.o $(stmmac-y)
66

77
# Ordering matters. Generic driver must be last.
88
obj-$(CONFIG_STMMAC_PLATFORM) += stmmac-platform.o
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (C) 2010 ROCKCHIP, Inc.
3+
* Author: roger_chen <cz@rock-chips.com>
4+
*
5+
* This program is the virtual flash device
6+
* used to store bd_addr or MAC
7+
*
8+
*/
9+
10+
#include <linux/module.h>
11+
#include <linux/kernel.h>
12+
#include <linux/errno.h>
13+
#include <linux/miscdevice.h>
14+
#include <linux/fs.h>
15+
#include <linux/platform_device.h>
16+
#include <asm/uaccess.h>
17+
#include <asm/io.h>
18+
#include <linux/fs.h>
19+
#include <linux/slab.h>
20+
#include "eth_mac_tinker.h"
21+
#include <linux/platform_data/at24.h>
22+
23+
#if 1
24+
#define DBG(x...) printk("eth_mac:" x)
25+
#else
26+
#define DBG(x...)
27+
#endif
28+
29+
#define VERSION "0.1"
30+
#define WLAN_MAC_FILE "/data/misc/wifi/wlan_mac"
31+
32+
int eth_mac_eeprom(u8 *eth_mac)
33+
{
34+
int i;
35+
memset(eth_mac, 0, 6);
36+
printk("Read the Ethernet MAC address from EEPROM:");
37+
at24_read_eeprom(eth_mac, 0, 6);
38+
for(i=0; i<5; i++)
39+
printk("%2.2x:", eth_mac[i]);
40+
printk("%2.2x\n", eth_mac[i]);
41+
42+
return 0;
43+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef _ETH_MAC_TINKER_H_
2+
#define _ETH_MAC_TINKER_H_
3+
/*
4+
* eth_mac/eth_mac.h
5+
*
6+
* Copyright (C) 2001 Russell King.
7+
*
8+
* This file is placed under the LGPL.
9+
*
10+
*/
11+
int eth_mac_eeprom(u8 *eth_mac);
12+
#endif /* _ETH_MAC_TINKER_H_ */

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "dwmac-rk-tool.h"
5555
#include <linux/reset.h>
5656
#include <linux/of_mdio.h>
57+
#include "eth_mac_tinker.h"
5758

5859
#define STMMAC_ALIGN(x) __ALIGN_KERNEL(x, SMP_CACHE_BYTES)
5960

@@ -1643,17 +1644,14 @@ static int stmmac_get_hw_features(struct stmmac_priv *priv)
16431644
*/
16441645
static void stmmac_check_ether_addr(struct stmmac_priv *priv)
16451646
{
1646-
if (!is_valid_ether_addr(priv->dev->dev_addr)) {
1647-
priv->hw->mac->get_umac_addr(priv->hw,
1648-
priv->dev->dev_addr, 0);
1649-
if (likely(priv->plat->get_eth_addr))
1650-
priv->plat->get_eth_addr(priv->plat->bsp_priv,
1651-
priv->dev->dev_addr);
1652-
if (!is_valid_ether_addr(priv->dev->dev_addr))
1653-
eth_hw_addr_random(priv->dev);
1654-
pr_info("%s: device MAC address %pM\n", priv->dev->name,
1647+
eth_mac_eeprom(priv->dev->dev_addr);
1648+
if (likely(priv->plat->get_eth_addr))
1649+
priv->plat->get_eth_addr(priv->plat->bsp_priv,
16551650
priv->dev->dev_addr);
1656-
}
1651+
if (!is_valid_ether_addr(priv->dev->dev_addr))
1652+
eth_hw_addr_random(priv->dev);
1653+
pr_info("%s: device MAC address %pM\n", priv->dev->name,
1654+
priv->dev->dev_addr);
16571655
}
16581656

16591657
/**

include/linux/platform_data/at24.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,6 @@ struct at24_platform_data {
5252
void *context;
5353
};
5454

55+
extern void at24_read_eeprom(char *buf, loff_t off, size_t count);
56+
5557
#endif /* _LINUX_AT24_H */

0 commit comments

Comments
 (0)