Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 97 additions & 25 deletions drivers/amlogic/efuse/efuse.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static long efuse_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned l
{
switch (cmd)
{
#ifndef CONFIG_MESON_TRUSTZONE
#ifndef CONFIG_MESON_TRUSTZONE
case EFUSE_ENCRYPT_ENABLE:
aml_set_reg32_bits( P_EFUSE_CNTL4, CNTL4_ENCRYPT_ENABLE_ON,
CNTL4_ENCRYPT_ENABLE_BIT, CNTL4_ENCRYPT_ENABLE_SIZE);
Expand Down Expand Up @@ -191,7 +191,7 @@ static ssize_t efuse_write( struct file *file, const char __user *buf, size_t co
unsigned char* contents = NULL;

if (pos >= EFUSE_BYTES)
return 0; /* Past EOF */
return 0; /* Past EOF */
if (count > EFUSE_BYTES - pos)
count = EFUSE_BYTES - pos;
if (count > EFUSE_BYTES)
Expand Down Expand Up @@ -239,21 +239,72 @@ static const struct file_operations efuse_fops = {
.unlocked_ioctl = efuse_unlocked_ioctl,
};

/* Sysfs Files */
static ssize_t mac_show(struct class *cla, struct class_attribute *attr, char *buf)
#define MACCHAR(x) (('A' <= (x) && (x) <= 'F') \
? (x) - 'A' + 'a' : (x))

static char *aml_efuse_mac(void)
{
char dec_mac[6] = {0};
char hwmac[20];
char buf[80];
char mac_mask;
efuseinfo_item_t info;
if(efuse_getinfo_byID(EFUSE_MAC_ID, &info) < 0){
printk(KERN_INFO"ID is not found\n");
return -EFAULT;

if (efuse_getinfo_byID(EFUSE_MAC_ID, &info) < 0)
return 0;

if (efuse_read_item(buf, info.data_len,
(loff_t*)&info.offset) < 0)
return 0;

sprintf(hwmac, "%02x:%02x:%02x:%02x:%02x:%02x",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);

mac_mask = buf[3] & 0xf0;
if ((0x30 == mac_mask)
|| ((0xa0 <= mac_mask) && (mac_mask <= 0xc0))) {
info.data_len = 16;
info.offset = 4;
efuse_read_item(buf, info.data_len,
(loff_t*)&info.offset);

if (0x30 == mac_mask) {
hwmac[9] = MACCHAR(buf[5]);
}

sprintf(hwmac + 10, "%c:%c%c:%c%c",
MACCHAR(buf[11]), MACCHAR(buf[12]), MACCHAR(buf[13]),
MACCHAR(buf[14]), MACCHAR(buf[15]));
}

if (efuse_read_item(dec_mac, info.data_len, (loff_t*)&info.offset) < 0)
return -EFAULT;
return hwmac;
}

return sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x\n",
dec_mac[0],dec_mac[1],dec_mac[2],dec_mac[3],dec_mac[4],dec_mac[5]);
unsigned char *aml_efuse_get_item(unsigned char* key_name)
{
unsigned char *ret = 0;
int id;

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 {
pr_info("%s: UNKNOWN key_name\n", __func__);
return 0;
}

if (id == EFUSE_MAC_ID) {
return aml_efuse_mac();
}

return ret;
}
EXPORT_SYMBOL(aml_efuse_get_item);

/* Sysfs Files */
static ssize_t mac_show(struct class *cla, struct class_attribute *attr, char *buf)
{
return sprintf(buf, "%s\n", aml_efuse_mac());
}

static ssize_t mac_wifi_show(struct class *cla, struct class_attribute *attr, char *buf)
Expand Down Expand Up @@ -290,6 +341,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));
Expand All @@ -310,9 +378,9 @@ struct device *efuse_class_to_device(struct class *cla)
{
int len;

len = strlen(usid);
if((len > 8)&&(len<31) )
return 0;
len = strlen(usid);
if((len > 8)&&(len<31) )
return 0;
else
return -1;
}*/
Expand Down Expand Up @@ -359,15 +427,15 @@ static ssize_t userdata_show(struct class *cla, struct class_attribute *attr, ch
// return -1;
//}
/*return sprintf(buf, "%01c%01c%01c%01c%01c%01c%01c%01c%01c%01c%01c%01c%01c%01c%01c%01c%01c%01c%01c%01c\n",
op[0],op[1],op[2],op[3],op[4],op[5],
op[6],op[7],op[8],op[9],op[10],op[11],
op[12],op[13],op[14],op[15],op[16],op[17],
op[18],op[19]);*/
op[0],op[1],op[2],op[3],op[4],op[5],
op[6],op[7],op[8],op[9],op[10],op[11],
op[12],op[13],op[14],op[15],op[16],op[17],
op[18],op[19]);*/

for(i = 0; i < info.data_len; i++) {
memset(tmp, 0, 5);
sprintf(tmp, "%02x:", op[i]);
strcat(buf, tmp);
memset(tmp, 0, 5);
sprintf(tmp, "%02x:", op[i]);
strcat(buf, tmp);
}
buf[3*info.data_len - 1] = 0; //delete the last ':'
return 3*info.data_len - 1;
Expand Down Expand Up @@ -428,6 +496,10 @@ static struct class_attribute efuse_class_attrs[] = {

__ATTR_RO(mac_bt),

#if defined(CONFIG_MACH_MESON8B_ODROIDC)
__ATTR_RO(usid),
#endif

#ifndef EFUSE_READ_ONLY /*make the efuse can not be write through sysfs */
__ATTR(userdata, S_IRWXU, userdata_show, userdata_write),

Expand Down Expand Up @@ -531,9 +603,9 @@ int usid_min,usid_max;
if(pdev->dev.platform_data)
devp->platform_data = pdev->dev.platform_data;
else
devp->platform_data = NULL;
devp->platform_data = NULL;
#endif
#ifndef CONFIG_MESON_TRUSTZONE
#ifndef CONFIG_MESON_TRUSTZONE
/* disable efuse encryption */
aml_set_reg32_bits( P_EFUSE_CNTL4, CNTL1_AUTO_WR_ENABLE_OFF,
CNTL4_ENCRYPT_ENABLE_BIT, CNTL4_ENCRYPT_ENABLE_SIZE );
Expand All @@ -547,7 +619,7 @@ int usid_min,usid_max;
// clear power down bit
aml_set_reg32_bits(P_EFUSE_CNTL1, CNTL1_PD_ENABLE_OFF,
CNTL1_PD_ENABLE_BIT, CNTL1_PD_ENABLE_SIZE);
#endif
#endif
#endif
return 0;

Expand Down
Loading