ODROIDC:Ethernet MAC_address using efuse data

Change-Id: I0789ff649a462e00f62705d8b3b08ef5c27a8b82
(cherry picked from commit 577b9c2c49122ea751175530ffca3ffa5d7ec494)

Signed-off-by: Dongjin Kim <tobetter@gmail.com>
This commit is contained in:
ckkim
2014-11-20 17:46:11 +09:00
committed by Dongjin Kim
parent 6c8d8d6c15
commit 02dcb20caf
2 changed files with 72 additions and 0 deletions

54
drivers/amlogic/efuse/efuse.c Executable file → Normal file
View File

@@ -239,6 +239,41 @@ static const struct file_operations efuse_fops = {
.unlocked_ioctl = efuse_unlocked_ioctl,
};
#if defined(CONFIG_MACH_MESON8B_ODROIDC)
/* function: aml_efuse_get_item
* key_name: key name
* data: key data
* return : >=0 ok, <0 error
* */
int aml_efuse_get_item(unsigned char* key_name, unsigned char* data)
{
char dec_mac[50] = {0};
efuseinfo_item_t info;
unsigned id=0;
if(strcmp(key_name,"mac")==0) id = EFUSE_MAC_ID;
else if(strcmp(key_name,"mac_bt")==0) id = EFUSE_MAC_BT_ID;
else if(strcmp(key_name,"mac_wifi")==0) id = EFUSE_MAC_WIFI_ID;
else if(strcmp(key_name,"usid")==0) id = EFUSE_USID_ID;
else {
printk(KERN_INFO"%s : UNKNOWN key_name\n",__func__);
return -EFAULT;
}
if(efuse_getinfo_byID(id, &info) < 0){
printk(KERN_INFO"ID is not found\n");
return -EFAULT;
}
if (efuse_read_item(dec_mac, info.data_len, (loff_t*)&info.offset) < 0)
return -EFAULT;
memcpy(&data[0],dec_mac,info.data_len);
return 0;
}
EXPORT_SYMBOL(aml_efuse_get_item);
#endif
/* Sysfs Files */
static ssize_t mac_show(struct class *cla, struct class_attribute *attr, char *buf)
{
@@ -290,6 +325,23 @@ static ssize_t mac_bt_show(struct class *cla, struct class_attribute *attr, char
dec_mac[0],dec_mac[1],dec_mac[2],dec_mac[3],dec_mac[4],dec_mac[5]);
}
#if defined(CONFIG_MACH_MESON8B_ODROIDC)
static ssize_t usid_show(struct class *cla, struct class_attribute *attr, char *buf)
{
char usid[50] = {0};
efuseinfo_item_t info;
if(efuse_getinfo_byID(EFUSE_USID_ID, &info) < 0){
printk(KERN_INFO"ID is not found\n");
return -EFAULT;
}
if (efuse_read_item(usid, info.data_len, (loff_t*)&info.offset) < 0)
return -EFAULT;
return sprintf(buf, "%s\n",usid);
}
#endif
static int efuse_device_match(struct device *dev, const void *data)
{
return (!strcmp(dev->kobj.name,(const char*)data));
@@ -428,6 +480,8 @@ static struct class_attribute efuse_class_attrs[] = {
__ATTR_RO(mac_bt),
__ATTR_RO(usid),
#ifndef EFUSE_READ_ONLY /*make the efuse can not be write through sysfs */
__ATTR(userdata, S_IRWXU, userdata_show, userdata_write),

18
drivers/amlogic/ethernet/am_net8218.c Executable file → Normal file
View File

@@ -916,6 +916,20 @@ void read_mac_from_nand(struct net_device *ndev)
}
#endif
#if defined(CONFIG_MACH_MESON8B_ODROIDC)
extern int aml_efuse_get_item(unsigned char* key_name, unsigned char* data);
void read_mac_from_efuse(struct net_device *ndev)
{
int ret;
ret = aml_efuse_get_item("mac", ndev->dev_addr);
if (ret < 0) {
printk(KERN_INFO "ERROR! failed to read hardware mac address\n");
random_ether_addr(ndev->dev_addr);
}
}
#endif
static int aml_mac_init(struct net_device *ndev)
{
struct am_net_private *np = netdev_priv(ndev);
@@ -923,6 +937,9 @@ static int aml_mac_init(struct net_device *ndev)
writel(1, (void*)(np->base_addr + ETH_DMA_0_Bus_Mode));
writel(0x00100800,(void*)(np->base_addr + ETH_DMA_0_Bus_Mode));
#if defined(CONFIG_MACH_MESON8B_ODROIDC)
read_mac_from_efuse(ndev);
#else
printk("--1--write mac add to:");
data_dump(ndev->dev_addr, 6);
@@ -931,6 +948,7 @@ static int aml_mac_init(struct net_device *ndev)
#endif
printk("--2--write mac add to:");
data_dump(ndev->dev_addr, 6);
#endif
write_mac_addr(ndev, ndev->dev_addr);
val = 0xc80c | //8<<8 | 8<<17; //tx and rx all 8bit mode;