Skip to content

Commit 2d84377

Browse files
andy_chiAndy Chi
authored andcommitted
Ethernet: read MAC address from EEPROM
Change-Id: I244f1369e7c2d7925d9cc73c34b6c836481277ba
1 parent ea56cd2 commit 2d84377

6 files changed

Lines changed: 74 additions & 4 deletions

File tree

drivers/misc/eeprom/at24.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ 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;
101102
#define AT24_SIZE_BYTELEN 5
102103
#define AT24_SIZE_FLAGS 8
103104

@@ -293,6 +294,13 @@ static ssize_t at24_bin_read(struct file *filp, struct kobject *kobj,
293294
return at24_read(at24, buf, off, count);
294295
}
295296

297+
void at24_read_eeprom(char *buf, loff_t off, size_t count)
298+
{
299+
struct at24_data *at24;
300+
301+
at24 = dev_get_drvdata(container_of(eeprom_kobj, struct device, kobj));
302+
at24_read(at24, buf, off, count);
303+
}
296304

297305
/*
298306
* Note that if the hardware write-protect pin is pulled high, the whole
@@ -631,6 +639,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
631639
if (err)
632640
goto err_clients;
633641

642+
eeprom_kobj = &client->dev.kobj;
634643
i2c_set_clientdata(client, at24);
635644

636645
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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
11+
#include <linux/module.h>
12+
#include <linux/kernel.h>
13+
#include <linux/errno.h>
14+
#include <linux/miscdevice.h>
15+
#include <linux/fs.h>
16+
#include <linux/platform_device.h>
17+
#include <asm/uaccess.h>
18+
#include <asm/io.h>
19+
#include <linux/fs.h>
20+
#include <linux/slab.h>
21+
#include "eth_mac_tinker.h"
22+
#include <linux/platform_data/at24.h>
23+
24+
#if 1
25+
#define DBG(x...) printk("eth_mac:" x)
26+
#else
27+
#define DBG(x...)
28+
#endif
29+
30+
#define VERSION "0.1"
31+
32+
#define WLAN_MAC_FILE "/data/misc/wifi/wlan_mac"
33+
34+
int eth_mac_eeprom(u8 *eth_mac)
35+
{
36+
int i;
37+
memset(eth_mac, 0, 6);
38+
printk("Read the Ethernet MAC address from EEPROM:");
39+
at24_read_eeprom(eth_mac, 0, 6);
40+
for(i=0; i<5; i++)
41+
printk("%2.2x:", eth_mac[i]);
42+
printk("%2.2x\n", eth_mac[i]);
43+
44+
return 0;
45+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
*
12+
*/
13+
int eth_mac_eeprom(u8 *eth_mac);
14+
#endif /* _ETH_MAC_TINKER_H_ */

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "stmmac.h"
5454
#include <linux/reset.h>
5555
#include <linux/of_mdio.h>
56+
#include "eth_mac_tinker.h"
5657

5758
#define STMMAC_ALIGN(x) L1_CACHE_ALIGN(x)
5859

@@ -1619,8 +1620,9 @@ static int stmmac_get_hw_features(struct stmmac_priv *priv)
16191620
static void stmmac_check_ether_addr(struct stmmac_priv *priv)
16201621
{
16211622
if (!is_valid_ether_addr(priv->dev->dev_addr)) {
1622-
priv->hw->mac->get_umac_addr(priv->hw,
1623-
priv->dev->dev_addr, 0);
1623+
/* priv->hw->mac->get_umac_addr(priv->hw,
1624+
priv->dev->dev_addr, 0);*/
1625+
eth_mac_eeprom(priv->dev->dev_addr);
16241626
if (!is_valid_ether_addr(priv->dev->dev_addr))
16251627
eth_hw_addr_random(priv->dev);
16261628
pr_info("%s: device MAC address %pM\n", priv->dev->name,

include/linux/platform_data/at24.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ struct at24_platform_data {
5151
void (*setup)(struct memory_accessor *, void *context);
5252
void *context;
5353
};
54-
54+
extern void at24_read_eeprom(char *buf, loff_t off, size_t count);
5555
#endif /* _LINUX_AT24_H */

0 commit comments

Comments
 (0)