soc: rockchip: add devinfo parser driver
authorZhangbin Tong <zebulun.tong@rock-chips.com>
Tue, 2 May 2017 10:44:56 +0000 (18:44 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Fri, 12 May 2017 11:30:26 +0000 (19:30 +0800)
Change-Id: I8e16d5ee8a1456de43e46e68bee60e7fb2a7b266
Signed-off-by: Zhangbin Tong <zebulun.tong@rock-chips.com>
drivers/soc/rockchip/Kconfig
drivers/soc/rockchip/Makefile
drivers/soc/rockchip/rk_devinfo.c [new file with mode: 0644]

index ae4cf24a8f70b95ee56f786f176bf6e7ac35e8f1..60496713ebce69b0d1cfa79a2e0de4b37a9acead 100644 (file)
@@ -13,6 +13,12 @@ config ROCKCHIP_CPUINFO
 
          If unsure, say N.
 
+config ROCKCHIP_DEVICEINFO
+       tristate "support deviceinfo partition"
+       default n
+       help
+         Say y here if you have a deviceinfo partition.
+
 config ROCKCHIP_PM_TEST
        bool "Rockchip pm_test support"
        default n
index 4c2ee0cf58816c061c5ca92882b4dd94178cbc37..16861bd11da931dc7ed5a932a55f628c7d5e9053 100644 (file)
@@ -2,6 +2,7 @@
 # Rockchip Soc drivers
 #
 obj-$(CONFIG_ROCKCHIP_CPUINFO) += rockchip-cpuinfo.o
+obj-$(CONFIG_ROCKCHIP_DEVICEINFO)      += rk_devinfo.o
 obj-$(CONFIG_ROCKCHIP_PM_TEST) += pm_test.o
 obj-$(CONFIG_ROCKCHIP_PM_DOMAINS) += pm_domains.o
 obj-$(CONFIG_FIQ_DEBUGGER) += rk_fiq_debugger.o
diff --git a/drivers/soc/rockchip/rk_devinfo.c b/drivers/soc/rockchip/rk_devinfo.c
new file mode 100644 (file)
index 0000000..74c98c0
--- /dev/null
@@ -0,0 +1,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);