Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Haavard Skinnemoen | 0768b7a | 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 | 0768b7a | 2008-08-18 13:41:27 +0200 | [diff] [blame] | 5 | */ |
| 6 | #include <common.h> |
| 7 | |
Ed Swarthout | 55f7934 | 2011-03-05 10:28:17 -0600 | [diff] [blame] | 8 | char *strmhz (char *buf, unsigned long hz) |
Haavard Skinnemoen | 0768b7a | 2008-08-18 13:41:27 +0200 | [diff] [blame] | 9 | { |
| 10 | long l, n; |
| 11 | long m; |
| 12 | |
Masahiro Yamada | 4515992 | 2014-11-07 03:03:26 +0900 | [diff] [blame] | 13 | n = DIV_ROUND_CLOSEST(hz, 1000) / 1000L; |
Haavard Skinnemoen | 0768b7a | 2008-08-18 13:41:27 +0200 | [diff] [blame] | 14 | l = sprintf (buf, "%ld", n); |
Wolfgang Denk | d50c7d4 | 2008-10-19 02:35:48 +0200 | [diff] [blame] | 15 | |
| 16 | hz -= n * 1000000L; |
Masahiro Yamada | 4515992 | 2014-11-07 03:03:26 +0900 | [diff] [blame] | 17 | m = DIV_ROUND_CLOSEST(hz, 1000L); |
Haavard Skinnemoen | 0768b7a | 2008-08-18 13:41:27 +0200 | [diff] [blame] | 18 | if (m != 0) |
| 19 | sprintf (buf + l, ".%03ld", m); |
| 20 | return (buf); |
| 21 | } |