Skip to contentSkip to conversation

ASoC: rt1015: apply some refactors

PATCH In review Tzung-Bi Shih 2 participants 7 messages Dec 24, 2020 – Dec 29, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover ASoC: rt1015: apply some refactors

The series refactors rt1015.c.

The 1st patch sorts header inclusions alphabetically.

The 2nd and 3rd patch improve error handling for kcontrols.

The 4th patch enhances readability.

The 5th patch removes unused variables in rt1015_priv.

Tzung-Bi Shih (5):
ASoC: rt1015: sort header inclusions
ASoC: rt1015: save boost_mode only if valid
ASoC: rt1015: return error if any when setting bypass_boost
ASoC: rt1015: refactor retry loop and rt1015_priv allocation
ASoC: rt1015: remove unneeded variables in rt1015_priv

 sound/soc/codecs/rt1015.c | 49 ++++++++++++++++++++-------------------
 sound/soc/codecs/rt1015.h |  4 ----
 2 files changed, 25 insertions(+), 28 deletions(-)
Signature · 1 line
2.29.2.729.g45daf8777d-goog
#1 lore raw

PATCH 1/5 ASoC: rt1015: sort header inclusions

Sorts header inclusions. ASCII value of 'r' is less than 's'.

---
 sound/soc/codecs/rt1015.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/rt1015.c +1 -1
index 32e6bcf763d1..1a29d3d5263e 100644
@@ -24,10 +24,10 @@
 #include <sound/initval.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
+#include <sound/rt1015.h>
 #include <sound/soc-dapm.h>
 #include <sound/soc.h>
 #include <sound/tlv.h>
-#include <sound/rt1015.h>
 
 #include "rl6231.h"
 #include "rt1015.h"
Signature · 1 line
2.29.2.729.g45daf8777d-goog
#2 lore raw

PATCH 2/5 ASoC: rt1015: save boost_mode only if valid

In reply to Tzung-Bi Shih

Saves boost_mode only if valid. Also returns -EINVAL if it is invalid.

---
 sound/soc/codecs/rt1015.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
sound/soc/codecs/rt1015.c +5 -3
index 1a29d3d5263e..696e00478991 100644
@@ -444,10 +444,9 @@ static int rt1015_boost_mode_put(struct snd_kcontrol *kcontrol,
 		snd_soc_kcontrol_component(kcontrol);
 	struct rt1015_priv *rt1015 =
 		snd_soc_component_get_drvdata(component);
+	int boost_mode = ucontrol->value.integer.value[0];
 
-	rt1015->boost_mode = ucontrol->value.integer.value[0];
-
-	switch (rt1015->boost_mode) {
+	switch (boost_mode) {
 	case BYPASS:
 		snd_soc_component_update_bits(component,
 			RT1015_SMART_BST_CTRL1, RT1015_ABST_AUTO_EN_MASK |
@@ -471,8 +470,11 @@ static int rt1015_boost_mode_put(struct snd_kcontrol *kcontrol,
 		break;
 	default:
 		dev_err(component->dev, "Unknown boost control.\n");
+		return -EINVAL;
 	}
 
+	rt1015->boost_mode = boost_mode;
+
 	return 0;
 }
 
Signature · 1 line
2.29.2.729.g45daf8777d-goog
#3 lore raw

PATCH 3/5 ASoC: rt1015: return error if any when setting bypass_boost

In reply to Tzung-Bi Shih

Returns -EBUSY if DAC is using when setting bypass_boost.

---
 sound/soc/codecs/rt1015.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
sound/soc/codecs/rt1015.c +11 -9
index 696e00478991..93e4763ece11 100644
@@ -548,17 +548,19 @@ static int rt1015_bypass_boost_put(struct snd_kcontrol *kcontrol,
 	struct rt1015_priv *rt1015 =
 		snd_soc_component_get_drvdata(component);
 
-	if (!rt1015->dac_is_used) {
-		rt1015->bypass_boost = ucontrol->value.integer.value[0];
-		if (rt1015->bypass_boost == RT1015_Bypass_Boost &&
+	if (rt1015->dac_is_used) {
+		dev_err(component->dev, "DAC is being used!\n");
+		return -EBUSY;
+	}
+
+	rt1015->bypass_boost = ucontrol->value.integer.value[0];
+	if (rt1015->bypass_boost == RT1015_Bypass_Boost &&
 			!rt1015->cali_done) {
-			rt1015_calibrate(rt1015);
-			rt1015->cali_done = 1;
+		rt1015_calibrate(rt1015);
+		rt1015->cali_done = 1;
 
-			regmap_write(rt1015->regmap, RT1015_MONO_DYNA_CTRL, 0x0010);
-		}
-	} else
-		dev_err(component->dev, "DAC is being used!\n");
+		regmap_write(rt1015->regmap, RT1015_MONO_DYNA_CTRL, 0x0010);
+	}
 
 	return 0;
 }
Signature · 1 line
2.29.2.729.g45daf8777d-goog
#4 lore raw

PATCH 4/5 ASoC: rt1015: refactor retry loop and rt1015_priv allocation

In reply to Tzung-Bi Shih

Refactors retry loop in flush DAC work. It is more clear to use a for-loop here.

Uses !rt1015 to check if NULL.

---
 sound/soc/codecs/rt1015.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
sound/soc/codecs/rt1015.c +4 -6
index 93e4763ece11..a7b9dfcb4b0f 100644
@@ -570,15 +570,14 @@ static void rt1015_flush_work(struct work_struct *work)
 	struct rt1015_priv *rt1015 = container_of(work, struct rt1015_priv,
 						flush_work.work);
 	struct snd_soc_component *component = rt1015->component;
-	unsigned int val, i = 0, count = 200;
+	unsigned int val, i;
 
-	while (i < count) {
+	for (i = 0; i < 200; ++i) {
 		usleep_range(1000, 1500);
 		dev_dbg(component->dev, "Flush DAC (retry:%u)\n", i);
 		regmap_read(rt1015->regmap, RT1015_CLK_DET, &val);
 		if (val & 0x800)
 			break;
-		i++;
 	}
 
 	regmap_write(rt1015->regmap, RT1015_SYS_RST1, 0x0597);
@@ -1187,9 +1186,8 @@ static int rt1015_i2c_probe(struct i2c_client *i2c,
 	int ret;
 	unsigned int val;
 
-	rt1015 = devm_kzalloc(&i2c->dev, sizeof(struct rt1015_priv),
-				GFP_KERNEL);
-	if (rt1015 == NULL)
+	rt1015 = devm_kzalloc(&i2c->dev, sizeof(*rt1015), GFP_KERNEL);
+	if (!rt1015)
 		return -ENOMEM;
 
 	i2c_set_clientdata(i2c, rt1015);
Signature · 1 line
2.29.2.729.g45daf8777d-goog
#5 lore raw

PATCH 5/5 ASoC: rt1015: remove unneeded variables in rt1015_priv

In reply to Tzung-Bi Shih

- `lrck' is only used in .hw_params callback so that it can be local.
- `bclk' is unused.
- `id' is unused.
- `amp_ver' is unused.

---
 sound/soc/codecs/rt1015.c | 9 ++++-----
 sound/soc/codecs/rt1015.h | 4 ----
 2 files changed, 4 insertions(+), 9 deletions(-)
sound/soc/codecs/rt1015.c +4 -5
index a7b9dfcb4b0f..4a9e2eaebe30 100644
@@ -724,11 +724,11 @@ static int rt1015_hw_params(struct snd_pcm_substream *substream,
 {
 	struct snd_soc_component *component = dai->component;
 	struct rt1015_priv *rt1015 = snd_soc_component_get_drvdata(component);
-	int pre_div, bclk_ms, frame_size;
+	int pre_div, bclk_ms, frame_size, lrck;
 	unsigned int val_len = 0;
 
-	rt1015->lrck = params_rate(params);
-	pre_div = rl6231_get_clk_info(rt1015->sysclk, rt1015->lrck);
+	lrck = params_rate(params);
+	pre_div = rl6231_get_clk_info(rt1015->sysclk, lrck);
 	if (pre_div < 0) {
 		dev_err(component->dev, "Unsupported clock rate\n");
 		return -EINVAL;
@@ -742,13 +742,12 @@ static int rt1015_hw_params(struct snd_pcm_substream *substream,
 	}
 
 	bclk_ms = frame_size > 32;
-	rt1015->bclk = rt1015->lrck * (32 << bclk_ms);
 
 	dev_dbg(component->dev, "bclk_ms is %d and pre_div is %d for iis %d\n",
 				bclk_ms, pre_div, dai->id);
 
 	dev_dbg(component->dev, "lrck is %dHz and pre_div is %d for iis %d\n",
-				rt1015->lrck, pre_div, dai->id);
+				lrck, pre_div, dai->id);
 
 	switch (params_width(params)) {
 	case 16:
sound/soc/codecs/rt1015.h +0 -4
index b6ea753014e1..e9b498a754e0 100644
@@ -427,16 +427,12 @@ struct rt1015_priv {
 	struct regmap *regmap;
 	int sysclk;
 	int sysclk_src;
-	int lrck;
-	int bclk;
 	int bclk_ratio;
-	int id;
 	int pll_src;
 	int pll_in;
 	int pll_out;
 	int boost_mode;
 	int bypass_boost;
-	int amp_ver;
 	int dac_is_used;
 	int cali_done;
 	int hw_config;
Signature · 1 line
2.29.2.729.g45daf8777d-goog
maintainer
#6 lore raw
In reply to Tzung-Bi Shih
Quoted 9 lines · Tzung-Bi Shih

The series refactors rt1015.c.

The 1st patch sorts header inclusions alphabetically.

The 2nd and 3rd patch improve error handling for kcontrols.

The 4th patch enhances readability.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/5] ASoC: rt1015: sort header inclusions

      commit: 4ac275eda0d7bf6f222ad0093ffbdfd2f4228eaa
[2/5] ASoC: rt1015: save boost_mode only if valid
      commit: bf1eb056ac15a058fb5e254307f14f45efbe79d8
[3/5] ASoC: rt1015: return error if any when setting bypass_boost
      commit: e48b41e903a102744827661080acd500b7bbef26
[4/5] ASoC: rt1015: refactor retry loop and rt1015_priv allocation
      commit: 3128f1c3b53d73e35e1069663736284358fcdd01
[5/5] ASoC: rt1015: remove unneeded variables in rt1015_priv
      commit: a5db2ca51367eeafb0c4013d3a6fc58932612c03

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark