From: Samuel Holland <samuel@sholland.org>
To: "Mark Brown" <broonie@kernel.org>,
"Liam Girdwood" <lgirdwood@gmail.com>,
"Rob Herring" <robh+dt@kernel.org>,
"Mark Rutland" <mark.rutland@arm.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Chen-Yu Tsai" <wens@csie.org>,
"Vasily Khoruzhick" <anarsoul@gmail.com>,
"Mylène Josserand" <mylene.josserand@free-electrons.com>,
"Jaroslav Kysela" <perex@perex.cz>,
"Takashi Iwai" <tiwai@suse.com>
Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Samuel Holland <samuel@sholland.org>
Subject: [RFC PATCH 20/34] ASoC: sun8i-codec: Support 8/20/24-bit word sizes
Date: Mon, 17 Feb 2020 00:42:36 -0600 [thread overview]
Message-ID: <20200217064250.15516-21-samuel@sholland.org> (raw)
In-Reply-To: <20200217064250.15516-1-samuel@sholland.org>
The codec hardware natively supports 8, 16, 20, and 24-bit word sizes.
However, it only supports slot widths that are a multiple of 16 bits.
So we can only support the 20-bit and 24-bit formats that are padded to
32 bits. This doesn't cost anything, because the DMA controller on the
CPU side only supports power-of-two byte sizes anyway.
S8, S16_LE, and S24_LE were tested using a modified version of the
sun4i-i2s driver as the CPU end of the DAI link. S20_LE was not tested
due to poor userspace support; it should work the same.
In 8 bit mono mode, the computed BCLK/LRCK divider will be less than the
minimum value 16. This is fine; there will just be padding after the
data bits, similar to how S20_LE and S24_LE always have padding.
Signed-off-by: Samuel Holland <samuel@sholland.org>
---
sound/soc/sunxi/sun8i-codec.c | 47 ++++++++++++++++++++++++-----------
1 file changed, 32 insertions(+), 15 deletions(-)
diff --git a/sound/soc/sunxi/sun8i-codec.c b/sound/soc/sunxi/sun8i-codec.c
index 2df899daec67..b915e62fa005 100644
--- a/sound/soc/sunxi/sun8i-codec.c
+++ b/sound/soc/sunxi/sun8i-codec.c
@@ -45,7 +45,6 @@
#define SUN8I_AIF1CLK_CTRL_AIF1_BCLK_DIV 9
#define SUN8I_AIF1CLK_CTRL_AIF1_LRCK_DIV 6
#define SUN8I_AIF1CLK_CTRL_AIF1_WORD_SIZ 4
-#define SUN8I_AIF1CLK_CTRL_AIF1_WORD_SIZ_16 (1 << 4)
#define SUN8I_AIF1CLK_CTRL_AIF1_DATA_FMT 2
#define SUN8I_AIF1CLK_CTRL_AIF1_MONO_PCM 1
#define SUN8I_AIF1_ADCDAT_CTRL 0x044
@@ -87,6 +86,10 @@
#define SUN8I_AIF1CLK_CTRL_AIF1_WORD_SIZ_MASK GENMASK(5, 4)
#define SUN8I_AIF1CLK_CTRL_AIF1_DATA_FMT_MASK GENMASK(3, 2)
+#define SUN8I_AIF_PCM_FMTS (SNDRV_PCM_FMTBIT_S8|\
+ SNDRV_PCM_FMTBIT_S16_LE|\
+ SNDRV_PCM_FMTBIT_S20_LE|\
+ SNDRV_PCM_FMTBIT_S24_LE)
#define SUN8I_AIF_PCM_RATES (SNDRV_PCM_RATE_8000_48000|\
SNDRV_PCM_RATE_96000|\
SNDRV_PCM_RATE_192000|\
@@ -307,7 +310,9 @@ static int sun8i_codec_get_lrck_div(unsigned int channels,
{
unsigned int div = word_size * channels;
- if (div < 16 || div > 256)
+ if (div < 16)
+ div = 16;
+ if (div > 256)
return -EINVAL;
return ilog2(div) - 4;
@@ -318,27 +323,19 @@ static int sun8i_codec_hw_params(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
struct sun8i_codec *scodec = snd_soc_component_get_drvdata(dai->component);
+ unsigned int slot_width = params_physical_width(params);
unsigned int channels = params_channels(params);
int sample_rate, lrck_div;
u8 bclk_div;
u32 value;
- /*
- * The CPU DAI handles only a sample of 16 bits. Configure the
- * codec to handle this type of sample resolution.
- */
- regmap_update_bits(scodec->regmap, SUN8I_AIF1CLK_CTRL,
- SUN8I_AIF1CLK_CTRL_AIF1_WORD_SIZ_MASK,
- SUN8I_AIF1CLK_CTRL_AIF1_WORD_SIZ_16);
-
bclk_div = sun8i_codec_get_bclk_div(scodec, params_rate(params),
- channels, 16);
+ channels, slot_width);
regmap_update_bits(scodec->regmap, SUN8I_AIF1CLK_CTRL,
SUN8I_AIF1CLK_CTRL_AIF1_BCLK_DIV_MASK,
bclk_div << SUN8I_AIF1CLK_CTRL_AIF1_BCLK_DIV);
- lrck_div = sun8i_codec_get_lrck_div(channels,
- params_physical_width(params));
+ lrck_div = sun8i_codec_get_lrck_div(channels, slot_width);
if (lrck_div < 0)
return lrck_div;
@@ -346,6 +343,26 @@ static int sun8i_codec_hw_params(struct snd_pcm_substream *substream,
SUN8I_AIF1CLK_CTRL_AIF1_LRCK_DIV_MASK,
lrck_div << SUN8I_AIF1CLK_CTRL_AIF1_LRCK_DIV);
+ switch (params_width(params)) {
+ case 8:
+ value = 0x0;
+ break;
+ case 16:
+ value = 0x1;
+ break;
+ case 20:
+ value = 0x2;
+ break;
+ case 24:
+ value = 0x3;
+ break;
+ default:
+ return -EINVAL;
+ }
+ regmap_update_bits(scodec->regmap, SUN8I_AIF1CLK_CTRL,
+ SUN8I_AIF1CLK_CTRL_AIF1_WORD_SIZ_MASK,
+ value << SUN8I_AIF1CLK_CTRL_AIF1_WORD_SIZ);
+
value = channels == 1;
regmap_update_bits(scodec->regmap, SUN8I_AIF1CLK_CTRL,
BIT(SUN8I_AIF1CLK_CTRL_AIF1_MONO_PCM),
@@ -533,7 +550,7 @@ static struct snd_soc_dai_driver sun8i_codec_dai = {
.channels_min = 1,
.channels_max = 2,
.rates = SUN8I_AIF_PCM_RATES,
- .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ .formats = SUN8I_AIF_PCM_FMTS,
},
/* capture capabilities */
.capture = {
@@ -541,7 +558,7 @@ static struct snd_soc_dai_driver sun8i_codec_dai = {
.channels_min = 1,
.channels_max = 2,
.rates = SUN8I_AIF_PCM_RATES,
- .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ .formats = SUN8I_AIF_PCM_FMTS,
.sig_bits = 24,
},
/* pcm operations */
--
2.24.1
next prev parent reply other threads:[~2020-02-17 6:44 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-17 6:42 [RFC PATCH 00/34] sun8i-codec fixes and new features Samuel Holland
2020-02-17 6:42 ` [RFC PATCH 01/34] ASoC: dt-bindings: Add a separate compatible for the A64 codec Samuel Holland
2020-02-17 9:49 ` Chen-Yu Tsai
2020-02-18 3:17 ` Samuel Holland
2020-02-26 15:18 ` Rob Herring
2020-02-17 6:42 ` [RFC PATCH 02/34] ASoC: sun8i-codec: LRCK is not inverted on A64 Samuel Holland
2020-02-17 9:50 ` Chen-Yu Tsai
2020-02-17 14:43 ` Mark Brown
2020-02-17 6:42 ` [RFC PATCH 03/34] arm64: dts: allwinner: a64: Fix the audio codec compatible Samuel Holland
2020-02-17 14:56 ` Mark Brown
2020-02-17 6:42 ` [RFC PATCH 04/34] ASoC: sun8i-codec: Remove unused dev from codec struct Samuel Holland
2020-02-17 7:41 ` Chen-Yu Tsai
2020-02-17 15:04 ` Mark Brown
2020-02-21 14:21 ` Applied "ASoC: sun8i-codec: Remove unused dev from codec struct" to the asoc tree Mark Brown
2020-02-17 6:42 ` [RFC PATCH 05/34] ASoC: sun8i-codec: Remove incorrect SND_SOC_DAIFMT_DSP_B Samuel Holland
2020-02-17 8:19 ` Chen-Yu Tsai
2020-02-17 15:02 ` Mark Brown
2020-02-18 1:35 ` Samuel Holland
2020-02-18 11:32 ` Mark Brown
2020-02-17 6:42 ` [RFC PATCH 06/34] ASoC: sun8i-codec: Fix setting DAI data format Samuel Holland
2020-02-17 8:23 ` Chen-Yu Tsai
2020-02-17 22:03 ` Applied "ASoC: sun8i-codec: Fix setting DAI data format" to the asoc tree Mark Brown
2020-02-17 6:42 ` [RFC PATCH 07/34] ASoC: sun8i-codec: Remove extraneous widgets Samuel Holland
2020-02-17 7:37 ` Chen-Yu Tsai
2020-02-17 15:05 ` Mark Brown
2020-02-17 6:42 ` [RFC PATCH 08/34] ASoC: sun8i-codec: Fix direction of AIF1 outputs Samuel Holland
2020-02-17 8:22 ` Chen-Yu Tsai
2020-02-17 15:09 ` Mark Brown
2020-02-18 1:44 ` Samuel Holland
2020-02-17 6:42 ` [RFC PATCH 09/34] ASoC: sun8i-codec: Fix broken DAPM routing Samuel Holland
2020-02-17 15:24 ` Mark Brown
2020-02-17 6:42 ` [RFC PATCH 10/34] ASoC: sun8i-codec: Advertise only hardware-supported rates Samuel Holland
2020-02-17 15:30 ` Mark Brown
2020-02-18 1:55 ` Samuel Holland
2020-02-17 6:42 ` [RFC PATCH 11/34] ASoC: sun8i-codec: Enforce parameter symmetry Samuel Holland
2020-02-17 6:42 ` [RFC PATCH 12/34] ASoC: sun8i-codec: Fix AIF1 MODCLK widget name Samuel Holland
2020-02-17 8:06 ` Chen-Yu Tsai
2020-02-17 6:42 ` [RFC PATCH 13/34] ASoC: sun8i-codec: Fix AIF1_ADCDAT_CTRL field names Samuel Holland
2020-02-17 7:58 ` Chen-Yu Tsai
2020-02-17 6:42 ` [RFC PATCH 14/34] ASoC: sun8i-codec: Fix AIF1_MXR_SRC " Samuel Holland
2020-02-17 7:57 ` Chen-Yu Tsai
2020-02-17 6:42 ` [RFC PATCH 15/34] ASoC: sun8i-codec: Fix ADC_DIG_CTRL field name Samuel Holland
2020-02-17 7:55 ` Chen-Yu Tsai
2020-02-17 6:42 ` [RFC PATCH 16/34] ASoC: sun8i-codec: Fix field bit number indentation Samuel Holland
2020-02-17 7:54 ` Chen-Yu Tsai
2020-02-17 6:42 ` [RFC PATCH 17/34] ASoC: sun8i-codec: Sort masks in a consistent order Samuel Holland
2020-02-17 7:59 ` Chen-Yu Tsai
2020-02-17 6:42 ` [RFC PATCH 18/34] ASoC: sun8i-codec: Allow all clock inversion permutations Samuel Holland
2020-02-17 6:42 ` [RFC PATCH 19/34] ASoC: sun8i-codec: Support mono DAI configurations Samuel Holland
2020-02-17 6:42 ` Samuel Holland [this message]
2020-02-17 6:42 ` [RFC PATCH 21/34] ASoC: sun8i-codec: Clean up module/clock hierarchy Samuel Holland
2020-02-17 6:42 ` [RFC PATCH 22/34] ASoC: sun8i-codec: Clean up AIF1 Slot 0 widgets Samuel Holland
2020-02-17 6:42 ` [RFC PATCH 23/34] ASoC: sun8i-codec: Clean up DAC widgets Samuel Holland
2020-02-17 6:42 ` [RFC PATCH 24/34] ASoC: sun8i-codec: Prepare to support multiple AIFs Samuel Holland
2020-02-17 6:42 ` [RFC PATCH 25/34] ASoC: sun8i-codec: Add support for AIF2 Samuel Holland
2020-02-17 6:42 ` [RFC PATCH 26/34] ASoC: sun8i-codec: Add support for AIF3 Samuel Holland
2020-02-17 6:42 ` [RFC PATCH 27/34] ASoC: sun8i-codec: Add AIF mono/stereo controls Samuel Holland
2020-02-17 6:42 ` [RFC PATCH 28/34] ASoC: sun8i-codec: Add AIF loopback controls Samuel Holland
2020-02-17 6:42 ` [RFC PATCH 29/34] ASoC: sun8i-codec: Add AIF, ADC, and DAC volume controls Samuel Holland
2020-02-17 6:42 ` [RFC PATCH 30/34] ASoC: dt-bindings: Bump sound-dai-cells on sun8i-codec Samuel Holland
2020-02-18 20:23 ` Rob Herring
2020-02-17 6:42 ` [RFC PATCH 31/34] ARM: dts: sun8i-a33: Allow using multiple codec DAIs Samuel Holland
2020-02-17 6:42 ` [RFC PATCH 32/34] arm64: dts: allwinner: a64: " Samuel Holland
2020-02-17 6:42 ` [RFC PATCH 33/34] arm64: dts: allwinner: a64: Allow multiple DAI links Samuel Holland
2020-02-17 6:42 ` [RFC PATCH 34/34] arm64: dts: allwinner: a64: Add pinmux for AIF2/AIF3 Samuel Holland
2020-02-17 9:14 ` [RFC PATCH 00/34] sun8i-codec fixes and new features Maxime Ripard
2020-02-17 9:44 ` Chen-Yu Tsai
2020-02-17 12:07 ` Maxime Ripard
2020-02-17 16:26 ` 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=20200217064250.15516-21-samuel@sholland.org \
--to=samuel@sholland.org \
--cc=alsa-devel@alsa-project.org \
--cc=anarsoul@gmail.com \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mripard@kernel.org \
--cc=mylene.josserand@free-electrons.com \
--cc=perex@perex.cz \
--cc=robh+dt@kernel.org \
--cc=tiwai@suse.com \
--cc=wens@csie.org \
/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).