diff options
Diffstat (limited to 'sound/soc/codecs/adau1373.c')
-rw-r--r-- | sound/soc/codecs/adau1373.c | 38 |
1 files changed, 10 insertions, 28 deletions
diff --git a/sound/soc/codecs/adau1373.c b/sound/soc/codecs/adau1373.c index fe1353a797b9..1556b360fa15 100644 --- a/sound/soc/codecs/adau1373.c +++ b/sound/soc/codecs/adau1373.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <sound/adau1373.h> | 23 | #include <sound/adau1373.h> |
24 | 24 | ||
25 | #include "adau1373.h" | 25 | #include "adau1373.h" |
26 | #include "adau-utils.h" | ||
26 | 27 | ||
27 | struct adau1373_dai { | 28 | struct adau1373_dai { |
28 | unsigned int clk_src; | 29 | unsigned int clk_src; |
@@ -1254,7 +1255,8 @@ static int adau1373_set_pll(struct snd_soc_codec *codec, int pll_id, | |||
1254 | { | 1255 | { |
1255 | struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec); | 1256 | struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec); |
1256 | unsigned int dpll_div = 0; | 1257 | unsigned int dpll_div = 0; |
1257 | unsigned int x, r, n, m, i, j, mode; | 1258 | uint8_t pll_regs[5]; |
1259 | int ret; | ||
1258 | 1260 | ||
1259 | switch (pll_id) { | 1261 | switch (pll_id) { |
1260 | case ADAU1373_PLL1: | 1262 | case ADAU1373_PLL1: |
@@ -1295,27 +1297,8 @@ static int adau1373_set_pll(struct snd_soc_codec *codec, int pll_id, | |||
1295 | dpll_div++; | 1297 | dpll_div++; |
1296 | } | 1298 | } |
1297 | 1299 | ||
1298 | if (freq_out % freq_in != 0) { | 1300 | ret = adau_calc_pll_cfg(freq_in, freq_out, pll_regs); |
1299 | /* fout = fin * (r + (n/m)) / x */ | 1301 | if (ret) |
1300 | x = DIV_ROUND_UP(freq_in, 13500000); | ||
1301 | freq_in /= x; | ||
1302 | r = freq_out / freq_in; | ||
1303 | i = freq_out % freq_in; | ||
1304 | j = gcd(i, freq_in); | ||
1305 | n = i / j; | ||
1306 | m = freq_in / j; | ||
1307 | x--; | ||
1308 | mode = 1; | ||
1309 | } else { | ||
1310 | /* fout = fin / r */ | ||
1311 | r = freq_out / freq_in; | ||
1312 | n = 0; | ||
1313 | m = 0; | ||
1314 | x = 0; | ||
1315 | mode = 0; | ||
1316 | } | ||
1317 | |||
1318 | if (r < 2 || r > 8 || x > 3 || m > 0xffff || n > 0xffff) | ||
1319 | return -EINVAL; | 1302 | return -EINVAL; |
1320 | 1303 | ||
1321 | if (dpll_div) { | 1304 | if (dpll_div) { |
@@ -1330,12 +1313,11 @@ static int adau1373_set_pll(struct snd_soc_codec *codec, int pll_id, | |||
1330 | 1313 | ||
1331 | regmap_write(adau1373->regmap, ADAU1373_DPLL_CTRL(pll_id), | 1314 | regmap_write(adau1373->regmap, ADAU1373_DPLL_CTRL(pll_id), |
1332 | (source << 4) | dpll_div); | 1315 | (source << 4) | dpll_div); |
1333 | regmap_write(adau1373->regmap, ADAU1373_PLL_CTRL1(pll_id), (m >> 8) & 0xff); | 1316 | regmap_write(adau1373->regmap, ADAU1373_PLL_CTRL1(pll_id), pll_regs[0]); |
1334 | regmap_write(adau1373->regmap, ADAU1373_PLL_CTRL2(pll_id), m & 0xff); | 1317 | regmap_write(adau1373->regmap, ADAU1373_PLL_CTRL2(pll_id), pll_regs[1]); |
1335 | regmap_write(adau1373->regmap, ADAU1373_PLL_CTRL3(pll_id), (n >> 8) & 0xff); | 1318 | regmap_write(adau1373->regmap, ADAU1373_PLL_CTRL3(pll_id), pll_regs[2]); |
1336 | regmap_write(adau1373->regmap, ADAU1373_PLL_CTRL4(pll_id), n & 0xff); | 1319 | regmap_write(adau1373->regmap, ADAU1373_PLL_CTRL4(pll_id), pll_regs[3]); |
1337 | regmap_write(adau1373->regmap, ADAU1373_PLL_CTRL5(pll_id), | 1320 | regmap_write(adau1373->regmap, ADAU1373_PLL_CTRL5(pll_id), pll_regs[4]); |
1338 | (r << 3) | (x << 1) | mode); | ||
1339 | 1321 | ||
1340 | /* Set sysclk to pll_rate / 4 */ | 1322 | /* Set sysclk to pll_rate / 4 */ |
1341 | regmap_update_bits(adau1373->regmap, ADAU1373_CLK_SRC_DIV(pll_id), 0x3f, 0x09); | 1323 | regmap_update_bits(adau1373->regmap, ADAU1373_CLK_SRC_DIV(pll_id), 0x3f, 0x09); |