Skip to contentSkip to conversation

dt-bindings: tas2770: Add shutdown gpio property

PATCH In review Dan Murphy 2 participants 9 messages Sep 23, 2020

Subsystems (4)
lore
Share & tools
lore

Dan Murphy

author
#0 lore raw

PATCH 1/6 dt-bindings: tas2770: Add shutdown gpio property

Add the shutdown-gpios property to the yaml to define the GPIO that can be used to place the device in shutdown mode or wake the device up.

---
 Documentation/devicetree/bindings/sound/tas2770.yaml | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/sound/tas2770.yaml +4 -0
index bb26d081c9fa..9fdf614add55 100644
@@ -29,6 +29,9 @@ properties:
   reset-gpio:
     description: GPIO used to reset the device.
 
+  shutdown-gpios:
+    description: GPIO used to control the state of the device.
+
   interrupts:
     maxItems: 1
 
@@ -69,6 +72,7 @@ examples:
        interrupt-parent = <&gpio1>;
        interrupts = <14>;
        reset-gpio = <&gpio1 15 0>;
+       shutdown-gpios = <&gpio1 14 0>;
        ti,imon-slot-no = <0>;
        ti,vmon-slot-no = <2>;
      };
Signature · 1 line
2.28.0
author
#1 lore raw

PATCH 2/6 ASoC: tas2770: Add shutdown capability via a GPIO

Add the hardware shutdown mechanism to shutdown and wake up the device via a GPIO.

---
 sound/soc/codecs/tas2770.c | 53 ++++++++++++++++++++++++++++----------
 sound/soc/codecs/tas2770.h |  1 +
 2 files changed, 40 insertions(+), 14 deletions(-)
sound/soc/codecs/tas2770.c +39 -14
index 386aaa11fa08..9f7363927c50 100644
@@ -79,28 +79,42 @@ static int tas2770_set_bias_level(struct snd_soc_component *component,
 #ifdef CONFIG_PM
 static int tas2770_codec_suspend(struct snd_soc_component *component)
 {
-	int ret;
+	struct tas2770_priv *tas2770 = snd_soc_component_get_drvdata(component);
+	int ret = 0;
 
-	ret = snd_soc_component_update_bits(component, TAS2770_PWR_CTRL,
-					    TAS2770_PWR_CTRL_MASK,
-					    TAS2770_PWR_CTRL_SHUTDOWN);
-	if (ret < 0)
-		return ret;
+	if (tas2770->sdz_gpio) {
+		gpiod_set_value_cansleep(tas2770->sdz_gpio, 0);
+	} else {
+		ret = snd_soc_component_update_bits(component, TAS2770_PWR_CTRL,
+						    TAS2770_PWR_CTRL_MASK,
+						    TAS2770_PWR_CTRL_SHUTDOWN);
+		if (ret < 0)
+			return ret;
 
-	return 0;
+		ret = 0;
+	}
+
+	return ret;
 }
 
 static int tas2770_codec_resume(struct snd_soc_component *component)
 {
-	int ret;
+	struct tas2770_priv *tas2770 = snd_soc_component_get_drvdata(component);
+	int ret = 0;
 
-	ret = snd_soc_component_update_bits(component, TAS2770_PWR_CTRL,
-					    TAS2770_PWR_CTRL_MASK,
-					    TAS2770_PWR_CTRL_ACTIVE);
-	if (ret < 0)
-		return ret;
+	if (tas2770->sdz_gpio) {
+		gpiod_set_value_cansleep(tas2770->sdz_gpio, 1);
+	} else {
+		ret = snd_soc_component_update_bits(component, TAS2770_PWR_CTRL,
+						    TAS2770_PWR_CTRL_MASK,
+						    TAS2770_PWR_CTRL_ACTIVE);
+		if (ret < 0)
+			return ret;
 
-	return 0;
+		ret = 0;
+	}
+
+	return ret;
 }
 #else
 #define tas2770_codec_suspend NULL
@@ -498,6 +512,9 @@ static int tas2770_codec_probe(struct snd_soc_component *component)
 
 	tas2770->component = component;
 
+	if (tas2770->sdz_gpio)
+		gpiod_set_value_cansleep(tas2770->sdz_gpio, 1);
+
 	tas2770_reset(tas2770);
 
 	return 0;
@@ -650,6 +667,14 @@ static int tas2770_parse_dt(struct device *dev, struct tas2770_priv *tas2770)
 		tas2770->v_sense_slot = 2;
 	}
 
+	tas2770->sdz_gpio = devm_gpiod_get_optional(dev, "shutdown", GPIOD_OUT_HIGH);
+	if (IS_ERR(tas2770->sdz_gpio)) {
+		if (PTR_ERR(tas2770->sdz_gpio) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+
+		tas2770->sdz_gpio = NULL;
+	}
+
 	return 0;
 }
 
sound/soc/codecs/tas2770.h +1 -0
index 07e3556fc702..b3fc4a487033 100644
@@ -134,6 +134,7 @@ struct tas2770_priv {
 	int power_state;
 	int asi_format;
 	struct gpio_desc *reset_gpio;
+	struct gpio_desc *sdz_gpio;
 	int sampling_rate;
 	int channel_size;
 	int slot_width;
Signature · 1 line
2.28.0
author
#2 lore raw

PATCH 3/6 ASoC: tas2770: Set regcache when shutting down and waking device

In reply to Dan Murphy

Set the regcache to cache data and mark cache as dirty when the device is shutdown when suspend is called. When the device is woken up then sync the cache and set to not caching the data.

---
 sound/soc/codecs/tas2770.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
sound/soc/codecs/tas2770.c +10 -4
index 9f7363927c50..c42e653cd653 100644
@@ -82,14 +82,20 @@ static int tas2770_codec_suspend(struct snd_soc_component *component)
 	struct tas2770_priv *tas2770 = snd_soc_component_get_drvdata(component);
 	int ret = 0;
 
+	regcache_cache_only(tas2770->regmap, true);
+	regcache_mark_dirty(tas2770->regmap);
+
 	if (tas2770->sdz_gpio) {
 		gpiod_set_value_cansleep(tas2770->sdz_gpio, 0);
 	} else {
 		ret = snd_soc_component_update_bits(component, TAS2770_PWR_CTRL,
 						    TAS2770_PWR_CTRL_MASK,
 						    TAS2770_PWR_CTRL_SHUTDOWN);
-		if (ret < 0)
+		if (ret < 0) {
+			regcache_cache_only(tas2770->regmap, false);
+			regcache_sync(tas2770->regmap);
 			return ret;
+		}
 
 		ret = 0;
 	}
@@ -110,11 +116,11 @@ static int tas2770_codec_resume(struct snd_soc_component *component)
 						    TAS2770_PWR_CTRL_ACTIVE);
 		if (ret < 0)
 			return ret;
-
-		ret = 0;
 	}
 
-	return ret;
+	regcache_cache_only(tas2770->regmap, false);
+
+	return regcache_sync(tas2770->regmap);
 }
 #else
 #define tas2770_codec_suspend NULL
Signature · 1 line
2.28.0
author
#3 lore raw

PATCH 4/6 dt-bindings: tas2770: Remove ti,asi-format property

In reply to Dan Murphy

Remove the property ti,asi-format as the driver only reads this property and performs no action against it.

---
 Documentation/devicetree/bindings/sound/tas2770.yaml | 7 -------
 1 file changed, 7 deletions(-)
Documentation/devicetree/bindings/sound/tas2770.yaml +0 -7
index 9fdf614add55..aa8c74575ac9 100644
@@ -43,13 +43,6 @@ properties:
     $ref: /schemas/types.yaml#/definitions/uint32
     description: TDM TX voltage sense time slot.
 
-  ti,asi-format:
-    $ref: /schemas/types.yaml#/definitions/uint32
-    description: Sets TDM RX capture edge.
-    enum:
-      - 0 # Rising edge
-      - 1 # Falling edge
-
   '#sound-dai-cells':
     const: 1
 
Signature · 1 line
2.28.0
maintainer
#4 lore raw

Re: [PATCH 4/6] dt-bindings: tas2770: Remove ti,asi-format property

Quoted 2 lines · Dan Murphy

Remove the property ti,asi-format as the driver only reads this property and performs no action against it.

We should probably leave the property as documented and move it to deprecated rather than delete the documentation entirely.

author
#5 lore raw

Re: [PATCH 4/6] dt-bindings: tas2770: Remove ti,asi-format property

Mark

Quoted 5 lines · Mark Brown
Quoted 2 lines · Dan Murphy

Remove the property ti,asi-format as the driver only reads this property and performs no action against it.

We should probably leave the property as documented and move it to deprecated rather than delete the documentation entirely.

I mulled this over to just deprecate the property and I know removing these ABIs are not highly accepted.

But the support code for it was incomplete and if a user had it populated in the DT and we removed the support then there will be no functional change.

This property was supposed to set the RX edge SBCLK detection but this is done based on the dai format.

So removing the property will have no affect on the users.

Dan

author
#6 lore raw

PATCH 5/6 ASoC: tas2770: Remove ti,asi-format code

In reply to Dan Murphy

Remove the code to support the asi-format binding property. The code does nothing except read the property and set a variable. No additional action is taken except to reset the variable. The property is supposed to set the rising or falling RX edge detection of the SBCLK but this edge detection is done by checking the DAI_FMT_INV_MASK.

---
 sound/soc/codecs/tas2770.c | 11 -----------
 sound/soc/codecs/tas2770.h |  1 -
 2 files changed, 12 deletions(-)
sound/soc/codecs/tas2770.c +0 -11
index c42e653cd653..c7a6f7e8200c 100644
@@ -391,8 +391,6 @@ static int tas2770_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 	if (ret < 0)
 		return ret;
 
-	tas2770->asi_format = fmt;
-
 	return 0;
 }
 
@@ -646,15 +644,6 @@ static int tas2770_parse_dt(struct device *dev, struct tas2770_priv *tas2770)
 {
 	int rc = 0;
 
-	rc = fwnode_property_read_u32(dev->fwnode, "ti,asi-format",
-				      &tas2770->asi_format);
-	if (rc) {
-		dev_info(tas2770->dev, "Property %s is missing setting default slot\n",
-			 "ti,asi-format");
-
-		tas2770->asi_format = 0;
-	}
-
 	rc = fwnode_property_read_u32(dev->fwnode, "ti,imon-slot-no",
 				      &tas2770->i_sense_slot);
 	if (rc) {
sound/soc/codecs/tas2770.h +0 -1
index b3fc4a487033..856a7c5cff5a 100644
@@ -132,7 +132,6 @@ struct tas2770_priv {
 	struct regmap *regmap;
 	struct snd_soc_component *component;
 	int power_state;
-	int asi_format;
 	struct gpio_desc *reset_gpio;
 	struct gpio_desc *sdz_gpio;
 	int sampling_rate;
Signature · 1 line
2.28.0
author
#7 lore raw

PATCH 6/6 ASoC: tas2770: Remove unused variables

In reply to Dan Murphy

Remove unused variables in the private struct and the code as these variables are initially set and then there is no additional code utilizing these variables.

---
 sound/soc/codecs/tas2770.c | 11 -----------
 sound/soc/codecs/tas2770.h |  8 ++------
 2 files changed, 2 insertions(+), 17 deletions(-)
sound/soc/codecs/tas2770.c +0 -11
index c7a6f7e8200c..a91a0a31e74d 100644
@@ -249,8 +249,6 @@ static int tas2770_set_bitwidth(struct tas2770_priv *tas2770, int bitwidth)
 	if (ret < 0)
 		return ret;
 
-	tas2770->channel_size = bitwidth;
-
 	ret = snd_soc_component_update_bits(component, TAS2770_TDM_CFG_REG5,
 					    TAS2770_TDM_CFG_REG5_VSNS_MASK |
 					    TAS2770_TDM_CFG_REG5_50_MASK,
@@ -312,7 +310,6 @@ static int tas2770_set_samplerate(struct tas2770_priv *tas2770, int samplerate)
 	if (ret < 0)
 		return ret;
 
-	tas2770->sampling_rate = samplerate;
 	return 0;
 }
 
@@ -400,8 +397,6 @@ static int tas2770_set_dai_tdm_slot(struct snd_soc_dai *dai,
 				int slots, int slot_width)
 {
 	struct snd_soc_component *component = dai->component;
-	struct tas2770_priv *tas2770 =
-			snd_soc_component_get_drvdata(component);
 	int left_slot, right_slot;
 	int ret;
 
@@ -466,7 +461,6 @@ static int tas2770_set_dai_tdm_slot(struct snd_soc_dai *dai,
 	if (ret < 0)
 		return ret;
 
-	tas2770->slot_width = slot_width;
 	return 0;
 }
 
@@ -688,8 +682,6 @@ static int tas2770_i2c_probe(struct i2c_client *client,
 	i2c_set_clientdata(client, tas2770);
 	dev_set_drvdata(&client->dev, tas2770);
 
-	tas2770->power_state = TAS2770_POWER_SHUTDOWN;
-
 	tas2770->regmap = devm_regmap_init_i2c(client, &tas2770_i2c_regmap);
 	if (IS_ERR(tas2770->regmap)) {
 		result = PTR_ERR(tas2770->regmap);
@@ -716,9 +708,6 @@ static int tas2770_i2c_probe(struct i2c_client *client,
 		}
 	}
 
-	tas2770->channel_size = 0;
-	tas2770->slot_width = 0;
-
 	result = tas2770_register_codec(tas2770);
 	if (result)
 		dev_err(tas2770->dev, "Register codec failed.\n");
sound/soc/codecs/tas2770.h +2 -6
index 856a7c5cff5a..d156666bcc55 100644
@@ -128,15 +128,11 @@
 #define ERROR_CLASSD_PWR    BIT(5)
 
 struct tas2770_priv {
-	struct device *dev;
-	struct regmap *regmap;
 	struct snd_soc_component *component;
-	int power_state;
 	struct gpio_desc *reset_gpio;
 	struct gpio_desc *sdz_gpio;
-	int sampling_rate;
-	int channel_size;
-	int slot_width;
+	struct regmap *regmap;
+	struct device *dev;
 	int v_sense_slot;
 	int i_sense_slot;
 };
Signature · 1 line
2.28.0
maintainer
#8 lore raw
In reply to Dan Murphy
Quoted 2 lines · Dan Murphy

Add the shutdown-gpios property to the yaml to define the GPIO that can be used to place the device in shutdown mode or wake the device up.

Applied to

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

Thanks!

[1/5] dt-bindings: tas2770: Add shutdown gpio property

      commit: 29d7b36ce98eb1bfba2c5c9b2ea0d58ff778a2d4
[2/5] ASoC: tas2770: Add shutdown capability via a GPIO
      commit: 5d0b9dfe0de26b8c4242145cbf7de3a5a2e98293
[3/5] ASoC: tas2770: Set regcache when shutting down and waking device
      commit: c0a30e2e07e35f219666788c8549156eb8d74105
[4/5] ASoC: tas2770: Remove ti,asi-format code
      commit: dd7d9052064b4bda94a89dbc1618927319602366
[5/5] ASoC: tas2770: Remove unused variables
      commit: 3121420cf9b4db7f2bafcdc0e562f60779bf365d

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