2 * Copyright 2011 Linaro Limited
3 * Aneesh V <aneesh@ti.com>
5 * SPDX-License-Identifier: GPL-2.0+
8 #include <asm/arch/sys_proto.h>
9 static void do_cancel_out(u32 *num, u32 *den, u32 factor)
12 if (((*num)/factor*factor == (*num)) &&
13 ((*den)/factor*factor == (*den))) {
22 * Cancel out the denominator and numerator of a fraction
23 * to get smaller numerator and denominator.
25 void cancel_out(u32 *num, u32 *den, u32 den_limit)
27 do_cancel_out(num, den, 2);
28 do_cancel_out(num, den, 3);
29 do_cancel_out(num, den, 5);
30 do_cancel_out(num, den, 7);
31 do_cancel_out(num, den, 11);
32 do_cancel_out(num, den, 13);
33 do_cancel_out(num, den, 17);
34 while ((*den) > den_limit) {
37 * Round up the denominator so that the final fraction
38 * (num/den) is always <= the desired value
40 *den = (*den + 1) / 2;
44 __weak void omap_die_id(unsigned int *die_id)
46 die_id[0] = die_id[1] = die_id[2] = die_id[3] = 0;
49 void omap_die_id_serial(void)
51 unsigned int die_id[4] = { 0 };
52 char serial_string[17] = { 0 };
54 omap_die_id((unsigned int *)&die_id);
56 if (!getenv("serial#")) {
57 snprintf(serial_string, sizeof(serial_string),
58 "%08x%08x", die_id[0], die_id[3]);
60 setenv("serial#", serial_string);
64 void omap_die_id_get_board_serial(struct tag_serialnr *serialnr)
67 unsigned long long serial;
69 serial_string = getenv("serial#");
72 serial = simple_strtoull(serial_string, NULL, 16);
74 serialnr->high = (unsigned int) (serial >> 32);
75 serialnr->low = (unsigned int) (serial & 0xffffffff);
82 void omap_die_id_usbethaddr(void)
84 unsigned int die_id[4] = { 0 };
85 unsigned char mac[6] = { 0 };
87 omap_die_id((unsigned int *)&die_id);
89 if (!getenv("usbethaddr")) {
91 * Create a fake MAC address from the processor ID code.
92 * First byte is 0x02 to signify locally administered.
95 mac[1] = die_id[3] & 0xff;
96 mac[2] = die_id[2] & 0xff;
97 mac[3] = die_id[1] & 0xff;
98 mac[4] = die_id[0] & 0xff;
99 mac[5] = (die_id[0] >> 8) & 0xff;
101 eth_setenv_enetaddr("usbethaddr", mac);
105 void omap_die_id_display(void)
107 unsigned int die_id[4] = { 0 };
111 printf("OMAP die ID: %08x%08x%08x%08x", die_id[0], die_id[1], die_id[2],