From 3f75d27f2d1ee0011dfcc94ff2eaa8fb85820a82 Mon Sep 17 00:00:00 2001 From: Keyon Jie Date: Wed, 16 Dec 2020 15:35:28 +0800 Subject: [PATCH 1/5] ssp: mn: log more info for bclk/mclk configuration Log more useful information about bclk/mclk configuration to help track the blck/mclk status. Signed-off-by: Keyon Jie --- src/drivers/intel/ssp/mn.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/drivers/intel/ssp/mn.c b/src/drivers/intel/ssp/mn.c index 31e638c6aa09..0f3c8a30c51f 100644 --- a/src/drivers/intel/ssp/mn.c +++ b/src/drivers/intel/ssp/mn.c @@ -166,6 +166,8 @@ static inline int check_current_mclk_source(uint32_t mclk_rate) struct mn *mn = mn_get(); int ret = 0; + tr_info(&mn_tr, "MCLK %d, source = %d", mclk_rate, mn->mclk_source_clock); + if (ssp_freq[mn->mclk_source_clock].freq % mclk_rate != 0) { tr_err(&mn_tr, "MCLK %d, no valid configuration for already selected source = %d", mclk_rate, mn->mclk_source_clock); @@ -187,6 +189,7 @@ static inline int set_mclk_divider(uint16_t mclk_id, uint32_t mdivr_val) { uint32_t mdivr; + tr_info(&mn_tr, "mclk_id %d mdivr_val %d", mclk_id, mdivr_val); switch (mdivr_val) { case 1: mdivr = 0x00000fff; /* bypass divider for MCLK */ @@ -233,6 +236,9 @@ int mn_set_mclk(uint16_t mclk_id, uint32_t mclk_rate) mn->mclk_sources_used[mclk_id] = true; + tr_info(&mn_tr, "mclk_rate %d, mclk_source_clock %d", + mclk_rate, mn->mclk_source_clock); + ret = set_mclk_divider(mclk_id, ssp_freq[mn->mclk_source_clock].freq / mclk_rate); @@ -271,6 +277,7 @@ static bool find_mn(uint32_t freq, uint32_t bclk, uint32_t m, n, mn_div; uint32_t scr_div = freq / bclk; + tr_info(&mn_tr, "find_mn for freq %d bclk %d", freq, bclk); /* check if just SCR is enough */ if (freq % bclk == 0 && scr_div < (SSCR0_SCR_MASK >> 8) + 1) { *out_scr_div = scr_div; @@ -309,6 +316,7 @@ static bool find_mn(uint32_t freq, uint32_t bclk, *out_m = m; *out_n = n; + tr_info(&mn_tr, "find_mn m %d n %d", m, n); return true; } @@ -518,6 +526,9 @@ int mn_set_bclk(uint32_t dai_index, uint32_t bclk_rate, if (ret >= 0) { mn->bclk_sources[dai_index] = MN_BCLK_SOURCE_MN; + tr_info(&mn_tr, "bclk_rate %d, *out_scr_div %d, m %d, n %d", + bclk_rate, *out_scr_div, m, n); + mn_reg_write(MN_MDIV_M_VAL(dai_index), dai_index, m); mn_reg_write(MN_MDIV_N_VAL(dai_index), dai_index, n); } From b6d89995ec755a54e307ebc53de7829a2412afa9 Mon Sep 17 00:00:00 2001 From: Keyon Jie Date: Thu, 10 Dec 2020 15:34:58 +0800 Subject: [PATCH 2/5] ssp: mn: log useful info when error happen Log the incorrect mdivr_val value when error happen, which could help to identify what has happened. Signed-off-by: Keyon Jie --- src/drivers/intel/ssp/mn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/intel/ssp/mn.c b/src/drivers/intel/ssp/mn.c index 0f3c8a30c51f..1e18fbdf88ce 100644 --- a/src/drivers/intel/ssp/mn.c +++ b/src/drivers/intel/ssp/mn.c @@ -204,7 +204,7 @@ static inline int set_mclk_divider(uint16_t mclk_id, uint32_t mdivr_val) mdivr = 0x6; /* 1/8 */ break; default: - tr_err(&mn_tr, "invalid ssp_freq %d", ssp_freq[1].freq); + tr_err(&mn_tr, "invalid mdivr_val %d", mdivr_val); return -EINVAL; } From 3cb05ec3679f6643c258b2516d6b9a59518ed82a Mon Sep 17 00:00:00 2001 From: Keyon Jie Date: Fri, 4 Dec 2020 17:45:23 +0800 Subject: [PATCH 3/5] ssp: mn: return -EINVAL if bclk source not found Use standard errno in find_bclk_source(), return -EINVAL if no matched bclk source found. Signed-off-by: Keyon Jie --- src/drivers/intel/ssp/mn.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/drivers/intel/ssp/mn.c b/src/drivers/intel/ssp/mn.c index 1e18fbdf88ce..f30eed454de1 100644 --- a/src/drivers/intel/ssp/mn.c +++ b/src/drivers/intel/ssp/mn.c @@ -328,7 +328,7 @@ static bool find_mn(uint32_t freq, uint32_t bclk, * \param[out] scr_div SCR divisor. * \param[out] m M value of M/N divider. * \param[out] n N value of M/N divider. - * \return index of suitable clock if could find it, -1 otherwise. + * \return index of suitable clock if could find it, -EINVAL otherwise. */ static int find_bclk_source(uint32_t bclk, uint32_t *scr_div, uint32_t *m, uint32_t *n) @@ -348,7 +348,7 @@ static int find_bclk_source(uint32_t bclk, scr_div, m, n)) return i; - return -1; + return -EINVAL; } /** From e5d79d377226d733260d19794ca297e450516079 Mon Sep 17 00:00:00 2001 From: Keyon Jie Date: Thu, 19 Nov 2020 10:47:51 +0800 Subject: [PATCH 4/5] ssp: mn: search from index 0 to get a proper one mclk source The ssp.freq is arranged in ascending sequence, to get the smallest matched clock, we should search from index 0. We should not stop the searching if 'mclk < ssp.freq', continue the searching until we get a larger/proper one or fail if all the items are iterated. Signed-off-by: Keyon Jie --- src/drivers/intel/ssp/mn.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/drivers/intel/ssp/mn.c b/src/drivers/intel/ssp/mn.c index f30eed454de1..3fee67539637 100644 --- a/src/drivers/intel/ssp/mn.c +++ b/src/drivers/intel/ssp/mn.c @@ -121,12 +121,11 @@ static inline int setup_initial_mclk_source(uint32_t mclk_id, int ret = 0; /* searching the smallest possible mclk source */ - for (i = MAX_SSP_FREQ_INDEX; i >= 0; i--) { - if (mclk_rate > ssp_freq[i].freq) - break; - - if (ssp_freq[i].freq % mclk_rate == 0) + for (i = 0; i <= MAX_SSP_FREQ_INDEX; i++) { + if (ssp_freq[i].freq % mclk_rate == 0) { clk_index = i; + break; + } } if (clk_index < 0) { From 1dd3b7d93e740308b40c5785c1db10ae245dfcb2 Mon Sep 17 00:00:00 2001 From: Keyon Jie Date: Wed, 16 Dec 2020 16:47:58 +0800 Subject: [PATCH 5/5] ssp: mn: enable more N values in set_mclk_divider According to spec, we can configure more devidier ratios via register MDIVR, in 1/N the N could be 2, 3, 4, 5, 6, 7, 8. Here change to enable these possibilities. Signed-off-by: Keyon Jie --- src/drivers/intel/ssp/mn.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/drivers/intel/ssp/mn.c b/src/drivers/intel/ssp/mn.c index 3fee67539637..1bd72a5a2299 100644 --- a/src/drivers/intel/ssp/mn.c +++ b/src/drivers/intel/ssp/mn.c @@ -193,14 +193,8 @@ static inline int set_mclk_divider(uint16_t mclk_id, uint32_t mdivr_val) case 1: mdivr = 0x00000fff; /* bypass divider for MCLK */ break; - case 2: - mdivr = 0x0; /* 1/2 */ - break; - case 4: - mdivr = 0x2; /* 1/4 */ - break; - case 8: - mdivr = 0x6; /* 1/8 */ + case 2 ... 8: + mdivr = mdivr_val - 2; /* 1/n */ break; default: tr_err(&mn_tr, "invalid mdivr_val %d", mdivr_val);