14 #include <linux/module.h>
25 #define ARIZONA_AIF_BCLK_CTRL 0x00
26 #define ARIZONA_AIF_TX_PIN_CTRL 0x01
27 #define ARIZONA_AIF_RX_PIN_CTRL 0x02
28 #define ARIZONA_AIF_RATE_CTRL 0x03
29 #define ARIZONA_AIF_FORMAT 0x04
30 #define ARIZONA_AIF_TX_BCLK_RATE 0x05
31 #define ARIZONA_AIF_RX_BCLK_RATE 0x06
32 #define ARIZONA_AIF_FRAME_CTRL_1 0x07
33 #define ARIZONA_AIF_FRAME_CTRL_2 0x08
34 #define ARIZONA_AIF_FRAME_CTRL_3 0x09
35 #define ARIZONA_AIF_FRAME_CTRL_4 0x0A
36 #define ARIZONA_AIF_FRAME_CTRL_5 0x0B
37 #define ARIZONA_AIF_FRAME_CTRL_6 0x0C
38 #define ARIZONA_AIF_FRAME_CTRL_7 0x0D
39 #define ARIZONA_AIF_FRAME_CTRL_8 0x0E
40 #define ARIZONA_AIF_FRAME_CTRL_9 0x0F
41 #define ARIZONA_AIF_FRAME_CTRL_10 0x10
42 #define ARIZONA_AIF_FRAME_CTRL_11 0x11
43 #define ARIZONA_AIF_FRAME_CTRL_12 0x12
44 #define ARIZONA_AIF_FRAME_CTRL_13 0x13
45 #define ARIZONA_AIF_FRAME_CTRL_14 0x14
46 #define ARIZONA_AIF_FRAME_CTRL_15 0x15
47 #define ARIZONA_AIF_FRAME_CTRL_16 0x16
48 #define ARIZONA_AIF_FRAME_CTRL_17 0x17
49 #define ARIZONA_AIF_FRAME_CTRL_18 0x18
50 #define ARIZONA_AIF_TX_ENABLES 0x19
51 #define ARIZONA_AIF_RX_ENABLES 0x1A
52 #define ARIZONA_AIF_FORCE_WRITE 0x1B
54 #define arizona_fll_err(_fll, fmt, ...) \
55 dev_err(_fll->arizona->dev, "FLL%d: " fmt, _fll->id, ##__VA_ARGS__)
56 #define arizona_fll_warn(_fll, fmt, ...) \
57 dev_warn(_fll->arizona->dev, "FLL%d: " fmt, _fll->id, ##__VA_ARGS__)
58 #define arizona_fll_dbg(_fll, fmt, ...) \
59 dev_err(_fll->arizona->dev, "FLL%d: " fmt, _fll->id, ##__VA_ARGS__)
61 #define arizona_aif_err(_dai, fmt, ...) \
62 dev_err(_dai->dev, "AIF%d: " fmt, _dai->id, ##__VA_ARGS__)
63 #define arizona_aif_warn(_dai, fmt, ...) \
64 dev_warn(_dai->dev, "AIF%d: " fmt, _dai->id, ##__VA_ARGS__)
65 #define arizona_aif_dbg(_dai, fmt, ...) \
66 dev_err(_dai->dev, "AIF%d: " fmt, _dai->id, ##__VA_ARGS__)
229 static const char *arizona_lhpf_mode_text[] = {
230 "Low-pass",
"High-pass"
235 arizona_lhpf_mode_text);
240 arizona_lhpf_mode_text);
245 arizona_lhpf_mode_text);
250 arizona_lhpf_mode_text);
268 static unsigned int arizona_sysclk_48k_rates[] = {
278 static unsigned int arizona_sysclk_44k1_rates[] = {
294 int ref,
div, refclk;
310 rates = arizona_sysclk_44k1_rates;
312 rates = arizona_sysclk_48k_rates;
314 for (ref = 0; ref <
ARRAY_SIZE(arizona_sysclk_48k_rates) &&
315 rates[ref] <= refclk; ref++) {
317 while (rates[ref] / div >= freq && div < 32) {
318 if (rates[ref] / div == freq) {
319 dev_dbg(codec->
dev,
"Configured %dHz OPCLK\n",
333 dev_err(codec->
dev,
"Unable to generate %dHz OPCLK\n", freq);
338 int source,
unsigned int freq,
int dir)
340 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
362 return arizona_set_opclk(codec, clk_id, freq);
392 dev_dbg(arizona->
dev,
"%s set to %uHz", name, freq);
423 fmt & SND_SOC_DAIFMT_FORMAT_MASK);
442 fmt & SND_SOC_DAIFMT_MASTER_MASK);
478 static const int arizona_48k_bclk_rates[] = {
500 static const unsigned int arizona_48k_rates[] = {
520 .list = arizona_48k_rates,
523 static const int arizona_44k1_bclk_rates[] = {
545 static const unsigned int arizona_44k1_rates[] = {
557 .list = arizona_44k1_rates,
560 static int arizona_sr_vals[] = {
591 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
594 unsigned int base_rate;
596 switch (dai_priv->
clk) {
607 if (base_rate % 8000)
608 constraint = &arizona_44k1_constraint;
610 constraint = &arizona_48k_constraint;
622 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
624 int base = dai->
driver->base;
630 rates = &arizona_44k1_bclk_rates[0];
632 rates = &arizona_48k_bclk_rates[0];
634 for (i = 0; i <
ARRAY_SIZE(arizona_44k1_bclk_rates); i++) {
641 if (i ==
ARRAY_SIZE(arizona_44k1_bclk_rates)) {
647 for (i = 0; i <
ARRAY_SIZE(arizona_sr_vals); i++)
660 rates[bclk], rates[bclk] / lrclk);
669 switch (dai_priv->
clk) {
703 static const char *arizona_dai_clk_str(
int clk_id)
711 return "Unknown clock";
715 static int arizona_dai_set_sysclk(
struct snd_soc_dai *dai,
716 int clk_id,
unsigned int freq,
int dir)
719 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
731 if (clk_id == dai_priv->
clk)
735 dev_err(codec->
dev,
"Can't change clock on active DAI %d\n",
740 memset(&routes, 0,
sizeof(routes));
741 routes[0].sink = dai->
driver->capture.stream_name;
742 routes[1].sink = dai->
driver->playback.stream_name;
744 routes[0].source = arizona_dai_clk_str(dai_priv->
clk);
745 routes[1].source = arizona_dai_clk_str(dai_priv->
clk);
748 routes[0].source = arizona_dai_clk_str(clk_id);
749 routes[1].source = arizona_dai_clk_str(clk_id);
756 .startup = arizona_startup,
757 .set_fmt = arizona_set_fmt,
758 .hw_params = arizona_hw_params,
759 .set_sysclk = arizona_dai_set_sysclk,
802 { 64000, 128000, 3, 8 },
803 { 128000, 256000, 2, 4 },
804 { 256000, 1000000, 1, 2 },
805 { 1000000, 13500000, 0, 1 },
817 static int arizona_calc_fll(
struct arizona_fll *fll,
830 while ((Fref / div) > 13500000) {
836 "Can't scale %dMHz in to <=13.5MHz\n",
847 while (Fout * div < 90000000 * fll->vco_mult) {
855 target = Fout * div / fll->
vco_mult;
861 for (i = 0; i <
ARRAY_SIZE(fll_fratios); i++) {
862 if (fll_fratios[i].
min <= Fref && Fref <= fll_fratios[i].
max) {
863 cfg->
fratio = fll_fratios[
i].fratio;
864 ratio = fll_fratios[
i].ratio;
874 cfg->
n = target / (ratio * Fref);
877 gcd_fll =
gcd(target, ratio * Fref);
880 cfg->
theta = (target - (cfg->
n * ratio * Fref))
882 cfg->
lambda = (ratio * Fref) / gcd_fll;
897 static void arizona_apply_fll(
struct arizona *
arizona,
unsigned int base,
919 unsigned int Fref,
unsigned int Fout)
948 if (source == syncsrc)
952 ret = arizona_calc_fll(fll, &sync, Fref, Fout);
956 ret = arizona_calc_fll(fll, &cfg, 32768, Fout);
960 ret = arizona_calc_fll(fll, &cfg, Fref, Fout);
966 ARIZONA_FLL1_ENA, 0);
971 pm_runtime_put_autosuspend(arizona->
dev);
981 arizona_apply_fll(arizona, fll->
base, &cfg, syncsrc);
982 arizona_apply_fll(arizona, fll->
base + 0x10, &sync, source);
984 arizona_apply_fll(arizona, fll->
base, &cfg, source);
988 pm_runtime_get(arizona->
dev);
994 ARIZONA_FLL1_ENA, ARIZONA_FLL1_ENA);
1014 init_completion(&fll->
lock);
1015 init_completion(&fll->
ok);
1023 "FLL%d clock OK",
id);
1026 arizona_fll_lock, fll);
1028 dev_err(arizona->
dev,
"Failed to get FLL%d lock IRQ: %d\n",
1033 arizona_fll_clock_ok, fll);
1035 dev_err(arizona->
dev,
"Failed to get FLL%d clock OK IRQ: %d\n",