summaryrefslogtreecommitdiff
path: root/arch/arm/mach-omap2/utils.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2016-11-08 02:34:54 (GMT)
committerTom Rini <trini@konsulko.com>2016-11-21 19:07:29 (GMT)
commit983e37007da506e8145f9b3a9e1dce5c11116fb0 (patch)
treec1d5449e1c56e17f22bb4f75b6f11336abca41a4 /arch/arm/mach-omap2/utils.c
parent272686eb7576c02df4616bcf893fde993e7ba57e (diff)
downloadu-boot-fsl-qoriq-983e37007da506e8145f9b3a9e1dce5c11116fb0.tar.xz
arm: Introduce arch/arm/mach-omap2 for OMAP2 derivative platforms
This moves what was in arch/arm/cpu/armv7/omap-common in to arch/arm/mach-omap2 and moves arch/arm/cpu/armv7/{am33xx,omap3,omap4,omap5} in to arch/arm/mach-omap2 as subdirectories. All refernces to the former locations are updated to the current locations. For the logic to decide what our outputs are, consolidate the tests into a single config.mk rather than including 4. Signed-off-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'arch/arm/mach-omap2/utils.c')
-rw-r--r--arch/arm/mach-omap2/utils.c113
1 files changed, 113 insertions, 0 deletions
diff --git a/arch/arm/mach-omap2/utils.c b/arch/arm/mach-omap2/utils.c
new file mode 100644
index 0000000..2d03ebf
--- /dev/null
+++ b/arch/arm/mach-omap2/utils.c
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2011 Linaro Limited
+ * Aneesh V <aneesh@ti.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+#include <common.h>
+#include <asm/arch/sys_proto.h>
+static void do_cancel_out(u32 *num, u32 *den, u32 factor)
+{
+ while (1) {
+ if (((*num)/factor*factor == (*num)) &&
+ ((*den)/factor*factor == (*den))) {
+ (*num) /= factor;
+ (*den) /= factor;
+ } else
+ break;
+ }
+}
+
+/*
+ * Cancel out the denominator and numerator of a fraction
+ * to get smaller numerator and denominator.
+ */
+void cancel_out(u32 *num, u32 *den, u32 den_limit)
+{
+ do_cancel_out(num, den, 2);
+ do_cancel_out(num, den, 3);
+ do_cancel_out(num, den, 5);
+ do_cancel_out(num, den, 7);
+ do_cancel_out(num, den, 11);
+ do_cancel_out(num, den, 13);
+ do_cancel_out(num, den, 17);
+ while ((*den) > den_limit) {
+ *num /= 2;
+ /*
+ * Round up the denominator so that the final fraction
+ * (num/den) is always <= the desired value
+ */
+ *den = (*den + 1) / 2;
+ }
+}
+
+__weak void omap_die_id(unsigned int *die_id)
+{
+ die_id[0] = die_id[1] = die_id[2] = die_id[3] = 0;
+}
+
+void omap_die_id_serial(void)
+{
+ unsigned int die_id[4] = { 0 };
+ char serial_string[17] = { 0 };
+
+ omap_die_id((unsigned int *)&die_id);
+
+ if (!getenv("serial#")) {
+ snprintf(serial_string, sizeof(serial_string),
+ "%08x%08x", die_id[0], die_id[3]);
+
+ setenv("serial#", serial_string);
+ }
+}
+
+void omap_die_id_get_board_serial(struct tag_serialnr *serialnr)
+{
+ char *serial_string;
+ unsigned long long serial;
+
+ serial_string = getenv("serial#");
+
+ if (serial_string) {
+ serial = simple_strtoull(serial_string, NULL, 16);
+
+ serialnr->high = (unsigned int) (serial >> 32);
+ serialnr->low = (unsigned int) (serial & 0xffffffff);
+ } else {
+ serialnr->high = 0;
+ serialnr->low = 0;
+ }
+}
+
+void omap_die_id_usbethaddr(void)
+{
+ unsigned int die_id[4] = { 0 };
+ unsigned char mac[6] = { 0 };
+
+ omap_die_id((unsigned int *)&die_id);
+
+ if (!getenv("usbethaddr")) {
+ /*
+ * Create a fake MAC address from the processor ID code.
+ * First byte is 0x02 to signify locally administered.
+ */
+ mac[0] = 0x02;
+ mac[1] = die_id[3] & 0xff;
+ mac[2] = die_id[2] & 0xff;
+ mac[3] = die_id[1] & 0xff;
+ mac[4] = die_id[0] & 0xff;
+ mac[5] = (die_id[0] >> 8) & 0xff;
+
+ eth_setenv_enetaddr("usbethaddr", mac);
+ }
+}
+
+void omap_die_id_display(void)
+{
+ unsigned int die_id[4] = { 0 };
+
+ omap_die_id(die_id);
+
+ printf("OMAP die ID: %08x%08x%08x%08x\n", die_id[3], die_id[2],
+ die_id[1], die_id[0]);
+}