All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kuninori Morimoto <morimoto.kuninori@renesas.com>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: Linux-ALSA <alsa-devel@alsa-project.org>
Subject: [PATCH 2/3] ASoC: ak4642: Add set_fmt function for snd_soc_dai_ops
Date: Mon, 15 Mar 2010 18:10:50 +0900	[thread overview]
Message-ID: <usk7r4hwa.wl%morimoto.kuninori@renesas.com> (raw)
In-Reply-To: <uvdcn4hx0.wl%morimoto.kuninori@renesas.com>

Signed-off-by: Kuninori Morimoto <morimoto.kuninori@renesas.com>
---
 sound/soc/codecs/ak4642.c |   69 +++++++++++++++++++++++++++++---------------
 sound/soc/sh/fsi-ak4642.c |    4 ++
 2 files changed, 49 insertions(+), 24 deletions(-)

diff --git a/sound/soc/codecs/ak4642.c b/sound/soc/codecs/ak4642.c
index d5bd4ca..3452bd7 100644
--- a/sound/soc/codecs/ak4642.c
+++ b/sound/soc/codecs/ak4642.c
@@ -80,6 +80,17 @@
 
 #define AK4642_CACHEREGNUM 	0x25
 
+/* PW_MGMT2 */
+#define HPMTN		(1 << 6)
+#define PMHPL		(1 << 5)
+#define PMHPR		(1 << 4)
+#define MS		(1 << 3) /* master/slave select */
+#define MCKO		(1 << 1)
+#define PMPLL		(1 << 0)
+
+#define PMHP_MASK	(PMHPL | PMHPR)
+#define PMHP		PMHP_MASK
+
 /* MD_CTL1 */
 #define PLL3		(1 << 7)
 #define PLL2		(1 << 6)
@@ -87,6 +98,9 @@
 #define PLL0		(1 << 4)
 #define PLL_MASK	(PLL3 | PLL2 | PLL1 | PLL0)
 
+#define BCKO_MASK	(1 << 3)
+#define BCKO_64		BCKO_MASK
+
 struct snd_soc_codec_device soc_codec_dev_ak4642;
 
 /* codec private data */
@@ -188,9 +202,6 @@ static int ak4642_dai_startup(struct snd_pcm_substream *substream,
 		 *
 		 * This operation came from example code of
 		 * "ASAHI KASEI AK4642" (japanese) manual p97.
-		 *
-		 * Example code use 0x39, 0x79 value for 0x01 address,
-		 * But we need MCKO (0x02) bit now
 		 */
 		ak4642_write(codec, 0x05, 0x27);
 		ak4642_write(codec, 0x0f, 0x09);
@@ -200,8 +211,8 @@ static int ak4642_dai_startup(struct snd_pcm_substream *substream,
 		ak4642_write(codec, 0x0a, 0x28);
 		ak4642_write(codec, 0x0d, 0x28);
 		ak4642_write(codec, 0x00, 0x64);
-		ak4642_write(codec, 0x01, 0x3b); /* + MCKO bit */
-		ak4642_write(codec, 0x01, 0x7b); /* + MCKO bit */
+		snd_soc_update_bits(codec, PW_MGMT2, PMHP_MASK,	PMHP);
+		snd_soc_update_bits(codec, PW_MGMT2, HPMTN,	HPMTN);
 	} else {
 		/*
 		 * start stereo input
@@ -238,8 +249,8 @@ static void ak4642_dai_shutdown(struct snd_pcm_substream *substream,
 
 	if (is_play) {
 		/* stop headphone output */
-		ak4642_write(codec, 0x01, 0x3b);
-		ak4642_write(codec, 0x01, 0x0b);
+		snd_soc_update_bits(codec, PW_MGMT2, HPMTN,	0);
+		snd_soc_update_bits(codec, PW_MGMT2, PMHP_MASK,	0);
 		ak4642_write(codec, 0x00, 0x40);
 		ak4642_write(codec, 0x0e, 0x11);
 		ak4642_write(codec, 0x0f, 0x08);
@@ -284,10 +295,37 @@ static int ak4642_dai_set_sysclk(struct snd_soc_dai *codec_dai,
 	return 0;
 }
 
+static int ak4642_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
+{
+	struct snd_soc_codec *codec = dai->codec;
+	u8 data;
+	u8 bcko;
+
+	data = MCKO | PMPLL; /* use MCKO */
+	bcko = 0;
+
+	/* set master/slave audio interface */
+	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+	case SND_SOC_DAIFMT_CBM_CFM:
+		data |= MS;
+		bcko = BCKO_64;
+		break;
+	case SND_SOC_DAIFMT_CBS_CFS:
+		break;
+	default:
+		return -EINVAL;
+	}
+	snd_soc_update_bits(codec, PW_MGMT2, MS, data);
+	snd_soc_update_bits(codec, MD_CTL1, BCKO_MASK, bcko);
+
+	return 0;
+}
+
 static struct snd_soc_dai_ops ak4642_dai_ops = {
 	.startup	= ak4642_dai_startup,
 	.shutdown	= ak4642_dai_shutdown,
 	.set_sysclk	= ak4642_dai_set_sysclk,
+	.set_fmt	= ak4642_dai_set_fmt,
 };
 
 struct snd_soc_dai ak4642_dai = {
@@ -366,23 +404,6 @@ static int ak4642_init(struct ak4642_priv *ak4642)
 		goto reg_cache_err;
 	}
 
-	/*
-	 * clock setting
-	 *
-	 * Audio I/F Format: MSB justified (ADC & DAC)
-	 * BICK frequency at Master Mode: 64fs
-	 * MCKO: Enable
-	 * Sampling Frequency: 44.1kHz
-	 *
-	 * This operation came from example code of
-	 * "ASAHI KASEI AK4642" (japanese) manual p89.
-	 *
-	 * please fix-me
-	 */
-	ak4642_write(codec, 0x01, 0x08);
-	ak4642_write(codec, 0x05, 0x27);
-	ak4642_write(codec, 0x04, 0x0a);
-
 	return ret;
 
 reg_cache_err:
diff --git a/sound/soc/sh/fsi-ak4642.c b/sound/soc/sh/fsi-ak4642.c
index c0207dc..be01854 100644
--- a/sound/soc/sh/fsi-ak4642.c
+++ b/sound/soc/sh/fsi-ak4642.c
@@ -26,6 +26,10 @@ static int fsi_ak4642_dai_init(struct snd_soc_codec *codec)
 {
 	int ret;
 
+	ret = snd_soc_dai_set_fmt(&ak4642_dai, SND_SOC_DAIFMT_CBM_CFM);
+	if (ret < 0)
+		return ret;
+
 	ret = snd_soc_dai_set_sysclk(&ak4642_dai, 0, 11289600, 0);
 
 	return ret;
-- 
1.6.3.3

  reply	other threads:[~2010-03-23  7:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-23  7:27 [PATCH 0/3] ASoC: ak4642: sampling rate update Kuninori Morimoto
2010-03-15  9:10 ` Kuninori Morimoto [this message]
2010-03-23 15:36   ` [PATCH 2/3] ASoC: ak4642: Add set_fmt function for snd_soc_dai_ops Liam Girdwood
2010-03-23  7:27 ` [PATCH 1/3] ASoC: ak4642: Add pll select support Kuninori Morimoto
2010-03-23 10:10   ` Liam Girdwood
2010-03-23  7:27 ` [PATCH 3/3] ASoC: ak4642: Add enhanced sampling rate Kuninori Morimoto
2010-03-23 10:10   ` Liam Girdwood
2010-03-23 15:38 ` [PATCH 0/3] ASoC: ak4642: sampling rate update Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=usk7r4hwa.wl%morimoto.kuninori@renesas.com \
    --to=morimoto.kuninori@renesas.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.