mirror of
https://github.com/u-boot/u-boot.git
synced 2025-05-08 10:39:08 +00:00
lib: rational: copy the rational fraction lib routines from Linux
Copy the best rational approximation calculation routines from Linux. Typical usecase for these routines is to calculate the M/N divider values for PLLs to reach a specific clock rate. This is based on linux kernel commit: "lib/math/rational.c: fix possible incorrect result from rational fractions helper" (sha1: 323dd2c3ed0641f49e89b4e420f9eef5d3d5a881) Signed-off-by: Tero Kristo <t-kristo@ti.com> Reviewed-by: Tom Rini <trini@konsulko.com> Signed-off-by: Tero Kristo <kristo@kernel.org>
This commit is contained in:
parent
08ea87a6de
commit
7d0f3fbb93
4 changed files with 128 additions and 0 deletions
20
include/linux/rational.h
Normal file
20
include/linux/rational.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* rational fractions
|
||||
*
|
||||
* Copyright (C) 2009 emlix GmbH, Oskar Schirmer <oskar@scara.com>
|
||||
*
|
||||
* helper functions when coping with rational numbers,
|
||||
* e.g. when calculating optimum numerator/denominator pairs for
|
||||
* pll configuration taking into account restricted register size
|
||||
*/
|
||||
|
||||
#ifndef _LINUX_RATIONAL_H
|
||||
#define _LINUX_RATIONAL_H
|
||||
|
||||
void rational_best_approximation(
|
||||
unsigned long given_numerator, unsigned long given_denominator,
|
||||
unsigned long max_numerator, unsigned long max_denominator,
|
||||
unsigned long *best_numerator, unsigned long *best_denominator);
|
||||
|
||||
#endif /* _LINUX_RATIONAL_H */
|
Loading…
Add table
Add a link
Reference in a new issue