Skip to contentSkip to conversation

McBSP: OMAP3: Add sidetone feature

PATCH Superseded Ilkka Koskinen 4 participants 8 messages Feb 18, 2010

Subsystems (5)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover McBSP: OMAP3: Add sidetone feature

The first patch implements McBSP sidetone feature on OMAP3 while the second one provides ALSA interface for using it.

The patch set is based on the patch Eduardo Valentin sent to alsa-devel mailing list in October 2009. Channel gain control and enabling the sidetone have been moved to ALSA interface as suggested in comments.

These patches apply on top of Janusz Krzysztofik's McBSP register cache patches in linux-omap-2.6.git

Since previous review round, I have combined McBSP port specific omap_mcbsp_st_set_mode() and omap_mcbsp_st_put_mode() functions to corresponding ones as suggested by Peter Ujfalusi.

Eero Nurkkala (1):
McBSP: OMAP3: Add sidetone feature

Ilkka Koskinen (1):
ASoC: OMAP-McBSP: ASoC interface for McBSP sidetone

 arch/arm/mach-omap2/mcbsp.c             |    2 +
 arch/arm/plat-omap/include/plat/mcbsp.h |   63 +++++
 arch/arm/plat-omap/mcbsp.c              |  394 ++++++++++++++++++++++++++++++-
 sound/soc/omap/omap-mcbsp.c             |  176 ++++++++++++++
 sound/soc/omap/omap-mcbsp.h             |    2 +
 5 files changed, 636 insertions(+), 1 deletions(-)
#1 lore raw

PATCH v3 1/2 McBSP: OMAP3: Add sidetone feature

From: Eero Nurkkala <[email protected]>

Add sidetone feature to McBSP instances 2 and 3 on OMAP3 based devices.

---
 arch/arm/mach-omap2/mcbsp.c             |    2 +
 arch/arm/plat-omap/include/plat/mcbsp.h |   63 +++++
 arch/arm/plat-omap/mcbsp.c              |  396 ++++++++++++++++++++++++++++++-
 3 files changed, 460 insertions(+), 1 deletions(-)
arch/arm/mach-omap2/mcbsp.c +2 -0
index d601f94..be8fce3 100644
@@ -136,6 +136,7 @@ static struct omap_mcbsp_platform_data omap34xx_mcbsp_pdata[] = {
 	},
 	{
 		.phys_base	= OMAP34XX_MCBSP2_BASE,
+		.phys_base_st	= OMAP34XX_MCBSP2_ST_BASE,
 		.dma_rx_sync	= OMAP24XX_DMA_MCBSP2_RX,
 		.dma_tx_sync	= OMAP24XX_DMA_MCBSP2_TX,
 		.rx_irq		= INT_24XX_MCBSP2_IRQ_RX,
@@ -145,6 +146,7 @@ static struct omap_mcbsp_platform_data omap34xx_mcbsp_pdata[] = {
 	},
 	{
 		.phys_base	= OMAP34XX_MCBSP3_BASE,
+		.phys_base_st	= OMAP34XX_MCBSP3_ST_BASE,
 		.dma_rx_sync	= OMAP24XX_DMA_MCBSP3_RX,
 		.dma_tx_sync	= OMAP24XX_DMA_MCBSP3_TX,
 		.rx_irq		= INT_24XX_MCBSP3_IRQ_RX,
arch/arm/plat-omap/include/plat/mcbsp.h +63 -0

101 lines not on this page · raw message

arch/arm/plat-omap/mcbsp.c +395 -1

463 lines not on this page · raw message

Signature · 1 line
1.6.0.4
#2 lore raw

PATCH v3 2/2 ASoC: OMAP-McBSP: ASoC interface for McBSP sidetone

Add ASoC interface for OMAP McBSP2 and McBSP3 sidetones.

---
 sound/soc/omap/omap-mcbsp.c |  157 +++++++++++++++++++++++++++++++++++++++++++
 sound/soc/omap/omap-mcbsp.h |    2 +
 2 files changed, 159 insertions(+), 0 deletions(-)
sound/soc/omap/omap-mcbsp.c +157 -0
index c0039b3..8c26a65 100644
@@ -39,6 +39,14 @@
 
 #define OMAP_MCBSP_RATES	(SNDRV_PCM_RATE_8000_96000)
 
+#define OMAP_MCBSP_SOC_SINGLE_S16_EXT(xname, xmin, xmax, \
+	xhandler_get, xhandler_put) \
+{	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
+	.info = omap_mcbsp_st_info_volsw, \
+	.get = xhandler_get, .put = xhandler_put, \
+	.private_value = (unsigned long) &(struct soc_mixer_control) \
+	{.min = xmin, .max = xmax} }
+
 struct omap_mcbsp_data {
 	unsigned int			bus_id;
 	struct omap_mcbsp_reg_cfg	regs;
@@ -637,6 +645,155 @@ struct snd_soc_dai omap_mcbsp_dai[] = {
 
 EXPORT_SYMBOL_GPL(omap_mcbsp_dai);
 
+int omap_mcbsp_st_info_volsw(struct snd_kcontrol *kcontrol,
+			struct snd_ctl_elem_info *uinfo)
+{
+	struct soc_mixer_control *mc =
+		(struct soc_mixer_control *)kcontrol->private_value;
+	int max = mc->max;
+	int min = mc->min;
+
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+	uinfo->count = 1;
+	uinfo->value.integer.min = min;
+	uinfo->value.integer.max = max;
+	return 0;
+}
+
+static int omap_mcbsp_set_st_channel_vol(struct snd_kcontrol *kcontrol,
+					struct snd_ctl_elem_value *ucontrol,
+					int id, int channel)
+{
+	struct soc_mixer_control *mc =
+		(struct soc_mixer_control *)kcontrol->private_value;
+	int max = mc->max;
+	int min = mc->min;
+	int val = ucontrol->value.integer.value[0];
+
+	if (val < min || val > max)
+		return -EINVAL;
+
+	return omap_st_set_chgain((id)-1, val, 0, channel);
+}
+
+static int omap_mcbsp_get_st_channel_vol(struct snd_kcontrol *kcontrol,
+					struct snd_ctl_elem_value *ucontrol,
+					int id, int channel)
+{
+	s16 ch0gain, ch1gain;
+
+	if (omap_st_get_chgain((id)-1, &ch0gain, &ch1gain))
+		return -EAGAIN;
+
+	if (channel == OMAP_MCBSP_ST_CHANNEL_0)
+		ucontrol->value.integer.value[0] = ch0gain;
+	else if (channel == OMAP_MCBSP_ST_CHANNEL_1)
+		ucontrol->value.integer.value[0] = ch1gain;
+
+	return 0;
+}
+
+#define OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(id, channel)			\
+static int								\
+omap_mcbsp##id##_set_st_ch##channel##_volume(struct snd_kcontrol *kc,	\
+					struct snd_ctl_elem_value *uc)	\
+{									\
+	return omap_mcbsp_set_st_channel_vol(kc, uc, id, 		\
+				OMAP_MCBSP_ST_CHANNEL_##channel);	\
+}
+
+#define OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(id, channel)			\
+static int								\
+omap_mcbsp##id##_get_st_ch##channel##_volume(struct snd_kcontrol *kc,	\
+					struct snd_ctl_elem_value *uc)	\
+{									\
+	return omap_mcbsp_get_st_channel_vol(kc, uc, id,		\
+				OMAP_MCBSP_ST_CHANNEL_##channel);	\
+}
+
+OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(2, 0)
+OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(2, 1)
+OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(3, 0)
+OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(3, 1)
+OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(2, 0)
+OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(2, 1)
+OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(3, 0)
+OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(3, 1)
+
+static int omap_mcbsp_st_put_mode(struct snd_kcontrol *kcontrol,
+				struct snd_ctl_elem_value *ucontrol)
+{
+	struct soc_mixer_control *mc =
+		(struct soc_mixer_control *)kcontrol->private_value;
+	u8 value = ucontrol->value.integer.value[0];
+
+	if (value == omap_st_is_enabled(mc->reg))
+		return 0;
+
+	if (value)
+		omap_st_enable(mc->reg);
+	else
+		omap_st_disable(mc->reg);
+
+	return 1;
+}
+
+static int omap_mcbsp_st_get_mode(struct snd_kcontrol *kcontrol,
+				struct snd_ctl_elem_value *ucontrol)
+{
+	struct soc_mixer_control *mc =
+		(struct soc_mixer_control *)kcontrol->private_value;
+
+	ucontrol->value.integer.value[0] = omap_st_is_enabled(mc->reg);
+	return 0;
+}
+
+static const struct snd_kcontrol_new omap_mcbsp2_st_controls[] = {
+	SOC_SINGLE_EXT("McBSP2 Sidetone Switch", 1, 0, 1, 0,
+			omap_mcbsp_st_get_mode, omap_mcbsp_st_put_mode),
+	OMAP_MCBSP_SOC_SINGLE_S16_EXT("McBSP2 Sidetone Channel 0 Volume",
+				      -32768, 32767,
+				      omap_mcbsp2_get_st_ch0_volume,
+				      omap_mcbsp2_set_st_ch0_volume),
+	OMAP_MCBSP_SOC_SINGLE_S16_EXT("McBSP2 Sidetone Channel 1 Volume",
+				      -32768, 32767,
+				      omap_mcbsp2_get_st_ch1_volume,
+				      omap_mcbsp2_set_st_ch1_volume),
+};
+
+static const struct snd_kcontrol_new omap_mcbsp3_st_controls[] = {
+	SOC_SINGLE_EXT("McBSP3 Sidetone Switch", 2, 0, 1, 0,
+			omap_mcbsp_st_get_mode, omap_mcbsp_st_put_mode),
+	OMAP_MCBSP_SOC_SINGLE_S16_EXT("McBSP3 Sidetone Channel 0 Volume",
+				      -32768, 32767,
+				      omap_mcbsp3_get_st_ch0_volume,
+				      omap_mcbsp3_set_st_ch0_volume),
+	OMAP_MCBSP_SOC_SINGLE_S16_EXT("McBSP3 Sidetone Channel 1 Volume",
+				      -32768, 32767,
+				      omap_mcbsp3_get_st_ch1_volume,
+				      omap_mcbsp3_set_st_ch1_volume),
+};
+
+int omap_mcbsp_st_add_controls(struct snd_soc_codec *codec, int mcbsp_id)
+{
+	if (!cpu_is_omap34xx())
+		return -ENODEV;
+
+	switch (mcbsp_id) {
+	case 2: /* McBSP 2 */
+		return snd_soc_add_controls(codec, omap_mcbsp2_st_controls,
+					ARRAY_SIZE(omap_mcbsp2_st_controls));
+	case 3: /* McBSP 3 */
+		return snd_soc_add_controls(codec, omap_mcbsp3_st_controls,
+					ARRAY_SIZE(omap_mcbsp3_st_controls));
+	default:
+		break;
+	}
+
+	return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(omap_mcbsp_st_add_controls);
+
 static int __init snd_omap_mcbsp_init(void)
 {
 	return snd_soc_register_dais(omap_mcbsp_dai,
sound/soc/omap/omap-mcbsp.h +2 -0
index 1968d03..6c363e5 100644
@@ -57,4 +57,6 @@ enum omap_mcbsp_div {
 
 extern struct snd_soc_dai omap_mcbsp_dai[NUM_LINKS];
 
+int omap_mcbsp_st_add_controls(struct snd_soc_codec *codec, int mcbsp_id);
+
 #endif
Signature · 1 line
1.6.0.4
#3 lore raw

Re: [PATCHv3 2/2] ASoC: OMAP-McBSP: ASoC interface for McBSP sidetone

On Thursday 18 February 2010 14:37:15 Koskinen Ilkka (Nokia-D/Tampere) wrote:

...

Quoted 4 lines
sound/soc/omap/omap-mcbsp.c +4 -0
+static int omap_mcbsp_set_st_channel_vol(struct snd_kcontrol *kcontrol,
+					struct snd_ctl_elem_value *ucontrol,
+					int id, int channel)
+{

sound/soc/omap/omap-mcbsp.c struct snd_soc_dai omap_mcbsp_dai[] = { · line 676

Quoted 10 lines
sound/soc/omap/omap-mcbsp.c +10 -0
+	struct soc_mixer_control *mc =
+		(struct soc_mixer_control *)kcontrol->private_value;
+	int max = mc->max;
+	int min = mc->min;
+	int val = ucontrol->value.integer.value[0];
+
+	if (val < min || val > max)
+		return -EINVAL;
+
+	return omap_st_set_chgain((id)-1, val, 0, channel);

So how do you actually set the ch1 gain to other than 0?

int omap_st_set_chgain(unsigned int id, s16 ch0gain, s16 ch1gain, int channels);

So in any cases you are calling with ch1gain = 0, and depending on the selected channel you put that to ch0gain.
All in all, with this code you are only able to update ch0, and never the ch1.

Should than the omap_st_set_chgain have only one parameter for the gain, and the channel parameter tells the code to which channel to put the gain?

sound/soc/omap/omap-mcbsp.c struct snd_soc_dai omap_mcbsp_dai[] = { · line 686

Quoted 10 lines
sound/soc/omap/omap-mcbsp.c +10 -0
+}
+
+static int omap_mcbsp_get_st_channel_vol(struct snd_kcontrol *kcontrol,
+					struct snd_ctl_elem_value *ucontrol,
+					int id, int channel)
+{
+	s16 ch0gain, ch1gain;
+
+	if (omap_st_get_chgain((id)-1, &ch0gain, &ch1gain))
+		return -EAGAIN;

Than probably the omap_st_get_chgain should only retrieve the gain for one channel also?

Quoted 9 lines
sound/soc/omap/omap-mcbsp.c +9 -0
+
+	if (channel == OMAP_MCBSP_ST_CHANNEL_0)
+		ucontrol->value.integer.value[0] = ch0gain;
+	else if (channel == OMAP_MCBSP_ST_CHANNEL_1)
+		ucontrol->value.integer.value[0] = ch1gain;
+
+	return 0;
+}
+
Signature · 1 line
Péter
#4 lore raw

Re: [alsa-devel] [PATCHv3 2/2] ASoC: OMAP-McBSP: ASoC interface for McBSP sidetone

Quoted 21 lines · Ujfalusi Peter (Nokia-D/Tampere)

On Thursday 18 February 2010 14:37:15 Koskinen Ilkka (Nokia-D/Tampere) wrote:

...

Quoted 4 lines
sound/soc/omap/omap-mcbsp.c +4 -0
+static int omap_mcbsp_set_st_channel_vol(struct snd_kcontrol *kcontrol,
+                                     struct snd_ctl_elem_value *ucontrol,
+                                     int id, int channel)
+{

sound/soc/omap/omap-mcbsp.c struct snd_soc_dai omap_mcbsp_dai[] = { · line 676

Quoted 10 lines
sound/soc/omap/omap-mcbsp.c +10 -0
+     struct soc_mixer_control *mc =
+             (struct soc_mixer_control *)kcontrol->private_value;
+     int max = mc->max;
+     int min = mc->min;
+     int val = ucontrol->value.integer.value[0];
+
+     if (val < min || val > max)
+             return -EINVAL;
+
+     return omap_st_set_chgain((id)-1, val, 0, channel);

So how do you actually set the ch1 gain to other than 0?

Quoted 3 lines

int omap_st_set_chgain(unsigned int id, s16 ch0gain, s16 ch1gain, int channels);

So in any cases you are calling with ch1gain = 0, and depending on the selected channel you put that to ch0gain. All in all, with this code you are only able to update ch0, and never the ch1.

Damn, it seems that I have messed up my trees :( That's obviously from the time I was just experimenting it, and I fixed it some time ago already.

Quoted 16 lines

Should than the omap_st_set_chgain have only one parameter for the gain, and the channel parameter tells the code to which channel to put the gain?

sound/soc/omap/omap-mcbsp.c struct snd_soc_dai omap_mcbsp_dai[] = { · line 686

Quoted 10 lines
sound/soc/omap/omap-mcbsp.c +10 -0
+}
+
+static int omap_mcbsp_get_st_channel_vol(struct snd_kcontrol *kcontrol,
+                                     struct snd_ctl_elem_value *ucontrol,
+                                     int id, int channel)
+{
+     s16 ch0gain, ch1gain;
+
+     if (omap_st_get_chgain((id)-1, &ch0gain, &ch1gain))
+             return -EAGAIN;

Than probably the omap_st_get_chgain should only retrieve the gain for one channel also?

Yes, indeed.

Sorry for the confusion. I'll send the fixed patches soon.

Cheers, Ilkka

Quoted 17 lines

sound/soc/omap/omap-mcbsp.c struct snd_soc_dai omap_mcbsp_dai[] = { · line 695

Quoted 9 lines
sound/soc/omap/omap-mcbsp.c +9 -0
+
+     if (channel == OMAP_MCBSP_ST_CHANNEL_0)
+             ucontrol->value.integer.value[0] = ch0gain;
+     else if (channel == OMAP_MCBSP_ST_CHANNEL_1)
+             ucontrol->value.integer.value[0] = ch1gain;
+
+     return 0;
+}
+

--
Péter
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#5 lore raw
In reply to Ilkka Koskinen

arch/arm/plat-omap/mcbsp.c static inline void __devinit omap34xx_device_init(struct omap_mcbsp *mcbsp) · line 1653

Quoted 10 lines · On Thu, 18 Feb 2010 14:37:14 +0200 Ilkka Koskinen <[email protected]>…

static inline void __devexit omap34xx_device_exit(struct omap_mcbsp *mcbsp) {

arch/arm/plat-omap/mcbsp.c +5 -1
-	if (cpu_is_omap34xx())
+	if (cpu_is_omap34xx()) {
 		omap_additional_remove(mcbsp->dev);
+
+		if (mcbsp->id == 2 || mcbsp->id == 3)
+			omap_st_remove(mcbsp);
+	}
 }

Are you sure about these ids? Same comment to the patch 2 as well. Worth to check.

Signature · 1 line
Jarkko
#6 lore raw

Hello,

Quoted 16 lines · On Thursday 18 February 2010 15:24:13 ext Jarkko Nikula wrote:

On Thu, 18 Feb 2010 14:37:14 +0200

Quoted 13 lines · Ilkka Koskinen

static inline void __devexit omap34xx_device_exit(struct omap_mcbsp *mcbsp) {

arch/arm/plat-omap/mcbsp.c +5 -1
-	if (cpu_is_omap34xx())
+	if (cpu_is_omap34xx()) {
 
 		omap_additional_remove(mcbsp->dev);
 
+
+		if (mcbsp->id == 2 || mcbsp->id == 3)
+			omap_st_remove(mcbsp);
+	}
Quoted 4 lines
Quoted 1 line

}

Are you sure about these ids? Same comment to the patch 2 as well. Worth to check.

They are correct.
mcbsp->id is 1 based (1 -> McBSP1, 2 -> McBSP2, etc) While the exported functions expect the id to be 0 based (0 -> McBSP1, 1 -> McBSP2, etc)

But, yes it is confusing at times...

Signature · 1 line
Péter
#7 lore raw
Quoted 10 lines · On Thu, 18 Feb 2010 15:56:03 +0200 Peter Ujfalusi <[email protected]>…
Quoted 2 lines

Are you sure about these ids? Same comment to the patch 2 as well. Worth to check.

They are correct.
mcbsp->id is 1 based (1 -> McBSP1, 2 -> McBSP2, etc) While the exported functions expect the id to be 0 based (0 -> McBSP1, 1 -> McBSP2, etc)

But, yes it is confusing at times...

Definitely. As existing API is using 0 based indexing, it's better to use here as well. That would make the lines like below simpler too :-)

+ return omap_st_set_chgain((id)-1, val, 0, channel);

Signature · 1 line
Jarkko