snapdragon: added msm_board_serial() func
authorRamon Fried <ramon.fried@gmail.com>
Fri, 3 Aug 2018 13:25:35 +0000 (16:25 +0300)
committerTom Rini <trini@konsulko.com>
Mon, 13 Aug 2018 18:04:04 +0000 (14:04 -0400)
This commit adds a function to get the board
serial number.
In snapdragon it's actually the eMMC serial number.

Function added in a new file misc.c that will
include further snapdragon miscellaneous functions.

Signed-off-by: Ramon Fried <ramon.fried@gmail.com>
arch/arm/mach-snapdragon/Makefile
arch/arm/mach-snapdragon/include/mach/misc.h [new file with mode: 0644]
arch/arm/mach-snapdragon/misc.c [new file with mode: 0644]

index f375d07d03d1cc0012802ae8f51a66439f62642b..2d9408360021e9e8ca44de3d155fc0e17ab153ab 100644 (file)
@@ -8,5 +8,6 @@ obj-$(CONFIG_TARGET_DRAGONBOARD410C) += clock-apq8016.o
 obj-$(CONFIG_TARGET_DRAGONBOARD410C) += sysmap-apq8016.o
 obj-$(CONFIG_TARGET_DRAGONBOARD410C) += pinctrl-apq8016.o
 obj-$(CONFIG_TARGET_DRAGONBOARD410C) += pinctrl-snapdragon.o
+obj-y += misc.o
 obj-y += clock-snapdragon.o
 obj-y += dram.o
diff --git a/arch/arm/mach-snapdragon/include/mach/misc.h b/arch/arm/mach-snapdragon/include/mach/misc.h
new file mode 100644 (file)
index 0000000..5af6ae8
--- /dev/null
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Snapdragon DRAM
+ * Copyright (C) 2018 Ramon Fried <ramon.fried@gmail.com>
+ */
+
+#ifndef MISC_H
+#define MISC_H
+
+u32 msm_board_serial(void);
+
+#endif
diff --git a/arch/arm/mach-snapdragon/misc.c b/arch/arm/mach-snapdragon/misc.c
new file mode 100644 (file)
index 0000000..678bd69
--- /dev/null
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Miscellaneous Snapdragon functionality
+ *
+ * (C) Copyright 2018 Ramon Fried <ramon.fried@gmail.com>
+ *
+ */
+
+#include <common.h>
+#include <mmc.h>
+#include <asm/arch/misc.h>
+
+/* UNSTUFF_BITS macro taken from Linux Kernel: drivers/mmc/core/sd.c */
+#define UNSTUFF_BITS(resp, start, size) \
+       ({ \
+               const int __size = size; \
+               const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \
+               const int __off = 3 - ((start) / 32); \
+               const int __shft = (start) & 31; \
+               u32 __res; \
+                                       \
+               __res = resp[__off] >> __shft; \
+               if (__size + __shft > 32) \
+                       __res |= resp[__off - 1] << ((32 - __shft) % 32); \
+               __res & __mask; \
+       })
+
+u32 msm_board_serial(void)
+{
+       struct mmc *mmc_dev;
+
+       mmc_dev = find_mmc_device(0);
+       if (!mmc_dev)
+               return 0;
+
+       return UNSTUFF_BITS(mmc_dev->cid, 16, 32);
+}