Skip to content

Commit

Permalink
ASoC: da7219: Add recalc_rate function to return DAI clock rate
Browse files Browse the repository at this point in the history
By making MCLK parent of DAI clocks, when querying the rate of the
clock the rate returned is now given from the parent clock so
gives the MCLK rate rather than 0 as previously returned. This is
a bit misleading, and actually there's no major reason why we can't
at least return the DAI WCLK rate, as set in HW, so that's what we
now do.

Signed-off-by: Adam Thomson <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
Adam Thomson authored and broonie committed Jan 9, 2019
1 parent a6028cc commit a58943a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
45 changes: 42 additions & 3 deletions sound/soc/codecs/da7219.c
Original file line number Diff line number Diff line change
Expand Up @@ -1767,7 +1767,7 @@ static int da7219_dai_clks_prepare(struct clk_hw *hw)
{
struct da7219_priv *da7219 =
container_of(hw, struct da7219_priv, dai_clks_hw);
struct snd_soc_component *component = da7219->aad->component;
struct snd_soc_component *component = da7219->component;

snd_soc_component_update_bits(component, DA7219_DAI_CLK_MODE,
DA7219_DAI_CLK_EN_MASK,
Expand All @@ -1780,7 +1780,7 @@ static void da7219_dai_clks_unprepare(struct clk_hw *hw)
{
struct da7219_priv *da7219 =
container_of(hw, struct da7219_priv, dai_clks_hw);
struct snd_soc_component *component = da7219->aad->component;
struct snd_soc_component *component = da7219->component;

snd_soc_component_update_bits(component, DA7219_DAI_CLK_MODE,
DA7219_DAI_CLK_EN_MASK, 0);
Expand All @@ -1790,18 +1790,55 @@ static int da7219_dai_clks_is_prepared(struct clk_hw *hw)
{
struct da7219_priv *da7219 =
container_of(hw, struct da7219_priv, dai_clks_hw);
struct snd_soc_component *component = da7219->aad->component;
struct snd_soc_component *component = da7219->component;
u8 clk_reg;

clk_reg = snd_soc_component_read32(component, DA7219_DAI_CLK_MODE);

return !!(clk_reg & DA7219_DAI_CLK_EN_MASK);
}

static unsigned long da7219_dai_clks_recalc_rate(struct clk_hw *hw,
unsigned long parent_rate)
{
struct da7219_priv *da7219 =
container_of(hw, struct da7219_priv, dai_clks_hw);
struct snd_soc_component *component = da7219->component;
u8 fs = snd_soc_component_read32(component, DA7219_SR);

switch (fs & DA7219_SR_MASK) {
case DA7219_SR_8000:
return 8000;
case DA7219_SR_11025:
return 11025;
case DA7219_SR_12000:
return 12000;
case DA7219_SR_16000:
return 16000;
case DA7219_SR_22050:
return 22050;
case DA7219_SR_24000:
return 24000;
case DA7219_SR_32000:
return 32000;
case DA7219_SR_44100:
return 44100;
case DA7219_SR_48000:
return 48000;
case DA7219_SR_88200:
return 88200;
case DA7219_SR_96000:
return 96000;
default:
return 0;
}
}

static const struct clk_ops da7219_dai_clks_ops = {
.prepare = da7219_dai_clks_prepare,
.unprepare = da7219_dai_clks_unprepare,
.is_prepared = da7219_dai_clks_is_prepared,
.recalc_rate = da7219_dai_clks_recalc_rate,
};

static int da7219_register_dai_clks(struct snd_soc_component *component)
Expand All @@ -1825,6 +1862,7 @@ static int da7219_register_dai_clks(struct snd_soc_component *component)

init.name = pdata->dai_clks_name;
init.ops = &da7219_dai_clks_ops;
init.flags = CLK_GET_RATE_NOCACHE;
da7219->dai_clks_hw.init = &init;

dai_clks = devm_clk_register(dev, &da7219->dai_clks_hw);
Expand Down Expand Up @@ -1912,6 +1950,7 @@ static int da7219_probe(struct snd_soc_component *component)
unsigned int rev;
int ret;

da7219->component = component;
mutex_init(&da7219->ctrl_lock);
mutex_init(&da7219->pll_lock);

Expand Down
1 change: 1 addition & 0 deletions sound/soc/codecs/da7219.h
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ struct da7219_aad_priv;

/* Private data */
struct da7219_priv {
struct snd_soc_component *component;
struct da7219_aad_priv *aad;
struct da7219_pdata *pdata;

Expand Down

0 comments on commit a58943a

Please sign in to comment.