All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] ASoC: Add iPAQ RX1950 sound support
@ 2010-08-28  7:49 Vasily Khoruzhick
  2010-08-28  7:49 ` [PATCH 1/2] ASoC: uda1380: make driver more powersave-friendly Vasily Khoruzhick
  2010-08-28  7:49 ` [PATCH 2/2] ASoC: Add HP iPAQ RX1950 support Vasily Khoruzhick
  0 siblings, 2 replies; 18+ messages in thread
From: Vasily Khoruzhick @ 2010-08-28  7:49 UTC (permalink / raw)
  To: Mark Brown, alsa-devel, Philipp Zabel, Liam Girdwood, Vasily

These two patches are necessary to add sound support for
iPAQ RX1950 PDA, appropriate mach-rx1950.c patch is missing,
as it depends on battery and LEDs patches which are still not
merged nor reviewed.

First patch improves situation with power consumption for uda1380
and also fixes suspend/resume.

Second patch just adds glue driver.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 1/2] ASoC: uda1380: make driver more powersave-friendly
  2010-08-28  7:49 [PATCH 0/2] ASoC: Add iPAQ RX1950 sound support Vasily Khoruzhick
@ 2010-08-28  7:49 ` Vasily Khoruzhick
  2010-08-28  8:56   ` Mark Brown
  2010-08-28  7:49 ` [PATCH 2/2] ASoC: Add HP iPAQ RX1950 support Vasily Khoruzhick
  1 sibling, 1 reply; 18+ messages in thread
From: Vasily Khoruzhick @ 2010-08-28  7:49 UTC (permalink / raw)
  To: Mark Brown, alsa-devel, Philipp Zabel, Liam Girdwood; +Cc: Vasily Khoruzhick

Disable some codec modules in standby mode, completely disable
codec in off mode to save some power.
Fix suspend/resume: mark mixer regs as dirty on resume to
restore mixer values, otherwise driver produces no sound
(master is muted by default).

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
---
 sound/soc/codecs/uda1380.c |  135 +++++++++++++++++++++++++++++++------------
 1 files changed, 97 insertions(+), 38 deletions(-)

diff --git a/sound/soc/codecs/uda1380.c b/sound/soc/codecs/uda1380.c
index 2f925a2..c53514b 100644
--- a/sound/soc/codecs/uda1380.c
+++ b/sound/soc/codecs/uda1380.c
@@ -131,7 +131,52 @@ static int uda1380_write(struct snd_soc_codec *codec, unsigned int reg,
 		return -EIO;
 }
 
-#define uda1380_reset(c)	uda1380_write(c, UDA1380_RESET, 0)
+static void uda1380_sync_cache(struct snd_soc_codec *codec)
+{
+	int reg;
+	u8 data[3];
+	u16 *cache = codec->reg_cache;
+
+	/* Sync reg_cache with the hardware */
+	for (reg = 0; reg < UDA1380_MVOL; reg++) {
+		data[0] = reg;
+		data[1] = (cache[reg] & 0xff00) >> 8;
+		data[2] = cache[reg] & 0x00ff;
+		if (codec->hw_write(codec->control_data, data, 3) != 3)
+			dev_err(codec->dev, "%s: write to reg 0x%x failed\n",
+				__func__, reg);
+	}
+
+	/* Make mixer regs as dirty, they can be modified only
+	 * when i2s clock is applied.
+	 */
+	for (reg = UDA1380_MVOL; reg < UDA1380_CACHEREGNUM; reg++)
+		set_bit(reg - 0x10, &uda1380_cache_dirty);
+}
+
+static int uda1380_reset(struct snd_soc_codec *codec)
+{
+	struct uda1380_platform_data *pdata = codec->dev->platform_data;
+
+	if (pdata->gpio_reset != -EINVAL) {
+		gpio_set_value(pdata->gpio_reset, 1);
+		mdelay(1);
+		gpio_set_value(pdata->gpio_reset, 0);
+	} else {
+		u8 data[3];
+
+		data[0] = UDA1380_RESET;
+		data[1] = 0;
+		data[2] = 0;
+
+		if (codec->hw_write(codec->control_data, data, 3) != 3) {
+			dev_err(codec->dev, "%s: failed\n", __func__);
+			return -EIO;
+		}
+	}
+
+	return 0;
+}
 
 static void uda1380_flush_work(struct work_struct *work)
 {
@@ -562,17 +607,31 @@ static int uda1380_set_bias_level(struct snd_soc_codec *codec,
 	enum snd_soc_bias_level level)
 {
 	int pm = uda1380_read_reg_cache(codec, UDA1380_PM);
+	struct uda1380_platform_data *pdata = codec->dev->platform_data;
+
+	if (codec->bias_level == level)
+		return 0;
 
 	switch (level) {
 	case SND_SOC_BIAS_ON:
 	case SND_SOC_BIAS_PREPARE:
+		/* ADC, DAC on */
 		uda1380_write(codec, UDA1380_PM, R02_PON_BIAS | pm);
 		break;
 	case SND_SOC_BIAS_STANDBY:
-		uda1380_write(codec, UDA1380_PM, R02_PON_BIAS);
+		if (codec->bias_level == SND_SOC_BIAS_OFF) {
+			if (pdata->gpio_power != -EINVAL) {
+				gpio_set_value(pdata->gpio_power, 1);
+				uda1380_reset(codec);
+			}
+
+			uda1380_sync_cache(codec);
+		}
+		uda1380_write(codec, UDA1380_PM, 0x0);
 		break;
 	case SND_SOC_BIAS_OFF:
-		uda1380_write(codec, UDA1380_PM, 0x0);
+		if (pdata->gpio_power != -EINVAL)
+			gpio_set_value(pdata->gpio_power, 0);
 		break;
 	}
 	codec->bias_level = level;
@@ -659,16 +718,7 @@ static int uda1380_resume(struct platform_device *pdev)
 {
 	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
 	struct snd_soc_codec *codec = socdev->card->codec;
-	int i;
-	u8 data[2];
-	u16 *cache = codec->reg_cache;
 
-	/* Sync reg_cache with the hardware */
-	for (i = 0; i < ARRAY_SIZE(uda1380_reg); i++) {
-		data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
-		data[1] = cache[i] & 0x00ff;
-		codec->hw_write(codec->control_data, data, 2);
-	}
 	uda1380_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 	return 0;
 }
@@ -698,16 +748,18 @@ static int uda1380_probe(struct platform_device *pdev)
 
 	/* power on device */
 	uda1380_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-	/* set clock input */
+
 	switch (pdata->dac_clk) {
 	case UDA1380_DAC_CLK_SYSCLK:
-		uda1380_write(codec, UDA1380_CLK, 0);
+		uda1380_write_reg_cache(codec, UDA1380_CLK, 0);
 		break;
 	case UDA1380_DAC_CLK_WSPLL:
-		uda1380_write(codec, UDA1380_CLK, R00_DAC_CLK);
+		uda1380_write_reg_cache(codec, UDA1380_CLK,
+			R00_DAC_CLK);
 		break;
 	}
 
+
 	snd_soc_add_controls(codec, uda1380_snd_controls,
 				ARRAY_SIZE(uda1380_snd_controls));
 	uda1380_add_widgets(codec);
@@ -752,22 +804,22 @@ static int uda1380_register(struct uda1380_priv *uda1380)
 		return -EINVAL;
 	}
 
-	if (!pdata || !pdata->gpio_power || !pdata->gpio_reset)
+	if (!pdata)
 		return -EINVAL;
 
-	ret = gpio_request(pdata->gpio_power, "uda1380 power");
-	if (ret)
-		goto err_out;
-	ret = gpio_request(pdata->gpio_reset, "uda1380 reset");
-	if (ret)
-		goto err_gpio;
-
-	gpio_direction_output(pdata->gpio_power, 1);
+	if (pdata->gpio_power != -EINVAL) {
+		ret = gpio_request(pdata->gpio_power, "uda1380 power");
+		if (ret)
+			goto err_out;
+		gpio_direction_output(pdata->gpio_power, 0);
+	}
 
-	/* we may need to have the clock running here - pH5 */
-	gpio_direction_output(pdata->gpio_reset, 1);
-	udelay(5);
-	gpio_set_value(pdata->gpio_reset, 0);
+	if (pdata->gpio_reset != -EINVAL) {
+		ret = gpio_request(pdata->gpio_reset, "uda1380 reset");
+		if (ret)
+			goto err_gpio;
+		gpio_direction_output(pdata->gpio_reset, 0);
+	}
 
 	mutex_init(&codec->mutex);
 	INIT_LIST_HEAD(&codec->dapm_widgets);
@@ -788,10 +840,12 @@ static int uda1380_register(struct uda1380_priv *uda1380)
 
 	memcpy(codec->reg_cache, uda1380_reg, sizeof(uda1380_reg));
 
-	ret = uda1380_reset(codec);
-	if (ret < 0) {
-		dev_err(codec->dev, "Failed to issue reset\n");
-		goto err_reset;
+	if (pdata->gpio_power == -EINVAL) {
+		ret = uda1380_reset(codec);
+		if (ret < 0) {
+			dev_err(codec->dev, "Failed to issue reset\n");
+			goto err_reset;
+		}
 	}
 
 	INIT_WORK(&uda1380->work, uda1380_flush_work);
@@ -818,10 +872,11 @@ static int uda1380_register(struct uda1380_priv *uda1380)
 err_dai:
 	snd_soc_unregister_codec(codec);
 err_reset:
-	gpio_set_value(pdata->gpio_power, 0);
-	gpio_free(pdata->gpio_reset);
+	if (pdata->gpio_reset != -EINVAL)
+		gpio_free(pdata->gpio_reset);
 err_gpio:
-	gpio_free(pdata->gpio_power);
+	if (pdata->gpio_power != -EINVAL)
+		gpio_free(pdata->gpio_power);
 err_out:
 	return ret;
 }
@@ -834,9 +889,13 @@ static void uda1380_unregister(struct uda1380_priv *uda1380)
 	snd_soc_unregister_dais(uda1380_dai, ARRAY_SIZE(uda1380_dai));
 	snd_soc_unregister_codec(&uda1380->codec);
 
-	gpio_set_value(pdata->gpio_power, 0);
-	gpio_free(pdata->gpio_reset);
-	gpio_free(pdata->gpio_power);
+	if (pdata->gpio_power != -EINVAL) {
+		gpio_set_value(pdata->gpio_power, 0);
+		gpio_free(pdata->gpio_power);
+	}
+
+	if (pdata->gpio_reset != -EINVAL)
+		gpio_free(pdata->gpio_reset);
 
 	kfree(uda1380);
 	uda1380_codec = NULL;
-- 
1.7.2

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 2/2] ASoC: Add HP iPAQ RX1950 support
  2010-08-28  7:49 [PATCH 0/2] ASoC: Add iPAQ RX1950 sound support Vasily Khoruzhick
  2010-08-28  7:49 ` [PATCH 1/2] ASoC: uda1380: make driver more powersave-friendly Vasily Khoruzhick
@ 2010-08-28  7:49 ` Vasily Khoruzhick
  2010-08-28  8:31   ` Vasily Khoruzhick
  2010-08-28  8:37   ` [PATCH v2 " Vasily Khoruzhick
  1 sibling, 2 replies; 18+ messages in thread
From: Vasily Khoruzhick @ 2010-08-28  7:49 UTC (permalink / raw)
  To: Mark Brown, alsa-devel, Philipp Zabel, Liam Girdwood; +Cc: Vasily Khoruzhick

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
---
 sound/soc/s3c24xx/Kconfig          |    8 +
 sound/soc/s3c24xx/Makefile         |    2 +
 sound/soc/s3c24xx/rx1950_uda1380.c |  312 ++++++++++++++++++++++++++++++++++++
 3 files changed, 322 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/s3c24xx/rx1950_uda1380.c

diff --git a/sound/soc/s3c24xx/Kconfig b/sound/soc/s3c24xx/Kconfig
index 213963ac..66231fd 100644
--- a/sound/soc/s3c24xx/Kconfig
+++ b/sound/soc/s3c24xx/Kconfig
@@ -118,6 +118,14 @@ config SND_S3C24XX_SOC_SIMTEC_HERMES
 	select SND_SOC_TLV320AIC3X
 	select SND_S3C24XX_SOC_SIMTEC
 
+config SND_S3C24XX_SOC_RX1950_UDA1380
+	tristate "Audio support for the HP iPAQ RX1950"
+	depends on SND_S3C24XX_SOC && MACH_RX1950
+	select SND_S3C24XX_SOC_I2S
+	select SND_SOC_UDA1380
+	help
+	  This driver provides audio support for HP iPAQ RX1950 PDA.
+
 config SND_SOC_SMDK_WM9713
 	tristate "SoC AC97 Audio support for SMDK with WM9713"
 	depends on SND_S3C24XX_SOC && (MACH_SMDK6410 || MACH_SMDKC100 || MACH_SMDKV210 || MACH_SMDKC110)
diff --git a/sound/soc/s3c24xx/Makefile b/sound/soc/s3c24xx/Makefile
index 50172c3..8c54a15 100644
--- a/sound/soc/s3c24xx/Makefile
+++ b/sound/soc/s3c24xx/Makefile
@@ -27,6 +27,7 @@ snd-soc-s3c24xx-uda134x-objs := s3c24xx_uda134x.o
 snd-soc-s3c24xx-simtec-objs := s3c24xx_simtec.o
 snd-soc-s3c24xx-simtec-hermes-objs := s3c24xx_simtec_hermes.o
 snd-soc-s3c24xx-simtec-tlv320aic23-objs := s3c24xx_simtec_tlv320aic23.o
+snd-soc-rx1950-uda1380-objs := rx1950_uda1380.o
 snd-soc-smdk64xx-wm8580-objs := smdk64xx_wm8580.o
 snd-soc-smdk-wm9713-objs := smdk_wm9713.o
 snd-soc-s3c64xx-smartq-wm8987-objs := smartq_wm8987.o
@@ -40,6 +41,7 @@ obj-$(CONFIG_SND_S3C24XX_SOC_S3C24XX_UDA134X) += snd-soc-s3c24xx-uda134x.o
 obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC) += snd-soc-s3c24xx-simtec.o
 obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC_HERMES) += snd-soc-s3c24xx-simtec-hermes.o
 obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC_TLV320AIC23) += snd-soc-s3c24xx-simtec-tlv320aic23.o
+obj-$(CONFIG_SND_S3C24XX_SOC_RX1950_UDA1380) += snd-soc-rx1950-uda1380.o
 obj-$(CONFIG_SND_S3C64XX_SOC_WM8580) += snd-soc-smdk64xx-wm8580.o
 obj-$(CONFIG_SND_SOC_SMDK_WM9713) += snd-soc-smdk-wm9713.o
 obj-$(CONFIG_SND_S3C64XX_SOC_SMARTQ) += snd-soc-s3c64xx-smartq-wm8987.o
diff --git a/sound/soc/s3c24xx/rx1950_uda1380.c b/sound/soc/s3c24xx/rx1950_uda1380.c
new file mode 100644
index 0000000..f80700f
--- /dev/null
+++ b/sound/soc/s3c24xx/rx1950_uda1380.c
@@ -0,0 +1,312 @@
+/*
+ * rx1950.c  --  ALSA Soc Audio Layer
+ *
+ * Copyright (c) 2010 Vasily Khoruzhick <anarsoul@gmail.com>
+ *
+ * Based on smdk2440.c and magician.c
+ *
+ * Authors: Graeme Gregory graeme.gregory@wolfsonmicro.com
+ *          Philipp Zabel <philipp.zabel@gmail.com>
+ *          Denis Grigoriev <dgreenday@gmail.com>
+ *          Vasily Khoruzhick <anarsoul@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.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/timer.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/spinlock.h>
+#include <linux/i2c.h>
+#include <linux/gpio.h>
+#include <linux/clk.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/uda1380.h>
+#include <sound/jack.h>
+
+#include <plat/regs-iis.h>
+
+#include <mach/regs-clock.h>
+
+#include "s3c-dma.h"
+#include "s3c24xx-i2s.h"
+#include "../codecs/uda1380.h"
+
+static int rx1950_uda1380_init(struct snd_soc_codec *codec);
+static int rx1950_startup(struct snd_pcm_substream *substream);
+static int rx1950_hw_params(struct snd_pcm_substream *substream,
+				struct snd_pcm_hw_params *params);
+static int rx1950_spk_power(struct snd_soc_dapm_widget *w,
+				struct snd_kcontrol *kcontrol, int event);
+
+static unsigned int rates[] = {
+	16000,
+	44100,
+	48000,
+	88200,
+};
+
+static struct snd_pcm_hw_constraint_list hw_rates = {
+	.count = ARRAY_SIZE(rates),
+	.list = rates,
+	.mask = 0,
+};
+
+static struct snd_soc_jack hp_jack;
+
+static struct snd_soc_jack_pin hp_jack_pins[] = {
+	{
+		.pin	= "Headphone Jack",
+		.mask	= SND_JACK_HEADPHONE,
+	},
+	{
+		.pin	= "Speaker",
+		.mask	= SND_JACK_HEADPHONE,
+		.invert	= 1,
+	},
+};
+
+static struct snd_soc_jack_gpio hp_jack_gpios[] = {
+	[0] = {
+		.gpio			= S3C2410_GPG(12),
+		.name			= "hp-gpio",
+		.report			= SND_JACK_HEADPHONE,
+		.invert			= 1,
+		.debounce_time		= 200,
+	},
+};
+
+static struct snd_soc_ops rx1950_ops = {
+	.startup	= rx1950_startup,
+	.hw_params	= rx1950_hw_params,
+};
+
+/* s3c24xx digital audio interface glue - connects codec <--> CPU */
+static struct snd_soc_dai_link rx1950_uda1380_dai[] = {
+	{
+		.name		= "uda1380",
+		.stream_name	= "UDA1380",
+		.cpu_dai	= &s3c24xx_i2s_dai,
+		.codec_dai	= &uda1380_dai[UDA1380_DAI_DUPLEX],
+		.init		= rx1950_uda1380_init,
+		.ops		= &rx1950_ops,
+	},
+};
+
+static struct snd_soc_card rx1950_asoc = {
+	.name = "rx1950",
+	.platform = &s3c24xx_soc_platform,
+	.dai_link = rx1950_uda1380_dai,
+	.num_links = ARRAY_SIZE(rx1950_uda1380_dai),
+};
+
+/* s3c24xx audio subsystem */
+static struct snd_soc_device s3c24xx_snd_devdata = {
+	.card		= &rx1950_asoc,
+	.codec_dev	= &soc_codec_dev_uda1380,
+};
+
+/* rx1950 machine dapm widgets */
+static const struct snd_soc_dapm_widget uda1380_dapm_widgets[] = {
+	SND_SOC_DAPM_HP("Headphone Jack", NULL),
+	SND_SOC_DAPM_MIC("Mic Jack", NULL),
+	SND_SOC_DAPM_SPK("Speaker", rx1950_spk_power),
+};
+
+/* rx1950 machine audio_map */
+static const struct snd_soc_dapm_route audio_map[] = {
+	/* headphone connected to VOUTLHP, VOUTRHP */
+	{"Headphone Jack", NULL, "VOUTLHP"},
+	{"Headphone Jack", NULL, "VOUTRHP"},
+
+	/* ext speaker connected to VOUTL, VOUTR  */
+	{"Speaker", NULL, "VOUTL"},
+	{"Speaker", NULL, "VOUTR"},
+
+	/* mic is connected to VINM */
+	{"VINM", NULL, "Mic Jack"},
+};
+
+static struct platform_device *s3c24xx_snd_device;
+static struct clk *xtal;
+
+static int rx1950_startup(struct snd_pcm_substream *substream)
+{
+	struct snd_pcm_runtime *runtime = substream->runtime;
+
+	runtime->hw.rate_min = hw_rates.list[0];
+	runtime->hw.rate_max = hw_rates.list[hw_rates.count - 1];
+	runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
+
+	return snd_pcm_hw_constraint_list(runtime, 0,
+					SNDRV_PCM_HW_PARAM_RATE,
+					&hw_rates);
+}
+
+static int rx1950_spk_power(struct snd_soc_dapm_widget *w,
+				struct snd_kcontrol *kcontrol, int event)
+{
+	if (SND_SOC_DAPM_EVENT_ON(event))
+		gpio_direction_output(S3C2410_GPA(1), 1);
+	else
+		gpio_direction_output(S3C2410_GPA(1), 0);
+
+	return 0;
+}
+
+static int rx1950_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 *cpu_dai = rtd->dai->cpu_dai;
+	struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
+	int div;
+	int ret;
+	unsigned int rate = params_rate(params);
+	int clk_source, fs_mode;
+
+	switch (rate) {
+	case 16000:
+	case 48000:
+		clk_source = S3C24XX_CLKSRC_PCLK;
+		fs_mode = S3C2410_IISMOD_384FS;
+		div = s3c24xx_i2s_get_clockrate() / (384 * rate);
+		if (s3c24xx_i2s_get_clockrate() % (384 * rate) > (182 * rate))
+			div++;
+		break;
+	case 44100:
+	case 88200:
+		clk_source = S3C24XX_CLKSRC_MPLL;
+		fs_mode = S3C2410_IISMOD_256FS;
+		div = clk_get_rate(xtal) / (256 * rate);
+		if (clk_get_rate(xtal) % (256 * rate) > (128 * rate))
+			div++;
+		break;
+	default:
+		printk(KERN_ERR "%s: rate %d is not supported\n",
+			__func__, rate);
+		return -EINVAL;
+	}
+
+	/* set codec DAI configuration */
+	ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
+		SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
+	if (ret < 0)
+		return ret;
+
+	/* set cpu DAI configuration */
+	ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
+		SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
+	if (ret < 0)
+		return ret;
+
+	/* select clock source */
+	ret = snd_soc_dai_set_sysclk(cpu_dai, clk_source, rate,
+			SND_SOC_CLOCK_OUT);
+	if (ret < 0)
+		return ret;
+
+	/* set MCLK division for sample rate */
+	ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
+		S3C2410_IISMOD_384FS);
+	if (ret < 0)
+		return ret;
+
+	/* set BCLK division for sample rate */
+	ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_BCLK,
+		S3C2410_IISMOD_32FS);
+	if (ret < 0)
+		return ret;
+
+	/* set prescaler division for sample rate */
+	ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
+		S3C24XX_PRESCALE(div, div));
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static int rx1950_uda1380_init(struct snd_soc_codec *codec)
+{
+	int err;
+
+	/* Add rx1950 specific widgets */
+	snd_soc_dapm_new_controls(codec, uda1380_dapm_widgets,
+				  ARRAY_SIZE(uda1380_dapm_widgets));
+
+	/* Set up rx1950 specific audio path audio_mapnects */
+	err = snd_soc_dapm_add_routes(codec, audio_map,
+				      ARRAY_SIZE(audio_map));
+
+	snd_soc_dapm_enable_pin(codec, "Headphone Jack");
+	snd_soc_dapm_enable_pin(codec, "Speaker");
+
+	snd_soc_dapm_sync(codec);
+
+	snd_soc_jack_new(&rx1950_asoc, "Headphone Jack", SND_JACK_HEADPHONE,
+		&hp_jack);
+
+	snd_soc_jack_add_pins(&hp_jack, ARRAY_SIZE(hp_jack_pins),
+		hp_jack_pins);
+
+	snd_soc_jack_add_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
+		hp_jack_gpios);
+
+	return 0;
+}
+
+static int __init rx1950_init(void)
+{
+	int ret;
+
+	/* configure some gpios */
+	gpio_request(S3C2410_GPA(1), "speaker-power");
+	gpio_direction_output(S3C2410_GPA(1), 0);
+
+	s3c24xx_snd_device = platform_device_alloc("soc-audio", -1);
+	if (!s3c24xx_snd_device) {
+		printk(KERN_ERR "platform_dev_alloc failed\n");
+		return -ENOMEM;
+	}
+
+	platform_set_drvdata(s3c24xx_snd_device, &s3c24xx_snd_devdata);
+	s3c24xx_snd_devdata.dev = &s3c24xx_snd_device->dev;
+	ret = platform_device_add(s3c24xx_snd_device);
+
+	if (ret)
+		platform_device_put(s3c24xx_snd_device);
+
+	xtal = clk_get(&s3c24xx_snd_device->dev, "xtal");
+
+	return ret;
+}
+
+static void __exit rx1950_exit(void)
+{
+	platform_device_unregister(s3c24xx_snd_device);
+	snd_soc_jack_free_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
+		hp_jack_gpios);
+	clk_put(xtal);
+	gpio_free(S3C2410_GPA(1));
+}
+
+module_init(rx1950_init);
+module_exit(rx1950_exit);
+
+/* Module information */
+MODULE_AUTHOR("Vasily Khoruzhick");
+MODULE_DESCRIPTION("ALSA SoC RX1950");
+MODULE_LICENSE("GPL");
-- 
1.7.2

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 2/2] ASoC: Add HP iPAQ RX1950 support
  2010-08-28  7:49 ` [PATCH 2/2] ASoC: Add HP iPAQ RX1950 support Vasily Khoruzhick
@ 2010-08-28  8:31   ` Vasily Khoruzhick
  2010-08-28  8:37   ` [PATCH v2 " Vasily Khoruzhick
  1 sibling, 0 replies; 18+ messages in thread
From: Vasily Khoruzhick @ 2010-08-28  8:31 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Philipp Zabel, Liam Girdwood


[-- Attachment #1.1: Type: Text/Plain, Size: 222 bytes --]

В сообщении от 28 августа 2010 10:49:36 автор Vasily Khoruzhick написал:
> Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>

Ooops, sent wrong version of this patch, will resend it soon

[-- Attachment #1.2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v2 2/2] ASoC: Add HP iPAQ RX1950 support
  2010-08-28  7:49 ` [PATCH 2/2] ASoC: Add HP iPAQ RX1950 support Vasily Khoruzhick
  2010-08-28  8:31   ` Vasily Khoruzhick
@ 2010-08-28  8:37   ` Vasily Khoruzhick
  2010-08-28  8:46     ` Vasily Khoruzhick
  2010-08-28  8:54     ` [PATCH v3 " Vasily Khoruzhick
  1 sibling, 2 replies; 18+ messages in thread
From: Vasily Khoruzhick @ 2010-08-28  8:37 UTC (permalink / raw)
  To: Mark Brown, alsa-devel, Philipp Zabel, Liam Girdwood; +Cc: Vasily Khoruzhick

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
---
 sound/soc/s3c24xx/Kconfig          |    8 +
 sound/soc/s3c24xx/Makefile         |    2 +
 sound/soc/s3c24xx/rx1950_uda1380.c |  330 ++++++++++++++++++++++++++++++++++++
 3 files changed, 340 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/s3c24xx/rx1950_uda1380.c

diff --git a/sound/soc/s3c24xx/Kconfig b/sound/soc/s3c24xx/Kconfig
index 213963ac..66231fd 100644
--- a/sound/soc/s3c24xx/Kconfig
+++ b/sound/soc/s3c24xx/Kconfig
@@ -118,6 +118,14 @@ config SND_S3C24XX_SOC_SIMTEC_HERMES
 	select SND_SOC_TLV320AIC3X
 	select SND_S3C24XX_SOC_SIMTEC
 
+config SND_S3C24XX_SOC_RX1950_UDA1380
+	tristate "Audio support for the HP iPAQ RX1950"
+	depends on SND_S3C24XX_SOC && MACH_RX1950
+	select SND_S3C24XX_SOC_I2S
+	select SND_SOC_UDA1380
+	help
+	  This driver provides audio support for HP iPAQ RX1950 PDA.
+
 config SND_SOC_SMDK_WM9713
 	tristate "SoC AC97 Audio support for SMDK with WM9713"
 	depends on SND_S3C24XX_SOC && (MACH_SMDK6410 || MACH_SMDKC100 || MACH_SMDKV210 || MACH_SMDKC110)
diff --git a/sound/soc/s3c24xx/Makefile b/sound/soc/s3c24xx/Makefile
index 50172c3..8c54a15 100644
--- a/sound/soc/s3c24xx/Makefile
+++ b/sound/soc/s3c24xx/Makefile
@@ -27,6 +27,7 @@ snd-soc-s3c24xx-uda134x-objs := s3c24xx_uda134x.o
 snd-soc-s3c24xx-simtec-objs := s3c24xx_simtec.o
 snd-soc-s3c24xx-simtec-hermes-objs := s3c24xx_simtec_hermes.o
 snd-soc-s3c24xx-simtec-tlv320aic23-objs := s3c24xx_simtec_tlv320aic23.o
+snd-soc-rx1950-uda1380-objs := rx1950_uda1380.o
 snd-soc-smdk64xx-wm8580-objs := smdk64xx_wm8580.o
 snd-soc-smdk-wm9713-objs := smdk_wm9713.o
 snd-soc-s3c64xx-smartq-wm8987-objs := smartq_wm8987.o
@@ -40,6 +41,7 @@ obj-$(CONFIG_SND_S3C24XX_SOC_S3C24XX_UDA134X) += snd-soc-s3c24xx-uda134x.o
 obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC) += snd-soc-s3c24xx-simtec.o
 obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC_HERMES) += snd-soc-s3c24xx-simtec-hermes.o
 obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC_TLV320AIC23) += snd-soc-s3c24xx-simtec-tlv320aic23.o
+obj-$(CONFIG_SND_S3C24XX_SOC_RX1950_UDA1380) += snd-soc-rx1950-uda1380.o
 obj-$(CONFIG_SND_S3C64XX_SOC_WM8580) += snd-soc-smdk64xx-wm8580.o
 obj-$(CONFIG_SND_SOC_SMDK_WM9713) += snd-soc-smdk-wm9713.o
 obj-$(CONFIG_SND_S3C64XX_SOC_SMARTQ) += snd-soc-s3c64xx-smartq-wm8987.o
diff --git a/sound/soc/s3c24xx/rx1950_uda1380.c b/sound/soc/s3c24xx/rx1950_uda1380.c
new file mode 100644
index 0000000..722fe31
--- /dev/null
+++ b/sound/soc/s3c24xx/rx1950_uda1380.c
@@ -0,0 +1,330 @@
+/*
+ * rx1950.c  --  ALSA Soc Audio Layer
+ *
+ * Copyright (c) 2010 Vasily Khoruzhick <anarsoul@gmail.com>
+ *
+ * Based on smdk2440.c and magician.c
+ *
+ * Authors: Graeme Gregory graeme.gregory@wolfsonmicro.com
+ *          Philipp Zabel <philipp.zabel@gmail.com>
+ *          Denis Grigoriev <dgreenday@gmail.com>
+ *          Vasily Khoruzhick <anarsoul@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.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/timer.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/spinlock.h>
+#include <linux/i2c.h>
+#include <linux/gpio.h>
+#include <linux/clk.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/uda1380.h>
+#include <sound/jack.h>
+
+#include <plat/regs-iis.h>
+
+#include <mach/regs-clock.h>
+
+#include "s3c-dma.h"
+#include "s3c24xx-i2s.h"
+#include "../codecs/uda1380.h"
+
+static int rx1950_uda1380_init(struct snd_soc_codec *codec);
+static int rx1950_startup(struct snd_pcm_substream *substream);
+static int rx1950_hw_params(struct snd_pcm_substream *substream,
+				struct snd_pcm_hw_params *params);
+static int rx1950_spk_power(struct snd_soc_dapm_widget *w,
+				struct snd_kcontrol *kcontrol, int event);
+
+static unsigned int rates[] = {
+	16000,
+	44100,
+	48000,
+	88200,
+};
+
+static struct snd_pcm_hw_constraint_list hw_rates = {
+	.count = ARRAY_SIZE(rates),
+	.list = rates,
+	.mask = 0,
+};
+
+static struct snd_soc_jack hp_jack;
+
+static struct snd_soc_jack_pin hp_jack_pins[] = {
+	{
+		.pin	= "Headphone Jack",
+		.mask	= SND_JACK_HEADPHONE,
+	},
+	{
+		.pin	= "Speaker",
+		.mask	= SND_JACK_HEADPHONE,
+		.invert	= 1,
+	},
+};
+
+static struct snd_soc_jack_gpio hp_jack_gpios[] = {
+	[0] = {
+		.gpio			= S3C2410_GPG(12),
+		.name			= "hp-gpio",
+		.report			= SND_JACK_HEADPHONE,
+		.invert			= 1,
+		.debounce_time		= 200,
+	},
+};
+
+static struct snd_soc_ops rx1950_ops = {
+	.startup	= rx1950_startup,
+	.hw_params	= rx1950_hw_params,
+};
+
+/* s3c24xx digital audio interface glue - connects codec <--> CPU */
+static struct snd_soc_dai_link rx1950_uda1380_dai[] = {
+	{
+		.name		= "uda1380",
+		.stream_name	= "UDA1380",
+		.cpu_dai	= &s3c24xx_i2s_dai,
+		.codec_dai	= &uda1380_dai[UDA1380_DAI_DUPLEX],
+		.init		= rx1950_uda1380_init,
+		.ops		= &rx1950_ops,
+	},
+};
+
+static struct snd_soc_card rx1950_asoc = {
+	.name = "rx1950",
+	.platform = &s3c24xx_soc_platform,
+	.dai_link = rx1950_uda1380_dai,
+	.num_links = ARRAY_SIZE(rx1950_uda1380_dai),
+};
+
+/* s3c24xx audio subsystem */
+static struct snd_soc_device s3c24xx_snd_devdata = {
+	.card		= &rx1950_asoc,
+	.codec_dev	= &soc_codec_dev_uda1380,
+};
+
+/* rx1950 machine dapm widgets */
+static const struct snd_soc_dapm_widget uda1380_dapm_widgets[] = {
+	SND_SOC_DAPM_HP("Headphone Jack", NULL),
+	SND_SOC_DAPM_MIC("Mic Jack", NULL),
+	SND_SOC_DAPM_SPK("Speaker", rx1950_spk_power),
+};
+
+/* rx1950 machine audio_map */
+static const struct snd_soc_dapm_route audio_map[] = {
+	/* headphone connected to VOUTLHP, VOUTRHP */
+	{"Headphone Jack", NULL, "VOUTLHP"},
+	{"Headphone Jack", NULL, "VOUTRHP"},
+
+	/* ext speaker connected to VOUTL, VOUTR  */
+	{"Speaker", NULL, "VOUTL"},
+	{"Speaker", NULL, "VOUTR"},
+
+	/* mic is connected to VINM */
+	{"VINM", NULL, "Mic Jack"},
+};
+
+static struct platform_device *s3c24xx_snd_device;
+static struct clk *xtal;
+
+static int rx1950_startup(struct snd_pcm_substream *substream)
+{
+	struct snd_pcm_runtime *runtime = substream->runtime;
+
+	runtime->hw.rate_min = hw_rates.list[0];
+	runtime->hw.rate_max = hw_rates.list[hw_rates.count - 1];
+	runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
+
+	return snd_pcm_hw_constraint_list(runtime, 0,
+					SNDRV_PCM_HW_PARAM_RATE,
+					&hw_rates);
+}
+
+static int rx1950_spk_power(struct snd_soc_dapm_widget *w,
+				struct snd_kcontrol *kcontrol, int event)
+{
+	if (SND_SOC_DAPM_EVENT_ON(event))
+		gpio_direction_output(S3C2410_GPA(1), 1);
+	else
+		gpio_direction_output(S3C2410_GPA(1), 0);
+
+	return 0;
+}
+
+static int rx1950_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 *cpu_dai = rtd->dai->cpu_dai;
+	struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
+	int div;
+	int ret;
+	unsigned int rate = params_rate(params);
+	int clk_source, fs_mode;
+
+	switch (rate) {
+	case 16000:
+	case 48000:
+		clk_source = S3C24XX_CLKSRC_PCLK;
+		fs_mode = S3C2410_IISMOD_384FS;
+		div = s3c24xx_i2s_get_clockrate() / (384 * rate);
+		if (s3c24xx_i2s_get_clockrate() % (384 * rate) > (182 * rate))
+			div++;
+		break;
+	case 44100:
+	case 88200:
+		clk_source = S3C24XX_CLKSRC_MPLL;
+		fs_mode = S3C2410_IISMOD_256FS;
+		div = clk_get_rate(xtal) / (256 * rate);
+		if (clk_get_rate(xtal) % (256 * rate) > (128 * rate))
+			div++;
+		break;
+	default:
+		printk(KERN_ERR "%s: rate %d is not supported\n",
+			__func__, rate);
+		return -EINVAL;
+	}
+
+	/* set codec DAI configuration */
+	ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
+		SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
+	if (ret < 0)
+		return ret;
+
+	/* set cpu DAI configuration */
+	ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
+		SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
+	if (ret < 0)
+		return ret;
+
+	/* select clock source */
+	ret = snd_soc_dai_set_sysclk(cpu_dai, clk_source, rate,
+			SND_SOC_CLOCK_OUT);
+	if (ret < 0)
+		return ret;
+
+	/* set MCLK division for sample rate */
+	ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
+		S3C2410_IISMOD_384FS);
+	if (ret < 0)
+		return ret;
+
+	/* set BCLK division for sample rate */
+	ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_BCLK,
+		S3C2410_IISMOD_32FS);
+	if (ret < 0)
+		return ret;
+
+	/* set prescaler division for sample rate */
+	ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
+		S3C24XX_PRESCALE(div, div));
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static int rx1950_uda1380_init(struct snd_soc_codec *codec)
+{
+	int err;
+
+	/* Add rx1950 specific widgets */
+	snd_soc_dapm_new_controls(codec, uda1380_dapm_widgets,
+				  ARRAY_SIZE(uda1380_dapm_widgets));
+
+	/* Set up rx1950 specific audio path audio_mapnects */
+	err = snd_soc_dapm_add_routes(codec, audio_map,
+				      ARRAY_SIZE(audio_map));
+
+	snd_soc_dapm_enable_pin(codec, "Headphone Jack");
+	snd_soc_dapm_enable_pin(codec, "Speaker");
+
+	snd_soc_dapm_sync(codec);
+
+	snd_soc_jack_new(&rx1950_asoc, "Headphone Jack", SND_JACK_HEADPHONE,
+		&hp_jack);
+
+	snd_soc_jack_add_pins(&hp_jack, ARRAY_SIZE(hp_jack_pins),
+		hp_jack_pins);
+
+	snd_soc_jack_add_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
+		hp_jack_gpios);
+
+	return 0;
+}
+
+static int __init rx1950_init(void)
+{
+	int ret;
+
+	/* configure some gpios */
+	ret = gpio_request(S3C2410_GPA(1), "speaker-power");
+	if (ret)
+		goto err_gpio;
+
+	gpio_direction_output(S3C2410_GPA(1), 0);
+
+	s3c24xx_snd_device = platform_device_alloc("soc-audio", -1);
+	if (!s3c24xx_snd_device) {
+		ret = -ENOMEM;
+		goto err_plat_alloc;
+	}
+
+	platform_set_drvdata(s3c24xx_snd_device, &s3c24xx_snd_devdata);
+	s3c24xx_snd_devdata.dev = &s3c24xx_snd_device->dev;
+	ret = platform_device_add(s3c24xx_snd_device);
+
+	if (ret) {
+		platform_device_put(s3c24xx_snd_device);
+		goto err_plat_add;
+	}
+
+	xtal = clk_get(&s3c24xx_snd_device->dev, "xtal");
+
+	if (!xtal) {
+		platform_device_unregister(s3c24xx_snd_device);
+		goto err_clk;
+	}
+
+	return 0;
+
+err_clk:
+err_plat_add:
+err_plat_alloc:
+	gpio_free(S3C2410_GPA(1));
+
+err_gpio:
+	return ret;
+}
+
+static void __exit rx1950_exit(void)
+{
+	platform_device_unregister(s3c24xx_snd_device);
+	snd_soc_jack_free_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
+		hp_jack_gpios);
+	clk_put(xtal);
+	gpio_free(S3C2410_GPA(1));
+}
+
+module_init(rx1950_init);
+module_exit(rx1950_exit);
+
+/* Module information */
+MODULE_AUTHOR("Vasily Khoruzhick");
+MODULE_DESCRIPTION("ALSA SoC RX1950");
+MODULE_LICENSE("GPL");
-- 
1.7.2

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 2/2] ASoC: Add HP iPAQ RX1950 support
  2010-08-28  8:37   ` [PATCH v2 " Vasily Khoruzhick
@ 2010-08-28  8:46     ` Vasily Khoruzhick
  2010-08-28  8:54     ` [PATCH v3 " Vasily Khoruzhick
  1 sibling, 0 replies; 18+ messages in thread
From: Vasily Khoruzhick @ 2010-08-28  8:46 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Philipp Zabel, Liam Girdwood


[-- Attachment #1.1: Type: Text/Plain, Size: 436 bytes --]

В сообщении от 28 августа 2010 11:37:12 автор Vasily Khoruzhick написал:
> +	if (!xtal) {
> +		platform_device_unregister(s3c24xx_snd_device);
> +		goto err_clk;
> +	}
> +
> +	return 0;
> +
> +err_clk:
> +err_plat_add:
> +err_plat_alloc:
> +	gpio_free(S3C2410_GPA(1));
> +
> +err_gpio:
> +	return ret;
> +}

And again bug in init code (wrong return code on err_clk) :\ Sorry for buzz, 
will send v3 soon.

[-- Attachment #1.2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v3 2/2] ASoC: Add HP iPAQ RX1950 support
  2010-08-28  8:37   ` [PATCH v2 " Vasily Khoruzhick
  2010-08-28  8:46     ` Vasily Khoruzhick
@ 2010-08-28  8:54     ` Vasily Khoruzhick
  2010-08-28  9:06       ` Mark Brown
  1 sibling, 1 reply; 18+ messages in thread
From: Vasily Khoruzhick @ 2010-08-28  8:54 UTC (permalink / raw)
  To: Mark Brown, alsa-devel, Philipp Zabel, Liam Girdwood; +Cc: Vasily Khoruzhick

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
---
 sound/soc/s3c24xx/Kconfig          |    8 +
 sound/soc/s3c24xx/Makefile         |    2 +
 sound/soc/s3c24xx/rx1950_uda1380.c |  331 ++++++++++++++++++++++++++++++++++++
 3 files changed, 341 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/s3c24xx/rx1950_uda1380.c

diff --git a/sound/soc/s3c24xx/Kconfig b/sound/soc/s3c24xx/Kconfig
index 213963ac..66231fd 100644
--- a/sound/soc/s3c24xx/Kconfig
+++ b/sound/soc/s3c24xx/Kconfig
@@ -118,6 +118,14 @@ config SND_S3C24XX_SOC_SIMTEC_HERMES
 	select SND_SOC_TLV320AIC3X
 	select SND_S3C24XX_SOC_SIMTEC
 
+config SND_S3C24XX_SOC_RX1950_UDA1380
+	tristate "Audio support for the HP iPAQ RX1950"
+	depends on SND_S3C24XX_SOC && MACH_RX1950
+	select SND_S3C24XX_SOC_I2S
+	select SND_SOC_UDA1380
+	help
+	  This driver provides audio support for HP iPAQ RX1950 PDA.
+
 config SND_SOC_SMDK_WM9713
 	tristate "SoC AC97 Audio support for SMDK with WM9713"
 	depends on SND_S3C24XX_SOC && (MACH_SMDK6410 || MACH_SMDKC100 || MACH_SMDKV210 || MACH_SMDKC110)
diff --git a/sound/soc/s3c24xx/Makefile b/sound/soc/s3c24xx/Makefile
index 50172c3..8c54a15 100644
--- a/sound/soc/s3c24xx/Makefile
+++ b/sound/soc/s3c24xx/Makefile
@@ -27,6 +27,7 @@ snd-soc-s3c24xx-uda134x-objs := s3c24xx_uda134x.o
 snd-soc-s3c24xx-simtec-objs := s3c24xx_simtec.o
 snd-soc-s3c24xx-simtec-hermes-objs := s3c24xx_simtec_hermes.o
 snd-soc-s3c24xx-simtec-tlv320aic23-objs := s3c24xx_simtec_tlv320aic23.o
+snd-soc-rx1950-uda1380-objs := rx1950_uda1380.o
 snd-soc-smdk64xx-wm8580-objs := smdk64xx_wm8580.o
 snd-soc-smdk-wm9713-objs := smdk_wm9713.o
 snd-soc-s3c64xx-smartq-wm8987-objs := smartq_wm8987.o
@@ -40,6 +41,7 @@ obj-$(CONFIG_SND_S3C24XX_SOC_S3C24XX_UDA134X) += snd-soc-s3c24xx-uda134x.o
 obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC) += snd-soc-s3c24xx-simtec.o
 obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC_HERMES) += snd-soc-s3c24xx-simtec-hermes.o
 obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC_TLV320AIC23) += snd-soc-s3c24xx-simtec-tlv320aic23.o
+obj-$(CONFIG_SND_S3C24XX_SOC_RX1950_UDA1380) += snd-soc-rx1950-uda1380.o
 obj-$(CONFIG_SND_S3C64XX_SOC_WM8580) += snd-soc-smdk64xx-wm8580.o
 obj-$(CONFIG_SND_SOC_SMDK_WM9713) += snd-soc-smdk-wm9713.o
 obj-$(CONFIG_SND_S3C64XX_SOC_SMARTQ) += snd-soc-s3c64xx-smartq-wm8987.o
diff --git a/sound/soc/s3c24xx/rx1950_uda1380.c b/sound/soc/s3c24xx/rx1950_uda1380.c
new file mode 100644
index 0000000..61d49a3
--- /dev/null
+++ b/sound/soc/s3c24xx/rx1950_uda1380.c
@@ -0,0 +1,331 @@
+/*
+ * rx1950.c  --  ALSA Soc Audio Layer
+ *
+ * Copyright (c) 2010 Vasily Khoruzhick <anarsoul@gmail.com>
+ *
+ * Based on smdk2440.c and magician.c
+ *
+ * Authors: Graeme Gregory graeme.gregory@wolfsonmicro.com
+ *          Philipp Zabel <philipp.zabel@gmail.com>
+ *          Denis Grigoriev <dgreenday@gmail.com>
+ *          Vasily Khoruzhick <anarsoul@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.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/timer.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/spinlock.h>
+#include <linux/i2c.h>
+#include <linux/gpio.h>
+#include <linux/clk.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/uda1380.h>
+#include <sound/jack.h>
+
+#include <plat/regs-iis.h>
+
+#include <mach/regs-clock.h>
+
+#include "s3c-dma.h"
+#include "s3c24xx-i2s.h"
+#include "../codecs/uda1380.h"
+
+static int rx1950_uda1380_init(struct snd_soc_codec *codec);
+static int rx1950_startup(struct snd_pcm_substream *substream);
+static int rx1950_hw_params(struct snd_pcm_substream *substream,
+				struct snd_pcm_hw_params *params);
+static int rx1950_spk_power(struct snd_soc_dapm_widget *w,
+				struct snd_kcontrol *kcontrol, int event);
+
+static unsigned int rates[] = {
+	16000,
+	44100,
+	48000,
+	88200,
+};
+
+static struct snd_pcm_hw_constraint_list hw_rates = {
+	.count = ARRAY_SIZE(rates),
+	.list = rates,
+	.mask = 0,
+};
+
+static struct snd_soc_jack hp_jack;
+
+static struct snd_soc_jack_pin hp_jack_pins[] = {
+	{
+		.pin	= "Headphone Jack",
+		.mask	= SND_JACK_HEADPHONE,
+	},
+	{
+		.pin	= "Speaker",
+		.mask	= SND_JACK_HEADPHONE,
+		.invert	= 1,
+	},
+};
+
+static struct snd_soc_jack_gpio hp_jack_gpios[] = {
+	[0] = {
+		.gpio			= S3C2410_GPG(12),
+		.name			= "hp-gpio",
+		.report			= SND_JACK_HEADPHONE,
+		.invert			= 1,
+		.debounce_time		= 200,
+	},
+};
+
+static struct snd_soc_ops rx1950_ops = {
+	.startup	= rx1950_startup,
+	.hw_params	= rx1950_hw_params,
+};
+
+/* s3c24xx digital audio interface glue - connects codec <--> CPU */
+static struct snd_soc_dai_link rx1950_uda1380_dai[] = {
+	{
+		.name		= "uda1380",
+		.stream_name	= "UDA1380",
+		.cpu_dai	= &s3c24xx_i2s_dai,
+		.codec_dai	= &uda1380_dai[UDA1380_DAI_DUPLEX],
+		.init		= rx1950_uda1380_init,
+		.ops		= &rx1950_ops,
+	},
+};
+
+static struct snd_soc_card rx1950_asoc = {
+	.name = "rx1950",
+	.platform = &s3c24xx_soc_platform,
+	.dai_link = rx1950_uda1380_dai,
+	.num_links = ARRAY_SIZE(rx1950_uda1380_dai),
+};
+
+/* s3c24xx audio subsystem */
+static struct snd_soc_device s3c24xx_snd_devdata = {
+	.card		= &rx1950_asoc,
+	.codec_dev	= &soc_codec_dev_uda1380,
+};
+
+/* rx1950 machine dapm widgets */
+static const struct snd_soc_dapm_widget uda1380_dapm_widgets[] = {
+	SND_SOC_DAPM_HP("Headphone Jack", NULL),
+	SND_SOC_DAPM_MIC("Mic Jack", NULL),
+	SND_SOC_DAPM_SPK("Speaker", rx1950_spk_power),
+};
+
+/* rx1950 machine audio_map */
+static const struct snd_soc_dapm_route audio_map[] = {
+	/* headphone connected to VOUTLHP, VOUTRHP */
+	{"Headphone Jack", NULL, "VOUTLHP"},
+	{"Headphone Jack", NULL, "VOUTRHP"},
+
+	/* ext speaker connected to VOUTL, VOUTR  */
+	{"Speaker", NULL, "VOUTL"},
+	{"Speaker", NULL, "VOUTR"},
+
+	/* mic is connected to VINM */
+	{"VINM", NULL, "Mic Jack"},
+};
+
+static struct platform_device *s3c24xx_snd_device;
+static struct clk *xtal;
+
+static int rx1950_startup(struct snd_pcm_substream *substream)
+{
+	struct snd_pcm_runtime *runtime = substream->runtime;
+
+	runtime->hw.rate_min = hw_rates.list[0];
+	runtime->hw.rate_max = hw_rates.list[hw_rates.count - 1];
+	runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
+
+	return snd_pcm_hw_constraint_list(runtime, 0,
+					SNDRV_PCM_HW_PARAM_RATE,
+					&hw_rates);
+}
+
+static int rx1950_spk_power(struct snd_soc_dapm_widget *w,
+				struct snd_kcontrol *kcontrol, int event)
+{
+	if (SND_SOC_DAPM_EVENT_ON(event))
+		gpio_direction_output(S3C2410_GPA(1), 1);
+	else
+		gpio_direction_output(S3C2410_GPA(1), 0);
+
+	return 0;
+}
+
+static int rx1950_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 *cpu_dai = rtd->dai->cpu_dai;
+	struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
+	int div;
+	int ret;
+	unsigned int rate = params_rate(params);
+	int clk_source, fs_mode;
+
+	switch (rate) {
+	case 16000:
+	case 48000:
+		clk_source = S3C24XX_CLKSRC_PCLK;
+		fs_mode = S3C2410_IISMOD_384FS;
+		div = s3c24xx_i2s_get_clockrate() / (384 * rate);
+		if (s3c24xx_i2s_get_clockrate() % (384 * rate) > (182 * rate))
+			div++;
+		break;
+	case 44100:
+	case 88200:
+		clk_source = S3C24XX_CLKSRC_MPLL;
+		fs_mode = S3C2410_IISMOD_256FS;
+		div = clk_get_rate(xtal) / (256 * rate);
+		if (clk_get_rate(xtal) % (256 * rate) > (128 * rate))
+			div++;
+		break;
+	default:
+		printk(KERN_ERR "%s: rate %d is not supported\n",
+			__func__, rate);
+		return -EINVAL;
+	}
+
+	/* set codec DAI configuration */
+	ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
+		SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
+	if (ret < 0)
+		return ret;
+
+	/* set cpu DAI configuration */
+	ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
+		SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
+	if (ret < 0)
+		return ret;
+
+	/* select clock source */
+	ret = snd_soc_dai_set_sysclk(cpu_dai, clk_source, rate,
+			SND_SOC_CLOCK_OUT);
+	if (ret < 0)
+		return ret;
+
+	/* set MCLK division for sample rate */
+	ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
+		S3C2410_IISMOD_384FS);
+	if (ret < 0)
+		return ret;
+
+	/* set BCLK division for sample rate */
+	ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_BCLK,
+		S3C2410_IISMOD_32FS);
+	if (ret < 0)
+		return ret;
+
+	/* set prescaler division for sample rate */
+	ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
+		S3C24XX_PRESCALE(div, div));
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static int rx1950_uda1380_init(struct snd_soc_codec *codec)
+{
+	int err;
+
+	/* Add rx1950 specific widgets */
+	snd_soc_dapm_new_controls(codec, uda1380_dapm_widgets,
+				  ARRAY_SIZE(uda1380_dapm_widgets));
+
+	/* Set up rx1950 specific audio path audio_mapnects */
+	err = snd_soc_dapm_add_routes(codec, audio_map,
+				      ARRAY_SIZE(audio_map));
+
+	snd_soc_dapm_enable_pin(codec, "Headphone Jack");
+	snd_soc_dapm_enable_pin(codec, "Speaker");
+
+	snd_soc_dapm_sync(codec);
+
+	snd_soc_jack_new(&rx1950_asoc, "Headphone Jack", SND_JACK_HEADPHONE,
+		&hp_jack);
+
+	snd_soc_jack_add_pins(&hp_jack, ARRAY_SIZE(hp_jack_pins),
+		hp_jack_pins);
+
+	snd_soc_jack_add_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
+		hp_jack_gpios);
+
+	return 0;
+}
+
+static int __init rx1950_init(void)
+{
+	int ret;
+
+	/* configure some gpios */
+	ret = gpio_request(S3C2410_GPA(1), "speaker-power");
+	if (ret)
+		goto err_gpio;
+
+	gpio_direction_output(S3C2410_GPA(1), 0);
+
+	s3c24xx_snd_device = platform_device_alloc("soc-audio", -1);
+	if (!s3c24xx_snd_device) {
+		ret = -ENOMEM;
+		goto err_plat_alloc;
+	}
+
+	platform_set_drvdata(s3c24xx_snd_device, &s3c24xx_snd_devdata);
+	s3c24xx_snd_devdata.dev = &s3c24xx_snd_device->dev;
+	ret = platform_device_add(s3c24xx_snd_device);
+
+	if (ret) {
+		platform_device_put(s3c24xx_snd_device);
+		goto err_plat_add;
+	}
+
+	xtal = clk_get(&s3c24xx_snd_device->dev, "xtal");
+
+	if (IS_ERR(xtal)) {
+		ret = PTR_ERR(xtal);
+		platform_device_unregister(s3c24xx_snd_device);
+		goto err_clk;
+	}
+
+	return 0;
+
+err_clk:
+err_plat_add:
+err_plat_alloc:
+	gpio_free(S3C2410_GPA(1));
+
+err_gpio:
+	return ret;
+}
+
+static void __exit rx1950_exit(void)
+{
+	platform_device_unregister(s3c24xx_snd_device);
+	snd_soc_jack_free_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
+		hp_jack_gpios);
+	clk_put(xtal);
+	gpio_free(S3C2410_GPA(1));
+}
+
+module_init(rx1950_init);
+module_exit(rx1950_exit);
+
+/* Module information */
+MODULE_AUTHOR("Vasily Khoruzhick");
+MODULE_DESCRIPTION("ALSA SoC RX1950");
+MODULE_LICENSE("GPL");
-- 
1.7.2

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] ASoC: uda1380: make driver more powersave-friendly
  2010-08-28  7:49 ` [PATCH 1/2] ASoC: uda1380: make driver more powersave-friendly Vasily Khoruzhick
@ 2010-08-28  8:56   ` Mark Brown
  2010-08-28  9:07     ` Vasily Khoruzhick
  0 siblings, 1 reply; 18+ messages in thread
From: Mark Brown @ 2010-08-28  8:56 UTC (permalink / raw)
  To: Vasily Khoruzhick; +Cc: alsa-devel, Philipp Zabel, Liam Girdwood

On Sat, Aug 28, 2010 at 10:49:35AM +0300, Vasily Khoruzhick wrote:
> Disable some codec modules in standby mode, completely disable
> codec in off mode to save some power.

> Fix suspend/resume: mark mixer regs as dirty on resume to
> restore mixer values, otherwise driver produces no sound
> (master is muted by default).

This sounds like there's a pre-existing bug where the register cache
defaults don't correspond to the chip defaults.  In general we always
keep the initial chip defaults for user visible controls in the driver
and let the application layer set the values it wants.  This avoids
having to worry about defaults being inappropriate for some systems (eg,
volumes far too loud or bad output path selection) - normally the chip
defaults will be reasonable for first power up.

The code itself looks good from a quick read through.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 2/2] ASoC: Add HP iPAQ RX1950 support
  2010-08-28  8:54     ` [PATCH v3 " Vasily Khoruzhick
@ 2010-08-28  9:06       ` Mark Brown
  2010-08-28  9:28         ` Vasily Khoruzhick
                           ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Mark Brown @ 2010-08-28  9:06 UTC (permalink / raw)
  To: Vasily Khoruzhick; +Cc: alsa-devel, Philipp Zabel, Liam Girdwood

On Sat, Aug 28, 2010 at 11:54:26AM +0300, Vasily Khoruzhick wrote:

This is basically fine but needs to be redone against current ASoC due
to Liam's multi-component work - the way the machine driver is
registered with the system has changed.  See either -next or

 git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound-2.6.git for-2.6.37

for the latest code.

> +static int rx1950_startup(struct snd_pcm_substream *substream)
> +{
> +	struct snd_pcm_runtime *runtime = substream->runtime;
> +
> +	runtime->hw.rate_min = hw_rates.list[0];
> +	runtime->hw.rate_max = hw_rates.list[hw_rates.count - 1];
> +	runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
> +
> +	return snd_pcm_hw_constraint_list(runtime, 0,
> +					SNDRV_PCM_HW_PARAM_RATE,
> +					&hw_rates);
> +}

Where does this constraint come from?  It's the sort of thing that
sounds like it comes from one of the chips so I'd expect their drivers
to be figuring it out.  Let's see below...

> +static int rx1950_spk_power(struct snd_soc_dapm_widget *w,
> +				struct snd_kcontrol *kcontrol, int event)
> +{
> +	if (SND_SOC_DAPM_EVENT_ON(event))
> +		gpio_direction_output(S3C2410_GPA(1), 1);
> +	else
> +		gpio_direction_output(S3C2410_GPA(1), 0);
> +
> +	return 0;
> +}

We should really make a standard GPIO DAPM thing.  Not a problem for
this driver, though.

> +	switch (rate) {
> +	case 16000:
> +	case 48000:
> +		clk_source = S3C24XX_CLKSRC_PCLK;
> +		fs_mode = S3C2410_IISMOD_384FS;
> +		div = s3c24xx_i2s_get_clockrate() / (384 * rate);
> +		if (s3c24xx_i2s_get_clockrate() % (384 * rate) > (182 * rate))
> +			div++;
> +		break;
> +	case 44100:
> +	case 88200:
> +		clk_source = S3C24XX_CLKSRC_MPLL;
> +		fs_mode = S3C2410_IISMOD_256FS;
> +		div = clk_get_rate(xtal) / (256 * rate);
> +		if (clk_get_rate(xtal) % (256 * rate) > (128 * rate))
> +			div++;
> +		break;

...right, it's the CPU driver which is a bit more manual than is ideal.
OK, again not a problem for this driver.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] ASoC: uda1380: make driver more powersave-friendly
  2010-08-28  8:56   ` Mark Brown
@ 2010-08-28  9:07     ` Vasily Khoruzhick
  2010-08-28  9:14       ` Mark Brown
  0 siblings, 1 reply; 18+ messages in thread
From: Vasily Khoruzhick @ 2010-08-28  9:07 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Philipp Zabel, Liam Girdwood


[-- Attachment #1.1: Type: Text/Plain, Size: 1351 bytes --]

В сообщении от 28 августа 2010 11:56:36 автор Mark Brown написал:
> On Sat, Aug 28, 2010 at 10:49:35AM +0300, Vasily Khoruzhick wrote:
> > Disable some codec modules in standby mode, completely disable
> > codec in off mode to save some power.
> > 
> > Fix suspend/resume: mark mixer regs as dirty on resume to
> > restore mixer values, otherwise driver produces no sound
> > (master is muted by default).
> 
> This sounds like there's a pre-existing bug where the register cache
> defaults don't correspond to the chip defaults.  In general we always
> keep the initial chip defaults for user visible controls in the driver
> and let the application layer set the values it wants.  This avoids
> having to worry about defaults being inappropriate for some systems (eg,
> volumes far too loud or bad output path selection) - normally the chip
> defaults will be reasonable for first power up.

It seems that you misunderstood me, chip defaults are ok for first power up, 
but resume is not first power up and codec defaults differ from cache, so we 
want to sync cache with codec regs on resume, but it is not possible to sync 
mixer regs until i2s clock is not applied, so we just mark them as dirty to 
sync them later (just before playback, when i2s clock is already applied)

Regards
Vasily

[-- Attachment #1.2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] ASoC: uda1380: make driver more powersave-friendly
  2010-08-28  9:07     ` Vasily Khoruzhick
@ 2010-08-28  9:14       ` Mark Brown
  2010-08-28  9:17         ` Vasily Khoruzhick
  2010-08-28 11:34         ` [PATCH v2 " Vasily Khoruzhick
  0 siblings, 2 replies; 18+ messages in thread
From: Mark Brown @ 2010-08-28  9:14 UTC (permalink / raw)
  To: Vasily Khoruzhick; +Cc: alsa-devel, Philipp Zabel, Liam Girdwood

On Sat, Aug 28, 2010 at 12:07:54PM +0300, Vasily Khoruzhick wrote:

> It seems that you misunderstood me, chip defaults are ok for first power up, 
> but resume is not first power up and codec defaults differ from cache, so we 
> want to sync cache with codec regs on resume, but it is not possible to sync 
> mixer regs until i2s clock is not applied, so we just mark them as dirty to 
> sync them later (just before playback, when i2s clock is already applied)

The normal flow for this is to mark things as dirty when you cut the
power rather than in one particular restore path - that is more robust
against code changes which alter the set of situations which can turn
off the power.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] ASoC: uda1380: make driver more powersave-friendly
  2010-08-28  9:14       ` Mark Brown
@ 2010-08-28  9:17         ` Vasily Khoruzhick
  2010-08-28 11:34         ` [PATCH v2 " Vasily Khoruzhick
  1 sibling, 0 replies; 18+ messages in thread
From: Vasily Khoruzhick @ 2010-08-28  9:17 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Philipp Zabel, Liam Girdwood


[-- Attachment #1.1: Type: Text/Plain, Size: 865 bytes --]

В сообщении от 28 августа 2010 12:14:46 автор Mark Brown написал:
> On Sat, Aug 28, 2010 at 12:07:54PM +0300, Vasily Khoruzhick wrote:
> > It seems that you misunderstood me, chip defaults are ok for first power
> > up, but resume is not first power up and codec defaults differ from
> > cache, so we want to sync cache with codec regs on resume, but it is not
> > possible to sync mixer regs until i2s clock is not applied, so we just
> > mark them as dirty to sync them later (just before playback, when i2s
> > clock is already applied)
> 
> The normal flow for this is to mark things as dirty when you cut the
> power rather than in one particular restore path - that is more robust
> against code changes which alter the set of situations which can turn
> off the power.

Ok, sounds reasonable.

Regards
Vasily

[-- Attachment #1.2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 2/2] ASoC: Add HP iPAQ RX1950 support
  2010-08-28  9:06       ` Mark Brown
@ 2010-08-28  9:28         ` Vasily Khoruzhick
  2010-08-31 10:45           ` Mark Brown
  2010-08-28 11:37         ` Vasily Khoruzhick
  2010-08-29  9:31         ` Vasily Khoruzhick
  2 siblings, 1 reply; 18+ messages in thread
From: Vasily Khoruzhick @ 2010-08-28  9:28 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Philipp Zabel, Liam Girdwood


[-- Attachment #1.1: Type: Text/Plain, Size: 2477 bytes --]

В сообщении от 28 августа 2010 12:06:17 автор Mark Brown написал:
> On Sat, Aug 28, 2010 at 11:54:26AM +0300, Vasily Khoruzhick wrote:
> 
> This is basically fine but needs to be redone against current ASoC due
> to Liam's multi-component work - the way the machine driver is
> registered with the system has changed.  See either -next or
> 
>  git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound-2.6.git
> for-2.6.37
> 
> for the latest code.
> 
> > +static int rx1950_startup(struct snd_pcm_substream *substream)
> > +{
> > +	struct snd_pcm_runtime *runtime = substream->runtime;
> > +
> > +	runtime->hw.rate_min = hw_rates.list[0];
> > +	runtime->hw.rate_max = hw_rates.list[hw_rates.count - 1];
> > +	runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
> > +
> > +	return snd_pcm_hw_constraint_list(runtime, 0,
> > +					SNDRV_PCM_HW_PARAM_RATE,
> > +					&hw_rates);
> > +}
> 
> Where does this constraint come from?  It's the sort of thing that
> sounds like it comes from one of the chips so I'd expect their drivers
> to be figuring it out.  Let's see below...
> 
> > +static int rx1950_spk_power(struct snd_soc_dapm_widget *w,
> > +				struct snd_kcontrol *kcontrol, int event)
> > +{
> > +	if (SND_SOC_DAPM_EVENT_ON(event))
> > +		gpio_direction_output(S3C2410_GPA(1), 1);
> > +	else
> > +		gpio_direction_output(S3C2410_GPA(1), 0);
> > +
> > +	return 0;
> > +}
> 
> We should really make a standard GPIO DAPM thing.  Not a problem for
> this driver, though.

Ok

> > +	switch (rate) {
> > +	case 16000:
> > +	case 48000:
> > +		clk_source = S3C24XX_CLKSRC_PCLK;
> > +		fs_mode = S3C2410_IISMOD_384FS;
> > +		div = s3c24xx_i2s_get_clockrate() / (384 * rate);
> > +		if (s3c24xx_i2s_get_clockrate() % (384 * rate) > (182 * rate))
> > +			div++;
> > +		break;
> > +	case 44100:
> > +	case 88200:
> > +		clk_source = S3C24XX_CLKSRC_MPLL;
> > +		fs_mode = S3C2410_IISMOD_256FS;
> > +		div = clk_get_rate(xtal) / (256 * rate);
> > +		if (clk_get_rate(xtal) % (256 * rate) > (128 * rate))
> > +			div++;
> > +		break;
> 
> ...right, it's the CPU driver which is a bit more manual than is ideal.
> OK, again not a problem for this driver.

These constraints are machine-specific. They depends on what clock source for 
i2s machine can provide, for rx1950 it's ~49.9mhz and 299mhz, so I doubt that 
these constraints can be integrated into s3c24xx-i2s driver

Regards
Vasily

[-- Attachment #1.2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v2 1/2] ASoC: uda1380: make driver more powersave-friendly
  2010-08-28  9:14       ` Mark Brown
  2010-08-28  9:17         ` Vasily Khoruzhick
@ 2010-08-28 11:34         ` Vasily Khoruzhick
  1 sibling, 0 replies; 18+ messages in thread
From: Vasily Khoruzhick @ 2010-08-28 11:34 UTC (permalink / raw)
  To: Mark Brown, alsa-devel, Philipp Zabel, Liam Girdwood; +Cc: Vasily Khoruzhick

Disable some codec modules in standby mode, completely disable
codec in off mode to save some power.
Fix suspend/resume: mark mixer regs as dirty on resume to
restore mixer values, otherwise driver produces no sound
(master is muted by default).

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
---
 sound/soc/codecs/uda1380.c |  139 +++++++++++++++++++++++++++++++------------
 1 files changed, 100 insertions(+), 39 deletions(-)

diff --git a/sound/soc/codecs/uda1380.c b/sound/soc/codecs/uda1380.c
index 2f925a2..c8902cc 100644
--- a/sound/soc/codecs/uda1380.c
+++ b/sound/soc/codecs/uda1380.c
@@ -131,7 +131,46 @@ static int uda1380_write(struct snd_soc_codec *codec, unsigned int reg,
 		return -EIO;
 }
 
-#define uda1380_reset(c)	uda1380_write(c, UDA1380_RESET, 0)
+static void uda1380_sync_cache(struct snd_soc_codec *codec)
+{
+	int reg;
+	u8 data[3];
+	u16 *cache = codec->reg_cache;
+
+	/* Sync reg_cache with the hardware */
+	for (reg = 0; reg < UDA1380_MVOL; reg++) {
+		data[0] = reg;
+		data[1] = (cache[reg] & 0xff00) >> 8;
+		data[2] = cache[reg] & 0x00ff;
+		if (codec->hw_write(codec->control_data, data, 3) != 3)
+			dev_err(codec->dev, "%s: write to reg 0x%x failed\n",
+				__func__, reg);
+	}
+}
+
+static int uda1380_reset(struct snd_soc_codec *codec)
+{
+	struct uda1380_platform_data *pdata = codec->dev->platform_data;
+
+	if (pdata->gpio_reset != -EINVAL) {
+		gpio_set_value(pdata->gpio_reset, 1);
+		mdelay(1);
+		gpio_set_value(pdata->gpio_reset, 0);
+	} else {
+		u8 data[3];
+
+		data[0] = UDA1380_RESET;
+		data[1] = 0;
+		data[2] = 0;
+
+		if (codec->hw_write(codec->control_data, data, 3) != 3) {
+			dev_err(codec->dev, "%s: failed\n", __func__);
+			return -EIO;
+		}
+	}
+
+	return 0;
+}
 
 static void uda1380_flush_work(struct work_struct *work)
 {
@@ -562,18 +601,40 @@ static int uda1380_set_bias_level(struct snd_soc_codec *codec,
 	enum snd_soc_bias_level level)
 {
 	int pm = uda1380_read_reg_cache(codec, UDA1380_PM);
+	struct uda1380_platform_data *pdata = codec->dev->platform_data;
+
+	if (codec->bias_level == level)
+		return 0;
 
 	switch (level) {
 	case SND_SOC_BIAS_ON:
 	case SND_SOC_BIAS_PREPARE:
+		/* ADC, DAC on */
 		uda1380_write(codec, UDA1380_PM, R02_PON_BIAS | pm);
 		break;
 	case SND_SOC_BIAS_STANDBY:
-		uda1380_write(codec, UDA1380_PM, R02_PON_BIAS);
-		break;
-	case SND_SOC_BIAS_OFF:
+		if (codec->bias_level == SND_SOC_BIAS_OFF) {
+			if (pdata->gpio_power != -EINVAL) {
+				gpio_set_value(pdata->gpio_power, 1);
+				uda1380_reset(codec);
+			}
+
+			uda1380_sync_cache(codec);
+		}
 		uda1380_write(codec, UDA1380_PM, 0x0);
 		break;
+	case SND_SOC_BIAS_OFF:
+		if (pdata->gpio_power != -EINVAL) {
+			int reg;
+			gpio_set_value(pdata->gpio_power, 0);
+
+			/* Mark mixer regs cache dirty to sync them with
+			 * codec regs on power on.
+			 */
+			for (reg = UDA1380_MVOL; reg < UDA1380_CACHEREGNUM;
+				reg++)
+				set_bit(reg - 0x10, &uda1380_cache_dirty);
+		}
 	}
 	codec->bias_level = level;
 	return 0;
@@ -659,16 +720,7 @@ static int uda1380_resume(struct platform_device *pdev)
 {
 	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
 	struct snd_soc_codec *codec = socdev->card->codec;
-	int i;
-	u8 data[2];
-	u16 *cache = codec->reg_cache;
 
-	/* Sync reg_cache with the hardware */
-	for (i = 0; i < ARRAY_SIZE(uda1380_reg); i++) {
-		data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
-		data[1] = cache[i] & 0x00ff;
-		codec->hw_write(codec->control_data, data, 2);
-	}
 	uda1380_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 	return 0;
 }
@@ -698,16 +750,18 @@ static int uda1380_probe(struct platform_device *pdev)
 
 	/* power on device */
 	uda1380_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-	/* set clock input */
+
 	switch (pdata->dac_clk) {
 	case UDA1380_DAC_CLK_SYSCLK:
-		uda1380_write(codec, UDA1380_CLK, 0);
+		uda1380_write_reg_cache(codec, UDA1380_CLK, 0);
 		break;
 	case UDA1380_DAC_CLK_WSPLL:
-		uda1380_write(codec, UDA1380_CLK, R00_DAC_CLK);
+		uda1380_write_reg_cache(codec, UDA1380_CLK,
+			R00_DAC_CLK);
 		break;
 	}
 
+
 	snd_soc_add_controls(codec, uda1380_snd_controls,
 				ARRAY_SIZE(uda1380_snd_controls));
 	uda1380_add_widgets(codec);
@@ -752,22 +806,22 @@ static int uda1380_register(struct uda1380_priv *uda1380)
 		return -EINVAL;
 	}
 
-	if (!pdata || !pdata->gpio_power || !pdata->gpio_reset)
+	if (!pdata)
 		return -EINVAL;
 
-	ret = gpio_request(pdata->gpio_power, "uda1380 power");
-	if (ret)
-		goto err_out;
-	ret = gpio_request(pdata->gpio_reset, "uda1380 reset");
-	if (ret)
-		goto err_gpio;
-
-	gpio_direction_output(pdata->gpio_power, 1);
+	if (pdata->gpio_power != -EINVAL) {
+		ret = gpio_request(pdata->gpio_power, "uda1380 power");
+		if (ret)
+			goto err_out;
+		gpio_direction_output(pdata->gpio_power, 0);
+	}
 
-	/* we may need to have the clock running here - pH5 */
-	gpio_direction_output(pdata->gpio_reset, 1);
-	udelay(5);
-	gpio_set_value(pdata->gpio_reset, 0);
+	if (pdata->gpio_reset != -EINVAL) {
+		ret = gpio_request(pdata->gpio_reset, "uda1380 reset");
+		if (ret)
+			goto err_gpio;
+		gpio_direction_output(pdata->gpio_reset, 0);
+	}
 
 	mutex_init(&codec->mutex);
 	INIT_LIST_HEAD(&codec->dapm_widgets);
@@ -788,10 +842,12 @@ static int uda1380_register(struct uda1380_priv *uda1380)
 
 	memcpy(codec->reg_cache, uda1380_reg, sizeof(uda1380_reg));
 
-	ret = uda1380_reset(codec);
-	if (ret < 0) {
-		dev_err(codec->dev, "Failed to issue reset\n");
-		goto err_reset;
+	if (pdata->gpio_power == -EINVAL) {
+		ret = uda1380_reset(codec);
+		if (ret < 0) {
+			dev_err(codec->dev, "Failed to issue reset\n");
+			goto err_reset;
+		}
 	}
 
 	INIT_WORK(&uda1380->work, uda1380_flush_work);
@@ -818,10 +874,11 @@ static int uda1380_register(struct uda1380_priv *uda1380)
 err_dai:
 	snd_soc_unregister_codec(codec);
 err_reset:
-	gpio_set_value(pdata->gpio_power, 0);
-	gpio_free(pdata->gpio_reset);
+	if (pdata->gpio_reset != -EINVAL)
+		gpio_free(pdata->gpio_reset);
 err_gpio:
-	gpio_free(pdata->gpio_power);
+	if (pdata->gpio_power != -EINVAL)
+		gpio_free(pdata->gpio_power);
 err_out:
 	return ret;
 }
@@ -834,9 +891,13 @@ static void uda1380_unregister(struct uda1380_priv *uda1380)
 	snd_soc_unregister_dais(uda1380_dai, ARRAY_SIZE(uda1380_dai));
 	snd_soc_unregister_codec(&uda1380->codec);
 
-	gpio_set_value(pdata->gpio_power, 0);
-	gpio_free(pdata->gpio_reset);
-	gpio_free(pdata->gpio_power);
+	if (pdata->gpio_power != -EINVAL) {
+		gpio_set_value(pdata->gpio_power, 0);
+		gpio_free(pdata->gpio_power);
+	}
+
+	if (pdata->gpio_reset != -EINVAL)
+		gpio_free(pdata->gpio_reset);
 
 	kfree(uda1380);
 	uda1380_codec = NULL;
-- 
1.7.2

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 2/2] ASoC: Add HP iPAQ RX1950 support
  2010-08-28  9:06       ` Mark Brown
  2010-08-28  9:28         ` Vasily Khoruzhick
@ 2010-08-28 11:37         ` Vasily Khoruzhick
  2010-08-29  9:31         ` Vasily Khoruzhick
  2 siblings, 0 replies; 18+ messages in thread
From: Vasily Khoruzhick @ 2010-08-28 11:37 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Philipp Zabel, Liam Girdwood


[-- Attachment #1.1: Type: Text/Plain, Size: 631 bytes --]

В сообщении от 28 августа 2010 12:06:17 автор Mark Brown написал:
> On Sat, Aug 28, 2010 at 11:54:26AM +0300, Vasily Khoruzhick wrote:
> 
> This is basically fine but needs to be redone against current ASoC due
> to Liam's multi-component work - the way the machine driver is
> registered with the system has changed.  See either -next or
> 
>  git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound-2.6.git
> for-2.6.37
> 
> for the latest code.

Ok, I'll rework it, but can you merge just uda1380 patch (v2) for now?

Thanks for quick response and review! :)

Regards
Vasily

[-- Attachment #1.2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 2/2] ASoC: Add HP iPAQ RX1950 support
  2010-08-28  9:06       ` Mark Brown
  2010-08-28  9:28         ` Vasily Khoruzhick
  2010-08-28 11:37         ` Vasily Khoruzhick
@ 2010-08-29  9:31         ` Vasily Khoruzhick
  2010-08-29 13:54           ` Mark Brown
  2 siblings, 1 reply; 18+ messages in thread
From: Vasily Khoruzhick @ 2010-08-29  9:31 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Philipp Zabel, Liam Girdwood


[-- Attachment #1.1: Type: Text/Plain, Size: 918 bytes --]

В сообщении от 28 августа 2010 12:06:17 автор Mark Brown написал:
> On Sat, Aug 28, 2010 at 11:54:26AM +0300, Vasily Khoruzhick wrote:
> 
> This is basically fine but needs to be redone against current ASoC due
> to Liam's multi-component work - the way the machine driver is
> registered with the system has changed.  See either -next or
> 
>  git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound-2.6.git
> for-2.6.37
> 
> for the latest code.

Hmm, it seems that s3c24xx-i2s is broken for multicomponent.

snd-soc-s3c24xx and snd-soc-s3c24xx-i2s are just drivers, but there's no 
appropriate platform_device for them. So I'm getting this (with debug 
enabled):

soc-audio soc-audio: CPU DAI s3c24xx-i2s not registered
soc-audio soc-audio: platform s3c24xx-pcm-audio not registered

Who should register platform_device for these drivers?

Regards
Vasily

[-- Attachment #1.2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 2/2] ASoC: Add HP iPAQ RX1950 support
  2010-08-29  9:31         ` Vasily Khoruzhick
@ 2010-08-29 13:54           ` Mark Brown
  0 siblings, 0 replies; 18+ messages in thread
From: Mark Brown @ 2010-08-29 13:54 UTC (permalink / raw)
  To: Vasily Khoruzhick; +Cc: alsa-devel, Philipp Zabel, Liam Girdwood

On Sun, Aug 29, 2010 at 12:31:54PM +0300, Vasily Khoruzhick wrote:

> snd-soc-s3c24xx and snd-soc-s3c24xx-i2s are just drivers, but there's no 
> appropriate platform_device for them. So I'm getting this (with debug 
> enabled):

> soc-audio soc-audio: CPU DAI s3c24xx-i2s not registered
> soc-audio soc-audio: platform s3c24xx-pcm-audio not registered

> Who should register platform_device for these drivers?

This should be done by the arch/arm code for the board, referring to
platform devices defined for the CPU (Samsung support tends to make the
registration of devices optional rather than just registering everything
the CPU supports as many other platforms do).

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 2/2] ASoC: Add HP iPAQ RX1950 support
  2010-08-28  9:28         ` Vasily Khoruzhick
@ 2010-08-31 10:45           ` Mark Brown
  0 siblings, 0 replies; 18+ messages in thread
From: Mark Brown @ 2010-08-31 10:45 UTC (permalink / raw)
  To: Vasily Khoruzhick; +Cc: alsa-devel, Philipp Zabel, Liam Girdwood

On Sat, Aug 28, 2010 at 12:28:19PM +0300, Vasily Khoruzhick wrote:
> В сообщении от 28 августа 2010 12:06:17 автор Mark Brown написал:

> > ...right, it's the CPU driver which is a bit more manual than is ideal.
> > OK, again not a problem for this driver.

> These constraints are machine-specific. They depends on what clock source for 
> i2s machine can provide, for rx1950 it's ~49.9mhz and 299mhz, so I doubt that 
> these constraints can be integrated into s3c24xx-i2s driver

Right, but the CPU driver should be able to implement them as a result
of knowing the clocks it's been given - the machine specific bit is the
clocking available to the CPU, not the sample rates that this results
in.
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2010-08-31 10:45 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-28  7:49 [PATCH 0/2] ASoC: Add iPAQ RX1950 sound support Vasily Khoruzhick
2010-08-28  7:49 ` [PATCH 1/2] ASoC: uda1380: make driver more powersave-friendly Vasily Khoruzhick
2010-08-28  8:56   ` Mark Brown
2010-08-28  9:07     ` Vasily Khoruzhick
2010-08-28  9:14       ` Mark Brown
2010-08-28  9:17         ` Vasily Khoruzhick
2010-08-28 11:34         ` [PATCH v2 " Vasily Khoruzhick
2010-08-28  7:49 ` [PATCH 2/2] ASoC: Add HP iPAQ RX1950 support Vasily Khoruzhick
2010-08-28  8:31   ` Vasily Khoruzhick
2010-08-28  8:37   ` [PATCH v2 " Vasily Khoruzhick
2010-08-28  8:46     ` Vasily Khoruzhick
2010-08-28  8:54     ` [PATCH v3 " Vasily Khoruzhick
2010-08-28  9:06       ` Mark Brown
2010-08-28  9:28         ` Vasily Khoruzhick
2010-08-31 10:45           ` Mark Brown
2010-08-28 11:37         ` Vasily Khoruzhick
2010-08-29  9:31         ` Vasily Khoruzhick
2010-08-29 13:54           ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.