From f19114808f09c872274f23cab7427e6cb1d80c6c Mon Sep 17 00:00:00 2001 From: Zhangbin Tong Date: Tue, 2 May 2017 18:44:56 +0800 Subject: [PATCH] soc: rockchip: add devinfo parser driver Change-Id: I8e16d5ee8a1456de43e46e68bee60e7fb2a7b266 Signed-off-by: Zhangbin Tong --- drivers/soc/rockchip/Kconfig | 6 +++ drivers/soc/rockchip/Makefile | 1 + drivers/soc/rockchip/rk_devinfo.c | 76 +++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 drivers/soc/rockchip/rk_devinfo.c diff --git a/drivers/soc/rockchip/Kconfig b/drivers/soc/rockchip/Kconfig index ae4cf24a8f70..60496713ebce 100644 --- a/drivers/soc/rockchip/Kconfig +++ b/drivers/soc/rockchip/Kconfig @@ -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 diff --git a/drivers/soc/rockchip/Makefile b/drivers/soc/rockchip/Makefile index 4c2ee0cf5881..16861bd11da9 100644 --- a/drivers/soc/rockchip/Makefile +++ b/drivers/soc/rockchip/Makefile @@ -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 index 000000000000..74c98c0f7c63 --- /dev/null +++ b/drivers/soc/rockchip/rk_devinfo.c @@ -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 +#include +#include +#include + +#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); -- 2.34.1