Skip to content

Commit

Permalink
remove mclk control from ssp driver
Browse files Browse the repository at this point in the history
Signed-off-by: Brent Lu <[email protected]>
  • Loading branch information
brentlu committed Feb 23, 2024
1 parent e0f2b8d commit 6fb8c50
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 86 deletions.
87 changes: 5 additions & 82 deletions src/drivers/intel/ssp/ssp.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,41 +145,6 @@ static void ssp_empty_rx_fifo_on_stop(struct dai *dai)
ssp_update_bits(dai, SSSR, SSSR_ROR, SSSR_ROR);
}

static int ssp_mclk_prepare_enable(struct dai *dai)
{
struct ssp_pdata *ssp = dai_get_drvdata(dai);
struct sof_ipc_dai_config *config = &ssp->config;
int ret = 0;

if (ssp->clk_active & SSP_CLK_MCLK_ACTIVE)
return 0;

/* MCLK config */
if (ssp->clk_active & SSP_CLK_MCLK_IS_NEEDED)
ret = mn_set_mclk(config->ssp.mclk_id, config->ssp.mclk_rate);

if (ret < 0)
dai_err(dai, "ssp_mclk_prepare_enable(): invalid mclk_rate = %d for mclk_id = %d",
config->ssp.mclk_rate, config->ssp.mclk_id);
else
ssp->clk_active |= SSP_CLK_MCLK_ACTIVE;

return ret;
}

static void ssp_mclk_disable_unprepare(struct dai *dai)
{
struct ssp_pdata *ssp = dai_get_drvdata(dai);

if (!(ssp->clk_active & SSP_CLK_MCLK_ACTIVE))
return;

if (ssp->clk_active & SSP_CLK_MCLK_IS_NEEDED)
mn_release_mclk(ssp->config.ssp.mclk_id);

ssp->clk_active &= ~SSP_CLK_MCLK_ACTIVE;
}

static int ssp_bclk_prepare_enable(struct dai *dai)
{
struct ssp_pdata *ssp = dai_get_drvdata(dai);
Expand Down Expand Up @@ -304,7 +269,7 @@ static int ssp_set_config_tplg(struct dai *dai, struct ipc_config_dai *common_co
goto clk;
}

if (ssp->clk_active & (SSP_CLK_MCLK_ACTIVE | SSP_CLK_BCLK_ACTIVE)) {
if (ssp->clk_active & SSP_CLK_BCLK_ACTIVE) {
dai_warn(dai, "ssp_set_config(): SSP active, cannot change config");
goto clk;
}
Expand Down Expand Up @@ -358,19 +323,18 @@ static int ssp_set_config_tplg(struct dai *dai, struct ipc_config_dai *common_co
sscr1 |= SSCR1_SCLKDIR | SSCR1_SFRMDIR;
break;
case SOF_DAI_FMT_CBC_CFC:
ssp->clk_active |= SSP_CLK_MCLK_IS_NEEDED | SSP_CLK_BCLK_IS_NEEDED;
ssp->clk_active |= SSP_CLK_BCLK_IS_NEEDED;
sscr1 |= SSCR1_SCFR;
cfs = true;
break;
case SOF_DAI_FMT_CBP_CFC:
ssp->clk_active |= SSP_CLK_MCLK_IS_NEEDED;
sscr1 |= SSCR1_SCLKDIR;
/* FIXME: this mode has not been tested */

cfs = true;
break;
case SOF_DAI_FMT_CBC_CFP:
ssp->clk_active |= SSP_CLK_MCLK_IS_NEEDED | SSP_CLK_BCLK_IS_NEEDED;
ssp->clk_active |= SSP_CLK_BCLK_IS_NEEDED;
sscr1 |= SSCR1_SCFR | SSCR1_SFRMDIR;
/* FIXME: this mode has not been tested */
break;
Expand Down Expand Up @@ -755,24 +719,12 @@ static int ssp_set_config_tplg(struct dai *dai, struct ipc_config_dai *common_co
clk:
/* MCLK always-on: turn on mclk and never turn it off */
if (ssp->params.clks_control & SOF_DAI_INTEL_SSP_CLKCTRL_MCLK_AON) {
ret = ssp_mclk_prepare_enable(dai);
if (ret < 0)
goto out;

ssp->clk_active |= SSP_CLK_MCLK_AON_REQ;

dai_info(dai, "ssp_set_config(): enable MCLK for SSP%d", dai->index);
}

switch (config->flags & SOF_DAI_CONFIG_FLAGS_CMD_MASK) {
case SOF_DAI_CONFIG_FLAGS_HW_PARAMS:
if (ssp->params.clks_control & SOF_DAI_INTEL_SSP_CLKCTRL_MCLK_ES) {
ret = ssp_mclk_prepare_enable(dai);
if (ret < 0)
goto out;

ssp->clk_active |= SSP_CLK_MCLK_ES_REQ;

dai_info(dai, "ssp_set_config(): hw_params stage: enabled MCLK clocks for SSP%d...",
dai->index);
}
Expand Down Expand Up @@ -822,8 +774,6 @@ static int ssp_set_config_tplg(struct dai *dai, struct ipc_config_dai *common_co
if (ssp->params.clks_control & SOF_DAI_INTEL_SSP_CLKCTRL_MCLK_ES) {
dai_info(dai, "ssp_set_config: hw_free stage: releasing MCLK clocks for SSP%d...",
dai->index);
ssp_mclk_disable_unprepare(dai);
ssp->clk_active &= ~SSP_CLK_MCLK_ES_REQ;
}
break;
default:
Expand Down Expand Up @@ -889,16 +839,13 @@ static int ssp_set_config_blob(struct dai *dai, struct ipc_config_dai *common_co
* Configure MCLK/BCLK only if SSP is the clock provider
*/
if (!(blob->i2s_driver_config.i2s_config.ssc1 & (SSCR1_SCLKDIR | SSCR1_SFRMDIR))) {
ssp->clk_active |= SSP_CLK_MCLK_IS_NEEDED;
if (!(blob->i2s_driver_config.i2s_config.ssc1 & SSCR1_SCLKDIR))
ssp->clk_active |= SSP_CLK_BCLK_IS_NEEDED;

mn_set_mclk_blob(blob->i2s_driver_config.mclk_config.mdivc,
blob->i2s_driver_config.mclk_config.mdivr);
}

ssp->clk_active |= SSP_CLK_MCLK_ES_REQ;

/* enable port */
ssp_update_bits(dai, SSCR0, SSCR0_SSE, SSCR0_SSE);
ssp->clk_active |= SSP_CLK_BCLK_ES_REQ;
Expand Down Expand Up @@ -928,17 +875,9 @@ static int ssp_pre_start(struct dai *dai)
dai_info(dai, "ssp_pre_start()");

/*
* We will test if mclk/bclk is configured in
* ssp_mclk/bclk_prepare_enable/disable functions
* We will test if bclk is configured in
* ssp_bclk_prepare_enable/disable functions
*/
if (!(ssp->clk_active & SSP_CLK_MCLK_ES_REQ) &&
!(ssp->clk_active & SSP_CLK_MCLK_AON_REQ)) {
/* MCLK config */
ret = ssp_mclk_prepare_enable(dai);
if (ret < 0)
return ret;
}

if (!(ssp->clk_active & SSP_CLK_BCLK_ES_REQ))
ret = ssp_bclk_prepare_enable(dai);

Expand All @@ -962,12 +901,6 @@ static void ssp_post_stop(struct dai *dai)
dai->index);
ssp_bclk_disable_unprepare(dai);
}
if (!(ssp->clk_active & SSP_CLK_MCLK_ES_REQ) &&
!(ssp->clk_active & SSP_CLK_MCLK_AON_REQ)) {
dai_info(dai, "ssp_post_stop releasing MCLK clocks for SSP%d...",
dai->index);
ssp_mclk_disable_unprepare(dai);
}
}
}

Expand Down Expand Up @@ -1195,18 +1128,8 @@ static int ssp_probe(struct dai *dai)

static int ssp_remove(struct dai *dai)
{
struct ssp_pdata *ssp = dai_get_drvdata(dai);

pm_runtime_put_sync(SSP_CLK, dai->index);

/*
* dai comp will be freed during HW_FREE stage if dynamic pipeline is
* enabled; need to check the MCLK_AON quirk to see if we need to keep
* MCLK on even when dai comp is going to be freed
*/
if (!(ssp->params.clks_control & SOF_DAI_INTEL_SSP_CLKCTRL_MCLK_AON))
ssp_mclk_disable_unprepare(dai);

ssp_bclk_disable_unprepare(dai);

/* Disable SSP power */
Expand Down
4 changes: 0 additions & 4 deletions src/include/sof/drivers/ssp.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,6 @@ extern const struct dai_driver ssp_driver;
#define ssp_irq(ssp) \
ssp->plat_data.irq

#define SSP_CLK_MCLK_IS_NEEDED BIT(1)
#define SSP_CLK_MCLK_ES_REQ BIT(2)
#define SSP_CLK_MCLK_ACTIVE BIT(3)
#define SSP_CLK_MCLK_AON_REQ BIT(4)
#define SSP_CLK_BCLK_IS_NEEDED BIT(5)
#define SSP_CLK_BCLK_ES_REQ BIT(6)
#define SSP_CLK_BCLK_ACTIVE BIT(7)
Expand Down

0 comments on commit 6fb8c50

Please sign in to comment.