Add ASoC drivers for SPEAr platform
cover Add ASoC drivers for SPEAr platform
This patch set adds support for ASoC sound drivers on ST's SPEAr platforms. Details of the SPEAr platforms can be seen here:
http://www.st.com/internet/mcu/product/250658.jsp
This patch set supports the following modules:
1. Audio codec sta529 (connected to I2S controller).
2. SPDIF IN dummy Codec.
3. Synopsys Designware I2S controller.
4. ST SPDIF IN controller.
5. ST SPDIF OUT controller.
This patch set has been tested for linux-kernel-version 3.3-rc3 on SPEAr platform.
In past, I had circulated the patch for the same and got some review comments. I have incorporate those commnets also. Please find the link below.
http://mailman.alsa-project.org/pipermail/alsa-devel/2011-April/038738.html
Rajeev Kumar (6):
sound:asoc: Add support for STA529 Audio Codec sound:asoc: Add support for synopsys i2s controller as per ASoC
framework.
sound:asoc: Add support for SPEAr ASoC pcm layer. sound:asoc: Add support for SPEAr ASoC machine driver. sound:asoc: Add Kconfig and Makefile to support SPEAr audio driver sound:asoc: Update Kconfig and Makefile(sound/soc/) to support SPEAr
audio
Vipin Kumar (2):
sound:asoc:spdif_in: Add spdif IN support
sound:asoc:spdif_out: Add spdif out support
include/linux/designware_i2s.h | 63 ++++ sound/soc/Kconfig | 1 + sound/soc/Makefile | 1 + sound/soc/codecs/Kconfig | 5 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/sta529.c | 414 ++++++++++++++++++++++++++ sound/soc/spear/Kconfig | 46 +++ sound/soc/spear/Makefile | 16 + sound/soc/spear/designware_i2s.c | 610 ++++++++++++++++++++++++++++++++++++++ sound/soc/spear/spdif_in.c | 304 +++++++++++++++++++ sound/soc/spear/spdif_in_regs.h | 60 ++++ sound/soc/spear/spdif_out.c | 397 +++++++++++++++++++++++++ sound/soc/spear/spdif_out_regs.h | 79 +++++ sound/soc/spear/spear_evb.c | 278 +++++++++++++++++ sound/soc/spear/spear_pcm.c | 460 ++++++++++++++++++++++++++++ sound/soc/spear/spear_pcm.h | 33 ++ 16 files changed, 2769 insertions(+), 0 deletions(-) create mode 100644 include/linux/designware_i2s.h create mode 100644 sound/soc/codecs/sta529.c create mode 100644 sound/soc/spear/Kconfig create mode 100644 sound/soc/spear/Makefile create mode 100644 sound/soc/spear/designware_i2s.c create mode 100644 sound/soc/spear/spdif_in.c create mode 100644 sound/soc/spear/spdif_in_regs.h create mode 100644 sound/soc/spear/spdif_out.c create mode 100644 sound/soc/spear/spdif_out_regs.h create mode 100644 sound/soc/spear/spear_evb.c create mode 100644 sound/soc/spear/spear_pcm.c create mode 100644 sound/soc/spear/spear_pcm.h
Signature · 1 line
1.7.2.2
PATCH 1/8 sound:asoc: Add support for STA529 Audio Codec
This patch adds the support for STA529 audio codec. Details of the audio codec can be seen here:
http://www.st.com/internet/imag_video/product/159187.jsp
--- sound/soc/codecs/Kconfig | 5 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/sta529.c | 414 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 421 insertions(+), 0 deletions(-) create mode 100644 sound/soc/codecs/sta529.c
sound/soc/codecs/Kconfig +5 -0
@@ -49,6 +49,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_SPDIF select SND_SOC_SSM2602 if SND_SOC_I2C_AND_SPI select SND_SOC_STA32X if I2C + select SND_SOC_STA529 if I2C select SND_SOC_STAC9766 if SND_SOC_AC97_BUS select SND_SOC_TLV320AIC23 if I2C select SND_SOC_TLV320AIC26 if SPI_MASTER
@@ -252,6 +253,10 @@ config SND_SOC_SSM2602 config SND_SOC_STA32X tristate +config SND_SOC_STA529 + tristate + depends on I2C + config SND_SOC_STAC9766 tristate
sound/soc/codecs/Makefile +2 -0
@@ -39,6 +39,7 @@ snd-soc-sn95031-objs := sn95031.o snd-soc-spdif-objs := spdif_transciever.o spdif_receiver.o snd-soc-ssm2602-objs := ssm2602.o snd-soc-sta32x-objs := sta32x.o +snd-soc-sta529-objs := sta529.o snd-soc-stac9766-objs := stac9766.o snd-soc-tlv320aic23-objs := tlv320aic23.o snd-soc-tlv320aic26-objs := tlv320aic26.o
@@ -143,6 +144,7 @@ obj-$(CONFIG_SND_SOC_SN95031) +=snd-soc-sn95031.o obj-$(CONFIG_SND_SOC_SPDIF) += snd-soc-spdif.o obj-$(CONFIG_SND_SOC_SSM2602) += snd-soc-ssm2602.o obj-$(CONFIG_SND_SOC_STA32X) += snd-soc-sta32x.o +obj-$(CONFIG_SND_SOC_STA529) += snd-soc-sta529.o obj-$(CONFIG_SND_SOC_STAC9766) += snd-soc-stac9766.o obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o obj-$(CONFIG_SND_SOC_TLV320AIC26) += snd-soc-tlv320aic26.o
sound/soc/codecs/sta529.c new file +414 -0
414 lines not on this page · raw message
Signature · 1 line
1.7.2.2
Re: [PATCH 1/8] sound:asoc: Add support for STA529 Audio Codec
Quoted 3 lines · Rajeev Kumar
This patch adds the support for STA529 audio codec. Details of the audio codec can be seen here:
http://www.st.com/internet/imag_video/product/159187.jsp
Please use subject lines appropriate for the subsystem. If your commits look visually different to all the other commits in the log that's not a good sign.
sound/soc/codecs/Kconfig config SND_SOC_SSM2602 · line 259
Quoted 4 lines
sound/soc/codecs/Kconfig +4
-0+config SND_SOC_STA529 + tristate + depends on I2C +
Drop the dependency, none of the other CODECs have this for a reason...
Quoted 1 line
+#include <
linux/platform_device.h>
If you need this something went wrong...
Quoted 1 line
+static const u8 sta529_reg[STA529_CACHEREGNUM] = {
Use regmap for register I/O.
sound/soc/codecs/sta529.c line 106
Quoted 4 lines
sound/soc/codecs/sta529.c new file +4
-0+struct sta529 { +unsigned int sysclk; +enum snd_soc_control_type control_type; +void *control_data;
Your device only supports I2C, no need for the infrastructure for other buses (though this will go away with regmap).
sound/soc/codecs/sta529.c line 111
Quoted 3 lines
sound/soc/codecs/sta529.c new file +3
-0+static const char *pwm_mode_text[] = {"binary" ,"headphone" ,"ternary" , +"phase-shift" }; +static const char *interface_mode_text[] = {"slave" ,"master" };
ALSA controls always use capitalisation.
sound/soc/codecs/sta529.c line 143
Quoted 4 lines
sound/soc/codecs/sta529.c new file +4
-0+case SND_SOC_BIAS_PREPARE : +snd_soc_update_bits (codec,STA529_FFXCFG0 ,POWER_CNTLMSAK , +POWER_UP ); +snd_soc_update_bits (codec,STA529_MISC ,1 ,0x01 );
One of these has magic numbers and the other doesn't, and the magic numbers are a little confusing as the mask is written in decimal but the binary in hex.
sound/soc/codecs/sta529.c line 184
Quoted 11 lines
sound/soc/codecs/sta529.c new file +11
-0+switch (params_format (params)) { +case SNDRV_PCM_FORMAT_S16_LE : + pdata =1 ; +break ; +case SNDRV_PCM_FORMAT_S24_LE : + pdata =2 ; +break ; +case SNDRV_PCM_FORMAT_S32_LE : + pdata =3 ; +break ; + }
Return an error on unsupported sample sizes.
sound/soc/codecs/sta529.c line 207
Quoted 4 lines
sound/soc/codecs/sta529.c new file +4
-0+default : +printk (KERN_WARNING ,"bad rate\n" ); +return -EINVAL ; + }
dev_warn() - always use the dev_ prints where possible.
sound/soc/codecs/sta529.c line 221
Quoted 2 lines
sound/soc/codecs/sta529.c new file +2
-0+sta529_set_bias_level (codec,SND_SOC_BIAS_PREPARE ); +mdelay (10 );
Absolutely no - why are you doing this?
sound/soc/codecs/sta529.c line 235
Quoted 10 lines
sound/soc/codecs/sta529.c new file +10
-0+static int sta529_mute (struct snd_soc_dai *dai,int mute) +{ +struct snd_soc_codec *codec = dai->codec; + +u8 mute_reg =snd_soc_read (codec,STA529_FFXCFG0 ) & ~CODEC_MUTE_VAL ; + +if (mute) + mute_reg |=CODEC_MUTE_VAL ; + +snd_soc_update_bits (codec,STA529_FFXCFG0 ,0x80 ,00 );
You're always setting the same value here...
sound/soc/codecs/sta529.c line 306
Quoted 5 lines
sound/soc/codecs/sta529.c new file +5
-0+snd_soc_add_controls (codec, sta529_snd_controls, +ARRAY_SIZE (sta529_snd_controls)); + +snd_soc_add_controls (codec, sta529_new_snd_controls, +ARRAY_SIZE (sta529_new_snd_controls));
Use the initialisers in the card struct.
sound/soc/codecs/sta529.c line 357
Quoted 3 lines
sound/soc/codecs/sta529.c new file +3
-0+ sta529 =kzalloc (sizeof (struct sta529 ),GFP_KERNEL ); +if (sta529 ==NULL ) +return -ENOMEM ;
devm_kzalloc().
Quoted 1 line
+static int
__initsta529_modinit(void)
module_i2c_driver().
Re: [PATCH 1/8] sound:asoc: Add support for STA529 Audio Codec
Hello Mark
Quoted 9 lines · Mark Brown
Quoted 3 lines · Rajeev Kumar
This patch adds the support for STA529 audio codec. Details of the audio codec can be seen here:
http://www.st.com/internet/imag_video/product/159187.jspPlease use subject lines appropriate for the subsystem. If your commits look visually different to all the other commits in the log that's not a good sign.
Ok
Quoted 5 lines
sound/soc/codecs/Kconfig config SND_SOC_SSM2602 · line 259
Quoted 4 lines
sound/soc/codecs/Kconfig +4
-0+config SND_SOC_STA529 + tristate + depends on I2C +
Agreed
Quoted 6 lines
Drop the dependency, none of the other CODECs have this for a reason...
Quoted 1 line
+#include<linux/platform_device.h>
If you need this something went wrong...
Oops
Quoted 4 lines
Quoted 1 line
+static const u8 sta529_reg[STA529_CACHEREGNUM] = {
Use regmap for register I/O.
OK
Quoted 8 lines
sound/soc/codecs/sta529.c line 106
Quoted 4 lines
sound/soc/codecs/sta529.c new file +4
-0+struct sta529 { +unsigned int sysclk; +enum snd_soc_control_type control_type; +void *control_data;Your device only supports I2C, no need for the infrastructure for other buses (though this will go away with regmap).
Agreed,
Quoted 6 lines
sound/soc/codecs/sta529.c line 111
Quoted 3 lines
sound/soc/codecs/sta529.c new file +3
-0+static const char *pwm_mode_text[] = {"binary" ,"headphone" ,"ternary" , +"phase-shift" }; +static const char *interface_mode_text[] = {"slave" ,"master" };ALSA controls always use capitalisation.
you mean to say
static const char *interface_mode_text[] = { "SLAVE", "MASTER"}
Quoted 9 lines
sound/soc/codecs/sta529.c line 143
Quoted 4 lines
sound/soc/codecs/sta529.c new file +4
-0+case SND_SOC_BIAS_PREPARE : +snd_soc_update_bits (codec,STA529_FFXCFG0 ,POWER_CNTLMSAK , +POWER_UP ); +snd_soc_update_bits (codec,STA529_MISC ,1 ,0x01 );One of these has magic numbers and the other doesn't, and the magic numbers are a little confusing as the mask is written in decimal but the binary in hex.
OK I will take mask for this.
Quoted 5 lines
Quoted 5 lines
sound/soc/codecs/sta529.c new file +5
-0+switch (params_format (params)) { +case SNDRV_PCM_FORMAT_S16_LE : + pdata =1 ; +break ; +case SNDRV_PCM_FORMAT_S24_LE :
Quoted 9 lines
sound/soc/codecs/sta529.c line 184
Quoted 6 lines
sound/soc/codecs/sta529.c new file +6
-0+ pdata =2 ; +break ; +case SNDRV_PCM_FORMAT_S32_LE : + pdata =3 ; +break ; + }Return an error on unsupported sample sizes.
In default , it is returning an error.
Quoted 7 lines
sound/soc/codecs/sta529.c line 207
Quoted 4 lines
sound/soc/codecs/sta529.c new file +4
-0+default : +printk (KERN_WARNING ,"bad rate\n" ); +return -EINVAL ; + }
dev_warn()- always use thedev_prints where possible.
Agreed,
Quoted 5 lines
sound/soc/codecs/sta529.c line 221
Quoted 2 lines
sound/soc/codecs/sta529.c new file +2
-0+sta529_set_bias_level (codec,SND_SOC_BIAS_PREPARE ); +mdelay (10 );Absolutely no - why are you doing this?
In probe I am putting codec in standby mode. so to come out of this sta529_set_bias_level(codec, SND_SOC_BIAS_PREPARE) is called. Since there are some transition time between STANDBY and ON/PREAPRE, so a delay is introduced in the code.
Quoted 4 lines
Quoted 4 lines
sound/soc/codecs/sta529.c new file +4
-0+static int sta529_mute (struct snd_soc_dai *dai,int mute) +{ +struct snd_soc_codec *codec = dai->codec; +
Quoted 9 lines
sound/soc/codecs/sta529.c line 235
Quoted 6 lines
sound/soc/codecs/sta529.c new file +6
-0+u8 mute_reg =snd_soc_read (codec,STA529_FFXCFG0 )& ~CODEC_MUTE_VAL ; + +if (mute) + mute_reg |=CODEC_MUTE_VAL ; + +snd_soc_update_bits (codec,STA529_FFXCFG0 ,0x80 ,00 );You're always setting the same value here...
Oops, it should besnd_soc_update_bits(codec, STA529_FFXCFG0, 0x80, mute_reg);
Quoted 8 lines
sound/soc/codecs/sta529.c line 306
Quoted 5 lines
sound/soc/codecs/sta529.c new file +5
-0+snd_soc_add_controls (codec, sta529_snd_controls, +ARRAY_SIZE (sta529_snd_controls)); + +snd_soc_add_controls (codec, sta529_new_snd_controls, +ARRAY_SIZE (sta529_new_snd_controls));Use the initialisers in the card struct.
ok
Quoted 5 lines
sound/soc/codecs/sta529.c line 357
Quoted 3 lines
sound/soc/codecs/sta529.c new file +3
-0+ sta529 =kzalloc (sizeof (struct sta529 ),GFP_KERNEL ); +if (sta529 ==NULL ) +return -ENOMEM ;
devm_kzalloc().
OK
Best Regards
Rajeev
Quoted 4 lines
Quoted 2 lines
+static int
__initsta529_modinit(void)
module_i2c_driver().
Re: [PATCH 1/8] sound:asoc: Add support for STA529 Audio Codec
Quoted 11 lines
Quoted 7 lines
sound/soc/codecs/sta529.c line 111
Quoted 4 lines
sound/soc/codecs/sta529.c new file +3
-0+static const char *pwm_mode_text[] = {"binary" ,"headphone" ,"ternary" , +"phase-shift" }; +static const char *interface_mode_text[] = {"slave" ,"master" };ALSA controls always use capitalisation.
you mean to say
static const char *interface_mode_text[] = { "SLAVE", "MASTER"}
No, only the first letter upper case.
Quoted 11 lines
Quoted 6 lines
sound/soc/codecs/sta529.c line 221
Quoted 3 lines
sound/soc/codecs/sta529.c new file +2
-0+sta529_set_bias_level (codec,SND_SOC_BIAS_PREPARE ); +mdelay (10 );Absolutely no - why are you doing this?
In probe I am putting codec in standby mode. so to come out of this
sta529_set_bias_level(codec, SND_SOC_BIAS_PREPARE)is called. Since there are some transition time between STANDBY and ON/PREAPRE, so a delay is introduced in the code.
The framework will take care of taking the CODEC out of standby mode when it is required, so you shouldn't need it here. Also, if the delay is required put it into the set_bias_level function.
Quoted 15 lines
Quoted 14 lines
sound/soc/codecs/sta529.c line 235
Quoted 11 lines
sound/soc/codecs/sta529.c new file +10
-0+static int sta529_mute (struct snd_soc_dai *dai,int mute) +{ +struct snd_soc_codec *codec = dai->codec; + +u8 mute_reg =snd_soc_read (codec,STA529_FFXCFG0 )& ~CODEC_MUTE_VAL ; + +if (mute) + mute_reg |=CODEC_MUTE_VAL ; + +snd_soc_update_bits (codec,STA529_FFXCFG0 ,0x80 ,00 );You're always setting the same value here...
Quoted 2 lines
Oops, it should be
snd_soc_update_bits(codec, STA529_FFXCFG0, 0x80, mute_reg);
If you use snd_soc_update_bits, you don't have to read the register first.
Re: [PATCH 1/8] sound:asoc: Add support for STA529 Audio Codec
Hello Clausen,
Quoted 8 lines · Lars-Peter Clausen
Quoted 8 lines
Quoted 7 lines
sound/soc/codecs/sta529.c line 111
Quoted 4 lines
sound/soc/codecs/sta529.c new file +3
-0+static const char *pwm_mode_text[] = {"binary" ,"headphone" ,"ternary" , +"phase-shift" }; +static const char *interface_mode_text[] = {"slave" ,"master" };ALSA controls always use capitalisation.
Quoted 18 lines
Quoted 3 lines
you mean to say
static const char *interface_mode_text[] = { "SLAVE", "MASTER"}No, only the first letter upper case.
Quoted 11 lines
Quoted 6 lines
sound/soc/codecs/sta529.c line 221
Quoted 3 lines
sound/soc/codecs/sta529.c new file +2
-0+sta529_set_bias_level (codec,SND_SOC_BIAS_PREPARE ); +mdelay (10 );Absolutely no - why are you doing this?
In probe I am putting codec in standby mode. so to come out of this
sta529_set_bias_level(codec, SND_SOC_BIAS_PREPARE)is called. Since there are some transition time between STANDBY and ON/PREAPRE, so a delay is introduced in the code.
Actually I was hoping for the same but not able to locate the code. Ok, I will made the changes.
Quoted 19 lines
The framework will take care of taking the CODEC out of standby mode when it is required, so you shouldn't need it here. Also, if the delay is required put it into the
set_bias_levelfunction.Quoted 15 lines
Quoted 14 lines
sound/soc/codecs/sta529.c line 235
Quoted 11 lines
sound/soc/codecs/sta529.c new file +10
-0+static int sta529_mute (struct snd_soc_dai *dai,int mute) +{ +struct snd_soc_codec *codec = dai->codec; + +u8 mute_reg =snd_soc_read (codec,STA529_FFXCFG0 )& ~CODEC_MUTE_VAL ; + +if (mute) + mute_reg |=CODEC_MUTE_VAL ; + +snd_soc_update_bits (codec,STA529_FFXCFG0 ,0x80 ,00 );You're always setting the same value here...
Quoted 5 lines
Quoted 2 lines
Oops, it should be
snd_soc_update_bits(codec, STA529_FFXCFG0, 0x80, mute_reg);If you use
snd_soc_update_bits, you don't have to read the register first.
Ok
Best Regards
Rajeev
Quoted 4 lines
.
Re: [PATCH 1/8] sound:asoc: Add support for STA529 Audio Codec
In reply to Rajeev KumarQuoted 1 line · Rajeev Kumar
+static const char *interface_mode_text[] = { "slave", "master"};
Master/slave mode should be configured using the set_dai_fmt callback.
Review
Quoted 2 lines
(quoted diff) +2
-0+ +static struct snd_soc_dai_ops sta529_dai_ops = {
const
Quoted 4 lines
sound/soc/codecs/sta529.c new file +4
-0+ .hw_params = sta529_hw_params, + .set_fmt = sta529_set_dai_fmt, + .digital_mute = sta529_mute, +};
sound/soc/codecs/sta529.c line 318
Quoted 10 lines
sound/soc/codecs/sta529.c new file +10
-0+ +/* power down chip */ +static int sta529_remove (struct snd_soc_codec *codec) +{ +sta529_set_bias_level (codec,SND_SOC_BIAS_OFF ); + +return 0 ; +} + +static int sta529_suspend (struct snd_soc_codec *codec,pm_message_t state)
The suspend callback doesn't take the state parameter anymore.
Quoted 6 lines
sound/soc/codecs/sta529.c new file +6
-0+{ +sta529_set_bias_level (codec,SND_SOC_BIAS_OFF ); + +return 0 ; +} +
sound/soc/codecs/sta529.c line 334
Quoted 10 lines
sound/soc/codecs/sta529.c new file +10
-0+static int sta529_resume (struct snd_soc_codec *codec) +{ +snd_soc_cache_sync (codec); +sta529_set_bias_level (codec,SND_SOC_BIAS_STANDBY ); +sta529_set_bias_level (codec, codec->dapm.suspend_bias_level); + +return 0 ; +} + +struct snd_soc_codec_driver soc_codec_dev_sta529 = {
A better name is be sta520_codec_driver
[...]
sound/soc/codecs/sta529.c line 370
Quoted 2 lines
sound/soc/codecs/sta529.c new file +2
-0+ +static int sta529_i2c_remove (struct i2c_client *client)
__devexit
sound/soc/codecs/sta529.c line 375
Quoted 5 lines
sound/soc/codecs/sta529.c new file +5
-0+{ +snd_soc_unregister_codec (&client->dev); +kfree (i2c_get_clientdata (client)); +return 0 ; +}
river");
Quoted 2 lines
sound/soc/codecs/sta529.c new file +2
-0+MODULE_AUTHOR ("Rajeev Kumar <[email protected]>" ); +MODULE_LICENSE ("GPL" );
Re: [PATCH 1/8] sound:asoc: Add support for STA529 Audio Codec
Hello Lars,
Quoted 5 lines · Lars-Peter Clausen
Quoted 1 line · Rajeev Kumar
+static const char *interface_mode_text[] = { "slave", "master"};
Master/slave mode should be configured using the
set_dai_fmtcallback.
You mean to say with the help of clock direction. I think you can do it in either way.
By this, I am giving full control to user for the selection.
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ +static struct snd_soc_dai_ops sta529_dai_ops = {const
Ok,
Quoted 8 lines
Quoted 8 lines
sound/soc/codecs/sta529.c new file +8
-0+ .hw_params = sta529_hw_params, + .set_fmt = sta529_set_dai_fmt, + .digital_mute = sta529_mute, +}; + +/* power down chip */ +static int sta529_remove (struct snd_soc_codec *codec) +{
Quoted 9 lines
sound/soc/codecs/sta529.c line 318
Quoted 6 lines
sound/soc/codecs/sta529.c new file +6
-0+sta529_set_bias_level (codec,SND_SOC_BIAS_OFF ); + +return 0 ; +} + +static int sta529_suspend (struct snd_soc_codec *codec,pm_message_t state)The suspend callback doesn't take the state parameter anymore.
Oops,
Quoted 10 lines
Quoted 10 lines
sound/soc/codecs/sta529.c new file +10
-0+{ +sta529_set_bias_level (codec,SND_SOC_BIAS_OFF ); + +return 0 ; +} + +static int sta529_resume (struct snd_soc_codec *codec) +{ +snd_soc_cache_sync (codec); +sta529_set_bias_level (codec,SND_SOC_BIAS_STANDBY );
Quoted 8 lines
sound/soc/codecs/sta529.c line 334
Quoted 6 lines
sound/soc/codecs/sta529.c new file +6
-0+sta529_set_bias_level (codec, codec->dapm.suspend_bias_level); + +return 0 ; +} + +struct snd_soc_codec_driver soc_codec_dev_sta529 = {A better name is be
sta520_codec_driver
Ok,
Quoted 10 lines
[...]
sound/soc/codecs/sta529.c line 370
Quoted 2 lines
sound/soc/codecs/sta529.c new file +2
-0+ +static int sta529_i2c_remove (struct i2c_client *client)
__devexitsound/soc/codecs/sta529.c line 375
Quoted 5 lines
sound/soc/codecs/sta529.c new file +5
-0+{ +snd_soc_unregister_codec (&client->dev); +kfree (i2c_get_clientdata (client)); +return 0 ; +}river");
This comment is not clear to me , please explain.
Best Regards
Rajeev
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+MODULE_AUTHOR("Rajeev Kumar<[email protected]>"); +MODULE_LICENSE("GPL");.
Re: [PATCH 1/8] sound:asoc: Add support for STA529 Audio Codec
Quoted 11 lines · Rajeev kumar
Hello Lars,
Quoted 5 lines · Lars-Peter Clausen
Quoted 1 line · Rajeev Kumar
+static const char *interface_mode_text[] = { "slave", "master"};
Master/slave mode should be configured using the
set_dai_fmtcallback.You mean to say with the help of clock direction. I think you can do it in either way.
By this, I am giving full control to user for the selection.
Maybe I'm misunderstanding what this control does. But if it is about putting the CODEC in master or slave mode, so whether it should generate the frame- and bitclocks or if the other end of the DAI link should do it, then this should be configured using set_dai_fmt. Making this runtime selectable from userspace doesn't make much sense since both sides of the DAI link have to agree on who is master and who is slave. If you just change one side the link will just stop working.
Quoted 4 lines
Quoted 4 lines
[...]
sound/soc/codecs/sta529.c line 370
Quoted 2 lines
sound/soc/codecs/sta529.c new file +2
-0+ +static int sta529_i2c_remove (struct i2c_client *client)
__devexit
Quoted 8 lines
Quoted 6 lines
sound/soc/codecs/sta529.c line 375
Quoted 5 lines
sound/soc/codecs/sta529.c new file +5
-0+{ +snd_soc_unregister_codec (&client->dev); +kfree (i2c_get_clientdata (client)); +return 0 ; +}river");
This comment is not clear to me , please explain.
Annotate the remove function with __devexit. Like this:
+static int __devexit sta529_i2c_remove(struct i2c_client *client)
Re: [PATCH 1/8] sound:asoc: Add support for STA529 Audio Codec
Hello Lars,
Quoted 13 lines · Lars-Peter Clausen
Quoted 11 lines · Rajeev kumar
Hello Lars,
Quoted 5 lines · Lars-Peter Clausen
Quoted 1 line · Rajeev Kumar
+static const char *interface_mode_text[] = { "slave", "master"};
Master/slave mode should be configured using the
set_dai_fmtcallback.You mean to say with the help of clock direction. I think you can do it in either way.
By this, I am giving full control to user for the selection.
Quoted 8 lines
Maybe I'm misunderstanding what this control does. But if it is about putting the CODEC in master or slave mode, so whether it should generate the frame- and bitclocks or if the other end of the DAI link should do it, then this should be configured using
set_dai_fmt. Making this runtime selectable from userspace doesn't make much sense since both sides of the DAI link have to agree on who is master and who is slave. If you just change one side the link will just stop working.
Yes, This will put CODEC in master or slave mode.
OK I will do it in set_dai_fmt.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
[...]
sound/soc/codecs/sta529.c line 370
Quoted 2 lines
sound/soc/codecs/sta529.c new file +2
-0+ +static int sta529_i2c_remove (struct i2c_client *client)
__devexitsound/soc/codecs/sta529.c line 375
Quoted 5 lines
sound/soc/codecs/sta529.c new file +5
-0+{ +snd_soc_unregister_codec (&client->dev); +kfree (i2c_get_clientdata (client)); +return 0 ; +}river");
Quoted 5 lines
Quoted 1 line
This comment is not clear to me , please explain.
Annotate the remove function with
__devexit. Like this:
+static int__devexitsta529_i2c_remove(struct i2c_client *client)
Ok,
Best Regards
Rajeev
Quoted 2 lines
.
PATCH 2/8 sound:asoc: Add support for synopsys i2s controller as per ASoC framework.
In reply to Rajeev KumarThis patch add support for synopsys I2S controller as per the ASoC framework.
--- include/linux/designware_i2s.h | 63 ++++ sound/soc/spear/designware_i2s.c | 610 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 673 insertions(+), 0 deletions(-) create mode 100644 include/linux/designware_i2s.h create mode 100644 sound/soc/spear/designware_i2s.c
include/linux/designware_i2s.h new file +63 -0
@@ -0,0 +1,63 @@ +/* +* linux/designware_i2s.h +* +* Copyright (ST) 2011 Rajeev Kumar ([email protected]) +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +*/ + +#ifndef DESIGNWARE_I2S_H +#define DESIGNWARE_I2S_H + +#include <linux/dmaengine.h> +#include <linux/types.h> + +/* +* struct i2s_clk_config_data - represent i2s clk configuration data +* @chan_nr: number of channel +* @data_width: number of bits per sample (8/16/24/32 bit) +* @sample_rate: sampling frequency (8Khz, 16Khz, 32Khz, 44Khz, 48Khz) +*/ +struct i2s_clk_config_data { +int chan_nr; +u32 data_width; +u32 sample_rate; +}; + +struct i2s_platform_data { +#define PLAY (1 << 0) +#define RECORD (1 << 1) +unsigned int cap; +int channel; +u8 swidth; +u32 snd_rates; + +void *play_dma_data; +void *capture_dma_data; +bool (*filter)(struct dma_chan *chan,void *slave); +int (*i2s_clk_cfg)(struct i2s_clk_config_data *config); +}; + +/* I2S DMA registers */ +#define I2S_RXDMA 0x01C0 +#define I2S_TXDMA 0x01C8 + +#define TWO_CHANNEL_SUPPORT 2/* up to 2.0 */ +#define FOUR_CHANNEL_SUPPORT 4/* up to 3.1 */ +#define SIX_CHANNEL_SUPPORT 6/* up to 5.1 */ +#define EIGHT_CHANNEL_SUPPORT 8/* up to 7.1 */ + +#endif /* DESIGNWARE_I2S_H */
sound/soc/spear/designware_i2s.c new file +610 -0
610 lines not on this page · raw message
Signature · 1 line
1.7.2.2
Re: [PATCH 2/8] sound:asoc: Add support for synopsys i2s controller as per ASoC framework.
Quoted 1 line · Rajeev Kumar
This patch add support for synopsys I2S controller as per the ASoC framework.
If this really is a generic Synopsys block shouldn't it be in a Synopsys directory, possibly with a wrapper in the SPEAr directory for the platform integration?
include/linux/designware_i2s.h line 42
Quoted 3 lines
include/linux/designware_i2s.h new file +3
-0+struct i2s_platform_data { +#define PLAY (1 << 0) +#define RECORD (1 << 1)
Namespacing here and with most of the other defines in the header (and the driver, though the ones in the code are less important). Normally ALSA headers go in include/sound.
Quoted 4 lines
sound/soc/spear/designware_i2s.c new file +4
-0+ +if (stream ==SNDRV_PCM_STREAM_PLAYBACK ) { +i2s_write_reg (dev->i2s_base,TCR (ch), dev->xfer_resolution); +i2s_write_reg (dev->i2s_base,TFCR (ch),0x02 );
sound/soc/spear/designware_i2s.c line 111
Quoted 10 lines
sound/soc/spear/designware_i2s.c new file +10
-0+ irq =i2s_read_reg (dev->i2s_base,IMR (ch)); +i2s_write_reg (dev->i2s_base,IMR (ch), irq & ~0x30 ); +i2s_write_reg (dev->i2s_base,TER (ch),1 ); + }else { +i2s_write_reg (dev->i2s_base,RCR (ch), dev->xfer_resolution); +i2s_write_reg (dev->i2s_base,RFCR (ch),0x07 ); + irq =i2s_read_reg (dev->i2s_base,IMR (ch)); +i2s_write_reg (dev->i2s_base,IMR (ch), irq & ~0x03 ); +i2s_write_reg (dev->i2s_base,RER (ch),1 ); + }
It would be good to split out the bits that are common from the bits that vary per stream.
sound/soc/spear/designware_i2s.c line 124
Quoted 6 lines
sound/soc/spear/designware_i2s.c new file +6
-0+if (stream ==SNDRV_PCM_STREAM_PLAYBACK ) { +for (i =0 ; i <4 ; i++) +i2s_write_reg (dev->i2s_base,TER (i),0 ); + }else { +for (i =0 ; i <4 ; i++) +i2s_write_reg (dev->i2s_base,RER (i),0 );
Magic numbers!
Quoted 17 lines
sound/soc/spear/designware_i2s.c new file +17
-0+static irqreturn_t dw_i2s_play_irq (int irq,void *_dev) +{ +struct dw_i2s_dev *dev = (struct dw_i2s_dev *)_dev; +u32 ch0, ch1; + +/* check for the tx data overrun condition */ + ch0 =i2s_read_reg (dev->i2s_base,ISR (0 )) &0x20 ; + ch1 =i2s_read_reg (dev->i2s_base,ISR (1 )) &0x20 ; +if (ch0 || ch1) { +/* disable i2s block */ +i2s_write_reg (dev->i2s_base,IER ,0 ); + +/* disable tx block */ +i2s_write_reg (dev->i2s_base,ITER ,0 ); + +/* flush all the tx fifo */ +i2s_write_reg (dev->i2s_base,TXFFR ,1 );
sound/soc/spear/designware_i2s.c line 226
Quoted 10 lines
sound/soc/spear/designware_i2s.c new file +10
-0+ +/* clear tx data overrun interrupt */ +i2s_clear_irqs (dev,SNDRV_PCM_STREAM_PLAYBACK ); + +/* enable rx block */ +i2s_write_reg (dev->i2s_base,ITER ,1 ); + +/* enable i2s block */ +i2s_write_reg (dev->i2s_base,IER ,1 ); + }
This is somewhat unusual - normally ALSA detects underrun and overrun and restarts the stream at the application layer. This looks like it attempts to mask information about errors from the application which probably isn't waht we want to do. Why is the normal ALSA handling not sufficient?
Review
Quoted 2 lines
(quoted diff) +2
-0+ + return IRQ_HANDLED;
This unconditionally says it handled the interrupt even if it didn't.
sound/soc/spear/designware_i2s.c line 270
Quoted 9 lines
sound/soc/spear/designware_i2s.c new file +9
-0+static int +dw_i2s_startup (struct snd_pcm_substream *substream,struct snd_soc_dai *cpu_dai) +{ +struct dw_i2s_dev *dev =snd_soc_dai_get_drvdata (cpu_dai); +struct dma_data *dma_data =NULL ; + +if (!(dev->capability &RECORD ) && + (substream->stream ==SNDRV_PCM_STREAM_CAPTURE )) +return -EINVAL ;
Indentation.
Quoted 5 lines
sound/soc/spear/designware_i2s.c new file +5
-0+ +if (dev->i2s_clk_cfg) { +if (dev->i2s_clk_cfg (config)) { +dev_err (dev->dev,"runtime audio clk config fail\n" ); +if (cpu_dai->driver->ops->trigger) {
sound/soc/spear/designware_i2s.c line 334
Quoted 10 lines
sound/soc/spear/designware_i2s.c new file +10
-0+int ret = + cpu_dai->driver->ops->trigger (substream, +SNDRV_PCM_TRIGGER_STOP , + cpu_dai); +if (ret <0 ) { +dev_err (dev->dev, +"trigger stop fail\n" ); +return ret; + } + }
No, return an error if you encounter an error!
sound/soc/spear/designware_i2s.c line 342
Quoted 2 lines
sound/soc/spear/designware_i2s.c new file +2
-0+static void +dw_i2s_shutdown (struct snd_pcm_substream *substream,struct snd_soc_dai *dai)
Indentation - throughout the kernel the type goes on the same line as the function name.
sound/soc/spear/designware_i2s.c line 405
Quoted 4 lines
sound/soc/spear/designware_i2s.c new file +4
-0+static const struct dev_pm_ops dw_i2s_dev_pm_ops = { + .suspend = dw_i2s_suspend, + .resume = dw_i2s_resume, +};
No, do this at the ASoC level like other CPU drivers (runtime PM callbacks are OK).
sound/soc/spear/designware_i2s.c line 437
Quoted 11 lines
sound/soc/spear/designware_i2s.c new file +11
-0+ cap = pdata->cap; + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (&pdev->dev,"no i2s resource defined\n" ); +return -ENODEV ; + } + +if (!request_mem_region (res->start,resource_size (res), pdev->name)) { +dev_err (&pdev->dev,"i2s region already claimed\n" ); +return -EBUSY ; + }
There's devm_ versions of this stuff too.
sound/soc/spear/designware_i2s.c line 438
Quoted 1 line
sound/soc/spear/designware_i2s.c new file +1
-0+ dev =kzalloc (sizeof (*dev),GFP_KERNEL );
devm_kzalloc()
sound/soc/spear/designware_i2s.c line 474
Quoted 2 lines
sound/soc/spear/designware_i2s.c new file +2
-0+ dev->i2s_base =ioremap (res->start,resource_size (res)); +if (!dev->i2s_base) {
devm_ioremap().
sound/soc/spear/designware_i2s.c line 492
Quoted 3 lines
sound/soc/spear/designware_i2s.c new file +3
-0+if (dev->play_irq <0 ) +dev_warn (&pdev->dev,"play irq not defined\n" ); +else {
Braces on both sides of the if.
Quoted 1 line
+static int
__initdw_i2s_init(void)
module_platform_driver().
Re: [PATCH 2/8] sound:asoc: Add support for synopsys i2s controller as per ASoC framework.
Hello Mark
Quoted 7 lines · Mark Brown
Quoted 1 line · Rajeev Kumar
This patch add support for synopsys I2S controller as per the ASoC framework.
If this really is a generic Synopsys block shouldn't it be in a Synopsys directory, possibly with a wrapper in the SPEAr directory for the platform integration?
I will create a new directory by name dwc.
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+struct i2s_platform_data { + #define PLAY (1<< 0) + #define RECORD (1<< 1)Namespacing here and with most of the other defines in the header (and the driver, though the ones in the code are less important). Normally ALSA headers go in
include/sound.
OK I will move it in include/sound/.
Next Patch will contains name spacing also.
Quoted 9 lines
Quoted 9 lines
sound/soc/spear/designware_i2s.c new file +9
-0+ +if (stream ==SNDRV_PCM_STREAM_PLAYBACK ) { +i2s_write_reg (dev->i2s_base,TCR (ch), dev->xfer_resolution); +i2s_write_reg (dev->i2s_base,TFCR (ch),0x02 ); + irq =i2s_read_reg (dev->i2s_base,IMR (ch)); +i2s_write_reg (dev->i2s_base,IMR (ch), irq& ~0x30 ); +i2s_write_reg (dev->i2s_base,TER (ch),1 ); + }else { +i2s_write_reg (dev->i2s_base,RCR (ch), dev->xfer_resolution);
Quoted 9 lines
sound/soc/spear/designware_i2s.c line 111
Quoted 5 lines
sound/soc/spear/designware_i2s.c new file +5
-0+i2s_write_reg (dev->i2s_base,RFCR (ch),0x07 ); + irq =i2s_read_reg (dev->i2s_base,IMR (ch)); +i2s_write_reg (dev->i2s_base,IMR (ch), irq& ~0x03 ); +i2s_write_reg (dev->i2s_base,RER (ch),1 ); + }It would be good to split out the bits that are common from the bits that vary per stream.
OK,
Quoted 9 lines
sound/soc/spear/designware_i2s.c line 124
Quoted 6 lines
sound/soc/spear/designware_i2s.c new file +6
-0+if (stream ==SNDRV_PCM_STREAM_PLAYBACK ) { +for (i =0 ; i<4 ; i++) +i2s_write_reg (dev->i2s_base,TER (i),0 ); + }else { +for (i =0 ; i<4 ; i++) +i2s_write_reg (dev->i2s_base,RER (i),0 );Magic numbers!
will be replaced with macro
Quoted 25 lines
Quoted 25 lines
sound/soc/spear/designware_i2s.c new file +25
-0+static irqreturn_t dw_i2s_play_irq (int irq,void *_dev) +{ +struct dw_i2s_dev *dev = (struct dw_i2s_dev *)_dev; +u32 ch0, ch1; + +/* check for the tx data overrun condition */ + ch0 =i2s_read_reg (dev->i2s_base,ISR (0 ))&0x20 ; + ch1 =i2s_read_reg (dev->i2s_base,ISR (1 ))&0x20 ; +if (ch0 || ch1) { +/* disable i2s block */ +i2s_write_reg (dev->i2s_base,IER ,0 ); + +/* disable tx block */ +i2s_write_reg (dev->i2s_base,ITER ,0 ); + +/* flush all the tx fifo */ +i2s_write_reg (dev->i2s_base,TXFFR ,1 ); + +/* clear tx data overrun interrupt */ +i2s_clear_irqs (dev,SNDRV_PCM_STREAM_PLAYBACK ); + +/* enable rx block */ +i2s_write_reg (dev->i2s_base,ITER ,1 ); + +/* enable i2s block */
Quoted 9 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ i2s_write_reg(dev->i2s_base, IER, 1); + }This is somewhat unusual - normally ALSA detects underrun and overrun and restarts the stream at the application layer. This looks like it attempts to mask information about errors from the application which probably isn't waht we want to do. Why is the normal ALSA handling not5 sufficient?
Normal ALSA handling is sufficient for underrun and overrun. This handler is not required.
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + return IRQ_HANDLED;This unconditionally says it handled the interrupt even if it didn't.
Removing handler will remove this too.
Quoted 12 lines
sound/soc/spear/designware_i2s.c line 270
Quoted 9 lines
sound/soc/spear/designware_i2s.c new file +9
-0+static int +dw_i2s_startup (struct snd_pcm_substream *substream,struct snd_soc_dai *cpu_dai) +{ +struct dw_i2s_dev *dev =snd_soc_dai_get_drvdata (cpu_dai); +struct dma_data *dma_data =NULL ; + +if (!(dev->capability&RECORD )&& + (substream->stream ==SNDRV_PCM_STREAM_CAPTURE )) +return -EINVAL ;Indentation.
Ok
Quoted 9 lines
Quoted 9 lines
sound/soc/spear/designware_i2s.c new file +9
-0+ +if (dev->i2s_clk_cfg) { +if (dev->i2s_clk_cfg (config)) { +dev_err (dev->dev,"runtime audio clk config fail\n" ); +if (cpu_dai->driver->ops->trigger) { +int ret = + cpu_dai->driver->ops->trigger (substream, +SNDRV_PCM_TRIGGER_STOP , + cpu_dai);
Quoted 9 lines
sound/soc/spear/designware_i2s.c line 334
Quoted 6 lines
sound/soc/spear/designware_i2s.c new file +6
-0+if (ret<0 ) { +dev_err (dev->dev, +"trigger stop fail\n" ); +return ret; + } + }No, return an error if you encounter an error!
You need not to stop controller in case clock fail ?
Quoted 6 lines
sound/soc/spear/designware_i2s.c line 342
Quoted 2 lines
sound/soc/spear/designware_i2s.c new file +2
-0+static void +dw_i2s_shutdown (struct snd_pcm_substream *substream,struct snd_soc_dai *dai)Indentation - throughout the kernel the type goes on the same line asi2s the function name.
Ok
Quoted 8 lines
sound/soc/spear/designware_i2s.c line 405
Quoted 4 lines
sound/soc/spear/designware_i2s.c new file +4
-0+static const struct dev_pm_ops dw_i2s_dev_pm_ops = { + .suspend = dw_i2s_suspend, + .resume = dw_i2s_resume, +};No, do this at the ASoC level like other CPU drivers (runtime PM callbacks are OK).
Ok,
Quoted 5 lines
Quoted 5 lines
sound/soc/spear/designware_i2s.c new file +5
-0+ cap = pdata->cap; + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (&pdev->dev,"no i2s resource defined\n" ); +return -ENODEV ;
Quoted 9 lines
sound/soc/spear/designware_i2s.c line 437
Quoted 6 lines
sound/soc/spear/designware_i2s.c new file +6
-0+ } + +if (!request_mem_region (res->start,resource_size (res), pdev->name)) { +dev_err (&pdev->dev,"i2s region already claimed\n" ); +return -EBUSY ; + }There's
devm_versions of this stuff too.
OK
Quoted 4 lines
sound/soc/spear/designware_i2s.c line 438
Quoted 1 line
sound/soc/spear/designware_i2s.c new file +1
-0+ dev =kzalloc (sizeof (*dev),GFP_KERNEL );
devm_kzalloc()
Ok
Quoted 5 lines
sound/soc/spear/designware_i2s.c line 474
Quoted 2 lines
sound/soc/spear/designware_i2s.c new file +2
-0+ dev->i2s_base =ioremap (res->start,resource_size (res)); +if (!dev->i2s_base) {
devm_ioremap().
Ok
Quoted 6 lines
sound/soc/spear/designware_i2s.c line 492
Quoted 3 lines
sound/soc/spear/designware_i2s.c new file +3
-0+if (dev->play_irq<0 ) +dev_warn (&pdev->dev,"play irq not defined\n" ); +else {Braces on both sides of the if.
Ok,
Best Regards
Rajeev
Quoted 3 lines
Quoted 1 line
+static int
__initdw_i2s_init(void)
module_platform_driver().
Re: [PATCH 2/8] sound:asoc: Add support for synopsys i2s controller as per ASoC framework.
Quoted 19 lines · Rajeev kumar
Quoted 17 lines · Mark Brown
sound/soc/spear/designware_i2s.c line 334
Quoted 13 lines · Rajeev Kumar
sound/soc/spear/designware_i2s.c new file +13
-0+if (dev->i2s_clk_cfg (config)) { +dev_err (dev->dev,"runtime audio clk config fail\n" ); +if (cpu_dai->driver->ops->trigger) { +int ret = + cpu_dai->driver->ops->trigger (substream, +SNDRV_PCM_TRIGGER_STOP , + cpu_dai); +if (ret<0 ) { +dev_err (dev->dev, +"trigger stop fail\n" ); +return ret; + } + }No, return an error if you encounter an error!
Quoted 1 line
You need not to stop controller in case clock fail ?
Let the upper layers worry about that. Don't randomly change the state of the controller without them knowing about it.
Re: [PATCH 2/8] sound:asoc: Add support for synopsys i2s controller as per ASoC framework.
Hello Mark,
Quoted 20 lines · Mark Brown
Quoted 18 lines · Rajeev kumar
Quoted 17 lines · Mark Brown
sound/soc/spear/designware_i2s.c line 334
Quoted 13 lines · Rajeev Kumar
sound/soc/spear/designware_i2s.c new file +13
-0+if (dev->i2s_clk_cfg (config)) { +dev_err (dev->dev,"runtime audio clk config fail\n" ); +if (cpu_dai->driver->ops->trigger) { +int ret = + cpu_dai->driver->ops->trigger (substream, +SNDRV_PCM_TRIGGER_STOP , + cpu_dai); +if (ret<0 ) { +dev_err (dev->dev, +"trigger stop fail\n" ); +return ret; + } + }No, return an error if you encounter an error!
Quoted 5 lines
Quoted 1 line
You need not to stop controller in case clock fail ?
Let the upper layers worry about that. Don't randomly change the state of the controller without them knowing about it.
Ok
Best Regards
Rajeev
PATCH 3/8 sound:asoc: Add support for SPEAr ASoC pcm layer.
In reply to Rajeev KumarThis patch add support for the SPEAr ASoC pcm layer in ASoC framework.
--- sound/soc/spear/spear_pcm.c | 460 +++++++++++++++++++++++++++++++++++++++++++ sound/soc/spear/spear_pcm.h | 33 +++ 2 files changed, 493 insertions(+), 0 deletions(-) create mode 100644 sound/soc/spear/spear_pcm.c create mode 100644 sound/soc/spear/spear_pcm.h
sound/soc/spear/spear_pcm.c new file +460 -0
@@ -0,0 +1,460 @@ +/* +* ALSA PCM interface for ST SPEAr Processors +* +* sound/soc/spear/spear_pcm.c +* +* Copyright (C) 2012 ST Microelectronics +* Rajeev Kumar<[email protected]> +* +* This file is licensed under the terms of the GNU General Public +* License version 2. This program is licensed "as is" without any +* warranty of any kind, whether express or implied. +*/ + +#include <linux/module.h> +#include <linux/dmaengine.h> +#include <linux/dma-mapping.h> +#include <linux/init.h> +#include <linux/platform_device.h> +#include <linux/scatterlist.h> +#include <linux/slab.h> +#include <linux/spear_dma.h> +#include <sound/core.h> +#include <sound/pcm.h> +#include <sound/soc.h> +#include "spear_pcm.h" + +struct snd_pcm_hardware spear_pcm_hardware = { + .info = (SNDRV_PCM_INFO_INTERLEAVED |SNDRV_PCM_INFO_BLOCK_TRANSFER | +SNDRV_PCM_INFO_MMAP |SNDRV_PCM_INFO_MMAP_VALID | +SNDRV_PCM_INFO_PAUSE |SNDRV_PCM_INFO_RESUME ), + .buffer_bytes_max =16 *1024 ,/* max buffer size */ + .period_bytes_min =2 *1024 ,/* 1 msec data minimum period size */ + .period_bytes_max =2 *1024 ,/* maximum period size */ + .periods_min =1 ,/* min # periods */ + .periods_max =8 ,/* max # of periods */ + .fifo_size =0 ,/* fifo size in bytes */ +}; + +static void pcm_dma_complete (void *arg); + +static int spear_pcm_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params) +{ +int ret =snd_pcm_lib_malloc_pages (substream, +params_buffer_bytes (params)); +if (ret <0 ) +return ret; + +return 0 ; +} + +static int spear_pcm_hw_free (struct snd_pcm_substream *substream) +{ +return snd_pcm_lib_free_pages (substream); +} + +static int spear_pcm_prepare (struct snd_pcm_substream *substream) +{ +struct snd_pcm_runtime *runtime = substream->runtime; +struct spear_runtime_data *prtd = runtime->private_data; +unsigned long flags; + +spin_lock_irqsave (&prtd->lock, flags); + prtd->dma_addr = runtime->dma_addr; + + prtd->buf_index =0 ; + prtd->dmacount =0 ; + prtd->xfer_len =snd_pcm_lib_period_bytes (substream); + prtd->xfer_cnt =snd_pcm_lib_buffer_bytes (substream) / prtd->xfer_len; + +spin_unlock_irqrestore (&prtd->lock, flags); + +return 0 ; +} + +static int start_dma (struct spear_runtime_data *prtd) +{ +struct dma_slave_config conf = { + .device_fc = false, + }; + +struct dma_chan *chan; +struct dma_async_tx_descriptor *desc; +struct scatterlist sg; +enum dma_data_direction direction; +dma_addr_t addr; +struct snd_soc_pcm_runtime *rtd = prtd->substream->private_data; +struct dma_data *dma_data = +snd_soc_dai_get_dma_data (rtd->cpu_dai, prtd->substream); + addr = prtd->dma_addr + prtd->buf_index * prtd->xfer_len; +if (prtd->substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { + chan = prtd->dma_chan[0 ]; + direction =DMA_TO_DEVICE ; + conf.dst_addr = dma_data->addr; + }else { + chan = prtd->dma_chan[1 ]; + direction =DMA_FROM_DEVICE ; + conf.src_addr = dma_data->addr; + } + + conf.src_maxburst = dma_data->max_burst; + conf.dst_maxburst = dma_data->max_burst; + conf.src_addr_width = dma_data->addr_width; + conf.dst_addr_width = dma_data->addr_width; + +/* Prepare sg's */ +sg_init_table (&sg,1 ); +sg_set_page (&sg,pfn_to_page (PFN_DOWN (addr)), prtd->xfer_len, + addr & (PAGE_SIZE -1 )); +sg_dma_address (&sg) = addr; + + conf.direction = direction; +dmaengine_slave_config (chan, &conf); + + desc = chan->device->device_prep_slave_sg (chan, &sg,1 , direction, +DMA_PREP_INTERRUPT ); +if (!desc) { +dev_err (&chan->dev->device,"cannot prepare slave dma\n" ); +return -EAGAIN ; + } + + desc->callback = pcm_dma_complete; + desc->callback_param = prtd; + desc->tx_submit (desc); + +return 0 ; +} + +static void pcm_dma_xfer (struct spear_runtime_data *prtd, +bool from_callback) +{ +struct snd_pcm_substream *substream = prtd->substream; +struct dma_chan *chan; +unsigned long flags; +int ret; + +spin_lock_irqsave (&prtd->lock, flags); +if (!prtd->pcm_running) { +spin_unlock_irqrestore (&prtd->lock, flags); +return ; + } + +BUG_ON (prtd->dmacount >= prtd->xfer_cnt); + +while (prtd->dmacount < prtd->xfer_cnt) { + + ret =start_dma (prtd); +if (ret) { +spin_unlock_irqrestore (&prtd->lock, flags); +return ; + } + + prtd->dmacount++; + prtd->buf_index++; + +/* Set to zero, if crosses buffer size */ + prtd->buf_index %= prtd->xfer_cnt; + +/* Inform framework that a transfer is finished */ +if (from_callback) { +spin_unlock_irqrestore (&prtd->lock, flags); +snd_pcm_period_elapsed (substream); +spin_lock_irqsave (&prtd->lock, flags); + } + } +spin_unlock_irqrestore (&prtd->lock, flags); + +/* Issue pending should be called after locks */ +if (prtd->substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) + chan = prtd->dma_chan[0 ]; +else + chan = prtd->dma_chan[1 ]; + + chan->device->device_issue_pending (chan); +} + +static void pcm_dma_complete (void *arg) +{ +struct spear_runtime_data *prtd = arg; +unsigned long flags; + +spin_lock_irqsave (&prtd->lock, flags); + prtd->dmacount--; +spin_unlock_irqrestore (&prtd->lock, flags); + +if (prtd->pcm_running) +pcm_dma_xfer (prtd, true); +} + +static int spear_pcm_trigger (struct snd_pcm_substream *substream,int cmd) +{ +struct spear_runtime_data *prtd = substream->runtime->private_data; +struct dma_chan *chan; +unsigned long flags; +int ret =0 ; + +switch (cmd) { +case SNDRV_PCM_TRIGGER_RESUME : +spin_lock_irqsave (&prtd->lock, flags); +/* Go to last successfully transferred index + 1 */ + prtd->buf_index += prtd->xfer_cnt - prtd->dmacount; + prtd->buf_index %= prtd->xfer_cnt; + prtd->dmacount =0 ; +spin_unlock_irqrestore (&prtd->lock, flags); +case SNDRV_PCM_TRIGGER_START : +spin_lock_irqsave (&prtd->lock, flags); + prtd->pcm_running = true; +spin_unlock_irqrestore (&prtd->lock, flags); +pcm_dma_xfer (prtd, false); +break ; +case SNDRV_PCM_TRIGGER_STOP : +case SNDRV_PCM_TRIGGER_SUSPEND : +spin_lock_irqsave (&prtd->lock, flags); + prtd->pcm_running = false; +spin_unlock_irqrestore (&prtd->lock, flags); +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) + chan = prtd->dma_chan[0 ]; +else + chan = prtd->dma_chan[1 ]; + + chan->device->device_control (chan,DMA_TERMINATE_ALL ,0 ); +break ; +case SNDRV_PCM_TRIGGER_PAUSE_PUSH : +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : +break ; +default : + ret = -EINVAL ; + } + +return ret; +} + +static snd_pcm_uframes_t +spear_pcm_pointer (struct snd_pcm_substream *substream) +{ +struct spear_runtime_data *prtd = substream->runtime->private_data; + +return bytes_to_frames (substream->runtime, prtd->buf_index * + prtd->xfer_len); +} + +static int pcm_alloc_dma_chan (struct snd_pcm_substream *substream) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct spear_runtime_data *prtd = substream->runtime->private_data; + +int stream = (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) ?0 :1 ; +struct dma_data *dma_data = +snd_soc_dai_get_dma_data (rtd->cpu_dai, substream); + + prtd->dma_chan[stream] =dma_request_channel (prtd->smask, + dma_data->filter, dma_data->data); +if (!prtd->dma_chan[stream]) +return -EAGAIN ; + +return 0 ; +} + +static void pcm_dma_free_chan (struct snd_pcm_substream *substream) +{ +struct spear_runtime_data *prtd = substream->runtime->private_data; +struct dma_chan *chan; + +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) + chan = prtd->dma_chan[0 ]; +else + chan = prtd->dma_chan[1 ]; + + chan->device->device_control (chan,DMA_TERMINATE_ALL ,0 ); +dma_release_channel (chan); +} + +static int spear_pcm_open (struct snd_pcm_substream *substream) +{ +struct spear_runtime_data *prtd; +int ret; + + ret =snd_soc_set_runtime_hwparams (substream, &spear_pcm_hardware); +if (ret) +return ret; + +/* ensure that buffer size is a multiple of period size */ + ret =snd_pcm_hw_constraint_integer (substream->runtime, +SNDRV_PCM_HW_PARAM_PERIODS ); +if (ret <0 ) +return ret; + + prtd =kzalloc (sizeof (*prtd),GFP_KERNEL ); +if (!prtd) +return -ENOMEM ; + +spin_lock_init (&prtd->lock); + substream->runtime->private_data = prtd; + prtd->substream = substream; +dma_cap_zero (prtd->smask); +dma_cap_set (DMA_SLAVE , prtd->smask); + + ret =pcm_alloc_dma_chan (substream); +if (ret) { +dev_err (substream->pcm->card->dev, +"pcm:Failed to get dma channels\n" ); +kfree (prtd); + } + +return 0 ; +} + +static int spear_pcm_close (struct snd_pcm_substream *substream) +{ +struct spear_runtime_data *prtd = substream->runtime->private_data; + +pcm_dma_free_chan (substream); +kfree (prtd); + +return 0 ; +} + +static int spear_pcm_mmap (struct snd_pcm_substream *substream, +struct vm_area_struct *vma) +{ +struct snd_pcm_runtime *runtime = substream->runtime; + +return dma_mmap_writecombine (substream->pcm->card->dev, vma, + runtime->dma_area, runtime->dma_addr, + runtime->dma_bytes); +} + +static struct snd_pcm_ops spear_pcm_ops = { + .open = spear_pcm_open, + .close = spear_pcm_close, + .ioctl = snd_pcm_lib_ioctl, + .hw_params = spear_pcm_hw_params, + .hw_free = spear_pcm_hw_free, + .prepare = spear_pcm_prepare, + .trigger = spear_pcm_trigger, + .pointer = spear_pcm_pointer, + .mmap = spear_pcm_mmap, +}; + +static int +spear_pcm_preallocate_dma_buffer (struct snd_pcm *pcm,int stream, +size_t size) +{ +struct snd_pcm_substream *substream = pcm->streams[stream].substream; +struct snd_dma_buffer *buf = &substream->dma_buffer; + + buf->dev.type =SNDRV_DMA_TYPE_DEV ; + buf->dev.dev = pcm->card->dev; + buf->private_data =NULL ; + + buf->area =dma_alloc_writecombine (pcm->card->dev, size, + &buf->addr,GFP_KERNEL ); +if (!buf->area) +return -ENOMEM ; + +dev_info (buf->dev.dev, +" preallocate_dma_buffer: area=%p, addr=%p, size=%d\n" , + (void *)buf->area, (void *)buf->addr, size); + + buf->bytes = size; +return 0 ; +} + +static void spear_pcm_free (struct snd_pcm *pcm) +{ +struct snd_pcm_substream *substream; +struct snd_dma_buffer *buf; +int stream; + +for (stream =0 ; stream <2 ; stream++) { + substream = pcm->streams[stream].substream; +if (!substream) +continue ; + + buf = &substream->dma_buffer; +if (!buf && !buf->area) +continue ; + +dma_free_writecombine (pcm->card->dev, buf->bytes, + buf->area, buf->addr); + buf->area =NULL ; + } +} + +static u64 spear_pcm_dmamask =DMA_BIT_MASK (32 ); + +static int spear_pcm_new (struct snd_soc_pcm_runtime *rtd) +{ +struct snd_card *card = rtd->card->snd_card; +struct snd_soc_dai *dai = rtd->cpu_dai; +struct snd_pcm *pcm = rtd->pcm; +int ret; + +if (!card->dev->dma_mask) + card->dev->dma_mask = &spear_pcm_dmamask; +if (!card->dev->coherent_dma_mask) + card->dev->coherent_dma_mask =DMA_BIT_MASK (32 ); + +if (dai->driver->playback.channels_min) { + ret =spear_pcm_preallocate_dma_buffer (pcm, +SNDRV_PCM_STREAM_PLAYBACK , + spear_pcm_hardware.buffer_bytes_max); +if (ret) +return ret; + } + +if (dai->driver->capture.channels_min) { + ret =spear_pcm_preallocate_dma_buffer (pcm, +SNDRV_PCM_STREAM_CAPTURE , + spear_pcm_hardware.buffer_bytes_max); +if (ret) +return ret; + } + +return 0 ; +} + +struct snd_soc_platform_driver spear_soc_platform = { + .ops = &spear_pcm_ops, + .pcm_new = spear_pcm_new, + .pcm_free = spear_pcm_free, +}; + +static int __devinit spear_soc_platform_probe (struct platform_device *pdev) +{ +return snd_soc_register_platform (&pdev->dev, &spear_soc_platform); +} + +static int __devexit spear_soc_platform_remove(struct platform_device *pdev) +{ +snd_soc_unregister_platform (&pdev->dev); + +return 0 ; +} + +static struct platform_driver spear_pcm_driver = { + .driver = { + .name ="spear-pcm-audio" , + .owner =THIS_MODULE , + }, + + .probe = spear_soc_platform_probe, + .remove =__devexit_p (spear_soc_platform_remove), +}; +static int __init snd_spear_pcm_init (void ) +{ +return platform_driver_register (&spear_pcm_driver); +} +module_init (snd_spear_pcm_init); + +static void __exit snd_spear_pcm_exit(void) +{ +platform_driver_unregister (&spear_pcm_driver); +} +module_exit (snd_spear_pcm_exit); + +MODULE_AUTHOR ("Rajeev Kumar <[email protected]>" ); +MODULE_DESCRIPTION ("SPEAr PCM DMA module" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS ("platform:spear_pcm" );
sound/soc/spear/spear_pcm.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* ALSA PCM interface for ST SPEAr Processors +* +* sound/soc/spear/spear_pcm.h +* +* Copyright (C) 2012 ST Microelectronics +* Rajeev Kumar<[email protected]> +* +* This file is licensed under the terms of the GNU General Public +* License version 2. This program is licensed "as is" without any +* warranty of any kind, whether express or implied. +*/ + +#ifndef SPEAR_PCM_H +#define SPEAR_PCM_H + +struct spear_runtime_data { +struct dma_chan *dma_chan[2 ]; +spinlock_t lock; +struct snd_pcm_substream *substream; +dma_addr_t dma_addr; + +/* DMA related mask */ +dma_cap_mask_t smask; + +/* For Keeping track of buffers */ +unsigned long xfer_len;/* Data transfered by one transfer */ +int xfer_cnt;/* Total number of transfers to be done */ +int buf_index;/* Current buffer count */ +int dmacount;/* No. of DMA transfer ongoing */ +bool pcm_running;/* Current state of pcm, true if running */ +}; +#endif /* end of pcm header file */
Signature · 1 line
1.7.2.2
Re: [PATCH 3/8] sound:asoc: Add support for SPEAr ASoC pcm layer.
Quoted 1 line · Rajeev Kumar
This patch add support for the SPEAr ASoC pcm layer in ASoC framework.
This should really be rewritten in terms of the dmaengine helper library which Lars-Peter contributed for 3.4. It looks like you're not using cyclic mode here which is currently a requirement for the library - if your hardware doesn't have cyclic support then that'll need to be added.
We've already got too many independant implementations of an ALSA to dmaengine mapping, we should be cutting down on the amount of code as much as possible in order to avoid code duplication and make sure that we're able to roll out good practice and new features as easily as possible.
PATCH 4/8 sound:asoc:spdif_in: Add spdif IN support
In reply to Rajeev KumarFrom: Vipin Kumar <[email protected]>
This patch implements the spdif IN driver for ST peripheral
--- sound/soc/spear/spdif_in.c | 304 +++++++++++++++++++++++++++++++++++++++ sound/soc/spear/spdif_in_regs.h | 60 ++++++++ 2 files changed, 364 insertions(+), 0 deletions(-) create mode 100644 sound/soc/spear/spdif_in.c create mode 100644 sound/soc/spear/spdif_in_regs.h
sound/soc/spear/spdif_in.c new file +304 -0
@@ -0,0 +1,304 @@ +/* +* ALSA SoC SPDIF In Audio Layer for spear processors +* +* Copyright (C) 2012 ST Microelectronics +* Vipin Kumar <[email protected]> +* +* This file is licensed under the terms of the GNU General Public +* License version 2. This program is licensed "as is" without any +* warranty of any kind, whether express or implied. +*/ + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/export.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/io.h> +#include <linux/ioport.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/spear_dma.h> +#include <sound/pcm.h> +#include <sound/pcm_params.h> +#include <sound/soc.h> +#include <mach/spdif.h> +#include "spdif_in_regs.h" + +struct spdif_in_params { +u32 format; +}; + +struct spdif_in_dev { +struct clk *clk; +struct dma_data dma_params; +struct spdif_in_params saved_params; +void *io_base; +void (*reset_perip)(void ); +int irq; +}; + +static void spdif_in_configure (struct spdif_in_dev *host) +{ +u32 ctrl =SPDIF_IN_PRTYEN |SPDIF_IN_STATEN |SPDIF_IN_USREN | +SPDIF_IN_VALEN |SPDIF_IN_BLKEN ; + ctrl |=SPDIF_MODE_16BIT |SPDIF_FIFO_THRES_16 ; + +writel (ctrl, host->io_base +SPDIF_IN_CTRL ); +writel (0xF , host->io_base +SPDIF_IN_IRQ_MASK ); +} + +static int spdif_in_startup (struct snd_pcm_substream *substream, +struct snd_soc_dai *cpu_dai) +{ +struct spdif_in_dev *host =snd_soc_dai_get_drvdata (cpu_dai); + +if (substream->stream !=SNDRV_PCM_STREAM_CAPTURE ) +return -EINVAL ; + +snd_soc_dai_set_dma_data (cpu_dai, substream, (void *)&host->dma_params); +return 0 ; +} + +static void spdif_in_shutdown (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct spdif_in_dev *host =snd_soc_dai_get_drvdata (dai); + +if (substream->stream !=SNDRV_PCM_STREAM_CAPTURE ) +return ; + +writel (0x0 , host->io_base +SPDIF_IN_IRQ_MASK ); +snd_soc_dai_set_dma_data (dai, substream,NULL ); +} + +static void spdif_in_format (struct spdif_in_dev *host,u32 format) +{ +u32 ctrl =readl (host->io_base +SPDIF_IN_CTRL ); + +switch (format) { +case SNDRV_PCM_FORMAT_S16_LE : + ctrl |=SPDIF_XTRACT_16BIT ; +break ; + +case SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE : + ctrl &= ~SPDIF_XTRACT_16BIT ; +break ; + } + +writel (ctrl, host->io_base +SPDIF_IN_CTRL ); +} + +static int spdif_in_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params, +struct snd_soc_dai *dai) +{ +struct spdif_in_dev *host =snd_soc_dai_get_drvdata (dai); +u32 format; + +if (substream->stream !=SNDRV_PCM_STREAM_CAPTURE ) +return -EINVAL ; + + format =params_format (params); + host->saved_params.format = format; + +return 0 ; +} + +static int spdif_in_trigger (struct snd_pcm_substream *substream,int cmd, +struct snd_soc_dai *dai) +{ +struct spdif_in_dev *host =snd_soc_dai_get_drvdata (dai); +u32 ctrl; +int ret =0 ; + +if (substream->stream !=SNDRV_PCM_STREAM_CAPTURE ) +return -EINVAL ; + +switch (cmd) { +case SNDRV_PCM_TRIGGER_START : +case SNDRV_PCM_TRIGGER_RESUME : +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : +clk_enable (host->clk); +spdif_in_configure (host); +spdif_in_format (host, host->saved_params.format); + + ctrl =readl (host->io_base +SPDIF_IN_CTRL ); + ctrl |=SPDIF_IN_SAMPLE |SPDIF_IN_ENB ; +writel (ctrl, host->io_base +SPDIF_IN_CTRL ); +writel (0xF , host->io_base +SPDIF_IN_IRQ_MASK ); +break ; + +case SNDRV_PCM_TRIGGER_STOP : +case SNDRV_PCM_TRIGGER_SUSPEND : +case SNDRV_PCM_TRIGGER_PAUSE_PUSH : + ctrl =readl (host->io_base +SPDIF_IN_CTRL ); + ctrl &= ~(SPDIF_IN_SAMPLE |SPDIF_IN_ENB ); +writel (ctrl, host->io_base +SPDIF_IN_CTRL ); +writel (0x0 , host->io_base +SPDIF_IN_IRQ_MASK ); + +if (host->reset_perip) + host->reset_perip (); +clk_disable (host->clk); +break ; + +default : + ret = -EINVAL ; +break ; + } +return ret; +} + +static struct snd_soc_dai_ops spdif_in_dai_ops = { + .startup = spdif_in_startup, + .shutdown = spdif_in_shutdown, + .trigger = spdif_in_trigger, + .hw_params = spdif_in_hw_params, +}; + +struct snd_soc_dai_driver spdif_in_dai = { + .capture = { + .channels_min =2 , + .channels_max =2 , + .rates = (SNDRV_PCM_RATE_32000 |SNDRV_PCM_RATE_44100 | \ +SNDRV_PCM_RATE_48000 |SNDRV_PCM_RATE_96000 | \ +SNDRV_PCM_RATE_192000 ), + .formats =SNDRV_PCM_FMTBIT_S16_LE | \ +SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE , + }, + .ops = &spdif_in_dai_ops, +}; + +static irqreturn_t spdif_in_irq (int irq,void *arg) +{ +struct spdif_in_dev *host = (struct spdif_in_dev *)arg; + +u32 irq_status =readl (host->io_base +SPDIF_IN_IRQ ); + +if (!irq_status) +return IRQ_NONE ; + +if (irq_status &SPDIF_IRQ_FIFOWRITE ) +pr_err ("spdif in: fifo write error\n" ); +if (irq_status &SPDIF_IRQ_EMPTYFIFOREAD ) +pr_err ("spdif in: empty fifo read error\n" ); +if (irq_status &SPDIF_IRQ_FIFOFULL ) +pr_err ("spdif in: fifo full error\n" ); +if (irq_status &SPDIF_IRQ_OUTOFRANGE ) +pr_err ("spdif in: out of range error\n" ); + +writel (0 , host->io_base +SPDIF_IN_IRQ ); + +return IRQ_HANDLED ; +} + +static int spdif_in_probe (struct platform_device *pdev) +{ +struct spdif_in_dev *host; +struct spdif_platform_data *pdata; +struct resource *res, *res_fifo; +int ret; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) +return -EINVAL ; + + res_fifo =platform_get_resource (pdev,IORESOURCE_IO ,0 ); +if (!res_fifo) +return -EINVAL ; + +if (!devm_request_mem_region (&pdev->dev, res->start, +resource_size (res), pdev->name)) { +dev_warn (&pdev->dev,"Failed to get memory resourse\n" ); +return -ENOENT ; + } + + host =devm_kzalloc (&pdev->dev,sizeof (*host),GFP_KERNEL ); +if (!host) { +dev_warn (&pdev->dev,"kzalloc fail\n" ); +return -ENOMEM ; + } + + host->io_base =devm_ioremap (&pdev->dev, res->start, +resource_size (res)); +if (!host->io_base) { +dev_warn (&pdev->dev,"ioremap failed\n" ); +return -ENOMEM ; + } + + host->irq =platform_get_irq (pdev,0 ); +if (host->irq <0 ) +return -EINVAL ; + + host->clk =clk_get (&pdev->dev,NULL ); +if (IS_ERR (host->clk)) +return PTR_ERR (host->clk); + + pdata =dev_get_platdata (&pdev->dev); + + host->dma_params.data = pdata->dma_params; + host->dma_params.addr = res_fifo->start; + host->dma_params.max_burst =16 ; + host->dma_params.addr_width =DMA_SLAVE_BUSWIDTH_4_BYTES ; + host->dma_params.filter = pdata->filter; + host->reset_perip = pdata->reset_perip; + +dev_set_drvdata (&pdev->dev, host); + + ret =devm_request_irq (&pdev->dev, host->irq, spdif_in_irq,0 , +"spdif-in" , host); +if (ret) { +clk_put (host->clk); +dev_warn (&pdev->dev,"request_irq failed\n" ); +return ret; + } + + ret =snd_soc_register_dai (&pdev->dev, &spdif_in_dai); +if (ret !=0 ) { +clk_put (host->clk); +return ret; + } + +return 0 ; +} + +static int spdif_in_remove (struct platform_device *pdev) +{ +struct spdif_in_dev *host =dev_get_drvdata (&pdev->dev); + +snd_soc_unregister_dai (&pdev->dev); +dev_set_drvdata (&pdev->dev,NULL ); + +clk_put (host->clk); + +return 0 ; +} + +#define SPDIF_IN_DEV_PM_OPS NULL + +static struct platform_driver spdif_in_driver = { + .probe = spdif_in_probe, + .remove = spdif_in_remove, + .driver = { + .name ="spdif-in" , + .owner =THIS_MODULE , + .pm =SPDIF_IN_DEV_PM_OPS , + }, +}; + +static int __init spdif_in_init (void ) +{ +return platform_driver_register (&spdif_in_driver); +} +module_init (spdif_in_init); + +static void __exit spdif_in_exit(void) +{ +platform_driver_unregister (&spdif_in_driver); +} +module_exit (spdif_in_exit); + +MODULE_AUTHOR ("Vipin Kumar <[email protected]>" ); +MODULE_DESCRIPTION ("SPEAr SPDIF IN SoC Interface" ); +MODULE_LICENSE ("GPL" );
sound/soc/spear/spdif_in_regs.h new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
1.7.2.2
Re: [PATCH 4/8] sound:asoc:spdif_in: Add spdif IN support
On Tue, Mar 20, 2012 at 05:03:48PM +0530, Rajeev Kumar wrote:
This looks good, a few minor things but almost good to go.
Quoted 1 line
This patch implements the spdif IN driver for ST peripheral
S/PDIF.
sound/soc/spear/spdif_in.c line 189
Quoted 8 lines
sound/soc/spear/spdif_in.c new file +8
-0+if (irq_status &SPDIF_IRQ_FIFOWRITE ) +pr_err ("spdif in: fifo write error\n" ); +if (irq_status &SPDIF_IRQ_EMPTYFIFOREAD ) +pr_err ("spdif in: empty fifo read error\n" ); +if (irq_status &SPDIF_IRQ_FIFOFULL ) +pr_err ("spdif in: fifo full error\n" ); +if (irq_status &SPDIF_IRQ_OUTOFRANGE ) +pr_err ("spdif in: out of range error\n" );
dev_err().
sound/soc/spear/spdif_in.c line 221
Quoted 11 lines
sound/soc/spear/spdif_in.c new file +11
-0+if (!devm_request_mem_region (&pdev->dev, res->start, +resource_size (res), pdev->name)) { +dev_warn (&pdev->dev,"Failed to get memory resourse\n" ); +return -ENOENT ; + } + + host =devm_kzalloc (&pdev->dev,sizeof (*host),GFP_KERNEL ); +if (!host) { +dev_warn (&pdev->dev,"kzalloc fail\n" ); +return -ENOMEM ; + }
Good to see this - this is the sort of stuff I was looking for in the I2S driver.
sound/soc/spear/spdif_in.c line 238
Quoted 5 lines
sound/soc/spear/spdif_in.c new file +4
-0+ host->clk =clk_get (&pdev->dev,NULL ); +if (IS_ERR (host->clk)) +return PTR_ERR (host->clk); + pdata =dev_get_platdata (&pdev->dev);
Should really be error checking in case you didn't get your platform data.
sound/soc/spear/spdif_in.c line 251
Quoted 3 lines
sound/soc/spear/spdif_in.c new file +3
-0+ ret =devm_request_irq (&pdev->dev, host->irq, spdif_in_irq,0 , +"spdif-in" , host); +if (ret) {
I'm really not enthused about the idea of using devm_request_irq() here
- what steps are you taking to make sure that the IRQ can't possibly fire after you've started tearing down the device. In general it's relatively hard to use devm_request_irq() safely.
Quoted 1 line
+#define
SPDIF_IN_DEV_PM_OPSNULL
Just remove this if it's unconditionally empty.
Quoted 1 line
+static int
__initspdif_in_init(void)
module_platform_driver().
Re: [PATCH 4/8] sound:asoc:spdif_in: Add spdif IN support
Hello Mark,
Quoted 8 lines · Mark Brown
On Tue, Mar 20, 2012 at 05:03:48PM +0530, Rajeev Kumar wrote:
This looks good, a few minor things but almost good to go.
Quoted 1 line
This patch implements the spdif IN driver for ST peripheral
S/PDIF.
Ok,
Quoted 11 lines
sound/soc/spear/spdif_in.c line 189
Quoted 8 lines
sound/soc/spear/spdif_in.c new file +8
-0+if (irq_status&SPDIF_IRQ_FIFOWRITE ) +pr_err ("spdif in: fifo write error\n" ); +if (irq_status&SPDIF_IRQ_EMPTYFIFOREAD ) +pr_err ("spdif in: empty fifo read error\n" ); +if (irq_status&SPDIF_IRQ_FIFOFULL ) +pr_err ("spdif in: fifo full error\n" ); +if (irq_status&SPDIF_IRQ_OUTOFRANGE ) +pr_err ("spdif in: out of range error\n" );
dev_err().
Ok
Quoted 6 lines
Quoted 6 lines
sound/soc/spear/spdif_in.c new file +6
-0+if (!devm_request_mem_region (&pdev->dev, res->start, +resource_size (res), pdev->name)) { +dev_warn (&pdev->dev,"Failed to get memory resourse\n" ); +return -ENOENT ; + } +
Quoted 9 lines
sound/soc/spear/spdif_in.c line 221
Quoted 5 lines
sound/soc/spear/spdif_in.c new file +5
-0+ host =devm_kzalloc (&pdev->dev,sizeof (*host),GFP_KERNEL ); +if (!host) { +dev_warn (&pdev->dev,"kzalloc fail\n" ); +return -ENOMEM ; + }Good to see this - this is the sort of stuff I was looking for in the I2S driver.
Will follow this in I2S driver.
Quoted 9 lines
sound/soc/spear/spdif_in.c line 238
Quoted 5 lines
sound/soc/spear/spdif_in.c new file +4
-0+ host->clk =clk_get (&pdev->dev,NULL ); +if (IS_ERR (host->clk)) +return PTR_ERR (host->clk); + pdata =dev_get_platdata (&pdev->dev);Should really be error checking in case you didn't get your platform data.
Agreed,
Quoted 9 lines
sound/soc/spear/spdif_in.c line 251
Quoted 3 lines
sound/soc/spear/spdif_in.c new file +3
-0+ ret =devm_request_irq (&pdev->dev, host->irq, spdif_in_irq,0 , +"spdif-in" , host); +if (ret) {I'm really not enthused about the idea of using
devm_request_irq()here
- what steps are you taking to make sure that the IRQ can't possibly fire after you've started tearing down the device. In general it's relatively hard to usedevm_request_irq()safely.
Disabling interrupt in remove will insure that interrupt will not fire after tearing down the device.
Quoted 4 lines
Quoted 1 line
+#define
SPDIF_IN_DEV_PM_OPSNULLJust remove this if it's unconditionally empty.
OK,
Best Regards
Rajeev
Quoted 3 lines
Quoted 1 line
+static int
__initspdif_in_init(void)
module_platform_driver().
PATCH 5/8 sound:asoc:spdif_out: Add spdif out support
In reply to Rajeev KumarFrom: Vipin Kumar <[email protected]>
This patch implements the spdif out driver for ST peripheral This peripheral implements IEC60958 standard
--- sound/soc/spear/spdif_out.c | 397 ++++++++++++++++++++++++++++++++++++++ sound/soc/spear/spdif_out_regs.h | 79 ++++++++ 2 files changed, 476 insertions(+), 0 deletions(-) create mode 100644 sound/soc/spear/spdif_out.c create mode 100644 sound/soc/spear/spdif_out_regs.h
sound/soc/spear/spdif_out.c new file +397 -0
@@ -0,0 +1,397 @@ +/* +* ALSA SoC SPDIF Out Audio Layer for spear processors +* +* Copyright (C) 2012 ST Microelectronics +* Vipin Kumar <[email protected]> +* +* This file is licensed under the terms of the GNU General Public +* License version 2. This program is licensed "as is" without any +* warranty of any kind, whether express or implied. +*/ + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/export.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/io.h> +#include <linux/ioport.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/spear_dma.h> +#include <sound/soc.h> +#include <mach/spdif.h> +#include "spdif_out_regs.h" + +static int spdif_out_mute; + +struct spdif_out_params { +u32 rate; +u32 core_freq; +}; + +struct spdif_out_dev { +struct clk *clk; +struct dma_data dma_params; +struct spdif_out_params saved_params; +u32 running; +void *io_base; +}; + +static void spdif_out_configure (struct spdif_out_dev *host) +{ +writel (SPDIF_OUT_RESET , host->io_base +SPDIF_OUT_SOFT_RST ); +mdelay (1 ); +writel (readl (host->io_base +SPDIF_OUT_SOFT_RST ) & ~SPDIF_OUT_RESET , + host->io_base +SPDIF_OUT_SOFT_RST ); + +writel (SPDIF_OUT_FDMA_TRIG_16 |SPDIF_OUT_MEMFMT_16_16 | +SPDIF_OUT_VALID_HW |SPDIF_OUT_USER_HW | +SPDIF_OUT_CHNLSTA_HW |SPDIF_OUT_PARITY_HW , + host->io_base +SPDIF_OUT_CFG ); + +writel (0x7F , host->io_base +SPDIF_OUT_INT_STA_CLR ); +writel (0x7F , host->io_base +SPDIF_OUT_INT_EN_CLR ); +} + +static int spdif_out_startup (struct snd_pcm_substream *substream, +struct snd_soc_dai *cpu_dai) +{ +struct spdif_out_dev *host =snd_soc_dai_get_drvdata (cpu_dai); +int ret; + +if (substream->stream !=SNDRV_PCM_STREAM_PLAYBACK ) +return -EINVAL ; + +snd_soc_dai_set_dma_data (cpu_dai, substream, (void *)&host->dma_params); + + ret =clk_enable (host->clk); +if (ret) +return ret; + + host->running = true; +spdif_out_configure (host); + +return 0 ; +} + +static void spdif_out_shutdown (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct spdif_out_dev *host =snd_soc_dai_get_drvdata (dai); + +if (substream->stream !=SNDRV_PCM_STREAM_PLAYBACK ) +return ; + +clk_disable (host->clk); + host->running = false; +snd_soc_dai_set_dma_data (dai, substream,NULL ); +} + +static void spdif_out_clock (struct spdif_out_dev *host,u32 core_freq, +u32 rate) +{ +u32 divider, ctrl; + +clk_set_rate (host->clk, core_freq); + divider =DIV_ROUND_CLOSEST (clk_get_rate (host->clk), (rate *128 )); + + ctrl =readl (host->io_base +SPDIF_OUT_CTRL ); + ctrl &= ~SPDIF_DIVIDER_MASK ; + ctrl |= (divider <<SPDIF_DIVIDER_SHIFT ) &SPDIF_DIVIDER_MASK ; +writel (ctrl, host->io_base +SPDIF_OUT_CTRL ); +} + +static int spdif_out_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params, +struct snd_soc_dai *dai) +{ +struct spdif_out_dev *host =snd_soc_dai_get_drvdata (dai); +u32 rate, core_freq; + +if (substream->stream !=SNDRV_PCM_STREAM_PLAYBACK ) +return -EINVAL ; + + rate =params_rate (params); + +switch (rate) { +case 8000 : +case 16000 : +case 32000 : +case 64000 : +/* +* The clock is multiplied by 10 to bring it to feasible range +* of frequencies for sscg +*/ + core_freq =64000 *128 *10 ;/* 81.92 MHz */ +break ; +case 5512 : +case 11025 : +case 22050 : +case 44100 : +case 88200 : +case 176400 : + core_freq =176400 *128 ;/* 22.5792 MHz */ +break ; +case 48000 : +case 96000 : +case 192000 : +default : + core_freq =192000 *128 ;/* 24.576 MHz */ +break ; + } + +spdif_out_clock (host, core_freq, rate); + host->saved_params.core_freq = core_freq; + host->saved_params.rate = rate; + +return 0 ; +} + +static int spdif_out_trigger (struct snd_pcm_substream *substream,int cmd, +struct snd_soc_dai *dai) +{ +struct spdif_out_dev *host =snd_soc_dai_get_drvdata (dai); +u32 ctrl; +int ret =0 ; + +if (substream->stream !=SNDRV_PCM_STREAM_PLAYBACK ) +return -EINVAL ; + +switch (cmd) { +case SNDRV_PCM_TRIGGER_START : +case SNDRV_PCM_TRIGGER_RESUME : +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : + ctrl =readl (host->io_base +SPDIF_OUT_CTRL ); + ctrl &= ~SPDIF_OPMODE_MASK ; +if (!spdif_out_mute) + ctrl |=SPDIF_OPMODE_AUD_DATA | +SPDIF_STATE_NORMAL ; +else + ctrl |=SPDIF_OPMODE_MUTE_PCM ; +writel (ctrl, host->io_base +SPDIF_OUT_CTRL ); +break ; + +case SNDRV_PCM_TRIGGER_STOP : +case SNDRV_PCM_TRIGGER_SUSPEND : +case SNDRV_PCM_TRIGGER_PAUSE_PUSH : + ctrl =readl (host->io_base +SPDIF_OUT_CTRL ); + ctrl &= ~SPDIF_OPMODE_MASK ; + ctrl |=SPDIF_OPMODE_OFF ; +writel (ctrl, host->io_base +SPDIF_OUT_CTRL ); +break ; + +default : + ret = -EINVAL ; +break ; + } +return ret; +} + +static int spdif_digital_mute (struct snd_soc_dai *dai,int mute) +{ +struct spdif_out_dev *host =snd_soc_dai_get_drvdata (dai); +u32 val; + + spdif_out_mute = mute; + val =readl (host->io_base +SPDIF_OUT_CTRL ); + val &= ~SPDIF_OPMODE_MASK ; + +if (mute) + val |=SPDIF_OPMODE_MUTE_PCM ; +else { +if (host->running) + val |=SPDIF_OPMODE_AUD_DATA |SPDIF_STATE_NORMAL ; +else + val |=SPDIF_OPMODE_OFF ; + } + +writel (val, host->io_base +SPDIF_OUT_CTRL ); +return 0 ; +} + +static int spdif_mute_get (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ + ucontrol->value.integer.value[0 ] = spdif_out_mute; +return 0 ; +} + +static int spdif_mute_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct snd_soc_codec *codec =snd_kcontrol_chip (kcontrol); +struct snd_soc_card *card = codec->card; +struct snd_soc_pcm_runtime *rtd = card->rtd; +struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + +if (spdif_out_mute == ucontrol->value.integer.value[0 ]) +return 0 ; + +spdif_digital_mute (cpu_dai, ucontrol->value.integer.value[0 ]); + +return 1 ; +} +static const struct snd_kcontrol_new spdif_out_controls[] = { +SOC_SINGLE_BOOL_EXT ("SPDIF Play Mute" , (unsigned long )&spdif_out_mute, + spdif_mute_get, spdif_mute_put), +}; + +int spdif_soc_dai_probe (struct snd_soc_dai *dai) +{ +struct snd_soc_card *card = dai->card; +struct snd_soc_pcm_runtime *rtd = card->rtd; +struct snd_soc_codec *codec = rtd->codec; + +return snd_soc_add_controls (codec, spdif_out_controls, +ARRAY_SIZE (spdif_out_controls)); +} + +static struct snd_soc_dai_ops spdif_out_dai_ops = { + .digital_mute = spdif_digital_mute, + .startup = spdif_out_startup, + .shutdown = spdif_out_shutdown, + .trigger = spdif_out_trigger, + .hw_params = spdif_out_hw_params, +}; + +struct snd_soc_dai_driver spdif_out_dai = { + .playback = { + .channels_min =2 , + .channels_max =2 , + .rates = (SNDRV_PCM_RATE_32000 |SNDRV_PCM_RATE_44100 | \ +SNDRV_PCM_RATE_48000 |SNDRV_PCM_RATE_96000 | \ +SNDRV_PCM_RATE_192000 ), + .formats =SNDRV_PCM_FMTBIT_S16_LE , + }, + .probe = spdif_soc_dai_probe, + .ops = (struct snd_soc_dai_ops *)&spdif_out_dai_ops, +}; + +static int spdif_out_probe (struct platform_device *pdev) +{ +struct spdif_out_dev *host; +struct spdif_platform_data *pdata; +struct resource *res; +int ret; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) +return -EINVAL ; + +if (!devm_request_mem_region (&pdev->dev, res->start, +resource_size (res), pdev->name)) { +dev_warn (&pdev->dev,"Failed to get memory resourse\n" ); +return -ENOENT ; + } + + host =devm_kzalloc (&pdev->dev,sizeof (*host),GFP_KERNEL ); +if (!host) { +dev_warn (&pdev->dev,"kzalloc fail\n" ); +return -ENOMEM ; + } + + host->io_base =devm_ioremap (&pdev->dev, res->start, +resource_size (res)); +if (!host->io_base) { +dev_warn (&pdev->dev,"ioremap failed\n" ); +return -ENOMEM ; + } + + host->clk =clk_get (&pdev->dev,NULL ); +if (IS_ERR (host->clk)) +return PTR_ERR (host->clk); + + pdata =dev_get_platdata (&pdev->dev); + + host->dma_params.data = pdata->dma_params; + host->dma_params.addr = res->start +SPDIF_OUT_FIFO_DATA ; + host->dma_params.max_burst =16 ; + host->dma_params.addr_width =DMA_SLAVE_BUSWIDTH_4_BYTES ; + host->dma_params.filter = pdata->filter; + +dev_set_drvdata (&pdev->dev, host); + + ret =snd_soc_register_dai (&pdev->dev, &spdif_out_dai); +if (ret !=0 ) { +clk_put (host->clk); +return ret; + } + +return 0 ; +} + +static int spdif_out_remove (struct platform_device *pdev) +{ +struct spdif_out_dev *host =dev_get_drvdata (&pdev->dev); + +snd_soc_unregister_dai (&pdev->dev); +dev_set_drvdata (&pdev->dev,NULL ); + +clk_put (host->clk); + +return 0 ; +} + +#ifdef CONFIG_PM +static int spdif_out_suspend (struct device *dev) +{ +struct platform_device *pdev =to_platform_device (dev); +struct spdif_out_dev *host =dev_get_drvdata (&pdev->dev); + +if (host->running) +clk_disable (host->clk); + +return 0 ; +} + +static int spdif_out_resume (struct device *dev) +{ +struct platform_device *pdev =to_platform_device (dev); +struct spdif_out_dev *host =dev_get_drvdata (&pdev->dev); + +if (host->running) { +clk_enable (host->clk); +spdif_out_configure (host); +spdif_out_clock (host, host->saved_params.core_freq, + host->saved_params.rate); + } +return 0 ; +} + +static SIMPLE_DEV_PM_OPS(spdif_out_dev_pm_ops, spdif_out_suspend, \ + spdif_out_resume); + +#define SPDIF_OUT_DEV_PM_OPS (&spdif_out_dev_pm_ops) + +#else +#define SPDIF_OUT_DEV_PM_OPS NULL + +#endif + +static struct platform_driver spdif_out_driver = { + .probe = spdif_out_probe, + .remove = spdif_out_remove, + .driver = { + .name ="spdif-out" , + .owner =THIS_MODULE , + .pm =SPDIF_OUT_DEV_PM_OPS , + }, +}; + +static int __init spdif_out_init (void ) +{ +return platform_driver_register (&spdif_out_driver); +} +module_init (spdif_out_init); + +static void __exit spdif_out_exit(void) +{ +platform_driver_unregister (&spdif_out_driver); +} +module_exit (spdif_out_exit); + +MODULE_AUTHOR ("Vipin Kumar <[email protected]>" ); +MODULE_DESCRIPTION ("SPEAr SPDIF OUT SoC Interface" ); +MODULE_LICENSE ("GPL" );
sound/soc/spear/spdif_out_regs.h new file +79 -0
79 lines not on this page · raw message
Signature · 1 line
1.7.2.2
PATCH 6/8 sound:asoc: Add support for SPEAr ASoC machine driver.
In reply to Rajeev KumarThe patch add support for SPEAr ASoC machine driver.
--- sound/soc/spear/spear_evb.c | 278 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 278 insertions(+), 0 deletions(-) create mode 100644 sound/soc/spear/spear_evb.c
sound/soc/spear/spear_evb.c new file +278 -0
@@ -0,0 +1,278 @@ +/* +* ASoC machine driver for SPEAr evaluation boards +* +* sound/soc/spear/spear_evb.c +* +* Copyright (C) 2012 ST Microelectronics +* Rajeev Kumar<[email protected]> +* +* This file is licensed under the terms of the GNU General Public +* License version 2. This program is licensed "as is" without any +* warranty of any kind, whether express or implied. +*/ + +#include <linux/io.h> +#include <linux/platform_device.h> +#include <linux/module.h> + +#include <sound/pcm.h> +#include <sound/pcm_params.h> +#include <sound/soc.h> +#include <mach/hardware.h> +#include <mach/misc_regs.h> + +static int sta529_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_dai *codec_dai = rtd->codec_dai; +int ret =0 ; +u32 channel; + +/* set codec DAI configuration */ + ret =snd_soc_dai_set_fmt (codec_dai,SND_SOC_DAIFMT_I2S | +SND_SOC_DAIFMT_CBS_CFM ); +if (ret <0 ) +return ret; + + channel =params_channels (params); + +if (cpu_is_spear1340 ()) { +#ifdef CONFIG_CPU_SPEAR1340 +u32 mode =0 ; +u32 val =readl (VA_SPEAR1340_PERIP_CFG ); + +switch (channel) { +case 8 : + mode =SPEAR1340_I2S_CHNL_7_1 ; +break ; +case 6 : + mode =SPEAR1340_I2S_CHNL_5_1 ; +break ; +case 4 : + mode =SPEAR1340_I2S_CHNL_3_1 ; +break ; +case 2 : +default : + mode =SPEAR1340_I2S_CHNL_2_0 ; +break ; + } + +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { + mode = mode <<SPEAR1340_I2S_CHNL_PLAY_SHIFT ; + val = (val & ~SPEAR1340_I2S_CHNL_PLAY_MASK ) | mode; + }else { + mode = mode <<SPEAR1340_I2S_CHNL_REC_SHIFT ; + val = (val & ~SPEAR1340_I2S_CHNL_REC_MASK ) | mode; + } +writel (val,VA_SPEAR1340_PERIP_CFG ); +#endif + }else if (cpu_is_spear1300 () ||cpu_is_spear1310_reva () || +cpu_is_spear900 () ||cpu_is_spear1310 ()) { +#if defined(CONFIG_CPU_SPEAR1300 ) || defined(CONFIG_CPU_SPEAR1310_REVA ) || \ + defined(CONFIG_CPU_SPEAR900 ) || defined(CONFIG_CPU_SPEAR1310 ) +/* setting mode 0 in conf register: 32c offset */ +u32 val =readl (VA_PERIP_CFG ); + val &= ~I2S_MODE_MASK ; + val |=I2S_MODE_I2S2_ONE_PORT ; +writel (val,VA_PERIP_CFG ); +#endif + } + +return 0 ; +} + +/* Audio machine driver for SPEAr evb */ +static struct snd_soc_ops sta529_ops = { + .hw_params = sta529_hw_params, +}; + +/* SPEAr audio interface glue - connects codec <--> CPU <--> platform */ +static struct snd_soc_dai_link spear_evb_dai[] = { + { + .name ="sta529-pcm" , + .stream_name ="pcm" , + .cpu_dai_name ="designware-i2s.0" , + .platform_name ="spear-pcm-audio" , + .codec_dai_name ="sta529-audio" , + .codec_name ="sta529-codec.0-001a" , + .ops = &sta529_ops, + }, +}; + +/* SPEAr audio machine driver */ +static struct snd_soc_card spear_snd_card = { + .name ="spear-evb" , + .dai_link = spear_evb_dai, + .num_links =ARRAY_SIZE (spear_evb_dai), +}; + +/* SPEAr320s audio interface glue - connects codec <--> CPU <--> platform */ +static struct snd_soc_dai_link spear320s_evb_dai[] = { + { + .name ="sta529-pcm" , + .stream_name ="pcm" , + .cpu_dai_name ="designware-i2s" , + .platform_name ="spear-pcm-audio" , + .codec_dai_name ="sta529-audio" , + .codec_name ="sta529-codec.0-001a" , + .ops = &sta529_ops, + }, +}; + +/* SPEAr320s audio machine driver */ +static struct snd_soc_card spear320s_snd_card = { + .name ="spear320s-evb" , + .dai_link = spear320s_evb_dai, + .num_links =ARRAY_SIZE (spear320s_evb_dai), +}; + +/* LCAD audio interface glue - connects codec <--> CPU <--> platform */ +static struct snd_soc_dai_link lcad_evb_dai[] = { + { + .name ="sta529-pcm0" , + .stream_name ="I2S Playback" , + .cpu_dai_name ="designware-i2s.0" , + .platform_name ="spear-pcm-audio" , + .codec_dai_name ="sta529-audio" , + .codec_name ="sta529-codec.0-001a" , + .ops = &sta529_ops, + }, { + .name ="sta529-pcm1" , + .stream_name ="I2S Capture" , + .cpu_dai_name ="designware-i2s.1" , + .platform_name ="spear-pcm-audio" , + .codec_dai_name ="sta529-audio" , + .codec_name ="sta529-codec.0-001a" , + .ops = &sta529_ops, + }, +}; + +static struct snd_soc_card lcad_snd_card = { + .name ="lcad-evb" , + .dai_link = lcad_evb_dai, + .num_links =ARRAY_SIZE (lcad_evb_dai), +}; + +/* Audio machine driver for SPEAr1340 evb */ + +/* SPEAr1340 audio interface glue - connects codec <--> CPU <--> platform */ +static struct snd_soc_dai_link spear1340_evb_dai[] = { + { + .name ="spdif-pcm0" , + .stream_name ="SPDIF Playback" , + .cpu_dai_name ="spdif-out" , + .platform_name ="spear-pcm-audio" , + .codec_dai_name ="dit-hifi" , + .codec_name ="spdif-dit" , + .ops =NULL , + }, { + .name ="spdif-pcm1" , + .stream_name ="SPDIF Capture" , + .cpu_dai_name ="spdif-in" , + .platform_name ="spear-pcm-audio" , + .codec_dai_name ="dir-hifi" , + .codec_name ="spdif-dir" , + .ops =NULL , + }, { + .name ="sta529-pcm0" , + .stream_name ="I2S Playback" , + .cpu_dai_name ="designware-i2s.0" , + .platform_name ="spear-pcm-audio" , + .codec_dai_name ="sta529-audio" , + .codec_name ="sta529-codec.0-001a" , + .ops = &sta529_ops, + }, { + .name ="sta529-pcm1" , + .stream_name ="I2S Capture" , + .cpu_dai_name ="designware-i2s.1" , + .platform_name ="spear-pcm-audio" , + .codec_dai_name ="sta529-audio" , + .codec_name ="sta529-codec.0-001a" , + .ops = &sta529_ops, + }, +}; + +static struct snd_soc_card spear1340_snd_card = { + .name ="spear1340-evb" , + .dai_link = spear1340_evb_dai, + .num_links =ARRAY_SIZE (spear1340_evb_dai), +}; + +static struct platform_device *evb_snd_device; +#if defined(CONFIG_CPU_SPEAR1340 ) +static struct platform_device *spdif_dit_device; +static struct platform_device *spdif_dir_device; +#endif + +static int __init spear_audio_init (void ) +{ +int ret; +struct snd_soc_card *spear_soc_card; + +if (machine_is_spear1340_lcad ()) + spear_soc_card = &lcad_snd_card; +else if (cpu_is_spear1340 ()) + spear_soc_card = &spear1340_snd_card; +else if (cpu_is_spear320 ()) + spear_soc_card = &spear320s_snd_card; +else + spear_soc_card = &spear_snd_card; + +#if defined(CONFIG_CPU_SPEAR1340 ) +if (cpu_is_spear1340 ()) { +/* Create and register spdif platform devices */ + spdif_dit_device =platform_device_alloc ("spdif-dit" ,-1 ); +if (!spdif_dit_device) { +printk (KERN_ERR "spdif transceiver " \ +"platform_device_alloc fails\n" ); +return -ENOMEM ; + } + ret =platform_device_add (spdif_dit_device); +if (ret) { +printk (KERN_ERR "Unable to add spdif transceiver " \ +"platform device\n" ); +platform_device_put (spdif_dit_device); + } + + spdif_dir_device =platform_device_alloc ("spdif-dir" ,-1 ); +if (!spdif_dir_device) { +printk (KERN_ERR "spdif receive platform_device_alloc " \ +"fails\n" ); +return -ENOMEM ; + } + ret =platform_device_add (spdif_dir_device); +if (ret) { +printk (KERN_ERR "Unable to add spdif receive platform" \ +"device\n" ); +platform_device_put (spdif_dir_device); + } + } +#endif +/* Create and register platform device */ + evb_snd_device =platform_device_alloc ("soc-audio" ,-1 ); +if (!evb_snd_device) { +printk (KERN_ERR "soc audio platform_device_alloc fails\n" ); +return -ENOMEM ; + } +platform_set_drvdata (evb_snd_device, spear_soc_card); + ret =platform_device_add (evb_snd_device); +if (ret) { +printk (KERN_ERR "Unable to add platform device\n" ); +platform_device_put (evb_snd_device); + } + +return ret; +} +module_init (spear_audio_init); + +static void __exit spear_audio_exit(void) +{ +platform_device_unregister (evb_snd_device); +} +module_exit (spear_audio_exit); + +MODULE_AUTHOR ("Rajeev Kumar <[email protected]>" ); +MODULE_DESCRIPTION ("ST SPEAr EVB ASoC driver" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS ("platform:spear_evb" );
Signature · 1 line
1.7.2.2
Re: [PATCH 6/8] sound:asoc: Add support for SPEAr ASoC machine driver.
Quoted 1 line · Rajeev Kumar
The patch add support for SPEAr ASoC machine driver.
This is the support for some particular board rather than for the SoC.
sound/soc/spear/spear_evb.c line 43
Quoted 4 lines
sound/soc/spear/spear_evb.c new file +4
-0+if (cpu_is_spear1340 ()) { +#ifdef CONFIG_CPU_SPEAR1340 +u32 mode =0 ; +u32 val =readl (VA_SPEAR1340_PERIP_CFG );
Ick, no! This should be in a driver for the SoC somewhere, not in the board. I've not really read most of the rest of the driver.
sound/soc/spear/spear_evb.c line 220
Quoted 13 lines
sound/soc/spear/spear_evb.c new file +13
-0+static int __init spear_audio_init (void ) +{ +int ret; +struct snd_soc_card *spear_soc_card; + +if (machine_is_spear1340_lcad ()) + spear_soc_card = &lcad_snd_card; +else if (cpu_is_spear1340 ()) + spear_soc_card = &spear1340_snd_card; +else if (cpu_is_spear320 ()) + spear_soc_card = &spear320s_snd_card; +else + spear_soc_card = &spear_snd_card;
Use snd_soc_register_card().
sound/soc/spear/spear_evb.c line 230
Quoted 9 lines
sound/soc/spear/spear_evb.c new file +9
-0+#if defined(CONFIG_CPU_SPEAR1340 ) +if (cpu_is_spear1340 ()) { +/* Create and register spdif platform devices */ + spdif_dit_device =platform_device_alloc ("spdif-dit" ,-1 ); +if (!spdif_dit_device) { +printk (KERN_ERR "spdif transceiver " \ +"platform_device_alloc fails\n" ); +return -ENOMEM ; + }
Absolutely no, all this setup of the devices for the SoC should be in your arch/arm code somewhere. This should only be a driver for the board.
PATCH 7/8 sound:asoc: Add Kconfig and Makefile to support SPEAr audio driver
In reply to Rajeev KumarThis patch add Kconfig and Makefile to support SPEAr Audio driver
--- sound/soc/spear/Kconfig | 46 ++++++++++++++++++++++++++++++++++++++++++++++ sound/soc/spear/Makefile | 16 ++++++++++++++++ 2 files changed, 62 insertions(+), 0 deletions(-) create mode 100644 sound/soc/spear/Kconfig create mode 100644 sound/soc/spear/Makefile
sound/soc/spear/Kconfig new file +46 -0
@@ -0,0 +1,46 @@ +config SND_SOC_SPEAR_EVM + tristate "SoC Audio support for SPEAr EVM" + select SND_SOC_DESIGNWARE_I2S + select SND_SOC_STA529 + select SND_SOC_SPEAR_PCM + help + Say Y if you want to add support for SoC audio on SPEAr + platform + +config SND_SOC_SPEAR1340_EVM + tristate "SoC Audio support for SPEAr1340 EVM" + select SND_SOC_DESIGNWARE_I2S + select SND_SOC_STA529 + select SND_SOC_SPEAR_SPDIF_OUT + select SND_SOC_SPEAR_SPDIF_IN + select SND_SOC_SPDIF + select SND_SOC_SPEAR_PCM + help + Say Y if you want to add support for SoC audio on SPEAr1340 + platform + +config SND_SOC_SPEAR_PCM + tristate "SoC Audio for the ST chip" + depends on SND_SOC_DESIGNWARE_I2S || SND_SOC_SPEAR_SPDIF_OUT || \ + SND_SOC_SPEAR_SPDIF_IN + help + Say Y or M if you want to add support for any of the audio + controllers (I2S/SPDIF). You will also need to select + the audio interface codecs to support below. + +config SND_SOC_DESIGNWARE_I2S + tristate "Synopsys I2S Device Driver" + help + Say Y or M if you want to add support for I2S driver for + Synopsys desigwnware I2S device. The device supports upto + maximum of 8 channels each for play, record or both. + +config SND_SOC_SPEAR_SPDIF_OUT + tristate "SPEAr SPDIF Out Device Driver" + help + Say Y or M if you want to add support for SPDIF OUT driver. + +config SND_SOC_SPEAR_SPDIF_IN + tristate "SPEAr SPDIF IN Device Driver" + help + Say Y or M if you want to add support for SPDIF IN driver.
sound/soc/spear/Makefile new file +16 -0
@@ -0,0 +1,16 @@ +# SPEAr Platform Support +snd-soc-pcm-objs := spear_pcm.o +snd-soc-i2s-objs := designware_i2s.o +snd-soc-spdif-in-objs := spdif_in.o +snd-soc-spdif-out-objs := spdif_out.o + +obj-$(CONFIG_SND_SOC_SPEAR_PCM) += snd-soc-pcm.o +obj-$(CONFIG_SND_SOC_DESIGNWARE_I2S) += snd-soc-i2s.o +obj-$(CONFIG_SND_SOC_SPEAR_SPDIF_IN) += snd-soc-spdif-in.o +obj-$(CONFIG_SND_SOC_SPEAR_SPDIF_OUT) += snd-soc-spdif-out.o + +# SPEAr Machine Support +snd-soc-evb-objs := spear_evb.o + +obj-$(CONFIG_SND_SOC_SPEAR_EVM) += snd-soc-evb.o +obj-$(CONFIG_SND_SOC_SPEAR1340_EVM) += snd-soc-evb.o
Signature · 1 line
1.7.2.2
PATCH 8/8 sound:asoc: Update Kconfig and Makefile(sound/soc/) to support SPEAr audio
In reply to Rajeev KumarThis patch update Kconfig and Makefile present in soc directory to support SPEAr.
--- sound/soc/Kconfig | 1 + sound/soc/Makefile | 1 + 2 files changed, 2 insertions(+), 0 deletions(-)
sound/soc/Kconfig +1 -0
@@ -43,6 +43,7 @@ source "sound/soc/pxa/Kconfig" source "sound/soc/samsung/Kconfig" source "sound/soc/s6000/Kconfig" source "sound/soc/sh/Kconfig" +source "sound/soc/spear/Kconfig" source "sound/soc/tegra/Kconfig" source "sound/soc/txx9/Kconfig"
sound/soc/Makefile +1 -0
@@ -20,5 +20,6 @@ obj-$(CONFIG_SND_SOC) += pxa/ obj-$(CONFIG_SND_SOC) += samsung/ obj-$(CONFIG_SND_SOC) += s6000/ obj-$(CONFIG_SND_SOC) += sh/ +obj-$(CONFIG_SND_SOC) += spear/ obj-$(CONFIG_SND_SOC) += tegra/ obj-$(CONFIG_SND_SOC) += txx9/
Signature · 1 line
1.7.2.2