2 * Shared helper functions for devices from the ADAU family
4 * Copyright 2011-2016 Analog Devices Inc.
5 * Author: Lars-Peter Clausen <lars@metafoo.de>
7 * Licensed under the GPL-2 or later.
10 #include <linux/gcd.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
14 #include "adau-utils.h"
16 int adau_calc_pll_cfg(unsigned int freq_in
, unsigned int freq_out
,
19 unsigned int r
, n
, m
, i
, j
;
28 if (freq_out
% freq_in
!= 0) {
29 div
= DIV_ROUND_UP(freq_in
, 13500000);
31 r
= freq_out
/ freq_in
;
32 i
= freq_out
% freq_in
;
38 r
= freq_out
/ freq_in
;
43 if (n
> 0xffff || m
> 0xffff || div
> 3 || r
> 8 || r
< 2)
51 regs
[4] = (r
<< 3) | (div
<< 1);
53 regs
[4] |= 1; /* Fractional mode */
57 EXPORT_SYMBOL_GPL(adau_calc_pll_cfg
);
59 MODULE_DESCRIPTION("ASoC ADAU audio CODECs shared helper functions");
60 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
61 MODULE_LICENSE("GPL v2");