diff options
Diffstat (limited to 'arch/arm/mach-tegra/eeprom-wifi-mac.c')
-rw-r--r-- | arch/arm/mach-tegra/eeprom-wifi-mac.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/arch/arm/mach-tegra/eeprom-wifi-mac.c b/arch/arm/mach-tegra/eeprom-wifi-mac.c new file mode 100644 index 00000000000..fb35c090906 --- /dev/null +++ b/arch/arm/mach-tegra/eeprom-wifi-mac.c | |||
@@ -0,0 +1,65 @@ | |||
1 | #include <linux/i2c/at24.h> | ||
2 | #include <linux/sysfs.h> | ||
3 | #include <linux/device.h> | ||
4 | #include <linux/slab.h> | ||
5 | |||
6 | #define EEPROM_LEN 32 | ||
7 | |||
8 | static char wifi_mac[] = "ff:ff:ff:ff:ff:ff"; | ||
9 | |||
10 | static ssize_t show_addr_sysfs(struct device *dev, | ||
11 | struct device_attribute *attr, char *buf) | ||
12 | { | ||
13 | return sprintf(buf, "%s\n", wifi_mac); | ||
14 | } | ||
15 | |||
16 | DEVICE_ATTR(addr, 0444, show_addr_sysfs, NULL); | ||
17 | |||
18 | static struct attribute *wifi_mac_addr_attributes[] = { | ||
19 | &dev_attr_addr.attr, | ||
20 | NULL | ||
21 | }; | ||
22 | |||
23 | static const struct attribute_group wifi_mac_addr_group = { | ||
24 | .attrs = wifi_mac_addr_attributes, | ||
25 | }; | ||
26 | |||
27 | int create_sys_fs(void) | ||
28 | { | ||
29 | int ret = -1; | ||
30 | static struct kobject *reg_kobj; | ||
31 | reg_kobj = kobject_create_and_add("wifi_mac_addr", kernel_kobj); | ||
32 | if (!reg_kobj) | ||
33 | return -ENOMEM; | ||
34 | |||
35 | ret = sysfs_create_group(reg_kobj, &wifi_mac_addr_group); | ||
36 | if (ret < 0) { | ||
37 | kobject_put(reg_kobj); | ||
38 | return ret; | ||
39 | } | ||
40 | return ret; | ||
41 | } | ||
42 | |||
43 | void get_mac_addr(struct memory_accessor *mem_acc, void *context) | ||
44 | { | ||
45 | char *mac_addr; | ||
46 | int ret = 0; | ||
47 | off_t offset = (off_t)context; | ||
48 | mac_addr = kzalloc(sizeof(char)*EEPROM_LEN, GFP_ATOMIC); | ||
49 | if (!mac_addr) { | ||
50 | pr_err("no memory to allocate"); | ||
51 | return; | ||
52 | } | ||
53 | |||
54 | /* Read MAC addr from EEPROM */ | ||
55 | ret = mem_acc->read(mem_acc, mac_addr, offset, EEPROM_LEN); | ||
56 | if (ret == EEPROM_LEN) { | ||
57 | pr_err("Read MAC addr from EEPROM: %pM\n", (mac_addr+19)); | ||
58 | sprintf(wifi_mac, "%02x:%02x:%02x:%02x:%02x:%02x", | ||
59 | *(mac_addr+19), *(mac_addr+20), *(mac_addr+21), | ||
60 | *(mac_addr+22), *(mac_addr+23), *(mac_addr+24)); | ||
61 | } else | ||
62 | pr_err("Error reading MAC addr from EEPROM\n"); | ||
63 | |||
64 | create_sys_fs(); | ||
65 | } | ||