Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Haavard Skinnemoen | b644d6b | 2008-08-18 13:41:27 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2002-2006 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Haavard Skinnemoen | b644d6b | 2008-08-18 13:41:27 +0200 | [diff] [blame] | 5 | */ |
| 6 | #include <common.h> |
| 7 | |
Ed Swarthout | d065acb | 2011-03-05 10:28:17 -0600 | [diff] [blame] | 8 | char *strmhz (char *buf, unsigned long hz) |
Haavard Skinnemoen | b644d6b | 2008-08-18 13:41:27 +0200 | [diff] [blame] | 9 | { |
| 10 | long l, n; |
| 11 | long m; |
| 12 | |
Masahiro Yamada | eff8e68 | 2014-11-07 03:03:26 +0900 | [diff] [blame] | 13 | n = DIV_ROUND_CLOSEST(hz, 1000) / 1000L; |
Haavard Skinnemoen | b644d6b | 2008-08-18 13:41:27 +0200 | [diff] [blame] | 14 | l = sprintf (buf, "%ld", n); |
Wolfgang Denk | 709e85d | 2008-10-19 02:35:48 +0200 | [diff] [blame] | 15 | |
| 16 | hz -= n * 1000000L; |
Masahiro Yamada | eff8e68 | 2014-11-07 03:03:26 +0900 | [diff] [blame] | 17 | m = DIV_ROUND_CLOSEST(hz, 1000L); |
Haavard Skinnemoen | b644d6b | 2008-08-18 13:41:27 +0200 | [diff] [blame] | 18 | if (m != 0) |
| 19 | sprintf (buf + l, ".%03ld", m); |
| 20 | return (buf); |
| 21 | } |