Add ES8328 audio codec
Subsystems (5)
v2 cover Add ES8328 audio codec
This patchset adds support for the Everest Semi ES8328 audio codec. It also adds support for using the es8328 on IMX boards.
We write a machine driver rather than using simple-card because the machine driver needs to support regulators for the codec itself and speaker amps, have headphone support, and must supply an unusual frequency to the codec chip.
Changes since v1:
- Rename HP/Speaker to OUT1/OUT2
- Use DAPM widgets for startup/shutdown
- Add regulator support to machine driver
Sean Cross (3):
devicetree: bindings: Add Everest Semicodunctor
ASoC: add es8328 codec driver
ASoC: fsl: add imx-es8328 machine driver
Documentation/devicetree/bindings/sound/es8328.txt | 18 + .../devicetree/bindings/sound/imx-audio-es8328.txt | 60 ++ .../devicetree/bindings/vendor-prefixes.txt | 1 + sound/soc/codecs/Kconfig | 5 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/es8328.c | 711 +++++++++++++++++++++ sound/soc/codecs/es8328.h | 305 +++++++++ sound/soc/fsl/Kconfig | 13 + sound/soc/fsl/Makefile | 2 + sound/soc/fsl/imx-es8328.c | 359 +++++++++++ 10 files changed, 1476 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/es8328.txt create mode 100644 Documentation/devicetree/bindings/sound/imx-audio-es8328.txt create mode 100644 sound/soc/codecs/es8328.c create mode 100644 sound/soc/codecs/es8328.h create mode 100644 sound/soc/fsl/imx-es8328.c
Signature · 1 line
2.0.0
PATCH v2 1/3 devicetree: bindings: Add Everest Semicodunctor
Everest Semiconductor makes audio codecs.
--- Documentation/devicetree/bindings/vendor-prefixes.txt | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/vendor-prefixes.txt +1 -0
@@ -46,6 +46,7 @@ epfl Ecole Polytechnique Fédérale de Lausanne epson Seiko Epson Corp. est ESTeem Wireless Modems eukrea Eukréa Electromatique +everest Everest Semiconductor Co. Ltd. excito Excito fsl Freescale Semiconductor GEFanuc GE Fanuc Intelligent Platforms Embedded Systems, Inc.
Signature · 6 lines
2.0.0 _______________________________________________ Alsa-devel mailing list [email protected] http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH v2 2/3 ASoC: add es8328 codec driver
In reply to Sean CrossAdd a codec driver for the Everest ES8328. It supports two separate audio outputs and two separate audio inputs.
--- Documentation/devicetree/bindings/sound/es8328.txt | 18 + sound/soc/codecs/Kconfig | 5 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/es8328.c | 711 +++++++++++++++++++++ sound/soc/codecs/es8328.h | 305 +++++++++ 5 files changed, 1041 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/es8328.txt create mode 100644 sound/soc/codecs/es8328.c create mode 100644 sound/soc/codecs/es8328.h
Documentation/devicetree/bindings/sound/es8328.txt new file +18 -0
@@ -0,0 +1,18 @@ +Everest ES8328 audio CODEC + +This device supports both I2C and SPI (configured with pin strapping +on the board). + +Required properties: + + - compatible : "everest,es8328" + + - reg : the I2C address of the device for I2C, the chip select + number for SPI. + +Example: + +codec: es8328@11 { + compatible = "everest,es8328"; + reg = <0x11>; +};
sound/soc/codecs/Kconfig +5 -0
@@ -56,6 +56,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_DA732X if I2C select SND_SOC_DA9055 if I2C select SND_SOC_BT_SCO + select SND_SOC_ES8328 if I2C select SND_SOC_ISABELLE if I2C select SND_SOC_JZ4740_CODEC select SND_SOC_LM4857 if I2C
@@ -396,6 +397,10 @@ config SND_SOC_DMIC config SND_SOC_HDMI_CODEC tristate "HDMI stub CODEC" +config SND_SOC_ES8328 + tristate "Everest Semi ES8328 CODEC" + depends on I2C + config SND_SOC_ISABELLE tristate
sound/soc/codecs/Makefile +2 -0
@@ -48,6 +48,7 @@ snd-soc-da732x-objs := da732x.o snd-soc-da9055-objs := da9055.o snd-soc-bt-sco-objs := bt-sco.o snd-soc-dmic-objs := dmic.o +snd-soc-es8328-objs := es8328.o snd-soc-isabelle-objs := isabelle.o snd-soc-jz4740-codec-objs := jz4740.o snd-soc-l3-objs := l3.o
@@ -213,6 +214,7 @@ obj-$(CONFIG_SND_SOC_DA732X) += snd-soc-da732x.o obj-$(CONFIG_SND_SOC_DA9055) += snd-soc-da9055.o obj-$(CONFIG_SND_SOC_BT_SCO) += snd-soc-bt-sco.o obj-$(CONFIG_SND_SOC_DMIC) += snd-soc-dmic.o +obj-$(CONFIG_SND_SOC_ES8328) += snd-soc-es8328.o obj-$(CONFIG_SND_SOC_ISABELLE) += snd-soc-isabelle.o obj-$(CONFIG_SND_SOC_JZ4740_CODEC) += snd-soc-jz4740-codec.o obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o
sound/soc/codecs/es8328.c new file +711 -0
711 lines not on this page · raw message
sound/soc/codecs/es8328.h new file +305 -0
305 lines not on this page · raw message
Signature · 1 line
2.0.0
Re: [PATCH v2 2/3] ASoC: add es8328 codec driver
On 06/17/2014 07:16 AM, Sean Cross wrote:
A couple of small bits inline.
[...]
Quoted 3 lines
sound/soc/codecs/es8328.c new file +0
-0@@ -0,0 +1,711 @@
[...]
Quoted 1 line
+#include <
linux/platform_device.h>
You don't use platform devices in here
[...]
Quoted 1 line
+uint8_t sample_ratios[] = {
static const, also a prefix like es8328_ wont hurt
Quoted 14 lines
sound/soc/codecs/es8328.c new file +14
-0+ [ES8328_RATE_8019] = 0x9, + [ES8328_RATE_11025] = 0x7, + [ES8328_RATE_22050] = 0x4, + [ES8328_RATE_44100] = 0x2, +}; + +#define ES8328_RATES (SNDRV_PCM_RATE_44100 | \ + SNDRV_PCM_RATE_22050 | \ + SNDRV_PCM_RATE_11025) +#define ES8328_FORMATS (SNDRV_PCM_FMTBIT_S16_LE) + +/* codec private data */ +struct es8328_priv { +struct regmap *regmap;
sound/soc/codecs/es8328.c line 65
Quoted 10 lines
sound/soc/codecs/es8328.c new file +10
-0+int sysclk; +}; + +/* +* ES8328 Controls +*/ + +static const char *const deemph_txt[] = {"None" ,"32Khz" ,"44.1Khz" ,"48Khz" }; +static SOC_ENUM_SINGLE_DECL(deemph, + ES8328_DACCONTROL6, 6, deemph_txt);
deemph should just be a single boolean switch (On or Off) and automatically select the correct setting based on the configured sample rate.
[...]
sound/soc/codecs/es8328.c line 120
Quoted 5 lines
sound/soc/codecs/es8328.c new file +5
-0+static const char *const es8328_line_texts[] = { +"Line 1" ,"Line 2" ,"PGA" ,"Differential" }; + +static const unsigned int es8328_line_values[] = { +0 ,1 ,2 ,3 };
You don't need to use a value enum for this.
[...]
sound/soc/codecs/es8328.c line 156
Quoted 3 lines
sound/soc/codecs/es8328.c new file +3
-0+static const char *const es8328_pga_sel[] = { +"Line 1" ,"Line 2" ,"Line 3" ,"Differential" }; +static const unsigned int es8328_pga_val[] = {0 ,1 ,2 ,3 };
same here
[...]
Quoted 47 lines
sound/soc/codecs/es8328.c new file +47
-0+static int es8328_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; + +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { +u8 dac =snd_soc_read (codec,ES8328_DACCONTROL2 ); + + dac &= ~ES8328_DACCONTROL2_RATEMASK ; + +switch (params_rate (params)) { +case 8000 : + dac |= sample_ratios[ES8328_RATE_8019 ]; +break ; +case 11025 : + dac |= sample_ratios[ES8328_RATE_11025 ]; +break ; +case 22050 : + dac |= sample_ratios[ES8328_RATE_22050 ]; +break ; +case 44100 : + dac |= sample_ratios[ES8328_RATE_44100 ]; +break ; +default : +dev_err (codec->dev,"%s: unknown rate %d\n" , + __func__,params_rate (params)); +return -EINVAL ; + } +snd_soc_write (codec,ES8328_DACCONTROL2 , dac); + } + +if (substream->stream ==SNDRV_PCM_STREAM_CAPTURE ) { +u8 adc =snd_soc_read (codec,ES8328_ADCCONTROL5 ); + + adc &= ~ES8328_ADCCONTROL5_RATEMASK ; + +switch (params_rate (params)) { +case 8000 : + adc |= sample_ratios[ES8328_RATE_8019 ]; +break ; +case 11025 : + adc |= sample_ratios[ES8328_RATE_11025 ]; +break ; +case 22050 : + adc |= sample_ratios[ES8328_RATE_22050 ]; +break ;
sound/soc/codecs/es8328.c line 389
Quoted 10 lines
sound/soc/codecs/es8328.c new file +10
-0+case 44100 : + adc |= sample_ratios[ES8328_RATE_44100 ]; +break ; +default : +dev_err (codec->dev,"%s: unknown rate %d\n" , + __func__,params_rate (params)); +return -EINVAL ; + } +snd_soc_write (codec,ES8328_ADCCONTROL5 , adc); + }
The capture and the playback case look pretty much the same. This could probably be handled without duplicating the code. Also use snd_soc_update_bits() for updating the register.
sound/soc/codecs/es8328.c line 392
Quoted 3 lines
sound/soc/codecs/es8328.c new file +3
-0+ +return 0 ; +}
[...][
sound/soc/codecs/es8328.c line 556
Quoted 5 lines
sound/soc/codecs/es8328.c new file +5
-0+static int es8328_probe (struct snd_soc_codec *codec) +{ +/* power on device */ +return es8328_set_bias_level (codec,SND_SOC_BIAS_STANDBY ); +}
You don't need this one, the core will automatically bring the dapm context to idle bias after the device has been probed.
sound/soc/codecs/es8328.c line 561
Quoted 5 lines
sound/soc/codecs/es8328.c new file +5
-0+ +static int es8328_remove (struct snd_soc_codec *codec) +{ +return 0 ; +}
No, need to have empty callbacks, just leave .remove of the codec driver struct NULL.
sound/soc/codecs/es8328.c line 563
Quoted 2 lines
sound/soc/codecs/es8328.c new file +2
-0+ +static struct snd_soc_codec_driver soc_codec_dev_es8328 = {
const
the soc_codec_dev_foobar naming pattern comes from a time when this actually used to be a device rather than a driver. Something like es8328_codec_driver is a more appropriate name these days.
Quoted 12 lines
sound/soc/codecs/es8328.c new file +12
-0+ .probe = es8328_probe, + .remove = es8328_remove, + .suspend = es8328_suspend, + .resume = es8328_resume, + .set_bias_level = es8328_set_bias_level, + .controls = es8328_snd_controls, + .num_controls = ARRAY_SIZE(es8328_snd_controls), + .dapm_widgets = es8328_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(es8328_dapm_widgets), + .dapm_routes = es8328_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(es8328_dapm_routes), +};
[...]
Quoted 1 line
+#if
defined(CONFIG_SPI_MASTER)
For CODECs with more than one bus interface we started splitting the bus interface support code into separate modules (e.g. one module for the core logic of the driver, one module for I2C and one module for SPI). This was done to avoid issue when one bus is built-in and the the other is built as a module. New drivers should follow this scheme. E.g. see http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/sound/soc/codecs/?id=6c3d713e6d32706999689e379a9098afb4cd8a2c
sound/soc/codecs/es8328.c line 596
Quoted 6 lines
sound/soc/codecs/es8328.c new file +6
-0+static int es8328_spi_probe (struct spi_device *spi) +{ +struct es8328_priv *es8328; +int ret; + + es8328 = devm_kzalloc(&spi->dev, sizeof(struct es8328_priv),
sizeof(*es8328) is the preferred style
Quoted 23 lines
sound/soc/codecs/es8328.c new file +23
-0+ GFP_KERNEL); +if (es8328 ==NULL ) +return -ENOMEM ; + + es8328->regmap =devm_regmap_init_spi (spi, &es8328_regmap); +if (IS_ERR (es8328->regmap)) +return PTR_ERR (es8328->regmap); + +spi_set_drvdata (spi, es8328); + + ret =snd_soc_register_codec (&spi->dev, + &soc_codec_dev_es8328, &es8328_dai,1 ); +if (ret <0 ) +dev_err (&spi->dev,"unable to register codec: %d\n" , ret); + +return ret; +} + +static int es8328_spi_remove (struct spi_device *spi) +{ +snd_soc_unregister_codec (&spi->dev); + +return 0 ;
[...]
sound/soc/codecs/es8328.c line 664
Quoted 2 lines
sound/soc/codecs/es8328.c new file +2
-0+static const struct i2c_device_id es8328_i2c_id[] = { + {"es8328" ,0x11 },
The second field is the drvdata, this is not the I2C address of the device. If you don't use drvdata just leave it 0.
Quoted 4 lines
sound/soc/codecs/es8328.c new file +4
-0+ { } +}; +MODULE_DEVICE_TABLE (i2c, es8328_i2c_id); +
[...]
Re: [PATCH v2 2/3] ASoC: add es8328 codec driver
Quoted 3 lines · Lars-Peter Clausen
On 06/17/2014 07:16 AM, Sean Cross wrote:
A couple of small bits inline.
[...]
Quoted 14 lines
[...]
sound/soc/codecs/es8328.c line 65
Quoted 9 lines
sound/soc/codecs/es8328.c new file +6
-0+ +/* +* ES8328 Controls +*/ + +static const char *const deemph_txt[] = {"None" ,"32Khz" ,"44.1Khz", "48Khz"};
sound/soc/codecs/es8328.c new file +2
-0+static SOC_ENUM_SINGLE_DECL(deemph, + ES8328_DACCONTROL6, 6, deemph_txt);deemph should just be a single boolean switch (On or Off) and automatically select the correct setting based on the configured sample rate.
Seems like a lot of work. Is there an example of how this should be written? What should the behavior be when deemph is enabled, and output is, say, 22.050 kHz (which doesn't have a deemph supported in hardware)? Should selection of the deemph register be performed inside hw_params()?
I'll incorporate the other fixes for v3.
Sean
PATCH v2 3/3 ASoC: fsl: add imx-es8328 machine driver
In reply to Sean CrossThis adds an initial machine driver for the ES8328 audio codec. The driver supports headphones, an audio regulator for both the codec itself and a speaker amp, and supports reparenting and adjusting clocks to supply the audio codec with the unusual frequency it requires.
--- .../devicetree/bindings/sound/imx-audio-es8328.txt | 60 ++++ sound/soc/fsl/Kconfig | 13 + sound/soc/fsl/Makefile | 2 + sound/soc/fsl/imx-es8328.c | 359 +++++++++++++++++++++ 4 files changed, 434 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/imx-audio-es8328.txt create mode 100644 sound/soc/fsl/imx-es8328.c
Documentation/devicetree/bindings/sound/imx-audio-es8328.txt new file +60 -0
@@ -0,0 +1,60 @@ +Freescale i.MX audio complex with ES8328 codec + +Required properties: +- compatible : "fsl,imx-audio-es8328" +- model : The user-visible name of this sound complex +- clocks : A list of clocks required to run the codec at 22.5792 MHz +- ssi-controller : The phandle of the i.MX SSI controller +- jack-gpio : Optional GPIO for headphone jack +- codec-supply : Power regulator for audio codec chip +- audio-amp-supply : Power regulator for speaker amps +- audio-codec : The phandle of the ES8328 audio codec +- audio-routing : A list of the connections between audio components. + Each entry is a pair of strings, the first being the connection's sink, + the second being the connection's source. Valid names could be power + supplies, ES8328 pins, and the jacks on the board: + + Power supplies: + * audio-amp + * codec + + ES8328 pins: + * LOUT1 + * LOUT2 + * ROUT1 + * ROUT2 + + Board connectors: + * Headphone + * Speaker + +- mux-int-port : The internal port of the i.MX audio muxer (AUDMUX) +- mux-ext-port : The external port of the i.MX audio muxer + +Note: The AUDMUX port numbering should start at 1, which is consistent with +hardware manual. + +Example: + +sound { + compatible = "fsl,imx-audio-es8328"; + model = "imx-audio-es8328"; + clocks = <&clks 169>, <&clks 57>, <&clks 173>, + <&clks 203>, <&clks 201>; + clock-names = "cko1", "cko1_sel", "pll4_audio", + "pll4_post_div", "cko_sel"; + ssi-controller = <&ssi1>; + audio-codec = <&codec>; + jack-gpio = <&gpio5 15 0>; + codec-supply = <®_audio_codec>; + audio-amp-supply = <®_audio_amp>; + audio-routing = + "Speaker", "LOUT2", + "Speaker", "ROUT2", + "Speaker", "audio-amp", + "Headphone", "ROUT1", + "Headphone", "LOUT1"; + mux-int-port = <1>; + mux-ext-port = <3>; +}; +
sound/soc/fsl/Kconfig +13 -0
@@ -229,6 +229,19 @@ config SND_SOC_IMX_WM8962 Say Y if you want to add support for SoC audio on an i.MX board with a wm8962 codec. +config SND_SOC_IMX_ES8328 + tristate "SoC Audio support for i.MX boards with the ES8328 codec" + depends on OF && (I2C || SPI) + select SND_SOC_ES8328 + select SND_SOC_IMX_PCM_DMA + select SND_SOC_IMX_AUDMUX + select SND_SOC_FSL_SSI + select SND_SOC_FSL_UTILS + select SND_SOC_IMX_PCM_FIQ + help + Say Y if you want to add support for the ES8328 audio codec connected + via SSI/I2S over either SPI or I2C. + config SND_SOC_IMX_SGTL5000 tristate "SoC Audio support for i.MX boards with sgtl5000" depends on OF && I2C
sound/soc/fsl/Makefile +2 -0
@@ -48,6 +48,7 @@ snd-soc-eukrea-tlv320-objs := eukrea-tlv320.o snd-soc-phycore-ac97-objs := phycore-ac97.o snd-soc-mx27vis-aic32x4-objs := mx27vis-aic32x4.o snd-soc-wm1133-ev1-objs := wm1133-ev1.o +snd-soc-imx-es8328-objs := imx-es8328.o snd-soc-imx-sgtl5000-objs := imx-sgtl5000.o snd-soc-imx-wm8962-objs := imx-wm8962.o snd-soc-imx-spdif-objs := imx-spdif.o
@@ -57,6 +58,7 @@ obj-$(CONFIG_SND_SOC_EUKREA_TLV320) += snd-soc-eukrea-tlv320.o obj-$(CONFIG_SND_SOC_PHYCORE_AC97) += snd-soc-phycore-ac97.o obj-$(CONFIG_SND_SOC_MX27VIS_AIC32X4) += snd-soc-mx27vis-aic32x4.o obj-$(CONFIG_SND_MXC_SOC_WM1133_EV1) += snd-soc-wm1133-ev1.o +obj-$(CONFIG_SND_SOC_IMX_ES8328) += snd-soc-imx-es8328.o obj-$(CONFIG_SND_SOC_IMX_SGTL5000) += snd-soc-imx-sgtl5000.o obj-$(CONFIG_SND_SOC_IMX_WM8962) += snd-soc-imx-wm8962.o obj-$(CONFIG_SND_SOC_IMX_SPDIF) += snd-soc-imx-spdif.o
sound/soc/fsl/imx-es8328.c new file +359 -0
359 lines not on this page · raw message
Signature · 1 line
2.0.0
Re: [PATCH v2 3/3] ASoC: fsl: add imx-es8328 machine driver
On 06/17/2014 07:16 AM, Sean Cross wrote:
[...]
Quoted 1 line
+- codec-supply : Power regulator for audio codec chip
If this is the supply for the CODEC it should be part of the CODEC's bindings and probably be handled by the CODEC driver.
Re: [PATCH v2 3/3] ASoC: fsl: add imx-es8328 machine driver
Quoted 8 lines · Lars-Peter Clausen
On 06/17/2014 07:16 AM, Sean Cross wrote:
[...]Quoted 1 line
+- codec-supply : Power regulator for audio codec chip
If this is the supply for the CODEC it should be part of the CODEC's bindings and probably be handled by the CODEC driver.
On this board, it's simply a GPIO on this board that enables or disables power to the chip. Since it's external to the codec, it seemed more appropriate to put it in the machine driver file.
Sean