Repository navigation
SSP bclk refining series #3622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SSP bclk refining series #3622
Changes from all commits
37e9109
9d535b0
e83b28d
6e5633a
b805052
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -343,6 +343,22 @@ static int find_bclk_source(uint32_t bclk, | |
| return -1; | ||
| } | ||
|
|
||
| /** | ||
| * \brief Finds index of SSP clock with the given clock source encoded index. | ||
| * \return the index in ssp_freq if could find it, -EINVAL otherwise. | ||
| */ | ||
| static int find_clk_ssp_index(uint32_t src_enc) | ||
| { | ||
| int i; | ||
|
|
||
| /* searching for the encode value matched bclk source */ | ||
| for (i = 0; i <= MAX_SSP_FREQ_INDEX; i++) | ||
| if (ssp_freq_sources[i] == src_enc) | ||
| return i; | ||
|
|
||
| return -EINVAL; | ||
| } | ||
|
|
||
| /** | ||
| * \brief Checks if given clock is used as source for any BCLK. | ||
| * \param[in] clk_src Bit clock source. | ||
|
|
@@ -405,6 +421,35 @@ static inline int setup_initial_bclk_mn_source(uint32_t bclk, uint32_t *scr_div, | |
| return 0; | ||
| } | ||
|
|
||
| /** | ||
| * \brief Reset M/N source clock for BCLK. | ||
| * If no port is using bclk, reset to use SSP_CLOCK_XTAL_OSCILLATOR | ||
| * as the default clock source. | ||
| */ | ||
| static inline void reset_bclk_mn_source(void) | ||
| { | ||
| struct mn *mn = mn_get(); | ||
| uint32_t mdivc; | ||
| int clk_index = find_clk_ssp_index(SSP_CLOCK_XTAL_OSCILLATOR); | ||
|
lgirdwood marked this conversation as resolved.
Resolved
|
||
|
|
||
| if (clk_index < 0) { | ||
| tr_err(&mn_tr, "BCLK reset failed, no SSP_CLOCK_XTAL_OSCILLATOR source!"); | ||
| return; | ||
| } | ||
|
|
||
| mdivc = mn_reg_read(MN_MDIVCTRL, 0); | ||
|
|
||
| /* reset to use XTAL Oscillator */ | ||
| mdivc &= ~MNDSS(MN_SOURCE_CLKS_MASK); | ||
| mdivc |= MNDSS(SSP_CLOCK_XTAL_OSCILLATOR); | ||
|
|
||
| mn_reg_write(MN_MDIVCTRL, 0, mdivc); | ||
|
|
||
| mn->bclk_source_mn_clock = clk_index; | ||
|
|
||
| platform_shared_commit(mn, sizeof(*mn)); | ||
| } | ||
|
|
||
| /** | ||
| * \brief Finds valid M/(N * SCR) values for source clock that is already locked | ||
| * because other ports use it. | ||
|
|
@@ -533,10 +578,16 @@ int mn_set_bclk(uint32_t dai_index, uint32_t bclk_rate, | |
| void mn_release_bclk(uint32_t dai_index) | ||
| { | ||
| struct mn *mn = mn_get(); | ||
| bool mn_in_use; | ||
|
|
||
| spin_lock(&mn->lock); | ||
| mn->bclk_sources[dai_index] = MN_BCLK_SOURCE_NONE; | ||
| platform_shared_commit(mn, sizeof(*mn)); | ||
|
|
||
| mn_in_use = is_bclk_source_in_use(MN_BCLK_SOURCE_MN); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's incorrect. There are platforms where we can have different sources for BCLK and MCLK, but other where there's a single source.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @plbossart but do we use the MN for MCLK too?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. M/N comes after selecting a source, and yes it's possible to apply it there as well IIRC.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @plbossart we have MNDSS and MCDSS for all cAVS, at least I am seeing them in spec for APL/CNL/TGL. This driver is for cAVS platforms only, so no need to take care BYT/BDW ones here. @ranj063 yes, please see the definition and block diagram for MNDSS(for BCLK) and MCDSS(for MCLK). We have M/N for BCLK, but only divider (similar to N) for MCLK, which means we can only set the MCLK frequency as 1/N of the MCLK source frequency.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @keyonjie I am 100% positive that there was a change in the clock tree somewhere between APL and TGL. In fact here it is: see commit 0a97c1a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @plbossart Yes, M/N can not be bypassed on cAVS2.x but we can set both M and N to 1. |
||
| /* release the M/N clock source if not used */ | ||
| if (!mn_in_use) | ||
| reset_bclk_mn_source(); | ||
| spin_unlock(&mn->lock); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,7 +140,6 @@ static int ssp_set_config(struct dai *dai, | |
| uint32_t ssrsa; | ||
| uint32_t ssto; | ||
| uint32_t ssioc; | ||
| uint32_t mdiv; | ||
| uint32_t bdiv; | ||
| uint32_t data_size; | ||
| uint32_t frame_end_padding; | ||
|
|
@@ -157,7 +156,6 @@ static int ssp_set_config(struct dai *dai, | |
| bool inverted_frame = false; | ||
| bool cfs = false; | ||
| bool start_delay = false; | ||
| bool need_ecs = false; | ||
|
|
||
| int ret = 0; | ||
|
|
||
|
|
@@ -332,42 +330,6 @@ static int ssp_set_config(struct dai *dai, | |
| goto out; | ||
| } | ||
|
|
||
| #if CONFIG_INTEL_MN | ||
| /* BCLK config */ | ||
| ret = mn_set_bclk(config->dai_index, config->ssp.bclk_rate, | ||
| &mdiv, &need_ecs); | ||
| if (ret < 0) { | ||
| dai_err(dai, "invalid bclk_rate = %d for dai_index = %d", | ||
| config->ssp.bclk_rate, config->dai_index); | ||
| goto out; | ||
| } | ||
| #else | ||
| if (ssp_freq[SSP_DEFAULT_IDX].freq % config->ssp.bclk_rate != 0) { | ||
| dai_err(dai, "invalid bclk_rate = %d for dai_index = %d", | ||
| config->ssp.bclk_rate, config->dai_index); | ||
| goto out; | ||
| } | ||
|
|
||
| mdiv = ssp_freq[SSP_DEFAULT_IDX].freq / config->ssp.bclk_rate; | ||
| #endif | ||
|
|
||
| if (need_ecs) | ||
| sscr0 |= SSCR0_ECS; | ||
|
|
||
| /* clock divisor is SCR + 1 */ | ||
| mdiv -= 1; | ||
|
|
||
| /* divisor must be within SCR range */ | ||
| if (mdiv > (SSCR0_SCR_MASK >> 8)) { | ||
| dai_err(dai, "ssp_set_config(): divisor %d is not within SCR range", | ||
| mdiv); | ||
| ret = -EINVAL; | ||
| goto out; | ||
| } | ||
|
|
||
| /* set the SCR divisor */ | ||
| sscr0 |= SSCR0_SCR(mdiv); | ||
|
|
||
| /* calc frame width based on BCLK and rate - must be divisable */ | ||
| if (config->ssp.bclk_rate % config->ssp.fsync_rate) { | ||
| dai_err(dai, "ssp_set_config(): BCLK %d is not divisable by rate %d", | ||
|
|
@@ -659,6 +621,93 @@ static int ssp_set_config(struct dai *dai, | |
| return ret; | ||
| } | ||
|
|
||
| /* | ||
| * Portion of the SSP configuration should be applied just before the | ||
| * SSP dai is activated, for either power saving or params runtime | ||
| * configurable flexibility. | ||
| */ | ||
| static int ssp_pre_start(struct dai *dai) | ||
| { | ||
| struct ssp_pdata *ssp = dai_get_drvdata(dai); | ||
| struct sof_ipc_dai_config *config = &ssp->config; | ||
| uint32_t sscr0; | ||
| uint32_t mdiv; | ||
| bool need_ecs = false; | ||
|
|
||
| int ret = 0; | ||
|
|
||
| dai_info(dai, "ssp_pre_start()"); | ||
|
|
||
| /* SSP active means bclk already configured. */ | ||
| if (ssp->state[SOF_IPC_STREAM_PLAYBACK] == COMP_STATE_ACTIVE || | ||
| ssp->state[SOF_IPC_STREAM_CAPTURE] == COMP_STATE_ACTIVE) | ||
| return 0; | ||
|
|
||
| sscr0 = ssp_read(dai, SSCR0); | ||
|
|
||
| #if CONFIG_INTEL_MN | ||
| /* BCLK config */ | ||
| ret = mn_set_bclk(config->dai_index, config->ssp.bclk_rate, | ||
| &mdiv, &need_ecs); | ||
| if (ret < 0) { | ||
| dai_err(dai, "invalid bclk_rate = %d for dai_index = %d", | ||
| config->ssp.bclk_rate, config->dai_index); | ||
| goto out; | ||
| } | ||
| #else | ||
| if (ssp_freq[SSP_DEFAULT_IDX].freq % config->ssp.bclk_rate != 0) { | ||
| dai_err(dai, "invalid bclk_rate = %d for dai_index = %d", | ||
| config->ssp.bclk_rate, config->dai_index); | ||
| goto out; | ||
| } | ||
|
|
||
| mdiv = ssp_freq[SSP_DEFAULT_IDX].freq / config->ssp.bclk_rate; | ||
| #endif | ||
|
|
||
| if (need_ecs) | ||
| sscr0 |= SSCR0_ECS; | ||
|
|
||
| /* clock divisor is SCR + 1 */ | ||
| mdiv -= 1; | ||
|
|
||
| /* divisor must be within SCR range */ | ||
| if (mdiv > (SSCR0_SCR_MASK >> 8)) { | ||
| dai_err(dai, "ssp_pre_start(): divisor %d is not within SCR range", | ||
| mdiv); | ||
| ret = -EINVAL; | ||
| goto out; | ||
| } | ||
|
|
||
| /* set the SCR divisor */ | ||
| sscr0 &= ~SSCR0_SCR_MASK; | ||
| sscr0 |= SSCR0_SCR(mdiv); | ||
|
|
||
| ssp_write(dai, SSCR0, sscr0); | ||
|
|
||
| dai_info(dai, "ssp_set_config(), sscr0 = 0x%08x", sscr0); | ||
| out: | ||
| platform_shared_commit(ssp, sizeof(*ssp)); | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| /* | ||
| * For power saving, we should do kinds of power release when the SSP | ||
| * dai is changed to inactive, though the runtime param configuration | ||
| * don't have to be reset. | ||
| */ | ||
| static void ssp_post_stop(struct dai *dai) | ||
| { | ||
| #if CONFIG_INTEL_MN | ||
| struct ssp_pdata *ssp = dai_get_drvdata(dai); | ||
|
|
||
| /* release bclk if SSP is inactive */ | ||
| if (ssp->state[SOF_IPC_STREAM_PLAYBACK] != COMP_STATE_ACTIVE && | ||
| ssp->state[SOF_IPC_STREAM_CAPTURE] != COMP_STATE_ACTIVE) | ||
| mn_release_bclk(dai->index); | ||
| #endif | ||
| } | ||
|
|
||
| /* get SSP hw params */ | ||
| static int ssp_get_hw_params(struct dai *dai, | ||
| struct sof_ipc_stream_params *params, int dir) | ||
|
|
@@ -698,6 +747,9 @@ static void ssp_start(struct dai *dai, int direction) | |
|
|
||
| spin_lock(&dai->lock); | ||
|
|
||
| /* request mclk/bclk */ | ||
| ssp_pre_start(dai); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should have a first patch that moves all the code from ssp_set_config() to ssp_pre_start(), and then add the M/N changes.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want to do this for pause/release as well?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Do you mean split this commit to 2? I thought about that, but compiler may complaint for the first commit that "function defined but not used".
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It will be called when ssp_start/stop is called with this change applied, so it will not be applied at ssp_pause() at the moment. For this pause/release scenario, it could be tricky as we don't release clear the RXEN bit at the moment, so forcing to release the bclk might lead to jitter (samples lost), but we are good with this series as we don't do this for pause. |
||
|
|
||
| /* enable port */ | ||
| ssp_update_bits(dai, SSCR0, SSCR0_SSE, SSCR0_SSE); | ||
| ssp->state[direction] = COMP_STATE_ACTIVE; | ||
|
|
@@ -764,6 +816,8 @@ static void ssp_stop(struct dai *dai, int direction) | |
| dai_info(dai, "ssp_stop(), SSP port disabled"); | ||
| } | ||
|
|
||
| ssp_post_stop(dai); | ||
|
|
||
| spin_unlock(&dai->lock); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.