Re: [alsa-devel] [PATCH V2 6/9] Codec for STAC9766 used on the Efika

2009-05-24 Thread Mark Brown
On Sat, May 23, 2009 at 07:13:07PM -0400, Jon Smirl wrote:
 AC97 codec for STAC9766 used on the Efika.
 Datasheet: http://www.idt.com/products/getDoc.cfm?docID=13134007
 
 Signed-off-by: Jon Smirl jonsm...@gmail.com

This looks mostly good, a couple of issues below.  I'll apply the patch
but please submit a followup patch for resume as discussed below.

 +static int ac97_digital_trigger(struct snd_pcm_substream *substream,
 + int cmd, struct 
 snd_soc_dai *dai)

Very strange indentation here...

 +static int stac9766_codec_resume(struct platform_device *pdev)
 +{

 + /* give the codec an AC97 warm reset to start the link */
 +reset:
 + if (reset  5) {
 + printk(KERN_ERR stac9766 failed to resume);
 + return -EIO;
 + }
 + codec-ac97-bus-ops-warm_reset(codec-ac97);
 + id = soc_ac97_ops.read(codec-ac97, AC97_VENDOR_ID2);
 + if (id != 0x4c13) {
 + stac9766_reset(codec, 0);
 + reset++;
 + goto reset;
 + }

As I said last time I'd this looks like it should be using the reset
function that you've provided?  

The loop is new since last time and seems very suspicious - are you sure
that this is a CODEC problem that's being worked around and not an issue
with the AC97 controller or with the specific system starting up the
master clock for the CODEC after resume?  If it's an issue with the
controler then it'd be better to fix it there so that all CODEC drivers
get the benefit.  If it's a CODEC issue a comment explaining the problem
would be helpful since it's not the sort of issue I'd expect to see in a
CODEC.  The fact that it's not needed on initial boot suggests something
controller or external clock related.

Either way, it'd be much clearer to rewrite it using a for or while loop
rather than a goto.  Please submit a followup patch fixing at least this
issue.

 +static int __init stac9766_modinit(void)
 +{
 + return snd_soc_register_dais(stac9766_dai, ARRAY_SIZE(stac9766_dai));
 +}
 +module_init(stac9766_modinit);
 +
 +static void __exit stac9766_exit(void)
 +{
 + snd_soc_unregister_dais(stac9766_dai, ARRAY_SIZE(stac9766_dai));
 +}
 +module_exit(stac9766_exit);

These are not needed for AC97 CODECs, ASoC doesn't wait for them to
probe.  I'll apply a patch removing these.
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


[PATCH V2 6/9] Codec for STAC9766 used on the Efika

2009-05-23 Thread Jon Smirl
AC97 codec for STAC9766 used on the Efika.
Datasheet: http://www.idt.com/products/getDoc.cfm?docID=13134007

Signed-off-by: Jon Smirl jonsm...@gmail.com
---
 0 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 7f78b65..cb07d9b 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -19,6 +19,7 @@ config SND_SOC_ALL_CODECS
select SND_SOC_CS4270 if I2C
select SND_SOC_PCM3008
select SND_SOC_SSM2602 if I2C
+   select SND_SOC_STAC9766 if SND_SOC_AC97_BUS
select SND_SOC_TLV320AIC23 if I2C
select SND_SOC_TLV320AIC26 if SPI_MASTER
select SND_SOC_TLV320AIC3X if I2C
@@ -93,6 +94,9 @@ config SND_SOC_PCM3008
 config SND_SOC_SSM2602
tristate
 
+config SND_SOC_STAC9766
+   tristate
+
 config SND_SOC_TLV320AIC23
tristate
 
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 70c55fa..46c007c 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -7,6 +7,7 @@ snd-soc-cs4270-objs := cs4270.o
 snd-soc-l3-objs := l3.o
 snd-soc-pcm3008-objs := pcm3008.o
 snd-soc-ssm2602-objs := ssm2602.o
+snd-soc-stac9766-objs := stac9766.o
 snd-soc-tlv320aic23-objs := tlv320aic23.o
 snd-soc-tlv320aic26-objs := tlv320aic26.o
 snd-soc-tlv320aic3x-objs := tlv320aic3x.o
@@ -42,6 +43,7 @@ obj-$(CONFIG_SND_SOC_CS4270)  += snd-soc-cs4270.o
 obj-$(CONFIG_SND_SOC_L3)   += snd-soc-l3.o
 obj-$(CONFIG_SND_SOC_PCM3008)  += snd-soc-pcm3008.o
 obj-$(CONFIG_SND_SOC_SSM2602)  += snd-soc-ssm2602.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
 obj-$(CONFIG_SND_SOC_TLV320AIC3X)  += snd-soc-tlv320aic3x.o
diff --git a/sound/soc/codecs/stac9766.c b/sound/soc/codecs/stac9766.c
new file mode 100644
index 000..7740cd5
--- /dev/null
+++ b/sound/soc/codecs/stac9766.c
@@ -0,0 +1,470 @@
+/*
+ * stac9766.c  --  ALSA SoC STAC9766 codec support
+ *
+ * Copyright 2009 Jon Smirl, Digispeaker
+ * Author: Jon Smirl jonsm...@gmail.com
+ *
+ *  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.
+ *
+ *  Features:-
+ *
+ *   o Support for AC97 Codec, S/PDIF
+ */
+
+#include linux/init.h
+#include linux/module.h
+#include linux/device.h
+#include sound/core.h
+#include sound/pcm.h
+#include sound/ac97_codec.h
+#include sound/initval.h
+#include sound/pcm_params.h
+#include sound/soc.h
+#include sound/tlv.h
+#include sound/soc-of-simple.h
+
+#include stac9766.h
+
+#define STAC9766_VERSION 0.10
+
+/*
+ * STAC9766 register cache
+ */
+static const u16 stac9766_reg[] = {
+   0x6A90, 0x8000, 0x8000, 0x8000, /* 6 */
+   0x, 0x, 0x8008, 0x8008, /* e */
+   0x8808, 0x8808, 0x8808, 0x8808, /* 16 */
+   0x8808, 0x, 0x8000, 0x, /* 1e */
+   0x, 0x, 0x, 0x000f, /* 26 */
+   0x0a05, 0x0400, 0xbb80, 0x, /* 2e */
+   0x, 0xbb80, 0x, 0x, /* 36 */
+   0x, 0x2000, 0x, 0x0100, /* 3e */
+   0x, 0x, 0x0080, 0x, /* 46 */
+   0x, 0x, 0x0003, 0x, /* 4e */
+   0x, 0x, 0x, 0x, /* 56 */
+   0x4000, 0x, 0x, 0x, /* 5e */
+   0x1201, 0x, 0x, 0x, /* 66 */
+   0x, 0x, 0x, 0x, /* 6e */
+   0x, 0x, 0x, 0x0006, /* 76 */
+   0x, 0x, 0x, 0x, /* 7e */
+};
+
+static const char *stac9766_record_mux[] = {Mic, CD, Video, AUX, 
Line, Stereo Mix, Mono Mix, Phone};
+static const char *stac9766_mono_mux[] = {Mix, Mic};
+static const char *stac9766_mic_mux[] = {Mic1, Mic2};
+static const char *stac9766_SPDIF_mux[] = {PCM, ADC Record};
+static const char *stac9766_popbypass_mux[] = {Normal, Bypass Mixer};
+static const char *stac9766_record_all_mux[] = {All analog, Analog plus 
DAC};
+static const char *stac9766_boost1[] = {0dB, 10dB};
+static const char *stac9766_boost2[] = {0dB, 20dB};
+static const char *stac9766_stereo_mic[] = {Off, On};
+
+static const struct soc_enum stac9766_record_enum =
+   SOC_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, stac9766_record_mux);
+static const struct soc_enum stac9766_mono_enum =
+   SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 9, 2, stac9766_mono_mux);
+static const struct soc_enum stac9766_mic_enum =
+   SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 8, 2, stac9766_mic_mux);
+static const struct soc_enum stac9766_SPDIF_enum =
+   SOC_ENUM_SINGLE(AC97_STAC_DA_CONTROL, 1, 2, stac9766_SPDIF_mux);
+static const struct soc_enum stac9766_popbypass_enum =
+   SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, stac9766_popbypass_mux);
+static const struct soc_enum stac9766_record_all_enum =
+   SOC_ENUM_SINGLE(AC97_STAC_ANALOG_SPECIAL,