Skip to contentSkip to conversation

ASoC: omap-mcpdm/twl6040: Offset cancellation

PATCH Superseded Peter Ujfalusi 2 participants 10 messages Sep 15, 2011 – Sep 26, 2011

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

cover ASoC: omap-mcpdm/twl6040: Offset cancellation

Hello,

The following series adds support for the McPDM offset cancellation feature. It provides the needed functionality to:
- read the HSTRIM values from the twl6040 codec
- configure the offset cancellation registers in OMAP-McPDM

Regards,
Peter
---
Peter Ujfalusi (4):
ASoC: twl6040: Read the TRIM values from the chip
ASoC: twl6040: Function to fetch the TRIM values
ASoC: omap-mcpdm: API to configure offset cancellation
ASoC: sdp4430: Configure McPDM offset cancellation

 sound/soc/codecs/twl6040.c  |   16 ++++++++++++++++
 sound/soc/codecs/twl6040.h  |   13 +++++++++++++
 sound/soc/omap/omap-mcpdm.c |   25 +++++++++++++++++++++++++
 sound/soc/omap/omap-mcpdm.h |   12 ++++++++++++
 sound/soc/omap/sdp4430.c    |   10 +++++++++-
 5 files changed, 75 insertions(+), 1 deletions(-)
Signature · 1 line
1.7.6.1
#1 lore raw

PATCH 1/4 ASoC: twl6040: Read the TRIM values from the chip

Update the reg_cache with values from chip regarding to TRIM.

---
 sound/soc/codecs/twl6040.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
sound/soc/codecs/twl6040.c +7 -0
index 063defc..638954c 100644
@@ -279,9 +279,16 @@ static void twl6040_init_chip(struct snd_soc_codec *codec)
 	struct twl6040 *twl6040 = codec->control_data;
 	u8 val;
 
+	/* Update reg_cache: ASICREV, and TRIM values */
 	val = twl6040_get_revid(twl6040);
 	twl6040_write_reg_cache(codec, TWL6040_REG_ASICREV, val);
 
+	twl6040_read_reg_volatile(codec, TWL6040_REG_TRIM1);
+	twl6040_read_reg_volatile(codec, TWL6040_REG_TRIM2);
+	twl6040_read_reg_volatile(codec, TWL6040_REG_TRIM3);
+	twl6040_read_reg_volatile(codec, TWL6040_REG_HSOTRIM);
+	twl6040_read_reg_volatile(codec, TWL6040_REG_HFOTRIM);
+
 	/* Change chip defaults */
 	/* No imput selected for microphone amplifiers */
 	twl6040_write_reg_cache(codec, TWL6040_REG_MICLCTL, 0x18);
Signature · 1 line
1.7.6.1
#2 lore raw

PATCH 2/4 ASoC: twl6040: Function to fetch the TRIM values

In reply to Peter Ujfalusi

Provide API to fetch the TRIM values (for machine drivers)

---
 sound/soc/codecs/twl6040.c |    9 +++++++++
 sound/soc/codecs/twl6040.h |   13 +++++++++++++
 2 files changed, 22 insertions(+), 0 deletions(-)
sound/soc/codecs/twl6040.c +9 -0
index 638954c..8eecf4a 100644
@@ -1111,6 +1111,15 @@ int twl6040_get_clk_id(struct snd_soc_codec *codec)
 }
 EXPORT_SYMBOL_GPL(twl6040_get_clk_id);
 
+int twl6040_get_trim_value(struct snd_soc_codec *codec, enum twl6040_trim trim)
+{
+	if (unlikely(trim >= TWL6040_TRIM_INVAL))
+		return -EINVAL;
+
+	return twl6040_read_reg_cache(codec, TWL6040_REG_TRIM1 + trim);
+}
+EXPORT_SYMBOL_GPL(twl6040_get_trim_value);
+
 static const struct snd_kcontrol_new twl6040_snd_controls[] = {
 	/* Capture gains */
 	SOC_DOUBLE_TLV("Capture Preamplifier Volume",
sound/soc/codecs/twl6040.h +13 -0
index d8de678..a83277b 100644
@@ -22,8 +22,21 @@
 #ifndef __TWL6040_H__
 #define __TWL6040_H__
 
+enum twl6040_trim {
+	TWL6040_TRIM_TRIM1 = 0,
+	TWL6040_TRIM_TRIM2,
+	TWL6040_TRIM_TRIM3,
+	TWL6040_TRIM_HSOTRIM,
+	TWL6040_TRIM_HFOTRIM,
+	TWL6040_TRIM_INVAL,
+};
+
+#define TWL6040_HSF_TRIM_LEFT(x)	(x & 0x0f)
+#define TWL6040_HSF_TRIM_RIGHT(x)	((x >> 4) & 0x0f)
+
 void twl6040_hs_jack_detect(struct snd_soc_codec *codec,
 			    struct snd_soc_jack *jack, int report);
 int twl6040_get_clk_id(struct snd_soc_codec *codec);
+int twl6040_get_trim_value(struct snd_soc_codec *codec, enum twl6040_trim trim);
 
 #endif /* End of __TWL6040_H__ */
Signature · 1 line
1.7.6.1
#3 lore raw

PATCH 3/4 ASoC: omap-mcpdm: API to configure offset cancellation

In reply to Peter Ujfalusi

The offset cancellation values can be different from board to board, even on the same HW platform.
Provide a way for the machine drivers to configure the McPDM offset cancellation.

---
 sound/soc/omap/omap-mcpdm.c |   25 +++++++++++++++++++++++++
 sound/soc/omap/omap-mcpdm.h |   12 ++++++++++++
 2 files changed, 37 insertions(+), 0 deletions(-)
sound/soc/omap/omap-mcpdm.c +25 -0
index 159a5e9..23eaacb 100644
@@ -59,6 +59,9 @@ struct omap_mcpdm {
 	/* McPDM FIFO thresholds */
 	u32 dn_threshold;
 	u32 up_threshold;
+
+	/* McPDM dn offsets for rx1, and 2 channels */
+	u32 dn_rx_offset;
 };
 
 /*
@@ -183,6 +186,15 @@ static void omap_mcpdm_open_streams(struct omap_mcpdm *mcpdm)
 			MCPDM_DN_IRQ_EMPTY | MCPDM_DN_IRQ_FULL |
 			MCPDM_UP_IRQ_EMPTY | MCPDM_UP_IRQ_FULL);
 
+	/* Enable DN RX1/2 offset cancellation feature, if configured */
+	if (mcpdm->dn_rx_offset) {
+		u32 dn_offset = mcpdm->dn_rx_offset;
+
+		omap_mcpdm_write(mcpdm, MCPDM_REG_DN_OFFSET, dn_offset);
+		dn_offset |= (MCPDM_DN_OFST_RX1_EN | MCPDM_DN_OFST_RX2_EN);
+		omap_mcpdm_write(mcpdm, MCPDM_REG_DN_OFFSET, dn_offset);
+	}
+
 	omap_mcpdm_write(mcpdm, MCPDM_REG_FIFO_CTRL_DN, mcpdm->dn_threshold);
 	omap_mcpdm_write(mcpdm, MCPDM_REG_FIFO_CTRL_UP, mcpdm->up_threshold);
 
@@ -209,6 +221,10 @@ static void omap_mcpdm_close_streams(struct omap_mcpdm *mcpdm)
 
 	/* Disable DMA request generation for uplink */
 	omap_mcpdm_write(mcpdm, MCPDM_REG_DMAENABLE_CLR, MCPDM_DMA_UP_ENABLE);
+
+	/* Disable RX1/2 offset cancellation */
+	if (mcpdm->dn_rx_offset)
+		omap_mcpdm_write(mcpdm, MCPDM_REG_DN_OFFSET, 0);
 }
 
 static irqreturn_t omap_mcpdm_irq_handler(int irq, void *dev_id)
@@ -416,6 +432,15 @@ static struct snd_soc_dai_driver omap_mcpdm_dai = {
 	.ops = &omap_mcpdm_dai_ops,
 };
 
+void omap_mcpdm_configure_dn_offsets(struct snd_soc_pcm_runtime *rtd,
+				    u8 rx1, u8 rx2)
+{
+	struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(rtd->cpu_dai);
+
+	mcpdm->dn_rx_offset = MCPDM_DNOFST_RX1(rx1) | MCPDM_DNOFST_RX2(rx2);
+}
+EXPORT_SYMBOL_GPL(omap_mcpdm_configure_dn_offsets);
+
 static __devinit int asoc_mcpdm_probe(struct platform_device *pdev)
 {
 	struct omap_mcpdm *mcpdm;
sound/soc/omap/omap-mcpdm.h +12 -0
index d23122a..de8cf26 100644
@@ -92,4 +92,16 @@
 #define MCPDM_UP_THRES_MAX		0xF
 #define MCPDM_DN_THRES_MAX		0xF
 
+/*
+ * MCPDM_DN_OFFSET bit fields
+ */
+
+#define MCPDM_DN_OFST_RX1_EN		(1 << 0)
+#define MCPDM_DNOFST_RX1(x)		((x & 0x1f) << 1)
+#define MCPDM_DN_OFST_RX2_EN		(1 << 8)
+#define MCPDM_DNOFST_RX2(x)		((x & 0x1f) << 9)
+
+void omap_mcpdm_configure_dn_offsets(struct snd_soc_pcm_runtime *rtd,
+				    u8 rx1, u8 rx2);
+
 #endif	/* End of __OMAP_MCPDM_H__ */
Signature · 1 line
1.7.6.1
#4 lore raw

PATCH 4/4 ASoC: sdp4430: Configure McPDM offset cancellation

In reply to Peter Ujfalusi

Based on the values from twl6040 codec (HSOTRIM L/R) we can configure the McPDM offset cancellation.

---
 sound/soc/omap/sdp4430.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
sound/soc/omap/sdp4430.c +9 -1
index 060066b..79ec76d 100644
@@ -121,7 +121,7 @@ static int sdp4430_twl6040_init(struct snd_soc_pcm_runtime *rtd)
 {
 	struct snd_soc_codec *codec = rtd->codec;
 	struct snd_soc_dapm_context *dapm = &codec->dapm;
-	int ret;
+	int ret, hs_trim;
 
 	/* Add SDP4430 specific widgets */
 	ret = snd_soc_dapm_new_controls(dapm, sdp4430_twl6040_dapm_widgets,
@@ -144,6 +144,14 @@ static int sdp4430_twl6040_init(struct snd_soc_pcm_runtime *rtd)
 	if (ret)
 		return ret;
 
+	/*
+	 * Configure McPDM offset cancellation based on the HSOTRIM value from
+	 * twl6040.
+	 */
+	hs_trim = twl6040_get_trim_value(codec, TWL6040_TRIM_HSOTRIM);
+	omap_mcpdm_configure_dn_offsets(rtd, TWL6040_HSF_TRIM_LEFT(hs_trim),
+					TWL6040_HSF_TRIM_RIGHT(hs_trim));
+
 	/* Headset jack detection */
 	ret = snd_soc_jack_new(codec, "Headset Jack",
 				SND_JACK_HEADSET, &hs_jack);
Signature · 1 line
1.7.6.1
Acked-by on the v1 series
#5 lore raw
In reply to Peter Ujfalusi
Quoted 6 lines · Peter Ujfalusi

Hello,

The following series adds support for the McPDM offset cancellation feature. It provides the needed functionality to:
- read the HSTRIM values from the twl6040 codec
- configure the offset cancellation registers in OMAP-McPDM

All

#6 lore raw
In reply to Peter Ujfalusi

Hi Liam,

Quoted 6 lines · On Thursday 15 September 2011 15:45:14 Peter Ujfalusi wrote:

Hello,

The following series adds support for the McPDM offset cancellation feature. It provides the needed functionality to:
- read the HSTRIM values from the twl6040 codec
- configure the offset cancellation registers in OMAP-McPDM

can you take a look at this series?
Mark already acked it, but I think your ack is needed so Mark can apply these for 3.2.

Thanks,
Péter

#7 lore raw
Quoted 3 lines · Péter Ujfalusi

can you take a look at this series?
Mark already acked it, but I think your ack is needed so Mark can apply these for 3.2.

I'm perfectly happy applying things without Liam while he's away.

#8 lore raw

Hi Mark,

Quoted 1 line · On Monday 26 September 2011 11:42:22 Mark Brown wrote:

I'm perfectly happy applying things without Liam while he's away.

Can you apply this series?
I can resend it if you want, it should apply cleanly on top of the other changes.

Thanks,
Péter

#9 lore raw
Quoted 6 lines · Péter Ujfalusi
Quoted 1 line · On Monday 26 September 2011 11:42:22 Mark Brown wrote:

I'm perfectly happy applying things without Liam while he's away.

Can you apply this series?
I can resend it if you want, it should apply cleanly on top of the other changes.

Resend, please. I'll have deleted anything I acked.