alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Ladislav Michl <ladis@linux-mips.org>
To: alsa-devel@alsa-project.org
Cc: Charles Keepax <ckeepax@opensource.cirrus.com>,
	Alexandre Belloni <alexandre.belloni@free-electrons.com>,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>,
	anish kumar <yesanishhere@gmail.com>
Subject: [PATCH 5/7] ASoC: max9867: Calculate LRCLK divider
Date: Tue, 30 Jan 2018 12:10:08 +0100	[thread overview]
Message-ID: <20180130111008.GF18123@lenoch> (raw)
In-Reply-To: <20180130110604.GA18123@lenoch>

Do not limit sample rate to a few precalculated frequencies
based on "Common NI Values Table" and put the same equation
used to create that table directly in code.

Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
---
 sound/soc/codecs/max9867.c | 64 +++-------------------------------------------
 1 file changed, 4 insertions(+), 60 deletions(-)

diff --git a/sound/soc/codecs/max9867.c b/sound/soc/codecs/max9867.c
index 2f60924fe919..026b7cf94910 100644
--- a/sound/soc/codecs/max9867.c
+++ b/sound/soc/codecs/max9867.c
@@ -126,75 +126,19 @@ static const struct snd_soc_dapm_route max9867_audio_map[] = {
 	{"LINE_IN", NULL, "Right Line"},
 };
 
-enum rates {
-	pcm_rate_8, pcm_rate_16, pcm_rate_24,
-	pcm_rate_32, pcm_rate_44,
-	pcm_rate_48, max_pcm_rate,
-};
-
-static const struct ni_div_rates {
-	u32 mclk;
-	u16 ni[max_pcm_rate];
-} ni_div[] = {
-	{11289600, {0x116A, 0x22D4, 0x343F, 0x45A9, 0x6000, 0x687D} },
-	{12000000, {0x1062, 0x20C5, 0x3127, 0x4189, 0x5A51, 0x624E} },
-	{12288000, {0x1000, 0x2000, 0x3000, 0x4000, 0x5833, 0x6000} },
-	{13000000, {0x0F20, 0x1E3F, 0x2D5F, 0x3C7F, 0x535F, 0x5ABE} },
-	{19200000, {0x0A3D, 0x147B, 0x1EB8, 0x28F6, 0x3873, 0x3D71} },
-	{24000000, {0x1062, 0x20C5, 0x1893, 0x4189, 0x5A51, 0x624E} },
-	{26000000, {0x0F20, 0x1E3F, 0x16AF, 0x3C7F, 0x535F, 0x5ABE} },
-	{27000000, {0x0E90, 0x1D21, 0x15D8, 0x3A41, 0x5048, 0x5762} },
-};
-
-static inline int get_ni_value(int mclk, int rate)
-{
-	int i, ret = 0;
-
-	/* find the closest rate index*/
-	for (i = 0; i < ARRAY_SIZE(ni_div); i++) {
-		if (ni_div[i].mclk >= mclk)
-			break;
-	}
-	if (i == ARRAY_SIZE(ni_div))
-		return -EINVAL;
-
-	switch (rate) {
-	case 8000:
-		return ni_div[i].ni[pcm_rate_8];
-	case 16000:
-		return ni_div[i].ni[pcm_rate_16];
-	case 32000:
-		return ni_div[i].ni[pcm_rate_32];
-	case 44100:
-		return ni_div[i].ni[pcm_rate_44];
-	case 48000:
-		return ni_div[i].ni[pcm_rate_48];
-	default:
-		pr_err("%s wrong rate %d\n", __func__, rate);
-		ret = -EINVAL;
-	}
-	return ret;
-}
-
 static int max9867_dai_hw_params(struct snd_pcm_substream *substream,
 		struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
 {
 	struct snd_soc_codec *codec = dai->codec;
 	struct max9867_priv *max9867 = snd_soc_codec_get_drvdata(codec);
-	unsigned int ni_h, ni_l;
-	int value;
-
-	value = get_ni_value(max9867->sysclk, params_rate(params));
-	if (value < 0)
-		return value;
+	unsigned int ni = DIV_ROUND_CLOSEST_ULL(96 * 0x10000 *
+		(unsigned long long)params_rate(params), max9867->sysclk);
 
-	ni_h = (0xFF00 & value) >> 8;
-	ni_l = 0x00FF & value;
 	/* set up the ni value */
 	regmap_update_bits(max9867->regmap, MAX9867_AUDIOCLKHIGH,
-		MAX9867_NI_HIGH_MASK, ni_h);
+		MAX9867_NI_HIGH_MASK, (0xFF00 & ni) >> 8);
 	regmap_update_bits(max9867->regmap, MAX9867_AUDIOCLKLOW,
-		MAX9867_NI_LOW_MASK, ni_l);
+		MAX9867_NI_LOW_MASK, 0x00FF & ni);
 	if (!max9867->master) {
 		/*
 		 * digital pll locks on to any externally supplied LRCLK signal
-- 
2.15.1

  parent reply	other threads:[~2018-01-30 11:10 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-30 11:06 [PATCH 0/7] Let Atmel use simple-audio-card Ladislav Michl
2018-01-30 11:06 ` [PATCH 1/7] ASoC: atmel: Remove redundant dev_err() call in probe function Ladislav Michl
2018-02-27 16:54   ` Alexandre Belloni
2018-02-27 17:13     ` Nicolas Ferre
2018-03-01 18:06   ` Applied "ASoC: atmel: Remove redundant dev_err() call in probe function" to the asoc tree Mark Brown
2018-01-30 11:08 ` [PATCH 2/7] ASoC: atmel_ssc_dai: Fix TCMR settings in I2S slave mode Ladislav Michl
2018-02-27 17:09   ` Alexandre Belloni
2018-02-27 18:50     ` Ladislav Michl
2018-01-30 11:08 ` [PATCH 3/7] ASoC: simple_card_utils: Set clock frequency Ladislav Michl
2018-02-27 17:19   ` Alexandre Belloni
2018-01-30 11:09 ` [PATCH 4/7] ASoC: max9867: Show Kconfig entry Ladislav Michl
2018-03-01 18:06   ` Applied "ASoC: max9867: Show Kconfig entry" to the asoc tree Mark Brown
2018-01-30 11:10 ` Ladislav Michl [this message]
2018-01-30 11:10 ` [PATCH 6/7] ASoC: max9867: Fix BSEL value in master mode Ladislav Michl
2018-02-27 17:23   ` Alexandre Belloni
2018-02-27 19:03     ` Ladislav Michl
2018-02-28 10:00       ` Alexandre Belloni
2018-02-28 10:23         ` Ladislav Michl
2018-02-28 10:28           ` Alexandre Belloni
2018-01-30 11:11 ` [PATCH 7/7] ASoC: max9867: Take chip out of shutdown Ladislav Michl

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=20180130111008.GF18123@lenoch \
    --to=ladis@linux-mips.org \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=ckeepax@opensource.cirrus.com \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=nicolas.ferre@microchip.com \
    --cc=yesanishhere@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).