sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / sound / soc / codecs / adau-utils.c
blob19d6a6f41b12797ff8cd768f68901d6e22d1a0ce
1 /*
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.
8 */
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,
17 uint8_t regs[5])
19 unsigned int r, n, m, i, j;
20 unsigned int div;
22 if (!freq_out) {
23 r = 0;
24 n = 0;
25 m = 0;
26 div = 0;
27 } else {
28 if (freq_out % freq_in != 0) {
29 div = DIV_ROUND_UP(freq_in, 13500000);
30 freq_in /= div;
31 r = freq_out / freq_in;
32 i = freq_out % freq_in;
33 j = gcd(i, freq_in);
34 n = i / j;
35 m = freq_in / j;
36 div--;
37 } else {
38 r = freq_out / freq_in;
39 n = 0;
40 m = 0;
41 div = 0;
43 if (n > 0xffff || m > 0xffff || div > 3 || r > 8 || r < 2)
44 return -EINVAL;
47 regs[0] = m >> 8;
48 regs[1] = m & 0xff;
49 regs[2] = n >> 8;
50 regs[3] = n & 0xff;
51 regs[4] = (r << 3) | (div << 1);
52 if (m != 0)
53 regs[4] |= 1; /* Fractional mode */
55 return 0;
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");