Skip to contentSkip to conversation

ALC562[123] / t5325 sound support - try 2

PATCH Superseded Arnaud Patard (Rtp) 2 participants 14 messages Oct 12, 2010 – Oct 13, 2010

Subsystems (4)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover ALC562[123] / t5325 sound support - try 2

Hi,

Here is a new try to get merged sound support for the alc562[123] codecs and HP's t5325 thin client merged. Not a lot of changes since last try. All of them are to address the comments I had.

Thanks,
Arnaud

#1 lore raw

PATCH 1/3 ASoC: add support for alc562[123] codecs

This patch is adding support for alc562[123] codecs. It's based on the source code available in HP source code and other places.

sound/soc/codecs/Kconfig +5 -0
Index: sound-2.6/sound/soc/codecs/Kconfig
===================================================================
@@ -22,6 +22,7 @@
 	select SND_SOC_AK4535 if I2C
 	select SND_SOC_AK4642 if I2C
 	select SND_SOC_AK4671 if I2C
+	select SND_SOC_ALC562 if I2C
 	select SND_SOC_CQ0093VC if MFD_DAVINCI_VOICECODEC
 	select SND_SOC_CS42L51 if I2C
 	select SND_SOC_CS4270 if I2C
@@ -126,6 +127,9 @@
 config SND_SOC_AK4671
 	tristate
 
+config SND_SOC_ALC5623
+       tristate
+
 config SND_SOC_CQ0093VC
 	tristate
 
@@ -305,3 +309,4 @@
 
 config SND_SOC_WM9090
 	tristate
+
sound/soc/codecs/Makefile +2 -0
Index: sound-2.6/sound/soc/codecs/Makefile
===================================================================
@@ -16,6 +16,7 @@
 snd-soc-da7210-objs := da7210.o
 snd-soc-l3-objs := l3.o
 snd-soc-pcm3008-objs := pcm3008.o
+snd-soc-alc5623-objs := alc5623.o
 snd-soc-spdif-objs := spdif_transciever.o
 snd-soc-ssm2602-objs := ssm2602.o
 snd-soc-stac9766-objs := stac9766.o
@@ -88,6 +89,7 @@
 obj-$(CONFIG_SND_SOC_L3)	+= snd-soc-l3.o
 obj-$(CONFIG_SND_SOC_JZ4740_CODEC)	+= snd-soc-jz4740-codec.o
 obj-$(CONFIG_SND_SOC_PCM3008)	+= snd-soc-pcm3008.o
+obj-$(CONFIG_SND_SOC_ALC5623)    += snd-soc-alc5623.o
 obj-$(CONFIG_SND_SOC_SPDIF)	+= snd-soc-spdif.o
 obj-$(CONFIG_SND_SOC_SSM2602)	+= snd-soc-ssm2602.o
 obj-$(CONFIG_SND_SOC_STAC9766)	+= snd-soc-stac9766.o
sound/soc/codecs/alc5623.c new file +1149 -0

1,149 lines not on this page · raw message

sound/soc/codecs/alc5623.h new file +161 -0

161 lines not on this page · raw message

include/sound/alc5623.h new file +15 -0
Index: sound-2.6/include/sound/alc5623.h
===================================================================
@@ -0,0 +1,15 @@
+#ifndef _INCLUDE_SOUND_ALC5623_H
+#define _INCLUDE_SOUND_ALC5623_H
+struct alc5623_platform_data {
+	/* configure :                              */
+	/* Lineout/Speaker Amps Vmid ratio control  */
+	/* enable/disable adc/dac high pass filters */
+	unsigned int add_ctrl;
+	/* configure :                              */
+	/* output to enable when jack is low        */
+	/* output to enable when jack is high       */
+	/* jack detect (gpio/nc/jack detect [12]    */
+	unsigned int jack_det_ctrl;
+};
+#endif
+
#2 lore raw

Re: [patch 1/3] ASoC: add support for alc562[123] codecs

Quoted 2 lines · Arnaud Patard

This patch is adding support for alc562[123] codecs. It's based on the source code available in HP source code and other places.

Looks very good - a few minor things below but they should be fairly easy to fix up.

sound/soc/codecs/alc5623.c line 72

Quoted 5 lines
sound/soc/codecs/alc5623.c new file +5 -0
+static int amp_mixer_event(struct snd_soc_dapm_widget *w,
+	struct snd_kcontrol *kcontrol, int event)
+{
+	/* index 0x46: class-d internal register */
+	snd_soc_write(w->codec, ALC5623_HID_CTRL_INDEX, 0x46);

This is a bit magic; some comments would help.

sound/soc/codecs/alc5623.c line 562

Quoted 11 lines
sound/soc/codecs/alc5623.c new file +11 -0
+	if (pll_id == ALC5623_PLL_FR_MCLK) {
+		for (i = 0; i < ARRAY_SIZE(codec_master_pll_div); i++) {
+			if (codec_master_pll_div[i].pll_in == freq_in
+			   && codec_master_pll_div[i].pll_out == freq_out) {
+				/* PLL source from MCLK */
+				pll_div  = codec_master_pll_div[i].regvalue;
+				break;
+			}
+		}
+	} else {
+		for (i = 0; i < ARRAY_SIZE(codec_slave_pll_div); i++) {

I'd expect a switch statement here.

sound/soc/codecs/alc5623.c line 738

Quoted 7 lines
sound/soc/codecs/alc5623.c new file +7 -0
+	coeff = get_coeff(codec, rate);
+	if (coeff >= 0) {
+		coeff = coeff_div[coeff].regvalue;
+		dev_dbg(codec->dev, "%s: sysclk=%d,rate=%d,coeff=0x%04x\n",
+			__func__, alc5623->sysclk, rate, coeff);
+		snd_soc_write(codec, ALC5623_STEREO_AD_DA_CLK_CTRL, coeff);
+	}

Shouldn't we be returning an error if we can't get coefficients?

sound/soc/codecs/alc5623.c line 808

Quoted 4 lines
sound/soc/codecs/alc5623.c new file +4 -0
+	switch (level) {
+	case SND_SOC_BIAS_ON:
+		enable_power_depop(codec);
+		break;

enable_power_depop() takes a rather long time - about 500ms - which is surprising for _ON. Are you sure it should be done here?

sound/soc/codecs/alc5623.c line 874

Quoted 5 lines
sound/soc/codecs/alc5623.c new file +5 -0
+static int alc5623_suspend(struct snd_soc_codec *codec, pm_message_t mesg)
+{
+	/* we only need to suspend if we are a valid card */
+	if (!codec->card)
+		return 0;

This isn't needed any more, this won't get called if there isn't a card.

sound/soc/codecs/alc5623.c line 903

Quoted 7 lines
sound/soc/codecs/alc5623.c new file +7 -0
+	/* charge alc5623 caps */
+	if (codec->suspend_bias_level == SND_SOC_BIAS_ON) {
+		alc5623_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+		codec->bias_level = SND_SOC_BIAS_ON;
+		schedule_delayed_work(&codec->delayed_work,
+			msecs_to_jiffies(caps_charge));
+	}

Just go directly to the bias level you want, don't use delayed work. ASoC will already do resume out of line with the main system so there's no need to do this and it will disrupt audio operation just after resume if you do it.

Quoted 3 lines

+/*
+ * rt5623.h -- audio driver for ALC5623
+ *

Bitrot here.

#3 lore raw

Re: [patch 1/3] ASoC: add support for alc562[123] codecs

Mark Brown <[email protected]> writes:

Hi,

Quoted 8 lines · Arnaud Patard
Quoted 3 lines

This patch is adding support for alc562[123] codecs. It's based on the source code available in HP source code and other places.

Looks very good - a few minor things below but they should be fairly easy to fix up.

Quoted 7 lines

sound/soc/codecs/alc5623.c line 72

Quoted 5 lines
sound/soc/codecs/alc5623.c new file +5 -0
+static int amp_mixer_event(struct snd_soc_dapm_widget *w,
+	struct snd_kcontrol *kcontrol, int event)
+{
+	/* index 0x46: class-d internal register */
+	snd_soc_write(w->codec, ALC5623_HID_CTRL_INDEX, 0x46);

This is a bit magic; some comments would help.

ok. I've added a comment. The aim is to power on/off the class-d amp parts and to do that one has to write to index-46h reg and to do that one has to write 0x46 to ALC5623_HID_CTRL_INDEX and then the value into ALC5623_HID_CTRL_DATA.

Quoted 14 lines

sound/soc/codecs/alc5623.c line 562

Quoted 12 lines
sound/soc/codecs/alc5623.c new file +11 -0
+	if (pll_id == ALC5623_PLL_FR_MCLK) {
+		for (i = 0; i < ARRAY_SIZE(codec_master_pll_div); i++) {
+			if (codec_master_pll_div[i].pll_in == freq_in
+			   && codec_master_pll_div[i].pll_out == freq_out) {
+				/* PLL source from MCLK */
+				pll_div  = codec_master_pll_div[i].regvalue;
+				break;
+			}
+		}
+	} else {
+		for (i = 0; i < ARRAY_SIZE(codec_slave_pll_div); i++) {

I'd expect a switch statement here.

ok.

Quoted 10 lines

sound/soc/codecs/alc5623.c line 738

Quoted 8 lines
sound/soc/codecs/alc5623.c new file +7 -0
+	coeff = get_coeff(codec, rate);
+	if (coeff >= 0) {
+		coeff = coeff_div[coeff].regvalue;
+		dev_dbg(codec->dev, "%s: sysclk=%d,rate=%d,coeff=0x%04x\n",
+			__func__, alc5623->sysclk, rate, coeff);
+		snd_soc_write(codec, ALC5623_STEREO_AD_DA_CLK_CTRL, coeff);
+	}

Shouldn't we be returning an error if we can't get coefficients?

I was hoping that current value of the ALC5623_STEREO_AD_DA_CLK_CTRL would be ok but you're probably right. It should be safer to return an error.

Quoted 8 lines

sound/soc/codecs/alc5623.c line 808

Quoted 5 lines
sound/soc/codecs/alc5623.c new file +4 -0
+	switch (level) {
+	case SND_SOC_BIAS_ON:
+		enable_power_depop(codec);
+		break;

enable_power_depop() takes a rather long time - about 500ms - which is surprising for _ON. Are you sure it should be done here?

It was there in the original driver and when working on this driver, I didn't see any reason for moving it elsewhere. tbh, if I have to move it elsewhere, I don't know where I'll put it.

Quoted 8 lines

sound/soc/codecs/alc5623.c line 874

Quoted 6 lines
sound/soc/codecs/alc5623.c new file +5 -0
+static int alc5623_suspend(struct snd_soc_codec *codec, pm_message_t mesg)
+{
+	/* we only need to suspend if we are a valid card */
+	if (!codec->card)
+		return 0;

This isn't needed any more, this won't get called if there isn't a card.

ok. removed.

Quoted 13 lines

sound/soc/codecs/alc5623.c line 903

Quoted 8 lines
sound/soc/codecs/alc5623.c new file +7 -0
+	/* charge alc5623 caps */
+	if (codec->suspend_bias_level == SND_SOC_BIAS_ON) {
+		alc5623_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+		codec->bias_level = SND_SOC_BIAS_ON;
+		schedule_delayed_work(&codec->delayed_work,
+			msecs_to_jiffies(caps_charge));
+	}

Just go directly to the bias level you want, don't use delayed work. ASoC will already do resume out of line with the main system so there's no need to do this and it will disrupt audio operation just after resume if you do it.

ok.

Arnaud

#4 lore raw

Re: [patch 1/3] ASoC: add support for alc562[123] codecs

Quoted 10 lines · Arnaud Patard
Quoted 7 lines · Mark Brown

sound/soc/codecs/alc5623.c line 808

Quoted 4 lines
sound/soc/codecs/alc5623.c new file +4 -0
+	switch (level) {
+	case SND_SOC_BIAS_ON:
+		enable_power_depop(codec);
+		break;

enable_power_depop() takes a rather long time - about 500ms - which is surprising for _ON. Are you sure it should be done here?

Quoted 3 lines

It was there in the original driver and when working on this driver, I didn't see any reason for moving it elsewhere. tbh, if I have to move it elsewhere, I don't know where I'll put it.

Normally _PREPARE if you must do it whenever bringing up playback but generally you should try to do anything really slow when bringing the biases up to standby. Bear in mind that I've no idea what's actually being done here...

#5 lore raw

Re: [patch 1/3] ASoC: add support for alc562[123] codecs

Quoted 11 lines · Mark Brown
Quoted 9 lines · Arnaud Patard
Quoted 7 lines · Mark Brown

sound/soc/codecs/alc5623.c line 808

Quoted 4 lines
sound/soc/codecs/alc5623.c new file +4 -0
+	switch (level) {
+	case SND_SOC_BIAS_ON:
+		enable_power_depop(codec);
+		break;

enable_power_depop() takes a rather long time - about 500ms - which is surprising for _ON. Are you sure it should be done here?

Quoted 8 lines
Quoted 3 lines

It was there in the original driver and when working on this driver, I didn't see any reason for moving it elsewhere. tbh, if I have to move it elsewhere, I don't know where I'll put it.

Normally _PREPARE if you must do it whenever bringing up playback but generally you should try to do anything really slow when bringing the biases up to standby. Bear in mind that I've no idea what's actually being done here...

The power_depop stuff aims at avoiding "pop noise" in the output according to the datasheet which iiuc happens when going from standby to on.
Unfortunately, I can't give details because it's described in the codec application note which I've been unable to find.

Arnaud

#6 lore raw

PATCH 2/3 kirkwood: Add audio support to hp t5325 thin clients

In reply to Arnaud Patard (Rtp)

This patch is adding support for hp t5325 thin clients. There's a alc5623 codec connected to the i2s interface.

sound/soc/kirkwood/Kconfig +10 -0
Index: sound-2.6/sound/soc/kirkwood/Kconfig
===================================================================
@@ -18,3 +18,13 @@
 	  Say Y if you want to add support for SoC audio on
 	  Openrd Client.
 
+config SND_KIRKWOOD_SOC_T5325
+	tristate "SoC Audio support for HP t5325"
+	#depends on SND_KIRKWOOD_SOC && MACH_T5325
+	depends on SND_KIRKWOOD_SOC
+	select SND_KIRKWOOD_SOC_I2S
+	select SND_SOC_ALC5623
+	help
+	  Say Y if you want to add support for SoC audio on
+	  the HP t5325 thin client.
+
sound/soc/kirkwood/Makefile +2 -0
Index: sound-2.6/sound/soc/kirkwood/Makefile
===================================================================
@@ -5,5 +5,7 @@
 obj-$(CONFIG_SND_KIRKWOOD_SOC_I2S) += snd-soc-kirkwood-i2s.o
 
 snd-soc-openrd-objs := kirkwood-openrd.o
+snd-soc-t5325-objs := kirkwood-t5325.o
 
 obj-$(CONFIG_SND_KIRKWOOD_SOC_OPENRD) += snd-soc-openrd.o
+obj-$(CONFIG_SND_KIRKWOOD_SOC_T5325) += snd-soc-t5325.o
sound/soc/kirkwood/kirkwood-t5325.c new file +153 -0

153 lines not on this page · raw message

#7 lore raw

Re: [patch 2/3] kirkwood: Add audio support to hp t5325 thin clients

sound/soc/kirkwood/Kconfig line 23

Quoted 3 lines · Arnaud Patard
sound/soc/kirkwood/Kconfig +3 -0
+config SND_KIRKWOOD_SOC_T5325
+	tristate "SoC Audio support for HP t5325"
+	#depends on SND_KIRKWOOD_SOC && MACH_T5325

Hrm?

sound/soc/kirkwood/kirkwood-t5325.c line 53

Quoted 12 lines
sound/soc/kirkwood/kirkwood-t5325.c new file +12 -0
+	switch (params_rate(params)) {
+	default:
+	case 44100:
+		freq = 11289600;
+		break;
+	case 48000:
+		freq = 12288000;
+		break;
+	case 96000:
+		freq = 24576000;
+		break;
+	}

This should have a default: or (better) just be rewritten to use params_rate(params) * 256 as the sysclk.

sound/soc/kirkwood/kirkwood-t5325.c line 153

Quoted 2 lines
sound/soc/kirkwood/kirkwood-t5325.c new file +2 -0
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:soc-audio");

No, you're registering the device here not the driver.

#8 lore raw

PATCH 3/3 t5325: add audio support

In reply to Arnaud Patard (Rtp)

This patch declares the i2c audio codec and initialise audio.

arch/arm/mach-kirkwood/t5325-setup.c +17 -0
Index: sound-2.6/arch/arm/mach-kirkwood/t5325-setup.c
===================================================================
@@ -23,6 +23,7 @@
 #include <linux/gpio.h>
 #include <linux/gpio_keys.h>
 #include <linux/input.h>
+#include <sound/alc5623.h>
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 #include <mach/kirkwood.h>
@@ -134,6 +135,7 @@
 	MPP33_GE1_TXCTL,
 	MPP39_AU_I2SBCLK,
 	MPP40_AU_I2SDO,
+	MPP43_AU_I2SDI,
 	MPP41_AU_I2SLRCLK,
 	MPP42_AU_I2SMCLK,
 	MPP45_GPIO,		/* Power button */
@@ -141,6 +143,18 @@
 	0
 };
 
+static struct alc5623_platform_data alc5621_data = {
+	.add_ctrl = 0x3700,
+	.jack_det_ctrl = 0x4810,
+};
+
+static struct i2c_board_info i2c_board_info[] __initdata = {
+	{
+		I2C_BOARD_INFO("alc5621", 0x1a),
+		.platform_data = &alc5621_data,
+	},
+};
+
 #define HP_T5325_GPIO_POWER_OFF		48
 
 static void hp_t5325_power_off(void)
@@ -166,6 +180,9 @@
 	kirkwood_ehci_init();
 	platform_device_register(&hp_t5325_button_device);
 
+	i2c_register_board_info(0, i2c_board_info, ARRAY_SIZE(i2c_board_info));
+	kirkwood_audio_init();
+
 	if (gpio_request(HP_T5325_GPIO_POWER_OFF, "power-off") == 0 &&
 	    gpio_direction_output(HP_T5325_GPIO_POWER_OFF, 0) == 0)
 		pm_power_off = hp_t5325_power_off;
#9 lore raw

Re: [patch 3/3] t5325: add audio support

Quoted 2 lines · Arnaud Patard

This patch declares the i2c audio codec and initialise audio.

Looks like the changelogs for this and the previous patch got transposed.

Quoted 1 line

+#include <sound/alc5623.h>

This will need to be merged along with the CODEC driver.

#10 lore raw

Re: [patch 3/3] t5325: add audio support

Quoted 6 lines · Mark Brown
Quoted 2 lines · Arnaud Patard

This patch declares the i2c audio codec and initialise audio.

Looks like the changelogs for this and the previous patch got transposed

It's bad wording then. For me the changelog is fine. It means that :

- it's adding the alc5621 codec in the i2c bard info
- initialise kirkwood audio stuff by calling kirkwood_audio_init().

Maybe putting the explanations above would be better ?

Thanks,
Arnaud

#11 lore raw

Re: [patch 3/3] t5325: add audio support

Quoted 8 lines · Arnaud Patard
Quoted 5 lines · Mark Brown
Quoted 1 line · Arnaud Patard

This patch declares the i2c audio codec and initialise audio.

Looks like the changelogs for this and the previous patch got transposed

Quoted 6 lines

It's bad wording then. For me the changelog is fine. It means that :

- it's adding the alc5621 codec in the i2c bard info
- initialise kirkwood audio stuff by calling kirkwood_audio_init().

Maybe putting the explanations above would be better ?

Oh, actually the problem is that you've not prefixed the ASoC patches with ASoC: so they look like they're supposed to be arch/arm patches (2/3 being the main offender).

#12 lore raw

Re: [patch 3/3] t5325: add audio support

Quoted 11 lines · Mark Brown
Quoted 9 lines · Arnaud Patard
Quoted 5 lines · Mark Brown
Quoted 1 line · Arnaud Patard

This patch declares the i2c audio codec and initialise audio.

Looks like the changelogs for this and the previous patch got transposed

It's bad wording then. For me the changelog is fine. It means that :

Quoted 8 lines
Quoted 4 lines

- it's adding the alc5621 codec in the i2c bard info
- initialise kirkwood audio stuff by calling kirkwood_audio_init().

Maybe putting the explanations above would be better ?

Oh, actually the problem is that you've not prefixed the ASoC patches with ASoC: so they look like they're supposed to be arch/arm patches (2/3 being the main offender).

Oh, I see. This patch is modify arch/arm/mach-kirkwood/t5325-setup.c and is adding only audio stuff and needs a header coming from previous patches. That's why I've put it in the patch serie. imho doing like this should make life easier for everyone.

Will add and "ASoC:" in the patch subject.

Thanks,
Arnaud

#13 lore raw

Re: [patch 3/3] t5325: add audio support

Quoted 6 lines · Arnaud Patard
Quoted 3 lines · Mark Brown

Oh, actually the problem is that you've not prefixed the ASoC patches with ASoC: so they look like they're supposed to be arch/arm patches (2/3 being the main offender).

Quoted 6 lines

Oh, I see. This patch is modify arch/arm/mach-kirkwood/t5325-setup.c and is adding only audio stuff and needs a header coming from previous patches. That's why I've put it in the patch serie. imho doing like this should make life easier for everyone.

Will add and "ASoC:" in the patch subject.

This one is for arch/arm so doesn't want that - the patch before is for ASoC and does.