ASoC: add RT286 CODEC driver
Subsystems (3)
PATCH v3 1/1 ASoC: add RT286 CODEC driver
From: Bard Liao <[email protected]>
This patch adds the ALC286 codec driver.
---
* Initialize all cache registers in rt286_reg_cache, and remove rt286_reg_cache size define.
--- include/sound/rt286.h | 19 + sound/soc/codecs/Kconfig | 4 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/rt286.c | 1373 +++++++++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/rt286.h | 89 +++ 5 files changed, 1487 insertions(+) create mode 100644 include/sound/rt286.h create mode 100644 sound/soc/codecs/rt286.c create mode 100644 sound/soc/codecs/rt286.h
include/sound/rt286.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* linux/sound/rt286.h -- Platform data for RT286 +* +* Copyright 2013 Realtek Microelectronics +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef __LINUX_SND_RT286_H +#define __LINUX_SND_RT286_H + +struct rt286_platform_data { +bool cbj_en;/*combo jack enable*/ +bool irq_en;/*IRQ enable*/ +}; + +#endif
sound/soc/codecs/Kconfig +4 -0
@@ -61,6 +61,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_PCM3008 select SND_SOC_RT5631 if I2C select SND_SOC_RT5640 if I2C + select SND_SOC_RT286 if I2C select SND_SOC_SGTL5000 if I2C select SND_SOC_SI476X if MFD_SI476X_CORE select SND_SOC_SN95031 if INTEL_SCU_IPC
@@ -319,6 +320,9 @@ config SND_SOC_RT5631 config SND_SOC_RT5640 tristate +config SND_SOC_RT286 + tristate + #Freescale sgtl5000 codec config SND_SOC_SGTL5000 tristate
sound/soc/codecs/Makefile +2 -0
@@ -48,6 +48,7 @@ snd-soc-pcm1792a-codec-objs := pcm1792a.o snd-soc-pcm3008-objs := pcm3008.o snd-soc-rt5631-objs := rt5631.o snd-soc-rt5640-objs := rt5640.o +snd-soc-rt286-objs := rt286.o snd-soc-sgtl5000-objs := sgtl5000.o snd-soc-alc5623-objs := alc5623.o snd-soc-alc5632-objs := alc5632.o
@@ -181,6 +182,7 @@ obj-$(CONFIG_SND_SOC_PCM1792A) += snd-soc-pcm1792a-codec.o obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o +obj-$(CONFIG_SND_SOC_RT286) += snd-soc-rt286.o obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o obj-$(CONFIG_SND_SOC_SIGMADSP) += snd-soc-sigmadsp.o obj-$(CONFIG_SND_SOC_SI476X) += snd-soc-si476x.o
sound/soc/codecs/rt286.c new file +1373 -0
1,373 lines not on this page · raw message
sound/soc/codecs/rt286.h new file +89 -0
89 lines not on this page · raw message
Signature · 1 line
1.8.1.1.439.g50a6b54
Mark Brown
maintainerOn Wed, Dec 11, 2013 at 09:58:10AM +0800, [email protected] wrote:
This is an improvement but there are still quite a few problems here.
sound/soc/codecs/Makefile snd-soc-pcm1792a-codec-objs := pcm1792a.o · line 54
Quoted 12 lines
sound/soc/codecs/Makefile +1
-0@@ -48,6 +48,7 @@ snd-soc-pcm1792a-codec-objs := pcm1792a.o snd-soc-pcm3008-objs := pcm3008.o snd-soc-rt5631-objs := rt5631.o snd-soc-rt5640-objs := rt5640.o +snd-soc-rt286-objs := rt286.o snd-soc-sgtl5000-objs := sgtl5000.o snd-soc-alc5623-objs := alc5623.o snd-soc-alc5632-objs := alc5632.o
Keep this file sorted please.
Quoted 1 line
+static int
rt286_hw_read(void *context, unsigned int reg, unsigned int *value)
To repeat what I said when reviewing the first version of this you should be using regmap not open coding your register I/O. This looks totally standard...
sound/soc/codecs/Makefile
Quoted 7 lines
sound/soc/codecs/Makefile +6
-0+int rt286_jack_detect(struct snd_soc_codec *codec, bool *hp, bool *mic) +{ + struct rt286_priv *rt286 = snd_soc_codec_get_drvdata(codec); + unsigned int val; + int i; +EXPORT_SYMBOL_GPL(rt286_jack_detect);
Use the standard jack detection APIs.
sound/soc/codecs/Makefile
Quoted 3 lines
sound/soc/codecs/Makefile +3
-0+ if (rt286->pdata.irq_en) + rt286_index_update_bits(codec, + NODE_ID_VENDOR_REGISTERS, 0x33, 0x0002, 0x0002);
Why would the system ever want to supply an interrupt and not use it?
sound/soc/codecs/Makefile
Quoted 7 lines
sound/soc/codecs/Makefile +7
-0+ /* Set configuration default */ + rt286_write(codec, AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, + NODE_ID_MIC1, 0x00); + rt286_write(codec, AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, + NODE_ID_DMIC1, 0x00); + rt286_write(codec, AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, + NODE_ID_DMIC2, 0x00);
Why are the silicon defaults not adequate?
Quoted 13 lines
sound/soc/codecs/Makefile +13
-0+static int rt286_hp_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + struct snd_soc_codec *codec = w->codec; + unsigned int val; + + switch (event) { + case SND_SOC_DAPM_POST_PMU: + val = snd_soc_read(codec, NODE_ID_HP_OUT) & 0x8080; + switch (val) { + case 0x0: + rt286_write(codec, AC_VERB_SET_AMP_GAIN_MUTE, + NODE_ID_HP_OUT, 0xb000);
sound/soc/codecs/Makefile
Quoted 10 lines
sound/soc/codecs/Makefile +10
-0+ break; + case 0x8000: + rt286_write(codec, AC_VERB_SET_AMP_GAIN_MUTE, + NODE_ID_HP_OUT, 0x9000); + break; + case 0x0080: + rt286_write(codec, AC_VERB_SET_AMP_GAIN_MUTE, + NODE_ID_HP_OUT, 0xa000); + break; + }
This is rather unclear. What is it doing?
sound/soc/codecs/Makefile
Quoted 7 lines
sound/soc/codecs/Makefile +7
-0+static int rt286_set_dai_sysclk(struct snd_soc_dai *dai, + int clk_id, unsigned int freq, int dir) +{ + struct snd_soc_codec *codec = dai->codec; + struct rt286_priv *rt286 = snd_soc_codec_get_drvdata(codec); + + pr_debug("%s freq=%d\n", __func__, freq);
dev_dbg().
Quoted 4 lines
sound/soc/codecs/Makefile +4
-0+static int rt286_set_bias_level(struct snd_soc_codec *codec, + enum snd_soc_bias_level level) +{ + switch (level) {
sound/soc/codecs/Makefile
Quoted 10 lines
sound/soc/codecs/Makefile +10
-0+ case SND_SOC_BIAS_PREPARE: + if (SND_SOC_BIAS_STANDBY == codec->dapm.bias_level) + rt286_write(codec, AC_VERB_SET_POWER_STATE, + NODE_ID_AUDIO_FUNCTION_GROUP, AC_PWRST_D0); + break; + + case SND_SOC_BIAS_OFF: + rt286_write(codec, AC_VERB_SET_POWER_STATE, + NODE_ID_AUDIO_FUNCTION_GROUP, AC_PWRST_D3); + break;
These aren't matched - you power up when leaving standby but only power down when you go to off. That's a bit odd and probably won't do the right thing and will leave the CODEC powered up all the time since you don't set idle_bias_off (though perhaps you should).
sound/soc/codecs/Makefile
Quoted 3 lines
sound/soc/codecs/Makefile +3
-0+static int rt286_probe(struct snd_soc_codec *codec) +{ + hw_configure(codec);
Just inline hw_configure(), there's no point having a separate function with only one use in a tiny function.
sound/soc/codecs/Makefile
Quoted 5 lines
sound/soc/codecs/Makefile +5
-0+static int rt286_remove(struct snd_soc_codec *codec) +{ + rt286_set_bias_level(codec, SND_SOC_BIAS_OFF); + return 0; +}
The framework should power down the device for you.
Quoted 10 lines
sound/soc/codecs/Makefile +10
-0+struct snd_soc_dai_driver rt286_dai[] = { + { + .name = "rt286-aif1", + .id = RT286_AIF1, + .playback = { + .stream_name = "AIF1 Playback", + .channels_min = 1, + .channels_max = 2, + .rates = RT286_STEREO_RATES, + .formats = RT286_FORMATS,
sound/soc/codecs/Makefile
Quoted 10 lines
sound/soc/codecs/Makefile +10
-0+ }, + .capture = { + .stream_name = "AIF1 Capture", + .channels_min = 1, + .channels_max = 2, + .rates = RT286_STEREO_RATES, + .formats = RT286_FORMATS, + }, + .ops = &rt286_aif_dai_ops, + },
Your code handles up to 16 channels, and looking at the code I suspect you need symmetric_rates.
Quoted 4 lines
sound/soc/codecs/Makefile +4
-0+ + ret = devm_snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt286, + rt286_dai, ARRAY_SIZE(rt286_dai)); + if (ret < 0)
sound/soc/codecs/Makefile
Quoted 10 lines
sound/soc/codecs/Makefile +10
-0+ goto err; + + return 0; +err: + return ret; +} + +static int rt286_i2c_remove(struct i2c_client *i2c) +{ + snd_soc_unregister_codec(&i2c->dev);
Remove this, the whole point of devm_ is that it cleans up for you.
I'm also not seeing any code for interrupts even though there appears to be some code to initialise them in the driver.
sound/soc/codecs/Makefile
Quoted 6 lines
sound/soc/codecs/Makefile +6
-0+static int __init rt286_modinit(void) +{ + return i2c_add_driver(&rt286_i2c_driver); +} + +module_init(rt286_modinit);
module_i2c_driver().
Quoted 13 lines
sound/soc/codecs/Makefile +13
-0+#define NODE_ID_AUDIO_FUNCTION_GROUP 0x01 +#define NODE_ID_DAC_OUT1 0x02 +#define NODE_ID_DAC_OUT2 0x03 +#define NODE_ID_ADC_IN1 0x09 +#define NODE_ID_ADC_IN2 0x08 +#define NODE_ID_MIXER_IN 0x0b +#define NODE_ID_MIXER_OUT1 0x0c +#define NODE_ID_MIXER_OUT2 0x0d +#define NODE_ID_DMIC1 0x12 +#define NODE_ID_DMIC2 0x13 +#define NODE_ID_SPK_OUT 0x14 +#define NODE_ID_MIC1 0x18 +#define NODE_ID_LINE1 0x1a
sound/soc/codecs/Makefile
Quoted 10 lines
sound/soc/codecs/Makefile +9
-0+#define NODE_ID_BEEP 0x1d +#define NODE_ID_SPDIF 0x1e +#define NODE_ID_VENDOR_REGISTERS 0x20 +#define NODE_ID_HP_OUT 0x21 +#define NODE_ID_MIXER_IN1 0x22 +#define NODE_ID_MIXER_IN2 0x23 +#define TOTAL_NODE_ID 0x23 +#define CONNECTION_INDEX_MIC1 0X0 +#define CONNECTION_INDEX_DMIC 0X5
These need namespacing if they're device specific.
Quoted 9 lines
-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Thursday, December 19, 2013 3:21 AM
To: Bard Liao
Cc: [email protected]; [email protected]; Flove; Oder Chiou; [email protected]
Subject: Re: [PATCH v3] ASoC: add RT286 CODEC driver
Quoted 5 lines
sound/soc/codecs/rt286.c line 546
Quoted 3 lines
sound/soc/codecs/rt286.c new file +3
-0+if (rt286->pdata.irq_en) +rt286_index_update_bits (codec, +NODE_ID_VENDOR_REGISTERS ,0x33 ,0x0002 ,0x0002 );Why would the system ever want to supply an interrupt and not use it?
The codec support a configurable irq pin which can be disable or enable. Some customers may not use it.
So, I add a flag in platform data to configure it.
Quoted 10 lines
sound/soc/codecs/rt286.c line 565
Quoted 8 lines
sound/soc/codecs/rt286.c new file +7
-0+/* Set configuration default */ +rt286_write (codec,AC_VERB_SET_CONFIG_DEFAULT_BYTES_3 , +NODE_ID_MIC1 ,0x00 ); +rt286_write (codec,AC_VERB_SET_CONFIG_DEFAULT_BYTES_3 , +NODE_ID_DMIC1 ,0x00 ); +rt286_write (codec,AC_VERB_SET_CONFIG_DEFAULT_BYTES_3 , +NODE_ID_DMIC2 ,0x00 );Why are the silicon defaults not adequate?
Actually, they are hardware dependency.
I will add a configuration flag in platform data.
Quoted 17 lines
Quoted 17 lines
sound/soc/codecs/rt286.c new file +16
-0+static int rt286_hp_event (struct snd_soc_dapm_widget *w, +struct snd_kcontrol *kcontrol,int event) { +struct snd_soc_codec *codec = w->codec; +unsigned int val; + +switch (event) { +case SND_SOC_DAPM_POST_PMU : + val =snd_soc_read (codec,NODE_ID_HP_OUT ) &0x8080 ; +switch (val) { +case 0x0 : +rt286_write (codec,AC_VERB_SET_AMP_GAIN_MUTE , +NODE_ID_HP_OUT ,0xb000 ); +break ; +case 0x8000 : +rt286_write (codec,AC_VERB_SET_AMP_GAIN_MUTE , +NODE_ID_HP_OUT ,0x9000 );
Quoted 8 lines
sound/soc/codecs/rt286.c line 710
Quoted 6 lines
sound/soc/codecs/rt286.c new file +6
-0+break ; +case 0x0080 : +rt286_write (codec,AC_VERB_SET_AMP_GAIN_MUTE , +NODE_ID_HP_OUT ,0xa000 ); +break ; + }This is rather unclear. What is it doing?
SOC_DOUBLE_EXT("Headphone Playback Switch", NODE_ID_HP_OUT,
15, 8, 1, 1, rt286_playback_switch_get, rt286_playback_switch_put),
We use NODE_ID_HP_OUT bit 15, 8 to store the mute/unmute status for headphone L/R channel. rt286_hp_event will mute both channels when power down.
And it will read the status from RT286_HP_OUT to unmute the corresponding channel(s) when power on.
Quoted 13 lines
Quoted 13 lines
sound/soc/codecs/rt286.c new file +11
-0+static int rt286_set_bias_level (struct snd_soc_codec *codec, +enum snd_soc_bias_level level) +{ +switch (level) { +case SND_SOC_BIAS_PREPARE : +if (SND_SOC_BIAS_STANDBY == codec->dapm.bias_level) +rt286_write (codec,AC_VERB_SET_POWER_STATE , +NODE_ID_AUDIO_FUNCTION_GROUP ,AC_PWRST_D0 ); +break ; + +case SND_SOC_BIAS_OFF :
Quoted 8 lines
sound/soc/codecs/rt286.c line 1211
Quoted 3 lines
sound/soc/codecs/rt286.c new file +3
-0+rt286_write (codec,AC_VERB_SET_POWER_STATE , +NODE_ID_AUDIO_FUNCTION_GROUP ,AC_PWRST_D3 ); +break ;These aren't matched - you power up when leaving standby but only power down when you go to off. That's a bit odd and probably won't do the right thing and will leave the CODEC powered up all the time since you don't set
idle_bias_off(though perhaps you should).
I will power off the codec in standby.
Quoted 3 lines
I'm also not seeing any code for interrupts even though there appears to be some code to initialise them in the driver.
I will add it along with jack detection function in another patch later.
Thanks.
Quoted 2 lines
------Please consider the environment before printing this e-mail.
Mark Brown
maintainerQuoted 9 lines · Bard Liao
Quoted 5 lines
sound/soc/codecs/rt286.c line 546
Quoted 3 lines
sound/soc/codecs/rt286.c new file +3
-0+if (rt286->pdata.irq_en) +rt286_index_update_bits (codec, +NODE_ID_VENDOR_REGISTERS ,0x33 ,0x0002 ,0x0002 );Why would the system ever want to supply an interrupt and not use it?
The codec support a configurable irq pin which can be disable or enable. Some customers may not use it.
So, I add a flag in platform data to configure it.
Should it not be possible to do this based on if an interrupt is specified - why is a separate configuration option needed for this when the user also needs to specify if an interrupt is used and which interrupt is used?
Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
sound/soc/codecs/rt286.c new file +16
-0+static int rt286_hp_event (struct snd_soc_dapm_widget *w, +struct snd_kcontrol *kcontrol,int event) { +struct snd_soc_codec *codec = w->codec; +unsigned int val; + +switch (event) { +case SND_SOC_DAPM_POST_PMU : + val =snd_soc_read (codec,NODE_ID_HP_OUT ) &0x8080 ; +switch (val) { +case 0x0 : +rt286_write (codec,AC_VERB_SET_AMP_GAIN_MUTE , +NODE_ID_HP_OUT ,0xb000 ); +break ; +case 0x8000 : +rt286_write (codec,AC_VERB_SET_AMP_GAIN_MUTE , +NODE_ID_HP_OUT ,0x9000 );Quoted 8 lines
sound/soc/codecs/rt286.c line 710
Quoted 6 lines
sound/soc/codecs/rt286.c new file +6
-0+break ; +case 0x0080 : +rt286_write (codec,AC_VERB_SET_AMP_GAIN_MUTE , +NODE_ID_HP_OUT ,0xa000 ); +break ; + }This is rather unclear. What is it doing?
Quoted 6 lines
SOC_DOUBLE_EXT("Headphone Playback Switch",
NODE_ID_HP_OUT,15, 8, 1, 1, rt286_playback_switch_get, rt286_playback_switch_put),We use
NODE_ID_HP_OUTbit 15, 8 to store the mute/unmute status for headphone L/R channel.rt286_hp_eventwill mute both channels when power down.
And it will read the status fromRT286_HP_OUTto unmute the corresponding channel(s) when power on.
So how does the mute control work when the headphone is powered up then? You may be looking for a SOC_DAPM_SINGLE_AUTODISABLE() control here, I think that's what you're implementing here.
Quoted 16 lines
-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Friday, February 07, 2014 8:51 PM
To: Bard Liao
Cc: [email protected]; [email protected]; Flove; Oder Chiou; [email protected]
Subject: Re: [PATCH v3] ASoC: add RT286 CODEC driverQuoted 5 lines · Bard Liao
Quoted 5 lines
sound/soc/codecs/rt286.c line 546
Quoted 3 lines
sound/soc/codecs/rt286.c new file +3
-0+if (rt286->pdata.irq_en) +rt286_index_update_bits (codec, +NODE_ID_VENDOR_REGISTERS ,0x33 ,0x0002 ,0x0002 );Why would the system ever want to supply an interrupt and not use it?
Quoted 8 lines
Quoted 3 lines
The codec support a configurable irq pin which can be disable or enable. Some customers may not use it.
So, I add a flag in platform data to configure it.Should it not be possible to do this based on if an interrupt is specified - why is a separate configuration option needed for this when the user also needs to specify if an interrupt is used and which interrupt is used?
You are right. I will do that base on if an interrupt is specified.
Quoted 29 lines
Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
sound/soc/codecs/rt286.c new file +16
-0+static int rt286_hp_event (struct snd_soc_dapm_widget *w, +struct snd_kcontrol *kcontrol,int event) { +struct snd_soc_codec *codec = w->codec; +unsigned int val; + +switch (event) { +case SND_SOC_DAPM_POST_PMU : + val =snd_soc_read (codec,NODE_ID_HP_OUT ) &0x8080 ; +switch (val) { +case 0x0 : +rt286_write (codec,AC_VERB_SET_AMP_GAIN_MUTE , +NODE_ID_HP_OUT ,0xb000 ); +break ; +case 0x8000 : +rt286_write (codec,AC_VERB_SET_AMP_GAIN_MUTE , +NODE_ID_HP_OUT ,0x9000 );Quoted 8 lines
sound/soc/codecs/rt286.c line 710
Quoted 6 lines
sound/soc/codecs/rt286.c new file +6
-0+break ; +case 0x0080 : +rt286_write (codec,AC_VERB_SET_AMP_GAIN_MUTE , +NODE_ID_HP_OUT ,0xa000 ); +break ; + }This is rather unclear. What is it doing?
Quoted 4 lines
SOC_DOUBLE_EXT("Headphone Playback Switch",
NODE_ID_HP_OUT,15, 8, 1, 1, rt286_playback_switch_get, rt286_playback_switch_put),We use
NODE_ID_HP_OUTbit 15, 8 to store the mute/unmute status for
Quoted 8 lines
headphone L/R channel.
Quoted 2 lines
rt286_hp_eventwill mute both channels when power down. And it will read the status fromRT286_HP_OUTto unmute thecorresponding channel(s) when power on.
So how does the mute control work when the headphone is powered up then? You may be looking for a
SOC_DAPM_SINGLE_AUTODISABLE()control here, I think that's what you're implementing here.
rt286_playback_switch_put will mute/unmute headphone immediately.
So, when the headphone is already powered on, headphone will be muted if "Headphone Playback Switch" is set to off. And I think it is no problem if user unmute the headphone during headphone is powered off.
Yes, what I am implementing here is what SOC_DAPM_SINGLE_AUTODISABLE() does.
The problem I meet is rt286 uses different registers for read and write the same bits.
That's why I didn't use SOC_DAPM_SINGLE_AUTODISABLE() control here.
Quoted 2 lines
------Please consider the environment before printing this e-mail.
Mark Brown
maintainerQuoted 2 lines · Bard Liao
The problem I meet is rt286 uses different registers for read and write the same bits. That's why I didn't use
SOC_DAPM_SINGLE_AUTODISABLE()control here.
OK, so same thing as a lot of the other code in the driver - less magic numbers and more documentation so this is clearer please.