From e150f22f63672e0a54f9d3ee1ea7eeaed5903231 Mon Sep 17 00:00:00 2001 From: Channagoud Kadabi Date: Mon, 5 Nov 2018 16:22:29 -0800 Subject: [PATCH] ANDROID: GKI: drivers: of: Add API to find ddr device type Add API to find the ddr device type from memory node. Test: build Bug: 150980314 Change-Id: I1cfc38d46f1ea0abc6fbe8cbb6e37cde72b9fc2e Signed-off-by: Channagoud Kadabi (cherry picked from commit 368f22bc0d35888285a523f190ac1f5024168fa4) [hridya: added an EXPORT_SYMBOL_GPL statement to make the new symbol avaialable to kernel modules]. Signed-off-by: Hridya Valsaraju --- drivers/of/fdt.c | 27 +++++++++++++++++++++++++++ include/linux/of_fdt.h | 1 + 2 files changed, 28 insertions(+) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 86e720332168..85b0055a5ae4 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -80,6 +80,33 @@ void of_fdt_limit_memory(int limit) } } +/** + * of_fdt_get_ddrtype - Return the type of ddr (4/5) on the current device + * + * On match, returns a non-zero positive value which matches the ddr type. + * Otherwise returns -ENOENT. + */ +int of_fdt_get_ddrtype(void) +{ + int memory; + int len; + int ret; + fdt32_t *prop = NULL; + + memory = fdt_path_offset(initial_boot_params, "/memory"); + if (memory > 0) + prop = fdt_getprop_w(initial_boot_params, memory, + "ddr_device_type", &len); + + if (!prop || len != sizeof(u32)) + return -ENOENT; + + ret = fdt32_to_cpu(*prop); + + return ret; +} +EXPORT_SYMBOL_GPL(of_fdt_get_ddrtype); + /** * of_fdt_is_compatible - Return true if given node from the given blob has * compat in its compatible list diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index 587c147a2436..f41f3c463307 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -47,6 +47,7 @@ extern char __dtb_end[]; /* Other Prototypes */ extern u64 of_flat_dt_translate_address(unsigned long node); extern void of_fdt_limit_memory(int limit); +extern int of_fdt_get_ddrtype(void); #endif /* CONFIG_OF_FLATTREE */ #ifdef CONFIG_OF_EARLY_FLATTREE