blob: 66afe91ab99d72ca0cf81a4a69c6b75f8f1cfef9 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Haavard Skinnemoen0768b7a2008-08-18 13:41:27 +02002/*
3 * (C) Copyright 2002-2006
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Haavard Skinnemoen0768b7a2008-08-18 13:41:27 +02005 */
6#include <common.h>
7
Ed Swarthout55f79342011-03-05 10:28:17 -06008char *strmhz (char *buf, unsigned long hz)
Haavard Skinnemoen0768b7a2008-08-18 13:41:27 +02009{
10 long l, n;
11 long m;
12
Masahiro Yamada45159922014-11-07 03:03:26 +090013 n = DIV_ROUND_CLOSEST(hz, 1000) / 1000L;
Haavard Skinnemoen0768b7a2008-08-18 13:41:27 +020014 l = sprintf (buf, "%ld", n);
Wolfgang Denkd50c7d42008-10-19 02:35:48 +020015
16 hz -= n * 1000000L;
Masahiro Yamada45159922014-11-07 03:03:26 +090017 m = DIV_ROUND_CLOSEST(hz, 1000L);
Haavard Skinnemoen0768b7a2008-08-18 13:41:27 +020018 if (m != 0)
19 sprintf (buf + l, ".%03ld", m);
20 return (buf);
21}