1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Shared helper functions for devices from the ADAU family
5 * Copyright 2011-2016 Analog Devices Inc.
6 * Author: Lars-Peter Clausen <lars@metafoo.de>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
13 #include "adau-utils.h"
15 int adau_calc_pll_cfg(unsigned int freq_in
, unsigned int freq_out
,
18 unsigned int r
, n
, m
, i
, j
;
27 if (freq_out
% freq_in
!= 0) {
28 div
= DIV_ROUND_UP(freq_in
, 13500000);
30 r
= freq_out
/ freq_in
;
31 i
= freq_out
% freq_in
;
37 r
= freq_out
/ freq_in
;
42 if (n
> 0xffff || m
> 0xffff || div
> 3 || r
> 8 || r
< 2)
50 regs
[4] = (r
<< 3) | (div
<< 1);
52 regs
[4] |= 1; /* Fractional mode */
56 EXPORT_SYMBOL_GPL(adau_calc_pll_cfg
);
58 MODULE_DESCRIPTION("ASoC ADAU audio CODECs shared helper functions");
59 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
60 MODULE_LICENSE("GPL v2");