Title: [9185] trunk/sound/soc: [#6260]ad73311: Add alsa Control for AD73311L
Revision
9185
Author
lliubbo
Date
2010-09-30 03:54:36 -0400 (Thu, 30 Sep 2010)

Log Message

[#6260]ad73311: Add alsa Control for AD73311L

Now ad73311 driver have no alsa control interface.
This commit add it.

Modified Paths

Diff

Modified: trunk/sound/soc/blackfin/Kconfig (9184 => 9185)


--- trunk/sound/soc/blackfin/Kconfig	2010-09-29 21:20:10 UTC (rev 9184)
+++ trunk/sound/soc/blackfin/Kconfig	2010-09-30 07:54:36 UTC (rev 9185)
@@ -33,6 +33,14 @@
 	  Enter the GPIO used to control AD73311's SE pin. Acceptable
 	  values are 0 to 7
 
+config SND_BFIN_AD73311_RESET
+	int "RESET pin for AD73311L Chip Select"
+	depends on SND_BF5XX_SOC_AD73311
+	default 4
+	help
+	  Enter the GPIO used to control AD73311's RESET pin. Acceptable
+	  values are 0 to 7
+
 config SND_AD7XXXX_SELECT
 	int "Select AD73311 or AD74111"
 	depends on SND_SOC_AD73311

Modified: trunk/sound/soc/blackfin/bf5xx-ad73311.c (9184 => 9185)


--- trunk/sound/soc/blackfin/bf5xx-ad73311.c	2010-09-29 21:20:10 UTC (rev 9184)
+++ trunk/sound/soc/blackfin/bf5xx-ad73311.c	2010-09-30 07:54:36 UTC (rev 9185)
@@ -8,6 +8,9 @@
  * Modified:
  *               Copyright 2008 Analog Devices Inc.
  *
+ * Modified:
+ *		 Copyright 2010 Nanakos Chrysostomos <[email protected]>
+ *
  * Bugs:         Enter bugs at http://blackfin.uclinux.org/
  *
  * This program is free software; you can redistribute it and/or modify
@@ -49,6 +52,18 @@
 #include "bf5xx-i2s-pcm.h"
 #include "bf5xx-i2s.h"
 
+/*
+ * Defaults for amixer-settable parameters, adds to fixed values in
+ * snd_ad73311_configure
+ * TODO: later not as global variable
+ */
+struct ad73311_ctrls ad73311 = {
+	.ogain  = 2,
+	.igain  = 2,
+	.rfseen = 1,
+	.srate  = 0,
+};
+
 #if CONFIG_SND_BF5XX_SPORT_NUM == 0
 #define bfin_write_SPORT_TCR1	bfin_write_SPORT0_TCR1
 #define bfin_read_SPORT_TCR1	bfin_read_SPORT0_TCR1
@@ -64,15 +79,24 @@
 #endif
 
 #define GPIO_SE CONFIG_SND_BFIN_AD73311_SE
+#define GPIO_RESET CONFIG_SND_BFIN_AD73311_RESET
 
 static struct snd_soc_card bf5xx_ad73311;
 
+static int snd_ad73311_reset(void)
+{
+	gpio_set_value(GPIO_RESET, 0);
+	udelay(100);
+	gpio_set_value(GPIO_RESET, 1);
+}
+
 static int snd_ad73311_startup(void)
 {
 	pr_debug("%s enter\n", __func__);
 
 	/* Pull up SE pin on AD73311L */
 	gpio_set_value(GPIO_SE, 1);
+	udelay(1);
 	return 0;
 }
 
@@ -84,16 +108,17 @@
 #if CONFIG_SND_AD7XXXX_SELECT == 0
 	/* DMCLK = MCLK = 16.384 MHz
 	 * SCLK = DMCLK/8 = 2.048 MHz
-	 * Sample Rate = DMCLK/2048  = 8 KHz
+	 * Sample Rate = DMCLK/2048  = 8 KHz  (DIRATE)
 	 */
 	ctrl_regs[0] = AD_CONTROL | AD_WRITE | CTRL_REG_B | REGB_MCDIV(0) | \
-			REGB_SCDIV(0) | REGB_DIRATE(0);
+			REGB_SCDIV(0) | REGB_DIRATE(ad73311.srate);
 	ctrl_regs[1] = AD_CONTROL | AD_WRITE | CTRL_REG_C | REGC_PUDEV | \
 			REGC_PUADC | REGC_PUDAC | REGC_PUREF | REGC_REFUSE ;
-	ctrl_regs[2] = AD_CONTROL | AD_WRITE | CTRL_REG_D | REGD_OGS(2) | \
-			REGD_IGS(2);
+	ctrl_regs[2] = AD_CONTROL | AD_WRITE | CTRL_REG_D | \
+			REGD_OGS(ad73311.ogain) | REGD_IGS(ad73311.igain);
 	ctrl_regs[3] = AD_CONTROL | AD_WRITE | CTRL_REG_E | REGE_DA(0x1f);
-	ctrl_regs[4] = AD_CONTROL | AD_WRITE | CTRL_REG_F | REGF_SEEN ;
+	ctrl_regs[4] = AD_CONTROL | AD_WRITE | CTRL_REG_F |
+			(ad73311.rfseen ? REGF_SEEN : 0);
 	ctrl_regs[5] = AD_CONTROL | AD_WRITE | CTRL_REG_A | REGA_MODE_DATA;
 #elif CONFIG_SND_AD7XXXX_SELECT == 1
 	/* MCLK = MCLK = 12.288 MHz
@@ -113,8 +138,8 @@
 	ctrl_regs[6] = AD_WRITE | CTRL_REG_G;
 #endif
 	local_irq_disable();
+	snd_ad73311_reset();
 	snd_ad73311_startup();
-	udelay(1);
 
 	bfin_write_SPORT_TCR1(TFSR);
 	bfin_write_SPORT_TCR2(0xF);
@@ -146,6 +171,11 @@
 	return 0;
 }
 
+int ad73311_reg_config(void)
+{
+	return snd_ad73311_configure();
+}
+
 static int bf5xx_probe(struct platform_device *pdev)
 {
 	int err;
@@ -154,7 +184,15 @@
 		return -EBUSY;
 	}
 
+	if (GPIO_SE != GPIO_RESET)
+		if (gpio_request(GPIO_RESET, "AD73311_RESET")) {
+			printk(KERN_ERR "%s: Failed ro request GPIO_%d\n", __func__, GPIO_RESET);
+			gpio_free(GPIO_SE);
+			return -EBUSY;
+		}
+
 	gpio_direction_output(GPIO_SE, 0);
+	gpio_direction_output(GPIO_RESET, 0);
 
 	err = snd_ad73311_configure();
 	if (err < 0)
@@ -239,7 +277,7 @@
 module_exit(bf5xx_ad73311_exit);
 
 /* Module information */
-MODULE_AUTHOR("Cliff Cai");
+MODULE_AUTHOR("Cliff Cai,Nanakos Chrysostomos");
 MODULE_DESCRIPTION("ALSA SoC AD73311 Blackfin");
 MODULE_LICENSE("GPL");
 

Modified: trunk/sound/soc/codecs/ad73311.c (9184 => 9185)


--- trunk/sound/soc/codecs/ad73311.c	2010-09-29 21:20:10 UTC (rev 9184)
+++ trunk/sound/soc/codecs/ad73311.c	2010-09-30 07:54:36 UTC (rev 9185)
@@ -4,6 +4,8 @@
  * Copyright:	Analog Device Inc.
  * Author:	Cliff Cai <[email protected]>
  *
+ * Modified:    Copyright 2010 Nanakos Chrysostomos <[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
@@ -17,9 +19,9 @@
 #include <linux/device.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
-#include <sound/ac97_codec.h>
 #include <sound/initval.h>
 #include <sound/soc.h>
+#include "ad73311.h"
 
 #if CONFIG_SND_AD7XXXX_SELECT == 0
 #define DRV_NAME "AD73311"
@@ -27,8 +29,105 @@
 #define DRV_NAME "AD74111"
 #endif
 
-#include "ad73311.h"
+#define AD73311_RATES (SNDRV_PCM_RATE_8000  | \
+					SNDRV_PCM_RATE_16000 | \
+					SNDRV_PCM_RATE_32000 | \
+					SNDRV_PCM_RATE_64000)
 
+static int ad73311_ogain_put(struct snd_kcontrol *kcontrol,
+				struct snd_ctl_elem_value *uvalue)
+{
+	if (ad73311.ogain != (7 - uvalue->value.integer.value[0])) {
+		ad73311.ogain = 7 - uvalue->value.integer.value[0];
+		return ad73311_reg_config();
+	}
+	return 0;
+}
+
+static int ad73311_ogain_get(struct snd_kcontrol *kcontrol,
+				struct snd_ctl_elem_value *uvalue)
+{
+	uvalue->value.integer.value[0] =  7 - ad73311.ogain;
+	return 0;
+}
+
+static int ad73311_igain_put(struct snd_kcontrol *kcontrol,
+				struct snd_ctl_elem_value *uvalue)
+{
+	if (ad73311.igain != uvalue->value.integer.value[0]) {
+		ad73311.igain =  uvalue->value.integer.value[0];
+		return ad73311_reg_config();
+	}
+	return 0;
+}
+
+static int ad73311_igain_get(struct snd_kcontrol *kcontrol,
+				struct snd_ctl_elem_value *uvalue)
+{
+	uvalue->value.integer.value[0] = ad73311.igain;
+	return 0;
+}
+
+static int ad73311_rfseen_put(struct snd_kcontrol *kcontrol,
+				struct snd_ctl_elem_value *uvalue)
+{
+	if (ad73311.rfseen != uvalue->value.integer.value[0]) {
+		ad73311.rfseen = uvalue->value.integer.value[0];
+		return ad73311_reg_config();
+	}
+	return 0;
+
+}
+
+static int ad73311_rfseen_get(struct snd_kcontrol *kcontrol,
+				struct snd_ctl_elem_value *uvalue)
+{
+	uvalue->value.integer.value[0] = ad73311.rfseen;
+	return 0;
+}
+
+static int ad73311_srate_put(struct snd_kcontrol *kcontrol,
+				struct snd_ctl_elem_value *uvalue)
+{
+	int tmpvar = 0;
+	if (ad73311.srate != uvalue->value.integer.value[0]) {
+		ad73311.srate = uvalue->value.integer.value[0];
+		switch (ad73311.srate) {
+		case 0:
+			tmpvar = SNDRV_PCM_RATE_8000;
+			break;
+		case 1:
+			tmpvar = SNDRV_PCM_RATE_16000;
+			break;
+		case 2:
+			tmpvar = SNDRV_PCM_RATE_32000;
+			break;
+		case 3:
+			tmpvar = SNDRV_PCM_RATE_64000;
+			break;
+		}
+		ad73311_dai.playback.rates = tmpvar;
+		ad73311_dai.capture.rates = tmpvar;
+		return ad73311_reg_config();
+	}
+	return 0;
+
+}
+
+static int ad73311_srate_get(struct snd_kcontrol *kcontrol,
+				struct snd_ctl_elem_value *uvalue)
+{
+	uvalue->value.integer.value[0] = ad73311.srate;
+	return 0;
+}
+
+static const struct snd_kcontrol_new ad73311_snd_controls[] = {
+	SOC_SINGLE_EXT("IGAIN", 0, 1, 7, 0, ad73311_igain_get, ad73311_igain_put),
+	SOC_SINGLE_EXT("OGAIN", 0, 1, 7, 0, ad73311_ogain_get, ad73311_ogain_put),
+	SOC_SINGLE_BOOL_EXT("SEEN", 0, ad73311_rfseen_get, ad73311_rfseen_put),
+	SOC_SINGLE_EXT("SRATE", 0, 1, 3, 0, ad73311_srate_get, ad73311_srate_put),
+};
+
 struct snd_soc_dai ad73311_dai = {
 	.name = DRV_NAME,
 	.playback = {
@@ -71,6 +170,10 @@
 		printk(KERN_ERR "%s: failed to create pcms\n", DRV_NAME);
 		goto pcm_err;
 	}
+	if (CONFIG_SND_AD7XXXX_SELECT == 0)
+		/* Register alsa controls */
+		snd_soc_add_controls(codec, ad73311_snd_controls,
+					ARRAY_SIZE(ad73311_snd_controls));
 
 	return ret;
 
@@ -111,5 +214,5 @@
 module_exit(ad73311_exit);
 
 MODULE_DESCRIPTION("ASoC ad73311/ad74111 driver");
-MODULE_AUTHOR("Cliff Cai ");
+MODULE_AUTHOR("Cliff Cai, Nanakos Chrysostomos ");
 MODULE_LICENSE("GPL");

Modified: trunk/sound/soc/codecs/ad73311.h (9184 => 9185)


--- trunk/sound/soc/codecs/ad73311.h	2010-09-29 21:20:10 UTC (rev 9184)
+++ trunk/sound/soc/codecs/ad73311.h	2010-09-30 07:54:36 UTC (rev 9185)
@@ -33,6 +33,13 @@
 
 #if CONFIG_SND_AD7XXXX_SELECT == 0
 
+struct ad73311_ctrls {
+	unsigned int ogain:3;
+	unsigned int igain:3;
+	unsigned int rfseen:1;
+	unsigned int srate:2;
+};
+
 #define AD_CONTROL	0x8000
 #define AD_DATA		0x0000
 #define AD_READ		0x4000
@@ -143,4 +150,8 @@
 
 extern struct snd_soc_dai ad73311_dai;
 extern struct snd_soc_codec_device soc_codec_dev_ad73311;
+extern struct ad73311_ctrls ad73311;
+EXPORT_SYMBOL(ad73311);
+extern int ad73311_reg_config(void);
+EXPORT_SYMBOL(ad73311_reg_config);
 #endif
_______________________________________________
Linux-kernel-commits mailing list
[email protected]
https://blackfin.uclinux.org/mailman/listinfo/linux-kernel-commits

Reply via email to