2011-07-21 13:10:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Linaro Limited
|
|
|
|
* Aneesh V <aneesh@ti.com>
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2011-07-21 13:10:12 +00:00
|
|
|
*/
|
|
|
|
#include <common.h>
|
2017-05-17 14:23:00 +00:00
|
|
|
#include <asm/setup.h>
|
2014-03-28 16:00:04 +00:00
|
|
|
#include <asm/arch/sys_proto.h>
|
2011-07-21 13:10:12 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2014-03-28 16:00:04 +00:00
|
|
|
|
2015-08-27 17:37:08 +00:00
|
|
|
__weak void omap_die_id(unsigned int *die_id)
|
|
|
|
{
|
|
|
|
die_id[0] = die_id[1] = die_id[2] = die_id[3] = 0;
|
|
|
|
}
|
|
|
|
|
2015-08-27 17:37:12 +00:00
|
|
|
void omap_die_id_serial(void)
|
2014-03-28 16:00:04 +00:00
|
|
|
{
|
2015-08-27 17:37:12 +00:00
|
|
|
unsigned int die_id[4] = { 0 };
|
|
|
|
char serial_string[17] = { 0 };
|
2014-03-28 16:00:04 +00:00
|
|
|
|
2015-08-27 17:37:12 +00:00
|
|
|
omap_die_id((unsigned int *)&die_id);
|
2014-03-28 16:00:04 +00:00
|
|
|
|
2015-08-27 17:37:12 +00:00
|
|
|
if (!getenv("serial#")) {
|
|
|
|
snprintf(serial_string, sizeof(serial_string),
|
|
|
|
"%08x%08x", die_id[0], die_id[3]);
|
|
|
|
|
|
|
|
setenv("serial#", serial_string);
|
2014-03-28 16:00:04 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-24 22:34:51 +00:00
|
|
|
|
2015-08-27 17:37:14 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-27 17:37:12 +00:00
|
|
|
void omap_die_id_usbethaddr(void)
|
2015-03-24 22:34:51 +00:00
|
|
|
{
|
2015-08-27 17:37:12 +00:00
|
|
|
unsigned int die_id[4] = { 0 };
|
|
|
|
unsigned char mac[6] = { 0 };
|
2015-03-24 22:34:51 +00:00
|
|
|
|
2015-08-27 17:37:12 +00:00
|
|
|
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);
|
2015-03-24 22:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-27 17:37:13 +00:00
|
|
|
|
|
|
|
void omap_die_id_display(void)
|
|
|
|
{
|
|
|
|
unsigned int die_id[4] = { 0 };
|
|
|
|
|
|
|
|
omap_die_id(die_id);
|
|
|
|
|
2016-06-02 09:43:16 +00:00
|
|
|
printf("OMAP die ID: %08x%08x%08x%08x\n", die_id[3], die_id[2],
|
|
|
|
die_id[1], die_id[0]);
|
2015-08-27 17:37:13 +00:00
|
|
|
}
|