All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements
@ 2015-06-04 13:04 Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 01/23] ASoC: tas2552: Make the enable-gpio really optional Peter Ujfalusi
                   ` (23 more replies)
  0 siblings, 24 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

Hi,

Changes since v01:
- missing patch found. It was merged with the previous patch while fixing
  checkpatch errors (patch 19 got squashed to patch 18)
- Sorry for this.

I have used the TAS2552-EVM to verify that my setup is in working condition for
a work on other audio product.
During the bringup of the EVM I have faced some issues and limitation with the
driver. The result is this series against the tas2552 driver.

Notable changes:
- Fixes for kernel crashes
- The enable-gpio was not optional as it was documented in the DTS
- Register bit definitions were not correct in several places
- Adding recommended startup/stop sequence
- Handling of sample formats the driver claims to support
- PLL configuration fixes and reference clock selection
- TDM support
- Gain control fix and control to select DIN source

Regards,
Peter
---
Peter Ujfalusi (23):
  ASoC: tas2552: Make the enable-gpio really optional
  ASoC: tas2552: Fix kernel crash when the codec is loaded but not part
    of a card
  ASoC: tas2552: Fix kernel crash caused by wrong kcontrol entry
  ASoC: tas2552: Correct PDM configuration register bit definitions
  ASoC: tas2552: Correct CFG1 register bit definitions
  ASoC: tas2552: Simplify the tas2552_mute function
  ASoC: tas2552: Simplify and reverse the functionality of
    tas2552_sw_shutdown
  ASoC: tas2552: Rename mclk parameter to pll_clkin to match with the
    datasheet
  DT/sound: bindings header file for tas2552 codec
  ASoC: tas2552: Add support for pll and pdm source clock selection
  ASoC: tas2552: Correct dai format support
  ASoC: tas2552: Correct and clean up data format and BCLK/WCLK
    direction
  ASoC: tas2552: Add TDM support
  ASoC: tas2552: Clean up the Digital - Analog DAPM route definition
  ASoC: tas2552: Correct the Speaker Driver Playback Volume (PGA_GAIN)
  ASoC: tas2552: Implement startup/stop sequence as per TRM
  ASoC: tas2552: Add support for word length configuration
  ASoC: tas2552: Configure the WCLK frequency based on the stream
  ASoC: tas2552: Correct the PLL configuration
  ASoC: tas2552: Add control for selecting DIN source
  ASoC: tas2552: Correct Output Data register usage
  ASoC: tas2552: Correct Boost Auto-Pass Through Control register usage
  ASoC: tas2552: Code, define alignment changes for uniformity

 include/dt-bindings/sound/tas2552.h |  18 ++
 sound/soc/codecs/tas2552.c          | 435 +++++++++++++++++++++++++++---------
 sound/soc/codecs/tas2552.h          | 149 ++++++------
 3 files changed, 431 insertions(+), 171 deletions(-)
 create mode 100644 include/dt-bindings/sound/tas2552.h

-- 
2.4.2

^ permalink raw reply	[flat|nested] 34+ messages in thread

* [PATCH v2 01/23] ASoC: tas2552: Make the enable-gpio really optional
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 02/23] ASoC: tas2552: Fix kernel crash when the codec is loaded but not part of a card Peter Ujfalusi
                   ` (22 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

Do not fail the probe if the enable-gpio is not specifiedbut handle
deferred probe case.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index dfb4ff5cc9ea..ff82f46ba504 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -486,8 +486,12 @@ static int tas2552_probe(struct i2c_client *client,
 		return -ENOMEM;
 
 	data->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW);
-	if (IS_ERR(data->enable_gpio))
-		return PTR_ERR(data->enable_gpio);
+	if (IS_ERR(data->enable_gpio)) {
+		if (PTR_ERR(data->enable_gpio) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+
+		data->enable_gpio = NULL;;
+	}
 
 	data->tas2552_client = client;
 	data->regmap = devm_regmap_init_i2c(client, &tas2552_regmap_config);
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 02/23] ASoC: tas2552: Fix kernel crash when the codec is loaded but not part of a card
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 01/23] ASoC: tas2552: Make the enable-gpio really optional Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-04 16:25   ` Mark Brown
  2015-06-04 16:50   ` Mark Brown
  2015-06-04 13:04 ` [PATCH v2 03/23] ASoC: tas2552: Fix kernel crash caused by wrong kcontrol entry Peter Ujfalusi
                   ` (21 subsequent siblings)
  23 siblings, 2 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

If the card is not part of any card the tas_data->codec is NULL since it is
set only during snd_soc_codec_driver.probe, which is not yet called.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index ff82f46ba504..df89947f1032 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -120,6 +120,9 @@ static void tas2552_sw_shutdown(struct tas2552_data *tas_data, int sw_shutdown)
 {
 	u8 cfg1_reg;
 
+	if (!tas_data->codec)
+		return;
+
 	if (sw_shutdown)
 		cfg1_reg = 0;
 	else
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 03/23] ASoC: tas2552: Fix kernel crash caused by wrong kcontrol entry
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 01/23] ASoC: tas2552: Make the enable-gpio really optional Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 02/23] ASoC: tas2552: Fix kernel crash when the codec is loaded but not part of a card Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 04/23] ASoC: tas2552: Correct PDM configuration register bit definitions Peter Ujfalusi
                   ` (20 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

SOC_DAPM_SINGLE("Playback AMP", ..) should not be under kcontrols. It
causes kernel crash (NULL pointer) when the mixers are listed.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index df89947f1032..9954bd4c14f3 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -338,7 +338,6 @@ static DECLARE_TLV_DB_SCALE(dac_tlv, -7, 100, 24);
 static const struct snd_kcontrol_new tas2552_snd_controls[] = {
 	SOC_SINGLE_TLV("Speaker Driver Playback Volume",
 			 TAS2552_PGA_GAIN, 0, 0x1f, 1, dac_tlv),
-	SOC_DAPM_SINGLE("Playback AMP", SND_SOC_NOPM, 0, 1, 0),
 };
 
 static const struct reg_default tas2552_init_regs[] = {
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 04/23] ASoC: tas2552: Correct PDM configuration register bit definitions
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (2 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 03/23] ASoC: tas2552: Fix kernel crash caused by wrong kcontrol entry Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 05/23] ASoC: tas2552: Correct CFG1 " Peter Ujfalusi
                   ` (19 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

The PDM clock can be selected via bit0-1.
PDM_DATA_ES bit is at bit2.

The code were trying to select BCLK as PDM reference clock but instead
it was selecting PLL and set the DATA_ES bit to 1.
Selecting the PLL output as reference clock as default does make sense,
but the driver should not change the PDM data edge.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c |  2 +-
 sound/soc/codecs/tas2552.h | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index 9954bd4c14f3..07a0ec03905d 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -376,7 +376,7 @@ static int tas2552_codec_probe(struct snd_soc_codec *codec)
 				TAS2552_DIN_SRC_SEL_AVG_L_R | TAS2552_88_96KHZ);
 	snd_soc_write(codec, TAS2552_DOUT, TAS2552_PDM_DATA_I);
 	snd_soc_write(codec, TAS2552_OUTPUT_DATA, TAS2552_PDM_DATA_V_I | 0x8);
-	snd_soc_write(codec, TAS2552_PDM_CFG, TAS2552_PDM_BCLK_SEL);
+	snd_soc_write(codec, TAS2552_PDM_CFG, TAS2552_PDM_CLK_SEL_PLL);
 	snd_soc_write(codec, TAS2552_BOOST_PT_CTRL, TAS2552_APT_DELAY_200 |
 				TAS2552_APT_THRESH_2_1_7);
 
diff --git a/sound/soc/codecs/tas2552.h b/sound/soc/codecs/tas2552.h
index 6cea8f31bf88..938d90f1cab9 100644
--- a/sound/soc/codecs/tas2552.h
+++ b/sound/soc/codecs/tas2552.h
@@ -99,12 +99,12 @@
 #define TAS2552_PDM_DATA_V_I	(0x11 << 6)
 
 /* PDM CFG Register */
-#define TAS2552_PDM_DATA_ES_RISE 0x4
-
-#define TAS2552_PDM_PLL_CLK_SEL 0x00
-#define TAS2552_PDM_IV_CLK_SEL	(1 << 1)
-#define TAS2552_PDM_BCLK_SEL	(1 << 2)
-#define TAS2552_PDM_MCLK_SEL	(1 << 3)
+#define TAS2552_PDM_CLK_SEL_PLL		(0x0 << 0)
+#define TAS2552_PDM_CLK_SEL_IVCLKIN	(0x1 << 0)
+#define TAS2552_PDM_CLK_SEL_BCLK	(0x2 << 0)
+#define TAS2552_PDM_CLK_SEL_MCLK	(0x3 << 0)
+#define TAS2552_PDM_CLK_SEL_MASK	TAS2552_PDM_CLK_SEL_MCLK
+#define TAS2552_PDM_DATA_ES	 	(1 << 2)
 
 /* Boost pass-through register */
 #define TAS2552_APT_DELAY_50	0x00
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 05/23] ASoC: tas2552: Correct CFG1 register bit definitions
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (3 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 04/23] ASoC: tas2552: Correct PDM configuration register bit definitions Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 06/23] ASoC: tas2552: Simplify the tas2552_mute function Peter Ujfalusi
                   ` (18 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

Remove the _MASK postfix of the bit definitions, collect the CFG1 bit
definition in one place and correct the bit shifts at the same time.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c | 14 +++++++-------
 sound/soc/codecs/tas2552.h | 17 ++++++++---------
 2 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index 07a0ec03905d..681b868a9e8c 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -126,10 +126,10 @@ static void tas2552_sw_shutdown(struct tas2552_data *tas_data, int sw_shutdown)
 	if (sw_shutdown)
 		cfg1_reg = 0;
 	else
-		cfg1_reg = TAS2552_SWS_MASK;
+		cfg1_reg = TAS2552_SWS;
 
-	snd_soc_update_bits(tas_data->codec, TAS2552_CFG_1,
-						 TAS2552_SWS_MASK, cfg1_reg);
+	snd_soc_update_bits(tas_data->codec, TAS2552_CFG_1, TAS2552_SWS,
+			    cfg1_reg);
 }
 #endif
 
@@ -258,11 +258,11 @@ static int tas2552_mute(struct snd_soc_dai *dai, int mute)
 	struct snd_soc_codec *codec = dai->codec;
 
 	if (mute)
-		cfg1_reg = TAS2552_MUTE_MASK;
+		cfg1_reg = TAS2552_MUTE;
 	else
-		cfg1_reg = ~TAS2552_MUTE_MASK;
+		cfg1_reg = ~TAS2552_MUTE;
 
-	snd_soc_update_bits(codec, TAS2552_CFG_1, TAS2552_MUTE_MASK, cfg1_reg);
+	snd_soc_update_bits(codec, TAS2552_CFG_1, TAS2552_MUTE, cfg1_reg);
 
 	return 0;
 }
@@ -370,7 +370,7 @@ static int tas2552_codec_probe(struct snd_soc_codec *codec)
 		goto probe_fail;
 	}
 
-	snd_soc_write(codec, TAS2552_CFG_1, TAS2552_MUTE_MASK |
+	snd_soc_write(codec, TAS2552_CFG_1, TAS2552_MUTE |
 				TAS2552_PLL_SRC_BCLK);
 	snd_soc_write(codec, TAS2552_CFG_3, TAS2552_I2S_OUT_SEL |
 				TAS2552_DIN_SRC_SEL_AVG_L_R | TAS2552_88_96KHZ);
diff --git a/sound/soc/codecs/tas2552.h b/sound/soc/codecs/tas2552.h
index 938d90f1cab9..0725befb4c41 100644
--- a/sound/soc/codecs/tas2552.h
+++ b/sound/soc/codecs/tas2552.h
@@ -45,10 +45,14 @@
 #define TAS2552_MAX_REG			0x20
 
 /* CFG1 Register Masks */
-#define TAS2552_MUTE_MASK		(1 << 2)
-#define TAS2552_SWS_MASK		(1 << 1)
-#define TAS2552_WCLK_MASK		0x07
-#define TAS2552_CLASSD_EN_MASK	(1 << 7)
+#define TAS2552_DEV_RESET		(1 << 0)
+#define TAS2552_SWS			(1 << 1)
+#define TAS2552_MUTE			(1 << 2)
+#define TAS2552_PLL_SRC_MCLK		(0x0 << 4)
+#define TAS2552_PLL_SRC_BCLK		(0x1 << 4)
+#define TAS2552_PLL_SRC_IVCLKIN		(0x2 << 4)
+#define TAS2552_PLL_SRC_1_8_FIXED 	(0x3 << 4)
+#define TAS2552_PLL_SRC_MASK	 	TAS2552_PLL_SRC_1_8_FIXED
 
 /* CFG2 Register Masks */
 #define TAS2552_CLASSD_EN		(1 << 7)
@@ -68,11 +72,6 @@
 #define TAS2552_DAIFMT_RIGHT_J		(1 << 4)
 #define TAS2552_DAIFMT_LEFT_J		(0x11 << 3)
 
-#define TAS2552_PLL_SRC_MCLK	0x00
-#define TAS2552_PLL_SRC_BCLK	(1 << 3)
-#define TAS2552_PLL_SRC_IVCLKIN	(1 << 4)
-#define TAS2552_PLL_SRC_1_8_FIXED (0x11 << 3)
-
 #define TAS2552_DIN_SRC_SEL_MUTED	0x00
 #define TAS2552_DIN_SRC_SEL_LEFT	(1 << 4)
 #define TAS2552_DIN_SRC_SEL_RIGHT	(1 << 5)
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 06/23] ASoC: tas2552: Simplify the tas2552_mute function
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (4 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 05/23] ASoC: tas2552: Correct CFG1 " Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 07/23] ASoC: tas2552: Simplify and reverse the functionality of tas2552_sw_shutdown Peter Ujfalusi
                   ` (17 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

Initialize the cfg1_reg to 0 and set the mute bit only when it is needed.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index 681b868a9e8c..2d52a397161d 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -254,13 +254,11 @@ static int tas2552_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
 
 static int tas2552_mute(struct snd_soc_dai *dai, int mute)
 {
-	u8 cfg1_reg;
+	u8 cfg1_reg = 0;
 	struct snd_soc_codec *codec = dai->codec;
 
 	if (mute)
-		cfg1_reg = TAS2552_MUTE;
-	else
-		cfg1_reg = ~TAS2552_MUTE;
+		cfg1_reg |= TAS2552_MUTE;
 
 	snd_soc_update_bits(codec, TAS2552_CFG_1, TAS2552_MUTE, cfg1_reg);
 
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 07/23] ASoC: tas2552: Simplify and reverse the functionality of tas2552_sw_shutdown
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (5 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 06/23] ASoC: tas2552: Simplify the tas2552_mute function Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 08/23] ASoC: tas2552: Rename mclk parameter to pll_clkin to match with the datasheet Peter Ujfalusi
                   ` (16 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

The function name and parameters of:
tas2552_sw_shutdown(struct tas2552_data *tas_data, int sw_shutdown)

implies that if sw_shutdown is 1 we should be entering to the software
shutdown mode.

The code can be simplified as well within the function.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index 2d52a397161d..61419e2f833b 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -118,14 +118,12 @@ static const struct snd_soc_dapm_route tas2552_audio_map[] = {
 #ifdef CONFIG_PM
 static void tas2552_sw_shutdown(struct tas2552_data *tas_data, int sw_shutdown)
 {
-	u8 cfg1_reg;
+	u8 cfg1_reg = 0;
 
 	if (!tas_data->codec)
 		return;
 
 	if (sw_shutdown)
-		cfg1_reg = 0;
-	else
 		cfg1_reg = TAS2552_SWS;
 
 	snd_soc_update_bits(tas_data->codec, TAS2552_CFG_1, TAS2552_SWS,
@@ -270,7 +268,7 @@ static int tas2552_runtime_suspend(struct device *dev)
 {
 	struct tas2552_data *tas2552 = dev_get_drvdata(dev);
 
-	tas2552_sw_shutdown(tas2552, 0);
+	tas2552_sw_shutdown(tas2552, 1);
 
 	regcache_cache_only(tas2552->regmap, true);
 	regcache_mark_dirty(tas2552->regmap);
@@ -288,7 +286,7 @@ static int tas2552_runtime_resume(struct device *dev)
 	if (tas2552->enable_gpio)
 		gpiod_set_value(tas2552->enable_gpio, 1);
 
-	tas2552_sw_shutdown(tas2552, 1);
+	tas2552_sw_shutdown(tas2552, 0);
 
 	regcache_cache_only(tas2552->regmap, false);
 	regcache_sync(tas2552->regmap);
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 08/23] ASoC: tas2552: Rename mclk parameter to pll_clkin to match with the datasheet
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (6 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 07/23] ASoC: tas2552: Simplify and reverse the functionality of tas2552_sw_shutdown Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-04 16:51   ` Mark Brown
  2015-06-04 13:04 ` [PATCH v2 09/23] DT/sound: bindings header file for tas2552 codec Peter Ujfalusi
                   ` (15 subsequent siblings)
  23 siblings, 1 reply; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

MCLK is one of the possible source for the pll_clkin frequency. Make this
clear by renaming the variable.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index 61419e2f833b..e29b29b279d9 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -75,7 +75,7 @@ struct tas2552_data {
 	struct regulator_bulk_data supplies[TAS2552_NUM_SUPPLIES];
 	struct gpio_desc *enable_gpio;
 	unsigned char regs[TAS2552_VBAT_DATA];
-	unsigned int mclk;
+	unsigned int pll_clkin;
 };
 
 /* Input mux controls */
@@ -141,13 +141,13 @@ static int tas2552_hw_params(struct snd_pcm_substream *substream,
 	int d;
 	u8 p, j;
 
-	if (!tas2552->mclk)
+	if (!tas2552->pll_clkin)
 		return -EINVAL;
 
 	snd_soc_update_bits(codec, TAS2552_CFG_2, TAS2552_PLL_ENABLE, 0);
 
-	if (tas2552->mclk == TAS2552_245MHZ_CLK ||
-		tas2552->mclk == TAS2552_225MHZ_CLK) {
+	if (tas2552->pll_clkin == TAS2552_245MHZ_CLK ||
+	    tas2552->pll_clkin == TAS2552_225MHZ_CLK) {
 		/* By pass the PLL configuration */
 		snd_soc_update_bits(codec, TAS2552_PLL_CTRL_2,
 				    TAS2552_PLL_BYPASS_MASK,
@@ -171,8 +171,8 @@ static int tas2552_hw_params(struct snd_pcm_substream *substream,
 			return -EINVAL;
 		}
 
-		j = (pll_clk * 2 * (1 << p)) / tas2552->mclk;
-		d = (pll_clk * 2 * (1 << p)) % tas2552->mclk;
+		j = (pll_clk * 2 * (1 << p)) / tas2552->pll_clkin;
+		d = (pll_clk * 2 * (1 << p)) % tas2552->pll_clkin;
 
 		snd_soc_update_bits(codec, TAS2552_PLL_CTRL_1,
 				TAS2552_PLL_J_MASK, j);
@@ -245,7 +245,7 @@ static int tas2552_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
 	struct snd_soc_codec *codec = dai->codec;
 	struct tas2552_data *tas2552 = dev_get_drvdata(codec->dev);
 
-	tas2552->mclk = freq;
+	tas2552->pll_clkin = freq;
 
 	return 0;
 }
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 09/23] DT/sound: bindings header file for tas2552 codec
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (7 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 08/23] ASoC: tas2552: Rename mclk parameter to pll_clkin to match with the datasheet Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-05 17:54   ` Mark Brown
  2015-06-04 13:04 ` [PATCH v2 10/23] ASoC: tas2552: Add support for pll and pdm source clock selection Peter Ujfalusi
                   ` (14 subsequent siblings)
  23 siblings, 1 reply; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

Binding header file for clock input selection and configuration.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 include/dt-bindings/sound/tas2552.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
 create mode 100644 include/dt-bindings/sound/tas2552.h

diff --git a/include/dt-bindings/sound/tas2552.h b/include/dt-bindings/sound/tas2552.h
new file mode 100644
index 000000000000..a4e1a079980b
--- /dev/null
+++ b/include/dt-bindings/sound/tas2552.h
@@ -0,0 +1,18 @@
+#ifndef __DT_TAS2552_H
+#define __DT_TAS2552_H
+
+#define TAS2552_PLL_CLKIN		(0)
+#define TAS2552_PDM_CLK			(1)
+#define TAS2552_CLK_TARGET_MASK		(1)
+
+#define TAS2552_PLL_CLKIN_MCLK		((0 << 1) | TAS2552_PLL_CLKIN)
+#define TAS2552_PLL_CLKIN_BCLK		((1 << 1) | TAS2552_PLL_CLKIN)
+#define TAS2552_PLL_CLKIN_IVCLKIN	((2 << 1) | TAS2552_PLL_CLKIN)
+#define TAS2552_PLL_CLKIN_1_8_FIXED	((3 << 1) | TAS2552_PLL_CLKIN)
+
+#define TAS2552_PDM_CLK_PLL		((0 << 1) | TAS2552_PDM_CLK)
+#define TAS2552_PDM_CLK_IVCLKIN		((1 << 1) | TAS2552_PDM_CLK)
+#define TAS2552_PDM_CLK_BCLK		((2 << 1) | TAS2552_PDM_CLK)
+#define TAS2552_PDM_CLK_MCLK		((3 << 1) | TAS2552_PDM_CLK)
+
+#endif /* __DT_TAS2552_H */
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 10/23] ASoC: tas2552: Add support for pll and pdm source clock selection
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (8 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 09/23] DT/sound: bindings header file for tas2552 codec Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 11/23] ASoC: tas2552: Correct dai format support Peter Ujfalusi
                   ` (13 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

Instead of hard wiring the PLL_CLKIN and PDM_CLK to be sourced from BCLK add
proper clock configuration via the set_dai_sysclk callback.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index e29b29b279d9..34495241c674 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -34,6 +34,7 @@
 #include <sound/soc-dapm.h>
 #include <sound/tlv.h>
 #include <sound/tas2552-plat.h>
+#include <dt-bindings/sound/tas2552.h>
 
 #include "tas2552.h"
 
@@ -76,6 +77,7 @@ struct tas2552_data {
 	struct gpio_desc *enable_gpio;
 	unsigned char regs[TAS2552_VBAT_DATA];
 	unsigned int pll_clkin;
+	unsigned int pdm_clk;
 };
 
 /* Input mux controls */
@@ -244,8 +246,33 @@ static int tas2552_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
 {
 	struct snd_soc_codec *codec = dai->codec;
 	struct tas2552_data *tas2552 = dev_get_drvdata(codec->dev);
+	u8 reg, mask, val;
+
+	switch (clk_id) {
+	case TAS2552_PLL_CLKIN_MCLK:
+	case TAS2552_PLL_CLKIN_BCLK:
+	case TAS2552_PLL_CLKIN_IVCLKIN:
+	case TAS2552_PLL_CLKIN_1_8_FIXED:
+		mask = TAS2552_PLL_SRC_MASK;
+		val = (clk_id << 3) & mask; /* bit 4:5 in the register */
+		reg = TAS2552_CFG_1;
+		tas2552->pll_clkin = freq;
+		break;
+	case TAS2552_PDM_CLK_PLL:
+	case TAS2552_PDM_CLK_IVCLKIN:
+	case TAS2552_PDM_CLK_BCLK:
+	case TAS2552_PDM_CLK_MCLK:
+		mask = TAS2552_PDM_CLK_SEL_MASK;
+		val = (clk_id >> 1) & mask; /* bit 0:1 in the register */
+		reg = TAS2552_PDM_CFG;
+		tas2552->pdm_clk = freq;
+		break;
+	default:
+		dev_err(codec->dev, "Invalid clk id: %d\n", clk_id);
+		return -EINVAL;
+	}
 
-	tas2552->pll_clkin = freq;
+	snd_soc_update_bits(codec, reg, mask, val);
 
 	return 0;
 }
@@ -366,13 +393,11 @@ static int tas2552_codec_probe(struct snd_soc_codec *codec)
 		goto probe_fail;
 	}
 
-	snd_soc_write(codec, TAS2552_CFG_1, TAS2552_MUTE |
-				TAS2552_PLL_SRC_BCLK);
+	snd_soc_write(codec, TAS2552_CFG_1, TAS2552_MUTE);
 	snd_soc_write(codec, TAS2552_CFG_3, TAS2552_I2S_OUT_SEL |
 				TAS2552_DIN_SRC_SEL_AVG_L_R | TAS2552_88_96KHZ);
 	snd_soc_write(codec, TAS2552_DOUT, TAS2552_PDM_DATA_I);
 	snd_soc_write(codec, TAS2552_OUTPUT_DATA, TAS2552_PDM_DATA_V_I | 0x8);
-	snd_soc_write(codec, TAS2552_PDM_CFG, TAS2552_PDM_CLK_SEL_PLL);
 	snd_soc_write(codec, TAS2552_BOOST_PT_CTRL, TAS2552_APT_DELAY_200 |
 				TAS2552_APT_THRESH_2_1_7);
 
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 11/23] ASoC: tas2552: Correct dai format support
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (9 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 10/23] ASoC: tas2552: Add support for pll and pdm source clock selection Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 12/23] ASoC: tas2552: Correct and clean up data format and BCLK/WCLK direction Peter Ujfalusi
                   ` (12 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

DSP_A mode require one bit delay from the FS, DSP_B is without data delay.
When checking the requested format, also match the bit and fs inversion
flag along with the format since it is not possible to change inversion.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index 34495241c674..2f4c2b52a9fa 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -188,11 +188,14 @@ static int tas2552_hw_params(struct snd_pcm_substream *substream,
 	return 0;
 }
 
+#define TAS2552_DAI_FMT_MASK	(TAS2552_BIT_CLK_MASK | \
+				 TAS2552_WORD_CLK_MASK | \
+				 TAS2552_DATA_FORMAT_MASK)
 static int tas2552_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 {
 	struct snd_soc_codec *codec = dai->codec;
+	u8 delay = 0;
 	u8 serial_format;
-	u8 serial_control_mask;
 
 	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
 	case SND_SOC_DAIFMT_CBS_CFS:
@@ -212,19 +215,19 @@ static int tas2552_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 		return -EINVAL;
 	}
 
-	serial_control_mask = TAS2552_BIT_CLK_MASK | TAS2552_WORD_CLK_MASK;
-
-	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
-	case SND_SOC_DAIFMT_I2S:
-		serial_format &= TAS2552_DAIFMT_I2S_MASK;
+	switch (fmt & (SND_SOC_DAIFMT_FORMAT_MASK |
+		       SND_SOC_DAIFMT_INV_MASK)) {
+	case (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF):
 		break;
-	case SND_SOC_DAIFMT_DSP_A:
+	case (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF):
+		delay = 1;
+	case (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF):
 		serial_format |= TAS2552_DAIFMT_DSP;
 		break;
-	case SND_SOC_DAIFMT_RIGHT_J:
+	case (SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_NB_NF):
 		serial_format |= TAS2552_DAIFMT_RIGHT_J;
 		break;
-	case SND_SOC_DAIFMT_LEFT_J:
+	case (SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF):
 		serial_format |= TAS2552_DAIFMT_LEFT_J;
 		break;
 	default:
@@ -232,11 +235,9 @@ static int tas2552_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 		return -EINVAL;
 	}
 
-	if (fmt & SND_SOC_DAIFMT_FORMAT_MASK)
-		serial_control_mask |= TAS2552_DATA_FORMAT_MASK;
-
-	snd_soc_update_bits(codec, TAS2552_SER_CTRL_1, serial_control_mask,
-						serial_format);
+	snd_soc_update_bits(codec, TAS2552_SER_CTRL_1, TAS2552_DAI_FMT_MASK,
+			    serial_format);
+	snd_soc_write(codec, TAS2552_SER_CTRL_2, delay);
 
 	return 0;
 }
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 12/23] ASoC: tas2552: Correct and clean up data format and BCLK/WCLK direction
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (10 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 11/23] ASoC: tas2552: Correct dai format support Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 13/23] ASoC: tas2552: Add TDM support Peter Ujfalusi
                   ` (11 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

Use names from the datasheet for the definitions.
Correct the data format definitions since they were not correct.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c | 18 +++++++++---------
 sound/soc/codecs/tas2552.h | 17 ++++++++---------
 2 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index 2f4c2b52a9fa..7615d1bc5f5d 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -188,9 +188,9 @@ static int tas2552_hw_params(struct snd_pcm_substream *substream,
 	return 0;
 }
 
-#define TAS2552_DAI_FMT_MASK	(TAS2552_BIT_CLK_MASK | \
-				 TAS2552_WORD_CLK_MASK | \
-				 TAS2552_DATA_FORMAT_MASK)
+#define TAS2552_DAI_FMT_MASK	(TAS2552_BCLKDIR | \
+				 TAS2552_WCLKDIR | \
+				 TAS2552_DATAFORMAT_MASK)
 static int tas2552_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 {
 	struct snd_soc_codec *codec = dai->codec;
@@ -202,13 +202,13 @@ static int tas2552_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 		serial_format = 0x00;
 		break;
 	case SND_SOC_DAIFMT_CBS_CFM:
-		serial_format = TAS2552_WORD_CLK_MASK;
+		serial_format = TAS2552_WCLKDIR;
 		break;
 	case SND_SOC_DAIFMT_CBM_CFS:
-		serial_format = TAS2552_BIT_CLK_MASK;
+		serial_format = TAS2552_BCLKDIR;
 		break;
 	case SND_SOC_DAIFMT_CBM_CFM:
-		serial_format = (TAS2552_BIT_CLK_MASK | TAS2552_WORD_CLK_MASK);
+		serial_format = (TAS2552_BCLKDIR | TAS2552_WCLKDIR);
 		break;
 	default:
 		dev_vdbg(codec->dev, "DAI Format master is not found\n");
@@ -222,13 +222,13 @@ static int tas2552_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 	case (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF):
 		delay = 1;
 	case (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF):
-		serial_format |= TAS2552_DAIFMT_DSP;
+		serial_format |= TAS2552_DATAFORMAT_DSP;
 		break;
 	case (SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_NB_NF):
-		serial_format |= TAS2552_DAIFMT_RIGHT_J;
+		serial_format |= TAS2552_DATAFORMAT_RIGHT_J;
 		break;
 	case (SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF):
-		serial_format |= TAS2552_DAIFMT_LEFT_J;
+		serial_format |= TAS2552_DATAFORMAT_LEFT_J;
 		break;
 	default:
 		dev_vdbg(codec->dev, "DAI Format is not found\n");
diff --git a/sound/soc/codecs/tas2552.h b/sound/soc/codecs/tas2552.h
index 0725befb4c41..0a12b511e951 100644
--- a/sound/soc/codecs/tas2552.h
+++ b/sound/soc/codecs/tas2552.h
@@ -62,15 +62,14 @@
 #define TAS2552_LIM_EN			(1 << 2)
 #define TAS2552_IVSENSE_EN		(1 << 1)
 
-/* CFG3 Register Masks */
-#define TAS2552_WORD_CLK_MASK		(1 << 7)
-#define TAS2552_BIT_CLK_MASK		(1 << 6)
-#define TAS2552_DATA_FORMAT_MASK	(0x11 << 2)
-
-#define TAS2552_DAIFMT_I2S_MASK		0xf3
-#define TAS2552_DAIFMT_DSP			(1 << 3)
-#define TAS2552_DAIFMT_RIGHT_J		(1 << 4)
-#define TAS2552_DAIFMT_LEFT_J		(0x11 << 3)
+/* Serial Interface Control Register Masks */
+#define TAS2552_DATAFORMAT_I2S		(0x0 << 2)
+#define TAS2552_DATAFORMAT_DSP		(0x1 << 2)
+#define TAS2552_DATAFORMAT_RIGHT_J	(0x2 << 2)
+#define TAS2552_DATAFORMAT_LEFT_J	(0x3 << 2)
+#define TAS2552_DATAFORMAT_MASK		TAS2552_DATAFORMAT_LEFT_J
+#define TAS2552_BCLKDIR			(1 << 6)
+#define TAS2552_WCLKDIR			(1 << 7)
 
 #define TAS2552_DIN_SRC_SEL_MUTED	0x00
 #define TAS2552_DIN_SRC_SEL_LEFT	(1 << 4)
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 13/23] ASoC: tas2552: Add TDM support
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (11 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 12/23] ASoC: tas2552: Correct and clean up data format and BCLK/WCLK direction Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 14/23] ASoC: tas2552: Clean up the Digital - Analog DAPM route definition Peter Ujfalusi
                   ` (10 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

TDM support is achieved using DSP transfer mode and setting a programmable
offset which specifies where data begins with respect to the frame sync.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c | 59 ++++++++++++++++++++++++++++++++++++++++++----
 sound/soc/codecs/tas2552.h |  3 +++
 2 files changed, 58 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index 7615d1bc5f5d..432aa54fe707 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -78,6 +78,9 @@ struct tas2552_data {
 	unsigned char regs[TAS2552_VBAT_DATA];
 	unsigned int pll_clkin;
 	unsigned int pdm_clk;
+
+	unsigned int dai_fmt;
+	unsigned int tdm_delay;
 };
 
 /* Input mux controls */
@@ -191,10 +194,29 @@ static int tas2552_hw_params(struct snd_pcm_substream *substream,
 #define TAS2552_DAI_FMT_MASK	(TAS2552_BCLKDIR | \
 				 TAS2552_WCLKDIR | \
 				 TAS2552_DATAFORMAT_MASK)
+static int tas2552_prepare(struct snd_pcm_substream *substream,
+			   struct snd_soc_dai *dai)
+{
+	struct snd_soc_codec *codec = dai->codec;
+	struct tas2552_data *tas2552 = snd_soc_codec_get_drvdata(codec);
+	int delay = 0;
+
+	/* TDM slot selection only valid in DSP_A/_B mode */
+	if (tas2552->dai_fmt == SND_SOC_DAIFMT_DSP_A)
+		delay += (tas2552->tdm_delay + 1);
+	else if (tas2552->dai_fmt == SND_SOC_DAIFMT_DSP_B)
+		delay += tas2552->tdm_delay;
+
+	/* Configure data delay */
+	snd_soc_write(codec, TAS2552_SER_CTRL_2, delay);
+
+	return 0;
+}
+
 static int tas2552_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 {
 	struct snd_soc_codec *codec = dai->codec;
-	u8 delay = 0;
+	struct tas2552_data *tas2552 = dev_get_drvdata(codec->dev);
 	u8 serial_format;
 
 	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
@@ -220,7 +242,6 @@ static int tas2552_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 	case (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF):
 		break;
 	case (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF):
-		delay = 1;
 	case (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF):
 		serial_format |= TAS2552_DATAFORMAT_DSP;
 		break;
@@ -234,11 +255,10 @@ static int tas2552_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 		dev_vdbg(codec->dev, "DAI Format is not found\n");
 		return -EINVAL;
 	}
+	tas2552->dai_fmt = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
 
 	snd_soc_update_bits(codec, TAS2552_SER_CTRL_1, TAS2552_DAI_FMT_MASK,
 			    serial_format);
-	snd_soc_write(codec, TAS2552_SER_CTRL_2, delay);
-
 	return 0;
 }
 
@@ -278,6 +298,35 @@ static int tas2552_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
 	return 0;
 }
 
+static int tas2552_set_dai_tdm_slot(struct snd_soc_dai *dai,
+				    unsigned int tx_mask, unsigned int rx_mask,
+				    int slots, int slot_width)
+{
+	struct snd_soc_codec *codec = dai->codec;
+	struct tas2552_data *tas2552 = snd_soc_codec_get_drvdata(codec);
+	unsigned int lsb;
+
+	if (unlikely(!tx_mask)) {
+		dev_err(codec->dev, "tx masks need to be non 0\n");
+		return -EINVAL;
+	}
+
+	/* TDM based on DSP mode requires slots to be adjacent */
+	lsb = __ffs(tx_mask);
+	if ((lsb + 1) != __fls(tx_mask)) {
+		dev_err(codec->dev, "Invalid mask, slots must be adjacent\n");
+		return -EINVAL;
+	}
+
+	tas2552->tdm_delay = lsb * slot_width;
+
+	/* DOUT in high-impedance on inactive bit clocks */
+	snd_soc_update_bits(codec, TAS2552_DOUT,
+			    TAS2552_SDOUT_TRISTATE, TAS2552_SDOUT_TRISTATE);
+
+	return 0;
+}
+
 static int tas2552_mute(struct snd_soc_dai *dai, int mute)
 {
 	u8 cfg1_reg = 0;
@@ -330,8 +379,10 @@ static const struct dev_pm_ops tas2552_pm = {
 
 static struct snd_soc_dai_ops tas2552_speaker_dai_ops = {
 	.hw_params	= tas2552_hw_params,
+	.prepare	= tas2552_prepare,
 	.set_sysclk	= tas2552_set_dai_sysclk,
 	.set_fmt	= tas2552_set_dai_fmt,
+	.set_tdm_slot	= tas2552_set_dai_tdm_slot,
 	.digital_mute = tas2552_mute,
 };
 
diff --git a/sound/soc/codecs/tas2552.h b/sound/soc/codecs/tas2552.h
index 0a12b511e951..5bdc7eaaddea 100644
--- a/sound/soc/codecs/tas2552.h
+++ b/sound/soc/codecs/tas2552.h
@@ -62,6 +62,9 @@
 #define TAS2552_LIM_EN			(1 << 2)
 #define TAS2552_IVSENSE_EN		(1 << 1)
 
+/* DOUT Register Masks */
+#define TAS2552_SDOUT_TRISTATE		(1 << 2)
+
 /* Serial Interface Control Register Masks */
 #define TAS2552_DATAFORMAT_I2S		(0x0 << 2)
 #define TAS2552_DATAFORMAT_DSP		(0x1 << 2)
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 14/23] ASoC: tas2552: Clean up the Digital - Analog DAPM route definition
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (12 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 13/23] ASoC: tas2552: Add TDM support Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 15/23] ASoC: tas2552: Correct the Speaker Driver Playback Volume (PGA_GAIN) Peter Ujfalusi
                   ` (9 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

The strings should be: 'static const char * const tas2552_input_texts[]'
SOC_DAPM_ENUM should have "Route" in place of xname and no need to have it
as an array.
Also align the parameters.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index 432aa54fe707..264df631b130 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -83,17 +83,15 @@ struct tas2552_data {
 	unsigned int tdm_delay;
 };
 
-/* Input mux controls */
-static const char *tas2552_input_texts[] = {
-	"Digital", "Analog"
-};
 
+/* Input mux controls */
+static const char * const tas2552_input_texts[] = {
+	"Digital", "Analog" };
 static SOC_ENUM_SINGLE_DECL(tas2552_input_mux_enum, TAS2552_CFG_3, 7,
 			    tas2552_input_texts);
 
-static const struct snd_kcontrol_new tas2552_input_mux_control[] = {
-	SOC_DAPM_ENUM("Input selection", tas2552_input_mux_enum)
-};
+static const struct snd_kcontrol_new tas2552_input_mux_control =
+	SOC_DAPM_ENUM("Route", tas2552_input_mux_enum);
 
 static const struct snd_soc_dapm_widget tas2552_dapm_widgets[] =
 {
@@ -101,7 +99,7 @@ static const struct snd_soc_dapm_widget tas2552_dapm_widgets[] =
 
 	/* MUX Controls */
 	SND_SOC_DAPM_MUX("Input selection", SND_SOC_NOPM, 0, 0,
-				tas2552_input_mux_control),
+			 &tas2552_input_mux_control),
 
 	SND_SOC_DAPM_AIF_IN("DAC IN", "DAC Playback", 0, SND_SOC_NOPM, 0, 0),
 	SND_SOC_DAPM_DAC("DAC", NULL, SND_SOC_NOPM, 0, 0),
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 15/23] ASoC: tas2552: Correct the Speaker Driver Playback Volume (PGA_GAIN)
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (13 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 14/23] ASoC: tas2552: Clean up the Digital - Analog DAPM route definition Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 16/23] ASoC: tas2552: Implement startup/stop sequence as per TRM Peter Ujfalusi
                   ` (8 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

The last parameter for DECLARE_TLV_DB_SCALE() is to tell if the gain will
be muted or not when it is set to raw 0. IN this case it is not muted.
The PGA_GAIN is in 0-4 bits in the register. Fix the offset in the
SOC_SINGLE_TLV() for this.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index 264df631b130..fe2e4d384a00 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -406,11 +406,11 @@ static struct snd_soc_dai_driver tas2552_dai[] = {
 /*
  * DAC digital volumes. From -7 to 24 dB in 1 dB steps
  */
-static DECLARE_TLV_DB_SCALE(dac_tlv, -7, 100, 24);
+static DECLARE_TLV_DB_SCALE(dac_tlv, -7, 100, 0);
 
 static const struct snd_kcontrol_new tas2552_snd_controls[] = {
 	SOC_SINGLE_TLV("Speaker Driver Playback Volume",
-			 TAS2552_PGA_GAIN, 0, 0x1f, 1, dac_tlv),
+			 TAS2552_PGA_GAIN, 0, 0x1f, 0, dac_tlv),
 };
 
 static const struct reg_default tas2552_init_regs[] = {
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 16/23] ASoC: tas2552: Implement startup/stop sequence as per TRM
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (14 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 15/23] ASoC: tas2552: Correct the Speaker Driver Playback Volume (PGA_GAIN) Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 17/23] ASoC: tas2552: Add support for word length configuration Peter Ujfalusi
                   ` (7 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

Certain sequence need to be followed in order to have smooth power up and
power down performance.
Execute this sequence via DAPM_POST widget.
Remove patching the RESERVED_0D register at probe time since it has to be
handled every time when we stop or start the amplifier.
In order to be able to execute the sequence at the correct time, the driver
need to request to ignore the pmdown time.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c | 44 ++++++++++++++++++++++++++++----------------
 1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index fe2e4d384a00..9c081344bd90 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -46,7 +46,7 @@ static struct reg_default tas2552_reg_defs[] = {
 	{TAS2552_PDM_CFG, 0x01},
 	{TAS2552_PGA_GAIN, 0x00},
 	{TAS2552_BOOST_PT_CTRL, 0x0f},
-	{TAS2552_RESERVED_0D, 0x00},
+	{TAS2552_RESERVED_0D, 0xbe},
 	{TAS2552_LIMIT_RATE_HYS, 0x08},
 	{TAS2552_CFG_2, 0xef},
 	{TAS2552_SER_CTRL_1, 0x00},
@@ -83,6 +83,29 @@ struct tas2552_data {
 	unsigned int tdm_delay;
 };
 
+static int tas2552_post_event(struct snd_soc_dapm_widget *w,
+			      struct snd_kcontrol *kcontrol, int event)
+{
+	struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
+
+	switch (event) {
+	case SND_SOC_DAPM_POST_PMU:
+		snd_soc_write(codec, TAS2552_RESERVED_0D, 0xc0);
+		snd_soc_update_bits(codec, TAS2552_LIMIT_RATE_HYS, (1 << 5),
+				    (1 << 5));
+		snd_soc_update_bits(codec, TAS2552_CFG_2, 1, 0);
+		snd_soc_update_bits(codec, TAS2552_CFG_1, TAS2552_SWS, 0);
+		break;
+	case SND_SOC_DAPM_POST_PMD:
+		snd_soc_update_bits(codec, TAS2552_CFG_1, TAS2552_SWS,
+				    TAS2552_SWS);
+		snd_soc_update_bits(codec, TAS2552_CFG_2, 1, 1);
+		snd_soc_update_bits(codec, TAS2552_LIMIT_RATE_HYS, (1 << 5), 0);
+		snd_soc_write(codec, TAS2552_RESERVED_0D, 0xbe);
+		break;
+	}
+	return 0;
+}
 
 /* Input mux controls */
 static const char * const tas2552_input_texts[] = {
@@ -105,6 +128,7 @@ static const struct snd_soc_dapm_widget tas2552_dapm_widgets[] =
 	SND_SOC_DAPM_DAC("DAC", NULL, SND_SOC_NOPM, 0, 0),
 	SND_SOC_DAPM_OUT_DRV("ClassD", TAS2552_CFG_2, 7, 0, NULL, 0),
 	SND_SOC_DAPM_SUPPLY("PLL", TAS2552_CFG_2, 3, 0, NULL, 0),
+	SND_SOC_DAPM_POST("Post Event", tas2552_post_event),
 
 	SND_SOC_DAPM_OUTPUT("OUT")
 };
@@ -413,10 +437,6 @@ static const struct snd_kcontrol_new tas2552_snd_controls[] = {
 			 TAS2552_PGA_GAIN, 0, 0x1f, 0, dac_tlv),
 };
 
-static const struct reg_default tas2552_init_regs[] = {
-	{ TAS2552_RESERVED_0D, 0xc0 },
-};
-
 static int tas2552_codec_probe(struct snd_soc_codec *codec)
 {
 	struct tas2552_data *tas2552 = snd_soc_codec_get_drvdata(codec);
@@ -443,7 +463,7 @@ static int tas2552_codec_probe(struct snd_soc_codec *codec)
 		goto probe_fail;
 	}
 
-	snd_soc_write(codec, TAS2552_CFG_1, TAS2552_MUTE);
+	snd_soc_update_bits(codec, TAS2552_CFG_1, TAS2552_MUTE, TAS2552_MUTE);
 	snd_soc_write(codec, TAS2552_CFG_3, TAS2552_I2S_OUT_SEL |
 				TAS2552_DIN_SRC_SEL_AVG_L_R | TAS2552_88_96KHZ);
 	snd_soc_write(codec, TAS2552_DOUT, TAS2552_PDM_DATA_I);
@@ -451,21 +471,11 @@ static int tas2552_codec_probe(struct snd_soc_codec *codec)
 	snd_soc_write(codec, TAS2552_BOOST_PT_CTRL, TAS2552_APT_DELAY_200 |
 				TAS2552_APT_THRESH_2_1_7);
 
-	ret = regmap_register_patch(tas2552->regmap, tas2552_init_regs,
-					    ARRAY_SIZE(tas2552_init_regs));
-	if (ret != 0) {
-		dev_err(codec->dev, "Failed to write init registers: %d\n",
-			ret);
-		goto patch_fail;
-	}
-
 	snd_soc_write(codec, TAS2552_CFG_2, TAS2552_BOOST_EN |
 				  TAS2552_APT_EN | TAS2552_LIM_EN);
 
 	return 0;
 
-patch_fail:
-	pm_runtime_put(codec->dev);
 probe_fail:
 	if (tas2552->enable_gpio)
 		gpiod_set_value(tas2552->enable_gpio, 0);
@@ -527,6 +537,8 @@ static struct snd_soc_codec_driver soc_codec_dev_tas2552 = {
 	.remove = tas2552_codec_remove,
 	.suspend =	tas2552_suspend,
 	.resume = tas2552_resume,
+	.ignore_pmdown_time = true,
+
 	.controls = tas2552_snd_controls,
 	.num_controls = ARRAY_SIZE(tas2552_snd_controls),
 	.dapm_widgets = tas2552_dapm_widgets,
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 17/23] ASoC: tas2552: Add support for word length configuration
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (15 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 16/23] ASoC: tas2552: Implement startup/stop sequence as per TRM Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 18/23] ASoC: tas2552: Configure the WCLK frequency based on the stream Peter Ujfalusi
                   ` (6 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

Configure the word length based on the params_width of the stream.
Also configure the clock per frame value which is used when tas2552 is bus
master.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c | 38 ++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/tas2552.h | 10 ++++++++++
 2 files changed, 48 insertions(+)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index 9c081344bd90..13b435f9a9b1 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -166,7 +166,45 @@ static int tas2552_hw_params(struct snd_pcm_substream *substream,
 	struct tas2552_data *tas2552 = dev_get_drvdata(codec->dev);
 	int sample_rate, pll_clk;
 	int d;
+	int cpf;
 	u8 p, j;
+	u8 ser_ctrl1_reg;
+
+	switch (params_width(params)) {
+	case 16:
+		ser_ctrl1_reg = TAS2552_WORDLENGTH_16BIT;
+		cpf = 32 + tas2552->tdm_delay;
+		break;
+	case 20:
+		ser_ctrl1_reg = TAS2552_WORDLENGTH_20BIT;
+		cpf = 64 + tas2552->tdm_delay;
+		break;
+	case 24:
+		ser_ctrl1_reg = TAS2552_WORDLENGTH_24BIT;
+		cpf = 64 + tas2552->tdm_delay;
+		break;
+	case 32:
+		ser_ctrl1_reg = TAS2552_WORDLENGTH_32BIT;
+		cpf = 64 + tas2552->tdm_delay;
+		break;
+	default:
+		dev_err(codec->dev, "Not supported sample size: %d\n",
+			params_width(params));
+		return -EINVAL;
+	}
+
+	if (cpf <= 32)
+		ser_ctrl1_reg |= TAS2552_CLKSPERFRAME_32;
+	else if (cpf <= 64)
+		ser_ctrl1_reg |= TAS2552_CLKSPERFRAME_64;
+	else if (cpf <= 128)
+		ser_ctrl1_reg |= TAS2552_CLKSPERFRAME_128;
+	else
+		ser_ctrl1_reg |= TAS2552_CLKSPERFRAME_256;
+
+	snd_soc_update_bits(codec, TAS2552_SER_CTRL_1,
+			    TAS2552_WORDLENGTH_MASK | TAS2552_CLKSPERFRAME_MASK,
+			    ser_ctrl1_reg);
 
 	if (!tas2552->pll_clkin)
 		return -EINVAL;
diff --git a/sound/soc/codecs/tas2552.h b/sound/soc/codecs/tas2552.h
index 5bdc7eaaddea..de0ab0d27520 100644
--- a/sound/soc/codecs/tas2552.h
+++ b/sound/soc/codecs/tas2552.h
@@ -66,11 +66,21 @@
 #define TAS2552_SDOUT_TRISTATE		(1 << 2)
 
 /* Serial Interface Control Register Masks */
+#define TAS2552_WORDLENGTH_16BIT	(0x0 << 0)
+#define TAS2552_WORDLENGTH_20BIT	(0x1 << 0)
+#define TAS2552_WORDLENGTH_24BIT	(0x2 << 0)
+#define TAS2552_WORDLENGTH_32BIT	(0x3 << 0)
+#define TAS2552_WORDLENGTH_MASK		TAS2552_WORDLENGTH_32BIT
 #define TAS2552_DATAFORMAT_I2S		(0x0 << 2)
 #define TAS2552_DATAFORMAT_DSP		(0x1 << 2)
 #define TAS2552_DATAFORMAT_RIGHT_J	(0x2 << 2)
 #define TAS2552_DATAFORMAT_LEFT_J	(0x3 << 2)
 #define TAS2552_DATAFORMAT_MASK		TAS2552_DATAFORMAT_LEFT_J
+#define TAS2552_CLKSPERFRAME_32		(0x0 << 4)
+#define TAS2552_CLKSPERFRAME_64		(0x1 << 4)
+#define TAS2552_CLKSPERFRAME_128	(0x2 << 4)
+#define TAS2552_CLKSPERFRAME_256	(0x3 << 4)
+#define TAS2552_CLKSPERFRAME_MASK	TAS2552_CLKSPERFRAME_256
 #define TAS2552_BCLKDIR			(1 << 6)
 #define TAS2552_WCLKDIR			(1 << 7)
 
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 18/23] ASoC: tas2552: Configure the WCLK frequency based on the stream
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (16 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 17/23] ASoC: tas2552: Add support for word length configuration Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 19/23] ASoC: tas2552: Correct the PLL configuration Peter Ujfalusi
                   ` (5 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

Instead of hard wiring the WCLK frequency at probe time do it runtime.
The hard wired 88_96KHz was not even setting the correct bits since it was
defined as (1 << 6) which will  change the I2S_OUT_SEL bit and will leave
the amplifier configured for 8KHz.
At the same time clean up and fix the CFG3 register bits.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c | 43 +++++++++++++++++++++++++++++++++++++++++--
 sound/soc/codecs/tas2552.h | 37 ++++++++++++++++++-------------------
 2 files changed, 59 insertions(+), 21 deletions(-)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index 13b435f9a9b1..891e2c529df3 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -168,7 +168,7 @@ static int tas2552_hw_params(struct snd_pcm_substream *substream,
 	int d;
 	int cpf;
 	u8 p, j;
-	u8 ser_ctrl1_reg;
+	u8 ser_ctrl1_reg, wclk_rate;
 
 	switch (params_width(params)) {
 	case 16:
@@ -206,6 +206,45 @@ static int tas2552_hw_params(struct snd_pcm_substream *substream,
 			    TAS2552_WORDLENGTH_MASK | TAS2552_CLKSPERFRAME_MASK,
 			    ser_ctrl1_reg);
 
+	switch (params_rate(params)) {
+	case 8000:
+		wclk_rate = TAS2552_WCLK_FREQ_8KHZ;
+		break;
+	case 11025:
+	case 12000:
+		wclk_rate = TAS2552_WCLK_FREQ_11_12KHZ;
+		break;
+	case 16000:
+		wclk_rate = TAS2552_WCLK_FREQ_16KHZ;
+		break;
+	case 22050:
+	case 24000:
+		wclk_rate = TAS2552_WCLK_FREQ_22_24KHZ;
+		break;
+	case 32000:
+		wclk_rate = TAS2552_WCLK_FREQ_32KHZ;
+		break;
+	case 44100:
+	case 48000:
+		wclk_rate = TAS2552_WCLK_FREQ_44_48KHZ;
+		break;
+	case 88200:
+	case 96000:
+		wclk_rate = TAS2552_WCLK_FREQ_88_96KHZ;
+		break;
+	case 176400:
+	case 192000:
+		wclk_rate = TAS2552_WCLK_FREQ_176_192KHZ;
+		break;
+	default:
+		dev_err(codec->dev, "Not supported sample rate: %d\n",
+			params_rate(params));
+		return -EINVAL;
+	}
+
+	snd_soc_update_bits(codec, TAS2552_CFG_3, TAS2552_WCLK_FREQ_MASK,
+			    wclk_rate);
+
 	if (!tas2552->pll_clkin)
 		return -EINVAL;
 
@@ -503,7 +542,7 @@ static int tas2552_codec_probe(struct snd_soc_codec *codec)
 
 	snd_soc_update_bits(codec, TAS2552_CFG_1, TAS2552_MUTE, TAS2552_MUTE);
 	snd_soc_write(codec, TAS2552_CFG_3, TAS2552_I2S_OUT_SEL |
-				TAS2552_DIN_SRC_SEL_AVG_L_R | TAS2552_88_96KHZ);
+					    TAS2552_DIN_SRC_SEL_AVG_L_R);
 	snd_soc_write(codec, TAS2552_DOUT, TAS2552_PDM_DATA_I);
 	snd_soc_write(codec, TAS2552_OUTPUT_DATA, TAS2552_PDM_DATA_V_I | 0x8);
 	snd_soc_write(codec, TAS2552_BOOST_PT_CTRL, TAS2552_APT_DELAY_200 |
diff --git a/sound/soc/codecs/tas2552.h b/sound/soc/codecs/tas2552.h
index de0ab0d27520..bbb820495516 100644
--- a/sound/soc/codecs/tas2552.h
+++ b/sound/soc/codecs/tas2552.h
@@ -62,6 +62,24 @@
 #define TAS2552_LIM_EN			(1 << 2)
 #define TAS2552_IVSENSE_EN		(1 << 1)
 
+/* CFG3 Register Masks */
+#define TAS2552_WCLK_FREQ_8KHZ		(0x0 << 0)
+#define TAS2552_WCLK_FREQ_11_12KHZ	(0x1 << 0)
+#define TAS2552_WCLK_FREQ_16KHZ		(0x2 << 0)
+#define TAS2552_WCLK_FREQ_22_24KHZ	(0x3 << 0)
+#define TAS2552_WCLK_FREQ_32KHZ		(0x4 << 0)
+#define TAS2552_WCLK_FREQ_44_48KHZ	(0x5 << 0)
+#define TAS2552_WCLK_FREQ_88_96KHZ	(0x6 << 0)
+#define TAS2552_WCLK_FREQ_176_192KHZ	(0x7 << 0)
+#define TAS2552_WCLK_FREQ_MASK		TAS2552_WCLK_FREQ_176_192KHZ
+#define TAS2552_DIN_SRC_SEL_MUTED	(0x0 << 3)
+#define TAS2552_DIN_SRC_SEL_LEFT	(0x1 << 3)
+#define TAS2552_DIN_SRC_SEL_RIGHT	(0x2 << 3)
+#define TAS2552_DIN_SRC_SEL_AVG_L_R	(0x3 << 3)
+#define TAS2552_PDM_IN_SEL		(1 << 5)
+#define TAS2552_I2S_OUT_SEL		(1 << 6)
+#define TAS2552_ANALOG_IN_SEL		(1 << 7)
+
 /* DOUT Register Masks */
 #define TAS2552_SDOUT_TRISTATE		(1 << 2)
 
@@ -84,25 +102,6 @@
 #define TAS2552_BCLKDIR			(1 << 6)
 #define TAS2552_WCLKDIR			(1 << 7)
 
-#define TAS2552_DIN_SRC_SEL_MUTED	0x00
-#define TAS2552_DIN_SRC_SEL_LEFT	(1 << 4)
-#define TAS2552_DIN_SRC_SEL_RIGHT	(1 << 5)
-#define TAS2552_DIN_SRC_SEL_AVG_L_R	(0x11 << 4)
-
-#define TAS2552_PDM_IN_SEL		(1 << 5)
-#define TAS2552_I2S_OUT_SEL		(1 << 6)
-#define TAS2552_ANALOG_IN_SEL	(1 << 7)
-
-/* CFG3 WCLK Dividers */
-#define TAS2552_8KHZ		0x00
-#define TAS2552_11_12KHZ	(1 << 1)
-#define TAS2552_16KHZ		(1 << 2)
-#define TAS2552_22_24KHZ	(1 << 3)
-#define TAS2552_32KHZ		(1 << 4)
-#define TAS2552_44_48KHZ	(1 << 5)
-#define TAS2552_88_96KHZ	(1 << 6)
-#define TAS2552_176_192KHZ	(1 << 7)
-
 /* OUTPUT_DATA register */
 #define TAS2552_PDM_DATA_I		0x00
 #define TAS2552_PDM_DATA_V		(1 << 6)
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 19/23] ASoC: tas2552: Correct the PLL configuration
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (17 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 18/23] ASoC: tas2552: Configure the WCLK frequency based on the stream Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-05  6:53   ` Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 20/23] ASoC: tas2552: Add control for selecting DIN source Peter Ujfalusi
                   ` (4 subsequent siblings)
  23 siblings, 1 reply; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

Do not restrict the sampling rate to 44.1/48KHz. The pll_clk clock should
be (sampling rate * 512) in all cases.
Correct the J.D calculation (the D part was incorrectly calculated).
Restore PLL enable status after we are done with the configuration.
Implement hardware constraint handling towards the pll_clkin:
if D != 0 (in J.D) then 1.1MHz <= pll_clkin <= 9.2MHz needs to be checked.
If the PLL setup does not met with this constraint, fall back to BCLK as
reference clock, if BCLK fails, use the internal 1.8MHz clock.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c | 141 ++++++++++++++++++++++++++++++---------------
 sound/soc/codecs/tas2552.h |   7 +--
 2 files changed, 96 insertions(+), 52 deletions(-)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index 891e2c529df3..01230395b61d 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -77,7 +77,9 @@ struct tas2552_data {
 	struct gpio_desc *enable_gpio;
 	unsigned char regs[TAS2552_VBAT_DATA];
 	unsigned int pll_clkin;
+	int pll_clk_id;
 	unsigned int pdm_clk;
+	int pdm_clk_id;
 
 	unsigned int dai_fmt;
 	unsigned int tdm_delay;
@@ -158,16 +160,93 @@ static void tas2552_sw_shutdown(struct tas2552_data *tas_data, int sw_shutdown)
 }
 #endif
 
+static int tas2552_setup_pll(struct snd_soc_codec *codec,
+			     struct snd_pcm_hw_params *params)
+{
+	struct tas2552_data *tas2552 = dev_get_drvdata(codec->dev);
+	bool bypass_pll = false;
+	unsigned int pll_clk = params_rate(params) * 512;
+	unsigned int pll_clkin = tas2552->pll_clkin;
+	u8 pll_enable;
+
+	if (!pll_clkin) {
+		if (tas2552->pll_clk_id != TAS2552_PLL_CLKIN_BCLK)
+			return -EINVAL;
+
+		pll_clkin = snd_soc_params_to_bclk(params);
+		pll_clkin += tas2552->tdm_delay;
+	}
+
+	pll_enable = snd_soc_read(codec, TAS2552_CFG_2) & TAS2552_PLL_ENABLE;
+	snd_soc_update_bits(codec, TAS2552_CFG_2, TAS2552_PLL_ENABLE, 0);
+
+	if (pll_clkin == pll_clk)
+		bypass_pll = true;
+
+	if (bypass_pll) {
+		/* By pass the PLL configuration */
+		snd_soc_update_bits(codec, TAS2552_PLL_CTRL_2,
+				    TAS2552_PLL_BYPASS, TAS2552_PLL_BYPASS);
+	} else {
+		/* Fill in the PLL control registers for J & D
+		 * pll_clk = (.5 * pll_clkin * J.D) / 2^p
+		 * Need to fill in J and D here based on incoming freq
+		 */
+		unsigned int d;
+		u8 j;
+		u8 pll_sel = (tas2552->pll_clk_id << 3) & TAS2552_PLL_SRC_MASK;
+		u8 p = snd_soc_read(codec, TAS2552_PLL_CTRL_1);
+
+		p = (p >> 7);
+
+recalc:
+		j = (pll_clk * 2 * (1 << p)) / pll_clkin;
+		d = (pll_clk * 2 * (1 << p)) % pll_clkin;
+		d /= (pll_clkin / 10000);
+
+		if (d && (pll_clkin < 512000 || pll_clkin > 9200000)) {
+			if (tas2552->pll_clk_id == TAS2552_PLL_CLKIN_BCLK) {
+				pll_clkin = 1800000;
+				pll_sel = (TAS2552_PLL_CLKIN_1_8_FIXED << 3) &
+							TAS2552_PLL_SRC_MASK;
+			} else {
+				pll_clkin = snd_soc_params_to_bclk(params);
+				pll_clkin += tas2552->tdm_delay;
+				pll_sel = (TAS2552_PLL_CLKIN_BCLK << 3) &
+							TAS2552_PLL_SRC_MASK;
+			}
+			goto recalc;
+		}
+
+		snd_soc_update_bits(codec, TAS2552_CFG_1, TAS2552_PLL_SRC_MASK,
+				    pll_sel);
+
+		snd_soc_update_bits(codec, TAS2552_PLL_CTRL_1,
+				    TAS2552_PLL_J_MASK, j);
+		snd_soc_write(codec, TAS2552_PLL_CTRL_2,
+			      (d >> 7) & TAS2552_PLL_D_UPPER_MASK);
+		snd_soc_write(codec, TAS2552_PLL_CTRL_3,
+			      d & TAS2552_PLL_D_LOWER_MASK);
+
+		/* PLL in use */
+		snd_soc_update_bits(codec, TAS2552_PLL_CTRL_2,
+				    TAS2552_PLL_BYPASS, 0);
+	}
+
+	/* Restore PLL status */
+	snd_soc_update_bits(codec, TAS2552_CFG_2, TAS2552_PLL_ENABLE,
+			    pll_enable);
+
+	return 0;
+}
+
 static int tas2552_hw_params(struct snd_pcm_substream *substream,
 			     struct snd_pcm_hw_params *params,
 			     struct snd_soc_dai *dai)
 {
 	struct snd_soc_codec *codec = dai->codec;
 	struct tas2552_data *tas2552 = dev_get_drvdata(codec->dev);
-	int sample_rate, pll_clk;
-	int d;
 	int cpf;
-	u8 p, j;
 	u8 ser_ctrl1_reg, wclk_rate;
 
 	switch (params_width(params)) {
@@ -245,49 +324,7 @@ static int tas2552_hw_params(struct snd_pcm_substream *substream,
 	snd_soc_update_bits(codec, TAS2552_CFG_3, TAS2552_WCLK_FREQ_MASK,
 			    wclk_rate);
 
-	if (!tas2552->pll_clkin)
-		return -EINVAL;
-
-	snd_soc_update_bits(codec, TAS2552_CFG_2, TAS2552_PLL_ENABLE, 0);
-
-	if (tas2552->pll_clkin == TAS2552_245MHZ_CLK ||
-	    tas2552->pll_clkin == TAS2552_225MHZ_CLK) {
-		/* By pass the PLL configuration */
-		snd_soc_update_bits(codec, TAS2552_PLL_CTRL_2,
-				    TAS2552_PLL_BYPASS_MASK,
-				    TAS2552_PLL_BYPASS);
-	} else {
-		/* Fill in the PLL control registers for J & D
-		 * PLL_CLK = (.5 * freq * J.D) / 2^p
-		 * Need to fill in J and D here based on incoming freq
-		 */
-		p = snd_soc_read(codec, TAS2552_PLL_CTRL_1);
-		p = (p >> 7);
-		sample_rate = params_rate(params);
-
-		if (sample_rate == 48000)
-			pll_clk = TAS2552_245MHZ_CLK;
-		else if (sample_rate == 44100)
-			pll_clk = TAS2552_225MHZ_CLK;
-		else {
-			dev_vdbg(codec->dev, "Substream sample rate is not found %i\n",
-					params_rate(params));
-			return -EINVAL;
-		}
-
-		j = (pll_clk * 2 * (1 << p)) / tas2552->pll_clkin;
-		d = (pll_clk * 2 * (1 << p)) % tas2552->pll_clkin;
-
-		snd_soc_update_bits(codec, TAS2552_PLL_CTRL_1,
-				TAS2552_PLL_J_MASK, j);
-		snd_soc_write(codec, TAS2552_PLL_CTRL_2,
-					(d >> 7) & TAS2552_PLL_D_UPPER_MASK);
-		snd_soc_write(codec, TAS2552_PLL_CTRL_3,
-				d & TAS2552_PLL_D_LOWER_MASK);
-
-	}
-
-	return 0;
+	return tas2552_setup_pll(codec, params);
 }
 
 #define TAS2552_DAI_FMT_MASK	(TAS2552_BCLKDIR | \
@@ -370,12 +407,21 @@ static int tas2552_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
 
 	switch (clk_id) {
 	case TAS2552_PLL_CLKIN_MCLK:
-	case TAS2552_PLL_CLKIN_BCLK:
 	case TAS2552_PLL_CLKIN_IVCLKIN:
+		if (freq < 512000 || freq > 24576000) {
+			/* out of range PLL_CLKIN, fall back to use BCLK */
+			dev_warn(codec->dev, "Out of range PLL_CLKIN: %u\n",
+				 freq);
+			clk_id = TAS2552_PLL_CLKIN_BCLK;
+			freq = 0;
+		}
+		/* fall through */
+	case TAS2552_PLL_CLKIN_BCLK:
 	case TAS2552_PLL_CLKIN_1_8_FIXED:
 		mask = TAS2552_PLL_SRC_MASK;
 		val = (clk_id << 3) & mask; /* bit 4:5 in the register */
 		reg = TAS2552_CFG_1;
+		tas2552->pll_clk_id = clk_id;
 		tas2552->pll_clkin = freq;
 		break;
 	case TAS2552_PDM_CLK_PLL:
@@ -385,6 +431,7 @@ static int tas2552_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
 		mask = TAS2552_PDM_CLK_SEL_MASK;
 		val = (clk_id >> 1) & mask; /* bit 0:1 in the register */
 		reg = TAS2552_PDM_CFG;
+		tas2552->pdm_clk_id = clk_id;
 		tas2552->pdm_clk = freq;
 		break;
 	default:
diff --git a/sound/soc/codecs/tas2552.h b/sound/soc/codecs/tas2552.h
index bbb820495516..f04d9e6db0aa 100644
--- a/sound/soc/codecs/tas2552.h
+++ b/sound/soc/codecs/tas2552.h
@@ -128,12 +128,9 @@
 #define TAS2552_APT_THRESH_2_1_7	(0x11 << 2)
 
 /* PLL Control Register */
-#define TAS2552_245MHZ_CLK			24576000
-#define TAS2552_225MHZ_CLK			22579200
-#define TAS2552_PLL_J_MASK			0x7f
+#define TAS2552_PLL_J_MASK		0x7f
 #define TAS2552_PLL_D_UPPER_MASK	0x3f
 #define TAS2552_PLL_D_LOWER_MASK	0xff
-#define TAS2552_PLL_BYPASS_MASK		0x80
-#define TAS2552_PLL_BYPASS			0x80
+#define TAS2552_PLL_BYPASS		(1 << 7)
 
 #endif
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 20/23] ASoC: tas2552: Add control for selecting DIN source
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (18 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 19/23] ASoC: tas2552: Correct the PLL configuration Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 21/23] ASoC: tas2552: Correct Output Data register usage Peter Ujfalusi
                   ` (3 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

'DIN source' enum can be used to select the DIN Source (muted, left, right
or average of left and right channels).

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index 01230395b61d..64abc932732d 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -556,9 +556,20 @@ static struct snd_soc_dai_driver tas2552_dai[] = {
  */
 static DECLARE_TLV_DB_SCALE(dac_tlv, -7, 100, 0);
 
+static const char * const tas2552_din_source_select[] = {
+	"Muted",
+	"Left",
+	"Right",
+	"Left + Right average",
+};
+static SOC_ENUM_SINGLE_DECL(tas2552_din_source_enum,
+			    TAS2552_CFG_3, 3,
+			    tas2552_din_source_select);
+
 static const struct snd_kcontrol_new tas2552_snd_controls[] = {
 	SOC_SINGLE_TLV("Speaker Driver Playback Volume",
 			 TAS2552_PGA_GAIN, 0, 0x1f, 0, dac_tlv),
+	SOC_ENUM("DIN source", tas2552_din_source_enum),
 };
 
 static int tas2552_codec_probe(struct snd_soc_codec *codec)
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 21/23] ASoC: tas2552: Correct Output Data register usage
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (19 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 20/23] ASoC: tas2552: Add control for selecting DIN source Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 22/23] ASoC: tas2552: Correct Boost Auto-Pass Through Control " Peter Ujfalusi
                   ` (2 subsequent siblings)
  23 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

Do not write to DOUT Tristate register at probe time, specially not write
data which is defined to be used in Output Data Register.
Fix the defines for the Output Data Register and correct the register write
at probe time.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c |  5 +++--
 sound/soc/codecs/tas2552.h | 19 +++++++++++++++----
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index 64abc932732d..d9a637020214 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -601,8 +601,9 @@ static int tas2552_codec_probe(struct snd_soc_codec *codec)
 	snd_soc_update_bits(codec, TAS2552_CFG_1, TAS2552_MUTE, TAS2552_MUTE);
 	snd_soc_write(codec, TAS2552_CFG_3, TAS2552_I2S_OUT_SEL |
 					    TAS2552_DIN_SRC_SEL_AVG_L_R);
-	snd_soc_write(codec, TAS2552_DOUT, TAS2552_PDM_DATA_I);
-	snd_soc_write(codec, TAS2552_OUTPUT_DATA, TAS2552_PDM_DATA_V_I | 0x8);
+	snd_soc_write(codec, TAS2552_OUTPUT_DATA,
+		      TAS2552_PDM_DATA_SEL_V_I |
+		      TAS2552_R_DATA_OUT(TAS2552_DATA_OUT_V_DATA));
 	snd_soc_write(codec, TAS2552_BOOST_PT_CTRL, TAS2552_APT_DELAY_200 |
 				TAS2552_APT_THRESH_2_1_7);
 
diff --git a/sound/soc/codecs/tas2552.h b/sound/soc/codecs/tas2552.h
index f04d9e6db0aa..14d40ef645c4 100644
--- a/sound/soc/codecs/tas2552.h
+++ b/sound/soc/codecs/tas2552.h
@@ -103,10 +103,21 @@
 #define TAS2552_WCLKDIR			(1 << 7)
 
 /* OUTPUT_DATA register */
-#define TAS2552_PDM_DATA_I		0x00
-#define TAS2552_PDM_DATA_V		(1 << 6)
-#define TAS2552_PDM_DATA_I_V	(1 << 7)
-#define TAS2552_PDM_DATA_V_I	(0x11 << 6)
+#define TAS2552_DATA_OUT_I_DATA		(0x0)
+#define TAS2552_DATA_OUT_V_DATA		(0x1)
+#define TAS2552_DATA_OUT_VBAT_DATA	(0x2)
+#define TAS2552_DATA_OUT_VBOOST_DATA	(0x3)
+#define TAS2552_DATA_OUT_PGA_GAIN	(0x4)
+#define TAS2552_DATA_OUT_IV_DATA	(0x5)
+#define TAS2552_DATA_OUT_VBAT_VBOOST_GAIN	(0x6)
+#define TAS2552_DATA_OUT_DISABLED	(0x7)
+#define TAS2552_L_DATA_OUT(x)		((x) << 0)
+#define TAS2552_R_DATA_OUT(x)		((x) << 3)
+#define TAS2552_PDM_DATA_SEL_I		(0x0 << 6)
+#define TAS2552_PDM_DATA_SEL_V		(0x1 << 6)
+#define TAS2552_PDM_DATA_SEL_I_V	(0x2 << 6)
+#define TAS2552_PDM_DATA_SEL_V_I	(0x3 << 6)
+#define TAS2552_PDM_DATA_SEL_MASK	TAS2552_PDM_DATA_SEL_V_I
 
 /* PDM CFG Register */
 #define TAS2552_PDM_CLK_SEL_PLL		(0x0 << 0)
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 22/23] ASoC: tas2552: Correct Boost Auto-Pass Through Control register usage
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (20 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 21/23] ASoC: tas2552: Correct Output Data register usage Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-04 13:04 ` [PATCH v2 23/23] ASoC: tas2552: Code, define alignment changes for uniformity Peter Ujfalusi
  2015-06-05 17:53 ` [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Mark Brown
  23 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

Correct the bit definition so the code will change the bits what it
supposed to change. Also rename the register define to
TAS2552_BOOST_APT_CTRL.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c |  6 +++---
 sound/soc/codecs/tas2552.h | 21 ++++++++++-----------
 2 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index d9a637020214..fe8a988e0a4a 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -45,7 +45,7 @@ static struct reg_default tas2552_reg_defs[] = {
 	{TAS2552_OUTPUT_DATA, 0xc0},
 	{TAS2552_PDM_CFG, 0x01},
 	{TAS2552_PGA_GAIN, 0x00},
-	{TAS2552_BOOST_PT_CTRL, 0x0f},
+	{TAS2552_BOOST_APT_CTRL, 0x0f},
 	{TAS2552_RESERVED_0D, 0xbe},
 	{TAS2552_LIMIT_RATE_HYS, 0x08},
 	{TAS2552_CFG_2, 0xef},
@@ -604,8 +604,8 @@ static int tas2552_codec_probe(struct snd_soc_codec *codec)
 	snd_soc_write(codec, TAS2552_OUTPUT_DATA,
 		      TAS2552_PDM_DATA_SEL_V_I |
 		      TAS2552_R_DATA_OUT(TAS2552_DATA_OUT_V_DATA));
-	snd_soc_write(codec, TAS2552_BOOST_PT_CTRL, TAS2552_APT_DELAY_200 |
-				TAS2552_APT_THRESH_2_1_7);
+	snd_soc_write(codec, TAS2552_BOOST_APT_CTRL, TAS2552_APT_DELAY_200 |
+						     TAS2552_APT_THRESH_20_17);
 
 	snd_soc_write(codec, TAS2552_CFG_2, TAS2552_BOOST_EN |
 				  TAS2552_APT_EN | TAS2552_LIM_EN);
diff --git a/sound/soc/codecs/tas2552.h b/sound/soc/codecs/tas2552.h
index 14d40ef645c4..364c6dd8e79b 100644
--- a/sound/soc/codecs/tas2552.h
+++ b/sound/soc/codecs/tas2552.h
@@ -39,7 +39,7 @@
 #define TAS2552_PDM_CFG			0x11
 #define TAS2552_PGA_GAIN		0x12
 #define TAS2552_EDGE_RATE_CTRL	0x13
-#define TAS2552_BOOST_PT_CTRL	0x14
+#define TAS2552_BOOST_APT_CTRL		0x14
 #define TAS2552_VER_NUM			0x16
 #define TAS2552_VBAT_DATA		0x19
 #define TAS2552_MAX_REG			0x20
@@ -127,16 +127,15 @@
 #define TAS2552_PDM_CLK_SEL_MASK	TAS2552_PDM_CLK_SEL_MCLK
 #define TAS2552_PDM_DATA_ES	 	(1 << 2)
 
-/* Boost pass-through register */
-#define TAS2552_APT_DELAY_50	0x00
-#define TAS2552_APT_DELAY_75	(1 << 1)
-#define TAS2552_APT_DELAY_125	(1 << 2)
-#define TAS2552_APT_DELAY_200	(1 << 3)
-
-#define TAS2552_APT_THRESH_2_5		0x00
-#define TAS2552_APT_THRESH_1_7		(1 << 3)
-#define TAS2552_APT_THRESH_1_4_1_1	(1 << 4)
-#define TAS2552_APT_THRESH_2_1_7	(0x11 << 2)
+/* Boost Auto-pass through register */
+#define TAS2552_APT_DELAY_50		(0x0 << 0)
+#define TAS2552_APT_DELAY_75		(0x1 << 0)
+#define TAS2552_APT_DELAY_125		(0x2 << 0)
+#define TAS2552_APT_DELAY_200		(0x3 << 0)
+#define TAS2552_APT_THRESH_05_02	(0x0 << 2)
+#define TAS2552_APT_THRESH_10_07	(0x1 << 2)
+#define TAS2552_APT_THRESH_14_11	(0x2 << 2)
+#define TAS2552_APT_THRESH_20_17	(0x3 << 2)
 
 /* PLL Control Register */
 #define TAS2552_PLL_J_MASK		0x7f
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 23/23] ASoC: tas2552: Code, define alignment changes for uniformity
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (21 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 22/23] ASoC: tas2552: Correct Boost Auto-Pass Through Control " Peter Ujfalusi
@ 2015-06-04 13:04 ` Peter Ujfalusi
  2015-06-05 17:53 ` [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Mark Brown
  23 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-04 13:04 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

Align the numbers in the header file to the same column.
At the same time change the wrapping of CFG_2 register write in the probe
function to be uniform with the other calls.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tas2552.c |  4 ++--
 sound/soc/codecs/tas2552.h | 10 +++++-----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index fe8a988e0a4a..21d8e1d764a2 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -607,8 +607,8 @@ static int tas2552_codec_probe(struct snd_soc_codec *codec)
 	snd_soc_write(codec, TAS2552_BOOST_APT_CTRL, TAS2552_APT_DELAY_200 |
 						     TAS2552_APT_THRESH_20_17);
 
-	snd_soc_write(codec, TAS2552_CFG_2, TAS2552_BOOST_EN |
-				  TAS2552_APT_EN | TAS2552_LIM_EN);
+	snd_soc_write(codec, TAS2552_CFG_2, TAS2552_BOOST_EN | TAS2552_APT_EN |
+					    TAS2552_LIM_EN);
 
 	return 0;
 
diff --git a/sound/soc/codecs/tas2552.h b/sound/soc/codecs/tas2552.h
index 364c6dd8e79b..13f8d1be1e06 100644
--- a/sound/soc/codecs/tas2552.h
+++ b/sound/soc/codecs/tas2552.h
@@ -19,7 +19,7 @@
 #define __TAS2552_H__
 
 /* Register Address Map */
-#define TAS2552_DEVICE_STATUS	0x00
+#define TAS2552_DEVICE_STATUS		0x00
 #define TAS2552_CFG_1			0x01
 #define TAS2552_CFG_2			0x02
 #define TAS2552_CFG_3			0x03
@@ -33,12 +33,12 @@
 #define TAS2552_BTIP			0x0b
 #define TAS2552_BTS_CTRL		0x0c
 #define TAS2552_RESERVED_0D		0x0d
-#define TAS2552_LIMIT_RATE_HYS	0x0e
-#define TAS2552_LIMIT_RELEASE	0x0f
-#define TAS2552_LIMIT_INT_COUNT	0x10
+#define TAS2552_LIMIT_RATE_HYS		0x0e
+#define TAS2552_LIMIT_RELEASE		0x0f
+#define TAS2552_LIMIT_INT_COUNT		0x10
 #define TAS2552_PDM_CFG			0x11
 #define TAS2552_PGA_GAIN		0x12
-#define TAS2552_EDGE_RATE_CTRL	0x13
+#define TAS2552_EDGE_RATE_CTRL		0x13
 #define TAS2552_BOOST_APT_CTRL		0x14
 #define TAS2552_VER_NUM			0x16
 #define TAS2552_VBAT_DATA		0x19
-- 
2.4.2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: [PATCH v2 02/23] ASoC: tas2552: Fix kernel crash when the codec is loaded but not part of a card
  2015-06-04 13:04 ` [PATCH v2 02/23] ASoC: tas2552: Fix kernel crash when the codec is loaded but not part of a card Peter Ujfalusi
@ 2015-06-04 16:25   ` Mark Brown
  2015-06-05  6:57     ` Peter Ujfalusi
  2015-06-04 16:50   ` Mark Brown
  1 sibling, 1 reply; 34+ messages in thread
From: Mark Brown @ 2015-06-04 16:25 UTC (permalink / raw)
  To: Peter Ujfalusi; +Cc: alsa-devel, Liam Girdwood, dmurphy


[-- Attachment #1.1: Type: text/plain, Size: 533 bytes --]

On Thu, Jun 04, 2015 at 04:04:14PM +0300, Peter Ujfalusi wrote:
> If the card is not part of any card the tas_data->codec is NULL since it is
> set only during snd_soc_codec_driver.probe, which is not yet called.

> @@ -120,6 +120,9 @@ static void tas2552_sw_shutdown(struct tas2552_data *tas_data, int sw_shutdown)
>  {
>  	u8 cfg1_reg;
>  
> +	if (!tas_data->codec)
> +		return;
> +

This fixes the crash but isn't whatever the function is doing important
(so we should fix by using regmap for the I/O or something)?

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v2 02/23] ASoC: tas2552: Fix kernel crash when the codec is loaded but not part of a card
  2015-06-04 13:04 ` [PATCH v2 02/23] ASoC: tas2552: Fix kernel crash when the codec is loaded but not part of a card Peter Ujfalusi
  2015-06-04 16:25   ` Mark Brown
@ 2015-06-04 16:50   ` Mark Brown
  1 sibling, 0 replies; 34+ messages in thread
From: Mark Brown @ 2015-06-04 16:50 UTC (permalink / raw)
  To: Peter Ujfalusi; +Cc: alsa-devel, Liam Girdwood, dmurphy


[-- Attachment #1.1: Type: text/plain, Size: 272 bytes --]

On Thu, Jun 04, 2015 at 04:04:14PM +0300, Peter Ujfalusi wrote:
> If the card is not part of any card the tas_data->codec is NULL since it is
> set only during snd_soc_codec_driver.probe, which is not yet called.

Please put bugfixes like this at the start of the series.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v2 08/23] ASoC: tas2552: Rename mclk parameter to pll_clkin to match with the datasheet
  2015-06-04 13:04 ` [PATCH v2 08/23] ASoC: tas2552: Rename mclk parameter to pll_clkin to match with the datasheet Peter Ujfalusi
@ 2015-06-04 16:51   ` Mark Brown
  0 siblings, 0 replies; 34+ messages in thread
From: Mark Brown @ 2015-06-04 16:51 UTC (permalink / raw)
  To: Peter Ujfalusi; +Cc: alsa-devel, Liam Girdwood, dmurphy


[-- Attachment #1.1: Type: text/plain, Size: 276 bytes --]

On Thu, Jun 04, 2015 at 04:04:20PM +0300, Peter Ujfalusi wrote:
> MCLK is one of the possible source for the pll_clkin frequency. Make this
> clear by renaming the variable.

Applied all up to here, thanks (not looked at the rest yet and it's
about the end of the day today).

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v2 19/23] ASoC: tas2552: Correct the PLL configuration
  2015-06-04 13:04 ` [PATCH v2 19/23] ASoC: tas2552: Correct the PLL configuration Peter Ujfalusi
@ 2015-06-05  6:53   ` Peter Ujfalusi
  0 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-05  6:53 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, dmurphy; +Cc: alsa-devel

On 06/04/2015 04:04 PM, Peter Ujfalusi wrote:
> Do not restrict the sampling rate to 44.1/48KHz. The pll_clk clock should
> be (sampling rate * 512) in all cases.
> Correct the J.D calculation (the D part was incorrectly calculated).
> Restore PLL enable status after we are done with the configuration.
> Implement hardware constraint handling towards the pll_clkin:
> if D != 0 (in J.D) then 1.1MHz <= pll_clkin <= 9.2MHz needs to be checked.
> If the PLL setup does not met with this constraint, fall back to BCLK as
> reference clock, if BCLK fails, use the internal 1.8MHz clock.
> 
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
> ---
>  sound/soc/codecs/tas2552.c | 141 ++++++++++++++++++++++++++++++---------------
>  sound/soc/codecs/tas2552.h |   7 +--
>  2 files changed, 96 insertions(+), 52 deletions(-)
> 
> diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
> index 891e2c529df3..01230395b61d 100644
> --- a/sound/soc/codecs/tas2552.c
> +++ b/sound/soc/codecs/tas2552.c
> @@ -77,7 +77,9 @@ struct tas2552_data {
>  	struct gpio_desc *enable_gpio;
>  	unsigned char regs[TAS2552_VBAT_DATA];
>  	unsigned int pll_clkin;
> +	int pll_clk_id;
>  	unsigned int pdm_clk;
> +	int pdm_clk_id;
>  
>  	unsigned int dai_fmt;
>  	unsigned int tdm_delay;
> @@ -158,16 +160,93 @@ static void tas2552_sw_shutdown(struct tas2552_data *tas_data, int sw_shutdown)
>  }
>  #endif
>  
> +static int tas2552_setup_pll(struct snd_soc_codec *codec,
> +			     struct snd_pcm_hw_params *params)
> +{
> +	struct tas2552_data *tas2552 = dev_get_drvdata(codec->dev);
> +	bool bypass_pll = false;
> +	unsigned int pll_clk = params_rate(params) * 512;
> +	unsigned int pll_clkin = tas2552->pll_clkin;
> +	u8 pll_enable;
> +
> +	if (!pll_clkin) {
> +		if (tas2552->pll_clk_id != TAS2552_PLL_CLKIN_BCLK)
> +			return -EINVAL;
> +
> +		pll_clkin = snd_soc_params_to_bclk(params);
> +		pll_clkin += tas2552->tdm_delay;
> +	}
> +
> +	pll_enable = snd_soc_read(codec, TAS2552_CFG_2) & TAS2552_PLL_ENABLE;
> +	snd_soc_update_bits(codec, TAS2552_CFG_2, TAS2552_PLL_ENABLE, 0);
> +
> +	if (pll_clkin == pll_clk)
> +		bypass_pll = true;
> +
> +	if (bypass_pll) {
> +		/* By pass the PLL configuration */
> +		snd_soc_update_bits(codec, TAS2552_PLL_CTRL_2,
> +				    TAS2552_PLL_BYPASS, TAS2552_PLL_BYPASS);
> +	} else {
> +		/* Fill in the PLL control registers for J & D
> +		 * pll_clk = (.5 * pll_clkin * J.D) / 2^p
> +		 * Need to fill in J and D here based on incoming freq
> +		 */
> +		unsigned int d;
> +		u8 j;
> +		u8 pll_sel = (tas2552->pll_clk_id << 3) & TAS2552_PLL_SRC_MASK;
> +		u8 p = snd_soc_read(codec, TAS2552_PLL_CTRL_1);
> +
> +		p = (p >> 7);
> +
> +recalc:
> +		j = (pll_clk * 2 * (1 << p)) / pll_clkin;
> +		d = (pll_clk * 2 * (1 << p)) % pll_clkin;
> +		d /= (pll_clkin / 10000);
> +
> +		if (d && (pll_clkin < 512000 || pll_clkin > 9200000)) {
> +			if (tas2552->pll_clk_id == TAS2552_PLL_CLKIN_BCLK) {
> +				pll_clkin = 1800000;
> +				pll_sel = (TAS2552_PLL_CLKIN_1_8_FIXED << 3) &
> +							TAS2552_PLL_SRC_MASK;
> +			} else {
> +				pll_clkin = snd_soc_params_to_bclk(params);
> +				pll_clkin += tas2552->tdm_delay;
> +				pll_sel = (TAS2552_PLL_CLKIN_BCLK << 3) &
> +							TAS2552_PLL_SRC_MASK;
> +			}
> +			goto recalc;
> +		}
> +
> +		snd_soc_update_bits(codec, TAS2552_CFG_1, TAS2552_PLL_SRC_MASK,
> +				    pll_sel);
> +
> +		snd_soc_update_bits(codec, TAS2552_PLL_CTRL_1,
> +				    TAS2552_PLL_J_MASK, j);
> +		snd_soc_write(codec, TAS2552_PLL_CTRL_2,
> +			      (d >> 7) & TAS2552_PLL_D_UPPER_MASK);

This bit shift is not correct, it should be 8... I carried it over from the
old code and it worked since In some of my tests I was using bitclock as
reference (D ends up as 0).

Mark, if you apply the series up this patch, I will resend the rest as v3 with
the fixed shift - I will create a macro for upper and lower, it will look a
bit better.


> +		snd_soc_write(codec, TAS2552_PLL_CTRL_3,
> +			      d & TAS2552_PLL_D_LOWER_MASK);
> +
> +		/* PLL in use */
> +		snd_soc_update_bits(codec, TAS2552_PLL_CTRL_2,
> +				    TAS2552_PLL_BYPASS, 0);
> +	}
> +
> +	/* Restore PLL status */
> +	snd_soc_update_bits(codec, TAS2552_CFG_2, TAS2552_PLL_ENABLE,
> +			    pll_enable);
> +
> +	return 0;
> +}
> +
>  static int tas2552_hw_params(struct snd_pcm_substream *substream,
>  			     struct snd_pcm_hw_params *params,
>  			     struct snd_soc_dai *dai)
>  {
>  	struct snd_soc_codec *codec = dai->codec;
>  	struct tas2552_data *tas2552 = dev_get_drvdata(codec->dev);
> -	int sample_rate, pll_clk;
> -	int d;
>  	int cpf;
> -	u8 p, j;
>  	u8 ser_ctrl1_reg, wclk_rate;
>  
>  	switch (params_width(params)) {
> @@ -245,49 +324,7 @@ static int tas2552_hw_params(struct snd_pcm_substream *substream,
>  	snd_soc_update_bits(codec, TAS2552_CFG_3, TAS2552_WCLK_FREQ_MASK,
>  			    wclk_rate);
>  
> -	if (!tas2552->pll_clkin)
> -		return -EINVAL;
> -
> -	snd_soc_update_bits(codec, TAS2552_CFG_2, TAS2552_PLL_ENABLE, 0);
> -
> -	if (tas2552->pll_clkin == TAS2552_245MHZ_CLK ||
> -	    tas2552->pll_clkin == TAS2552_225MHZ_CLK) {
> -		/* By pass the PLL configuration */
> -		snd_soc_update_bits(codec, TAS2552_PLL_CTRL_2,
> -				    TAS2552_PLL_BYPASS_MASK,
> -				    TAS2552_PLL_BYPASS);
> -	} else {
> -		/* Fill in the PLL control registers for J & D
> -		 * PLL_CLK = (.5 * freq * J.D) / 2^p
> -		 * Need to fill in J and D here based on incoming freq
> -		 */
> -		p = snd_soc_read(codec, TAS2552_PLL_CTRL_1);
> -		p = (p >> 7);
> -		sample_rate = params_rate(params);
> -
> -		if (sample_rate == 48000)
> -			pll_clk = TAS2552_245MHZ_CLK;
> -		else if (sample_rate == 44100)
> -			pll_clk = TAS2552_225MHZ_CLK;
> -		else {
> -			dev_vdbg(codec->dev, "Substream sample rate is not found %i\n",
> -					params_rate(params));
> -			return -EINVAL;
> -		}
> -
> -		j = (pll_clk * 2 * (1 << p)) / tas2552->pll_clkin;
> -		d = (pll_clk * 2 * (1 << p)) % tas2552->pll_clkin;
> -
> -		snd_soc_update_bits(codec, TAS2552_PLL_CTRL_1,
> -				TAS2552_PLL_J_MASK, j);
> -		snd_soc_write(codec, TAS2552_PLL_CTRL_2,
> -					(d >> 7) & TAS2552_PLL_D_UPPER_MASK);
> -		snd_soc_write(codec, TAS2552_PLL_CTRL_3,
> -				d & TAS2552_PLL_D_LOWER_MASK);
> -
> -	}
> -
> -	return 0;
> +	return tas2552_setup_pll(codec, params);
>  }
>  
>  #define TAS2552_DAI_FMT_MASK	(TAS2552_BCLKDIR | \
> @@ -370,12 +407,21 @@ static int tas2552_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
>  
>  	switch (clk_id) {
>  	case TAS2552_PLL_CLKIN_MCLK:
> -	case TAS2552_PLL_CLKIN_BCLK:
>  	case TAS2552_PLL_CLKIN_IVCLKIN:
> +		if (freq < 512000 || freq > 24576000) {
> +			/* out of range PLL_CLKIN, fall back to use BCLK */
> +			dev_warn(codec->dev, "Out of range PLL_CLKIN: %u\n",
> +				 freq);
> +			clk_id = TAS2552_PLL_CLKIN_BCLK;
> +			freq = 0;
> +		}
> +		/* fall through */
> +	case TAS2552_PLL_CLKIN_BCLK:
>  	case TAS2552_PLL_CLKIN_1_8_FIXED:
>  		mask = TAS2552_PLL_SRC_MASK;
>  		val = (clk_id << 3) & mask; /* bit 4:5 in the register */
>  		reg = TAS2552_CFG_1;
> +		tas2552->pll_clk_id = clk_id;
>  		tas2552->pll_clkin = freq;
>  		break;
>  	case TAS2552_PDM_CLK_PLL:
> @@ -385,6 +431,7 @@ static int tas2552_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
>  		mask = TAS2552_PDM_CLK_SEL_MASK;
>  		val = (clk_id >> 1) & mask; /* bit 0:1 in the register */
>  		reg = TAS2552_PDM_CFG;
> +		tas2552->pdm_clk_id = clk_id;
>  		tas2552->pdm_clk = freq;
>  		break;
>  	default:
> diff --git a/sound/soc/codecs/tas2552.h b/sound/soc/codecs/tas2552.h
> index bbb820495516..f04d9e6db0aa 100644
> --- a/sound/soc/codecs/tas2552.h
> +++ b/sound/soc/codecs/tas2552.h
> @@ -128,12 +128,9 @@
>  #define TAS2552_APT_THRESH_2_1_7	(0x11 << 2)
>  
>  /* PLL Control Register */
> -#define TAS2552_245MHZ_CLK			24576000
> -#define TAS2552_225MHZ_CLK			22579200
> -#define TAS2552_PLL_J_MASK			0x7f
> +#define TAS2552_PLL_J_MASK		0x7f
>  #define TAS2552_PLL_D_UPPER_MASK	0x3f
>  #define TAS2552_PLL_D_LOWER_MASK	0xff
> -#define TAS2552_PLL_BYPASS_MASK		0x80
> -#define TAS2552_PLL_BYPASS			0x80
> +#define TAS2552_PLL_BYPASS		(1 << 7)
>  
>  #endif
> 


-- 
Péter

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v2 02/23] ASoC: tas2552: Fix kernel crash when the codec is loaded but not part of a card
  2015-06-04 16:25   ` Mark Brown
@ 2015-06-05  6:57     ` Peter Ujfalusi
  0 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-05  6:57 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Liam Girdwood, dmurphy

On 06/04/2015 07:25 PM, Mark Brown wrote:
> On Thu, Jun 04, 2015 at 04:04:14PM +0300, Peter Ujfalusi wrote:
>> If the card is not part of any card the tas_data->codec is NULL since it is
>> set only during snd_soc_codec_driver.probe, which is not yet called.
> 
>> @@ -120,6 +120,9 @@ static void tas2552_sw_shutdown(struct tas2552_data *tas_data, int sw_shutdown)
>>  {
>>  	u8 cfg1_reg;
>>  
>> +	if (!tas_data->codec)
>> +		return;
>> +
> 
> This fixes the crash but isn't whatever the function is doing important
> (so we should fix by using regmap for the I/O or something)?

If the driver's snd_soc_codec_driver->probe is not called we do not initialize
the amplifier.
This function would put the amp to software shutdown, which is the power up
state of the amp.

Hrm, it should use tas2552 instead of tas_dat for the tas2552_data to be
consistent with the rest of the driver.
I will add a patch for this in v3.

-- 
Péter

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements
  2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
                   ` (22 preceding siblings ...)
  2015-06-04 13:04 ` [PATCH v2 23/23] ASoC: tas2552: Code, define alignment changes for uniformity Peter Ujfalusi
@ 2015-06-05 17:53 ` Mark Brown
  2015-06-08  7:52   ` Peter Ujfalusi
  23 siblings, 1 reply; 34+ messages in thread
From: Mark Brown @ 2015-06-05 17:53 UTC (permalink / raw)
  To: Peter Ujfalusi; +Cc: alsa-devel, Liam Girdwood, dmurphy


[-- Attachment #1.1: Type: text/plain, Size: 344 bytes --]

On Thu, Jun 04, 2015 at 04:04:12PM +0300, Peter Ujfalusi wrote:
> Hi,
> 
> Changes since v01:
> - missing patch found. It was merged with the previous patch while fixing
>   checkpatch errors (patch 19 got squashed to patch 18)
> - Sorry for this.

Applied all, thanks.  Please use subject lines matching the style for
the subsystem.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v2 09/23] DT/sound: bindings header file for tas2552 codec
  2015-06-04 13:04 ` [PATCH v2 09/23] DT/sound: bindings header file for tas2552 codec Peter Ujfalusi
@ 2015-06-05 17:54   ` Mark Brown
  0 siblings, 0 replies; 34+ messages in thread
From: Mark Brown @ 2015-06-05 17:54 UTC (permalink / raw)
  To: Peter Ujfalusi; +Cc: alsa-devel, Liam Girdwood, dmurphy


[-- Attachment #1.1: Type: text/plain, Size: 196 bytes --]

On Thu, Jun 04, 2015 at 04:04:21PM +0300, Peter Ujfalusi wrote:
> Binding header file for clock input selection and configuration.

These should probably be mentioned in the binding document too?

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements
  2015-06-05 17:53 ` [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Mark Brown
@ 2015-06-08  7:52   ` Peter Ujfalusi
  2015-06-08  9:24     ` Mark Brown
  0 siblings, 1 reply; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-08  7:52 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Liam Girdwood, dmurphy

On 06/05/2015 08:53 PM, Mark Brown wrote:
> On Thu, Jun 04, 2015 at 04:04:12PM +0300, Peter Ujfalusi wrote:
>> Hi,
>>
>> Changes since v01:
>> - missing patch found. It was merged with the previous patch while fixing
>>   checkpatch errors (patch 19 got squashed to patch 18)
>> - Sorry for this.
> 
> Applied all, thanks.  Please use subject lines matching the style for
> the subsystem.

I believe 'ASoC: tas2552: bla-bla-bla' should be fine. Or did I missed something?

-- 
Péter

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements
  2015-06-08  7:52   ` Peter Ujfalusi
@ 2015-06-08  9:24     ` Mark Brown
  2015-06-08  9:54       ` Peter Ujfalusi
  0 siblings, 1 reply; 34+ messages in thread
From: Mark Brown @ 2015-06-08  9:24 UTC (permalink / raw)
  To: Peter Ujfalusi; +Cc: alsa-devel, Liam Girdwood, dmurphy


[-- Attachment #1.1: Type: text/plain, Size: 333 bytes --]

On Mon, Jun 08, 2015 at 10:52:01AM +0300, Peter Ujfalusi wrote:
> On 06/05/2015 08:53 PM, Mark Brown wrote:

> > Applied all, thanks.  Please use subject lines matching the style for
> > the subsystem.

> I believe 'ASoC: tas2552: bla-bla-bla' should be fine. Or did I missed something?

That wasn't what you used for your DT patch.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements
  2015-06-08  9:24     ` Mark Brown
@ 2015-06-08  9:54       ` Peter Ujfalusi
  0 siblings, 0 replies; 34+ messages in thread
From: Peter Ujfalusi @ 2015-06-08  9:54 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Liam Girdwood, dmurphy

On 06/08/2015 12:24 PM, Mark Brown wrote:
> On Mon, Jun 08, 2015 at 10:52:01AM +0300, Peter Ujfalusi wrote:
>> On 06/05/2015 08:53 PM, Mark Brown wrote:
> 
>>> Applied all, thanks.  Please use subject lines matching the style for
>>> the subsystem.
> 
>> I believe 'ASoC: tas2552: bla-bla-bla' should be fine. Or did I missed something?
> 
> That wasn't what you used for your DT patch.

true, I forgot to look at the history of the directory. Sorry.

-- 
Péter

^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2015-06-08  9:54 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-04 13:04 [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Peter Ujfalusi
2015-06-04 13:04 ` [PATCH v2 01/23] ASoC: tas2552: Make the enable-gpio really optional Peter Ujfalusi
2015-06-04 13:04 ` [PATCH v2 02/23] ASoC: tas2552: Fix kernel crash when the codec is loaded but not part of a card Peter Ujfalusi
2015-06-04 16:25   ` Mark Brown
2015-06-05  6:57     ` Peter Ujfalusi
2015-06-04 16:50   ` Mark Brown
2015-06-04 13:04 ` [PATCH v2 03/23] ASoC: tas2552: Fix kernel crash caused by wrong kcontrol entry Peter Ujfalusi
2015-06-04 13:04 ` [PATCH v2 04/23] ASoC: tas2552: Correct PDM configuration register bit definitions Peter Ujfalusi
2015-06-04 13:04 ` [PATCH v2 05/23] ASoC: tas2552: Correct CFG1 " Peter Ujfalusi
2015-06-04 13:04 ` [PATCH v2 06/23] ASoC: tas2552: Simplify the tas2552_mute function Peter Ujfalusi
2015-06-04 13:04 ` [PATCH v2 07/23] ASoC: tas2552: Simplify and reverse the functionality of tas2552_sw_shutdown Peter Ujfalusi
2015-06-04 13:04 ` [PATCH v2 08/23] ASoC: tas2552: Rename mclk parameter to pll_clkin to match with the datasheet Peter Ujfalusi
2015-06-04 16:51   ` Mark Brown
2015-06-04 13:04 ` [PATCH v2 09/23] DT/sound: bindings header file for tas2552 codec Peter Ujfalusi
2015-06-05 17:54   ` Mark Brown
2015-06-04 13:04 ` [PATCH v2 10/23] ASoC: tas2552: Add support for pll and pdm source clock selection Peter Ujfalusi
2015-06-04 13:04 ` [PATCH v2 11/23] ASoC: tas2552: Correct dai format support Peter Ujfalusi
2015-06-04 13:04 ` [PATCH v2 12/23] ASoC: tas2552: Correct and clean up data format and BCLK/WCLK direction Peter Ujfalusi
2015-06-04 13:04 ` [PATCH v2 13/23] ASoC: tas2552: Add TDM support Peter Ujfalusi
2015-06-04 13:04 ` [PATCH v2 14/23] ASoC: tas2552: Clean up the Digital - Analog DAPM route definition Peter Ujfalusi
2015-06-04 13:04 ` [PATCH v2 15/23] ASoC: tas2552: Correct the Speaker Driver Playback Volume (PGA_GAIN) Peter Ujfalusi
2015-06-04 13:04 ` [PATCH v2 16/23] ASoC: tas2552: Implement startup/stop sequence as per TRM Peter Ujfalusi
2015-06-04 13:04 ` [PATCH v2 17/23] ASoC: tas2552: Add support for word length configuration Peter Ujfalusi
2015-06-04 13:04 ` [PATCH v2 18/23] ASoC: tas2552: Configure the WCLK frequency based on the stream Peter Ujfalusi
2015-06-04 13:04 ` [PATCH v2 19/23] ASoC: tas2552: Correct the PLL configuration Peter Ujfalusi
2015-06-05  6:53   ` Peter Ujfalusi
2015-06-04 13:04 ` [PATCH v2 20/23] ASoC: tas2552: Add control for selecting DIN source Peter Ujfalusi
2015-06-04 13:04 ` [PATCH v2 21/23] ASoC: tas2552: Correct Output Data register usage Peter Ujfalusi
2015-06-04 13:04 ` [PATCH v2 22/23] ASoC: tas2552: Correct Boost Auto-Pass Through Control " Peter Ujfalusi
2015-06-04 13:04 ` [PATCH v2 23/23] ASoC: tas2552: Code, define alignment changes for uniformity Peter Ujfalusi
2015-06-05 17:53 ` [PATCH v2 00/23] ASoC: tas2552: Fixes, cleanups and improvements Mark Brown
2015-06-08  7:52   ` Peter Ujfalusi
2015-06-08  9:24     ` Mark Brown
2015-06-08  9:54       ` Peter Ujfalusi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.