Re: [PATCH 2/5] ASoC: Add HA (HEAD acoustics) DSP codec driver template

2014-04-29 Thread Mark Brown
On Mon, Apr 28, 2014 at 02:17:53PM +0200, Stefan Roese wrote:

 +static int ha_dsp_hw_params(struct snd_pcm_substream *substream,
 + struct snd_pcm_hw_params *params,
 + struct snd_soc_dai *dai)
 +{
 + struct snd_soc_pcm_runtime *rtd = substream-private_data;
 + struct snd_soc_codec *codec = rtd-codec;
 +
 + dev_dbg(codec-dev, Sample format 0x%X\n, params_format(params));
 + dev_dbg(codec-dev, Channels %d\n, params_channels(params));
 + dev_dbg(codec-dev, Rate %d\n, params_rate(params));
 +
 + return 0;
 +}

This doesn't do anything, you should either implement active code here
or remove it (I note that a range of sample rates are supported and the
CODEC can be clock master so I'd expect to see code here).

 + /* codec role */
 + switch (fmt  SND_SOC_DAIFMT_MASTER_MASK) {
 + case SND_SOC_DAIFMT_CBM_CFM:
 + dev_dbg(codec-dev, Codec is master\n);
 + break;
 + case SND_SOC_DAIFMT_CBS_CFS:
 + dev_dbg(codec-dev, Codec is slave\n);
 + break;
 + default:
 + return -EINVAL;
 + }

This isn't doing anything with what it parsed, how does that work?

 +/*
 + * This name/ID is neded to match the DT node for the codec
 + */
 +static const struct i2c_device_id ha_dsp_i2c_id[] = {
 + { ha-dsp-audio, 0 },
 + { }
 +};
 +MODULE_DEVICE_TABLE(i2c, ha_dsp_i2c_id);

This doesn't have any actual part numbers?


signature.asc
Description: Digital signature


[PATCH 2/5] ASoC: Add HA (HEAD acoustics) DSP codec driver template

2014-04-28 Thread Stefan Roese
From: Jarkko Nikula jarkko.nik...@bitmer.com

This codec driver template represents an I2C controlled multichannel audio
codec that has many typical ASoC codec driver features like volume controls,
mixer stages, mux selection, output power control, in-codec audio routings,
codec bias management and DAI link configuration.

Updates from Stefan Roese, 2014-04-28:
Port the HA DSP codec driver to Linux v3.15-rc. This includes
support for DT based probing. No platform-data code is needed
any more, DT nodes are sufficient.

Signed-off-by: Jarkko Nikula jarkko.nik...@bitmer.com
Signed-off-by: Stefan Roese s...@denx.de
Cc: Thorsten Eisbein thorsten.eisb...@head-acoustics.de
---
 sound/soc/codecs/Kconfig  |   4 +
 sound/soc/codecs/Makefile |   2 +
 sound/soc/codecs/ha-dsp.c | 419 ++
 sound/soc/codecs/ha-dsp.h |  50 ++
 4 files changed, 475 insertions(+)
 create mode 100644 sound/soc/codecs/ha-dsp.c
 create mode 100644 sound/soc/codecs/ha-dsp.h

diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index f0e8401..f357988 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -51,6 +51,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_HA_DSP if I2C
select SND_SOC_ISABELLE if I2C
select SND_SOC_JZ4740_CODEC
select SND_SOC_LM4857 if I2C
@@ -343,6 +344,9 @@ config SND_SOC_BT_SCO
 config SND_SOC_DMIC
tristate
 
+config SND_SOC_HA_DSP
+   tristate
+
 config SND_SOC_HDMI_CODEC
tristate HDMI stub CODEC
 
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 3c4d275..f296bec 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -39,6 +39,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-ha-dsp-objs := ha-dsp.o
 snd-soc-isabelle-objs := isabelle.o
 snd-soc-jz4740-codec-objs := jz4740.o
 snd-soc-l3-objs := l3.o
@@ -190,6 +191,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_HA_DSP)   += snd-soc-ha-dsp.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
diff --git a/sound/soc/codecs/ha-dsp.c b/sound/soc/codecs/ha-dsp.c
new file mode 100644
index 000..7cf24dc
--- /dev/null
+++ b/sound/soc/codecs/ha-dsp.c
@@ -0,0 +1,419 @@
+/*
+ * ha-dsp.c  --  HA DSP ALSA SoC Audio driver
+ *
+ * Copyright 2011 Head acoustics GmbH
+ *
+ * Author: Jarkko Nikula jarkko.nik...@bitmer.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include linux/module.h
+#include linux/moduleparam.h
+#include linux/init.h
+#include linux/delay.h
+#include linux/pm.h
+#include linux/i2c.h
+#include linux/platform_device.h
+#include linux/regmap.h
+#include linux/slab.h
+#include sound/core.h
+#include sound/pcm.h
+#include sound/pcm_params.h
+#include sound/soc.h
+#include sound/soc-dapm.h
+#include sound/tlv.h
+#include sound/initval.h
+
+#include ha-dsp.h
+
+/* Reset default register values for soc-cache */
+static const struct reg_default ha_dsp_reg_defaults[] = {
+   { 0x00, 0x00 },
+   { 0x01, 0x55 },
+   { 0x02, 0x55 },
+   { 0x03, 0x00 },
+   { 0x04, 0x00 },
+   { 0x05, 0x00 },
+   { 0x06, 0x00 },
+   { 0x07, 0x00 },
+   { 0x08, 0x02 },
+   { 0x09, 0x02 },
+   { 0x0a, 0x02 },
+   { 0x0b, 0x02 },
+   { 0x0c, 0x02 },
+   { 0x0d, 0x02 },
+   { 0x0e, 0x02 },
+   { 0x0f, 0x02 },
+};
+
+/* DSP mode selection */
+static const char *ha_dsp_mode_texts[] = {Mode 1, Mode 2};
+static SOC_ENUM_SINGLE_DECL(ha_dsp_mode_enum, HA_DSP_CTRL, 0,
+   ha_dsp_mode_texts);
+
+/* Monitor output mux selection */
+static const char *ha_dsp_monitor_texts[] = {Off, ADC, DAC};
+static SOC_ENUM_SINGLE_DECL(ha_dsp_monitor_enum, HA_DSP_CTRL, 1,
+   ha_dsp_monitor_texts);
+
+static const struct snd_kcontrol_new ha_dsp_monitor_control =
+   SOC_DAPM_ENUM(Route, ha_dsp_monitor_enum);
+
+/* Output mixers */
+static const struct snd_kcontrol_new ha_dsp_out1_mixer_controls[] = {
+   SOC_DAPM_SINGLE(DAC Switch, HA_DSP_OUT1_CTRL, 1, 1, 0),
+   SOC_DAPM_SINGLE(IN Bypass Switch, HA_DSP_OUT1_CTRL, 2, 1, 0),
+};
+static const struct snd_kcontrol_new ha_dsp_out2_mixer_controls[] = {
+   SOC_DAPM_SINGLE(DAC Switch, HA_DSP_OUT2_CTRL, 1, 1, 0),
+   SOC_DAPM_SINGLE(IN Bypass Switch, HA_DSP_OUT2_CTRL, 2, 1, 0),
+};
+static const struct snd_kcontrol_new 

Re: [alsa-devel] [PATCH 2/5] ASoC: Add HA (HEAD acoustics) DSP codec driver template

2014-04-28 Thread Lars-Peter Clausen

On 04/28/2014 02:17 PM, Stefan Roese wrote:

From: Jarkko Nikula jarkko.nik...@bitmer.com

This codec driver template represents an I2C controlled multichannel audio
codec that has many typical ASoC codec driver features like volume controls,
mixer stages, mux selection, output power control, in-codec audio routings,
codec bias management and DAI link configuration.

Updates from Stefan Roese, 2014-04-28:
Port the HA DSP codec driver to Linux v3.15-rc. This includes
support for DT based probing. No platform-data code is needed
any more, DT nodes are sufficient.

Signed-off-by: Jarkko Nikula jarkko.nik...@bitmer.com
Signed-off-by: Stefan Roese s...@denx.de
Cc: Thorsten Eisbein thorsten.eisb...@head-acoustics.de


Looks very good. Couple of bits inline.

[...]

+
+#include linux/module.h
+#include linux/moduleparam.h
+#include linux/init.h
+#include linux/delay.h
+#include linux/pm.h
+#include linux/i2c.h
+#include linux/platform_device.h
+#include linux/regmap.h
+#include linux/slab.h
+#include sound/core.h
+#include sound/pcm.h
+#include sound/pcm_params.h
+#include sound/soc.h
+#include sound/soc-dapm.h
+#include sound/tlv.h
+#include sound/initval.h


There seem to be a couple of includes here that are not really needed.


+
+#include ha-dsp.h

[...]

+static const char *ha_dsp_mode_texts[] = {Mode 1, Mode 2};


const char *const


+static SOC_ENUM_SINGLE_DECL(ha_dsp_mode_enum, HA_DSP_CTRL, 0,
+   ha_dsp_mode_texts);
+
+/* Monitor output mux selection */
+static const char *ha_dsp_monitor_texts[] = {Off, ADC, DAC};


const char *const


+static SOC_ENUM_SINGLE_DECL(ha_dsp_monitor_enum, HA_DSP_CTRL, 1,
+   ha_dsp_monitor_texts);
+

[...]

+static const struct snd_soc_dapm_widget ha_dsp_widgets[] = {
+   SND_SOC_DAPM_ADC(ADC, Capture, SND_SOC_NOPM, 0, 0),
+   SND_SOC_DAPM_DAC(DAC, Playback, SND_SOC_NOPM, 0, 0),
+
+   SND_SOC_DAPM_MIXER(OUT1 Mixer, SND_SOC_NOPM, 0, 0,
+  ha_dsp_out1_mixer_controls[0],
+  ARRAY_SIZE(ha_dsp_out1_mixer_controls)),


There is the SOC_MIXER_ARRAY() helper macro that you can use here and below.


+   SND_SOC_DAPM_MIXER(OUT2 Mixer, SND_SOC_NOPM, 0, 0,
+  ha_dsp_out2_mixer_controls[0],
+  ARRAY_SIZE(ha_dsp_out2_mixer_controls)),
+   SND_SOC_DAPM_MIXER(OUT3 Mixer, SND_SOC_NOPM, 0, 0,
+  ha_dsp_out3_mixer_controls[0],
+  ARRAY_SIZE(ha_dsp_out3_mixer_controls)),
+   SND_SOC_DAPM_MIXER(OUT4 Mixer, SND_SOC_NOPM, 0, 0,
+  ha_dsp_out4_mixer_controls[0],
+  ARRAY_SIZE(ha_dsp_out4_mixer_controls)),
+   SND_SOC_DAPM_MIXER(OUT5 Mixer, SND_SOC_NOPM, 0, 0,
+  ha_dsp_out5_mixer_controls[0],
+  ARRAY_SIZE(ha_dsp_out5_mixer_controls)),
+   SND_SOC_DAPM_MIXER(OUT6 Mixer, SND_SOC_NOPM, 0, 0,
+  ha_dsp_out6_mixer_controls[0],
+  ARRAY_SIZE(ha_dsp_out6_mixer_controls)),
+   SND_SOC_DAPM_MIXER(OUT7 Mixer, SND_SOC_NOPM, 0, 0,
+  ha_dsp_out7_mixer_controls[0],
+  ARRAY_SIZE(ha_dsp_out7_mixer_controls)),
+   SND_SOC_DAPM_MIXER(OUT8 Mixer, SND_SOC_NOPM, 0, 0,
+  ha_dsp_out8_mixer_controls[0],
+  ARRAY_SIZE(ha_dsp_out8_mixer_controls)),

[...]

+static int ha_dsp_hw_params(struct snd_pcm_substream *substream,
+   struct snd_pcm_hw_params *params,
+   struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream-private_data;
+   struct snd_soc_codec *codec = rtd-codec;


A codec should never look at the pcm_runtime. The proper way to get a 
pointer to the codec in dai callbacks is dai-codec. Or just use dai-dev below.



+
+   dev_dbg(codec-dev, Sample format 0x%X\n, params_format(params));
+   dev_dbg(codec-dev, Channels %d\n, params_channels(params));
+   dev_dbg(codec-dev, Rate %d\n, params_rate(params));
+
+   return 0;
+}

[...]

+static int ha_dsp_set_bias_level(struct snd_soc_codec *codec,
+enum snd_soc_bias_level level)
+{
+   dev_dbg(codec-dev, Changing bias from %d to %d\n,
+   codec-dapm.bias_level, level);
+
+   switch (level) {
+   case SND_SOC_BIAS_ON:
+   break;
+   case SND_SOC_BIAS_PREPARE:
+   /* Set PLL on */
+   break;
+   case SND_SOC_BIAS_STANDBY:
+   /* Set power on, Set PLL off */
+   break;
+   case SND_SOC_BIAS_OFF:
+   /* Set power down */
+   break;
+   }
+   codec-dapm.bias_level = level;


If you don't do anything in set_bias_level, just don't implement the 
function. The default implementation if no callback is specified is to set 
the bias_level to the requested level.


Re: [PATCH 2/5] ASoC: Add HA (HEAD acoustics) DSP codec driver template

2014-04-28 Thread Jarkko Nikula
Hi Stefan

On 04/28/2014 03:17 PM, Stefan Roese wrote:
 From: Jarkko Nikula jarkko.nik...@bitmer.com
 
 This codec driver template represents an I2C controlled multichannel audio
 codec that has many typical ASoC codec driver features like volume controls,
 mixer stages, mux selection, output power control, in-codec audio routings,
 codec bias management and DAI link configuration.
 
I think it's fair to change authorship to you or Thorsten as this is now
more a real codec driver than implementation template I developed
originally a few years back and you have done porting to newer kernel
and API. Plus taking review commits too :-)

 Updates from Stefan Roese, 2014-04-28:
 Port the HA DSP codec driver to Linux v3.15-rc. This includes
 support for DT based probing. No platform-data code is needed
 any more, DT nodes are sufficient.
 
 Signed-off-by: Jarkko Nikula jarkko.nik...@bitmer.com
 Signed-off-by: Stefan Roese s...@denx.de
 Cc: Thorsten Eisbein thorsten.eisb...@head-acoustics.de
 ---
To me it's fine if you write commit log like it was done by you and say
it's based on early implementation template from me. Or something like that.

 diff --git a/sound/soc/codecs/ha-dsp.c b/sound/soc/codecs/ha-dsp.c
 new file mode 100644
 index 000..7cf24dc
 --- /dev/null
 +++ b/sound/soc/codecs/ha-dsp.c
 @@ -0,0 +1,419 @@
 +/*
 + * ha-dsp.c  --  HA DSP ALSA SoC Audio driver
 + *
 + * Copyright 2011 Head acoustics GmbH
 + *
 + * Author: Jarkko Nikula jarkko.nik...@bitmer.com
 + *
List here also other authors in order to get kudos to you too.

-- 
Jarkko
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html