Aneesh V | c0e8852 | 2011-07-21 09:10:12 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Linaro Limited |
| 3 | * Aneesh V <aneesh@ti.com> |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Aneesh V | c0e8852 | 2011-07-21 09:10:12 -0400 | [diff] [blame] | 6 | */ |
| 7 | #include <common.h> |
Nishanth Menon | 92adeb6 | 2014-03-28 11:00:04 -0500 | [diff] [blame] | 8 | #include <asm/arch/sys_proto.h> |
Aneesh V | c0e8852 | 2011-07-21 09:10:12 -0400 | [diff] [blame] | 9 | static void do_cancel_out(u32 *num, u32 *den, u32 factor) |
| 10 | { |
| 11 | while (1) { |
| 12 | if (((*num)/factor*factor == (*num)) && |
| 13 | ((*den)/factor*factor == (*den))) { |
| 14 | (*num) /= factor; |
| 15 | (*den) /= factor; |
| 16 | } else |
| 17 | break; |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | /* |
| 22 | * Cancel out the denominator and numerator of a fraction |
| 23 | * to get smaller numerator and denominator. |
| 24 | */ |
| 25 | void cancel_out(u32 *num, u32 *den, u32 den_limit) |
| 26 | { |
| 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) { |
| 35 | *num /= 2; |
| 36 | /* |
| 37 | * Round up the denominator so that the final fraction |
| 38 | * (num/den) is always <= the desired value |
| 39 | */ |
| 40 | *den = (*den + 1) / 2; |
| 41 | } |
| 42 | } |
Nishanth Menon | 92adeb6 | 2014-03-28 11:00:04 -0500 | [diff] [blame] | 43 | |
| 44 | void __weak usb_fake_mac_from_die_id(u32 *id) |
| 45 | { |
| 46 | uint8_t device_mac[6]; |
| 47 | |
| 48 | if (!getenv("usbethaddr")) { |
| 49 | /* |
| 50 | * create a fake MAC address from the processor ID code. |
| 51 | * first byte is 0x02 to signify locally administered. |
| 52 | */ |
| 53 | device_mac[0] = 0x02; |
| 54 | device_mac[1] = id[3] & 0xff; |
| 55 | device_mac[2] = id[2] & 0xff; |
| 56 | device_mac[3] = id[1] & 0xff; |
| 57 | device_mac[4] = id[0] & 0xff; |
| 58 | device_mac[5] = (id[0] >> 8) & 0xff; |
| 59 | |
| 60 | eth_setenv_enetaddr("usbethaddr", device_mac); |
| 61 | } |
| 62 | } |