hc
2023-12-02 57e32c52610e6a560beda60bf33c48f9f42306d5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * Copyright (C) 2015 ROCKCHIP, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
#include <linux/module.h>
#include <linux/memblock.h>
#include <linux/of.h>
#include <linux/of_address.h>
 
#define ETH_MAC_OFFSET    36
 
static u8 eth_mac[6];
 
void rk_devinfo_get_eth_mac(u8 *mac)
{
   memcpy(mac, eth_mac, 6);
   pr_info("%s: %02x.%02x.%02x.%02x.%02x.%02x\n", __func__,
       eth_mac[0], eth_mac[1], eth_mac[2],
       eth_mac[3], eth_mac[4], eth_mac[5]);
}
EXPORT_SYMBOL_GPL(rk_devinfo_get_eth_mac);
 
static int __init rk_devinfo_init(void)
{
   int ret;
   u8 *vaddr;
   struct device_node *node;
   struct resource res;
   phys_addr_t start, size;
   void *begin, *end;
 
   node = of_find_node_by_name(NULL, "stb-devinfo");
   if (!node) {
       pr_err("%s.%d: fail to get node\n", __func__, __LINE__);
       goto out;
   }
 
   ret = of_address_to_resource(node, 0, &res);
   if (ret) {
       pr_err("%s.%d: fail to get resource\n", __func__, __LINE__);
       of_node_put(node);
       goto out;
   }
 
   of_node_put(node);
 
   start = res.start;
   size = resource_size(&res);
   if (!size) {
       pr_err("%s.%d: size = 0\n", __func__, __LINE__);
       goto out;
   }
   vaddr = phys_to_virt(start);
   /* copy eth mac addr */
   memcpy(eth_mac, vaddr + ETH_MAC_OFFSET, 6);
 
   begin = phys_to_virt(start);
   end = phys_to_virt(start + size);
   memblock_free(start, size);
   free_reserved_area(begin, end, -1, "stb_devinfo");
 
out:
 
   return 0;
}
 
module_init(rk_devinfo_init);