Previously, sysclk was configured using devicetree and sysclk-id. Change the method to obtain and use clock information using clk_get. Signed-off-by: Kiseok Jo <kiseok.jo@xxxxxxxxxxxxxx> --- sound/soc/codecs/sma1303.c | 124 ++++++++++++++++++------------------- sound/soc/codecs/sma1303.h | 5 -- 2 files changed, 59 insertions(+), 70 deletions(-) diff --git a/sound/soc/codecs/sma1303.c b/sound/soc/codecs/sma1303.c index 9ae4e3cba3ae..a21cde126906 100644 --- a/sound/soc/codecs/sma1303.c +++ b/sound/soc/codecs/sma1303.c @@ -7,6 +7,7 @@ // Auther: Gyuhwa Park <gyuhwa.park@xxxxxxxxxxxxxx> // Kiseok Jo <kiseok.jo@xxxxxxxxxxxxxx> +#include <linux/clk.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/kernel.h> @@ -59,6 +60,7 @@ struct sma1303_pll_match { struct sma1303_priv { enum sma1303_type devtype; struct attribute_group *attr_grp; + struct clk *mclk; struct delayed_work check_fault_work; struct device *dev; struct kobject *kobj; @@ -936,27 +938,23 @@ static int sma1303_setup_pll(struct snd_soc_component *component, dev_dbg(component->dev, "%s : BCLK = %dHz\n", __func__, bclk); - if (sma1303->sys_clk_id == SMA1303_PLL_CLKIN_MCLK) { - dev_dbg(component->dev, "%s : MCLK is not supported\n", - __func__); - } else if (sma1303->sys_clk_id == SMA1303_PLL_CLKIN_BCLK) { - for (i = 0; i < sma1303->num_of_pll_matches; i++) { - if (sma1303->pll_matches[i].input_clk == bclk) - break; - } - if (i == sma1303->num_of_pll_matches) { - dev_dbg(component->dev, "%s : No matching value between pll table and SCK\n", + for (i = 0; i < sma1303->num_of_pll_matches; i++) { + if (sma1303->pll_matches[i].input_clk == bclk) + break; + } + if (i == sma1303->num_of_pll_matches) { + dev_dbg(component->dev, + "%s : No matching value between pll table and SCK\n", __func__); - return -EINVAL; - } - - ret += sma1303_regmap_update_bits(sma1303, - SMA1303_A2_TOP_MAN1, - SMA1303_PLL_PD_MASK|SMA1303_PLL_REF_CLK_MASK, - SMA1303_PLL_OPERATION|SMA1303_PLL_SCK, - NULL); + return -EINVAL; } + ret += sma1303_regmap_update_bits(sma1303, + SMA1303_A2_TOP_MAN1, + SMA1303_PLL_PD_MASK|SMA1303_PLL_REF_CLK_MASK, + SMA1303_PLL_OPERATION|SMA1303_PLL_SCK, + NULL); + ret += sma1303_regmap_write(sma1303, SMA1303_8B_PLL_POST_N, sma1303->pll_matches[i].post_n); @@ -999,13 +997,14 @@ static int sma1303_dai_hw_params_amp(struct snd_pcm_substream *substream, if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { - if (sma1303->sys_clk_id == SMA1303_PLL_CLKIN_MCLK - || sma1303->sys_clk_id == SMA1303_PLL_CLKIN_BCLK) { - + if (IS_ERR(sma1303->mclk)) { if (sma1303->last_bclk != bclk) { sma1303_setup_pll(component, bclk); sma1303->last_bclk = bclk; } + } else { + dev_dbg(component->dev, + "%s : MCLK is not supported\n", __func__); } switch (params_rate(params)) { @@ -1175,19 +1174,6 @@ static int sma1303_dai_set_sysclk_amp(struct snd_soc_dai *dai, struct snd_soc_component *component = dai->component; struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component); - switch (clk_id) { - case SMA1303_EXTERNAL_CLOCK_19_2: - break; - case SMA1303_EXTERNAL_CLOCK_24_576: - break; - case SMA1303_PLL_CLKIN_MCLK: - break; - case SMA1303_PLL_CLKIN_BCLK: - break; - default: - dev_err(component->dev, "Invalid clk id: %d\n", clk_id); - return -EINVAL; - } sma1303->sys_clk_id = clk_id; return 0; } @@ -1570,8 +1556,12 @@ static int sma1303_probe(struct snd_soc_component *component) { struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); + struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component); snd_soc_dapm_sync(dapm); + sma1303->mclk = devm_clk_get(sma1303->dev, "mclk"); + if (PTR_ERR(sma1303->mclk) == -EPROBE_DEFER) + return -EPROBE_DEFER; return 0; } @@ -1583,9 +1573,44 @@ static void sma1303_remove(struct snd_soc_component *component) cancel_delayed_work_sync(&sma1303->check_fault_work); } +static int sma1303_set_bias_level(struct snd_soc_component *component, + enum snd_soc_bias_level level) +{ + struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component); + int ret; + + switch (level) { + case SND_SOC_BIAS_ON: + dev_dbg(sma1303->dev, "%s : SND_SOC_BIAS_ON\n", __func__); + break; + case SND_SOC_BIAS_STANDBY: + dev_dbg(sma1303->dev, "%s : SND_SOC_BIAS_STANDBY\n", __func__); + break; + case SND_SOC_BIAS_PREPARE: + dev_dbg(sma1303->dev, "%s : SND_SOC_BIAS_PREPARE\n", __func__); + if (IS_ERR(sma1303->mclk)) + break; + if (snd_soc_component_get_bias_level(component) + == SND_SOC_BIAS_ON) { + clk_disable_unprepare(sma1303->mclk); + } else { + ret = clk_prepare_enable(sma1303->mclk); + if (ret) + return ret; + } + break; + case SND_SOC_BIAS_OFF: + dev_dbg(sma1303->dev, "%s : SND_SOC_BIAS_OFF\n", __func__); + sma1303_shutdown(component); + break; + } + return 0; +} + static const struct snd_soc_component_driver sma1303_component = { .probe = sma1303_probe, .remove = sma1303_remove, + .set_bias_level = sma1303_set_bias_level, .controls = sma1303_snd_controls, .num_controls = ARRAY_SIZE(sma1303_snd_controls), .dapm_widgets = sma1303_dapm_widgets, @@ -1680,9 +1705,7 @@ static struct attribute_group sma1303_attr_group = { static int sma1303_i2c_probe(struct i2c_client *client) { struct sma1303_priv *sma1303; - struct device_node *np = client->dev.of_node; int ret, i = 0; - u32 value = 0; unsigned int device_info, status, otp_stat; sma1303 = devm_kzalloc(&client->dev, @@ -1700,35 +1723,6 @@ static int sma1303_i2c_probe(struct i2c_client *client) return ret; } - if (np) { - if (!of_property_read_u32(np, "sys-clk-id", &value)) { - switch (value) { - case SMA1303_EXTERNAL_CLOCK_19_2: - case SMA1303_EXTERNAL_CLOCK_24_576: - case SMA1303_PLL_CLKIN_MCLK: - dev_dbg(&client->dev, "MCLK is not supported\n"); - break; - case SMA1303_PLL_CLKIN_BCLK: - dev_dbg(&client->dev, - "Take an BCLK(SCK) and covert it to an internal PLL for use\n"); - break; - default: - dev_err(&client->dev, - "Invalid sys-clk-id: %u\n", value); - return -EINVAL; - } - sma1303->sys_clk_id = value; - } else { - dev_dbg(&client->dev, "Use the internal PLL clock by default\n"); - sma1303->sys_clk_id = SMA1303_PLL_CLKIN_BCLK; - } - } else { - dev_err(&client->dev, - "device node initialization error\n"); - devm_kfree(&client->dev, sma1303); - return -ENODEV; - } - ret = sma1303_regmap_read(sma1303, SMA1303_FF_DEVICE_INDEX, &device_info); diff --git a/sound/soc/codecs/sma1303.h b/sound/soc/codecs/sma1303.h index ae70f207adde..29e6d19035c6 100644 --- a/sound/soc/codecs/sma1303.h +++ b/sound/soc/codecs/sma1303.h @@ -16,11 +16,6 @@ #define SMA1303_I2C_ADDR_10 0x5e #define SMA1303_I2C_ADDR_11 0x7e -#define SMA1303_EXTERNAL_CLOCK_19_2 0x00 -#define SMA1303_EXTERNAL_CLOCK_24_576 0x01 -#define SMA1303_PLL_CLKIN_MCLK 0x02 -#define SMA1303_PLL_CLKIN_BCLK 0x03 - #define SMA1303_MONO 0x00 #define SMA1303_STEREO 0x01 -- 2.20.1