1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
10 #define div_mask(w) ((1 << (w)) - 1)
12 int div_frac_get(unsigned long rate
, unsigned parent_rate
, u8 width
,
13 u8 frac_width
, u8 flags
)
15 u64 divider_ux1
= parent_rate
;
21 mul
= 1 << frac_width
;
23 if (!(flags
& TEGRA_DIVIDER_INT
))
26 if (flags
& TEGRA_DIVIDER_ROUND_UP
)
27 divider_ux1
+= rate
- 1;
29 do_div(divider_ux1
, rate
);
31 if (flags
& TEGRA_DIVIDER_INT
)
34 if (divider_ux1
< mul
)
39 if (divider_ux1
> div_mask(width
))
40 return div_mask(width
);